diff --git a/call/rtp_demuxer.cc b/call/rtp_demuxer.cc index 9fc4ba1c16..c09aefd9b9 100644 --- a/call/rtp_demuxer.cc +++ b/call/rtp_demuxer.cc @@ -91,7 +91,7 @@ std::string RtpDemuxer::DescribePacket(const RtpPacketReceived& packet) { return sb.Release(); } -RtpDemuxer::RtpDemuxer() = default; +RtpDemuxer::RtpDemuxer(bool use_mid /* = true*/) : use_mid_(use_mid) {} RtpDemuxer::~RtpDemuxer() { RTC_DCHECK(sink_by_mid_.empty()); diff --git a/call/rtp_demuxer.h b/call/rtp_demuxer.h index 3aa7e9df26..b89f154072 100644 --- a/call/rtp_demuxer.h +++ b/call/rtp_demuxer.h @@ -94,7 +94,7 @@ class RtpDemuxer { // relevant for demuxing. static std::string DescribePacket(const RtpPacketReceived& packet); - RtpDemuxer(); + explicit RtpDemuxer(bool use_mid = true); ~RtpDemuxer(); RtpDemuxer(const RtpDemuxer&) = delete; @@ -132,10 +132,6 @@ class RtpDemuxer { // if the packet was forwarded and false if the packet was dropped. bool OnRtpPacket(const RtpPacketReceived& packet); - // Configure whether to look at the MID header extension when demuxing - // incoming RTP packets. By default this is enabled. - void set_use_mid(bool use_mid) { use_mid_ = use_mid; } - private: // Returns true if adding a sink with the given criteria would cause conflicts // with the existing criteria and should be rejected. @@ -191,7 +187,7 @@ class RtpDemuxer { // Adds a binding from the SSRC to the given sink. void AddSsrcSinkBinding(uint32_t ssrc, RtpPacketSinkInterface* sink); - bool use_mid_ = true; + const bool use_mid_; }; } // namespace webrtc diff --git a/call/rtp_stream_receiver_controller.cc b/call/rtp_stream_receiver_controller.cc index f440b426d6..7150b34bdb 100644 --- a/call/rtp_stream_receiver_controller.cc +++ b/call/rtp_stream_receiver_controller.cc @@ -37,11 +37,7 @@ RtpStreamReceiverController::Receiver::~Receiver() { controller_->RemoveSink(sink_); } -RtpStreamReceiverController::RtpStreamReceiverController() { - // At this level the demuxer is only configured to demux by SSRC, so don't - // worry about MIDs (MIDs are handled by upper layers). - demuxer_.set_use_mid(false); -} +RtpStreamReceiverController::RtpStreamReceiverController() {} RtpStreamReceiverController::~RtpStreamReceiverController() = default; @@ -52,19 +48,19 @@ RtpStreamReceiverController::CreateReceiver(uint32_t ssrc, } bool RtpStreamReceiverController::OnRtpPacket(const RtpPacketReceived& packet) { - rtc::CritScope cs(&lock_); + RTC_DCHECK_RUN_ON(&demuxer_sequence_); return demuxer_.OnRtpPacket(packet); } bool RtpStreamReceiverController::AddSink(uint32_t ssrc, RtpPacketSinkInterface* sink) { - rtc::CritScope cs(&lock_); + RTC_DCHECK_RUN_ON(&demuxer_sequence_); return demuxer_.AddSink(ssrc, sink); } size_t RtpStreamReceiverController::RemoveSink( const RtpPacketSinkInterface* sink) { - rtc::CritScope cs(&lock_); + RTC_DCHECK_RUN_ON(&demuxer_sequence_); return demuxer_.RemoveSink(sink); } diff --git a/call/rtp_stream_receiver_controller.h b/call/rtp_stream_receiver_controller.h index 62447aa521..261156116a 100644 --- a/call/rtp_stream_receiver_controller.h +++ b/call/rtp_stream_receiver_controller.h @@ -14,7 +14,7 @@ #include "call/rtp_demuxer.h" #include "call/rtp_stream_receiver_controller_interface.h" -#include "rtc_base/deprecated/recursive_critical_section.h" +#include "rtc_base/synchronization/sequence_checker.h" namespace webrtc { @@ -58,13 +58,18 @@ class RtpStreamReceiverController RtpPacketSinkInterface* const sink_; }; - // TODO(nisse): Move to a TaskQueue for synchronization. When used - // by Call, we expect construction and all methods but OnRtpPacket - // to be called on the same thread, and OnRtpPacket to be called - // by a single, but possibly distinct, thread. But applications not - // using Call may have use threads differently. - rtc::RecursiveCriticalSection lock_; - RtpDemuxer demuxer_ RTC_GUARDED_BY(&lock_); + // TODO(bugs.webrtc.org/11993): We expect construction and all methods to be + // called on the same thread/tq. Currently this is the worker thread + // (including OnRtpPacket) but a more natural fit would be the network thread. + // Using a sequence checker to ensure that usage is correct but at the same + // time not require a specific thread/tq, an instance of this class + the + // associated functionality should be easily moved from one execution context + // to another (i.e. when network packets don't hop to the worker thread inside + // of Call). + SequenceChecker demuxer_sequence_; + // At this level the demuxer is only configured to demux by SSRC, so don't + // worry about MIDs (MIDs are handled by upper layers). + RtpDemuxer demuxer_ RTC_GUARDED_BY(&demuxer_sequence_){false /*use_mid*/}; }; } // namespace webrtc