Skip to content
Snippets Groups Projects
Commit ac9bc3e8 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

Added pa_stream_cork to resume/stop PulseAudio callbac

parent 4cc4c405
No related branches found
No related tags found
No related merge requests found
...@@ -53,7 +53,7 @@ AudioStream::disconnect( void ) ...@@ -53,7 +53,7 @@ AudioStream::disconnect( void )
void void
AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED ) AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED )
{ {
_debug("The state of the stream changed\n"); _debug("AudioStream::stream_state_callback :: The state of the stream changed\n");
assert(s); assert(s);
switch(pa_stream_get_state(s)){ switch(pa_stream_get_state(s)){
case PA_STREAM_CREATING: case PA_STREAM_CREATING:
...@@ -64,6 +64,7 @@ AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED ) ...@@ -64,6 +64,7 @@ AudioStream::stream_state_callback( pa_stream* s, void* user_data UNUSED )
PulseLayer::streamState++; PulseLayer::streamState++;
break; break;
case PA_STREAM_READY: case PA_STREAM_READY:
_debug("Stream successfully created, connected to %s\n", pa_stream_get_device_name( s )); _debug("Stream successfully created, connected to %s\n", pa_stream_get_device_name( s ));
break; break;
case PA_STREAM_UNCONNECTED: case PA_STREAM_UNCONNECTED:
......
...@@ -38,7 +38,7 @@ static void audioCallback ( pa_stream* s, size_t bytes, void* userdata ) ...@@ -38,7 +38,7 @@ static void audioCallback ( pa_stream* s, size_t bytes, void* userdata )
, record() , record()
{ {
PulseLayer::streamState = 0; PulseLayer::streamState = 0;
_debug("Pulse audio constructor: Create context\n"); _debug("PulseLayer::Pulse audio constructor: Create context\n");
} }
// Destructor // Destructor
...@@ -53,7 +53,7 @@ PulseLayer::~PulseLayer (void) ...@@ -53,7 +53,7 @@ PulseLayer::~PulseLayer (void)
void void
PulseLayer::closeLayer( void ) PulseLayer::closeLayer( void )
{ {
_debug(" Destroy pulselayer\n"); _debug("PulseLayer::closeLayer :: Destroy pulselayer\n");
playback->disconnect(); playback->disconnect();
record->disconnect(); record->disconnect();
...@@ -69,6 +69,7 @@ PulseLayer::closeLayer( void ) ...@@ -69,6 +69,7 @@ PulseLayer::closeLayer( void )
void void
PulseLayer::connectPulseAudioServer( void ) PulseLayer::connectPulseAudioServer( void )
{ {
_debug("PulseLayer::connectPulseAudioServer \n");
pa_context_flags_t flag = PA_CONTEXT_NOAUTOSPAWN ; pa_context_flags_t flag = PA_CONTEXT_NOAUTOSPAWN ;
pa_threaded_mainloop_lock( m ); pa_threaded_mainloop_lock( m );
...@@ -94,7 +95,7 @@ PulseLayer::connectPulseAudioServer( void ) ...@@ -94,7 +95,7 @@ PulseLayer::connectPulseAudioServer( void )
void PulseLayer::context_state_callback( pa_context* c, void* user_data ) void PulseLayer::context_state_callback( pa_context* c, void* user_data )
{ {
_debug("The state of the context changed\n"); _debug("PulseLayer::context_state_callback ::The state of the context changed\n");
PulseLayer* pulse = (PulseLayer*)user_data; PulseLayer* pulse = (PulseLayer*)user_data;
assert(c && pulse->m); assert(c && pulse->m);
switch(pa_context_get_state(c)){ switch(pa_context_get_state(c)){
...@@ -121,6 +122,7 @@ void PulseLayer::context_state_callback( pa_context* c, void* user_data ) ...@@ -121,6 +122,7 @@ void PulseLayer::context_state_callback( pa_context* c, void* user_data )
void PulseLayer::disconnectPulseAudioServer( void ) void PulseLayer::disconnectPulseAudioServer( void )
{ {
_debug(" PulseLayer::disconnectPulseAudioServer( void ) \n");
if( playback ) if( playback )
delete playback; playback=NULL; delete playback; playback=NULL;
...@@ -131,6 +133,7 @@ void PulseLayer::disconnectPulseAudioServer( void ) ...@@ -131,6 +133,7 @@ void PulseLayer::disconnectPulseAudioServer( void )
void void
PulseLayer::createStreams( pa_context* c ) PulseLayer::createStreams( pa_context* c )
{ {
_debug("PulseLayer::createStreams \n");
playback = new AudioStream(c, PLAYBACK_STREAM, PLAYBACK_STREAM_NAME, _manager->getSpkrVolume()); playback = new AudioStream(c, PLAYBACK_STREAM, PLAYBACK_STREAM_NAME, _manager->getSpkrVolume());
pa_stream_set_write_callback( playback->pulseStream() , audioCallback, this); pa_stream_set_write_callback( playback->pulseStream() , audioCallback, this);
//pa_stream_set_overflow_callback( playback->pulseStream() , overflow , this); //pa_stream_set_overflow_callback( playback->pulseStream() , overflow , this);
...@@ -144,6 +147,7 @@ PulseLayer::createStreams( pa_context* c ) ...@@ -144,6 +147,7 @@ PulseLayer::createStreams( pa_context* c )
bool bool
PulseLayer::openDevice(int indexIn UNUSED, int indexOut UNUSED, int sampleRate, int frameSize , int stream UNUSED, std::string plugin UNUSED) PulseLayer::openDevice(int indexIn UNUSED, int indexOut UNUSED, int sampleRate, int frameSize , int stream UNUSED, std::string plugin UNUSED)
{ {
_debug("PulseLayer::openDevice \n");
_sampleRate = sampleRate; _sampleRate = sampleRate;
_frameSize = frameSize; _frameSize = frameSize;
...@@ -199,9 +203,12 @@ PulseLayer::getMic(void *buffer, int toCopy) ...@@ -199,9 +203,12 @@ PulseLayer::getMic(void *buffer, int toCopy)
PulseLayer::startStream (void) PulseLayer::startStream (void)
{ {
flushMic(); flushMic();
_debug("Start stream\n"); _debug("PulseLayer::Start stream\n");
pa_threaded_mainloop_lock(m); pa_threaded_mainloop_lock(m);
pa_stream_cork( playback->pulseStream(), NULL, NULL, NULL);
pa_stream_cork( record->pulseStream(), NULL, NULL, NULL); pa_stream_cork( record->pulseStream(), NULL, NULL, NULL);
pa_threaded_mainloop_unlock(m); pa_threaded_mainloop_unlock(m);
} }
...@@ -209,9 +216,13 @@ PulseLayer::startStream (void) ...@@ -209,9 +216,13 @@ PulseLayer::startStream (void)
void void
PulseLayer::stopStream (void) PulseLayer::stopStream (void)
{ {
_debug("Stop stream\n"); _debug("PulseLayer::Stop stream\n");
pa_stream_flush( playback->pulseStream(), NULL, NULL ); pa_stream_flush( playback->pulseStream(), NULL, NULL );
pa_stream_flush( record->pulseStream(), NULL, NULL ); pa_stream_flush( record->pulseStream(), NULL, NULL );
pa_stream_cork( playback->pulseStream(), NULL, NULL, NULL);
pa_stream_cork( record->pulseStream(), NULL, NULL, NULL);
flushMic(); flushMic();
flushMain(); flushMain();
flushUrgent(); flushUrgent();
...@@ -222,7 +233,7 @@ PulseLayer::stopStream (void) ...@@ -222,7 +233,7 @@ PulseLayer::stopStream (void)
void void
PulseLayer::underflow ( pa_stream* s UNUSED, void* userdata UNUSED ) PulseLayer::underflow ( pa_stream* s UNUSED, void* userdata UNUSED )
{ {
_debug("Buffer Underflow\n"); _debug("PulseLayer::Buffer Underflow\n");
} }
...@@ -239,17 +250,18 @@ PulseLayer::processData( void ) ...@@ -239,17 +250,18 @@ PulseLayer::processData( void )
{ {
// Handle the mic // Handle the mic
// We check if the stream is ready // We check if the stream is ready
if( (record->pulseStream()) && pa_stream_get_state( record->pulseStream()) == PA_STREAM_READY) if( (record->pulseStream()) && (pa_stream_get_state( record->pulseStream()) == PA_STREAM_READY) && record)
// _debug("PulseLayer::processData() readFromMic() \n");
readFromMic(); readFromMic();
// Handle the data for the speakers // Handle the data for the speakers
if( (playback->pulseStream()) && pa_stream_get_state( playback->pulseStream()) == PA_STREAM_READY){ if( (playback->pulseStream()) && (pa_stream_get_state( playback->pulseStream()) == PA_STREAM_READY) && playback){
// If the playback buffer is full, we don't overflow it; wait for it to have free space // If the playback buffer is full, we don't overflow it; wait for it to have free space
if( pa_stream_writable_size(playback->pulseStream()) == 0 ) if( pa_stream_writable_size(playback->pulseStream()) == 0 )
return; return;
_debug("PulseLayer::processData() \n"); // _debug("PulseLayer::processData() writeToSpeaker()\n");
writeToSpeaker(); writeToSpeaker();
} }
} }
...@@ -257,7 +269,6 @@ PulseLayer::processData( void ) ...@@ -257,7 +269,6 @@ PulseLayer::processData( void )
void void
PulseLayer::writeToSpeaker( void ) PulseLayer::writeToSpeaker( void )
{ {
_debug("PulseLayer::writeToSpeaker() \n");
/** Bytes available in the urgent ringbuffer ( reserved for DTMF ) */ /** Bytes available in the urgent ringbuffer ( reserved for DTMF ) */
int urgentAvail; int urgentAvail;
/** Bytes available in the regular ringbuffer ( reserved for voice ) */ /** Bytes available in the regular ringbuffer ( reserved for voice ) */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment