blob: 5fc5d00a07d31b60489e4c20b5087e57b6b411a3 [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
17#ifndef BINDING_RINGBUFFER_PARCELABLE_H
18#define BINDING_RINGBUFFER_PARCELABLE_H
19
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 Burk5ed503c2017-02-01 09:38:15 -080069 aaudio_result_t validate();
Phil Burk828bea52017-01-03 17:22:09 -080070
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
Phil Burk5ed503c2017-02-01 09:38:15 -080083} /* namespace aaudio */
Phil Burk828bea52017-01-03 17:22:09 -080084
85#endif //BINDING_RINGBUFFER_PARCELABLE_H