Move android audio device code into sdk/android

This CL adds a stand-alone Android AudioDeviceModule in the
sdk/android folder. It's forked from modules/audio_device/android/
and then simplified for the Android case. The stand-alone Android
ADM is available both in the native_api and also under a field trial
in the Java API.

Bug: webrtc:7452
Change-Id: If6e558026bd0ccb52f56d78ac833339a5789d300
Reviewed-on: https://webrtc-review.googlesource.com/60541
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22517}
This commit is contained in:
Paulina Hensman
2018-03-20 15:27:52 +01:00
committed by Commit Bot
parent 4d22a6d8db
commit 89dd7bf924
37 changed files with 7491 additions and 39 deletions

View File

@ -0,0 +1,4 @@
include_rules = [
"+modules/audio_device/include/audio_device.h",
"+system_wrappers/include",
]

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2018 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/audio_device_module/audio_device_android.h"
#include <stdlib.h>
#include "rtc_base/logging.h"
#include "rtc_base/refcount.h"
#include "rtc_base/refcountedobject.h"
#include "system_wrappers/include/metrics.h"
#if defined(AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO)
#include "sdk/android/src/jni/audio_device/aaudio_player.h"
#include "sdk/android/src/jni/audio_device/aaudio_recorder.h"
#endif
#include "sdk/android/src/jni/audio_device/audio_device_template_android.h"
#include "sdk/android/src/jni/audio_device/audio_manager.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"
namespace webrtc {
rtc::scoped_refptr<AudioDeviceModule> CreateAndroidAudioDeviceModule() {
RTC_LOG(INFO) << __FUNCTION__;
// Create an Android audio manager.
android_adm::AudioManager audio_manager_android;
// Select best possible combination of audio layers.
if (audio_manager_android.IsAAudioSupported()) {
#if defined(AUDIO_DEVICE_INCLUDE_ANDROID_AAUDIO)
return new rtc::RefCountedObject<android_adm::AudioDeviceTemplateAndroid<
android_adm::AAudioRecorder, android_adm::AAudioPlayer>>(
AudioDeviceModule::kAndroidAAudioAudio);
#endif
} else if (audio_manager_android.IsLowLatencyPlayoutSupported() &&
audio_manager_android.IsLowLatencyRecordSupported()) {
// Use OpenSL ES for both playout and recording.
return new rtc::RefCountedObject<android_adm::AudioDeviceTemplateAndroid<
android_adm::OpenSLESRecorder, android_adm::OpenSLESPlayer>>(
AudioDeviceModule::kAndroidOpenSLESAudio);
} else if (audio_manager_android.IsLowLatencyPlayoutSupported() &&
!audio_manager_android.IsLowLatencyRecordSupported()) {
// Use OpenSL ES for output on devices that only supports the
// low-latency output audio path.
// This combination provides low-latency output audio and at the same
// time support for HW AEC using the AudioRecord Java API.
return new rtc::RefCountedObject<android_adm::AudioDeviceTemplateAndroid<
android_adm::AudioRecordJni, android_adm::OpenSLESPlayer>>(
AudioDeviceModule::kAndroidJavaInputAndOpenSLESOutputAudio);
} else {
// Use Java-based audio in both directions when low-latency output is
// not supported.
return new rtc::RefCountedObject<android_adm::AudioDeviceTemplateAndroid<
android_adm::AudioRecordJni, android_adm::AudioTrackJni>>(
AudioDeviceModule::kAndroidJavaAudio);
}
RTC_LOG(LS_ERROR) << "The requested audio layer is not supported";
return nullptr;
}
} // namespace webrtc

View File

@ -0,0 +1,22 @@
/*
* Copyright (c) 2018 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_AUDIO_DEVICE_MODULE_AUDIO_DEVICE_ANDROID_H_
#define SDK_ANDROID_NATIVE_API_AUDIO_DEVICE_MODULE_AUDIO_DEVICE_ANDROID_H_
#include "modules/audio_device/include/audio_device.h"
namespace webrtc {
rtc::scoped_refptr<AudioDeviceModule> CreateAndroidAudioDeviceModule();
} // namespace webrtc
#endif // SDK_ANDROID_NATIVE_API_AUDIO_DEVICE_MODULE_AUDIO_DEVICE_ANDROID_H_