1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00
vdr/audio.c

98 lines
2.0 KiB
C
Raw Permalink Normal View History

/*
* audio.c: The basic audio interface
*
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
2005-02-12 13:01:24 +01:00
* $Id: audio.c 1.3 2005/02/12 12:40:51 kls Exp $
*/
#include "audio.h"
2002-11-03 11:53:58 +01:00
#include "stdlib.h"
2002-11-03 11:53:58 +01:00
// --- cAudio ----------------------------------------------------------------
cAudio::cAudio(void)
{
Audios.Add(this);
}
cAudio::~cAudio()
{
}
// --- cAudios ---------------------------------------------------------------
cAudios Audios;
2005-02-12 13:01:24 +01:00
void cAudios::PlayAudio(const uchar *Data, int Length, uchar Id)
2002-11-03 11:53:58 +01:00
{
for (cAudio *audio = First(); audio; audio = Next(audio))
2005-02-12 13:01:24 +01:00
audio->Play(Data, Length, Id);
2002-11-03 11:53:58 +01:00
}
void cAudios::MuteAudio(bool On)
{
for (cAudio *audio = First(); audio; audio = Next(audio))
audio->Mute(On);
}
void cAudios::ClearAudio(void)
{
for (cAudio *audio = First(); audio; audio = Next(audio))
audio->Clear();
}
// --- cExternalAudio --------------------------------------------------------
cExternalAudio::cExternalAudio(const char *Command)
{
command = strdup(Command);
mute = false;
}
cExternalAudio::~cExternalAudio()
{
free(command);
}
2005-02-12 13:01:24 +01:00
void cExternalAudio::Play(const uchar *Data, int Length, uchar Id)
2002-11-03 11:53:58 +01:00
{
if (command && !mute) {
if (pipe || pipe.Open(command, "w")) {
2005-02-12 13:01:24 +01:00
if (0x80 <= Id && Id <= 0x87 || Id == 0xBD) { // AC3
int written = Data[8] + 9; // skips the PES header
if (Id != 0xBD)
written += 4; // skips AC3 bytes
Length -= written;
while (Length > 0) {
int w = fwrite(Data + written, 1, Length, pipe);
if (w < 0) {
LOG_ERROR;
break;
2002-11-03 11:53:58 +01:00
}
2005-02-12 13:01:24 +01:00
Length -= w;
written += w;
}
2002-11-03 11:53:58 +01:00
}
}
else {
esyslog("ERROR: can't open pipe to audio command '%s'", command);
free(command);
command = NULL;
}
}
}
void cExternalAudio::Mute(bool On)
{
mute = On;
if (mute)
Clear();
}
void cExternalAudio::Clear(void)
{
pipe.Close();
}