diff --git a/daemon/src/audio/codecs/audiocodecfactory.cpp b/daemon/src/audio/codecs/audiocodecfactory.cpp index ffa603e6328c2cd02e1c7ee88dfcb9073d8356c8..7bf87aa827a58aeeaea76367ab67e0c56e0fbe7c 100644 --- a/daemon/src/audio/codecs/audiocodecfactory.cpp +++ b/daemon/src/audio/codecs/audiocodecfactory.cpp @@ -105,9 +105,8 @@ AudioCodecFactory::getCodec (AudioCodecType payload) { CodecsMap::iterator iter = _CodecsMap.find (payload); - // FIXME: isn't this static cast pointless? if (iter != _CodecsMap.end()) - return static_cast<sfl::AudioCodec *>(iter->second); + return iter->second; _error ("CodecDescriptor: Error cannont found codec %i in _CodecsMap from codec descriptor", payload); diff --git a/daemon/src/dbus/configurationmanager.cpp b/daemon/src/dbus/configurationmanager.cpp index 86994d0f1ca4bdb344db55435042d92c2e2d8234..fa3688251343235171613d7073f14635dbee20b5 100644 --- a/daemon/src/dbus/configurationmanager.cpp +++ b/daemon/src/dbus/configurationmanager.cpp @@ -368,21 +368,17 @@ std::vector<std::string> ConfigurationManager::getRingtoneList() */ std::vector<std::string> ConfigurationManager::getAudioCodecList (void) { - std::vector<std::string> list; CodecsMap codecs = Manager::instance().getAudioCodecFactory().getCodecsMap(); - CodecsMap::iterator iter = codecs.begin(); - while (iter != codecs.end()) { + for (CodecsMap::iterator iter = codecs.begin(); iter != codecs.end(); ++iter) { std::stringstream ss; if (iter->second != NULL) { ss << iter->first; - list.push_back ( (ss.str()).data()); + list.push_back (ss.str()); } - - iter++; } return list; diff --git a/daemon/src/sip/sdp.cpp b/daemon/src/sip/sdp.cpp index 8c4b23fba6736aed0516f08cc9a0c60210d7f139..294396ea7923ff0abd07c8a0bb1f389fde3a06d2 100644 --- a/daemon/src/sip/sdp.cpp +++ b/daemon/src/sip/sdp.cpp @@ -276,12 +276,7 @@ void Sdp::setTelephoneEventRtpmap(pjmedia_sdp_media *med) void Sdp::setLocalMediaCapabilities (CodecOrder selectedCodecs) { - - unsigned int i; sdpMedia *audio; - CodecsMap codecs_list; - CodecsMap::iterator iter; - // Clean it first localAudioMediaCap_.clear(); @@ -292,19 +287,18 @@ void Sdp::setLocalMediaCapabilities (CodecOrder selectedCodecs) audio->set_port (getLocalPublishedAudioPort()); /* We retrieve the codecs selected by the user */ - codecs_list = Manager::instance().getAudioCodecFactory().getCodecsMap(); - - 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]); - - if (iter!=codecs_list.end()) { - audio->add_codec (iter->second); - } else { - _warn ("SDP: Couldn't find audio codec"); + 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); + else + _warn ("SDP: Couldn't find audio codec"); } } @@ -377,7 +371,7 @@ int Sdp::createOffer (CodecOrder selectedCodecs) int Sdp::receiveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCodecs) { - char buffer[1000]; + char buffer[1000]; _debug ("SDP: Receiving initial offer"); @@ -404,7 +398,7 @@ int Sdp::receiveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCod remoteSession_ = pjmedia_sdp_session_clone (memPool_, remote); status = pjmedia_sdp_neg_create_w_remote_offer (memPool_, localSession_, - remoteSession_, &negotiator_); + remoteSession_, &negotiator_); PJ_ASSERT_RETURN (status == PJ_SUCCESS, 1); @@ -413,89 +407,77 @@ int Sdp::receiveOffer (const pjmedia_sdp_session* remote, CodecOrder selectedCod int Sdp::receivingAnswerAfterInitialOffer(const pjmedia_sdp_session* remote) { - pj_status_t status; + pj_status_t status; - if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) { - _warn("SDP: Session not in a valid state for receiving answer"); - } + if (pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_LOCAL_OFFER) + _warn("SDP: Session not in a valid state for receiving answer"); - status = pjmedia_sdp_neg_set_remote_answer(memPool_, negotiator_, remote); + status = pjmedia_sdp_neg_set_remote_answer(memPool_, negotiator_, remote); - if(status != PJ_SUCCESS) { - _warn("SDP: Error: Could not set SDP remote answer"); - } + if (status != PJ_SUCCESS) + _warn("SDP: Error: Could not set SDP remote answer"); - if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { - _warn("SDP: Session not in a valid state after receiving answer"); - } + if (pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) + _warn("SDP: Session not in a valid state after receiving answer"); - return status; + return status; } int Sdp::generateAnswerAfterInitialOffer(void) { - pj_status_t status; - - if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER) { - _warn("SDP: Session not in a valid state for generating answer"); - } + pj_status_t status; - status = pjmedia_sdp_neg_set_local_answer (memPool_, negotiator_, localSession_); + if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_REMOTE_OFFER) + _warn("SDP: Session not in a valid state for generating answer"); - if(status != PJ_SUCCESS) { - _warn("SDP: Error: could not set SDP local answer"); - } + status = pjmedia_sdp_neg_set_local_answer (memPool_, negotiator_, localSession_); - if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { - _warn("SDP: Session not in a valid state after generating answer"); - } + if (status != PJ_SUCCESS) + _warn("SDP: Error: could not set SDP local answer"); - return status; + if (pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) + _warn("SDP: Session not in a valid state after generating answer"); + return status; } pj_status_t Sdp::startNegotiation() { pj_status_t status; - const pjmedia_sdp_session *active_local; - const pjmedia_sdp_session *active_remote; + const pjmedia_sdp_session *active_local; + const pjmedia_sdp_session *active_remote; _debug ("SDP: Start negotiation"); - if(negotiator_ == NULL) { - _error("SDP: Error: negotiator is NULL in SDP session"); - } + if (negotiator_ == NULL) + _error("SDP: Error: negotiator is NULL in SDP session"); - if(pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) { - _warn("SDP: Warning: negotiator not in wright state for negotiation"); - } + if (pjmedia_sdp_neg_get_state(negotiator_) != PJMEDIA_SDP_NEG_STATE_WAIT_NEGO) + _warn("SDP: Warning: negotiator not in wright state for negotiation"); status = pjmedia_sdp_neg_negotiate (memPool_, negotiator_, 0); - if(status != PJ_SUCCESS) { - return status; - } - - status = pjmedia_sdp_neg_get_active_local(negotiator_, &active_local); - if(status != PJ_SUCCESS) { - _error("SDP: Could not retrieve local active session"); - } - - setActiveLocalSdpSession(active_local); + if (status != PJ_SUCCESS) + return status; - status = pjmedia_sdp_neg_get_active_remote(negotiator_, &active_remote); - if(status != PJ_SUCCESS) { - _error("SDP: Could not retrieve remote active session"); - } + status = pjmedia_sdp_neg_get_active_local(negotiator_, &active_local); + if (status != PJ_SUCCESS) + _error("SDP: Could not retrieve local active session"); + else + setActiveLocalSdpSession(active_local); - setActiveRemoteSdpSession(active_remote); + status = pjmedia_sdp_neg_get_active_remote(negotiator_, &active_remote); + if (status != PJ_SUCCESS) + _error("SDP: Could not retrieve remote active session"); + else + setActiveRemoteSdpSession(active_remote); return status; } -void Sdp::updateInternalState() { - - // Populate internal field - setMediaTransportInfoFromRemoteSdp (activeRemoteSession_); +void Sdp::updateInternalState() +{ + // Populate internal field + setMediaTransportInfoFromRemoteSdp (activeRemoteSession_); } void Sdp::addProtocol () @@ -521,7 +503,6 @@ void Sdp::addOrigin () void Sdp::addSessionName () { - localSession_->name = STR_SDP_NAME; } @@ -545,7 +526,6 @@ void Sdp::addTiming () void Sdp::addAttributes() { - pjmedia_sdp_attr *a; localSession_->attr_count = 1; a = PJ_POOL_ZALLOC_T (memPool_, pjmedia_sdp_attr); @@ -575,10 +555,9 @@ void Sdp::addSdesAttribute (const std::vector<std::string>& crypto) // temporary buffer used to store crypto attribute char tempbuf[256]; - std::vector<std::string>::const_iterator iter = crypto.begin(); - - while (iter != crypto.end()) { - + for (std::vector<std::string>::const_iterator iter = crypto.begin(); + iter != crypto.end(); ++iter) + { // the attribute to add to sdp pjmedia_sdp_attr *attribute = (pjmedia_sdp_attr*) pj_pool_zalloc (memPool_, sizeof (pjmedia_sdp_attr)); @@ -588,7 +567,7 @@ void Sdp::addSdesAttribute (const std::vector<std::string>& crypto) int len = pj_ansi_snprintf (tempbuf, sizeof (tempbuf), - "%.*s", (int) (*iter).size(), (*iter).c_str()); + "%.*s", (int) (*iter).size(), (*iter).c_str()); attribute->value.slen = len; attribute->value.ptr = (char*) pj_pool_alloc (memPool_, attribute->value.slen+1); @@ -598,16 +577,9 @@ void Sdp::addSdesAttribute (const std::vector<std::string>& crypto) int media_count = localSession_->media_count; // add crypto attribute to media - for (int i = 0; i < media_count; i++) { - - if (pjmedia_sdp_media_add_attr (localSession_->media[i], attribute) != PJ_SUCCESS) { - // if(pjmedia_sdp_attr_add(&(_local_offer->attr_count), _local_offer->attr, attribute) != PJ_SUCCESS){ + for (int i = 0; i < media_count; i++) + if (pjmedia_sdp_media_add_attr (localSession_->media[i], attribute) != PJ_SUCCESS) throw SdpException ("Could not add sdes attribute to media"); - } - } - - - ++iter; } } @@ -624,41 +596,40 @@ void Sdp::addZrtpAttribute (pjmedia_sdp_media* media, std::string hash) /* Format: ":version value" */ len = pj_ansi_snprintf (tempbuf, sizeof (tempbuf), - "%.*s %.*s", - 4, - ZRTP_VERSION, - (int) hash.size(), - hash.c_str()); + "%.*s %.*s", + 4, + ZRTP_VERSION, + (int) hash.size(), + hash.c_str()); attribute->value.slen = len; attribute->value.ptr = (char*) pj_pool_alloc (memPool_, attribute->value.slen+1); pj_memcpy (attribute->value.ptr, tempbuf, attribute->value.slen+1); - if (pjmedia_sdp_media_add_attr (media, attribute) != PJ_SUCCESS) { + if (pjmedia_sdp_media_add_attr (media, attribute) != PJ_SUCCESS) throw SdpException ("Could not add zrtp attribute to media"); - } } Sdp::~Sdp() { - std::vector<sdpMedia *>::iterator iter = sessionAudioMedia_.begin(); - - for (iter = sessionAudioMedia_.begin(); iter != sessionAudioMedia_.end(); ++iter) + typedef std::vector<sdpMedia *>::iterator MediaIterator; + for (MediaIterator iter = sessionAudioMedia_.begin(); + iter != sessionAudioMedia_.end(); ++iter) delete *iter; - for (iter = localAudioMediaCap_.begin(); iter != localAudioMediaCap_.end(); ++iter) + for (MediaIterator iter = localAudioMediaCap_.begin(); + iter != localAudioMediaCap_.end(); ++iter) delete *iter; } void Sdp::setPortToAllMedia (int port) { + typedef std::vector<sdpMedia *>::iterator MediaIterator; setLocalPublishedAudioPort (port); - int size = localAudioMediaCap_.size(); - - for (int i = 0; i < size; i++) - localAudioMediaCap_[i]->set_port (port); + for (MediaIterator iter = localAudioMediaCap_.begin(); iter != localAudioMediaCap_.end(); ++iter) + (*iter)->set_port (port); } void Sdp::addAttributeToLocalAudioMedia(std::string attr) @@ -667,19 +638,18 @@ void Sdp::addAttributeToLocalAudioMedia(std::string attr) attribute = pjmedia_sdp_attr_create (memPool_, attr.c_str(), NULL); - pjmedia_sdp_media_add_attr (localSession_->media[0], attribute); + pjmedia_sdp_media_add_attr (localSession_->media[0], attribute); } void Sdp::removeAttributeFromLocalAudioMedia(std::string attr) { - pjmedia_sdp_media_remove_all_attr (localSession_->media[0], attr.c_str()); + pjmedia_sdp_media_remove_all_attr (localSession_->media[0], attr.c_str()); } void Sdp::setRemoteIpFromSdp (const pjmedia_sdp_session *r_sdp) { - - std::string remote_ip (r_sdp->conn->addr.ptr, r_sdp->conn->addr.slen); + const std::string remote_ip (r_sdp->conn->addr.ptr, r_sdp->conn->addr.slen); _info ("SDP: Remote IP from fetching SDP: %s", remote_ip.c_str()); this->setRemoteIP (remote_ip); } @@ -697,7 +667,7 @@ void Sdp::setMediaTransportInfoFromRemoteSdp (const pjmedia_sdp_session *remote_ _info ("SDP: Fetching media from sdp"); if (!remote_sdp) { - _error("Sdp: Error: Remote sdp is NULL while parsing media"); + _error("Sdp: Error: Remote sdp is NULL while parsing media"); return; } @@ -715,12 +685,10 @@ void Sdp::setMediaTransportInfoFromRemoteSdp (const pjmedia_sdp_session *remote_ void Sdp::getRemoteSdpMediaFromOffer (const pjmedia_sdp_session* remote_sdp, pjmedia_sdp_media** r_media) { - int count; - if (!remote_sdp) return; - count = remote_sdp->media_count; + int count = remote_sdp->media_count; *r_media = NULL; @@ -734,46 +702,42 @@ void Sdp::getRemoteSdpMediaFromOffer (const pjmedia_sdp_session* remote_sdp, pjm void Sdp::getRemoteSdpTelephoneEventFromOffer(const pjmedia_sdp_session *remote_sdp) { - int media_count, attr_count; - pjmedia_sdp_media *r_media = NULL; - pjmedia_sdp_attr *attribute; - pjmedia_sdp_rtpmap *rtpmap; - - if(!remote_sdp) { - _error("Sdp: Error: Remote sdp is NULL while parsing telephone event attribute"); - return; - } - - media_count = remote_sdp->media_count; - - for(int i = 0; i < media_count; i++) { - if(pj_stricmp2(&remote_sdp->media[i]->desc.media, "audio") == 0) { - r_media = remote_sdp->media[i]; - break; - } - } + int media_count, attr_count; + pjmedia_sdp_media *r_media = NULL; + pjmedia_sdp_attr *attribute; + pjmedia_sdp_rtpmap *rtpmap; - if(r_media == NULL) { - _error("Sdp: Error: Could not found dtmf event gfrom remote sdp"); - return; - } + if(!remote_sdp) { + _error("Sdp: Error: Remote sdp is NULL while parsing telephone event attribute"); + return; + } - attr_count = r_media->attr_count; + media_count = remote_sdp->media_count; - attribute = pjmedia_sdp_attr_find(attr_count, r_media->attr, &STR_TELEPHONE_EVENT, NULL); + for (int i = 0; i < media_count; i++) { + if(pj_stricmp2(&remote_sdp->media[i]->desc.media, "audio") == 0) { + r_media = remote_sdp->media[i]; + break; + } + } - if(attribute != NULL) { + if (r_media == NULL) { + _error("Sdp: Error: Could not found dtmf event gfrom remote sdp"); + return; + } - pjmedia_sdp_attr_to_rtpmap (memPool_, attribute, &rtpmap); + attr_count = r_media->attr_count; - telephoneEventPayload_ = pj_strtoul (&rtpmap->pt); - } + attribute = pjmedia_sdp_attr_find(attr_count, r_media->attr, &STR_TELEPHONE_EVENT, NULL); + if (attribute != NULL) { + pjmedia_sdp_attr_to_rtpmap (memPool_, attribute, &rtpmap); + telephoneEventPayload_ = pj_strtoul (&rtpmap->pt); + } } void Sdp::getRemoteSdpCryptoFromOffer (const pjmedia_sdp_session* remote_sdp, CryptoOffer& crypto_offer) { - int i, j; int attr_count, media_count; pjmedia_sdp_attr *attribute; @@ -812,4 +776,3 @@ void Sdp::getRemoteSdpCryptoFromOffer (const pjmedia_sdp_session* remote_sdp, Cr } } } - diff --git a/gnome/src/actions.c b/gnome/src/actions.c index 85c895a92f7712793e8c7637182246123f69c5d5..6f7885e56ea07f1dfa52468191f78edc48763458 100644 --- a/gnome/src/actions.c +++ b/gnome/src/actions.c @@ -1046,7 +1046,6 @@ sflphone_join_participant (const gchar* sel_callID, const gchar* drag_callID) { DEBUG ("sflphone join participants %s and %s", sel_callID, drag_callID); - dbus_join_participant (sel_callID, drag_callID); } @@ -1060,9 +1059,9 @@ sflphone_add_participant (const gchar* callID, const gchar* confID) DEBUG (">SFLphone: Add participant %s to conference %s", callID, confID); call = calllist_get_call(current_calls, callID); - if(call == NULL) { - ERROR("SFLphone: Error: Could not find call"); - return; + if (call == NULL) { + ERROR("SFLphone: Error: Could not find call"); + return; } set_timestamp(&call->_time_added); @@ -1160,7 +1159,6 @@ sflphone_rec_call() void sflphone_fill_codec_list () { - guint account_list_size; guint i; account_t *current = NULL; @@ -1172,20 +1170,17 @@ void sflphone_fill_codec_list () for (i=0; i<account_list_size; i++) { current = account_list_get_nth (i); - if (current) { + if (current) sflphone_fill_codec_list_per_account (¤t); - } } } void sflphone_fill_codec_list_per_account (account_t **account) { - gchar **order; gchar** pl; GQueue *codeclist; - gboolean active = FALSE; order = (gchar**) dbus_get_active_audio_codec_list ( (*account)->accountID); @@ -1194,36 +1189,32 @@ void sflphone_fill_codec_list_per_account (account_t **account) // First clean the list codec_list_clear (&codeclist); - if (! (*order)) + if (!(*order)) ERROR ("SFLphone: No codec list provided"); - - for (pl=order; *pl; pl++) { - codec_t * cpy = NULL; - - // Each account will have a copy of the system-wide capabilities - codec_create_new_from_caps (codec_list_get_by_payload ( (gconstpointer) (size_t) atoi (*pl), NULL), &cpy); - - if (cpy) { - cpy->is_active = TRUE; - codec_list_add (cpy, &codeclist); - } else - ERROR ("SFLphone: Couldn't find codec"); + else { + for (pl = order; *pl; pl++) { + codec_t * cpy = NULL; + + // Each account will have a copy of the system-wide capabilities + codec_create_new_from_caps (codec_list_get_by_payload ( (gconstpointer) (size_t) atoi (*pl), NULL), &cpy); + + if (cpy) { + cpy->is_active = TRUE; + codec_list_add (cpy, &codeclist); + } else + ERROR ("SFLphone: Couldn't find codec"); + } } - // Test here if we just added some active codec. - active = (codeclist->length == 0) ? TRUE : FALSE; - - guint caps_size = codec_list_get_size (), i=0; + guint caps_size = codec_list_get_size (); + guint i; for (i = 0; i < caps_size; i++) { - codec_t * current_cap = capabilities_get_nth (i); // Check if this codec has already been enabled for this account if (codec_list_get_by_payload ( (gconstpointer) (size_t) (current_cap->_payload), codeclist) == NULL) { - // codec_t *cpy; - // codec_create_new_from_caps (current_cap, &cpy); - current_cap->is_active = active; + current_cap->is_active = FALSE; codec_list_add (current_cap, &codeclist); } } diff --git a/gnome/src/codeclist.c b/gnome/src/codeclist.c index c05adcec0ccacf4d17c66de68988377830ed07f5..7b7ecc09e830a4aae507056d71d9b5bdcd18ba30 100644 --- a/gnome/src/codeclist.c +++ b/gnome/src/codeclist.c @@ -62,8 +62,6 @@ is_payload_codecstruct (gconstpointer a, gconstpointer b) void codec_capabilities_load (void) { - guint payload; - // Create the queue object that will contain the global list of audio codecs if (codecsCapabilities != NULL) g_queue_free (codecsCapabilities); @@ -77,9 +75,8 @@ void codec_capabilities_load (void) if (codecs != NULL) { // Add the codecs in the list for (; *codecs; codecs++) { - codec_t *c; - payload = atoi (*codecs); + guint payload = atoi (*codecs); gchar **specs = dbus_audio_codec_details (payload); codec_create_new_with_specs (payload, specs, TRUE, &c); g_strfreev(specs); @@ -91,7 +88,6 @@ void codec_capabilities_load (void) // If we didn't load any codecs, problem ... if (g_queue_get_length (codecsCapabilities) == 0) { - // Error message ERROR ("No audio codecs found"); dbus_unregister (getpid()); @@ -115,7 +111,6 @@ void account_create_codec_list (account_t **acc) void codec_create_new (gint payload, gboolean active, codec_t **c) { - codec_t *codec; gchar **specs; @@ -132,7 +127,6 @@ void codec_create_new (gint payload, gboolean active, codec_t **c) void codec_create_new_with_specs (gint payload, gchar **specs, gboolean active, codec_t **c) { - codec_t *codec; codec = g_new0 (codec_t, 1); @@ -147,7 +141,6 @@ void codec_create_new_with_specs (gint payload, gchar **specs, gboolean active, void codec_create_new_from_caps (codec_t *original, codec_t **copy) { - codec_t *codec; if (!original) { @@ -168,29 +161,19 @@ void codec_create_new_from_caps (codec_t *original, codec_t **copy) void codec_list_clear (GQueue **queue) { - if (*queue != NULL) g_queue_free (*queue); - *queue = g_queue_new(); } -/*void codec_list_clear (void) { - - g_queue_free (codecsCapabilities); - codecsCapabilities = g_queue_new(); -}*/ - void codec_list_add (codec_t * c, GQueue **queue) { - // Add a codec to a specific list g_queue_push_tail (*queue, (gpointer *) c); } void codec_set_active (codec_t **c) { - if (c) { DEBUG ("%s set active", (*c)->name); (*c)->is_active = TRUE; @@ -199,16 +182,14 @@ void codec_set_active (codec_t **c) void codec_set_inactive (codec_t **c) { - if (c) { - DEBUG ("%s set active", (*c)->name); + DEBUG ("%s set inactive", (*c)->name); (*c)->is_active = FALSE; } } guint codec_list_get_size () { - // The system wide codec list and the one per account have exactly the same size // The only difference may be the order and the enabled codecs return g_queue_get_length (codecsCapabilities); @@ -216,7 +197,6 @@ guint codec_list_get_size () codec_t* codec_list_get_by_name (gconstpointer name, GQueue *q) { - // If NULL is passed as argument, we look into the global capabilities if (q == NULL) q = codecsCapabilities; @@ -231,7 +211,6 @@ codec_t* codec_list_get_by_name (gconstpointer name, GQueue *q) codec_t* codec_list_get_by_payload (gconstpointer payload, GQueue *q) { - // If NULL is passed as argument, we look into the global capabilities if (q == NULL) q = codecsCapabilities; @@ -251,13 +230,11 @@ codec_t* codec_list_get_nth (guint index, GQueue *q) codec_t* capabilities_get_nth (guint index) { - return g_queue_peek_nth (codecsCapabilities, index); } void codec_set_prefered_order (guint index, GQueue *q) { - codec_t * prefered = codec_list_get_nth (index, q); g_queue_pop_nth (q, index); g_queue_push_head (q, prefered); @@ -265,7 +242,6 @@ void codec_set_prefered_order (guint index, GQueue *q) void codec_list_move_codec_up (guint index, GQueue **q) { - DEBUG ("Codec list Size: %i \n", codec_list_get_size ()); GQueue *tmp = *q; @@ -276,17 +252,16 @@ void codec_list_move_codec_up (guint index, GQueue **q) } *q = tmp; - } void codec_list_move_codec_down (guint index, GQueue **q) { - DEBUG ("Codec list Size: %i \n",codec_list_get_size()); + DEBUG ("Codec list Size: %i \n", codec_list_get_size()); GQueue *tmp = *q; - if (index != tmp->length) { + if (index != g_queue_get_length(tmp) ) { gpointer codec = g_queue_pop_nth (tmp, index); g_queue_push_nth (tmp, codec, index+1); } @@ -297,33 +272,29 @@ void codec_list_move_codec_down (guint index, GQueue **q) void codec_list_update_to_daemon (account_t *acc) { - - // String listing codecs payloads - const gchar** codecList; - // Length of the codec list - int length = acc->codecs->length; + int length = g_queue_get_length(acc->codecs); + // String listing codecs payloads // Initiate double array char list for one string - codecList = (void*) malloc (sizeof (void*)); + const gchar **codecList = (void*) g_malloc (sizeof (void*)); // Get all codecs in queue int c = 0; - int i = 0; + int i; for (i = 0; i < length; i++) { codec_t* currentCodec = codec_list_get_nth (i, acc->codecs); - // Assert not null if (currentCodec) { // Save only if active if (currentCodec->is_active) { // Reallocate memory each time more than one active codec is found - if (c!=0) - codecList = (void*) realloc (codecList, (c+1) *sizeof (void*)); + if (c != 0) + codecList = (void*) g_realloc (codecList, (c + 1) * sizeof (void*)); // Allocate memory for the payload - * (codecList+c) = (gchar*) malloc (sizeof (gchar*)); + * (codecList + c) = (gchar*) g_malloc (sizeof (gchar*)); char payload[10]; // Put payload string in char array sprintf (payload, "%d", currentCodec->_payload); @@ -334,21 +305,20 @@ void codec_list_update_to_daemon (account_t *acc) } // Allocate NULL array at the end for Dbus - codecList = (void*) realloc (codecList, (c+1) *sizeof (void*)); + codecList = (void*) g_realloc (codecList, (c + 1) * sizeof (void*)); * (codecList+c) = NULL; // call dbus function with array of strings dbus_set_active_audio_codec_list (codecList, acc->accountID); // Delete memory - for (i = 0; i < c; i++) { - free ( (gchar*) * (codecList+i)); - } + for (i = 0; i < c; i++) + g_free ( (gchar*) * (codecList+i)); - free (codecList); + g_free (codecList); } GQueue* get_system_codec_list (void) { - return codecsCapabilities; + return codecsCapabilities; } diff --git a/gnome/src/config/audioconf.c b/gnome/src/config/audioconf.c index 0ad9bb353ac149a2353ce4eed57ae88ff8ebbe9e..f1cbebd08914f03f945cc1abd216ca8c689b243e 100644 --- a/gnome/src/config/audioconf.c +++ b/gnome/src/config/audioconf.c @@ -69,7 +69,6 @@ static void active_is_always_recording (void); */ static void preferences_dialog_fill_codec_list (account_t *a) { - GtkListStore *codecStore; GtkTreeIter iter; GQueue *current; @@ -79,11 +78,12 @@ static void preferences_dialog_fill_codec_list (account_t *a) gtk_list_store_clear (codecStore); current = a ? a->codecs : get_system_codec_list (); + if (!a) DEBUG("Using system codec list"); // Insert codecs unsigned int i; - for (i = 0; i < current->length; i++) { + for (i = 0; i < g_queue_get_length(current); i++) { codec_t *c = codec_list_get_nth (i, current); if (c) { @@ -543,11 +543,10 @@ codec_active_toggled (GtkCellRendererToggle *renderer UNUSED, gchar *path, gpoin gtk_tree_path_free (treePath); // Modify codec queue to represent change - if (active) { + if (active) codec_set_active (&codec); - } else { + else codec_set_inactive (&codec); - } } /**