blob: 29d0d862f09c35a08a06f5967b242ac4130a126c [file] [log] [blame]
Phil Burk828bea52017-01-03 17:22:09 -08001/*
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 Burk5204d312017-05-04 17:16:13 -070017#ifndef ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H
18#define ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H
Phil Burk828bea52017-01-03 17:22:09 -080019
20#include <stdint.h>
21
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070022#include <aaudio/RingBuffer.h>
Phil Burk828bea52017-01-03 17:22:09 -080023#include <binder/Parcelable.h>
24
Phil Burk5ed503c2017-02-01 09:38:15 -080025#include "binding/AAudioServiceDefinitions.h"
Phil Burk828bea52017-01-03 17:22:09 -080026#include "binding/SharedRegionParcelable.h"
27
Phil Burk5ed503c2017-02-01 09:38:15 -080028namespace aaudio {
Phil Burk828bea52017-01-03 17:22:09 -080029
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070030class RingBufferParcelable {
Phil Burk828bea52017-01-03 17:22:09 -080031public:
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070032 RingBufferParcelable() = default;
33
34 // Construct based on a parcelable representation.
35 explicit RingBufferParcelable(const RingBuffer& parcelable);
Phil Burk828bea52017-01-03 17:22:09 -080036
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
jiabinf7f06152021-11-22 18:10:14 +000049 int32_t getBytesPerFrame() const;
Phil Burk828bea52017-01-03 17:22:09 -080050
51 void setBytesPerFrame(int32_t bytesPerFrame);
52
jiabinf7f06152021-11-22 18:10:14 +000053 int32_t getFramesPerBurst() const;
Phil Burk828bea52017-01-03 17:22:09 -080054
55 void setFramesPerBurst(int32_t framesPerBurst);
56
jiabinf7f06152021-11-22 18:10:14 +000057 int32_t getCapacityInFrames() const;
Phil Burk828bea52017-01-03 17:22:09 -080058
59 void setCapacityInFrames(int32_t capacityInFrames);
60
Phil Burkc0c70e32017-02-09 13:18:38 -080061 bool isFileDescriptorSafe(SharedMemoryParcelable *memoryParcels);
62
Phil Burk5ed503c2017-02-01 09:38:15 -080063 aaudio_result_t resolve(SharedMemoryParcelable *memoryParcels, RingBufferDescriptor *descriptor);
Phil Burk828bea52017-01-03 17:22:09 -080064
jiabinf7f06152021-11-22 18:10:14 +000065 void updateMemory(const RingBufferParcelable& parcelable);
66
67 int32_t getSharedMemoryIndex() const {
68 return mSharedMemoryIndex;
69 }
70
Phil Burk828bea52017-01-03 17:22:09 -080071 void dump();
72
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070073 // Extract a parcelable representation of this object.
74 RingBuffer parcelable() const;
75
Phil Burk828bea52017-01-03 17:22:09 -080076private:
77 SharedRegionParcelable mReadCounterParcelable;
78 SharedRegionParcelable mWriteCounterParcelable;
79 SharedRegionParcelable mDataParcelable;
jiabinf7f06152021-11-22 18:10:14 +000080 int32_t mSharedMemoryIndex = -1;
Phil Burk828bea52017-01-03 17:22:09 -080081 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;
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070085
86 aaudio_result_t validate() const;
Phil Burk828bea52017-01-03 17:22:09 -080087};
88
Phil Burk5ed503c2017-02-01 09:38:15 -080089} /* namespace aaudio */
Phil Burk828bea52017-01-03 17:22:09 -080090
Phil Burk5204d312017-05-04 17:16:13 -070091#endif //ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H