blob: db1103dc9c6c74329126f185c95ca0d51fc5a4f7 [file] [log] [blame]
Phil Burkc0c70e32017-02-09 13:18:38 -08001/*
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 Burk87c9f642017-05-17 07:22:39 -070026#include "AAudioServiceEndpointCapture.h"
27#include "AAudioServiceEndpointPlay.h"
Phil Burkc0c70e32017-02-09 13:18:38 -080028
29namespace aaudio {
30
31class AAudioEndpointManager : public android::Singleton<AAudioEndpointManager>{
32public:
33 AAudioEndpointManager();
34 ~AAudioEndpointManager() = default;
35
36 /**
37 * Find a service endpoint for the given deviceId and direction.
38 * If an endpoint does not already exist then it will try to create one.
39 *
40 * @param deviceId
41 * @param direction
42 * @return endpoint or nullptr
43 */
Phil Burk71f35bb2017-04-13 16:05:07 -070044 AAudioServiceEndpoint *openEndpoint(android::AAudioService &audioService,
Phil Burkc0c70e32017-02-09 13:18:38 -080045 int32_t deviceId,
46 aaudio_direction_t direction);
47
Phil Burk71f35bb2017-04-13 16:05:07 -070048 void closeEndpoint(AAudioServiceEndpoint *serviceEndpoint);
Phil Burkc0c70e32017-02-09 13:18:38 -080049
50private:
51
52 std::mutex mLock;
53
Phil Burk87c9f642017-05-17 07:22:39 -070054 std::map<int32_t, AAudioServiceEndpointCapture *> mInputs;
55 std::map<int32_t, AAudioServiceEndpointPlay *> mOutputs;
Phil Burkc0c70e32017-02-09 13:18:38 -080056
57};
58
59} /* namespace aaudio */
60
61#endif //AAUDIO_AAUDIO_ENDPOINT_MANAGER_H