diff --git a/daemon/src/account.cpp b/daemon/src/account.cpp index 2f67a497ad851cb7e38a052aa5bb2e0fa4e8d778..a2c867d549993763146e01a0acb55e7365badc96 100644 --- a/daemon/src/account.cpp +++ b/daemon/src/account.cpp @@ -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(); ++iter) { 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 diff --git a/daemon/src/audio/codecs/audiocodecfactory.cpp b/daemon/src/audio/codecs/audiocodecfactory.cpp index 0253d32b98c455004d24dc6862ea3e874bbe4c08..60191b19cce367776b41cade72f016bb9e857c7a 100644 --- a/daemon/src/audio/codecs/audiocodecfactory.cpp +++ b/daemon/src/audio/codecs/audiocodecfactory.cpp @@ -36,8 +36,7 @@ #include <algorithm> // for std::find #include "fileutils.h" -void -AudioCodecFactory::init() +AudioCodecFactory::AudioCodecFactory() : codecsMap_() { typedef std::vector<sfl::Codec*> CodecVector; CodecVector codecDynamicList(scanCodecDirectory()); @@ -46,7 +45,7 @@ AudioCodecFactory::init() else { for (CodecVector::const_iterator iter = codecDynamicList.begin(); iter != codecDynamicList.end() ; ++iter) { - codecsMap_[ (AudioCodecType) (*iter)->getPayloadType() ] = *iter; + codecsMap_[ (int) (*iter)->getPayloadType() ] = *iter; _debug ("Loaded codec %s" , (*iter)->getMimeSubtype().c_str()); } } @@ -61,7 +60,7 @@ void AudioCodecFactory::setDefaultOrder() } std::string -AudioCodecFactory::getCodecName (AudioCodecType payload) +AudioCodecFactory::getCodecName (int payload) const { CodecsMap::const_iterator iter = codecsMap_.find (payload); @@ -71,8 +70,20 @@ AudioCodecFactory::getCodecName (AudioCodecType payload) 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* -AudioCodecFactory::getCodec (AudioCodecType payload) +AudioCodecFactory::getCodec (int payload) const { CodecsMap::const_iterator iter = codecsMap_.find (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); @@ -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); @@ -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) { int payload = std::atoi(iter->c_str()); 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 = codecInMemory_.begin(); iter != codecInMemory_.end(); ++iter) unloadCodec (*iter); - - codecInMemory_.clear(); } std::vector<sfl::Codec*> AudioCodecFactory::scanCodecDirectory() @@ -211,9 +220,9 @@ void AudioCodecFactory::unloadCodec (CodecHandlePointer p) 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) { if (iter->first->getPayloadType() == payload) { @@ -275,7 +284,7 @@ AudioCodecFactory::alreadyInCache (const std::string &lib) 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; for (iter = codecsMap_.begin(); iter != codecsMap_.end(); ++iter) @@ -285,21 +294,21 @@ bool AudioCodecFactory::isCodecLoaded (int payload) 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::stringstream ss; // 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 - ss << getSampleRate (static_cast<AudioCodecType>(payload)); + ss << getSampleRate (static_cast<int>(payload)); v.push_back(ss.str()); ss.str(""); // Add the bit rate - ss << getBitRate(static_cast<AudioCodecType>(payload)); + ss << getBitRate(static_cast<int>(payload)); v.push_back(ss.str()); return v; diff --git a/daemon/src/audio/codecs/audiocodecfactory.h b/daemon/src/audio/codecs/audiocodecfactory.h index 9faa103e34d70124315671b8f40e5c7e72b83182..17f04cfab416e599e042651fa30144fec1b471f0 100644 --- a/daemon/src/audio/codecs/audiocodecfactory.h +++ b/daemon/src/audio/codecs/audiocodecfactory.h @@ -46,18 +46,14 @@ */ /** 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 { public: - /** - * Accessor to data structures - * @return CodecsMap& The available codec - */ - const CodecsMap& getCodecsMap() const { - return codecsMap_; - } + AudioCodecFactory(); + + ~AudioCodecFactory(); /** * Get codec name by its payload @@ -65,19 +61,15 @@ class AudioCodecFactory * same as getPayload() * @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 * @param payload The payload looked for * @return AudioCodec* A pointer on a AudioCodec object */ - sfl::Codec* getCodec (AudioCodecType payload); - - /** - * Initialiaze the map with all the supported codecs, even those inactive - */ - void init(); + sfl::Codec* getCodec (int payload) const; /** * Set the default codecs order. @@ -90,14 +82,14 @@ class AudioCodecFactory * @param payload The payload of the codec * @return double The bit rate */ - double getBitRate (AudioCodecType payload); + double getBitRate (int payload) const; /** * Get the clock rate of the specified codec * @param payload The payload of the 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 @@ -105,16 +97,11 @@ class AudioCodecFactory */ 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 * @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 @@ -122,7 +109,7 @@ class AudioCodecFactory * @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 */ - 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 @@ -130,7 +117,7 @@ class AudioCodecFactory * @return bool True if the audiocodec has been created * false otherwise */ - bool isCodecLoaded (int payload); + bool isCodecLoaded (int payload) const; private: /** Enable us to keep the handle pointer on the codec dynamicaly loaded so that we could destroy when we dont need it anymore */ diff --git a/daemon/src/dbus/configurationmanager-introspec.xml b/daemon/src/dbus/configurationmanager-introspec.xml index a126d8e023b5c27aa138b1f120fd83835cc8eec7..d1e7faecb4144bd22c581b88c114d07ec379b6c9 100755 --- a/daemon/src/dbus/configurationmanager-introspec.xml +++ b/daemon/src/dbus/configurationmanager-introspec.xml @@ -285,7 +285,7 @@ <tp:docstring> </tp:docstring> <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> </arg> diff --git a/daemon/src/dbus/configurationmanager.cpp b/daemon/src/dbus/configurationmanager.cpp index 096896e958721bc7b7d52f401c071c97a0e31225..9eaa364dde28582dbde9d6d75ba3a2e23b8d9862 100644 --- a/daemon/src/dbus/configurationmanager.cpp +++ b/daemon/src/dbus/configurationmanager.cpp @@ -160,18 +160,9 @@ std::vector<std::string> ConfigurationManager::getAccountList() * 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 */ -std::vector<std::string> ConfigurationManager::getAudioCodecList (void) +std::vector<int32_t > ConfigurationManager::getAudioCodecList (void) { - std::vector<std::string> list; - - 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()); - } + std::vector<int32_t> list(Manager::instance().audioCodecFactory.getAudioCodecList()); if (list.empty()) errorAlert(CODECS_NOT_LOADED); @@ -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> result(Manager::instance().getAudioCodecFactory().getCodecSpecifications(payload)); + std::vector<std::string> result(Manager::instance().audioCodecFactory.getCodecSpecifications(payload)); if (result.empty()) errorAlert(CODECS_NOT_LOADED); return result; diff --git a/daemon/src/dbus/configurationmanager.h b/daemon/src/dbus/configurationmanager.h index fe9da5987feb86f4eb1ac0a958c35b023732e550..08fd6da1a660b90770e6fde1aa461b168bcd6972 100644 --- a/daemon/src/dbus/configurationmanager.h +++ b/daemon/src/dbus/configurationmanager.h @@ -69,7 +69,7 @@ class ConfigurationManager 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 > getAudioCodecDetails (const int32_t& payload); std::vector< std::string > getActiveAudioCodecList (const std::string& accountID); diff --git a/daemon/src/global.h b/daemon/src/global.h index d1aec2917e754c06b5385d93d627d9f1d9979967..b7d8458aa872f386a33e8e552f01b4dae30033b1 100644 --- a/daemon/src/global.h +++ b/daemon/src/global.h @@ -130,7 +130,7 @@ static const SOUND_FORMAT INT32 = 0x8; #define HOOK_DEFAULT_URL_COMMAND "x-www-browser" /** Enumeration that contains known audio payloads */ -typedef enum { +enum { // http://www.iana.org/assignments/rtp-parameters // http://www.gnu.org/software/ccrtp/doc/refman/html/formats_8h.html#a0 // 0 PCMU A 8000 1 [RFC3551] @@ -152,10 +152,10 @@ typedef enum { PAYLOAD_CODEC_SPEEX_8000 = 110, PAYLOAD_CODEC_SPEEX_16000 = 111, PAYLOAD_CODEC_SPEEX_32000 = 112 -} AudioCodecType; +}; /** 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 DIR_SEPARATOR_STR "/" // Directory separator char diff --git a/daemon/src/iax/iaxcall.cpp b/daemon/src/iax/iaxcall.cpp index edfd37364e45c674625a85fd443d797a15432f93..fa09091f32ce79e6d9dfab091f09e3e983a813dd 100644 --- a/daemon/src/iax/iaxcall.cpp +++ b/daemon/src/iax/iaxcall.cpp @@ -35,9 +35,9 @@ #include "manager.h" namespace { - int codecToASTFormat(AudioCodecType c) + int codecToASTFormat(int c) { - static std::map<AudioCodecType, int> mapping; + static std::map<int, int> mapping; if (mapping.empty()) { mapping[PAYLOAD_CODEC_ULAW] = AST_FORMAT_ULAW; mapping[PAYLOAD_CODEC_GSM] = AST_FORMAT_GSM; @@ -53,9 +53,9 @@ namespace { else 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()) { mapping[AST_FORMAT_ULAW] = PAYLOAD_CODEC_ULAW; mapping[AST_FORMAT_GSM] = PAYLOAD_CODEC_GSM; @@ -65,7 +65,7 @@ namespace { } if (mapping.find(format) == mapping.end()) { _error("Format not supported!"); - return static_cast<AudioCodecType>(-1); + return static_cast<int>(-1); } else return mapping[format]; @@ -118,12 +118,7 @@ int IAXCall::getFirstMatchingFormat (int needles, const std::string &accountID) return 0; } -AudioCodecFactory& IAXCall::getAudioCodecFactory() -{ - return _audioCodecFactory; -} - -AudioCodecType IAXCall::getAudioCodec() +int IAXCall::getAudioCodec() { return _audioCodec; } diff --git a/daemon/src/iax/iaxcall.h b/daemon/src/iax/iaxcall.h index 50cb2e430ef8149fc6092d5c66be6816ac749525..a4579e4d1bc9a752f6735156251908ce976d71ee 100644 --- a/daemon/src/iax/iaxcall.h +++ b/daemon/src/iax/iaxcall.h @@ -102,26 +102,11 @@ class IAXCall : public Call */ 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 AudioCodecType The payload of the codec + * @return int The payload of the codec */ - AudioCodecType getAudioCodec(); + int getAudioCodec(); private: /** Each call is associated with an iax_session */ @@ -131,15 +116,12 @@ class IAXCall : public Call * Set the audio codec used. [not protected] * @param audioCodec The payload of the codec */ - void setAudioCodec (AudioCodecType audioCodec) { + void setAudioCodec (int audioCodec) { _audioCodec = audioCodec; } - /** Codec Map */ - AudioCodecFactory _audioCodecFactory; - /** Codec pointer */ - AudioCodecType _audioCodec; + int _audioCodec; /** * Format currently in use in the conversation, diff --git a/daemon/src/iax/iaxvoiplink.cpp b/daemon/src/iax/iaxvoiplink.cpp index 80f7f3be155097e30f70f9841d11ad1b2834a1ca..6170322f4ff2d83a288847839eb305dc83703e32 100644 --- a/daemon/src/iax/iaxvoiplink.cpp +++ b/daemon/src/iax/iaxvoiplink.cpp @@ -210,8 +210,8 @@ IAXVoIPLink::sendAudioFromMic (void) if (!currentCall or currentCall->getState() != Call::Active) continue; - AudioCodecType codecType = currentCall->getAudioCodec(); - sfl::AudioCodec *audioCodec = static_cast<sfl::AudioCodec *>(currentCall->getAudioCodecFactory().getCodec(codecType)); + int codecType = currentCall->getAudioCodec(); + sfl::AudioCodec *audioCodec = static_cast<sfl::AudioCodec *>(Manager::instance().audioCodecFactory.getCodec(codecType)); if (!audioCodec or !audiolayer_) continue; @@ -325,7 +325,6 @@ Call* IAXVoIPLink::newOutgoingCall (const std::string& id, const std::string& toUrl) { IAXCall* call = new IAXCall (id, Call::Outgoing); - call->setCodecMap (Manager::instance().getAudioCodecFactory()); call->setPeerNumber (toUrl); call->initRecFileName (toUrl); @@ -347,7 +346,6 @@ void IAXVoIPLink::answer (Call *c) { IAXCall* call = dynamic_cast<IAXCall*>(c); - call->setCodecMap(Manager::instance().getAudioCodecFactory()); Manager::instance().addStream (call->getCallId()); @@ -513,7 +511,7 @@ std::string IAXVoIPLink::getCurrentCodecName(Call *c) const { IAXCall *call = dynamic_cast<IAXCall*>(c); - sfl::Codec *audioCodec = call->getAudioCodecFactory().getCodec(call->getAudioCodec()); + sfl::Codec *audioCodec = Manager::instance().audioCodecFactory.getCodec(call->getAudioCodec()); return audioCodec ? audioCodec->getMimeSubtype() : ""; } @@ -690,7 +688,7 @@ IAXVoIPLink::iaxHandleVoiceEvent (iax_event* event, IAXCall* call) return; } - sfl::AudioCodec *audioCodec = static_cast<sfl::AudioCodec *>(call->getAudioCodecFactory().getCodec(call->getAudioCodec())); + sfl::AudioCodec *audioCodec = static_cast<sfl::AudioCodec *>(Manager::instance().audioCodecFactory.getCodec(call->getAudioCodec())); if (!audioCodec) return; @@ -813,9 +811,6 @@ IAXVoIPLink::iaxHandlePrecallEvent (iax_event* event) // Associate the call to the session. call->setSession (event->session); - // setCallAudioLocal(call); - call->setCodecMap (Manager::instance().getAudioCodecFactory()); - call->setConnectionState (Call::Progressing); diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index 5a28eb5ce4bbbc7e7bd6b48bdd879f11bfe2ea4b..9b1f1a1ac5af722a217bd6bf68dc7eec30d228d6 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -70,7 +70,7 @@ ManagerImpl::ManagerImpl (void) : _hasTriedToRegister (false), _config(), _currentCallId2(), _currentCallMutex(), _audiodriver (0), - _dtmfKey (0), _audioCodecFactory(), _toneMutex(), + _dtmfKey (0), _toneMutex(), _telephoneTone (0), _audiofile (0), _spkr_volume (0), _mic_volume (0), _waitingCall(), _waitingCallMutex(), _nbIncomingWaitingCall (0), _path (""), @@ -118,9 +118,6 @@ void ManagerImpl::init (std::string config_file) initVolume(); initAudioDriver(); - // Initialize the list of supported audio codecs - _audioCodecFactory.init(); - audioLayerMutexLock(); if (_audiodriver) { @@ -156,7 +153,6 @@ void ManagerImpl::terminate () delete _audiodriver; _audiodriver = NULL; - _audioCodecFactory.deleteHandlePointer(); audioLayerMutexUnlock(); } @@ -1875,7 +1871,7 @@ void ManagerImpl::ringtone (const std::string& accountID) else { sfl::Codec *codec; if (ringchoice.find (".ul") != std::string::npos || ringchoice.find (".au") != std::string::npos) - codec = _audioCodecFactory.getCodec(PAYLOAD_CODEC_ULAW); + codec = audioCodecFactory.getCodec(PAYLOAD_CODEC_ULAW); else throw AudioFileException("Couldn't guess an appropriate decoder"); _audiofile = new RawFile(ringchoice, static_cast<sfl::AudioCodec *>(codec), samplerate); diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index 892413aab4512fda7efd08de2d6b3876953f796b..e87ca3a129a33a6a29e581f9e3ec5df9e0ecf480 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -153,21 +153,13 @@ class ManagerImpl return _audiodriver; } - /** - * Get a descriptor map of codec available - * @return CodecDescriptor The internal codec map - */ - AudioCodecFactory& getAudioCodecFactory (void) { - return _audioCodecFactory; - } - /** * Functions which occur with a user's action * Place a new call * @param accountId The account to make tha call with * @param call_id The call identifier * @param to The recipient of the call - * @param conf_id The conference identifier if any + * @param conf_id The conference identifier if any * @return bool true on success * false otherwise */ @@ -934,6 +926,10 @@ class ManagerImpl * @return std::vector<std::string> A vector containing the account ID's */ std::vector<std::string> loadAccountOrder () const; + + // map of codec (for configlist request) + const AudioCodecFactory audioCodecFactory; + private: /** * Play the dtmf-associated sound @@ -995,9 +991,6 @@ class ManagerImpl DTMF* _dtmfKey; - // map of codec (for configlist request) - AudioCodecFactory _audioCodecFactory; - ///////////////////// // Protected by Mutex ///////////////////// diff --git a/daemon/src/sip/sdp.cpp b/daemon/src/sip/sdp.cpp index 241aace67e690156aef7eb5f3a052944d8effe6b..70030a01b845d665ffe785b9f1030bdb77c3e71f 100644 --- a/daemon/src/sip/sdp.cpp +++ b/daemon/src/sip/sdp.cpp @@ -77,7 +77,6 @@ void Sdp::setActiveLocalSdpSession (const pjmedia_sdp_session *sdp) pjmedia_sdp_media *current; sdpMedia *media = NULL; std::string dir; - CodecsMap codecs_list; pjmedia_sdp_attr *attribute = NULL; pjmedia_sdp_rtpmap *rtpmap; @@ -85,8 +84,6 @@ void Sdp::setActiveLocalSdpSession (const pjmedia_sdp_session *sdp) activeLocalSession_ = (pjmedia_sdp_session*) sdp; - codecs_list = Manager::instance().getAudioCodecFactory().getCodecsMap(); - // retrieve the media information nb_media = activeLocalSession_->media_count; @@ -111,15 +108,15 @@ void Sdp::setActiveLocalSdpSession (const pjmedia_sdp_session *sdp) pjmedia_sdp_attr_to_rtpmap (memPool_, attribute, &rtpmap); - CodecsMap::iterator iter = codecs_list.find ( (AudioCodecType) pj_strtoul (&rtpmap->pt)); + sfl::Codec *codec = Manager::instance().audioCodecFactory.getCodec((int) pj_strtoul (&rtpmap->pt)); - if (iter == codecs_list.end()) + if (!codec) { delete media; return; } - media->add_codec (iter->second); + media->add_codec(codec); } sessionAudioMedia_.push_back (media); @@ -286,17 +283,13 @@ void Sdp::setLocalMediaCapabilities (const CodecOrder &selectedCodecs) audio = new sdpMedia (MIME_TYPE_AUDIO); audio->set_port (getLocalPublishedAudioPort()); - /* We retrieve the codecs selected by the user */ - CodecsMap codecs_list = Manager::instance().getAudioCodecFactory().getCodecsMap(); - if (selectedCodecs.size() == 0) _warn("No selected codec while building local SDP offer"); else { for (CodecOrder::const_iterator iter = selectedCodecs.begin(); iter != selectedCodecs.end(); ++iter) { - CodecsMap::const_iterator map_iter = codecs_list.find (*iter); - - if (map_iter != codecs_list.end()) - audio->add_codec (map_iter->second); + sfl::Codec *codec = Manager::instance().audioCodecFactory.getCodec(*iter); + if (codec) + audio->add_codec(codec); else _warn ("SDP: Couldn't find audio codec"); } diff --git a/daemon/src/sip/sipvoiplink.cpp b/daemon/src/sip/sipvoiplink.cpp index c635031187453478aaf517dac4a163789cdad2ae..74905d0306692fcf76c056a889afd4433180df29 100644 --- a/daemon/src/sip/sipvoiplink.cpp +++ b/daemon/src/sip/sipvoiplink.cpp @@ -573,7 +573,7 @@ Call *SIPVoIPLink::newOutgoingCall (const std::string& id, const std::string& to // 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 - sfl::Codec* audiocodec = Manager::instance().getAudioCodecFactory().instantiateCodec (PAYLOAD_CODEC_ULAW); + sfl::Codec* audiocodec = Manager::instance().audioCodecFactory.instantiateCodec (PAYLOAD_CODEC_ULAW); if (audiocodec == NULL) { _error ("UserAgent: Could not instantiate codec"); delete call; @@ -764,20 +764,20 @@ SIPVoIPLink::offhold (const std::string& id) try { // Retreive previously selected codec - AudioCodecType pl; + int pl; sfl::Codec *sessionMedia = sdpSession->getSessionMedia(); if (sessionMedia == NULL) { _warn("UserAgent: Session media not yet initialized, using default (ULAW)"); pl = PAYLOAD_CODEC_ULAW; } else - pl = (AudioCodecType) sessionMedia->getPayloadType(); + pl = (int) sessionMedia->getPayloadType(); _debug ("UserAgent: Payload from session media %d", pl); // Create a new instance for this codec - sfl::Codec* audiocodec = Manager::instance().getAudioCodecFactory().instantiateCodec (pl); + sfl::Codec* audiocodec = Manager::instance().audioCodecFactory.instantiateCodec (pl); if (audiocodec == NULL) throw VoipLinkException("Could not instantiate codec"); @@ -1300,7 +1300,7 @@ bool SIPVoIPLink::SIPNewIpToIpCall (const std::string& id, const std::string& to _debug ("UserAgent: TO uri for IP2IP call: %s", toUri.c_str()); - sfl::Codec* audiocodec = Manager::instance().getAudioCodecFactory().instantiateCodec (PAYLOAD_CODEC_ULAW); + sfl::Codec* audiocodec = Manager::instance().audioCodecFactory.instantiateCodec (PAYLOAD_CODEC_ULAW); // Audio Rtp Session must be initialized before creating initial offer in SDP session // since SDES require crypto attribute. @@ -1522,7 +1522,7 @@ void SIPVoIPLink::pjsipInit() // Add endpoint capabilities (INFO, OPTIONS, etc) for this UA pj_str_t allowed[] = { { (char*) "INFO", 4}, { (char*) "REGISTER", 8}, { (char*) "OPTIONS", 7}, { (char*) "MESSAGE", 7 } }; // //{"INVITE", 6}, {"ACK",3}, {"BYE",3}, {"CANCEL",6} - pj_str_t accepted = pj_str ( (char*) "application/sdp"); + pj_str_t accepted = { (char*) "application/sdp", 15 }; // Register supported methods pjsip_endpt_add_capability (_endpt, &_mod_ua, PJSIP_H_ALLOW, NULL, PJ_ARRAY_SIZE (allowed), allowed); @@ -2520,7 +2520,7 @@ void sdp_media_update_cb (pjsip_inv_session *inv, pj_status_t status) if (!sessionMedia) return; - AudioCodecType pl = (AudioCodecType) sessionMedia->getPayloadType(); + int pl = (int) sessionMedia->getPayloadType(); try { Manager::instance().audioLayerMutexLock(); @@ -2529,7 +2529,7 @@ void sdp_media_update_cb (pjsip_inv_session *inv, pj_status_t status) // udate session media only if required if (pl != call->getAudioRtp()->getSessionMedia()) { - sfl::Codec* audiocodec = Manager::instance().getAudioCodecFactory().instantiateCodec (pl); + sfl::Codec* audiocodec = Manager::instance().audioCodecFactory.instantiateCodec (pl); if (audiocodec == NULL) _error ("UserAgent: No audiocodec found"); @@ -2989,7 +2989,7 @@ transaction_request_cb (pjsip_rx_data *rdata) try { _debug ("UserAgent: Create RTP session for this call"); // Init default codec for early media session - sfl::Codec* audiocodec = Manager::instance().getAudioCodecFactory().instantiateCodec (PAYLOAD_CODEC_ULAW); + sfl::Codec* audiocodec = Manager::instance().audioCodecFactory.instantiateCodec (PAYLOAD_CODEC_ULAW); call->getAudioRtp()->start (static_cast<sfl::AudioCodec *>(audiocodec)); } catch (...) { _warn ("UserAgent: Error: Failed to create rtp thread from answer"); diff --git a/gnome/src/actions.c b/gnome/src/actions.c index d2ad2971b30a2dd47d45e7ace952010d4abcdced..cc608e476f7e8a471c505b9af4f9e0e0892c3f51 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -241,23 +241,13 @@ sflphone_hung_up (callable_obj_t * c) /** Internal to actions: Fill account list */ void sflphone_fill_account_list (void) { - - gchar** array; - gchar** accountID; - unsigned int i; - int count; - - DEBUG ("SFLphone: Fill account list"); - - count = current_account_get_message_number (); + int count = current_account_get_message_number (); account_list_clear (); - array = (gchar **) dbus_account_list(); - + gchar **array = dbus_account_list(); if (array) { - - for (accountID = array; *accountID; accountID++) { + for (gchar **accountID = array; *accountID; accountID++) { account_t * a = g_new0 (account_t,1); a->accountID = g_strdup (*accountID); a->credential_information = NULL; @@ -267,7 +257,7 @@ void sflphone_fill_account_list (void) g_strfreev (array); } - for (i = 0; i < account_list_get_size(); i++) { + for (unsigned i = 0; i < account_list_get_size(); i++) { account_t * a = account_list_get_nth (i); if(a == NULL) { ERROR("SFLphone: Error: Could not find account %d in list", i); @@ -311,12 +301,9 @@ void sflphone_fill_account_list (void) a->state = ACCOUNT_STATE_INVALID; } - gchar * code = NULL; - code = g_hash_table_lookup (details, REGISTRATION_STATE_CODE); - - if (code != NULL) { + gchar * code = g_hash_table_lookup (details, REGISTRATION_STATE_CODE); + if (code != NULL) a->protocol_state_code = atoi (code); - } g_free (a->protocol_state_description); a->protocol_state_description = g_hash_table_lookup (details, REGISTRATION_STATE_DESCRIPTION); @@ -438,13 +425,11 @@ void sflphone_pick_up() { callable_obj_t *selectedCall = calltab_get_selected_call (active_calltree); - - DEBUG("SFLphone: Pick up"); - if (!selectedCall) { sflphone_new_call(); return; } + switch (selectedCall->_state) { case CALL_STATE_DIALING: sflphone_place_call (selectedCall); @@ -489,13 +474,9 @@ sflphone_on_hold () callable_obj_t * selectedCall = calltab_get_selected_call (current_calls); conference_obj_t * selectedConf = calltab_get_selected_conf (active_calltree); - DEBUG ("sflphone_on_hold"); - if (selectedCall) { switch (selectedCall->_state) { case CALL_STATE_CURRENT: - dbus_hold (selectedCall); - break; case CALL_STATE_RECORD: dbus_hold (selectedCall); break; @@ -525,8 +506,6 @@ sflphone_off_hold () break; } } else if (selectedConf) { - - dbus_unhold_conference (selectedConf); } } @@ -626,18 +605,7 @@ sflphone_incoming_call (callable_obj_t * c) } } -/* Truncates last char from dynamically allocated string */ -static void truncate_last_char(gchar **str) -{ - if (strlen(*str) > 0) { - gchar *tmp = *str; - tmp = g_strndup(*str, strlen(*str) - 1); - g_free(*str); - *str = tmp; - } -} - -void +static void process_dialing (callable_obj_t *c, guint keyval, gchar *key) { // We stop the tone @@ -653,18 +621,21 @@ process_dialing (callable_obj_t *c, guint keyval, gchar *key) sflphone_hang_up (); break; case GDK_BackSpace: - if (c->_state == CALL_STATE_TRANSFER) { - truncate_last_char(&c->_trsft_to); - calltree_update_call (current_calls, c, NULL); - } else { - truncate_last_char(&c->_peer_number); + { + gchar *num = (c->_state == CALL_STATE_TRANSFER) ? c->_trsft_to : c->_peer_number; + size_t len = strlen(num); + printf("\"%s\" : %zu\n", num, len); + if (len) { + len--; // delete one character + num[len] = '\0'; calltree_update_call (current_calls, c, NULL); + /* If number is now empty, hang up immediately */ - if (strlen(c->_peer_number) == 0) + if (c->_state != CALL_STATE_TRANSFER && len == 0) dbus_hang_up(c); } - break; + } case GDK_Tab: case GDK_Alt_L: case GDK_Control_L: @@ -729,6 +700,7 @@ sflphone_keypad (guint keyval, gchar * key) case GDK_Return: case GDK_KP_Enter: case GDK_Escape: + case GDK_BackSpace: break; default: calltree_display (current_calls); diff --git a/gnome/src/codeclist.c b/gnome/src/codeclist.c index 35c4eeeaf833d22261f7606b0eac500493018f2b..d1cea947aa08df67c4b873e1876666c44dd79d07 100644 --- a/gnome/src/codeclist.c +++ b/gnome/src/codeclist.c @@ -69,23 +69,20 @@ void codec_capabilities_load (void) codecsCapabilities = g_queue_new(); // This is a global list inherited by all accounts - gchar **codecs = dbus_audio_codec_list (); - gchar **codecs_orig = codecs; - - if (codecs != NULL) { - // Add the codecs in the list - for (; *codecs; codecs++) { - codec_t *c; - guint payload = atoi (*codecs); - gchar **specs = dbus_audio_codec_details (payload); - codec_create_new_with_specs (payload, specs, TRUE, &c); - g_strfreev(specs); - g_queue_push_tail (codecsCapabilities, (gpointer) c); - g_free(*codecs); - } - g_free(codecs_orig); + GArray *codecs = dbus_audio_codec_list (); + + // Add the codecs in the list + for (guint i = 0; i < codecs->len; i++) { + codec_t *c; + gint payload = g_array_index(codecs, gint, i); + gchar **specs = dbus_audio_codec_details (payload); + codec_create_new_with_specs (payload, specs, TRUE, &c); + g_strfreev(specs); + g_queue_push_tail (codecsCapabilities, (gpointer) c); } + g_array_unref(codecs); + // If we didn't load any codecs, problem ... if (g_queue_get_length (codecsCapabilities) == 0) ERROR ("No audio codecs found"); diff --git a/gnome/src/dbus/configurationmanager-introspec.xml b/gnome/src/dbus/configurationmanager-introspec.xml index a126d8e023b5c27aa138b1f120fd83835cc8eec7..d1e7faecb4144bd22c581b88c114d07ec379b6c9 100755 --- a/gnome/src/dbus/configurationmanager-introspec.xml +++ b/gnome/src/dbus/configurationmanager-introspec.xml @@ -285,7 +285,7 @@ <tp:docstring> </tp:docstring> <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> </arg> diff --git a/gnome/src/dbus/dbus.c b/gnome/src/dbus/dbus.c index 6d8da167ac59d0d40fec87c1dcd492ec2ef54fa8..2e3546b0e55a767a3c2d8b4c7bbf78849efb7951 100644 --- a/gnome/src/dbus/dbus.c +++ b/gnome/src/dbus/dbus.c @@ -1135,11 +1135,11 @@ dbus_unregister (int pid) } } -gchar** +GArray * dbus_audio_codec_list() { GError *error = NULL; - gchar** array = NULL; + GArray * array = NULL; org_sflphone_SFLphone_ConfigurationManager_get_audio_codec_list ( configurationManagerProxy, &array, &error); diff --git a/gnome/src/dbus/dbus.h b/gnome/src/dbus/dbus.h index 18a361952fd1407d377bd6535dac0a5f36ce550c..1eaebc4edec4a78a1925ec183367bd05fd77580b 100644 --- a/gnome/src/dbus/dbus.h +++ b/gnome/src/dbus/dbus.h @@ -193,7 +193,7 @@ void dbus_play_dtmf (const gchar * key); * ConfigurationManager - Get the audio codecs list * @return gchar** The list of audiocodecs */ -gchar** dbus_audio_codec_list(); +GArray *dbus_audio_codec_list(); /** * ConfigurationManager - Get the audio codec details