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
17#ifndef ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H
18#define ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H
19
20#include <stdint.h>
21
22#include <binder/Parcelable.h>
23
24#include "binding/AAudioServiceDefinitions.h"
25#include "binding/SharedRegionParcelable.h"
26
27namespace aaudio {
28
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
58    bool isFileDescriptorSafe(SharedMemoryParcelable *memoryParcels);
59
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
67    aaudio_result_t resolve(SharedMemoryParcelable *memoryParcels, RingBufferDescriptor *descriptor);
68
69    aaudio_result_t validate();
70
71    void dump();
72
73private:
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
83} /* namespace aaudio */
84
85#endif //ANDROID_AAUDIO_RINGBUFFER_PARCELABLE_H
86