Create EncoderStreamFactory in VideoStreamEncoder

This cl/ changes so that the EncoderStreamFactory is
not created inside WebRtcVideoSendStream (webrtc_video_engine).

The benifit of this is that the VideoStreamEncoder can then
amend the EncoderStreamFactory with state (and types)
w/o exposing it in VideoEncoderConfig.

I.e as an alternative to changes done inside
https://webrtc-review.googlesource.com/c/src/+/276742.

The fake_webrtc_call is modified to (if needed) create
it's own EncoderStreamFactory if needed.

Note: this cl/ will have to be merged with with
https://webrtc-review.googlesource.com/c/src/+/277002.

Bug: webrtc:14451
Change-Id: I3d896b227d39725ba6409622e8d09d14bd45d5fe
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/277160
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Jonas Oreland <jonaso@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38237}
This commit is contained in:
Jonas Oreland
2022-09-28 16:28:42 +02:00
committed by WebRTC LUCI CQ
parent e82c2285a4
commit 7252348d76
8 changed files with 64 additions and 12 deletions

View File

@ -158,6 +158,9 @@ class VideoEncoderConfig {
VideoCodecType codec_type;
SdpVideoFormat video_format;
// Note: This factory can be unset, and VideoStreamEncoder will
// then use the EncoderStreamFactory. The factory is only set by
// tests.
rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory;
std::vector<SpatialLayer> spatial_layers;
ContentType content_type;
@ -189,6 +192,11 @@ class VideoEncoderConfig {
// Indicates whether quality scaling can be used or not.
bool is_quality_scaling_allowed;
// Maximum Quantization Parameter.
// This value is fed into EncoderStreamFactory that
// apply it to all simulcast layers/spatial layers.
int max_qp;
private:
// Access to the copy constructor is private to force use of the Copy()
// method for those exceptional cases where we do use it.

View File

@ -331,7 +331,6 @@ rtc_library("rtc_audio_video") {
"../rtc_base/third_party/base64",
"../system_wrappers",
"../system_wrappers:metrics",
"../video/config:streams_config",
]
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",
@ -527,6 +526,7 @@ if (rtc_include_tests) {
"../rtc_base/third_party/sigslot",
"../test:scoped_key_value_config",
"../test:test_support",
"../video/config:streams_config",
"//testing/gtest",
]
absl_deps = [

View File

@ -28,4 +28,7 @@ specific_include_rules = {
".*webrtc_video_engine_unittest\.cc": [
"+video/config",
],
".*fake_webrtc_call\.cc": [
"+video/config",
],
}

View File

@ -19,6 +19,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/gunit.h"
#include "rtc_base/thread.h"
#include "video/config/encoder_stream_factory.h"
namespace cricket {
@ -241,8 +242,23 @@ void FakeVideoSendStream::OnFrame(const webrtc::VideoFrame& frame) {
if (!last_frame_ || frame.width() != last_frame_->width() ||
frame.height() != last_frame_->height() ||
frame.rotation() != last_frame_->rotation()) {
video_streams_ = encoder_config_.video_stream_factory->CreateEncoderStreams(
frame.width(), frame.height(), encoder_config_);
if (encoder_config_.video_stream_factory) {
// Note: only tests set their own EncoderStreamFactory...
video_streams_ =
encoder_config_.video_stream_factory->CreateEncoderStreams(
frame.width(), frame.height(), encoder_config_);
} else {
rtc::scoped_refptr<
webrtc::VideoEncoderConfig::VideoStreamFactoryInterface>
factory = rtc::make_ref_counted<cricket::EncoderStreamFactory>(
encoder_config_.video_format.name, encoder_config_.max_qp,
encoder_config_.content_type ==
webrtc::VideoEncoderConfig::ContentType::kScreen,
encoder_config_.legacy_conference_mode);
video_streams_ = factory->CreateEncoderStreams(
frame.width(), frame.height(), encoder_config_);
}
}
last_frame_ = frame;
}
@ -265,8 +281,21 @@ void FakeVideoSendStream::ReconfigureVideoEncoder(
} else {
width = height = 0;
}
video_streams_ =
config.video_stream_factory->CreateEncoderStreams(width, height, config);
if (config.video_stream_factory) {
// Note: only tests set their own EncoderStreamFactory...
video_streams_ = config.video_stream_factory->CreateEncoderStreams(
width, height, config);
} else {
rtc::scoped_refptr<webrtc::VideoEncoderConfig::VideoStreamFactoryInterface>
factory = rtc::make_ref_counted<cricket::EncoderStreamFactory>(
config.video_format.name, config.max_qp,
config.content_type ==
webrtc::VideoEncoderConfig::ContentType::kScreen,
config.legacy_conference_mode);
video_streams_ = factory->CreateEncoderStreams(width, height, config);
}
if (config.encoder_specific_settings != nullptr) {
const unsigned char num_temporal_layers = static_cast<unsigned char>(
video_streams_.back().num_temporal_layers.value_or(1));

View File

@ -2512,9 +2512,7 @@ WebRtcVideoChannel::WebRtcVideoSendStream::CreateVideoEncoderConfig(
int max_qp = kDefaultQpMax;
codec.GetParam(kCodecParamMaxQuantization, &max_qp);
encoder_config.video_stream_factory =
rtc::make_ref_counted<EncoderStreamFactory>(
codec.name, max_qp, is_screencast, parameters_.conference_mode);
encoder_config.max_qp = max_qp;
return encoder_config;
}

View File

@ -37,7 +37,6 @@
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/no_unique_address.h"
#include "rtc_base/thread_annotations.h"
#include "video/config/encoder_stream_factory.h"
namespace webrtc {
class VideoDecoderFactory;

View File

@ -434,6 +434,7 @@ rtc_library("video_stream_encoder_impl") {
"../system_wrappers:field_trial",
"../system_wrappers:metrics",
"adaptation:video_adaptation",
"config:streams_config",
]
absl_deps = [
"//third_party/abseil-cpp/absl/algorithm:container",

View File

@ -51,6 +51,7 @@
#include "system_wrappers/include/metrics.h"
#include "video/adaptation/video_stream_encoder_resource_manager.h"
#include "video/alignment_adjuster.h"
#include "video/config/encoder_stream_factory.h"
#include "video/frame_cadence_adapter.h"
namespace webrtc {
@ -936,9 +937,22 @@ void VideoStreamEncoder::ReconfigureEncoder() {
AlignmentAdjuster::GetAlignmentAndMaybeAdjustScaleFactors(
encoder_->GetEncoderInfo(), &encoder_config_, absl::nullopt);
std::vector<VideoStream> streams =
encoder_config_.video_stream_factory->CreateEncoderStreams(
last_frame_info_->width, last_frame_info_->height, encoder_config_);
std::vector<VideoStream> streams;
if (encoder_config_.video_stream_factory) {
// Note: only tests set their own EncoderStreamFactory...
streams = encoder_config_.video_stream_factory->CreateEncoderStreams(
last_frame_info_->width, last_frame_info_->height, encoder_config_);
} else {
rtc::scoped_refptr<VideoEncoderConfig::VideoStreamFactoryInterface>
factory = rtc::make_ref_counted<cricket::EncoderStreamFactory>(
encoder_config_.video_format.name, encoder_config_.max_qp,
encoder_config_.content_type ==
webrtc::VideoEncoderConfig::ContentType::kScreen,
encoder_config_.legacy_conference_mode);
streams = factory->CreateEncoderStreams(
last_frame_info_->width, last_frame_info_->height, encoder_config_);
}
// Get alignment when actual number of layers are known.
int alignment = AlignmentAdjuster::GetAlignmentAndMaybeAdjustScaleFactors(