@@ -44,7 +44,7 @@ std::string SdpUtils::SetPreferAudioCodecs(const std::string& original_sdp,
44
44
std::string SdpUtils::SetPreferVideoCodecs (const std::string& original_sdp,
45
45
std::vector<VideoCodec>& codec, bool set_quality) {
46
46
std::string cur_sdp (original_sdp);
47
- if (codec.size () == 0 )
47
+ if (codec.size () == 0 && !set_quality )
48
48
return cur_sdp;
49
49
std::vector<VideoCodec> rcodecs (codec.rbegin (), codec.rend ());
50
50
std::vector<std::string> codec_names;
@@ -59,6 +59,7 @@ std::string SdpUtils::SetPreferVideoCodecs(const std::string& original_sdp,
59
59
cur_sdp = SdpUtils::SetPreferCodecs (cur_sdp, codec_names, false , set_quality);
60
60
return cur_sdp;
61
61
}
62
+
62
63
std::vector<std::string> SdpUtils::GetCodecValues (const std::string& sdp,
63
64
std::string& codec_name,
64
65
bool is_audio) {
@@ -95,7 +96,7 @@ std::string SdpUtils::SetPreferCodecs(const std::string& sdp,
95
96
current_sdp = rtx_map_match.suffix ();
96
97
}
97
98
std::vector<std::string> kept_codec_values;
98
- if (!is_audio) {
99
+ if (!is_audio && codec_names. size () > 0 ) {
99
100
// Get red and ulpfec payload type if any.
100
101
bool has_red = false , has_ulpfec = false , has_flexfec = false ;
101
102
std::regex reg_red_map (
@@ -194,47 +195,69 @@ std::string SdpUtils::SetPreferCodecs(const std::string& sdp,
194
195
m_line_stream << " " << codec_value;
195
196
}
196
197
197
- RTC_LOG (LS_INFO) << " New m-line: " << m_line_stream.str ();
198
- std::string before_strip = std::regex_replace (sdp, reg_m_line, m_line_stream.str ());
198
+ std::string before_strip = sdp;
199
199
std::string after_strip = before_strip;
200
200
201
- if (!is_audio && set_quality) {
202
- // Search for c-line and add a=priority line after it.
203
- std::regex reg_c_line (" c=IN .*\\ r\\ n" );
204
- std::smatch c_line_match;
205
- auto cline_search_result =
206
- std::regex_search (after_strip, c_line_match, reg_c_line);
207
- if (!cline_search_result || c_line_match.size () == 0 ) {
208
- RTC_LOG (LS_WARNING) << " c-line is not found. SDP: " << sdp;
209
- return sdp;
210
- }
211
- std::string c_line (c_line_match[0 ]);
212
- std::stringstream c_line_stream (c_line);
213
- std::string new_cline = c_line_stream.str () + " a=quality:10\r\n " ;
201
+ if (codec_names.size () > 0 ) {
202
+ RTC_LOG (LS_INFO) << " New m-line: " << m_line_stream.str ();
203
+ before_strip =
204
+ std::regex_replace (sdp, reg_m_line, m_line_stream.str ());
205
+ after_strip = before_strip;
214
206
215
- after_strip = std::regex_replace (before_strip, reg_c_line, new_cline);
216
- before_strip = after_strip;
217
- }
218
- // Remove all a=fmtp:xx, a=rtpmap:xx and a=rtcp-fb:xx where xx is not in m-line,
219
- // this includes the a=fmtp:xx apt:yy lines for rtx.
220
- for (size_t i = 3 , m_line_vector_size = m_line_vector.size (); i < m_line_vector_size; i++) {
221
- if (std::find (kept_codec_values.begin (), kept_codec_values.end (),
222
- m_line_vector[i]) == kept_codec_values.end ()) {
223
- std::string codec_value = m_line_vector[i];
224
- std::regex reg_rtp_xx_map (
225
- " a=rtpmap:" + codec_value + " .*\\ r\\ n" ,
226
- std::regex_constants::icase);
227
- after_strip = std::regex_replace (before_strip, reg_rtp_xx_map, " " );
228
- before_strip = after_strip;
229
- std::regex reg_fmtp_xx_map (
230
- " a=fmtp:" + codec_value + " .*\\ r\\ n" ,
231
- std::regex_constants::icase);
232
- after_strip = std::regex_replace (before_strip, reg_fmtp_xx_map, " " );
207
+ if (!is_audio && set_quality) {
208
+ // Search for c-line and add a=priority line after it.
209
+ std::regex reg_c_line (" c=IN .*\\ r\\ n" );
210
+ std::smatch c_line_match;
211
+ auto cline_search_result =
212
+ std::regex_search (after_strip, c_line_match, reg_c_line);
213
+ if (!cline_search_result || c_line_match.size () == 0 ) {
214
+ RTC_LOG (LS_WARNING) << " c-line is not found. SDP: " << sdp;
215
+ return sdp;
216
+ }
217
+ std::string c_line (c_line_match[0 ]);
218
+ std::stringstream c_line_stream (c_line);
219
+ std::string new_cline = c_line_stream.str () + " a=quality:10\r\n " ;
220
+
221
+ after_strip = std::regex_replace (before_strip, reg_c_line, new_cline);
233
222
before_strip = after_strip;
234
- std::regex reg_rtcp_map (
235
- " a=rtcp-fb:" + codec_value + " .*\\ r\\ n" ,
236
- std::regex_constants::icase);
237
- after_strip = std::regex_replace (before_strip, reg_rtcp_map, " " );
223
+ }
224
+ // Remove all a=fmtp:xx, a=rtpmap:xx and a=rtcp-fb:xx where xx is not in
225
+ // m-line, this includes the a=fmtp:xx apt:yy lines for rtx.
226
+ for (size_t i = 3 , m_line_vector_size = m_line_vector.size ();
227
+ i < m_line_vector_size; i++) {
228
+ if (std::find (kept_codec_values.begin (), kept_codec_values.end (),
229
+ m_line_vector[i]) == kept_codec_values.end ()) {
230
+ std::string codec_value = m_line_vector[i];
231
+ std::regex reg_rtp_xx_map (" a=rtpmap:" + codec_value + " .*\\ r\\ n" ,
232
+ std::regex_constants::icase);
233
+ after_strip = std::regex_replace (before_strip, reg_rtp_xx_map, " " );
234
+ before_strip = after_strip;
235
+ std::regex reg_fmtp_xx_map (" a=fmtp:" + codec_value + " .*\\ r\\ n" ,
236
+ std::regex_constants::icase);
237
+ after_strip = std::regex_replace (before_strip, reg_fmtp_xx_map, " " );
238
+ before_strip = after_strip;
239
+ std::regex reg_rtcp_map (" a=rtcp-fb:" + codec_value + " .*\\ r\\ n" ,
240
+ std::regex_constants::icase);
241
+ after_strip = std::regex_replace (before_strip, reg_rtcp_map, " " );
242
+ before_strip = after_strip;
243
+ }
244
+ }
245
+ } else {
246
+ if (!is_audio && set_quality) {
247
+ // Search for c-line and add a=priority line after it.
248
+ std::regex reg_c_line (" c=IN .*\\ r\\ n" );
249
+ std::smatch c_line_match;
250
+ auto cline_search_result =
251
+ std::regex_search (after_strip, c_line_match, reg_c_line);
252
+ if (!cline_search_result || c_line_match.size () == 0 ) {
253
+ RTC_LOG (LS_WARNING) << " c-line is not found. SDP: " << sdp;
254
+ return sdp;
255
+ }
256
+ std::string c_line (c_line_match[0 ]);
257
+ std::stringstream c_line_stream (c_line);
258
+ std::string new_cline = c_line_stream.str () + " a=quality:10\r\n " ;
259
+
260
+ after_strip = std::regex_replace (before_strip, reg_c_line, new_cline);
238
261
before_strip = after_strip;
239
262
}
240
263
}
0 commit comments