Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Runtime/Plugins/ffi-ios-arm64/liblivekit_ffi.a
Git LFS file not shown
4 changes: 2 additions & 2 deletions Runtime/Plugins/ffi-macos-arm64/liblivekit_ffi.dylib
Git LFS file not shown
8 changes: 8 additions & 0 deletions Runtime/Plugins/iOS.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 70 additions & 0 deletions Runtime/Plugins/iOS/LiveKitAudioSession.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <AVFoundation/AVFoundation.h>

extern "C" {

/// Configures the iOS audio session for VoIP/WebRTC use.
/// This sets AVAudioSessionCategoryPlayAndRecord with VoiceChat mode,
/// which enables the VPIO (Voice Processing IO) AudioUnit for:
/// - Hardware echo cancellation (AEC)
/// - Automatic gain control (AGC)
/// - Noise suppression (NS)
///
/// Call this before creating PlatformAudio to ensure WebRTC can
/// properly initialize the microphone and speaker.
void LiveKit_ConfigureAudioSessionForVoIP() {
AVAudioSession* session = [AVAudioSession sharedInstance];
NSError* error = nil;

// Configure for VoIP with echo cancellation
BOOL success = [session setCategory:AVAudioSessionCategoryPlayAndRecord
mode:AVAudioSessionModeVoiceChat
options:AVAudioSessionCategoryOptionDefaultToSpeaker |
AVAudioSessionCategoryOptionAllowBluetooth |
AVAudioSessionCategoryOptionAllowBluetoothA2DP
error:&error];

if (!success || error) {
NSLog(@"LiveKit: Failed to configure VoIP audio session: %@", error.localizedDescription);
return;
}

// Activate the audio session
success = [session setActive:YES error:&error];
if (!success || error) {
NSLog(@"LiveKit: Failed to activate audio session: %@", error.localizedDescription);
return;
}

NSLog(@"LiveKit: Audio session configured for VoIP (PlayAndRecord + VoiceChat mode)");
}

/// Restores the audio session to the default ambient category.
/// Call this when PlatformAudio is disposed if you want to restore
/// the original audio behavior.
void LiveKit_RestoreDefaultAudioSession() {
AVAudioSession* session = [AVAudioSession sharedInstance];
NSError* error = nil;

[session setCategory:AVAudioSessionCategoryAmbient error:&error];
if (error) {
NSLog(@"LiveKit: Failed to restore default audio session: %@", error.localizedDescription);
}
}

}
42 changes: 42 additions & 0 deletions Runtime/Plugins/iOS/LiveKitAudioSession.mm.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Runtime/Plugins/iOS/liblivekit_ffi.a
Git LFS file not shown
27 changes: 27 additions & 0 deletions Runtime/Plugins/iOS/liblivekit_ffi.a.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Runtime/Scripts/Internal/FFIClients/FfiRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,19 @@ public static void Inject<T>(this FfiRequest ffiRequest, T request)
case RemixAndResampleRequest remixAndResampleRequest:
ffiRequest.RemixAndResample = remixAndResampleRequest;
break;
// PlatformAudio
case NewPlatformAudioRequest newPlatformAudioRequest:
ffiRequest.NewPlatformAudio = newPlatformAudioRequest;
break;
case GetAudioDevicesRequest getAudioDevicesRequest:
ffiRequest.GetAudioDevices = getAudioDevicesRequest;
break;
case SetRecordingDeviceRequest setRecordingDeviceRequest:
ffiRequest.SetRecordingDevice = setRecordingDeviceRequest;
break;
case SetPlayoutDeviceRequest setPlayoutDeviceRequest:
ffiRequest.SetPlayoutDevice = setPlayoutDeviceRequest;
break;
case LocalTrackMuteRequest localTrackMuteRequest:
ffiRequest.LocalTrackMute = localTrackMuteRequest;
break;
Expand Down
Loading
Loading