AudioEndpoint.h revision c0c70e3c7dd10bc2c0caffcab1f3f5fb406b35fb
1/* 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 17#ifndef AAUDIO_AUDIO_ENDPOINT_H 18#define AAUDIO_AUDIO_ENDPOINT_H 19 20#include <aaudio/AAudio.h> 21 22#include "binding/AAudioServiceMessage.h" 23#include "binding/AudioEndpointParcelable.h" 24#include "fifo/FifoBuffer.h" 25 26namespace aaudio { 27 28#define ENDPOINT_DATA_QUEUE_SIZE_MIN 48 29 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 */ 43 aaudio_result_t configure(const EndpointDescriptor *pEndpointDescriptor); 44 45 /** 46 * Read from a command passed up from the Server. 47 * @return 1 if command received, 0 for no command, or negative error. 48 */ 49 aaudio_result_t readUpCommand(AAudioServiceMessage *commandPtr); 50 51 /** 52 * Non-blocking write. 53 * @return framesWritten or a negative error code. 54 */ 55 aaudio_result_t writeDataNow(const void *buffer, int32_t numFrames); 56 57 void getEmptyRoomAvailable(android::WrappingBuffer *wrappingBuffer); 58 59 void advanceWriteIndex(int32_t deltaFrames); 60 61 /** 62 * Set the read index in the downData queue. 63 * This is needed if the reader is not updating the index itself. 64 */ 65 void setDownDataReadCounter(android::fifo_counter_t framesRead); 66 android::fifo_counter_t getDownDataReadCounter(); 67 68 void setDownDataWriteCounter(android::fifo_counter_t framesWritten); 69 android::fifo_counter_t getDownDataWriteCounter(); 70 71 /** 72 * The result is not valid until after configure() is called. 73 * 74 * @return true if the output buffer read position is not updated, eg. DMA 75 */ 76 bool isOutputFreeRunning() const { return mOutputFreeRunning; } 77 78 int32_t setBufferSizeInFrames(int32_t requestedFrames, 79 int32_t *actualFrames); 80 int32_t getBufferSizeInFrames() const; 81 82 int32_t getBufferCapacityInFrames() const; 83 84 int32_t getFullFramesAvailable(); 85 86private: 87 android::FifoBuffer *mUpCommandQueue; 88 android::FifoBuffer *mDownDataQueue; 89 bool mOutputFreeRunning; 90 android::fifo_counter_t mDataReadCounter; // only used if free-running 91 android::fifo_counter_t mDataWriteCounter; // only used if free-running 92}; 93 94} // namespace aaudio 95 96#endif //AAUDIO_AUDIO_ENDPOINT_H 97