diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp index 3f17b171d3002742067c34114b0bf0446ca74d00..bbdfa444faef0801c5d4177f10ac73c462546b93 100644 --- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp +++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp @@ -132,7 +132,6 @@ static void source_input_info_callback (pa_context *c UNUSED, const pa_source_in char s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX]; if (!eol) { - printf ("Sink %u\n" " Name: %s\n" " Driver: %s\n" @@ -157,7 +156,6 @@ static void source_input_info_callback (pa_context *c UNUSED, const pa_source_in i->flags & PA_SOURCE_HW_VOLUME_CTRL ? "HW_VOLUME_CTRL " : "", i->flags & PA_SOURCE_LATENCY ? "LATENCY " : "", i->flags & PA_SOURCE_HARDWARE ? "HARDWARE" : ""); - std::string deviceName (i->name); ( (PulseLayer *) userdata)->getSourceList()->push_back (deviceName); @@ -169,7 +167,6 @@ static void context_changed_callback (pa_context* c, pa_subscription_event_type_ { switch (t) { - case PA_SUBSCRIPTION_EVENT_SINK: _debug ("Audio: PA_SUBSCRIPTION_EVENT_SINK"); ( (PulseLayer *) userdata)->getSinkList()->clear(); @@ -751,6 +748,8 @@ void PulseLayer::writeToSpeaker (void) _warn ("Audio: playback error : %s", pa_strerror (writeableSize)); } + AudioLoop *toneToPlay = _manager->getTelephoneTone(); + if (urgentAvailBytes > writeableSize) { out = (SFLDataFormat*) pa_xmalloc (writeableSize); @@ -766,7 +765,24 @@ void PulseLayer::writeToSpeaker (void) getMainBuffer()->discard (writeableSize); - } else { + } + else if (toneToPlay != 0) { + + if (playback->getStreamState() == PA_STREAM_READY) { + + out = (SFLDataFormat*) pa_xmalloc (writeableSize); + memset (out, 0, writeableSize); + + int copied = toneToPlay->getNext (out, writeableSize / sizeof (SFLDataFormat), 100); + + //spkrFile->write ( (const char *) out, copied*sizeof (SFLDataFormat)); + pa_stream_write (playback->pulseStream(), out, copied * sizeof (SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE); + + pa_xfree (out); + + } + } + else { // We must test if data have been received from network in case of early media normalAvailBytes = getMainBuffer()->availForGet(); @@ -832,15 +848,14 @@ void PulseLayer::writeToSpeaker (void) } else { // Get ringtone - AudioLoop *fileToPlay = _manager->getTelephoneTone(); + // AudioLoop *fileToPlay = _manager->getTelephoneTone(); // If audio stream is open and there is realy nothing to play (i.e. audio voce is late and audio layer is underrun) - if (fileToPlay == NULL) { + if (toneToPlay == NULL) { SFLDataFormat* zeros = (SFLDataFormat*) pa_xmalloc (writeableSize); bzero (zeros, writeableSize); - _debug("write zeros"); pa_stream_write (playback->pulseStream(), zeros, writeableSize, NULL, 0, PA_SEEK_RELATIVE); pa_xfree (zeros); diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index 80d13a72fc1709ac94c8ba3d0858a568b4ae643a..889dc95509475ad3430591a74935c48097ba1107 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -196,12 +196,6 @@ void ManagerImpl::terminate () delete _audiodriver; _audiodriver = NULL; - audioLayerMutexUnlock(); - - _debug ("Manager: Unload telephone tone"); - delete _telephoneTone; - _telephoneTone = NULL; - _debug ("Manager: Unload audio codecs "); _audioCodecFactory.deleteHandlePointer(); @@ -2245,21 +2239,21 @@ bool ManagerImpl::playATone (Tone::TONEID toneId) */ void ManagerImpl::stopTone () { - bool hasToPlayTone; + bool hasToPlayTone = voipPreferences.getPlayTones(); - hasToPlayTone = voipPreferences.getPlayTones(); - - if (!hasToPlayTone) + if (hasToPlayTone == false) { return; + } _toneMutex.enterMutex(); - if (_telephoneTone != 0) { + if (_telephoneTone != NULL) { _telephoneTone->setCurrentTone (Tone::TONE_NULL); } - if (_audiofile) + if (_audiofile) { _audiofile->stop(); + } _toneMutex.leaveMutex(); } @@ -2382,8 +2376,6 @@ void ManagerImpl::ringtone (const AccountID& accountID) _audiodriver->startStream(); audioLayerMutexUnlock(); - ringback(); - } else { ringback(); } @@ -2392,26 +2384,22 @@ void ManagerImpl::ringtone (const AccountID& accountID) AudioLoop* ManagerImpl::getTelephoneTone () { - // _debug ("ManagerImpl::getTelephoneTone()"); - - if (_telephoneTone != 0) { - // _debug ("telephone tone!!!!!!"); + if (_telephoneTone != NULL) { ost::MutexLock m (_toneMutex); return _telephoneTone->getCurrentTone(); } else { - //_debug ("No Tone!!!!!!"); - return 0; + return NULL; } } AudioLoop* ManagerImpl::getTelephoneFile () { - // _debug("ManagerImpl::getTelephoneFile()"); ost::MutexLock m (_toneMutex); - if (!_audiofile) + if (!_audiofile) { return NULL; + } if (_audiofile->isStarted()) { return _audiofile;