liboboe: rename Oboe to AAudio
All of the edits were done using scripts in media/liboboe/scripts.
The conversion is done using SED, which is called from
convert_oboe_aaudio.sh
The conversion can be reverted when debugging using revert_all_aaudio.sh
The string substitutions are in oboe_to_aaudio.sed
Bug: 34749573
Test: cts/tests/tests/nativemedia/aaudio
Change-Id: Ia10b34472a90df2652b87607c99156e9084e57aa
Signed-off-by: Phil Burk <philburk@google.com>
diff --git a/media/liboboe/src/utility/AAudioUtilities.cpp b/media/liboboe/src/utility/AAudioUtilities.cpp
new file mode 100644
index 0000000..34c1ae4
--- /dev/null
+++ b/media/liboboe/src/utility/AAudioUtilities.cpp
@@ -0,0 +1,188 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "AAudio"
+//#define LOG_NDEBUG 0
+#include <utils/Log.h>
+
+#include <stdint.h>
+#include <sys/types.h>
+#include <utils/Errors.h>
+
+#include "aaudio/AAudioDefinitions.h"
+#include "AAudioUtilities.h"
+
+using namespace android;
+
+aaudio_size_bytes_t AAudioConvert_formatToSizeInBytes(aaudio_audio_format_t format) {
+ aaudio_size_bytes_t size = AAUDIO_ERROR_ILLEGAL_ARGUMENT;
+ switch (format) {
+ case AAUDIO_FORMAT_PCM_I16:
+ size = sizeof(int16_t);
+ break;
+ case AAUDIO_FORMAT_PCM_I32:
+ case AAUDIO_FORMAT_PCM_I8_24:
+ size = sizeof(int32_t);
+ break;
+ case AAUDIO_FORMAT_PCM_FLOAT:
+ size = sizeof(float);
+ break;
+ default:
+ break;
+ }
+ return size;
+}
+
+// TODO This similar to a function in audio_utils. Consider using that instead.
+void AAudioConvert_floatToPcm16(const float *source, int32_t numSamples, int16_t *destination) {
+ for (int i = 0; i < numSamples; i++) {
+ float fval = source[i];
+ fval += 1.0; // to avoid discontinuity at 0.0 caused by truncation
+ fval *= 32768.0f;
+ int32_t sample = (int32_t) fval;
+ // clip to 16-bit range
+ if (sample < 0) sample = 0;
+ else if (sample > 0x0FFFF) sample = 0x0FFFF;
+ sample -= 32768; // center at zero
+ destination[i] = (int16_t) sample;
+ }
+}
+
+void AAudioConvert_pcm16ToFloat(const float *source, int32_t numSamples, int16_t *destination) {
+ for (int i = 0; i < numSamples; i++) {
+ destination[i] = source[i] * (1.0f / 32768.0f);
+ }
+}
+
+status_t AAudioConvert_aaudioToAndroidStatus(aaudio_result_t result) {
+ // This covers the case for AAUDIO_OK and for positive results.
+ if (result >= 0) {
+ return result;
+ }
+ status_t status;
+ switch (result) {
+ case AAUDIO_ERROR_DISCONNECTED:
+ case AAUDIO_ERROR_INVALID_HANDLE:
+ status = DEAD_OBJECT;
+ break;
+ case AAUDIO_ERROR_INVALID_STATE:
+ status = INVALID_OPERATION;
+ break;
+ case AAUDIO_ERROR_UNEXPECTED_VALUE: // TODO redundant?
+ case AAUDIO_ERROR_ILLEGAL_ARGUMENT:
+ status = BAD_VALUE;
+ break;
+ case AAUDIO_ERROR_WOULD_BLOCK:
+ status = WOULD_BLOCK;
+ break;
+ // TODO add more result codes
+ default:
+ status = UNKNOWN_ERROR;
+ break;
+ }
+ return status;
+}
+
+aaudio_result_t AAudioConvert_androidToAAudioResult(status_t status) {
+ // This covers the case for OK and for positive result.
+ if (status >= 0) {
+ return status;
+ }
+ aaudio_result_t result;
+ switch (status) {
+ case BAD_TYPE:
+ result = AAUDIO_ERROR_INVALID_HANDLE;
+ break;
+ case DEAD_OBJECT:
+ result = AAUDIO_ERROR_DISCONNECTED;
+ break;
+ case INVALID_OPERATION:
+ result = AAUDIO_ERROR_INVALID_STATE;
+ break;
+ case BAD_VALUE:
+ result = AAUDIO_ERROR_UNEXPECTED_VALUE;
+ break;
+ case WOULD_BLOCK:
+ result = AAUDIO_ERROR_WOULD_BLOCK;
+ break;
+ // TODO add more status codes
+ default:
+ result = AAUDIO_ERROR_INTERNAL;
+ break;
+ }
+ return result;
+}
+
+audio_format_t AAudioConvert_aaudioToAndroidDataFormat(aaudio_audio_format_t aaudioFormat) {
+ audio_format_t androidFormat;
+ switch (aaudioFormat) {
+ case AAUDIO_FORMAT_PCM_I16:
+ androidFormat = AUDIO_FORMAT_PCM_16_BIT;
+ break;
+ case AAUDIO_FORMAT_PCM_FLOAT:
+ androidFormat = AUDIO_FORMAT_PCM_FLOAT;
+ break;
+ case AAUDIO_FORMAT_PCM_I8_24:
+ androidFormat = AUDIO_FORMAT_PCM_8_24_BIT;
+ break;
+ case AAUDIO_FORMAT_PCM_I32:
+ androidFormat = AUDIO_FORMAT_PCM_32_BIT;
+ break;
+ default:
+ androidFormat = AUDIO_FORMAT_DEFAULT;
+ ALOGE("AAudioConvert_aaudioToAndroidDataFormat 0x%08X unrecognized", aaudioFormat);
+ break;
+ }
+ return androidFormat;
+}
+
+aaudio_audio_format_t AAudioConvert_androidToAAudioDataFormat(audio_format_t androidFormat) {
+ aaudio_audio_format_t aaudioFormat = AAUDIO_FORMAT_INVALID;
+ switch (androidFormat) {
+ case AUDIO_FORMAT_PCM_16_BIT:
+ aaudioFormat = AAUDIO_FORMAT_PCM_I16;
+ break;
+ case AUDIO_FORMAT_PCM_FLOAT:
+ aaudioFormat = AAUDIO_FORMAT_PCM_FLOAT;
+ break;
+ case AUDIO_FORMAT_PCM_32_BIT:
+ aaudioFormat = AAUDIO_FORMAT_PCM_I32;
+ break;
+ case AUDIO_FORMAT_PCM_8_24_BIT:
+ aaudioFormat = AAUDIO_FORMAT_PCM_I8_24;
+ break;
+ default:
+ aaudioFormat = AAUDIO_FORMAT_INVALID;
+ ALOGE("AAudioConvert_androidToAAudioDataFormat 0x%08X unrecognized", androidFormat);
+ break;
+ }
+ return aaudioFormat;
+}
+
+aaudio_size_bytes_t AAudioConvert_framesToBytes(aaudio_size_frames_t numFrames,
+ aaudio_size_bytes_t bytesPerFrame,
+ aaudio_size_bytes_t *sizeInBytes) {
+ // TODO implement more elegantly
+ const int32_t maxChannels = 256; // ridiculously large
+ const aaudio_size_frames_t maxBytesPerFrame = maxChannels * sizeof(float);
+ // Prevent overflow by limiting multiplicands.
+ if (bytesPerFrame > maxBytesPerFrame || numFrames > (0x3FFFFFFF / maxBytesPerFrame)) {
+ ALOGE("size overflow, numFrames = %d, frameSize = %zd", numFrames, bytesPerFrame);
+ return AAUDIO_ERROR_OUT_OF_RANGE;
+ }
+ *sizeInBytes = numFrames * bytesPerFrame;
+ return AAUDIO_OK;
+}
diff --git a/media/liboboe/src/utility/AAudioUtilities.h b/media/liboboe/src/utility/AAudioUtilities.h
new file mode 100644
index 0000000..38696df
--- /dev/null
+++ b/media/liboboe/src/utility/AAudioUtilities.h
@@ -0,0 +1,62 @@
+/*
+ * 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 UTILITY_AAUDIO_UTILITIES_H
+#define UTILITY_AAUDIO_UTILITIES_H
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <utils/Errors.h>
+#include <hardware/audio.h>
+
+#include "aaudio/AAudioDefinitions.h"
+
+/**
+ * Convert an AAudio result into the closest matching Android status.
+ */
+android::status_t AAudioConvert_aaudioToAndroidStatus(aaudio_result_t result);
+
+/**
+ * Convert an Android status into the closest matching AAudio result.
+ */
+aaudio_result_t AAudioConvert_androidToAAudioResult(android::status_t status);
+
+void AAudioConvert_floatToPcm16(const float *source, int32_t numSamples, int16_t *destination);
+
+void AAudioConvert_pcm16ToFloat(const int16_t *source, int32_t numSamples, float *destination);
+
+/**
+ * Calculate the number of bytes and prevent numeric overflow.
+ * @param numFrames frame count
+ * @param bytesPerFrame size of a frame in bytes
+ * @param sizeInBytes total size in bytes
+ * @return AAUDIO_OK or negative error, eg. AAUDIO_ERROR_OUT_OF_RANGE
+ */
+aaudio_size_bytes_t AAudioConvert_framesToBytes(aaudio_size_frames_t numFrames,
+ aaudio_size_bytes_t bytesPerFrame,
+ aaudio_size_bytes_t *sizeInBytes);
+
+audio_format_t AAudioConvert_aaudioToAndroidDataFormat(aaudio_audio_format_t aaudio_format);
+
+aaudio_audio_format_t AAudioConvert_androidToAAudioDataFormat(audio_format_t format);
+
+/**
+ * @return the size of a sample of the given format in bytes or AAUDIO_ERROR_ILLEGAL_ARGUMENT
+ */
+aaudio_size_bytes_t AAudioConvert_formatToSizeInBytes(aaudio_audio_format_t format);
+
+#endif //UTILITY_AAUDIO_UTILITIES_H
diff --git a/media/liboboe/src/utility/AudioClock.h b/media/liboboe/src/utility/AudioClock.h
index 1779d8b..9ac21d3 100644
--- a/media/liboboe/src/utility/AudioClock.h
+++ b/media/liboboe/src/utility/AudioClock.h
@@ -20,35 +20,35 @@
#include <stdint.h>
#include <time.h>
-#include <oboe/OboeDefinitions.h>
+#include <aaudio/AAudioDefinitions.h>
class AudioClock {
public:
- static oboe_nanoseconds_t getNanoseconds(clockid_t clockId = CLOCK_MONOTONIC) {
+ static aaudio_nanoseconds_t getNanoseconds(clockid_t clockId = CLOCK_MONOTONIC) {
struct timespec time;
int result = clock_gettime(clockId, &time);
if (result < 0) {
return -errno;
}
- return (time.tv_sec * OBOE_NANOS_PER_SECOND) + time.tv_nsec;
+ return (time.tv_sec * AAUDIO_NANOS_PER_SECOND) + time.tv_nsec;
}
/**
* Sleep until the specified absolute time.
- * Return immediately with OBOE_ERROR_ILLEGAL_ARGUMENT if a negative
+ * Return immediately with AAUDIO_ERROR_ILLEGAL_ARGUMENT if a negative
* nanoTime is specified.
*
* @param nanoTime time to wake up
* @param clockId CLOCK_MONOTONIC is default
* @return 0, a negative error, or 1 if the call is interrupted by a signal handler (EINTR)
*/
- static int sleepUntilNanoTime(oboe_nanoseconds_t nanoTime,
+ static int sleepUntilNanoTime(aaudio_nanoseconds_t nanoTime,
clockid_t clockId = CLOCK_MONOTONIC) {
if (nanoTime > 0) {
struct timespec time;
- time.tv_sec = nanoTime / OBOE_NANOS_PER_SECOND;
+ time.tv_sec = nanoTime / AAUDIO_NANOS_PER_SECOND;
// Calculate the fractional nanoseconds. Avoids expensive % operation.
- time.tv_nsec = nanoTime - (time.tv_sec * OBOE_NANOS_PER_SECOND);
+ time.tv_nsec = nanoTime - (time.tv_sec * AAUDIO_NANOS_PER_SECOND);
int err = clock_nanosleep(clockId, TIMER_ABSTIME, &time, nullptr);
switch (err) {
case EINTR:
@@ -60,7 +60,7 @@
return 0 - err;
}
} else {
- return OBOE_ERROR_ILLEGAL_ARGUMENT;
+ return AAUDIO_ERROR_ILLEGAL_ARGUMENT;
}
}
@@ -72,12 +72,12 @@
* @param clockId CLOCK_MONOTONIC is default
* @return 0, a negative error, or 1 if the call is interrupted by a signal handler (EINTR)
*/
- static int sleepForNanos(oboe_nanoseconds_t nanoseconds, clockid_t clockId = CLOCK_MONOTONIC) {
+ static int sleepForNanos(aaudio_nanoseconds_t nanoseconds, clockid_t clockId = CLOCK_MONOTONIC) {
if (nanoseconds > 0) {
struct timespec time;
- time.tv_sec = nanoseconds / OBOE_NANOS_PER_SECOND;
+ time.tv_sec = nanoseconds / AAUDIO_NANOS_PER_SECOND;
// Calculate the fractional nanoseconds. Avoids expensive % operation.
- time.tv_nsec = nanoseconds - (time.tv_sec * OBOE_NANOS_PER_SECOND);
+ time.tv_nsec = nanoseconds - (time.tv_sec * AAUDIO_NANOS_PER_SECOND);
const int flags = 0; // documented as relative sleep
int err = clock_nanosleep(clockId, flags, &time, nullptr);
switch (err) {
diff --git a/media/liboboe/src/utility/HandleTracker.cpp b/media/liboboe/src/utility/HandleTracker.cpp
index 27cc1f8..c4880b8 100644
--- a/media/liboboe/src/utility/HandleTracker.cpp
+++ b/media/liboboe/src/utility/HandleTracker.cpp
@@ -15,7 +15,7 @@
*
*/
-#define LOG_TAG "OboeAudio"
+#define LOG_TAG "AAudio"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
@@ -24,7 +24,7 @@
#include <stdint.h>
#include <utils/Mutex.h>
-#include <oboe/OboeDefinitions.h>
+#include <aaudio/AAudioDefinitions.h>
#include "HandleTracker.h"
using android::Mutex;
@@ -112,13 +112,13 @@
return generation;
}
-oboe_handle_t HandleTracker::put(handle_tracker_type_t type, void *address)
+aaudio_handle_t HandleTracker::put(handle_tracker_type_t type, void *address)
{
if (type < 0 || type >= HANDLE_TRACKER_MAX_TYPES) {
- return static_cast<oboe_handle_t>(OBOE_ERROR_OUT_OF_RANGE);
+ return static_cast<aaudio_handle_t>(AAUDIO_ERROR_OUT_OF_RANGE);
}
if (!isInitialized()) {
- return static_cast<oboe_handle_t>(OBOE_ERROR_NO_MEMORY);
+ return static_cast<aaudio_handle_t>(AAUDIO_ERROR_NO_MEMORY);
}
Mutex::Autolock _l(mLock);
@@ -127,7 +127,7 @@
handle_tracker_slot_t index = allocateSlot_l();
if (index == SLOT_UNAVAILABLE) {
ALOGE("HandleTracker::put() no room for more handles");
- return static_cast<oboe_handle_t>(OBOE_ERROR_NO_FREE_HANDLES);
+ return static_cast<aaudio_handle_t>(AAUDIO_ERROR_NO_FREE_HANDLES);
}
// Cycle the generation counter so stale handles can be detected.
@@ -140,20 +140,20 @@
// TODO use store release to enforce memory order with get()
// Generate a handle.
- oboe_handle_t handle = buildHandle(inputHeader, index);
+ aaudio_handle_t handle = buildHandle(inputHeader, index);
ALOGV("HandleTracker::put(%p) returns 0x%08x", address, handle);
return handle;
}
handle_tracker_slot_t HandleTracker::handleToIndex(handle_tracker_type_t type,
- oboe_handle_t handle) const
+ aaudio_handle_t handle) const
{
// Validate the handle.
handle_tracker_slot_t index = extractIndex(handle);
if (index >= mMaxHandleCount) {
ALOGE("HandleTracker::handleToIndex() invalid handle = 0x%08X", handle);
- return static_cast<oboe_handle_t>(OBOE_ERROR_INVALID_HANDLE);
+ return static_cast<aaudio_handle_t>(AAUDIO_ERROR_INVALID_HANDLE);
}
handle_tracker_generation_t handleGeneration = extractGeneration(handle);
handle_tracker_header_t inputHeader = buildHeader(type, handleGeneration);
@@ -162,12 +162,12 @@
if (inputHeader != mHandleHeaders[index]) {
ALOGE("HandleTracker::handleToIndex() inputHeader = 0x%08x != mHandleHeaders[%d] = 0x%08x",
inputHeader, index, mHandleHeaders[index]);
- return static_cast<oboe_handle_t>(OBOE_ERROR_INVALID_HANDLE);
+ return static_cast<aaudio_handle_t>(AAUDIO_ERROR_INVALID_HANDLE);
}
return index;
}
-handle_tracker_address_t HandleTracker::get(handle_tracker_type_t type, oboe_handle_t handle) const
+handle_tracker_address_t HandleTracker::get(handle_tracker_type_t type, aaudio_handle_t handle) const
{
if (!isInitialized()) {
return nullptr;
@@ -182,7 +182,7 @@
}
}
-handle_tracker_address_t HandleTracker::remove(handle_tracker_type_t type, oboe_handle_t handle) {
+handle_tracker_address_t HandleTracker::remove(handle_tracker_type_t type, aaudio_handle_t handle) {
if (!isInitialized()) {
return nullptr;
}
@@ -208,9 +208,9 @@
}
}
-oboe_handle_t HandleTracker::buildHandle(handle_tracker_header_t typeGeneration,
+aaudio_handle_t HandleTracker::buildHandle(handle_tracker_header_t typeGeneration,
handle_tracker_slot_t index) {
- return (oboe_handle_t)((typeGeneration << GENERATION_SHIFT) | (index & INDEX_MASK));
+ return (aaudio_handle_t)((typeGeneration << GENERATION_SHIFT) | (index & INDEX_MASK));
}
handle_tracker_header_t HandleTracker::buildHeader(handle_tracker_type_t type,
@@ -220,12 +220,12 @@
| (generation & GENERATION_MASK));
}
-handle_tracker_slot_t HandleTracker::extractIndex(oboe_handle_t handle)
+handle_tracker_slot_t HandleTracker::extractIndex(aaudio_handle_t handle)
{
return handle & INDEX_MASK;
}
-handle_tracker_generation_t HandleTracker::extractGeneration(oboe_handle_t handle)
+handle_tracker_generation_t HandleTracker::extractGeneration(aaudio_handle_t handle)
{
return (handle >> GENERATION_SHIFT) & GENERATION_MASK;
}
diff --git a/media/liboboe/src/utility/HandleTracker.h b/media/liboboe/src/utility/HandleTracker.h
index f1bead8..c80860c 100644
--- a/media/liboboe/src/utility/HandleTracker.h
+++ b/media/liboboe/src/utility/HandleTracker.h
@@ -60,7 +60,7 @@
* @param address pointer to be converted to a handle
* @return a valid handle or a negative error
*/
- oboe_handle_t put(handle_tracker_type_t expectedType, handle_tracker_address_t address);
+ aaudio_handle_t put(handle_tracker_type_t expectedType, handle_tracker_address_t address);
/**
* Get the original pointer associated with the handle.
@@ -72,7 +72,7 @@
* @param handle to be converted to a pointer
* @return address associated with handle or nullptr
*/
- handle_tracker_address_t get(handle_tracker_type_t expectedType, oboe_handle_t handle) const;
+ handle_tracker_address_t get(handle_tracker_type_t expectedType, aaudio_handle_t handle) const;
/**
* Free up the storage associated with the handle.
@@ -84,7 +84,7 @@
* @param handle to be removed from tracking
* @return address associated with handle or nullptr if not found
*/
- handle_tracker_address_t remove(handle_tracker_type_t expectedType, oboe_handle_t handle);
+ handle_tracker_address_t remove(handle_tracker_type_t expectedType, aaudio_handle_t handle);
private:
const int32_t mMaxHandleCount; // size of array
@@ -115,7 +115,7 @@
* Validate the handle and return the corresponding index.
* @return slot index or a negative error
*/
- handle_tracker_slot_t handleToIndex(oboe_handle_t handle, handle_tracker_type_t type) const;
+ handle_tracker_slot_t handleToIndex(aaudio_handle_t handle, handle_tracker_type_t type) const;
/**
* Construct a handle from a header and an index.
@@ -123,7 +123,7 @@
* @param index slot index returned from allocateSlot
* @return handle or a negative error
*/
- static oboe_handle_t buildHandle(handle_tracker_header_t header, handle_tracker_slot_t index);
+ static aaudio_handle_t buildHandle(handle_tracker_header_t header, handle_tracker_slot_t index);
/**
* Combine a type and a generation field into a header.
@@ -136,14 +136,14 @@
* Does not validate the handle.
* @return index associated with a handle
*/
- static handle_tracker_slot_t extractIndex(oboe_handle_t handle);
+ static handle_tracker_slot_t extractIndex(aaudio_handle_t handle);
/**
* Extract the generation from a handle.
* Does not validate the handle.
* @return generation associated with a handle
*/
- static handle_tracker_generation_t extractGeneration(oboe_handle_t handle);
+ static handle_tracker_generation_t extractGeneration(aaudio_handle_t handle);
};
diff --git a/media/liboboe/src/utility/OboeUtilities.cpp b/media/liboboe/src/utility/OboeUtilities.cpp
deleted file mode 100644
index fcf4252..0000000
--- a/media/liboboe/src/utility/OboeUtilities.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * 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.
- */
-
-#define LOG_TAG "OboeAudio"
-//#define LOG_NDEBUG 0
-#include <utils/Log.h>
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <utils/Errors.h>
-
-#include "oboe/OboeDefinitions.h"
-#include "OboeUtilities.h"
-
-using namespace android;
-
-oboe_size_bytes_t OboeConvert_formatToSizeInBytes(oboe_audio_format_t format) {
- oboe_size_bytes_t size = OBOE_ERROR_ILLEGAL_ARGUMENT;
- switch (format) {
- case OBOE_AUDIO_FORMAT_PCM_I16:
- size = sizeof(int16_t);
- break;
- case OBOE_AUDIO_FORMAT_PCM_I32:
- case OBOE_AUDIO_FORMAT_PCM_I8_24:
- size = sizeof(int32_t);
- break;
- case OBOE_AUDIO_FORMAT_PCM_FLOAT:
- size = sizeof(float);
- break;
- default:
- break;
- }
- return size;
-}
-
-// TODO This similar to a function in audio_utils. Consider using that instead.
-void OboeConvert_floatToPcm16(const float *source, int32_t numSamples, int16_t *destination) {
- for (int i = 0; i < numSamples; i++) {
- float fval = source[i];
- fval += 1.0; // to avoid discontinuity at 0.0 caused by truncation
- fval *= 32768.0f;
- int32_t sample = (int32_t) fval;
- // clip to 16-bit range
- if (sample < 0) sample = 0;
- else if (sample > 0x0FFFF) sample = 0x0FFFF;
- sample -= 32768; // center at zero
- destination[i] = (int16_t) sample;
- }
-}
-
-void OboeConvert_pcm16ToFloat(const float *source, int32_t numSamples, int16_t *destination) {
- for (int i = 0; i < numSamples; i++) {
- destination[i] = source[i] * (1.0f / 32768.0f);
- }
-}
-
-status_t OboeConvert_oboeToAndroidStatus(oboe_result_t result) {
- // This covers the case for OBOE_OK and for positive results.
- if (result >= 0) {
- return result;
- }
- status_t status;
- switch (result) {
- case OBOE_ERROR_DISCONNECTED:
- case OBOE_ERROR_INVALID_HANDLE:
- status = DEAD_OBJECT;
- break;
- case OBOE_ERROR_INVALID_STATE:
- status = INVALID_OPERATION;
- break;
- case OBOE_ERROR_UNEXPECTED_VALUE: // TODO redundant?
- case OBOE_ERROR_ILLEGAL_ARGUMENT:
- status = BAD_VALUE;
- break;
- case OBOE_ERROR_WOULD_BLOCK:
- status = WOULD_BLOCK;
- break;
- // TODO add more result codes
- default:
- status = UNKNOWN_ERROR;
- break;
- }
- return status;
-}
-
-oboe_result_t OboeConvert_androidToOboeResult(status_t status) {
- // This covers the case for OK and for positive result.
- if (status >= 0) {
- return status;
- }
- oboe_result_t result;
- switch (status) {
- case BAD_TYPE:
- result = OBOE_ERROR_INVALID_HANDLE;
- break;
- case DEAD_OBJECT:
- result = OBOE_ERROR_DISCONNECTED;
- break;
- case INVALID_OPERATION:
- result = OBOE_ERROR_INVALID_STATE;
- break;
- case BAD_VALUE:
- result = OBOE_ERROR_UNEXPECTED_VALUE;
- break;
- case WOULD_BLOCK:
- result = OBOE_ERROR_WOULD_BLOCK;
- break;
- // TODO add more status codes
- default:
- result = OBOE_ERROR_INTERNAL;
- break;
- }
- return result;
-}
-
-audio_format_t OboeConvert_oboeToAndroidDataFormat(oboe_audio_format_t oboeFormat) {
- audio_format_t androidFormat;
- switch (oboeFormat) {
- case OBOE_AUDIO_FORMAT_PCM_I16:
- androidFormat = AUDIO_FORMAT_PCM_16_BIT;
- break;
- case OBOE_AUDIO_FORMAT_PCM_FLOAT:
- androidFormat = AUDIO_FORMAT_PCM_FLOAT;
- break;
- case OBOE_AUDIO_FORMAT_PCM_I8_24:
- androidFormat = AUDIO_FORMAT_PCM_8_24_BIT;
- break;
- case OBOE_AUDIO_FORMAT_PCM_I32:
- androidFormat = AUDIO_FORMAT_PCM_32_BIT;
- break;
- default:
- androidFormat = AUDIO_FORMAT_DEFAULT;
- ALOGE("OboeConvert_oboeToAndroidDataFormat 0x%08X unrecognized", oboeFormat);
- break;
- }
- return androidFormat;
-}
-
-oboe_audio_format_t OboeConvert_androidToOboeDataFormat(audio_format_t androidFormat) {
- oboe_audio_format_t oboeFormat = OBOE_AUDIO_FORMAT_INVALID;
- switch (androidFormat) {
- case AUDIO_FORMAT_PCM_16_BIT:
- oboeFormat = OBOE_AUDIO_FORMAT_PCM_I16;
- break;
- case AUDIO_FORMAT_PCM_FLOAT:
- oboeFormat = OBOE_AUDIO_FORMAT_PCM_FLOAT;
- break;
- case AUDIO_FORMAT_PCM_32_BIT:
- oboeFormat = OBOE_AUDIO_FORMAT_PCM_I32;
- break;
- case AUDIO_FORMAT_PCM_8_24_BIT:
- oboeFormat = OBOE_AUDIO_FORMAT_PCM_I8_24;
- break;
- default:
- oboeFormat = OBOE_AUDIO_FORMAT_INVALID;
- ALOGE("OboeConvert_androidToOboeDataFormat 0x%08X unrecognized", androidFormat);
- break;
- }
- return oboeFormat;
-}
-
-oboe_size_bytes_t OboeConvert_framesToBytes(oboe_size_frames_t numFrames,
- oboe_size_bytes_t bytesPerFrame,
- oboe_size_bytes_t *sizeInBytes) {
- // TODO implement more elegantly
- const int32_t maxChannels = 256; // ridiculously large
- const oboe_size_frames_t maxBytesPerFrame = maxChannels * sizeof(float);
- // Prevent overflow by limiting multiplicands.
- if (bytesPerFrame > maxBytesPerFrame || numFrames > (0x3FFFFFFF / maxBytesPerFrame)) {
- ALOGE("size overflow, numFrames = %d, frameSize = %zd", numFrames, bytesPerFrame);
- return OBOE_ERROR_OUT_OF_RANGE;
- }
- *sizeInBytes = numFrames * bytesPerFrame;
- return OBOE_OK;
-}
diff --git a/media/liboboe/src/utility/OboeUtilities.h b/media/liboboe/src/utility/OboeUtilities.h
deleted file mode 100644
index 4096e2a..0000000
--- a/media/liboboe/src/utility/OboeUtilities.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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 UTILITY_OBOE_UTILITIES_H
-#define UTILITY_OBOE_UTILITIES_H
-
-#include <stdint.h>
-#include <sys/types.h>
-
-#include <utils/Errors.h>
-#include <hardware/audio.h>
-
-#include "oboe/OboeDefinitions.h"
-
-/**
- * Convert an Oboe result into the closest matching Android status.
- */
-android::status_t OboeConvert_oboeToAndroidStatus(oboe_result_t result);
-
-/**
- * Convert an Android status into the closest matching Oboe result.
- */
-oboe_result_t OboeConvert_androidToOboeResult(android::status_t status);
-
-void OboeConvert_floatToPcm16(const float *source, int32_t numSamples, int16_t *destination);
-
-void OboeConvert_pcm16ToFloat(const int16_t *source, int32_t numSamples, float *destination);
-
-/**
- * Calculate the number of bytes and prevent numeric overflow.
- * @param numFrames frame count
- * @param bytesPerFrame size of a frame in bytes
- * @param sizeInBytes total size in bytes
- * @return OBOE_OK or negative error, eg. OBOE_ERROR_OUT_OF_RANGE
- */
-oboe_size_bytes_t OboeConvert_framesToBytes(oboe_size_frames_t numFrames,
- oboe_size_bytes_t bytesPerFrame,
- oboe_size_bytes_t *sizeInBytes);
-
-audio_format_t OboeConvert_oboeToAndroidDataFormat(oboe_audio_format_t oboe_format);
-
-oboe_audio_format_t OboeConvert_androidToOboeDataFormat(audio_format_t format);
-
-/**
- * @return the size of a sample of the given format in bytes or OBOE_ERROR_ILLEGAL_ARGUMENT
- */
-oboe_size_bytes_t OboeConvert_formatToSizeInBytes(oboe_audio_format_t format);
-
-#endif //UTILITY_OBOE_UTILITIES_H
diff --git a/media/liboboe/src/utility/README.md b/media/liboboe/src/utility/README.md
index 9db926a..0ac74ea 100644
--- a/media/liboboe/src/utility/README.md
+++ b/media/liboboe/src/utility/README.md
@@ -1,3 +1,3 @@
-The utility folder contains things that may be shared between the Oboe client and server.
-They might also be handy outside Oboe.
-They generally do not depend on Oboe functionality.
+The utility folder contains things that may be shared between the AAudio client and server.
+They might also be handy outside AAudio.
+They generally do not depend on AAudio functionality.