mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Propagate Environment into VideoStreamEncoder
VideoStreamEncoder creates VideoEncoders. To pass an Environment to VideoEncoder, it should be available in the VideoStreamEncoder. Bug: webrtc:15860 Change-Id: Id89ac024ce61fdd9673bb66f03f94f243fc0c7f7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/341840 Reviewed-by: Philip Eliasson <philipel@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/main@{#41861}
This commit is contained in:
parent
9f11b96e6b
commit
c9bb2c6c4e
8 changed files with 107 additions and 111 deletions
10
call/call.cc
10
call/call.cc
|
@ -888,13 +888,11 @@ webrtc::VideoSendStream* Call::CreateVideoSendStream(
|
|||
std::vector<uint32_t> ssrcs = config.rtp.ssrcs;
|
||||
|
||||
VideoSendStreamImpl* send_stream = new VideoSendStreamImpl(
|
||||
&env_.clock(), num_cpu_cores_, &env_.task_queue_factory(),
|
||||
call_stats_->AsRtcpRttStats(), transport_send_.get(),
|
||||
config_.encode_metronome, bitrate_allocator_.get(),
|
||||
video_send_delay_stats_.get(), &env_.event_log(), std::move(config),
|
||||
env_, num_cpu_cores_, call_stats_->AsRtcpRttStats(),
|
||||
transport_send_.get(), config_.encode_metronome, bitrate_allocator_.get(),
|
||||
video_send_delay_stats_.get(), std::move(config),
|
||||
std::move(encoder_config), suspended_video_send_ssrcs_,
|
||||
suspended_video_payload_states_, std::move(fec_controller),
|
||||
env_.field_trials());
|
||||
suspended_video_payload_states_, std::move(fec_controller));
|
||||
|
||||
for (uint32_t ssrc : ssrcs) {
|
||||
RTC_DCHECK(video_send_ssrcs_.find(ssrc) == video_send_ssrcs_.end());
|
||||
|
|
|
@ -413,6 +413,7 @@ rtc_library("video_stream_encoder_impl") {
|
|||
"../api:rtp_sender_interface",
|
||||
"../api:sequence_checker",
|
||||
"../api/adaptation:resource_adaptation_api",
|
||||
"../api/environment",
|
||||
"../api/task_queue:pending_task_safety_flag",
|
||||
"../api/task_queue:task_queue",
|
||||
"../api/units:data_rate",
|
||||
|
@ -464,7 +465,6 @@ rtc_library("video_stream_encoder_impl") {
|
|||
"../rtc_base/system:no_unique_address",
|
||||
"../rtc_base/task_utils:repeating_task",
|
||||
"../system_wrappers",
|
||||
"../system_wrappers:field_trial",
|
||||
"../system_wrappers:metrics",
|
||||
"adaptation:video_adaptation",
|
||||
"config:encoder_config",
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "api/adaptation/resource.h"
|
||||
#include "api/call/bitrate_allocation.h"
|
||||
#include "api/crypto/crypto_options.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/fec_controller.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "api/metronome/metronome.h"
|
||||
|
@ -340,27 +341,25 @@ RtpSenderObservers CreateObservers(RtcpRttStats* call_stats,
|
|||
}
|
||||
|
||||
std::unique_ptr<VideoStreamEncoderInterface> CreateVideoStreamEncoder(
|
||||
Clock* clock,
|
||||
const Environment& env,
|
||||
int num_cpu_cores,
|
||||
TaskQueueFactory* task_queue_factory,
|
||||
SendStatisticsProxy* stats_proxy,
|
||||
const VideoStreamEncoderSettings& encoder_settings,
|
||||
VideoStreamEncoder::BitrateAllocationCallbackType
|
||||
bitrate_allocation_callback_type,
|
||||
const FieldTrialsView& field_trials,
|
||||
Metronome* metronome,
|
||||
webrtc::VideoEncoderFactory::EncoderSelectorInterface* encoder_selector) {
|
||||
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> encoder_queue =
|
||||
task_queue_factory->CreateTaskQueue("EncoderQueue",
|
||||
TaskQueueFactory::Priority::NORMAL);
|
||||
env.task_queue_factory().CreateTaskQueue(
|
||||
"EncoderQueue", TaskQueueFactory::Priority::NORMAL);
|
||||
TaskQueueBase* encoder_queue_ptr = encoder_queue.get();
|
||||
return std::make_unique<VideoStreamEncoder>(
|
||||
clock, num_cpu_cores, stats_proxy, encoder_settings,
|
||||
env, num_cpu_cores, stats_proxy, encoder_settings,
|
||||
std::make_unique<OveruseFrameDetector>(stats_proxy),
|
||||
FrameCadenceAdapterInterface::Create(
|
||||
clock, encoder_queue_ptr, metronome,
|
||||
/*worker_queue=*/TaskQueueBase::Current(), field_trials),
|
||||
std::move(encoder_queue), bitrate_allocation_callback_type, field_trials,
|
||||
&env.clock(), encoder_queue_ptr, metronome,
|
||||
/*worker_queue=*/TaskQueueBase::Current(), env.field_trials()),
|
||||
std::move(encoder_queue), bitrate_allocation_callback_type,
|
||||
encoder_selector);
|
||||
}
|
||||
|
||||
|
@ -385,24 +384,25 @@ PacingConfig::PacingConfig(const PacingConfig&) = default;
|
|||
PacingConfig::~PacingConfig() = default;
|
||||
|
||||
VideoSendStreamImpl::VideoSendStreamImpl(
|
||||
Clock* clock,
|
||||
const Environment& env,
|
||||
int num_cpu_cores,
|
||||
TaskQueueFactory* task_queue_factory,
|
||||
RtcpRttStats* call_stats,
|
||||
RtpTransportControllerSendInterface* transport,
|
||||
Metronome* metronome,
|
||||
BitrateAllocatorInterface* bitrate_allocator,
|
||||
SendDelayStats* send_delay_stats,
|
||||
RtcEventLog* event_log,
|
||||
VideoSendStream::Config config,
|
||||
VideoEncoderConfig encoder_config,
|
||||
const std::map<uint32_t, RtpState>& suspended_ssrcs,
|
||||
const std::map<uint32_t, RtpPayloadState>& suspended_payload_states,
|
||||
std::unique_ptr<FecController> fec_controller,
|
||||
const FieldTrialsView& field_trials,
|
||||
std::unique_ptr<VideoStreamEncoderInterface> video_stream_encoder_for_test)
|
||||
: transport_(transport),
|
||||
stats_proxy_(clock, config, encoder_config.content_type, field_trials),
|
||||
: env_(env),
|
||||
transport_(transport),
|
||||
stats_proxy_(&env_.clock(),
|
||||
config,
|
||||
encoder_config.content_type,
|
||||
env_.field_trials()),
|
||||
send_packet_observer_(&stats_proxy_, send_delay_stats),
|
||||
config_(std::move(config)),
|
||||
content_type_(encoder_config.content_type),
|
||||
|
@ -410,17 +410,16 @@ VideoSendStreamImpl::VideoSendStreamImpl(
|
|||
video_stream_encoder_for_test
|
||||
? std::move(video_stream_encoder_for_test)
|
||||
: CreateVideoStreamEncoder(
|
||||
clock,
|
||||
env_,
|
||||
num_cpu_cores,
|
||||
task_queue_factory,
|
||||
&stats_proxy_,
|
||||
config_.encoder_settings,
|
||||
GetBitrateAllocationCallbackType(config_, field_trials),
|
||||
field_trials,
|
||||
GetBitrateAllocationCallbackType(config_,
|
||||
env_.field_trials()),
|
||||
metronome,
|
||||
config_.encoder_selector)),
|
||||
encoder_feedback_(
|
||||
clock,
|
||||
&env_.clock(),
|
||||
SupportsPerLayerPictureLossIndication(
|
||||
encoder_config.video_format.parameters),
|
||||
config_.rtp.ssrcs,
|
||||
|
@ -438,18 +437,16 @@ VideoSendStreamImpl::VideoSendStreamImpl(
|
|||
&encoder_feedback_,
|
||||
&stats_proxy_,
|
||||
&send_packet_observer_),
|
||||
event_log,
|
||||
&env_.event_log(),
|
||||
std::move(fec_controller),
|
||||
CreateFrameEncryptionConfig(&config_),
|
||||
config_.frame_transformer)),
|
||||
clock_(clock),
|
||||
has_alr_probing_(
|
||||
config_.periodic_alr_bandwidth_probing ||
|
||||
GetAlrSettings(field_trials, encoder_config.content_type)),
|
||||
pacing_config_(PacingConfig(field_trials)),
|
||||
GetAlrSettings(env_.field_trials(), encoder_config.content_type)),
|
||||
pacing_config_(PacingConfig(env_.field_trials())),
|
||||
worker_queue_(TaskQueueBase::Current()),
|
||||
timed_out_(false),
|
||||
|
||||
bitrate_allocator_(bitrate_allocator),
|
||||
has_active_encodings_(HasActiveEncodings(encoder_config)),
|
||||
disable_padding_(true),
|
||||
|
@ -460,11 +457,13 @@ VideoSendStreamImpl::VideoSendStreamImpl(
|
|||
encoder_target_rate_bps_(0),
|
||||
encoder_bitrate_priority_(encoder_config.bitrate_priority),
|
||||
encoder_av1_priority_bitrate_override_bps_(
|
||||
GetEncoderPriorityBitrate(config_.rtp.payload_name, field_trials)),
|
||||
configured_pacing_factor_(GetConfiguredPacingFactor(config_,
|
||||
content_type_,
|
||||
pacing_config_,
|
||||
field_trials)) {
|
||||
GetEncoderPriorityBitrate(config_.rtp.payload_name,
|
||||
env_.field_trials())),
|
||||
configured_pacing_factor_(
|
||||
GetConfiguredPacingFactor(config_,
|
||||
content_type_,
|
||||
pacing_config_,
|
||||
env_.field_trials())) {
|
||||
RTC_DCHECK_GE(config_.rtp.payload_type, 0);
|
||||
RTC_DCHECK_LE(config_.rtp.payload_type, 127);
|
||||
RTC_DCHECK(!config_.rtp.ssrcs.empty());
|
||||
|
@ -472,7 +471,8 @@ VideoSendStreamImpl::VideoSendStreamImpl(
|
|||
RTC_DCHECK_NE(encoder_max_bitrate_bps_, 0);
|
||||
RTC_LOG(LS_INFO) << "VideoSendStreamImpl: " << config_.ToString();
|
||||
|
||||
RTC_CHECK(AlrExperimentSettings::MaxOneFieldTrialEnabled(field_trials));
|
||||
RTC_CHECK(
|
||||
AlrExperimentSettings::MaxOneFieldTrialEnabled(env_.field_trials()));
|
||||
|
||||
absl::optional<bool> enable_alr_bw_probing;
|
||||
|
||||
|
@ -480,14 +480,14 @@ VideoSendStreamImpl::VideoSendStreamImpl(
|
|||
// pacing settings.
|
||||
if (configured_pacing_factor_) {
|
||||
absl::optional<AlrExperimentSettings> alr_settings =
|
||||
GetAlrSettings(field_trials, content_type_);
|
||||
GetAlrSettings(env_.field_trials(), content_type_);
|
||||
int queue_time_limit_ms;
|
||||
if (alr_settings) {
|
||||
enable_alr_bw_probing = true;
|
||||
queue_time_limit_ms = alr_settings->max_paced_queue_time;
|
||||
} else {
|
||||
RateControlSettings rate_control_settings =
|
||||
RateControlSettings::ParseFromKeyValueConfig(&field_trials);
|
||||
RateControlSettings::ParseFromKeyValueConfig(&env_.field_trials());
|
||||
enable_alr_bw_probing = rate_control_settings.UseAlrProbing();
|
||||
queue_time_limit_ms = pacing_config_.max_pacing_delay.Get().ms();
|
||||
}
|
||||
|
@ -720,7 +720,7 @@ void VideoSendStreamImpl::OnBitrateAllocationUpdated(
|
|||
if (encoder_target_rate_bps_ == 0) {
|
||||
return;
|
||||
}
|
||||
int64_t now_ms = clock_->TimeInMilliseconds();
|
||||
int64_t now_ms = env_.clock().TimeInMilliseconds();
|
||||
if (video_bitrate_allocation_context_) {
|
||||
// If new allocation is within kMaxVbaSizeDifferencePercent larger
|
||||
// than the previously sent allocation and the same streams are still
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "absl/types/optional.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "api/metronome/metronome.h"
|
||||
#include "api/task_queue/pending_task_safety_flag.h"
|
||||
|
@ -73,21 +74,18 @@ class VideoSendStreamImpl : public webrtc::VideoSendStream,
|
|||
using RtpStateMap = std::map<uint32_t, RtpState>;
|
||||
using RtpPayloadStateMap = std::map<uint32_t, RtpPayloadState>;
|
||||
|
||||
VideoSendStreamImpl(Clock* clock,
|
||||
VideoSendStreamImpl(const Environment& env,
|
||||
int num_cpu_cores,
|
||||
TaskQueueFactory* task_queue_factory,
|
||||
RtcpRttStats* call_stats,
|
||||
RtpTransportControllerSendInterface* transport,
|
||||
Metronome* metronome,
|
||||
BitrateAllocatorInterface* bitrate_allocator,
|
||||
SendDelayStats* send_delay_stats,
|
||||
RtcEventLog* event_log,
|
||||
VideoSendStream::Config config,
|
||||
VideoEncoderConfig encoder_config,
|
||||
const RtpStateMap& suspended_ssrcs,
|
||||
const RtpPayloadStateMap& suspended_payload_states,
|
||||
std::unique_ptr<FecController> fec_controller,
|
||||
const FieldTrialsView& field_trials,
|
||||
std::unique_ptr<VideoStreamEncoderInterface>
|
||||
video_stream_encoder_for_test = nullptr);
|
||||
~VideoSendStreamImpl() override;
|
||||
|
@ -187,6 +185,7 @@ class VideoSendStreamImpl : public webrtc::VideoSendStream,
|
|||
MediaStreamAllocationConfig GetAllocationConfig() const
|
||||
RTC_RUN_ON(thread_checker_);
|
||||
|
||||
const Environment env_;
|
||||
RTC_NO_UNIQUE_ADDRESS SequenceChecker thread_checker_;
|
||||
|
||||
RtpTransportControllerSendInterface* const transport_;
|
||||
|
@ -200,7 +199,6 @@ class VideoSendStreamImpl : public webrtc::VideoSendStream,
|
|||
RtpVideoSenderInterface* const rtp_video_sender_;
|
||||
bool running_ RTC_GUARDED_BY(thread_checker_) = false;
|
||||
|
||||
Clock* const clock_;
|
||||
const bool has_alr_probing_;
|
||||
const PacingConfig pacing_config_;
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "absl/types/optional.h"
|
||||
#include "api/array_view.h"
|
||||
#include "api/call/bitrate_allocation.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/rtc_event_log/rtc_event_log.h"
|
||||
#include "api/rtp_parameters.h"
|
||||
#include "api/task_queue/task_queue_base.h"
|
||||
|
@ -193,14 +195,14 @@ class VideoSendStreamImplTest : public ::testing::Test {
|
|||
video_stream_encoder_ = video_stream_encoder.get();
|
||||
|
||||
auto ret = std::make_unique<VideoSendStreamImpl>(
|
||||
time_controller_.GetClock(),
|
||||
/*num_cpu_cores=*/1, time_controller_.GetTaskQueueFactory(),
|
||||
CreateEnvironment(&field_trials_, time_controller_.GetClock(),
|
||||
time_controller_.GetTaskQueueFactory()),
|
||||
/*num_cpu_cores=*/1,
|
||||
/*call_stats=*/nullptr, &transport_controller_,
|
||||
/*metronome=*/nullptr, &bitrate_allocator_, &send_delay_stats_,
|
||||
/*event_log=*/nullptr, config_.Copy(), std::move(encoder_config),
|
||||
suspended_ssrcs, suspended_payload_states,
|
||||
/*fec_controller=*/nullptr, field_trials_,
|
||||
std::move(video_stream_encoder));
|
||||
config_.Copy(), std::move(encoder_config), suspended_ssrcs,
|
||||
suspended_payload_states,
|
||||
/*fec_controller=*/nullptr, std::move(video_stream_encoder));
|
||||
|
||||
// The call to GetStartBitrate() executes asynchronously on the tq.
|
||||
// Ensure all tasks get to run.
|
||||
|
|
|
@ -645,7 +645,7 @@ class VideoStreamEncoder::DegradationPreferenceManager
|
|||
};
|
||||
|
||||
VideoStreamEncoder::VideoStreamEncoder(
|
||||
Clock* clock,
|
||||
const Environment& env,
|
||||
uint32_t number_of_cores,
|
||||
VideoStreamEncoderObserver* encoder_stats_observer,
|
||||
const VideoStreamEncoderSettings& settings,
|
||||
|
@ -654,15 +654,14 @@ VideoStreamEncoder::VideoStreamEncoder(
|
|||
std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter>
|
||||
encoder_queue,
|
||||
BitrateAllocationCallbackType allocation_cb_type,
|
||||
const FieldTrialsView& field_trials,
|
||||
webrtc::VideoEncoderFactory::EncoderSelectorInterface* encoder_selector)
|
||||
: field_trials_(field_trials),
|
||||
: env_(env),
|
||||
worker_queue_(TaskQueueBase::Current()),
|
||||
number_of_cores_(number_of_cores),
|
||||
settings_(settings),
|
||||
allocation_cb_type_(allocation_cb_type),
|
||||
rate_control_settings_(
|
||||
RateControlSettings::ParseFromKeyValueConfig(&field_trials)),
|
||||
RateControlSettings::ParseFromKeyValueConfig(&env_.field_trials())),
|
||||
encoder_selector_from_constructor_(encoder_selector),
|
||||
encoder_selector_from_factory_(
|
||||
encoder_selector_from_constructor_
|
||||
|
@ -673,10 +672,9 @@ VideoStreamEncoder::VideoStreamEncoder(
|
|||
: encoder_selector_from_factory_.get()),
|
||||
encoder_stats_observer_(encoder_stats_observer),
|
||||
frame_cadence_adapter_(std::move(frame_cadence_adapter)),
|
||||
clock_(clock),
|
||||
delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() -
|
||||
clock_->TimeInMilliseconds()),
|
||||
last_frame_log_ms_(clock_->TimeInMilliseconds()),
|
||||
delta_ntp_internal_ms_(env_.clock().CurrentNtpInMilliseconds() -
|
||||
env_.clock().TimeInMilliseconds()),
|
||||
last_frame_log_ms_(env_.clock().TimeInMilliseconds()),
|
||||
next_frame_types_(1, VideoFrameType::kVideoFrameDelta),
|
||||
automatic_animation_detection_experiment_(
|
||||
ParseAutomatincAnimationDetectionFieldTrial()),
|
||||
|
@ -684,28 +682,29 @@ VideoStreamEncoder::VideoStreamEncoder(
|
|||
video_stream_adapter_(
|
||||
std::make_unique<VideoStreamAdapter>(&input_state_provider_,
|
||||
encoder_stats_observer,
|
||||
field_trials)),
|
||||
env_.field_trials())),
|
||||
degradation_preference_manager_(
|
||||
std::make_unique<DegradationPreferenceManager>(
|
||||
video_stream_adapter_.get())),
|
||||
stream_resource_manager_(&input_state_provider_,
|
||||
encoder_stats_observer,
|
||||
clock_,
|
||||
&env_.clock(),
|
||||
settings_.experiment_cpu_load_estimator,
|
||||
std::move(overuse_detector),
|
||||
degradation_preference_manager_.get(),
|
||||
field_trials),
|
||||
env_.field_trials()),
|
||||
video_source_sink_controller_(/*sink=*/frame_cadence_adapter_.get(),
|
||||
/*source=*/nullptr),
|
||||
default_limits_allowed_(
|
||||
!field_trials.IsEnabled("WebRTC-DefaultBitrateLimitsKillSwitch")),
|
||||
default_limits_allowed_(!env_.field_trials().IsEnabled(
|
||||
"WebRTC-DefaultBitrateLimitsKillSwitch")),
|
||||
qp_parsing_allowed_(
|
||||
!field_trials.IsEnabled("WebRTC-QpParsingKillSwitch")),
|
||||
switch_encoder_on_init_failures_(!field_trials.IsDisabled(
|
||||
!env_.field_trials().IsEnabled("WebRTC-QpParsingKillSwitch")),
|
||||
switch_encoder_on_init_failures_(!env_.field_trials().IsDisabled(
|
||||
kSwitchEncoderOnInitializationFailuresFieldTrial)),
|
||||
vp9_low_tier_core_threshold_(
|
||||
ParseVp9LowTierCoreCountThreshold(field_trials)),
|
||||
experimental_encoder_thread_limit_(ParseEncoderThreadLimit(field_trials)),
|
||||
ParseVp9LowTierCoreCountThreshold(env_.field_trials())),
|
||||
experimental_encoder_thread_limit_(
|
||||
ParseEncoderThreadLimit(env_.field_trials())),
|
||||
encoder_queue_(std::move(encoder_queue)) {
|
||||
TRACE_EVENT0("webrtc", "VideoStreamEncoder::VideoStreamEncoder");
|
||||
RTC_DCHECK_RUN_ON(worker_queue_);
|
||||
|
@ -950,7 +949,7 @@ void VideoStreamEncoder::ReconfigureEncoder() {
|
|||
encoder_ = MaybeCreateFrameDumpingEncoderWrapper(
|
||||
settings_.encoder_factory->CreateVideoEncoder(
|
||||
encoder_config_.video_format),
|
||||
field_trials_);
|
||||
env_.field_trials());
|
||||
if (!encoder_) {
|
||||
RTC_LOG(LS_ERROR) << "CreateVideoEncoder failed, failing encoder format: "
|
||||
<< encoder_config_.video_format.ToString();
|
||||
|
@ -986,7 +985,7 @@ void VideoStreamEncoder::ReconfigureEncoder() {
|
|||
webrtc::VideoEncoderConfig::ContentType::kScreen,
|
||||
encoder_config_.legacy_conference_mode, encoder_->GetEncoderInfo(),
|
||||
MergeRestrictions({latest_restrictions_, animate_restrictions_}),
|
||||
&field_trials_);
|
||||
&env_.field_trials());
|
||||
|
||||
streams = factory->CreateEncoderStreams(
|
||||
last_frame_info_->width, last_frame_info_->height, encoder_config_);
|
||||
|
@ -1362,13 +1361,13 @@ void VideoStreamEncoder::ReconfigureEncoder() {
|
|||
// * We have screensharing with layers.
|
||||
// * "WebRTC-FrameDropper" field trial is "Disabled".
|
||||
force_disable_frame_dropper_ =
|
||||
field_trials_.IsDisabled(kFrameDropperFieldTrial) ||
|
||||
env_.field_trials().IsDisabled(kFrameDropperFieldTrial) ||
|
||||
(num_layers > 1 && codec.mode == VideoCodecMode::kScreensharing);
|
||||
|
||||
const VideoEncoder::EncoderInfo info = encoder_->GetEncoderInfo();
|
||||
if (rate_control_settings_.UseEncoderBitrateAdjuster()) {
|
||||
bitrate_adjuster_ =
|
||||
std::make_unique<EncoderBitrateAdjuster>(codec, field_trials_);
|
||||
std::make_unique<EncoderBitrateAdjuster>(codec, env_.field_trials());
|
||||
bitrate_adjuster_->OnEncoderInfo(info);
|
||||
}
|
||||
|
||||
|
@ -1787,7 +1786,7 @@ void VideoStreamEncoder::MaybeEncodeVideoFrame(const VideoFrame& video_frame,
|
|||
uint32_t framerate_fps = GetInputFramerateFps();
|
||||
frame_cadence_adapter_->UpdateFrameRate();
|
||||
|
||||
int64_t now_ms = clock_->TimeInMilliseconds();
|
||||
int64_t now_ms = env_.clock().TimeInMilliseconds();
|
||||
if (pending_encoder_reconfiguration_) {
|
||||
ReconfigureEncoder();
|
||||
last_parameters_update_ms_.emplace(now_ms);
|
||||
|
@ -1936,7 +1935,7 @@ void VideoStreamEncoder::EncodeVideoFrame(const VideoFrame& video_frame,
|
|||
}
|
||||
}
|
||||
encoder_info_ = info;
|
||||
last_encode_info_ms_ = clock_->TimeInMilliseconds();
|
||||
last_encode_info_ms_ = env_.clock().TimeInMilliseconds();
|
||||
|
||||
VideoFrame out_frame(video_frame);
|
||||
// Crop or scale the frame if needed. Dimension may be reduced to fit encoder
|
||||
|
@ -2198,7 +2197,7 @@ EncodedImageCallback::Result VideoStreamEncoder::OnEncodedImage(
|
|||
temporal_index = 0;
|
||||
}
|
||||
|
||||
RunPostEncode(image_copy, clock_->CurrentTime().us(), temporal_index,
|
||||
RunPostEncode(image_copy, env_.clock().CurrentTime().us(), temporal_index,
|
||||
frame_size);
|
||||
|
||||
if (result.error == Result::OK) {
|
||||
|
@ -2319,7 +2318,7 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate,
|
|||
!DropDueToSize(pending_frame_->size())) {
|
||||
// A pending stored frame can be processed.
|
||||
int64_t pending_time_us =
|
||||
clock_->CurrentTime().us() - pending_frame_post_time_us_;
|
||||
env_.clock().CurrentTime().us() - pending_frame_post_time_us_;
|
||||
if (pending_time_us < kPendingFrameTimeoutMs * 1000)
|
||||
EncodeVideoFrame(*pending_frame_, pending_frame_post_time_us_);
|
||||
pending_frame_.reset();
|
||||
|
@ -2450,8 +2449,8 @@ VideoStreamEncoder::AutomaticAnimationDetectionExperiment
|
|||
VideoStreamEncoder::ParseAutomatincAnimationDetectionFieldTrial() const {
|
||||
AutomaticAnimationDetectionExperiment result;
|
||||
|
||||
result.Parser()->Parse(
|
||||
field_trials_.Lookup("WebRTC-AutomaticAnimationDetectionScreenshare"));
|
||||
result.Parser()->Parse(env_.field_trials().Lookup(
|
||||
"WebRTC-AutomaticAnimationDetectionScreenshare"));
|
||||
|
||||
if (!result.enabled) {
|
||||
RTC_LOG(LS_INFO) << "Automatic animation detection experiment is disabled.";
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
#include "absl/container/inlined_vector.h"
|
||||
#include "api/adaptation/resource.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/rtp_sender_interface.h"
|
||||
#include "api/sequence_checker.h"
|
||||
#include "api/task_queue/pending_task_safety_flag.h"
|
||||
|
@ -43,7 +43,6 @@
|
|||
#include "rtc_base/race_checker.h"
|
||||
#include "rtc_base/rate_statistics.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "video/adaptation/video_stream_encoder_resource_manager.h"
|
||||
#include "video/encoder_bitrate_adjuster.h"
|
||||
#include "video/frame_cadence_adapter.h"
|
||||
|
@ -74,7 +73,7 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
|
|||
kVideoLayersAllocation
|
||||
};
|
||||
VideoStreamEncoder(
|
||||
Clock* clock,
|
||||
const Environment& env,
|
||||
uint32_t number_of_cores,
|
||||
VideoStreamEncoderObserver* encoder_stats_observer,
|
||||
const VideoStreamEncoderSettings& settings,
|
||||
|
@ -83,7 +82,6 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
|
|||
std::unique_ptr<webrtc::TaskQueueBase, webrtc::TaskQueueDeleter>
|
||||
encoder_queue,
|
||||
BitrateAllocationCallbackType allocation_cb_type,
|
||||
const FieldTrialsView& field_trials,
|
||||
webrtc::VideoEncoderFactory::EncoderSelectorInterface* encoder_selector =
|
||||
nullptr);
|
||||
~VideoStreamEncoder() override;
|
||||
|
@ -270,7 +268,7 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
|
|||
VideoStreamEncoderObserver::DropReason reason)
|
||||
RTC_RUN_ON(encoder_queue_);
|
||||
|
||||
const FieldTrialsView& field_trials_;
|
||||
const Environment env_;
|
||||
TaskQueueBase* const worker_queue_;
|
||||
|
||||
const int number_of_cores_;
|
||||
|
@ -331,7 +329,6 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
|
|||
RTC_GUARDED_BY(encoder_queue_) = false;
|
||||
|
||||
bool encoder_failed_ RTC_GUARDED_BY(encoder_queue_) = false;
|
||||
Clock* const clock_;
|
||||
|
||||
// Used to make sure incoming time stamp is increasing for every frame.
|
||||
int64_t last_captured_timestamp_ RTC_GUARDED_BY(encoder_queue_) = 0;
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
#include <utility>
|
||||
|
||||
#include "absl/memory/memory.h"
|
||||
#include "api/environment/environment.h"
|
||||
#include "api/environment/environment_factory.h"
|
||||
#include "api/field_trials_view.h"
|
||||
#include "api/rtp_parameters.h"
|
||||
#include "api/task_queue/default_task_queue_factory.h"
|
||||
|
@ -381,17 +383,17 @@ class VideoStreamEncoderUnderTest : public VideoStreamEncoder {
|
|||
allocation_callback_type,
|
||||
const FieldTrialsView& field_trials,
|
||||
int num_cores)
|
||||
: VideoStreamEncoder(time_controller->GetClock(),
|
||||
num_cores,
|
||||
stats_proxy,
|
||||
settings,
|
||||
std::unique_ptr<OveruseFrameDetector>(
|
||||
overuse_detector_proxy_ =
|
||||
new CpuOveruseDetectorProxy(stats_proxy)),
|
||||
std::move(cadence_adapter),
|
||||
std::move(encoder_queue),
|
||||
allocation_callback_type,
|
||||
field_trials),
|
||||
: VideoStreamEncoder(
|
||||
CreateEnvironment(&field_trials, time_controller->GetClock()),
|
||||
num_cores,
|
||||
stats_proxy,
|
||||
settings,
|
||||
std::unique_ptr<OveruseFrameDetector>(
|
||||
overuse_detector_proxy_ =
|
||||
new CpuOveruseDetectorProxy(stats_proxy)),
|
||||
std::move(cadence_adapter),
|
||||
std::move(encoder_queue),
|
||||
allocation_callback_type),
|
||||
time_controller_(time_controller),
|
||||
fake_cpu_resource_(FakeResource::Create("FakeResource[CPU]")),
|
||||
fake_quality_resource_(FakeResource::Create("FakeResource[QP]")),
|
||||
|
@ -693,15 +695,15 @@ class SimpleVideoStreamEncoderFactory {
|
|||
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> encoder_queue,
|
||||
const FieldTrialsView* field_trials = nullptr) {
|
||||
auto result = std::make_unique<AdaptedVideoStreamEncoder>(
|
||||
time_controller_.GetClock(),
|
||||
CreateEnvironment(&field_trials_, field_trials,
|
||||
time_controller_.GetClock()),
|
||||
/*number_of_cores=*/1,
|
||||
/*stats_proxy=*/stats_proxy_.get(), encoder_settings_,
|
||||
std::make_unique<CpuOveruseDetectorProxy>(
|
||||
/*stats_proxy=*/nullptr),
|
||||
std::move(zero_hertz_adapter), std::move(encoder_queue),
|
||||
VideoStreamEncoder::BitrateAllocationCallbackType::
|
||||
kVideoBitrateAllocation,
|
||||
field_trials ? *field_trials : field_trials_);
|
||||
kVideoBitrateAllocation);
|
||||
result->SetSink(&sink_, /*rotation_applied=*/false);
|
||||
return result;
|
||||
}
|
||||
|
@ -9230,11 +9232,12 @@ TEST(VideoStreamEncoderSimpleTest, CreateDestroy) {
|
|||
};
|
||||
|
||||
// Lots of boiler plate.
|
||||
test::ScopedKeyValueConfig field_trials;
|
||||
GlobalSimulatedTimeController time_controller(Timestamp::Zero());
|
||||
auto stats_proxy = std::make_unique<MockableSendStatisticsProxy>(
|
||||
time_controller.GetClock(), VideoSendStream::Config(nullptr),
|
||||
webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo, field_trials);
|
||||
Environment env = CreateEnvironment(time_controller.GetClock());
|
||||
MockableSendStatisticsProxy stats_proxy(
|
||||
&env.clock(), VideoSendStream::Config(nullptr),
|
||||
webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo,
|
||||
env.field_trials());
|
||||
SimpleVideoStreamEncoderFactory::MockFakeEncoder mock_fake_encoder(
|
||||
time_controller.GetClock());
|
||||
test::VideoEncoderProxyFactory encoder_factory(&mock_fake_encoder);
|
||||
|
@ -9252,20 +9255,19 @@ TEST(VideoStreamEncoderSimpleTest, CreateDestroy) {
|
|||
encoder_queue(new SuperLazyTaskQueue());
|
||||
|
||||
// Construct a VideoStreamEncoder instance and let it go out of scope without
|
||||
// doing anything else (including calling Stop()). This should be fine since
|
||||
// the posted init task will simply be deleted.
|
||||
auto encoder = std::make_unique<VideoStreamEncoder>(
|
||||
time_controller.GetClock(), 1, stats_proxy.get(), encoder_settings,
|
||||
std::make_unique<CpuOveruseDetectorProxy>(stats_proxy.get()),
|
||||
// doing anything else. This should be fine since the posted init task will
|
||||
// simply be deleted.
|
||||
VideoStreamEncoder encoder(
|
||||
env, 1, &stats_proxy, encoder_settings,
|
||||
std::make_unique<CpuOveruseDetectorProxy>(&stats_proxy),
|
||||
std::move(adapter), std::move(encoder_queue),
|
||||
VideoStreamEncoder::BitrateAllocationCallbackType::
|
||||
kVideoBitrateAllocation,
|
||||
field_trials);
|
||||
kVideoBitrateAllocation);
|
||||
|
||||
// Stop the encoder explicitly. This additional step tests if we could
|
||||
// hang when calling stop and the TQ has been stopped and/or isn't accepting
|
||||
// any more tasks.
|
||||
encoder->Stop();
|
||||
encoder.Stop();
|
||||
}
|
||||
|
||||
TEST(VideoStreamEncoderFrameCadenceTest, ActivatesFrameCadenceOnContentType) {
|
||||
|
|
Loading…
Reference in a new issue