diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 34e638f3cf..3665a82e03 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -3337,7 +3337,7 @@ RTCError PeerConnection::ApplyRemoteDescription( if (content->rejected && !transceiver->stopped()) { RTC_LOG(LS_INFO) << "Stopping transceiver for MID=" << content->name << " since the media section was rejected."; - transceiver->StopInternal(); + transceiver->internal()->StopTransceiverProcedure(); } if (!content->rejected && RtpTransceiverDirectionHasRecv(local_direction)) { diff --git a/pc/rtp_transceiver.cc b/pc/rtp_transceiver.cc index b267e4e333..fd6f4bbd17 100644 --- a/pc/rtp_transceiver.cc +++ b/pc/rtp_transceiver.cc @@ -321,7 +321,7 @@ RTCError RtpTransceiver::SetDirectionWithError( absl::optional RtpTransceiver::current_direction() const { - if (unified_plan_ && stopping()) + if (unified_plan_ && stopped()) return webrtc::RtpTransceiverDirection::kStopped; return current_direction_; @@ -354,7 +354,11 @@ void RtpTransceiver::StopSendingAndReceiving() { RTCError RtpTransceiver::StopStandard() { RTC_DCHECK_RUN_ON(thread_); - RTC_DCHECK(unified_plan_); + // If we're on Plan B, do what Stop() used to do there. + if (!unified_plan_) { + StopInternal(); + return RTCError::OK(); + } // 1. Let transceiver be the RTCRtpTransceiver object on which the method is // invoked. // @@ -380,7 +384,12 @@ RTCError RtpTransceiver::StopStandard() { } void RtpTransceiver::StopInternal() { + StopTransceiverProcedure(); +} + +void RtpTransceiver::StopTransceiverProcedure() { RTC_DCHECK_RUN_ON(thread_); + // As specified in the "Stop the RTCRtpTransceiver" procedure // 1. If transceiver.[[Stopping]] is false, stop sending and receiving given // transceiver. if (!stopping_) diff --git a/pc/rtp_transceiver.h b/pc/rtp_transceiver.h index 1d3ceaef61..9c048adc06 100644 --- a/pc/rtp_transceiver.h +++ b/pc/rtp_transceiver.h @@ -177,6 +177,10 @@ class RtpTransceiver final // PeerConnection is closed. void SetPeerConnectionClosed(); + // Executes the "stop the RTCRtpTransceiver" procedure from + // the webrtc-pc specification, described under the stop() method. + void StopTransceiverProcedure(); + // Fired when the RtpTransceiver state changes such that negotiation is now // needed (e.g., in response to a direction change). sigslot::signal0<> SignalNegotiationNeeded; diff --git a/pc/rtp_transceiver_unittest.cc b/pc/rtp_transceiver_unittest.cc index 78abfff8b9..e4883f32f6 100644 --- a/pc/rtp_transceiver_unittest.cc +++ b/pc/rtp_transceiver_unittest.cc @@ -79,6 +79,40 @@ TEST(RtpTransceiverTest, CanUnsetChannelOnStoppedTransceiver) { EXPECT_EQ(nullptr, transceiver.channel()); } +class RtpTransceiverUnifiedPlanTest : public ::testing::Test { + public: + RtpTransceiverUnifiedPlanTest() + : channel_manager_(std::make_unique(), + std::make_unique(), + rtc::Thread::Current(), + rtc::Thread::Current()), + transceiver_(RtpSenderProxyWithInternal::Create( + rtc::Thread::Current(), + new rtc::RefCountedObject()), + RtpReceiverProxyWithInternal::Create( + rtc::Thread::Current(), + new rtc::RefCountedObject()), + &channel_manager_, + channel_manager_.GetSupportedAudioRtpHeaderExtensions()) {} + + cricket::ChannelManager channel_manager_; + RtpTransceiver transceiver_; +}; + +// Basic tests for Stop() +TEST_F(RtpTransceiverUnifiedPlanTest, StopSetsDirection) { + EXPECT_EQ(RtpTransceiverDirection::kInactive, transceiver_.direction()); + EXPECT_FALSE(transceiver_.current_direction()); + transceiver_.StopStandard(); + EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_.direction()); + EXPECT_FALSE(transceiver_.current_direction()); + transceiver_.StopTransceiverProcedure(); + EXPECT_TRUE(transceiver_.current_direction()); + EXPECT_EQ(RtpTransceiverDirection::kStopped, transceiver_.direction()); + EXPECT_EQ(RtpTransceiverDirection::kStopped, + *transceiver_.current_direction()); +} + class RtpTransceiverTestForHeaderExtensions : public ::testing::Test { public: RtpTransceiverTestForHeaderExtensions()