Commit eee8d6b0 authored by Alexandre Savard's avatar Alexandre Savard

[#1962] Open a different stream for SFLphone ringtone in pulseaudio

parent ea419fec
......@@ -41,6 +41,15 @@ static void capture_callback (pa_stream* s, size_t bytes, void* userdata)
}
static void ringtone_callback (pa_stream* s, size_t bytes, void* userdata)
{
assert(s && bytes);
assert(bytes > 0);
static_cast<PulseLayer*> (userdata)->processRingtoneData();
}
/*
static void stream_suspended_callback (pa_stream *s UNUSED, void *userdata UNUSED)
{
......@@ -278,7 +287,7 @@ bool PulseLayer::createStreams (pa_context* c)
// pa_stream_set_suspended_callback(record->pulseStream(), stream_suspended_callback, this);
// pa_stream_set_moved_callback(record->pulseStream(), stream_moved_callback, this);
delete recordParam;
PulseLayerType * ringtoneParam = new PulseLayerType();
ringtoneParam->context = c;
ringtoneParam->type = RINGTONE_STREAM;
......@@ -288,7 +297,7 @@ bool PulseLayer::createStreams (pa_context* c)
ringtone = new AudioStream (ringtoneParam, _audioSampleRate);
ringtone->connectStream();
pa_stream_set_write_callback(ringtone->pulseStream(), playback_callback, this);
pa_stream_set_write_callback(ringtone->pulseStream(), ringtone_callback, this);
delete ringtoneParam;
pa_threaded_mainloop_signal (m , 0);
......@@ -329,6 +338,13 @@ void PulseLayer::closePlaybackStream (void)
delete playback;
playback=NULL;
}
if(ringtone) {
delete ringtone;
ringtone = NULL;
}
_debug("ringtone is dead");
}
......@@ -353,8 +369,8 @@ int PulseLayer::getMic (void *buffer, int toCopy)
void PulseLayer::startStream (void)
{
// Create Streams
if(!playback || !record)
createStreams(context);
if(!playback || !record)
createStreams(context);
// Flush outside the if statement: every time start stream is
// called is to notify a new event
......@@ -411,6 +427,19 @@ void PulseLayer::processCaptureData (void)
}
void PulseLayer::processRingtoneData (void)
{
// handle ringtone playback
if(ringtone && (ringtone)->pulseStream() && (pa_stream_get_state(ringtone->pulseStream()) == PA_STREAM_READY)) {
// If the playback buffer is full, we don't overflow it; wait for it to have free space
if(pa_stream_writable_size(ringtone->pulseStream()) == 0)
return;
ringtoneToSpeaker();
}
}
void PulseLayer::processData (void)
{
......@@ -487,10 +516,11 @@ void PulseLayer::writeToSpeaker (void)
pa_xfree (out);
}
}
//}
else if (file_tone != 0) {
// else if (file_tone != 0) {
/*
if (playback->getStreamState() == PA_STREAM_READY) {
out = (SFLDataFormat*) pa_xmalloc (writeableSize);
......@@ -501,6 +531,7 @@ void PulseLayer::writeToSpeaker (void)
pa_xfree (out);
}
*/
} else {
......@@ -641,6 +672,43 @@ void PulseLayer::readFromMic (void)
}
void PulseLayer::ringtoneToSpeaker(void)
{
int availBytes;
AudioLoop* file_tone = _manager->getTelephoneFile();
SFLDataFormat* out;
int writableSize = pa_stream_writable_size(ringtone->pulseStream());
_debug("writable size: %d", writableSize);
if (file_tone) {
if(ringtone->getStreamState() == PA_STREAM_READY) {
out = (SFLDataFormat*)pa_xmalloc(writableSize);
int copied = file_tone->getNext(out, writableSize/sizeof(SFLDataFormat), 100);
pa_stream_write(ringtone->pulseStream(), out, copied*sizeof(SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
pa_xfree(out);
}
}
else {
out = (SFLDataFormat*)pa_xmalloc(writableSize);
memset(out, 0, writableSize);
pa_stream_write(ringtone->pulseStream(), out, writableSize, NULL, 0, PA_SEEK_RELATIVE);
pa_xfree(out);
}
}
static void retrieve_server_info (pa_context *c UNUSED, const pa_server_info *i, void *userdata UNUSED)
{
_debug ("Server Info: Process owner : %s" , i->user_name);
......
......@@ -140,6 +140,8 @@ class PulseLayer : public AudioLayer {
void processCaptureData( void );
void processRingtoneData( void );
void processData(void);
private:
......@@ -160,6 +162,7 @@ class PulseLayer : public AudioLayer {
*/
void readFromMic( void );
void writeToSpeaker( void );
void ringtoneToSpeaker( void );
/**
* Create the audio streams into the given context
......
......@@ -3864,15 +3864,19 @@ void ManagerImpl::unloadAccountMap () {
while (iter != _accountMap.end()) {
_debug ("Unloading account %s\n", iter->first.c_str());
_debug ("Unloading account %s", iter->first.c_str());
delete iter->second;
iter->second = 0;
iter->second = NULL;
iter++;
}
_debug("Manager: Clear account map");
_accountMap.clear();
_debug("Manager: Unload account map");
}
bool ManagerImpl::accountExists (const AccountID& accountID) {
......
......@@ -332,6 +332,8 @@ SIPVoIPLink::terminate()
}
initDone (false);
_debug("Terminating");
}
void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment