diff options
-rw-r--r-- | Makefile | 15 | ||||
-rw-r--r-- | dxr3.c | 5 | ||||
-rw-r--r-- | dxr3audio-pa.c | 79 | ||||
-rw-r--r-- | dxr3audio-pa.h | 50 | ||||
-rw-r--r-- | dxr3device.c | 15 | ||||
-rw-r--r-- | settings.c | 4 | ||||
-rw-r--r-- | settings.h | 6 |
7 files changed, 169 insertions, 5 deletions
@@ -24,6 +24,9 @@ VDRDIR = ../../.. LIBDIR = ../../lib TMPDIR = /tmp +# Add support for PulseAudio audio driver? +#PULSEAUDIO = 1 + # Usually something like -I/path/to/ffmpeg, should work as is if FFmpeg was # installed properly and pkg-config is available. FFMPEG_INC = $(shell pkg-config --cflags-only-I libavcodec) @@ -64,13 +67,23 @@ DEFINES += -D_GNU_SOURCE # versions to /usr/share/misc/em8300.uc. DEFINES += -DMICROCODE=\"/lib/firmware/em8300.bin\" +# PulseAudio stuff +ifdef PULSEAUDIO +DEFINES += -DPULSEAUDIO +PA_INC = $(shell pkg-config --cflags-only-I libpulse-simple) +PA_LIBS = $(shell pkg-config --libs libpulse-simple) +INCLUDES += $(PA_INC) +LIBS += $(PA_LIBS) +endif + ### The object files (add further files here): OBJS = $(PLUGIN).o dxr3multichannelaudio.o \ dxr3audiodecoder.o dxr3blackframe.o dxr3audio.o \ dxr3pesframe.o settings.o \ dxr3device.o dxr3osd.o dxr3spudecoder.o \ - dxr3audio-oss.o dxr3audio-alsa.o spuencoder.o spuregion.o scaler.o + dxr3audio-oss.o dxr3audio-alsa.o dxr3audio-pa.o \ + spuencoder.o spuregion.o scaler.o ### Default target: @@ -229,7 +229,10 @@ const char *cPluginDxr3::CommandLineHelp() { return " -f --firmware-loading Enable automatic firmware loading\n" \ " -a DRIVER --audio-driver=DRIVER Select wanted audio driver" \ - " - alsa " \ + " - alsa " +#ifdef PULSEAUDIO + " - pa (PulseAudio)" +#endif " - oss (default)"; } diff --git a/dxr3audio-pa.c b/dxr3audio-pa.c new file mode 100644 index 0000000..fefabae --- /dev/null +++ b/dxr3audio-pa.c @@ -0,0 +1,79 @@ +/* + * + * Copyright (C) 2010 Christian Gmeiner + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef PULSEAUDIO + +#include "dxr3audio-pa.h" + +#include <pulse/error.h> + +void cAudioPA::releaseDevice() +{ + if (s) { + pa_simple_free(s); + s = NULL; + } +} + +void cAudioPA::setup(int channels, int samplerate) +{ + bool reopen = false; + + // set sample rate + if (curContext.samplerate != samplerate) { + dsyslog("[dxr3-audio-pa] changing samplerate to %d (old %d) ", samplerate, curContext.samplerate); + curContext.samplerate = samplerate; + ss.rate = samplerate; + reopen = true; + } + + // set channels + if (curContext.channels != channels) { + dsyslog("[dxr3-audio-pa] changing num of channels to %d (old %d)", channels, curContext.channels); + curContext.channels = channels; + ss.channels = channels; + reopen = true; + } + + if (reopen) { + ss.format = PA_SAMPLE_S16LE; + + if (s) + pa_simple_free(s); + + // create a new playback stream + s = pa_simple_new(NULL, "vdr-plugin-dxr3", PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error); + + if (!s) { + // error handling + } + } +} + +void cAudioPA::write(uchar* data, size_t size) +{ + int ret = pa_simple_write(s, data, size, &error); + + if (ret < 0) { + esyslog("[dxr3-audio-pa] failed to write audio data: %s", pa_strerror(error)); + } +} + +#endif diff --git a/dxr3audio-pa.h b/dxr3audio-pa.h new file mode 100644 index 0000000..350ee13 --- /dev/null +++ b/dxr3audio-pa.h @@ -0,0 +1,50 @@ +/* + * + * Copyright (C) 2010 Christian Gmeiner + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef _AUDIO_PA_H_ +#define _AUDIO_PA_H_ + +#ifdef PULSEAUDIO + +#include "dxr3audio.h" + +#include <pulse/simple.h> + +class cAudioPA : public iAudio { +public: + cAudioPA() : iAudio(), s(NULL) {} + + virtual void openDevice() {} + virtual void releaseDevice(); + virtual void setup(int channels, int samplerate); + virtual void write(uchar* data, size_t size); + + virtual void poll(cPoller &poller) {} + virtual void setDigitalAudio(bool on) {} + +private: + pa_sample_spec ss; + pa_simple *s; + int error; +}; + +#endif + +#endif /*_AUDIO_PA_H_*/ diff --git a/dxr3device.c b/dxr3device.c index 938388a..ef2cc53 100644 --- a/dxr3device.c +++ b/dxr3device.c @@ -27,6 +27,7 @@ #include "dxr3osd.h" #include "dxr3audio-oss.h" #include "dxr3audio-alsa.h" +#include "dxr3audio-pa.h" #include "dxr3pesframe.h" #include "settings.h" @@ -47,12 +48,22 @@ cDxr3Device::cDxr3Device() : spuDecoder(NULL), pluginOn(true), vPts(0), scrSet(f claimDevices(); - if (cSettings::instance()->audioDriver() == OSS) { + switch (cSettings::instance()->audioDriver()) { + case OSS: isyslog("[dxr3-device] using oss audio driver"); audioOut = new cAudioOss(); - } else { + break; + + case ALSA: isyslog("[dxr3-device] using alsa audio driver"); audioOut = new cAudioAlsa(); + break; +#ifdef PULSEAUDIO + case PA: + isyslog("[dxr3-device] using PulseAudio audio driver"); + audioOut = new cAudioPA(); + break; +#endif } audioOut->openDevice(); @@ -49,6 +49,10 @@ bool cSettings::processArgs(int argc, char *argv[]) audioDriver(ALSA); } else if (optarg && strcmp(optarg, "oss") == 0) { audioDriver(OSS); +#ifdef PULSEAUDIO + } else if (optarg && strcmp(optarg, "pa") == 0) { + audioDriver(PA); +#endif } else { esyslog("[dxr3-settings] unkown audio driver - default audio driver will be used"); } @@ -23,6 +23,7 @@ * along with dxr3-plugin. If not, see <http://www.gnu.org/licenses/>. * */ + #ifndef SETTINGS_H #define SETTINGS_H @@ -41,7 +42,10 @@ enum eVideoMode enum AudioDriver { OSS = 0, - ALSA + ALSA, +#ifdef PULSEAUDIO + PA +#endif }; // ================================== |