Browse code

rtpengine: support new codec flags

Adds explicit support for codec-set and codec-except.

Also eliminates code redundancy.

Richard Fuchs authored on 21/10/2020 18:05:20
Showing 1 changed files
... ...
@@ -119,7 +119,8 @@ struct ng_flags_parse {
119 119
 	int via, to, packetize, transport, directional;
120 120
 	bencode_item_t *dict, *flags, *direction, *replace, *rtcp_mux, *sdes,
121 121
 		       *t38,
122
-		       *codec, *codec_strip, *codec_offer, *codec_transcode, *codec_mask;
122
+		       *codec, *codec_strip, *codec_offer, *codec_transcode, *codec_mask,
123
+		       *codec_set, *codec_except;
123 124
 	str call_id, from_tag, to_tag;
124 125
 };
125 126
 
... ...
@@ -2082,6 +2083,29 @@ static const char *transports[] = {
2082 2083
 	[0x06]	= "UDP/TLS/RTP/SAVPF",
2083 2084
 };
2084 2085
 
2086
+static int parse_codec_flag(struct ng_flags_parse *ng_flags, const str *key, const str *val,
2087
+		const char *cmp1, const char *cmp2,
2088
+		bencode_item_t **dictp)
2089
+{
2090
+	str s;
2091
+
2092
+	if (!str_key_val_prefix(key, cmp1, val, &s)) {
2093
+		if (!cmp2)
2094
+			return 0;
2095
+		if (!str_key_val_prefix(key, cmp2, val, &s))
2096
+			return 0;
2097
+	}
2098
+
2099
+	if (!*dictp) {
2100
+		*dictp = bencode_list(ng_flags->dict->buffer);
2101
+		bencode_dictionary_add(ng_flags->codec, "transcode",
2102
+			*dictp);
2103
+	}
2104
+	bencode_list_add_str(*dictp, &s);
2105
+
2106
+	return 1;
2107
+}
2108
+
2085 2109
 static int parse_flags(struct ng_flags_parse *ng_flags, struct sip_msg *msg, enum rtpe_operation *op,
2086 2110
 		const char *flags_str)
2087 2111
 {
... ...
@@ -2135,47 +2159,18 @@ static int parse_flags(struct ng_flags_parse *ng_flags, struct sip_msg *msg, enu
2135 2159
 			goto next;
2136 2160
 		}
2137 2161
 
2138
-		if (str_key_val_prefix(&key, "transcode", &val, &s)
2139
-				|| str_key_val_prefix(&key, "codec-transcode", &val, &s))
2140
-		{
2141
-			if (!ng_flags->codec_transcode) {
2142
-				ng_flags->codec_transcode = bencode_list(ng_flags->dict->buffer);
2143
-				bencode_dictionary_add(ng_flags->codec, "transcode",
2144
-					ng_flags->codec_transcode);
2145
-			}
2146
-			bencode_list_add_str(ng_flags->codec_transcode, &s);
2162
+		if (parse_codec_flag(ng_flags, &key, &val, "transcode", "codec-transcode", &ng_flags->codec_transcode))
2147 2163
 			goto next;
2148
-		}
2149
-
2150
-		if (str_key_val_prefix(&key, "codec-strip", &val, &s)) {
2151
-			if (!ng_flags->codec_strip) {
2152
-				ng_flags->codec_strip = bencode_list(ng_flags->dict->buffer);
2153
-				bencode_dictionary_add(ng_flags->codec, "strip",
2154
-					ng_flags->codec_strip);
2155
-			}
2156
-			bencode_list_add_str(ng_flags->codec_strip, &s);
2164
+		if (parse_codec_flag(ng_flags, &key, &val, "codec-strip", NULL, &ng_flags->codec_strip))
2157 2165
 			goto next;
2158
-		}
2159
-
2160
-		if (str_key_val_prefix(&key, "codec-offer", &val, &s)) {
2161
-			if (!ng_flags->codec_offer) {
2162
-				ng_flags->codec_offer = bencode_list(ng_flags->dict->buffer);
2163
-				bencode_dictionary_add(ng_flags->codec, "offer",
2164
-					ng_flags->codec_offer);
2165
-			}
2166
-			bencode_list_add_str(ng_flags->codec_offer, &s);
2166
+		if (parse_codec_flag(ng_flags, &key, &val, "codec-offer", NULL, &ng_flags->codec_offer))
2167 2167
 			goto next;
2168
-		}
2169
-
2170
-		if (str_key_val_prefix(&key, "codec-mask", &val, &s)) {
2171
-			if (!ng_flags->codec_mask) {
2172
-				ng_flags->codec_mask = bencode_list(ng_flags->dict->buffer);
2173
-				bencode_dictionary_add(ng_flags->codec, "mask",
2174
-					ng_flags->codec_mask);
2175
-			}
2176
-			bencode_list_add_str(ng_flags->codec_mask, &s);
2168
+		if (parse_codec_flag(ng_flags, &key, &val, "codec-mask", NULL, &ng_flags->codec_mask))
2169
+			goto next;
2170
+		if (parse_codec_flag(ng_flags, &key, &val, "codec-set", NULL, &ng_flags->codec_set))
2171
+			goto next;
2172
+		if (parse_codec_flag(ng_flags, &key, &val, "codec-except", NULL, &ng_flags->codec_except))
2177 2173
 			goto next;
2178
-		}
2179 2174
 
2180 2175
 		/* check for specially handled items */
2181 2176
 		switch (key.len) {