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 | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_AAUDIO_AUDIO_ENDPOINT_H |
| 18 | #define ANDROID_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 | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 22 | #include "binding/AAudioServiceMessage.h" |
| 23 | #include "binding/AudioEndpointParcelable.h" |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 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 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 28 | #define ENDPOINT_DATA_QUEUE_SIZE_MIN 48 |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * A sink for audio. |
| 32 | * Used by the client code. |
| 33 | */ |
| 34 | class AudioEndpoint { |
| 35 | |
| 36 | public: |
| 37 | AudioEndpoint(); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Configure based on the EndPointDescriptor_t. |
| 41 | */ |
Phil Burk | fd34a93 | 2017-07-19 07:03:52 -0700 | [diff] [blame] | 42 | aaudio_result_t configure(const EndpointDescriptor *pEndpointDescriptor, |
| 43 | aaudio_direction_t direction); |
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 | |
Phil Burk | fd34a93 | 2017-07-19 07:03:52 -0700 | [diff] [blame] | 51 | int32_t getEmptyFramesAvailable(android::WrappingBuffer *wrappingBuffer); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 52 | |
Phil Burk | 4485d41 | 2017-05-09 15:55:02 -0700 | [diff] [blame] | 53 | int32_t getEmptyFramesAvailable(); |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 54 | |
Phil Burk | fd34a93 | 2017-07-19 07:03:52 -0700 | [diff] [blame] | 55 | int32_t getFullFramesAvailable(android::WrappingBuffer *wrappingBuffer); |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 56 | |
Phil Burk | 4485d41 | 2017-05-09 15:55:02 -0700 | [diff] [blame] | 57 | int32_t getFullFramesAvailable(); |
| 58 | |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 59 | void advanceReadIndex(int32_t deltaFrames); |
| 60 | |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 61 | void advanceWriteIndex(int32_t deltaFrames); |
| 62 | |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 63 | /** |
| 64 | * Set the read index in the downData queue. |
| 65 | * This is needed if the reader is not updating the index itself. |
| 66 | */ |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 67 | void setDataReadCounter(android::fifo_counter_t framesRead); |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 68 | |
Phil Burk | 5edc4ea | 2020-04-17 08:15:42 -0700 | [diff] [blame^] | 69 | android::fifo_counter_t getDataReadCounter() const; |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 70 | |
| 71 | void setDataWriteCounter(android::fifo_counter_t framesWritten); |
| 72 | |
Phil Burk | 5edc4ea | 2020-04-17 08:15:42 -0700 | [diff] [blame^] | 73 | android::fifo_counter_t getDataWriteCounter() const; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * The result is not valid until after configure() is called. |
| 77 | * |
| 78 | * @return true if the output buffer read position is not updated, eg. DMA |
| 79 | */ |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 80 | bool isFreeRunning() const { return mFreeRunning; } |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 81 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 82 | int32_t setBufferSizeInFrames(int32_t requestedFrames, |
| 83 | int32_t *actualFrames); |
| 84 | int32_t getBufferSizeInFrames() const; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 85 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame] | 86 | int32_t getBufferCapacityInFrames() const; |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 87 | |
Phil Burk | ea04d97 | 2017-08-07 12:30:44 -0700 | [diff] [blame] | 88 | /** |
| 89 | * Write zeros to the data queue memory. |
| 90 | */ |
| 91 | void eraseDataMemory(); |
| 92 | |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 93 | void dump() const; |
| 94 | |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 95 | private: |
Phil Burk | 5edc4ea | 2020-04-17 08:15:42 -0700 | [diff] [blame^] | 96 | std::unique_ptr<android::FifoBuffer> mUpCommandQueue; |
| 97 | std::unique_ptr<android::FifoBuffer> mDataQueue; |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 98 | bool mFreeRunning; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 99 | android::fifo_counter_t mDataReadCounter; // only used if free-running |
| 100 | android::fifo_counter_t mDataWriteCounter; // only used if free-running |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 103 | } // namespace aaudio |
Phil Burk | 204a163 | 2017-01-03 17:23:43 -0800 | [diff] [blame] | 104 | |
Phil Burk | 5204d31 | 2017-05-04 17:16:13 -0700 | [diff] [blame] | 105 | #endif //ANDROID_AAUDIO_AUDIO_ENDPOINT_H |