From 6e7c2685e3f2a17774481b042e04b38f68cd8fba Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Mon, 25 Jul 2022 15:58:28 +0200 Subject: [PATCH] Allow recursive check for RTC_DCHECK_RUN_ON macro instead of using Lock/Unlock attributes, use Assert attribute to annotate code is running on certain task queue or thread. Such check better matches what is checked, in particular allows to recheck (and thus better document) currently used task queue Bug: None Change-Id: I5bc1c397efbc8342cf7915093b578bb015c85651 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/269381 Commit-Queue: Danil Chapovalov Reviewed-by: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#37619} --- api/sequence_checker.h | 9 +++--- audio/channel_receive.cc | 2 +- call/call.cc | 10 +++---- media/engine/webrtc_video_engine.cc | 2 +- modules/rtp_rtcp/source/rtp_rtcp_impl2.cc | 4 +-- modules/video_coding/nack_requester.cc | 2 +- p2p/base/connection.cc | 8 +++--- p2p/base/p2p_transport_channel.cc | 2 +- pc/audio_rtp_receiver.cc | 8 +++--- pc/video_rtp_receiver.cc | 10 +++---- .../sequence_checker_internal.h | 28 ++++++++----------- video/frame_cadence_adapter.cc | 24 ++++++++-------- video/rtp_video_stream_receiver2.cc | 16 +++++------ video/video_receive_stream2.cc | 14 +++++----- video/video_send_stream_impl.cc | 2 +- 15 files changed, 68 insertions(+), 73 deletions(-) diff --git a/api/sequence_checker.h b/api/sequence_checker.h index 5db7b9e4df..b9f466b9a7 100644 --- a/api/sequence_checker.h +++ b/api/sequence_checker.h @@ -107,10 +107,9 @@ class RTC_LOCKABLE SequenceChecker #define RTC_RUN_ON(x) \ RTC_THREAD_ANNOTATION_ATTRIBUTE__(exclusive_locks_required(x)) -#define RTC_DCHECK_RUN_ON(x) \ - webrtc::webrtc_sequence_checker_internal::SequenceCheckerScope \ - seq_check_scope(x); \ - RTC_DCHECK((x)->IsCurrent()) \ - << webrtc::webrtc_sequence_checker_internal::ExpectationToString(x) +#define RTC_DCHECK_RUN_ON(x) \ + RTC_DCHECK((x)->IsCurrent()) \ + << webrtc::webrtc_sequence_checker_internal::ExpectationToString(x); \ + webrtc::webrtc_sequence_checker_internal::AssertHeld(x) #endif // API_SEQUENCE_CHECKER_H_ diff --git a/audio/channel_receive.cc b/audio/channel_receive.cc index c1225b1cd4..c661f0bf8b 100644 --- a/audio/channel_receive.cc +++ b/audio/channel_receive.cc @@ -1036,8 +1036,8 @@ absl::optional ChannelReceive::GetSyncInfo() const { return info; } -// RTC_RUN_ON(worker_thread_checker_) void ChannelReceive::UpdatePlayoutTimestamp(bool rtcp, int64_t now_ms) { + RTC_DCHECK_RUN_ON(&worker_thread_checker_); // TODO(bugs.webrtc.org/11993): Expect to be called exclusively on the // network thread. Once that's done, we won't need video_sync_lock_. diff --git a/call/call.cc b/call/call.cc index 9be095320e..09bc902370 100644 --- a/call/call.cc +++ b/call/call.cc @@ -1350,9 +1350,9 @@ void Call::OnAllocationLimitsChanged(BitrateAllocationLimits limits) { std::memory_order_relaxed); } -// RTC_RUN_ON(worker_thread_) AudioReceiveStreamImpl* Call::FindAudioStreamForSyncGroup( absl::string_view sync_group) { + RTC_DCHECK_RUN_ON(worker_thread_); RTC_DCHECK_RUN_ON(&receive_11993_checker_); if (!sync_group.empty()) { for (AudioReceiveStreamImpl* stream : audio_receive_streams_) { @@ -1364,9 +1364,9 @@ AudioReceiveStreamImpl* Call::FindAudioStreamForSyncGroup( return nullptr; } -// TODO(bugs.webrtc.org/11993): Expect to be called on the network thread. -// RTC_RUN_ON(worker_thread_) void Call::ConfigureSync(absl::string_view sync_group) { + // TODO(bugs.webrtc.org/11993): Expect to be called on the network thread. + RTC_DCHECK_RUN_ON(worker_thread_); // `audio_stream` may be nullptr when clearing the audio stream for a group. AudioReceiveStreamImpl* audio_stream = FindAudioStreamForSyncGroup(sync_group); @@ -1389,8 +1389,8 @@ void Call::ConfigureSync(absl::string_view sync_group) { } } -// RTC_RUN_ON(network_thread_) void Call::DeliverRtcp(MediaType media_type, rtc::CopyOnWriteBuffer packet) { + RTC_DCHECK_RUN_ON(network_thread_); TRACE_EVENT0("webrtc", "Call::DeliverRtcp"); // TODO(bugs.webrtc.org/11993): This DCHECK is here just to maintain the @@ -1533,10 +1533,10 @@ void Call::OnRecoveredPacket(const uint8_t* packet, size_t length) { video_receiver_controller_.OnRtpPacket(parsed_packet); } -// RTC_RUN_ON(worker_thread_) void Call::NotifyBweOfReceivedPacket(const RtpPacketReceived& packet, MediaType media_type, bool use_send_side_bwe) { + RTC_DCHECK_RUN_ON(worker_thread_); RTPHeader header; packet.GetHeader(&header); diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index 6b9730ffc8..366a42c894 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -1274,8 +1274,8 @@ std::string WebRtcVideoChannel::CodecSettingsVectorToString( return out.Release(); } -// RTC_RUN_ON(&thread_checker_) void WebRtcVideoChannel::SetReceiverReportSsrc(uint32_t ssrc) { + RTC_DCHECK_RUN_ON(&thread_checker_); if (ssrc == rtcp_receiver_report_ssrc_) return; diff --git a/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc b/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc index 354eccb751..9eb40abfaf 100644 --- a/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc +++ b/modules/rtp_rtcp/source/rtp_rtcp_impl2.cc @@ -757,17 +757,17 @@ void ModuleRtpRtcpImpl2::PeriodicUpdate() { } } -// RTC_RUN_ON(worker_queue_); void ModuleRtpRtcpImpl2::MaybeSendRtcp() { + RTC_DCHECK_RUN_ON(worker_queue_); if (rtcp_sender_.TimeToSendRTCPReport()) rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport); } // TODO(bugs.webrtc.org/12889): Consider removing this function when the issue // is resolved. -// RTC_RUN_ON(worker_queue_); void ModuleRtpRtcpImpl2::MaybeSendRtcpAtOrAfterTimestamp( Timestamp execution_time) { + RTC_DCHECK_RUN_ON(worker_queue_); Timestamp now = clock_->CurrentTime(); if (now >= execution_time) { MaybeSendRtcp(); diff --git a/modules/video_coding/nack_requester.cc b/modules/video_coding/nack_requester.cc index 80dfe86cc3..4e74032d01 100644 --- a/modules/video_coding/nack_requester.cc +++ b/modules/video_coding/nack_requester.cc @@ -71,8 +71,8 @@ void NackPeriodicProcessor::UnregisterNackModule(NackRequesterBase* module) { repeating_task_.Stop(); } -// RTC_RUN_ON(sequence_) void NackPeriodicProcessor::ProcessNackModules() { + RTC_DCHECK_RUN_ON(&sequence_); for (NackRequesterBase* module : modules_) module->ProcessNacks(); } diff --git a/p2p/base/connection.cc b/p2p/base/connection.cc index 9aefdf6d3f..e59de3de9d 100644 --- a/p2p/base/connection.cc +++ b/p2p/base/connection.cc @@ -1289,18 +1289,18 @@ void Connection::set_ice_event_log(webrtc::IceEventLog* ice_event_log) { ice_event_log_ = ice_event_log; } -// RTC_RUN_ON(network_thread_) void Connection::LogCandidatePairConfig( webrtc::IceCandidatePairConfigType type) { + RTC_DCHECK_RUN_ON(network_thread_); if (ice_event_log_ == nullptr) { return; } ice_event_log_->LogCandidatePairConfig(type, id(), ToLogDescription()); } -// RTC_RUN_ON(network_thread_) void Connection::LogCandidatePairEvent(webrtc::IceCandidatePairEventType type, uint32_t transaction_id) { + RTC_DCHECK_RUN_ON(network_thread_); if (ice_event_log_ == nullptr) { return; } @@ -1403,8 +1403,8 @@ void Connection::OnConnectionRequestTimeout(ConnectionRequest* request) { << request->Elapsed() << " ms"; } -// RTC_RUN_ON(network_thread_). void Connection::OnConnectionRequestSent(ConnectionRequest* request) { + RTC_DCHECK_RUN_ON(network_thread_); // Log at LS_INFO if we send a ping on an unwritable connection. rtc::LoggingSeverity sev = !writable() ? rtc::LS_INFO : rtc::LS_VERBOSE; RTC_LOG_V(sev) << ToString() << ": Sent " @@ -1620,8 +1620,8 @@ void Connection::SetLocalCandidateNetworkCost(uint16_t cost) { SignalStateChange(this); } -// RTC_RUN_ON(network_thread_). bool Connection::ShouldSendGoogPing(const StunMessage* message) { + RTC_DCHECK_RUN_ON(network_thread_); if (remote_support_goog_ping_ == true && cached_stun_binding_ && cached_stun_binding_->EqualAttributes(message, [](int type) { // Ignore these attributes. diff --git a/p2p/base/p2p_transport_channel.cc b/p2p/base/p2p_transport_channel.cc index 87338bfb90..213cfbde77 100644 --- a/p2p/base/p2p_transport_channel.cc +++ b/p2p/base/p2p_transport_channel.cc @@ -2026,8 +2026,8 @@ void P2PTransportChannel::MaybeStopPortAllocatorSessions() { } } -// RTC_RUN_ON(network_thread_) void P2PTransportChannel::OnSelectedConnectionDestroyed() { + RTC_DCHECK_RUN_ON(network_thread_); RTC_LOG(LS_INFO) << "Selected connection destroyed. Will choose a new one."; IceSwitchReason reason = IceSwitchReason::SELECTED_CONNECTION_DESTROYED; SwitchSelectedConnection(nullptr, reason); diff --git a/pc/audio_rtp_receiver.cc b/pc/audio_rtp_receiver.cc index 6ed163a196..e58b74ec72 100644 --- a/pc/audio_rtp_receiver.cc +++ b/pc/audio_rtp_receiver.cc @@ -83,8 +83,8 @@ void AudioRtpReceiver::OnChanged() { })); } -// RTC_RUN_ON(worker_thread_) void AudioRtpReceiver::SetOutputVolume_w(double volume) { + RTC_DCHECK_RUN_ON(worker_thread_); RTC_DCHECK_GE(volume, 0.0); RTC_DCHECK_LE(volume, 10.0); @@ -164,8 +164,8 @@ void AudioRtpReceiver::Stop() { track_->internal()->set_ended(); } -// RTC_RUN_ON(&signaling_thread_checker_) void AudioRtpReceiver::RestartMediaChannel(absl::optional ssrc) { + RTC_DCHECK_RUN_ON(&signaling_thread_checker_); bool enabled = track_->internal()->enabled(); MediaSourceInterface::SourceState state = source_->state(); worker_thread_->Invoke(RTC_FROM_HERE, [&]() { @@ -175,11 +175,11 @@ void AudioRtpReceiver::RestartMediaChannel(absl::optional ssrc) { source_->SetState(MediaSourceInterface::kLive); } -// RTC_RUN_ON(worker_thread_) void AudioRtpReceiver::RestartMediaChannel_w( absl::optional ssrc, bool track_enabled, MediaSourceInterface::SourceState state) { + RTC_DCHECK_RUN_ON(worker_thread_); if (!media_channel_) return; // Can't restart. @@ -281,8 +281,8 @@ void AudioRtpReceiver::SetDepacketizerToDecoderFrameTransformer( frame_transformer_ = std::move(frame_transformer); } -// RTC_RUN_ON(worker_thread_) void AudioRtpReceiver::Reconfigure(bool track_enabled) { + RTC_DCHECK_RUN_ON(worker_thread_); RTC_DCHECK(media_channel_); SetOutputVolume_w(track_enabled ? cached_volume_ : 0); diff --git a/pc/video_rtp_receiver.cc b/pc/video_rtp_receiver.cc index c872fe45ab..d6272e760c 100644 --- a/pc/video_rtp_receiver.cc +++ b/pc/video_rtp_receiver.cc @@ -113,8 +113,8 @@ void VideoRtpReceiver::Stop() { track_->internal()->set_ended(); } -// RTC_RUN_ON(&signaling_thread_checker_) void VideoRtpReceiver::RestartMediaChannel(absl::optional ssrc) { + RTC_DCHECK_RUN_ON(&signaling_thread_checker_); MediaSourceInterface::SourceState state = source_->state(); // TODO(tommi): Can we restart the media channel without blocking? worker_thread_->Invoke(RTC_FROM_HERE, [&] { @@ -124,10 +124,10 @@ void VideoRtpReceiver::RestartMediaChannel(absl::optional ssrc) { source_->SetState(MediaSourceInterface::kLive); } -// RTC_RUN_ON(worker_thread_) void VideoRtpReceiver::RestartMediaChannel_w( absl::optional ssrc, MediaSourceInterface::SourceState state) { + RTC_DCHECK_RUN_ON(worker_thread_); if (!media_channel_) { return; // Can't restart. } @@ -166,8 +166,8 @@ void VideoRtpReceiver::RestartMediaChannel_w( } } -// RTC_RUN_ON(worker_thread_) void VideoRtpReceiver::SetSink(rtc::VideoSinkInterface* sink) { + RTC_DCHECK_RUN_ON(worker_thread_); if (ssrc_) { media_channel_->SetSink(*ssrc_, sink); } else { @@ -260,8 +260,8 @@ void VideoRtpReceiver::SetMediaChannel(cricket::MediaChannel* media_channel) { SetMediaChannel_w(media_channel); } -// RTC_RUN_ON(worker_thread_) void VideoRtpReceiver::SetMediaChannel_w(cricket::MediaChannel* media_channel) { + RTC_DCHECK_RUN_ON(worker_thread_); if (media_channel == media_channel_) return; @@ -347,8 +347,8 @@ void VideoRtpReceiver::OnEncodedSinkEnabled(bool enable) { saved_encoded_sink_enabled_ = enable; } -// RTC_RUN_ON(worker_thread_) void VideoRtpReceiver::SetEncodedSinkEnabled(bool enable) { + RTC_DCHECK_RUN_ON(worker_thread_); if (!media_channel_) return; diff --git a/rtc_base/synchronization/sequence_checker_internal.h b/rtc_base/synchronization/sequence_checker_internal.h index f7ac6de125..3457765216 100644 --- a/rtc_base/synchronization/sequence_checker_internal.h +++ b/rtc_base/synchronization/sequence_checker_internal.h @@ -19,9 +19,21 @@ #include "rtc_base/system/rtc_export.h" #include "rtc_base/thread_annotations.h" +namespace rtc { +class TaskQueue; +} // namespace rtc + namespace webrtc { +class SequenceChecker; namespace webrtc_sequence_checker_internal { +inline void AssertHeld(const SequenceChecker* checker) + RTC_ASSERT_EXCLUSIVE_LOCK(checker) {} +inline void AssertHeld(const TaskQueueBase* task_queue) + RTC_ASSERT_EXCLUSIVE_LOCK(task_queue) {} +inline void AssertHeld(const rtc::TaskQueue* task_queue) + RTC_ASSERT_EXCLUSIVE_LOCK(task_queue) {} + // Real implementation of SequenceChecker, for use in debug mode, or // for temporary use in release mode (e.g. to RTC_CHECK on a threading issue // seen only in the wild). @@ -63,22 +75,6 @@ class SequenceCheckerDoNothing { void Detach() {} }; -// Helper class used by RTC_DCHECK_RUN_ON (see example usage below). -class RTC_SCOPED_LOCKABLE SequenceCheckerScope { - public: - template - explicit SequenceCheckerScope(const ThreadLikeObject* thread_like_object) - RTC_EXCLUSIVE_LOCK_FUNCTION(thread_like_object) {} - SequenceCheckerScope(const SequenceCheckerScope&) = delete; - SequenceCheckerScope& operator=(const SequenceCheckerScope&) = delete; - ~SequenceCheckerScope() RTC_UNLOCK_FUNCTION() {} - - template - static bool IsCurrent(const ThreadLikeObject* thread_like_object) { - return thread_like_object->IsCurrent(); - } -}; - std::string ExpectationToString(const SequenceCheckerImpl* checker); // Catch-all implementation for types other than explicitly supported above. diff --git a/video/frame_cadence_adapter.cc b/video/frame_cadence_adapter.cc index 0ff1680a97..c24a82cbe4 100644 --- a/video/frame_cadence_adapter.cc +++ b/video/frame_cadence_adapter.cc @@ -442,8 +442,8 @@ void ZeroHertzAdapterMode::ProcessKeyFrameRequest() { return; } -// RTC_RUN_ON(&sequence_checker_) bool ZeroHertzAdapterMode::HasQualityConverged() const { + RTC_DCHECK_RUN_ON(&sequence_checker_); // 1. Define ourselves as unconverged with no spatial layers configured. This // is to keep short repeating until the layer configuration comes. // 2. Unset layers implicitly imply that they're converged to support @@ -456,8 +456,8 @@ bool ZeroHertzAdapterMode::HasQualityConverged() const { return quality_converged; } -// RTC_RUN_ON(&sequence_checker_) void ZeroHertzAdapterMode::ResetQualityConvergenceInfo() { + RTC_DCHECK_RUN_ON(&sequence_checker_); RTC_DLOG(LS_INFO) << __func__ << " this " << this; for (auto& layer_tracker : layer_trackers_) { if (layer_tracker.quality_converged.has_value()) @@ -465,8 +465,8 @@ void ZeroHertzAdapterMode::ResetQualityConvergenceInfo() { } } -// RTC_RUN_ON(&sequence_checker_) void ZeroHertzAdapterMode::ProcessOnDelayedCadence() { + RTC_DCHECK_RUN_ON(&sequence_checker_); RTC_DCHECK(!queued_frames_.empty()); RTC_DLOG(LS_VERBOSE) << __func__ << " this " << this; @@ -485,8 +485,8 @@ void ZeroHertzAdapterMode::ProcessOnDelayedCadence() { ScheduleRepeat(current_frame_id_, HasQualityConverged()); } -// RTC_RUN_ON(&sequence_checker_) void ZeroHertzAdapterMode::ScheduleRepeat(int frame_id, bool idle_repeat) { + RTC_DCHECK_RUN_ON(&sequence_checker_); RTC_DLOG(LS_VERBOSE) << __func__ << " this " << this << " frame_id " << frame_id; Timestamp now = clock_->CurrentTime(); @@ -507,8 +507,8 @@ void ZeroHertzAdapterMode::ScheduleRepeat(int frame_id, bool idle_repeat) { repeat_delay); } -// RTC_RUN_ON(&sequence_checker_) void ZeroHertzAdapterMode::ProcessRepeatedFrameOnDelayedCadence(int frame_id) { + RTC_DCHECK_RUN_ON(&sequence_checker_); RTC_DLOG(LS_VERBOSE) << __func__ << " this " << this << " frame_id " << frame_id; RTC_DCHECK(!queued_frames_.empty()); @@ -545,8 +545,8 @@ void ZeroHertzAdapterMode::ProcessRepeatedFrameOnDelayedCadence(int frame_id) { ScheduleRepeat(frame_id, HasQualityConverged()); } -// RTC_RUN_ON(&sequence_checker_) void ZeroHertzAdapterMode::SendFrameNow(const VideoFrame& frame) const { + RTC_DCHECK_RUN_ON(&sequence_checker_); RTC_DLOG(LS_VERBOSE) << __func__ << " this " << this << " timestamp " << frame.timestamp() << " timestamp_us " << frame.timestamp_us() << " ntp_time_ms " @@ -557,15 +557,15 @@ void ZeroHertzAdapterMode::SendFrameNow(const VideoFrame& frame) const { /*frames_scheduled_for_processing=*/1, frame); } -// RTC_RUN_ON(&sequence_checker_) TimeDelta ZeroHertzAdapterMode::RepeatDuration(bool idle_repeat) const { + RTC_DCHECK_RUN_ON(&sequence_checker_); return idle_repeat ? FrameCadenceAdapterInterface::kZeroHertzIdleRepeatRatePeriod : frame_delay_; } -// RTC_RUN_ON(&sequence_checker_) void ZeroHertzAdapterMode::MaybeStartRefreshFrameRequester() { + RTC_DCHECK_RUN_ON(&sequence_checker_); RTC_DLOG(LS_VERBOSE) << __func__; if (!refresh_frame_requester_.Running()) { refresh_frame_requester_ = RepeatingTaskHandle::DelayedStart( @@ -696,26 +696,26 @@ void FrameCadenceAdapterImpl::OnConstraintsChanged( })); } -// RTC_RUN_ON(queue_) void FrameCadenceAdapterImpl::OnFrameOnMainQueue( Timestamp post_time, int frames_scheduled_for_processing, const VideoFrame& frame) { + RTC_DCHECK_RUN_ON(queue_); current_adapter_mode_->OnFrame(post_time, frames_scheduled_for_processing, frame); } -// RTC_RUN_ON(queue_) bool FrameCadenceAdapterImpl::IsZeroHertzScreenshareEnabled() const { + RTC_DCHECK_RUN_ON(queue_); return zero_hertz_screenshare_enabled_ && source_constraints_.has_value() && source_constraints_->max_fps.value_or(-1) > 0 && source_constraints_->min_fps.value_or(-1) == 0 && zero_hertz_params_.has_value(); } -// RTC_RUN_ON(queue_) void FrameCadenceAdapterImpl::MaybeReconfigureAdapters( bool was_zero_hertz_enabled) { + RTC_DCHECK_RUN_ON(queue_); bool is_zero_hertz_enabled = IsZeroHertzScreenshareEnabled(); if (is_zero_hertz_enabled) { if (!was_zero_hertz_enabled) { @@ -733,8 +733,8 @@ void FrameCadenceAdapterImpl::MaybeReconfigureAdapters( } } -// RTC_RUN_ON(queue_) void FrameCadenceAdapterImpl::MaybeReportFrameRateConstraintUmas() { + RTC_DCHECK_RUN_ON(queue_); if (has_reported_screenshare_frame_rate_umas_) return; has_reported_screenshare_frame_rate_umas_ = true; diff --git a/video/rtp_video_stream_receiver2.cc b/video/rtp_video_stream_receiver2.cc index 84aeae8e63..b516b677f7 100644 --- a/video/rtp_video_stream_receiver2.cc +++ b/video/rtp_video_stream_receiver2.cc @@ -351,11 +351,11 @@ absl::optional RtpVideoStreamReceiver2::GetSyncInfo() const { return info; } -// RTC_RUN_ON(packet_sequence_checker_) RtpVideoStreamReceiver2::ParseGenericDependenciesResult RtpVideoStreamReceiver2::ParseGenericDependenciesExtension( const RtpPacketReceived& rtp_packet, RTPVideoHeader* video_header) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); if (rtp_packet.HasExtension()) { webrtc::DependencyDescriptor dependency_descriptor; if (!rtp_packet.GetExtension( @@ -707,9 +707,9 @@ bool RtpVideoStreamReceiver2::IsDecryptable() const { return frames_decryptable_; } -// RTC_RUN_ON(packet_sequence_checker_) void RtpVideoStreamReceiver2::OnInsertedPacket( video_coding::PacketBuffer::InsertResult result) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); RTC_DCHECK_RUN_ON(&worker_task_checker_); video_coding::PacketBuffer::Packet* first_packet = nullptr; int max_nack_count; @@ -785,9 +785,9 @@ void RtpVideoStreamReceiver2::OnInsertedPacket( } } -// RTC_RUN_ON(packet_sequence_checker_) void RtpVideoStreamReceiver2::OnAssembledFrame( std::unique_ptr frame) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); RTC_DCHECK(frame); const absl::optional& descriptor = @@ -852,9 +852,9 @@ void RtpVideoStreamReceiver2::OnAssembledFrame( } } -// RTC_RUN_ON(packet_sequence_checker_) void RtpVideoStreamReceiver2::OnCompleteFrames( RtpFrameReferenceFinder::ReturnVector frames) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); for (auto& frame : frames) { last_seq_num_for_pic_id_[frame->Id()] = frame->last_seq_num(); @@ -952,8 +952,8 @@ void RtpVideoStreamReceiver2::ManageFrame( OnCompleteFrames(reference_finder_->ManageFrame(std::move(frame))); } -// RTC_RUN_ON(packet_sequence_checker_) void RtpVideoStreamReceiver2::ReceivePacket(const RtpPacketReceived& packet) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); RTC_DCHECK_RUN_ON(&worker_task_checker_); if (packet.payload_size() == 0) { // Padding or keep-alive packet. @@ -982,9 +982,9 @@ void RtpVideoStreamReceiver2::ReceivePacket(const RtpPacketReceived& packet) { parsed_payload->video_header); } -// RTC_RUN_ON(packet_sequence_checker_) void RtpVideoStreamReceiver2::ParseAndHandleEncapsulatingHeader( const RtpPacketReceived& packet) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); if (packet.PayloadType() == config_.rtp.red_payload_type && packet.payload_size() > 0) { if (packet.payload()[0] == config_.rtp.ulpfec_payload_type) { @@ -1003,8 +1003,8 @@ void RtpVideoStreamReceiver2::ParseAndHandleEncapsulatingHeader( // In the case of a video stream without picture ids and no rtx the // RtpFrameReferenceFinder will need to know about padding to // correctly calculate frame references. -// RTC_RUN_ON(packet_sequence_checker_) void RtpVideoStreamReceiver2::NotifyReceiverOfEmptyPacket(uint16_t seq_num) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); RTC_DCHECK_RUN_ON(&worker_task_checker_); OnCompleteFrames(reference_finder_->PaddingReceived(seq_num)); @@ -1140,8 +1140,8 @@ void RtpVideoStreamReceiver2::UpdateHistograms() { } } -// RTC_RUN_ON(packet_sequence_checker_) void RtpVideoStreamReceiver2::InsertSpsPpsIntoTracker(uint8_t payload_type) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); RTC_DCHECK_RUN_ON(&worker_task_checker_); auto codec_params_it = pt_codec_params_.find(payload_type); diff --git a/video/video_receive_stream2.cc b/video/video_receive_stream2.cc index 30101cd812..7a53f34ddd 100644 --- a/video/video_receive_stream2.cc +++ b/video/video_receive_stream2.cc @@ -659,7 +659,7 @@ void VideoReceiveStream2::SetDepacketizerToDecoderFrameTransformer( } void VideoReceiveStream2::RequestKeyFrame(Timestamp now) { - // Running on worker_sequence_checker_. + RTC_DCHECK_RUN_ON(&worker_sequence_checker_); // Called from RtpVideoStreamReceiver (rtp_video_stream_receiver_ is // ultimately responsible). rtp_video_stream_receiver_.RequestKeyFrame(); @@ -775,9 +775,9 @@ void VideoReceiveStream2::OnDecodableFrameTimeout(TimeDelta wait_time) { })); } -// RTC_RUN_ON(decode_queue_) void VideoReceiveStream2::HandleEncodedFrame( std::unique_ptr frame) { + RTC_DCHECK_RUN_ON(&decode_queue_); Timestamp now = clock_->CurrentTime(); // Current OnPreDecode only cares about QP for VP8. @@ -847,7 +847,7 @@ void VideoReceiveStream2::HandleEncodedFrame( int VideoReceiveStream2::DecodeAndMaybeDispatchEncodedFrame( std::unique_ptr frame) { - // Running on decode_queue_. + RTC_DCHECK_RUN_ON(&decode_queue_); // If `buffered_encoded_frames_` grows out of control (=60 queued frames), // maybe due to a stuck decoder, we just halt the process here and log the @@ -905,12 +905,12 @@ int VideoReceiveStream2::DecodeAndMaybeDispatchEncodedFrame( return decode_result; } -// RTC_RUN_ON(packet_sequence_checker_) void VideoReceiveStream2::HandleKeyFrameGeneration( bool received_frame_is_keyframe, Timestamp now, bool always_request_key_frame, bool keyframe_request_is_due) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); bool request_key_frame = always_request_key_frame; // Repeat sending keyframe requests if we've requested a keyframe. @@ -934,9 +934,9 @@ void VideoReceiveStream2::HandleKeyFrameGeneration( } } -// RTC_RUN_ON(packet_sequence_checker_) void VideoReceiveStream2::HandleFrameBufferTimeout(Timestamp now, TimeDelta wait) { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); absl::optional last_packet_ms = rtp_video_stream_receiver_.LastReceivedPacketMs(); @@ -958,8 +958,8 @@ void VideoReceiveStream2::HandleFrameBufferTimeout(Timestamp now, } } -// RTC_RUN_ON(packet_sequence_checker_) bool VideoReceiveStream2::IsReceivingKeyFrame(Timestamp now) const { + RTC_DCHECK_RUN_ON(&packet_sequence_checker_); absl::optional last_keyframe_packet_ms = rtp_video_stream_receiver_.LastReceivedKeyframePacketMs(); @@ -972,7 +972,7 @@ bool VideoReceiveStream2::IsReceivingKeyFrame(Timestamp now) const { } void VideoReceiveStream2::UpdatePlayoutDelays() const { - // Running on worker_sequence_checker_. + RTC_DCHECK_RUN_ON(&worker_sequence_checker_); const std::initializer_list> min_delays = { frame_minimum_playout_delay_, base_minimum_playout_delay_, syncable_minimum_playout_delay_}; diff --git a/video/video_send_stream_impl.cc b/video/video_send_stream_impl.cc index 2032c4cb58..3954ef0fed 100644 --- a/video/video_send_stream_impl.cc +++ b/video/video_send_stream_impl.cc @@ -373,8 +373,8 @@ void VideoSendStreamImpl::Stop() { StopVideoSendStream(); } -// RTC_RUN_ON(rtp_transport_queue_) void VideoSendStreamImpl::StopVideoSendStream() { + RTC_DCHECK_RUN_ON(rtp_transport_queue_); bitrate_allocator_->RemoveObserver(this); check_encoder_activity_task_.Stop(); video_stream_encoder_->OnBitrateUpdated(DataRate::Zero(), DataRate::Zero(),