RingBufferParcelable.h revision 5ed503c7a66c90f93759c90237a9b432dbd93f9f
1828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk/*
2828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Copyright 2016 The Android Open Source Project
3828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
4828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Licensed under the Apache License, Version 2.0 (the "License");
5828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * you may not use this file except in compliance with the License.
6828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * You may obtain a copy of the License at
7828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
8828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *      http://www.apache.org/licenses/LICENSE-2.0
9828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk *
10828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * Unless required by applicable law or agreed to in writing, software
11828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * distributed under the License is distributed on an "AS IS" BASIS,
12828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * See the License for the specific language governing permissions and
14828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk * limitations under the License.
15828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk */
16828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
17828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#ifndef BINDING_RINGBUFFER_PARCELABLE_H
18828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#define BINDING_RINGBUFFER_PARCELABLE_H
19828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
20828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <stdint.h>
21828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
22828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include <binder/Parcelable.h>
23828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
245ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk#include "binding/AAudioServiceDefinitions.h"
25828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#include "binding/SharedRegionParcelable.h"
26828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
275ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burknamespace aaudio {
28828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
29828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkclass RingBufferParcelable : public Parcelable {
30828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkpublic:
31828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    RingBufferParcelable();
32828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    virtual ~RingBufferParcelable();
33828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
34828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    // TODO This assumes that all three use the same SharedMemoryParcelable
35828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    void setupMemory(int32_t sharedMemoryIndex,
36828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                     int32_t dataMemoryOffset,
37828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                     int32_t dataSizeInBytes,
38828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                     int32_t readCounterOffset,
39828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                     int32_t writeCounterOffset,
40828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                     int32_t counterSizeBytes);
41828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
42828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    void setupMemory(int32_t sharedMemoryIndex,
43828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                     int32_t dataMemoryOffset,
44828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk                     int32_t dataSizeInBytes);
45828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
46828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int32_t getBytesPerFrame();
47828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
48828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    void setBytesPerFrame(int32_t bytesPerFrame);
49828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
50828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int32_t getFramesPerBurst();
51828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
52828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    void setFramesPerBurst(int32_t framesPerBurst);
53828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
54828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int32_t getCapacityInFrames();
55828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
56828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    void setCapacityInFrames(int32_t capacityInFrames);
57828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
58828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    /**
59828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     * The read and write must be symmetric.
60828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk     */
61828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    virtual status_t writeToParcel(Parcel* parcel) const override;
62828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
63828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    virtual status_t readFromParcel(const Parcel* parcel) override;
64828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
655ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk    aaudio_result_t resolve(SharedMemoryParcelable *memoryParcels, RingBufferDescriptor *descriptor);
66828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
675ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk    aaudio_result_t validate();
68828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
69828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    void dump();
70828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
71828bea5f61f3c40d24759cd8739dd95570883b56Phil Burkprivate:
72828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    SharedRegionParcelable  mReadCounterParcelable;
73828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    SharedRegionParcelable  mWriteCounterParcelable;
74828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    SharedRegionParcelable  mDataParcelable;
75828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int32_t                 mBytesPerFrame = 0;     // index is in frames
76828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int32_t                 mFramesPerBurst = 0;    // for ISOCHRONOUS queues
77828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    int32_t                 mCapacityInFrames = 0;  // zero if unused
78828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk    RingbufferFlags         mFlags = RingbufferFlags::NONE;
79828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk};
80828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
815ed503c7a66c90f93759c90237a9b432dbd93f9fPhil Burk} /* namespace aaudio */
82828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk
83828bea5f61f3c40d24759cd8739dd95570883b56Phil Burk#endif //BINDING_RINGBUFFER_PARCELABLE_H
84