-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
176 additions
and
16 deletions.
There are no files selected for viewing
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
Binary file modified
BIN
+6.14 KB
(100%)
stream-webrtc-android/libs/arm64-v8a/libjingle_peerconnection_so.so
Binary file not shown.
Binary file modified
BIN
+3.03 KB
(100%)
stream-webrtc-android/libs/armeabi-v7a/libjingle_peerconnection_so.so
Binary file not shown.
Binary file modified
BIN
+5.63 KB
(100%)
stream-webrtc-android/libs/x86/libjingle_peerconnection_so.so
Binary file not shown.
Binary file modified
BIN
+5.73 KB
(100%)
stream-webrtc-android/libs/x86_64/libjingle_peerconnection_so.so
Binary file not shown.
141 changes: 127 additions & 14 deletions
141
stream-webrtc-android/src/main/java/org/webrtc/ExternalAudioProcessingFactory.java
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 |
---|---|---|
@@ -1,31 +1,144 @@ | ||
/* | ||
* Copyright 2022 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. | ||
*/ | ||
|
||
package org.webrtc; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import androidx.annotation.Nullable; | ||
import org.webrtc.AudioProcessingFactory; | ||
|
||
|
||
public class ExternalAudioProcessingFactory implements AudioProcessingFactory { | ||
|
||
private final String libname; | ||
/** | ||
* Interface for external audio processing. | ||
*/ | ||
public static interface AudioProcessing { | ||
/** | ||
* Called when the processor should be initialized with a new sample rate and | ||
* number of channels. | ||
*/ | ||
@CalledByNative("AudioProcessing") | ||
void initialize(int sampleRateHz, int numChannels); | ||
/** Called when the processor should be reset with a new sample rate. */ | ||
@CalledByNative("AudioProcessing") | ||
void reset(int newRate); | ||
/** | ||
* Processes the given capture or render signal. NOTE: `buffer.data` will be | ||
* freed once this function returns so callers who want to use the data | ||
* asynchronously must make sure to copy it first. | ||
*/ | ||
@CalledByNative("AudioProcessing") | ||
void process(int numBands, int numFrames, ByteBuffer buffer); | ||
} | ||
|
||
public ExternalAudioProcessingFactory(String libname) { | ||
if (libname == null) { | ||
throw new NullPointerException("libname must not be null."); | ||
} | ||
if (libname.isEmpty()) { | ||
throw new IllegalArgumentException("libname must not be empty."); | ||
} | ||
this.libname = libname; | ||
private long apmPtr; | ||
private long capturePostProcessingPtr; | ||
private long renderPreProcessingPtr; | ||
|
||
public ExternalAudioProcessingFactory() { | ||
apmPtr = nativeGetDefaultApm(); | ||
capturePostProcessingPtr = 0; | ||
renderPreProcessingPtr = 0; | ||
} | ||
|
||
@Override | ||
public long createNative() { | ||
return nativeCreateAudioProcessingModule(libname); | ||
if(apmPtr == 0) { | ||
apmPtr = nativeGetDefaultApm(); | ||
} | ||
return apmPtr; | ||
} | ||
|
||
public void destroyNative() { | ||
nativeDestroyAudioProcessingModule(); | ||
/** | ||
* Sets the capture post processing module. | ||
* This module is applied to the audio signal after capture and before sending | ||
* to the audio encoder. | ||
*/ | ||
public void setCapturePostProcessing(@Nullable AudioProcessing processing) { | ||
checkExternalAudioProcessorExists(); | ||
long newPtr = nativeSetCapturePostProcessing(processing); | ||
if (capturePostProcessingPtr != 0) { | ||
JniCommon.nativeReleaseRef(capturePostProcessingPtr); | ||
capturePostProcessingPtr = 0; | ||
} | ||
capturePostProcessingPtr = newPtr; | ||
} | ||
|
||
private static native long nativeCreateAudioProcessingModule(String libname); | ||
/** | ||
* Sets the render pre processing module. | ||
* This module is applied to the audio signal after receiving from the audio | ||
* decoder and before rendering. | ||
*/ | ||
public void setRenderPreProcessing(@Nullable AudioProcessing processing) { | ||
checkExternalAudioProcessorExists(); | ||
long newPtr = nativeSetRenderPreProcessing(processing); | ||
if (renderPreProcessingPtr != 0) { | ||
JniCommon.nativeReleaseRef(renderPreProcessingPtr); | ||
renderPreProcessingPtr = 0; | ||
} | ||
renderPreProcessingPtr = newPtr; | ||
} | ||
|
||
/** | ||
* Sets the bypass flag for the capture post processing module. | ||
* If true, the registered audio processing will be bypassed. | ||
*/ | ||
public void setBypassFlagForCapturePost( boolean bypass) { | ||
checkExternalAudioProcessorExists(); | ||
nativeSetBypassFlagForCapturePost(bypass); | ||
} | ||
|
||
/** | ||
* Sets the bypass flag for the render pre processing module. | ||
* If true, the registered audio processing will be bypassed. | ||
*/ | ||
public void setBypassFlagForRenderPre( boolean bypass) { | ||
checkExternalAudioProcessorExists(); | ||
nativeSetBypassFlagForRenderPre(bypass); | ||
} | ||
|
||
/** | ||
* Destroys the ExternalAudioProcessor. | ||
*/ | ||
public void destroy() { | ||
checkExternalAudioProcessorExists(); | ||
if (renderPreProcessingPtr != 0) { | ||
JniCommon.nativeReleaseRef(renderPreProcessingPtr); | ||
renderPreProcessingPtr = 0; | ||
} | ||
if (capturePostProcessingPtr != 0) { | ||
JniCommon.nativeReleaseRef(capturePostProcessingPtr); | ||
capturePostProcessingPtr = 0; | ||
} | ||
nativeDestroy(); | ||
apmPtr = 0; | ||
} | ||
|
||
private static native void nativeDestroyAudioProcessingModule(); | ||
private void checkExternalAudioProcessorExists() { | ||
if (apmPtr == 0) { | ||
throw new IllegalStateException("ExternalAudioProcessor has been disposed."); | ||
} | ||
} | ||
|
||
private static native long nativeGetDefaultApm(); | ||
private static native long nativeSetCapturePostProcessing(AudioProcessing processing); | ||
private static native long nativeSetRenderPreProcessing(AudioProcessing processing); | ||
private static native void nativeSetBypassFlagForCapturePost(boolean bypass); | ||
private static native void nativeSetBypassFlagForRenderPre(boolean bypass); | ||
private static native void nativeDestroy(); | ||
} |
31 changes: 31 additions & 0 deletions
31
stream-webrtc-android/src/main/java/org/webrtc/NativeExternalAudioProcessingFactory.java
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,31 @@ | ||
package org.webrtc; | ||
|
||
public class NativeExternalAudioProcessingFactory implements AudioProcessingFactory { | ||
|
||
private final String libname; | ||
|
||
public NativeExternalAudioProcessingFactory(String libname) { | ||
if (libname == null) { | ||
throw new NullPointerException("libname must not be null."); | ||
} | ||
if (libname.isEmpty()) { | ||
throw new IllegalArgumentException("libname must not be empty."); | ||
} | ||
this.libname = libname; | ||
} | ||
|
||
@Override | ||
public long createNative() { | ||
return nativeCreateAudioProcessingModule(libname); | ||
} | ||
|
||
public void destroyNative() { | ||
nativeDestroyAudioProcessingModule(); | ||
} | ||
|
||
private static native long nativeCreateAudioProcessingModule(String libname); | ||
|
||
|
||
private static native void nativeDestroyAudioProcessingModule(); | ||
|
||
} |