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(); 50 51 void setBytesPerFrame(int32_t bytesPerFrame); 52 53 int32_t getFramesPerBurst(); 54 55 void setFramesPerBurst(int32_t framesPerBurst); 56 57 int32_t getCapacityInFrames(); 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 dump(); 66 67 // Extract a parcelable representation of this object. 68 RingBuffer parcelable() const; 69 70 private: 71 SharedRegionParcelable mReadCounterParcelable; 72 SharedRegionParcelable mWriteCounterParcelable; 73 SharedRegionParcelable mDataParcelable; 74 int32_t mBytesPerFrame = 0; // index is in frames 75 int32_t mFramesPerBurst = 0; // for ISOCHRONOUS queues 76 int32_t mCapacityInFrames = 0; // zero if unused 77 RingbufferFlags mFlags = RingbufferFlags::NONE; 78 79 aaudio_result_t validate() const; 80 }; 81 82 } /* namespace aaudio */ 83 84 #endif //ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H 85