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" |
| 26 | |
| 27 | namespace aaudio { |
| 28 | |
| 29 | class AAudioEndpointManager : public android::Singleton<AAudioEndpointManager>{ |
| 30 | public: |
| 31 | AAudioEndpointManager(); |
| 32 | ~AAudioEndpointManager() = default; |
| 33 | |
| 34 | /** |
| 35 | * Find a service endpoint for the given deviceId and direction. |
| 36 | * If an endpoint does not already exist then it will try to create one. |
| 37 | * |
| 38 | * @param deviceId |
| 39 | * @param direction |
| 40 | * @return endpoint or nullptr |
| 41 | */ |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame^] | 42 | AAudioServiceEndpoint *openEndpoint(android::AAudioService &audioService, |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 43 | int32_t deviceId, |
| 44 | aaudio_direction_t direction); |
| 45 | |
Phil Burk | 71f35bb | 2017-04-13 16:05:07 -0700 | [diff] [blame^] | 46 | void closeEndpoint(AAudioServiceEndpoint *serviceEndpoint); |
Phil Burk | c0c70e3 | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 47 | |
| 48 | private: |
| 49 | |
| 50 | std::mutex mLock; |
| 51 | |
| 52 | // We need separate inputs and outputs because they may both have device==0. |
| 53 | // TODO review |
| 54 | std::map<int32_t, AAudioServiceEndpoint *> mInputs; |
| 55 | std::map<int32_t, AAudioServiceEndpoint *> mOutputs; |
| 56 | |
| 57 | }; |
| 58 | |
| 59 | } /* namespace aaudio */ |
| 60 | |
| 61 | #endif //AAUDIO_AAUDIO_ENDPOINT_MANAGER_H |