blob: 2508ceabe332db10538dab7dee16bb0ad5e773cc [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
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 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
Phil Burk828bea52017-01-03 17:22:09 -080065 void dump();
66
Ytai Ben-Tsvic5f45872020-08-18 10:39:44 -070067 // Extract a parcelable representation of this object.
68 RingBuffer parcelable() const;
69
Phil Burk828bea52017-01-03 17:22:09 -080070private:
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-Tsvic5f45872020-08-18 10:39:44 -070078
79 aaudio_result_t validate() const;
Phil Burk828bea52017-01-03 17:22:09 -080080};
81
Phil Burk5ed503c2017-02-01 09:38:15 -080082} /* namespace aaudio */
Phil Burk828bea52017-01-03 17:22:09 -080083
Phil Burk5204d312017-05-04 17:16:13 -070084#endif //ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H