Reland "Reland "Delete old Android ADM.""
This reverts commit 38a28603fd7b2eec46a362105b225dd6f08b4137. Reason for revert: Attempt to reland, now that WebRTC dependency cycle has been broken. Original change's description: > Revert "Reland "Delete old Android ADM."" > > This reverts commit 6e4d7e606c4327eaa9298193e22794fcb9b30218. > > Reason for revert: Still breaks downstream build (though in a different way this time) > > Original change's description: > > Reland "Delete old Android ADM." > > > > This is a reland of commit 4ec3e9c98873520b3171d40ab0426b2f05edbbd2 > > > > Original change's description: > > > Delete old Android ADM. > > > > > > The schedule move Android ADM code to sdk directory have been around > > > for several years, but the old code still not delete. > > > > > > Bug: webrtc:7452 > > > Change-Id: I0f75c680f71f0b2ce614de6cbd9f124c2a59d453 > > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/264620 > > > Reviewed-by: Magnus Jedvert <magjed@webrtc.org> > > > Commit-Queue: Henrik Andreassson <henrika@webrtc.org> > > > Reviewed-by: Henrik Andreassson <henrika@webrtc.org> > > > Cr-Commit-Position: refs/heads/main@{#37174} > > > > Bug: webrtc:7452 > > Change-Id: Icabad23e72c8258a854b7809a93811161517266c > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265872 > > Reviewed-by: Henrik Andreassson <henrika@webrtc.org> > > Commit-Queue: Björn Terelius <terelius@webrtc.org> > > Cr-Commit-Position: refs/heads/main@{#37236} > > Bug: webrtc:7452 > Change-Id: Ide8fbd55fadd7aed9989053afff7c63c04f1320f > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266023 > Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> > Commit-Queue: Björn Terelius <terelius@webrtc.org> > Owners-Override: Björn Terelius <terelius@webrtc.org> > Cr-Commit-Position: refs/heads/main@{#37242} Bug: webrtc:7452 Change-Id: I6946d0fc28cf4c08387e451e6a07765f7410ce7c Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266980 Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com> Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Commit-Queue: Björn Terelius <terelius@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37356}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
a2476e3783
commit
db30009304
@ -1,4 +1,5 @@
|
||||
include_rules = [
|
||||
"+modules/audio_device/include/audio_device.h",
|
||||
"+modules/utility/include/jvm_android.h",
|
||||
"+system_wrappers/include",
|
||||
]
|
||||
|
||||
@ -24,10 +24,12 @@
|
||||
#include "sdk/android/src/jni/audio_device/aaudio_recorder.h"
|
||||
#endif
|
||||
|
||||
#include "sdk/android/native_api/jni/application_context_provider.h"
|
||||
#include "sdk/android/src/jni/audio_device/audio_record_jni.h"
|
||||
#include "sdk/android/src/jni/audio_device/audio_track_jni.h"
|
||||
#include "sdk/android/src/jni/audio_device/opensles_player.h"
|
||||
#include "sdk/android/src/jni/audio_device/opensles_recorder.h"
|
||||
#include "sdk/android/src/jni/jvm.h"
|
||||
#include "system_wrappers/include/metrics.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -70,6 +72,31 @@ rtc::scoped_refptr<AudioDeviceModule> CreateAAudioAudioDeviceModule(
|
||||
std::make_unique<jni::AAudioRecorder>(input_parameters),
|
||||
std::make_unique<jni::AAudioPlayer>(output_parameters));
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<AudioDeviceModule>
|
||||
CreateJavaInputAndAAudioOutputAudioDeviceModule(JNIEnv* env,
|
||||
jobject application_context) {
|
||||
RTC_DLOG(LS_INFO) << __FUNCTION__;
|
||||
// Get default audio input/output parameters.
|
||||
const JavaParamRef<jobject> j_context(application_context);
|
||||
const ScopedJavaLocalRef<jobject> j_audio_manager =
|
||||
jni::GetAudioManager(env, j_context);
|
||||
AudioParameters input_parameters;
|
||||
AudioParameters output_parameters;
|
||||
GetDefaultAudioParameters(env, application_context, &input_parameters,
|
||||
&output_parameters);
|
||||
// Create ADM from AudioRecord and OpenSLESPlayer.
|
||||
auto audio_input = std::make_unique<jni::AudioRecordJni>(
|
||||
env, input_parameters, jni::kLowLatencyModeDelayEstimateInMilliseconds,
|
||||
jni::AudioRecordJni::CreateJavaWebRtcAudioRecord(env, j_context,
|
||||
j_audio_manager));
|
||||
|
||||
return CreateAudioDeviceModuleFromInputAndOutput(
|
||||
AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio,
|
||||
false /* use_stereo_input */, false /* use_stereo_output */,
|
||||
jni::kLowLatencyModeDelayEstimateInMilliseconds, std::move(audio_input),
|
||||
std::make_unique<jni::AAudioPlayer>(output_parameters));
|
||||
}
|
||||
#endif
|
||||
|
||||
rtc::scoped_refptr<AudioDeviceModule> CreateJavaAudioDeviceModule(
|
||||
@ -152,4 +179,57 @@ CreateJavaInputAndOpenSLESOutputAudioDeviceModule(JNIEnv* env,
|
||||
std::move(audio_output));
|
||||
}
|
||||
|
||||
rtc::scoped_refptr<AudioDeviceModule> CreateAndroidAudioDeviceModule(
|
||||
AudioDeviceModule::AudioLayer audio_layer) {
|
||||
auto env = AttachCurrentThreadIfNeeded();
|
||||
auto j_context = webrtc::GetAppContext(env);
|
||||
// Select best possible combination of audio layers.
|
||||
if (audio_layer == AudioDeviceModule::kPlatformDefaultAudio) {
|
||||
#if defined(WEBRTC_AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO)
|
||||
// AAudio based audio for both input and output.
|
||||
audio_layer = AudioDeviceModule::kAndroidAAudioAudio;
|
||||
#else
|
||||
if (jni::IsLowLatencyInputSupported(env, j_context) &&
|
||||
jni::IsLowLatencyOutputSupported(env, j_context)) {
|
||||
// Use OpenSL ES for both playout and recording.
|
||||
audio_layer = AudioDeviceModule::kAndroidOpenSLESAudio;
|
||||
} else if (jni::IsLowLatencyOutputSupported(env, j_context) &&
|
||||
!jni::IsLowLatencyInputSupported(env, j_context)) {
|
||||
// Use OpenSL ES for output on devices that only supports the
|
||||
// low-latency output audio path.
|
||||
audio_layer = AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio;
|
||||
} else {
|
||||
// Use Java-based audio in both directions when low-latency output is
|
||||
// not supported.
|
||||
audio_layer = AudioDeviceModule::kAndroidJavaAudio;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
switch (audio_layer) {
|
||||
case AudioDeviceModule::kAndroidJavaAudio:
|
||||
// Java audio for both input and output audio.
|
||||
return CreateJavaAudioDeviceModule(env, j_context.obj());
|
||||
case AudioDeviceModule::kAndroidOpenSLESAudio:
|
||||
// OpenSL ES based audio for both input and output audio.
|
||||
return CreateOpenSLESAudioDeviceModule(env, j_context.obj());
|
||||
case AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio:
|
||||
// Java audio for input and OpenSL ES for output audio (i.e. mixed APIs).
|
||||
// This combination provides low-latency output audio and at the same
|
||||
// time support for HW AEC using the AudioRecord Java API.
|
||||
return CreateJavaInputAndOpenSLESOutputAudioDeviceModule(
|
||||
env, j_context.obj());
|
||||
#if defined(WEBRTC_AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO)
|
||||
case AudioDeviceModule::kAndroidAAudioAudio:
|
||||
// AAudio based audio for both input and output.
|
||||
return CreateAAudioAudioDeviceModule(env, j_context.obj());
|
||||
case AudioDeviceModule::kAndroidJavaInputAndAAudioOutputAudio:
|
||||
// Java audio for input and AAudio for output audio (i.e. mixed APIs).
|
||||
return CreateJavaInputAndAAudioOutputAudioDeviceModule(
|
||||
env, j_context.obj());
|
||||
#endif
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -32,8 +32,17 @@ rtc::scoped_refptr<AudioDeviceModule> CreateOpenSLESAudioDeviceModule(
|
||||
jobject application_context);
|
||||
|
||||
rtc::scoped_refptr<AudioDeviceModule>
|
||||
CreateJavaInputAndOpenSLESOutputAudioDeviceModule(JNIEnv* env,
|
||||
jobject application_context);
|
||||
CreateJavaInputAndOpenSLESOutputAudioDeviceModule(
|
||||
JNIEnv* env,
|
||||
jobject application_context);
|
||||
|
||||
rtc::scoped_refptr<AudioDeviceModule>
|
||||
CreateJavaInputAndAAudioOutputAudioDeviceModule(
|
||||
JNIEnv* env,
|
||||
jobject application_context);
|
||||
|
||||
rtc::scoped_refptr<AudioDeviceModule> CreateAndroidAudioDeviceModule(
|
||||
AudioDeviceModule::AudioLayer audio_layer);
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
|
||||
22
sdk/android/native_api/jni/application_context_provider.cc
Normal file
22
sdk/android/native_api/jni/application_context_provider.cc
Normal file
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#include "sdk/android/native_api/jni/application_context_provider.h"
|
||||
|
||||
#include "sdk/android/generated_native_api_jni/ApplicationContextProvider_jni.h"
|
||||
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScopedJavaLocalRef<jobject> GetAppContext(JNIEnv* jni) {
|
||||
return ScopedJavaLocalRef<jobject>(
|
||||
jni::Java_ApplicationContextProvider_getApplicationContext(jni));
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
21
sdk/android/native_api/jni/application_context_provider.h
Normal file
21
sdk/android/native_api/jni/application_context_provider.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
#ifndef SDK_ANDROID_NATIVE_API_JNI_APPLICATION_CONTEXT_PROVIDER_H_
|
||||
#define SDK_ANDROID_NATIVE_API_JNI_APPLICATION_CONTEXT_PROVIDER_H_
|
||||
|
||||
#include "sdk/android/native_api/jni/scoped_java_ref.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
ScopedJavaLocalRef<jobject> GetAppContext(JNIEnv* jni);
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // SDK_ANDROID_NATIVE_API_JNI_APPLICATION_CONTEXT_PROVIDER_H_
|
||||
Reference in New Issue
Block a user