Commit b37c813f authored by Alexandre Savard's avatar Alexandre Savard

[#5208] Refactor codec management for accounts

parent 2bff3720
......@@ -40,12 +40,14 @@ Account::Account (const AccountID& accountID, std::string type) :
, _type (type)
, _registrationState (Unregistered)
, _codecOrder ()
, _codecStr ("0/")
, _codecStr ("")
, _ringtonePath ("/usr/share/sflphone/ringtones/konga.ul")
, _ringtoneEnabled (true)
, _displayName ("")
, _useragent ("SFLphone")
{
// Initialize the codec order, used when creating a new account
loadDefaultCodecs();
}
Account::~Account()
......@@ -62,8 +64,6 @@ void Account::loadConfig()
_enabled = false;
#endif
loadAudioCodecs ();
}
void Account::setRegistrationState (RegistrationState state)
......@@ -78,28 +78,33 @@ void Account::setRegistrationState (RegistrationState state)
}
}
void Account::loadAudioCodecs (void)
void Account::loadDefaultCodecs()
{
// if the user never set the codec list, use the default configuration for this account
if (_codecStr == "") {
_info ("Account: Use default codec order");
Manager::instance ().getCodecDescriptorMap ().setDefaultOrder();
}
// else retrieve the one set in the user config file
else {
_debug ("Account: Set codec order from configuration file");
std::vector<std::string> active_list = Manager::instance ().retrieveActiveCodecs();
// This property is now set per account basis
// std::string s = Manager::instance ().getConfigString (_accountID, "ActiveCodecs");
setActiveCodecs (Manager::instance ().unserialize (_codecStr));
}
// TODO
// CodecMap codecMap = Manager::instance ().getCodecDescriptorMap ().getCodecsMap();
// Initialize codec
std::vector <std::string> codecList;
codecList.push_back ("0");
codecList.push_back ("3");
codecList.push_back ("8");
codecList.push_back ("9");
codecList.push_back ("110");
codecList.push_back ("111");
codecList.push_back ("112");
setActiveCodecs (codecList);
}
void Account::setActiveCodecs (const std::vector <std::string> &list)
{
_debug ("Account: Set active codec");
// first clear the previously stored codecs
_codecOrder.clear();
// list contains the ordered payload of active codecs picked by the user for this account
// we used the CodecOrder vector to save the order.
int i=0;
......@@ -108,14 +113,12 @@ void Account::setActiveCodecs (const std::vector <std::string> &list)
while ( (unsigned int) i < size) {
payload = std::atoi (list[i].data());
_info ("Account: Adding codec with RTP payload=%i", payload);
//if (Manager::instance ().getCodecDescriptorMap ().isCodecLoaded (payload)) {
_info ("Account: Adding codec with RTP payload type %d", payload);
_codecOrder.push_back ( (AudioCodecType) payload);
//}
i++;
}
// setConfig
// update the codec string according to new codec selection
_codecStr = Manager::instance ().serialize (list);
}
......@@ -179,7 +179,6 @@ class Account : public Serializable
virtual std::map<std::string, std::string> getAccountDetails() = 0;
/**
* Load the settings for this account.
*/
......@@ -264,12 +263,11 @@ class Account : public Serializable
return _registrationStateDetailed;
}
/* inline functions */
/* They should be treated like macro definitions by the C++ compiler */
inline std::string getUsername (void) {
return _username;
}
inline void setUsername (std::string username) {
_username = username;
}
......@@ -309,6 +307,11 @@ class Account : public Serializable
inline CodecOrder& getActiveCodecs (void) {
return _codecOrder;
}
/**
* Update both the codec order structure and the codec string used for
* SDP offer and configuration respectively
*/
void setActiveCodecs (const std::vector <std::string>& list);
inline std::string getRingtonePath (void) {
......@@ -354,9 +357,14 @@ class Account : public Serializable
// assignment operator
Account& operator= (const Account& rh);
/**
* Helper function used to load the default codec order from the codec factory
* setActiveCodecs is called to sync both _codecOrder and _codecStr
*/
void loadDefaultCodecs (void);
protected:
void loadAudioCodecs (void);
/**
* Account ID are assign in constructor and shall not changed
......
......@@ -71,7 +71,7 @@ CodecDescriptor::init()
for (i = 0 ; i < _nbCodecs ; i++) {
_CodecsMap[ (AudioCodecType) CodecDynamicList[i]->getPayload() ] = CodecDynamicList[i];
_debug ("%s" , CodecDynamicList[i]->getCodecName().c_str());
_debug ("CodecDescriptor: %s" , CodecDynamicList[i]->getCodecName().c_str());
}
}
......@@ -107,7 +107,6 @@ CodecDescriptor::getCodec (AudioCodecType payload)
CodecsMap::iterator iter = _CodecsMap.find (payload);
if (iter!=_CodecsMap.end()) {
// _debug("Found codec %i _CodecsMap from codec descriptor", payload);
return (iter->second);
}
......
......@@ -74,12 +74,6 @@ class CodecDescriptor
return _CodecsMap;
}
/**
* Accessor to data structures
* @return CodecOrder& The list that reflects the user's choice
*/
// CodecOrder& getActiveCodecs() { return _codecOrder; }
/**
* Get codec name by its payload
* @param payload the payload looked for
......
......@@ -153,6 +153,9 @@ void IAXAccount::unserialize (Conf::MappingNode *map)
val = NULL;
}
// Update codec list which one is used for SDP offer
setActiveCodecs (Manager::instance ().unserialize (_codecStr));
val = (Conf::ScalarNode *) (map->getValue (displayNameKey));
if (val) {
......
......@@ -2432,18 +2432,6 @@ void ManagerImpl::initAudioCodec (void)
_codecDescriptorMap.init();
}
/*
* TODO Retrieve the active codec list per account
*/
std::vector<std::string> ManagerImpl::retrieveActiveCodecs ()
{
// This property is now set per account basis so we should remove it...
std::string s = "";
_info ("Manager: Retrieve active codecs: %s", s.c_str ());
return unserialize (s);
}
std::vector<std::string> ManagerImpl::unserialize (std::string s)
{
......
......@@ -859,13 +859,6 @@ class ManagerImpl
*/
int32_t getMailNotify (void);
/**
* Retrieve the formatted list of codecs payload in the user config file and
* load in the active list of codecs
* @return std::vector<std::string> The vector containing the active codecs
*/
std::vector<std::string> retrieveActiveCodecs (void);
/**
* Get the list of the active codecs
* @return std::vector< ::std::string > The list of active codecs
......
......@@ -394,7 +394,7 @@ void Sdp::sdp_add_media_description()
}
}
void Sdp::sdp_add_sdes_attribute (std::vector<std::string>& crypto)
void Sdp::sdp_add_sdes_attribute (std::vector<std::string>& crypto) throw (SdpException)
{
// temporary buffer used to store crypto attribute
......@@ -427,7 +427,7 @@ void Sdp::sdp_add_sdes_attribute (std::vector<std::string>& crypto)
if (pjmedia_sdp_media_add_attr (_local_offer->media[i], attribute) != PJ_SUCCESS) {
// if(pjmedia_sdp_attr_add(&(_local_offer->attr_count), _local_offer->attr, attribute) != PJ_SUCCESS){
throw sdpException();
throw SdpException ("Could not add sdes attribute to media");
}
}
......@@ -437,7 +437,7 @@ void Sdp::sdp_add_sdes_attribute (std::vector<std::string>& crypto)
}
void Sdp::sdp_add_zrtp_attribute (pjmedia_sdp_media* media, std::string hash)
void Sdp::sdp_add_zrtp_attribute (pjmedia_sdp_media* media, std::string hash) throw (SdpException)
{
pjmedia_sdp_attr *attribute;
char tempbuf[256];
......@@ -460,7 +460,7 @@ void Sdp::sdp_add_zrtp_attribute (pjmedia_sdp_media* media, std::string hash)
pj_memcpy (attribute->value.ptr, tempbuf, attribute->value.slen+1);
if (pjmedia_sdp_media_add_attr (media, attribute) != PJ_SUCCESS) {
throw sdpException();
throw SdpException ("Could not add zrtp attribute to media");
}
}
......@@ -668,8 +668,9 @@ void Sdp::set_local_media_capabilities (CodecOrder selectedCodecs)
/* We retrieve the codecs selected by the user */
codecs_list = Manager::instance().getCodecDescriptorMap().getCodecsMap();
if (selectedCodecs.size() == 0)
_warn ("SDP: No selected codec while building local SDP offer");
if (selectedCodecs.size() == 0) {
throw SdpException ("No selected codec while building local SDP offer");
}
for (i=0; i<selectedCodecs.size(); i++) {
iter=codecs_list.find (selectedCodecs[i]);
......
......@@ -47,11 +47,20 @@
#include <exception>
class sdpException: public std::exception
class SdpException : public std::exception
{
virtual const char* what() const throw() {
return "An sdpException Occured";
public:
SdpException (const std::string& str="") throw() : errstr (str) {}
virtual ~SdpException() throw() {}
virtual const char *what() const throw() {
std::string expt ("SDP: SdpException occured: ");
expt.append (errstr);
return expt.c_str();
}
private:
std::string errstr;
};
typedef std::vector<std::string> CryptoOffer;
......@@ -395,7 +404,7 @@ class Sdp
*
* @param media The media to add the srtp attribute to
*/
void sdp_add_sdes_attribute (std::vector<std::string>& crypto);
void sdp_add_sdes_attribute (std::vector<std::string>& crypto) throw (SdpException);
/*
* Adds a zrtp-hash attribute to
......@@ -406,7 +415,7 @@ class Sdp
* @param media The media to add the zrtp-hash attribute to
* @param hash The hash to which the attribute should be set to
*/
void sdp_add_zrtp_attribute (pjmedia_sdp_media* media, std::string hash);
void sdp_add_zrtp_attribute (pjmedia_sdp_media* media, std::string hash) throw (SdpException);
};
......
......@@ -353,6 +353,9 @@ void SIPAccount::unserialize (Conf::MappingNode *map)
val = NULL;
}
// Update codec list which one is used for SDP offer
setActiveCodecs (Manager::instance ().unserialize (_codecStr));
val = (Conf::ScalarNode *) (map->getValue (ringtonePathKey));
if (val) {
......@@ -621,8 +624,6 @@ void SIPAccount::unserialize (Conf::MappingNode *map)
val = NULL;
}
Account::loadAudioCodecs();
}
......@@ -1030,9 +1031,6 @@ int SIPAccount::registerVoIPLink()
{
_debug ("Account: Register account %s", getAccountID().c_str());
// Init general settings
// loadConfig();
if (_hostname.length() >= PJ_MAX_HOSTNAME) {
return !SUCCESS;
}
......
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