From c4d100c1fc79b40a17fd37eb720e46902a6c86cb Mon Sep 17 00:00:00 2001 From: CloudWebRTC Date: Fri, 27 Dec 2024 11:18:47 +0900 Subject: [PATCH] fix bypass voice processing not work. (#668) * fix bypass voice processing not work. * import sorter. * update. * fix. --- .../kotlin/io/livekit/plugin/LiveKitPlugin.kt | 12 ++--- lib/src/livekit.dart | 3 ++ lib/src/support/native.dart | 8 +++ lib/src/track/options.dart | 53 +++++++++++++------ pubspec.yaml | 2 +- 5 files changed, 53 insertions(+), 25 deletions(-) diff --git a/android/src/main/kotlin/io/livekit/plugin/LiveKitPlugin.kt b/android/src/main/kotlin/io/livekit/plugin/LiveKitPlugin.kt index 46f82074d..7d8f97e8e 100644 --- a/android/src/main/kotlin/io/livekit/plugin/LiveKitPlugin.kt +++ b/android/src/main/kotlin/io/livekit/plugin/LiveKitPlugin.kt @@ -32,7 +32,7 @@ import org.webrtc.AudioTrack /** LiveKitPlugin */ class LiveKitPlugin: FlutterPlugin, MethodCallHandler { - private var processors = mutableMapOf() + private var processors = mutableMapOf() private var flutterWebRTCPlugin = FlutterWebRTCPlugin.sharedSingleton private var binaryMessenger: BinaryMessenger? = null /// The MethodChannel that will the communication between Flutter and native Android @@ -77,7 +77,7 @@ class LiveKitPlugin: FlutterPlugin, MethodCallHandler { barCount = barCount, isCentered = isCentered, audioTrack = audioTrack, binaryMessenger = binaryMessenger!!) - processors[audioTrack] = visualizer + processors[trackId] = visualizer result.success(null) } @@ -87,13 +87,7 @@ class LiveKitPlugin: FlutterPlugin, MethodCallHandler { result.error("INVALID_ARGUMENT", "trackId is required", null) return } - processors.entries.removeAll { (k, v) -> - if (k.id() == trackId) { - v.stop() - true - } - false - } + processors.entries.removeAll { (k, v) -> k == trackId } result.success(null) } diff --git a/lib/src/livekit.dart b/lib/src/livekit.dart index e60384003..228340318 100644 --- a/lib/src/livekit.dart +++ b/lib/src/livekit.dart @@ -15,6 +15,7 @@ import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc; import 'package:livekit_client/livekit_client.dart'; +import 'support/native.dart'; /// Main entry point to connect to a room. /// {@category Room} @@ -30,6 +31,8 @@ class LiveKitClient { if (bypassVoiceProcessing) 'bypassVoiceProcessing': bypassVoiceProcessing, }); + + Native.bypassVoiceProcessing = bypassVoiceProcessing; } } } diff --git a/lib/src/support/native.dart b/lib/src/support/native.dart index e1b8a6527..459d02e24 100644 --- a/lib/src/support/native.dart +++ b/lib/src/support/native.dart @@ -24,10 +24,18 @@ class Native { @internal static const channel = MethodChannel('livekit_client'); + @internal + static bool bypassVoiceProcessing = false; + @internal static Future configureAudio( NativeAudioConfiguration configuration) async { try { + if (bypassVoiceProcessing) { + /// skip configuring audio if bypassVoiceProcessing + /// is enabled + return false; + } final result = await channel.invokeMethod( 'configureNativeAudio', configuration.toMap(), diff --git a/lib/src/track/options.dart b/lib/src/track/options.dart index d7f500ceb..8483c891c 100644 --- a/lib/src/track/options.dart +++ b/lib/src/track/options.dart @@ -14,6 +14,7 @@ import 'package:flutter/foundation.dart' show kIsWeb; +import '../support/native.dart'; import '../support/platform.dart'; import '../track/local/audio.dart'; import '../track/local/video.dart'; @@ -261,6 +262,10 @@ class AudioCaptureOptions extends LocalTrackOptions { /// Defaults to true. final bool typingNoiseDetection; + /// Attempt to use voiceIsolation option (if supported by the platform) + /// Defaults to true. + final bool voiceIsolation; + /// set to false to only toggle enabled instead of stop/replaceTrack for muting final bool stopAudioCaptureOnMute; @@ -270,6 +275,7 @@ class AudioCaptureOptions extends LocalTrackOptions { this.echoCancellation = true, this.autoGainControl = true, this.highPassFilter = false, + this.voiceIsolation = true, this.typingNoiseDetection = true, this.stopAudioCaptureOnMute = true, }); @@ -278,23 +284,40 @@ class AudioCaptureOptions extends LocalTrackOptions { Map toMediaConstraintsMap() { var constraints = {}; - /// in we platform it's not possible to provide optional and mandatory parameters. - /// deviceId is a mandatory parameter - if (!kIsWeb || (kIsWeb && deviceId == null)) { + if (Native.bypassVoiceProcessing) { constraints['optional'] = >[ - {'echoCancellation': echoCancellation}, - {'noiseSuppression': noiseSuppression}, - {'autoGainControl': autoGainControl}, - {'voiceIsolation': noiseSuppression}, - {'googDAEchoCancellation': echoCancellation}, - {'googEchoCancellation': echoCancellation}, - {'googEchoCancellation2': echoCancellation}, - {'googNoiseSuppression': noiseSuppression}, - {'googNoiseSuppression2': noiseSuppression}, - {'googAutoGainControl': autoGainControl}, - {'googHighpassFilter': highPassFilter}, - {'googTypingNoiseDetection': typingNoiseDetection}, + {'googEchoCancellation': false}, + {'googEchoCancellation2': false}, + {'googNoiseSuppression': false}, + {'googNoiseSuppression2': false}, + {'googAutoGainControl': false}, + {'googHighpassFilter': false}, + {'googTypingNoiseDetection': false}, + {'noiseSuppression': false}, + {'echoCancellation': false}, + {'autoGainControl': false}, + {'voiceIsolation': false}, + {'googDAEchoCancellation': false}, ]; + } else { + /// in we platform it's not possible to provide optional and mandatory parameters. + /// deviceId is a mandatory parameter + if (!kIsWeb || (kIsWeb && deviceId == null)) { + constraints['optional'] = >[ + {'echoCancellation': echoCancellation}, + {'noiseSuppression': noiseSuppression}, + {'autoGainControl': autoGainControl}, + {'voiceIsolation': noiseSuppression}, + {'googDAEchoCancellation': echoCancellation}, + {'googEchoCancellation': echoCancellation}, + {'googEchoCancellation2': echoCancellation}, + {'googNoiseSuppression': noiseSuppression}, + {'googNoiseSuppression2': noiseSuppression}, + {'googAutoGainControl': autoGainControl}, + {'googHighpassFilter': highPassFilter}, + {'googTypingNoiseDetection': typingNoiseDetection}, + ]; + } } if (deviceId != null) { diff --git a/pubspec.yaml b/pubspec.yaml index 1442e0bb9..d78e6b3ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -37,7 +37,7 @@ dependencies: uuid: '>=3.0.6' synchronized: ^3.0.0+3 protobuf: ^3.0.0 - flutter_webrtc: ^0.12.5 + flutter_webrtc: ^0.12.5+hotfix.1 device_info_plus: ^11.1.1 js: '>=0.6.4' platform_detect: ^2.0.7