From 5f9268ed2f0c568a1b196437a5cdef1cb5fc675d Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Tue, 28 Dec 2021 08:30:16 +0800 Subject: [PATCH 1/2] feat: support bypass voice processing for darwin. --- .../RTCPeerConnectionFactory+Native.h | 6 ++++ .../peerconnection/RTCPeerConnectionFactory.h | 6 ++++ .../RTCPeerConnectionFactory.mm | 33 ++++++++++++++++--- 3 files changed, 41 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 5575af98c9..939eb9dae0 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h +++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.h @@ -51,6 +51,12 @@ RTC_OBJC_EXPORT decoderFactory:(nullable id)decoderFactory audioDevice:(nullable id)audioDevice; +/* 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 62b55543d4..d83ff4992a 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm +++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm @@ -60,9 +60,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 @@ -76,7 +76,7 @@ - (instancetype)init { RTCVideoEncoderFactoryH264) alloc] init]) nativeVideoDecoderFactory:webrtc::ObjCToNativeVideoDecoderFactory([[RTC_OBJC_TYPE( RTCVideoDecoderFactoryH264) alloc] init]) - audioDeviceModule:[self audioDeviceModule].get() + audioDeviceModule:[self audioDeviceModule:false].get() audioProcessingModule:nullptr]; } @@ -105,7 +105,7 @@ - (instancetype)init { if (audioDevice) { audio_device_module = webrtc::CreateAudioDeviceModule(audioDevice); } else { - audio_device_module = [self audioDeviceModule]; + audio_device_module = [self audioDeviceModule:false]; } return [self initWithNativeAudioEncoderFactory:webrtc::CreateBuiltinAudioEncoderFactory() nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory() @@ -116,6 +116,31 @@ - (instancetype)init { #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(); From 2fa5a29d83a684610e9636147e146dac5ef30818 Mon Sep 17 00:00:00 2001 From: kanat Date: Fri, 5 Apr 2024 11:07:22 -0700 Subject: [PATCH 2/2] use explicit conversion from scoped_refptr to T*. --- sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm index d83ff4992a..2617b6caaf 100644 --- a/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm +++ b/sdk/objc/api/peerconnection/RTCPeerConnectionFactory.mm @@ -136,7 +136,7 @@ - (instancetype)init { nativeAudioDecoderFactory:webrtc::CreateBuiltinAudioDecoderFactory() nativeVideoEncoderFactory:std::move(native_encoder_factory) nativeVideoDecoderFactory:std::move(native_decoder_factory) - audioDeviceModule:[self audioDeviceModule:bypassVoiceProcessing] + audioDeviceModule:[self audioDeviceModule:bypassVoiceProcessing].get() audioProcessingModule:nullptr]; #endif }