pidgin.vv.yahoo.voice: 9d6cc5a4: Move SDP parsing to its own function.
maiku at pidgin.im
maiku at pidgin.im
Mon Aug 31 00:15:40 EDT 2009
-----------------------------------------------------------------
Revision: 9d6cc5a4aa44d370386bf1578e7db9c313e461ff
Ancestor: 2c2a838006c159388ba4d8fc7f30e7166bcabaca
Author: maiku at pidgin.im
Date: 2009-08-31T00:31:01
Branch: im.pidgin.pidgin.vv.yahoo.voice
URL: http://d.pidgin.im/viewmtn/revision/info/9d6cc5a4aa44d370386bf1578e7db9c313e461ff
Modified files:
libpurple/protocols/yahoo/yahoo_sip.c
ChangeLog:
Move SDP parsing to its own function.
-------------- next part --------------
============================================================
--- libpurple/protocols/yahoo/yahoo_sip.c eeb67c8bdf7923950b54347cca5c0e3da20ea2f2
+++ libpurple/protocols/yahoo/yahoo_sip.c 77f91fbb73db99d8ba58ce996d98e0aa93e2dea6
@@ -69,6 +69,142 @@ send_yahooref(gpointer nh)
return TRUE;
}
+static GParameter*
+yahoo_get_media_params(YahooSip *ysip, guint *num_params)
+{
+ GParameter *params;
+
+ if (ysip->stun_ip && !purple_network_get_stun_ip()) {
+ params = g_new0(GParameter, 2);
+ *num_params = 2;
+ params[1].name = "stun-ip";
+ params[1].value.g_type = 0;
+ g_value_init(¶ms[1].value, G_TYPE_STRING);
+ g_value_set_string(¶ms[1].value, ysip->stun_ip);
+ } else {
+ params = g_new0(GParameter, 1);
+ *num_params = 1;
+ }
+
+ /* NICE_COMPATIBILITY_YAHOO */
+ params[0].name = "compatibility-mode";
+ params[0].value.g_type = 0;
+ g_value_init(¶ms[0].value, G_TYPE_UINT);
+ g_value_set_uint(¶ms[0].value, 4);
+
+ return params;
+}
+
+static gboolean
+yahoo_sdp_to_stream(PurpleMedia *media, const gchar *name,
+ sdp_media_t *sdp_media)
+{
+ GList *ids = NULL, *codecs = NULL, *candidates = NULL;
+ sdp_rtpmap_t *codec_iter;
+ sdp_attribute_t *conn_iter;
+ const gchar *session_id;
+ PurpleMediaSessionType type;
+
+ g_return_val_if_fail(PURPLE_IS_MEDIA(media), FALSE);
+ g_return_val_if_fail(sdp_media, FALSE);
+
+ if (sdp_media->m_type == sdp_media_audio) {
+ session_id = "yahoo-voice";
+ type = PURPLE_MEDIA_AUDIO;
+ } else if (sdp_media->m_type == sdp_media_video) {
+ session_id = "yahoo-video";
+ type = PURPLE_MEDIA_VIDEO;
+ } else {
+ purple_debug_warning("yahoo",
+ "sdp_to_stream: unknown media type\n");
+ return FALSE;
+ }
+
+ ids = purple_media_get_session_ids(media);
+ for (; ids; ids = g_list_delete_link(ids, ids)) {
+ if (!strcmp(ids->data, session_id))
+ break;
+ }
+ if (ids == NULL) {
+ PurpleAccount *account = purple_media_get_account(media);
+ PurpleConnection *pc = purple_account_get_connection(account);
+ YahooData *yd = purple_connection_get_protocol_data(pc);
+ YahooSip *ysip = yd->ysip;
+ guint num_params;
+ GParameter *params;
+ params = yahoo_get_media_params(ysip, &num_params);
+ purple_media_add_stream(media, session_id, name,
+ type, FALSE, "nice",
+ num_params, params);
+ g_free(params);
+ } else
+ g_list_free(ids);
+
+ codec_iter = sdp_media->m_rtpmaps;
+ conn_iter = sdp_media->m_attributes;
+
+ for (; codec_iter; codec_iter = codec_iter->rm_next) {
+ PurpleMediaCodec *codec = purple_media_codec_new(
+ codec_iter->rm_pt, codec_iter->rm_encoding,
+ PURPLE_MEDIA_AUDIO, codec_iter->rm_rate);
+ /* XXX: Need to add FsCodec parameters if they exist */
+ purple_debug_info("yahoo", "codec: a=rtpmap:%d %s/%lu"
+ " rm_params: %s rm_fmtp: %s\n",
+ codec_iter->rm_pt, codec_iter->rm_encoding,
+ codec_iter->rm_rate, codec_iter->rm_params,
+ codec_iter->rm_fmtp);
+ codecs = g_list_append(codecs, codec);
+ }
+ purple_media_set_remote_codecs(media, session_id,
+ name, codecs);
+ purple_media_codec_list_free(codecs);
+
+ for (; conn_iter; conn_iter = conn_iter->a_next) {
+ PurpleMediaCandidate *candidate;
+ gchar **c;
+ guint type;
+ if (strcmp(conn_iter->a_name, "candidate"))
+ continue;
+ c = g_strsplit(conn_iter->a_value, " ", 0);
+ purple_debug_info("yahoo", "candidate ?: %s "
+ "component-id: %s ?: %s network-type:"
+ " %s ?: %s ip: %s port: %s "
+ "channel-type: %s\n", c[0], c[1],
+ c[2], c[3], c[4], c[5], c[6], c[8]);
+ type = atoi(c[8]);
+ candidate= purple_media_candidate_new(c[0], atoi(c[1]), type == 1 ?
+ PURPLE_MEDIA_CANDIDATE_TYPE_HOST : type == 2 ?
+ PURPLE_MEDIA_CANDIDATE_TYPE_SRFLX :
+ PURPLE_MEDIA_CANDIDATE_TYPE_RELAY,
+ !strcmp(c[3], "UDP") ?
+ PURPLE_MEDIA_NETWORK_PROTOCOL_UDP :
+ PURPLE_MEDIA_NETWORK_PROTOCOL_TCP,
+ c[5], atoi(c[6]));
+ g_object_set(G_OBJECT(candidate), "username",
+ c[0], "password", c[2], NULL);
+ purple_debug_info("yahoo", "candidate a_value: %s\n",
+ conn_iter->a_value);
+ g_strfreev(c);
+ candidates = g_list_append(candidates, candidate);
+ }
+ purple_media_add_remote_candidates(media, session_id,
+ name, candidates);
+ purple_media_candidate_list_free(candidates);
+ return TRUE;
+}
+
+static gboolean
+yahoo_sdp_parse_media(PurpleMedia *media, const gchar *name,
+ sdp_media_t *sdp_media)
+{
+ g_return_val_if_fail(sdp_media, FALSE);
+ for (; sdp_media; sdp_media = sdp_media->m_next) {
+ if (!yahoo_sdp_to_stream(media, name, sdp_media))
+ return FALSE;
+ }
+ return TRUE;
+}
+
static void
yahoo_sip_send_response(PurpleMedia *media, nua_handle_t *nh)
{
@@ -314,8 +450,8 @@ event_callback(nua_event_t event, int st
PurpleConnection *pc = purple_account_get_connection(account);
YahooData *yd = pc->proto_data;
YahooSip *ysip = yd->ysip;
- GParameter params[2];
- guint num_params = 1;
+ GParameter *params;
+ guint num_params;
sip_unknown_t *iter = sip_unknown(sip);
purple_debug_info("yahoo", "INVITE status %d display: %s\n",
@@ -365,23 +501,11 @@ event_callback(nua_event_t event, int st
g_signal_connect(G_OBJECT(media), "stream-info",
G_CALLBACK(yahoo_sip_stream_info_cb), nh);
- /* NICE_COMPATIBILITY_YAHOO */
- params[0].name = "compatibility-mode";
- params[0].value.g_type = 0;
- g_value_init(¶ms[0].value, G_TYPE_UINT);
- g_value_set_uint(¶ms[0].value, 4);
-
- if (ysip->stun_ip && !purple_network_get_stun_ip()) {
- num_params = 2;
- params[1].name = "stun-ip";
- params[1].value.g_type = 0;
- g_value_init(¶ms[1].value, G_TYPE_STRING);
- g_value_set_string(¶ms[1].value, ysip->stun_ip);
- }
-
+ params = yahoo_get_media_params(ysip, &num_params);
purple_media_add_stream(media, "yahoo-voice", name,
PURPLE_MEDIA_AUDIO, FALSE, "nice",
num_params, params);
+ g_free(params);
} else if (event == nua_i_state && status == 100) {
/*
* This has a phrase of "Trying" if not,
@@ -391,9 +515,6 @@ event_callback(nua_event_t event, int st
const gchar *name = purple_url_decode(
nua_handle_remote(nh)->a_display);
sdp_media_t *sdp_media;
- sdp_rtpmap_t *codec_iter;
- sdp_attribute_t *conn_iter;
- GList *codecs = NULL, *candidates = NULL;
PurpleMedia *media = hmagic;
tl_gets(tags, SOATAG_REMOTE_SDP_REF(sdp_session), TAG_END());
@@ -402,9 +523,6 @@ event_callback(nua_event_t event, int st
"remote SDP from invitation.\n");
return;
}
- sdp_media = sdp_session->sdp_media;
- codec_iter = sdp_media->m_rtpmaps;
- conn_iter = sdp_media->m_attributes;
if (!PURPLE_IS_MEDIA(media)) {
purple_debug_error("yahoo", "Couldn't find media "
@@ -412,53 +530,12 @@ event_callback(nua_event_t event, int st
return;
}
- for (; codec_iter; codec_iter = codec_iter->rm_next) {
- PurpleMediaCodec *codec = purple_media_codec_new(
- codec_iter->rm_pt, codec_iter->rm_encoding,
- PURPLE_MEDIA_AUDIO, codec_iter->rm_rate);
- /* XXX: Need to add FsCodec parameters if they exist */
- purple_debug_info("yahoo", "codec: a=rtpmap:%d %s/%lu"
- " rm_params: %s rm_fmtp: %s\n",
- codec_iter->rm_pt, codec_iter->rm_encoding,
- codec_iter->rm_rate, codec_iter->rm_params,
- codec_iter->rm_fmtp);
- codecs = g_list_append(codecs, codec);
- }
- purple_media_set_remote_codecs(media, "yahoo-voice",
- name, codecs);
- purple_media_codec_list_free(codecs);
+ sdp_media = sdp_session->sdp_media;
- for (; conn_iter; conn_iter = conn_iter->a_next) {
- PurpleMediaCandidate *candidate;
- gchar **c;
- guint type;
- if (strcmp(conn_iter->a_name, "candidate"))
- continue;
- c = g_strsplit(conn_iter->a_value, " ", 0);
- purple_debug_info("yahoo", "candidate ?: %s "
- "component-id: %s ?: %s network-type:"
- " %s ?: %s ip: %s port: %s "
- "channel-type: %s\n", c[0], c[1],
- c[2], c[3], c[4], c[5], c[6], c[8]);
- type = atoi(c[8]);
- candidate= purple_media_candidate_new(c[0], atoi(c[1]), type == 1 ?
- PURPLE_MEDIA_CANDIDATE_TYPE_HOST : type == 2 ?
- PURPLE_MEDIA_CANDIDATE_TYPE_SRFLX :
- PURPLE_MEDIA_CANDIDATE_TYPE_RELAY,
- !strcmp(c[3], "UDP") ?
- PURPLE_MEDIA_NETWORK_PROTOCOL_UDP :
- PURPLE_MEDIA_NETWORK_PROTOCOL_TCP,
- c[5], atoi(c[6]));
- g_object_set(G_OBJECT(candidate), "username",
- c[0], "password", c[2], NULL);
- purple_debug_info("yahoo", "candidate a_value: %s\n",
- conn_iter->a_value);
- g_strfreev(c);
- candidates = g_list_append(candidates, candidate);
+ if (!yahoo_sdp_parse_media(media, name, sdp_media)) {
+ purple_debug_error("yahoo", "Error parsing SDP.\n");
+ return;
}
- purple_media_add_remote_candidates(media, "yahoo-voice",
- name, candidates);
- purple_media_codec_list_free(candidates);
} else if ((event == nua_i_bye || event == nua_i_cancel)
&& status >= 200) {
PurpleMedia *media = hmagic;
More information about the Commits
mailing list