From 744cc0a9da2e05ae0fb8e1dd0869588a95495a5a Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Tue, 28 Dec 2021 08:30:16 +0800 Subject: [PATCH] feat: support bypass voice processing for darwin. --- .../RTCPeerConnectionFactory+Native.h | 6 ++++ .../peerconnection/RTCPeerConnectionFactory.h | 7 ++++ .../RTCPeerConnectionFactory.mm | 34 ++++++++++++++++--- 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory+Native.h b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory+Native.h index f361b9f0ea..b7f5e27ded 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory+Native.h +++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory+Native.h @@ -71,6 +71,12 @@ NS_ASSUME_NONNULL_BEGIN initWithEncoderFactory:(nullable id)encoderFactory decoderFactory:(nullable id)decoderFactory; +- (instancetype) + initWithBypassVoiceProcessing:(BOOL)bypassVoiceProcessing + encoderFactory:(nullable id)encoderFactory + decoderFactory: + (nullable id)decoderFactory; + /** Initialize an RTCPeerConnection with a configuration, constraints, and * dependencies. */ diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h index 2b0489885f..a9c7802e6f 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h +++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h @@ -41,6 +41,13 @@ RTC_OBJC_EXPORT initWithEncoderFactory:(nullable id)encoderFactory decoderFactory:(nullable id)decoderFactory; +/* Initialize object with bypass voice processing */ +- (instancetype) + initWithBypassVoiceProcessing:(BOOL)bypassVoiceProcessing + encoderFactory:(nullable id)encoderFactory + decoderFactory: + (nullable id)decoderFactory; + /** Initialize an RTCAudioSource with constraints. */ - (RTC_OBJC_TYPE(RTCAudioSource) *)audioSourceWithConstraints: (nullable RTC_OBJC_TYPE(RTCMediaConstraints) *)constraints; diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm index 2f324f7289..d27a26a714 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm +++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm @@ -67,9 +67,9 @@ @implementation RTC_OBJC_TYPE (RTCPeerConnectionFactory) { @synthesize nativeFactory = _nativeFactory; -- (rtc::scoped_refptr)audioDeviceModule { +- (rtc::scoped_refptr)audioDeviceModule:(BOOL)bypassVoiceProcessing { #if defined(WEBRTC_IOS) - return webrtc::CreateAudioDeviceModule(); + return webrtc::CreateAudioDeviceModule(bypassVoiceProcessing); #else return nullptr; #endif @@ -86,7 +86,7 @@ - (instancetype)init { RTCVideoEncoderFactoryH264) alloc] init]) nativeVideoDecoderFactory:webrtc::ObjCToNativeVideoDecoderFactory([[RTC_OBJC_TYPE( RTCVideoDecoderFactoryH264) alloc] init]) - audioDeviceModule:[self audioDeviceModule] + audioDeviceModule:[self audioDeviceModule:false] audioProcessingModule:nullptr]; #endif } @@ -109,10 +109,36 @@ - (instancetype)init { nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory() nativeVideoEncoderFactory:std::move(native_encoder_factory) nativeVideoDecoderFactory:std::move(native_decoder_factory) - audioDeviceModule:[self audioDeviceModule] + audioDeviceModule:[self audioDeviceModule:false] audioProcessingModule:nullptr]; #endif } + +- (instancetype) + initWithBypassVoiceProcessing:(BOOL)bypassVoiceProcessing + encoderFactory:(nullable id)encoderFactory + decoderFactory: + (nullable id)decoderFactory { +#ifdef HAVE_NO_MEDIA + return [self initWithNoMedia]; +#else + std::unique_ptr native_encoder_factory; + std::unique_ptr native_decoder_factory; + if (encoderFactory) { + native_encoder_factory = webrtc::ObjCToNativeVideoEncoderFactory(encoderFactory); + } + if (decoderFactory) { + native_decoder_factory = webrtc::ObjCToNativeVideoDecoderFactory(decoderFactory); + } + return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory() + nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory() + nativeVideoEncoderFactory:std::move(native_encoder_factory) + nativeVideoDecoderFactory:std::move(native_decoder_factory) + audioDeviceModule:[self audioDeviceModule:bypassVoiceProcessing] + audioProcessingModule:nullptr]; +#endif +} + - (instancetype)initNative { if (self = [super init]) { _networkThread = rtc::Thread::CreateWithSocketServer();