-
Notifications
You must be signed in to change notification settings - Fork 160
FrameProcessor protocol #865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /* | ||
| * Copyright 2025 LiveKit | ||
| * | ||
| * 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 Foundation | ||
|
|
||
| @objc | ||
| public extension Room { | ||
| func add(audioFrameProcessor: AudioFrameProcessor) { | ||
| add(delegate: audioFrameProcessor) | ||
| AudioManager.shared.capturePostProcessingDelegate = audioFrameProcessor | ||
| } | ||
|
|
||
| func add(videoFrameProcessor: VideoFrameProcessor) { | ||
| add(delegate: videoFrameProcessor) | ||
| (localParticipant.firstCameraVideoTrack as? LocalVideoTrack)?.capturer.processor = videoFrameProcessor | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,14 @@ internal import LiveKitWebRTC | |
|
|
||
| public let kLiveKitKrispAudioProcessorName = "livekit_krisp_noise_cancellation" | ||
|
|
||
| public typealias AudioFrameProcessor = AudioCustomProcessingDelegate & RoomDelegate | ||
|
|
||
| /// Used to modify audio buffers before they are sent to the network or played to the user | ||
| @objc | ||
| public protocol AudioCustomProcessingDelegate: Sendable { | ||
| @objc | ||
| var isEnabled: Bool { get set } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This IS a breaking change for Krisp, we can go for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the alternative would be to not define it here and keep Maybe that's preferable if the alternative is a breaking change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The motivation here is obviously to avoid casting in the audio/video thread.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but implementations could still implement an isEnabled check in the process function and just return early?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or should WE do it internally (not passing frames) (see below) |
||
|
|
||
| /// An optional identifier for the audio processor implementation. | ||
| /// This can be used to identify different types of audio processing (e.g. noise cancellation). | ||
| /// Generally you can leave this as the default value. | ||
|
|
@@ -112,7 +117,10 @@ class AudioCustomProcessingDelegateAdapter: MulticastDelegate<AudioRenderer>, @u | |
|
|
||
| func audioProcessingProcess(audioBuffer: LKRTCAudioBuffer) { | ||
| let lkAudioBuffer = LKAudioBuffer(audioBuffer: audioBuffer) | ||
| target?.audioProcessingProcess(audioBuffer: lkAudioBuffer) | ||
|
|
||
| if let target, target.isEnabled { | ||
| target.audioProcessingProcess(audioBuffer: lkAudioBuffer) | ||
| } | ||
|
|
||
| // Convert to pcmBuffer and notify only if an audioRenderer is added. | ||
| if isDelegatesNotEmpty, let pcmBuffer = lkAudioBuffer.toAVAudioPCMBuffer() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minimal implementation is: