diff --git a/media/BUILD.gn b/media/BUILD.gn index 89a5d46a57..6ae156b108 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -211,7 +211,7 @@ rtc_library("rtc_internal_video_codecs") { "../modules/video_coding:webrtc_vp8", "../modules/video_coding:webrtc_vp9", "../modules/video_coding/codecs/av1:libaom_av1_decoder", - "../modules/video_coding/codecs/av1:libaom_av1_encoder", + "../modules/video_coding/codecs/av1:libaom_av1_encoder_if_supported", "../rtc_base:checks", "../rtc_base:rtc_base_approved", "../rtc_base/system:rtc_export", @@ -622,7 +622,7 @@ if (rtc_include_tests) { "../modules/video_coding:webrtc_h264", "../modules/video_coding:webrtc_vp8", "../modules/video_coding/codecs/av1:libaom_av1_decoder", - "../modules/video_coding/codecs/av1:libaom_av1_encoder", + "../modules/video_coding/codecs/av1:libaom_av1_encoder_if_supported", "../p2p:p2p_test_utils", "../rtc_base", "../rtc_base:checks", diff --git a/media/engine/internal_encoder_factory.cc b/media/engine/internal_encoder_factory.cc index bb550662f9..5ccb93d0c1 100644 --- a/media/engine/internal_encoder_factory.cc +++ b/media/engine/internal_encoder_factory.cc @@ -16,7 +16,7 @@ #include "api/video_codecs/sdp_video_format.h" #include "media/base/codec.h" #include "media/base/media_constants.h" -#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h" +#include "modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h" #include "modules/video_coding/codecs/h264/include/h264.h" #include "modules/video_coding/codecs/vp8/include/vp8.h" #include "modules/video_coding/codecs/vp9/include/vp9.h" @@ -51,7 +51,7 @@ std::unique_ptr InternalEncoderFactory::CreateVideoEncoder( return H264Encoder::Create(cricket::VideoCodec(format)); if (kIsLibaomAv1EncoderSupported && absl::EqualsIgnoreCase(format.name, cricket::kAv1CodecName)) - return CreateLibaomAv1Encoder(); + return CreateLibaomAv1EncoderIfSupported(); RTC_LOG(LS_ERROR) << "Trying to created encoder of unsupported format " << format.name; return nullptr; diff --git a/media/engine/internal_encoder_factory_unittest.cc b/media/engine/internal_encoder_factory_unittest.cc index 3365e59696..c3a667e733 100644 --- a/media/engine/internal_encoder_factory_unittest.cc +++ b/media/engine/internal_encoder_factory_unittest.cc @@ -14,7 +14,7 @@ #include "api/video_codecs/video_encoder.h" #include "api/video_codecs/vp9_profile.h" #include "media/base/media_constants.h" -#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h" +#include "modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h" #include "test/gmock.h" #include "test/gtest.h" diff --git a/modules/video_coding/codecs/av1/BUILD.gn b/modules/video_coding/codecs/av1/BUILD.gn index 7106ca4809..2e4d824821 100644 --- a/modules/video_coding/codecs/av1/BUILD.gn +++ b/modules/video_coding/codecs/av1/BUILD.gn @@ -71,32 +71,46 @@ rtc_library("libaom_av1_encoder") { visibility = [ "*" ] poisonous = [ "software_video_codecs" ] public = [ "libaom_av1_encoder.h" ] + sources = [ "libaom_av1_encoder.cc" ] + deps = [ + "../..:video_codec_interface", + "../../../../api:scoped_refptr", + "../../../../api/video:encoded_image", + "../../../../api/video:video_frame", + "../../../../api/video_codecs:video_codecs_api", + "../../../../common_video", + "../../../../rtc_base:checks", + "../../../../rtc_base:logging", + "../../svc:scalability_structures", + "../../svc:scalable_video_controller", + "//third_party/libaom", + ] + absl_deps = [ + "//third_party/abseil-cpp/absl/algorithm:container", + "//third_party/abseil-cpp/absl/strings:strings", + "//third_party/abseil-cpp/absl/types:optional", + ] +} + +rtc_library("libaom_av1_encoder_if_supported") { + visibility = [ "*" ] + poisonous = [ "software_video_codecs" ] + public = [ "libaom_av1_encoder_supported.h" ] + sources = [ "libaom_av1_encoder_supported.cc" ] deps = [ "../../../../api/video_codecs:video_codecs_api", "../../svc:scalability_structures", "../../svc:scalable_video_controller", ] absl_deps = [ - "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/strings:strings", - "//third_party/abseil-cpp/absl/types:optional", ] + defines = [] if (enable_libaom) { - sources = [ "libaom_av1_encoder.cc" ] - deps += [ - "../..:video_codec_interface", - "../../../../api:scoped_refptr", - "../../../../api/video:encoded_image", - "../../../../api/video:video_frame", - "../../../../common_video", - "../../../../rtc_base:checks", - "../../../../rtc_base:logging", - "//third_party/libaom", - ] - } else { - sources = [ "libaom_av1_encoder_absent.cc" ] + defines += [ "RTC_USE_LIBAOM_AV1_ENCODER" ] + deps += [ ":libaom_av1_encoder" ] } } diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc index 967ec7d45a..79a31d9baa 100644 --- a/modules/video_coding/codecs/av1/libaom_av1_encoder.cc +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder.cc @@ -820,17 +820,8 @@ VideoEncoder::EncoderInfo LibaomAv1Encoder::GetEncoderInfo() const { } // namespace -const bool kIsLibaomAv1EncoderSupported = true; - std::unique_ptr CreateLibaomAv1Encoder() { return std::make_unique(); } -bool LibaomAv1EncoderSupportsScalabilityMode( - absl::string_view scalability_mode) { - // For AV1, the scalability mode is supported if we can create the scalability - // structure. - return ScalabilityStructureConfig(scalability_mode) != absl::nullopt; -} - } // namespace webrtc diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder.h b/modules/video_coding/codecs/av1/libaom_av1_encoder.h index 0d81c9c17e..e69df9e8bb 100644 --- a/modules/video_coding/codecs/av1/libaom_av1_encoder.h +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder.h @@ -12,18 +12,11 @@ #include -#include "absl/base/attributes.h" #include "absl/strings/string_view.h" #include "api/video_codecs/video_encoder.h" namespace webrtc { - -ABSL_CONST_INIT extern const bool kIsLibaomAv1EncoderSupported; - std::unique_ptr CreateLibaomAv1Encoder(); -bool LibaomAv1EncoderSupportsScalabilityMode( - absl::string_view scalability_mode); - } // namespace webrtc #endif // MODULES_VIDEO_CODING_CODECS_AV1_LIBAOM_AV1_ENCODER_H_ diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder_absent.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder_absent.cc deleted file mode 100644 index fff1dd9ed8..0000000000 --- a/modules/video_coding/codecs/av1/libaom_av1_encoder_absent.cc +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2020 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 "modules/video_coding/codecs/av1/libaom_av1_encoder.h" - -#include - -#include "api/video_codecs/video_encoder.h" - -namespace webrtc { - -const bool kIsLibaomAv1EncoderSupported = false; - -std::unique_ptr CreateLibaomAv1Encoder() { - return nullptr; -} - -bool LibaomAv1EncoderSupportsScalabilityMode( - absl::string_view scalability_mode) { - return false; -} - -} // namespace webrtc diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder_supported.cc b/modules/video_coding/codecs/av1/libaom_av1_encoder_supported.cc new file mode 100644 index 0000000000..0bb31085e2 --- /dev/null +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder_supported.cc @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2021 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 "modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h" + +#include "modules/video_coding/svc/create_scalability_structure.h" + +#if defined(RTC_USE_LIBAOM_AV1_ENCODER) +#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h" // nogncheck +#endif + +namespace webrtc { +#if defined(RTC_USE_LIBAOM_AV1_ENCODER) +const bool kIsLibaomAv1EncoderSupported = true; +std::unique_ptr CreateLibaomAv1EncoderIfSupported() { + return CreateLibaomAv1Encoder(); +} +bool LibaomAv1EncoderSupportsScalabilityMode( + absl::string_view scalability_mode) { + // For libaom AV1, the scalability mode is supported if we can create the + // scalability structure. + return ScalabilityStructureConfig(scalability_mode) != absl::nullopt; +} +#else +const bool kIsLibaomAv1EncoderSupported = false; +std::unique_ptr CreateLibaomAv1EncoderIfSupported() { + return nullptr; +} +bool LibaomAv1EncoderSupportsScalabilityMode( + absl::string_view scalability_mode) { + return false; +} +#endif + +} // namespace webrtc diff --git a/modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h b/modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h new file mode 100644 index 0000000000..84dd8d6002 --- /dev/null +++ b/modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 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 MODULES_VIDEO_CODING_CODECS_AV1_LIBAOM_AV1_ENCODER_SUPPORTED_H_ +#define MODULES_VIDEO_CODING_CODECS_AV1_LIBAOM_AV1_ENCODER_SUPPORTED_H_ + +#include + +#include "absl/base/attributes.h" +#include "absl/strings/string_view.h" +#include "api/video_codecs/video_encoder.h" + +namespace webrtc { + +ABSL_CONST_INIT extern const bool kIsLibaomAv1EncoderSupported; + +std::unique_ptr CreateLibaomAv1EncoderIfSupported(); +bool LibaomAv1EncoderSupportsScalabilityMode( + absl::string_view scalability_mode); + +} // namespace webrtc + +#endif // MODULES_VIDEO_CODING_CODECS_AV1_LIBAOM_AV1_ENCODER_SUPPORTED_H_ diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 8f76c52691..718d9274a1 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -730,7 +730,7 @@ if (is_ios || is_mac) { ":wrapped_native_codec_objc", "../media:rtc_media_base", "../modules/video_coding/codecs/av1:libaom_av1_decoder", - "../modules/video_coding/codecs/av1:libaom_av1_encoder", + "../modules/video_coding/codecs/av1:libaom_av1_encoder_if_supported", ] } diff --git a/sdk/android/BUILD.gn b/sdk/android/BUILD.gn index ff3f55197b..561a33db8d 100644 --- a/sdk/android/BUILD.gn +++ b/sdk/android/BUILD.gn @@ -876,7 +876,7 @@ if (current_os == "linux" || is_android) { ":generated_libaom_av1_jni", ":video_jni", "../../modules/video_coding/codecs/av1:libaom_av1_decoder", - "../../modules/video_coding/codecs/av1:libaom_av1_encoder", + "../../modules/video_coding/codecs/av1:libaom_av1_encoder_if_supported", ] } diff --git a/sdk/android/src/jni/libaom_av1_codec.cc b/sdk/android/src/jni/libaom_av1_codec.cc index 02070f7901..e4332a6512 100644 --- a/sdk/android/src/jni/libaom_av1_codec.cc +++ b/sdk/android/src/jni/libaom_av1_codec.cc @@ -11,7 +11,7 @@ #include #include "modules/video_coding/codecs/av1/libaom_av1_decoder.h" -#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h" +#include "modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h" #include "sdk/android/generated_libaom_av1_jni/LibaomAv1Decoder_jni.h" #include "sdk/android/generated_libaom_av1_jni/LibaomAv1Encoder_jni.h" #include "sdk/android/src/jni/jni_helpers.h" @@ -20,7 +20,8 @@ namespace webrtc { namespace jni { static jlong JNI_LibaomAv1Encoder_CreateEncoder(JNIEnv* jni) { - return jlongFromPointer(webrtc::CreateLibaomAv1Encoder().release()); + return jlongFromPointer( + webrtc::CreateLibaomAv1EncoderIfSupported().release()); } static jboolean JNI_LibaomAv1Encoder_IsSupported(JNIEnv* jni) { diff --git a/sdk/objc/api/video_codec/RTCVideoEncoderAV1.mm b/sdk/objc/api/video_codec/RTCVideoEncoderAV1.mm index 92e924a475..853ffedf4b 100644 --- a/sdk/objc/api/video_codec/RTCVideoEncoderAV1.mm +++ b/sdk/objc/api/video_codec/RTCVideoEncoderAV1.mm @@ -15,12 +15,12 @@ #import "RTCVideoEncoderAV1.h" #import "RTCWrappedNativeVideoEncoder.h" -#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h" +#include "modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h" @implementation RTC_OBJC_TYPE (RTCVideoEncoderAV1) + (id)av1Encoder { - std::unique_ptr nativeEncoder(webrtc::CreateLibaomAv1Encoder()); + std::unique_ptr nativeEncoder(webrtc::CreateLibaomAv1EncoderIfSupported()); if (nativeEncoder == nullptr) { return nil; } diff --git a/video/BUILD.gn b/video/BUILD.gn index 0f9b66963c..92f5dd4b35 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn @@ -736,7 +736,7 @@ if (rtc_include_tests) { "../modules/video_coding:webrtc_vp8", "../modules/video_coding:webrtc_vp9", "../modules/video_coding:webrtc_vp9_helpers", - "../modules/video_coding/codecs/av1:libaom_av1_encoder", + "../modules/video_coding/codecs/av1:libaom_av1_encoder_if_supported", "../rtc_base", "../rtc_base:checks", "../rtc_base:gunit_helpers", diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index 3a81ec25ba..1b0597e339 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -40,7 +40,7 @@ #include "common_video/include/video_frame_buffer.h" #include "media/base/video_adapter.h" #include "media/engine/webrtc_video_engine.h" -#include "modules/video_coding/codecs/av1/libaom_av1_encoder.h" +#include "modules/video_coding/codecs/av1/libaom_av1_encoder_supported.h" #include "modules/video_coding/codecs/h264/include/h264.h" #include "modules/video_coding/codecs/multiplex/include/multiplex_encoder_adapter.h" #include "modules/video_coding/codecs/vp8/include/vp8.h" @@ -8439,7 +8439,7 @@ class VideoStreamEncoderWithRealEncoderTest encoder = VP9Encoder::Create(); break; case kVideoCodecAV1: - encoder = CreateLibaomAv1Encoder(); + encoder = CreateLibaomAv1EncoderIfSupported(); break; case kVideoCodecH264: encoder =