From 0b1a19c17abd0af5adf06b46e25c8bf10a3d81a5 Mon Sep 17 00:00:00 2001 From: Lars Bisballe Jensen Date: Sun, 28 Sep 2014 23:42:31 +0200 Subject: Audio is going through now, but it stutters... a lot! --- src/audiobackend-pulse.cc | 72 ++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/src/audiobackend-pulse.cc b/src/audiobackend-pulse.cc index 2eadedf..5e3136e 100644 --- a/src/audiobackend-pulse.cc +++ b/src/audiobackend-pulse.cc @@ -41,65 +41,59 @@ Output example: http://freedesktop.org/software/pulseaudio/doxygen/parec-simple_8c-example.html */ -#include "mediaconfig.h" - AudioBackendPulse::AudioBackendPulse(const char *device) { // Initialize PulseAudio - pa_sample_spec ss; - ss.format = PA_SAMPLE_S16NE; - ss.channels = 1; - ss.rate = SAMPLERATE; + static const pa_sample_spec ss = { + .format = PA_SAMPLE_S16LE, + .rate = SAMPLERATE, + .channels = 1 + }; int error; - sIn = pa_simple_new(NULL, // Use the default server. - "SimpleRTP", // Our application's name. - PA_STREAM_RECORD, - NULL, // Use the default device. - "SimpleRTPin", // Description of our stream. - &ss, // Our sample format. - NULL, // Use default channel map - NULL, // Use default buffering attributes. - &error // Ignore error code. - ); - printf("Pulse in: %s\n", pa_strerror(error)); - - sOut = pa_simple_new(NULL, // Use the default server. - "SimpleRTP", // Our application's name. - PA_STREAM_PLAYBACK, - NULL, // Use the default device. - "SimpleRTPout", // Description of our stream. - &ss, // Our sample format. - NULL, // Use default channel map - NULL, // Use default buffering attributes. - &error // Ignore error code. - ); - printf("Pulse out: %s\n", pa_strerror(error)); + if (!(sIn = pa_simple_new(NULL, "Anything", PA_STREAM_RECORD, NULL, "record", &ss, NULL, NULL, &error))) { + fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); + } + if (!(sOut = pa_simple_new(NULL, "Anything", PA_STREAM_PLAYBACK, NULL, "playback", &ss, NULL, NULL, &error))) { + fprintf(stderr, __FILE__": pa_simple_new() failed: %s\n", pa_strerror(error)); + } } AudioBackendPulse::~AudioBackendPulse() { - // Freeeeedoooooom! Set the PulseAudio instance free again, we're done + // Freeeeedoooooom! Set the PulseAudio instances 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. - return pa_simple_read(sIn, - pcm, - maxsize, - NULL); + int error; + + if (pa_simple_read(sIn, pcm, maxsize, &error) < 0) { + fprintf(stderr, __FILE__": pa_simple_read() failed: %s\n", + pa_strerror(error)); + } + return maxsize; } int AudioBackendPulse::write(const char *pcm, size_t size) { - return pa_simple_write(sOut, - pcm, - size, - NULL); + int error; + + if (pa_simple_write(sOut, pcm, size, &error) < 0) { + fprintf(stderr, __FILE__": pa_simple_write() failed: %s\n", + pa_strerror(error)); + } + /* + if(pa_simple_drain(sOut, &error) < 0) { + fprintf(stderr, __FILE__": pa_simple_drain() failed: %s\n", + pa_strerror(error)); + } + */ + + return 0; } #endif/*WITH_PULSE*/ -- cgit v1.2.3