From ed6b586b62ec93ae82a231b6128f2f7360e663af Mon Sep 17 00:00:00 2001 From: Tommi Date: Mon, 25 Jul 2022 13:48:37 +0200 Subject: [PATCH] Make OnEncodedFrame and OnDecodableFrameTimeout expectations consistent. Fix call in FrameBuffer3Proxy to OnDecodableFrameTimeout to match with FrameBuffer2Proxy and how OnEncodedFrame is called. Bug: none Change-Id: I6f5f18bd9a425aa55f5826654b24c2c0ee5af5f7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/269302 Commit-Queue: Tomas Gunnarsson Commit-Queue: Danil Chapovalov Reviewed-by: Danil Chapovalov Auto-Submit: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#37610} --- video/frame_buffer_proxy.cc | 8 ++++++-- video/video_receive_stream2.cc | 32 ++++++++++++-------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/video/frame_buffer_proxy.cc b/video/frame_buffer_proxy.cc index e54cd59d1f..4675f8b1c7 100644 --- a/video/frame_buffer_proxy.cc +++ b/video/frame_buffer_proxy.cc @@ -364,6 +364,7 @@ class FrameBuffer3Proxy : public FrameBufferProxy { // VideoReceiveStream2 wants frames on the decoder thread. decode_queue_->PostTask( SafeTask(decode_safety_, [this, frame = std::move(frame)]() mutable { + RTC_DCHECK_RUN_ON(decode_queue_); receiver_->OnEncodedFrame(std::move(frame)); })); } @@ -375,7 +376,10 @@ class FrameBuffer3Proxy : public FrameBufferProxy { timeout_tracker_.Stop(); return; } - receiver_->OnDecodableFrameTimeout(delay); + decode_queue_->PostTask(SafeTask(decode_safety_, [this, delay]() { + RTC_DCHECK_RUN_ON(decode_queue_); + receiver_->OnDecodableFrameTimeout(delay); + })); // Stop sending timeouts until receive starts waiting for a new frame. timeout_tracker_.Stop(); decoder_ready_for_new_frame_ = false; @@ -493,7 +497,7 @@ class FrameBuffer3Proxy : public FrameBufferProxy { TaskQueueBase* const worker_queue_; TaskQueueBase* const decode_queue_; VCMReceiveStatisticsCallback* const stats_proxy_; - FrameSchedulingReceiver* const receiver_; + FrameSchedulingReceiver* const receiver_ RTC_PT_GUARDED_BY(decode_queue_); VCMTiming* const timing_; const std::unique_ptr frame_decode_scheduler_ RTC_GUARDED_BY(&worker_sequence_checker_); diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc index 4fb2f9cf26..30101cd812 100644 --- a/video/video_receive_stream2.cc +++ b/video/video_receive_stream2.cc @@ -752,12 +752,6 @@ TimeDelta VideoReceiveStream2::GetMaxWait() const { } void VideoReceiveStream2::OnEncodedFrame(std::unique_ptr frame) { - if (!decode_queue_.IsCurrent()) { - decode_queue_.PostTask([this, frame = std::move(frame)]() mutable { - OnEncodedFrame(std::move(frame)); - }); - return; - } RTC_DCHECK_RUN_ON(&decode_queue_); if (decoder_stopped_) return; @@ -766,26 +760,24 @@ void VideoReceiveStream2::OnEncodedFrame(std::unique_ptr frame) { } void VideoReceiveStream2::OnDecodableFrameTimeout(TimeDelta wait_time) { - if (!call_->worker_thread()->IsCurrent()) { - call_->worker_thread()->PostTask( - SafeTask(task_safety_.flag(), - [this, wait_time] { OnDecodableFrameTimeout(wait_time); })); - return; - } - + RTC_DCHECK_RUN_ON(&decode_queue_); + Timestamp now = clock_->CurrentTime(); // TODO(bugs.webrtc.org/11993): PostTask to the network thread. - RTC_DCHECK_RUN_ON(&packet_sequence_checker_); - HandleFrameBufferTimeout(clock_->CurrentTime(), wait_time); + call_->worker_thread()->PostTask( + SafeTask(task_safety_.flag(), [this, wait_time, now] { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); + HandleFrameBufferTimeout(now, wait_time); - decode_queue_.PostTask([this] { - RTC_DCHECK_RUN_ON(&decode_queue_); - frame_buffer_->StartNextDecode(keyframe_required_); - }); + decode_queue_.PostTask([this] { + RTC_DCHECK_RUN_ON(&decode_queue_); + frame_buffer_->StartNextDecode(keyframe_required_); + }); + })); } +// RTC_RUN_ON(decode_queue_) void VideoReceiveStream2::HandleEncodedFrame( std::unique_ptr frame) { - // Running on `decode_queue_`. Timestamp now = clock_->CurrentTime(); // Current OnPreDecode only cares about QP for VP8.