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:

committed by
WebRTC LUCI CQ

parent
20d0323e57
commit
d7eef66a39
@ -868,6 +868,12 @@ bool WebRtcVideoChannel::SetSendParameters(const VideoSendParameters& params) {
|
||||
}
|
||||
|
||||
void WebRtcVideoChannel::RequestEncoderFallback() {
|
||||
if (!worker_thread_->IsCurrent()) {
|
||||
worker_thread_->PostTask(
|
||||
ToQueuedTask(task_safety_, [this] { RequestEncoderFallback(); }));
|
||||
return;
|
||||
}
|
||||
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
if (negotiated_codecs_.size() <= 1) {
|
||||
RTC_LOG(LS_WARNING) << "Encoder failed but no fallback codec is available";
|
||||
@ -883,6 +889,12 @@ void WebRtcVideoChannel::RequestEncoderFallback() {
|
||||
|
||||
void WebRtcVideoChannel::RequestEncoderSwitch(
|
||||
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_);
|
||||
|
||||
if (!allow_codec_switching_) {
|
||||
@ -923,6 +935,12 @@ void WebRtcVideoChannel::RequestEncoderSwitch(
|
||||
|
||||
void WebRtcVideoChannel::RequestEncoderSwitch(
|
||||
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_);
|
||||
|
||||
for (const VideoCodecSettings& codec_setting : negotiated_codecs_) {
|
||||
|
@ -1768,14 +1768,12 @@ void VideoStreamEncoder::EncodeVideoFrame(const VideoFrame& video_frame,
|
||||
if (settings_.encoder_switch_request_callback) {
|
||||
if (encoder_selector_) {
|
||||
if (auto encoder = encoder_selector_->OnEncoderBroken()) {
|
||||
QueueRequestEncoderSwitch(*encoder);
|
||||
settings_.encoder_switch_request_callback->RequestEncoderSwitch(
|
||||
*encoder);
|
||||
}
|
||||
} else {
|
||||
encoder_failed_ = true;
|
||||
worker_queue_->PostTask(ToQueuedTask(task_safety_, [this]() {
|
||||
RTC_DCHECK_RUN_ON(worker_queue_);
|
||||
settings_.encoder_switch_request_callback->RequestEncoderFallback();
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
RTC_LOG(LS_ERROR)
|
||||
@ -2014,7 +2012,7 @@ void VideoStreamEncoder::OnBitrateUpdated(DataRate target_bitrate,
|
||||
if (!video_is_suspended && settings_.encoder_switch_request_callback &&
|
||||
encoder_selector_) {
|
||||
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(
|
||||
rtc::scoped_refptr<Resource> resource,
|
||||
VideoAdaptationReason reason) {
|
||||
|
@ -241,13 +241,6 @@ class VideoStreamEncoder : public VideoStreamEncoderInterface,
|
||||
int64_t time_when_posted_in_ms)
|
||||
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_;
|
||||
|
||||
const uint32_t number_of_cores_;
|
||||
|
Reference in New Issue
Block a user