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}
This commit is contained in:
parent
340d6c0236
commit
c708c00f95
@ -1345,6 +1345,7 @@ if (rtc_include_tests) {
|
|||||||
deps = [
|
deps = [
|
||||||
"../api/video_codecs:video_codecs_api",
|
"../api/video_codecs:video_codecs_api",
|
||||||
"../test:test_support",
|
"../test:test_support",
|
||||||
|
"environment",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "api/environment/environment.h"
|
||||||
#include "api/video_codecs/sdp_video_format.h"
|
#include "api/video_codecs/sdp_video_format.h"
|
||||||
#include "api/video_codecs/video_decoder.h"
|
#include "api/video_codecs/video_decoder.h"
|
||||||
#include "api/video_codecs/video_decoder_factory.h"
|
#include "api/video_codecs/video_decoder_factory.h"
|
||||||
@ -21,17 +22,21 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class MockVideoDecoderFactory : public webrtc::VideoDecoderFactory {
|
class MockVideoDecoderFactory : public VideoDecoderFactory {
|
||||||
public:
|
public:
|
||||||
~MockVideoDecoderFactory() override { Die(); }
|
~MockVideoDecoderFactory() override { Die(); }
|
||||||
|
|
||||||
MOCK_METHOD(std::vector<webrtc::SdpVideoFormat>,
|
MOCK_METHOD(std::vector<SdpVideoFormat>,
|
||||||
GetSupportedFormats,
|
GetSupportedFormats,
|
||||||
(),
|
(),
|
||||||
(const, override));
|
(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,
|
CreateVideoDecoder,
|
||||||
(const webrtc::SdpVideoFormat&),
|
(const SdpVideoFormat&),
|
||||||
(override));
|
(override));
|
||||||
MOCK_METHOD(void, Die, ());
|
MOCK_METHOD(void, Die, ());
|
||||||
};
|
};
|
||||||
|
|||||||
@ -58,6 +58,7 @@ rtc_library("video_codecs_api") {
|
|||||||
"video_codec.h",
|
"video_codec.h",
|
||||||
"video_decoder.cc",
|
"video_decoder.cc",
|
||||||
"video_decoder.h",
|
"video_decoder.h",
|
||||||
|
"video_decoder_factory.cc",
|
||||||
"video_decoder_factory.h",
|
"video_decoder_factory.h",
|
||||||
"video_encoder.cc",
|
"video_encoder.cc",
|
||||||
"video_encoder.h",
|
"video_encoder.h",
|
||||||
@ -91,6 +92,7 @@ rtc_library("video_codecs_api") {
|
|||||||
"../../rtc_base:refcount",
|
"../../rtc_base:refcount",
|
||||||
"../../rtc_base:stringutils",
|
"../../rtc_base:stringutils",
|
||||||
"../../rtc_base/system:rtc_export",
|
"../../rtc_base/system:rtc_export",
|
||||||
|
"../environment",
|
||||||
"../units:data_rate",
|
"../units:data_rate",
|
||||||
"../video:encoded_image",
|
"../video:encoded_image",
|
||||||
"../video:render_resolution",
|
"../video:render_resolution",
|
||||||
|
|||||||
45
api/video_codecs/video_decoder_factory.cc
Normal file
45
api/video_codecs/video_decoder_factory.cc
Normal file
@ -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
|
||||||
@ -12,17 +12,15 @@
|
|||||||
#define API_VIDEO_CODECS_VIDEO_DECODER_FACTORY_H_
|
#define API_VIDEO_CODECS_VIDEO_DECODER_FACTORY_H_
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "absl/types/optional.h"
|
#include "api/environment/environment.h"
|
||||||
#include "api/video_codecs/sdp_video_format.h"
|
#include "api/video_codecs/sdp_video_format.h"
|
||||||
|
#include "api/video_codecs/video_decoder.h"
|
||||||
#include "rtc_base/system/rtc_export.h"
|
#include "rtc_base/system/rtc_export.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
|
||||||
class VideoDecoder;
|
|
||||||
|
|
||||||
// A factory that creates VideoDecoders.
|
// A factory that creates VideoDecoders.
|
||||||
// NOTE: This class is still under development and may change without notice.
|
// NOTE: This class is still under development and may change without notice.
|
||||||
class RTC_EXPORT VideoDecoderFactory {
|
class RTC_EXPORT VideoDecoderFactory {
|
||||||
@ -32,6 +30,8 @@ class RTC_EXPORT VideoDecoderFactory {
|
|||||||
bool is_power_efficient = false;
|
bool is_power_efficient = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
virtual ~VideoDecoderFactory() = default;
|
||||||
|
|
||||||
// Returns a list of supported video formats in order of preference, to use
|
// Returns a list of supported video formats in order of preference, to use
|
||||||
// for signaling etc.
|
// for signaling etc.
|
||||||
virtual std::vector<SdpVideoFormat> GetSupportedFormats() const = 0;
|
virtual std::vector<SdpVideoFormat> GetSupportedFormats() const = 0;
|
||||||
@ -47,21 +47,18 @@ class RTC_EXPORT VideoDecoderFactory {
|
|||||||
// different scalabilty modes. NOTE: QueryCodecSupport is currently an
|
// different scalabilty modes. NOTE: QueryCodecSupport is currently an
|
||||||
// experimental feature that is subject to change without notice.
|
// experimental feature that is subject to change without notice.
|
||||||
virtual CodecSupport QueryCodecSupport(const SdpVideoFormat& format,
|
virtual CodecSupport QueryCodecSupport(const SdpVideoFormat& format,
|
||||||
bool reference_scaling) const {
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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(
|
virtual std::unique_ptr<VideoDecoder> CreateVideoDecoder(
|
||||||
const SdpVideoFormat& format) = 0;
|
const SdpVideoFormat& format);
|
||||||
|
|
||||||
virtual ~VideoDecoderFactory() {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user