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 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 22 | #include <aaudio/RingBuffer.h> |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 23 | #include <binder/Parcelable.h> |
| 24 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 25 | #include "binding/AAudioServiceDefinitions.h" |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 26 | #include "binding/SharedRegionParcelable.h" |
| 27 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 28 | namespace aaudio { |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 29 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 30 | class RingBufferParcelable { |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 31 | public: |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 32 | RingBufferParcelable() = default; |
| 33 | |
| 34 | // Construct based on a parcelable representation. |
| 35 | explicit RingBufferParcelable(const RingBuffer& parcelable); |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 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 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 61 | bool isFileDescriptorSafe(SharedMemoryParcelable *memoryParcels); |
| 62 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 63 | aaudio_result_t resolve(SharedMemoryParcelable *memoryParcels, RingBufferDescriptor *descriptor); |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 64 | |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 65 | void dump(); |
| 66 | |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 67 | // Extract a parcelable representation of this object. |
| 68 | RingBuffer parcelable() const; |
| 69 | |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 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; |
Ytai Ben-Tsvi | c5f4587 | 2020-08-18 10:39:44 -0700 | [diff] [blame] | 78 | |
| 79 | aaudio_result_t validate() const; |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 80 | }; |
| 81 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 82 | } /* namespace aaudio */ |
Phil Burk | 828bea5 | 2017-01-03 17:22:09 -0800 | [diff] [blame] | 83 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 84 | #endif //ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H |