Fix the crash when GetSources is called with non-existing ssrc.

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 <deadbeef@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Zhi Huang <zhihuang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21258}
This commit is contained in:
Zhi Huang 2017-12-13 10:27:46 -08:00 committed by Commit Bot
parent 095f1c344d
commit fa266efb27
2 changed files with 17 additions and 3 deletions

View File

@ -2307,9 +2307,11 @@ void WebRtcVoiceMediaChannel::SetRawAudioSink(
std::vector<webrtc::RtpSource> 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<webrtc::RtpSource>();
}
return it->second->GetSources();
}

View File

@ -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<cricket::WebRtcVoiceMediaChannel*>(channel_);
// Call GetSources with |kSsrcY| which doesn't exist.
std::vector<webrtc::RtpSource> 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