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

[#790] Reduce number of start/stop streams call on pulse audio

parent 3352a2d9
No related branches found
No related tags found
No related merge requests found
......@@ -412,8 +412,6 @@ calltree_update_call (calltab_t* tab, callable_obj_t * c)
void calltree_add_history_entry (callable_obj_t * c)
{
printf("calltree_add_history_entry\n");
if (dbus_get_history_enabled () == 0)
return;
......@@ -473,8 +471,6 @@ void calltree_add_history_entry (callable_obj_t * c)
void calltree_add_call (calltab_t* tab, callable_obj_t * c)
{
printf("calltree_add_call\n");
if (tab == history)
{
calltree_add_history_entry (c);
......
......@@ -98,7 +98,7 @@ AudioRtp::closeRtpSession () {
throw;
}
AudioLayer* audiolayer = Manager::instance().getAudioDriver();
audiolayer->stopStream();
// audiolayer->stopStream();
return true;
}
......@@ -398,52 +398,6 @@ AudioRtpRTX::sendSessionFromMic(int timestamp)
int compSize = processDataEncode(audiolayer);
/*
// compute codec framesize in ms
float fixed_codec_framesize = computeCodecFrameSize(_audiocodec->getFrameSize(), _audiocodec->getClockRate());
// compute nb of byte to get coresponding to 20 ms at audio layer frame size (44.1 khz)
int maxBytesToGet = computeNbByteAudioLayer(fixed_codec_framesize);
// available bytes inside ringbuffer
int availBytesFromMic = audiolayer->canGetMic();
// set available byte to maxByteToGet
int bytesAvail = (availBytesFromMic < maxBytesToGet) ? availBytesFromMic : maxBytesToGet;
if (bytesAvail == 0)
return;
// Get bytes from micRingBuffer to data_from_mic
int nbSample = audiolayer->getMic( micData , bytesAvail ) / sizeof(SFLDataFormat);
// nb bytes to be sent over RTP
int compSize = 0;
// test if resampling is required
if (_audiocodec->getClockRate() != _layerSampleRate) {
int nb_sample_up = nbSample;
// _debug("_nbSample audiolayer->getMic(): %i \n", nbSample);
// Store the length of the mic buffer in samples for recording
_nSamplesMic = nbSample;
// int nbSamplesMax = _layerFrameSize * _audiocodec->getClockRate() / 1000;
nbSample = reSampleData(micData , micDataConverted, _audiocodec->getClockRate(), nb_sample_up, DOWN_SAMPLING);
compSize = _audiocodec->codecEncode( micDataEncoded, micDataConverted, nbSample*sizeof(int16));
} else {
// no resampling required
// int nbSamplesMax = _codecFrameSize;
compSize = _audiocodec->codecEncode( micDataEncoded, micData, nbSample*sizeof(int16));
}
*/
// putData put the data on RTP queue, sendImmediate bypass this queue
if (!_sym) {
// _sessionSend->putData(timestamp, micDataEncoded, compSize);
......@@ -483,53 +437,9 @@ AudioRtpRTX::receiveSessionForSpkr (int& countTime)
unsigned int size = adu->getSize(); // size in char
processDataDecode(audiolayer, spkrData, size, countTime);
/*
if (_audiocodec != NULL) {
// Return the size of data in bytes
int expandedSize = _audiocodec->codecDecode( spkrDataDecoded , spkrData , size );
// buffer _receiveDataDecoded ----> short int or int16, coded on 2 bytes
int nbSample = expandedSize / sizeof(SFLDataFormat);
// test if resampling is required
if (_audiocodec->getClockRate() != _layerSampleRate) {
// Do sample rate conversion
int nb_sample_down = nbSample;
nbSample = reSampleData(spkrDataDecoded , spkrDataConverted, _codecSampleRate , nb_sample_down, UP_SAMPLING);
// Store the number of samples for recording
_nSamplesSpkr = nbSample;
// put data in audio layer, size in byte
audiolayer->putMain (spkrDataConverted, nbSample * sizeof(SFLDataFormat));
} else {
// Stor the number of samples for recording
_nSamplesSpkr = nbSample;
// put data in audio layer, size in byte
audiolayer->putMain (spkrDataDecoded, nbSample * sizeof(SFLDataFormat));
}
// Notify (with a beep) an incoming call when there is already a call
countTime += time->getSecond();
if (Manager::instance().incomingCallWaiting() > 0) {
countTime = countTime % 500; // more often...
if (countTime == 0) {
Manager::instance().notificationIncomingCall();
}
}
} else {
countTime += time->getSecond();
}
delete adu; adu = NULL;
*/
}
int
AudioRtpRTX::reSampleData(SFLDataFormat *input, SFLDataFormat *output, int sampleRate_codec, int nbSamples, int status)
......@@ -634,7 +544,7 @@ AudioRtpRTX::run () {
}
audiolayer->stopStream();
// audiolayer->stopStream();
_debug("- ARTP Action: Stop call %s\n",_ca->getCallId().c_str());
//} catch(std::exception &e) {
//_start.post();
......
......@@ -49,10 +49,6 @@ AudioStream::connectStream()
if(!_audiostream)
_audiostream = createStream( _context );
else {
disconnectStream();
_audiostream = createStream( _context );
}
return true;
}
......
......@@ -166,12 +166,15 @@ bool PulseLayer::createStreams( pa_context* c )
pa_threaded_mainloop_signal(m , 0);
isCorked = true;
return true;
}
bool PulseLayer::openDevice(int indexIn UNUSED, int indexOut UNUSED, int sampleRate, int frameSize , int stream UNUSED, std::string plugin UNUSED)
{
_debug("PulseLayer::openDevice \n");
_sampleRate = sampleRate;
_frameSize = frameSize;
......@@ -225,6 +228,7 @@ int PulseLayer::getMic(void *buffer, int toCopy)
void PulseLayer::startStream (void)
{
// flushMic();
if (isCorked) {
_urgentRingBuffer.flush();
_micRingBuffer.flush();
......@@ -238,11 +242,17 @@ void PulseLayer::startStream (void)
pa_threaded_mainloop_unlock(m);
isCorked = false;
}
}
void
PulseLayer::stopStream (void)
{
if (!isCorked) {
_debug("PulseLayer::Stop stream\n");
pa_stream_flush( playback->pulseStream(), NULL, NULL );
pa_stream_flush( record->pulseStream(), NULL, NULL );
......@@ -254,6 +264,10 @@ PulseLayer::stopStream (void)
pa_stream_cork( playback->pulseStream(), 1, NULL, NULL);
pa_stream_cork( record->pulseStream(), 1, NULL, NULL);
isCorked = true;
}
}
......
......@@ -189,6 +189,8 @@ class PulseLayer : public AudioLayer {
*/
AudioStream* record;
bool isCorked;
int spkrVolume;
int micVolume;
......
......@@ -326,6 +326,13 @@ ManagerImpl::hangupCall(const CallID& id)
_debug("Stop audio stream\n");
audiolayer = getAudioDriver();
int nbCalls = getCallList().size();
_debug("nbCalls %i \n", nbCalls);
// stop stream
if (!(nbCalls > 1))
audiolayer->stopStream();
/* Direct IP to IP call */
......@@ -958,6 +965,7 @@ void ManagerImpl::stopTone (bool stopAudio=true)
if (audiolayer) audiolayer->stopStream();
}
_toneMutex.enterMutex();
if (_telephoneTone != 0) {
_telephoneTone->setCurrentTone(Tone::TONE_NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment