From fa266efb27f6e7db548a9c52f8f28bad911e4fd2 Mon Sep 17 00:00:00 2001 From: Zhi Huang Date: Wed, 13 Dec 2017 10:27:46 -0800 Subject: [PATCH] Fix the crash when GetSources is called with non-existing ssrc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When GetSources is called with non-existing ssrc, it will log the error and return an empty RtpSource list instead of hitting the DCHECK. Bug: chromium:793699 Change-Id: I30bebb657de32f87f9c82920fa0b19403893791f Reviewed-on: https://webrtc-review.googlesource.com/32860 Reviewed-by: Taylor Brandstetter Reviewed-by: Henrik Boström Commit-Queue: Zhi Huang Cr-Commit-Position: refs/heads/master@{#21258} --- media/engine/webrtcvoiceengine.cc | 8 +++++--- media/engine/webrtcvoiceengine_unittest.cc | 12 ++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/media/engine/webrtcvoiceengine.cc b/media/engine/webrtcvoiceengine.cc index 1ebbb0fe2b..061a16b442 100644 --- a/media/engine/webrtcvoiceengine.cc +++ b/media/engine/webrtcvoiceengine.cc @@ -2307,9 +2307,11 @@ void WebRtcVoiceMediaChannel::SetRawAudioSink( std::vector WebRtcVoiceMediaChannel::GetSources( uint32_t ssrc) const { auto it = recv_streams_.find(ssrc); - RTC_DCHECK(it != recv_streams_.end()) - << "Attempting to get contributing sources for SSRC:" << ssrc - << " which doesn't exist."; + if (it == recv_streams_.end()) { + RTC_LOG(LS_ERROR) << "Attempting to get contributing sources for SSRC:" + << ssrc << " which doesn't exist."; + return std::vector(); + } return it->second->GetSources(); } diff --git a/media/engine/webrtcvoiceengine_unittest.cc b/media/engine/webrtcvoiceengine_unittest.cc index 5546f1b490..4fd087ac1a 100644 --- a/media/engine/webrtcvoiceengine_unittest.cc +++ b/media/engine/webrtcvoiceengine_unittest.cc @@ -3300,6 +3300,18 @@ TEST_F(WebRtcVoiceEngineTestFake, PreservePlayoutWhenRecreateRecvStream) { EXPECT_TRUE(GetRecvStream(kSsrcX).started()); } +// Tests when GetSources is called with non-existing ssrc, it will return an +// empty list of RtpSource without crashing. +TEST_F(WebRtcVoiceEngineTestFake, GetSourcesWithNonExistingSsrc) { + // Setup an recv stream with |kSsrcX|. + SetupRecvStream(); + cricket::WebRtcVoiceMediaChannel* media_channel = + static_cast(channel_); + // Call GetSources with |kSsrcY| which doesn't exist. + std::vector sources = media_channel->GetSources(kSsrcY); + EXPECT_EQ(0u, sources.size()); +} + // Tests that the library initializes and shuts down properly. TEST(WebRtcVoiceEngineTest, StartupShutdown) { // If the VoiceEngine wants to gather available codecs early, that's fine but