diff --git a/sflphone-common/src/audio/alsa/alsalayer.cpp b/sflphone-common/src/audio/alsa/alsalayer.cpp index 0fc73f67fb6bac02788d6681eb5f173ee182978a..ee8ccdaac8cbad640f7a11ae655167162c53c212 100644 --- a/sflphone-common/src/audio/alsa/alsalayer.cpp +++ b/sflphone-common/src/audio/alsa/alsalayer.cpp @@ -160,9 +160,11 @@ AlsaLayer::startStream (void) startCaptureStream (); startPlaybackStream (); - _urgentRingBuffer.flush(); - getMainBuffer()->flushAllBuffers(); - getMainBuffer()->flushDefault(); + flushMain(); + flushUrgent(); + // _urgentRingBuffer.flush(); + // getMainBuffer()->flushAllBuffers(); + // getMainBuffer()->flushDefault(); if(_audioThread == NULL) { try { diff --git a/sflphone-common/src/audio/audiolayer.cpp b/sflphone-common/src/audio/audiolayer.cpp index 9853fad03ef44bf17a42d53457edccc3d357178f..1e513c7744ab9ff0887890eae8937e2582b05ca1 100644 --- a/sflphone-common/src/audio/audiolayer.cpp +++ b/sflphone-common/src/audio/audiolayer.cpp @@ -23,8 +23,10 @@ void AudioLayer::flushMain (void) { ost::MutexLock guard (_mutex); - // should pass call id - getMainBuffer()->flushAllBuffers(); + // should pass call id + MainBuffer* mainbuffer = getMainBuffer(); + if(mainbuffer) + mainbuffer->flushAllBuffers(); } @@ -37,6 +39,7 @@ void AudioLayer::flushUrgent (void) int AudioLayer::putUrgent (void* buffer, int toCopy) { + _debug("------------------- AudioLayer::putUrgent --------------------\n"); int a; ost::MutexLock guard (_mutex); diff --git a/sflphone-common/src/audio/mainbuffer.cpp b/sflphone-common/src/audio/mainbuffer.cpp index 485698bdba23f4d482cf24e58f8b5b988daad929..d4745be5f1017158ec70834a934eec5746de10d9 100644 --- a/sflphone-common/src/audio/mainbuffer.cpp +++ b/sflphone-common/src/audio/mainbuffer.cpp @@ -435,7 +435,7 @@ int MainBuffer::availForGet(CallID call_id) // _debug("MainBuffer::availForGet availForGetByID(%s,%s)\n", (*iter_id).c_str(), call_id.c_str()); if((call_id != default_id) && (*iter_id == call_id)) { - _debug("This problem should not occur since we have %i element\n", callid_set->size()); + _debug("This problem should not occur since we have %i element\n", (int)callid_set->size()); } // else return availForGetByID(*iter_id, call_id); @@ -586,10 +586,15 @@ void MainBuffer::flushByID(CallID call_id, CallID reader_id) void MainBuffer::flushAllBuffers() { + + // _debug("-------------------------- flushAllBuffers()\n"); + RingBufferMap::iterator iter_buffer = _ringBufferMap.begin(); while(iter_buffer != _ringBufferMap.end()) { + // _debug("-------------------------- flushing: %s\n",iter_buffer->second->getBufferId().c_str()); + iter_buffer->second->flushAll(); iter_buffer++; diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp index ec62751477090569f47e8b759264e8ccd4ca6d7f..2a7c11fdc83e5f36a58ea6b658fd4941f3b88e33 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp @@ -173,8 +173,6 @@ PulseLayer::connectPulseAudioServer (void) pa_threaded_mainloop_unlock (m); - _urgentRingBuffer.flushAll(); - //serverinfo(); //muteAudioApps(99); _debug ("Context creation done\n"); @@ -267,7 +265,9 @@ bool PulseLayer::createStreams (pa_context* c) pa_threaded_mainloop_signal (m , 0); - _urgentRingBuffer.flushAll(); + flushMain(); + flushUrgent(); + // _urgentRingBuffer.flushAll(); return true; @@ -279,7 +279,8 @@ bool PulseLayer::openDevice (int indexIn UNUSED, int indexOut UNUSED, int sample _audioSampleRate = sampleRate; _frameSize = frameSize; - _urgentRingBuffer.flushAll(); + // _urgentRingBuffer.flushAll(); + flushUrgent(); _converter = new SamplerateConverter (_audioSampleRate, _frameSize*4); @@ -361,8 +362,10 @@ void PulseLayer::startStream (void) is_started = true; } - _urgentRingBuffer.flushAll(); - getMainBuffer()->flushAllBuffers(); + // Flush outside the if statement: every time start stream is + // called is to notify a new event + flushUrgent(); + flushMain(); } @@ -487,6 +490,7 @@ void PulseLayer::writeToSpeaker (void) SFLDataFormat* out;// = (SFLDataFormat*)pa_xmalloc(framesPerBuffer); urgentAvailBytes = _urgentRingBuffer.AvailForGet(); + int writeableSize = pa_stream_writable_size(playback->pulseStream()); // _debug("PulseLayer writablesize : %i\n", writeableSize); @@ -499,6 +503,8 @@ void PulseLayer::writeToSpeaker (void) // _debug("urgentAvailBytes: %i\n", urgentAvailBytes); + // _debug("Play Urgent!\n"); + out = (SFLDataFormat*) pa_xmalloc (writeableSize); _urgentRingBuffer.Get (out, writeableSize, 100); // pa_threaded_mainloop_lock (m); @@ -517,7 +523,7 @@ void PulseLayer::writeToSpeaker (void) AudioLoop* file_tone = _manager->getTelephoneFile(); // flush remaining samples in _urgentRingBuffer - _urgentRingBuffer.flushAll(); + flushUrgent(); if (tone != 0) { @@ -526,6 +532,8 @@ void PulseLayer::writeToSpeaker (void) if (playback->getStreamState() == PA_STREAM_READY) { + // _debug("Play Sine Tone!\n"); + out = (SFLDataFormat*) pa_xmalloc (writeableSize); int copied = tone->getNext (out, writeableSize / sizeof (SFLDataFormat), 100); // pa_threaded_mainloop_lock (m); @@ -541,6 +549,7 @@ void PulseLayer::writeToSpeaker (void) if (playback->getStreamState() == PA_STREAM_READY) { + // _debug("Play File Tone!\n"); out = (SFLDataFormat*) pa_xmalloc (writeableSize); int copied = file_tone->getNext(out, writeableSize / sizeof(SFLDataFormat), 100); diff --git a/sflphone-common/src/audio/ringbuffer.cpp b/sflphone-common/src/audio/ringbuffer.cpp index a25eb0e0a62e12c299de7e73f7a67406566a6204..f8420187e8cba33490687b192f8d37924c60fd47 100644 --- a/sflphone-common/src/audio/ringbuffer.cpp +++ b/sflphone-common/src/audio/ringbuffer.cpp @@ -64,9 +64,12 @@ RingBuffer::flushAll () { // _debug("flushall: reinit all readpointer in \"%s\" ringbuffer\n", buffer_id.c_str()); + // _debug("------------------------------ flushAll() in \"%s\" ringbuffer\n", buffer_id.c_str()); + ReadPointer::iterator iter_pointer = _readpointer.begin(); while(iter_pointer != _readpointer.end()) { + // _debug("------------------------------ reinit readpointer %s\n", iter_pointer->first.c_str()); iter_pointer->second = mEnd; iter_pointer++; @@ -186,7 +189,7 @@ RingBuffer::createReadPointer(CallID call_id) _debug("---- createReadPointer ringbuffer_id %s, call_id %s\n", buffer_id.c_str(), call_id.c_str()); _readpointer.insert(pair<CallID, int>(call_id, mEnd)); - _debug("---- createReadPointer ringbuffer_id %s, size %i\n", buffer_id.c_str(),_readpointer.size()); + _debug("---- createReadPointer ringbuffer_id %s, size %i\n", buffer_id.c_str(), (int)_readpointer.size()); } @@ -198,7 +201,7 @@ RingBuffer::removeReadPointer(CallID call_id) _debug("---- removeReadPointer ringbuffer_id %s, call_id %s\n", buffer_id.c_str(), call_id.c_str()); _readpointer.erase(call_id); - _debug("---- removeReadPointer ringbuffer_id %s, size %i\n", buffer_id.c_str(), _readpointer.size()); + _debug("---- removeReadPointer ringbuffer_id %s, size %i\n", buffer_id.c_str(), (int)_readpointer.size()); } diff --git a/sflphone-common/src/audio/ringbuffer.h b/sflphone-common/src/audio/ringbuffer.h index 9dc97cc5675fd804d3976d6dcd7baebf5203dbfc..ac559e98c1db50c4571d33f8ea97e5c508e03125 100644 --- a/sflphone-common/src/audio/ringbuffer.h +++ b/sflphone-common/src/audio/ringbuffer.h @@ -48,6 +48,7 @@ class RingBuffer { */ ~RingBuffer(); + CallID getBufferId(){ return buffer_id; } /** * Reset the counters to 0 diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index dcd4778e100a121cb8a0a5dd344027d06699d48a..66462cc2f734997a2d19d6ae6a5f8e2ceb118be9 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -1525,7 +1525,10 @@ ManagerImpl::addStream(const CallID& call_id) // bind to main getAudioDriver()->getMainBuffer()->bindCallID(call_id); - _audiodriver->getMainBuffer()->flush(default_id); + // _audiodriver->getMainBuffer()->flush(default_id); + _audiodriver->flushUrgent(); + _audiodriver->flushMain(); + } } @@ -1758,7 +1761,7 @@ ManagerImpl::incomingCall (Call* call, const AccountID& accountId) PulseLayer *pulselayer; std::string from, number, display_name, display; - stopTone (true); + stopTone (false); _debug ("Incoming call %s for account %s\n", call->getCallId().data(), accountId.c_str()); @@ -1845,6 +1848,7 @@ ManagerImpl::incomingMessage (const AccountID& accountId, const std::string& mes void ManagerImpl::peerAnsweredCall (const CallID& id) { + // The if statement is usefull only if we sent two calls at the same time. if (isCurrentCall (id)) { stopTone (false); } @@ -1856,6 +1860,7 @@ ManagerImpl::peerAnsweredCall (const CallID& id) // _debug("ManagerImpl::hangupCall(): broadcast codec name %s \n",codecName.c_str()); if (_dbus) _dbus->getCallManager()->currentSelectedCodec (id,codecName.c_str()); + // Required if there have been no sip reinvite, in this case we must reinit buffers since the _audiodriver->flushMain(); _audiodriver->flushUrgent(); } @@ -2005,9 +2010,9 @@ void ManagerImpl::connectionStatusNotification() bool ManagerImpl::playATone (Tone::TONEID toneId) { bool hasToPlayTone; - AudioLoop *audioloop; + // AudioLoop *audioloop; AudioLayer *audiolayer; - unsigned int nbSamples; + // unsigned int nbSamples; _debug("ManagerImpl::playATone\n"); @@ -2020,15 +2025,16 @@ bool ManagerImpl::playATone (Tone::TONEID toneId) if (audiolayer) { - audiolayer->flushUrgent(); - audiolayer->startStream(); + + audiolayer->flushUrgent(); + audiolayer->startStream(); } if (_telephoneTone != 0) { _toneMutex.enterMutex(); _telephoneTone->setCurrentTone (toneId); _toneMutex.leaveMutex(); - + /* audioloop = getTelephoneTone(); nbSamples = audioloop->getSize(); SFLDataFormat buf[nbSamples]; @@ -2038,6 +2044,7 @@ bool ManagerImpl::playATone (Tone::TONEID toneId) audiolayer->putUrgent (buf, nbSamples); } else return false; + */ } return true; @@ -2050,6 +2057,8 @@ void ManagerImpl::stopTone (bool stopAudio=true) { bool hasToPlayTone; + _debug("ManagerImpl::stopTone\n"); + hasToPlayTone = getConfigBool (SIGNALISATION, PLAY_TONES); if (!hasToPlayTone) @@ -2104,6 +2113,8 @@ ManagerImpl::congestion () void ManagerImpl::ringback () { + _debug("ManagerImpl::ringback\n"); + playATone (Tone::TONE_RINGTONE); } @@ -2113,6 +2124,7 @@ ManagerImpl::ringback () void ManagerImpl::ringtone() { + _debug("ManagerImpl::ringtone\n"); std::string ringchoice; AudioLayer *audiolayer; AudioCodec *codecForTone; @@ -2122,6 +2134,8 @@ ManagerImpl::ringtone() // stopTone(true); if (isRingtoneEnabled()) { + + _debug(" Tone is enabled\n"); //TODO Comment this because it makes the daemon crashes since the main thread //synchronizes the ringtone thread. @@ -2157,6 +2171,7 @@ ManagerImpl::ringtone() _audiofile.start(); _toneMutex.leaveMutex(); + // start audio if not started AND flush all buffers (main and urgent) audiolayer->startStream(); } else {