1 /* 2 * Copyright 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H 18 #define ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H 19 20 #include <stdint.h> 21 22 #include <aaudio/RingBuffer.h> 23 #include <binder/Parcelable.h> 24 25 #include "binding/AAudioServiceDefinitions.h" 26 #include "binding/SharedRegionParcelable.h" 27 28 namespace aaudio { 29 30 class RingBufferParcelable { 31 public: 32 RingBufferParcelable() = default; 33 34 // Construct based on a parcelable representation. 35 explicit RingBufferParcelable(const RingBuffer& parcelable); 36 37 // TODO This assumes that all three use the same SharedMemoryParcelable 38 void setupMemory(int32_t sharedMemoryIndex, 39 int32_t dataMemoryOffset, 40 int32_t dataSizeInBytes, 41 int32_t readCounterOffset, 42 int32_t writeCounterOffset, 43 int32_t counterSizeBytes); 44 45 void setupMemory(int32_t sharedMemoryIndex, 46 int32_t dataMemoryOffset, 47 int32_t dataSizeInBytes); 48 49 int32_t getBytesPerFrame() const; 50 51 void setBytesPerFrame(int32_t bytesPerFrame); 52 53 int32_t getFramesPerBurst() const; 54 55 void setFramesPerBurst(int32_t framesPerBurst); 56 57 int32_t getCapacityInFrames() const; 58 59 void setCapacityInFrames(int32_t capacityInFrames); 60 61 bool isFileDescriptorSafe(SharedMemoryParcelable *memoryParcels); 62 63 aaudio_result_t resolve(SharedMemoryParcelable *memoryParcels, RingBufferDescriptor *descriptor); 64 65 void updateMemory(const RingBufferParcelable& parcelable); 66 getSharedMemoryIndex()67 int32_t getSharedMemoryIndex() const { 68 return mSharedMemoryIndex; 69 } 70 71 void dump(); 72 73 // Extract a parcelable representation of this object. 74 RingBuffer parcelable() const; 75 76 private: 77 SharedRegionParcelable mReadCounterParcelable; 78 SharedRegionParcelable mWriteCounterParcelable; 79 SharedRegionParcelable mDataParcelable; 80 int32_t mSharedMemoryIndex = -1; 81 int32_t mBytesPerFrame = 0; // index is in frames 82 int32_t mFramesPerBurst = 0; // for ISOCHRONOUS queues 83 int32_t mCapacityInFrames = 0; // zero if unused 84 RingbufferFlags mFlags = RingbufferFlags::NONE; 85 86 aaudio_result_t validate() const; 87 }; 88 89 } /* namespace aaudio */ 90 91 #endif //ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H 92