blob: 1dbcf07e9bb5662951cd408f6a9118092e9a2ded [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
22#include <binder/Parcelable.h>
23
Phil Burk5ed503c2017-02-01 09:38:15 -080024#include "binding/AAudioServiceDefinitions.h"
Phil Burk828bea52017-01-03 17:22:09 -080025#include "binding/SharedRegionParcelable.h"
26
Phil Burk5ed503c2017-02-01 09:38:15 -080027namespace aaudio {
Phil Burk828bea52017-01-03 17:22:09 -080028
29class RingBufferParcelable : public Parcelable {
30public:
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 Burkc0c70e32017-02-09 13:18:38 -080058 bool isFileDescriptorSafe(SharedMemoryParcelable *memoryParcels);
59
Phil Burk828bea52017-01-03 17:22:09 -080060 /**
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 Burk5ed503c2017-02-01 09:38:15 -080067 aaudio_result_t resolve(SharedMemoryParcelable *memoryParcels, RingBufferDescriptor *descriptor);
Phil Burk828bea52017-01-03 17:22:09 -080068
Phil Burk828bea52017-01-03 17:22:09 -080069 void dump();
70
71private:
Phil Burka5891f42018-03-12 17:21:11 -070072
73 aaudio_result_t validate() const;
74
Phil Burk828bea52017-01-03 17:22:09 -080075 SharedRegionParcelable mReadCounterParcelable;
76 SharedRegionParcelable mWriteCounterParcelable;
77 SharedRegionParcelable mDataParcelable;
78 int32_t mBytesPerFrame = 0; // index is in frames
79 int32_t mFramesPerBurst = 0; // for ISOCHRONOUS queues
80 int32_t mCapacityInFrames = 0; // zero if unused
81 RingbufferFlags mFlags = RingbufferFlags::NONE;
82};
83
Phil Burk5ed503c2017-02-01 09:38:15 -080084} /* namespace aaudio */
Phil Burk828bea52017-01-03 17:22:09 -080085
Phil Burk5204d312017-05-04 17:16:13 -070086#endif //ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H