From c6ce953664780563c873ac0dc8b306249740ac4b Mon Sep 17 00:00:00 2001 From: Harald Alvestrand Date: Fri, 24 Feb 2023 10:57:54 +0000 Subject: [PATCH] Add support for subclasses that override the old MediaChannel API. Bug: webrtc:13931 Change-Id: I7d139c9914c5a4ac71b8d15fd4d73229d3331be2 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/294840 Reviewed-by: Florent Castelli Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#39387} --- media/base/media_engine.h | 51 ++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/media/base/media_engine.h b/media/base/media_engine.h index 3891ddf837..d3ef1f4bb8 100644 --- a/media/base/media_engine.h +++ b/media/base/media_engine.h @@ -107,9 +107,17 @@ class VoiceEngineInterface : public RtpHeaderExtensionQueryInterface { const AudioOptions& options, const webrtc::CryptoOptions& crypto_options, webrtc::AudioCodecPairId codec_pair_id) { + // For the case where a subclass overrides the deprecated method + // but not the replacement method, call the deprecated method. // TODO(bugs.webrtc.org/13931): Remove default implementation // when downstream has migrated to new API. - RTC_CHECK_NOTREACHED(); + RTC_CHECK(!recursion_guard_); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + RTC_LOG(LS_ERROR) + << "Override of deprecated declaration detected - please update!"; + return CreateMediaChannel(call, config, options, crypto_options); +#pragma clang diagnostic pop } // Backwards compatible version @@ -118,9 +126,12 @@ class VoiceEngineInterface : public RtpHeaderExtensionQueryInterface { const MediaConfig& config, const AudioOptions& options, const webrtc::CryptoOptions& crypto_options) { - return CreateMediaChannel(MediaChannel::Role::kBoth, call, config, options, - crypto_options, - webrtc::AudioCodecPairId::Create()); + recursion_guard_ = true; + auto new_channel = + CreateMediaChannel(MediaChannel::Role::kBoth, call, config, options, + crypto_options, webrtc::AudioCodecPairId::Create()); + recursion_guard_ = false; + return new_channel; } virtual const std::vector& send_codecs() const = 0; @@ -137,6 +148,11 @@ class VoiceEngineInterface : public RtpHeaderExtensionQueryInterface { virtual absl::optional GetAudioDeviceStats() = 0; + + private: + // Workaround variable for avoiding recursion between old and new APIs. + // TODO(bugs.webrtc.org/13931): Remove when old interface is gone. + bool recursion_guard_ = false; }; class VideoEngineInterface : public RtpHeaderExtensionQueryInterface { @@ -156,10 +172,18 @@ class VideoEngineInterface : public RtpHeaderExtensionQueryInterface { const VideoOptions& options, const webrtc::CryptoOptions& crypto_options, webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory) { + // For the case where a subclass overrides the deprecated method + // but not the replacement method, call the deprecated method. // TODO(bugs.webrtc.org/13931): Remove default implementation - // when downstream has migrated. - RTC_CHECK_NOTREACHED(); - return nullptr; + // when downstream has migrated to new API. + RTC_CHECK(!recursion_guard_); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + RTC_LOG(LS_ERROR) + << "Override of deprecated declaration detected - please update!"; + return CreateMediaChannel(call, config, options, crypto_options, + video_bitrate_allocator_factory); +#pragma clang diagnostic pop } // Creates a video media channel. @@ -172,8 +196,12 @@ class VideoEngineInterface : public RtpHeaderExtensionQueryInterface { const VideoOptions& options, const webrtc::CryptoOptions& crypto_options, webrtc::VideoBitrateAllocatorFactory* video_bitrate_allocator_factory) { - return CreateMediaChannel(MediaChannel::Role::kBoth, call, config, options, - crypto_options, video_bitrate_allocator_factory); + recursion_guard_ = true; + auto new_channel = + CreateMediaChannel(MediaChannel::Role::kBoth, call, config, options, + crypto_options, video_bitrate_allocator_factory); + recursion_guard_ = false; + return new_channel; } // Retrieve list of supported codecs. @@ -190,6 +218,11 @@ class VideoEngineInterface : public RtpHeaderExtensionQueryInterface { RTC_DCHECK(include_rtx); return recv_codecs(); } + + private: + // Workaround variable for avoiding recursion between old and new APIs. + // TODO(bugs.webrtc.org/13931): Remove when old interface is gone. + bool recursion_guard_ = false; }; // MediaEngineInterface is an abstraction of a media engine which can be