From f53327e318db02b0e17a3bad4725bac95e9b2290 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Mon, 23 Dec 2024 21:55:33 +0800 Subject: [PATCH 1/4] fix bypass voice processing not work. --- lib/src/livekit.dart | 4 ++++ lib/src/support/native.dart | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/src/livekit.dart b/lib/src/livekit.dart index e60384003..770be1992 100644 --- a/lib/src/livekit.dart +++ b/lib/src/livekit.dart @@ -16,6 +16,8 @@ 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} class LiveKitClient { @@ -30,6 +32,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(), From 48464d2178d3da063cabb36d6a16054c64260bdf Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Mon, 23 Dec 2024 22:00:13 +0800 Subject: [PATCH 2/4] import sorter. --- lib/src/livekit.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/src/livekit.dart b/lib/src/livekit.dart index 770be1992..228340318 100644 --- a/lib/src/livekit.dart +++ b/lib/src/livekit.dart @@ -15,7 +15,6 @@ 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. From 9229723cc24b7c0672e827d40e6baa9c8f1f6182 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Wed, 25 Dec 2024 23:01:23 +0900 Subject: [PATCH 3/4] update. --- lib/src/track/options.dart | 53 +++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 15 deletions(-) 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) { From fb2bb83674b695ca5aaffddb1b0b24032e2d8fc7 Mon Sep 17 00:00:00 2001 From: cloudwebrtc Date: Wed, 25 Dec 2024 23:38:53 +0900 Subject: [PATCH 4/4] fix. --- .../main/kotlin/io/livekit/plugin/LiveKitPlugin.kt | 12 +++--------- pubspec.yaml | 2 +- 2 files changed, 4 insertions(+), 10 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/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