Phil Burk | 2355edb | 2016-12-26 13:54:02 -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_AAUDIO_SERVICE_STREAM_BASE_H |
| 18 | #define AAUDIO_AAUDIO_SERVICE_STREAM_BASE_H |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 19 | |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 20 | #include <utils/Mutex.h> |
| 21 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 22 | #include "IAAudioService.h" |
| 23 | #include "AAudioServiceDefinitions.h" |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 24 | #include "fifo/FifoBuffer.h" |
| 25 | #include "SharedRingBuffer.h" |
| 26 | #include "AudioEndpointParcelable.h" |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 27 | #include "AAudioThread.h" |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 28 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 29 | namespace aaudio { |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 30 | |
| 31 | // We expect the queue to only have a few commands. |
| 32 | // This should be way more than we need. |
| 33 | #define QUEUE_UP_CAPACITY_COMMANDS (128) |
| 34 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 35 | class AAudioServiceStreamBase { |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 36 | |
| 37 | public: |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 38 | AAudioServiceStreamBase(); |
| 39 | virtual ~AAudioServiceStreamBase(); |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 40 | |
| 41 | enum { |
| 42 | ILLEGAL_THREAD_ID = 0 |
| 43 | }; |
| 44 | |
| 45 | /** |
| 46 | * Fill in a parcelable description of stream. |
| 47 | */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 48 | virtual aaudio_result_t getDescription(aaudio::AudioEndpointParcelable &parcelable) = 0; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Open the device. |
| 52 | */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 53 | virtual aaudio_result_t open(aaudio::AAudioStreamRequest &request, |
| 54 | aaudio::AAudioStreamConfiguration &configuration) = 0; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * Start the flow of data. |
| 58 | */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 59 | virtual aaudio_result_t start() = 0; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Stop the flow of data such that start() can resume with loss of data. |
| 63 | */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 64 | virtual aaudio_result_t pause() = 0; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * Discard any data held by the underlying HAL or Service. |
| 68 | */ |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 69 | virtual aaudio_result_t flush() = 0; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 70 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 71 | virtual aaudio_result_t close() = 0; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 72 | |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 73 | virtual void sendCurrentTimestamp() = 0; |
| 74 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame^] | 75 | int32_t getFramesPerBurst() { |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 76 | return mFramesPerBurst; |
| 77 | } |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 78 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 79 | virtual void sendServiceEvent(aaudio_service_event_t event, |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 80 | int32_t data1 = 0, |
| 81 | int64_t data2 = 0); |
| 82 | |
| 83 | virtual void setRegisteredThread(pid_t pid) { |
| 84 | mRegisteredClientThread = pid; |
| 85 | } |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 86 | |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 87 | virtual pid_t getRegisteredThread() { |
| 88 | return mRegisteredClientThread; |
| 89 | } |
| 90 | |
| 91 | protected: |
| 92 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame^] | 93 | pid_t mRegisteredClientThread = ILLEGAL_THREAD_ID; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 94 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame^] | 95 | SharedRingBuffer* mUpMessageQueue; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 96 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame^] | 97 | int32_t mSampleRate = 0; |
| 98 | int32_t mBytesPerFrame = 0; |
| 99 | int32_t mFramesPerBurst = 0; |
| 100 | int32_t mCapacityInFrames = 0; |
| 101 | int32_t mCapacityInBytes = 0; |
Phil Burk | dec33ab | 2017-01-17 14:48:16 -0800 | [diff] [blame] | 102 | |
Phil Burk | 3316d5e | 2017-02-15 11:23:01 -0800 | [diff] [blame^] | 103 | android::Mutex mLockUpMessageQueue; |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 106 | } /* namespace aaudio */ |
Phil Burk | 2355edb | 2016-12-26 13:54:02 -0800 | [diff] [blame] | 107 | |
Phil Burk | 5ed503c | 2017-02-01 09:38:15 -0800 | [diff] [blame] | 108 | #endif //AAUDIO_AAUDIO_SERVICE_STREAM_BASE_H |