Android JavaAudioDeviceModule: Defer creation of native ADM
Any native call before PeerConnectionFactory.initialize() will fail. This means creation of JavaAudioDeviceModule will fail if it's created before PeerConnectionFactory.initialize(). Clients should technically always call PeerConnectionFactory.initialize() first, but we can help the situation by deferring creation of the native ADM until it's actually needed. Bug: webrtc:7452 Change-Id: I53df2bdb980a8bdc413975f1cea6bcf297b453d5 Reviewed-on: https://webrtc-review.googlesource.com/70763 Reviewed-by: Paulina Hensman <phensman@webrtc.org> Commit-Queue: Magnus Jedvert <magjed@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22936}
This commit is contained in:
committed by
Commit Bot
parent
0ad2d8af39
commit
aedd090b72
@ -143,9 +143,8 @@ public class JavaAudioDeviceModule implements AudioDeviceModule {
|
||||
samplesReadyCallback, useHardwareAcousticEchoCanceler, useHardwareNoiseSuppressor);
|
||||
final WebRtcAudioTrack audioOutput =
|
||||
new WebRtcAudioTrack(context, audioManager, audioTrackErrorCallback);
|
||||
final long nativeAudioDeviceModule = nativeCreateAudioDeviceModule(context, audioManager,
|
||||
audioInput, audioOutput, sampleRate, useStereoInput, useStereoOutput);
|
||||
return new JavaAudioDeviceModule(audioInput, audioOutput, nativeAudioDeviceModule);
|
||||
return new JavaAudioDeviceModule(context, audioManager, audioInput, audioOutput, sampleRate,
|
||||
useStereoInput, useStereoOutput);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,27 +232,47 @@ public class JavaAudioDeviceModule implements AudioDeviceModule {
|
||||
return WebRtcAudioEffects.isNoiseSuppressorSupported();
|
||||
}
|
||||
|
||||
private final Context context;
|
||||
private final AudioManager audioManager;
|
||||
private final WebRtcAudioRecord audioInput;
|
||||
private final WebRtcAudioTrack audioOutput;
|
||||
private final int sampleRate;
|
||||
private final boolean useStereoInput;
|
||||
private final boolean useStereoOutput;
|
||||
|
||||
private final Object nativeLock = new Object();
|
||||
private long nativeAudioDeviceModule;
|
||||
|
||||
private JavaAudioDeviceModule(
|
||||
WebRtcAudioRecord audioInput, WebRtcAudioTrack audioOutput, long nativeAudioDeviceModule) {
|
||||
private JavaAudioDeviceModule(Context context, AudioManager audioManager,
|
||||
WebRtcAudioRecord audioInput, WebRtcAudioTrack audioOutput, int sampleRate,
|
||||
boolean useStereoInput, boolean useStereoOutput) {
|
||||
this.context = context;
|
||||
this.audioManager = audioManager;
|
||||
this.audioInput = audioInput;
|
||||
this.audioOutput = audioOutput;
|
||||
this.nativeAudioDeviceModule = nativeAudioDeviceModule;
|
||||
this.sampleRate = sampleRate;
|
||||
this.useStereoInput = useStereoInput;
|
||||
this.useStereoOutput = useStereoOutput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getNativeAudioDeviceModulePointer() {
|
||||
return nativeAudioDeviceModule;
|
||||
synchronized (nativeLock) {
|
||||
if (nativeAudioDeviceModule == 0) {
|
||||
nativeAudioDeviceModule = nativeCreateAudioDeviceModule(context, audioManager, audioInput,
|
||||
audioOutput, sampleRate, useStereoInput, useStereoOutput);
|
||||
}
|
||||
return nativeAudioDeviceModule;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
if (nativeAudioDeviceModule != 0) {
|
||||
JniCommon.nativeReleaseRef(nativeAudioDeviceModule);
|
||||
nativeAudioDeviceModule = 0;
|
||||
synchronized (nativeLock) {
|
||||
if (nativeAudioDeviceModule != 0) {
|
||||
JniCommon.nativeReleaseRef(nativeAudioDeviceModule);
|
||||
nativeAudioDeviceModule = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user