From cc9b7ec7401880e4c14e5c76c4637e191ab4490a Mon Sep 17 00:00:00 2001 From: Tomas Gunnarsson Date: Sun, 16 Jan 2022 20:44:25 +0100 Subject: [PATCH] Add utility method for consistency checking in BaseChannel classes. This is a simple check for upcoming changes for media channels to be able to check if the state on the network thread is consistent. Bug: webrtc:11992 Change-Id: I8ed2d091ecf3869a66970fc4733aebf209c4ef82 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/246681 Reviewed-by: Niels Moller Commit-Queue: Tomas Gunnarsson Cr-Commit-Position: refs/heads/main@{#35706} --- media/base/media_channel.cc | 5 +++++ media/base/media_channel.h | 4 ++++ pc/channel.cc | 3 +++ pc/channel.h | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/media/base/media_channel.cc b/media/base/media_channel.cc index 5d59dba5b5..1b11fcc4e8 100644 --- a/media/base/media_channel.cc +++ b/media/base/media_channel.cc @@ -89,6 +89,11 @@ bool MediaChannel::ExtmapAllowMixed() const { return extmap_allow_mixed_; } +bool MediaChannel::HasNetworkInterface() const { + RTC_DCHECK_RUN_ON(network_thread_); + return network_interface_ != nullptr; +} + void MediaChannel::SetEncoderToPacketizerFrameTransformer( uint32_t ssrc, rtc::scoped_refptr frame_transformer) {} diff --git a/media/base/media_channel.h b/media/base/media_channel.h index 8f20616ebb..2b0ef81277 100644 --- a/media/base/media_channel.h +++ b/media/base/media_channel.h @@ -260,6 +260,10 @@ class MediaChannel { void SetExtmapAllowMixed(bool extmap_allow_mixed); bool ExtmapAllowMixed() const; + // Returns `true` if a non-null NetworkInterface pointer is held. + // Must be called on the network thread. + bool HasNetworkInterface() const; + virtual webrtc::RtpParameters GetRtpSendParameters(uint32_t ssrc) const = 0; virtual webrtc::RTCError SetRtpSendParameters( uint32_t ssrc, diff --git a/pc/channel.cc b/pc/channel.cc index e969d4c399..95e702667d 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -192,6 +192,7 @@ void BaseChannel::Init_w(webrtc::RtpTransportInternal* rtp_transport) { SetRtpTransport(rtp_transport); // Both RTP and RTCP channels should be set, we can call SetInterface on // the media channel and it can set network options. + RTC_DCHECK(!media_channel_->HasNetworkInterface()); media_channel_->SetInterface(this); }); } @@ -208,6 +209,7 @@ void BaseChannel::Deinit() { if (rtp_transport_) { DisconnectFromRtpTransport_n(); } + RTC_DCHECK(!network_initialized()); }); } @@ -797,6 +799,7 @@ bool BaseChannel::ClearHandledPayloadTypes() { void BaseChannel::SignalSentPacket_n(const rtc::SentPacket& sent_packet) { RTC_DCHECK_RUN_ON(network_thread()); + RTC_DCHECK(network_initialized()); media_channel()->OnPacketSent(sent_packet); } diff --git a/pc/channel.h b/pc/channel.h index 109e3491eb..6c2fa1d6e3 100644 --- a/pc/channel.h +++ b/pc/channel.h @@ -217,6 +217,10 @@ class BaseChannel : public ChannelInterface, return extensions_filter_; } + bool network_initialized() RTC_RUN_ON(network_thread()) { + return media_channel_->HasNetworkInterface(); + } + bool enabled() const RTC_RUN_ON(worker_thread()) { return enabled_; } rtc::Thread* signaling_thread() const { return signaling_thread_; }