[svn-commits] oej: branch oej/earlyrtpfix r47874 - /team/oej/earlyrtpfix/channels/chan_sip.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Tue Nov 21 02:07:23 MST 2006


Author: oej
Date: Tue Nov 21 03:07:21 2006
New Revision: 47874

URL: http://svn.digium.com/view/asterisk?view=rev&rev=47874
Log:
when setting up the remote bridge early (without re-invites) we need to use the
payload definition from the incoming call when sending out the invite to the outbound
call leg, so the RTP payloads sent from the callee to the caller follow whatever the
caller expects.

Modified:
    team/oej/earlyrtpfix/channels/chan_sip.c

Modified: team/oej/earlyrtpfix/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/earlyrtpfix/channels/chan_sip.c?view=diff&rev=47874&r1=47873&r2=47874
==============================================================================
--- team/oej/earlyrtpfix/channels/chan_sip.c (original)
+++ team/oej/earlyrtpfix/channels/chan_sip.c Tue Nov 21 03:07:21 2006
@@ -977,8 +977,12 @@
 	struct sip_peer *relatedpeer;		/*!< If this dialog is related to a peer, which one 
 							Used in peerpoke, mwi subscriptions */
 	struct sip_registry *registry;		/*!< If this is a REGISTER dialog, to which registry */
+
 	struct ast_rtp *rtp;			/*!< RTP Session */
 	struct ast_rtp *vrtp;			/*!< Video RTP session */
+	struct ast_rtp *remotertp;		/*!< Remote RTP Session (for direct RTP setup) */
+	struct ast_rtp *remotevrtp;		/*!< Remote Video RTP session (for direct RTP setup) */
+
 	struct sip_pkt *packets;		/*!< Packets scheduled for re-transmission */
 	struct sip_history_head *history;	/*!< History of this SIP dialog */
 	struct ast_variable *chanvars;		/*!< Channel variables to set for inbound call */
@@ -1264,7 +1268,7 @@
 static const char *get_sdp(struct sip_request *req, const char *name);
 static int find_sdp(struct sip_request *req);
 static int process_sdp(struct sip_pvt *p, struct sip_request *req);
-static void add_codec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
+static void add_codec_to_sdp(const struct sip_pvt *p, struct ast_rtp *rtp, int codec, int sample_rate,
 			     char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
 			     int debug, int *min_packet_size);
 static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_rate,
@@ -5815,24 +5819,24 @@
 }
 
 /*! \brief Add codec offer to SDP offer/answer body in INVITE or 200 OK */
-static void add_codec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate,
+static void add_codec_to_sdp(const struct sip_pvt *p, struct ast_rtp *rtp, int codec, int sample_rate,
 			     char **m_buf, size_t *m_size, char **a_buf, size_t *a_size,
 			     int debug, int *min_packet_size)
 {
 	int rtp_code;
 	struct ast_format_list fmt;
-
+	struct ast_codec_pref *pref;
+
+	if (!rtp)
+		return;
 
 	if (debug)
 		ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec));
-	if ((rtp_code = ast_rtp_lookup_code(p->rtp, 1, codec)) == -1)
+	if ((rtp_code = ast_rtp_lookup_code(rtp, 1, codec)) == -1)
 		return;
 
-	if (p->rtp) {
-		struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp);
-		fmt = ast_codec_pref_getsize(pref, codec);
-	} else /* I dont see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */
-		return;
+	pref = ast_rtp_codec_getpref(rtp);
+	fmt = ast_codec_pref_getsize(pref, codec);
 	ast_build_string(m_buf, m_size, " %d", rtp_code);
 	ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
 			 ast_rtp_lookup_mime_subtype(1, codec,
@@ -6050,6 +6054,10 @@
 	int min_audio_packet_size = 0;
 	int min_video_packet_size = 0;
 
+	struct ast_rtp *rtp;			/*!< RTP Audio Session - in early remote bridge the remote RTP */
+	struct ast_rtp *vrtp;			/*!< RTP Video Session - in early remote bridge the remote RTP */
+
+
 	m_video[0] = '\0';	/* Reset the video media string if it's not needed */
 
 	if (!p->rtp) {
@@ -6063,6 +6071,12 @@
 		p->sessionversion = p->sessionid;
 	} else
 		p->sessionversion++;
+
+	/* If we're setting up a call with early remote RTP bridging, we need to use the caller's
+	 * RTP maps 
+	 */
+	rtp = p->remotertp ? p->remotertp : p->rtp;
+	vrtp = p->remotevrtp ? p->remotevrtp : p->vrtp;
 
 	/* Get our addresses */
 	ast_rtp_get_us(p->rtp, &sin);
@@ -6103,7 +6117,6 @@
 		} else if (option_debug > 1)
 			ast_log(LOG_DEBUG, "This call needs video offers, but there's no video support enabled!\n");
 	}
-		
 
 	/* Ok, we need video. Let's add what we need for video and set codecs.
 	   Video is handled differently than audio since we can not transcode. */
@@ -6156,7 +6169,7 @@
 	if (capability & p->prefcodec) {
 		int codec = p->prefcodec & AST_FORMAT_AUDIO_MASK;
 
-		add_codec_to_sdp(p, codec, SDP_SAMPLE_RATE(codec),
+		add_codec_to_sdp(p, rtp, codec, SDP_SAMPLE_RATE(codec),
 				 &m_audio_next, &m_audio_left,
 				 &a_audio_next, &a_audio_left,
 				 debug, &min_audio_packet_size);
@@ -6176,7 +6189,7 @@
 		if (alreadysent & codec)
 			continue;
 
-		add_codec_to_sdp(p, codec, SDP_SAMPLE_RATE(codec),
+		add_codec_to_sdp(p, rtp, codec, SDP_SAMPLE_RATE(codec),
 				 &m_audio_next, &m_audio_left,
 				 &a_audio_next, &a_audio_left,
 				 debug, &min_audio_packet_size);
@@ -6192,12 +6205,12 @@
 			continue;
 
 		if (x <= AST_FORMAT_MAX_AUDIO)
-			add_codec_to_sdp(p, x, SDP_SAMPLE_RATE(x),
+			add_codec_to_sdp(p, rtp, x, SDP_SAMPLE_RATE(x),
 					 &m_audio_next, &m_audio_left,
 					 &a_audio_next, &a_audio_left,
 					 debug, &min_audio_packet_size);
 		else 
-			add_codec_to_sdp(p, x, 90000,
+			add_codec_to_sdp(p, vrtp, x, 90000,
 					 &m_video_next, &m_video_left,
 					 &a_video_next, &a_video_left,
 					 debug, &min_video_packet_size);
@@ -6262,6 +6275,9 @@
 		char buf[BUFSIZ];
 		ast_log(LOG_DEBUG, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, BUFSIZ, capability));
 	}
+	/* Clean up */
+	p->remotertp = NULL;
+	p->remotevrtp = NULL;
 
 	return AST_SUCCESS;
 }
@@ -16617,6 +16633,9 @@
 				append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal.");
 			if (option_debug)
 				ast_log(LOG_DEBUG, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip));
+			/* Store pointers to remote rtp to copy the source RTP maps to the destination */
+			p->remotertp = rtp;
+			p->remotevrtp = vrtp;
 		} else if (!p->pendinginvite) {		/* We are up, and have no outstanding invite */
 			if (option_debug > 2) {
 				ast_log(LOG_DEBUG, "Sending reinvite on SIP '%s' - It's audio soon redirected to IP %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip));



More information about the svn-commits mailing list