Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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_AAUDIO_ENDPOINT_MANAGER_H |
| 18 | #define AAUDIO_AAUDIO_ENDPOINT_MANAGER_H |
| 19 | |
| 20 | #include <map> |
| 21 | #include <mutex> |
| 22 | #include <utils/Singleton.h> |
| 23 | |
| 24 | #include "binding/AAudioServiceMessage.h" |
| 25 | #include "AAudioServiceEndpoint.h" |
Phil Burk | 87c9f64 | 2017-05-17 07:22:39 -0700 | [diff] [blame] | 26 | #include "AAudioServiceEndpointCapture.h" |
| 27 | #include "AAudioServiceEndpointPlay.h" |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 28 | |
| 29 | namespace aaudio { |
| 30 | |
| 31 | class AAudioEndpointManager : public android::Singleton<AAudioEndpointManager>{ |
| 32 | public: |
| 33 | AAudioEndpointManager(); |
| 34 | ~AAudioEndpointManager() = default; |
| 35 | |
| 36 | /** |
Phil Burk | 4501b35 | 2017-06-29 18:12:36 -0700 | [diff] [blame^] | 37 | * Returns information about the state of the this class. |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 38 | * |
| 39 | * Will attempt to get the object lock, but will proceed |
| 40 | * even if it cannot. |
| 41 | * |
| 42 | * Each line of information ends with a newline. |
| 43 | * |
Phil Burk | 4501b35 | 2017-06-29 18:12:36 -0700 | [diff] [blame^] | 44 | * @return a string with useful information |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 45 | */ |
| 46 | std::string dump() const; |
| 47 | |
| 48 | /** |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 49 | * Find a service endpoint for the given deviceId and direction. |
Phil Burk | ec89b2e | 2017-06-20 15:05:06 -0700 | [diff] [blame] | 50 | * If an endpoint does not already exist then try to create one. |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 51 | * |
| 52 | * @param deviceId |
| 53 | * @param direction |
| 54 | * @return endpoint or nullptr |
| 55 | */ |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 56 | AAudioServiceEndpoint *openEndpoint(android::AAudioService &audioService, |
Eric Laurent | a17ae74 | 2017-06-29 15:43:55 -0700 | [diff] [blame] | 57 | const AAudioStreamConfiguration& configuration, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 58 | aaudio_direction_t direction); |
| 59 | |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame] | 60 | void closeEndpoint(AAudioServiceEndpoint *serviceEndpoint); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 61 | |
| 62 | private: |
| 63 | |
Andy Hung | 47c5e53 | 2017-06-26 18:28:00 -0700 | [diff] [blame] | 64 | mutable std::mutex mLock; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 65 | |
Eric Laurent | a17ae74 | 2017-06-29 15:43:55 -0700 | [diff] [blame] | 66 | std::vector<AAudioServiceEndpointCapture *> mInputs; |
| 67 | std::vector<AAudioServiceEndpointPlay *> mOutputs; |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 68 | |
| 69 | }; |
| 70 | |
| 71 | } /* namespace aaudio */ |
| 72 | |
| 73 | #endif //AAUDIO_AAUDIO_ENDPOINT_MANAGER_H |