Skip to content

Commit

Permalink
fix bypass voice processing not work. (#668)
Browse files Browse the repository at this point in the history
* fix bypass voice processing not work.

* import sorter.

* update.

* fix.
  • Loading branch information
cloudwebrtc authored Dec 27, 2024
1 parent 2afc996 commit c4d100c
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
12 changes: 3 additions & 9 deletions android/src/main/kotlin/io/livekit/plugin/LiveKitPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.webrtc.AudioTrack

/** LiveKitPlugin */
class LiveKitPlugin: FlutterPlugin, MethodCallHandler {
private var processors = mutableMapOf<LKAudioTrack, Visualizer>()
private var processors = mutableMapOf<String, Visualizer>()
private var flutterWebRTCPlugin = FlutterWebRTCPlugin.sharedSingleton
private var binaryMessenger: BinaryMessenger? = null
/// The MethodChannel that will the communication between Flutter and native Android
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down
3 changes: 3 additions & 0 deletions lib/src/livekit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -30,6 +31,8 @@ class LiveKitClient {
if (bypassVoiceProcessing)
'bypassVoiceProcessing': bypassVoiceProcessing,
});

Native.bypassVoiceProcessing = bypassVoiceProcessing;
}
}
}
8 changes: 8 additions & 0 deletions lib/src/support/native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ class Native {
@internal
static const channel = MethodChannel('livekit_client');

@internal
static bool bypassVoiceProcessing = false;

@internal
static Future<bool> configureAudio(
NativeAudioConfiguration configuration) async {
try {
if (bypassVoiceProcessing) {
/// skip configuring audio if bypassVoiceProcessing
/// is enabled
return false;
}
final result = await channel.invokeMethod<bool>(
'configureNativeAudio',
configuration.toMap(),
Expand Down
53 changes: 38 additions & 15 deletions lib/src/track/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;

Expand All @@ -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,
});
Expand All @@ -278,23 +284,40 @@ class AudioCaptureOptions extends LocalTrackOptions {
Map<String, dynamic> toMediaConstraintsMap() {
var constraints = <String, dynamic>{};

/// 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'] = <Map<String, dynamic>>[
<String, dynamic>{'echoCancellation': echoCancellation},
<String, dynamic>{'noiseSuppression': noiseSuppression},
<String, dynamic>{'autoGainControl': autoGainControl},
<String, dynamic>{'voiceIsolation': noiseSuppression},
<String, dynamic>{'googDAEchoCancellation': echoCancellation},
<String, dynamic>{'googEchoCancellation': echoCancellation},
<String, dynamic>{'googEchoCancellation2': echoCancellation},
<String, dynamic>{'googNoiseSuppression': noiseSuppression},
<String, dynamic>{'googNoiseSuppression2': noiseSuppression},
<String, dynamic>{'googAutoGainControl': autoGainControl},
<String, dynamic>{'googHighpassFilter': highPassFilter},
<String, dynamic>{'googTypingNoiseDetection': typingNoiseDetection},
<String, dynamic>{'googEchoCancellation': false},
<String, dynamic>{'googEchoCancellation2': false},
<String, dynamic>{'googNoiseSuppression': false},
<String, dynamic>{'googNoiseSuppression2': false},
<String, dynamic>{'googAutoGainControl': false},
<String, dynamic>{'googHighpassFilter': false},
<String, dynamic>{'googTypingNoiseDetection': false},
<String, dynamic>{'noiseSuppression': false},
<String, dynamic>{'echoCancellation': false},
<String, dynamic>{'autoGainControl': false},
<String, dynamic>{'voiceIsolation': false},
<String, dynamic>{'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'] = <Map<String, dynamic>>[
<String, dynamic>{'echoCancellation': echoCancellation},
<String, dynamic>{'noiseSuppression': noiseSuppression},
<String, dynamic>{'autoGainControl': autoGainControl},
<String, dynamic>{'voiceIsolation': noiseSuppression},
<String, dynamic>{'googDAEchoCancellation': echoCancellation},
<String, dynamic>{'googEchoCancellation': echoCancellation},
<String, dynamic>{'googEchoCancellation2': echoCancellation},
<String, dynamic>{'googNoiseSuppression': noiseSuppression},
<String, dynamic>{'googNoiseSuppression2': noiseSuppression},
<String, dynamic>{'googAutoGainControl': autoGainControl},
<String, dynamic>{'googHighpassFilter': highPassFilter},
<String, dynamic>{'googTypingNoiseDetection': typingNoiseDetection},
];
}
}

if (deviceId != null) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4d100c

Please sign in to comment.