diff --git a/sflphone-common/src/audio/pulseaudio/audiostream.cpp b/sflphone-common/src/audio/pulseaudio/audiostream.cpp index ffdb6e4514aa99d5713b7723af45c8ebc827fa00..bd138140250c679b6b407913f5fec3308e35905c 100644 --- a/sflphone-common/src/audio/pulseaudio/audiostream.cpp +++ b/sflphone-common/src/audio/pulseaudio/audiostream.cpp @@ -188,8 +188,8 @@ AudioStream::createStream (pa_context* c) attributes->prebuf = 4096; attributes->minreq = 940; attributes->fragsize = 4096; - // pa_stream_connect_playback( s , NULL , attributes, PA_STREAM_INTERPOLATE_TIMING, &_volume, NULL); - pa_stream_connect_playback (s , NULL , attributes, PA_STREAM_START_CORKED, &_volume, NULL); + pa_stream_connect_playback( s , NULL , attributes, PA_STREAM_INTERPOLATE_TIMING, &_volume, NULL); + // pa_stream_connect_playback (s , NULL , attributes, PA_STREAM_START_CORKED, &_volume, NULL); } else if (_streamType == CAPTURE_STREAM) { // attributes->maxlength = 66500; @@ -201,8 +201,8 @@ AudioStream::createStream (pa_context* c) attributes->minreq = 940; attributes->fragsize = 4096; - pa_stream_connect_record (s , NULL , attributes , PA_STREAM_START_CORKED); - // pa_stream_connect_record( s , NULL , attributes , PA_STREAM_INTERPOLATE_TIMING ); + // pa_stream_connect_record (s , NULL , attributes , PA_STREAM_START_CORKED); + pa_stream_connect_record( s , NULL , attributes , PA_STREAM_INTERPOLATE_TIMING ); } else if (_streamType == UPLOAD_STREAM) { pa_stream_connect_upload (s , 1024); } else { diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp index e8ae5f0521954c7c8859508507f8d36e3f29dc13..88569e918d2b9cf74f1892cda9dc3fcdfa8405d4 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2008 Savoir-Faire Linux inc. + * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify @@ -30,6 +31,33 @@ static void audioCallback (pa_stream* s, size_t bytes, void* userdata) } +static void stream_suspended_callback (pa_stream *s UNUSED, void *userdata UNUSED) +{ + _debug("PulseLayer::Stream Suspended\n"); +} + + +static void stream_moved_callback(pa_stream *s UNUSED, void *userdata UNUSED) +{ + _debug("PulseLayer::Stream Moved\n"); +} + + +static void playback_underflow_callback (pa_stream* s, void* userdata UNUSED) +{ + _debug ("PulseLayer::Buffer Underflow\n"); + pa_stream_trigger (s, NULL, NULL); +} + + +static void playback_overflow_callback (pa_stream* s UNUSED, void* userdata UNUSED) +{ + _debug("PulseLayer::Buffer OverFlow\n"); + //PulseLayer* pulse = (PulseLayer*) userdata; + // pa_stream_drop (s); + // pa_stream_trigger (s, NULL, NULL); +} + PulseLayer::PulseLayer (ManagerImpl* manager) : AudioLayer (manager , PULSEAUDIO) @@ -42,6 +70,7 @@ PulseLayer::PulseLayer (ManagerImpl* manager) _urgentRingBuffer.createReadPointer(); dcblocker = new DcBlocker(); + is_started = false; } // Destructor @@ -190,7 +219,11 @@ bool PulseLayer::createStreams (pa_context* c) playback = new AudioStream (playbackParam); playback->connectStream(); - 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(), playback_overflow_callback, this); + pa_stream_set_underflow_callback(playback->pulseStream(), playback_underflow_callback, this); + pa_stream_set_suspended_callback(playback->pulseStream(), stream_suspended_callback, this); + pa_stream_set_moved_callback(playback->pulseStream(), stream_moved_callback, this); delete playbackParam; PulseLayerType * recordParam = new PulseLayerType(); @@ -203,11 +236,12 @@ bool PulseLayer::createStreams (pa_context* c) record = new AudioStream (recordParam); record->connectStream(); pa_stream_set_read_callback (record->pulseStream() , audioCallback, this); + pa_stream_set_suspended_callback(record->pulseStream(), stream_suspended_callback, this); + pa_stream_set_moved_callback(record->pulseStream(), stream_moved_callback, this); delete recordParam; pa_threaded_mainloop_signal (m , 0); - isCorked = true; return true; } @@ -270,20 +304,25 @@ int PulseLayer::getMic (void *buffer, int toCopy) void PulseLayer::startStream (void) { - _debug ("PulseLayer::Start stream\n"); + - _urgentRingBuffer.flush(); + if(!is_started) { - _mainBuffer.flush(); + _debug ("------------------------ PulseLayer::Start stream ---------------\n"); - pa_threaded_mainloop_lock (m); + _urgentRingBuffer.flush(); - pa_stream_cork (playback->pulseStream(), 0, NULL, NULL); - pa_stream_cork (record->pulseStream(), 0, NULL, NULL); + _mainBuffer.flushAllBuffers(); - pa_threaded_mainloop_unlock (m); + // pa_threaded_mainloop_lock (m); + + // pa_stream_cork (playback->pulseStream(), 0, NULL, NULL); + // pa_stream_cork (record->pulseStream(), 0, NULL, NULL); - isCorked = false; + // pa_threaded_mainloop_unlock (m); + + is_started = true; + } } @@ -291,22 +330,26 @@ void PulseLayer::stopStream (void) { - _debug ("PulseLayer::Stop stream\n"); - pa_stream_flush (playback->pulseStream(), NULL, NULL); - pa_stream_flush (record->pulseStream(), NULL, NULL); + if(is_started) { - flushMic(); - flushMain(); - flushUrgent(); + _debug ("------------------------ PulseLayer::Stop stream ---------------\n"); + pa_stream_flush (playback->pulseStream(), NULL, NULL); + pa_stream_flush (record->pulseStream(), NULL, NULL); - pa_threaded_mainloop_lock (m); + flushMic(); + flushMain(); + flushUrgent(); - pa_stream_cork (playback->pulseStream(), 1, NULL, NULL); - pa_stream_cork (record->pulseStream(), 1, NULL, NULL); + // pa_threaded_mainloop_lock (m); + + // pa_stream_cork (playback->pulseStream(), 1, NULL, NULL); + // pa_stream_cork (record->pulseStream(), 1, NULL, NULL); - pa_threaded_mainloop_unlock (m); + // pa_threaded_mainloop_unlock (m); + + is_started = false; - isCorked = true; + } } diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.h b/sflphone-common/src/audio/pulseaudio/pulselayer.h index efe0e7f3fd5527e1a6881c2b1b93fe0a0c99fbf1..cdd3096b8c4a837822a74ac584192c846fdb08c9 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.h +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.h @@ -194,7 +194,7 @@ class PulseLayer : public AudioLayer { /** Sample rate converter object */ SamplerateConverter * _converter; - bool isCorked; + bool is_started; int spkrVolume; int micVolume;