diff --git a/sflphone-common/src/audio/alsa/alsalayer.cpp b/sflphone-common/src/audio/alsa/alsalayer.cpp index 0aa39b9b0acb026bdbe2cfc578faf58b312c1f67..ddd1303f39487f4008a2341c7e5cee6f5a24c446 100644 --- a/sflphone-common/src/audio/alsa/alsalayer.cpp +++ b/sflphone-common/src/audio/alsa/alsalayer.cpp @@ -713,6 +713,8 @@ AlsaLayer::handle_xrun_playback (void) if (state == SND_PCM_STATE_XRUN) { stopPlaybackStream (); preparePlaybackStream (); + + _trigger_request = true; } } @@ -958,8 +960,12 @@ void AlsaLayer::audioCallback (void) if((tone == 0) && (file_tone == 0)) { - bzero (out, maxNbBytesToGet); - write (out, maxNbBytesToGet); + SFLDataFormat* zeros = (SFLDataFormat*)malloc (framesPerBufferAlsa * sizeof (SFLDataFormat)); + + bzero (zeros, framesPerBufferAlsa * sizeof (SFLDataFormat)); + write (zeros, framesPerBufferAlsa * sizeof (SFLDataFormat)); + + free (zeros); } } diff --git a/sflphone-common/src/audio/pulseaudio/audiostream.cpp b/sflphone-common/src/audio/pulseaudio/audiostream.cpp index 21cb6aa5cce900684d7db52891e07521412604fc..362e7189bcf2b5c04b800af03178428c481fa2b8 100644 --- a/sflphone-common/src/audio/pulseaudio/audiostream.cpp +++ b/sflphone-common/src/audio/pulseaudio/audiostream.cpp @@ -184,11 +184,11 @@ AudioStream::createStream (pa_context* c) // parameters are defined as number of bytes // 2048 bytes (1024 int16) is 20 ms at 44100 Hz if (_streamType == PLAYBACK_STREAM) { - attributes->maxlength = 32000; - attributes->tlength = 16000; - attributes->prebuf = 1024; - attributes->minreq = 512; - attributes->fragsize = (uint32_t) -1; + attributes->maxlength = 16000; + attributes->tlength = 8192; + attributes->prebuf = 2048; // Pulseaudio will not start if prebuffering is not reached + attributes->minreq = 512; // The server side playback framesize + attributes->fragsize = 1024; // Fragment size at wich we receive an interupt 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) { @@ -197,13 +197,14 @@ AudioStream::createStream (pa_context* c) // attributes->fragsize = (uint32_t)-1; attributes->maxlength = 32000; - attributes->tlength = 16000; - attributes->prebuf = 1024; - attributes->minreq = 512; - attributes->fragsize = (uint32_t) -1; + attributes->tlength = (uint32_t)-1; + attributes->prebuf = (uint32_t)-1; + attributes->minreq = (uint32_t)-1; + attributes->fragsize = (uint32_t)-1; // 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_INTERPOLATE_TIMING ); + pa_stream_connect_record( s, NULL, NULL, 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 f727c1a3d7dfb04d6a4974b9a7d2b36b60cc2780..1c7db92d307fb445c3c83e7be84757ace3b8601f 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp @@ -57,7 +57,14 @@ static void stream_moved_callback(pa_stream *s UNUSED, void *userdata UNUSED) static void playback_underflow_callback (pa_stream* s, void* userdata UNUSED) { _debug ("PulseLayer::Buffer Underflow\n"); + // const pa_timing_info* info = pa_stream_get_timing_info(s); + // _debug(" pa write_index: %l\n", (long)(info->write_index)); + // _debug(" pa write_index_corupt (if not 0): %i\n", info->write_index_corrupt); + // _debug(" pa read_index: %l\n", (long)(info->read_index)); + // _debug(" pa read_index_corrupt (if not 0): %i\n", info->read_index_corrupt); + + // fill in audio buffer twice the prebuffering value to restart playback SFLDataFormat* out = (SFLDataFormat*) pa_xmalloc (framesPerBuffer*sizeof(SFLDataFormat)); bzero (out, framesPerBuffer*sizeof(SFLDataFormat)); @@ -347,12 +354,12 @@ void PulseLayer::startStream (void) assert (context); } - _urgentRingBuffer.flush(); - _mainBuffer.flushAllBuffers(); - // Create Streams connectPulseAudioServer(); + _urgentRingBuffer.flushAll(); + _mainBuffer.flushAllBuffers(); + is_started = true; } @@ -402,18 +409,19 @@ PulseLayer::stopStream (void) -void PulseLayer::underflow (pa_stream* s UNUSED, void* userdata UNUSED) -{ - _debug ("PulseLayer::Buffer Underflow\n"); -} - +// void PulseLayer::underflow (pa_stream* s UNUSED, void* userdata UNUSED) +//{ +// _debug ("PulseLayer::Buffer Underflow\n"); +//} +/* void PulseLayer::overflow (pa_stream* s, void* userdata UNUSED) { //PulseLayer* pulse = (PulseLayer*) userdata; pa_stream_drop (s); pa_stream_trigger (s, NULL, NULL); } +*/ void PulseLayer::processPlaybackData (void) @@ -452,12 +460,21 @@ void PulseLayer::writeToSpeaker (void) int toGet; int toPlay; + // const pa_timing_info* info = pa_stream_get_timing_info(s); + + // _debug(" pa write_index: %i", info->write_index); + // _debug(" pa write_index_corupt (if not 0): %i" info->write_index_corrupt); + // _debug(" pa read_index: %i", info->read_index); + // _debug(" pa read_index_corrupt (if not 0): %i", info->read_index_corrupt); + SFLDataFormat* out;// = (SFLDataFormat*)pa_xmalloc(framesPerBuffer); urgentAvailBytes = _urgentRingBuffer.AvailForGet(); + if (urgentAvailBytes > 0) { - + // _debug("urgentAvailBytes: %i\n", urgentAvailBytes); + toGet = (urgentAvailBytes < (int) (framesPerBuffer * sizeof (SFLDataFormat))) ? urgentAvailBytes : framesPerBuffer * sizeof (SFLDataFormat); out = (SFLDataFormat*) pa_xmalloc (toGet * sizeof (SFLDataFormat)); _urgentRingBuffer.Get (out, toGet, 100); @@ -487,7 +504,7 @@ void PulseLayer::writeToSpeaker (void) } } - if (file_tone != 0) { + else if (file_tone != 0) { if (playback->getStreamState() == PA_STREAM_READY) { @@ -556,11 +573,17 @@ void PulseLayer::writeToSpeaker (void) if((tone == 0) && (file_tone == 0)) { // _debug("maxNbBytesToGet: %i\n", maxNbBytesToGet); - bzero (out, maxNbBytesToGet); - pa_stream_write (playback->pulseStream(), out, maxNbBytesToGet, NULL, 0, PA_SEEK_RELATIVE); + SFLDataFormat* zeros = (SFLDataFormat*)pa_xmalloc (framesPerBuffer*sizeof(SFLDataFormat)); + + bzero (zeros, framesPerBuffer*sizeof(SFLDataFormat)); + pa_stream_write(playback->pulseStream(), zeros, framesPerBuffer*sizeof(SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE); + + pa_xfree (zeros); + } } + _urgentRingBuffer.Discard(toGet); pa_xfree (out); diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index 5491f2fe9d44ecc3c7ad645ba6bda9daf1dc3a07..95293f6dc513ffe7c6e12ad5013ffbcb364a5f7c 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -1701,7 +1701,7 @@ ManagerImpl::playDtmf (char code, bool isTalking) // Put buffer to urgentRingBuffer // put the size in bytes... // so size * 1 channel (mono) * sizeof (bytes for the data) - audiolayer->flushUrgent(); + // audiolayer->flushUrgent(); audiolayer->startStream(); audiolayer->putUrgent (buf, size * sizeof (SFLDataFormat));