Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit d71b214

Browse files
committed
Fix port range setting for subscription without codec specified.
1 parent baa7449 commit d71b214

File tree

1 file changed

+62
-39
lines changed

1 file changed

+62
-39
lines changed

talk/owt/sdk/base/sdputils.cc

Lines changed: 62 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ std::string SdpUtils::SetPreferAudioCodecs(const std::string& original_sdp,
4444
std::string SdpUtils::SetPreferVideoCodecs(const std::string& original_sdp,
4545
std::vector<VideoCodec>& codec, bool set_quality) {
4646
std::string cur_sdp(original_sdp);
47-
if (codec.size() == 0)
47+
if (codec.size() == 0 && !set_quality)
4848
return cur_sdp;
4949
std::vector<VideoCodec> rcodecs(codec.rbegin(), codec.rend());
5050
std::vector<std::string> codec_names;
@@ -59,6 +59,7 @@ std::string SdpUtils::SetPreferVideoCodecs(const std::string& original_sdp,
5959
cur_sdp = SdpUtils::SetPreferCodecs(cur_sdp, codec_names, false, set_quality);
6060
return cur_sdp;
6161
}
62+
6263
std::vector<std::string> SdpUtils::GetCodecValues(const std::string& sdp,
6364
std::string& codec_name,
6465
bool is_audio) {
@@ -95,7 +96,7 @@ std::string SdpUtils::SetPreferCodecs(const std::string& sdp,
9596
current_sdp = rtx_map_match.suffix();
9697
}
9798
std::vector<std::string> kept_codec_values;
98-
if (!is_audio) {
99+
if (!is_audio && codec_names.size() > 0) {
99100
// Get red and ulpfec payload type if any.
100101
bool has_red = false, has_ulpfec = false, has_flexfec = false;
101102
std::regex reg_red_map(
@@ -194,47 +195,69 @@ std::string SdpUtils::SetPreferCodecs(const std::string& sdp,
194195
m_line_stream << " " << codec_value;
195196
}
196197

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;
199199
std::string after_strip = before_strip;
200200

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;
214206

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);
233222
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);
238261
before_strip = after_strip;
239262
}
240263
}

0 commit comments

Comments
 (0)