Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 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 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 17 | #ifndef AAUDIO_AUDIO_ENDPOINT_H |
| 18 | #define AAUDIO_AUDIO_ENDPOINT_H |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 19 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 20 | #include <aaudio/AAudio.h> |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 21 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 22 | #include "AAudioServiceMessage.h" |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 23 | #include "AudioEndpointParcelable.h" |
| 24 | #include "fifo/FifoBuffer.h" |
| 25 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 26 | namespace aaudio { |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 27 | |
| 28 | #define ENDPOINT_DATA_QUEUE_SIZE_MIN 64 |
| 29 | |
| 30 | /** |
| 31 | * A sink for audio. |
| 32 | * Used by the client code. |
| 33 | */ |
| 34 | class AudioEndpoint { |
| 35 | |
| 36 | public: |
| 37 | AudioEndpoint(); |
| 38 | virtual ~AudioEndpoint(); |
| 39 | |
| 40 | /** |
| 41 | * Configure based on the EndPointDescriptor_t. |
| 42 | */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 43 | aaudio_result_t configure(const EndpointDescriptor *pEndpointDescriptor); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 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 | */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 49 | aaudio_result_t readUpCommand(AAudioServiceMessage *commandPtr); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Non-blocking write. |
| 53 | * @return framesWritten or a negative error code. |
| 54 | */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 55 | aaudio_result_t writeDataNow(const void *buffer, int32_t numFrames); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Set the read index in the downData queue. |
| 59 | * This is needed if the reader is not updating the index itself. |
| 60 | */ |
| 61 | void setDownDataReadCounter(fifo_counter_t framesRead); |
| 62 | fifo_counter_t getDownDataReadCounter(); |
| 63 | |
| 64 | void setDownDataWriteCounter(fifo_counter_t framesWritten); |
| 65 | fifo_counter_t getDownDataWriteCounter(); |
| 66 | |
| 67 | /** |
| 68 | * The result is not valid until after configure() is called. |
| 69 | * |
| 70 | * @return true if the output buffer read position is not updated, eg. DMA |
| 71 | */ |
| 72 | bool isOutputFreeRunning() const { return mOutputFreeRunning; } |
| 73 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 74 | int32_t setBufferSizeInFrames(aaudio_size_frames_t requestedFrames, |
| 75 | aaudio_size_frames_t *actualFrames); |
| 76 | aaudio_size_frames_t getBufferSizeInFrames() const; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 77 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 78 | aaudio_size_frames_t getBufferCapacityInFrames() const; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 79 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 80 | aaudio_size_frames_t getFullFramesAvailable(); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 81 | |
| 82 | private: |
| 83 | FifoBuffer * mUpCommandQueue; |
| 84 | FifoBuffer * mDownDataQueue; |
| 85 | bool mOutputFreeRunning; |
| 86 | fifo_counter_t mDataReadCounter; // only used if free-running |
| 87 | fifo_counter_t mDataWriteCounter; // only used if free-running |
| 88 | }; |
| 89 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 90 | } // namespace aaudio |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 91 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame^] | 92 | #endif //AAUDIO_AUDIO_ENDPOINT_H |