Browse Source

sdp parser: detect on hold media during sdp parsing

Ovidiu Sas 15 years ago
parent
commit
27e1d6f41a
4 changed files with 30 additions and 7 deletions
  1. 19 1
      parser/sdp/sdp.c
  2. 2 1
      parser/sdp/sdp.h
  3. 8 4
      parser/sdp/sdp_helpr_funcs.c
  4. 1 1
      parser/sdp/sdp_helpr_funcs.h

+ 19 - 1
parser/sdp/sdp.c

@@ -29,6 +29,7 @@
  */
 
 
+#include "../../ut.h"
 #include "../../mem/mem.h"
 #include "../../mem/shm_mem.h"
 #include "../parser_f.h"
@@ -39,6 +40,9 @@
 #define USE_PKG_MEM 0
 #define USE_SHM_MEM 1
 
+#define HOLD_IP_STR "0.0.0.0"
+#define HOLD_IP_LEN 7
+
 /**
  * Creates and initialize a new sdp_info structure
  */
@@ -524,7 +528,8 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
 
 			if (parse_payload_attr && extract_ptime(&tmpstr1, &stream->ptime) == 0) {
 				a1p = stream->ptime.s + stream->ptime.len;
-			} else if (parse_payload_attr && extract_sendrecv_mode(&tmpstr1, &stream->sendrecv_mode) == 0) {
+			} else if (parse_payload_attr && extract_sendrecv_mode(&tmpstr1,
+					&stream->sendrecv_mode, &stream->is_on_hold) == 0) {
 				a1p = stream->sendrecv_mode.s + stream->sendrecv_mode.len;
 			} else if (parse_payload_attr && extract_rtpmap(&tmpstr1, &rtp_payload, &rtp_enc, &rtp_clock, &rtp_params) == 0) {
 				if (rtp_params.len != 0 && rtp_params.s != NULL) {
@@ -554,6 +559,19 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
 
 			a2p = find_next_sdp_line(a1p, m2p, 'a', m2p);
 		}
+		/* Let's detect if the media is on hold by checking
+		 * the good old "0.0.0.0" connection address */
+		if (!stream->is_on_hold) {
+			if (stream->ip_addr.s && stream->ip_addr.len) {
+				if (stream->ip_addr.len == HOLD_IP_LEN &&
+					strncmp(stream->ip_addr.s, HOLD_IP_STR, HOLD_IP_LEN)==0)
+					stream->is_on_hold = 1;
+			} else if (session->ip_addr.s && session->ip_addr.len) {
+				if (session->ip_addr.len == HOLD_IP_LEN &&
+					strncmp(session->ip_addr.s, HOLD_IP_STR, HOLD_IP_LEN)==0)
+					stream->is_on_hold = 1;
+			}
+		}
 		++stream_num;
 	} /* Iterate medias/streams in session */
 	return 0;

+ 2 - 1
parser/sdp/sdp.h

@@ -50,7 +50,8 @@ typedef struct sdp_stream_cell {
 	int pf;         /**< connection address family: AF_INET/AF_INET6 */
 	str ip_addr;    /**< connection address */
 	int stream_num; /**< stream index inside a session */
-	int is_rtp;	/**< flag indicating is this is an RTP stream */
+	int is_rtp;	/**< flag indicating if this is an RTP stream */
+	int is_on_hold; /**< flag indicating if this stream is on hold */
 	/* m=<media> <port> <transport> <payloads> */
 	str media;
 	str port;

+ 8 - 4
parser/sdp/sdp_helpr_funcs.c

@@ -321,15 +321,19 @@ int extract_rtcp(str *body, str *rtcp)
 	return extract_field(body, rtcp, field);
 }
 
-int extract_sendrecv_mode(str *body, str *sendrecv_mode)
+int extract_sendrecv_mode(str *body, str *sendrecv_mode, int *is_on_hold)
 {
 	char *cp1;
 
 	cp1 = body->s;
 	if ( !( (strncasecmp(cp1, "a=sendrecv", 10) == 0) ||
-		(strncasecmp(cp1, "a=inactive", 10) == 0) ||
-		(strncasecmp(cp1, "a=recvonly", 10) == 0) ||
-		(strncasecmp(cp1, "a=sendonly", 10) == 0) )) {
+		(strncasecmp(cp1, "a=recvonly", 10) == 0))) {
+		if ( !( (strncasecmp(cp1, "a=inactive", 10) == 0) ||
+			(strncasecmp(cp1, "a=sendonly", 10) == 0) )) {
+			return -1;
+		} else {
+			*is_on_hold = 1;
+		}
 		return -1;
 	}
 

+ 1 - 1
parser/sdp/sdp_helpr_funcs.h

@@ -47,7 +47,7 @@ int get_mixed_part_delimiter(str * body, str * mp_delimiter);
 int extract_rtpmap(str *body, str *rtpmap_payload, str *rtpmap_encoding, str *rtpmap_clockrate, str *rtpmap_parmas);
 int extract_fmtp( str *body, str *fmtp_payload, str *fmtp_string );
 int extract_ptime(str *body, str *ptime);
-int extract_sendrecv_mode(str *body, str *sendrecv_mode);
+int extract_sendrecv_mode(str *body, str *sendrecv_mode, int *is_on_hold);
 int extract_mediaip(str *body, str *mediaip, int *pf, char *line);
 int extract_media_attr(str *body, str *mediamedia, str *mediaport, str *mediatransport, str *mediapayload, int *is_rtp);
 int extract_bwidth(str *body, str *bwtype, str *bwwitdth);