VideoStreamEncoder: move PostTasks to WebRtcVideoChannel.

This change moves the responsibility of posting
EncoderSwitchRequestCallback calls closer to the top-level
users which has a better idea about threading requirements.

The change is planned to be followed-up with more changes removing
the need for VSE to post to the worker thread.

Bug: webrtc:13414, chromium:1255737
Change-Id: I57a2962a70e9f245460c59c0d61824371394b952
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/238420
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35387}
This commit is contained in:
Markus Handell
2021-11-19 11:03:03 +01:00
committed by WebRTC LUCI CQ
parent 20d0323e57
commit d7eef66a39
3 changed files with 22 additions and 31 deletions

View File

@ -868,6 +868,12 @@ bool WebRtcVideoChannel::SetSendParameters(const VideoSendParameters& params) {
} }
void WebRtcVideoChannel::RequestEncoderFallback() { void WebRtcVideoChannel::RequestEncoderFallback() {
if (!worker_thread_->IsCurrent()) {
worker_thread_->PostTask(
ToQueuedTask(task_safety_, [this] { RequestEncoderFallback(); }));
return;
}
RTC_DCHECK_RUN_ON(&thread_checker_); RTC_DCHECK_RUN_ON(&thread_checker_);
if (negotiated_codecs_.size() <= 1) { if (negotiated_codecs_.size() <= 1) {
RTC_LOG(LS_WARNING) << "Encoder failed but no fallback codec is available"; RTC_LOG(LS_WARNING) << "Encoder failed but no fallback codec is available";
@ -883,6 +889,12 @@ void WebRtcVideoChannel::RequestEncoderFallback() {
void WebRtcVideoChannel::RequestEncoderSwitch( void WebRtcVideoChannel::RequestEncoderSwitch(
const EncoderSwitchRequestCallback::Config& conf) { const EncoderSwitchRequestCallback::Config& conf) {
if (!worker_thread_->IsCurrent()) {
worker_thread_->PostTask(ToQueuedTask(
task_safety_, [this, conf] { RequestEncoderSwitch(conf); }));
return;
}
RTC_DCHECK_RUN_ON(&thread_checker_); RTC_DCHECK_RUN_ON(&thread_checker_);
if (!allow_codec_switching_) { if (!allow_codec_switching_) {
@ -923,6 +935,12 @@ void WebRtcVideoChannel::RequestEncoderSwitch(
void WebRtcVideoChannel::RequestEncoderSwitch( void WebRtcVideoChannel::RequestEncoderSwitch(
const webrtc::SdpVideoFormat& format) { const webrtc::SdpVideoFormat& format) {
if (!worker_thread_->IsCurrent()) {
worker_thread_->PostTask(ToQueuedTask(
task_safety_, [this, format] { RequestEncoderSwitch(format); }));
return;
}
RTC_DCHECK_RUN_ON(&thread_checker_); RTC_DCHECK_RUN_ON(&thread_checker_);
for (const VideoCodecSettings& codec_setting : negotiated_codecs_) { for (const VideoCodecSettings& codec_setting : negotiated_codecs_) {

View File

@ -1768,14 +1768,12 @@ void VideoStreamEncoder::EncodeVideoFrame(const VideoFrame& video_frame,
if (settings_.encoder_switch_request_callback) { if (settings_.encoder_switch_request_callback) {
if (encoder_selector_) { if (encoder_selector_) {
if (auto encoder = encoder_selector_->OnEncoderBroken()) { if (auto encoder = encoder_selector_->OnEncoderBroken()) {
QueueRequestEncoderSwitch(*encoder); settings_.encoder_switch_request_callback->RequestEncoderSwitch(
*encoder);
} }
} else { } else {
encoder_failed_ = true; encoder_failed_ = true;
worker_queue_->PostTask(ToQueuedTask(task_safety_, [this]() { settings_.encoder_switch_request_callback->RequestEncoderFallback();
RTC_DCHECK_RUN_ON(worker_queue_);
settings_.encoder_switch_request_callback->RequestEncoderFallback();
}));
} }
} else { } else {
RTC_LOG(LS_ERROR) RTC_LOG(LS_ERROR)
@ -2014,7 +2012,7 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate,
if (!video_is_suspended && settings_.encoder_switch_request_callback && if (!video_is_suspended && settings_.encoder_switch_request_callback &&
encoder_selector_) { encoder_selector_) {
if (auto encoder = encoder_selector_->OnAvailableBitrate(link_allocation)) { if (auto encoder = encoder_selector_->OnAvailableBitrate(link_allocation)) {
QueueRequestEncoderSwitch(*encoder); settings_.encoder_switch_request_callback->RequestEncoderSwitch(*encoder);
} }
} }
@ -2265,24 +2263,6 @@ void VideoStreamEncoder::CheckForAnimatedContent(
} }
} }
// RTC_RUN_ON(&encoder_queue_)
void VideoStreamEncoder::QueueRequestEncoderSwitch(
const EncoderSwitchRequestCallback::Config& conf) {
worker_queue_->PostTask(ToQueuedTask(task_safety_, [this, conf]() {
RTC_DCHECK_RUN_ON(worker_queue_);
settings_.encoder_switch_request_callback->RequestEncoderSwitch(conf);
}));
}
// RTC_RUN_ON(&encoder_queue_)
void VideoStreamEncoder::QueueRequestEncoderSwitch(
const webrtc::SdpVideoFormat& format) {
worker_queue_->PostTask(ToQueuedTask(task_safety_, [this, format]() {
RTC_DCHECK_RUN_ON(worker_queue_);
settings_.encoder_switch_request_callback->RequestEncoderSwitch(format);
}));
}
void VideoStreamEncoder::InjectAdaptationResource( void VideoStreamEncoder::InjectAdaptationResource(
rtc::scoped_refptr<Resource> resource, rtc::scoped_refptr<Resource> resource,
VideoAdaptationReason reason) { VideoAdaptationReason reason) {

View File

@ -241,13 +241,6 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
int64_t time_when_posted_in_ms) int64_t time_when_posted_in_ms)
RTC_RUN_ON(&encoder_queue_); RTC_RUN_ON(&encoder_queue_);
// TODO(bugs.webrtc.org/11341) : Remove this version of RequestEncoderSwitch.
void QueueRequestEncoderSwitch(
const EncoderSwitchRequestCallback::Config& conf)
RTC_RUN_ON(&encoder_queue_);
void QueueRequestEncoderSwitch(const webrtc::SdpVideoFormat& format)
RTC_RUN_ON(&encoder_queue_);
TaskQueueBase* const worker_queue_; TaskQueueBase* const worker_queue_;
const uint32_t number_of_cores_; const uint32_t number_of_cores_;