diff --git a/webrtc-jni/src/main/cpp/include/JNI_AudioDeviceModule.h b/webrtc-jni/src/main/cpp/include/JNI_AudioDeviceModule.h index c7489cd..1f89e54 100644 --- a/webrtc-jni/src/main/cpp/include/JNI_AudioDeviceModule.h +++ b/webrtc-jni/src/main/cpp/include/JNI_AudioDeviceModule.h @@ -149,7 +149,7 @@ extern "C" { * Signature: ()V */ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_audio_AudioDeviceModule_initialize - (JNIEnv *, jobject); + (JNIEnv *, jobject, jobject); #ifdef __cplusplus } diff --git a/webrtc-jni/src/main/cpp/src/JNI_AudioDeviceModule.cpp b/webrtc-jni/src/main/cpp/src/JNI_AudioDeviceModule.cpp index 5b7e667..7e3a81c 100644 --- a/webrtc-jni/src/main/cpp/src/JNI_AudioDeviceModule.cpp +++ b/webrtc-jni/src/main/cpp/src/JNI_AudioDeviceModule.cpp @@ -17,6 +17,7 @@ #include "JNI_AudioDeviceModule.h" #include "Exception.h" #include "JavaArrayList.h" +#include "JavaEnums.h" #include "JavaError.h" #include "JavaObject.h" #include "JavaRef.h" @@ -305,7 +306,7 @@ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_audio_AudioDeviceModule_disp } JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_audio_AudioDeviceModule_initialize -(JNIEnv * env, jobject caller) +(JNIEnv * env, jobject caller, jobject jAudioLayer) { std::unique_ptr taskQueueFactory = webrtc::CreateDefaultTaskQueueFactory(); @@ -314,8 +315,10 @@ JNIEXPORT void JNICALL Java_dev_onvoid_webrtc_media_audio_AudioDeviceModule_init return; } + const auto audioLayer = jni::JavaEnums::toNative(env, jAudioLayer); + rtc::scoped_refptr audioModule = webrtc::AudioDeviceModule::Create( - webrtc::AudioDeviceModule::kPlatformDefaultAudio, taskQueueFactory.release()); + audioLayer, taskQueueFactory.release()); if (!audioModule) { env->Throw(jni::JavaError(env, "Create AudioDeviceModule failed")); diff --git a/webrtc-jni/src/main/cpp/src/WebRTCContext.cpp b/webrtc-jni/src/main/cpp/src/WebRTCContext.cpp index 3b696b7..1c0f947 100644 --- a/webrtc-jni/src/main/cpp/src/WebRTCContext.cpp +++ b/webrtc-jni/src/main/cpp/src/WebRTCContext.cpp @@ -79,6 +79,7 @@ namespace jni JavaEnums::add(env, PKG"TlsCertPolicy"); JavaEnums::add(env, PKG"RTCRtpTransceiverDirection"); JavaEnums::add(env, PKG"RTCSdpType"); + JavaEnums::add(env, PKG_AUDIO"AudioLayer"); JavaEnums::add(env, PKG"RTCStatsType"); JavaFactories::add(env, PKG_MEDIA"audio/AudioSource"); diff --git a/webrtc/src/main/java/dev/onvoid/webrtc/media/audio/AudioDeviceModule.java b/webrtc/src/main/java/dev/onvoid/webrtc/media/audio/AudioDeviceModule.java index 2b7ae7c..6689d91 100644 --- a/webrtc/src/main/java/dev/onvoid/webrtc/media/audio/AudioDeviceModule.java +++ b/webrtc/src/main/java/dev/onvoid/webrtc/media/audio/AudioDeviceModule.java @@ -21,7 +21,11 @@ public class AudioDeviceModule extends DisposableNativeObject { public AudioDeviceModule() { - initialize(); + initialize(AudioLayer.kPlatformDefaultAudio); + } + + public AudioDeviceModule(AudioLayer audioLayer) { + initialize(audioLayer); } public native void initPlayout(); @@ -59,6 +63,6 @@ public AudioDeviceModule() { @Override public native void dispose(); - private native void initialize(); + private native void initialize(AudioLayer audioLayer); } diff --git a/webrtc/src/main/java/dev/onvoid/webrtc/media/audio/AudioLayer.java b/webrtc/src/main/java/dev/onvoid/webrtc/media/audio/AudioLayer.java new file mode 100644 index 0000000..7b1bab3 --- /dev/null +++ b/webrtc/src/main/java/dev/onvoid/webrtc/media/audio/AudioLayer.java @@ -0,0 +1,15 @@ +package dev.onvoid.webrtc.media.audio; + +public enum AudioLayer { + kPlatformDefaultAudio, + kWindowsCoreAudio, + kWindowsCoreAudio2, + kLinuxAlsaAudio, + kLinuxPulseAudio, + kAndroidJavaAudio, + kAndroidOpenSLESAudio, + kAndroidJavaInputAndOpenSLESOutputAudio, + kAndroidAAudioAudio, + kAndroidJavaInputAndAAudioOutputAudio, + kDummyAudio +} diff --git a/webrtc/src/test/java/dev/onvoid/webrtc/DummyAudioDeviceModuleTest.java b/webrtc/src/test/java/dev/onvoid/webrtc/DummyAudioDeviceModuleTest.java new file mode 100644 index 0000000..586da98 --- /dev/null +++ b/webrtc/src/test/java/dev/onvoid/webrtc/DummyAudioDeviceModuleTest.java @@ -0,0 +1,39 @@ +package dev.onvoid.webrtc; + +import dev.onvoid.webrtc.media.audio.AudioDeviceModule; +import dev.onvoid.webrtc.media.audio.AudioLayer; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@Execution(ExecutionMode.SAME_THREAD) +public class DummyAudioDeviceModuleTest { + private PeerConnectionFactory factory; + + @BeforeAll + void initFactory() { + factory = new PeerConnectionFactory(new AudioDeviceModule()); + } + + @AfterAll + void disposeFactory() { + factory.dispose(); + } + + @Test + void createPeerConnectionWithDummyAudio() { + RTCConfiguration config = new RTCConfiguration(); + RTCPeerConnection peerConnection = factory.createPeerConnection(config, + candidate -> { }); + + assertNotNull(peerConnection); + + peerConnection.close(); + } +}