From d9255b18404f64c0e4d561635a3d5aa33f60d56b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Bostr=C3=B6m?= Date: Mon, 4 May 2020 16:10:41 +0200 Subject: [PATCH] [getStats] Fix DCHECK crash in MergeInfoAboutOutboundRtpSubstreams(). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It seems possible that getStats() and merging RTX/FlexFEC substream stats into media substream stats can race with the creation or destruction of the media substream that the RTX/FlexFEC substream is associated with. In other words, the DCHECK that ensures that there exists a stats object to merge into is not always valid. Because there is no media stats object to merge in to, and outbound-rtp stats objects only exists per media SSRCs, the sensible thing to do is to RTC_LOG and ignore the substream stats. Bug: webrtc:11545 Change-Id: I4061d7190da7ab8bd33fa1fd92c9d819f35d76c7 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174360 Reviewed-by: Ilya Nikolaevskiy Commit-Queue: Henrik Boström Cr-Commit-Position: refs/heads/master@{#31156} --- media/engine/webrtc_video_engine.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index 3de4cdfc7a..2288325694 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -49,6 +49,19 @@ namespace { const int kMinLayerSize = 16; +const char* StreamTypeToString( + webrtc::VideoSendStream::StreamStats::StreamType type) { + switch (type) { + case webrtc::VideoSendStream::StreamStats::StreamType::kMedia: + return "kMedia"; + case webrtc::VideoSendStream::StreamStats::StreamType::kRtx: + return "kRtx"; + case webrtc::VideoSendStream::StreamStats::StreamType::kFlexfec: + return "kFlexfec"; + } + return nullptr; +} + // If this field trial is enabled, we will enable sending FlexFEC and disable // sending ULPFEC whenever the former has been negotiated in the SDPs. bool IsFlexfecFieldTrialEnabled() { @@ -372,7 +385,14 @@ MergeInfoAboutOutboundRtpSubstreams( pair.second; RTC_DCHECK(associated_substream.referenced_media_ssrc.has_value()); uint32_t media_ssrc = associated_substream.referenced_media_ssrc.value(); - RTC_DCHECK(substreams.find(media_ssrc) != substreams.end()); + if (substreams.find(media_ssrc) == substreams.end()) { + RTC_LOG(LS_WARNING) << "Substream [ssrc: " << pair.first << ", type: " + << StreamTypeToString(associated_substream.type) + << "] is associated with a media ssrc (" << media_ssrc + << ") that does not have StreamStats. Ignoring its " + << "RTP stats."; + continue; + } webrtc::VideoSendStream::StreamStats& rtp_substream = rtp_substreams[media_ssrc];