blob: f5b67e87d6a76af961fb6cf581f203e985e452e2 [file] [log] [blame]
Phil Burk204a1632017-01-03 17:23:43 -08001/*
2 * Copyright (C) 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_AUDIO_ENDPOINT_H
18#define ANDROID_AAUDIO_AUDIO_ENDPOINT_H
Phil Burk204a1632017-01-03 17:23:43 -080019
Phil Burk5ed503c2017-02-01 09:38:15 -080020#include <aaudio/AAudio.h>
Phil Burk204a1632017-01-03 17:23:43 -080021
Phil Burkc0c70e32017-02-09 13:18:38 -080022#include "binding/AAudioServiceMessage.h"
23#include "binding/AudioEndpointParcelable.h"
Phil Burk204a1632017-01-03 17:23:43 -080024#include "fifo/FifoBuffer.h"
25
Phil Burk5ed503c2017-02-01 09:38:15 -080026namespace aaudio {
Phil Burk204a1632017-01-03 17:23:43 -080027
Phil Burkc0c70e32017-02-09 13:18:38 -080028#define ENDPOINT_DATA_QUEUE_SIZE_MIN 48
Phil Burk204a1632017-01-03 17:23:43 -080029
30/**
31 * A sink for audio.
32 * Used by the client code.
33 */
34class AudioEndpoint {
35
36public:
37 AudioEndpoint();
38 virtual ~AudioEndpoint();
39
40 /**
41 * Configure based on the EndPointDescriptor_t.
42 */
Phil Burkfd34a932017-07-19 07:03:52 -070043 aaudio_result_t configure(const EndpointDescriptor *pEndpointDescriptor,
44 aaudio_direction_t direction);
Phil Burk204a1632017-01-03 17:23:43 -080045
46 /**
47 * Read from a command passed up from the Server.
48 * @return 1 if command received, 0 for no command, or negative error.
49 */
Phil Burk5ed503c2017-02-01 09:38:15 -080050 aaudio_result_t readUpCommand(AAudioServiceMessage *commandPtr);
Phil Burk204a1632017-01-03 17:23:43 -080051
Phil Burkfd34a932017-07-19 07:03:52 -070052 int32_t getEmptyFramesAvailable(android::WrappingBuffer *wrappingBuffer);
Phil Burkc0c70e32017-02-09 13:18:38 -080053
Phil Burk4485d412017-05-09 15:55:02 -070054 int32_t getEmptyFramesAvailable();
Phil Burk87c9f642017-05-17 07:22:39 -070055
Phil Burkfd34a932017-07-19 07:03:52 -070056 int32_t getFullFramesAvailable(android::WrappingBuffer *wrappingBuffer);
Phil Burk87c9f642017-05-17 07:22:39 -070057
Phil Burk4485d412017-05-09 15:55:02 -070058 int32_t getFullFramesAvailable();
59
Phil Burk87c9f642017-05-17 07:22:39 -070060 void advanceReadIndex(int32_t deltaFrames);
61
Phil Burkc0c70e32017-02-09 13:18:38 -080062 void advanceWriteIndex(int32_t deltaFrames);
63
Phil Burk204a1632017-01-03 17:23:43 -080064 /**
65 * Set the read index in the downData queue.
66 * This is needed if the reader is not updating the index itself.
67 */
Phil Burk87c9f642017-05-17 07:22:39 -070068 void setDataReadCounter(android::fifo_counter_t framesRead);
Phil Burk204a1632017-01-03 17:23:43 -080069
Phil Burk87c9f642017-05-17 07:22:39 -070070 android::fifo_counter_t getDataReadCounter();
71
72 void setDataWriteCounter(android::fifo_counter_t framesWritten);
73
74 android::fifo_counter_t getDataWriteCounter();
Phil Burk204a1632017-01-03 17:23:43 -080075
76 /**
77 * The result is not valid until after configure() is called.
78 *
79 * @return true if the output buffer read position is not updated, eg. DMA
80 */
Phil Burk87c9f642017-05-17 07:22:39 -070081 bool isFreeRunning() const { return mFreeRunning; }
Phil Burk204a1632017-01-03 17:23:43 -080082
Phil Burk3316d5e2017-02-15 11:23:01 -080083 int32_t setBufferSizeInFrames(int32_t requestedFrames,
84 int32_t *actualFrames);
85 int32_t getBufferSizeInFrames() const;
Phil Burk204a1632017-01-03 17:23:43 -080086
Phil Burk3316d5e2017-02-15 11:23:01 -080087 int32_t getBufferCapacityInFrames() const;
Phil Burk204a1632017-01-03 17:23:43 -080088
Phil Burkea04d972017-08-07 12:30:44 -070089 /**
90 * Write zeros to the data queue memory.
91 */
92 void eraseDataMemory();
93
Phil Burkec89b2e2017-06-20 15:05:06 -070094 void dump() const;
95
Phil Burk204a1632017-01-03 17:23:43 -080096private:
Phil Burkc0c70e32017-02-09 13:18:38 -080097 android::FifoBuffer *mUpCommandQueue;
Phil Burk87c9f642017-05-17 07:22:39 -070098 android::FifoBuffer *mDataQueue;
99 bool mFreeRunning;
Phil Burkc0c70e32017-02-09 13:18:38 -0800100 android::fifo_counter_t mDataReadCounter; // only used if free-running
101 android::fifo_counter_t mDataWriteCounter; // only used if free-running
Phil Burk204a1632017-01-03 17:23:43 -0800102};
103
Phil Burk5ed503c2017-02-01 09:38:15 -0800104} // namespace aaudio
Phil Burk204a1632017-01-03 17:23:43 -0800105
Phil Burk5204d312017-05-04 17:16:13 -0700106#endif //ANDROID_AAUDIO_AUDIO_ENDPOINT_H