diff --git a/sflphone-common/src/audio/alsa/alsalayer.cpp b/sflphone-common/src/audio/alsa/alsalayer.cpp index a8984237a5b6d503e0678a0989de27bd05ada715..b7f95cb122af7084dacb46057188ec32fc135be3 100644 --- a/sflphone-common/src/audio/alsa/alsalayer.cpp +++ b/sflphone-common/src/audio/alsa/alsalayer.cpp @@ -136,10 +136,15 @@ AlsaLayer::openDevice (int indexIn, int indexOut, int sampleRate, int frameSize, void AlsaLayer::startStream (void) { - _debug ("Start ALSA streams\n"); + _debug ("AlsaLayer:: startStream\n"); prepareCaptureStream (); + _debug("------------------------------\n"); + preparePlaybackStream (); + _debug("------------------------------\n"); startCaptureStream (); + _debug("------------------------------\n"); startPlaybackStream (); + _debug("------------------------------\n"); _urgentRingBuffer.flush(); _mainBuffer.flush(); @@ -150,9 +155,9 @@ AlsaLayer::startStream (void) void AlsaLayer::stopStream (void) { - _debug ("AlsaLayer::stopStream :: Stop ALSA streams\n"); + _debug ("AlsaLayer:: stopStream\n"); stopCaptureStream (); - //stopPlaybackStream (); + stopPlaybackStream (); /* Flush the ring buffers */ flushUrgent (); @@ -227,40 +232,53 @@ void AlsaLayer::stopCaptureStream (void) int err; if (_CaptureHandle) { - err = snd_pcm_drop (_CaptureHandle); - - stop_capture (); + _debug("AlsaLayer:: stop Alsa capture\n"); + if((err = snd_pcm_drop (_CaptureHandle)) < 0) + _debug("AlsaLayer:: Error stopping ALSA capture: %s\n", snd_strerror(err)); + else + stop_capture (); } } void AlsaLayer::closeCaptureStream (void) { - _debug("Close Capture Stream\n"); + int err; + + _debug("AlsaLayer:: close ALSA capture\n"); if (is_capture_prepared() == true && is_capture_running() == true) stopCaptureStream (); - if (is_capture_open()) - snd_pcm_close (_CaptureHandle); - - close_capture (); + if (is_capture_open()) { + if ((err = snd_pcm_close (_CaptureHandle)) < 0) + _debug("Error closing ALSA capture: %s\n", snd_strerror(err)); + else + close_capture (); + } } void AlsaLayer::startCaptureStream (void) { - if (_CaptureHandle) { - _debug ("Start the capture\n"); - snd_pcm_start (_CaptureHandle); - start_capture(); + int err; + + if (_CaptureHandle && !is_capture_running()) { + _debug ("AlsaLayer:: start ALSA capture\n"); + if((err = snd_pcm_start (_CaptureHandle)) < 0) + _debug("Error starting ALSA capture: %s\n", snd_strerror(err)); + else + start_capture(); } } void AlsaLayer::prepareCaptureStream (void) { - if (is_capture_open()) { - if (snd_pcm_prepare (_CaptureHandle) < 0) - _debug (""); + int err; + + if (is_capture_open() && !is_capture_prepared()) { + _debug("AlsaLayer:: prepare ALSA capture\n"); + if ((err = snd_pcm_prepare (_CaptureHandle)) < 0) + _debug ("Error preparing ALSA capture: %s\n", snd_strerror(err)); else prepare_capture (); } @@ -268,38 +286,56 @@ void AlsaLayer::prepareCaptureStream (void) void AlsaLayer::stopPlaybackStream (void) { - if (_PlaybackHandle) { - snd_pcm_drop (_PlaybackHandle); - stop_playback (); + int err; + + if (_PlaybackHandle && is_playback_running()) { + _debug("AlsaLayer:: stop ALSA playback\n"); + if((err = snd_pcm_drop (_PlaybackHandle)) < 0) + _debug("Error stopping ALSA playback: %s\n", snd_strerror(err)); + else + stop_playback (); } } void AlsaLayer::closePlaybackStream (void) { + int err; + if (is_playback_prepared() == true && is_playback_running() == true) stopPlaybackStream (); - if (is_playback_open()) - snd_pcm_close (_PlaybackHandle); - - close_playback (); + if (is_playback_open()) { + if ((err = snd_pcm_close (_PlaybackHandle)) < 0) + _debug("Error closing ALSA playback: %s\n", snd_strerror(err)); + else + close_playback (); + } } void AlsaLayer::startPlaybackStream (void) { - if (_PlaybackHandle) { - snd_pcm_start (_PlaybackHandle); - start_playback(); + int err; + + if (_PlaybackHandle && !is_playback_running()) { + _debug ("AlsaLayer:: start ALSA playback\n"); + if ((err = snd_pcm_start (_PlaybackHandle)) < 0) + _debug("Error starting ALSA playback: %s\n", snd_strerror(err)); + else + start_playback(); } } void AlsaLayer::preparePlaybackStream (void) { - if (is_playback_open()) { - if (snd_pcm_prepare (_PlaybackHandle) < 0) _debug ("Error preparing the device\n"); + int err; - prepare_playback (); + if (is_playback_open() && !is_playback_prepared()) { + _debug("AlsaLayer:: prepare playback stream\n"); + if ((err = snd_pcm_prepare (_PlaybackHandle)) < 0) + _debug ("Error preparing the device: %s\n", snd_strerror(err)); + else + prepare_playback (); } } diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp index ab2812425e6988692854d80c44d080237e8cd23c..c1712d6409bb1d1fc7e81d00d446078c9a5765bb 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp @@ -25,7 +25,7 @@ int framesPerBuffer = 2048; static void playback_callback (pa_stream* s, size_t bytes, void* userdata) { - _debug("playback_callback\n"); + // _debug("playback_callback\n"); assert (s && bytes); assert (bytes > 0); @@ -448,7 +448,6 @@ void PulseLayer::writeToSpeaker (void) if (urgentAvailBytes > 0) { - _debug("Urgent Avail?????????????????????\n"); toGet = (urgentAvailBytes < (int) (framesPerBuffer * sizeof (SFLDataFormat))) ? urgentAvailBytes : framesPerBuffer * sizeof (SFLDataFormat); out = (SFLDataFormat*) pa_xmalloc (toGet * sizeof (SFLDataFormat)); @@ -469,7 +468,6 @@ void PulseLayer::writeToSpeaker (void) if (playback->getStreamState() == PA_STREAM_READY) { - _debug("Play Tone!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); toGet = framesPerBuffer; out = (SFLDataFormat*) pa_xmalloc (toGet * sizeof (SFLDataFormat)); @@ -485,8 +483,6 @@ void PulseLayer::writeToSpeaker (void) if (playback->getStreamState() == PA_STREAM_READY) { - _debug("Play File Tone!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n"); - toGet = framesPerBuffer; toPlay = ( (int) (toGet * sizeof (SFLDataFormat)) > framesPerBuffer) ? framesPerBuffer : toGet * sizeof (SFLDataFormat); _debug("toPlay: %i\n", toPlay); @@ -494,11 +490,7 @@ void PulseLayer::writeToSpeaker (void) file_tone->getNext (out, toPlay/2 , 100); pa_stream_write (playback->pulseStream(), out, toPlay, NULL, 0, PA_SEEK_RELATIVE); - _debug("ok\n"); - pa_xfree (out); - - _debug("end of play file\n"); } } else { @@ -554,8 +546,6 @@ void PulseLayer::writeToSpeaker (void) } else { if((tone == 0) && (file_tone == 0)) { - - _debug("send zeros......................\n"); bzero (out, maxNbBytesToGet); pa_stream_write (playback->pulseStream(), out, maxNbBytesToGet, NULL, 0, PA_SEEK_RELATIVE);