[asterisk-commits] mmichelson: branch mmichelson/correct_sdp_answer r206640 - /team/mmichelson/c...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jul 15 11:06:52 CDT 2009


Author: mmichelson
Date: Wed Jul 15 11:06:49 2009
New Revision: 206640

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=206640
Log:
Expand the offered_media to also keep track of codecs offered. This way
our parroted m= lines are correct.

"endoplasmic reticulum"


Modified:
    team/mmichelson/correct_sdp_answer/channels/chan_sip.c

Modified: team/mmichelson/correct_sdp_answer/channels/chan_sip.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/mmichelson/correct_sdp_answer/channels/chan_sip.c?view=diff&rev=206640&r1=206639&r2=206640
==============================================================================
--- team/mmichelson/correct_sdp_answer/channels/chan_sip.c (original)
+++ team/mmichelson/correct_sdp_answer/channels/chan_sip.c Wed Jul 15 11:06:49 2009
@@ -910,6 +910,10 @@
 	enum referstatus status;			/*!< REFER status */
 };
 
+struct offered_media {
+	int offered;
+	char text[128];
+};
 /*! \brief sip_pvt: PVT structures are used for each SIP dialog, ie. a call, a registration, a subscribe  */
 static struct sip_pvt {
 	ast_mutex_t lock;			/*!< Dialog private lock */
@@ -1040,14 +1044,14 @@
 	 * The reason for the length being 3 is that in this branch of Asterisk, the only media types supported are 
 	 * image, audio, and video. Therefore we need to keep track of which types of media were offered.
 	 *
-	 * Note that if we wanted to be 100% correct, we would keep a list of all media types offered. That way we could respond
+	 * Note that if we wanted to be 100% correct, we would keep a list of all media streams offered. That way we could respond
 	 * even to unknown media types, and we could respond to multiple streams of the same type. Such large-scale changes
 	 * are not a good idea for released branches, though, so we're compromising by just making sure that for the common cases:
 	 * audio and video, and audio and T.38, we give the appropriate response to both media streams.
 	 *
 	 * The large-scale changes would be a good idea for implementing during an SDP rewrite.
 	 */
-	int offered_media[3];
+	struct offered_media offered_media[3];
 } *iflist = NULL;
 
 /*! Max entires in the history list for a sip_pvt */
@@ -5165,6 +5169,12 @@
 	SDP_IMAGE,
 };
 
+static inline void init_offered_media(struct offered_media offered_media[], enum media_type index)
+{
+	offered_media[index].offered = 1;
+	*(offered_media[index].text) = '\0';
+}
+
 static int get_ip_and_port_from_sdp(struct sip_request *req, const enum media_type media, struct sockaddr_in *sin)
 {
 	const char *m;
@@ -5333,12 +5343,14 @@
 		if ((sscanf(m, "audio %d/%d RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) ||
 		    (sscanf(m, "audio %d RTP/AVP %n", &x, &len) == 1 && len > 0)) {
 			audio = TRUE;
-			p->offered_media[SDP_AUDIO] = 1;
+			init_offered_media(p->offered_media, SDP_AUDIO);
 			numberofmediastreams++;
 			/* Found audio stream in this media definition */
 			portno = x;
 			/* Scan through the RTP payload types specified in a "m=" line: */
-			for (codecs = m + len; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
+			codecs = m + len;
+			ast_copy_string(p->offered_media[SDP_AUDIO].text, codecs, sizeof(p->offered_media[SDP_AUDIO].text));
+			for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
 				if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
 					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
 					return -1;
@@ -5356,10 +5368,12 @@
 		    (sscanf(m, "video %d RTP/AVP %n", &x, &len) == 1 && len >= 0)) {
 			/* If it is not audio - is it video ? */
 			ast_clear_flag(&p->flags[0], SIP_NOVIDEO);
-			p->offered_media[SDP_VIDEO] = 1;
+			init_offered_media(p->offered_media, SDP_VIDEO);
 			numberofmediastreams++;
 			vportno = x;
 			/* Scan through the RTP payload types specified in a "m=" line: */
+			codecs = m + len;
+			ast_copy_string(p->offered_media[SDP_VIDEO].text, codecs, sizeof(p->offered_media[SDP_VIDEO].text));
 			for (codecs = m + len; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
 				if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
 					ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
@@ -5373,7 +5387,7 @@
 		 (sscanf(m, "image %d UDPTL t38%n", &x, &len) == 1 && len >= 0) )) {
 			if (debug)
 				ast_verbose("Got T.38 offer in SDP in dialog %s\n", p->callid);
-			p->offered_media[SDP_IMAGE] = 1;
+			init_offered_media(p->offered_media, SDP_IMAGE);
 			udptlportno = x;
 			numberofmediastreams++;
 			
@@ -6981,22 +6995,26 @@
 		add_line(resp, m_audio);
 		add_line(resp, a_audio);
 		add_line(resp, hold);
-	} else if (p->offered_media[SDP_AUDIO]) {
-		add_line(resp, "m=audio 0 RTP/AVP\r\n");
+	} else if (p->offered_media[SDP_AUDIO].offered) {
+		char dummy_audio[256];
+		snprintf(dummy_audio, sizeof(dummy_audio), "m=audio 0 RTP/AVP %s\r\n", p->offered_media[SDP_AUDIO].text);
+		add_line(resp, dummy_audio);
 		add_line(resp, "a=inactive\r\n");
 	}
 	if (needvideo) { /* only if video response is appropriate */
 		add_line(resp, m_video);
 		add_line(resp, a_video);
 		add_line(resp, hold);	/* Repeat hold for the video stream */
-	} else if (p->offered_media[SDP_VIDEO]) {
-		add_line(resp, "m=video 0 RTP/AVP\r\n");
+	} else if (p->offered_media[SDP_VIDEO].offered) {
+		char dummy_video[256];
+		snprintf(dummy_video, sizeof(dummy_video), "m=video 0 RTP/AVP %s\r\n", p->offered_media[SDP_VIDEO].text);
+		add_line(resp, dummy_video);
 		add_line(resp, "a=inactive\r\n");
 	}
 	if (add_t38) {
 		add_line(resp, m_modem);
 		add_line(resp, a_modem);
-	} else if (p->offered_media[SDP_IMAGE]) {
+	} else if (p->offered_media[SDP_IMAGE].offered) {
 		add_line(resp, "m=image 0 udptl t38\r\n");
 		add_line(resp, "a=inactive\r\n");
 	}




More information about the asterisk-commits mailing list