Browse code

rtpengine: explicitly handle new option flags (transcoding)

Richard Fuchs authored on 08/03/2018 15:16:22
Showing 1 changed files
... ...
@@ -115,7 +115,8 @@ enum {
115 115
 
116 116
 struct ng_flags_parse {
117 117
 	int via, to, packetize, transport;
118
-	bencode_item_t *dict, *flags, *direction, *replace, *rtcp_mux;
118
+	bencode_item_t *dict, *flags, *direction, *replace, *rtcp_mux, *sdes,
119
+		       *codec, *codec_strip, *codec_offer, *codec_transcode, *codec_mask;
119 120
 	str call_id, from_tag, to_tag;
120 121
 };
121 122
 
... ...
@@ -653,17 +654,32 @@ static inline int str_eq(const str *p, const char *q) {
653 654
 	return 1;
654 655
 }
655 656
 
656
-static inline str str_prefix(const str *p, const char *q) {
657
-	str ret = STR_NULL;
657
+static inline int str_prefix(const str *p, const char *q, str *out) {
658 658
 	int l = strlen(q);
659 659
 	if (p->len < l)
660
-		return ret;
660
+		return 0;
661 661
 	if (memcmp(p->s, q, l))
662
-		return ret;
663
-	ret = *p;
664
-	ret.s += l;
665
-	ret.len -= l;
666
-	return ret;
662
+		return 0;
663
+	*out = *p;
664
+	out->s += l;
665
+	out->len -= l;
666
+	return 1;
667
+}
668
+/* handle either "foo-bar" or "foo=bar" from flags */
669
+static inline int str_key_val_prefix(const str *p, const char *q, const str *v, str *out) {
670
+	if (str_eq(p, q)) {
671
+		*out = *v;
672
+		return 1;
673
+	}
674
+	if (!str_prefix(p, q, out))
675
+		return 0;
676
+	if (out->len < 2)
677
+		return 0;
678
+	if (*out->s != '-')
679
+		return 0;
680
+	out->s++;
681
+	out->len--;
682
+	return 1;
667 683
 }
668 684
 
669 685
 
... ...
@@ -1928,18 +1944,61 @@ static int parse_flags(struct ng_flags_parse *ng_flags, struct sip_msg *msg, enu
1928 1944
 			break;
1929 1945
 
1930 1946
 		/* check for items which have their own sub-list */
1931
-		s = str_prefix(&key, "replace-");
1932
-		if (s.s) {
1947
+		if (str_key_val_prefix(&key, "replace", &val, &s)) {
1933 1948
 			bencode_list_add_str(ng_flags->replace, &s);
1934 1949
 			goto next;
1935 1950
 		}
1936
-
1937
-		s = str_prefix(&key, "rtcp-mux-");
1938
-		if (s.s) {
1951
+		if (str_key_val_prefix(&key, "SDES", &val, &s)) {
1952
+			bencode_list_add_str(ng_flags->sdes, &s);
1953
+			goto next;
1954
+		}
1955
+		if (str_key_val_prefix(&key, "rtcp-mux", &val, &s)) {
1939 1956
 			bencode_list_add_str(ng_flags->rtcp_mux, &s);
1940 1957
 			goto next;
1941 1958
 		}
1942 1959
 
1960
+		if (str_key_val_prefix(&key, "transcode", &val, &s)
1961
+				|| str_key_val_prefix(&key, "codec-transcode", &val, &s))
1962
+		{
1963
+			if (!ng_flags->codec_transcode) {
1964
+				ng_flags->codec_transcode = bencode_list(ng_flags->dict->buffer);
1965
+				bencode_dictionary_add(ng_flags->codec, "transcode",
1966
+					ng_flags->codec_transcode);
1967
+			}
1968
+			bencode_list_add_str(ng_flags->codec_transcode, &s);
1969
+			goto next;
1970
+		}
1971
+
1972
+		if (str_key_val_prefix(&key, "codec-strip", &val, &s)) {
1973
+			if (!ng_flags->codec_strip) {
1974
+				ng_flags->codec_strip = bencode_list(ng_flags->dict->buffer);
1975
+				bencode_dictionary_add(ng_flags->codec, "strip",
1976
+					ng_flags->codec_strip);
1977
+			}
1978
+			bencode_list_add_str(ng_flags->codec_strip, &s);
1979
+			goto next;
1980
+		}
1981
+
1982
+		if (str_key_val_prefix(&key, "codec-offer", &val, &s)) {
1983
+			if (!ng_flags->codec_offer) {
1984
+				ng_flags->codec_offer = bencode_list(ng_flags->dict->buffer);
1985
+				bencode_dictionary_add(ng_flags->codec, "offer",
1986
+					ng_flags->codec_offer);
1987
+			}
1988
+			bencode_list_add_str(ng_flags->codec_offer, &s);
1989
+			goto next;
1990
+		}
1991
+
1992
+		if (str_key_val_prefix(&key, "codec-mask", &val, &s)) {
1993
+			if (!ng_flags->codec_mask) {
1994
+				ng_flags->codec_mask = bencode_list(ng_flags->dict->buffer);
1995
+				bencode_dictionary_add(ng_flags->codec, "mask",
1996
+					ng_flags->codec_mask);
1997
+			}
1998
+			bencode_list_add_str(ng_flags->codec_mask, &s);
1999
+			goto next;
2000
+		}
2001
+
1943 2002
 		/* check for specially handled items */
1944 2003
 		switch (key.len) {
1945 2004
 			case 3:
... ...
@@ -2150,6 +2209,8 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
2150 2209
 		ng_flags.direction = bencode_list(bencbuf);
2151 2210
 		ng_flags.replace = bencode_list(bencbuf);
2152 2211
 		ng_flags.rtcp_mux = bencode_list(bencbuf);
2212
+		ng_flags.sdes = bencode_list(bencbuf);
2213
+		ng_flags.codec = bencode_dictionary(bencbuf);
2153 2214
 
2154 2215
 		if (read_sdp_pvar!= NULL) {
2155 2216
 			if (read_sdp_pvar->getf(msg,&read_sdp_pvar->pvp, &pv_val) < 0)
... ...
@@ -2184,11 +2245,15 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
2184 2245
 		bencode_dictionary_add(ng_flags.dict, "flags", ng_flags.flags);
2185 2246
 	if (ng_flags.replace && ng_flags.replace->child)
2186 2247
 		bencode_dictionary_add(ng_flags.dict, "replace", ng_flags.replace);
2248
+	if (ng_flags.codec && ng_flags.codec->child)
2249
+		bencode_dictionary_add(ng_flags.dict, "codec", ng_flags.codec);
2187 2250
 	if ((ng_flags.transport & 0x100))
2188 2251
 		bencode_dictionary_add_string(ng_flags.dict, "transport-protocol",
2189 2252
 				transports[ng_flags.transport & 0x007]);
2190 2253
 	if (ng_flags.rtcp_mux && ng_flags.rtcp_mux->child)
2191 2254
 		bencode_dictionary_add(ng_flags.dict, "rtcp-mux", ng_flags.rtcp_mux);
2255
+	if (ng_flags.sdes && ng_flags.sdes->child)
2256
+		bencode_dictionary_add(ng_flags.dict, "SDES", ng_flags.sdes);
2192 2257
 
2193 2258
 	bencode_dictionary_add_str(ng_flags.dict, "call-id", &ng_flags.call_id);
2194 2259