Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 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 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame^] | 17 | #ifndef ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H |
| 18 | #define ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | |
| 22 | #include <binder/Parcelable.h> |
| 23 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 24 | #include "binding/AAudioServiceDefinitions.h" |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 25 | #include "binding/SharedRegionParcelable.h" |
| 26 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 27 | namespace aaudio { |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 28 | |
| 29 | class RingBufferParcelable : public Parcelable { |
| 30 | public: |
| 31 | RingBufferParcelable(); |
| 32 | virtual ~RingBufferParcelable(); |
| 33 | |
| 34 | // TODO This assumes that all three use the same SharedMemoryParcelable |
| 35 | void setupMemory(int32_t sharedMemoryIndex, |
| 36 | int32_t dataMemoryOffset, |
| 37 | int32_t dataSizeInBytes, |
| 38 | int32_t readCounterOffset, |
| 39 | int32_t writeCounterOffset, |
| 40 | int32_t counterSizeBytes); |
| 41 | |
| 42 | void setupMemory(int32_t sharedMemoryIndex, |
| 43 | int32_t dataMemoryOffset, |
| 44 | int32_t dataSizeInBytes); |
| 45 | |
| 46 | int32_t getBytesPerFrame(); |
| 47 | |
| 48 | void setBytesPerFrame(int32_t bytesPerFrame); |
| 49 | |
| 50 | int32_t getFramesPerBurst(); |
| 51 | |
| 52 | void setFramesPerBurst(int32_t framesPerBurst); |
| 53 | |
| 54 | int32_t getCapacityInFrames(); |
| 55 | |
| 56 | void setCapacityInFrames(int32_t capacityInFrames); |
| 57 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 58 | bool isFileDescriptorSafe(SharedMemoryParcelable *memoryParcels); |
| 59 | |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 60 | /** |
| 61 | * The read and write must be symmetric. |
| 62 | */ |
| 63 | virtual status_t writeToParcel(Parcel* parcel) const override; |
| 64 | |
| 65 | virtual status_t readFromParcel(const Parcel* parcel) override; |
| 66 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 67 | aaudio_result_t resolve(SharedMemoryParcelable *memoryParcels, RingBufferDescriptor *descriptor); |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 68 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 69 | aaudio_result_t validate(); |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 70 | |
| 71 | void dump(); |
| 72 | |
| 73 | private: |
| 74 | SharedRegionParcelable mReadCounterParcelable; |
| 75 | SharedRegionParcelable mWriteCounterParcelable; |
| 76 | SharedRegionParcelable mDataParcelable; |
| 77 | int32_t mBytesPerFrame = 0; // index is in frames |
| 78 | int32_t mFramesPerBurst = 0; // for ISOCHRONOUS queues |
| 79 | int32_t mCapacityInFrames = 0; // zero if unused |
| 80 | RingbufferFlags mFlags = RingbufferFlags::NONE; |
| 81 | }; |
| 82 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 83 | } /* namespace aaudio */ |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 84 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame^] | 85 | #endif //ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H |