From 56b208761dbd1a33fefc2cbcf60de279126991ab Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Fri, 1 Jul 2022 07:36:59 +0000 Subject: [PATCH] [M104] Do not allow simulcast to be turned off using SDP munging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is an error that puts the PC into an inconsistent state, so causing a crash is the right thing to do. (cherry picked from commit 3fe8b0d9a980642ee5ebb1f9e429378b063c1f07) Bug: chromium:1341043 Change-Id: Ie1eb89400ad87f0c83634b7073236b07e92ec7ab Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/267281 Reviewed-by: Mirko Bonadei Reviewed-by: Henrik Boström Commit-Queue: Harald Alvestrand Cr-Original-Commit-Position: refs/heads/main@{#37391} No-Presubmit: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/267940 Cr-Commit-Position: refs/branch-heads/5112@{#4} Cr-Branched-From: a976a871159f85f975fbd6f170d0a8f00a4aee49-refs/heads/main@{#37168} --- pc/rtp_sender.cc | 4 ++-- pc/rtp_sender_receiver_unittest.cc | 38 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/pc/rtp_sender.cc b/pc/rtp_sender.cc index d8d4b520eb..3ee9145a20 100644 --- a/pc/rtp_sender.cc +++ b/pc/rtp_sender.cc @@ -317,8 +317,8 @@ void RtpSenderBase::SetSsrc(uint32_t ssrc) { // we need to copy. RtpParameters current_parameters = media_channel_->GetRtpSendParameters(ssrc_); - RTC_DCHECK_GE(current_parameters.encodings.size(), - init_parameters_.encodings.size()); + RTC_CHECK_GE(current_parameters.encodings.size(), + init_parameters_.encodings.size()); for (size_t i = 0; i < init_parameters_.encodings.size(); ++i) { init_parameters_.encodings[i].ssrc = current_parameters.encodings[i].ssrc; diff --git a/pc/rtp_sender_receiver_unittest.cc b/pc/rtp_sender_receiver_unittest.cc index 654fffc60d..59d4c606b1 100644 --- a/pc/rtp_sender_receiver_unittest.cc +++ b/pc/rtp_sender_receiver_unittest.cc @@ -1151,6 +1151,44 @@ TEST_F(RtpSenderReceiverTest, DestroyVideoRtpSender(); } +#if GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) +using RtpSenderReceiverDeathTest = RtpSenderReceiverTest; + +TEST_F(RtpSenderReceiverDeathTest, + VideoSenderManualRemoveSimulcastFailsDeathTest) { + AddVideoTrack(false); + + std::unique_ptr set_streams_observer = + std::make_unique(); + video_rtp_sender_ = VideoRtpSender::Create(worker_thread_, video_track_->id(), + set_streams_observer.get()); + ASSERT_TRUE(video_rtp_sender_->SetTrack(video_track_.get())); + EXPECT_CALL(*set_streams_observer, OnSetStreams()); + video_rtp_sender_->SetStreams({local_stream_->id()}); + + std::vector init_encodings(2); + init_encodings[0].max_bitrate_bps = 60000; + init_encodings[1].max_bitrate_bps = 120000; + video_rtp_sender_->set_init_send_encodings(init_encodings); + + RtpParameters params = video_rtp_sender_->GetParameters(); + ASSERT_EQ(2u, params.encodings.size()); + EXPECT_EQ(params.encodings[0].max_bitrate_bps, 60000); + + // Simulate the setLocalDescription call as if the user used SDP munging + // to disable simulcast. + std::vector ssrcs; + ssrcs.reserve(2); + for (int i = 0; i < 2; ++i) + ssrcs.push_back(kVideoSsrcSimulcast + i); + cricket::StreamParams stream_params = + cricket::StreamParams::CreateLegacy(kVideoSsrc); + video_media_channel()->AddSendStream(stream_params); + video_rtp_sender_->SetMediaChannel(video_media_channel()); + EXPECT_DEATH(video_rtp_sender_->SetSsrc(kVideoSsrcSimulcast), ""); +} +#endif + TEST_F(RtpSenderReceiverTest, VideoSenderMustCallGetParametersBeforeSetParametersBeforeNegotiation) { video_rtp_sender_ =