Skip to content

Commit

Permalink
Merge branch 'issupported' of https://github.com/google/oboe
Browse files Browse the repository at this point in the history
* 'issupported' of https://github.com/google/oboe:
  oboe: add easy way to query whether AAudio is supported
  • Loading branch information
dturner committed Oct 25, 2017
2 parents 6ef7e0c + 19f9815 commit 01f0477
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
7 changes: 7 additions & 0 deletions include/oboe/OboeStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ class OboeStream : public OboeStreamBase {
return OBOE_ERROR_UNIMPLEMENTED;
}

/**
*
* @return true if this stream is implemented using the AAudio API
*/
virtual bool usesAAudio() const {
return false;
}

protected:

Expand Down
10 changes: 9 additions & 1 deletion include/oboe/OboeStreamBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class OboeStreamBuilder : public OboeStreamBase {
return this;
}


/**
* Request the direction for a stream. The default is OBOE_DIRECTION_OUTPUT.
*
Expand Down Expand Up @@ -142,6 +141,15 @@ class OboeStreamBuilder : public OboeStreamBase {
return this;
}

/**
* Is the AAudio API supported on this device?
*
* AAudio was introduced in the Oreo release.
*
* @return true if supported
*/
static bool isAAudioSupported();

/**
* Request a mode for sharing the device.
* The requested sharing mode may not be available.
Expand Down
3 changes: 3 additions & 0 deletions src/aaudio/OboeStreamAAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ oboe_result_t OboeStreamAAudio::open() {
goto error2;
}

// Query and cache the values that will not change.
mDeviceId = mLibLoader->stream_getDeviceId(mAAudioStream);
mChannelCount = mLibLoader->stream_getChannelCount(mAAudioStream);
mSampleRate = mLibLoader->stream_getSampleRate(mAAudioStream);
mNativeFormat = mLibLoader->stream_getFormat(mAAudioStream);
Expand All @@ -130,6 +132,7 @@ oboe_result_t OboeStreamAAudio::open() {

LOGD("OboeStreamAAudio.open() app format = %d", (int) mFormat);
LOGD("OboeStreamAAudio.open() native format = %d", (int) mNativeFormat);
LOGD("OboeStreamAAudio.open() sample rate = %d", (int) mSampleRate);

error2:
mLibLoader->builder_delete(aaudioBuilder);
Expand Down
6 changes: 5 additions & 1 deletion src/aaudio/OboeStreamAAudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class OboeStreamAAudio : public OboeStream {

/**
*
* @return true is AAudio is supported on this device.
* @return true if AAudio is supported on this device.
*/
static bool isSupported();

Expand Down Expand Up @@ -80,6 +80,10 @@ class OboeStreamAAudio : public OboeStream {
oboe_stream_state_t getState() override;


bool usesAAudio() const override {
return true;
}

public:
aaudio_data_callback_result_t callOnAudioReady(AAudioStream *stream,
void *audioData,
Expand Down
4 changes: 4 additions & 0 deletions src/common/OboeStreamBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include "opensles/OboeStreamOpenSLES.h"
#include "aaudio/OboeStreamAAudio.h"

bool OboeStreamBuilder::isAAudioSupported() {
return OboeStreamAAudio::isSupported();
}

OboeStream *OboeStreamBuilder::build() {
LOGD("OboeStreamBuilder.build(): mAudioApi %d, mChannelCount = %d, mFramesPerCallback = %d",
mAudioApi, mChannelCount, mFramesPerCallback);
Expand Down
1 change: 0 additions & 1 deletion src/common/OboeUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#define OBOE_CASE_ENUM(name) case name: return #name


void Oboe_convertFloatToPcm16(const float *source, int16_t *destination, int32_t numSamples) {
for (int i = 0; i < numSamples; i++) {
float fval = source[i];
Expand Down

0 comments on commit 01f0477

Please sign in to comment.