Commit 83e739c9 authored by Philippe Groarke's avatar Philippe Groarke Committed by Tristan Matthews

daemon: use sfl namespace for audio

Avoids conflict with AudioBuffer from CoreAudio

Refs #57980

Change-Id: I5eaae38ae376cb8c51d33cf266f42a35cfdde766
parent 0f4ca098
......@@ -42,6 +42,8 @@
#include <thread>
#include <atomic>
namespace sfl {
class AlsaThread {
public:
AlsaThread(AlsaLayer *alsa);
......@@ -848,3 +850,5 @@ void AlsaLayer::updatePreference(AudioPreference &preference, int index, DeviceT
break;
}
}
}
......@@ -51,6 +51,8 @@
* @brief Main sound class. Manages the data transfers between the application and the hardware.
*/
namespace sfl {
class AlsaThread;
class RingBuffer;
......@@ -261,4 +263,6 @@ class AlsaLayer : public AudioLayer {
std::shared_ptr<RingBuffer> mainRingBuffer_;
};
}
#endif // ALSA_LAYER_H_
......@@ -31,6 +31,8 @@
#include "audiobuffer.h"
#include "logger.h"
namespace sfl {
std::ostream& operator <<(std::ostream& stream, const AudioFormat& f) {
stream << f.toString();
return stream;
......@@ -257,3 +259,5 @@ size_t AudioBuffer::copy(SFLAudioSample* in, size_t sample_num, size_t pos_out /
return sample_num;
}
}
......@@ -38,6 +38,8 @@
#include "sfl_types.h"
namespace sfl {
/**
* Structure to hold sample rate and channel number associated with audio data.
*/
......@@ -324,4 +326,6 @@ class AudioBuffer {
std::vector<std::vector<SFLAudioSample> > samples_;
};
}
#endif // _AUDIO_BUFFER_H
......@@ -38,6 +38,8 @@
#include <ctime>
namespace sfl {
AudioLayer::AudioLayer(const AudioPreference &pref)
: isCaptureMuted_(pref.getCaptureMuted())
, isPlaybackMuted_(pref.getPlaybackMuted())
......@@ -112,3 +114,5 @@ void AudioLayer::notifyIncomingCall()
flushUrgent();
putUrgent(buf);
}
}
......@@ -58,12 +58,15 @@
#define PCM_DMIX_DSNOOP "dmix/dsnoop" // Audio profile using Alsa dmix/dsnoop
class AudioPreference;
class Resampler;
namespace ost {
class Time;
}
namespace sfl {
class Resampler;
enum class DeviceType {
PLAYBACK, /** To open playback device only */
CAPTURE, /** To open capture device only */
......@@ -266,4 +269,6 @@ class AudioLayer {
time_t lastNotificationTime_;
};
}
#endif // _AUDIO_LAYER_H_
......@@ -44,6 +44,8 @@
#include <cassert>
#include "logger.h"
namespace sfl {
AudioLoop::AudioLoop(unsigned int sampleRate) :
buffer_(new AudioBuffer(0, AudioFormat(sampleRate, 1))), pos_(0)
{}
......@@ -99,3 +101,5 @@ AudioLoop::getNext(AudioBuffer& output, double gain)
}
void AudioLoop::onBufferFinish() {}
}
......@@ -43,6 +43,8 @@
* @brief Loop on a sound file
*/
namespace sfl {
class AudioLoop {
public:
AudioLoop(unsigned int sampleRate);
......@@ -87,5 +89,7 @@ class AudioLoop {
virtual void onBufferFinish();
};
}
#endif // __AUDIOLOOP_H__
......@@ -43,6 +43,8 @@
#include <cstdio>
#include <unistd.h>
namespace sfl {
static std::string
createFilename()
{
......@@ -235,3 +237,5 @@ void AudioRecord::recData(AudioBuffer& buffer)
fileHandle_->writeSync();
}
}
}
......@@ -41,6 +41,8 @@
class SndfileHandle;
namespace sfl {
class AudioRecord {
public:
......@@ -153,4 +155,6 @@ class AudioRecord {
NON_COPYABLE(AudioRecord);
};
}
#endif // _AUDIO_RECORD_H
......@@ -37,6 +37,8 @@
#include <sstream>
#include <unistd.h>
namespace sfl {
int AudioRecorder::count_ = 0;
AudioRecorder::AudioRecorder(AudioRecord *arec, RingBufferPool &rbp)
......@@ -98,3 +100,5 @@ void AudioRecorder::run()
std::this_thread::sleep_for(SLEEP_TIME);
}
}
}
......@@ -37,6 +37,8 @@
#include <atomic>
#include <string>
namespace sfl {
class RingBufferPool;
class AudioRecord;
......@@ -72,4 +74,6 @@ class AudioRecorder {
std::thread thread_;
};
}
#endif
......@@ -48,12 +48,12 @@
#include <atomic>
#include <cstddef>
namespace sfl {
class Resampler;
class DSP;
class RingBuffer;
namespace sfl {
class AudioRtpContext {
public:
AudioRtpContext(AudioFormat f);
......
......@@ -55,7 +55,7 @@ class ZrtpZidException : public std::runtime_error {
};
class AudioZrtpSession :
public ost::SymmetricZRTPSession,
public ::ost::SymmetricZRTPSession,
public AudioRtpSession {
public:
AudioZrtpSession(SIPCall &call, const std::string& zidFilename, const std::string &localIP);
......@@ -63,7 +63,7 @@ class AudioZrtpSession :
std::vector<long>
getSocketDescriptors() const;
virtual bool onRTPPacketRecv(ost::IncomingRTPPkt &pkt) {
virtual bool onRTPPacketRecv(::ost::IncomingRTPPkt &pkt) {
return AudioRtpSession::onRTPPacketRecv(pkt);
}
......
......@@ -30,6 +30,8 @@
#include "dcblocker.h"
namespace sfl {
DcBlocker::DcBlocker(unsigned channels /* = 1 */)
: states(channels, (struct StreamState){0, 0, 0, 0})
{}
......@@ -73,3 +75,4 @@ void DcBlocker::process(AudioBuffer& buf)
}
}
}
......@@ -35,6 +35,8 @@
#include "sfl_types.h"
#include "audiobuffer.h"
namespace sfl {
class DcBlocker {
public:
DcBlocker(unsigned channels = 1);
......@@ -57,4 +59,6 @@ class DcBlocker {
std::vector<StreamState> states;
};
}
#endif
......@@ -32,6 +32,8 @@
#include "dsp.h"
#include "audiobuffer.h"
namespace sfl {
void
DSP::speexStateDeleter(SpeexPreprocessState *state)
{
......@@ -98,3 +100,5 @@ void DSP::process(AudioBuffer& buff, int samples)
++index;
}
}
}
......@@ -36,6 +36,8 @@
#include <memory>
#include "noncopyable.h"
namespace sfl {
class AudioBuffer;
class DSP {
......@@ -57,4 +59,6 @@ class DSP {
std::vector<SpeexStatePtr> dspStates_;
};
}
#endif // DSP_H_
......@@ -50,6 +50,8 @@ TODO
* auto connect optional
#endif
namespace sfl {
namespace
{
void connectPorts(jack_client_t *client, int portType, const std::vector<jack_port_t *> &ports)
......@@ -532,3 +534,5 @@ JackLayer::stopStream()
flushMain();
flushUrgent();
}
}
......@@ -42,6 +42,8 @@
#include <memory>
namespace sfl {
class RingBuffer;
class JackLayer : public AudioLayer {
......@@ -109,4 +111,6 @@ class JackLayer : public AudioLayer {
~JackLayer();
};
}
#endif // JACK_LAYER_H_
......@@ -33,6 +33,8 @@
#include "logger.h"
#include <stdexcept>
namespace sfl {
AudioStream::AudioStream(pa_context *c,
pa_threaded_mainloop *m,
const char *desc,
......@@ -150,3 +152,5 @@ bool AudioStream::isReady()
return pa_stream_get_state(audiostream_) == PA_STREAM_READY;
}
}
......@@ -37,6 +37,8 @@
#include <pulse/pulseaudio.h>
#include <string>
namespace sfl {
/**
* This data structure contains the different king of audio streams available
*/
......@@ -107,4 +109,6 @@ class AudioStream {
pa_threaded_mainloop * mainloop_;
};
}
#endif // _AUDIO_STREAM_H
......@@ -49,6 +49,8 @@
#include <cstdlib>
#include <fstream>
namespace sfl {
static void
playback_callback(pa_stream * /*s*/, size_t /*bytes*/, void* userdata)
{
......@@ -844,3 +846,5 @@ int PulseLayer::getIndexRingtone() const
{
return getAudioDeviceIndexByName(preference_.getPulseDeviceRingtone(), DeviceType::RINGTONE);
}
}
......@@ -46,6 +46,9 @@
#include <memory>
class AudioPreference;
namespace sfl {
class AudioStream;
class RingBuffer;
......@@ -227,5 +230,7 @@ class PulseLayer : public AudioLayer {
friend class AudioLayerTest;
};
}
#endif // PULSE_LAYER_H_
......@@ -31,6 +31,8 @@
#include "manager.h"
#include "logger.h"
namespace sfl {
Recordable::Recordable() : recAudio_(), recorder_(&recAudio_, Manager::instance().getRingBufferPool())
{
DEBUG("Set recording options: %s", Manager::instance().audioPreference.getRecordPath().c_str());
......@@ -57,3 +59,5 @@ void Recordable::setRecordingFormat(AudioFormat format)
{
recAudio_.setSndFormat(format);
}
}
......@@ -33,6 +33,8 @@
#include "audiorecord.h"
#include "audiorecorder.h"
namespace sfl {
class Recordable {
public:
......@@ -85,4 +87,6 @@ class Recordable {
AudioRecorder recorder_;
};
}
#endif
......@@ -34,6 +34,8 @@
#include <samplerate.h>
namespace sfl {
class SrcState {
public:
SrcState(int nb_channels)
......@@ -130,3 +132,5 @@ void Resampler::resample(const AudioBuffer &dataIn, AudioBuffer &dataOut)
src_float_to_short_array(floatBufferOut_.data(), scratchBuffer_.data(), outSamples);
dataOut.deinterleave(scratchBuffer_.data(), src_data.output_frames, nbChans);
}
}
......@@ -39,6 +39,8 @@
#include "sfl_types.h"
#include "noncopyable.h"
namespace sfl {
struct SrcState;
class Resampler {
......@@ -83,4 +85,6 @@ class Resampler {
std::unique_ptr<SrcState> src_state_;
};
}
#endif //_SAMPLE_RATE_H
......@@ -41,6 +41,8 @@
#include <cstdlib>
#include <cstring>
namespace sfl {
// corresponds to 160 ms (about 5 rtp packets)
static const size_t MIN_BUFFER_SIZE = 1024;
......@@ -310,3 +312,5 @@ RingBuffer::discard(size_t toDiscard)
}
return toDiscard;
}
}
......@@ -35,6 +35,8 @@
typedef std::map<std::string, size_t> ReadOffset;
namespace sfl {
/**
* A ring buffer for mutichannel audio samples
*/
......@@ -178,5 +180,6 @@ class RingBuffer {
ReadOffset readoffsets_;
};
}
#endif /* __RING_BUFFER__ */
......@@ -38,6 +38,8 @@
#include <utility> // for std::pair
#include <cstring>
namespace sfl {
const char * const RingBufferPool::DEFAULT_ID = "audiolayer_id";
RingBufferPool::RingBufferPool()
......@@ -419,3 +421,5 @@ RingBufferPool::flushAllBuffers()
ringBufferMap_.erase(item.first);
}
}
}
......@@ -41,6 +41,8 @@
#include <mutex>
#include <memory>
namespace sfl {
class RingBuffer;
class RingBufferPool {
......@@ -162,4 +164,6 @@ class RingBufferPool {
std::shared_ptr<RingBuffer> defaultRingBuffer_;
};
}
#endif // RING_BUFFER_POOL_H_
......@@ -45,6 +45,8 @@
#include "logger.h"
namespace sfl {
void
AudioFile::onBufferFinish()
{
......@@ -136,3 +138,5 @@ AudioFile::AudioFile(const std::string &fileName, unsigned int sampleRate) :
buffer_ = buffer;
}
}
}
......@@ -37,6 +37,8 @@
#include <stdexcept>
#include "audio/audioloop.h"
namespace sfl {
class AudioFileException : public std::runtime_error {
public:
AudioFileException(const std::string &str) :
......@@ -64,4 +66,6 @@ class AudioFile : public AudioLoop {
unsigned updatePlaybackScale_;
};
}
#endif // __AUDIOFILE_H__
......@@ -34,6 +34,8 @@
#include "dtmf.h"
namespace sfl {
DTMF::DTMF(unsigned int sampleRate)
: currentTone_(0), newTone_(0), dtmfgenerator_(sampleRate)
{}
......@@ -80,3 +82,4 @@ bool DTMF::generateDTMF(vector<SFLAudioSample> &buffer)
}
}
}
......@@ -41,6 +41,8 @@
* @file dtmf.h
* @brief DMTF library to generate a dtmf sample
*/
namespace sfl {
class DTMF {
public:
/**
......@@ -68,4 +70,6 @@ class DTMF {
DTMFGenerator dtmfgenerator_;
};
}
#endif // __KEY_DTMF_H_
......@@ -38,6 +38,8 @@
#include "dtmfgenerator.h"
namespace sfl {
/*
* Tone frequencies
*/
......@@ -143,3 +145,5 @@ SFLAudioSample* DTMFGenerator::fillToneBuffer(int index)
tone_.genSin(ptr, tones_[index].higher, tones_[index].lower, sampleRate_);
return ptr;
}
}
......@@ -48,6 +48,9 @@
* @file dtmfgenerator.h
* @brief DMTF Generator Exception
*/
namespace sfl {
class DTMFException : public std::runtime_error {
public:
DTMFException(const std::string& str) : std::runtime_error(str) {};
......@@ -123,4 +126,6 @@ class DTMFGenerator {
SFLAudioSample* fillToneBuffer(int index);
};
}
#endif // DTMFGENERATOR_H
......@@ -43,6 +43,8 @@
#include <cstring>
#include <vector>
namespace sfl {
Tone::Tone(const std::string& definition, unsigned int sampleRate) :
AudioLoop(sampleRate), xhigher_(0.0), xlower_(0.0)
{
......@@ -186,3 +188,4 @@ Tone::genSin(SFLAudioSample* buffer, int lowFrequency, int highFrequency, int nb
xlower_ = x_l;
}
}
......@@ -40,6 +40,9 @@
* @file tone.h
* @brief Tone sample (dial, busy, ring, congestion)
*/
namespace sfl {
class Tone : public AudioLoop {
public:
/**
......@@ -90,5 +93,7 @@ class Tone : public AudioLoop {
double xlower_;
};
}
#endif // __TONE_H__
......@@ -32,6 +32,8 @@
*/
#include "tonelist.h"
namespace sfl {
static const char *toneZone[TelephoneTone::ZID_COUNTRIES][Tone::TONE_NULL] = {
{
// ZID_NORTH_AMERICA
......@@ -132,3 +134,5 @@ TelephoneTone::getCurrentTone()
return tone_[currentTone_];
}
}
......@@ -37,6 +37,8 @@
#include "tone.h"
namespace sfl {
class TelephoneTone {
public:
/** Countries */
......@@ -66,4 +68,6 @@ class TelephoneTone {
Tone::TONEID currentTone_;
};
}
#endif
......@@ -198,17 +198,17 @@ bool
Call::toggleRecording()
{
const bool startRecording = Recordable::toggleRecording();
RingBufferPool &rbPool = Manager::instance().getRingBufferPool();
sfl::RingBufferPool &rbPool = Manager::instance().getRingBufferPool();
std::string process_id = Recordable::recorder_.getRecorderID();
if (startRecording) {
rbPool.bindHalfDuplexOut(process_id, id_);
rbPool.bindHalfDuplexOut(process_id, RingBufferPool::DEFAULT_ID);
rbPool.bindHalfDuplexOut(process_id, sfl::RingBufferPool::DEFAULT_ID);
Recordable::recorder_.start();
} else {
rbPool.unBindHalfDuplexOut(process_id, id_);
rbPool.unBindHalfDuplexOut(process_id, RingBufferPool::DEFAULT_ID);
rbPool.unBindHalfDuplexOut(process_id, sfl::RingBufferPool::DEFAULT_ID);
}
return startRecording;
......
......@@ -55,7 +55,7 @@ template <class T> using CallMap = std::map<std::string, std::shared_ptr<T> >;
* @brief A call is the base class for protocol-based calls
*/
class Call : public Recordable {
class Call : public sfl::Recordable {
public:
static const char * const DEFAULT_ID;
......
......@@ -258,17 +258,17 @@ std::vector<std::string> ConfigurationManager::getAudioInputDeviceList()
void ConfigurationManager::setAudioOutputDevice(int32_t index)
{
return Manager::instance().setAudioDevice(index, DeviceType::PLAYBACK);
return Manager::instance().setAudioDevice(index, sfl::DeviceType::PLAYBACK);
}
void ConfigurationManager::setAudioInputDevice(int32_t index)
{
return Manager::instance().setAudioDevice(index, DeviceType::CAPTURE);
return Manager::instance().setAudioDevice(index, sfl::DeviceType::CAPTURE);
}
void ConfigurationManager::setAudioRingtoneDevice(int32_t index)
{
return Manager::instance().setAudioDevice(index, DeviceType::RINGTONE);
return Manager::instance().setAudioDevice(index, sfl::DeviceType::RINGTONE);
}
std::vector<std::string> ConfigurationManager::getCurrentAudioDevicesIndex()
......
......@@ -108,8 +108,8 @@ void Conference::bindParticipant(const std::string &participant_id)
rbPool.flush(item);
}
rbPool.bindCallID(participant_id, RingBufferPool::DEFAULT_ID);
rbPool.flush(RingBufferPool::DEFAULT_ID);
rbPool.bindCallID(participant_id, sfl::RingBufferPool::DEFAULT_ID);
rbPool.flush(sfl::RingBufferPool::DEFAULT_ID);
}
std::string Conference::getStateStr() const
......@@ -162,14 +162,14 @@ bool Conference::toggleRecording()
for (const auto &item : participants_)
rbPool.bindHalfDuplexOut(process_id, item);
rbPool.bindHalfDuplexOut(process_id, RingBufferPool::DEFAULT_ID);
rbPool.bindHalfDuplexOut(process_id, sfl::RingBufferPool::DEFAULT_ID);
Recordable::recorder_.start();
} else {
for (const auto &item : participants_)
rbPool.unBindHalfDuplexOut(process_id, item);
rbPool.unBindHalfDuplexOut(process_id, RingBufferPool::DEFAULT_ID);
rbPool.unBindHalfDuplexOut(process_id, sfl::RingBufferPool::DEFAULT_ID);