From b0bf93a4b7cddbc70ef7468394852968e2bdbc3f Mon Sep 17 00:00:00 2001 From: kwiberg Date: Thu, 23 Mar 2017 00:10:09 -0700 Subject: [PATCH] DCHECK that no RTPPayloadRegistry instance is used for both audio and video BUG=webrtc:5805 Review-Url: https://codereview.webrtc.org/2763323002 Cr-Commit-Position: refs/heads/master@{#17352} --- .../rtp_rtcp/include/rtp_payload_registry.h | 7 +++++++ .../rtp_rtcp/source/rtp_payload_registry.cc | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h b/webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h index 668fe876f2..767bd07f26 100644 --- a/webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h +++ b/webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h @@ -138,6 +138,13 @@ class RTPPayloadRegistry { // Only warn once per payload type, if an RTX packet is received but // no associated payload type found in |rtx_payload_type_map_|. std::set payload_types_with_suppressed_warnings_ GUARDED_BY(crit_sect_); + + // As a first step in splitting this class up in separate cases for audio and + // video, DCHECK that no instance is used for both audio and video. +#if RTC_DCHECK_IS_ON + bool used_for_audio_ GUARDED_BY(crit_sect_) = false; + bool used_for_video_ GUARDED_BY(crit_sect_) = false; +#endif }; } // namespace webrtc diff --git a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc index 3d2aad42a0..1023bf8bb2 100644 --- a/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc +++ b/webrtc/modules/rtp_rtcp/source/rtp_payload_registry.cc @@ -121,12 +121,17 @@ RTPPayloadRegistry::~RTPPayloadRegistry() = default; int32_t RTPPayloadRegistry::RegisterReceivePayload(const CodecInst& audio_codec, bool* created_new_payload) { + rtc::CritScope cs(&crit_sect_); + +#if RTC_DCHECK_IS_ON + RTC_DCHECK(!used_for_video_); + used_for_audio_ = true; +#endif + *created_new_payload = false; if (!IsPayloadTypeValid(audio_codec.pltype)) return -1; - rtc::CritScope cs(&crit_sect_); - auto it = payload_type_map_.find(audio_codec.pltype); if (it != payload_type_map_.end()) { // We already use this payload type. Check if it's the same as we already @@ -154,11 +159,16 @@ int32_t RTPPayloadRegistry::RegisterReceivePayload(const CodecInst& audio_codec, int32_t RTPPayloadRegistry::RegisterReceivePayload( const VideoCodec& video_codec) { + rtc::CritScope cs(&crit_sect_); + +#if RTC_DCHECK_IS_ON + RTC_DCHECK(!used_for_audio_); + used_for_video_ = true; +#endif + if (!IsPayloadTypeValid(video_codec.plType)) return -1; - rtc::CritScope cs(&crit_sect_); - auto it = payload_type_map_.find(video_codec.plType); if (it != payload_type_map_.end()) { // We already use this payload type. Check if it's the same as we already