Skip to content

Commit

Permalink
[RTCVideoEncoderH264 initWithCodecInfo] should cope with invalid prof…
Browse files Browse the repository at this point in the history
…ile level id

https://bugs.webkit.org/show_bug.cgi?id=259592
rdar://113008968

Reviewed by Eric Carlson.

With WebCodecs, we allow JS to pass any profile level id to RTCVideoEncoderH264.
For now, we are defaulting to a default profile level id if none is matching.
A future patch should probably make sure that we return an error so that JS knows the configuration is not unsupported.

* Source/ThirdParty/libwebrtc/Source/webrtc/api/video_codecs/h264_profile_level_id.cc:

Canonical link: https://commits.webkit.org/266392@main
  • Loading branch information
youennf committed Jul 28, 2023
1 parent 7ccd31a commit 9b88dbf
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,29 @@ absl::optional<H264Level> H264SupportedLevel(int max_frame_pixel_count,
return absl::nullopt;
}

#if defined(WEBRTC_WEBKIT_BUILD)
H264ProfileLevelId defaultProfileLevelId()
{
// TODO(magjed): The default should really be kProfileBaseline and kLevel1
// according to the spec: https://tools.ietf.org/html/rfc6184#section-8.1. In
// order to not break backwards compatibility with older versions of WebRTC
// where external codecs don't have any parameters, use
// kProfileConstrainedBaseline kLevel3_1 instead. This workaround will only be
// done in an interim period to allow external clients to update their code.
// http://crbug/webrtc/6337.
return { H264Profile::kProfileConstrainedBaseline, H264Level::kLevel3_1 };
}

absl::optional<H264ProfileLevelId> ParseSdpForH264ProfileLevelId(
const SdpVideoFormat::Parameters& params) {
const auto profile_level_id_it = params.find(kProfileLevelId);
// This function is always returning a H264ProfileLevelId.
// FIXME: We might want to return std::nullopt and propagate an error in case of bad parsing.
return (profile_level_id_it == params.end())
? defaultProfileLevelId()
: ParseH264ProfileLevelId(profile_level_id_it->second.c_str()).value_or(defaultProfileLevelId());
}
#else
absl::optional<H264ProfileLevelId> ParseSdpForH264ProfileLevelId(
const SdpVideoFormat::Parameters& params) {
// TODO(magjed): The default should really be kProfileBaseline and kLevel1
Expand All @@ -194,6 +217,7 @@ absl::optional<H264ProfileLevelId> ParseSdpForH264ProfileLevelId(
? kDefaultProfileLevelId
: ParseH264ProfileLevelId(profile_level_id_it->second.c_str());
}
#endif

absl::optional<std::string> H264ProfileLevelIdToString(
const H264ProfileLevelId& profile_level_id) {
Expand Down

0 comments on commit 9b88dbf

Please sign in to comment.