![]() |
|||
Dokumentation
VDR
|
00001 /* 00002 * audio.c: The basic audio interface 00003 * 00004 * See the main source file 'vdr.c' for copyright information and 00005 * how to reach the author. 00006 * 00007 * $Id: audio.c 1.2 2002/11/03 11:53:34 kls Exp $ 00008 */ 00009 00010 #include "audio.h" 00011 #include "stdlib.h" 00012 00013 // --- cAudio ---------------------------------------------------------------- 00014 00015 cAudio::cAudio(void) 00016 { 00017 Audios.Add(this); 00018 } 00019 00020 cAudio::~cAudio() 00021 { 00022 } 00023 00024 // --- cAudios --------------------------------------------------------------- 00025 00026 cAudios Audios; 00027 00028 void cAudios::PlayAudio(const uchar *Data, int Length) 00029 { 00030 for (cAudio *audio = First(); audio; audio = Next(audio)) 00031 audio->Play(Data, Length); 00032 } 00033 00034 void cAudios::MuteAudio(bool On) 00035 { 00036 for (cAudio *audio = First(); audio; audio = Next(audio)) 00037 audio->Mute(On); 00038 } 00039 00040 void cAudios::ClearAudio(void) 00041 { 00042 for (cAudio *audio = First(); audio; audio = Next(audio)) 00043 audio->Clear(); 00044 } 00045 00046 // --- cExternalAudio -------------------------------------------------------- 00047 00048 cExternalAudio::cExternalAudio(const char *Command) 00049 { 00050 command = strdup(Command); 00051 mute = false; 00052 } 00053 00054 cExternalAudio::~cExternalAudio() 00055 { 00056 free(command); 00057 } 00058 00059 void cExternalAudio::Play(const uchar *Data, int Length) 00060 { 00061 if (command && !mute) { 00062 if (pipe || pipe.Open(command, "w")) { 00063 if (Data[0] == 0x00 && Data[1] == 0x00 && Data[2] == 0x01) { 00064 if (Data[3] == 0xBD) { // dolby 00065 //XXX??? int written = Data[8] + (skipAC3bytes ? 13 : 9); // skips the PES header 00066 int written = Data[8] + 9; // skips the PES header 00067 Length -= written; 00068 while (Length > 0) { 00069 int w = fwrite(Data + written, 1, Length, pipe); 00070 if (w < 0) { 00071 LOG_ERROR; 00072 break; 00073 } 00074 Length -= w; 00075 written += w; 00076 } 00077 } 00078 } 00079 } 00080 else { 00081 esyslog("ERROR: can't open pipe to audio command '%s'", command); 00082 free(command); 00083 command = NULL; 00084 } 00085 } 00086 } 00087 00088 void cExternalAudio::Mute(bool On) 00089 { 00090 mute = On; 00091 if (mute) 00092 Clear(); 00093 } 00094 00095 void cExternalAudio::Clear(void) 00096 { 00097 pipe.Close(); 00098 }