Android: Add AudioDeviceModule interface and clean up implementation code
This CL introduces sdk/android/api/org/webrtc/audio/AudioDeviceModule.java, which is the new interface for audio device modules on Android. This CL also refactors the main AudioDeviceModule implementation, which is sdk/android/api/org/webrtc/audio/JavaAudioDeviceModule.java and makes it conform to the new interface. The old code used global static methods to configure the audio device code. This CL gets rid of all that and uses a builder pattern in JavaAudioDeviceModule instead. The only two dynamic methods left in the interface are setSpeakerMute() and setMicrophoneMute(). Removing the global static methods allowed a significant cleanup, and e.g. the file sdk/android/src/jni/audio_device/audio_manager.cc has been completely removed. The PeerConnectionFactory interface is also updated to allow passing in an external AudioDeviceModule. The current built-in ADM is encapsulated under LegacyAudioDeviceModule.java, which is the default for now to ensure backwards compatibility. Bug: webrtc:7452 Change-Id: I64d5f4dba9a004da001f1acb2bd0c1b1f2b64f21 Reviewed-on: https://webrtc-review.googlesource.com/65360 Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Reviewed-by: Paulina Hensman <phensman@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22765}
This commit is contained in:
committed by
Commit Bot
parent
3ab5c40f72
commit
66f1e9eb34
@ -13,6 +13,8 @@ package org.webrtc;
|
||||
import android.content.Context;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import org.webrtc.audio.AudioDeviceModule;
|
||||
import org.webrtc.audio.LegacyAudioDeviceModule;
|
||||
|
||||
/**
|
||||
* Java wrapper for a C++ PeerConnectionFactoryInterface. Main entry point to
|
||||
@ -132,6 +134,7 @@ public class PeerConnectionFactory {
|
||||
|
||||
public static class Builder {
|
||||
private @Nullable Options options;
|
||||
private @Nullable AudioDeviceModule audioDeviceModule = new LegacyAudioDeviceModule();
|
||||
private @Nullable VideoEncoderFactory encoderFactory;
|
||||
private @Nullable VideoDecoderFactory decoderFactory;
|
||||
private @Nullable AudioProcessingFactory audioProcessingFactory;
|
||||
@ -144,6 +147,11 @@ public class PeerConnectionFactory {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAudioDeviceModule(AudioDeviceModule audioDeviceModule) {
|
||||
this.audioDeviceModule = audioDeviceModule;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setVideoEncoderFactory(VideoEncoderFactory encoderFactory) {
|
||||
this.encoderFactory = encoderFactory;
|
||||
return this;
|
||||
@ -170,7 +178,7 @@ public class PeerConnectionFactory {
|
||||
}
|
||||
|
||||
public PeerConnectionFactory createPeerConnectionFactory() {
|
||||
return new PeerConnectionFactory(options, encoderFactory, decoderFactory,
|
||||
return new PeerConnectionFactory(options, audioDeviceModule, encoderFactory, decoderFactory,
|
||||
audioProcessingFactory, fecControllerFactoryFactory);
|
||||
}
|
||||
}
|
||||
@ -255,8 +263,8 @@ public class PeerConnectionFactory {
|
||||
public PeerConnectionFactory(
|
||||
Options options, VideoEncoderFactory encoderFactory, VideoDecoderFactory decoderFactory) {
|
||||
checkInitializeHasBeenCalled();
|
||||
nativeFactory = nativeCreatePeerConnectionFactory(
|
||||
ContextUtils.getApplicationContext(), options, encoderFactory, decoderFactory, 0, 0);
|
||||
nativeFactory = nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options,
|
||||
0 /* audioDeviceModule */, encoderFactory, decoderFactory, 0, 0);
|
||||
if (nativeFactory == 0) {
|
||||
throw new RuntimeException("Failed to initialize PeerConnectionFactory!");
|
||||
}
|
||||
@ -265,16 +273,17 @@ public class PeerConnectionFactory {
|
||||
@Deprecated
|
||||
public PeerConnectionFactory(Options options, VideoEncoderFactory encoderFactory,
|
||||
VideoDecoderFactory decoderFactory, AudioProcessingFactory audioProcessingFactory) {
|
||||
this(options, encoderFactory, decoderFactory, audioProcessingFactory,
|
||||
null /* fecControllerFactoryFactory */);
|
||||
this(options, new LegacyAudioDeviceModule(), encoderFactory, decoderFactory,
|
||||
audioProcessingFactory, null /* fecControllerFactoryFactory */);
|
||||
}
|
||||
|
||||
private PeerConnectionFactory(Options options, @Nullable VideoEncoderFactory encoderFactory,
|
||||
@Nullable VideoDecoderFactory decoderFactory,
|
||||
private PeerConnectionFactory(Options options, @Nullable AudioDeviceModule audioDeviceModule,
|
||||
@Nullable VideoEncoderFactory encoderFactory, @Nullable VideoDecoderFactory decoderFactory,
|
||||
@Nullable AudioProcessingFactory audioProcessingFactory,
|
||||
@Nullable FecControllerFactoryFactoryInterface fecControllerFactoryFactory) {
|
||||
checkInitializeHasBeenCalled();
|
||||
nativeFactory = nativeCreatePeerConnectionFactory(ContextUtils.getApplicationContext(), options,
|
||||
audioDeviceModule == null ? 0 : audioDeviceModule.getNativeAudioDeviceModulePointer(),
|
||||
encoderFactory, decoderFactory,
|
||||
audioProcessingFactory == null ? 0 : audioProcessingFactory.createNative(),
|
||||
fecControllerFactoryFactory == null ? 0 : fecControllerFactoryFactory.createNative());
|
||||
@ -483,8 +492,9 @@ public class PeerConnectionFactory {
|
||||
private static native boolean nativeStartInternalTracingCapture(String tracingFilename);
|
||||
private static native void nativeStopInternalTracingCapture();
|
||||
private static native long nativeCreatePeerConnectionFactory(Context context, Options options,
|
||||
VideoEncoderFactory encoderFactory, VideoDecoderFactory decoderFactory,
|
||||
long nativeAudioProcessor, long nativeFecControllerFactory);
|
||||
long nativeAudioDeviceModule, VideoEncoderFactory encoderFactory,
|
||||
VideoDecoderFactory decoderFactory, long nativeAudioProcessor,
|
||||
long nativeFecControllerFactory);
|
||||
private static native long nativeCreatePeerConnection(long factory,
|
||||
PeerConnection.RTCConfiguration rtcConfig, MediaConstraints constraints, long nativeObserver);
|
||||
private static native long nativeCreateLocalMediaStream(long factory, String label);
|
||||
|
||||
Reference in New Issue
Block a user