Allow to set av1 scalability mode after encoder is constructed

Bug: webrtc:11404
Change-Id: I70b4115c8afdc4f32fd876d31d54b7d95d0a7e1b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/188582
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32437}
This commit is contained in:
Danil Chapovalov 2020-10-16 17:45:41 +02:00 committed by Commit Bot
parent 0835ce5d6d
commit 9f4859e5e3
11 changed files with 39 additions and 20 deletions

View file

@ -16,6 +16,7 @@
#include <string> #include <string>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/video/video_bitrate_allocation.h" #include "api/video/video_bitrate_allocation.h"
#include "api/video/video_codec_type.h" #include "api/video/video_codec_type.h"
@ -101,6 +102,14 @@ class RTC_EXPORT VideoCodec {
public: public:
VideoCodec(); VideoCodec();
// Scalability mode as described in
// https://www.w3.org/TR/webrtc-svc/#scalabilitymodes*
// or value 'NONE' to indicate no scalability.
absl::string_view ScalabilityMode() const { return scalability_mode_; }
void SetScalabilityMode(absl::string_view scalability_mode) {
scalability_mode_ = std::string(scalability_mode);
}
// Public variables. TODO(hta): Make them private with accessors. // Public variables. TODO(hta): Make them private with accessors.
VideoCodecType codecType; VideoCodecType codecType;
@ -166,6 +175,7 @@ class RTC_EXPORT VideoCodec {
// TODO(hta): Consider replacing the union with a pointer type. // TODO(hta): Consider replacing the union with a pointer type.
// This will allow removing the VideoCodec* types from this file. // This will allow removing the VideoCodec* types from this file.
VideoCodecUnion codec_specific_; VideoCodecUnion codec_specific_;
std::string scalability_mode_;
}; };
} // namespace webrtc } // namespace webrtc

View file

@ -156,8 +156,6 @@ SimulcastEncoderAdapter::SimulcastEncoderAdapter(
// The adapter is typically created on the worker thread, but operated on // The adapter is typically created on the worker thread, but operated on
// the encoder task queue. // the encoder task queue.
encoder_queue_.Detach(); encoder_queue_.Detach();
memset(&codec_, 0, sizeof(webrtc::VideoCodec));
} }
SimulcastEncoderAdapter::~SimulcastEncoderAdapter() { SimulcastEncoderAdapter::~SimulcastEncoderAdapter() {

View file

@ -40,6 +40,7 @@ rtc_library("libaom_av1_encoder") {
public = [ "libaom_av1_encoder.h" ] public = [ "libaom_av1_encoder.h" ]
deps = [ deps = [
"../../../../api/video_codecs:video_codecs_api", "../../../../api/video_codecs:video_codecs_api",
"../../svc:scalability_structures",
"../../svc:scalable_video_controller", "../../svc:scalable_video_controller",
] ]
absl_deps = [ absl_deps = [

View file

@ -27,6 +27,7 @@
#include "api/video_codecs/video_encoder.h" #include "api/video_codecs/video_encoder.h"
#include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_codec_interface.h"
#include "modules/video_coding/include/video_error_codes.h" #include "modules/video_coding/include/video_error_codes.h"
#include "modules/video_coding/svc/create_scalability_structure.h"
#include "modules/video_coding/svc/scalable_video_controller.h" #include "modules/video_coding/svc/scalable_video_controller.h"
#include "modules/video_coding/svc/scalable_video_controller_no_layering.h" #include "modules/video_coding/svc/scalable_video_controller_no_layering.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
@ -93,7 +94,7 @@ class LibaomAv1Encoder final : public VideoEncoder {
void SetSvcRefFrameConfig( void SetSvcRefFrameConfig(
const ScalableVideoController::LayerFrameConfig& layer_frame); const ScalableVideoController::LayerFrameConfig& layer_frame);
const std::unique_ptr<ScalableVideoController> svc_controller_; std::unique_ptr<ScalableVideoController> svc_controller_;
bool inited_; bool inited_;
absl::optional<aom_svc_params_t> svc_params_; absl::optional<aom_svc_params_t> svc_params_;
VideoCodec encoder_settings_; VideoCodec encoder_settings_;
@ -164,6 +165,21 @@ int LibaomAv1Encoder::InitEncode(const VideoCodec* codec_settings,
"LibaomAv1Encoder."; "LibaomAv1Encoder.";
return result; return result;
} }
if (encoder_settings_.numberOfSimulcastStreams > 1) {
RTC_LOG(LS_WARNING) << "Simulcast is not implemented by LibaomAv1Encoder.";
return result;
}
absl::string_view scalability_mode = encoder_settings_.ScalabilityMode();
// When scalability_mode is not set, keep using svc_controller_ created
// at construction of the encoder.
if (!scalability_mode.empty()) {
svc_controller_ = CreateScalabilityStructure(scalability_mode);
}
if (svc_controller_ == nullptr) {
RTC_LOG(LS_WARNING) << "Failed to set scalability mode "
<< scalability_mode;
return WEBRTC_VIDEO_CODEC_ERR_PARAMETER;
}
if (!SetSvcParams(svc_controller_->StreamConfig())) { if (!SetSvcParams(svc_controller_->StreamConfig())) {
return WEBRTC_VIDEO_CODEC_ERROR; return WEBRTC_VIDEO_CODEC_ERROR;

View file

@ -179,14 +179,13 @@ struct SvcTestParam {
class LibaomAv1SvcTest : public ::testing::TestWithParam<SvcTestParam> {}; class LibaomAv1SvcTest : public ::testing::TestWithParam<SvcTestParam> {};
TEST_P(LibaomAv1SvcTest, EncodeAndDecodeAllDecodeTargets) { TEST_P(LibaomAv1SvcTest, EncodeAndDecodeAllDecodeTargets) {
std::unique_ptr<ScalableVideoController> svc_controller = size_t num_decode_targets = CreateScalabilityStructure(GetParam().name)
CreateScalabilityStructure(GetParam().name); ->DependencyStructure()
size_t num_decode_targets = .num_decode_targets;
svc_controller->DependencyStructure().num_decode_targets;
std::unique_ptr<VideoEncoder> encoder = std::unique_ptr<VideoEncoder> encoder = CreateLibaomAv1Encoder();
CreateLibaomAv1Encoder(std::move(svc_controller));
VideoCodec codec_settings = DefaultCodecSettings(); VideoCodec codec_settings = DefaultCodecSettings();
codec_settings.SetScalabilityMode(GetParam().name);
ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()), ASSERT_EQ(encoder->InitEncode(&codec_settings, DefaultEncoderSettings()),
WEBRTC_VIDEO_CODEC_OK); WEBRTC_VIDEO_CODEC_OK);
std::vector<EncodedVideoFrameProducer::EncodedFrame> encoded_frames = std::vector<EncodedVideoFrameProducer::EncodedFrame> encoded_frames =

View file

@ -96,7 +96,7 @@ bool VCMDecoderDataBase::DeregisterReceiveCodec(uint8_t payload_type) {
dec_map_.erase(it); dec_map_.erase(it);
if (payload_type == current_payload_type_) { if (payload_type == current_payload_type_) {
// This codec is currently in use. // This codec is currently in use.
memset(&receive_codec_, 0, sizeof(VideoCodec)); receive_codec_ = {};
current_payload_type_ = 0; current_payload_type_ = 0;
} }
return true; return true;
@ -113,7 +113,7 @@ VCMGenericDecoder* VCMDecoderDataBase::GetDecoder(
// If decoder exists - delete. // If decoder exists - delete.
if (ptr_decoder_) { if (ptr_decoder_) {
ptr_decoder_.reset(); ptr_decoder_.reset();
memset(&receive_codec_, 0, sizeof(VideoCodec)); receive_codec_ = {};
current_payload_type_ = 0; current_payload_type_ = 0;
} }
ptr_decoder_ = CreateAndInitDecoder(frame, &receive_codec_); ptr_decoder_ = CreateAndInitDecoder(frame, &receive_codec_);
@ -126,7 +126,7 @@ VCMGenericDecoder* VCMDecoderDataBase::GetDecoder(
if (ptr_decoder_->RegisterDecodeCompleteCallback(decoded_frame_callback) < if (ptr_decoder_->RegisterDecodeCompleteCallback(decoded_frame_callback) <
0) { 0) {
ptr_decoder_.reset(); ptr_decoder_.reset();
memset(&receive_codec_, 0, sizeof(VideoCodec)); receive_codec_ = {};
current_payload_type_ = 0; current_payload_type_ = 0;
return nullptr; return nullptr;
} }
@ -178,7 +178,7 @@ std::unique_ptr<VCMGenericDecoder> VCMDecoderDataBase::CreateAndInitDecoder(
RTC_LOG(LS_ERROR) << "Failed to initialize decoder. Error code: " << err; RTC_LOG(LS_ERROR) << "Failed to initialize decoder. Error code: " << err;
return nullptr; return nullptr;
} }
memcpy(new_codec, decoder_item->settings.get(), sizeof(VideoCodec)); *new_codec = *decoder_item->settings.get();
return ptr_decoder; return ptr_decoder;
} }

View file

@ -54,7 +54,6 @@ class MockTemporalLayers : public Vp8FrameBufferController {
class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> { class SimulcastRateAllocatorTest : public ::testing::TestWithParam<bool> {
public: public:
SimulcastRateAllocatorTest() { SimulcastRateAllocatorTest() {
memset(&codec_, 0, sizeof(VideoCodec));
codec_.codecType = kVideoCodecVP8; codec_.codecType = kVideoCodecVP8;
codec_.minBitrate = kMinBitrateKbps; codec_.minBitrate = kMinBitrateKbps;
codec_.maxBitrate = kLegacyScreenshareMaxBitrateKbps; codec_.maxBitrate = kLegacyScreenshareMaxBitrateKbps;

View file

@ -213,7 +213,7 @@ void SimulcastTestFixtureImpl::DefaultSettings(
VideoCodecType codec_type, VideoCodecType codec_type,
bool reverse_layer_order) { bool reverse_layer_order) {
RTC_CHECK(settings); RTC_CHECK(settings);
memset(settings, 0, sizeof(VideoCodec)); *settings = {};
settings->codecType = codec_type; settings->codecType = codec_type;
settings->startBitrate = 300; settings->startBitrate = 300;
settings->minBitrate = 30; settings->minBitrate = 30;

View file

@ -25,7 +25,7 @@ const int64_t kTestTimingFramesDelayMs = 200;
const uint16_t kTestOutlierFrameSizePercent = 250; const uint16_t kTestOutlierFrameSizePercent = 250;
static void CodecSettings(VideoCodecType codec_type, VideoCodec* settings) { static void CodecSettings(VideoCodecType codec_type, VideoCodec* settings) {
memset(settings, 0, sizeof(VideoCodec)); *settings = {};
settings->width = kTestWidth; settings->width = kTestWidth;
settings->height = kTestHeight; settings->height = kTestHeight;

View file

@ -115,8 +115,6 @@ class WebRtcRecordableEncodedFrame : public RecordableEncodedFrame {
VideoCodec CreateDecoderVideoCodec(const VideoReceiveStream::Decoder& decoder) { VideoCodec CreateDecoderVideoCodec(const VideoReceiveStream::Decoder& decoder) {
VideoCodec codec; VideoCodec codec;
memset(&codec, 0, sizeof(codec));
codec.codecType = PayloadStringToCodecType(decoder.video_format.name); codec.codecType = PayloadStringToCodecType(decoder.video_format.name);
if (codec.codecType == kVideoCodecVP8) { if (codec.codecType == kVideoCodecVP8) {

View file

@ -113,8 +113,6 @@ class WebRtcRecordableEncodedFrame : public RecordableEncodedFrame {
VideoCodec CreateDecoderVideoCodec(const VideoReceiveStream::Decoder& decoder) { VideoCodec CreateDecoderVideoCodec(const VideoReceiveStream::Decoder& decoder) {
VideoCodec codec; VideoCodec codec;
memset(&codec, 0, sizeof(codec));
codec.codecType = PayloadStringToCodecType(decoder.video_format.name); codec.codecType = PayloadStringToCodecType(decoder.video_format.name);
if (codec.codecType == kVideoCodecVP8) { if (codec.codecType == kVideoCodecVP8) {