Convert AAudioService to AIDL
This change removes all hand-written binder code associated with
parceling of AAudio types and IAAudioService interface.
The existing types defined in the 'binding' directory have not been
replaced by their AIDL counterparts, but rather were made convertible
to/from them (in lieu of them being parcelables themselves).
The reasons are:
- Some of those types offer additional functionality rather than
simply being data containers / serializers. For example, the
SharedMemoryParcelable type supports mmaping a memory region.
- Reduce impact on existing code, which relies on the interface
offered by those type, which is different than the interface offered
by their AIDL counterparts.
The conversion between those types and their parcelable counterparts
is handled at the edge of the client (inside AAudioBinderAdapter) and
server (inside AAudioService) code.
Future changes may gradually get rid of the duality by retiring the
data types in the 'binding' directory, inlining some of the features
they are offering (such as accessor methods) and replacing others with
utility functions, operation on the parcelables directly.
Bug: 160253486
Test: Manual testing using OboeTester
Ran atest CtsNativeMediaAAudioTestCases
Ran atest test_aaudio_marshalling
Change-Id: I6eed19246a472dc31c1e2d6d2112d7562cf8940c
diff --git a/media/libaaudio/src/binding/RingBufferParcelable.h b/media/libaaudio/src/binding/RingBufferParcelable.h
index 1dbcf07..2508cea 100644
--- a/media/libaaudio/src/binding/RingBufferParcelable.h
+++ b/media/libaaudio/src/binding/RingBufferParcelable.h
@@ -19,6 +19,7 @@
#include <stdint.h>
+#include <aaudio/RingBuffer.h>
#include <binder/Parcelable.h>
#include "binding/AAudioServiceDefinitions.h"
@@ -26,10 +27,12 @@
namespace aaudio {
-class RingBufferParcelable : public Parcelable {
+class RingBufferParcelable {
public:
- RingBufferParcelable();
- virtual ~RingBufferParcelable();
+ RingBufferParcelable() = default;
+
+ // Construct based on a parcelable representation.
+ explicit RingBufferParcelable(const RingBuffer& parcelable);
// TODO This assumes that all three use the same SharedMemoryParcelable
void setupMemory(int32_t sharedMemoryIndex,
@@ -57,21 +60,14 @@
bool isFileDescriptorSafe(SharedMemoryParcelable *memoryParcels);
- /**
- * The read and write must be symmetric.
- */
- virtual status_t writeToParcel(Parcel* parcel) const override;
-
- virtual status_t readFromParcel(const Parcel* parcel) override;
-
aaudio_result_t resolve(SharedMemoryParcelable *memoryParcels, RingBufferDescriptor *descriptor);
void dump();
+ // Extract a parcelable representation of this object.
+ RingBuffer parcelable() const;
+
private:
-
- aaudio_result_t validate() const;
-
SharedRegionParcelable mReadCounterParcelable;
SharedRegionParcelable mWriteCounterParcelable;
SharedRegionParcelable mDataParcelable;
@@ -79,6 +75,8 @@
int32_t mFramesPerBurst = 0; // for ISOCHRONOUS queues
int32_t mCapacityInFrames = 0; // zero if unused
RingbufferFlags mFlags = RingbufferFlags::NONE;
+
+ aaudio_result_t validate() const;
};
} /* namespace aaudio */