Restore primary/rtx payload type assignment logic (followup)

Follow-up to
  https://webrtc-review.googlesource.com/c/src/+/375847
moving to a big outer loop over formats instead of calling the inner loop with single-element arrays.

BUG=webrtc:360058654

Change-Id: I7d263c1014d80f2312bf93595ee8e8ef9c4e7953
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/376081
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Philipp Hancke <phancke@meta.com>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#43896}
This commit is contained in:
Philipp Hancke 2025-02-10 13:54:27 -08:00 committed by WebRTC LUCI CQ
parent bdb9db695d
commit fe753682ba

View File

@ -200,50 +200,34 @@ std::vector<webrtc::SdpVideoFormat> GetDefaultSupportedFormats(
// This function will assign dynamic payload types (in the range [96, 127]
// and then [35, 63]) to the input codecs, and also add ULPFEC, RED, FlexFEC,
// It will also add default feedback params to the codecs.
webrtc::RTCErrorOr<std::vector<Codec>> AssignPayloadTypes(
const std::vector<webrtc::SdpVideoFormat>& supported_formats,
webrtc::RTCErrorOr<Codec> AssignPayloadType(
const webrtc::SdpVideoFormat& format,
webrtc::PayloadTypePicker& pt_mapper,
const webrtc::FieldTrialsView& trials) {
std::vector<Codec> output_codecs;
for (const webrtc::SdpVideoFormat& format : supported_formats) {
Codec codec = cricket::CreateVideoCodec(format);
codec.id = pt_mapper.SuggestMapping(codec, /* excluder= */ nullptr).value();
// TODO: https://issues.webrtc.org/360058654 - Handle running out of IDs.
AddDefaultFeedbackParams(&codec, trials);
output_codecs.push_back(codec);
webrtc::RTCErrorOr<webrtc::PayloadType> result =
pt_mapper.SuggestMapping(codec, /* excluder= */ nullptr);
if (!result.ok()) {
return result.MoveError();
}
return output_codecs;
codec.id = result.value();
AddDefaultFeedbackParams(&codec, trials);
return codec;
}
// This function will add associated RTX codecs for recognized codecs (VP8, VP9,
// H264, and RED).
webrtc::RTCErrorOr<std::vector<Codec>> AddRtx(
const std::vector<Codec>& input_codecs,
// This function will add a associated RTX codec for a recognized primary codecs
// (VP8, VP9, AV1, H264, and RED).
webrtc::RTCErrorOr<Codec> AddRtx(const Codec& primary_codec,
webrtc::PayloadTypePicker& pt_mapper) {
std::vector<Codec> output_codecs;
for (const Codec& codec : input_codecs) {
// We want to interleave the input codecs with the output codecs.
output_codecs.push_back(codec);
bool isFecCodec = absl::EqualsIgnoreCase(codec.name, kUlpfecCodecName) ||
absl::EqualsIgnoreCase(codec.name, kFlexfecCodecName);
// Add associated RTX codec for non-FEC codecs.
if (!isFecCodec) {
Codec rtx_codec =
cricket::CreateVideoRtxCodec(Codec::kIdNotSet, codec.id);
cricket::CreateVideoRtxCodec(Codec::kIdNotSet, primary_codec.id);
webrtc::RTCErrorOr<webrtc::PayloadType> result =
pt_mapper.SuggestMapping(rtx_codec, /* excluder= */ nullptr);
if (!result.ok()) {
if (result.error().type() == webrtc::RTCErrorType::RESOURCE_EXHAUSTED) {
// Out of payload types. Stop adding RTX codecs.
break;
}
return result.MoveError();
}
rtx_codec.id = result.value();
output_codecs.push_back(rtx_codec);
}
}
return output_codecs;
return rtx_codec;
}
// TODO(kron): Perhaps it is better to move the implicit knowledge to the place
@ -258,30 +242,34 @@ std::vector<Codec> GetPayloadTypesAndDefaultCodecs(
GetDefaultSupportedFormats(factory, is_decoder_factory, trials);
// Temporary: Use PayloadTypePicker for assignments.
// TODO: https://issues.webrtc.org/360058654 - stop assigning PTs here.
webrtc::PayloadTypePicker pt_mapper;
std::vector<Codec> output_codecs;
for (const auto& supported_format : supported_formats) {
webrtc::RTCErrorOr<std::vector<Codec>> result =
AssignPayloadTypes({supported_format}, pt_mapper, trials);
RTC_DCHECK(result.ok());
if (result.ok()) {
for (const auto& codec : result.value()) {
if (include_rtx) {
// This will return both primary and rtx if there is rtx.
result = AddRtx({codec}, pt_mapper);
if (result.ok()) {
for (const auto& codec : result.value()) {
output_codecs.push_back(codec);
webrtc::RTCErrorOr<Codec> result =
AssignPayloadType(supported_format, pt_mapper, trials);
if (!result.ok()) {
// TODO: https://issues.webrtc.org/360058654 - stop assigning PTs here.
// TODO: https://issues.webrtc.org/360058654 - Handle running out of IDs.
continue;
}
} else {
output_codecs.push_back(codec);
output_codecs.push_back(result.value());
if (include_rtx) {
Codec::ResiliencyType resiliency_type =
result.value().GetResiliencyType();
// FEC codecs do not use retransmission.
if (resiliency_type == Codec::ResiliencyType::kFlexfec ||
resiliency_type == Codec::ResiliencyType::kUlpfec) {
continue;
}
} else {
output_codecs.push_back(codec);
}
webrtc::RTCErrorOr<Codec> rtx_result = AddRtx(result.value(), pt_mapper);
if (!rtx_result.ok()) {
// TODO: https://issues.webrtc.org/360058654 - stop assigning PTs here.
// TODO: https://issues.webrtc.org/360058654 - Handle running out of
// IDs.
continue;
}
output_codecs.push_back(rtx_result.MoveValue());
}
}
return output_codecs;