Commit d29d8d20 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#5730] Fix start audio session after changing sampling rate

parent e654fe16
......@@ -196,6 +196,7 @@ AlsaLayer::startStream (void)
}
}
_isStarted = true;
}
void
......@@ -203,6 +204,8 @@ AlsaLayer::stopStream (void)
{
_debug ("Audio: Stop stream");
_isStarted = false;
try {
/* Stop the audio thread first */
if (_audioThread) {
......
......@@ -72,6 +72,7 @@ class AudioLayer
AudioLayer (ManagerImpl* manager , int type)
: _defaultVolume (100)
, _layerType (type)
, _isStarted(false)
, _manager (manager)
, _urgentRingBuffer (SIZEBUF, default_id)
, _indexIn (0)
......@@ -126,6 +127,8 @@ class AudioLayer
*/
virtual void stopStream (void) = 0;
bool isStarted(void) { return _isStarted; }
/**
* Send a chunk of data to the hardware buffer to start the playback
* Copy data in the urgent buffer.
......@@ -296,6 +299,11 @@ class AudioLayer
* Drop the pending frames and close the playback device
*/
virtual void closePlaybackStream (void) = 0;
/**
* Wether or not the audio layer stream is started
*/
bool _isStarted;
/** Augment coupling, reduce indirect access */
ManagerImpl* _manager;
......
......@@ -306,7 +306,6 @@ void AudioRtpSession::receiveSpeakerData ()
spkrDataIn = (unsigned char*) adu->getData(); // data in char
size = adu->getSize(); // size in char
// DTMF over RTP, size must be over 4 in order to process it as voice data
if (size > 4) {
processDataDecode (spkrDataIn, size);
......
......@@ -243,8 +243,6 @@ PulseLayer::PulseLayer (ManagerImpl* manager)
{
_urgentRingBuffer.createReadPointer();
is_started = false;
AudioLayer::_noisesuppressstate = true;
byteCounter = 0;
......@@ -272,16 +270,14 @@ PulseLayer::~PulseLayer (void)
void
PulseLayer::openLayer (void)
{
if (!is_started) {
_info ("Audio: Open Pulseaudio layer");
if(_isStarted)
return;
connectPulseAudioServer();
_info ("Audio: Open Pulseaudio layer");
is_started = true;
}
connectPulseAudioServer();
_isStarted = true;
}
bool
......@@ -289,6 +285,8 @@ PulseLayer::closeLayer (void)
{
_info ("Audio: Close Pulseaudio layer");
_isStarted = false;
disconnectAudioStream();
if (m) {
......
......@@ -285,8 +285,6 @@ class PulseLayer : public AudioLayer
/** Sample rate converter object */
SamplerateConverter * _converter;
bool is_started;
int spkrVolume;
int micVolume;
......
......@@ -3070,9 +3070,12 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate)
int type, currentSamplerate, framesize, numCardIn, numCardOut, numCardRing;
std::string alsaPlugin;
bool wasActive;
_debug("Manager: Audio Sampling rate changed");
if (!_audiodriver) {
_debug("Manager: No Audio driver set");
_debug("Manager: No Audio driver initialized");
return;
}
......@@ -3099,12 +3102,9 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate)
_debug ("Manager: Deleting current layer...");
// ost::MutexLock lock (*getAudioLayerMutex());
// getAudioLayerMutex()->enter();
wasActive = _audiodriver->isStarted();
// _audiodriver->closeLayer();
delete _audiodriver;
_audiodriver = NULL;
switch (type) {
......@@ -3126,35 +3126,48 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate)
break;
}
if(_audiodriver == NULL) {
_debug("Manager: Error: Audio driver could not be initialized");
}
_audiodriver->setErrorMessage (-1);
_audiodriver->openDevice (numCardIn, numCardOut, numCardRing, samplerate, framesize,
SFL_PCM_BOTH, alsaPlugin);
if (_audiodriver -> getErrorMessage() != -1)
if (_audiodriver -> getErrorMessage() != -1) {
notifyErrClient (_audiodriver -> getErrorMessage());
}
_debug ("Manager: Current device: %d ", type);
_mainBuffer.setInternalSamplingRate(samplerate);
if (_audiodriver) {
unsigned int sampleRate = _audiodriver->getSampleRate();
unsigned int sampleRate = _audiodriver->getSampleRate();
delete _telephoneTone;
delete _telephoneTone;
_telephoneTone = NULL;
_debugInit ("Manager: Load telephone tone");
std::string country = preferences.getZoneToneChoice();
_telephoneTone = new TelephoneTone (country, sampleRate);
_debugInit ("Manager: Load telephone tone");
std::string country = preferences.getZoneToneChoice();
_telephoneTone = new TelephoneTone (country, sampleRate);
if(_telephoneTone == NULL) {
_debug("Manager: Error: Telephone tone is NULL");
}
delete _dtmfKey;
_dtmfKey = NULL;
delete _dtmfKey;
_debugInit ("Manager: Loading DTMF key with sample rate %d", sampleRate);
_dtmfKey = new DTMF (sampleRate);
_debugInit ("Manager: Loading DTMF key with sample rate %d", sampleRate);
_dtmfKey = new DTMF (sampleRate);
if(_dtmfKey == NULL) {
_debug("Manager: Error: DtmfKey is NULL");
}
if (hasCurrentCall()) {
// Restart audio layer if it was active
if (wasActive) {
_audiodriver->startStream();
}
}
......
Supports Markdown
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