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/services/oboeservice/AAudioService.cpp b/services/oboeservice/AAudioService.cpp
new file mode 100644
index 0000000..dfa9753
--- /dev/null
+++ b/services/oboeservice/AAudioService.cpp
@@ -0,0 +1,170 @@
+/*
+ * Copyright (C) 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 "AAudioService"
+//#define LOG_NDEBUG 0
+#include <utils/Log.h>
+
+#include <time.h>
+#include <pthread.h>
+
+#include <aaudio/AAudioDefinitions.h>
+
+#include "HandleTracker.h"
+#include "IAAudioService.h"
+#include "AAudioServiceDefinitions.h"
+#include "AAudioService.h"
+#include "AAudioServiceStreamFakeHal.h"
+
+using namespace android;
+using namespace aaudio;
+
+typedef enum
+{
+ AAUDIO_HANDLE_TYPE_DUMMY1, // TODO remove DUMMYs
+ AAUDIO_HANDLE_TYPE_DUMMY2, // make server handles different than client
+ AAUDIO_HANDLE_TYPE_STREAM,
+ AAUDIO_HANDLE_TYPE_COUNT
+} aaudio_service_handle_type_t;
+static_assert(AAUDIO_HANDLE_TYPE_COUNT <= HANDLE_TRACKER_MAX_TYPES, "Too many handle types.");
+
+android::AAudioService::AAudioService()
+ : BnAAudioService() {
+}
+
+AAudioService::~AAudioService() {
+}
+
+aaudio_handle_t AAudioService::openStream(aaudio::AAudioStreamRequest &request,
+ aaudio::AAudioStreamConfiguration &configuration) {
+ AAudioServiceStreamBase *serviceStream = new AAudioServiceStreamFakeHal();
+ ALOGD("AAudioService::openStream(): created serviceStream = %p", serviceStream);
+ aaudio_result_t result = serviceStream->open(request, configuration);
+ if (result < 0) {
+ ALOGE("AAudioService::openStream(): open returned %d", result);
+ return result;
+ } else {
+ AAudioStream handle = mHandleTracker.put(AAUDIO_HANDLE_TYPE_STREAM, serviceStream);
+ ALOGD("AAudioService::openStream(): handle = 0x%08X", handle);
+ if (handle < 0) {
+ delete serviceStream;
+ }
+ return handle;
+ }
+}
+
+aaudio_result_t AAudioService::closeStream(aaudio_handle_t streamHandle) {
+ AAudioServiceStreamBase *serviceStream = (AAudioServiceStreamBase *)
+ mHandleTracker.remove(AAUDIO_HANDLE_TYPE_STREAM,
+ streamHandle);
+ ALOGD("AAudioService.closeStream(0x%08X)", streamHandle);
+ if (serviceStream != nullptr) {
+ ALOGD("AAudioService::closeStream(): deleting serviceStream = %p", serviceStream);
+ delete serviceStream;
+ return AAUDIO_OK;
+ }
+ return AAUDIO_ERROR_INVALID_HANDLE;
+}
+
+AAudioServiceStreamBase *AAudioService::convertHandleToServiceStream(
+ aaudio_handle_t streamHandle) const {
+ return (AAudioServiceStreamBase *) mHandleTracker.get(AAUDIO_HANDLE_TYPE_STREAM,
+ (aaudio_handle_t)streamHandle);
+}
+
+aaudio_result_t AAudioService::getStreamDescription(
+ aaudio_handle_t streamHandle,
+ aaudio::AudioEndpointParcelable &parcelable) {
+ AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
+ ALOGD("AAudioService::getStreamDescription(), serviceStream = %p", serviceStream);
+ if (serviceStream == nullptr) {
+ return AAUDIO_ERROR_INVALID_HANDLE;
+ }
+ return serviceStream->getDescription(parcelable);
+}
+
+aaudio_result_t AAudioService::startStream(aaudio_handle_t streamHandle) {
+ AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
+ ALOGD("AAudioService::startStream(), serviceStream = %p", serviceStream);
+ if (serviceStream == nullptr) {
+ return AAUDIO_ERROR_INVALID_HANDLE;
+ }
+ aaudio_result_t result = serviceStream->start();
+ return result;
+}
+
+aaudio_result_t AAudioService::pauseStream(aaudio_handle_t streamHandle) {
+ AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
+ ALOGD("AAudioService::pauseStream(), serviceStream = %p", serviceStream);
+ if (serviceStream == nullptr) {
+ return AAUDIO_ERROR_INVALID_HANDLE;
+ }
+ aaudio_result_t result = serviceStream->pause();
+ return result;
+}
+
+aaudio_result_t AAudioService::flushStream(aaudio_handle_t streamHandle) {
+ AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
+ ALOGD("AAudioService::flushStream(), serviceStream = %p", serviceStream);
+ if (serviceStream == nullptr) {
+ return AAUDIO_ERROR_INVALID_HANDLE;
+ }
+ return serviceStream->flush();
+}
+
+aaudio_result_t AAudioService::registerAudioThread(aaudio_handle_t streamHandle,
+ pid_t clientThreadId,
+ aaudio_nanoseconds_t periodNanoseconds) {
+ AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
+ ALOGD("AAudioService::registerAudioThread(), serviceStream = %p", serviceStream);
+ if (serviceStream == nullptr) {
+ ALOGE("AAudioService::registerAudioThread(), serviceStream == nullptr");
+ return AAUDIO_ERROR_INVALID_HANDLE;
+ }
+ if (serviceStream->getRegisteredThread() != AAudioServiceStreamBase::ILLEGAL_THREAD_ID) {
+ ALOGE("AAudioService::registerAudioThread(), thread already registered");
+ return AAUDIO_ERROR_INVALID_ORDER;
+ }
+ serviceStream->setRegisteredThread(clientThreadId);
+ // Boost client thread to SCHED_FIFO
+ struct sched_param sp;
+ memset(&sp, 0, sizeof(sp));
+ sp.sched_priority = 2; // TODO use 'requestPriority' function from frameworks/av/media/utils
+ int err = sched_setscheduler(clientThreadId, SCHED_FIFO, &sp);
+ if (err != 0){
+ ALOGE("AAudioService::sched_setscheduler() failed, errno = %d, priority = %d",
+ errno, sp.sched_priority);
+ return AAUDIO_ERROR_INTERNAL;
+ } else {
+ return AAUDIO_OK;
+ }
+}
+
+aaudio_result_t AAudioService::unregisterAudioThread(aaudio_handle_t streamHandle,
+ pid_t clientThreadId) {
+ AAudioServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
+ ALOGI("AAudioService::unregisterAudioThread(), serviceStream = %p", serviceStream);
+ if (serviceStream == nullptr) {
+ ALOGE("AAudioService::unregisterAudioThread(), serviceStream == nullptr");
+ return AAUDIO_ERROR_INVALID_HANDLE;
+ }
+ if (serviceStream->getRegisteredThread() != clientThreadId) {
+ ALOGE("AAudioService::unregisterAudioThread(), wrong thread");
+ return AAUDIO_ERROR_ILLEGAL_ARGUMENT;
+ }
+ serviceStream->setRegisteredThread(0);
+ return AAUDIO_OK;
+}
diff --git a/services/oboeservice/AAudioService.h b/services/oboeservice/AAudioService.h
new file mode 100644
index 0000000..e9625b2
--- /dev/null
+++ b/services/oboeservice/AAudioService.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 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 AAUDIO_AAUDIO_AUDIO_SERVICE_H
+#define AAUDIO_AAUDIO_AUDIO_SERVICE_H
+
+#include <time.h>
+#include <pthread.h>
+
+#include <binder/BinderService.h>
+
+#include <aaudio/AAudioDefinitions.h>
+#include <aaudio/AAudio.h>
+#include "utility/HandleTracker.h"
+#include "IAAudioService.h"
+#include "AAudioServiceStreamBase.h"
+
+namespace android {
+
+class AAudioService :
+ public BinderService<AAudioService>,
+ public BnAAudioService
+{
+ friend class BinderService<AAudioService>;
+
+public:
+ AAudioService();
+ virtual ~AAudioService();
+
+ static const char* getServiceName() { return "media.audio_aaudio"; }
+
+ virtual aaudio_handle_t openStream(aaudio::AAudioStreamRequest &request,
+ aaudio::AAudioStreamConfiguration &configuration);
+
+ virtual aaudio_result_t closeStream(aaudio_handle_t streamHandle);
+
+ virtual aaudio_result_t getStreamDescription(
+ aaudio_handle_t streamHandle,
+ aaudio::AudioEndpointParcelable &parcelable);
+
+ virtual aaudio_result_t startStream(aaudio_handle_t streamHandle);
+
+ virtual aaudio_result_t pauseStream(aaudio_handle_t streamHandle);
+
+ virtual aaudio_result_t flushStream(aaudio_handle_t streamHandle);
+
+ virtual aaudio_result_t registerAudioThread(aaudio_handle_t streamHandle,
+ pid_t pid, aaudio_nanoseconds_t periodNanoseconds) ;
+
+ virtual aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle, pid_t pid);
+
+private:
+
+ aaudio::AAudioServiceStreamBase *convertHandleToServiceStream(aaudio_handle_t streamHandle) const;
+
+ HandleTracker mHandleTracker;
+
+};
+
+} /* namespace android */
+
+#endif //AAUDIO_AAUDIO_AUDIO_SERVICE_H
diff --git a/services/oboeservice/AAudioServiceDefinitions.h b/services/oboeservice/AAudioServiceDefinitions.h
new file mode 100644
index 0000000..ee9aaa7
--- /dev/null
+++ b/services/oboeservice/AAudioServiceDefinitions.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 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 AAUDIO_AAUDIO_SERVICE_H
+#define AAUDIO_AAUDIO_SERVICE_H
+
+#include <stdint.h>
+
+#include <aaudio/AAudio.h>
+
+#include "binding/RingBufferParcelable.h"
+
+namespace aaudio {
+
+// TODO move this an "include" folder for the service.
+
+struct AAudioMessageTimestamp {
+ aaudio_position_frames_t position;
+ int64_t deviceOffset; // add to client position to get device position
+ aaudio_nanoseconds_t timestamp;
+};
+
+typedef enum aaudio_service_event_e : uint32_t {
+ AAUDIO_SERVICE_EVENT_STARTED,
+ AAUDIO_SERVICE_EVENT_PAUSED,
+ AAUDIO_SERVICE_EVENT_FLUSHED,
+ AAUDIO_SERVICE_EVENT_CLOSED,
+ AAUDIO_SERVICE_EVENT_DISCONNECTED
+} aaudio_service_event_t;
+
+struct AAudioMessageEvent {
+ aaudio_service_event_t event;
+ int32_t data1;
+ int64_t data2;
+};
+
+typedef struct AAudioServiceMessage_s {
+ enum class code : uint32_t {
+ NOTHING,
+ TIMESTAMP,
+ EVENT,
+ };
+
+ code what;
+ union {
+ AAudioMessageTimestamp timestamp;
+ AAudioMessageEvent event;
+ };
+} AAudioServiceMessage;
+
+
+} /* namespace aaudio */
+
+#endif //AAUDIO_AAUDIO_SERVICE_H
diff --git a/services/oboeservice/OboeServiceMain.cpp b/services/oboeservice/AAudioServiceMain.cpp
similarity index 67%
rename from services/oboeservice/OboeServiceMain.cpp
rename to services/oboeservice/AAudioServiceMain.cpp
index 18bcf2b..aa89180 100644
--- a/services/oboeservice/OboeServiceMain.cpp
+++ b/services/oboeservice/AAudioServiceMain.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_TAG "OboeService"
+#define LOG_TAG "AAudioService"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
@@ -33,26 +33,26 @@
#include <cutils/ashmem.h>
#include <sys/mman.h>
-#include "OboeService.h"
-#include "IOboeAudioService.h"
-#include "OboeAudioService.h"
+#include "AAudioServiceDefinitions.h"
+#include "IAAudioService.h"
+#include "AAudioService.h"
using namespace android;
-using namespace oboe;
+using namespace aaudio;
/**
- * This is used to test the OboeService as a standalone application.
- * It is not used when the OboeService is integrated with AudioFlinger.
+ * This is used to test the AAudioService as a standalone application.
+ * It is not used when the AAudioService is integrated with AudioFlinger.
*/
int main(int argc, char **argv) {
- printf("Test OboeService %s\n", argv[1]);
- ALOGD("This is the OboeAudioService");
+ printf("Test AAudioService %s\n", argv[1]);
+ ALOGD("This is the AAudioService");
- defaultServiceManager()->addService(String16("OboeAudioService"), new OboeAudioService());
+ defaultServiceManager()->addService(String16("AAudioService"), new AAudioService());
android::ProcessState::self()->startThreadPool();
- printf("OboeAudioService service is now ready\n");
+ printf("AAudioService service is now ready\n");
IPCThreadState::self()->joinThreadPool();
- printf("OboeAudioService service thread joined\n");
+ printf("AAudioService service thread joined\n");
return 0;
}
diff --git a/services/oboeservice/OboeServiceStreamBase.cpp b/services/oboeservice/AAudioServiceStreamBase.cpp
similarity index 72%
rename from services/oboeservice/OboeServiceStreamBase.cpp
rename to services/oboeservice/AAudioServiceStreamBase.cpp
index 15b70a5..a7938dc 100644
--- a/services/oboeservice/OboeServiceStreamBase.cpp
+++ b/services/oboeservice/AAudioServiceStreamBase.cpp
@@ -14,43 +14,43 @@
* limitations under the License.
*/
-#define LOG_TAG "OboeService"
+#define LOG_TAG "AAudioService"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
-#include "IOboeAudioService.h"
-#include "OboeService.h"
-#include "OboeServiceStreamBase.h"
+#include "IAAudioService.h"
+#include "AAudioServiceDefinitions.h"
+#include "AAudioServiceStreamBase.h"
#include "AudioEndpointParcelable.h"
using namespace android;
-using namespace oboe;
+using namespace aaudio;
/**
* Construct the AudioCommandQueues and the AudioDataQueue
* and fill in the endpoint parcelable.
*/
-OboeServiceStreamBase::OboeServiceStreamBase()
+AAudioServiceStreamBase::AAudioServiceStreamBase()
: mUpMessageQueue(nullptr)
{
// TODO could fail so move out of constructor
mUpMessageQueue = new SharedRingBuffer();
- mUpMessageQueue->allocate(sizeof(OboeServiceMessage), QUEUE_UP_CAPACITY_COMMANDS);
+ mUpMessageQueue->allocate(sizeof(AAudioServiceMessage), QUEUE_UP_CAPACITY_COMMANDS);
}
-OboeServiceStreamBase::~OboeServiceStreamBase() {
+AAudioServiceStreamBase::~AAudioServiceStreamBase() {
Mutex::Autolock _l(mLockUpMessageQueue);
delete mUpMessageQueue;
}
-void OboeServiceStreamBase::sendServiceEvent(oboe_service_event_t event,
+void AAudioServiceStreamBase::sendServiceEvent(aaudio_service_event_t event,
int32_t data1,
int64_t data2) {
Mutex::Autolock _l(mLockUpMessageQueue);
- OboeServiceMessage command;
- command.what = OboeServiceMessage::code::EVENT;
+ AAudioServiceMessage command;
+ command.what = AAudioServiceMessage::code::EVENT;
command.event.event = event;
command.event.data1 = data1;
command.event.data2 = data2;
diff --git a/services/oboeservice/OboeServiceStreamBase.h b/services/oboeservice/AAudioServiceStreamBase.h
similarity index 61%
rename from services/oboeservice/OboeServiceStreamBase.h
rename to services/oboeservice/AAudioServiceStreamBase.h
index 33857c6..4a59253 100644
--- a/services/oboeservice/OboeServiceStreamBase.h
+++ b/services/oboeservice/AAudioServiceStreamBase.h
@@ -14,29 +14,29 @@
* limitations under the License.
*/
-#ifndef OBOE_OBOE_SERVICE_STREAM_BASE_H
-#define OBOE_OBOE_SERVICE_STREAM_BASE_H
+#ifndef AAUDIO_AAUDIO_SERVICE_STREAM_BASE_H
+#define AAUDIO_AAUDIO_SERVICE_STREAM_BASE_H
#include <utils/Mutex.h>
-#include "IOboeAudioService.h"
-#include "OboeService.h"
+#include "IAAudioService.h"
+#include "AAudioServiceDefinitions.h"
#include "fifo/FifoBuffer.h"
#include "SharedRingBuffer.h"
#include "AudioEndpointParcelable.h"
-#include "OboeThread.h"
+#include "AAudioThread.h"
-namespace oboe {
+namespace aaudio {
// We expect the queue to only have a few commands.
// This should be way more than we need.
#define QUEUE_UP_CAPACITY_COMMANDS (128)
-class OboeServiceStreamBase {
+class AAudioServiceStreamBase {
public:
- OboeServiceStreamBase();
- virtual ~OboeServiceStreamBase();
+ AAudioServiceStreamBase();
+ virtual ~AAudioServiceStreamBase();
enum {
ILLEGAL_THREAD_ID = 0
@@ -45,38 +45,38 @@
/**
* Fill in a parcelable description of stream.
*/
- virtual oboe_result_t getDescription(oboe::AudioEndpointParcelable &parcelable) = 0;
+ virtual aaudio_result_t getDescription(aaudio::AudioEndpointParcelable &parcelable) = 0;
/**
* Open the device.
*/
- virtual oboe_result_t open(oboe::OboeStreamRequest &request,
- oboe::OboeStreamConfiguration &configuration) = 0;
+ virtual aaudio_result_t open(aaudio::AAudioStreamRequest &request,
+ aaudio::AAudioStreamConfiguration &configuration) = 0;
/**
* Start the flow of data.
*/
- virtual oboe_result_t start() = 0;
+ virtual aaudio_result_t start() = 0;
/**
* Stop the flow of data such that start() can resume with loss of data.
*/
- virtual oboe_result_t pause() = 0;
+ virtual aaudio_result_t pause() = 0;
/**
* Discard any data held by the underlying HAL or Service.
*/
- virtual oboe_result_t flush() = 0;
+ virtual aaudio_result_t flush() = 0;
- virtual oboe_result_t close() = 0;
+ virtual aaudio_result_t close() = 0;
virtual void sendCurrentTimestamp() = 0;
- oboe_size_frames_t getFramesPerBurst() {
+ aaudio_size_frames_t getFramesPerBurst() {
return mFramesPerBurst;
}
- virtual void sendServiceEvent(oboe_service_event_t event,
+ virtual void sendServiceEvent(aaudio_service_event_t event,
int32_t data1 = 0,
int64_t data2 = 0);
@@ -94,15 +94,15 @@
SharedRingBuffer * mUpMessageQueue;
- oboe_sample_rate_t mSampleRate = 0;
- oboe_size_bytes_t mBytesPerFrame = 0;
- oboe_size_frames_t mFramesPerBurst = 0;
- oboe_size_frames_t mCapacityInFrames = 0;
- oboe_size_bytes_t mCapacityInBytes = 0;
+ aaudio_sample_rate_t mSampleRate = 0;
+ aaudio_size_bytes_t mBytesPerFrame = 0;
+ aaudio_size_frames_t mFramesPerBurst = 0;
+ aaudio_size_frames_t mCapacityInFrames = 0;
+ aaudio_size_bytes_t mCapacityInBytes = 0;
android::Mutex mLockUpMessageQueue;
};
-} /* namespace oboe */
+} /* namespace aaudio */
-#endif //OBOE_OBOE_SERVICE_STREAM_BASE_H
+#endif //AAUDIO_AAUDIO_SERVICE_STREAM_BASE_H
diff --git a/services/oboeservice/OboeServiceStreamFakeHal.cpp b/services/oboeservice/AAudioServiceStreamFakeHal.cpp
similarity index 63%
rename from services/oboeservice/OboeServiceStreamFakeHal.cpp
rename to services/oboeservice/AAudioServiceStreamFakeHal.cpp
index da4099d..627a504 100644
--- a/services/oboeservice/OboeServiceStreamFakeHal.cpp
+++ b/services/oboeservice/AAudioServiceStreamFakeHal.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#define LOG_TAG "OboeService"
+#define LOG_TAG "AAudioService"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
@@ -23,13 +23,13 @@
#include "AudioClock.h"
#include "AudioEndpointParcelable.h"
-#include "OboeServiceStreamBase.h"
-#include "OboeServiceStreamFakeHal.h"
+#include "AAudioServiceStreamBase.h"
+#include "AAudioServiceStreamFakeHal.h"
#include "FakeAudioHal.h"
using namespace android;
-using namespace oboe;
+using namespace aaudio;
// HACK values for Marlin
#define CARD_ID 0
@@ -39,24 +39,24 @@
* Construct the audio message queuues and message queues.
*/
-OboeServiceStreamFakeHal::OboeServiceStreamFakeHal()
- : OboeServiceStreamBase()
+AAudioServiceStreamFakeHal::AAudioServiceStreamFakeHal()
+ : AAudioServiceStreamBase()
, mStreamId(nullptr)
, mPreviousFrameCounter(0)
- , mOboeThread()
+ , mAAudioThread()
{
}
-OboeServiceStreamFakeHal::~OboeServiceStreamFakeHal() {
- ALOGD("OboeServiceStreamFakeHal::~OboeServiceStreamFakeHal() call close()");
+AAudioServiceStreamFakeHal::~AAudioServiceStreamFakeHal() {
+ ALOGD("AAudioServiceStreamFakeHal::~AAudioServiceStreamFakeHal() call close()");
close();
}
-oboe_result_t OboeServiceStreamFakeHal::open(oboe::OboeStreamRequest &request,
- oboe::OboeStreamConfiguration &configuration) {
+aaudio_result_t AAudioServiceStreamFakeHal::open(aaudio::AAudioStreamRequest &request,
+ aaudio::AAudioStreamConfiguration &configuration) {
// Open stream on HAL and pass information about the ring buffer to the client.
mmap_buffer_info mmapInfo;
- oboe_result_t error;
+ aaudio_result_t error;
// Open HAL
error = fake_hal_open(CARD_ID, DEVICE_ID, &mStreamId);
@@ -79,26 +79,26 @@
mCapacityInBytes = mmapInfo.buffer_capacity_in_bytes;
mSampleRate = mmapInfo.sample_rate;
mBytesPerFrame = mmapInfo.channel_count * sizeof(int16_t); // FIXME based on data format
- ALOGD("OboeServiceStreamFakeHal::open() mmapInfo.burst_size_in_frames = %d",
+ ALOGD("AAudioServiceStreamFakeHal::open() mmapInfo.burst_size_in_frames = %d",
mmapInfo.burst_size_in_frames);
- ALOGD("OboeServiceStreamFakeHal::open() mmapInfo.buffer_capacity_in_frames = %d",
+ ALOGD("AAudioServiceStreamFakeHal::open() mmapInfo.buffer_capacity_in_frames = %d",
mmapInfo.buffer_capacity_in_frames);
- ALOGD("OboeServiceStreamFakeHal::open() mmapInfo.buffer_capacity_in_bytes = %d",
+ ALOGD("AAudioServiceStreamFakeHal::open() mmapInfo.buffer_capacity_in_bytes = %d",
mmapInfo.buffer_capacity_in_bytes);
- // Fill in OboeStreamConfiguration
+ // Fill in AAudioStreamConfiguration
configuration.setSampleRate(mSampleRate);
configuration.setSamplesPerFrame(mmapInfo.channel_count);
- configuration.setAudioFormat(OBOE_AUDIO_FORMAT_PCM_I16);
+ configuration.setAudioFormat(AAUDIO_FORMAT_PCM_I16);
- return OBOE_OK;
+ return AAUDIO_OK;
}
/**
* Get an immutable description of the in-memory queues
* used to communicate with the underlying HAL or Service.
*/
-oboe_result_t OboeServiceStreamFakeHal::getDescription(AudioEndpointParcelable &parcelable) {
+aaudio_result_t AAudioServiceStreamFakeHal::getDescription(AudioEndpointParcelable &parcelable) {
// Gather information on the message queue.
mUpMessageQueue->fillParcelable(parcelable,
parcelable.mUpMessageQueueParcelable);
@@ -110,20 +110,20 @@
parcelable.mDownDataQueueParcelable.setBytesPerFrame(mBytesPerFrame);
parcelable.mDownDataQueueParcelable.setFramesPerBurst(mFramesPerBurst);
parcelable.mDownDataQueueParcelable.setCapacityInFrames(mCapacityInFrames);
- return OBOE_OK;
+ return AAUDIO_OK;
}
/**
* Start the flow of data.
*/
-oboe_result_t OboeServiceStreamFakeHal::start() {
- if (mStreamId == nullptr) return OBOE_ERROR_NULL;
- oboe_result_t result = fake_hal_start(mStreamId);
- sendServiceEvent(OBOE_SERVICE_EVENT_STARTED);
- mState = OBOE_STREAM_STATE_STARTED;
- if (result == OBOE_OK) {
+aaudio_result_t AAudioServiceStreamFakeHal::start() {
+ if (mStreamId == nullptr) return AAUDIO_ERROR_NULL;
+ aaudio_result_t result = fake_hal_start(mStreamId);
+ sendServiceEvent(AAUDIO_SERVICE_EVENT_STARTED);
+ mState = AAUDIO_STREAM_STATE_STARTED;
+ if (result == AAUDIO_OK) {
mThreadEnabled.store(true);
- result = mOboeThread.start(this);
+ result = mAAudioThread.start(this);
}
return result;
}
@@ -131,33 +131,33 @@
/**
* Stop the flow of data such that start() can resume with loss of data.
*/
-oboe_result_t OboeServiceStreamFakeHal::pause() {
- if (mStreamId == nullptr) return OBOE_ERROR_NULL;
+aaudio_result_t AAudioServiceStreamFakeHal::pause() {
+ if (mStreamId == nullptr) return AAUDIO_ERROR_NULL;
sendCurrentTimestamp();
- oboe_result_t result = fake_hal_pause(mStreamId);
- sendServiceEvent(OBOE_SERVICE_EVENT_PAUSED);
- mState = OBOE_STREAM_STATE_PAUSED;
+ aaudio_result_t result = fake_hal_pause(mStreamId);
+ sendServiceEvent(AAUDIO_SERVICE_EVENT_PAUSED);
+ mState = AAUDIO_STREAM_STATE_PAUSED;
mFramesRead.reset32();
- ALOGD("OboeServiceStreamFakeHal::pause() sent OBOE_SERVICE_EVENT_PAUSED");
+ ALOGD("AAudioServiceStreamFakeHal::pause() sent AAUDIO_SERVICE_EVENT_PAUSED");
mThreadEnabled.store(false);
- result = mOboeThread.stop();
+ result = mAAudioThread.stop();
return result;
}
/**
* Discard any data held by the underlying HAL or Service.
*/
-oboe_result_t OboeServiceStreamFakeHal::flush() {
- if (mStreamId == nullptr) return OBOE_ERROR_NULL;
+aaudio_result_t AAudioServiceStreamFakeHal::flush() {
+ if (mStreamId == nullptr) return AAUDIO_ERROR_NULL;
// TODO how do we flush an MMAP/NOIRQ buffer? sync pointers?
- ALOGD("OboeServiceStreamFakeHal::pause() send OBOE_SERVICE_EVENT_FLUSHED");
- sendServiceEvent(OBOE_SERVICE_EVENT_FLUSHED);
- mState = OBOE_STREAM_STATE_FLUSHED;
- return OBOE_OK;
+ ALOGD("AAudioServiceStreamFakeHal::pause() send AAUDIO_SERVICE_EVENT_FLUSHED");
+ sendServiceEvent(AAUDIO_SERVICE_EVENT_FLUSHED);
+ mState = AAUDIO_STREAM_STATE_FLUSHED;
+ return AAUDIO_OK;
}
-oboe_result_t OboeServiceStreamFakeHal::close() {
- oboe_result_t result = OBOE_OK;
+aaudio_result_t AAudioServiceStreamFakeHal::close() {
+ aaudio_result_t result = AAUDIO_OK;
if (mStreamId != nullptr) {
result = fake_hal_close(mStreamId);
mStreamId = nullptr;
@@ -165,18 +165,18 @@
return result;
}
-void OboeServiceStreamFakeHal::sendCurrentTimestamp() {
+void AAudioServiceStreamFakeHal::sendCurrentTimestamp() {
int frameCounter = 0;
int error = fake_hal_get_frame_counter(mStreamId, &frameCounter);
if (error < 0) {
- ALOGE("OboeServiceStreamFakeHal::sendCurrentTimestamp() error %d",
+ ALOGE("AAudioServiceStreamFakeHal::sendCurrentTimestamp() error %d",
error);
} else if (frameCounter != mPreviousFrameCounter) {
- OboeServiceMessage command;
- command.what = OboeServiceMessage::code::TIMESTAMP;
+ AAudioServiceMessage command;
+ command.what = AAudioServiceMessage::code::TIMESTAMP;
mFramesRead.update32(frameCounter);
command.timestamp.position = mFramesRead.get();
- ALOGD("OboeServiceStreamFakeHal::sendCurrentTimestamp() HAL frames = %d, pos = %d",
+ ALOGD("AAudioServiceStreamFakeHal::sendCurrentTimestamp() HAL frames = %d, pos = %d",
frameCounter, (int)mFramesRead.get());
command.timestamp.timestamp = AudioClock::getNanoseconds();
mUpMessageQueue->getFifoBuffer()->write(&command, 1);
@@ -185,12 +185,12 @@
}
// implement Runnable
-void OboeServiceStreamFakeHal::run() {
+void AAudioServiceStreamFakeHal::run() {
TimestampScheduler timestampScheduler;
timestampScheduler.setBurstPeriod(mFramesPerBurst, mSampleRate);
timestampScheduler.start(AudioClock::getNanoseconds());
while(mThreadEnabled.load()) {
- oboe_nanoseconds_t nextTime = timestampScheduler.nextAbsoluteTime();
+ aaudio_nanoseconds_t nextTime = timestampScheduler.nextAbsoluteTime();
if (AudioClock::getNanoseconds() >= nextTime) {
sendCurrentTimestamp();
} else {
diff --git a/services/oboeservice/AAudioServiceStreamFakeHal.h b/services/oboeservice/AAudioServiceStreamFakeHal.h
new file mode 100644
index 0000000..170d0ee
--- /dev/null
+++ b/services/oboeservice/AAudioServiceStreamFakeHal.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 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 AAUDIO_AAUDIO_SERVICE_STREAM_FAKE_HAL_H
+#define AAUDIO_AAUDIO_SERVICE_STREAM_FAKE_HAL_H
+
+#include "AAudioServiceDefinitions.h"
+#include "AAudioServiceStreamBase.h"
+#include "FakeAudioHal.h"
+#include "MonotonicCounter.h"
+#include "AudioEndpointParcelable.h"
+#include "TimestampScheduler.h"
+
+namespace aaudio {
+
+class AAudioServiceStreamFakeHal
+ : public AAudioServiceStreamBase
+ , public Runnable {
+
+public:
+ AAudioServiceStreamFakeHal();
+ virtual ~AAudioServiceStreamFakeHal();
+
+ virtual aaudio_result_t getDescription(AudioEndpointParcelable &parcelable) override;
+
+ virtual aaudio_result_t open(aaudio::AAudioStreamRequest &request,
+ aaudio::AAudioStreamConfiguration &configuration) override;
+
+ /**
+ * Start the flow of data.
+ */
+ virtual aaudio_result_t start() override;
+
+ /**
+ * Stop the flow of data such that start() can resume with loss of data.
+ */
+ virtual aaudio_result_t pause() override;
+
+ /**
+ * Discard any data held by the underlying HAL or Service.
+ */
+ virtual aaudio_result_t flush() override;
+
+ virtual aaudio_result_t close() override;
+
+ void sendCurrentTimestamp();
+
+ virtual void run() override; // to implement Runnable
+
+private:
+ fake_hal_stream_ptr mStreamId; // Move to HAL
+
+ MonotonicCounter mFramesWritten;
+ MonotonicCounter mFramesRead;
+ int mHalFileDescriptor = -1;
+ int mPreviousFrameCounter = 0; // from HAL
+
+ aaudio_stream_state_t mState = AAUDIO_STREAM_STATE_UNINITIALIZED;
+
+ AAudioThread mAAudioThread;
+ std::atomic<bool> mThreadEnabled;
+};
+
+} // namespace aaudio
+
+#endif //AAUDIO_AAUDIO_SERVICE_STREAM_FAKE_HAL_H
diff --git a/services/oboeservice/AAudioThread.cpp b/services/oboeservice/AAudioThread.cpp
new file mode 100644
index 0000000..f5e5784
--- /dev/null
+++ b/services/oboeservice/AAudioThread.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 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 "AAudioService"
+//#define LOG_NDEBUG 0
+#include <utils/Log.h>
+
+#include <pthread.h>
+
+#include <aaudio/AAudioDefinitions.h>
+
+#include "AAudioThread.h"
+
+using namespace aaudio;
+
+
+AAudioThread::AAudioThread() {
+ // mThread is a pthread_t of unknown size so we need memset.
+ memset(&mThread, 0, sizeof(mThread));
+}
+
+void AAudioThread::dispatch() {
+ if (mRunnable != nullptr) {
+ mRunnable->run();
+ } else {
+ run();
+ }
+}
+
+// This is the entry point for the new thread created by createThread().
+// It converts the 'C' function call to a C++ method call.
+static void * AAudioThread_internalThreadProc(void *arg) {
+ AAudioThread *aaudioThread = (AAudioThread *) arg;
+ aaudioThread->dispatch();
+ return nullptr;
+}
+
+aaudio_result_t AAudioThread::start(Runnable *runnable) {
+ if (mHasThread) {
+ return AAUDIO_ERROR_INVALID_STATE;
+ }
+ mRunnable = runnable; // TODO use atomic?
+ int err = pthread_create(&mThread, nullptr, AAudioThread_internalThreadProc, this);
+ if (err != 0) {
+ ALOGE("AAudioThread::pthread_create() returned %d", err);
+ // TODO convert errno to aaudio_result_t
+ return AAUDIO_ERROR_INTERNAL;
+ } else {
+ mHasThread = true;
+ return AAUDIO_OK;
+ }
+}
+
+aaudio_result_t AAudioThread::stop() {
+ if (!mHasThread) {
+ return AAUDIO_ERROR_INVALID_STATE;
+ }
+ int err = pthread_join(mThread, nullptr);
+ mHasThread = false;
+ // TODO convert errno to aaudio_result_t
+ return err ? AAUDIO_ERROR_INTERNAL : AAUDIO_OK;
+}
+
diff --git a/services/oboeservice/OboeThread.h b/services/oboeservice/AAudioThread.h
similarity index 79%
rename from services/oboeservice/OboeThread.h
rename to services/oboeservice/AAudioThread.h
index 48fafc7..1f676dc 100644
--- a/services/oboeservice/OboeThread.h
+++ b/services/oboeservice/AAudioThread.h
@@ -14,15 +14,15 @@
* limitations under the License.
*/
-#ifndef OBOE_THREAD_H
-#define OBOE_THREAD_H
+#ifndef AAUDIO_THREAD_H
+#define AAUDIO_THREAD_H
#include <atomic>
#include <pthread.h>
-#include <oboe/OboeDefinitions.h>
+#include <aaudio/AAudioDefinitions.h>
-namespace oboe {
+namespace aaudio {
class Runnable {
public:
@@ -35,23 +35,23 @@
/**
* Abstraction for a host thread.
*/
-class OboeThread
+class AAudioThread
{
public:
- OboeThread();
- OboeThread(Runnable *runnable);
- virtual ~OboeThread() = default;
+ AAudioThread();
+ AAudioThread(Runnable *runnable);
+ virtual ~AAudioThread() = default;
/**
* Start the thread running.
*/
- oboe_result_t start(Runnable *runnable = nullptr);
+ aaudio_result_t start(Runnable *runnable = nullptr);
/**
* Join the thread.
* The caller must somehow tell the thread to exit before calling join().
*/
- oboe_result_t stop();
+ aaudio_result_t stop();
/**
* This will get called in the thread.
@@ -68,6 +68,6 @@
};
-} /* namespace oboe */
+} /* namespace aaudio */
-#endif ///OBOE_THREAD_H
+#endif ///AAUDIO_THREAD_H
diff --git a/services/oboeservice/Android.mk b/services/oboeservice/Android.mk
index 5a79b80..68e43ed 100644
--- a/services/oboeservice/Android.mk
+++ b/services/oboeservice/Android.mk
@@ -1,13 +1,13 @@
LOCAL_PATH:= $(call my-dir)
-# Oboe Service
+# AAudio Service
include $(CLEAR_VARS)
LOCAL_MODULE := oboeservice
LOCAL_MODULE_TAGS := optional
-LIBOBOE_DIR := ../../media/liboboe
-LIBOBOE_SRC_DIR := $(LIBOBOE_DIR)/src
+LIBAAUDIO_DIR := ../../media/liboboe
+LIBAAUDIO_SRC_DIR := $(LIBAAUDIO_DIR)/src
LOCAL_C_INCLUDES := \
$(call include-path-for, audio-utils) \
@@ -26,25 +26,25 @@
# TODO These could be in a liboboe_common library
LOCAL_SRC_FILES += \
- $(LIBOBOE_SRC_DIR)/utility/HandleTracker.cpp \
- $(LIBOBOE_SRC_DIR)/utility/OboeUtilities.cpp \
- $(LIBOBOE_SRC_DIR)/fifo/FifoBuffer.cpp \
- $(LIBOBOE_SRC_DIR)/fifo/FifoControllerBase.cpp \
- $(LIBOBOE_SRC_DIR)/binding/SharedMemoryParcelable.cpp \
- $(LIBOBOE_SRC_DIR)/binding/SharedRegionParcelable.cpp \
- $(LIBOBOE_SRC_DIR)/binding/RingBufferParcelable.cpp \
- $(LIBOBOE_SRC_DIR)/binding/AudioEndpointParcelable.cpp \
- $(LIBOBOE_SRC_DIR)/binding/OboeStreamRequest.cpp \
- $(LIBOBOE_SRC_DIR)/binding/OboeStreamConfiguration.cpp \
- $(LIBOBOE_SRC_DIR)/binding/IOboeAudioService.cpp \
+ $(LIBAAUDIO_SRC_DIR)/utility/HandleTracker.cpp \
+ $(LIBAAUDIO_SRC_DIR)/utility/AAudioUtilities.cpp \
+ $(LIBAAUDIO_SRC_DIR)/fifo/FifoBuffer.cpp \
+ $(LIBAAUDIO_SRC_DIR)/fifo/FifoControllerBase.cpp \
+ $(LIBAAUDIO_SRC_DIR)/binding/SharedMemoryParcelable.cpp \
+ $(LIBAAUDIO_SRC_DIR)/binding/SharedRegionParcelable.cpp \
+ $(LIBAAUDIO_SRC_DIR)/binding/RingBufferParcelable.cpp \
+ $(LIBAAUDIO_SRC_DIR)/binding/AudioEndpointParcelable.cpp \
+ $(LIBAAUDIO_SRC_DIR)/binding/AAudioStreamRequest.cpp \
+ $(LIBAAUDIO_SRC_DIR)/binding/AAudioStreamConfiguration.cpp \
+ $(LIBAAUDIO_SRC_DIR)/binding/IAAudioService.cpp \
SharedRingBuffer.cpp \
FakeAudioHal.cpp \
- OboeAudioService.cpp \
- OboeServiceStreamBase.cpp \
- OboeServiceStreamFakeHal.cpp \
+ AAudioService.cpp \
+ AAudioServiceStreamBase.cpp \
+ AAudioServiceStreamFakeHal.cpp \
TimestampScheduler.cpp \
- OboeServiceMain.cpp \
- OboeThread.cpp
+ AAudioServiceMain.cpp \
+ AAudioThread.cpp
LOCAL_CFLAGS += -Wno-unused-parameter
LOCAL_CFLAGS += -Wall -Werror
diff --git a/services/oboeservice/FakeAudioHal.cpp b/services/oboeservice/FakeAudioHal.cpp
index 7fa2eef..cf0dc86 100644
--- a/services/oboeservice/FakeAudioHal.cpp
+++ b/services/oboeservice/FakeAudioHal.cpp
@@ -32,7 +32,7 @@
#include "FakeAudioHal.h"
-//using namespace oboe;
+//using namespace aaudio;
using sample_t = int16_t;
using std::cout;
diff --git a/services/oboeservice/FakeAudioHal.h b/services/oboeservice/FakeAudioHal.h
index d6f28b2..f47ccd9 100644
--- a/services/oboeservice/FakeAudioHal.h
+++ b/services/oboeservice/FakeAudioHal.h
@@ -21,7 +21,7 @@
#ifndef FAKE_AUDIO_HAL_H
#define FAKE_AUDIO_HAL_H
-//namespace oboe {
+//namespace aaudio {
using sample_t = int16_t;
struct mmap_buffer_info {
@@ -53,6 +53,6 @@
//} /* "C" */
-//} /* namespace oboe */
+//} /* namespace aaudio */
#endif // FAKE_AUDIO_HAL_H
diff --git a/services/oboeservice/OboeAudioService.cpp b/services/oboeservice/OboeAudioService.cpp
deleted file mode 100644
index 001569c..0000000
--- a/services/oboeservice/OboeAudioService.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (C) 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 "OboeService"
-//#define LOG_NDEBUG 0
-#include <utils/Log.h>
-
-#include <time.h>
-#include <pthread.h>
-
-#include <oboe/OboeDefinitions.h>
-
-#include "HandleTracker.h"
-#include "IOboeAudioService.h"
-#include "OboeService.h"
-#include "OboeAudioService.h"
-#include "OboeServiceStreamFakeHal.h"
-
-using namespace android;
-using namespace oboe;
-
-typedef enum
-{
- OBOE_HANDLE_TYPE_DUMMY1, // TODO remove DUMMYs
- OBOE_HANDLE_TYPE_DUMMY2, // make server handles different than client
- OBOE_HANDLE_TYPE_STREAM,
- OBOE_HANDLE_TYPE_COUNT
-} oboe_service_handle_type_t;
-static_assert(OBOE_HANDLE_TYPE_COUNT <= HANDLE_TRACKER_MAX_TYPES, "Too many handle types.");
-
-android::OboeAudioService::OboeAudioService()
- : BnOboeAudioService() {
-}
-
-OboeAudioService::~OboeAudioService() {
-}
-
-oboe_handle_t OboeAudioService::openStream(oboe::OboeStreamRequest &request,
- oboe::OboeStreamConfiguration &configuration) {
- OboeServiceStreamBase *serviceStream = new OboeServiceStreamFakeHal();
- ALOGD("OboeAudioService::openStream(): created serviceStream = %p", serviceStream);
- oboe_result_t result = serviceStream->open(request, configuration);
- if (result < 0) {
- ALOGE("OboeAudioService::openStream(): open returned %d", result);
- return result;
- } else {
- OboeStream handle = mHandleTracker.put(OBOE_HANDLE_TYPE_STREAM, serviceStream);
- ALOGD("OboeAudioService::openStream(): handle = 0x%08X", handle);
- if (handle < 0) {
- delete serviceStream;
- }
- return handle;
- }
-}
-
-oboe_result_t OboeAudioService::closeStream(oboe_handle_t streamHandle) {
- OboeServiceStreamBase *serviceStream = (OboeServiceStreamBase *)
- mHandleTracker.remove(OBOE_HANDLE_TYPE_STREAM,
- streamHandle);
- ALOGD("OboeAudioService.closeStream(0x%08X)", streamHandle);
- if (serviceStream != nullptr) {
- ALOGD("OboeAudioService::closeStream(): deleting serviceStream = %p", serviceStream);
- delete serviceStream;
- return OBOE_OK;
- }
- return OBOE_ERROR_INVALID_HANDLE;
-}
-
-OboeServiceStreamBase *OboeAudioService::convertHandleToServiceStream(
- oboe_handle_t streamHandle) const {
- return (OboeServiceStreamBase *) mHandleTracker.get(OBOE_HANDLE_TYPE_STREAM,
- (oboe_handle_t)streamHandle);
-}
-
-oboe_result_t OboeAudioService::getStreamDescription(
- oboe_handle_t streamHandle,
- oboe::AudioEndpointParcelable &parcelable) {
- OboeServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
- ALOGD("OboeAudioService::getStreamDescription(), serviceStream = %p", serviceStream);
- if (serviceStream == nullptr) {
- return OBOE_ERROR_INVALID_HANDLE;
- }
- return serviceStream->getDescription(parcelable);
-}
-
-oboe_result_t OboeAudioService::startStream(oboe_handle_t streamHandle) {
- OboeServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
- ALOGD("OboeAudioService::startStream(), serviceStream = %p", serviceStream);
- if (serviceStream == nullptr) {
- return OBOE_ERROR_INVALID_HANDLE;
- }
- oboe_result_t result = serviceStream->start();
- return result;
-}
-
-oboe_result_t OboeAudioService::pauseStream(oboe_handle_t streamHandle) {
- OboeServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
- ALOGD("OboeAudioService::pauseStream(), serviceStream = %p", serviceStream);
- if (serviceStream == nullptr) {
- return OBOE_ERROR_INVALID_HANDLE;
- }
- oboe_result_t result = serviceStream->pause();
- return result;
-}
-
-oboe_result_t OboeAudioService::flushStream(oboe_handle_t streamHandle) {
- OboeServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
- ALOGD("OboeAudioService::flushStream(), serviceStream = %p", serviceStream);
- if (serviceStream == nullptr) {
- return OBOE_ERROR_INVALID_HANDLE;
- }
- return serviceStream->flush();
-}
-
-oboe_result_t OboeAudioService::registerAudioThread(oboe_handle_t streamHandle,
- pid_t clientThreadId,
- oboe_nanoseconds_t periodNanoseconds) {
- OboeServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
- ALOGD("OboeAudioService::registerAudioThread(), serviceStream = %p", serviceStream);
- if (serviceStream == nullptr) {
- ALOGE("OboeAudioService::registerAudioThread(), serviceStream == nullptr");
- return OBOE_ERROR_INVALID_HANDLE;
- }
- if (serviceStream->getRegisteredThread() != OboeServiceStreamBase::ILLEGAL_THREAD_ID) {
- ALOGE("OboeAudioService::registerAudioThread(), thread already registered");
- return OBOE_ERROR_INVALID_ORDER;
- }
- serviceStream->setRegisteredThread(clientThreadId);
- // Boost client thread to SCHED_FIFO
- struct sched_param sp;
- memset(&sp, 0, sizeof(sp));
- sp.sched_priority = 2; // TODO use 'requestPriority' function from frameworks/av/media/utils
- int err = sched_setscheduler(clientThreadId, SCHED_FIFO, &sp);
- if (err != 0){
- ALOGE("OboeAudioService::sched_setscheduler() failed, errno = %d, priority = %d",
- errno, sp.sched_priority);
- return OBOE_ERROR_INTERNAL;
- } else {
- return OBOE_OK;
- }
-}
-
-oboe_result_t OboeAudioService::unregisterAudioThread(oboe_handle_t streamHandle,
- pid_t clientThreadId) {
- OboeServiceStreamBase *serviceStream = convertHandleToServiceStream(streamHandle);
- ALOGI("OboeAudioService::unregisterAudioThread(), serviceStream = %p", serviceStream);
- if (serviceStream == nullptr) {
- ALOGE("OboeAudioService::unregisterAudioThread(), serviceStream == nullptr");
- return OBOE_ERROR_INVALID_HANDLE;
- }
- if (serviceStream->getRegisteredThread() != clientThreadId) {
- ALOGE("OboeAudioService::unregisterAudioThread(), wrong thread");
- return OBOE_ERROR_ILLEGAL_ARGUMENT;
- }
- serviceStream->setRegisteredThread(0);
- return OBOE_OK;
-}
diff --git a/services/oboeservice/OboeAudioService.h b/services/oboeservice/OboeAudioService.h
deleted file mode 100644
index b196f1d..0000000
--- a/services/oboeservice/OboeAudioService.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 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_OBOE_AUDIO_SERVICE_H
-#define OBOE_OBOE_AUDIO_SERVICE_H
-
-#include <time.h>
-#include <pthread.h>
-
-#include <binder/BinderService.h>
-
-#include <oboe/OboeDefinitions.h>
-#include <oboe/OboeAudio.h>
-#include "utility/HandleTracker.h"
-#include "IOboeAudioService.h"
-#include "OboeServiceStreamBase.h"
-
-namespace android {
-
-class OboeAudioService :
- public BinderService<OboeAudioService>,
- public BnOboeAudioService
-{
- friend class BinderService<OboeAudioService>;
-
-public:
- OboeAudioService();
- virtual ~OboeAudioService();
-
- static const char* getServiceName() { return "media.audio_oboe"; }
-
- virtual oboe_handle_t openStream(oboe::OboeStreamRequest &request,
- oboe::OboeStreamConfiguration &configuration);
-
- virtual oboe_result_t closeStream(oboe_handle_t streamHandle);
-
- virtual oboe_result_t getStreamDescription(
- oboe_handle_t streamHandle,
- oboe::AudioEndpointParcelable &parcelable);
-
- virtual oboe_result_t startStream(oboe_handle_t streamHandle);
-
- virtual oboe_result_t pauseStream(oboe_handle_t streamHandle);
-
- virtual oboe_result_t flushStream(oboe_handle_t streamHandle);
-
- virtual oboe_result_t registerAudioThread(oboe_handle_t streamHandle,
- pid_t pid, oboe_nanoseconds_t periodNanoseconds) ;
-
- virtual oboe_result_t unregisterAudioThread(oboe_handle_t streamHandle, pid_t pid);
-
-private:
-
- oboe::OboeServiceStreamBase *convertHandleToServiceStream(oboe_handle_t streamHandle) const;
-
- HandleTracker mHandleTracker;
-
-};
-
-} /* namespace android */
-
-#endif //OBOE_OBOE_AUDIO_SERVICE_H
diff --git a/services/oboeservice/OboeService.h b/services/oboeservice/OboeService.h
deleted file mode 100644
index a24f525..0000000
--- a/services/oboeservice/OboeService.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 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_OBOE_SERVICE_H
-#define OBOE_OBOE_SERVICE_H
-
-#include <stdint.h>
-
-#include <oboe/OboeAudio.h>
-
-#include "binding/RingBufferParcelable.h"
-
-namespace oboe {
-
-// TODO move this an "include" folder for the service.
-
-struct OboeMessageTimestamp {
- oboe_position_frames_t position;
- int64_t deviceOffset; // add to client position to get device position
- oboe_nanoseconds_t timestamp;
-};
-
-typedef enum oboe_service_event_e : uint32_t {
- OBOE_SERVICE_EVENT_STARTED,
- OBOE_SERVICE_EVENT_PAUSED,
- OBOE_SERVICE_EVENT_FLUSHED,
- OBOE_SERVICE_EVENT_CLOSED,
- OBOE_SERVICE_EVENT_DISCONNECTED
-} oboe_service_event_t;
-
-struct OboeMessageEvent {
- oboe_service_event_t event;
- int32_t data1;
- int64_t data2;
-};
-
-typedef struct OboeServiceMessage_s {
- enum class code : uint32_t {
- NOTHING,
- TIMESTAMP,
- EVENT,
- };
-
- code what;
- union {
- OboeMessageTimestamp timestamp;
- OboeMessageEvent event;
- };
-} OboeServiceMessage;
-
-
-} /* namespace oboe */
-
-#endif //OBOE_OBOE_SERVICE_H
diff --git a/services/oboeservice/OboeServiceStreamFakeHal.h b/services/oboeservice/OboeServiceStreamFakeHal.h
deleted file mode 100644
index 39b952a..0000000
--- a/services/oboeservice/OboeServiceStreamFakeHal.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 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_OBOE_SERVICE_STREAM_FAKE_HAL_H
-#define OBOE_OBOE_SERVICE_STREAM_FAKE_HAL_H
-
-#include "OboeService.h"
-#include "OboeServiceStreamBase.h"
-#include "FakeAudioHal.h"
-#include "MonotonicCounter.h"
-#include "AudioEndpointParcelable.h"
-#include "TimestampScheduler.h"
-
-namespace oboe {
-
-class OboeServiceStreamFakeHal
- : public OboeServiceStreamBase
- , public Runnable {
-
-public:
- OboeServiceStreamFakeHal();
- virtual ~OboeServiceStreamFakeHal();
-
- virtual oboe_result_t getDescription(AudioEndpointParcelable &parcelable) override;
-
- virtual oboe_result_t open(oboe::OboeStreamRequest &request,
- oboe::OboeStreamConfiguration &configuration) override;
-
- /**
- * Start the flow of data.
- */
- virtual oboe_result_t start() override;
-
- /**
- * Stop the flow of data such that start() can resume with loss of data.
- */
- virtual oboe_result_t pause() override;
-
- /**
- * Discard any data held by the underlying HAL or Service.
- */
- virtual oboe_result_t flush() override;
-
- virtual oboe_result_t close() override;
-
- void sendCurrentTimestamp();
-
- virtual void run() override; // to implement Runnable
-
-private:
- fake_hal_stream_ptr mStreamId; // Move to HAL
-
- MonotonicCounter mFramesWritten;
- MonotonicCounter mFramesRead;
- int mHalFileDescriptor = -1;
- int mPreviousFrameCounter = 0; // from HAL
-
- oboe_stream_state_t mState = OBOE_STREAM_STATE_UNINITIALIZED;
-
- OboeThread mOboeThread;
- std::atomic<bool> mThreadEnabled;
-};
-
-} // namespace oboe
-
-#endif //OBOE_OBOE_SERVICE_STREAM_FAKE_HAL_H
diff --git a/services/oboeservice/OboeThread.cpp b/services/oboeservice/OboeThread.cpp
deleted file mode 100644
index 9ecfa90..0000000
--- a/services/oboeservice/OboeThread.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright (C) 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 "OboeService"
-//#define LOG_NDEBUG 0
-#include <utils/Log.h>
-
-#include <pthread.h>
-
-#include <oboe/OboeDefinitions.h>
-
-#include "OboeThread.h"
-
-using namespace oboe;
-
-
-OboeThread::OboeThread() {
- // mThread is a pthread_t of unknown size so we need memset.
- memset(&mThread, 0, sizeof(mThread));
-}
-
-void OboeThread::dispatch() {
- if (mRunnable != nullptr) {
- mRunnable->run();
- } else {
- run();
- }
-}
-
-// This is the entry point for the new thread created by createThread().
-// It converts the 'C' function call to a C++ method call.
-static void * OboeThread_internalThreadProc(void *arg) {
- OboeThread *oboeThread = (OboeThread *) arg;
- oboeThread->dispatch();
- return nullptr;
-}
-
-oboe_result_t OboeThread::start(Runnable *runnable) {
- if (mHasThread) {
- return OBOE_ERROR_INVALID_STATE;
- }
- mRunnable = runnable; // TODO use atomic?
- int err = pthread_create(&mThread, nullptr, OboeThread_internalThreadProc, this);
- if (err != 0) {
- ALOGE("OboeThread::pthread_create() returned %d", err);
- // TODO convert errno to oboe_result_t
- return OBOE_ERROR_INTERNAL;
- } else {
- mHasThread = true;
- return OBOE_OK;
- }
-}
-
-oboe_result_t OboeThread::stop() {
- if (!mHasThread) {
- return OBOE_ERROR_INVALID_STATE;
- }
- int err = pthread_join(mThread, nullptr);
- mHasThread = false;
- // TODO convert errno to oboe_result_t
- return err ? OBOE_ERROR_INTERNAL : OBOE_OK;
-}
-
diff --git a/services/oboeservice/SharedRingBuffer.cpp b/services/oboeservice/SharedRingBuffer.cpp
index c3df5ce..9ac8fdf 100644
--- a/services/oboeservice/SharedRingBuffer.cpp
+++ b/services/oboeservice/SharedRingBuffer.cpp
@@ -14,20 +14,20 @@
* limitations under the License.
*/
-#define LOG_TAG "OboeService"
+#define LOG_TAG "AAudioService"
//#define LOG_NDEBUG 0
#include <utils/Log.h>
#include "AudioClock.h"
#include "AudioEndpointParcelable.h"
-//#include "OboeServiceStreamBase.h"
-//#include "OboeServiceStreamFakeHal.h"
+//#include "AAudioServiceStreamBase.h"
+//#include "AAudioServiceStreamFakeHal.h"
#include "SharedRingBuffer.h"
using namespace android;
-using namespace oboe;
+using namespace aaudio;
SharedRingBuffer::~SharedRingBuffer()
{
@@ -39,23 +39,23 @@
}
}
-oboe_result_t SharedRingBuffer::allocate(fifo_frames_t bytesPerFrame,
+aaudio_result_t SharedRingBuffer::allocate(fifo_frames_t bytesPerFrame,
fifo_frames_t capacityInFrames) {
mCapacityInFrames = capacityInFrames;
// Create shared memory large enough to hold the data and the read and write counters.
mDataMemorySizeInBytes = bytesPerFrame * capacityInFrames;
mSharedMemorySizeInBytes = mDataMemorySizeInBytes + (2 * (sizeof(fifo_counter_t)));
- mFileDescriptor = ashmem_create_region("OboeSharedRingBuffer", mSharedMemorySizeInBytes);
+ mFileDescriptor = ashmem_create_region("AAudioSharedRingBuffer", mSharedMemorySizeInBytes);
if (mFileDescriptor < 0) {
ALOGE("SharedRingBuffer::allocate() ashmem_create_region() failed %d", errno);
- return OBOE_ERROR_INTERNAL;
+ return AAUDIO_ERROR_INTERNAL;
}
int err = ashmem_set_prot_region(mFileDescriptor, PROT_READ|PROT_WRITE); // TODO error handling?
if (err < 0) {
ALOGE("SharedRingBuffer::allocate() ashmem_set_prot_region() failed %d", errno);
close(mFileDescriptor);
- return OBOE_ERROR_INTERNAL; // TODO convert errno to a better OBOE_ERROR;
+ return AAUDIO_ERROR_INTERNAL; // TODO convert errno to a better AAUDIO_ERROR;
}
// Map the fd to memory addresses.
@@ -66,7 +66,7 @@
if (mSharedMemory == MAP_FAILED) {
ALOGE("SharedRingBuffer::allocate() mmap() failed %d", errno);
close(mFileDescriptor);
- return OBOE_ERROR_INTERNAL; // TODO convert errno to a better OBOE_ERROR;
+ return AAUDIO_ERROR_INTERNAL; // TODO convert errno to a better AAUDIO_ERROR;
}
// Get addresses for our counters and data from the shared memory.
@@ -78,7 +78,7 @@
mFifoBuffer = new(std::nothrow) FifoBuffer(bytesPerFrame, capacityInFrames,
readCounterAddress, writeCounterAddress, dataAddress);
- return (mFifoBuffer == nullptr) ? OBOE_ERROR_NO_MEMORY : OBOE_OK;
+ return (mFifoBuffer == nullptr) ? AAUDIO_ERROR_NO_MEMORY : AAUDIO_OK;
}
void SharedRingBuffer::fillParcelable(AudioEndpointParcelable &endpointParcelable,
diff --git a/services/oboeservice/SharedRingBuffer.h b/services/oboeservice/SharedRingBuffer.h
index 3cc1c2d..75f138b 100644
--- a/services/oboeservice/SharedRingBuffer.h
+++ b/services/oboeservice/SharedRingBuffer.h
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#ifndef OBOE_SHARED_RINGBUFFER_H
-#define OBOE_SHARED_RINGBUFFER_H
+#ifndef AAUDIO_SHARED_RINGBUFFER_H
+#define AAUDIO_SHARED_RINGBUFFER_H
#include <stdint.h>
#include <cutils/ashmem.h>
@@ -25,7 +25,7 @@
#include "RingBufferParcelable.h"
#include "AudioEndpointParcelable.h"
-namespace oboe {
+namespace aaudio {
// Determine the placement of the counters and data in shared memory.
#define SHARED_RINGBUFFER_READ_OFFSET 0
@@ -41,7 +41,7 @@
virtual ~SharedRingBuffer();
- oboe_result_t allocate(fifo_frames_t bytesPerFrame, fifo_frames_t capacityInFrames);
+ aaudio_result_t allocate(fifo_frames_t bytesPerFrame, fifo_frames_t capacityInFrames);
void fillParcelable(AudioEndpointParcelable &endpointParcelable,
RingBufferParcelable &ringBufferParcelable);
@@ -59,6 +59,6 @@
fifo_frames_t mCapacityInFrames = 0;
};
-} /* namespace oboe */
+} /* namespace aaudio */
-#endif //OBOE_SHARED_RINGBUFFER_H
+#endif //AAUDIO_SHARED_RINGBUFFER_H
diff --git a/services/oboeservice/TimestampScheduler.cpp b/services/oboeservice/TimestampScheduler.cpp
index 17d6c63..5875909 100644
--- a/services/oboeservice/TimestampScheduler.cpp
+++ b/services/oboeservice/TimestampScheduler.cpp
@@ -19,14 +19,14 @@
#include "TimestampScheduler.h"
-using namespace oboe;
+using namespace aaudio;
-void TimestampScheduler::start(oboe_nanoseconds_t startTime) {
+void TimestampScheduler::start(aaudio_nanoseconds_t startTime) {
mStartTime = startTime;
mLastTime = startTime;
}
-oboe_nanoseconds_t TimestampScheduler::nextAbsoluteTime() {
+aaudio_nanoseconds_t TimestampScheduler::nextAbsoluteTime() {
int64_t periodsElapsed = (mLastTime - mStartTime) / mBurstPeriod;
// This is an arbitrary schedule that could probably be improved.
// It starts out sending a timestamp on every period because we want to
@@ -35,10 +35,10 @@
int64_t minPeriodsToDelay = (periodsElapsed < 10) ? 1 :
(periodsElapsed < 100) ? 3 :
(periodsElapsed < 1000) ? 10 : 50;
- oboe_nanoseconds_t sleepTime = minPeriodsToDelay * mBurstPeriod;
+ aaudio_nanoseconds_t sleepTime = minPeriodsToDelay * mBurstPeriod;
// Generate a random rectangular distribution one burst wide so that we get
// an uncorrelated sampling of the MMAP pointer.
- sleepTime += (oboe_nanoseconds_t)(random() * mBurstPeriod / RAND_MAX);
+ sleepTime += (aaudio_nanoseconds_t)(random() * mBurstPeriod / RAND_MAX);
mLastTime += sleepTime;
return mLastTime;
}
diff --git a/services/oboeservice/TimestampScheduler.h b/services/oboeservice/TimestampScheduler.h
index 041e432..efc9c5f 100644
--- a/services/oboeservice/TimestampScheduler.h
+++ b/services/oboeservice/TimestampScheduler.h
@@ -14,19 +14,19 @@
* limitations under the License.
*/
-#ifndef OBOE_TIMESTAMP_SCHEDULER_H
-#define OBOE_TIMESTAMP_SCHEDULER_H
+#ifndef AAUDIO_TIMESTAMP_SCHEDULER_H
+#define AAUDIO_TIMESTAMP_SCHEDULER_H
//#include <stdlib.h> // random()
-#include "IOboeAudioService.h"
-#include "OboeService.h"
+#include "IAAudioService.h"
+#include "AAudioServiceDefinitions.h"
#include "AudioStream.h"
#include "fifo/FifoBuffer.h"
#include "SharedRingBuffer.h"
#include "AudioEndpointParcelable.h"
-namespace oboe {
+namespace aaudio {
/**
* Schedule wakeup time for monitoring the position
@@ -43,34 +43,34 @@
/**
* Start the schedule at the given time.
*/
- void start(oboe_nanoseconds_t startTime);
+ void start(aaudio_nanoseconds_t startTime);
/**
* Calculate the next time that the read position should be
* measured.
*/
- oboe_nanoseconds_t nextAbsoluteTime();
+ aaudio_nanoseconds_t nextAbsoluteTime();
- void setBurstPeriod(oboe_nanoseconds_t burstPeriod) {
+ void setBurstPeriod(aaudio_nanoseconds_t burstPeriod) {
mBurstPeriod = burstPeriod;
}
- void setBurstPeriod(oboe_size_frames_t framesPerBurst,
- oboe_sample_rate_t sampleRate) {
- mBurstPeriod = OBOE_NANOS_PER_SECOND * framesPerBurst / sampleRate;
+ void setBurstPeriod(aaudio_size_frames_t framesPerBurst,
+ aaudio_sample_rate_t sampleRate) {
+ mBurstPeriod = AAUDIO_NANOS_PER_SECOND * framesPerBurst / sampleRate;
}
- oboe_nanoseconds_t getBurstPeriod() {
+ aaudio_nanoseconds_t getBurstPeriod() {
return mBurstPeriod;
}
private:
// Start with an arbitrary default so we do not divide by zero.
- oboe_nanoseconds_t mBurstPeriod = OBOE_NANOS_PER_MILLISECOND;
- oboe_nanoseconds_t mStartTime;
- oboe_nanoseconds_t mLastTime;
+ aaudio_nanoseconds_t mBurstPeriod = AAUDIO_NANOS_PER_MILLISECOND;
+ aaudio_nanoseconds_t mStartTime;
+ aaudio_nanoseconds_t mLastTime;
};
-} /* namespace oboe */
+} /* namespace aaudio */
-#endif /* OBOE_TIMESTAMP_SCHEDULER_H */
+#endif /* AAUDIO_TIMESTAMP_SCHEDULER_H */