vdr  2.2.0
audio.c
Go to the documentation of this file.
1 /*
2  * audio.c: The basic audio interface
3  *
4  * See the main source file 'vdr.c' for copyright information and
5  * how to reach the author.
6  *
7  * $Id: audio.c 3.0 2010/05/16 13:30:11 kls Exp $
8  */
9 
10 #include "audio.h"
11 #include <stdlib.h>
12 #include "dvbdevice.h"
13 
14 // --- cAudio ----------------------------------------------------------------
15 
17 {
18  Audios.Add(this);
19 }
20 
22 {
23 }
24 
25 // --- cAudios ---------------------------------------------------------------
26 
28 
29 void cAudios::PlayAudio(const uchar *Data, int Length, uchar Id)
30 {
31  for (cAudio *audio = First(); audio; audio = Next(audio))
32  audio->Play(Data, Length, Id);
33 }
34 
35 void cAudios::PlayTsAudio(const uchar *Data, int Length)
36 {
37  for (cAudio *audio = First(); audio; audio = Next(audio))
38  audio->PlayTs(Data, Length);
39 }
40 
41 void cAudios::MuteAudio(bool On)
42 {
43  for (cAudio *audio = First(); audio; audio = Next(audio))
44  audio->Mute(On);
45 }
46 
48 {
49  for (cAudio *audio = First(); audio; audio = Next(audio))
50  audio->Clear();
51 }
52 
53 // --- cExternalAudio --------------------------------------------------------
54 
55 cExternalAudio::cExternalAudio(const char *Command)
56 {
57  command = strdup(Command);
58  mute = false;
60 }
61 
63 {
64  free(command);
65 }
66 
67 void cExternalAudio::Play(const uchar *Data, int Length, uchar Id)
68 {
69  if (command && !mute) {
70  if (pipe || pipe.Open(command, "w")) {
71  if (0x80 <= Id && Id <= 0x87 || Id == 0xBD) { // AC3
72  int written = Data[8] + 9; // skips the PES header
73  if (Id != 0xBD)
74  written += 4; // skips AC3 bytes
75  Length -= written;
76  while (Length > 0) {
77  int w = fwrite(Data + written, 1, Length, pipe);
78  if (w < 0) {
79  LOG_ERROR;
80  break;
81  }
82  Length -= w;
83  written += w;
84  }
85  }
86  }
87  else {
88  esyslog("ERROR: can't open pipe to audio command '%s'", command);
89  free(command);
90  command = NULL;
91  }
92  }
93 }
94 
95 void cExternalAudio::PlayTs(const uchar *Data, int Length)
96 {
97  if (command && !mute) {
98  if (pipe || pipe.Open(command, "w")) {
99  int written = 0;
100  while (Length > 0) {
101  int w = fwrite(Data + written, 1, Length, pipe);
102  if (w < 0) {
103  LOG_ERROR;
104  break;
105  }
106  Length -= w;
107  written += w;
108  }
109  }
110  else {
111  esyslog("ERROR: can't open pipe to audio command '%s'", command);
112  free(command);
113  command = NULL;
114  }
115  }
116 }
117 
118 void cExternalAudio::Mute(bool On)
119 {
120  mute = On;
121  if (mute)
122  Clear();
123 }
124 
126 {
127  pipe.Close();
128 }
void MuteAudio(bool On)
Definition: audio.c:41
unsigned char uchar
Definition: tools.h:30
void ClearAudio(void)
Definition: audio.c:47
#define LOG_ERROR
Definition: tools.h:38
cAudio(void)
Definition: audio.c:16
virtual ~cAudio()
Definition: audio.c:21
void Add(cListObject *Object, cListObject *After=NULL)
Definition: tools.c:2014
void PlayAudio(const uchar *Data, int Length, uchar Id)
Definition: audio.c:29
#define esyslog(a...)
Definition: tools.h:34
virtual void Clear(void)
Clears all data that might still be awaiting processing.
Definition: audio.c:125
virtual void PlayTs(const uchar *Data, int Length)
Plays the given block of audio Data.
Definition: audio.c:95
virtual void Mute(bool On)
Immediately sets the audio device to be silent (On==true) or to normal replay (On==false).
Definition: audio.c:118
virtual void Play(const uchar *Data, int Length, uchar Id)
Plays the given block of audio Data.
Definition: audio.c:67
virtual ~cExternalAudio()
Definition: audio.c:62
cAudios Audios
Definition: audio.c:27
cListObject * Next(void) const
Definition: tools.h:468
cExternalAudio(const char *Command)
Definition: audio.c:55
Definition: audio.h:39
virtual void Clear(void)=0
Clears all data that might still be awaiting processing.
Definition: audio.h:16
void PlayTsAudio(const uchar *Data, int Length)
Definition: audio.c:35
static void SetTransferModeForDolbyDigital(int Mode)
Definition: dvbdevice.c:1662