From 3cd7a0ffddc4cbc706bd0f5fbefb7b044e05f448 Mon Sep 17 00:00:00 2001 From: Johannes Kron Date: Thu, 19 Aug 2021 12:13:06 +0200 Subject: [PATCH] Remove media/base/h264_profile_level_id.* and media/base/vp9_profile.h The content of these files was moved to api/video_codecs in https://webrtc.googlesource.com/src.git/+/c3fcee7c3a7714afc3e37d4753b40f4fdbc3653e but the original files could not be removed due to dependencies in downstream projects. Bug: chromium:1187565 Change-Id: I414efa22102bfdea0765fa72a8cf8b0bd5c090db Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/229303 Reviewed-by: Harald Alvestrand Commit-Queue: Johannes Kron Cr-Commit-Position: refs/heads/main@{#34869} --- api/BUILD.gn | 1 - api/test/videocodec_test_fixture.h | 2 +- api/video_codecs/test/BUILD.gn | 1 + .../test/sdp_video_format_unittest.cc | 15 +++ media/BUILD.gn | 19 ---- media/base/codec.cc | 17 +--- media/base/codec.h | 4 - media/base/codec_unittest.cc | 91 ------------------- media/base/h264_profile_level_id.cc | 43 --------- media/base/h264_profile_level_id.h | 85 ----------------- media/base/vp9_profile.h | 19 ---- media/engine/fake_webrtc_video_engine.cc | 20 +--- modules/video_coding/BUILD.gn | 1 - .../video_coding/codecs/h264/include/h264.h | 2 +- sdk/BUILD.gn | 1 - 15 files changed, 25 insertions(+), 296 deletions(-) delete mode 100644 media/base/h264_profile_level_id.cc delete mode 100644 media/base/h264_profile_level_id.h delete mode 100644 media/base/vp9_profile.h diff --git a/api/BUILD.gn b/api/BUILD.gn index 00ac4a1878..89f2b15f05 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -802,7 +802,6 @@ if (rtc_include_tests) { "test/videocodec_test_stats.h", ] deps = [ - "../media:rtc_h264_profile_id", "../modules/video_coding:video_codec_interface", "../rtc_base:stringutils", "video:video_frame_type", diff --git a/api/test/videocodec_test_fixture.h b/api/test/videocodec_test_fixture.h index e0f804fe46..c9b9ed4087 100644 --- a/api/test/videocodec_test_fixture.h +++ b/api/test/videocodec_test_fixture.h @@ -15,9 +15,9 @@ #include #include "api/test/videocodec_test_stats.h" +#include "api/video_codecs/h264_profile_level_id.h" #include "api/video_codecs/video_decoder_factory.h" #include "api/video_codecs/video_encoder_factory.h" -#include "media/base/h264_profile_level_id.h" #include "modules/video_coding/include/video_codec_interface.h" namespace webrtc { diff --git a/api/video_codecs/test/BUILD.gn b/api/video_codecs/test/BUILD.gn index c082dbc562..14b54a1f99 100644 --- a/api/video_codecs/test/BUILD.gn +++ b/api/video_codecs/test/BUILD.gn @@ -26,6 +26,7 @@ if (rtc_include_tests) { "../..:fec_controller_api", "../..:mock_video_encoder", "../../../api:scoped_refptr", + "../../../media:rtc_media_base", "../../../modules/video_coding:video_codec_interface", "../../../modules/video_coding:video_coding_utility", "../../../modules/video_coding:webrtc_vp8", diff --git a/api/video_codecs/test/sdp_video_format_unittest.cc b/api/video_codecs/test/sdp_video_format_unittest.cc index d55816690e..6334b8ad67 100644 --- a/api/video_codecs/test/sdp_video_format_unittest.cc +++ b/api/video_codecs/test/sdp_video_format_unittest.cc @@ -12,6 +12,7 @@ #include +#include "media/base/media_constants.h" #include "test/gtest.h" namespace webrtc { @@ -25,11 +26,13 @@ TEST(SdpVideoFormatTest, SameCodecNameNoParameters) { EXPECT_TRUE(Sdp("Vp9").IsSameCodec(Sdp("vp9"))); EXPECT_TRUE(Sdp("AV1").IsSameCodec(Sdp("Av1"))); } + TEST(SdpVideoFormatTest, DifferentCodecNameNoParameters) { EXPECT_FALSE(Sdp("H264").IsSameCodec(Sdp("VP8"))); EXPECT_FALSE(Sdp("VP8").IsSameCodec(Sdp("VP9"))); EXPECT_FALSE(Sdp("AV1").IsSameCodec(Sdp(""))); } + TEST(SdpVideoFormatTest, SameCodecNameSameParameters) { EXPECT_TRUE(Sdp("VP9").IsSameCodec(Sdp("VP9", Params{{"profile-id", "0"}}))); EXPECT_TRUE(Sdp("VP9", Params{{"profile-id", "0"}}) @@ -71,4 +74,16 @@ TEST(SdpVideoFormatTest, DifferentCodecNameSameParameters) { .IsSameCodec(Sdp("VP8", Params{{"profile-level-id", "640c34"}}))); } +TEST(SdpVideoFormatTest, H264PacketizationMode) { + // The default packetization mode is 0. + EXPECT_TRUE(Sdp("H264", Params{{cricket::kH264FmtpPacketizationMode, "0"}}) + .IsSameCodec(Sdp("H264"))); + EXPECT_FALSE(Sdp("H264", Params{{cricket::kH264FmtpPacketizationMode, "1"}}) + .IsSameCodec(Sdp("H264"))); + + EXPECT_TRUE( + Sdp("H264", Params{{cricket::kH264FmtpPacketizationMode, "1"}}) + .IsSameCodec( + Sdp("H264", Params{{cricket::kH264FmtpPacketizationMode, "1"}}))); +} } // namespace webrtc diff --git a/media/BUILD.gn b/media/BUILD.gn index 7dbd9174cc..acfa09f039 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -23,30 +23,11 @@ config("rtc_media_defines_config") { defines = [ "HAVE_WEBRTC_VIDEO" ] } -# Remove once downstream projects stop depend on this. -rtc_source_set("rtc_h264_profile_id") { - visibility = [ "*" ] - sources = [ - "base/h264_profile_level_id.cc", - "base/h264_profile_level_id.h", - ] - public_deps = # no-presubmit-check TODO(webrtc:8603) - [ "../api/video_codecs:video_codecs_api" ] -} - rtc_source_set("rtc_media_config") { visibility = [ "*" ] sources = [ "base/media_config.h" ] } -# Remove once downstream projects stop depend on this. -rtc_source_set("rtc_vp9_profile") { - visibility = [ "*" ] - sources = [ "base/vp9_profile.h" ] - public_deps = # no-presubmit-check TODO(webrtc:8603) - [ "../api/video_codecs:video_codecs_api" ] -} - rtc_library("rtc_sdp_video_format_utils") { visibility = [ "*" ] sources = [ diff --git a/media/base/codec.cc b/media/base/codec.cc index a116184f0c..9b09f5e73b 100644 --- a/media/base/codec.cc +++ b/media/base/codec.cc @@ -412,27 +412,16 @@ bool HasTransportCc(const Codec& codec) { const VideoCodec* FindMatchingCodec( const std::vector& supported_codecs, const VideoCodec& codec) { + webrtc::SdpVideoFormat sdp_video_format{codec.name, codec.params}; for (const VideoCodec& supported_codec : supported_codecs) { - if (IsSameCodec(codec.name, codec.params, supported_codec.name, - supported_codec.params)) { + if (sdp_video_format.IsSameCodec( + {supported_codec.name, supported_codec.params})) { return &supported_codec; } } return nullptr; } -// TODO(crbug.com/1187565): Remove once downstream projects stopped using this -// method in favor of SdpVideoFormat::IsSameCodec(). -bool IsSameCodec(const std::string& name1, - const CodecParameterMap& params1, - const std::string& name2, - const CodecParameterMap& params2) { - // Two codecs are considered the same if the name matches (case insensitive) - // and certain codec-specific parameters match. - return absl::EqualsIgnoreCase(name1, name2) && - IsSameCodecSpecific(name1, params1, name2, params2); -} - // If a decoder supports any H264 profile, it is implicitly assumed to also // support constrained base line even though it's not explicitly listed. void AddH264ConstrainedBaselineProfileToSupportedFormats( diff --git a/media/base/codec.h b/media/base/codec.h index 29c54a8b8a..cfc31aed1f 100644 --- a/media/base/codec.h +++ b/media/base/codec.h @@ -223,10 +223,6 @@ bool HasTransportCc(const Codec& codec); const VideoCodec* FindMatchingCodec( const std::vector& supported_codecs, const VideoCodec& codec); -RTC_EXPORT bool IsSameCodec(const std::string& name1, - const CodecParameterMap& params1, - const std::string& name2, - const CodecParameterMap& params2); RTC_EXPORT void AddH264ConstrainedBaselineProfileToSupportedFormats( std::vector* supported_formats); diff --git a/media/base/codec_unittest.cc b/media/base/codec_unittest.cc index 23bae7b7fe..c5aa5bf186 100644 --- a/media/base/codec_unittest.cc +++ b/media/base/codec_unittest.cc @@ -496,94 +496,3 @@ TEST(CodecTest, H264CostrainedBaselineNotAddedIfAlreadySpecified) { EXPECT_EQ(supported_formats[3], kExplicitlySupportedFormats[3]); EXPECT_EQ(supported_formats.size(), kExplicitlySupportedFormats.size()); } - -// Tests that the helper IsSameCodec returns the correct value for codecs that -// must also be matched on particular parameter values. -using IsSameCodecParamsTestCase = - std::tuple; -class IsSameCodecParamsTest - : public ::testing::TestWithParam< - std::tuple> { - protected: - IsSameCodecParamsTest() { - name_ = std::get<0>(GetParam()); - expected_ = std::get<1>(GetParam()); - const auto& test_case = std::get<2>(GetParam()); - params_left_ = std::get<0>(test_case); - params_right_ = std::get<1>(test_case); - } - - std::string name_; - bool expected_; - cricket::CodecParameterMap params_left_; - cricket::CodecParameterMap params_right_; -}; - -TEST_P(IsSameCodecParamsTest, Expected) { - EXPECT_EQ(expected_, - cricket::IsSameCodec(name_, params_left_, name_, params_right_)); -} - -TEST_P(IsSameCodecParamsTest, Commutative) { - EXPECT_EQ(expected_, - cricket::IsSameCodec(name_, params_right_, name_, params_left_)); -} - -IsSameCodecParamsTestCase MakeTestCase(cricket::CodecParameterMap left, - cricket::CodecParameterMap right) { - return std::make_tuple(left, right); -} - -const IsSameCodecParamsTestCase kH264ParamsSameTestCases[] = { - // Both have the same defaults. - MakeTestCase({}, {}), - // packetization-mode: 0 is the default. - MakeTestCase({{cricket::kH264FmtpPacketizationMode, "0"}}, {}), - // Non-default packetization-mode matches. - MakeTestCase({{cricket::kH264FmtpPacketizationMode, "1"}}, - {{cricket::kH264FmtpPacketizationMode, "1"}}), -}; -INSTANTIATE_TEST_SUITE_P( - H264_Same, - IsSameCodecParamsTest, - ::testing::Combine(::testing::Values("H264"), - ::testing::Values(true), - ::testing::ValuesIn(kH264ParamsSameTestCases))); - -const IsSameCodecParamsTestCase kH264ParamsNotSameTestCases[] = { - // packetization-mode does not match the default of "0". - MakeTestCase({{cricket::kH264FmtpPacketizationMode, "1"}}, {}), -}; -INSTANTIATE_TEST_SUITE_P( - H264_NotSame, - IsSameCodecParamsTest, - ::testing::Combine(::testing::Values("H264"), - ::testing::Values(false), - ::testing::ValuesIn(kH264ParamsNotSameTestCases))); - -const IsSameCodecParamsTestCase kVP9ParamsSameTestCases[] = { - // Both have the same defaults. - MakeTestCase({}, {}), - // profile-id: 0 is the default. - MakeTestCase({{webrtc::kVP9FmtpProfileId, "0"}}, {}), - // Non-default profile-id matches. - MakeTestCase({{webrtc::kVP9FmtpProfileId, "2"}}, - {{webrtc::kVP9FmtpProfileId, "2"}}), -}; -INSTANTIATE_TEST_SUITE_P( - VP9_Same, - IsSameCodecParamsTest, - ::testing::Combine(::testing::Values("VP9"), - ::testing::Values(true), - ::testing::ValuesIn(kVP9ParamsSameTestCases))); - -const IsSameCodecParamsTestCase kVP9ParamsNotSameTestCases[] = { - // profile-id missing from right. - MakeTestCase({{webrtc::kVP9FmtpProfileId, "2"}}, {}), -}; -INSTANTIATE_TEST_SUITE_P( - VP9_NotSame, - IsSameCodecParamsTest, - ::testing::Combine(::testing::Values("VP9"), - ::testing::Values(false), - ::testing::ValuesIn(kVP9ParamsNotSameTestCases))); diff --git a/media/base/h264_profile_level_id.cc b/media/base/h264_profile_level_id.cc deleted file mode 100644 index 6f9fa46694..0000000000 --- a/media/base/h264_profile_level_id.cc +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017 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 "media/base/h264_profile_level_id.h" - -// TODO(crbug.com/1187565): Remove this file once downstream projects stop -// depend on it. - -namespace webrtc { -namespace H264 { - -absl::optional ParseProfileLevelId(const char* str) { - return webrtc::ParseH264ProfileLevelId(str); -} - -absl::optional ParseSdpProfileLevelId( - const SdpVideoFormat::Parameters& params) { - return webrtc::ParseSdpForH264ProfileLevelId(params); -} - -absl::optional SupportedLevel(int max_frame_pixel_count, float max_fps) { - return webrtc::H264SupportedLevel(max_frame_pixel_count, max_fps); -} - -absl::optional ProfileLevelIdToString( - const ProfileLevelId& profile_level_id) { - return webrtc::H264ProfileLevelIdToString(profile_level_id); -} - -bool IsSameH264Profile(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2) { - return webrtc::H264IsSameProfile(params1, params2); -} - -} // namespace H264 -} // namespace webrtc diff --git a/media/base/h264_profile_level_id.h b/media/base/h264_profile_level_id.h deleted file mode 100644 index c85709faa9..0000000000 --- a/media/base/h264_profile_level_id.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2017 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 MEDIA_BASE_H264_PROFILE_LEVEL_ID_H_ -#define MEDIA_BASE_H264_PROFILE_LEVEL_ID_H_ - -#include - -#include "api/video_codecs/h264_profile_level_id.h" - -// TODO(crbug.com/1187565): Remove this file once downstream projects stop -// depend on it. - -namespace webrtc { -namespace H264 { - -typedef H264Profile Profile; -typedef H264Level Level; -typedef H264ProfileLevelId ProfileLevelId; - -constexpr H264Profile kProfileConstrainedBaseline = - H264Profile::kProfileConstrainedBaseline; -constexpr H264Profile kProfileBaseline = H264Profile::kProfileBaseline; -constexpr H264Profile kProfileMain = H264Profile::kProfileMain; -constexpr H264Profile kProfileConstrainedHigh = - H264Profile::kProfileConstrainedHigh; -constexpr H264Profile kProfileHigh = H264Profile::kProfileHigh; - -constexpr H264Level kLevel1_b = H264Level::kLevel1_b; -constexpr H264Level kLevel1 = H264Level::kLevel1; -constexpr H264Level kLevel1_1 = H264Level::kLevel1_1; -constexpr H264Level kLevel1_2 = H264Level::kLevel1_2; -constexpr H264Level kLevel1_3 = H264Level::kLevel1_3; -constexpr H264Level kLevel2 = H264Level::kLevel2; -constexpr H264Level kLevel2_1 = H264Level::kLevel2_1; -constexpr H264Level kLevel2_2 = H264Level::kLevel2_2; -constexpr H264Level kLevel3 = H264Level::kLevel3; -constexpr H264Level kLevel3_1 = H264Level::kLevel3_1; -constexpr H264Level kLevel3_2 = H264Level::kLevel3_2; -constexpr H264Level kLevel4 = H264Level::kLevel4; -constexpr H264Level kLevel4_1 = H264Level::kLevel4_1; -constexpr H264Level kLevel4_2 = H264Level::kLevel4_2; -constexpr H264Level kLevel5 = H264Level::kLevel5; -constexpr H264Level kLevel5_1 = H264Level::kLevel5_1; -constexpr H264Level kLevel5_2 = H264Level::kLevel5_2; - -// Parse profile level id that is represented as a string of 3 hex bytes. -// Nothing will be returned if the string is not a recognized H264 -// profile level id. -absl::optional ParseProfileLevelId(const char* str); - -// Parse profile level id that is represented as a string of 3 hex bytes -// contained in an SDP key-value map. A default profile level id will be -// 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 ParseSdpProfileLevelId( - const SdpVideoFormat::Parameters& 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 -// can guarantee that it will be able to support all valid encoded streams that -// are within that level. -RTC_EXPORT absl::optional SupportedLevel(int max_frame_pixel_count, - float max_fps); - -// Returns canonical string representation as three hex bytes of the profile -// level id, or returns nothing for invalid profile level ids. -RTC_EXPORT absl::optional ProfileLevelIdToString( - const ProfileLevelId& profile_level_id); - -// Returns true if the parameters have the same H264 profile, i.e. the same -// H264::Profile (Baseline, High, etc). -RTC_EXPORT bool IsSameH264Profile(const SdpVideoFormat::Parameters& params1, - const SdpVideoFormat::Parameters& params2); - -} // namespace H264 -} // namespace webrtc -#endif // MEDIA_BASE_H264_PROFILE_LEVEL_ID_H_ diff --git a/media/base/vp9_profile.h b/media/base/vp9_profile.h deleted file mode 100644 index d44a7998d2..0000000000 --- a/media/base/vp9_profile.h +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2018 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 MEDIA_BASE_VP9_PROFILE_H_ -#define MEDIA_BASE_VP9_PROFILE_H_ - -#include "api/video_codecs/vp9_profile.h" - -// TODO(crbug.com/1187565): Remove this file once downstream projects stop -// depend on it. - -#endif // MEDIA_BASE_VP9_PROFILE_H_ diff --git a/media/engine/fake_webrtc_video_engine.cc b/media/engine/fake_webrtc_video_engine.cc index 35b631589e..6b042f7981 100644 --- a/media/engine/fake_webrtc_video_engine.cc +++ b/media/engine/fake_webrtc_video_engine.cc @@ -26,18 +26,6 @@ namespace { static const int kEventTimeoutMs = 10000; -bool IsFormatSupported( - const std::vector& supported_formats, - const webrtc::SdpVideoFormat& format) { - for (const webrtc::SdpVideoFormat& supported_format : supported_formats) { - if (IsSameCodec(format.name, format.parameters, supported_format.name, - supported_format.parameters)) { - return true; - } - } - return false; -} - } // namespace // Decoder. @@ -85,7 +73,7 @@ FakeWebRtcVideoDecoderFactory::GetSupportedFormats() const { for (const webrtc::SdpVideoFormat& format : supported_codec_formats_) { // Don't add same codec twice. - if (!IsFormatSupported(formats, format)) + if (!format.IsCodecInList(formats)) formats.push_back(format); } @@ -95,7 +83,7 @@ FakeWebRtcVideoDecoderFactory::GetSupportedFormats() const { std::unique_ptr FakeWebRtcVideoDecoderFactory::CreateVideoDecoder( const webrtc::SdpVideoFormat& format) { - if (IsFormatSupported(supported_codec_formats_, format)) { + if (format.IsCodecInList(supported_codec_formats_)) { num_created_decoders_++; std::unique_ptr decoder = std::make_unique(this); @@ -209,7 +197,7 @@ FakeWebRtcVideoEncoderFactory::GetSupportedFormats() const { for (const webrtc::SdpVideoFormat& format : formats_) { // Don't add same codec twice. - if (!IsFormatSupported(formats, format)) + if (!format.IsCodecInList(formats)) formats.push_back(format); } @@ -221,7 +209,7 @@ FakeWebRtcVideoEncoderFactory::CreateVideoEncoder( const webrtc::SdpVideoFormat& format) { webrtc::MutexLock lock(&mutex_); std::unique_ptr encoder; - if (IsFormatSupported(formats_, format)) { + if (format.IsCodecInList(formats_)) { if (absl::EqualsIgnoreCase(format.name, kVp8CodecName) && !vp8_factory_mode_) { // The simulcast adapter will ask this factory for multiple VP8 diff --git a/modules/video_coding/BUILD.gn b/modules/video_coding/BUILD.gn index 9a438c6b7c..b6496b29ae 100644 --- a/modules/video_coding/BUILD.gn +++ b/modules/video_coding/BUILD.gn @@ -401,7 +401,6 @@ rtc_library("webrtc_h264") { "../../api/video:video_rtp_headers", "../../api/video_codecs:video_codecs_api", "../../common_video", - "../../media:rtc_h264_profile_id", "../../media:rtc_media_base", "../../rtc_base", "../../rtc_base:checks", diff --git a/modules/video_coding/codecs/h264/include/h264.h b/modules/video_coding/codecs/h264/include/h264.h index bd859d69ef..bffd31cf8d 100644 --- a/modules/video_coding/codecs/h264/include/h264.h +++ b/modules/video_coding/codecs/h264/include/h264.h @@ -16,8 +16,8 @@ #include #include +#include "api/video_codecs/h264_profile_level_id.h" #include "media/base/codec.h" -#include "media/base/h264_profile_level_id.h" #include "modules/video_coding/include/video_codec_interface.h" #include "rtc_base/system/rtc_export.h" diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 24e041a23a..4b89f60ee6 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -638,7 +638,6 @@ if (is_ios || is_mac) { ":helpers_objc", "../api/video_codecs:video_codecs_api", "../common_video", - "../media:rtc_h264_profile_id", "../media:rtc_media_base", "../modules/video_coding:video_codec_interface", "../rtc_base:checks",