From 0778ef5b7a60e1d8ed8b3ea2faf913a36a8ed327 Mon Sep 17 00:00:00 2001 From: Lars Bisballe Jensen Date: Sun, 28 Sep 2014 20:37:22 +0200 Subject: Added pulse audio code --- configure.ac | 2 +- src/audiobackend-pulse.cc | 57 ++++++++++++++++++++++++++++++++++------------- src/audiobackend-pulse.h | 11 +++++---- 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/configure.ac b/configure.ac index 685ddd3..9aaa8c8 100644 --- a/configure.ac +++ b/configure.ac @@ -55,7 +55,7 @@ dnl Check for libpulse dnl ====================== AC_ARG_WITH(pulse, [ --with-pulse Build with pulse support]) if test x$with_pulse == xyes; then - PKG_CHECK_MODULES(PULSE, pulse >= 1.0.0) + PKG_CHECK_MODULES(PULSE, libpulse-simple >= 4.0) AC_MSG_WARN([*** Building with libpulse support!]) CXXFLAGS="$CXXFLAGS -DWITH_PULSE" fi diff --git a/src/audiobackend-pulse.cc b/src/audiobackend-pulse.cc index 57d1a5c..63013af 100644 --- a/src/audiobackend-pulse.cc +++ b/src/audiobackend-pulse.cc @@ -25,6 +25,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "audiobackend-pulse.h" +#include "mediaconfig.h" + +#include +#include #ifdef WITH_PULSE @@ -40,34 +44,57 @@ http://freedesktop.org/software/pulseaudio/doxygen/parec-simple_8c-example.html AudioBackendPulse::AudioBackendPulse(const char *device) { - // Initialise pulse here - - //s = pa_simple_new(...); + // Initialize PulseAudio + pa_sample_spec ss; + ss.format = PA_SAMPLE_S16NE; + ss.channels = 1; + ss.rate = SAMPLERATE; + + sIn = pa_simple_new(NULL, // Use the default server. + "SimpleRTP", // Our application's name. + PA_STREAM_RECORD, + NULL, // Use the default device. + "SimpleRTP", // Description of our stream. + &ss, // Our sample format. + NULL, // Use default channel map + NULL, // Use default buffering attributes. + NULL // Ignore error code. + ); + + sOut = pa_simple_new(NULL, // Use the default server. + "SimpleRTP", // Our application's name. + PA_STREAM_PLAYBACK, + NULL, // Use the default device. + "SimpleRTP", // Description of our stream. + &ss, // Our sample format. + NULL, // Use default channel map + NULL, // Use default buffering attributes. + NULL // Ignore error code. + ); } AudioBackendPulse::~AudioBackendPulse() { - // Shut down pulse here - - //pa_simple_free(s); + // Freeeeedoooooom! Set the PulseAudio instance free again, we're done + pa_simple_free(sIn); + pa_simple_free(sOut); } int AudioBackendPulse::read(char *pcm, size_t maxsize) { // read maximum 'maxsize' bytes into pcm and return number of bytes read. - - //pa_simple_read(...) - - return 0; + return pa_simple_read(sIn, + pcm, + maxsize, + NULL); } int AudioBackendPulse::write(const char *pcm, size_t size) { - // write pcm to pulse - - //pa_simple_write(...) - - return 0; + return pa_simple_write(sOut, + pcm, + size, + NULL); } #endif/*WITH_PULSE*/ diff --git a/src/audiobackend-pulse.h b/src/audiobackend-pulse.h index 7dc2be8..4c696ae 100644 --- a/src/audiobackend-pulse.h +++ b/src/audiobackend-pulse.h @@ -24,11 +24,13 @@ * along with SimpleRTP; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#ifndef __SIMPLERTP_AUDIOBACKEND-PULSE_H__ -#define __SIMPLERTP_AUDIOBACKEND-PULSE_H__ +#ifndef __SIMPLERTP_AUDIOBACKEND_PULSE_H__ +#define __SIMPLERTP_AUDIOBACKEND_PULSE_H__ #ifdef WITH_PULSE +#include "audiobackend.h" + #include class AudioBackendPulse : public AudioBackend { @@ -40,9 +42,10 @@ public: int write(const char *pcm, size_t size); private: - pa_simple *s; + pa_simple *sIn; + pa_simple *sOut; }; #endif/*WITH_PULSE*/ -#endif/*__SIMPLERTP_AUDIOBACKEND-PULSE_H__*/ +#endif/*__SIMPLERTP_AUDIOBACKEND_PULSE_H__*/ -- cgit v1.2.3