Commit fd1583b8 authored by Alexandre Savard's avatar Alexandre Savard

#14818: Get MainBuffer as a reference instead of a pointer

parent 551fd3c8
......@@ -634,7 +634,7 @@ AlsaLayer::getAudioDeviceName(int index, PCMType type) const
void AlsaLayer::capture()
{
unsigned int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
unsigned int mainBufferSampleRate = Manager::instance().getMainBuffer().getInternalSamplingRate();
bool resample = sampleRate_ != mainBufferSampleRate;
int toGetSamples = snd_pcm_avail_update(captureHandle_);
......@@ -667,18 +667,18 @@ void AlsaLayer::capture()
rsmpl_out.size(), mainBufferSampleRate, sampleRate_,
toGetSamples);
dcblocker_.process(rsmpl_out_ptr, rsmpl_out_ptr, outSamples);
Manager::instance().getMainBuffer()->putData(rsmpl_out_ptr,
Manager::instance().getMainBuffer().putData(rsmpl_out_ptr,
rsmpl_out.size() * sizeof(rsmpl_out[0]), MainBuffer::DEFAULT_ID);
} else {
dcblocker_.process(in_ptr, in_ptr, toGetSamples);
Manager::instance().getMainBuffer()->putData(in_ptr, toGetBytes,
Manager::instance().getMainBuffer().putData(in_ptr, toGetBytes,
MainBuffer::DEFAULT_ID);
}
}
void AlsaLayer::playback(int maxSamples)
{
size_t bytesToGet = Manager::instance().getMainBuffer()->availableForGet(MainBuffer::DEFAULT_ID);
size_t bytesToGet = Manager::instance().getMainBuffer().availableForGet(MainBuffer::DEFAULT_ID);
const size_t bytesToPut = maxSamples * sizeof(SFLDataFormat);
// no audio available, play tone or silence
......@@ -697,7 +697,7 @@ void AlsaLayer::playback(int maxSamples)
} else {
// play the regular sound samples
const size_t mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
const size_t mainBufferSampleRate = Manager::instance().getMainBuffer().getInternalSamplingRate();
const bool resample = sampleRate_ != mainBufferSampleRate;
double resampleFactor = 1.0;
......@@ -712,7 +712,7 @@ void AlsaLayer::playback(int maxSamples)
const size_t samplesToGet = bytesToGet / sizeof(SFLDataFormat);
std::vector<SFLDataFormat> out(samplesToGet, 0);
SFLDataFormat * const out_ptr = &(*out.begin());
Manager::instance().getMainBuffer()->getData(out_ptr, bytesToGet, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().getData(out_ptr, bytesToGet, MainBuffer::DEFAULT_ID);
AudioLayer::applyGain(out_ptr, samplesToGet, getPlaybackGain());
if (resample) {
......@@ -756,7 +756,7 @@ void AlsaLayer::audioCallback()
write(out_ptr, bytesToGet, playbackHandle_);
// Consume the regular one as well (same amount of bytes)
Manager::instance().getMainBuffer()->discard(bytesToGet, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().discard(bytesToGet, MainBuffer::DEFAULT_ID);
} else {
// regular audio data
playback(playbackAvailSmpl);
......
......@@ -40,7 +40,7 @@ unsigned int AudioLayer::playbackGain_ = 100;
AudioLayer::AudioLayer()
: isStarted_(false)
, urgentRingBuffer_(SIZEBUF, MainBuffer::DEFAULT_ID)
, sampleRate_(Manager::instance().getMainBuffer()->getInternalSamplingRate())
, sampleRate_(Manager::instance().getMainBuffer().getInternalSamplingRate())
, mutex_()
, dcblocker_()
, converter_(sampleRate_)
......@@ -53,7 +53,7 @@ void AudioLayer::flushMain()
{
ost::MutexLock guard(mutex_);
// should pass call id
Manager::instance().getMainBuffer()->flushAllBuffers();
Manager::instance().getMainBuffer().flushAllBuffers();
}
void AudioLayer::flushUrgent()
......
......@@ -181,7 +181,7 @@ int AudioRtpRecordHandler::processDataEncode()
return 0;
int codecSampleRate = getCodecSampleRate();
int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
int mainBufferSampleRate = Manager::instance().getMainBuffer().getInternalSamplingRate();
double resampleFactor = (double) mainBufferSampleRate / codecSampleRate;
......@@ -189,11 +189,11 @@ int AudioRtpRecordHandler::processDataEncode()
int samplesToGet = resampleFactor * getCodecFrameSize();
const size_t bytesToGet = samplesToGet * sizeof(SFLDataFormat);
if (Manager::instance().getMainBuffer()->availableForGet(id_) < bytesToGet)
if (Manager::instance().getMainBuffer().availableForGet(id_) < bytesToGet)
return 0;
SFLDataFormat *micData = audioRtpRecord_.decData_.data();
const size_t bytes = Manager::instance().getMainBuffer()->getData(micData, bytesToGet, id_);
const size_t bytes = Manager::instance().getMainBuffer().getData(micData, bytesToGet, id_);
#ifdef RECTODISK
rtpNotResampled.write((const char *)micData, bytes);
......@@ -277,7 +277,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
int outSamples = inSamples;
int codecSampleRate = getCodecSampleRate();
int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
int mainBufferSampleRate = Manager::instance().getMainBuffer().getInternalSamplingRate();
// test if resampling is required
if (codecSampleRate != mainBufferSampleRate) {
......@@ -290,7 +290,7 @@ void AudioRtpRecordHandler::processDataDecode(unsigned char *spkrData, size_t si
mainBufferSampleRate, inSamples);
}
Manager::instance().getMainBuffer()->putData(out, outSamples * sizeof(SFLDataFormat), id_);
Manager::instance().getMainBuffer().putData(out, outSamples * sizeof(SFLDataFormat), id_);
}
#undef RETURN_IF_NULL
......
......@@ -356,7 +356,7 @@ void PulseLayer::writeToSpeaker()
applyGain(static_cast<SFLDataFormat *>(data), urgentBytes / sizeof(SFLDataFormat), getPlaybackGain());
pa_stream_write(s, data, urgentBytes, NULL, 0, PA_SEEK_RELATIVE);
// Consume the regular one as well (same amount of bytes)
Manager::instance().getMainBuffer()->discard(urgentBytes, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().discard(urgentBytes, MainBuffer::DEFAULT_ID);
return;
}
......@@ -375,7 +375,7 @@ void PulseLayer::writeToSpeaker()
flushUrgent(); // flush remaining samples in _urgentRingBuffer
size_t availSamples = Manager::instance().getMainBuffer()->availableForGet(MainBuffer::DEFAULT_ID) / sizeof(SFLDataFormat);
size_t availSamples = Manager::instance().getMainBuffer().availableForGet(MainBuffer::DEFAULT_ID) / sizeof(SFLDataFormat);
if (availSamples == 0) {
pa_stream_begin_write(s, &data, &writableBytes);
......@@ -392,7 +392,7 @@ void PulseLayer::writeToSpeaker()
double resampleFactor = 1.;
unsigned int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
unsigned int mainBufferSampleRate = Manager::instance().getMainBuffer().getInternalSamplingRate();
bool resample = sampleRate_ != mainBufferSampleRate;
if (resample) {
resampleFactor = (double) sampleRate_ / mainBufferSampleRate;
......@@ -404,7 +404,7 @@ void PulseLayer::writeToSpeaker()
size_t readableBytes = readableSamples * sizeof(SFLDataFormat);
pa_stream_begin_write(s, &data, &readableBytes);
Manager::instance().getMainBuffer()->getData(data, readableBytes, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().getData(data, readableBytes, MainBuffer::DEFAULT_ID);
if (resample) {
const size_t nResampled = (double) readableSamples * resampleFactor;
......@@ -432,7 +432,7 @@ void PulseLayer::readFromMic()
if (pa_stream_peek(record_->pulseStream() , (const void**) &data , &bytes) < 0 or !data)
return;
unsigned int mainBufferSampleRate = Manager::instance().getMainBuffer()->getInternalSamplingRate();
unsigned int mainBufferSampleRate = Manager::instance().getMainBuffer().getInternalSamplingRate();
bool resample = sampleRate_ != mainBufferSampleRate;
if (resample) {
......@@ -457,7 +457,7 @@ void PulseLayer::readFromMic()
dcblocker_.process(mic_buffer_, (SFLDataFormat*)data, samples);
applyGain(mic_buffer_, bytes / sizeof(SFLDataFormat), getCaptureGain());
Manager::instance().getMainBuffer()->putData(mic_buffer_, bytes, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().putData(mic_buffer_, bytes, MainBuffer::DEFAULT_ID);
#ifdef RECTODISK
outfileResampled.write((const char *)mic_buffer_, bytes);
#endif
......
......@@ -31,7 +31,7 @@
#include "manager.h"
#include "logger.h"
Recordable::Recordable() : recAudio_(), recorder_(&recAudio_, Manager::instance().getMainBuffer())
Recordable::Recordable() : recAudio_(), recorder_(&recAudio_, &Manager::instance().getMainBuffer())
{
DEBUG("Set recording options: %s", Manager::instance().audioPreference.getRecordPath().c_str());
recAudio_.setRecordingOption(AudioRecord::FILE_WAV, 8000, Manager::instance().audioPreference.getRecordPath());
......
......@@ -148,20 +148,20 @@ Call::setRecording()
bool recordStatus = Recordable::recAudio_.isRecording();
Recordable::recAudio_.setRecording();
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
MainBuffer &mbuffer = Manager::instance().getMainBuffer();
std::string process_id = Recordable::recorder_.getRecorderID();
if (!recordStatus) {
mbuffer->bindHalfDuplexOut(process_id, id_);
mbuffer->bindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
mbuffer.bindHalfDuplexOut(process_id, id_);
mbuffer.bindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
Recordable::recorder_.start();
} else {
mbuffer->unBindHalfDuplexOut(process_id, id_);
mbuffer->unBindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
mbuffer.unBindHalfDuplexOut(process_id, id_);
mbuffer.unBindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
}
Manager::instance().getMainBuffer()->dumpInfo();
Manager::instance().getMainBuffer().dumpInfo();
return recordStatus;
}
......
......@@ -69,9 +69,9 @@ void Conference::bindParticipant(const std::string &participant_id)
for (ParticipantSet::const_iterator iter = participants_.begin();
iter != participants_.end(); ++iter)
if (participant_id != *iter)
Manager::instance().getMainBuffer()->bindCallID(participant_id, *iter);
Manager::instance().getMainBuffer().bindCallID(participant_id, *iter);
Manager::instance().getMainBuffer()->bindCallID(participant_id, MainBuffer::DEFAULT_ID);
Manager::instance().getMainBuffer().bindCallID(participant_id, MainBuffer::DEFAULT_ID);
}
std::string Conference::getStateStr() const
......@@ -104,23 +104,23 @@ bool Conference::setRecording()
bool recordStatus = Recordable::recAudio_.isRecording();
Recordable::recAudio_.setRecording();
MainBuffer *mbuffer = Manager::instance().getMainBuffer();
MainBuffer &mbuffer = Manager::instance().getMainBuffer();
std::string process_id(Recordable::recorder_.getRecorderID());
// start recording
if (!recordStatus) {
for (ParticipantSet::const_iterator iter = participants_.begin(); iter != participants_.end(); ++iter)
mbuffer->bindHalfDuplexOut(process_id, *iter);
mbuffer.bindHalfDuplexOut(process_id, *iter);
mbuffer->bindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
mbuffer.bindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
Recordable::recorder_.start();
} else {
for (ParticipantSet::const_iterator iter = participants_.begin(); iter != participants_.end(); ++iter)
mbuffer->unBindHalfDuplexOut(process_id, *iter);
mbuffer.unBindHalfDuplexOut(process_id, *iter);
mbuffer->unBindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
mbuffer.unBindHalfDuplexOut(process_id, MainBuffer::DEFAULT_ID);
}
return recordStatus;
......
......@@ -126,7 +126,7 @@ void ManagerImpl::init(const std::string &config_file)
ost::MutexLock lock(audioLayerMutex_);
if (audiodriver_) {
telephoneTone_.reset(new TelephoneTone(preferences.getZoneToneChoice(), audiodriver_->getSampleRate()));
dtmfKey_.reset(new DTMF(getMainBuffer()->getInternalSamplingRate()));
dtmfKey_.reset(new DTMF(getMainBuffer().getInternalSamplingRate()));
}
}
......@@ -278,7 +278,7 @@ bool ManagerImpl::outgoingCall(const std::string& account_id,
return false;
}
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
return true;
}
......@@ -333,7 +333,7 @@ bool ManagerImpl::answerCall(const std::string& call_id)
// Connect streams
addStream(call_id);
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
// Start recording if set in preference
if (audioPreference.getIsAlwaysRecording())
......@@ -398,7 +398,7 @@ void ManagerImpl::hangupCall(const std::string& callId)
}
}
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
}
bool ManagerImpl::hangupConference(const std::string& id)
......@@ -424,7 +424,7 @@ bool ManagerImpl::hangupConference(const std::string& id)
unsetCurrentCall();
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
return true;
}
......@@ -470,7 +470,7 @@ void ManagerImpl::onHoldCall(const std::string& callId)
dbus_.getCallManager()->callStateChanged(callId, "HOLD");
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
}
//THREAD=Main
......@@ -519,7 +519,7 @@ void ManagerImpl::offHoldCall(const std::string& callId)
addStream(callId);
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
}
//THREAD=Main
......@@ -546,7 +546,7 @@ bool ManagerImpl::transferCall(const std::string& callId, const std::string& to)
// remove waiting call in case we make transfer without even answer
removeWaitingCall(callId);
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
return true;
}
......@@ -607,7 +607,7 @@ void ManagerImpl::refuseCall(const std::string& id)
// Disconnect streams
removeStream(id);
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
}
Conference*
......@@ -651,7 +651,7 @@ void ManagerImpl::removeConference(const std::string& conference_id)
// We now need to bind the audio to the remain participant
// Unbind main participant audio from conference
getMainBuffer()->unBindAll(MainBuffer::DEFAULT_ID);
getMainBuffer().unBindAll(MainBuffer::DEFAULT_ID);
ParticipantSet participants(conf->getParticipantList());
......@@ -659,7 +659,7 @@ void ManagerImpl::removeConference(const std::string& conference_id)
ParticipantSet::iterator iter_p = participants.begin();
if (iter_p != participants.end())
getMainBuffer()->bindCallID(*iter_p, MainBuffer::DEFAULT_ID);
getMainBuffer().bindCallID(*iter_p, MainBuffer::DEFAULT_ID);
// Then remove the conference from the conference map
if (conferenceMap_.erase(conference_id))
......@@ -791,7 +791,7 @@ void ManagerImpl::addParticipant(const std::string& callId, const std::string& c
conf->add(callId);
// Connect new audio streams together
getMainBuffer()->unBindAll(callId);
getMainBuffer().unBindAll(callId);
std::map<std::string, std::string> callDetails(getCallDetails(callId));
std::string callState(callDetails.find("CALL_STATE")->second);
......@@ -814,9 +814,9 @@ void ManagerImpl::addParticipant(const std::string& callId, const std::string& c
// flush conference participants only
for (ParticipantSet::const_iterator p = participants.begin();
p != participants.end(); ++p)
getMainBuffer()->flush(*p);
getMainBuffer().flush(*p);
getMainBuffer()->flush(MainBuffer::DEFAULT_ID);
getMainBuffer().flush(MainBuffer::DEFAULT_ID);
// Connect stream
addStream(callId);
......@@ -845,12 +845,12 @@ void ManagerImpl::addMainParticipant(const std::string& conference_id)
for (ParticipantSet::const_iterator iter_p = participants.begin();
iter_p != participants.end(); ++iter_p) {
getMainBuffer()->bindCallID(*iter_p, MainBuffer::DEFAULT_ID);
getMainBuffer().bindCallID(*iter_p, MainBuffer::DEFAULT_ID);
// Reset ringbuffer's readpointers
getMainBuffer()->flush(*iter_p);
getMainBuffer().flush(*iter_p);
}
getMainBuffer()->flush(MainBuffer::DEFAULT_ID);
getMainBuffer().flush(MainBuffer::DEFAULT_ID);
if (conf->getState() == Conference::ACTIVE_DETACHED)
conf->setState(Conference::ACTIVE_ATTACHED);
......@@ -925,10 +925,10 @@ void ManagerImpl::joinParticipant(const std::string& callId1, const std::string&
Conference *conf = createConference(callId1, callId2);
call1->setConfId(conf->getConfID());
getMainBuffer()->unBindAll(callId1);
getMainBuffer().unBindAll(callId1);
call2->setConfId(conf->getConfID());
getMainBuffer()->unBindAll(callId2);
getMainBuffer().unBindAll(callId2);
// Process call1 according to its state
std::string call1_state_str(call1Details.find("CALL_STATE")->second);
......@@ -977,7 +977,7 @@ void ManagerImpl::joinParticipant(const std::string& callId1, const std::string&
conf->setRecordingSmplRate(audiodriver_->getSampleRate());
}
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
}
void ManagerImpl::createConfFromParticipantList(const std::vector< std::string > &participantList)
......@@ -1029,7 +1029,7 @@ void ManagerImpl::createConfFromParticipantList(const std::vector< std::string >
conf->setRecordingSmplRate(audiodriver_->getSampleRate());
}
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
} else {
delete conf;
}
......@@ -1075,7 +1075,7 @@ void ManagerImpl::detachParticipant(const std::string& call_id,
}
} else {
DEBUG("Unbind main participant from conference %d");
getMainBuffer()->unBindAll(MainBuffer::DEFAULT_ID);
getMainBuffer().unBindAll(MainBuffer::DEFAULT_ID);
if (not isConference(current_call_id)) {
ERROR("Current call id (%s) is not a conference", current_call_id.c_str());
......@@ -1127,7 +1127,7 @@ void ManagerImpl::removeParticipant(const std::string& call_id)
call->setConfId("");
removeStream(call_id);
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
dbus_.getCallManager()->conferenceChanged(conf->getConfID(), conf->getStateStr());
processRemainingParticipants(*conf);
}
......@@ -1144,9 +1144,9 @@ void ManagerImpl::processRemainingParticipants(Conference &conf)
// Reset ringbuffer's readpointers
for (ParticipantSet::const_iterator p = participants.begin();
p != participants.end(); ++p)
getMainBuffer()->flush(*p);
getMainBuffer().flush(*p);
getMainBuffer()->flush(MainBuffer::DEFAULT_ID);
getMainBuffer().flush(MainBuffer::DEFAULT_ID);
} else if (n == 1) {
// this call is the last participant, hence
// the conference is over
......@@ -1217,30 +1217,30 @@ void ManagerImpl::addStream(const std::string& call_id)
// reset ring buffer for all conference participant
for (ParticipantSet::const_iterator iter_p = participants.begin();
iter_p != participants.end(); ++iter_p)
getMainBuffer()->flush(*iter_p);
getMainBuffer().flush(*iter_p);
getMainBuffer()->flush(MainBuffer::DEFAULT_ID);
getMainBuffer().flush(MainBuffer::DEFAULT_ID);
}
} else {
DEBUG("Add stream to call");
// bind to main
getMainBuffer()->bindCallID(call_id, MainBuffer::DEFAULT_ID);
getMainBuffer().bindCallID(call_id, MainBuffer::DEFAULT_ID);
ost::MutexLock lock(audioLayerMutex_);
audiodriver_->flushUrgent();
audiodriver_->flushMain();
}
getMainBuffer()->dumpInfo();
getMainBuffer().dumpInfo();
}
void ManagerImpl::removeStream(const std::string& call_id)
{
DEBUG("Remove audio stream %s", call_id.c_str());
getMainBuffer()->unBindAll(call_id);
getMainBuffer()->dumpInfo();
getMainBuffer().unBindAll(call_id);
getMainBuffer().dumpInfo();
}
//THREAD=Main
......
......@@ -1026,8 +1026,8 @@ class ManagerImpl {
/**
* Return a pointer to the instance of the mainbuffer
*/
MainBuffer *getMainBuffer() {
return &mainBuffer_;
MainBuffer &getMainBuffer() {
return mainBuffer_;
}
/**
......
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