[sr-dev] git:master: core: sdp parser - add rtp flag identifier for sdp streams

Ovidiu Sas osas at voipembedded.com
Mon Jun 28 17:58:45 CEST 2010


Module: sip-router
Branch: master
Commit: 6face3f2b282333f241cb28782874cfa5dee495b
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=6face3f2b282333f241cb28782874cfa5dee495b

Author: Ovidiu Sas <osas at voipembedded.com>
Committer: Ovidiu Sas <osas at voipembedded.com>
Date:   Mon Jun 28 12:04:26 2010 -0400

core: sdp parser - add rtp flag identifier for sdp streams

---

 parser/sdp/sdp.c             |   16 +++++++++++-----
 parser/sdp/sdp.h             |    2 ++
 parser/sdp/sdp_helpr_funcs.c |   30 +++++++++++++++++++-----------
 parser/sdp/sdp_helpr_funcs.h |    3 ++-
 4 files changed, 34 insertions(+), 17 deletions(-)

diff --git a/parser/sdp/sdp.c b/parser/sdp/sdp.c
index e6721a7..d294d11 100644
--- a/parser/sdp/sdp.c
+++ b/parser/sdp/sdp.c
@@ -4,6 +4,7 @@
  * SDP parser interface
  *
  * Copyright (C) 2008-2009 SOMA Networks, INC.
+ * Copyright (C) 2010 VoIP Embedded, Inc
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -92,7 +93,7 @@ static inline sdp_session_cell_t *add_sdp_session(sdp_info_t* _sdp, int session_
  * Allocate a new stream cell.
  */
 static inline sdp_stream_cell_t *add_sdp_stream(sdp_session_cell_t* _session, int stream_num,
-		str* media, str* port, str* transport, str* payloads, int pf, str* sdp_ip)
+		str* media, str* port, str* transport, str* payloads, int is_rtp, int pf, str* sdp_ip)
 {
 	sdp_stream_cell_t *stream;
 	int len;
@@ -116,6 +117,8 @@ static inline sdp_stream_cell_t *add_sdp_stream(sdp_session_cell_t* _session, in
 	stream->payloads.s = payloads->s;
 	stream->payloads.len = payloads->len;
 
+	stream->is_rtp = is_rtp;
+
 	stream->pf = pf;
 	stream->ip_addr.s = sdp_ip->s;
 	stream->ip_addr.len = sdp_ip->len;
@@ -340,6 +343,7 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
 	str sdp_ip, sdp_media, sdp_port, sdp_transport, sdp_payload;
 	str payload;
 	str rtp_payload, rtp_enc, rtp_clock, rtp_params;
+	int is_rtp;
 	char *bodylimit;
 	char *v1p, *o1p, *m1p, *m2p, *c1p, *c2p, *a1p, *a2p, *b1p;
 	str tmpstr1;
@@ -441,13 +445,13 @@ static int parse_sdp_session(str *sdp_body, int session_num, str *cnt_disp, sdp_
 		/* Extract the port on sdp_port */
 		tmpstr1.s = m1p;
 		tmpstr1.len = m2p - m1p;
-		if (extract_media_attr(&tmpstr1, &sdp_media, &sdp_port, &sdp_transport, &sdp_payload) == -1) {
+		if (extract_media_attr(&tmpstr1, &sdp_media, &sdp_port, &sdp_transport, &sdp_payload, &is_rtp) == -1) {
 			LM_ERR("can't extract media attr from the message\n");
 			return -1;
 		}
 
 		/* Allocate a stream cell */
-		stream = add_sdp_stream(session, stream_num, &sdp_media, &sdp_port, &sdp_transport, &sdp_payload, pf, &sdp_ip);
+		stream = add_sdp_stream(session, stream_num, &sdp_media, &sdp_port, &sdp_transport, &sdp_payload, is_rtp, pf, &sdp_ip);
 		if (stream == 0) return -1;
 
 		/* increment total number of streams */
@@ -758,13 +762,13 @@ void print_sdp_stream(sdp_stream_cell_t *stream)
 {
 	sdp_payload_attr_t *payload;
 
-	LM_DBG("....stream[%d]:%p=>%p {%p} '%.*s' '%.*s:%.*s:%.*s' '%.*s' '%.*s' '%.*s:%.*s' (%d)=>%p '%.*s' '%.*s' '%.*s' '%.*s' '%.*s' '%.*s'\n",
+	LM_DBG("....stream[%d]:%p=>%p {%p} '%.*s' '%.*s:%.*s:%.*s' '%.*s' [%d] '%.*s' '%.*s:%.*s' (%d)=>%p '%.*s' '%.*s' '%.*s' '%.*s' '%.*s' '%.*s'\n",
 		stream->stream_num, stream, stream->next,
 		stream->p_payload_attr,
 		stream->media.len, stream->media.s,
 		stream->ip_addr.len, stream->ip_addr.s, stream->port.len, stream->port.s,
 		stream->rtcp_port.len, stream->rtcp_port.s,
-		stream->transport.len, stream->transport.s,
+		stream->transport.len, stream->transport.s, stream->is_rtp,
 		stream->payloads.len, stream->payloads.s,
 		stream->bw_type.len, stream->bw_type.s, stream->bw_width.len, stream->bw_width.s,
 		stream->payloads_num, stream->payload_attr,
@@ -985,6 +989,8 @@ sdp_stream_cell_t * clone_sdp_stream_cell(sdp_stream_cell_t *stream)
 		p += stream->ip_addr.len;
 	}
 
+	clone_stream->is_rtp = stream->is_rtp;
+
 	if (stream->media.len) {
 		clone_stream->media.s = p;
 		clone_stream->media.len = stream->media.len;
diff --git a/parser/sdp/sdp.h b/parser/sdp/sdp.h
index 0e9f19c..2ab34de 100644
--- a/parser/sdp/sdp.h
+++ b/parser/sdp/sdp.h
@@ -4,6 +4,7 @@
  * SDP parser interface
  *
  * Copyright (C) 2008-2009 SOMA Networks, INC.
+ * Copyright (C) 2010 VoIP Embedded, Inc
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -48,6 +49,7 @@ 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 */
 	/* m=<media> <port> <transport> <payloads> */
 	str media;
 	str port;
diff --git a/parser/sdp/sdp_helpr_funcs.c b/parser/sdp/sdp_helpr_funcs.c
index 681dd23..90a19fe 100644
--- a/parser/sdp/sdp_helpr_funcs.c
+++ b/parser/sdp/sdp_helpr_funcs.c
@@ -4,6 +4,7 @@
  * SDP parser helpers
  *
  * Copyright (C) 2008-2009 SOMA Networks, INC.
+ * Copyright (C) 2010 VoIP Embedded, Inc
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -34,14 +35,19 @@
 #include "../parse_hname2.h"
 
 
-static str sup_ptypes[] = {
-	str_init("udp"),
-	str_init("udptl"),
-	str_init("rtp/avp"),
-	str_init("rtp/savpf"),
-	str_init("TCP/MSRP"),
-	str_init("TCP/TLS/MSRP"),
-	{ NULL, 0}
+static struct {
+	const char *s;
+	int len;
+	int is_rtp;
+} sup_ptypes[] = {
+	{.s = "rtp/avp",   .len = 7, .is_rtp = 1},
+	{.s = "udptl",     .len = 5, .is_rtp = 0},
+	{.s = "rtp/avpf",  .len = 8, .is_rtp = 1},
+	{.s = "rtp/savp",  .len = 8, .is_rtp = 1},
+	{.s = "rtp/savpf", .len = 9, .is_rtp = 1},
+	{.s = "udp",       .len = 3, .is_rtp = 0},
+	{.s = "udp/bfcp",  .len = 8, .is_rtp = 0},
+	{.s = NULL,        .len = 0, .is_rtp = 0}
 };
 
 
@@ -385,7 +391,7 @@ int extract_mediaip(str *body, str *mediaip, int *pf, char *line)
 	return 1;
 }
 
-int extract_media_attr(str *body, str *mediamedia, str *mediaport, str *mediatransport, str *mediapayload)
+int extract_media_attr(str *body, str *mediamedia, str *mediaport, str *mediatransport, str *mediapayload, int *is_rtp)
 {
 	char *cp, *cp1;
 	int len, i;
@@ -462,10 +468,12 @@ int extract_media_attr(str *body, str *mediamedia, str *mediaport, str *mediatra
 
 	for (i = 0; sup_ptypes[i].s != NULL; i++)
 		if (mediatransport->len == sup_ptypes[i].len &&
-		    strncasecmp(mediatransport->s, sup_ptypes[i].s, mediatransport->len) == 0)
+		    strncasecmp(mediatransport->s, sup_ptypes[i].s, mediatransport->len) == 0) {
+			*is_rtp = sup_ptypes[i].is_rtp;
 			return 0;
+		}
 	/* Unproxyable protocol type. Generally it isn't error. */
-	return -1;
+	return 0;
 }
 
 
diff --git a/parser/sdp/sdp_helpr_funcs.h b/parser/sdp/sdp_helpr_funcs.h
index d7b02ee..0456993 100644
--- a/parser/sdp/sdp_helpr_funcs.h
+++ b/parser/sdp/sdp_helpr_funcs.h
@@ -4,6 +4,7 @@
  * SDP parser helpers
  *
  * Copyright (C) 2008-2009 SOMA Networks, INC.
+ * Copyright (C) 2010 VoIP Embedded, Inc
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -47,7 +48,7 @@ int extract_rtpmap(str *body, str *rtpmap_payload, str *rtpmap_encoding, str *rt
 int extract_ptime(str *body, str *ptime);
 int extract_sendrecv_mode(str *body, str *sendrecv_mode);
 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 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);
 
 /* RFC3605 attributes */




More information about the sr-dev mailing list