vdr 2.6.9
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 2.2 2010/05/16 11:00:52 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
24
25// --- cAudios ---------------------------------------------------------------
26
28
29void 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
35void cAudios::PlayTsAudio(const uchar *Data, int Length)
36{
37 for (cAudio *audio = First(); audio; audio = Next(audio))
38 audio->PlayTs(Data, Length);
39}
40
41void 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
56{
57 command = strdup(Command);
58 mute = false;
60}
61
66
67void 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) {
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
95void 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
119{
120 mute = On;
121 if (mute)
122 Clear();
123}
124
126{
127 pipe.Close();
128}
cAudios Audios
Definition audio.c:27
cAudios Audios
Definition audio.c:27
Definition audio.h:16
cAudio(void)
Definition audio.c:16
virtual ~cAudio()
Definition audio.c:21
void PlayAudio(const uchar *Data, int Length, uchar Id)
Definition audio.c:29
void PlayTsAudio(const uchar *Data, int Length)
Definition audio.c:35
void ClearAudio(void)
Definition audio.c:47
void MuteAudio(bool On)
Definition audio.c:41
static void SetTransferModeForDolbyDigital(int Mode)
Definition dvbdevice.c:2362
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 ~cExternalAudio()
Definition audio.c:62
cPipe pipe
Definition audio.h:52
char * command
Definition audio.h:51
virtual void Play(const uchar *Data, int Length, uchar Id)
Plays the given block of audio Data.
Definition audio.c:67
virtual void Clear(void)
Clears all data that might still be awaiting processing.
Definition audio.c:125
bool mute
Definition audio.h:53
cExternalAudio(const char *Command)
Definition audio.c:55
virtual void PlayTs(const uchar *Data, int Length)
Plays the given block of audio Data.
Definition audio.c:95
virtual void Clear(void)
Definition tools.c:2296
void Add(cListObject *Object, cListObject *After=NULL)
Definition tools.c:2219
const cAudio * First(void) const
Returns the first element in this list, or NULL if the list is empty.
Definition tools.h:656
const cAudio * Next(const cAudio *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
Definition tools.h:663
int Close(void)
Definition thread.c:1001
bool Open(const char *Command, const char *Mode)
Definition thread.c:947
unsigned char uchar
Definition tools.h:31
#define esyslog(a...)
Definition tools.h:35
#define LOG_ERROR
Definition tools.h:39