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

#6093: Rename CodecDescriptor for AudioCodecFactory

parent 5790f546
......@@ -2,7 +2,7 @@ include $(top_srcdir)/globals.mak
noinst_LTLIBRARIES = libcodecdescriptor.la
libcodecdescriptor_la_SOURCES = codecDescriptor.cpp audiocodec.cpp
libcodecdescriptor_la_SOURCES = audiocodecfactory.cpp audiocodec.cpp
if BUILD_GSM
GSM_LIB = libcodec_gsm.so
......@@ -66,7 +66,7 @@ endif
noinst_PROGRAMS = libcodec_ulaw.so libcodec_alaw.so libcodec_g722.so $(GSM_LIB) $(SPEEX_NB_LIB) $(SPEEX_WB_LIB) $(SPEEX_UB_LIB) $(CELT_LIB)
noinst_HEADERS = audiocodec.h codecDescriptor.h
noinst_HEADERS = audiocodec.h audiocodecfactory.h
libcodec_ulaw_so_SOURCES = ulaw.cpp
libcodec_ulaw_so_CFLAGS = -fPIC -g -Wall
......
......@@ -34,14 +34,14 @@
#include <iostream>
#include <cstdlib>
#include "codecDescriptor.h"
#include "audiocodecfactory.h"
CodecFactory::CodecFactory() : _CodecsMap(), _defaultCodecOrder(), _Cache(), _nbCodecs(), _CodecInMemory()
AudioCodecFactory::AudioCodecFactory() : _CodecsMap(), _defaultCodecOrder(), _Cache(), _nbCodecs(), _CodecInMemory()
{
}
CodecFactory::~CodecFactory()
AudioCodecFactory::~AudioCodecFactory()
{
}
......@@ -60,7 +60,7 @@ CodecFactory::~CodecFactory()
void
CodecFactory::init()
AudioCodecFactory::init()
{
std::vector<sfl::Codec*> CodecDynamicList = scanCodecDirectory();
_nbCodecs = CodecDynamicList.size();
......@@ -78,7 +78,7 @@ CodecFactory::init()
}
}
void CodecFactory::setDefaultOrder()
void AudioCodecFactory::setDefaultOrder()
{
_defaultCodecOrder.clear();
......@@ -92,7 +92,7 @@ void CodecFactory::setDefaultOrder()
}
std::string
CodecFactory::getCodecName (AudioCodecType payload)
AudioCodecFactory::getCodecName (AudioCodecType payload)
{
std::string resNull = "";
CodecsMap::iterator iter = _CodecsMap.find (payload);
......@@ -105,7 +105,7 @@ CodecFactory::getCodecName (AudioCodecType payload)
}
sfl::Codec*
CodecFactory::getCodec (AudioCodecType payload)
AudioCodecFactory::getCodec (AudioCodecType payload)
{
CodecsMap::iterator iter = _CodecsMap.find (payload);
......@@ -118,7 +118,7 @@ CodecFactory::getCodec (AudioCodecType payload)
return NULL;
}
double CodecFactory::getBitRate (AudioCodecType payload)
double AudioCodecFactory::getBitRate (AudioCodecType payload)
{
CodecsMap::iterator iter = _CodecsMap.find (payload);
......@@ -129,7 +129,7 @@ double CodecFactory::getBitRate (AudioCodecType payload)
return 0.0;
}
double CodecFactory::getBandwidthPerCall (AudioCodecType payload)
double AudioCodecFactory::getBandwidthPerCall (AudioCodecType payload)
{
CodecsMap::iterator iter = _CodecsMap.find (payload);
......@@ -140,7 +140,7 @@ double CodecFactory::getBandwidthPerCall (AudioCodecType payload)
return 0.0;
}
int CodecFactory::getSampleRate (AudioCodecType payload)
int AudioCodecFactory::getSampleRate (AudioCodecType payload)
{
CodecsMap::iterator iter = _CodecsMap.find (payload);
......@@ -151,7 +151,7 @@ int CodecFactory::getSampleRate (AudioCodecType payload)
return 0;
}
void CodecFactory::saveActiveCodecs (const std::vector<std::string>& list)
void AudioCodecFactory::saveActiveCodecs (const std::vector<std::string>& list)
{
_defaultCodecOrder.clear();
......@@ -174,7 +174,7 @@ void CodecFactory::saveActiveCodecs (const std::vector<std::string>& list)
}
void
CodecFactory::deleteHandlePointer (void)
AudioCodecFactory::deleteHandlePointer (void)
{
_debug ("CodecDesccriptor: Delete codec handle pointers");
......@@ -185,7 +185,7 @@ CodecFactory::deleteHandlePointer (void)
_CodecInMemory.clear();
}
std::vector<sfl::Codec*> CodecFactory::scanCodecDirectory (void)
std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory (void)
{
std::vector<sfl::Codec*> codecs;
......@@ -226,7 +226,7 @@ std::vector<sfl::Codec*> CodecFactory::scanCodecDirectory (void)
return codecs;
}
sfl::Codec* CodecFactory::loadCodec (std::string path)
sfl::Codec* AudioCodecFactory::loadCodec (std::string path)
{
CodecHandlePointer p;
......@@ -253,7 +253,7 @@ sfl::Codec* CodecFactory::loadCodec (std::string path)
}
void CodecFactory::unloadCodec (CodecHandlePointer p)
void AudioCodecFactory::unloadCodec (CodecHandlePointer p)
{
using std::cerr;
......@@ -267,7 +267,7 @@ void CodecFactory::unloadCodec (CodecHandlePointer p)
dlclose (p.second);
}
sfl::Codec* CodecFactory::instantiateCodec (AudioCodecType payload)
sfl::Codec* AudioCodecFactory::instantiateCodec (AudioCodecType payload)
{
using std::cerr;
......@@ -294,7 +294,7 @@ sfl::Codec* CodecFactory::instantiateCodec (AudioCodecType payload)
sfl::Codec* CodecFactory::getFirstCodecAvailable (void)
sfl::Codec* AudioCodecFactory::getFirstCodecAvailable (void)
{
CodecsMap::iterator iter = _CodecsMap.begin();
......@@ -305,7 +305,7 @@ sfl::Codec* CodecFactory::getFirstCodecAvailable (void)
return NULL;
}
bool CodecFactory::seemsValid (std::string lib)
bool AudioCodecFactory::seemsValid (std::string lib)
{
// The name of the shared library seems valid <==> it looks like libcodec_xxx.so
......@@ -362,7 +362,7 @@ bool CodecFactory::seemsValid (std::string lib)
}
bool
CodecFactory::alreadyInCache (std::string lib)
AudioCodecFactory::alreadyInCache (std::string lib)
{
int i;
......@@ -375,7 +375,7 @@ CodecFactory::alreadyInCache (std::string lib)
return false;
}
bool CodecFactory::isCodecLoaded (int payload)
bool AudioCodecFactory::isCodecLoaded (int payload)
{
CodecsMap::iterator iter = _CodecsMap.begin();
......@@ -390,7 +390,7 @@ bool CodecFactory::isCodecLoaded (int payload)
return false;
}
std::vector <std::string> CodecFactory::getCodecSpecifications (const int32_t& payload)
std::vector <std::string> AudioCodecFactory::getCodecSpecifications (const int32_t& payload)
{
_debug ("CodecDescriptor: Gathering codec specifications for payload %i", payload);
......
......@@ -53,18 +53,18 @@ typedef std::map<AudioCodecType, std::string> CodecMap;
* @brief Handle audio codecs, load them in memory
*/
class CodecFactory
class AudioCodecFactory
{
public:
/**
* Constructor
*/
CodecFactory();
AudioCodecFactory();
/**
* Destructor
*/
~CodecFactory();
~AudioCodecFactory();
/**
* Accessor to data structures
......
......@@ -38,7 +38,7 @@
#include <limits.h>
#include "audiofile.h"
#include "audio/codecs/codecDescriptor.h"
#include "audio/codecs/audiocodecfactory.h"
#include "audio/samplerateconverter.h"
#include "manager.h"
......
......@@ -38,7 +38,7 @@
#include "audio/audioloop.h"
#include "audio/codecs/audiocodec.h"
#include "audio/codecs/codecDescriptor.h"
#include "audio/codecs/audiocodecfactory.h"
/**
......
......@@ -411,7 +411,7 @@ std::vector<std::string> ConfigurationManager::getAudioCodecList (void)
std::vector<std::string> list;
CodecsMap codecs = Manager::instance().getCodecDescriptorMap().getCodecsMap();
CodecsMap codecs = Manager::instance().getAudioCodecFactory().getCodecsMap();
CodecsMap::iterator iter = codecs.begin();
while (iter != codecs.end()) {
......@@ -443,7 +443,7 @@ std::vector<std::string> ConfigurationManager::getAudioCodecDetails (
const int32_t& payload)
{
return Manager::instance().getCodecDescriptorMap().getCodecSpecifications (
return Manager::instance().getAudioCodecFactory().getCodecSpecifications (
payload);
}
......
......@@ -198,9 +198,9 @@ int IAXCall::getFirstMatchingFormat (int needles, std::string accountID)
return 0;
}
CodecFactory& IAXCall::getCodecMap()
AudioCodecFactory& IAXCall::getAudioCodecFactory()
{
return _codecMap;
return _audioCodecFactory;
}
AudioCodecType IAXCall::getAudioCodec()
......
......@@ -32,7 +32,7 @@
#define IAXCALL_H
#include "call.h"
#include "audio/codecs/codecDescriptor.h"
#include "audio/codecs/audiocodecfactory.h"
#include <iax-client.h>
#include <frame.h>
......@@ -114,15 +114,15 @@ class IAXCall : public Call
* Set internal codec Map: initialization only, not protected
* @param map The codec map
*/
void setCodecMap (const CodecFactory& map) {
_codecMap = map;
void setCodecMap (const AudioCodecFactory& factory) {
_audioCodecFactory = factory;
}
/**
* Get internal codec Map: initialization only, not protected
* @return CodecDescriptor The codec map
*/
CodecFactory& getCodecMap();
AudioCodecFactory& getAudioCodecFactory();
/**
* Return audio codec [mutex protected]
......@@ -143,7 +143,7 @@ class IAXCall : public Call
}
/** Codec Map */
CodecFactory _codecMap;
AudioCodecFactory _audioCodecFactory;
/** Codec pointer */
AudioCodecType _audioCodec;
......
......@@ -264,7 +264,6 @@ IAXVoIPLink::getEvent()
if (call) {
// We know that call, deal with it
iaxHandleCallEvent (event, call);
//_audiocodec = Manager::instance().getCodecDescriptorMap().getCodec( call -> getAudioCodec() );
} else if (event->session && event->session == _regSession) {
// This is a registration session, deal with it
iaxHandleRegReply (event);
......@@ -303,7 +302,7 @@ IAXVoIPLink::sendAudioFromMic (void)
{
int maxBytesToGet, availBytesFromMic, bytesAvail, compSize;
AudioCodec *ac;
AudioCodec *audioCodec = NULL;
IAXCall *currentCall;
// We have to update the audio layer type in case we switched
......@@ -330,16 +329,17 @@ IAXVoIPLink::sendAudioFromMic (void)
if (callIsActive) {
ac = static_cast<AudioCodec *>(currentCall->getCodecMap().getCodec (currentCall->getAudioCodec()));
AudioCodecType codecType = currentCall->getAudioCodec();
audioCodec = static_cast<AudioCodec *>(currentCall->getAudioCodecFactory().getCodec (codecType));
// Send sound here
if (ac && audiolayer) {
if (audioCodec && audiolayer) {
// _debug("Send sound");
// audiolayer->getMainBuffer()->flush(currentCall->getCallId());
Manager::instance().getMainBuffer()->setInternalSamplingRate (ac->getClockRate());
Manager::instance().getMainBuffer()->setInternalSamplingRate (audioCodec->getClockRate());
int _mainBufferSampleRate = audiolayer->getMainBuffer()->getInternalSamplingRate();
......@@ -364,18 +364,18 @@ IAXVoIPLink::sendAudioFromMic (void)
nbSampleForRec_ = nbSample_;
if (ac->getClockRate() && ((int) ac->getClockRate() != _mainBufferSampleRate)) {
if (audioCodec->getClockRate() && ((int) audioCodec->getClockRate() != _mainBufferSampleRate)) {
// resample
nbSample_ = converter->downsampleData (micData , micDataConverted , (int) ac->getClockRate(), _mainBufferSampleRate, nbSample_);
nbSample_ = converter->downsampleData (micData , micDataConverted , (int) audioCodec->getClockRate(), _mainBufferSampleRate, nbSample_);
// for the mono: range = 0 to IAX_FRAME2SEND * sizeof(int16)
compSize = ac->encode (micDataEncoded, micDataConverted , nbSample_*sizeof (int16));
compSize = audioCodec->encode (micDataEncoded, micDataConverted , nbSample_*sizeof (int16));
} else {
// for the mono: range = 0 to IAX_FRAME2SEND * sizeof(int16)
compSize = ac->encode (micDataEncoded, micData, nbSample_*sizeof (int16));
compSize = audioCodec->encode (micDataEncoded, micData, nbSample_*sizeof (int16));
}
......@@ -492,7 +492,7 @@ Call*
IAXVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl) throw(VoipLinkException)
{
IAXCall* call = new IAXCall (id, Call::Outgoing);
call->setCodecMap (Manager::instance().getCodecDescriptorMap());
call->setCodecMap (Manager::instance().getAudioCodecFactory());
if (call) {
call->setPeerNumber (toUrl);
......@@ -516,7 +516,7 @@ bool
IAXVoIPLink::answer (const CallID& id) throw (VoipLinkException)
{
IAXCall* call = getIAXCall (id);
call->setCodecMap (Manager::instance().getCodecDescriptorMap());
call->setCodecMap (Manager::instance().getAudioCodecFactory());
Manager::instance().addStream (call->getCallId());
......@@ -708,16 +708,25 @@ std::string
IAXVoIPLink::getCurrentCodecName(const CallID& /*id*/)
{
IAXCall *call = NULL;
AudioCodec *ac = NULL;
AudioCodec *audioCodec = NULL;
std::string name = "";
call = getIAXCall (Manager::instance().getCurrentCallId());
if (call)
ac = static_cast<AudioCodec *>(call->getCodecMap().getCodec (call->getAudioCodec()));
if(call == NULL) {
_error("IAX: Error: Could not load call");
return "";
}
if (ac)
name = ac->getMimeSubtype();
AudioCodecType audioCodecType = call->getAudioCodec();
audioCodec= static_cast<AudioCodec *>(call->getAudioCodecFactory().getCodec (audioCodecType));
if(audioCodec == NULL) {
_error("IAX: Error: Could not load audio codec");
return "";
}
name = audioCodec->getMimeSubtype();
return name;
}
......@@ -966,10 +975,11 @@ IAXVoIPLink::iaxHandleVoiceEvent (iax_event* event, IAXCall* call)
unsigned char *data;
unsigned int size, max, nbInt16;
int expandedSize, nbSample_;
AudioCodec *ac;
AudioCodec *audioCodec;
if (!call)
if (!call) {
return;
}
if (!event->datalen) {
// Skip this empty packet.
......@@ -977,14 +987,15 @@ IAXVoIPLink::iaxHandleVoiceEvent (iax_event* event, IAXCall* call)
return;
}
ac = static_cast<AudioCodec *>(call->getCodecMap ().getCodec (call->getAudioCodec ()));
AudioCodecType audioCodecType = call->getAudioCodec();
audioCodec = static_cast<AudioCodec *>(call->getAudioCodecFactory().getCodec (audioCodecType));
if (!ac)
if (!audioCodec)
return;
if (audiolayer) {
Manager::instance().getMainBuffer ()->setInternalSamplingRate (ac->getClockRate ());
Manager::instance().getMainBuffer ()->setInternalSamplingRate (audioCodec->getClockRate ());
// If we receive datalen == 0, some things of the jitter buffer in libiax2/iax.c
// were triggered
......@@ -1000,22 +1011,19 @@ IAXVoIPLink::iaxHandleVoiceEvent (iax_event* event, IAXCall* call)
call->setFormat (event->subclass);
}
//_debug("Receive: len=%d, format=%d, _receiveDataDecoded=%p", event->datalen, call->getFormat(), _receiveDataDecoded);
// ac = call->getCodecMap().getCodec (call -> getAudioCodec());
data = (unsigned char*) event->data;
size = event->datalen;
// Decode data with relevant codec
max = (int) (ac->getClockRate() * audiolayer->getFrameSize() / 1000);
max = (int) (audioCodec->getClockRate() * audiolayer->getFrameSize() / 1000);
if (size > max) {
_debug ("The size %d is bigger than expected %d. Packet cropped. Ouch!", size, max);
size = max;
}
expandedSize = ac->decode (spkrDataDecoded , data , size);
expandedSize = audioCodec->decode (spkrDataDecoded , data , size);
nbInt16 = expandedSize/sizeof (int16);
......@@ -1028,10 +1036,10 @@ IAXVoIPLink::iaxHandleVoiceEvent (iax_event* event, IAXCall* call)
// test if resampling is required
if (ac->getClockRate() && ((int) ac->getClockRate() != _mainBufferSampleRate)) {
if (audioCodec->getClockRate() && ((int) audioCodec->getClockRate() != _mainBufferSampleRate)) {
// resample
nbInt16 = converter->upsampleData (spkrDataDecoded, spkrDataConverted, ac->getClockRate(), _mainBufferSampleRate, nbSample_);
nbInt16 = converter->upsampleData (spkrDataDecoded, spkrDataConverted, audioCodec->getClockRate(), _mainBufferSampleRate, nbSample_);
/* Write the data to the mic ring buffer */
audiolayer->getMainBuffer()->putData (spkrDataConverted, nbInt16 * sizeof (SFLDataFormat), 100, call->getCallId());
......@@ -1156,7 +1164,7 @@ IAXVoIPLink::iaxHandlePrecallEvent (iax_event* event)
call->setSession (event->session);
// setCallAudioLocal(call);
call->setCodecMap (Manager::instance().getCodecDescriptorMap());
call->setCodecMap (Manager::instance().getAudioCodecFactory());
call->setConnectionState (Call::Progressing);
......
......@@ -36,7 +36,7 @@
#include <iax-client.h>
#include "global.h"
#include "audio/codecs/codecDescriptor.h"
#include "audio/codecs/audiocodecfactory.h"
#include "audio/samplerateconverter.h"
#include "hooks/urlhook.h"
......
......@@ -76,8 +76,8 @@
ManagerImpl::ManagerImpl (void) :
_hasTriedToRegister (false), _config(), _currentCallId2(),
_currentCallMutex(), _codecBuilder (NULL), _audiodriver (NULL),
_dtmfKey (NULL), _codecDescriptorMap(), _toneMutex(),
_currentCallMutex(), _audiodriver (NULL),
_dtmfKey (NULL), _audioCodecFactory(), _toneMutex(),
_telephoneTone (NULL), _audiofile (NULL), _spkr_volume (0),
_mic_volume (0), _mutex(), _dbus (NULL), _waitingCall(),
_waitingCallMutex(), _nbIncomingWaitingCall (0), _path (""),
......@@ -203,7 +203,7 @@ void ManagerImpl::terminate ()
_telephoneTone = NULL;
_debug ("Manager: Unload audio codecs ");
_codecDescriptorMap.deleteHandlePointer();
_audioCodecFactory.deleteHandlePointer();
}
......@@ -2344,7 +2344,7 @@ void ManagerImpl::ringtone (const AccountID& accountID)
layer = _audiodriver->getLayerType();
samplerate = _audiodriver->getSampleRate();
codecForTone = static_cast<AudioCodec *>(_codecDescriptorMap.getFirstCodecAvailable());
codecForTone = static_cast<AudioCodec *>(_audioCodecFactory.getFirstCodecAvailable());
audioLayerMutexUnlock();
......@@ -2592,7 +2592,7 @@ void ManagerImpl::initAudioCodec (void)
/* Init list of all supported codecs by the application.
* This is a global list. Every account will inherit it.
*/
_codecDescriptorMap.init();
_audioCodecFactory.init();
}
std::vector<std::string> ManagerImpl::unserialize (std::string s)
......
......@@ -53,7 +53,7 @@
#include "audio/sound/tonelist.h" // for Tone::TONEID declaration
#include "audio/sound/audiofile.h"
#include "audio/sound/dtmf.h" // DTMF class contained by value here
#include "audio/codecs/codecDescriptor.h" // CodecDescriptor class contained by value here
#include "audio/codecs/audiocodecfactory.h"
#include "audio/mainbuffer.h"
#include "yamlemitter.h"
......@@ -186,8 +186,8 @@ class ManagerImpl
* Get a descriptor map of codec available
* @return CodecDescriptor The internal codec map
*/
CodecFactory& getCodecDescriptorMap (void) {
return _codecDescriptorMap;
AudioCodecFactory& getAudioCodecFactory (void) {
return _audioCodecFactory;
}
/**
......@@ -1221,9 +1221,6 @@ class ManagerImpl
/** Protected current call access */
ost::Mutex _currentCallMutex;
/** Vector of CodecDescriptor */
CodecFactory* _codecBuilder;
/** Audio layer */
AudioLayer* _audiodriver;
......@@ -1232,7 +1229,7 @@ class ManagerImpl
DTMF* _dtmfKey;
// map of codec (for configlist request)
CodecFactory _codecDescriptorMap;
AudioCodecFactory _audioCodecFactory;
/////////////////////
// Protected by Mutex
......
......@@ -88,7 +88,7 @@ void Sdp::setActiveLocalSdpSession (const pjmedia_sdp_session *sdp)
activeLocalSession = (pjmedia_sdp_session*) sdp;
codecs_list = Manager::instance().getCodecDescriptorMap().getCodecsMap();
codecs_list = Manager::instance().getAudioCodecFactory().getCodecsMap();
// retrieve the media information
nb_media = activeLocalSession->media_count;
......@@ -296,7 +296,7 @@ void Sdp::setLocalMediaCapabilities (CodecOrder selectedCodecs)
audio->set_port (getLocalPublishedAudioPort());
/* We retrieve the codecs selected by the user */
codecs_list = Manager::instance().getCodecDescriptorMap().getCodecsMap();
codecs_list = Manager::instance().getAudioCodecFactory().getCodecsMap();
if (selectedCodecs.size() == 0) {
throw SdpException ("No selected codec while building local SDP offer");
......
......@@ -42,7 +42,7 @@
#include <pj/assert.h>
#include <vector>
#include "audio/codecs/codecDescriptor.h"
#include "audio/codecs/audiocodecfactory.h"
#include "sdpmedia.h"
#include <exception>
......
......@@ -33,7 +33,7 @@
#include <vector>
#include "audio/codecs/codecDescriptor.h"
#include "audio/codecs/audiocodecfactory.h"
#define DEFAULT_STREAM_DIRECTION "sendrecv"
......
......@@ -701,7 +701,7 @@ Call *SIPVoIPLink::newOutgoingCall (const CallID& id, const std::string& toUrl)
// Initialize the session using ULAW as default codec in case of early media
// The session should be ready to receive media once the first INVITE is sent, before
// the session initialization is completed