red: remove hardcoded parameters in favor of taking them from the codec

and make it less opus-specific.

BUG=None

Change-Id: I6fe2975ba6e45a3758fedc5b950de90e8d9df362
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/375436
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Jakob Ivarsson‎ <jakobi@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@meta.com>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43846}
This commit is contained in:
Philipp Hancke 2025-01-28 13:30:38 -08:00 committed by WebRTC LUCI CQ
parent 9c56cb3eda
commit e828c6dba3
2 changed files with 7 additions and 7 deletions

View File

@ -413,8 +413,8 @@ std::vector<Codec> LegacyCollectCodecs(
if (allocate_pt) { if (allocate_pt) {
std::string red_fmtp = std::string red_fmtp =
rtc::ToString(codec.id) + "/" + rtc::ToString(codec.id); rtc::ToString(codec.id) + "/" + rtc::ToString(codec.id);
cricket::Codec red_codec = cricket::Codec red_codec = CreateAudioCodec(
CreateAudioCodec({kRedCodecName, 48000, 2, {{"", red_fmtp}}}); {kRedCodecName, codec.clockrate, codec.channels, {{"", red_fmtp}}});
red_codec.id = pt_mapper.SuggestMapping(red_codec, nullptr).value(); red_codec.id = pt_mapper.SuggestMapping(red_codec, nullptr).value();
out.push_back(red_codec); out.push_back(red_codec);
} else { } else {

View File

@ -434,7 +434,7 @@ webrtc::RTCError AssignCodecIdsAndLinkRed(
webrtc::PayloadTypeSuggester* pt_suggester, webrtc::PayloadTypeSuggester* pt_suggester,
const std::string& mid, const std::string& mid,
std::vector<Codec>& codecs) { std::vector<Codec>& codecs) {
int opus_codec = Codec::kIdNotSet; int codec_payload_type = Codec::kIdNotSet;
for (cricket::Codec& codec : codecs) { for (cricket::Codec& codec : codecs) {
if (codec.id == Codec::kIdNotSet) { if (codec.id == Codec::kIdNotSet) {
// Add payload types to codecs, if needed // Add payload types to codecs, if needed
@ -449,18 +449,18 @@ webrtc::RTCError AssignCodecIdsAndLinkRed(
} }
// record first Opus codec id // record first Opus codec id
if (absl::EqualsIgnoreCase(codec.name, kOpusCodecName) && if (absl::EqualsIgnoreCase(codec.name, kOpusCodecName) &&
opus_codec == Codec::kIdNotSet) { codec_payload_type == Codec::kIdNotSet) {
opus_codec = codec.id; codec_payload_type = codec.id;
} }
} }
if (opus_codec != Codec::kIdNotSet) { if (codec_payload_type != Codec::kIdNotSet) {
for (cricket::Codec& codec : codecs) { for (cricket::Codec& codec : codecs) {
if (codec.type == Codec::Type::kAudio && if (codec.type == Codec::Type::kAudio &&
absl::EqualsIgnoreCase(codec.name, kRedCodecName)) { absl::EqualsIgnoreCase(codec.name, kRedCodecName)) {
if (codec.params.empty()) { if (codec.params.empty()) {
char buffer[100]; char buffer[100];
rtc::SimpleStringBuilder param(buffer); rtc::SimpleStringBuilder param(buffer);
param << opus_codec << "/" << opus_codec; param << codec_payload_type << "/" << codec_payload_type;
RTC_LOG(LS_ERROR) << "DEBUG: Setting RED param to " << param.str(); RTC_LOG(LS_ERROR) << "DEBUG: Setting RED param to " << param.str();
codec.SetParam(kCodecParamNotInNameValueFormat, param.str()); codec.SetParam(kCodecParamNotInNameValueFormat, param.str());
} }