Skip to content

Commit

Permalink
Do not use AAudio unless running on Android 8.1 or higher
Browse files Browse the repository at this point in the history
From #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.
  • Loading branch information
Mikhail Naganov committed Feb 6, 2018
1 parent 8de6af0 commit d35c572
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/aaudio/AudioStreamAAudio.cpp
Expand Up @@ -16,12 +16,16 @@

#include <assert.h>
#include <stdint.h>
#include <stdlib.h>

#include "aaudio/AAudioLoader.h"
#include "aaudio/AudioStreamAAudio.h"
#include "common/OboeDebug.h"
#include "oboe/Utilities.h"

#ifdef __ANDROID__
#include <sys/system_properties.h>
#endif


using namespace oboe;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -380,4 +399,4 @@ Result AudioStreamAAudio::getTimestamp(clockid_t clockId,
}
}

} // namespace oboe
} // namespace oboe

0 comments on commit d35c572

Please sign in to comment.