Add VideoDecoderFactory function to pass Environment for VideoDecoder construction
Bug: webrtc:15791
Change-Id: I3fa962ae13d8b36092a5b910f1ce6e946689daea
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/335680
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41600}
diff --git a/api/BUILD.gn b/api/BUILD.gn
index 6af4fa5..95850c6 100644
--- a/api/BUILD.gn
+++ b/api/BUILD.gn
@@ -1345,6 +1345,7 @@
deps = [
"../api/video_codecs:video_codecs_api",
"../test:test_support",
+ "environment",
]
}
diff --git a/api/test/mock_video_decoder_factory.h b/api/test/mock_video_decoder_factory.h
index 6150d9f..48d96ea 100644
--- a/api/test/mock_video_decoder_factory.h
+++ b/api/test/mock_video_decoder_factory.h
@@ -14,6 +14,7 @@
#include <memory>
#include <vector>
+#include "api/environment/environment.h"
#include "api/video_codecs/sdp_video_format.h"
#include "api/video_codecs/video_decoder.h"
#include "api/video_codecs/video_decoder_factory.h"
@@ -21,17 +22,21 @@
namespace webrtc {
-class MockVideoDecoderFactory : public webrtc::VideoDecoderFactory {
+class MockVideoDecoderFactory : public VideoDecoderFactory {
public:
~MockVideoDecoderFactory() override { Die(); }
- MOCK_METHOD(std::vector<webrtc::SdpVideoFormat>,
+ MOCK_METHOD(std::vector<SdpVideoFormat>,
GetSupportedFormats,
(),
(const, override));
- MOCK_METHOD(std::unique_ptr<webrtc::VideoDecoder>,
+ MOCK_METHOD(std::unique_ptr<VideoDecoder>,
+ Create,
+ (const Environment&, const SdpVideoFormat&),
+ (override));
+ MOCK_METHOD(std::unique_ptr<VideoDecoder>,
CreateVideoDecoder,
- (const webrtc::SdpVideoFormat&),
+ (const SdpVideoFormat&),
(override));
MOCK_METHOD(void, Die, ());
};
diff --git a/api/video_codecs/BUILD.gn b/api/video_codecs/BUILD.gn
index 3865f4f..aaa2a57 100644
--- a/api/video_codecs/BUILD.gn
+++ b/api/video_codecs/BUILD.gn
@@ -58,6 +58,7 @@
"video_codec.h",
"video_decoder.cc",
"video_decoder.h",
+ "video_decoder_factory.cc",
"video_decoder_factory.h",
"video_encoder.cc",
"video_encoder.h",
@@ -91,6 +92,7 @@
"../../rtc_base:refcount",
"../../rtc_base:stringutils",
"../../rtc_base/system:rtc_export",
+ "../environment",
"../units:data_rate",
"../video:encoded_image",
"../video:render_resolution",
diff --git a/api/video_codecs/video_decoder_factory.cc b/api/video_codecs/video_decoder_factory.cc
new file mode 100644
index 0000000..60fe92b
--- /dev/null
+++ b/api/video_codecs/video_decoder_factory.cc
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2024 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/video_decoder_factory.h"
+
+#include <memory>
+
+#include "api/video_codecs/sdp_video_format.h"
+#include "api/video_codecs/video_decoder.h"
+#include "rtc_base/checks.h"
+
+namespace webrtc {
+
+VideoDecoderFactory::CodecSupport VideoDecoderFactory::QueryCodecSupport(
+ const SdpVideoFormat& format,
+ bool reference_scaling) const {
+ // Default implementation, query for supported formats and check if the
+ // specified format is supported. Returns false if `reference_scaling` is
+ // true.
+ return {.is_supported = !reference_scaling &&
+ format.IsCodecInList(GetSupportedFormats())};
+}
+
+std::unique_ptr<VideoDecoder> VideoDecoderFactory::Create(
+ const Environment& env,
+ const SdpVideoFormat& format) {
+ return CreateVideoDecoder(format);
+}
+
+std::unique_ptr<VideoDecoder> VideoDecoderFactory::CreateVideoDecoder(
+ const SdpVideoFormat& format) {
+ // Newer code shouldn't call this function,
+ // Older code should implement it in derived classes.
+ RTC_CHECK_NOTREACHED();
+ return nullptr;
+}
+
+} // namespace webrtc
diff --git a/api/video_codecs/video_decoder_factory.h b/api/video_codecs/video_decoder_factory.h
index 7e1d2ee..6048cb2 100644
--- a/api/video_codecs/video_decoder_factory.h
+++ b/api/video_codecs/video_decoder_factory.h
@@ -12,17 +12,15 @@
#define API_VIDEO_CODECS_VIDEO_DECODER_FACTORY_H_
#include <memory>
-#include <string>
#include <vector>
-#include "absl/types/optional.h"
+#include "api/environment/environment.h"
#include "api/video_codecs/sdp_video_format.h"
+#include "api/video_codecs/video_decoder.h"
#include "rtc_base/system/rtc_export.h"
namespace webrtc {
-class VideoDecoder;
-
// A factory that creates VideoDecoders.
// NOTE: This class is still under development and may change without notice.
class RTC_EXPORT VideoDecoderFactory {
@@ -32,6 +30,8 @@
bool is_power_efficient = false;
};
+ virtual ~VideoDecoderFactory() = default;
+
// Returns a list of supported video formats in order of preference, to use
// for signaling etc.
virtual std::vector<SdpVideoFormat> GetSupportedFormats() const = 0;
@@ -47,21 +47,18 @@
// different scalabilty modes. NOTE: QueryCodecSupport is currently an
// experimental feature that is subject to change without notice.
virtual CodecSupport QueryCodecSupport(const SdpVideoFormat& format,
- bool reference_scaling) const {
- // Default implementation, query for supported formats and check if the
- // specified format is supported. Returns false if `reference_scaling` is
- // true.
- CodecSupport codec_support;
- codec_support.is_supported =
- !reference_scaling && format.IsCodecInList(GetSupportedFormats());
- return codec_support;
- }
+ bool reference_scaling) const;
- // Creates a VideoDecoder for the specified format.
+ // Creates a VideoDecoder for the specified `format`.
+ // TODO: bugs.webrtc.org/15791 - Make pure virtual when implemented in all
+ // derived classes.
+ virtual std::unique_ptr<VideoDecoder> Create(const Environment& env,
+ const SdpVideoFormat& format);
+
+ // TODO: bugs.webrtc.org/15791 - Make private or delete when all callers are
+ // migrated to `Create`.
virtual std::unique_ptr<VideoDecoder> CreateVideoDecoder(
- const SdpVideoFormat& format) = 0;
-
- virtual ~VideoDecoderFactory() {}
+ const SdpVideoFormat& format);
};
} // namespace webrtc