[asterisk-commits] file: branch file/rtp_engine-mark2 r184189 - in /team/file/rtp_engine-mark2: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 25 09:16:34 CDT 2009


Author: file
Date: Wed Mar 25 09:16:29 2009
New Revision: 184189

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=184189
Log:
Be sure to bump the reference count when each glue callback returns an RTP instance. Additionally implement a function needed for early bridging. Copy codec information to the actual RTP instance in chan_sip.

Modified:
    team/file/rtp_engine-mark2/apps/app_dial.c
    team/file/rtp_engine-mark2/channels/chan_gtalk.c
    team/file/rtp_engine-mark2/channels/chan_h323.c
    team/file/rtp_engine-mark2/channels/chan_jingle.c
    team/file/rtp_engine-mark2/channels/chan_mgcp.c
    team/file/rtp_engine-mark2/channels/chan_sip.c
    team/file/rtp_engine-mark2/channels/chan_skinny.c
    team/file/rtp_engine-mark2/channels/chan_unistim.c
    team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h
    team/file/rtp_engine-mark2/main/rtp_engine.c

Modified: team/file/rtp_engine-mark2/apps/app_dial.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/apps/app_dial.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/apps/app_dial.c (original)
+++ team/file/rtp_engine-mark2/apps/app_dial.c Wed Mar 25 09:16:29 2009
@@ -54,7 +54,7 @@
 #include "asterisk/utils.h"
 #include "asterisk/app.h"
 #include "asterisk/causes.h"
-#include "asterisk/rtp.h"
+#include "asterisk/rtp_engine.h"
 #include "asterisk/cdr.h"
 #include "asterisk/manager.h"
 #include "asterisk/privacy.h"
@@ -745,7 +745,9 @@
 		char *new_cid_num, *new_cid_name;
 		struct ast_channel *src;
 
-		ast_rtp_make_compatible(c, in, single);
+		if (single) {
+			ast_rtp_instance_early_bridge_make_compatible(c, in);
+		}
 		if (ast_test_flag64(o, OPT_FORCECLID)) {
 			new_cid_num = ast_strdup(S_OR(in->macroexten, in->exten));
 			new_cid_name = NULL; /* XXX no name ? */
@@ -1745,7 +1747,9 @@
 		pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", numsubst);
 
 		/* Setup outgoing SDP to match incoming one */
-		ast_rtp_make_compatible(tc, chan, !outgoing && !rest);
+		if (!outgoing && !rest) {
+			ast_rtp_instance_early_bridge_make_compatible(tc, chan);
+		}
 		
 		/* Inherit specially named variables from parent channel */
 		ast_channel_inherit_variables(chan, tc);

Modified: team/file/rtp_engine-mark2/channels/chan_gtalk.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_gtalk.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_gtalk.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_gtalk.c Wed Mar 25 09:16:29 2009
@@ -521,6 +521,7 @@
 
 	ast_mutex_lock(&p->lock);
 	if (p->rtp){
+		ao2_ref(p->rtp, +1);
 		*instance = p->rtp;
 		res = AST_RTP_GLUE_RESULT_LOCAL;
 	}

Modified: team/file/rtp_engine-mark2/channels/chan_h323.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_h323.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_h323.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_h323.c Wed Mar 25 09:16:29 2009
@@ -3121,7 +3121,7 @@
 		return AST_RTP_GLUE_RESULT_FORBID;
 
 	ast_mutex_lock(&pvt->lock);
-	*instance = pvt->rtp;
+	*instance = pvt->rtp ? ao2_ref(pvt->rtp, +1), pvt->rtp : NULL;
 #if 0
 	if (pvt->options.bridge) {
 		res = AST_RTP_GLUE_RESULT_REMOTE;

Modified: team/file/rtp_engine-mark2/channels/chan_jingle.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_jingle.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_jingle.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_jingle.c Wed Mar 25 09:16:29 2009
@@ -393,6 +393,7 @@
 
 	ast_mutex_lock(&p->lock);
 	if (p->rtp) {
+		ao2_ref(p->rtp, +1);
 		*instance = p->rtp;
 		res = AST_RTP_GLUE_RESULT_LOCAL;
 	}

Modified: team/file/rtp_engine-mark2/channels/chan_mgcp.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_mgcp.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_mgcp.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_mgcp.c Wed Mar 25 09:16:29 2009
@@ -3944,7 +3944,7 @@
 	if (!(sub = chan->tech_pvt) || !(sub->rtp))
 		return AST_RTP_GLUE_RESULT_FORBID;
 
-	*instance = sub->rtp;
+	*instance = sub->rtp ? ao2_ref(sub->rtp, +1), sub->rtp : NULL;
 
 	if (sub->parent->canreinvite)
 		return AST_RTP_GLUE_RESULT_REMOTE;

Modified: team/file/rtp_engine-mark2/channels/chan_sip.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_sip.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_sip.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_sip.c Wed Mar 25 09:16:29 2009
@@ -8064,6 +8064,10 @@
 		p->red = 0;
 	}
 
+	ast_rtp_codecs_payloads_copy(&newaudiortp, &p->rtp->codecs, p->rtp);
+	if (p->vrtp) {
+		ast_rtp_codecs_payloads_copy(&newvideortp, &p->vrtp->codecs, p->vrtp);
+	}
 	if (p->trtp) {
 		ast_rtp_codecs_payloads_copy(&newtextrtp, &p->trtp->codecs, p->trtp);
 	}
@@ -23875,8 +23879,9 @@
                 return AST_RTP_GLUE_RESULT_FORBID;
         }
 
-        *instance = p->rtp;
-	
+	ao2_ref(p->rtp, +1);
+	*instance = p->rtp;
+
         if (!ast_test_flag(&p->flags[0], SIP_CAN_REINVITE_NAT)) {
                 res = AST_RTP_GLUE_RESULT_LOCAL;
 	} else if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) {
@@ -23905,6 +23910,7 @@
 		return AST_RTP_GLUE_RESULT_FORBID;
 	}
 
+	ao2_ref(p->vrtp, +1);
 	*instance = p->vrtp;
 
 	if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) {
@@ -23931,6 +23937,7 @@
                 return AST_RTP_GLUE_RESULT_FORBID;
         }
 
+	ao2_ref(p->trtp, +1);
         *instance = p->trtp;
 
         if (ast_test_flag(&p->flags[0], SIP_CAN_REINVITE)) {

Modified: team/file/rtp_engine-mark2/channels/chan_skinny.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_skinny.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_skinny.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_skinny.c Wed Mar 25 09:16:29 2009
@@ -2564,6 +2564,7 @@
 	if (!(sub = c->tech_pvt) || !(sub->vrtp))
 		return AST_RTP_GLUE_RESULT_FORBID;
 
+	ao2_ref(sub->vrtp, +1);
 	*instance = sub->vrtp;
 
 	return AST_RTP_GLUE_RESULT_REMOTE;
@@ -2589,6 +2590,7 @@
 		return AST_RTP_GLUE_RESULT_FORBID;
 	}
 
+	ao2_ref(sub->rtp, +1);
 	*instance = sub->rtp;
 
 	l = sub->parent;

Modified: team/file/rtp_engine-mark2/channels/chan_unistim.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/channels/chan_unistim.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/channels/chan_unistim.c (original)
+++ team/file/rtp_engine-mark2/channels/chan_unistim.c Wed Mar 25 09:16:29 2009
@@ -5530,6 +5530,7 @@
 {
 	struct unistim_subchannel *sub = chan->tech_pvt;
 
+	ao2_ref(sub->rtp, +1);
 	*instance = sub->rtp;
 
 	return AST_RTP_GLUE_RESULT_LOCAL;

Modified: team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h (original)
+++ team/file/rtp_engine-mark2/include/asterisk/rtp_engine.h Wed Mar 25 09:16:29 2009
@@ -61,6 +61,8 @@
 #if defined(__cplusplus) || defined(c_plusplus)
 extern "C" {
 #endif
+
+#include "asterisk/astobj2.h"
 
 /* Maximum number of payloads supported */
 #define AST_RTP_MAX_PT 256
@@ -1051,6 +1053,14 @@
  */
 enum ast_bridge_result ast_rtp_instance_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
 
+/*! \brief Make two channels compatible for early bridging
+ *
+ * \param c0 First channel part of the bridge
+ * \param c1 Second channel part of the bridge
+ *
+ */
+void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
+
 /*! \brief Early bridge two channels that use RTP instances
  *
  * \param c0 First channel part of the bridge

Modified: team/file/rtp_engine-mark2/main/rtp_engine.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/rtp_engine-mark2/main/rtp_engine.c?view=diff&rev=184189&r1=184188&r2=184189
==============================================================================
--- team/file/rtp_engine-mark2/main/rtp_engine.c (original)
+++ team/file/rtp_engine-mark2/main/rtp_engine.c Wed Mar 25 09:16:29 2009
@@ -1224,6 +1224,90 @@
 	return res;
 }
 
+void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c0, struct ast_channel *c1)
+{
+	struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
+		*vinstance0 = NULL, *vinstance1 = NULL,
+		*tinstance0 = NULL, *tinstance1 = NULL;
+	struct ast_rtp_glue *glue0, *glue1;
+	enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID, text_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
+	enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID, text_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
+	int codec0 = 0, codec1 = 0;
+	int res = 0;
+
+	/* Lock both channels so we can look for the glue that binds them together */
+	ast_channel_lock(c0);
+	while (ast_channel_trylock(c1)) {
+		ast_channel_unlock(c0);
+		usleep(1);
+		ast_channel_lock(c0);
+	}
+
+	/* Grab glue that binds each channel to something using the RTP engine */
+	if (!(glue0 = ast_rtp_instance_get_glue(c0->tech->type)) || !(glue1 = ast_rtp_instance_get_glue(c1->tech->type))) {
+		ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? c1->name : c0->name);
+		goto done;
+	}
+
+	audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
+	video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
+	text_glue0_res = glue0->get_trtp_info ? glue0->get_trtp_info(c0, &tinstance0) : AST_RTP_GLUE_RESULT_FORBID;
+
+	audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
+	video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
+	text_glue1_res = glue1->get_trtp_info ? glue1->get_trtp_info(c1, &tinstance1) : AST_RTP_GLUE_RESULT_FORBID;
+
+	/* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
+	if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) {
+		audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
+	}
+	if (video_glue1_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) {
+		audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
+	}
+	if (audio_glue0_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue0_res == AST_RTP_GLUE_RESULT_FORBID || video_glue0_res == AST_RTP_GLUE_RESULT_REMOTE) && glue0->get_codec(c0)) {
+		codec0 = glue0->get_codec(c0);
+	}
+	if (audio_glue1_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue1_res == AST_RTP_GLUE_RESULT_FORBID || video_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) && glue1->get_codec(c1)) {
+		codec1 = glue1->get_codec(c1);
+	}
+
+	/* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
+	if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
+		goto done;
+	}
+
+	/* Make sure we have matching codecs */
+	if (!(codec0 & codec1)) {
+		goto done;
+	}
+
+	ast_rtp_codecs_payloads_copy(&instance0->codecs, &instance1->codecs, instance1);
+
+	if (vinstance0 && vinstance1) {
+		ast_rtp_codecs_payloads_copy(&vinstance0->codecs, &vinstance1->codecs, vinstance1);
+	}
+	if (tinstance0 && tinstance1) {
+		ast_rtp_codecs_payloads_copy(&tinstance0->codecs, &tinstance1->codecs, tinstance1);
+	}
+
+	res = 0;
+
+done:
+	ast_channel_unlock(c0);
+	ast_channel_unlock(c1);
+
+	unref_instance_cond(&instance0);
+	unref_instance_cond(&instance1);
+	unref_instance_cond(&vinstance0);
+	unref_instance_cond(&vinstance1);
+	unref_instance_cond(&tinstance0);
+	unref_instance_cond(&tinstance1);
+
+	if (!res) {
+		ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n", c0->name, c1 ? c1->name : "<unspecified>");
+	}
+}
+
 int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
 {
 	struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,




More information about the asterisk-commits mailing list