Skip to content
Snippets Groups Projects
Commit d909a749 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#2308] Fix tone and ringtone

parent 837b8a68
Branches
Tags
No related merge requests found
...@@ -136,7 +136,6 @@ AudioStream::stream_state_callback (pa_stream* s, void* user_data) ...@@ -136,7 +136,6 @@ AudioStream::stream_state_callback (pa_stream* s, void* user_data)
break; break;
case PA_STREAM_READY: case PA_STREAM_READY:
_debug ("Stream successfully created, connected to %s\n", pa_stream_get_device_name (s)); _debug ("Stream successfully created, connected to %s\n", pa_stream_get_device_name (s));
// pa_stream_cork( s, 0, NULL, NULL); // pa_stream_cork( s, 0, NULL, NULL);
break; break;
...@@ -187,9 +186,9 @@ AudioStream::createStream (pa_context* c) ...@@ -187,9 +186,9 @@ AudioStream::createStream (pa_context* c)
if (_streamType == PLAYBACK_STREAM) { if (_streamType == PLAYBACK_STREAM) {
attributes->maxlength = 16000; attributes->maxlength = 16000;
attributes->tlength = 2048; attributes->tlength = 2048;
attributes->prebuf = 1024; attributes->prebuf = 2048;
attributes->minreq = 1024; attributes->minreq = 1024;
attributes->fragsize = 1024; 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_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_START_CORKED, &_volume, NULL);
} else if (_streamType == CAPTURE_STREAM) { } else if (_streamType == CAPTURE_STREAM) {
......
...@@ -183,6 +183,8 @@ class AudioStream { ...@@ -183,6 +183,8 @@ class AudioStream {
ost::Mutex _mutex; ost::Mutex _mutex;
bool _stream_is_ready;
}; };
#endif // _AUDIO_STREAM_H #endif // _AUDIO_STREAM_H
...@@ -154,6 +154,8 @@ PulseLayer::connectPulseAudioServer (void) ...@@ -154,6 +154,8 @@ PulseLayer::connectPulseAudioServer (void)
pa_threaded_mainloop_unlock (m); pa_threaded_mainloop_unlock (m);
_urgentRingBuffer.flushAll();
//serverinfo(); //serverinfo();
//muteAudioApps(99); //muteAudioApps(99);
_debug ("Context creation done\n"); _debug ("Context creation done\n");
...@@ -246,6 +248,8 @@ bool PulseLayer::createStreams (pa_context* c) ...@@ -246,6 +248,8 @@ bool PulseLayer::createStreams (pa_context* c)
pa_threaded_mainloop_signal (m , 0); pa_threaded_mainloop_signal (m , 0);
_urgentRingBuffer.flushAll();
return true; return true;
} }
...@@ -258,6 +262,8 @@ bool PulseLayer::openDevice (int indexIn UNUSED, int indexOut UNUSED, int sample ...@@ -258,6 +262,8 @@ bool PulseLayer::openDevice (int indexIn UNUSED, int indexOut UNUSED, int sample
_audioSampleRate = sampleRate; _audioSampleRate = sampleRate;
_frameSize = frameSize; _frameSize = frameSize;
_urgentRingBuffer.flushAll();
/* /*
m = pa_threaded_mainloop_new(); m = pa_threaded_mainloop_new();
assert (m); assert (m);
...@@ -373,9 +379,9 @@ PulseLayer::stopStream (void) ...@@ -373,9 +379,9 @@ PulseLayer::stopStream (void)
pa_stream_flush (playback->pulseStream(), NULL, NULL); pa_stream_flush (playback->pulseStream(), NULL, NULL);
pa_stream_flush (record->pulseStream(), NULL, NULL); pa_stream_flush (record->pulseStream(), NULL, NULL);
flushMic(); // flushMic();
flushMain(); // flushMain();
flushUrgent(); // flushUrgent();
// closeCaptureStream(); // closeCaptureStream();
// closePlaybackStream(); // closePlaybackStream();
...@@ -428,6 +434,8 @@ void PulseLayer::processPlaybackData (void) ...@@ -428,6 +434,8 @@ void PulseLayer::processPlaybackData (void)
// Handle the data for the speakers // Handle the data for the speakers
if ( playback &&(playback->pulseStream()) && (pa_stream_get_state (playback->pulseStream()) == PA_STREAM_READY)) { if ( playback &&(playback->pulseStream()) && (pa_stream_get_state (playback->pulseStream()) == PA_STREAM_READY)) {
_debug("PulseLayer::processPlaybackData()\n");
// If the playback buffer is full, we don't overflow it; wait for it to have free space // If the playback buffer is full, we don't overflow it; wait for it to have free space
if (pa_stream_writable_size (playback->pulseStream()) == 0) if (pa_stream_writable_size (playback->pulseStream()) == 0)
return; return;
...@@ -462,6 +470,8 @@ void PulseLayer::writeToSpeaker (void) ...@@ -462,6 +470,8 @@ void PulseLayer::writeToSpeaker (void)
if (urgentAvailBytes > 0) { if (urgentAvailBytes > 0) {
_debug("Urgent Avail?????????????????????\n");
// Urgent data (dtmf, incoming call signal) come first. // Urgent data (dtmf, incoming call signal) come first.
//_debug("Play urgent!: %i\e" , urgentAvail); //_debug("Play urgent!: %i\e" , urgentAvail);
toGet = (urgentAvailBytes < (int) (framesPerBuffer * sizeof (SFLDataFormat))) ? urgentAvailBytes : framesPerBuffer * sizeof (SFLDataFormat); toGet = (urgentAvailBytes < (int) (framesPerBuffer * sizeof (SFLDataFormat))) ? urgentAvailBytes : framesPerBuffer * sizeof (SFLDataFormat);
...@@ -476,9 +486,14 @@ void PulseLayer::writeToSpeaker (void) ...@@ -476,9 +486,14 @@ void PulseLayer::writeToSpeaker (void)
} else { } else {
AudioLoop* tone = _manager->getTelephoneTone(); AudioLoop* tone = _manager->getTelephoneTone();
AudioLoop* file_tone = _manager->getTelephoneFile();
if (tone != 0) { if (tone != 0) {
if (playback->getStreamState() == PA_STREAM_READY)
{
_debug("Play Tone!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
toGet = framesPerBuffer; toGet = framesPerBuffer;
out = (SFLDataFormat*) pa_xmalloc (toGet * sizeof (SFLDataFormat)); out = (SFLDataFormat*) pa_xmalloc (toGet * sizeof (SFLDataFormat));
tone->getNext (out, toGet , 100); tone->getNext (out, toGet , 100);
...@@ -486,17 +501,29 @@ void PulseLayer::writeToSpeaker (void) ...@@ -486,17 +501,29 @@ void PulseLayer::writeToSpeaker (void)
pa_xfree (out); pa_xfree (out);
} }
}
if ( (tone=_manager->getTelephoneFile()) != 0) { if (file_tone != 0) {
if (playback->getStreamState() == PA_STREAM_READY)
{
_debug("Play File Tone!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
toGet = framesPerBuffer; toGet = framesPerBuffer;
toPlay = ( (int) (toGet * sizeof (SFLDataFormat)) > framesPerBuffer) ? framesPerBuffer : toGet * sizeof (SFLDataFormat); toPlay = ( (int) (toGet * sizeof (SFLDataFormat)) > framesPerBuffer) ? framesPerBuffer : toGet * sizeof (SFLDataFormat);
_debug("toPlay: %i\n", toPlay);
out = (SFLDataFormat*) pa_xmalloc (toPlay); out = (SFLDataFormat*) pa_xmalloc (toPlay);
tone->getNext (out, toPlay/2 , 100); file_tone->getNext (out, toPlay/2 , 100);
pa_stream_write (playback->pulseStream(), out, toPlay, NULL, 0, PA_SEEK_RELATIVE); pa_stream_write (playback->pulseStream(), out, toPlay, NULL, 0, PA_SEEK_RELATIVE);
_debug("ok\n");
pa_xfree (out); pa_xfree (out);
_debug("end of play file\n");
}
} else { } else {
int _mainBufferSampleRate = getMainBuffer()->getInternalSamplingRate(); int _mainBufferSampleRate = getMainBuffer()->getInternalSamplingRate();
...@@ -549,11 +576,14 @@ void PulseLayer::writeToSpeaker (void) ...@@ -549,11 +576,14 @@ void PulseLayer::writeToSpeaker (void)
} else { } else {
if((tone == 0) && (file_tone == 0)) {
_debug("send zeros......................\n"); _debug("send zeros......................\n");
bzero (out, maxNbBytesToGet); bzero (out, maxNbBytesToGet);
pa_stream_write (playback->pulseStream(), out, maxNbBytesToGet, NULL, 0, PA_SEEK_RELATIVE); pa_stream_write (playback->pulseStream(), out, maxNbBytesToGet, NULL, 0, PA_SEEK_RELATIVE);
} }
}
_urgentRingBuffer.Discard(toGet); _urgentRingBuffer.Discard(toGet);
......
...@@ -1998,6 +1998,9 @@ bool ManagerImpl::playATone (Tone::TONEID toneId) ...@@ -1998,6 +1998,9 @@ bool ManagerImpl::playATone (Tone::TONEID toneId)
audiolayer = getAudioDriver(); audiolayer = getAudioDriver();
if (audiolayer)
audiolayer->startStream();
if (_telephoneTone != 0) { if (_telephoneTone != 0) {
_toneMutex.enterMutex(); _toneMutex.enterMutex();
_telephoneTone->setCurrentTone (toneId); _telephoneTone->setCurrentTone (toneId);
...@@ -2148,7 +2151,7 @@ ManagerImpl::ringtone() ...@@ -2148,7 +2151,7 @@ ManagerImpl::ringtone()
AudioLoop* AudioLoop*
ManagerImpl::getTelephoneTone() ManagerImpl::getTelephoneTone()
{ {
// _debug("ManagerImpl::getTelephoneTone()\n"); _debug("ManagerImpl::getTelephoneTone()\n");
if (_telephoneTone != 0) { if (_telephoneTone != 0) {
ost::MutexLock m (_toneMutex); ost::MutexLock m (_toneMutex);
return _telephoneTone->getCurrentTone(); return _telephoneTone->getCurrentTone();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment