From d35c572c56e312c8cef0e0eb31779ef8dcbb1ded Mon Sep 17 00:00:00 2001 From: Mikhail Naganov Date: Mon, 5 Feb 2018 17:26:45 -0800 Subject: [PATCH] Do not use AAudio unless running on Android 8.1 or higher From https://github.com/google/oboe/issues/40, it seems that AAudio on Android 8.0 isn't stable enough. As a safety measure, always fall back to OpenSL ES on it. --- src/aaudio/AudioStreamAAudio.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/aaudio/AudioStreamAAudio.cpp b/src/aaudio/AudioStreamAAudio.cpp index a256ef1c4..452f8407e 100644 --- a/src/aaudio/AudioStreamAAudio.cpp +++ b/src/aaudio/AudioStreamAAudio.cpp @@ -16,12 +16,16 @@ #include #include +#include #include "aaudio/AAudioLoader.h" #include "aaudio/AudioStreamAAudio.h" #include "common/OboeDebug.h" #include "oboe/Utilities.h" +#ifdef __ANDROID__ +#include +#endif using namespace oboe; @@ -89,7 +93,22 @@ AudioStreamAAudio::~AudioStreamAAudio() delete[] mShortCallbackBuffer; } +static bool isRunningOnAndroid8_1OrHigher() { +#ifdef __ANDROID__ + char sdk[PROP_VALUE_MAX] = {0}; + if (__system_property_get("ro.build.version.sdk", sdk) != 0) { + return atoi(sdk) >= 27; // SDK Level 27 is Android Oreo 8.1 + } +#endif + return false; +} + bool AudioStreamAAudio::isSupported() { + if (!isRunningOnAndroid8_1OrHigher()) { + // See https://github.com/google/oboe/issues/40, + // AAudio is not stable enough on Android 8.0. + return false; + } mLibLoader = AAudioLoader::getInstance(); int openResult = mLibLoader->open(); return openResult == 0; @@ -380,4 +399,4 @@ Result AudioStreamAAudio::getTimestamp(clockid_t clockId, } } -} // namespace oboe \ No newline at end of file +} // namespace oboe