mirror of
https://git.eden-emu.dev/eden-emu/eden
synced 2026-04-28 17:49:00 +02:00
Move dead submodules in-tree
Signed-off-by: swurl <swurl@swurl.xyz>
This commit is contained in:
parent
c0cceff365
commit
6c655321e6
4081 changed files with 1185566 additions and 45 deletions
304
externals/oboe/src/aaudio/AAudioExtensions.h
vendored
Normal file
304
externals/oboe/src/aaudio/AAudioExtensions.h
vendored
Normal file
|
|
@ -0,0 +1,304 @@
|
|||
/*
|
||||
* Copyright 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OBOE_AAUDIO_EXTENSIONS_H
|
||||
#define OBOE_AAUDIO_EXTENSIONS_H
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <sys/system_properties.h>
|
||||
|
||||
#include "common/OboeDebug.h"
|
||||
#include "oboe/Oboe.h"
|
||||
#include "AAudioLoader.h"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
#define LIB_AAUDIO_NAME "libaaudio.so"
|
||||
#define FUNCTION_IS_MMAP "AAudioStream_isMMapUsed"
|
||||
#define FUNCTION_SET_MMAP_POLICY "AAudio_setMMapPolicy"
|
||||
#define FUNCTION_GET_MMAP_POLICY "AAudio_getMMapPolicy"
|
||||
|
||||
#define AAUDIO_ERROR_UNAVAILABLE static_cast<aaudio_result_t>(Result::ErrorUnavailable)
|
||||
|
||||
typedef struct AAudioStreamStruct AAudioStream;
|
||||
|
||||
// The output device type collection must be updated if there is any new added output device type
|
||||
const static std::set<DeviceType> ALL_OUTPUT_DEVICE_TYPES = {
|
||||
DeviceType::BuiltinEarpiece,
|
||||
DeviceType::BuiltinSpeaker,
|
||||
DeviceType::WiredHeadset,
|
||||
DeviceType::WiredHeadphones,
|
||||
DeviceType::LineAnalog,
|
||||
DeviceType::LineDigital,
|
||||
DeviceType::BluetoothSco,
|
||||
DeviceType::BluetoothA2dp,
|
||||
DeviceType::Hdmi,
|
||||
DeviceType::HdmiArc,
|
||||
DeviceType::HdmiEarc,
|
||||
DeviceType::UsbDevice,
|
||||
DeviceType::UsbHeadset,
|
||||
DeviceType::UsbAccessory,
|
||||
DeviceType::Dock,
|
||||
DeviceType::DockAnalog,
|
||||
DeviceType::FM,
|
||||
DeviceType::Telephony,
|
||||
DeviceType::AuxLine,
|
||||
DeviceType::IP,
|
||||
DeviceType::Bus,
|
||||
DeviceType::HearingAid,
|
||||
DeviceType::BuiltinSpeakerSafe,
|
||||
DeviceType::RemoteSubmix,
|
||||
DeviceType::BleHeadset,
|
||||
DeviceType::BleSpeaker,
|
||||
DeviceType::BleBroadcast,
|
||||
};
|
||||
|
||||
// The input device type collection must be updated if there is any new added input device type
|
||||
const static std::set<DeviceType> ALL_INPUT_DEVICE_TYPES = {
|
||||
DeviceType::BuiltinMic,
|
||||
DeviceType::BluetoothSco,
|
||||
DeviceType::WiredHeadset,
|
||||
DeviceType::Hdmi,
|
||||
DeviceType::Telephony,
|
||||
DeviceType::Dock,
|
||||
DeviceType::DockAnalog,
|
||||
DeviceType::UsbAccessory,
|
||||
DeviceType::UsbDevice,
|
||||
DeviceType::UsbHeadset,
|
||||
DeviceType::FMTuner,
|
||||
DeviceType::TVTuner,
|
||||
DeviceType::LineAnalog,
|
||||
DeviceType::LineDigital,
|
||||
DeviceType::BluetoothA2dp,
|
||||
DeviceType::IP,
|
||||
DeviceType::Bus,
|
||||
DeviceType::RemoteSubmix,
|
||||
DeviceType::BleHeadset,
|
||||
DeviceType::HdmiArc,
|
||||
DeviceType::HdmiEarc,
|
||||
};
|
||||
|
||||
/**
|
||||
* Call some AAudio test routines that are not part of the normal API.
|
||||
*/
|
||||
class AAudioExtensions {
|
||||
private: // Because it is a singleton. Call getInstance() instead.
|
||||
AAudioExtensions() {
|
||||
mLibLoader = AAudioLoader::getInstance();
|
||||
if (!initMMapPolicy()) {
|
||||
int32_t policy = getIntegerProperty("aaudio.mmap_policy", 0);
|
||||
mMMapSupported = isPolicyEnabled(policy);
|
||||
|
||||
policy = getIntegerProperty("aaudio.mmap_exclusive_policy", 0);
|
||||
mMMapExclusiveSupported = isPolicyEnabled(policy);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
static bool isPolicyEnabled(int32_t policy) {
|
||||
const MMapPolicy mmapPolicy = static_cast<MMapPolicy>(policy);
|
||||
return (mmapPolicy == MMapPolicy::Auto || mmapPolicy == MMapPolicy::Always);
|
||||
}
|
||||
|
||||
static AAudioExtensions &getInstance() {
|
||||
static AAudioExtensions instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
bool isMMapUsed(oboe::AudioStream *oboeStream) {
|
||||
AAudioStream *aaudioStream = (AAudioStream *) oboeStream->getUnderlyingStream();
|
||||
return isMMapUsed(aaudioStream);
|
||||
}
|
||||
|
||||
bool isMMapUsed(AAudioStream *aaudioStream) {
|
||||
if (mLibLoader != nullptr && mLibLoader->stream_isMMapUsed != nullptr) {
|
||||
return mLibLoader->stream_isMMapUsed(aaudioStream);
|
||||
}
|
||||
if (loadSymbols()) return false;
|
||||
if (mAAudioStream_isMMap == nullptr) return false;
|
||||
return mAAudioStream_isMMap(aaudioStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* Controls whether the MMAP data path can be selected when opening a stream.
|
||||
* It has no effect after the stream has been opened.
|
||||
* It only affects the application that calls it. Other apps are not affected.
|
||||
*
|
||||
* @param enabled
|
||||
* @return 0 or a negative error code
|
||||
*/
|
||||
int32_t setMMapEnabled(bool enabled) {
|
||||
// The API for setting mmap policy is public after API level 36.
|
||||
if (mLibLoader != nullptr && mLibLoader->aaudio_setMMapPolicy != nullptr) {
|
||||
return mLibLoader->aaudio_setMMapPolicy(
|
||||
static_cast<aaudio_policy_t>(enabled ? MMapPolicy::Auto : MMapPolicy::Never));
|
||||
}
|
||||
// When there is no public API, fallback to loading the symbol from hidden API.
|
||||
if (loadSymbols()) return AAUDIO_ERROR_UNAVAILABLE;
|
||||
if (mAAudio_setMMapPolicy == nullptr) return false;
|
||||
return mAAudio_setMMapPolicy(
|
||||
static_cast<int32_t>(enabled ? MMapPolicy::Auto : MMapPolicy::Never));
|
||||
}
|
||||
|
||||
bool isMMapEnabled() {
|
||||
// The API for getting mmap policy is public after API level 36.
|
||||
// Use it when it is available.
|
||||
if (mLibLoader != nullptr && mLibLoader->aaudio_getMMapPolicy != nullptr) {
|
||||
MMapPolicy policy = static_cast<MMapPolicy>(mLibLoader->aaudio_getMMapPolicy());
|
||||
return policy == MMapPolicy::Unspecified
|
||||
? mMMapSupported : isPolicyEnabled(static_cast<int32_t>(policy));
|
||||
}
|
||||
// When there is no public API, fallback to loading the symbol from hidden API.
|
||||
if (loadSymbols()) return false;
|
||||
if (mAAudio_getMMapPolicy == nullptr) return false;
|
||||
int32_t policy = mAAudio_getMMapPolicy();
|
||||
return (policy == Unspecified) ? mMMapSupported : isPolicyEnabled(policy);
|
||||
}
|
||||
|
||||
bool isMMapSupported() {
|
||||
return mMMapSupported;
|
||||
}
|
||||
|
||||
bool isMMapExclusiveSupported() {
|
||||
return mMMapExclusiveSupported;
|
||||
}
|
||||
|
||||
MMapPolicy getMMapPolicy(DeviceType deviceType, Direction direction) {
|
||||
if (mLibLoader == nullptr ||
|
||||
mLibLoader->aaudio_getPlatformMMapPolicy == nullptr) {
|
||||
return MMapPolicy::Unspecified;
|
||||
}
|
||||
return static_cast<MMapPolicy>(mLibLoader->aaudio_getPlatformMMapPolicy(
|
||||
static_cast<AAudio_DeviceType>(deviceType),
|
||||
static_cast<aaudio_direction_t>(direction)));
|
||||
}
|
||||
|
||||
MMapPolicy getMMapExclusivePolicy(DeviceType deviceType, Direction direction) {
|
||||
if (mLibLoader == nullptr ||
|
||||
mLibLoader->aaudio_getPlatformMMapExclusivePolicy == nullptr) {
|
||||
return MMapPolicy::Unspecified;
|
||||
}
|
||||
return static_cast<MMapPolicy>(mLibLoader->aaudio_getPlatformMMapExclusivePolicy(
|
||||
static_cast<AAudio_DeviceType>(deviceType),
|
||||
static_cast<aaudio_direction_t>(direction)));
|
||||
}
|
||||
|
||||
private:
|
||||
bool initMMapPolicy() {
|
||||
if (mLibLoader == nullptr || mLibLoader->open() != 0) {
|
||||
return false;
|
||||
}
|
||||
if (mLibLoader->aaudio_getPlatformMMapPolicy == nullptr ||
|
||||
mLibLoader->aaudio_getPlatformMMapExclusivePolicy == nullptr) {
|
||||
return false;
|
||||
}
|
||||
mMMapSupported =
|
||||
std::any_of(ALL_INPUT_DEVICE_TYPES.begin(), ALL_INPUT_DEVICE_TYPES.end(),
|
||||
[this](DeviceType deviceType) {
|
||||
return isPolicyEnabled(static_cast<int32_t>(
|
||||
getMMapPolicy(deviceType, Direction::Input)));
|
||||
}) ||
|
||||
std::any_of(ALL_OUTPUT_DEVICE_TYPES.begin(), ALL_OUTPUT_DEVICE_TYPES.end(),
|
||||
[this](DeviceType deviceType) {
|
||||
return isPolicyEnabled(static_cast<int32_t>(
|
||||
getMMapPolicy(deviceType, Direction::Output)));
|
||||
});
|
||||
mMMapExclusiveSupported =
|
||||
std::any_of(ALL_INPUT_DEVICE_TYPES.begin(), ALL_INPUT_DEVICE_TYPES.end(),
|
||||
[this](DeviceType deviceType) {
|
||||
return isPolicyEnabled(static_cast<int32_t>(
|
||||
getMMapExclusivePolicy(deviceType, Direction::Input)));
|
||||
}) ||
|
||||
std::any_of(ALL_OUTPUT_DEVICE_TYPES.begin(), ALL_OUTPUT_DEVICE_TYPES.end(),
|
||||
[this](DeviceType deviceType) {
|
||||
return isPolicyEnabled(static_cast<int32_t>(
|
||||
getMMapExclusivePolicy(deviceType, Direction::Output)));
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
int getIntegerProperty(const char *name, int defaultValue) {
|
||||
int result = defaultValue;
|
||||
char valueText[PROP_VALUE_MAX] = {0};
|
||||
if (__system_property_get(name, valueText) != 0) {
|
||||
result = atoi(valueText);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the function pointers.
|
||||
* This can be called multiple times.
|
||||
* It should only be called from one thread.
|
||||
*
|
||||
* @return 0 if successful or negative error.
|
||||
*/
|
||||
aaudio_result_t loadSymbols() {
|
||||
if (mAAudio_getMMapPolicy != nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mLibLoader == nullptr || mLibLoader->open() != 0) {
|
||||
LOGD("%s() could not open " LIB_AAUDIO_NAME, __func__);
|
||||
return AAUDIO_ERROR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
void *libHandle = mLibLoader->getLibHandle();
|
||||
if (libHandle == nullptr) {
|
||||
LOGE("%s() could not find " LIB_AAUDIO_NAME, __func__);
|
||||
return AAUDIO_ERROR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
mAAudioStream_isMMap = (bool (*)(AAudioStream *stream))
|
||||
dlsym(libHandle, FUNCTION_IS_MMAP);
|
||||
if (mAAudioStream_isMMap == nullptr) {
|
||||
LOGI("%s() could not find " FUNCTION_IS_MMAP, __func__);
|
||||
return AAUDIO_ERROR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
mAAudio_setMMapPolicy = (int32_t (*)(aaudio_policy_t policy))
|
||||
dlsym(libHandle, FUNCTION_SET_MMAP_POLICY);
|
||||
if (mAAudio_setMMapPolicy == nullptr) {
|
||||
LOGI("%s() could not find " FUNCTION_SET_MMAP_POLICY, __func__);
|
||||
return AAUDIO_ERROR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
mAAudio_getMMapPolicy = (aaudio_policy_t (*)())
|
||||
dlsym(libHandle, FUNCTION_GET_MMAP_POLICY);
|
||||
if (mAAudio_getMMapPolicy == nullptr) {
|
||||
LOGI("%s() could not find " FUNCTION_GET_MMAP_POLICY, __func__);
|
||||
return AAUDIO_ERROR_UNAVAILABLE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool mMMapSupported = false;
|
||||
bool mMMapExclusiveSupported = false;
|
||||
|
||||
bool (*mAAudioStream_isMMap)(AAudioStream *stream) = nullptr;
|
||||
int32_t (*mAAudio_setMMapPolicy)(aaudio_policy_t policy) = nullptr;
|
||||
aaudio_policy_t (*mAAudio_getMMapPolicy)() = nullptr;
|
||||
|
||||
AAudioLoader *mLibLoader;
|
||||
};
|
||||
|
||||
} // namespace oboe
|
||||
|
||||
#endif //OBOE_AAUDIO_EXTENSIONS_H
|
||||
606
externals/oboe/src/aaudio/AAudioLoader.cpp
vendored
Normal file
606
externals/oboe/src/aaudio/AAudioLoader.cpp
vendored
Normal file
|
|
@ -0,0 +1,606 @@
|
|||
/*
|
||||
* Copyright 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <oboe/Utilities.h>
|
||||
#include "common/OboeDebug.h"
|
||||
#include "AAudioLoader.h"
|
||||
|
||||
#define LIB_AAUDIO_NAME "libaaudio.so"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
AAudioLoader::~AAudioLoader() {
|
||||
// Issue 360: thread_local variables with non-trivial destructors
|
||||
// will cause segfaults if the containing library is dlclose()ed on
|
||||
// devices running M or newer, or devices before M when using a static STL.
|
||||
// The simple workaround is to not call dlclose.
|
||||
// https://github.com/android/ndk/wiki/Changelog-r22#known-issues
|
||||
//
|
||||
// The libaaudio and libaaudioclient do not use thread_local.
|
||||
// But, to be safe, we should avoid dlclose() if possible.
|
||||
// Because AAudioLoader is a static Singleton, we can safely skip
|
||||
// calling dlclose() without causing a resource leak.
|
||||
LOGI("%s() dlclose(%s) not called, OK", __func__, LIB_AAUDIO_NAME);
|
||||
}
|
||||
|
||||
AAudioLoader* AAudioLoader::getInstance() {
|
||||
static AAudioLoader instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
int AAudioLoader::open() {
|
||||
if (mLibHandle != nullptr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Use RTLD_NOW to avoid the unpredictable behavior that RTLD_LAZY can cause.
|
||||
// Also resolving all the links now will prevent a run-time penalty later.
|
||||
mLibHandle = dlopen(LIB_AAUDIO_NAME, RTLD_NOW);
|
||||
if (mLibHandle == nullptr) {
|
||||
LOGI("AAudioLoader::open() could not find " LIB_AAUDIO_NAME);
|
||||
return -1; // TODO review return code
|
||||
} else {
|
||||
LOGD("AAudioLoader(): dlopen(%s) returned %p", LIB_AAUDIO_NAME, mLibHandle);
|
||||
}
|
||||
|
||||
// Load all the function pointers.
|
||||
createStreamBuilder = load_I_PPB("AAudio_createStreamBuilder");
|
||||
builder_openStream = load_I_PBPPS("AAudioStreamBuilder_openStream");
|
||||
|
||||
builder_setChannelCount = load_V_PBI("AAudioStreamBuilder_setChannelCount");
|
||||
if (builder_setChannelCount == nullptr) {
|
||||
// Use old deprecated alias if needed.
|
||||
builder_setChannelCount = load_V_PBI("AAudioStreamBuilder_setSamplesPerFrame");
|
||||
}
|
||||
|
||||
builder_setBufferCapacityInFrames = load_V_PBI("AAudioStreamBuilder_setBufferCapacityInFrames");
|
||||
builder_setDeviceId = load_V_PBI("AAudioStreamBuilder_setDeviceId");
|
||||
builder_setDirection = load_V_PBI("AAudioStreamBuilder_setDirection");
|
||||
builder_setFormat = load_V_PBI("AAudioStreamBuilder_setFormat");
|
||||
builder_setFramesPerDataCallback = load_V_PBI("AAudioStreamBuilder_setFramesPerDataCallback");
|
||||
builder_setSharingMode = load_V_PBI("AAudioStreamBuilder_setSharingMode");
|
||||
builder_setPerformanceMode = load_V_PBI("AAudioStreamBuilder_setPerformanceMode");
|
||||
builder_setSampleRate = load_V_PBI("AAudioStreamBuilder_setSampleRate");
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_P__){
|
||||
builder_setUsage = load_V_PBI("AAudioStreamBuilder_setUsage");
|
||||
builder_setContentType = load_V_PBI("AAudioStreamBuilder_setContentType");
|
||||
builder_setInputPreset = load_V_PBI("AAudioStreamBuilder_setInputPreset");
|
||||
builder_setSessionId = load_V_PBI("AAudioStreamBuilder_setSessionId");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_Q__){
|
||||
builder_setAllowedCapturePolicy = load_V_PBI("AAudioStreamBuilder_setAllowedCapturePolicy");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_R__){
|
||||
builder_setPrivacySensitive = load_V_PBO("AAudioStreamBuilder_setPrivacySensitive");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_S__){
|
||||
builder_setPackageName = load_V_PBCPH("AAudioStreamBuilder_setPackageName");
|
||||
builder_setAttributionTag = load_V_PBCPH("AAudioStreamBuilder_setAttributionTag");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_S_V2__) {
|
||||
builder_setChannelMask = load_V_PBU("AAudioStreamBuilder_setChannelMask");
|
||||
builder_setIsContentSpatialized = load_V_PBO("AAudioStreamBuilder_setIsContentSpatialized");
|
||||
builder_setSpatializationBehavior = load_V_PBI("AAudioStreamBuilder_setSpatializationBehavior");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_B__) {
|
||||
builder_setPresentationEndCallback = load_V_PBPRPV("AAudioStreamBuilder_setPresentationEndCallback");
|
||||
}
|
||||
|
||||
builder_delete = load_I_PB("AAudioStreamBuilder_delete");
|
||||
|
||||
|
||||
builder_setDataCallback = load_V_PBPDPV("AAudioStreamBuilder_setDataCallback");
|
||||
builder_setErrorCallback = load_V_PBPEPV("AAudioStreamBuilder_setErrorCallback");
|
||||
|
||||
stream_read = load_I_PSPVIL("AAudioStream_read");
|
||||
|
||||
stream_write = load_I_PSCPVIL("AAudioStream_write");
|
||||
|
||||
stream_waitForStateChange = load_I_PSTPTL("AAudioStream_waitForStateChange");
|
||||
|
||||
stream_getTimestamp = load_I_PSKPLPL("AAudioStream_getTimestamp");
|
||||
|
||||
stream_getChannelCount = load_I_PS("AAudioStream_getChannelCount");
|
||||
if (stream_getChannelCount == nullptr) {
|
||||
// Use old alias if needed.
|
||||
stream_getChannelCount = load_I_PS("AAudioStream_getSamplesPerFrame");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_R__) {
|
||||
stream_release = load_I_PS("AAudioStream_release");
|
||||
}
|
||||
|
||||
stream_close = load_I_PS("AAudioStream_close");
|
||||
|
||||
stream_getBufferSize = load_I_PS("AAudioStream_getBufferSizeInFrames");
|
||||
stream_getDeviceId = load_I_PS("AAudioStream_getDeviceId");
|
||||
stream_getBufferCapacity = load_I_PS("AAudioStream_getBufferCapacityInFrames");
|
||||
stream_getFormat = load_F_PS("AAudioStream_getFormat");
|
||||
stream_getFramesPerBurst = load_I_PS("AAudioStream_getFramesPerBurst");
|
||||
stream_getFramesRead = load_L_PS("AAudioStream_getFramesRead");
|
||||
stream_getFramesWritten = load_L_PS("AAudioStream_getFramesWritten");
|
||||
stream_getPerformanceMode = load_I_PS("AAudioStream_getPerformanceMode");
|
||||
stream_getSampleRate = load_I_PS("AAudioStream_getSampleRate");
|
||||
stream_getSharingMode = load_I_PS("AAudioStream_getSharingMode");
|
||||
stream_getState = load_I_PS("AAudioStream_getState");
|
||||
stream_getXRunCount = load_I_PS("AAudioStream_getXRunCount");
|
||||
|
||||
stream_requestStart = load_I_PS("AAudioStream_requestStart");
|
||||
stream_requestPause = load_I_PS("AAudioStream_requestPause");
|
||||
stream_requestFlush = load_I_PS("AAudioStream_requestFlush");
|
||||
stream_requestStop = load_I_PS("AAudioStream_requestStop");
|
||||
|
||||
stream_setBufferSize = load_I_PSI("AAudioStream_setBufferSizeInFrames");
|
||||
|
||||
convertResultToText = load_CPH_I("AAudio_convertResultToText");
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_P__){
|
||||
stream_getUsage = load_I_PS("AAudioStream_getUsage");
|
||||
stream_getContentType = load_I_PS("AAudioStream_getContentType");
|
||||
stream_getInputPreset = load_I_PS("AAudioStream_getInputPreset");
|
||||
stream_getSessionId = load_I_PS("AAudioStream_getSessionId");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_Q__){
|
||||
stream_getAllowedCapturePolicy = load_I_PS("AAudioStream_getAllowedCapturePolicy");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_R__){
|
||||
stream_isPrivacySensitive = load_O_PS("AAudioStream_isPrivacySensitive");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_S_V2__) {
|
||||
stream_getChannelMask = load_U_PS("AAudioStream_getChannelMask");
|
||||
stream_isContentSpatialized = load_O_PS("AAudioStream_isContentSpatialized");
|
||||
stream_getSpatializationBehavior = load_I_PS("AAudioStream_getSpatializationBehavior");
|
||||
}
|
||||
|
||||
if (getSdkVersion() >= __ANDROID_API_U__) {
|
||||
stream_getHardwareChannelCount = load_I_PS("AAudioStream_getHardwareChannelCount");
|
||||
stream_getHardwareSampleRate = load_I_PS("AAudioStream_getHardwareSampleRate");
|
||||
stream_getHardwareFormat = load_F_PS("AAudioStream_getHardwareFormat");
|
||||
}
|
||||
|
||||
// TODO: Remove pre-release check after Android B release
|
||||
if (getSdkVersion() >= __ANDROID_API_B__ || isAtLeastPreReleaseCodename("Baklava")) {
|
||||
aaudio_getPlatformMMapPolicy = load_I_II("AAudio_getPlatformMMapPolicy");
|
||||
aaudio_getPlatformMMapExclusivePolicy = load_I_II("AAudio_getPlatformMMapExclusivePolicy");
|
||||
aaudio_setMMapPolicy = load_I_I("AAudio_setMMapPolicy");
|
||||
aaudio_getMMapPolicy = load_I("AAudio_getMMapPolicy");
|
||||
stream_isMMapUsed = load_O_PS("AAudioStream_isMMapUsed");
|
||||
|
||||
stream_setOffloadDelayPadding = load_I_PSII("AAudioStream_setOffloadDelayPadding");
|
||||
stream_getOffloadDelay = load_I_PS("AAudioStream_getOffloadDelay");
|
||||
stream_getOffloadPadding = load_I_PS("AAudioStream_getOffloadPadding");
|
||||
stream_setOffloadEndOfStream = load_I_PS("AAudioStream_setOffloadEndOfStream");
|
||||
|
||||
stream_getDeviceIds = load_I_PSPIPI("AAudioStream_getDeviceIds");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void AAudioLoader_check(void *proc, const char *functionName) {
|
||||
if (proc == nullptr) {
|
||||
LOGW("AAudioLoader could not find %s", functionName);
|
||||
}
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PPB AAudioLoader::load_I_PPB(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PPB>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_CPH_I AAudioLoader::load_CPH_I(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_CPH_I>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_V_PBI AAudioLoader::load_V_PBI(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_V_PBI>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_V_PBCPH AAudioLoader::load_V_PBCPH(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_V_PBCPH>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_V_PBPDPV AAudioLoader::load_V_PBPDPV(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_V_PBPDPV>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_V_PBPEPV AAudioLoader::load_V_PBPEPV(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_V_PBPEPV>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PSI AAudioLoader::load_I_PSI(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PSI>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PS AAudioLoader::load_I_PS(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PS>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_L_PS AAudioLoader::load_L_PS(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_L_PS>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_F_PS AAudioLoader::load_F_PS(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_F_PS>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_O_PS AAudioLoader::load_O_PS(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_O_PS>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PB AAudioLoader::load_I_PB(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PB>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PBPPS AAudioLoader::load_I_PBPPS(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PBPPS>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PSCPVIL AAudioLoader::load_I_PSCPVIL(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PSCPVIL>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PSPVIL AAudioLoader::load_I_PSPVIL(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PSPVIL>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PSTPTL AAudioLoader::load_I_PSTPTL(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PSTPTL>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PSKPLPL AAudioLoader::load_I_PSKPLPL(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PSKPLPL>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_V_PBU AAudioLoader::load_V_PBU(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_V_PBU>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_U_PS AAudioLoader::load_U_PS(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_U_PS>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_V_PBO AAudioLoader::load_V_PBO(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_V_PBO>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_II AAudioLoader::load_I_II(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_II>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_I AAudioLoader::load_I_I(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_I>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I AAudioLoader::load_I(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_V_PBPRPV AAudioLoader::load_V_PBPRPV(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_V_PBPRPV>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PSII AAudioLoader::load_I_PSII(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PSII>(proc);
|
||||
}
|
||||
|
||||
AAudioLoader::signature_I_PSPIPI AAudioLoader::load_I_PSPIPI(const char *functionName) {
|
||||
void *proc = dlsym(mLibHandle, functionName);
|
||||
AAudioLoader_check(proc, functionName);
|
||||
return reinterpret_cast<signature_I_PSPIPI>(proc);
|
||||
}
|
||||
|
||||
// Ensure that all AAudio primitive data types are int32_t
|
||||
#define ASSERT_INT32(type) static_assert(std::is_same<int32_t, type>::value, \
|
||||
#type" must be int32_t")
|
||||
|
||||
// Ensure that all AAudio primitive data types are uint32_t
|
||||
#define ASSERT_UINT32(type) static_assert(std::is_same<uint32_t, type>::value, \
|
||||
#type" must be uint32_t")
|
||||
|
||||
#define ERRMSG "Oboe constants must match AAudio constants."
|
||||
|
||||
// These asserts help verify that the Oboe definitions match the equivalent AAudio definitions.
|
||||
// This code is in this .cpp file so it only gets tested once.
|
||||
#ifdef AAUDIO_AAUDIO_H
|
||||
|
||||
ASSERT_INT32(aaudio_stream_state_t);
|
||||
ASSERT_INT32(aaudio_direction_t);
|
||||
ASSERT_INT32(aaudio_format_t);
|
||||
ASSERT_INT32(aaudio_data_callback_result_t);
|
||||
ASSERT_INT32(aaudio_result_t);
|
||||
ASSERT_INT32(aaudio_sharing_mode_t);
|
||||
ASSERT_INT32(aaudio_performance_mode_t);
|
||||
|
||||
static_assert((int32_t)StreamState::Uninitialized == AAUDIO_STREAM_STATE_UNINITIALIZED, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Unknown == AAUDIO_STREAM_STATE_UNKNOWN, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Open == AAUDIO_STREAM_STATE_OPEN, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Starting == AAUDIO_STREAM_STATE_STARTING, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Started == AAUDIO_STREAM_STATE_STARTED, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Pausing == AAUDIO_STREAM_STATE_PAUSING, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Paused == AAUDIO_STREAM_STATE_PAUSED, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Flushing == AAUDIO_STREAM_STATE_FLUSHING, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Flushed == AAUDIO_STREAM_STATE_FLUSHED, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Stopping == AAUDIO_STREAM_STATE_STOPPING, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Stopped == AAUDIO_STREAM_STATE_STOPPED, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Closing == AAUDIO_STREAM_STATE_CLOSING, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Closed == AAUDIO_STREAM_STATE_CLOSED, ERRMSG);
|
||||
static_assert((int32_t)StreamState::Disconnected == AAUDIO_STREAM_STATE_DISCONNECTED, ERRMSG);
|
||||
|
||||
static_assert((int32_t)Direction::Output == AAUDIO_DIRECTION_OUTPUT, ERRMSG);
|
||||
static_assert((int32_t)Direction::Input == AAUDIO_DIRECTION_INPUT, ERRMSG);
|
||||
|
||||
static_assert((int32_t)AudioFormat::Invalid == AAUDIO_FORMAT_INVALID, ERRMSG);
|
||||
static_assert((int32_t)AudioFormat::Unspecified == AAUDIO_FORMAT_UNSPECIFIED, ERRMSG);
|
||||
static_assert((int32_t)AudioFormat::I16 == AAUDIO_FORMAT_PCM_I16, ERRMSG);
|
||||
static_assert((int32_t)AudioFormat::Float == AAUDIO_FORMAT_PCM_FLOAT, ERRMSG);
|
||||
|
||||
static_assert((int32_t)DataCallbackResult::Continue == AAUDIO_CALLBACK_RESULT_CONTINUE, ERRMSG);
|
||||
static_assert((int32_t)DataCallbackResult::Stop == AAUDIO_CALLBACK_RESULT_STOP, ERRMSG);
|
||||
|
||||
static_assert((int32_t)Result::OK == AAUDIO_OK, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorBase == AAUDIO_ERROR_BASE, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorDisconnected == AAUDIO_ERROR_DISCONNECTED, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorIllegalArgument == AAUDIO_ERROR_ILLEGAL_ARGUMENT, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorInternal == AAUDIO_ERROR_INTERNAL, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorInvalidState == AAUDIO_ERROR_INVALID_STATE, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorInvalidHandle == AAUDIO_ERROR_INVALID_HANDLE, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorUnimplemented == AAUDIO_ERROR_UNIMPLEMENTED, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorUnavailable == AAUDIO_ERROR_UNAVAILABLE, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorNoFreeHandles == AAUDIO_ERROR_NO_FREE_HANDLES, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorNoMemory == AAUDIO_ERROR_NO_MEMORY, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorNull == AAUDIO_ERROR_NULL, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorTimeout == AAUDIO_ERROR_TIMEOUT, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorWouldBlock == AAUDIO_ERROR_WOULD_BLOCK, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorInvalidFormat == AAUDIO_ERROR_INVALID_FORMAT, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorOutOfRange == AAUDIO_ERROR_OUT_OF_RANGE, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorNoService == AAUDIO_ERROR_NO_SERVICE, ERRMSG);
|
||||
static_assert((int32_t)Result::ErrorInvalidRate == AAUDIO_ERROR_INVALID_RATE, ERRMSG);
|
||||
|
||||
static_assert((int32_t)SharingMode::Exclusive == AAUDIO_SHARING_MODE_EXCLUSIVE, ERRMSG);
|
||||
static_assert((int32_t)SharingMode::Shared == AAUDIO_SHARING_MODE_SHARED, ERRMSG);
|
||||
|
||||
static_assert((int32_t)PerformanceMode::None == AAUDIO_PERFORMANCE_MODE_NONE, ERRMSG);
|
||||
static_assert((int32_t)PerformanceMode::PowerSaving
|
||||
== AAUDIO_PERFORMANCE_MODE_POWER_SAVING, ERRMSG);
|
||||
static_assert((int32_t)PerformanceMode::LowLatency
|
||||
== AAUDIO_PERFORMANCE_MODE_LOW_LATENCY, ERRMSG);
|
||||
|
||||
// The aaudio_ usage, content and input_preset types were added in NDK 17,
|
||||
// which is the first version to support Android Pie (API 28).
|
||||
#if __NDK_MAJOR__ >= 17
|
||||
|
||||
ASSERT_INT32(aaudio_usage_t);
|
||||
ASSERT_INT32(aaudio_content_type_t);
|
||||
ASSERT_INT32(aaudio_input_preset_t);
|
||||
|
||||
static_assert((int32_t)Usage::Media == AAUDIO_USAGE_MEDIA, ERRMSG);
|
||||
static_assert((int32_t)Usage::VoiceCommunication == AAUDIO_USAGE_VOICE_COMMUNICATION, ERRMSG);
|
||||
static_assert((int32_t)Usage::VoiceCommunicationSignalling
|
||||
== AAUDIO_USAGE_VOICE_COMMUNICATION_SIGNALLING, ERRMSG);
|
||||
static_assert((int32_t)Usage::Alarm == AAUDIO_USAGE_ALARM, ERRMSG);
|
||||
static_assert((int32_t)Usage::Notification == AAUDIO_USAGE_NOTIFICATION, ERRMSG);
|
||||
static_assert((int32_t)Usage::NotificationRingtone == AAUDIO_USAGE_NOTIFICATION_RINGTONE, ERRMSG);
|
||||
static_assert((int32_t)Usage::NotificationEvent == AAUDIO_USAGE_NOTIFICATION_EVENT, ERRMSG);
|
||||
static_assert((int32_t)Usage::AssistanceAccessibility == AAUDIO_USAGE_ASSISTANCE_ACCESSIBILITY, ERRMSG);
|
||||
static_assert((int32_t)Usage::AssistanceNavigationGuidance
|
||||
== AAUDIO_USAGE_ASSISTANCE_NAVIGATION_GUIDANCE, ERRMSG);
|
||||
static_assert((int32_t)Usage::AssistanceSonification == AAUDIO_USAGE_ASSISTANCE_SONIFICATION, ERRMSG);
|
||||
static_assert((int32_t)Usage::Game == AAUDIO_USAGE_GAME, ERRMSG);
|
||||
static_assert((int32_t)Usage::Assistant == AAUDIO_USAGE_ASSISTANT, ERRMSG);
|
||||
|
||||
static_assert((int32_t)ContentType::Speech == AAUDIO_CONTENT_TYPE_SPEECH, ERRMSG);
|
||||
static_assert((int32_t)ContentType::Music == AAUDIO_CONTENT_TYPE_MUSIC, ERRMSG);
|
||||
static_assert((int32_t)ContentType::Movie == AAUDIO_CONTENT_TYPE_MOVIE, ERRMSG);
|
||||
static_assert((int32_t)ContentType::Sonification == AAUDIO_CONTENT_TYPE_SONIFICATION, ERRMSG);
|
||||
|
||||
static_assert((int32_t)InputPreset::Generic == AAUDIO_INPUT_PRESET_GENERIC, ERRMSG);
|
||||
static_assert((int32_t)InputPreset::Camcorder == AAUDIO_INPUT_PRESET_CAMCORDER, ERRMSG);
|
||||
static_assert((int32_t)InputPreset::VoiceRecognition == AAUDIO_INPUT_PRESET_VOICE_RECOGNITION, ERRMSG);
|
||||
static_assert((int32_t)InputPreset::VoiceCommunication
|
||||
== AAUDIO_INPUT_PRESET_VOICE_COMMUNICATION, ERRMSG);
|
||||
static_assert((int32_t)InputPreset::Unprocessed == AAUDIO_INPUT_PRESET_UNPROCESSED, ERRMSG);
|
||||
|
||||
static_assert((int32_t)SessionId::None == AAUDIO_SESSION_ID_NONE, ERRMSG);
|
||||
static_assert((int32_t)SessionId::Allocate == AAUDIO_SESSION_ID_ALLOCATE, ERRMSG);
|
||||
|
||||
#endif // __NDK_MAJOR__ >= 17
|
||||
|
||||
// aaudio_allowed_capture_policy_t was added in NDK 20,
|
||||
// which is the first version to support Android Q (API 29).
|
||||
#if __NDK_MAJOR__ >= 20
|
||||
|
||||
ASSERT_INT32(aaudio_allowed_capture_policy_t);
|
||||
|
||||
static_assert((int32_t)AllowedCapturePolicy::Unspecified == AAUDIO_UNSPECIFIED, ERRMSG);
|
||||
static_assert((int32_t)AllowedCapturePolicy::All == AAUDIO_ALLOW_CAPTURE_BY_ALL, ERRMSG);
|
||||
static_assert((int32_t)AllowedCapturePolicy::System == AAUDIO_ALLOW_CAPTURE_BY_SYSTEM, ERRMSG);
|
||||
static_assert((int32_t)AllowedCapturePolicy::None == AAUDIO_ALLOW_CAPTURE_BY_NONE, ERRMSG);
|
||||
|
||||
#endif // __NDK_MAJOR__ >= 20
|
||||
|
||||
// The aaudio channel masks and spatialization behavior were added in NDK 24,
|
||||
// which is the first version to support Android SC_V2 (API 32).
|
||||
#if __NDK_MAJOR__ >= 24
|
||||
|
||||
ASSERT_UINT32(aaudio_channel_mask_t);
|
||||
|
||||
static_assert((uint32_t)ChannelMask::FrontLeft == AAUDIO_CHANNEL_FRONT_LEFT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::FrontRight == AAUDIO_CHANNEL_FRONT_RIGHT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::FrontCenter == AAUDIO_CHANNEL_FRONT_CENTER, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::LowFrequency == AAUDIO_CHANNEL_LOW_FREQUENCY, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::BackLeft == AAUDIO_CHANNEL_BACK_LEFT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::BackRight == AAUDIO_CHANNEL_BACK_RIGHT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::FrontLeftOfCenter == AAUDIO_CHANNEL_FRONT_LEFT_OF_CENTER, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::FrontRightOfCenter == AAUDIO_CHANNEL_FRONT_RIGHT_OF_CENTER, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::BackCenter == AAUDIO_CHANNEL_BACK_CENTER, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::SideLeft == AAUDIO_CHANNEL_SIDE_LEFT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::SideRight == AAUDIO_CHANNEL_SIDE_RIGHT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopCenter == AAUDIO_CHANNEL_TOP_CENTER, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopFrontLeft == AAUDIO_CHANNEL_TOP_FRONT_LEFT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopFrontCenter == AAUDIO_CHANNEL_TOP_FRONT_CENTER, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopFrontRight == AAUDIO_CHANNEL_TOP_FRONT_RIGHT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopBackLeft == AAUDIO_CHANNEL_TOP_BACK_LEFT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopBackCenter == AAUDIO_CHANNEL_TOP_BACK_CENTER, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopBackRight == AAUDIO_CHANNEL_TOP_BACK_RIGHT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopSideLeft == AAUDIO_CHANNEL_TOP_SIDE_LEFT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TopSideRight == AAUDIO_CHANNEL_TOP_SIDE_RIGHT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::BottomFrontLeft == AAUDIO_CHANNEL_BOTTOM_FRONT_LEFT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::BottomFrontCenter == AAUDIO_CHANNEL_BOTTOM_FRONT_CENTER, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::BottomFrontRight == AAUDIO_CHANNEL_BOTTOM_FRONT_RIGHT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::LowFrequency2 == AAUDIO_CHANNEL_LOW_FREQUENCY_2, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::FrontWideLeft == AAUDIO_CHANNEL_FRONT_WIDE_LEFT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::FrontWideRight == AAUDIO_CHANNEL_FRONT_WIDE_RIGHT, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::Mono == AAUDIO_CHANNEL_MONO, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::Stereo == AAUDIO_CHANNEL_STEREO, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM2Point1 == AAUDIO_CHANNEL_2POINT1, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::Tri == AAUDIO_CHANNEL_TRI, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::TriBack == AAUDIO_CHANNEL_TRI_BACK, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM3Point1 == AAUDIO_CHANNEL_3POINT1, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM2Point0Point2 == AAUDIO_CHANNEL_2POINT0POINT2, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM2Point1Point2 == AAUDIO_CHANNEL_2POINT1POINT2, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM3Point0Point2 == AAUDIO_CHANNEL_3POINT0POINT2, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM3Point1Point2 == AAUDIO_CHANNEL_3POINT1POINT2, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::Quad == AAUDIO_CHANNEL_QUAD, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::QuadSide == AAUDIO_CHANNEL_QUAD_SIDE, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::Surround == AAUDIO_CHANNEL_SURROUND, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::Penta == AAUDIO_CHANNEL_PENTA, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM5Point1 == AAUDIO_CHANNEL_5POINT1, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM5Point1Side == AAUDIO_CHANNEL_5POINT1_SIDE, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM6Point1 == AAUDIO_CHANNEL_6POINT1, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM7Point1 == AAUDIO_CHANNEL_7POINT1, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM5Point1Point2 == AAUDIO_CHANNEL_5POINT1POINT2, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM5Point1Point4 == AAUDIO_CHANNEL_5POINT1POINT4, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM7Point1Point2 == AAUDIO_CHANNEL_7POINT1POINT2, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM7Point1Point4 == AAUDIO_CHANNEL_7POINT1POINT4, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM9Point1Point4 == AAUDIO_CHANNEL_9POINT1POINT4, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::CM9Point1Point6 == AAUDIO_CHANNEL_9POINT1POINT6, ERRMSG);
|
||||
static_assert((uint32_t)ChannelMask::FrontBack == AAUDIO_CHANNEL_FRONT_BACK, ERRMSG);
|
||||
|
||||
ASSERT_INT32(aaudio_spatialization_behavior_t);
|
||||
|
||||
static_assert((int32_t)SpatializationBehavior::Unspecified == AAUDIO_UNSPECIFIED, ERRMSG);
|
||||
static_assert((int32_t)SpatializationBehavior::Auto == AAUDIO_SPATIALIZATION_BEHAVIOR_AUTO, ERRMSG);
|
||||
static_assert((int32_t)SpatializationBehavior::Never == AAUDIO_SPATIALIZATION_BEHAVIOR_NEVER, ERRMSG);
|
||||
|
||||
#endif
|
||||
|
||||
// The aaudio device type and aaudio policy were added in NDK 28,
|
||||
// which is the first version to support Android W (API 36).
|
||||
#if __NDK_MAJOR__ >= 29
|
||||
|
||||
ASSERT_INT32(AAudio_DeviceType);
|
||||
static_assert((int32_t)DeviceType::BuiltinEarpiece == AAUDIO_DEVICE_BUILTIN_EARPIECE, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::BuiltinSpeaker == AAUDIO_DEVICE_BUILTIN_SPEAKER, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::WiredHeadset == AAUDIO_DEVICE_WIRED_HEADSET, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::WiredHeadphones == AAUDIO_DEVICE_WIRED_HEADPHONES, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::LineAnalog == AAUDIO_DEVICE_LINE_ANALOG, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::LineDigital == AAUDIO_DEVICE_LINE_DIGITAL, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::BluetoothSco == AAUDIO_DEVICE_BLUETOOTH_SCO, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::BluetoothA2dp == AAUDIO_DEVICE_BLUETOOTH_A2DP, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::Hdmi == AAUDIO_DEVICE_HDMI, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::HdmiArc == AAUDIO_DEVICE_HDMI_ARC, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::UsbDevice == AAUDIO_DEVICE_USB_DEVICE, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::UsbAccessory == AAUDIO_DEVICE_USB_ACCESSORY, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::Dock == AAUDIO_DEVICE_DOCK, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::FM == AAUDIO_DEVICE_FM, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::BuiltinMic == AAUDIO_DEVICE_BUILTIN_MIC, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::FMTuner == AAUDIO_DEVICE_FM_TUNER, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::TVTuner == AAUDIO_DEVICE_TV_TUNER, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::Telephony == AAUDIO_DEVICE_TELEPHONY, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::AuxLine == AAUDIO_DEVICE_AUX_LINE, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::IP == AAUDIO_DEVICE_IP, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::Bus == AAUDIO_DEVICE_BUS, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::UsbHeadset == AAUDIO_DEVICE_USB_HEADSET, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::HearingAid == AAUDIO_DEVICE_HEARING_AID, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::BuiltinSpeakerSafe == AAUDIO_DEVICE_BUILTIN_SPEAKER_SAFE, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::RemoteSubmix == AAUDIO_DEVICE_REMOTE_SUBMIX, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::BleHeadset == AAUDIO_DEVICE_BLE_HEADSET, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::BleSpeaker == AAUDIO_DEVICE_BLE_SPEAKER, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::HdmiEarc == AAUDIO_DEVICE_HDMI_EARC, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::BleBroadcast == AAUDIO_DEVICE_BLE_BROADCAST, ERRMSG);
|
||||
static_assert((int32_t)DeviceType::DockAnalog == AAUDIO_DEVICE_DOCK_ANALOG, ERRMSG);
|
||||
|
||||
ASSERT_INT32(aaudio_policy_t);
|
||||
static_assert((int32_t)MMapPolicy::Unspecified == AAUDIO_UNSPECIFIED, ERRMSG);
|
||||
static_assert((int32_t)MMapPolicy::Never == AAUDIO_POLICY_NEVER, ERRMSG);
|
||||
static_assert((int32_t)MMapPolicy::Auto == AAUDIO_POLICY_AUTO, ERRMSG);
|
||||
static_assert((int32_t)MMapPolicy::Always == AAUDIO_POLICY_ALWAYS, ERRMSG);
|
||||
|
||||
#endif // __NDK_MAJOR__ >= 28
|
||||
|
||||
#endif // AAUDIO_AAUDIO_H
|
||||
|
||||
} // namespace oboe
|
||||
353
externals/oboe/src/aaudio/AAudioLoader.h
vendored
Normal file
353
externals/oboe/src/aaudio/AAudioLoader.h
vendored
Normal file
|
|
@ -0,0 +1,353 @@
|
|||
/*
|
||||
* Copyright 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OBOE_AAUDIO_LOADER_H_
|
||||
#define OBOE_AAUDIO_LOADER_H_
|
||||
|
||||
#include <unistd.h>
|
||||
#include "oboe/Definitions.h"
|
||||
|
||||
// If the NDK is before O then define this in your build
|
||||
// so that AAudio.h will not be included.
|
||||
#ifdef OBOE_NO_INCLUDE_AAUDIO
|
||||
|
||||
// Define missing types from AAudio.h
|
||||
typedef int32_t aaudio_stream_state_t;
|
||||
typedef int32_t aaudio_direction_t;
|
||||
typedef int32_t aaudio_format_t;
|
||||
typedef int32_t aaudio_data_callback_result_t;
|
||||
typedef int32_t aaudio_result_t;
|
||||
typedef int32_t aaudio_sharing_mode_t;
|
||||
typedef int32_t aaudio_performance_mode_t;
|
||||
|
||||
typedef struct AAudioStreamStruct AAudioStream;
|
||||
typedef struct AAudioStreamBuilderStruct AAudioStreamBuilder;
|
||||
|
||||
typedef aaudio_data_callback_result_t (*AAudioStream_dataCallback)(
|
||||
AAudioStream *stream,
|
||||
void *userData,
|
||||
void *audioData,
|
||||
int32_t numFrames);
|
||||
|
||||
typedef void (*AAudioStream_errorCallback)(
|
||||
AAudioStream *stream,
|
||||
void *userData,
|
||||
aaudio_result_t error);
|
||||
|
||||
// These were defined in P
|
||||
typedef int32_t aaudio_usage_t;
|
||||
typedef int32_t aaudio_content_type_t;
|
||||
typedef int32_t aaudio_input_preset_t;
|
||||
typedef int32_t aaudio_session_id_t;
|
||||
|
||||
// There are a few definitions used by Oboe.
|
||||
#define AAUDIO_OK static_cast<aaudio_result_t>(Result::OK)
|
||||
#define AAUDIO_ERROR_TIMEOUT static_cast<aaudio_result_t>(Result::ErrorTimeout)
|
||||
#define AAUDIO_STREAM_STATE_STARTING static_cast<aaudio_stream_state_t>(StreamState::Starting)
|
||||
#define AAUDIO_STREAM_STATE_STARTED static_cast<aaudio_stream_state_t>(StreamState::Started)
|
||||
#else
|
||||
#include <aaudio/AAudio.h>
|
||||
#endif
|
||||
|
||||
#ifdef __NDK_MAJOR__
|
||||
#define OBOE_USING_NDK 1
|
||||
#else
|
||||
#define __NDK_MAJOR__ 0
|
||||
#define OBOE_USING_NDK 0
|
||||
#endif
|
||||
|
||||
#if __NDK_MAJOR__ < 24
|
||||
// Defined in SC_V2
|
||||
typedef uint32_t aaudio_channel_mask_t;
|
||||
typedef int32_t aaudio_spatialization_behavior_t;
|
||||
#endif
|
||||
|
||||
#if OBOE_USING_NDK && __NDK_MAJOR__ < 29
|
||||
// Defined in Android B
|
||||
typedef void (*AAudioStream_presentationEndCallback)(
|
||||
AAudioStream* stream,
|
||||
void* userData);
|
||||
#endif
|
||||
|
||||
#ifndef __ANDROID_API_Q__
|
||||
#define __ANDROID_API_Q__ 29
|
||||
#endif
|
||||
|
||||
#ifndef __ANDROID_API_R__
|
||||
#define __ANDROID_API_R__ 30
|
||||
#endif
|
||||
|
||||
#ifndef __ANDROID_API_S__
|
||||
#define __ANDROID_API_S__ 31
|
||||
#endif
|
||||
|
||||
#ifndef __ANDROID_API_S_V2__
|
||||
#define __ANDROID_API_S_V2__ 32
|
||||
#endif
|
||||
|
||||
#ifndef __ANDROID_API_U__
|
||||
#define __ANDROID_API_U__ 34
|
||||
#endif
|
||||
|
||||
#ifndef __ANDROID_API_B__
|
||||
#define __ANDROID_API_B__ 36
|
||||
#endif
|
||||
|
||||
#if OBOE_USING_NDK && __NDK_MAJOR__ < 29
|
||||
// These were defined in Android B
|
||||
typedef int32_t AAudio_DeviceType;
|
||||
typedef int32_t aaudio_policy_t;
|
||||
#endif
|
||||
|
||||
namespace oboe {
|
||||
|
||||
/**
|
||||
* The AAudio API was not available in early versions of Android.
|
||||
* To avoid linker errors, we dynamically link with the functions by name using dlsym().
|
||||
* On older versions this linkage will safely fail.
|
||||
*/
|
||||
class AAudioLoader {
|
||||
public:
|
||||
// Use signatures for common functions.
|
||||
// Key to letter abbreviations.
|
||||
// S = Stream
|
||||
// B = Builder
|
||||
// I = int32_t
|
||||
// L = int64_t
|
||||
// T = sTate
|
||||
// K = clocKid_t
|
||||
// P = Pointer to following data type
|
||||
// C = Const prefix
|
||||
// H = cHar
|
||||
// U = uint32_t
|
||||
// O = bOol
|
||||
// R = pResentation end callback
|
||||
|
||||
typedef int32_t (*signature_I_PPB)(AAudioStreamBuilder **builder);
|
||||
|
||||
typedef const char * (*signature_CPH_I)(int32_t);
|
||||
|
||||
typedef int32_t (*signature_I_PBPPS)(AAudioStreamBuilder *,
|
||||
AAudioStream **stream); // AAudioStreamBuilder_open()
|
||||
|
||||
typedef int32_t (*signature_I_PB)(AAudioStreamBuilder *); // AAudioStreamBuilder_delete()
|
||||
// AAudioStreamBuilder_setSampleRate()
|
||||
typedef void (*signature_V_PBI)(AAudioStreamBuilder *, int32_t);
|
||||
|
||||
// AAudioStreamBuilder_setChannelMask()
|
||||
typedef void (*signature_V_PBU)(AAudioStreamBuilder *, uint32_t);
|
||||
|
||||
typedef void (*signature_V_PBCPH)(AAudioStreamBuilder *, const char *);
|
||||
|
||||
// AAudioStreamBuilder_setPrivacySensitive
|
||||
typedef void (*signature_V_PBO)(AAudioStreamBuilder *, bool);
|
||||
|
||||
typedef int32_t (*signature_I_PS)(AAudioStream *); // AAudioStream_getSampleRate()
|
||||
typedef int64_t (*signature_L_PS)(AAudioStream *); // AAudioStream_getFramesRead()
|
||||
// AAudioStream_setBufferSizeInFrames()
|
||||
typedef int32_t (*signature_I_PSI)(AAudioStream *, int32_t);
|
||||
|
||||
typedef void (*signature_V_PBPDPV)(AAudioStreamBuilder *,
|
||||
AAudioStream_dataCallback,
|
||||
void *);
|
||||
|
||||
typedef void (*signature_V_PBPEPV)(AAudioStreamBuilder *,
|
||||
AAudioStream_errorCallback,
|
||||
void *);
|
||||
|
||||
typedef void (*signature_V_PBPRPV)(AAudioStreamBuilder *,
|
||||
AAudioStream_presentationEndCallback,
|
||||
void *);
|
||||
|
||||
typedef aaudio_format_t (*signature_F_PS)(AAudioStream *stream);
|
||||
|
||||
typedef int32_t (*signature_I_PSPVIL)(AAudioStream *, void *, int32_t, int64_t);
|
||||
typedef int32_t (*signature_I_PSCPVIL)(AAudioStream *, const void *, int32_t, int64_t);
|
||||
|
||||
typedef int32_t (*signature_I_PSTPTL)(AAudioStream *,
|
||||
aaudio_stream_state_t,
|
||||
aaudio_stream_state_t *,
|
||||
int64_t);
|
||||
|
||||
typedef int32_t (*signature_I_PSKPLPL)(AAudioStream *, clockid_t, int64_t *, int64_t *);
|
||||
|
||||
typedef bool (*signature_O_PS)(AAudioStream *);
|
||||
|
||||
typedef uint32_t (*signature_U_PS)(AAudioStream *);
|
||||
|
||||
typedef int32_t (*signature_I_II)(int32_t, int32_t);
|
||||
typedef int32_t (*signature_I_I)(int32_t);
|
||||
typedef int32_t (*signature_I)();
|
||||
typedef int32_t (*signature_I_PSII)(AAudioStream *, int32_t, int32_t);
|
||||
|
||||
// AAudioStream_getDeviceIds()
|
||||
typedef int32_t (*signature_I_PSPIPI)(AAudioStream *, int32_t *, int32_t *);
|
||||
|
||||
static AAudioLoader* getInstance(); // singleton
|
||||
|
||||
/**
|
||||
* Open the AAudio shared library and load the function pointers.
|
||||
* This can be called multiple times.
|
||||
* It should only be called from one thread.
|
||||
*
|
||||
* The destructor will clean up after the open.
|
||||
*
|
||||
* @return 0 if successful or negative error.
|
||||
*/
|
||||
int open();
|
||||
|
||||
void *getLibHandle() const { return mLibHandle; }
|
||||
|
||||
// Function pointers into the AAudio shared library.
|
||||
signature_I_PPB createStreamBuilder = nullptr;
|
||||
|
||||
signature_I_PBPPS builder_openStream = nullptr;
|
||||
|
||||
signature_V_PBI builder_setBufferCapacityInFrames = nullptr;
|
||||
signature_V_PBI builder_setChannelCount = nullptr;
|
||||
signature_V_PBI builder_setDeviceId = nullptr;
|
||||
signature_V_PBI builder_setDirection = nullptr;
|
||||
signature_V_PBI builder_setFormat = nullptr;
|
||||
signature_V_PBI builder_setFramesPerDataCallback = nullptr;
|
||||
signature_V_PBI builder_setPerformanceMode = nullptr;
|
||||
signature_V_PBI builder_setSampleRate = nullptr;
|
||||
signature_V_PBI builder_setSharingMode = nullptr;
|
||||
signature_V_PBU builder_setChannelMask = nullptr;
|
||||
|
||||
signature_V_PBI builder_setUsage = nullptr;
|
||||
signature_V_PBI builder_setContentType = nullptr;
|
||||
signature_V_PBI builder_setInputPreset = nullptr;
|
||||
signature_V_PBI builder_setSessionId = nullptr;
|
||||
|
||||
signature_V_PBO builder_setPrivacySensitive = nullptr;
|
||||
signature_V_PBI builder_setAllowedCapturePolicy = nullptr;
|
||||
|
||||
signature_V_PBCPH builder_setPackageName = nullptr;
|
||||
signature_V_PBCPH builder_setAttributionTag = nullptr;
|
||||
|
||||
signature_V_PBO builder_setIsContentSpatialized = nullptr;
|
||||
signature_V_PBI builder_setSpatializationBehavior = nullptr;
|
||||
|
||||
signature_V_PBPDPV builder_setDataCallback = nullptr;
|
||||
signature_V_PBPEPV builder_setErrorCallback = nullptr;
|
||||
signature_V_PBPRPV builder_setPresentationEndCallback = nullptr;
|
||||
|
||||
signature_I_PB builder_delete = nullptr;
|
||||
|
||||
signature_F_PS stream_getFormat = nullptr;
|
||||
|
||||
signature_I_PSPVIL stream_read = nullptr;
|
||||
signature_I_PSCPVIL stream_write = nullptr;
|
||||
|
||||
signature_I_PSTPTL stream_waitForStateChange = nullptr;
|
||||
|
||||
signature_I_PSKPLPL stream_getTimestamp = nullptr;
|
||||
|
||||
signature_I_PSPIPI stream_getDeviceIds = nullptr;
|
||||
|
||||
signature_I_PS stream_release = nullptr;
|
||||
signature_I_PS stream_close = nullptr;
|
||||
|
||||
signature_I_PS stream_getChannelCount = nullptr;
|
||||
signature_I_PS stream_getDeviceId = nullptr;
|
||||
|
||||
signature_I_PS stream_getBufferSize = nullptr;
|
||||
signature_I_PS stream_getBufferCapacity = nullptr;
|
||||
signature_I_PS stream_getFramesPerBurst = nullptr;
|
||||
signature_I_PS stream_getState = nullptr;
|
||||
signature_I_PS stream_getPerformanceMode = nullptr;
|
||||
signature_I_PS stream_getSampleRate = nullptr;
|
||||
signature_I_PS stream_getSharingMode = nullptr;
|
||||
signature_I_PS stream_getXRunCount = nullptr;
|
||||
|
||||
signature_I_PSI stream_setBufferSize = nullptr;
|
||||
signature_I_PS stream_requestStart = nullptr;
|
||||
signature_I_PS stream_requestPause = nullptr;
|
||||
signature_I_PS stream_requestFlush = nullptr;
|
||||
signature_I_PS stream_requestStop = nullptr;
|
||||
|
||||
signature_L_PS stream_getFramesRead = nullptr;
|
||||
signature_L_PS stream_getFramesWritten = nullptr;
|
||||
|
||||
signature_CPH_I convertResultToText = nullptr;
|
||||
|
||||
signature_I_PS stream_getUsage = nullptr;
|
||||
signature_I_PS stream_getContentType = nullptr;
|
||||
signature_I_PS stream_getInputPreset = nullptr;
|
||||
signature_I_PS stream_getSessionId = nullptr;
|
||||
|
||||
signature_O_PS stream_isPrivacySensitive = nullptr;
|
||||
signature_I_PS stream_getAllowedCapturePolicy = nullptr;
|
||||
|
||||
signature_U_PS stream_getChannelMask = nullptr;
|
||||
|
||||
signature_O_PS stream_isContentSpatialized = nullptr;
|
||||
signature_I_PS stream_getSpatializationBehavior = nullptr;
|
||||
|
||||
signature_I_PS stream_getHardwareChannelCount = nullptr;
|
||||
signature_I_PS stream_getHardwareSampleRate = nullptr;
|
||||
signature_F_PS stream_getHardwareFormat = nullptr;
|
||||
|
||||
|
||||
signature_I_II aaudio_getPlatformMMapPolicy = nullptr;
|
||||
signature_I_II aaudio_getPlatformMMapExclusivePolicy = nullptr;
|
||||
signature_I_I aaudio_setMMapPolicy = nullptr;
|
||||
signature_I aaudio_getMMapPolicy = nullptr;
|
||||
signature_O_PS stream_isMMapUsed = nullptr;
|
||||
|
||||
signature_I_PSII stream_setOffloadDelayPadding = nullptr;
|
||||
signature_I_PS stream_getOffloadDelay = nullptr;
|
||||
signature_I_PS stream_getOffloadPadding = nullptr;
|
||||
signature_I_PS stream_setOffloadEndOfStream = nullptr;
|
||||
|
||||
private:
|
||||
AAudioLoader() {}
|
||||
~AAudioLoader();
|
||||
|
||||
// Load function pointers for specific signatures.
|
||||
signature_I_PPB load_I_PPB(const char *name);
|
||||
signature_CPH_I load_CPH_I(const char *name);
|
||||
signature_V_PBI load_V_PBI(const char *name);
|
||||
signature_V_PBCPH load_V_PBCPH(const char *name);
|
||||
signature_V_PBPDPV load_V_PBPDPV(const char *name);
|
||||
signature_V_PBPEPV load_V_PBPEPV(const char *name);
|
||||
signature_I_PB load_I_PB(const char *name);
|
||||
signature_I_PBPPS load_I_PBPPS(const char *name);
|
||||
signature_I_PS load_I_PS(const char *name);
|
||||
signature_L_PS load_L_PS(const char *name);
|
||||
signature_F_PS load_F_PS(const char *name);
|
||||
signature_O_PS load_O_PS(const char *name);
|
||||
signature_I_PSI load_I_PSI(const char *name);
|
||||
signature_I_PSPVIL load_I_PSPVIL(const char *name);
|
||||
signature_I_PSCPVIL load_I_PSCPVIL(const char *name);
|
||||
signature_I_PSTPTL load_I_PSTPTL(const char *name);
|
||||
signature_I_PSKPLPL load_I_PSKPLPL(const char *name);
|
||||
signature_V_PBU load_V_PBU(const char *name);
|
||||
signature_U_PS load_U_PS(const char *name);
|
||||
signature_V_PBO load_V_PBO(const char *name);
|
||||
signature_I_II load_I_II(const char *name);
|
||||
signature_I_I load_I_I(const char *name);
|
||||
signature_I load_I(const char *name);
|
||||
signature_V_PBPRPV load_V_PBPRPV(const char *name);
|
||||
signature_I_PSII load_I_PSII(const char *name);
|
||||
signature_I_PSPIPI load_I_PSPIPI(const char *name);
|
||||
|
||||
void *mLibHandle = nullptr;
|
||||
};
|
||||
|
||||
} // namespace oboe
|
||||
|
||||
#endif //OBOE_AAUDIO_LOADER_H_
|
||||
1022
externals/oboe/src/aaudio/AudioStreamAAudio.cpp
vendored
Normal file
1022
externals/oboe/src/aaudio/AudioStreamAAudio.cpp
vendored
Normal file
File diff suppressed because it is too large
Load diff
171
externals/oboe/src/aaudio/AudioStreamAAudio.h
vendored
Normal file
171
externals/oboe/src/aaudio/AudioStreamAAudio.h
vendored
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
/*
|
||||
* Copyright 2016 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OBOE_STREAM_AAUDIO_H_
|
||||
#define OBOE_STREAM_AAUDIO_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <shared_mutex>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
|
||||
#include <common/AdpfWrapper.h>
|
||||
#include "oboe/AudioStreamBuilder.h"
|
||||
#include "oboe/AudioStream.h"
|
||||
#include "oboe/Definitions.h"
|
||||
#include "AAudioLoader.h"
|
||||
|
||||
namespace oboe {
|
||||
|
||||
/**
|
||||
* Implementation of OboeStream that uses AAudio.
|
||||
*
|
||||
* Do not create this class directly.
|
||||
* Use an OboeStreamBuilder to create one.
|
||||
*/
|
||||
class AudioStreamAAudio : public AudioStream {
|
||||
public:
|
||||
AudioStreamAAudio();
|
||||
explicit AudioStreamAAudio(const AudioStreamBuilder &builder);
|
||||
|
||||
virtual ~AudioStreamAAudio() = default;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return true if AAudio is supported on this device.
|
||||
*/
|
||||
static bool isSupported();
|
||||
|
||||
// These functions override methods in AudioStream.
|
||||
// See AudioStream for documentation.
|
||||
Result open() override;
|
||||
Result release() override;
|
||||
Result close() override;
|
||||
|
||||
Result requestStart() override;
|
||||
Result requestPause() override;
|
||||
Result requestFlush() override;
|
||||
Result requestStop() override;
|
||||
|
||||
ResultWithValue<int32_t> write(const void *buffer,
|
||||
int32_t numFrames,
|
||||
int64_t timeoutNanoseconds) override;
|
||||
|
||||
ResultWithValue<int32_t> read(void *buffer,
|
||||
int32_t numFrames,
|
||||
int64_t timeoutNanoseconds) override;
|
||||
|
||||
ResultWithValue<int32_t> setBufferSizeInFrames(int32_t requestedFrames) override;
|
||||
int32_t getBufferSizeInFrames() override;
|
||||
ResultWithValue<int32_t> getXRunCount() override;
|
||||
bool isXRunCountSupported() const override { return true; }
|
||||
|
||||
ResultWithValue<double> calculateLatencyMillis() override;
|
||||
|
||||
Result waitForStateChange(StreamState currentState,
|
||||
StreamState *nextState,
|
||||
int64_t timeoutNanoseconds) override;
|
||||
|
||||
Result getTimestamp(clockid_t clockId,
|
||||
int64_t *framePosition,
|
||||
int64_t *timeNanoseconds) override;
|
||||
|
||||
StreamState getState() override;
|
||||
|
||||
AudioApi getAudioApi() const override {
|
||||
return AudioApi::AAudio;
|
||||
}
|
||||
|
||||
DataCallbackResult callOnAudioReady(AAudioStream *stream,
|
||||
void *audioData,
|
||||
int32_t numFrames);
|
||||
|
||||
bool isMMapUsed();
|
||||
|
||||
void closePerformanceHint() override {
|
||||
mAdpfWrapper.close();
|
||||
mAdpfOpenAttempted = false;
|
||||
}
|
||||
|
||||
oboe::Result reportWorkload(int32_t appWorkload) override {
|
||||
if (!isPerformanceHintEnabled()) {
|
||||
return oboe::Result::ErrorInvalidState;
|
||||
}
|
||||
mAdpfWrapper.reportWorkload(appWorkload);
|
||||
return oboe::Result::OK;
|
||||
}
|
||||
|
||||
Result setOffloadDelayPadding(int32_t delayInFrames, int32_t paddingInFrames) override;
|
||||
ResultWithValue<int32_t> getOffloadDelay() override;
|
||||
ResultWithValue<int32_t> getOffloadPadding() override;
|
||||
Result setOffloadEndOfStream() override;
|
||||
|
||||
protected:
|
||||
static void internalErrorCallback(
|
||||
AAudioStream *stream,
|
||||
void *userData,
|
||||
aaudio_result_t error);
|
||||
|
||||
static void internalPresentationEndCallback(
|
||||
AAudioStream *stream,
|
||||
void *userData);
|
||||
|
||||
void *getUnderlyingStream() const override {
|
||||
return mAAudioStream.load();
|
||||
}
|
||||
|
||||
void updateFramesRead() override;
|
||||
void updateFramesWritten() override;
|
||||
|
||||
void logUnsupportedAttributes();
|
||||
|
||||
void beginPerformanceHintInCallback() override;
|
||||
|
||||
void endPerformanceHintInCallback(int32_t numFrames) override;
|
||||
|
||||
// set by callback (or app when idle)
|
||||
std::atomic<bool> mAdpfOpenAttempted{false};
|
||||
AdpfWrapper mAdpfWrapper;
|
||||
|
||||
private:
|
||||
// Must call under mLock. And stream must NOT be nullptr.
|
||||
Result requestStop_l(AAudioStream *stream);
|
||||
|
||||
/**
|
||||
* Launch a thread that will stop the stream.
|
||||
*/
|
||||
void launchStopThread();
|
||||
|
||||
void updateDeviceIds();
|
||||
|
||||
private:
|
||||
|
||||
std::atomic<bool> mCallbackThreadEnabled;
|
||||
std::atomic<bool> mStopThreadAllowed{false};
|
||||
|
||||
// pointer to the underlying 'C' AAudio stream, valid if open, null if closed
|
||||
std::atomic<AAudioStream *> mAAudioStream{nullptr};
|
||||
std::shared_mutex mAAudioStreamLock; // to protect mAAudioStream while closing
|
||||
|
||||
static AAudioLoader *mLibLoader;
|
||||
|
||||
// We may not use this but it is so small that it is not worth allocating dynamically.
|
||||
AudioStreamErrorCallback mDefaultErrorCallback;
|
||||
};
|
||||
|
||||
} // namespace oboe
|
||||
|
||||
#endif // OBOE_STREAM_AAUDIO_H_
|
||||
Loading…
Add table
Add a link
Reference in a new issue