[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r303281 - /team/dvossel/fixt...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 21 12:03:36 CST 2011


Author: dvossel
Date: Fri Jan 21 12:03:32 2011
New Revision: 303281

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=303281
Log:
performace improvement to chan_sip format negotation.

Modified:
    team/dvossel/fixtheworld_phase1_step3/channels/chan_sip.c

Modified: team/dvossel/fixtheworld_phase1_step3/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/channels/chan_sip.c?view=diff&rev=303281&r1=303280&r2=303281
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/channels/chan_sip.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/channels/chan_sip.c Fri Jan 21 12:03:32 2011
@@ -6548,17 +6548,12 @@
 	struct ast_channel *tmp;
 	struct ast_variable *v = NULL;
 	struct ast_format fmt;
-	struct ast_format_cap *what = ast_format_cap_alloc_nolock();
-	struct ast_format_cap *video = NULL;
-	struct ast_format_cap *text = NULL;
+	struct ast_format_cap *what = NULL; /* SHALLOW COPY DO NOT DESTROY! */
 	int needvideo = 0;
 	int needtext = 0;
 	char buf[SIPBUFSIZE];
 	char *decoded_exten;
 
-	if (!what) {
-		return NULL;
-	}
 	{
 		const char *my_name;	/* pick a good name */
 	
@@ -6575,7 +6570,6 @@
 	if (!tmp) {
 		ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n");
 		sip_pvt_lock(i);
-		ast_format_cap_destroy(what);
 		return NULL;
 	}
 	ast_channel_lock(tmp);
@@ -6589,28 +6583,19 @@
 	/* Select our native format based on codec preference until we receive
 	   something from another device to the contrary. */
 	if (!(ast_format_cap_is_empty(i->jointcaps))) {	/* The joint capabilities of us and peer */
-		ast_format_cap_copy2(what, i->jointcaps);
-		video = ast_format_cap_get_type(i->jointcaps, AST_FORMAT_TYPE_VIDEO);
-		text = ast_format_cap_get_type(i->jointcaps, AST_FORMAT_TYPE_TEXT);
+		what = i->jointcaps;
 	} else if (!(ast_format_cap_is_empty(i->caps))) {		/* Our configured capability for this peer */
-		ast_format_cap_copy2(what, i->caps);
-		video = ast_format_cap_get_type(i->caps, AST_FORMAT_TYPE_VIDEO);
-		text = ast_format_cap_get_type(i->caps, AST_FORMAT_TYPE_TEXT);
+		what = i->caps;
 	} else {
-		ast_format_cap_copy2(what, sip_cfg.caps);	/* Global codec support */
-		video = ast_format_cap_get_type(sip_cfg.caps, AST_FORMAT_TYPE_VIDEO);
-		text = ast_format_cap_get_type(sip_cfg.caps, AST_FORMAT_TYPE_TEXT);
-	}
-
-	/* Set the native formats for audio  and merge in video */
-	ast_codec_choose(&i->prefs, what, 1, &fmt);
-	if (video) {
-		ast_format_cap_append(tmp->nativeformats, video);
-	}
-	if (text) {
-		ast_format_cap_append(tmp->nativeformats, text);
-	}
-	ast_format_cap_add(tmp->nativeformats, &fmt);
+		what = sip_cfg.caps;
+	}
+
+	/* Set the native formats */
+	ast_format_cap_copy2(tmp->nativeformats, what);
+	/* choose and use only the best audio format for our native formats */
+	ast_codec_choose(&i->prefs, tmp->nativeformats, 1, &fmt); /* get the best audio format */
+	ast_format_cap_remove_bytype(tmp->nativeformats, AST_FORMAT_TYPE_AUDIO); /* remove only the other audio formats */
+	ast_format_cap_add(tmp->nativeformats, &fmt); /* add our best choice back */
 
 	ast_debug(3, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, tmp->nativeformats));
 	ast_debug(3, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->jointcaps));
@@ -6774,10 +6759,6 @@
 			"Channel: %s\r\nUniqueid: %s\r\nChanneltype: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\n",
 			tmp->name, tmp->uniqueid, "SIP", i->callid, i->fullcontact);
 	}
-
-	what = ast_format_cap_destroy(what);
-	video = ast_format_cap_destroy(video);
-	text = ast_format_cap_destroy(text);
 
 	return tmp;
 }




More information about the asterisk-commits mailing list