Reland "[WebRTC-SendPacketsOnWorkerThread] Cleanup VideoSendStream(Impl)"
This reverts commit 779aadeb2e2041d5ae18439cf26aa61f591d2556. Reason for revert: Downstream project fixed. Original change's description: > Revert "[WebRTC-SendPacketsOnWorkerThread] Cleanup VideoSendStream(Impl)" > > This reverts commit 77c47947ad098e4182a6244cb998e4fa8c7bd37e. > > Reason for revert: Breaks downstream project. > > Original change's description: > > [WebRTC-SendPacketsOnWorkerThread] Cleanup VideoSendStream(Impl) > > > > Cleanup and remove usage of MaybeWorkerThread from VideoSendStream. > > VideoSendStream is now created and lives on the worker thread. > > > > Bug: webrtc:14502 > > Change-Id: I81ccf6b9fc6e8889db81b09bd4a75a3831a003e2 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300842 > > Reviewed-by: Erik Språng <sprang@webrtc.org> > > Commit-Queue: Per Kjellander <perkj@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#39814} > > Bug: webrtc:14502 > Change-Id: Ic969071d8797204851ecbaeea3b37f9256303d3d > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300962 > Owners-Override: Mirko Bonadei <mbonadei@webrtc.org> > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> > Auto-Submit: Mirko Bonadei <mbonadei@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#39819} Bug: webrtc:14502 Change-Id: I5e63dcd01a3d157ed08e14650468368b144f1908 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/300865 Reviewed-by: Erik Språng <sprang@webrtc.org> Commit-Queue: Per Kjellander <perkj@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39829}
This commit is contained in:
parent
50b0a76ee7
commit
08dcd7a526
@ -124,7 +124,6 @@ rtc_library("video") {
|
||||
"../modules/rtp_rtcp",
|
||||
"../modules/rtp_rtcp:rtp_rtcp_format",
|
||||
"../modules/rtp_rtcp:rtp_video_header",
|
||||
"../modules/utility:utility",
|
||||
"../modules/video_coding",
|
||||
"../modules/video_coding:nack_requester",
|
||||
"../modules/video_coding:packet_buffer",
|
||||
|
||||
@ -149,8 +149,7 @@ VideoSendStream::VideoSendStream(
|
||||
const std::map<uint32_t, RtpPayloadState>& suspended_payload_states,
|
||||
std::unique_ptr<FecController> fec_controller,
|
||||
const FieldTrialsView& field_trials)
|
||||
: rtp_transport_queue_(transport->GetWorkerQueue()),
|
||||
transport_(transport),
|
||||
: transport_(transport),
|
||||
stats_proxy_(clock, config, encoder_config.content_type, field_trials),
|
||||
config_(std::move(config)),
|
||||
content_type_(encoder_config.content_type),
|
||||
@ -237,12 +236,7 @@ void VideoSendStream::StartPerRtpStream(const std::vector<bool> active_layers) {
|
||||
}
|
||||
active_layers_string << "}";
|
||||
RTC_LOG(LS_INFO) << "StartPerRtpStream: " << active_layers_string.str();
|
||||
|
||||
rtp_transport_queue_->RunOrPost(
|
||||
SafeTask(transport_queue_safety_, [this, active_layers] {
|
||||
send_stream_.StartPerRtpStream(active_layers);
|
||||
}));
|
||||
|
||||
send_stream_.StartPerRtpStream(active_layers);
|
||||
running_ = running;
|
||||
}
|
||||
|
||||
@ -252,13 +246,7 @@ void VideoSendStream::Stop() {
|
||||
return;
|
||||
RTC_DLOG(LS_INFO) << "VideoSendStream::Stop";
|
||||
running_ = false;
|
||||
rtp_transport_queue_->RunOrPost(SafeTask(transport_queue_safety_, [this] {
|
||||
// As the stream can get re-used and implicitly restarted via changing
|
||||
// the state of the active layers, we do not mark the
|
||||
// `transport_queue_safety_` flag with `SetNotAlive()` here. That's only
|
||||
// done when we stop permanently via `StopPermanentlyAndGetRtpStates()`.
|
||||
send_stream_.Stop();
|
||||
}));
|
||||
send_stream_.Stop();
|
||||
}
|
||||
|
||||
bool VideoSendStream::started() {
|
||||
@ -300,9 +288,7 @@ void VideoSendStream::ReconfigureVideoEncoder(VideoEncoderConfig config,
|
||||
}
|
||||
|
||||
VideoSendStream::Stats VideoSendStream::GetStats() {
|
||||
// TODO(perkj, solenberg): Some test cases in EndToEndTest call GetStats from
|
||||
// a network thread. See comment in Call::GetStats().
|
||||
// RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
return stats_proxy_.GetStats();
|
||||
}
|
||||
|
||||
@ -320,13 +306,9 @@ void VideoSendStream::StopPermanentlyAndGetRtpStates(
|
||||
// Always run these cleanup steps regardless of whether running_ was set
|
||||
// or not. This will unregister callbacks before destruction.
|
||||
// See `VideoSendStreamImpl::StopVideoSendStream` for more.
|
||||
rtp_transport_queue_->RunSynchronous(
|
||||
[this, rtp_state_map, payload_state_map]() {
|
||||
transport_queue_safety_->SetNotAlive();
|
||||
send_stream_.Stop();
|
||||
*rtp_state_map = send_stream_.GetRtpStates();
|
||||
*payload_state_map = send_stream_.GetRtpPayloadStates();
|
||||
});
|
||||
send_stream_.Stop();
|
||||
*rtp_state_map = send_stream_.GetRtpStates();
|
||||
*payload_state_map = send_stream_.GetRtpPayloadStates();
|
||||
}
|
||||
|
||||
void VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
|
||||
@ -335,6 +317,7 @@ void VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
|
||||
}
|
||||
|
||||
void VideoSendStream::GenerateKeyFrame(const std::vector<std::string>& rids) {
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
// Map rids to layers. If rids is empty, generate a keyframe for all layers.
|
||||
std::vector<VideoFrameType> next_frames(config_.rtp.ssrcs.size(),
|
||||
VideoFrameType::kVideoFrameKey);
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
#include "call/bitrate_allocator.h"
|
||||
#include "call/video_receive_stream.h"
|
||||
#include "call/video_send_stream.h"
|
||||
#include "modules/utility/maybe_worker_thread.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/system/no_unique_address.h"
|
||||
#include "video/encoder_rtcp_feedback.h"
|
||||
@ -104,11 +103,7 @@ class VideoSendStream : public webrtc::VideoSendStream {
|
||||
absl::optional<float> GetPacingFactorOverride() const;
|
||||
|
||||
RTC_NO_UNIQUE_ADDRESS SequenceChecker thread_checker_;
|
||||
MaybeWorkerThread* const rtp_transport_queue_;
|
||||
RtpTransportControllerSendInterface* const transport_;
|
||||
rtc::Event thread_sync_event_;
|
||||
rtc::scoped_refptr<PendingTaskSafetyFlag> transport_queue_safety_ =
|
||||
PendingTaskSafetyFlag::CreateDetached();
|
||||
|
||||
SendStatisticsProxy stats_proxy_;
|
||||
const VideoSendStream::Config config_;
|
||||
|
||||
@ -233,7 +233,7 @@ VideoSendStreamImpl::VideoSendStreamImpl(
|
||||
pacing_config_(PacingConfig(field_trials)),
|
||||
stats_proxy_(stats_proxy),
|
||||
config_(config),
|
||||
rtp_transport_queue_(transport->GetWorkerQueue()),
|
||||
worker_queue_(TaskQueueBase::Current()),
|
||||
timed_out_(false),
|
||||
transport_(transport),
|
||||
bitrate_allocator_(bitrate_allocator),
|
||||
@ -298,33 +298,26 @@ VideoSendStreamImpl::VideoSendStreamImpl(
|
||||
transport->EnablePeriodicAlrProbing(*enable_alr_bw_probing);
|
||||
}
|
||||
|
||||
rtp_transport_queue_->RunOrPost(SafeTask(transport_queue_safety_, [this] {
|
||||
if (configured_pacing_factor_)
|
||||
transport_->SetPacingFactor(*configured_pacing_factor_);
|
||||
if (configured_pacing_factor_)
|
||||
transport_->SetPacingFactor(*configured_pacing_factor_);
|
||||
|
||||
video_stream_encoder_->SetStartBitrate(
|
||||
bitrate_allocator_->GetStartBitrate(this));
|
||||
}));
|
||||
video_stream_encoder_->SetStartBitrate(
|
||||
bitrate_allocator_->GetStartBitrate(this));
|
||||
}
|
||||
|
||||
VideoSendStreamImpl::~VideoSendStreamImpl() {
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RTC_LOG(LS_INFO) << "~VideoSendStreamImpl: " << config_->ToString();
|
||||
// TODO(webrtc:14502): Change `transport_queue_safety_` to be of type
|
||||
// ScopedTaskSafety if experiment WebRTC-SendPacketsOnWorkerThread succeed.
|
||||
if (rtp_transport_queue_->IsCurrent()) {
|
||||
transport_queue_safety_->SetNotAlive();
|
||||
}
|
||||
}
|
||||
|
||||
void VideoSendStreamImpl::DeliverRtcp(const uint8_t* packet, size_t length) {
|
||||
// Runs on a worker thread.
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
rtp_video_sender_->DeliverRtcp(packet, length);
|
||||
}
|
||||
|
||||
void VideoSendStreamImpl::StartPerRtpStream(
|
||||
const std::vector<bool> active_layers) {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
bool previously_active = rtp_video_sender_->IsActive();
|
||||
rtp_video_sender_->SetActiveModules(active_layers);
|
||||
if (!rtp_video_sender_->IsActive() && previously_active) {
|
||||
@ -335,8 +328,7 @@ void VideoSendStreamImpl::StartPerRtpStream(
|
||||
}
|
||||
|
||||
void VideoSendStreamImpl::StartupVideoSendStream() {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
transport_queue_safety_->SetAlive();
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
|
||||
bitrate_allocator_->AddObserver(this, GetAllocationConfig());
|
||||
// Start monitoring encoder activity.
|
||||
@ -346,9 +338,8 @@ void VideoSendStreamImpl::StartupVideoSendStream() {
|
||||
activity_ = false;
|
||||
timed_out_ = false;
|
||||
check_encoder_activity_task_ = RepeatingTaskHandle::DelayedStart(
|
||||
rtp_transport_queue_->TaskQueueForDelayedTasks(), kEncoderTimeOut,
|
||||
[this] {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
worker_queue_, kEncoderTimeOut, [this] {
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
if (!activity_) {
|
||||
if (!timed_out_) {
|
||||
SignalEncoderTimedOut();
|
||||
@ -368,29 +359,27 @@ void VideoSendStreamImpl::StartupVideoSendStream() {
|
||||
}
|
||||
|
||||
void VideoSendStreamImpl::Stop() {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RTC_LOG(LS_INFO) << "VideoSendStreamImpl::Stop";
|
||||
if (!rtp_video_sender_->IsActive())
|
||||
return;
|
||||
|
||||
RTC_DCHECK(transport_queue_safety_->alive());
|
||||
TRACE_EVENT_INSTANT0("webrtc", "VideoSendStream::Stop");
|
||||
rtp_video_sender_->Stop();
|
||||
StopVideoSendStream();
|
||||
}
|
||||
|
||||
void VideoSendStreamImpl::StopVideoSendStream() {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
bitrate_allocator_->RemoveObserver(this);
|
||||
check_encoder_activity_task_.Stop();
|
||||
video_stream_encoder_->OnBitrateUpdated(DataRate::Zero(), DataRate::Zero(),
|
||||
DataRate::Zero(), 0, 0, 0);
|
||||
stats_proxy_->OnSetEncoderTargetRate(0);
|
||||
transport_queue_safety_->SetNotAlive();
|
||||
}
|
||||
|
||||
void VideoSendStreamImpl::SignalEncoderTimedOut() {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
// If the encoder has not produced anything the last kEncoderTimeOut and it
|
||||
// is supposed to, deregister as BitrateAllocatorObserver. This can happen
|
||||
// if a camera stops producing frames.
|
||||
@ -403,9 +392,9 @@ void VideoSendStreamImpl::SignalEncoderTimedOut() {
|
||||
void VideoSendStreamImpl::OnBitrateAllocationUpdated(
|
||||
const VideoBitrateAllocation& allocation) {
|
||||
// OnBitrateAllocationUpdated is invoked from the encoder task queue or
|
||||
// the rtp_transport_queue_.
|
||||
auto task = [=] {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
// the worker_queue_.
|
||||
auto task = [this, allocation] {
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
if (encoder_target_rate_bps_ == 0) {
|
||||
return;
|
||||
}
|
||||
@ -441,9 +430,9 @@ void VideoSendStreamImpl::OnBitrateAllocationUpdated(
|
||||
// Send bitrate allocation metadata only if encoder is not paused.
|
||||
rtp_video_sender_->OnBitrateAllocationUpdated(allocation);
|
||||
};
|
||||
if (!rtp_transport_queue_->IsCurrent()) {
|
||||
rtp_transport_queue_->TaskQueueForPost()->PostTask(
|
||||
SafeTask(transport_queue_safety_, std::move(task)));
|
||||
if (!worker_queue_->IsCurrent()) {
|
||||
worker_queue_->PostTask(
|
||||
SafeTask(worker_queue_safety_.flag(), std::move(task)));
|
||||
} else {
|
||||
task();
|
||||
}
|
||||
@ -457,7 +446,7 @@ void VideoSendStreamImpl::OnVideoLayersAllocationUpdated(
|
||||
}
|
||||
|
||||
void VideoSendStreamImpl::SignalEncoderActive() {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
if (rtp_video_sender_->IsActive()) {
|
||||
RTC_LOG(LS_INFO) << "SignalEncoderActive, Encoder is active.";
|
||||
bitrate_allocator_->AddObserver(this, GetAllocationConfig());
|
||||
@ -480,12 +469,12 @@ void VideoSendStreamImpl::OnEncoderConfigurationChanged(
|
||||
VideoEncoderConfig::ContentType content_type,
|
||||
int min_transmit_bitrate_bps) {
|
||||
// Currently called on the encoder TQ
|
||||
RTC_DCHECK(!rtp_transport_queue_->IsCurrent());
|
||||
RTC_DCHECK(!worker_queue_->IsCurrent());
|
||||
auto closure = [this, streams = std::move(streams), is_svc, content_type,
|
||||
min_transmit_bitrate_bps]() mutable {
|
||||
RTC_DCHECK_GE(config_->rtp.ssrcs.size(), streams.size());
|
||||
TRACE_EVENT0("webrtc", "VideoSendStream::OnEncoderConfigurationChanged");
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
|
||||
const VideoCodecType codec_type =
|
||||
PayloadStringToCodecType(config_->rtp.payload_name);
|
||||
@ -537,8 +526,8 @@ void VideoSendStreamImpl::OnEncoderConfigurationChanged(
|
||||
}
|
||||
};
|
||||
|
||||
rtp_transport_queue_->TaskQueueForPost()->PostTask(
|
||||
SafeTask(transport_queue_safety_, std::move(closure)));
|
||||
worker_queue_->PostTask(
|
||||
SafeTask(worker_queue_safety_.flag(), std::move(closure)));
|
||||
}
|
||||
|
||||
EncodedImageCallback::Result VideoSendStreamImpl::OnEncodedImage(
|
||||
@ -550,10 +539,10 @@ EncodedImageCallback::Result VideoSendStreamImpl::OnEncodedImage(
|
||||
|
||||
// Indicate that there still is activity going on.
|
||||
activity_ = true;
|
||||
RTC_DCHECK(!rtp_transport_queue_->IsCurrent());
|
||||
RTC_DCHECK(!worker_queue_->IsCurrent());
|
||||
|
||||
auto task_to_run_on_worker = [this]() {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
if (disable_padding_) {
|
||||
disable_padding_ = false;
|
||||
// To ensure that padding bitrate is propagated to the bitrate allocator.
|
||||
@ -566,8 +555,8 @@ EncodedImageCallback::Result VideoSendStreamImpl::OnEncodedImage(
|
||||
OnBitrateAllocationUpdated(*context->throttled_allocation);
|
||||
}
|
||||
};
|
||||
rtp_transport_queue_->TaskQueueForPost()->PostTask(
|
||||
SafeTask(transport_queue_safety_, std::move(task_to_run_on_worker)));
|
||||
worker_queue_->PostTask(
|
||||
SafeTask(worker_queue_safety_.flag(), std::move(task_to_run_on_worker)));
|
||||
|
||||
return rtp_video_sender_->OnEncodedImage(encoded_image, codec_specific_info);
|
||||
}
|
||||
@ -587,7 +576,7 @@ std::map<uint32_t, RtpPayloadState> VideoSendStreamImpl::GetRtpPayloadStates()
|
||||
}
|
||||
|
||||
uint32_t VideoSendStreamImpl::OnBitrateUpdated(BitrateAllocationUpdate update) {
|
||||
RTC_DCHECK_RUN_ON(rtp_transport_queue_);
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RTC_DCHECK(rtp_video_sender_->IsActive())
|
||||
<< "VideoSendStream::Start has not been called.";
|
||||
|
||||
|
||||
@ -32,7 +32,6 @@
|
||||
#include "call/rtp_video_sender_interface.h"
|
||||
#include "modules/include/module_common_types.h"
|
||||
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
||||
#include "modules/utility/maybe_worker_thread.h"
|
||||
#include "modules/video_coding/include/video_codec_interface.h"
|
||||
#include "rtc_base/experiments/field_trial_parser.h"
|
||||
#include "rtc_base/system/no_unique_address.h"
|
||||
@ -121,14 +120,14 @@ class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver,
|
||||
void StartupVideoSendStream();
|
||||
// Removes the bitrate observer, stops monitoring and notifies the video
|
||||
// encoder of the bitrate update.
|
||||
void StopVideoSendStream() RTC_RUN_ON(rtp_transport_queue_);
|
||||
void StopVideoSendStream() RTC_RUN_ON(thread_checker_);
|
||||
|
||||
void ConfigureProtection();
|
||||
void ConfigureSsrcs();
|
||||
void SignalEncoderTimedOut();
|
||||
void SignalEncoderActive();
|
||||
MediaStreamAllocationConfig GetAllocationConfig() const
|
||||
RTC_RUN_ON(rtp_transport_queue_);
|
||||
RTC_RUN_ON(thread_checker_);
|
||||
|
||||
RTC_NO_UNIQUE_ADDRESS SequenceChecker thread_checker_;
|
||||
Clock* const clock_;
|
||||
@ -138,31 +137,30 @@ class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver,
|
||||
SendStatisticsProxy* const stats_proxy_;
|
||||
const VideoSendStream::Config* const config_;
|
||||
|
||||
MaybeWorkerThread* const rtp_transport_queue_;
|
||||
TaskQueueBase* const worker_queue_;
|
||||
|
||||
RepeatingTaskHandle check_encoder_activity_task_
|
||||
RTC_GUARDED_BY(rtp_transport_queue_);
|
||||
RTC_GUARDED_BY(thread_checker_);
|
||||
|
||||
std::atomic_bool activity_;
|
||||
bool timed_out_ RTC_GUARDED_BY(rtp_transport_queue_);
|
||||
bool timed_out_ RTC_GUARDED_BY(thread_checker_);
|
||||
|
||||
RtpTransportControllerSendInterface* const transport_;
|
||||
BitrateAllocatorInterface* const bitrate_allocator_;
|
||||
|
||||
bool disable_padding_;
|
||||
int max_padding_bitrate_;
|
||||
int encoder_min_bitrate_bps_;
|
||||
uint32_t encoder_max_bitrate_bps_;
|
||||
uint32_t encoder_target_rate_bps_;
|
||||
double encoder_bitrate_priority_;
|
||||
bool disable_padding_ RTC_GUARDED_BY(thread_checker_);
|
||||
int max_padding_bitrate_ RTC_GUARDED_BY(thread_checker_);
|
||||
int encoder_min_bitrate_bps_ RTC_GUARDED_BY(thread_checker_);
|
||||
uint32_t encoder_max_bitrate_bps_ RTC_GUARDED_BY(thread_checker_);
|
||||
uint32_t encoder_target_rate_bps_ RTC_GUARDED_BY(thread_checker_);
|
||||
double encoder_bitrate_priority_ RTC_GUARDED_BY(thread_checker_);
|
||||
|
||||
VideoStreamEncoderInterface* const video_stream_encoder_;
|
||||
|
||||
RtcpBandwidthObserver* const bandwidth_observer_;
|
||||
RtpVideoSenderInterface* const rtp_video_sender_;
|
||||
|
||||
rtc::scoped_refptr<PendingTaskSafetyFlag> transport_queue_safety_ =
|
||||
PendingTaskSafetyFlag::CreateDetached();
|
||||
ScopedTaskSafety worker_queue_safety_;
|
||||
|
||||
// Context for the most recent and last sent video bitrate allocation. Used to
|
||||
// throttle sending of similar bitrate allocations.
|
||||
@ -172,7 +170,7 @@ class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver,
|
||||
int64_t last_send_time_ms;
|
||||
};
|
||||
absl::optional<VbaSendContext> video_bitrate_allocation_context_
|
||||
RTC_GUARDED_BY(rtp_transport_queue_);
|
||||
RTC_GUARDED_BY(thread_checker_);
|
||||
const absl::optional<float> configured_pacing_factor_;
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
#include "call/test/mock_bitrate_allocator.h"
|
||||
#include "call/test/mock_rtp_transport_controller_send.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_sequence_number_map.h"
|
||||
#include "modules/utility/maybe_worker_thread.h"
|
||||
#include "modules/video_coding/fec_controller_default.h"
|
||||
#include "rtc_base/event.h"
|
||||
#include "rtc_base/experiments/alr_experiment.h"
|
||||
@ -123,9 +122,6 @@ class VideoSendStreamImplTest : public ::testing::Test {
|
||||
: time_controller_(Timestamp::Seconds(1000)),
|
||||
config_(&transport_),
|
||||
send_delay_stats_(time_controller_.GetClock()),
|
||||
worker_queue_(field_trials_,
|
||||
"worker_queue",
|
||||
time_controller_.GetTaskQueueFactory()),
|
||||
encoder_queue_(time_controller_.GetTaskQueueFactory()->CreateTaskQueue(
|
||||
"encoder_queue",
|
||||
TaskQueueFactory::Priority::NORMAL)),
|
||||
@ -153,8 +149,6 @@ class VideoSendStreamImplTest : public ::testing::Test {
|
||||
}));
|
||||
ON_CALL(rtp_video_sender_, SetActiveModules)
|
||||
.WillByDefault(::testing::SaveArg<0>(&active_modules_));
|
||||
ON_CALL(transport_controller_, GetWorkerQueue())
|
||||
.WillByDefault(Return(&worker_queue_));
|
||||
}
|
||||
~VideoSendStreamImplTest() {}
|
||||
|
||||
@ -162,8 +156,6 @@ class VideoSendStreamImplTest : public ::testing::Test {
|
||||
int initial_encoder_max_bitrate,
|
||||
double initial_encoder_bitrate_priority,
|
||||
VideoEncoderConfig::ContentType content_type) {
|
||||
RTC_DCHECK_RUN_ON(&worker_queue_);
|
||||
|
||||
EXPECT_CALL(bitrate_allocator_, GetStartBitrate(_))
|
||||
.WillOnce(Return(123000));
|
||||
|
||||
@ -196,7 +188,6 @@ class VideoSendStreamImplTest : public ::testing::Test {
|
||||
RtcEventLogNull event_log_;
|
||||
VideoSendStream::Config config_;
|
||||
SendDelayStats send_delay_stats_;
|
||||
MaybeWorkerThread worker_queue_;
|
||||
std::unique_ptr<TaskQueueBase, TaskQueueDeleter> encoder_queue_;
|
||||
SendStatisticsProxy stats_proxy_;
|
||||
PacketRouter packet_router_;
|
||||
@ -217,11 +208,9 @@ TEST_F(VideoSendStreamImplTest, RegistersAsBitrateObserverOnStart) {
|
||||
EXPECT_EQ(config.enforce_min_bitrate, !kSuspend);
|
||||
EXPECT_EQ(config.bitrate_priority, kDefaultBitratePriority);
|
||||
}));
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
EXPECT_CALL(bitrate_allocator_, RemoveObserver(vss_impl.get())).Times(1);
|
||||
vss_impl->Stop();
|
||||
});
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
EXPECT_CALL(bitrate_allocator_, RemoveObserver(vss_impl.get())).Times(1);
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChange) {
|
||||
@ -233,7 +222,7 @@ TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChange) {
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kRealtimeVideo);
|
||||
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->StartPerRtpStream({true}); });
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
|
||||
// QVGA + VGA configuration matching defaults in
|
||||
// media/engine/simulcast.cc.
|
||||
@ -265,7 +254,6 @@ TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChange) {
|
||||
EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _))
|
||||
.WillRepeatedly(Invoke(
|
||||
[&](BitrateAllocatorObserver*, MediaStreamAllocationConfig config) {
|
||||
EXPECT_TRUE(worker_queue_.IsCurrent());
|
||||
EXPECT_EQ(config.min_bitrate_bps,
|
||||
static_cast<uint32_t>(min_transmit_bitrate_bps));
|
||||
EXPECT_EQ(config.max_bitrate_bps,
|
||||
@ -287,7 +275,7 @@ TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChange) {
|
||||
min_transmit_bitrate_bps);
|
||||
});
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChangeWithAlr) {
|
||||
@ -299,7 +287,7 @@ TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChangeWithAlr) {
|
||||
auto vss_impl = CreateVideoSendStreamImpl(
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kScreen);
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->StartPerRtpStream({true}); });
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
|
||||
// Simulcast screenshare.
|
||||
VideoStream low_stream;
|
||||
@ -334,7 +322,6 @@ TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChangeWithAlr) {
|
||||
EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _))
|
||||
.WillRepeatedly(Invoke(
|
||||
[&](BitrateAllocatorObserver*, MediaStreamAllocationConfig config) {
|
||||
EXPECT_TRUE(worker_queue_.IsCurrent());
|
||||
EXPECT_EQ(config.min_bitrate_bps,
|
||||
static_cast<uint32_t>(low_stream.min_bitrate_bps));
|
||||
EXPECT_EQ(config.max_bitrate_bps,
|
||||
@ -353,7 +340,7 @@ TEST_F(VideoSendStreamImplTest, UpdatesObserverOnConfigurationChangeWithAlr) {
|
||||
VideoEncoderConfig::ContentType::kScreen, min_transmit_bitrate_bps);
|
||||
});
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest,
|
||||
@ -365,7 +352,7 @@ TEST_F(VideoSendStreamImplTest,
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kRealtimeVideo);
|
||||
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->StartPerRtpStream({true}); });
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
// 2-layer video simulcast.
|
||||
VideoStream low_stream;
|
||||
low_stream.width = 320;
|
||||
@ -393,7 +380,6 @@ TEST_F(VideoSendStreamImplTest,
|
||||
EXPECT_CALL(bitrate_allocator_, AddObserver(vss_impl.get(), _))
|
||||
.WillRepeatedly(Invoke([&](BitrateAllocatorObserver*,
|
||||
MediaStreamAllocationConfig config) {
|
||||
EXPECT_TRUE(worker_queue_.IsCurrent());
|
||||
EXPECT_EQ(config.min_bitrate_bps,
|
||||
static_cast<uint32_t>(low_stream.min_bitrate_bps));
|
||||
EXPECT_EQ(config.max_bitrate_bps,
|
||||
@ -414,7 +400,7 @@ TEST_F(VideoSendStreamImplTest,
|
||||
/*min_transmit_bitrate_bps=*/0);
|
||||
});
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, SetsScreensharePacingFactorWithFeedback) {
|
||||
@ -429,10 +415,8 @@ TEST_F(VideoSendStreamImplTest, SetsScreensharePacingFactorWithFeedback) {
|
||||
auto vss_impl = CreateVideoSendStreamImpl(
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kScreen);
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
vss_impl->Stop();
|
||||
});
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, DoesNotSetPacingFactorWithoutFeedback) {
|
||||
@ -440,11 +424,9 @@ TEST_F(VideoSendStreamImplTest, DoesNotSetPacingFactorWithoutFeedback) {
|
||||
auto vss_impl = CreateVideoSendStreamImpl(
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kScreen);
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
EXPECT_CALL(transport_controller_, SetPacingFactor(_)).Times(0);
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
vss_impl->Stop();
|
||||
});
|
||||
EXPECT_CALL(transport_controller_, SetPacingFactor(_)).Times(0);
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationWhenEnabled) {
|
||||
@ -455,7 +437,7 @@ TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationWhenEnabled) {
|
||||
EXPECT_CALL(transport_controller_, SetPacingFactor(_)).Times(0);
|
||||
VideoStreamEncoderInterface::EncoderSink* const sink =
|
||||
static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get());
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->StartPerRtpStream({true}); });
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
// Populate a test instance of video bitrate allocation.
|
||||
VideoBitrateAllocation alloc;
|
||||
alloc.SetBitrate(0, 0, 10000);
|
||||
@ -471,46 +453,40 @@ TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationWhenEnabled) {
|
||||
});
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
// Unpause encoder, allocation should be passed through.
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
});
|
||||
// Unpause encoder, allocation should be passed through.
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)).Times(1);
|
||||
encoder_queue_->PostTask([&] { sink->OnBitrateAllocationUpdated(alloc); });
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
// Pause encoder again, and block allocations.
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(0));
|
||||
});
|
||||
// Pause encoder again, and block allocations.
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(0));
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateAllocationUpdated(alloc)).Times(0);
|
||||
encoder_queue_->PostTask([&] { sink->OnBitrateAllocationUpdated(alloc); });
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, ThrottlesVideoBitrateAllocationWhenTooSimilar) {
|
||||
auto vss_impl = CreateVideoSendStreamImpl(
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kScreen);
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
// Unpause encoder, to allows allocations to be passed through.
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
});
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
// Unpause encoder, to allows allocations to be passed through.
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
VideoStreamEncoderInterface::EncoderSink* const sink =
|
||||
static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get());
|
||||
|
||||
@ -555,7 +531,7 @@ TEST_F(VideoSendStreamImplTest, ThrottlesVideoBitrateAllocationWhenTooSimilar) {
|
||||
[&] { sink->OnBitrateAllocationUpdated(updated_alloc); });
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationOnLayerChange) {
|
||||
@ -563,16 +539,14 @@ TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationOnLayerChange) {
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kScreen);
|
||||
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
// Unpause encoder, to allows allocations to be passed through.
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
});
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
// Unpause encoder, to allows allocations to be passed through.
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
VideoStreamEncoderInterface::EncoderSink* const sink =
|
||||
static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get());
|
||||
|
||||
@ -599,23 +573,21 @@ TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationOnLayerChange) {
|
||||
[&] { sink->OnBitrateAllocationUpdated(updated_alloc); });
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationAfterTimeout) {
|
||||
auto vss_impl = CreateVideoSendStreamImpl(
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kScreen);
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
// Unpause encoder, to allows allocations to be passed through.
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillRepeatedly(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
});
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
// Unpause encoder, to allows allocations to be passed through.
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillRepeatedly(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
VideoStreamEncoderInterface::EncoderSink* const sink =
|
||||
static_cast<VideoStreamEncoderInterface::EncoderSink*>(vss_impl.get());
|
||||
|
||||
@ -706,7 +678,7 @@ TEST_F(VideoSendStreamImplTest, ForwardsVideoBitrateAllocationAfterTimeout) {
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
}
|
||||
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, CallsVideoStreamEncoderOnBitrateUpdate) {
|
||||
@ -717,7 +689,7 @@ TEST_F(VideoSendStreamImplTest, CallsVideoStreamEncoderOnBitrateUpdate) {
|
||||
auto vss_impl = CreateVideoSendStreamImpl(
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kRealtimeVideo);
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->StartPerRtpStream({true}); });
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
VideoStream qvga_stream;
|
||||
qvga_stream.width = 320;
|
||||
qvga_stream.height = 180;
|
||||
@ -741,76 +713,74 @@ TEST_F(VideoSendStreamImplTest, CallsVideoStreamEncoderOnBitrateUpdate) {
|
||||
});
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
const DataRate network_constrained_rate =
|
||||
DataRate::BitsPerSec(qvga_stream.target_bitrate_bps);
|
||||
BitrateAllocationUpdate update;
|
||||
update.target_bitrate = network_constrained_rate;
|
||||
update.stable_target_bitrate = network_constrained_rate;
|
||||
update.round_trip_time = TimeDelta::Millis(1);
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _));
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.WillOnce(Return(network_constrained_rate.bps()));
|
||||
EXPECT_CALL(
|
||||
video_stream_encoder_,
|
||||
OnBitrateUpdated(network_constrained_rate, network_constrained_rate,
|
||||
network_constrained_rate, 0, _, 0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(update);
|
||||
const DataRate network_constrained_rate =
|
||||
DataRate::BitsPerSec(qvga_stream.target_bitrate_bps);
|
||||
BitrateAllocationUpdate update;
|
||||
update.target_bitrate = network_constrained_rate;
|
||||
update.stable_target_bitrate = network_constrained_rate;
|
||||
update.round_trip_time = TimeDelta::Millis(1);
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _));
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.WillOnce(Return(network_constrained_rate.bps()));
|
||||
EXPECT_CALL(
|
||||
video_stream_encoder_,
|
||||
OnBitrateUpdated(network_constrained_rate, network_constrained_rate,
|
||||
network_constrained_rate, 0, _, 0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(update);
|
||||
|
||||
// Test allocation where the link allocation is larger than the
|
||||
// target, meaning we have some headroom on the link.
|
||||
const DataRate qvga_max_bitrate =
|
||||
DataRate::BitsPerSec(qvga_stream.max_bitrate_bps);
|
||||
const DataRate headroom = DataRate::BitsPerSec(50000);
|
||||
const DataRate rate_with_headroom = qvga_max_bitrate + headroom;
|
||||
update.target_bitrate = rate_with_headroom;
|
||||
update.stable_target_bitrate = rate_with_headroom;
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _));
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.WillOnce(Return(rate_with_headroom.bps()));
|
||||
EXPECT_CALL(video_stream_encoder_,
|
||||
OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate,
|
||||
rate_with_headroom, 0, _, 0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(update);
|
||||
// Test allocation where the link allocation is larger than the
|
||||
// target, meaning we have some headroom on the link.
|
||||
const DataRate qvga_max_bitrate =
|
||||
DataRate::BitsPerSec(qvga_stream.max_bitrate_bps);
|
||||
const DataRate headroom = DataRate::BitsPerSec(50000);
|
||||
const DataRate rate_with_headroom = qvga_max_bitrate + headroom;
|
||||
update.target_bitrate = rate_with_headroom;
|
||||
update.stable_target_bitrate = rate_with_headroom;
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _));
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.WillOnce(Return(rate_with_headroom.bps()));
|
||||
EXPECT_CALL(video_stream_encoder_,
|
||||
OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate,
|
||||
rate_with_headroom, 0, _, 0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(update);
|
||||
|
||||
// Add protection bitrate to the mix, this should be subtracted
|
||||
// from the headroom.
|
||||
const uint32_t protection_bitrate_bps = 10000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetProtectionBitrateBps())
|
||||
.WillOnce(Return(protection_bitrate_bps));
|
||||
// Add protection bitrate to the mix, this should be subtracted
|
||||
// from the headroom.
|
||||
const uint32_t protection_bitrate_bps = 10000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetProtectionBitrateBps())
|
||||
.WillOnce(Return(protection_bitrate_bps));
|
||||
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _));
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.WillOnce(Return(rate_with_headroom.bps()));
|
||||
const DataRate headroom_minus_protection =
|
||||
rate_with_headroom - DataRate::BitsPerSec(protection_bitrate_bps);
|
||||
EXPECT_CALL(video_stream_encoder_,
|
||||
OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate,
|
||||
headroom_minus_protection, 0, _, 0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(update);
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _));
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.WillOnce(Return(rate_with_headroom.bps()));
|
||||
const DataRate headroom_minus_protection =
|
||||
rate_with_headroom - DataRate::BitsPerSec(protection_bitrate_bps);
|
||||
EXPECT_CALL(video_stream_encoder_,
|
||||
OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate,
|
||||
headroom_minus_protection, 0, _, 0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(update);
|
||||
|
||||
// Protection bitrate exceeds head room, link allocation should be
|
||||
// capped to target bitrate.
|
||||
EXPECT_CALL(rtp_video_sender_, GetProtectionBitrateBps())
|
||||
.WillOnce(Return(headroom.bps() + 1000));
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _));
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.WillOnce(Return(rate_with_headroom.bps()));
|
||||
EXPECT_CALL(video_stream_encoder_,
|
||||
OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate,
|
||||
qvga_max_bitrate, 0, _, 0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(update);
|
||||
// Protection bitrate exceeds head room, link allocation should be
|
||||
// capped to target bitrate.
|
||||
EXPECT_CALL(rtp_video_sender_, GetProtectionBitrateBps())
|
||||
.WillOnce(Return(headroom.bps() + 1000));
|
||||
EXPECT_CALL(rtp_video_sender_, OnBitrateUpdated(update, _));
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.WillOnce(Return(rate_with_headroom.bps()));
|
||||
EXPECT_CALL(video_stream_encoder_,
|
||||
OnBitrateUpdated(qvga_max_bitrate, qvga_max_bitrate,
|
||||
qvga_max_bitrate, 0, _, 0));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(update);
|
||||
|
||||
// Set rates to zero on stop.
|
||||
EXPECT_CALL(video_stream_encoder_,
|
||||
OnBitrateUpdated(DataRate::Zero(), DataRate::Zero(),
|
||||
DataRate::Zero(), 0, 0, 0));
|
||||
vss_impl->Stop();
|
||||
});
|
||||
// Set rates to zero on stop.
|
||||
EXPECT_CALL(video_stream_encoder_,
|
||||
OnBitrateUpdated(DataRate::Zero(), DataRate::Zero(),
|
||||
DataRate::Zero(), 0, 0, 0));
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, DisablesPaddingOnPausedEncoder) {
|
||||
@ -850,7 +820,7 @@ TEST_F(VideoSendStreamImplTest, DisablesPaddingOnPausedEncoder) {
|
||||
int min_transmit_bitrate_bps = 30000;
|
||||
|
||||
config_.rtp.ssrcs.emplace_back(1);
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->StartPerRtpStream({true}); });
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
// Starts without padding.
|
||||
EXPECT_EQ(0, padding_bitrate);
|
||||
encoder_queue_->PostTask([&] {
|
||||
@ -866,15 +836,13 @@ TEST_F(VideoSendStreamImplTest, DisablesPaddingOnPausedEncoder) {
|
||||
// reconfiguration happened.
|
||||
EXPECT_EQ(0, padding_bitrate);
|
||||
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
// Unpause encoder.
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
});
|
||||
// Unpause encoder.
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
|
||||
encoder_queue_->PostTask([&] {
|
||||
// A frame is encoded.
|
||||
@ -892,7 +860,7 @@ TEST_F(VideoSendStreamImplTest, DisablesPaddingOnPausedEncoder) {
|
||||
// sent.
|
||||
EXPECT_EQ(0, padding_bitrate);
|
||||
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, KeepAliveOnDroppedFrame) {
|
||||
@ -900,25 +868,21 @@ TEST_F(VideoSendStreamImplTest, KeepAliveOnDroppedFrame) {
|
||||
kDefaultInitialBitrateBps, kDefaultBitratePriority,
|
||||
VideoEncoderConfig::ContentType::kRealtimeVideo);
|
||||
EXPECT_CALL(bitrate_allocator_, RemoveObserver(vss_impl.get())).Times(0);
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
});
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
const uint32_t kBitrateBps = 100000;
|
||||
EXPECT_CALL(rtp_video_sender_, GetPayloadBitrateBps())
|
||||
.Times(1)
|
||||
.WillOnce(Return(kBitrateBps));
|
||||
static_cast<BitrateAllocatorObserver*>(vss_impl.get())
|
||||
->OnBitrateUpdated(CreateAllocation(kBitrateBps));
|
||||
encoder_queue_->PostTask([&] {
|
||||
// Keep the stream from deallocating by dropping a frame.
|
||||
static_cast<EncodedImageCallback*>(vss_impl.get())
|
||||
->OnDroppedFrame(EncodedImageCallback::DropReason::kDroppedByEncoder);
|
||||
});
|
||||
time_controller_.AdvanceTime(TimeDelta::Seconds(2));
|
||||
worker_queue_.RunSynchronous([&] {
|
||||
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
|
||||
vss_impl->Stop();
|
||||
});
|
||||
testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
|
||||
vss_impl->Stop();
|
||||
}
|
||||
|
||||
TEST_F(VideoSendStreamImplTest, ConfiguresBitratesForSvc) {
|
||||
@ -949,7 +913,7 @@ TEST_F(VideoSendStreamImplTest, ConfiguresBitratesForSvc) {
|
||||
? VideoEncoderConfig::ContentType::kScreen
|
||||
: VideoEncoderConfig::ContentType::kRealtimeVideo);
|
||||
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->StartPerRtpStream({true}); });
|
||||
vss_impl->StartPerRtpStream({true});
|
||||
|
||||
// Svc
|
||||
VideoStream stream;
|
||||
@ -1030,7 +994,7 @@ TEST_F(VideoSendStreamImplTest, ConfiguresBitratesForSvc) {
|
||||
time_controller_.AdvanceTime(TimeDelta::Zero());
|
||||
::testing::Mock::VerifyAndClearExpectations(&bitrate_allocator_);
|
||||
|
||||
worker_queue_.RunSynchronous([&] { vss_impl->Stop(); });
|
||||
vss_impl->Stop();
|
||||
}
|
||||
}
|
||||
} // namespace internal
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user