Commit 0c8db47c authored by Emmanuel Lepage's avatar Emmanuel Lepage
Browse files
parents e27e5c39 40a68b9d
...@@ -94,7 +94,7 @@ void Account::setActiveCodecs (const std::vector <std::string> &list) ...@@ -94,7 +94,7 @@ void Account::setActiveCodecs (const std::vector <std::string> &list)
for (std::vector<std::string>::const_iterator iter = list.begin(); iter != list.end(); for (std::vector<std::string>::const_iterator iter = list.begin(); iter != list.end();
++iter) { ++iter) {
int payload = std::atoi (iter->c_str()); int payload = std::atoi (iter->c_str());
codecOrder_.push_back ( (AudioCodecType) payload); codecOrder_.push_back ( (int) payload);
} }
// update the codec string according to new codec selection // update the codec string according to new codec selection
......
...@@ -36,8 +36,7 @@ ...@@ -36,8 +36,7 @@
#include <algorithm> // for std::find #include <algorithm> // for std::find
#include "fileutils.h" #include "fileutils.h"
void AudioCodecFactory::AudioCodecFactory() : codecsMap_()
AudioCodecFactory::init()
{ {
typedef std::vector<sfl::Codec*> CodecVector; typedef std::vector<sfl::Codec*> CodecVector;
CodecVector codecDynamicList(scanCodecDirectory()); CodecVector codecDynamicList(scanCodecDirectory());
...@@ -46,7 +45,7 @@ AudioCodecFactory::init() ...@@ -46,7 +45,7 @@ AudioCodecFactory::init()
else { else {
for (CodecVector::const_iterator iter = codecDynamicList.begin(); for (CodecVector::const_iterator iter = codecDynamicList.begin();
iter != codecDynamicList.end() ; ++iter) { iter != codecDynamicList.end() ; ++iter) {
codecsMap_[ (AudioCodecType) (*iter)->getPayloadType() ] = *iter; codecsMap_[ (int) (*iter)->getPayloadType() ] = *iter;
_debug ("Loaded codec %s" , (*iter)->getMimeSubtype().c_str()); _debug ("Loaded codec %s" , (*iter)->getMimeSubtype().c_str());
} }
} }
...@@ -61,7 +60,7 @@ void AudioCodecFactory::setDefaultOrder() ...@@ -61,7 +60,7 @@ void AudioCodecFactory::setDefaultOrder()
} }
std::string std::string
AudioCodecFactory::getCodecName (AudioCodecType payload) AudioCodecFactory::getCodecName (int payload) const
{ {
CodecsMap::const_iterator iter = codecsMap_.find (payload); CodecsMap::const_iterator iter = codecsMap_.find (payload);
...@@ -71,8 +70,20 @@ AudioCodecFactory::getCodecName (AudioCodecType payload) ...@@ -71,8 +70,20 @@ AudioCodecFactory::getCodecName (AudioCodecType payload)
return ""; return "";
} }
std::vector<int32_t >
AudioCodecFactory::getAudioCodecList() const
{
std::vector<int32_t> list;
for (CodecsMap::const_iterator iter = codecsMap_.begin(); iter != codecsMap_.end(); ++iter)
if (iter->second)
list.push_back((int32_t)iter->first);
return list;
}
sfl::Codec* sfl::Codec*
AudioCodecFactory::getCodec (AudioCodecType payload) AudioCodecFactory::getCodec (int payload) const
{ {
CodecsMap::const_iterator iter = codecsMap_.find (payload); CodecsMap::const_iterator iter = codecsMap_.find (payload);
...@@ -84,7 +95,7 @@ AudioCodecFactory::getCodec (AudioCodecType payload) ...@@ -84,7 +95,7 @@ AudioCodecFactory::getCodec (AudioCodecType payload)
} }
} }
double AudioCodecFactory::getBitRate (AudioCodecType payload) double AudioCodecFactory::getBitRate (int payload) const
{ {
CodecsMap::const_iterator iter = codecsMap_.find (payload); CodecsMap::const_iterator iter = codecsMap_.find (payload);
...@@ -95,7 +106,7 @@ double AudioCodecFactory::getBitRate (AudioCodecType payload) ...@@ -95,7 +106,7 @@ double AudioCodecFactory::getBitRate (AudioCodecType payload)
} }
int AudioCodecFactory::getSampleRate (AudioCodecType payload) const int AudioCodecFactory::getSampleRate (int payload) const
{ {
CodecsMap::const_iterator iter = codecsMap_.find (payload); CodecsMap::const_iterator iter = codecsMap_.find (payload);
...@@ -114,18 +125,16 @@ void AudioCodecFactory::saveActiveCodecs (const std::vector<std::string>& list) ...@@ -114,18 +125,16 @@ void AudioCodecFactory::saveActiveCodecs (const std::vector<std::string>& list)
for (std::vector<std::string>::const_iterator iter = list.begin(); iter != list.end(); ++iter) { for (std::vector<std::string>::const_iterator iter = list.begin(); iter != list.end(); ++iter) {
int payload = std::atoi(iter->c_str()); int payload = std::atoi(iter->c_str());
if (isCodecLoaded (payload)) if (isCodecLoaded (payload))
defaultCodecOrder_.push_back ( (AudioCodecType) payload); defaultCodecOrder_.push_back ( (int) payload);
} }
} }
void
AudioCodecFactory::deleteHandlePointer() AudioCodecFactory::~AudioCodecFactory()
{ {
for (std::vector<CodecHandlePointer>::const_iterator iter = for (std::vector<CodecHandlePointer>::const_iterator iter =
codecInMemory_.begin(); iter != codecInMemory_.end(); ++iter) codecInMemory_.begin(); iter != codecInMemory_.end(); ++iter)
unloadCodec (*iter); unloadCodec (*iter);
codecInMemory_.clear();
} }
std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory() std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory()
...@@ -211,9 +220,9 @@ void AudioCodecFactory::unloadCodec (CodecHandlePointer p) ...@@ -211,9 +220,9 @@ void AudioCodecFactory::unloadCodec (CodecHandlePointer p)
dlclose (p.second); dlclose (p.second);
} }
sfl::Codec* AudioCodecFactory::instantiateCodec (AudioCodecType payload) sfl::Codec* AudioCodecFactory::instantiateCodec (int payload) const
{ {
std::vector< CodecHandlePointer >::iterator iter; std::vector< CodecHandlePointer >::const_iterator iter;
for (iter = codecInMemory_.begin(); iter != codecInMemory_.end(); ++iter) { for (iter = codecInMemory_.begin(); iter != codecInMemory_.end(); ++iter) {
if (iter->first->getPayloadType() == payload) { if (iter->first->getPayloadType() == payload) {
...@@ -275,7 +284,7 @@ AudioCodecFactory::alreadyInCache (const std::string &lib) ...@@ -275,7 +284,7 @@ AudioCodecFactory::alreadyInCache (const std::string &lib)
return std::find(libCache_.begin(), libCache_.end(), lib) != libCache_.end(); return std::find(libCache_.begin(), libCache_.end(), lib) != libCache_.end();
} }
bool AudioCodecFactory::isCodecLoaded (int payload) bool AudioCodecFactory::isCodecLoaded (int payload) const
{ {
CodecsMap::const_iterator iter; CodecsMap::const_iterator iter;
for (iter = codecsMap_.begin(); iter != codecsMap_.end(); ++iter) for (iter = codecsMap_.begin(); iter != codecsMap_.end(); ++iter)
...@@ -285,21 +294,21 @@ bool AudioCodecFactory::isCodecLoaded (int payload) ...@@ -285,21 +294,21 @@ bool AudioCodecFactory::isCodecLoaded (int payload)
return false; return false;
} }
std::vector <std::string> AudioCodecFactory::getCodecSpecifications (const int32_t& payload) std::vector <std::string> AudioCodecFactory::getCodecSpecifications (const int32_t& payload) const
{ {
std::vector<std::string> v; std::vector<std::string> v;
std::stringstream ss; std::stringstream ss;
// Add the name of the codec // Add the name of the codec
v.push_back(getCodecName(static_cast<AudioCodecType>(payload))); v.push_back(getCodecName(static_cast<int>(payload)));
// Add the sample rate // Add the sample rate
ss << getSampleRate (static_cast<AudioCodecType>(payload)); ss << getSampleRate (static_cast<int>(payload));
v.push_back(ss.str()); v.push_back(ss.str());
ss.str(""); ss.str("");
// Add the bit rate // Add the bit rate
ss << getBitRate(static_cast<AudioCodecType>(payload)); ss << getBitRate(static_cast<int>(payload));
v.push_back(ss.str()); v.push_back(ss.str());
return v; return v;
......
...@@ -46,18 +46,14 @@ ...@@ -46,18 +46,14 @@
*/ */
/** Maps a pointer on an audiocodec object to a payload */ /** Maps a pointer on an audiocodec object to a payload */
typedef std::map<AudioCodecType, sfl::Codec*> CodecsMap; typedef std::map<int, sfl::Codec*> CodecsMap;
class AudioCodecFactory class AudioCodecFactory
{ {
public: public:
/** AudioCodecFactory();
* Accessor to data structures
* @return CodecsMap& The available codec ~AudioCodecFactory();
*/
const CodecsMap& getCodecsMap() const {
return codecsMap_;
}
/** /**
* Get codec name by its payload * Get codec name by its payload
...@@ -65,19 +61,15 @@ class AudioCodecFactory ...@@ -65,19 +61,15 @@ class AudioCodecFactory
* same as getPayload() * same as getPayload()
* @return std::string The name of the codec * @return std::string The name of the codec
*/ */
std::string getCodecName (AudioCodecType payload); std::string getCodecName (int payload) const;
std::vector<int32_t > getAudioCodecList() const;
/** /**
* Get the codec object associated with the payload * Get the codec object associated with the payload
* @param payload The payload looked for * @param payload The payload looked for
* @return AudioCodec* A pointer on a AudioCodec object * @return AudioCodec* A pointer on a AudioCodec object
*/ */
sfl::Codec* getCodec (AudioCodecType payload); sfl::Codec* getCodec (int payload) const;
/**
* Initialiaze the map with all the supported codecs, even those inactive
*/
void init();
/** /**
* Set the default codecs order. * Set the default codecs order.
...@@ -90,14 +82,14 @@ class AudioCodecFactory ...@@ -90,14 +82,14 @@ class AudioCodecFactory
* @param payload The payload of the codec * @param payload The payload of the codec
* @return double The bit rate * @return double The bit rate
*/ */
double getBitRate (AudioCodecType payload); double getBitRate (int payload) const;
/** /**
* Get the clock rate of the specified codec * Get the clock rate of the specified codec
* @param payload The payload of the codec * @param payload The payload of the codec
* @return int The clock rate of the specified codec * @return int The clock rate of the specified codec
*/ */
int getSampleRate (AudioCodecType payload) const; int getSampleRate (int payload) const;
/** /**
* Set the order of codecs by their payload * Set the order of codecs by their payload
...@@ -105,16 +97,11 @@ class AudioCodecFactory ...@@ -105,16 +97,11 @@ class AudioCodecFactory
*/ */
void saveActiveCodecs (const std::vector<std::string>& list); void saveActiveCodecs (const std::vector<std::string>& list);
/**
* Unreferences the codecs loaded in memory
*/
void deleteHandlePointer (void);
/** /**
* Instantiate a codec, used in AudioRTP to get an instance of Codec per call * Instantiate a codec, used in AudioRTP to get an instance of Codec per call
* @param CodecHandlePointer The map containing the pointer on the object and the pointer on the handle function * @param CodecHandlePointer The map containing the pointer on the object and the pointer on the handle function
*/ */
sfl::Codec* instantiateCodec (AudioCodecType payload); sfl::Codec* instantiateCodec (int payload) const;
/** /**
* For a given codec, return its specification * For a given codec, return its specification
...@@ -122,7 +109,7 @@ class AudioCodecFactory ...@@ -122,7 +109,7 @@ class AudioCodecFactory
* @param payload The RTP payload of the codec * @param payload The RTP payload of the codec
* @return std::vector <std::string> A vector containing codec's name, sample rate, bandwidth and bit rate * @return std::vector <std::string> A vector containing codec's name, sample rate, bandwidth and bit rate
*/ */
std::vector <std::string> getCodecSpecifications (const int32_t& payload); std::vector <std::string> getCodecSpecifications (const int32_t& payload) const;
/** /**
* Check if the audiocodec object has been successfully created * Check if the audiocodec object has been successfully created
...@@ -130,7 +117,7 @@ class AudioCodecFactory ...@@ -130,7 +117,7 @@ class AudioCodecFactory
* @return bool True if the audiocodec has been created * @return bool True if the audiocodec has been created
* false otherwise * false otherwise
*/ */
bool isCodecLoaded (int payload); bool isCodecLoaded (int payload) const;
private: private:
/** Enable us to keep the handle pointer on the codec dynamicaly loaded so that we could destroy when we dont need it anymore */ /** Enable us to keep the handle pointer on the codec dynamicaly loaded so that we could destroy when we dont need it anymore */
......
...@@ -285,7 +285,7 @@ ...@@ -285,7 +285,7 @@
<tp:docstring> <tp:docstring>
</tp:docstring> </tp:docstring>
<annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="VectorString"/> <annotation name="com.trolltech.QtDBus.QtTypeName.Out0" value="VectorString"/>
<arg type="as" name="list" direction="out"> <arg type="ai" name="list" direction="out">
<tp:docstring> <tp:docstring>
</tp:docstring> </tp:docstring>
</arg> </arg>
......
...@@ -160,18 +160,9 @@ std::vector<std::string> ConfigurationManager::getAccountList() ...@@ -160,18 +160,9 @@ std::vector<std::string> ConfigurationManager::getAccountList()
* Send the list of all codecs loaded to the client through DBus. * Send the list of all codecs loaded to the client through DBus.
* Can stay global, as only the active codecs will be set per accounts * Can stay global, as only the active codecs will be set per accounts
*/ */
std::vector<std::string> ConfigurationManager::getAudioCodecList (void) std::vector<int32_t > ConfigurationManager::getAudioCodecList (void)
{ {
std::vector<std::string> list; std::vector<int32_t> list(Manager::instance().audioCodecFactory.getAudioCodecList());
const CodecsMap &codecs(Manager::instance().getAudioCodecFactory().getCodecsMap());
for (CodecsMap::const_iterator iter = codecs.begin(); iter != codecs.end(); ++iter)
if (iter->second) {
std::stringstream ss;
ss << iter->first;
list.push_back (ss.str());
}
if (list.empty()) if (list.empty())
errorAlert(CODECS_NOT_LOADED); errorAlert(CODECS_NOT_LOADED);
...@@ -192,7 +183,7 @@ std::vector<std::string> ConfigurationManager::getSupportedTlsMethod (void) ...@@ -192,7 +183,7 @@ std::vector<std::string> ConfigurationManager::getSupportedTlsMethod (void)
std::vector<std::string> ConfigurationManager::getAudioCodecDetails (const int32_t& payload) std::vector<std::string> ConfigurationManager::getAudioCodecDetails (const int32_t& payload)
{ {
std::vector<std::string> result(Manager::instance().getAudioCodecFactory().getCodecSpecifications(payload)); std::vector<std::string> result(Manager::instance().audioCodecFactory.getCodecSpecifications(payload));
if (result.empty()) if (result.empty())
errorAlert(CODECS_NOT_LOADED); errorAlert(CODECS_NOT_LOADED);
return result; return result;
......
...@@ -69,7 +69,7 @@ class ConfigurationManager ...@@ -69,7 +69,7 @@ class ConfigurationManager
std::map< std::string, std::string > getTlsSettingsDefault (void); std::map< std::string, std::string > getTlsSettingsDefault (void);
std::vector< std::string > getAudioCodecList (void); std::vector< int32_t > getAudioCodecList (void);
std::vector< std::string > getSupportedTlsMethod (void); std::vector< std::string > getSupportedTlsMethod (void);
std::vector< std::string > getAudioCodecDetails (const int32_t& payload); std::vector< std::string > getAudioCodecDetails (const int32_t& payload);
std::vector< std::string > getActiveAudioCodecList (const std::string& accountID); std::vector< std::string > getActiveAudioCodecList (const std::string& accountID);
......
...@@ -130,7 +130,7 @@ static const SOUND_FORMAT INT32 = 0x8; ...@@ -130,7 +130,7 @@ static const SOUND_FORMAT INT32 = 0x8;
#define HOOK_DEFAULT_URL_COMMAND "x-www-browser" #define HOOK_DEFAULT_URL_COMMAND "x-www-browser"
/** Enumeration that contains known audio payloads */ /** Enumeration that contains known audio payloads */
typedef enum { enum {
// http://www.iana.org/assignments/rtp-parameters // http://www.iana.org/assignments/rtp-parameters
// http://www.gnu.org/software/ccrtp/doc/refman/html/formats_8h.html#a0 // http://www.gnu.org/software/ccrtp/doc/refman/html/formats_8h.html#a0
// 0 PCMU A 8000 1 [RFC3551] // 0 PCMU A 8000 1 [RFC3551]
...@@ -152,10 +152,10 @@ typedef enum { ...@@ -152,10 +152,10 @@ typedef enum {
PAYLOAD_CODEC_SPEEX_8000 = 110, PAYLOAD_CODEC_SPEEX_8000 = 110,
PAYLOAD_CODEC_SPEEX_16000 = 111, PAYLOAD_CODEC_SPEEX_16000 = 111,
PAYLOAD_CODEC_SPEEX_32000 = 112 PAYLOAD_CODEC_SPEEX_32000 = 112
} AudioCodecType; };
/** The struct to reflect the order the user wants to use the codecs */ /** The struct to reflect the order the user wants to use the codecs */
typedef std::vector<AudioCodecType> CodecOrder; typedef std::vector<int> CodecOrder;
#define IP2IP_PROFILE "IP2IP" #define IP2IP_PROFILE "IP2IP"
#define DIR_SEPARATOR_STR "/" // Directory separator char #define DIR_SEPARATOR_STR "/" // Directory separator char
......
...@@ -35,9 +35,9 @@ ...@@ -35,9 +35,9 @@
#include "manager.h" #include "manager.h"
namespace { namespace {
int codecToASTFormat(AudioCodecType c) int codecToASTFormat(int c)
{ {
static std::map<AudioCodecType, int> mapping; static std::map<int, int> mapping;
if (mapping.empty()) { if (mapping.empty()) {
mapping[PAYLOAD_CODEC_ULAW] = AST_FORMAT_ULAW; mapping[PAYLOAD_CODEC_ULAW] = AST_FORMAT_ULAW;
mapping[PAYLOAD_CODEC_GSM] = AST_FORMAT_GSM; mapping[PAYLOAD_CODEC_GSM] = AST_FORMAT_GSM;
...@@ -53,9 +53,9 @@ namespace { ...@@ -53,9 +53,9 @@ namespace {
else else
return mapping[c]; return mapping[c];
} }
AudioCodecType ASTFormatToCodec(int format) int ASTFormatToCodec(int format)
{ {
static std::map<int, AudioCodecType> mapping; static std::map<int, int> mapping;
if (mapping.empty()) { if (mapping.empty()) {
mapping[AST_FORMAT_ULAW] = PAYLOAD_CODEC_ULAW; mapping[AST_FORMAT_ULAW] = PAYLOAD_CODEC_ULAW;
mapping[AST_FORMAT_GSM] = PAYLOAD_CODEC_GSM; mapping[AST_FORMAT_GSM] = PAYLOAD_CODEC_GSM;
...@@ -65,7 +65,7 @@ namespace { ...@@ -65,7 +65,7 @@ namespace {
} }
if (mapping.find(format) == mapping.end()) { if (mapping.find(format) == mapping.end()) {
_error("Format not supported!"); _error("Format not supported!");
return static_cast<AudioCodecType>(-1); return static_cast<int>(-1);
} }
else else
return mapping[format]; return mapping[format];
...@@ -118,12 +118,7 @@ int IAXCall::getFirstMatchingFormat (int needles, const std::string &accountID) ...@@ -118,12 +118,7 @@ int IAXCall::getFirstMatchingFormat (int needles, const std::string &accountID)
return 0; return 0;
} }
AudioCodecFactory& IAXCall::getAudioCodecFactory() int IAXCall::getAudioCodec()
{
return _audioCodecFactory;
}
AudioCodecType IAXCall::getAudioCodec()
{ {
return _audioCodec; return _audioCodec;
} }
...@@ -102,26 +102,11 @@ class IAXCall : public Call ...@@ -102,26 +102,11 @@ class IAXCall : public Call
*/ */
int getFirstMatchingFormat (int needles, const std::string &accountID) const; int getFirstMatchingFormat (int needles, const std::string &accountID) const;
// AUDIO
/**
* Set internal codec Map: initialization only, not protected
* @param map The codec map
*/
void setCodecMap (const AudioCodecFactory& factory) {
_audioCodecFactory = factory;
}
/**
* Get internal codec Map: initialization only, not protected
* @return CodecDescriptor The codec map
*/
AudioCodecFactory& getAudioCodecFactory();
/** /**
* Return audio codec [mutex protected] * Return audio codec [mutex protected]
* @return AudioCodecType The payload of the codec * @return int The payload of the codec
*/ */
AudioCodecType getAudioCodec(); int getAudioCodec();
private: private:
/** Each call is associated with an iax_session */ /** Each call is associated with an iax_session */
...@@ -131,15 +116,12 @@ class IAXCall : public Call ...@@ -131,15 +116,12 @@ class IAXCall : public Call
* Set the audio codec used. [not protected] * Set the audio codec used. [not protected]
* @param audioCodec The payload of the codec * @param audioCodec The payload of the codec
*/ */
void setAudioCodec (AudioCodecType audioCodec) { void setAudioCodec (int audioCodec) {
_audioCodec = audioCodec; _audioCodec = audioCodec;
} }
/** Codec Map */
AudioCodecFactory _audioCodecFactory;
/** Codec pointer */ /** Codec pointer */
AudioCodecType _audioCodec; int _audioCodec;
/** /**
* Format currently in use in the conversation, * Format currently in use in the conversation,
......
...@@ -210,8 +210,8 @@ IAXVoIPLink::sendAudioFromMic (void) ...@@ -210,8 +210,8 @@ IAXVoIPLink::sendAudioFromMic (void)
if (!currentCall or currentCall->getState() != Call::Active) if (!currentCall or currentCall->getState() != Call::Active)
continue; continue;
AudioCodecType codecType = currentCall->getAudioCodec(); int codecType = currentCall->getAudioCodec();
sfl::AudioCodec *audioCodec = static_cast<sfl::AudioCodec *>(currentCall->getAudioCodecFactory().getCodec(codecType)); sfl::AudioCodec *audioCodec = static_cast<sfl::AudioCodec *>(Manager::instance().audioCodecFactory.getCodec(codecType));
if (!audioCodec or !audiolayer_) if (!audioCodec or !audiolayer_)
continue; continue;
...@@ -325,7 +325,6 @@ Call* ...@@ -325,7 +325,6 @@ Call*
IAXVoIPLink::newOutgoingCall (const std::string& id, const std::string& toUrl) IAXVoIPLink::newOutgoingCall (const std::string& id, const std::string& toUrl)
{ {
IAXCall* call = new IAXCall (id, Call::Outgoing); IAXCall* call = new IAXCall (id, Call::Outgoing);
call->setCodecMap (Manager::instance().getAudioCodecFactory());