-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow custom audio processing by exposing AudioProcessingModule (#85)
* apm * progress * expose raw buffer * config * runtime delegate update * always create audio processing adapter * delegate nullable * dynamic delegate update thread safety * fix delegate life cycle when swapped * refactor * avoid crash when no apm is passed in * format * make delegate weak & docs * fix memory issue
- Loading branch information
1 parent
ebaa79b
commit 68167af
Showing
19 changed files
with
875 additions
and
140 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2023 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 "RTCAudioBuffer.h" | ||
|
||
#include "modules/audio_processing/audio_buffer.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RTC_OBJC_TYPE (RTCAudioBuffer)() | ||
|
||
- (instancetype)initWithNativeType: (webrtc::AudioBuffer *) audioBuffer; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2023 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/Foundation.h> | ||
|
||
#import "RTCMacros.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
RTC_OBJC_EXPORT | ||
@interface RTC_OBJC_TYPE (RTCAudioBuffer) : NSObject | ||
|
||
@property(nonatomic, readonly) size_t channels; | ||
@property(nonatomic, readonly) size_t frames; | ||
@property(nonatomic, readonly) size_t framesPerBand; | ||
@property(nonatomic, readonly) size_t bands; | ||
|
||
// Returns pointer arrays. Index range from 0 to `frames`. | ||
- (float* _Nonnull)rawBufferForChannel:(size_t)channel; | ||
|
||
// TODO: More convenience methods... | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright 2023 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 "RTCAudioBuffer.h" | ||
|
||
#include "modules/audio_processing/audio_buffer.h" | ||
|
||
@implementation RTC_OBJC_TYPE (RTCAudioBuffer) { | ||
// Raw | ||
webrtc::AudioBuffer *_audioBuffer; | ||
} | ||
|
||
- (size_t)channels { | ||
return _audioBuffer->num_channels(); | ||
} | ||
|
||
- (size_t)frames { | ||
return _audioBuffer->num_frames(); | ||
} | ||
|
||
- (size_t)framesPerBand { | ||
return _audioBuffer->num_frames_per_band(); | ||
} | ||
|
||
- (size_t)bands { | ||
return _audioBuffer->num_bands(); | ||
} | ||
|
||
- (float *)rawBufferForChannel:(size_t)channel { | ||
return _audioBuffer->channels()[channel]; | ||
} | ||
|
||
#pragma mark - Private | ||
|
||
- (instancetype)initWithNativeType:(webrtc::AudioBuffer *)audioBuffer { | ||
if (self = [super init]) { | ||
_audioBuffer = audioBuffer; | ||
} | ||
return self; | ||
} | ||
|
||
@end |
43 changes: 43 additions & 0 deletions
43
sdk/objc/components/audio/RTCAudioCustomProcessingAdapter+Private.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2023 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 "RTCAudioCustomProcessingAdapter.h" | ||
#import "RTCAudioCustomProcessingDelegate.h" | ||
#import "RTCMacros.h" | ||
|
||
#include "modules/audio_processing/include/audio_processing.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RTCAudioCustomProcessingAdapter () | ||
|
||
// Thread safe set/get with os_unfair_lock. | ||
@property(nonatomic, weak, nullable) id<RTCAudioCustomProcessingDelegate> | ||
audioCustomProcessingDelegate; | ||
|
||
// Direct read access without lock. | ||
@property(nonatomic, readonly, weak, nullable) id<RTCAudioCustomProcessingDelegate> | ||
rawAudioCustomProcessingDelegate; | ||
|
||
@property(nonatomic, readonly) std::unique_ptr<webrtc::CustomProcessing> | ||
nativeAudioCustomProcessingModule; | ||
|
||
- (instancetype)initWithDelegate: | ||
(nullable id<RTCAudioCustomProcessingDelegate>)audioCustomProcessingDelegate; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
28 changes: 28 additions & 0 deletions
28
sdk/objc/components/audio/RTCAudioCustomProcessingAdapter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2023 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/Foundation.h> | ||
#import "RTCMacros.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface RTCAudioCustomProcessingAdapter : NSObject | ||
|
||
- (instancetype)init NS_UNAVAILABLE; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.