From d8bbc7858622b6d9c278469aab701ca0b609cddf Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 15 May 2024 05:35:49 +0200 Subject: Merging upstream version 126.0. Signed-off-by: Daniel Baumann --- third_party/libwebrtc/api/video_codecs/BUILD.gn | 1 + .../libwebrtc/api/video_codecs/av1_profile.cc | 6 +- .../libwebrtc/api/video_codecs/av1_profile.h | 6 +- .../api/video_codecs/h264_profile_level_id.cc | 6 +- .../api/video_codecs/h264_profile_level_id.h | 6 +- .../api/video_codecs/h265_profile_tier_level.cc | 496 ++++++++++----------- .../api/video_codecs/h265_profile_tier_level.h | 218 ++++----- .../libwebrtc/api/video_codecs/sdp_video_format.cc | 11 +- .../libwebrtc/api/video_codecs/sdp_video_format.h | 10 +- .../test/h264_profile_level_id_unittest.cc | 6 +- .../test/h265_profile_tier_level_unittest.cc | 496 ++++++++++----------- .../video_codecs/test/sdp_video_format_unittest.cc | 2 +- ...o_encoder_factory_template_libaom_av1_adapter.h | 3 +- ...o_encoder_factory_template_libvpx_vp8_adapter.h | 3 +- .../libwebrtc/api/video_codecs/vp9_profile.cc | 6 +- .../libwebrtc/api/video_codecs/vp9_profile.h | 6 +- 16 files changed, 641 insertions(+), 641 deletions(-) (limited to 'third_party/libwebrtc/api/video_codecs') diff --git a/third_party/libwebrtc/api/video_codecs/BUILD.gn b/third_party/libwebrtc/api/video_codecs/BUILD.gn index 94c9cc8b87..3865f4fee7 100644 --- a/third_party/libwebrtc/api/video_codecs/BUILD.gn +++ b/third_party/libwebrtc/api/video_codecs/BUILD.gn @@ -83,6 +83,7 @@ rtc_library("video_codecs_api") { "..:fec_controller_api", "..:scoped_refptr", "../../api:array_view", + "../../api:rtp_parameters", "../../modules/video_coding:codec_globals_headers", "../../rtc_base:checks", "../../rtc_base:logging", diff --git a/third_party/libwebrtc/api/video_codecs/av1_profile.cc b/third_party/libwebrtc/api/video_codecs/av1_profile.cc index eefe166d80..59d7b13e51 100644 --- a/third_party/libwebrtc/api/video_codecs/av1_profile.cc +++ b/third_party/libwebrtc/api/video_codecs/av1_profile.cc @@ -50,7 +50,7 @@ absl::optional StringToAV1Profile(absl::string_view str) { } absl::optional ParseSdpForAV1Profile( - const SdpVideoFormat::Parameters& params) { + const CodecParameterMap& params) { const auto profile_it = params.find(kAV1FmtpProfile); if (profile_it == params.end()) return AV1Profile::kProfile0; @@ -58,8 +58,8 @@ absl::optional ParseSdpForAV1Profile( return StringToAV1Profile(profile_str); } -bool AV1IsSameProfile(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2) { +bool AV1IsSameProfile(const CodecParameterMap& params1, + const CodecParameterMap& params2) { const absl::optional profile = ParseSdpForAV1Profile(params1); const absl::optional other_profile = ParseSdpForAV1Profile(params2); diff --git a/third_party/libwebrtc/api/video_codecs/av1_profile.h b/third_party/libwebrtc/api/video_codecs/av1_profile.h index 2254d5ecd3..bc9767631c 100644 --- a/third_party/libwebrtc/api/video_codecs/av1_profile.h +++ b/third_party/libwebrtc/api/video_codecs/av1_profile.h @@ -45,12 +45,12 @@ absl::optional StringToAV1Profile(absl::string_view profile); // specified and an empty value if the profile key is present but contains an // invalid value. RTC_EXPORT absl::optional ParseSdpForAV1Profile( - const SdpVideoFormat::Parameters& params); + const CodecParameterMap& params); // Returns true if the parameters have the same AV1 profile or neither contains // an AV1 profile, otherwise false. -bool AV1IsSameProfile(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2); +bool AV1IsSameProfile(const CodecParameterMap& params1, + const CodecParameterMap& params2); } // namespace webrtc diff --git a/third_party/libwebrtc/api/video_codecs/h264_profile_level_id.cc b/third_party/libwebrtc/api/video_codecs/h264_profile_level_id.cc index 5844ca0e32..9bd9c9e4ab 100644 --- a/third_party/libwebrtc/api/video_codecs/h264_profile_level_id.cc +++ b/third_party/libwebrtc/api/video_codecs/h264_profile_level_id.cc @@ -178,7 +178,7 @@ absl::optional H264SupportedLevel(int max_frame_pixel_count, } absl::optional ParseSdpForH264ProfileLevelId( - const SdpVideoFormat::Parameters& params) { + const CodecParameterMap& params) { // 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 @@ -243,8 +243,8 @@ absl::optional H264ProfileLevelIdToString( return {str}; } -bool H264IsSameProfile(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2) { +bool H264IsSameProfile(const CodecParameterMap& params1, + const CodecParameterMap& params2) { const absl::optional profile_level_id = ParseSdpForH264ProfileLevelId(params1); const absl::optional other_profile_level_id = diff --git a/third_party/libwebrtc/api/video_codecs/h264_profile_level_id.h b/third_party/libwebrtc/api/video_codecs/h264_profile_level_id.h index 4b46ad329d..37709fae64 100644 --- a/third_party/libwebrtc/api/video_codecs/h264_profile_level_id.h +++ b/third_party/libwebrtc/api/video_codecs/h264_profile_level_id.h @@ -67,7 +67,7 @@ absl::optional ParseH264ProfileLevelId(const char* str); // returned if the profile-level-id key is missing. Nothing will be returned if // the key is present but the string is invalid. RTC_EXPORT absl::optional ParseSdpForH264ProfileLevelId( - const SdpVideoFormat::Parameters& params); + const CodecParameterMap& params); // Given that a decoder supports up to a given frame size (in pixels) at up to a // given number of frames per second, return the highest H.264 level where it @@ -84,8 +84,8 @@ RTC_EXPORT absl::optional H264ProfileLevelIdToString( // Returns true if the parameters have the same H264 profile (Baseline, High, // etc). -RTC_EXPORT bool H264IsSameProfile(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2); +RTC_EXPORT bool H264IsSameProfile(const CodecParameterMap& params1, + const CodecParameterMap& params2); } // namespace webrtc diff --git a/third_party/libwebrtc/api/video_codecs/h265_profile_tier_level.cc b/third_party/libwebrtc/api/video_codecs/h265_profile_tier_level.cc index f5b376e287..f4dcebb25a 100644 --- a/third_party/libwebrtc/api/video_codecs/h265_profile_tier_level.cc +++ b/third_party/libwebrtc/api/video_codecs/h265_profile_tier_level.cc @@ -1,248 +1,248 @@ -/* - * Copyright (c) 2023 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "api/video_codecs/h265_profile_tier_level.h" - -#include - -#include "rtc_base/string_to_number.h" - -namespace webrtc { - -namespace { - -const char kH265FmtpProfile[] = "profile-id"; -const char kH265FmtpTier[] = "tier-flag"; -const char kH265FmtpLevel[] = "level-id"; - -} // anonymous namespace - -// Annex A of https://www.itu.int/rec/T-REC-H.265 (08/21), section A.3. -absl::optional StringToH265Profile(const std::string& profile) { - absl::optional i = rtc::StringToNumber(profile); - if (!i.has_value()) { - return absl::nullopt; - } - - switch (i.value()) { - case 1: - return H265Profile::kProfileMain; - case 2: - return H265Profile::kProfileMain10; - case 3: - return H265Profile::kProfileMainStill; - case 4: - return H265Profile::kProfileRangeExtensions; - case 5: - return H265Profile::kProfileHighThroughput; - case 6: - return H265Profile::kProfileMultiviewMain; - case 7: - return H265Profile::kProfileScalableMain; - case 8: - return H265Profile::kProfile3dMain; - case 9: - return H265Profile::kProfileScreenContentCoding; - case 10: - return H265Profile::kProfileScalableRangeExtensions; - case 11: - return H265Profile::kProfileHighThroughputScreenContentCoding; - default: - return absl::nullopt; - } -} - -// Annex A of https://www.itu.int/rec/T-REC-H.265 (08/21), section A.4, -// tiers and levels. -absl::optional StringToH265Tier(const std::string& tier) { - absl::optional i = rtc::StringToNumber(tier); - if (!i.has_value()) { - return absl::nullopt; - } - - switch (i.value()) { - case 0: - return H265Tier::kTier0; - case 1: - return H265Tier::kTier1; - default: - return absl::nullopt; - } -} - -absl::optional StringToH265Level(const std::string& level) { - const absl::optional i = rtc::StringToNumber(level); - if (!i.has_value()) - return absl::nullopt; - - switch (i.value()) { - case 30: - return H265Level::kLevel1; - case 60: - return H265Level::kLevel2; - case 63: - return H265Level::kLevel2_1; - case 90: - return H265Level::kLevel3; - case 93: - return H265Level::kLevel3_1; - case 120: - return H265Level::kLevel4; - case 123: - return H265Level::kLevel4_1; - case 150: - return H265Level::kLevel5; - case 153: - return H265Level::kLevel5_1; - case 156: - return H265Level::kLevel5_2; - case 180: - return H265Level::kLevel6; - case 183: - return H265Level::kLevel6_1; - case 186: - return H265Level::kLevel6_2; - default: - return absl::nullopt; - } -} - -std::string H265ProfileToString(H265Profile profile) { - switch (profile) { - case H265Profile::kProfileMain: - return "1"; - case H265Profile::kProfileMain10: - return "2"; - case H265Profile::kProfileMainStill: - return "3"; - case H265Profile::kProfileRangeExtensions: - return "4"; - case H265Profile::kProfileHighThroughput: - return "5"; - case H265Profile::kProfileMultiviewMain: - return "6"; - case H265Profile::kProfileScalableMain: - return "7"; - case H265Profile::kProfile3dMain: - return "8"; - case H265Profile::kProfileScreenContentCoding: - return "9"; - case H265Profile::kProfileScalableRangeExtensions: - return "10"; - case H265Profile::kProfileHighThroughputScreenContentCoding: - return "11"; - } -} - -std::string H265TierToString(H265Tier tier) { - switch (tier) { - case H265Tier::kTier0: - return "0"; - case H265Tier::kTier1: - return "1"; - } -} - -std::string H265LevelToString(H265Level level) { - switch (level) { - case H265Level::kLevel1: - return "30"; - case H265Level::kLevel2: - return "60"; - case H265Level::kLevel2_1: - return "63"; - case H265Level::kLevel3: - return "90"; - case H265Level::kLevel3_1: - return "93"; - case H265Level::kLevel4: - return "120"; - case H265Level::kLevel4_1: - return "123"; - case H265Level::kLevel5: - return "150"; - case H265Level::kLevel5_1: - return "153"; - case H265Level::kLevel5_2: - return "156"; - case H265Level::kLevel6: - return "180"; - case H265Level::kLevel6_1: - return "183"; - case H265Level::kLevel6_2: - return "186"; - } -} - -absl::optional ParseSdpForH265ProfileTierLevel( - const SdpVideoFormat::Parameters& params) { - static const H265ProfileTierLevel kDefaultProfileTierLevel( - H265Profile::kProfileMain, H265Tier::kTier0, H265Level::kLevel3_1); - bool profile_tier_level_specified = false; - - absl::optional profile; - const auto profile_it = params.find(kH265FmtpProfile); - if (profile_it != params.end()) { - profile_tier_level_specified = true; - const std::string& profile_str = profile_it->second; - profile = StringToH265Profile(profile_str); - if (!profile) { - return absl::nullopt; - } - } else { - profile = H265Profile::kProfileMain; - } - absl::optional tier; - const auto tier_it = params.find(kH265FmtpTier); - if (tier_it != params.end()) { - profile_tier_level_specified = true; - const std::string& tier_str = tier_it->second; - tier = StringToH265Tier(tier_str); - if (!tier) { - return absl::nullopt; - } - } else { - tier = H265Tier::kTier0; - } - absl::optional level; - const auto level_it = params.find(kH265FmtpLevel); - if (level_it != params.end()) { - profile_tier_level_specified = true; - const std::string& level_str = level_it->second; - level = StringToH265Level(level_str); - if (!level) { - return absl::nullopt; - } - } else { - level = H265Level::kLevel3_1; - } - - // Spec Table A.9, level 1 to level 3.1 does not allow high tiers. - if (level <= H265Level::kLevel3_1 && tier == H265Tier::kTier1) { - return absl::nullopt; - } - - return !profile_tier_level_specified - ? kDefaultProfileTierLevel - : H265ProfileTierLevel(profile.value(), tier.value(), - level.value()); -} - -bool H265IsSameProfileTierLevel(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2) { - const absl::optional ptl1 = - ParseSdpForH265ProfileTierLevel(params1); - const absl::optional ptl2 = - ParseSdpForH265ProfileTierLevel(params2); - return ptl1 && ptl2 && ptl1->profile == ptl2->profile && - ptl1->tier == ptl2->tier && ptl1->level == ptl2->level; -} - -} // namespace webrtc +/* + * Copyright (c) 2023 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "api/video_codecs/h265_profile_tier_level.h" + +#include + +#include "rtc_base/string_to_number.h" + +namespace webrtc { + +namespace { + +const char kH265FmtpProfile[] = "profile-id"; +const char kH265FmtpTier[] = "tier-flag"; +const char kH265FmtpLevel[] = "level-id"; + +} // anonymous namespace + +// Annex A of https://www.itu.int/rec/T-REC-H.265 (08/21), section A.3. +absl::optional StringToH265Profile(const std::string& profile) { + absl::optional i = rtc::StringToNumber(profile); + if (!i.has_value()) { + return absl::nullopt; + } + + switch (i.value()) { + case 1: + return H265Profile::kProfileMain; + case 2: + return H265Profile::kProfileMain10; + case 3: + return H265Profile::kProfileMainStill; + case 4: + return H265Profile::kProfileRangeExtensions; + case 5: + return H265Profile::kProfileHighThroughput; + case 6: + return H265Profile::kProfileMultiviewMain; + case 7: + return H265Profile::kProfileScalableMain; + case 8: + return H265Profile::kProfile3dMain; + case 9: + return H265Profile::kProfileScreenContentCoding; + case 10: + return H265Profile::kProfileScalableRangeExtensions; + case 11: + return H265Profile::kProfileHighThroughputScreenContentCoding; + default: + return absl::nullopt; + } +} + +// Annex A of https://www.itu.int/rec/T-REC-H.265 (08/21), section A.4, +// tiers and levels. +absl::optional StringToH265Tier(const std::string& tier) { + absl::optional i = rtc::StringToNumber(tier); + if (!i.has_value()) { + return absl::nullopt; + } + + switch (i.value()) { + case 0: + return H265Tier::kTier0; + case 1: + return H265Tier::kTier1; + default: + return absl::nullopt; + } +} + +absl::optional StringToH265Level(const std::string& level) { + const absl::optional i = rtc::StringToNumber(level); + if (!i.has_value()) + return absl::nullopt; + + switch (i.value()) { + case 30: + return H265Level::kLevel1; + case 60: + return H265Level::kLevel2; + case 63: + return H265Level::kLevel2_1; + case 90: + return H265Level::kLevel3; + case 93: + return H265Level::kLevel3_1; + case 120: + return H265Level::kLevel4; + case 123: + return H265Level::kLevel4_1; + case 150: + return H265Level::kLevel5; + case 153: + return H265Level::kLevel5_1; + case 156: + return H265Level::kLevel5_2; + case 180: + return H265Level::kLevel6; + case 183: + return H265Level::kLevel6_1; + case 186: + return H265Level::kLevel6_2; + default: + return absl::nullopt; + } +} + +std::string H265ProfileToString(H265Profile profile) { + switch (profile) { + case H265Profile::kProfileMain: + return "1"; + case H265Profile::kProfileMain10: + return "2"; + case H265Profile::kProfileMainStill: + return "3"; + case H265Profile::kProfileRangeExtensions: + return "4"; + case H265Profile::kProfileHighThroughput: + return "5"; + case H265Profile::kProfileMultiviewMain: + return "6"; + case H265Profile::kProfileScalableMain: + return "7"; + case H265Profile::kProfile3dMain: + return "8"; + case H265Profile::kProfileScreenContentCoding: + return "9"; + case H265Profile::kProfileScalableRangeExtensions: + return "10"; + case H265Profile::kProfileHighThroughputScreenContentCoding: + return "11"; + } +} + +std::string H265TierToString(H265Tier tier) { + switch (tier) { + case H265Tier::kTier0: + return "0"; + case H265Tier::kTier1: + return "1"; + } +} + +std::string H265LevelToString(H265Level level) { + switch (level) { + case H265Level::kLevel1: + return "30"; + case H265Level::kLevel2: + return "60"; + case H265Level::kLevel2_1: + return "63"; + case H265Level::kLevel3: + return "90"; + case H265Level::kLevel3_1: + return "93"; + case H265Level::kLevel4: + return "120"; + case H265Level::kLevel4_1: + return "123"; + case H265Level::kLevel5: + return "150"; + case H265Level::kLevel5_1: + return "153"; + case H265Level::kLevel5_2: + return "156"; + case H265Level::kLevel6: + return "180"; + case H265Level::kLevel6_1: + return "183"; + case H265Level::kLevel6_2: + return "186"; + } +} + +absl::optional ParseSdpForH265ProfileTierLevel( + const CodecParameterMap& params) { + static const H265ProfileTierLevel kDefaultProfileTierLevel( + H265Profile::kProfileMain, H265Tier::kTier0, H265Level::kLevel3_1); + bool profile_tier_level_specified = false; + + absl::optional profile; + const auto profile_it = params.find(kH265FmtpProfile); + if (profile_it != params.end()) { + profile_tier_level_specified = true; + const std::string& profile_str = profile_it->second; + profile = StringToH265Profile(profile_str); + if (!profile) { + return absl::nullopt; + } + } else { + profile = H265Profile::kProfileMain; + } + absl::optional tier; + const auto tier_it = params.find(kH265FmtpTier); + if (tier_it != params.end()) { + profile_tier_level_specified = true; + const std::string& tier_str = tier_it->second; + tier = StringToH265Tier(tier_str); + if (!tier) { + return absl::nullopt; + } + } else { + tier = H265Tier::kTier0; + } + absl::optional level; + const auto level_it = params.find(kH265FmtpLevel); + if (level_it != params.end()) { + profile_tier_level_specified = true; + const std::string& level_str = level_it->second; + level = StringToH265Level(level_str); + if (!level) { + return absl::nullopt; + } + } else { + level = H265Level::kLevel3_1; + } + + // Spec Table A.9, level 1 to level 3.1 does not allow high tiers. + if (level <= H265Level::kLevel3_1 && tier == H265Tier::kTier1) { + return absl::nullopt; + } + + return !profile_tier_level_specified + ? kDefaultProfileTierLevel + : H265ProfileTierLevel(profile.value(), tier.value(), + level.value()); +} + +bool H265IsSameProfileTierLevel(const CodecParameterMap& params1, + const CodecParameterMap& params2) { + const absl::optional ptl1 = + ParseSdpForH265ProfileTierLevel(params1); + const absl::optional ptl2 = + ParseSdpForH265ProfileTierLevel(params2); + return ptl1 && ptl2 && ptl1->profile == ptl2->profile && + ptl1->tier == ptl2->tier && ptl1->level == ptl2->level; +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/api/video_codecs/h265_profile_tier_level.h b/third_party/libwebrtc/api/video_codecs/h265_profile_tier_level.h index 3056d2b623..efbdf287ed 100644 --- a/third_party/libwebrtc/api/video_codecs/h265_profile_tier_level.h +++ b/third_party/libwebrtc/api/video_codecs/h265_profile_tier_level.h @@ -1,109 +1,109 @@ -/* - * Copyright (c) 2023 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#ifndef API_VIDEO_CODECS_H265_PROFILE_TIER_LEVEL_H_ -#define API_VIDEO_CODECS_H265_PROFILE_TIER_LEVEL_H_ - -#include - -#include "absl/types/optional.h" -#include "api/video_codecs/sdp_video_format.h" -#include "rtc_base/system/rtc_export.h" - -namespace webrtc { - -// Profiles can be found at: -// https://www.itu.int/rec/T-REC-H.265 -// The enum values match the number specified in the SDP. -enum class H265Profile { - kProfileMain = 1, - kProfileMain10 = 2, - kProfileMainStill = 3, - kProfileRangeExtensions = 4, - kProfileHighThroughput = 5, - kProfileMultiviewMain = 6, - kProfileScalableMain = 7, - kProfile3dMain = 8, - kProfileScreenContentCoding = 9, - kProfileScalableRangeExtensions = 10, - kProfileHighThroughputScreenContentCoding = 11, -}; - -// Tiers can be found at https://www.itu.int/rec/T-REC-H.265 -enum class H265Tier { - kTier0, - kTier1, -}; - -// All values are equal to 30 times the level number. -enum class H265Level { - kLevel1 = 30, - kLevel2 = 60, - kLevel2_1 = 63, - kLevel3 = 90, - kLevel3_1 = 93, - kLevel4 = 120, - kLevel4_1 = 123, - kLevel5 = 150, - kLevel5_1 = 153, - kLevel5_2 = 156, - kLevel6 = 180, - kLevel6_1 = 183, - kLevel6_2 = 186, -}; - -struct H265ProfileTierLevel { - constexpr H265ProfileTierLevel(H265Profile profile, - H265Tier tier, - H265Level level) - : profile(profile), tier(tier), level(level) {} - H265Profile profile; - H265Tier tier; - H265Level level; -}; - -// Helper function to convert H265Profile to std::string. -RTC_EXPORT std::string H265ProfileToString(H265Profile profile); - -// Helper function to convert H265Tier to std::string. -RTC_EXPORT std::string H265TierToString(H265Tier tier); - -// Helper function to convert H265Level to std::string. -RTC_EXPORT std::string H265LevelToString(H265Level level); - -// Helper function to get H265Profile from profile string. -RTC_EXPORT absl::optional StringToH265Profile( - const std::string& profile); - -// Helper function to get H265Tier from tier string. -RTC_EXPORT absl::optional StringToH265Tier(const std::string& tier); - -// Helper function to get H265Level from level string. -RTC_EXPORT absl::optional StringToH265Level( - const std::string& level); - -// Parses an SDP key-value map of format parameters to retrive an H265 -// profile/tier/level. Returns an H265ProfileTierlevel by setting its -// members. profile defaults to `kProfileMain` if no profile-id is specified. -// tier defaults to "kTier0" if no tier-flag is specified. -// level defaults to "kLevel3_1" if no level-id is specified. -// Returns empty value if any of the profile/tier/level key is present but -// contains an invalid value. -RTC_EXPORT absl::optional ParseSdpForH265ProfileTierLevel( - const SdpVideoFormat::Parameters& params); - -// Returns true if the parameters have the same H265 profile or neither contains -// an H265 profile, otherwise false. -bool H265IsSameProfileTierLevel(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2); - -} // namespace webrtc - -#endif // API_VIDEO_CODECS_H265_PROFILE_TIER_LEVEL_H_ +/* + * Copyright (c) 2023 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef API_VIDEO_CODECS_H265_PROFILE_TIER_LEVEL_H_ +#define API_VIDEO_CODECS_H265_PROFILE_TIER_LEVEL_H_ + +#include + +#include "absl/types/optional.h" +#include "api/video_codecs/sdp_video_format.h" +#include "rtc_base/system/rtc_export.h" + +namespace webrtc { + +// Profiles can be found at: +// https://www.itu.int/rec/T-REC-H.265 +// The enum values match the number specified in the SDP. +enum class H265Profile { + kProfileMain = 1, + kProfileMain10 = 2, + kProfileMainStill = 3, + kProfileRangeExtensions = 4, + kProfileHighThroughput = 5, + kProfileMultiviewMain = 6, + kProfileScalableMain = 7, + kProfile3dMain = 8, + kProfileScreenContentCoding = 9, + kProfileScalableRangeExtensions = 10, + kProfileHighThroughputScreenContentCoding = 11, +}; + +// Tiers can be found at https://www.itu.int/rec/T-REC-H.265 +enum class H265Tier { + kTier0, + kTier1, +}; + +// All values are equal to 30 times the level number. +enum class H265Level { + kLevel1 = 30, + kLevel2 = 60, + kLevel2_1 = 63, + kLevel3 = 90, + kLevel3_1 = 93, + kLevel4 = 120, + kLevel4_1 = 123, + kLevel5 = 150, + kLevel5_1 = 153, + kLevel5_2 = 156, + kLevel6 = 180, + kLevel6_1 = 183, + kLevel6_2 = 186, +}; + +struct H265ProfileTierLevel { + constexpr H265ProfileTierLevel(H265Profile profile, + H265Tier tier, + H265Level level) + : profile(profile), tier(tier), level(level) {} + H265Profile profile; + H265Tier tier; + H265Level level; +}; + +// Helper function to convert H265Profile to std::string. +RTC_EXPORT std::string H265ProfileToString(H265Profile profile); + +// Helper function to convert H265Tier to std::string. +RTC_EXPORT std::string H265TierToString(H265Tier tier); + +// Helper function to convert H265Level to std::string. +RTC_EXPORT std::string H265LevelToString(H265Level level); + +// Helper function to get H265Profile from profile string. +RTC_EXPORT absl::optional StringToH265Profile( + const std::string& profile); + +// Helper function to get H265Tier from tier string. +RTC_EXPORT absl::optional StringToH265Tier(const std::string& tier); + +// Helper function to get H265Level from level string. +RTC_EXPORT absl::optional StringToH265Level( + const std::string& level); + +// Parses an SDP key-value map of format parameters to retrive an H265 +// profile/tier/level. Returns an H265ProfileTierlevel by setting its +// members. profile defaults to `kProfileMain` if no profile-id is specified. +// tier defaults to "kTier0" if no tier-flag is specified. +// level defaults to "kLevel3_1" if no level-id is specified. +// Returns empty value if any of the profile/tier/level key is present but +// contains an invalid value. +RTC_EXPORT absl::optional ParseSdpForH265ProfileTierLevel( + const CodecParameterMap& params); + +// Returns true if the parameters have the same H265 profile or neither contains +// an H265 profile, otherwise false. +RTC_EXPORT bool H265IsSameProfileTierLevel(const CodecParameterMap& params1, + const CodecParameterMap& params2); + +} // namespace webrtc + +#endif // API_VIDEO_CODECS_H265_PROFILE_TIER_LEVEL_H_ diff --git a/third_party/libwebrtc/api/video_codecs/sdp_video_format.cc b/third_party/libwebrtc/api/video_codecs/sdp_video_format.cc index 51ae18cd78..0f313e84a9 100644 --- a/third_party/libwebrtc/api/video_codecs/sdp_video_format.cc +++ b/third_party/libwebrtc/api/video_codecs/sdp_video_format.cc @@ -28,8 +28,7 @@ namespace webrtc { namespace { -std::string H264GetPacketizationModeOrDefault( - const SdpVideoFormat::Parameters& params) { +std::string H264GetPacketizationModeOrDefault(const CodecParameterMap& params) { constexpr char kH264FmtpPacketizationMode[] = "packetization-mode"; const auto it = params.find(kH264FmtpPacketizationMode); if (it != params.end()) { @@ -40,8 +39,8 @@ std::string H264GetPacketizationModeOrDefault( return "0"; } -bool H264IsSamePacketizationMode(const SdpVideoFormat::Parameters& left, - const SdpVideoFormat::Parameters& right) { +bool H264IsSamePacketizationMode(const CodecParameterMap& left, + const CodecParameterMap& right) { return H264GetPacketizationModeOrDefault(left) == H264GetPacketizationModeOrDefault(right); } @@ -77,12 +76,12 @@ bool IsSameCodecSpecific(const SdpVideoFormat& format1, SdpVideoFormat::SdpVideoFormat(const std::string& name) : name(name) {} SdpVideoFormat::SdpVideoFormat(const std::string& name, - const Parameters& parameters) + const CodecParameterMap& parameters) : name(name), parameters(parameters) {} SdpVideoFormat::SdpVideoFormat( const std::string& name, - const Parameters& parameters, + const CodecParameterMap& parameters, const absl::InlinedVector& scalability_modes) : name(name), diff --git a/third_party/libwebrtc/api/video_codecs/sdp_video_format.h b/third_party/libwebrtc/api/video_codecs/sdp_video_format.h index faaa66c241..af9537b5a3 100644 --- a/third_party/libwebrtc/api/video_codecs/sdp_video_format.h +++ b/third_party/libwebrtc/api/video_codecs/sdp_video_format.h @@ -17,6 +17,7 @@ #include "absl/container/inlined_vector.h" #include "absl/types/optional.h" #include "api/array_view.h" +#include "api/rtp_parameters.h" #include "api/video_codecs/scalability_mode.h" #include "rtc_base/system/rtc_export.h" @@ -25,13 +26,14 @@ namespace webrtc { // SDP specification for a single video codec. // NOTE: This class is still under development and may change without notice. struct RTC_EXPORT SdpVideoFormat { - using Parameters = std::map; + using Parameters [[deprecated(("Use webrtc::CodecParameterMap"))]] = + std::map; explicit SdpVideoFormat(const std::string& name); - SdpVideoFormat(const std::string& name, const Parameters& parameters); + SdpVideoFormat(const std::string& name, const CodecParameterMap& parameters); SdpVideoFormat( const std::string& name, - const Parameters& parameters, + const CodecParameterMap& parameters, const absl::InlinedVector& scalability_modes); SdpVideoFormat(const SdpVideoFormat&); @@ -58,7 +60,7 @@ struct RTC_EXPORT SdpVideoFormat { } std::string name; - Parameters parameters; + CodecParameterMap parameters; absl::InlinedVector scalability_modes; }; diff --git a/third_party/libwebrtc/api/video_codecs/test/h264_profile_level_id_unittest.cc b/third_party/libwebrtc/api/video_codecs/test/h264_profile_level_id_unittest.cc index 47098d2682..404d3e2cb3 100644 --- a/third_party/libwebrtc/api/video_codecs/test/h264_profile_level_id_unittest.cc +++ b/third_party/libwebrtc/api/video_codecs/test/h264_profile_level_id_unittest.cc @@ -145,7 +145,7 @@ TEST(H264ProfileLevelId, TestToStringInvalid) { TEST(H264ProfileLevelId, TestParseSdpProfileLevelIdEmpty) { const absl::optional profile_level_id = - ParseSdpForH264ProfileLevelId(SdpVideoFormat::Parameters()); + ParseSdpForH264ProfileLevelId(CodecParameterMap()); EXPECT_TRUE(profile_level_id); EXPECT_EQ(H264Profile::kProfileConstrainedBaseline, profile_level_id->profile); @@ -153,7 +153,7 @@ TEST(H264ProfileLevelId, TestParseSdpProfileLevelIdEmpty) { } TEST(H264ProfileLevelId, TestParseSdpProfileLevelIdConstrainedHigh) { - SdpVideoFormat::Parameters params; + CodecParameterMap params; params["profile-level-id"] = "640c2a"; const absl::optional profile_level_id = ParseSdpForH264ProfileLevelId(params); @@ -163,7 +163,7 @@ TEST(H264ProfileLevelId, TestParseSdpProfileLevelIdConstrainedHigh) { } TEST(H264ProfileLevelId, TestParseSdpProfileLevelIdInvalid) { - SdpVideoFormat::Parameters params; + CodecParameterMap params; params["profile-level-id"] = "foobar"; EXPECT_FALSE(ParseSdpForH264ProfileLevelId(params)); } diff --git a/third_party/libwebrtc/api/video_codecs/test/h265_profile_tier_level_unittest.cc b/third_party/libwebrtc/api/video_codecs/test/h265_profile_tier_level_unittest.cc index a9fdf966a5..85c0f09cd0 100644 --- a/third_party/libwebrtc/api/video_codecs/test/h265_profile_tier_level_unittest.cc +++ b/third_party/libwebrtc/api/video_codecs/test/h265_profile_tier_level_unittest.cc @@ -1,248 +1,248 @@ -/* - * Copyright (c) 2023 The WebRTC project authors. All Rights Reserved. - * - * Use of this source code is governed by a BSD-style license - * that can be found in the LICENSE file in the root of the source - * tree. An additional intellectual property rights grant can be found - * in the file PATENTS. All contributing project authors may - * be found in the AUTHORS file in the root of the source tree. - */ - -#include "api/video_codecs/h265_profile_tier_level.h" - -#include - -#include "absl/types/optional.h" -#include "test/gtest.h" - -namespace webrtc { - -TEST(H265ProfileTierLevel, TestLevelToString) { - EXPECT_EQ(H265LevelToString(H265Level::kLevel1), "30"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel2), "60"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel2_1), "63"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel3), "90"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel3_1), "93"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel4), "120"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel4_1), "123"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel5), "150"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel5_1), "153"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel5_2), "156"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel6), "180"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel6_1), "183"); - EXPECT_EQ(H265LevelToString(H265Level::kLevel6_2), "186"); -} - -TEST(H265ProfileTierLevel, TestProfileToString) { - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileMain), "1"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileMain10), "2"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileMainStill), "3"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileRangeExtensions), "4"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileHighThroughput), "5"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileMultiviewMain), "6"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileScalableMain), "7"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfile3dMain), "8"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileScreenContentCoding), "9"); - EXPECT_EQ(H265ProfileToString(H265Profile::kProfileScalableRangeExtensions), - "10"); - EXPECT_EQ(H265ProfileToString( - H265Profile::kProfileHighThroughputScreenContentCoding), - "11"); -} - -TEST(H265ProfileTierLevel, TestTierToString) { - EXPECT_EQ(H265TierToString(H265Tier::kTier0), "0"); - EXPECT_EQ(H265TierToString(H265Tier::kTier1), "1"); -} - -TEST(H265ProfileTierLevel, TestStringToProfile) { - // Invalid profiles. - EXPECT_FALSE(StringToH265Profile("0")); - EXPECT_FALSE(StringToH265Profile("12")); - - // Malformed profiles - EXPECT_FALSE(StringToH265Profile("")); - EXPECT_FALSE(StringToH265Profile(" 1")); - EXPECT_FALSE(StringToH265Profile("12x")); - EXPECT_FALSE(StringToH265Profile("x12")); - EXPECT_FALSE(StringToH265Profile("gggg")); - - // Valid profiles. - EXPECT_EQ(StringToH265Profile("1"), H265Profile::kProfileMain); - EXPECT_EQ(StringToH265Profile("2"), H265Profile::kProfileMain10); - EXPECT_EQ(StringToH265Profile("4"), H265Profile::kProfileRangeExtensions); -} - -TEST(H265ProfileTierLevel, TestStringToLevel) { - // Invalid levels. - EXPECT_FALSE(StringToH265Level("0")); - EXPECT_FALSE(StringToH265Level("200")); - - // Malformed levels. - EXPECT_FALSE(StringToH265Level("")); - EXPECT_FALSE(StringToH265Level(" 30")); - EXPECT_FALSE(StringToH265Level("30x")); - EXPECT_FALSE(StringToH265Level("x30")); - EXPECT_FALSE(StringToH265Level("ggggg")); - - // Valid levels. - EXPECT_EQ(StringToH265Level("30"), H265Level::kLevel1); - EXPECT_EQ(StringToH265Level("93"), H265Level::kLevel3_1); - EXPECT_EQ(StringToH265Level("183"), H265Level::kLevel6_1); -} - -TEST(H265ProfileTierLevel, TestStringToTier) { - // Invalid tiers. - EXPECT_FALSE(StringToH265Tier("4")); - EXPECT_FALSE(StringToH265Tier("-1")); - - // Malformed tiers. - EXPECT_FALSE(StringToH265Tier("")); - EXPECT_FALSE(StringToH265Tier(" 1")); - EXPECT_FALSE(StringToH265Tier("t1")); - - // Valid tiers. - EXPECT_EQ(StringToH265Tier("0"), H265Tier::kTier0); - EXPECT_EQ(StringToH265Tier("1"), H265Tier::kTier1); -} - -TEST(H265ProfileTierLevel, TestParseSdpProfileTierLevelAllEmpty) { - const absl::optional profile_tier_level = - ParseSdpForH265ProfileTierLevel(SdpVideoFormat::Parameters()); - EXPECT_TRUE(profile_tier_level); - EXPECT_EQ(H265Profile::kProfileMain, profile_tier_level->profile); - EXPECT_EQ(H265Level::kLevel3_1, profile_tier_level->level); - EXPECT_EQ(H265Tier::kTier0, profile_tier_level->tier); -} - -TEST(H265ProfileTierLevel, TestParseSdpProfileTierLevelPartialEmpty) { - SdpVideoFormat::Parameters params; - params["profile-id"] = "1"; - params["tier-flag"] = "0"; - absl::optional profile_tier_level = - ParseSdpForH265ProfileTierLevel(params); - EXPECT_TRUE(profile_tier_level); - EXPECT_EQ(H265Profile::kProfileMain, profile_tier_level->profile); - EXPECT_EQ(H265Level::kLevel3_1, profile_tier_level->level); - EXPECT_EQ(H265Tier::kTier0, profile_tier_level->tier); - - params.clear(); - params["profile-id"] = "2"; - profile_tier_level = ParseSdpForH265ProfileTierLevel(params); - EXPECT_TRUE(profile_tier_level); - EXPECT_EQ(H265Profile::kProfileMain10, profile_tier_level->profile); - EXPECT_EQ(H265Level::kLevel3_1, profile_tier_level->level); - EXPECT_EQ(H265Tier::kTier0, profile_tier_level->tier); - - params.clear(); - params["level-id"] = "180"; - profile_tier_level = ParseSdpForH265ProfileTierLevel(params); - EXPECT_TRUE(profile_tier_level); - EXPECT_EQ(H265Profile::kProfileMain, profile_tier_level->profile); - EXPECT_EQ(H265Level::kLevel6, profile_tier_level->level); - EXPECT_EQ(H265Tier::kTier0, profile_tier_level->tier); -} - -TEST(H265ProfileTierLevel, TestParseSdpProfileTierLevelInvalid) { - SdpVideoFormat::Parameters params; - - // Invalid profile-tier-level combination. - params["profile-id"] = "1"; - params["tier-flag"] = "1"; - params["level-id"] = "93"; - absl::optional profile_tier_level = - ParseSdpForH265ProfileTierLevel(params); - EXPECT_FALSE(profile_tier_level); - params.clear(); - params["profile-id"] = "1"; - params["tier-flag"] = "4"; - params["level-id"] = "180"; - profile_tier_level = ParseSdpForH265ProfileTierLevel(params); - EXPECT_FALSE(profile_tier_level); - - // Valid profile-tier-level combination. - params.clear(); - params["profile-id"] = "1"; - params["tier-flag"] = "0"; - params["level-id"] = "153"; - profile_tier_level = ParseSdpForH265ProfileTierLevel(params); - EXPECT_TRUE(profile_tier_level); -} - -TEST(H265ProfileTierLevel, TestToStringRoundTrip) { - SdpVideoFormat::Parameters params; - params["profile-id"] = "1"; - params["tier-flag"] = "0"; - params["level-id"] = "93"; - absl::optional profile_tier_level = - ParseSdpForH265ProfileTierLevel(params); - EXPECT_TRUE(profile_tier_level); - EXPECT_EQ("1", H265ProfileToString(profile_tier_level->profile)); - EXPECT_EQ("0", H265TierToString(profile_tier_level->tier)); - EXPECT_EQ("93", H265LevelToString(profile_tier_level->level)); - - params.clear(); - params["profile-id"] = "2"; - params["tier-flag"] = "1"; - params["level-id"] = "180"; - profile_tier_level = ParseSdpForH265ProfileTierLevel(params); - EXPECT_TRUE(profile_tier_level); - EXPECT_EQ("2", H265ProfileToString(profile_tier_level->profile)); - EXPECT_EQ("1", H265TierToString(profile_tier_level->tier)); - EXPECT_EQ("180", H265LevelToString(profile_tier_level->level)); -} - -TEST(H265ProfileTierLevel, TestProfileTierLevelCompare) { - SdpVideoFormat::Parameters params1; - SdpVideoFormat::Parameters params2; - - // None of profile-id/tier-flag/level-id is specified, - EXPECT_TRUE(H265IsSameProfileTierLevel(params1, params2)); - - // Same non-empty PTL - params1["profile-id"] = "1"; - params1["tier-flag"] = "0"; - params1["level-id"] = "120"; - params2["profile-id"] = "1"; - params2["tier-flag"] = "0"; - params2["level-id"] = "120"; - EXPECT_TRUE(H265IsSameProfileTierLevel(params1, params2)); - - // Different profiles. - params1.clear(); - params2.clear(); - params1["profile-id"] = "1"; - params2["profile-id"] = "2"; - EXPECT_FALSE(H265IsSameProfileTierLevel(params1, params2)); - - // Different levels. - params1.clear(); - params2.clear(); - params1["profile-id"] = "1"; - params2["profile-id"] = "1"; - params1["level-id"] = "93"; - params2["level-id"] = "183"; - EXPECT_FALSE(H265IsSameProfileTierLevel(params1, params2)); - - // Different tiers. - params1.clear(); - params2.clear(); - params1["profile-id"] = "1"; - params2["profile-id"] = "1"; - params1["level-id"] = "93"; - params2["level-id"] = "93"; - params1["tier-flag"] = "0"; - params2["tier-flag"] = "1"; - EXPECT_FALSE(H265IsSameProfileTierLevel(params1, params2)); - - // One of the SdpVideoFormat::Parameters is invalid. - params1.clear(); - params2.clear(); - params1["profile-id"] = "1"; - params2["profile-id"] = "1"; - params1["tier-flag"] = "0"; - params2["tier-flag"] = "4"; - EXPECT_FALSE(H265IsSameProfileTierLevel(params1, params2)); -} - -} // namespace webrtc +/* + * Copyright (c) 2023 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#include "api/video_codecs/h265_profile_tier_level.h" + +#include + +#include "absl/types/optional.h" +#include "test/gtest.h" + +namespace webrtc { + +TEST(H265ProfileTierLevel, TestLevelToString) { + EXPECT_EQ(H265LevelToString(H265Level::kLevel1), "30"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel2), "60"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel2_1), "63"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel3), "90"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel3_1), "93"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel4), "120"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel4_1), "123"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel5), "150"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel5_1), "153"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel5_2), "156"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel6), "180"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel6_1), "183"); + EXPECT_EQ(H265LevelToString(H265Level::kLevel6_2), "186"); +} + +TEST(H265ProfileTierLevel, TestProfileToString) { + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileMain), "1"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileMain10), "2"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileMainStill), "3"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileRangeExtensions), "4"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileHighThroughput), "5"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileMultiviewMain), "6"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileScalableMain), "7"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfile3dMain), "8"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileScreenContentCoding), "9"); + EXPECT_EQ(H265ProfileToString(H265Profile::kProfileScalableRangeExtensions), + "10"); + EXPECT_EQ(H265ProfileToString( + H265Profile::kProfileHighThroughputScreenContentCoding), + "11"); +} + +TEST(H265ProfileTierLevel, TestTierToString) { + EXPECT_EQ(H265TierToString(H265Tier::kTier0), "0"); + EXPECT_EQ(H265TierToString(H265Tier::kTier1), "1"); +} + +TEST(H265ProfileTierLevel, TestStringToProfile) { + // Invalid profiles. + EXPECT_FALSE(StringToH265Profile("0")); + EXPECT_FALSE(StringToH265Profile("12")); + + // Malformed profiles + EXPECT_FALSE(StringToH265Profile("")); + EXPECT_FALSE(StringToH265Profile(" 1")); + EXPECT_FALSE(StringToH265Profile("12x")); + EXPECT_FALSE(StringToH265Profile("x12")); + EXPECT_FALSE(StringToH265Profile("gggg")); + + // Valid profiles. + EXPECT_EQ(StringToH265Profile("1"), H265Profile::kProfileMain); + EXPECT_EQ(StringToH265Profile("2"), H265Profile::kProfileMain10); + EXPECT_EQ(StringToH265Profile("4"), H265Profile::kProfileRangeExtensions); +} + +TEST(H265ProfileTierLevel, TestStringToLevel) { + // Invalid levels. + EXPECT_FALSE(StringToH265Level("0")); + EXPECT_FALSE(StringToH265Level("200")); + + // Malformed levels. + EXPECT_FALSE(StringToH265Level("")); + EXPECT_FALSE(StringToH265Level(" 30")); + EXPECT_FALSE(StringToH265Level("30x")); + EXPECT_FALSE(StringToH265Level("x30")); + EXPECT_FALSE(StringToH265Level("ggggg")); + + // Valid levels. + EXPECT_EQ(StringToH265Level("30"), H265Level::kLevel1); + EXPECT_EQ(StringToH265Level("93"), H265Level::kLevel3_1); + EXPECT_EQ(StringToH265Level("183"), H265Level::kLevel6_1); +} + +TEST(H265ProfileTierLevel, TestStringToTier) { + // Invalid tiers. + EXPECT_FALSE(StringToH265Tier("4")); + EXPECT_FALSE(StringToH265Tier("-1")); + + // Malformed tiers. + EXPECT_FALSE(StringToH265Tier("")); + EXPECT_FALSE(StringToH265Tier(" 1")); + EXPECT_FALSE(StringToH265Tier("t1")); + + // Valid tiers. + EXPECT_EQ(StringToH265Tier("0"), H265Tier::kTier0); + EXPECT_EQ(StringToH265Tier("1"), H265Tier::kTier1); +} + +TEST(H265ProfileTierLevel, TestParseSdpProfileTierLevelAllEmpty) { + const absl::optional profile_tier_level = + ParseSdpForH265ProfileTierLevel(CodecParameterMap()); + EXPECT_TRUE(profile_tier_level); + EXPECT_EQ(H265Profile::kProfileMain, profile_tier_level->profile); + EXPECT_EQ(H265Level::kLevel3_1, profile_tier_level->level); + EXPECT_EQ(H265Tier::kTier0, profile_tier_level->tier); +} + +TEST(H265ProfileTierLevel, TestParseSdpProfileTierLevelPartialEmpty) { + CodecParameterMap params; + params["profile-id"] = "1"; + params["tier-flag"] = "0"; + absl::optional profile_tier_level = + ParseSdpForH265ProfileTierLevel(params); + EXPECT_TRUE(profile_tier_level); + EXPECT_EQ(H265Profile::kProfileMain, profile_tier_level->profile); + EXPECT_EQ(H265Level::kLevel3_1, profile_tier_level->level); + EXPECT_EQ(H265Tier::kTier0, profile_tier_level->tier); + + params.clear(); + params["profile-id"] = "2"; + profile_tier_level = ParseSdpForH265ProfileTierLevel(params); + EXPECT_TRUE(profile_tier_level); + EXPECT_EQ(H265Profile::kProfileMain10, profile_tier_level->profile); + EXPECT_EQ(H265Level::kLevel3_1, profile_tier_level->level); + EXPECT_EQ(H265Tier::kTier0, profile_tier_level->tier); + + params.clear(); + params["level-id"] = "180"; + profile_tier_level = ParseSdpForH265ProfileTierLevel(params); + EXPECT_TRUE(profile_tier_level); + EXPECT_EQ(H265Profile::kProfileMain, profile_tier_level->profile); + EXPECT_EQ(H265Level::kLevel6, profile_tier_level->level); + EXPECT_EQ(H265Tier::kTier0, profile_tier_level->tier); +} + +TEST(H265ProfileTierLevel, TestParseSdpProfileTierLevelInvalid) { + CodecParameterMap params; + + // Invalid profile-tier-level combination. + params["profile-id"] = "1"; + params["tier-flag"] = "1"; + params["level-id"] = "93"; + absl::optional profile_tier_level = + ParseSdpForH265ProfileTierLevel(params); + EXPECT_FALSE(profile_tier_level); + params.clear(); + params["profile-id"] = "1"; + params["tier-flag"] = "4"; + params["level-id"] = "180"; + profile_tier_level = ParseSdpForH265ProfileTierLevel(params); + EXPECT_FALSE(profile_tier_level); + + // Valid profile-tier-level combination. + params.clear(); + params["profile-id"] = "1"; + params["tier-flag"] = "0"; + params["level-id"] = "153"; + profile_tier_level = ParseSdpForH265ProfileTierLevel(params); + EXPECT_TRUE(profile_tier_level); +} + +TEST(H265ProfileTierLevel, TestToStringRoundTrip) { + CodecParameterMap params; + params["profile-id"] = "1"; + params["tier-flag"] = "0"; + params["level-id"] = "93"; + absl::optional profile_tier_level = + ParseSdpForH265ProfileTierLevel(params); + EXPECT_TRUE(profile_tier_level); + EXPECT_EQ("1", H265ProfileToString(profile_tier_level->profile)); + EXPECT_EQ("0", H265TierToString(profile_tier_level->tier)); + EXPECT_EQ("93", H265LevelToString(profile_tier_level->level)); + + params.clear(); + params["profile-id"] = "2"; + params["tier-flag"] = "1"; + params["level-id"] = "180"; + profile_tier_level = ParseSdpForH265ProfileTierLevel(params); + EXPECT_TRUE(profile_tier_level); + EXPECT_EQ("2", H265ProfileToString(profile_tier_level->profile)); + EXPECT_EQ("1", H265TierToString(profile_tier_level->tier)); + EXPECT_EQ("180", H265LevelToString(profile_tier_level->level)); +} + +TEST(H265ProfileTierLevel, TestProfileTierLevelCompare) { + CodecParameterMap params1; + CodecParameterMap params2; + + // None of profile-id/tier-flag/level-id is specified, + EXPECT_TRUE(H265IsSameProfileTierLevel(params1, params2)); + + // Same non-empty PTL + params1["profile-id"] = "1"; + params1["tier-flag"] = "0"; + params1["level-id"] = "120"; + params2["profile-id"] = "1"; + params2["tier-flag"] = "0"; + params2["level-id"] = "120"; + EXPECT_TRUE(H265IsSameProfileTierLevel(params1, params2)); + + // Different profiles. + params1.clear(); + params2.clear(); + params1["profile-id"] = "1"; + params2["profile-id"] = "2"; + EXPECT_FALSE(H265IsSameProfileTierLevel(params1, params2)); + + // Different levels. + params1.clear(); + params2.clear(); + params1["profile-id"] = "1"; + params2["profile-id"] = "1"; + params1["level-id"] = "93"; + params2["level-id"] = "183"; + EXPECT_FALSE(H265IsSameProfileTierLevel(params1, params2)); + + // Different tiers. + params1.clear(); + params2.clear(); + params1["profile-id"] = "1"; + params2["profile-id"] = "1"; + params1["level-id"] = "93"; + params2["level-id"] = "93"; + params1["tier-flag"] = "0"; + params2["tier-flag"] = "1"; + EXPECT_FALSE(H265IsSameProfileTierLevel(params1, params2)); + + // One of the CodecParameterMap is invalid. + params1.clear(); + params2.clear(); + params1["profile-id"] = "1"; + params2["profile-id"] = "1"; + params1["tier-flag"] = "0"; + params2["tier-flag"] = "4"; + EXPECT_FALSE(H265IsSameProfileTierLevel(params1, params2)); +} + +} // namespace webrtc diff --git a/third_party/libwebrtc/api/video_codecs/test/sdp_video_format_unittest.cc b/third_party/libwebrtc/api/video_codecs/test/sdp_video_format_unittest.cc index 797a9a2e72..26e50d6945 100644 --- a/third_party/libwebrtc/api/video_codecs/test/sdp_video_format_unittest.cc +++ b/third_party/libwebrtc/api/video_codecs/test/sdp_video_format_unittest.cc @@ -18,7 +18,7 @@ namespace webrtc { typedef SdpVideoFormat Sdp; -typedef SdpVideoFormat::Parameters Params; +typedef CodecParameterMap Params; TEST(SdpVideoFormatTest, SameCodecNameNoParameters) { EXPECT_TRUE(Sdp("H264").IsSameCodec(Sdp("h264"))); diff --git a/third_party/libwebrtc/api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h b/third_party/libwebrtc/api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h index 417df1e192..0f801ad3c7 100644 --- a/third_party/libwebrtc/api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h +++ b/third_party/libwebrtc/api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h @@ -24,8 +24,7 @@ struct LibaomAv1EncoderTemplateAdapter { static std::vector SupportedFormats() { absl::InlinedVector scalability_modes = LibaomAv1EncoderSupportedScalabilityModes(); - return { - SdpVideoFormat("AV1", SdpVideoFormat::Parameters(), scalability_modes)}; + return {SdpVideoFormat("AV1", CodecParameterMap(), scalability_modes)}; } static std::unique_ptr CreateEncoder( diff --git a/third_party/libwebrtc/api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h b/third_party/libwebrtc/api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h index 0f0a9bacd5..c60aa04795 100644 --- a/third_party/libwebrtc/api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h +++ b/third_party/libwebrtc/api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h @@ -28,8 +28,7 @@ struct LibvpxVp8EncoderTemplateAdapter { scalability_modes.push_back(scalability_mode); } - return { - SdpVideoFormat("VP8", SdpVideoFormat::Parameters(), scalability_modes)}; + return {SdpVideoFormat("VP8", CodecParameterMap(), scalability_modes)}; } static std::unique_ptr CreateEncoder( diff --git a/third_party/libwebrtc/api/video_codecs/vp9_profile.cc b/third_party/libwebrtc/api/video_codecs/vp9_profile.cc index 7e627cc080..ccd3937296 100644 --- a/third_party/libwebrtc/api/video_codecs/vp9_profile.cc +++ b/third_party/libwebrtc/api/video_codecs/vp9_profile.cc @@ -54,7 +54,7 @@ absl::optional StringToVP9Profile(const std::string& str) { } absl::optional ParseSdpForVP9Profile( - const SdpVideoFormat::Parameters& params) { + const CodecParameterMap& params) { const auto profile_it = params.find(kVP9FmtpProfileId); if (profile_it == params.end()) return VP9Profile::kProfile0; @@ -62,8 +62,8 @@ absl::optional ParseSdpForVP9Profile( return StringToVP9Profile(profile_str); } -bool VP9IsSameProfile(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2) { +bool VP9IsSameProfile(const CodecParameterMap& params1, + const CodecParameterMap& params2) { const absl::optional profile = ParseSdpForVP9Profile(params1); const absl::optional other_profile = ParseSdpForVP9Profile(params2); diff --git a/third_party/libwebrtc/api/video_codecs/vp9_profile.h b/third_party/libwebrtc/api/video_codecs/vp9_profile.h index b570bc3bb6..27f84cbecc 100644 --- a/third_party/libwebrtc/api/video_codecs/vp9_profile.h +++ b/third_party/libwebrtc/api/video_codecs/vp9_profile.h @@ -42,12 +42,12 @@ absl::optional StringToVP9Profile(const std::string& str); // profile key is missing. Nothing will be returned if the key is present but // the string is invalid. RTC_EXPORT absl::optional ParseSdpForVP9Profile( - const SdpVideoFormat::Parameters& params); + const CodecParameterMap& params); // Returns true if the parameters have the same VP9 profile, or neither contains // VP9 profile. -bool VP9IsSameProfile(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2); +bool VP9IsSameProfile(const CodecParameterMap& params1, + const CodecParameterMap& params2); } // namespace webrtc -- cgit v1.2.3