Commit 246e3032 authored by Guillaume Roguez's avatar Guillaume Roguez Committed by Tristan Matthews

daemon: rename mainbuffer to ringbufferpool

Refs #52750

Change-Id: I8f101c8c3d2ac284b65373920b31d924c123d822
parent 1f4107a1
......@@ -29,7 +29,7 @@ libaudio_la_SOURCES = \
audiobuffer.cpp \
audioloop.cpp \
ringbuffer.cpp \
mainbuffer.cpp \
ringbufferpool.cpp \
audiorecord.cpp \
audiorecorder.cpp \
recordable.cpp \
......@@ -42,7 +42,7 @@ noinst_HEADERS = \
audiobuffer.h \
audioloop.h \
ringbuffer.h \
mainbuffer.h \
ringbufferpool.h \
audiorecord.h \
audiorecorder.h \
audiolayer.h \
......
......@@ -35,6 +35,7 @@
#include "manager.h"
#include "noncopyable.h"
#include "client/configurationmanager.h"
#include "audio/ringbufferpool.h"
#include "audio/ringbuffer.h"
#include <thread>
......@@ -158,7 +159,7 @@ AlsaLayer::AlsaLayer(const AudioPreference &pref)
, is_playback_open_(false)
, is_capture_open_(false)
, audioThread_(nullptr)
, mainRingBuffer_(Manager::instance().getMainBuffer().getRingBuffer(MainBuffer::DEFAULT_ID))
, mainRingBuffer_(Manager::instance().getRingBufferPool().getRingBuffer(RingBufferPool::DEFAULT_ID))
{}
AlsaLayer::~AlsaLayer()
......@@ -674,7 +675,7 @@ AlsaLayer::getAudioDeviceName(int index, DeviceType type) const
void AlsaLayer::capture()
{
AudioFormat mainBufferFormat = Manager::instance().getMainBuffer().getInternalAudioFormat();
AudioFormat mainBufferFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat();
int toGetFrames = snd_pcm_avail_update(captureHandle_);
......@@ -713,7 +714,7 @@ void AlsaLayer::capture()
void AlsaLayer::playback(int maxFrames)
{
unsigned framesToGet = Manager::instance().getMainBuffer().availableForGet(MainBuffer::DEFAULT_ID);
unsigned framesToGet = Manager::instance().getRingBufferPool().availableForGet(RingBufferPool::DEFAULT_ID);
// no audio available, play tone or silence
if (framesToGet <= 0) {
......@@ -736,7 +737,7 @@ void AlsaLayer::playback(int maxFrames)
write(playbackIBuff_.data(), playbackBuff_.frames(), playbackHandle_);
} else {
// play the regular sound samples
const AudioFormat mainBufferFormat = Manager::instance().getMainBuffer().getInternalAudioFormat();
const AudioFormat mainBufferFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat();
const bool resample = audioFormat_.sample_rate != mainBufferFormat.sample_rate;
double resampleFactor = 1.0;
......@@ -752,7 +753,7 @@ void AlsaLayer::playback(int maxFrames)
playbackBuff_.setFormat(mainBufferFormat);
playbackBuff_.resize(framesToGet);
Manager::instance().getMainBuffer().getData(playbackBuff_, MainBuffer::DEFAULT_ID);
Manager::instance().getRingBufferPool().getData(playbackBuff_, RingBufferPool::DEFAULT_ID);
playbackBuff_.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
if (audioFormat_.nb_channels != mainBufferFormat.nb_channels) {
......@@ -785,19 +786,19 @@ void AlsaLayer::audioCallback()
if (not safeUpdate(playbackHandle_, playbackAvailFrames))
return;
unsigned framesToGet = urgentRingBuffer_.availableForGet(MainBuffer::DEFAULT_ID);
unsigned framesToGet = urgentRingBuffer_.availableForGet(RingBufferPool::DEFAULT_ID);
if (framesToGet > 0) {
// Urgent data (dtmf, incoming call signal) come first.
framesToGet = std::min(framesToGet, (unsigned)playbackAvailFrames);
playbackBuff_.setFormat(audioFormat_);
playbackBuff_.resize(framesToGet);
urgentRingBuffer_.get(playbackBuff_, MainBuffer::DEFAULT_ID);
urgentRingBuffer_.get(playbackBuff_, RingBufferPool::DEFAULT_ID);
playbackBuff_.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
playbackBuff_.interleave(playbackIBuff_);
write(playbackIBuff_.data(), framesToGet, playbackHandle_);
// Consume the regular one as well (same amount of frames)
Manager::instance().getMainBuffer().discard(framesToGet, MainBuffer::DEFAULT_ID);
Manager::instance().getRingBufferPool().discard(framesToGet, RingBufferPool::DEFAULT_ID);
} else {
// regular audio data
playback(playbackAvailFrames);
......
......@@ -33,6 +33,7 @@
#include "audio/dcblocker.h"
#include "logger.h"
#include "manager.h"
#include "audio/ringbufferpool.h"
#include <ctime>
......@@ -42,14 +43,14 @@ AudioLayer::AudioLayer(const AudioPreference &pref)
, captureGain_(pref.getVolumemic())
, playbackGain_(pref.getVolumespkr())
, isStarted_(false)
, audioFormat_(Manager::instance().getMainBuffer().getInternalAudioFormat())
, audioFormat_(Manager::instance().getRingBufferPool().getInternalAudioFormat())
, urgentRingBuffer_("urgentRingBuffer_id", SIZEBUF, audioFormat_)
, mutex_()
, dcblocker_()
, resampler_(audioFormat_.sample_rate)
, lastNotificationTime_(0)
{
urgentRingBuffer_.createReadOffset(MainBuffer::DEFAULT_ID);
urgentRingBuffer_.createReadOffset(RingBufferPool::DEFAULT_ID);
}
AudioLayer::~AudioLayer()
......@@ -68,7 +69,7 @@ void AudioLayer::flushMain()
{
std::lock_guard<std::mutex> lock(mutex_);
// should pass call id
Manager::instance().getMainBuffer().flushAllBuffers();
Manager::instance().getRingBufferPool().flushAllBuffers();
}
void AudioLayer::flushUrgent()
......
......@@ -49,7 +49,6 @@
* @brief Main sound class. Manages the data transfers between the application and the hardware.
*/
class MainBuffer;
class AudioPreference;
namespace ost {
......
......@@ -30,7 +30,7 @@
#include "audiorecorder.h"
#include "audiorecord.h"
#include "mainbuffer.h"
#include "ringbufferpool.h"
#include "logger.h"
#include <chrono>
......@@ -39,8 +39,9 @@
int AudioRecorder::count_ = 0;
AudioRecorder::AudioRecorder(AudioRecord *arec, MainBuffer &mb) :
recorderId_(), mbuffer_(mb), arecord_(arec), running_(false), thread_()
AudioRecorder::AudioRecorder(AudioRecord *arec, RingBufferPool &rbp)
: recorderId_(), ringBufferPool_(rbp), arecord_(arec), running_(false)
, thread_()
{
++count_;
......@@ -65,7 +66,7 @@ AudioRecorder::~AudioRecorder()
void AudioRecorder::init() {
if (!arecord_->isRecording()) {
arecord_->setSndFormat(mbuffer_.getInternalAudioFormat());
arecord_->setSndFormat(ringBufferPool_.getInternalAudioFormat());
}
}
......@@ -84,12 +85,12 @@ void AudioRecorder::run()
static const size_t BUFFER_LENGTH = 10000;
static const std::chrono::milliseconds SLEEP_TIME(20); // 20 ms
AudioBuffer buffer(BUFFER_LENGTH, mbuffer_.getInternalAudioFormat());
AudioBuffer buffer(BUFFER_LENGTH, ringBufferPool_.getInternalAudioFormat());
while (running_) {
const size_t availableSamples = mbuffer_.availableForGet(recorderId_);
const size_t availableSamples = ringBufferPool_.availableForGet(recorderId_);
buffer.resize(std::min(availableSamples, BUFFER_LENGTH));
mbuffer_.getData(buffer, recorderId_);
ringBufferPool_.getData(buffer, recorderId_);
if (availableSamples > 0)
arecord_->recData(buffer);
......
......@@ -37,13 +37,13 @@
#include <atomic>
#include <string>
class MainBuffer;
class RingBufferPool;
class AudioRecord;
class AudioRecorder {
public:
AudioRecorder(AudioRecord *arec, MainBuffer &mb);
AudioRecorder(AudioRecord *arec, RingBufferPool &rbp);
~AudioRecorder();
std::string getRecorderID() const {
return recorderId_;
......@@ -66,7 +66,7 @@ class AudioRecorder {
static int count_;
std::string recorderId_;
MainBuffer &mbuffer_;
RingBufferPool &ringBufferPool_;
AudioRecord *arecord_;
std::atomic<bool> running_;
std::thread thread_;
......
......@@ -133,9 +133,11 @@ class AudioRtpFactory {
void setDtmfPayloadType(unsigned int);
/**
* Send DTMF over RTP (RFC2833). The timestamp and sequence number must be
* incremented as if it was microphone audio. This function change the payload type of the rtp session,
* send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get
* Send DTMF over RTP (RFC2833).
* The timestamp and sequence number must be incremented
* as if it was microphone audio. This function change the payload type
* of the rtp session, send the appropriate DTMF digit using
* this payload, discard corresponding data from RingBufferPool and get
* back the codec payload for further audio processing.
*/
void sendDtmfDigit(int digit);
......
......@@ -141,9 +141,11 @@ class AudioRtpSession {
virtual void startRTPLoop() = 0;
/**
* Send DTMF over RTP (RFC2833). The timestamp and sequence number must be
* incremented as if it was microphone audio. This function change the payload type of the rtp session,
* send the appropriate DTMF digit using this payload, discard coresponding data from mainbuffer and get
* Send DTMF over RTP (RFC2833).
* The timestamp and sequence number must be incremented
* as if it was microphone audio. This function change the payload type
* of the rtp session, send the appropriate DTMF digit using
* this payload, discard corresponding data from RingBufferPool and get
* back the codec payload for further audio processing.
*/
void sendDtmfEvent();
......
......@@ -36,6 +36,7 @@
#include "audio/audiolayer.h"
#include "audio/resampler.h"
#include "audio/ringbufferpool.h"
#include "audio/ringbuffer.h"
#if HAVE_SPEEXDSP
......@@ -69,7 +70,7 @@ AudioRtpStream::AudioRtpStream(const std::string &id) :
, plcPool_(nullptr)
, plcDec_()
{
ringbuffer_ = Manager::instance().getMainBuffer().createRingBuffer(id_);
ringbuffer_ = Manager::instance().getRingBufferPool().createRingBuffer(id_);
pj_caching_pool_init(&plcCachePool_, &pj_pool_factory_default_policy, 0);
plcPool_ = pj_pool_create(&plcCachePool_.factory, "plc", 64, 1024, nullptr);
}
......@@ -131,7 +132,7 @@ bool AudioRtpStream::tryToSwitchDecoder(int newPt)
for (unsigned i=0, n=audioCodecs_.size(); i<n; i++) {
auto codec = audioCodecs_[i];
if (codec == nullptr || codec->getPayloadType() != newPt) continue;
AudioFormat f = Manager::instance().getMainBuffer().getInternalAudioFormat();
AudioFormat f = Manager::instance().getRingBufferPool().getInternalAudioFormat();
codec->setOptimalFormat(f.sample_rate, f.nb_channels);
decoder_.payloadType_ = codec->getPayloadType();
decoder_.frameSize_ = codec->getFrameSize();
......@@ -250,7 +251,7 @@ void AudioRtpStream::setRtpMedia(const std::vector<AudioCodec*> &audioCodecs)
currentEncoderIndex_ = currentDecoderIndex_ = 0;
AudioCodec& codec = *audioCodecs[currentEncoderIndex_];
AudioFormat f = Manager::instance().getMainBuffer().getInternalAudioFormat();
AudioFormat f = Manager::instance().getRingBufferPool().getInternalAudioFormat();
codec.setOptimalFormat(f.sample_rate, f.nb_channels);
const int pt = codec.getPayloadType();
......@@ -288,7 +289,7 @@ void AudioRtpStream::resetDSP()
bool AudioRtpStream::waitForDataEncode(const std::chrono::milliseconds& max_wait) const
{
const auto &mainBuffer = Manager::instance().getMainBuffer();
const auto &mainBuffer = Manager::instance().getRingBufferPool();
const AudioFormat mainBuffFormat = mainBuffer.getInternalAudioFormat();
const double resampleFactor = (double) mainBuffFormat.sample_rate / encoder_.format_.sample_rate;
const size_t samplesToGet = resampleFactor * encoder_.frameSize_;
......@@ -301,22 +302,23 @@ size_t AudioRtpStream::processDataEncode()
if (isDead())
return 0;
AudioFormat mainBuffFormat = Manager::instance().getMainBuffer().getInternalAudioFormat();
AudioFormat mainBuffFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat();
double resampleFactor = (double) mainBuffFormat.sample_rate / encoder_.format_.sample_rate;
// compute nb of byte to get corresponding to 1 audio frame
const size_t samplesToGet = resampleFactor * encoder_.frameSize_;
if (Manager::instance().getMainBuffer().availableForGet(id_) < samplesToGet)
if (Manager::instance().getRingBufferPool().availableForGet(id_) < samplesToGet)
return 0;
micData_.setFormat(mainBuffFormat);
micData_.resize(samplesToGet);
const size_t samples = Manager::instance().getMainBuffer().getData(micData_, id_);
const size_t samples = Manager::instance().getRingBufferPool().getData(micData_, id_);
if (samples != samplesToGet) {
ERROR("Asked for %d samples from mainbuffer, got %d", samplesToGet, samples);
ERROR("Asked for %d samples from bindings on call '%s', got %d",
samplesToGet, id_.c_str(), samples);
return 0;
}
......@@ -416,7 +418,7 @@ void AudioRtpStream::processDataDecode(unsigned char *spkrData, size_t size, int
// test if resampling or up/down-mixing is required
AudioBuffer *out = &rawBuffer_;
AudioFormat decFormat = out->getFormat();
AudioFormat mainBuffFormat = Manager::instance().getMainBuffer().getInternalAudioFormat();
AudioFormat mainBuffFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat();
if (decFormat.sample_rate != mainBuffFormat.sample_rate) {
if (!decoder_.resampler_) {
ERROR("Resampler already destroyed");
......
......@@ -107,12 +107,12 @@ class AudioRtpStream {
void processDataDecode(uint8_t *spkrData, size_t size, int payloadType);
/**
* Wait for available data to be encoded from mainbuffer.
* Wait for available data to be encoded from RingBufferPool.
*/
bool waitForDataEncode(const std::chrono::milliseconds& max_wait) const;
/**
* Encode audio data from mainbuffer
* Encode audio data from RingBufferPool
* @return size of encoded data, in bytes.
*/
size_t processDataEncode();
......
......@@ -36,7 +36,7 @@
#include <cassert>
#include <climits>
#include "logger.h"
#include "audio/mainbuffer.h"
#include "audio/ringbufferpool.h"
#include "audio/ringbuffer.h"
#include "manager.h"
#include "array_size.h"
......@@ -83,19 +83,19 @@ void JackLayer::fillWithUrgent(AudioBuffer &buffer, size_t samplesToGet)
// Urgent data (dtmf, incoming call signal) come first.
samplesToGet = std::min(samplesToGet, hardwareBufferSize_);
buffer.resize(samplesToGet);
urgentRingBuffer_.get(buffer, MainBuffer::DEFAULT_ID);
urgentRingBuffer_.get(buffer, RingBufferPool::DEFAULT_ID);
buffer.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
// Consume the regular one as well (same amount of samples)
Manager::instance().getMainBuffer().discard(samplesToGet, MainBuffer::DEFAULT_ID);
Manager::instance().getRingBufferPool().discard(samplesToGet, RingBufferPool::DEFAULT_ID);
}
void JackLayer::fillWithVoice(AudioBuffer &buffer, size_t samplesAvail)
{
MainBuffer &mainBuffer = Manager::instance().getMainBuffer();
RingBufferPool &mainBuffer = Manager::instance().getRingBufferPool();
buffer.resize(samplesAvail);
mainBuffer.getData(buffer, MainBuffer::DEFAULT_ID);
mainBuffer.getData(buffer, RingBufferPool::DEFAULT_ID);
buffer.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
if (audioFormat_.sample_rate != (unsigned) mainBuffer.getInternalSamplingRate()) {
......@@ -129,8 +129,8 @@ JackLayer::playback()
{
notifyIncomingCall();
const size_t samplesToGet = Manager::instance().getMainBuffer().availableForGet(MainBuffer::DEFAULT_ID);
const size_t urgentSamplesToGet = urgentRingBuffer_.availableForGet(MainBuffer::DEFAULT_ID);
const size_t samplesToGet = Manager::instance().getRingBufferPool().availableForGet(RingBufferPool::DEFAULT_ID);
const size_t urgentSamplesToGet = urgentRingBuffer_.availableForGet(RingBufferPool::DEFAULT_ID);
if (urgentSamplesToGet > 0) {
fillWithUrgent(playbackBuffer_, urgentSamplesToGet);
......@@ -152,7 +152,7 @@ JackLayer::capture()
// get audio from jack ringbuffer
read(captureBuffer_);
const AudioFormat mainBufferFormat = Manager::instance().getMainBuffer().getInternalAudioFormat();
const AudioFormat mainBufferFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat();
const bool resample = mainBufferFormat.sample_rate != audioFormat_.sample_rate;
captureBuffer_.applyGain(isCaptureMuted_ ? 0.0 : captureGain_);
......@@ -326,7 +326,7 @@ JackLayer::JackLayer(const AudioPreference &p) :
captureBuffer_(0, audioFormat_),
captureFloatBuffer_(),
hardwareBufferSize_(0),
mainRingBuffer_(Manager::instance().getMainBuffer().getRingBuffer(MainBuffer::DEFAULT_ID))
mainRingBuffer_(Manager::instance().getRingBufferPool().getRingBuffer(RingBufferPool::DEFAULT_ID))
{
playbackClient_ = jack_client_open(PACKAGE_NAME,
(jack_options_t) (JackNullOption | JackNoStartServer), NULL);
......
......@@ -33,7 +33,7 @@
#include "client/configurationmanager.h"
#include "manager.h"
#include "audio/mainbuffer.h"
#include "audio/ringbufferpool.h"
#include "audio/ringbuffer.h"
#include "audio/dcblocker.h"
#include "logger.h"
......@@ -77,7 +77,7 @@ OpenSLLayer::OpenSLLayer(const AudioPreference &pref)
, hardwareBuffSize_(BUFFER_SIZE)
, playbackBufferStack_(ANDROID_BUFFER_QUEUE_LENGTH, AudioBuffer(hardwareBuffSize_, AudioFormat::MONO()))
, recordBufferStack_(ANDROID_BUFFER_QUEUE_LENGTH, AudioBuffer(hardwareBuffSize_, AudioFormat::MONO()))
, mainRingBuffer_(Manager::instance().getMainBuffer().getRingBuffer(MainBuffer::DEFAULT_ID))
, mainRingBuffer_(Manager::instance().getRingBufferPool().getRingBuffer(RingBufferPool::DEFAULT_ID))
{
}
......@@ -345,7 +345,7 @@ OpenSLLayer::initAudioCapture() const
};
DEBUG("Capture-> Sampling Rate: %d", audioFormat_.sample_rate);
DEBUG("Capture-> getInternalSamplingRate: %d", Manager::instance().getMainBuffer().getInternalSamplingRate());
DEBUG("Capture-> getInternalSamplingRate: %d", Manager::instance().getRingBufferPool().getInternalSamplingRate());
SLDataFormat_PCM audioFormat = {SL_DATAFORMAT_PCM, 1,
audioFormat_.sample_rate * 1000,
SL_PCMSAMPLEFORMAT_FIXED_16,
......@@ -638,13 +638,13 @@ OpenSLLayer::playback(SLAndroidSimpleBufferQueueItf queue)
notifyIncomingCall();
AudioBuffer &buffer = getNextPlaybackBuffer();
size_t urgentSamplesToGet = urgentRingBuffer_.availableForGet(MainBuffer::DEFAULT_ID);
size_t urgentSamplesToGet = urgentRingBuffer_.availableForGet(RingBufferPool::DEFAULT_ID);
bufferIsFilled_ = false;
if (urgentSamplesToGet > 0) {
bufferIsFilled_ = audioPlaybackFillWithUrgent(buffer, std::min(urgentSamplesToGet, hardwareBuffSize_));
} else {
auto& main_buffer = Manager::instance().getMainBuffer();
auto& main_buffer = Manager::instance().getRingBufferPool();
buffer.resize(hardwareBuffSize_);
size_t samplesToGet = audioPlaybackFillWithVoice(buffer);
if (samplesToGet == 0) {
......@@ -716,7 +716,7 @@ OpenSLLayer::updatePreference(AudioPreference &preference, int index, DeviceType
void OpenSLLayer::audioCaptureFillBuffer(AudioBuffer &buffer)
{
MainBuffer &mbuffer = Manager::instance().getMainBuffer();
RingBufferPool &mbuffer = Manager::instance().getRingBufferPool();
//const unsigned mainBufferSampleRate = mbuffer.getInternalSamplingRate();
const AudioFormat mainBufferFormat = mbuffer.getInternalAudioFormat();
......@@ -760,19 +760,19 @@ bool OpenSLLayer::audioPlaybackFillWithUrgent(AudioBuffer &buffer, size_t sample
// Urgent data (dtmf, incoming call signal) come first.
samplesToGet = std::min(samplesToGet, hardwareBuffSize_);
buffer.resize(samplesToGet);
urgentRingBuffer_.get(buffer, MainBuffer::DEFAULT_ID);
urgentRingBuffer_.get(buffer, RingBufferPool::DEFAULT_ID);
buffer.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
// Consume the regular one as well (same amount of samples)
Manager::instance().getMainBuffer().discard(samplesToGet, MainBuffer::DEFAULT_ID);
Manager::instance().getRingBufferPool().discard(samplesToGet, RingBufferPool::DEFAULT_ID);
return true;
}
size_t OpenSLLayer::audioPlaybackFillWithVoice(AudioBuffer &buffer)
{
MainBuffer &mainBuffer = Manager::instance().getMainBuffer();
size_t got = mainBuffer.getAvailableData(buffer, MainBuffer::DEFAULT_ID);
RingBufferPool &mainBuffer = Manager::instance().getRingBufferPool();
size_t got = mainBuffer.getAvailableData(buffer, RingBufferPool::DEFAULT_ID);
buffer.resize(got);
buffer.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
if (audioFormat_.sample_rate != mainBuffer.getInternalSamplingRate()) {
......
......@@ -38,6 +38,7 @@
#include "pulselayer.h"
#include "audio/resampler.h"
#include "audio/dcblocker.h"
#include "audio/ringbufferpool.h"
#include "audio/ringbuffer.h"
#include "logger.h"
#include "manager.h"
......@@ -103,7 +104,7 @@ PulseLayer::PulseLayer(AudioPreference &pref)
, enumeratingSinks_(false)
, enumeratingSources_(false)
, preference_(pref)
, mainRingBuffer_(Manager::instance().getMainBuffer().getRingBuffer(MainBuffer::DEFAULT_ID))
, mainRingBuffer_(Manager::instance().getRingBufferPool().getRingBuffer(RingBufferPool::DEFAULT_ID))
{
setCaptureGain(pref.getVolumemic());
setPlaybackGain(pref.getVolumespkr());
......@@ -464,7 +465,7 @@ void PulseLayer::writeToSpeaker()
notifyIncomingCall();
size_t urgentSamples = urgentRingBuffer_.availableForGet(MainBuffer::DEFAULT_ID);
size_t urgentSamples = urgentRingBuffer_.availableForGet(RingBufferPool::DEFAULT_ID);
size_t urgentBytes = urgentSamples * sample_size;
if (urgentSamples > writableSamples) {
......@@ -477,12 +478,12 @@ void PulseLayer::writeToSpeaker()
if (urgentBytes) {
AudioBuffer linearbuff(urgentSamples, format);
pa_stream_begin_write(s, (void**)&data, &urgentBytes);
urgentRingBuffer_.get(linearbuff, MainBuffer::DEFAULT_ID); // retrive only the first sample_spec->channels channels
urgentRingBuffer_.get(linearbuff, RingBufferPool::DEFAULT_ID); // retrive only the first sample_spec->channels channels
linearbuff.applyGain(isPlaybackMuted_ ? 0.0 : playbackGain_);
linearbuff.interleave(data);
pa_stream_write(s, data, urgentBytes, nullptr, 0, PA_SEEK_RELATIVE);
// Consume the regular one as well (same amount of samples)
Manager::instance().getMainBuffer().discard(urgentSamples, MainBuffer::DEFAULT_ID);
Manager::instance().getRingBufferPool().discard(urgentSamples, RingBufferPool::DEFAULT_ID);
return;
}
......@@ -504,7 +505,7 @@ void PulseLayer::writeToSpeaker()
flushUrgent(); // flush remaining samples in _urgentRingBuffer
size_t availSamples = Manager::instance().getMainBuffer().availableForGet(MainBuffer::DEFAULT_ID);
size_t availSamples = Manager::instance().getRingBufferPool().availableForGet(RingBufferPool::DEFAULT_ID);
if (availSamples == 0) {
pa_stream_begin_write(s, (void**)&data, &writableBytes);
......@@ -518,7 +519,7 @@ void PulseLayer::writeToSpeaker()
double resampleFactor = 1.;
AudioFormat mainBufferAudioFormat = Manager::instance().getMainBuffer().getInternalAudioFormat();
AudioFormat mainBufferAudioFormat = Manager::instance().getRingBufferPool().getInternalAudioFormat();
bool resample = audioFormat_.sample_rate != mainBufferAudioFormat.sample_rate;
if (resample) {
......@@ -533,7 +534,7 @@ void PulseLayer::writeToSpeaker()
pa_stream_begin_write(s, (void**)&data, &resampledBytes);
AudioBuffer linearbuff(readableSamples, format);
Manager::instance().getMainBuffer().getData(linearbuff, MainBuffer::DEFAULT_ID);
Manager::instance().getRingBufferPool().getData(linearbuff, RingBufferPool::DEFAULT_ID);
if (resample) {
AudioBuffer rsmpl_out(nResampled, format);
......@@ -569,7 +570,7 @@ void PulseLayer::readFromMic()
AudioBuffer in(samples, format);
in.deinterleave((SFLAudioSample*)data, samples, format.nb_channels);
unsigned int mainBufferSampleRate = Manager::instance().getMainBuffer().getInternalSamplingRate();
unsigned int mainBufferSampleRate = Manager::instance().getRingBufferPool().getInternalSamplingRate();
bool resample = audioFormat_.sample_rate != mainBufferSampleRate;
in.applyGain(isCaptureMuted_ ? 0.0 : captureGain_);
......
......@@ -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().getRingBufferPool())
{
DEBUG("Set recording options: %s", Manager::instance().audioPreference.getRecordPath().c_str());
recAudio_.setRecordingOptions(AudioFormat::MONO(), Manager::instance().audioPreference.getRecordPath());
......
/*
* Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
* Author : Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
* Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -28,7 +29,7 @@
* as that of the covered work.
*/
#include "mainbuffer.h"
#include "ringbufferpool.h"
#include "ringbuffer.h"
#include "sfl_types.h" // for SIZEBUF
#include "logger.h"
......@@ -37,12 +38,13 @@
#include <utility> // for std::pair
#include <cstring>
const char * const MainBuffer::DEFAULT_ID = "audiolayer_id";
const char * const RingBufferPool::DEFAULT_ID = "audiolayer_id";
MainBuffer::MainBuffer() : defaultRingBuffer_(createRingBuffer(DEFAULT_ID))
RingBufferPool::RingBufferPool()
: defaultRingBuffer_(createRingBuffer(DEFAULT_ID))
{}
MainBuffer::~MainBuffer()
RingBufferPool::~RingBufferPool()
{
readBindingsMap_.clear();
defaultRingBuffer_.reset();
......@@ -57,7 +59,7 @@ MainBuffer::~MainBuffer()
}
void
MainBuffer::setInternalSamplingRate(unsigned sr)
RingBufferPool::setInternalSamplingRate(unsigned sr)
{
std::lock_guard<std::recursive_mutex> lk(stateLock_);
......@@ -68,7 +70,7 @@ MainBuffer::setInternalSamplingRate(unsigned sr)
}
void
MainBuffer::setInternalAudioFormat(AudioFormat format)
RingBufferPool::setInternalAudioFormat(AudioFormat format)
{
std::lock_guard<std::recursive_mutex> lk(stateLock_);
......@@ -79,7 +81,7 @@ MainBuffer::setInternalAudioFormat(AudioFormat format)
}
std::shared_ptr<RingBuffer>
MainBuffer::getRingBuffer(const std::string& id)
RingBufferPool::getRingBuffer(const std::string& id)
{
std::lock_guard<std::recursive_mutex> lk(stateLock_);
......@@ -94,7 +96,7 @@ MainBuffer::getRingBuffer(const std::string& id)
}
std::shared_ptr<RingBuffer>
MainBuffer::getRingBuffer(const std::string& id) const
RingBufferPool::getRingBuffer(const std::string& id) const
{
std::lock_guard<std::recursive_mutex> lk(stateLock_);
......@@ -106,7 +108,7 @@ MainBuffer::getRingBuffer(const std::string& id) const
}
std::shared_ptr<RingBuffer>
MainBuffer::createRingBuffer(const std::string& id)
RingBufferPool::createRingBuffer(const std::string& id)
{
std::lock_guard<std::recursive_mutex> lk(stateLock_);
......@@ -122,22 +124,22 @@ MainBuffer::createRingBuffer(const std::string& id)
return rbuf;
}
const MainBuffer::ReadBindings*
MainBuffer::getReadBindings(const std::string& call_id) const
const RingBufferPool::ReadBindings*
RingBufferPool::getReadBindings(const std::string& call_id) const
{
const auto& iter = readBindingsMap_.find(call_id);
return iter != readBindingsMap_.cend() ? &iter->second : nullptr;
}
MainBuffer::ReadBindings*
MainBuffer::getReadBindings(const std::string& call_id)
RingBufferPool::ReadBindings*
RingBufferPool::getReadBindings(const std::string& call_id)
{
const auto& iter = readBindingsMap_.find(call_id);
return iter != readBindingsMap_.cend() ? &iter->second : nullptr;
}
void
MainBuffer::removeReadBindings(const std::string& call_id)
RingBufferPool::removeReadBindings(const std::string& call_id)
{
if (not readBindingsMap_.erase(call_id))
ERROR("CallID set %s does not exist!", call_id.c_str());
......@@ -147,7 +149,7 @@ MainBuffer::removeReadBindings(const std::string& call_id)
* Make given call ID a reader of given ring buffer
*/
void
MainBuffer::addReaderToRingBuffer(std::shared_ptr<RingBuffer> rbuf,
RingBufferPool::addReaderToRingBuffer(std::shared_ptr<RingBuffer> rbuf,
const std::string& call_id)
{
if (call_id != DEFAULT_ID and rbuf->id == call_id)
......@@ -159,7 +161,7 @@ MainBuffer::addReaderToRingBuffer(std::shared_ptr<RingBuffer> rbuf,
}
void
MainBuffer::removeReaderFromRingBuffer(std::shared_ptr<RingBuffer> rbuf,
RingBufferPool::removeReaderFromRingBuffer(std::shared_ptr<RingBuffer> rbuf,
const std::string& call_id)
{
if (auto bindings = getReadBindings(call_id)) {
......@@ -172,7 +174,8 @@ MainBuffer::removeReaderFromRingBuffer(std::shared_ptr<RingBuffer> rbuf,
}
void
MainBuffer::bindCallID(const std::string& call_id1, const std::string& call_id2)
RingBufferPool::bindCallID(const std::string& call_id1,
const std::string& call_id2)
{
const auto& rb_call1 = getRingBuffer(call_id1);
if (not rb_call1) {
......@@ -193,7 +196,7 @@ MainBuffer::bindCallID(const std::string& call_id1, const std::string& call_id2)
}
void
MainBuffer::bindHalfDuplexOut(const std::string& process_id,
RingBufferPool::bindHalfDuplexOut(const std::string& process_id,
const std::string& call_id)
{
/* This method is used only for active calls, if this call does not exist,
......@@ -206,7 +209,7 @@ MainBuffer::bindHalfDuplexOut(const std::string& process_id,
}
void
MainBuffer::unBindCallID(const std::string& call_id1,
RingBufferPool::unBindCallID(const std::string& call_id1,
const std::string& call_id2)
{
const auto& rb_call1 = getRingBuffer(call_id1);
......@@ -228,7 +231,7 @@ MainBuffer::unBindCallID(const std::string& call_id1,
}
void
MainBuffer::unBindHalfDuplexOut(const std::string& process_id,
RingBufferPool::unBindHalfDuplexOut(const std::string& process_id,
const std::string& call_id)
{
std::lock_guard<std::recursive_mutex> lk(stateLock_);
......@@ -238,7 +241,7 @@ MainBuffer::unBindHalfDuplexOut(const std::string& process_id,
}
void
MainBuffer::unBindAll(const std::string& call_id)