blob: 6d3b52bd7de681e73871122baa1b65de3d25ca58 [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 /**
Andy Hung47c5e532017-06-26 18:28:00 -070037 * Returns EndpointManager information.
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 *
44 * @return a string representing the EndpointManager info
45 */
46 std::string dump() const;
47
48 /**
Phil Burkc0c70e32017-02-09 13:18:38 -080049 * Find a service endpoint for the given deviceId and direction.
Phil Burkec89b2e2017-06-20 15:05:06 -070050 * If an endpoint does not already exist then try to create one.
Phil Burkc0c70e32017-02-09 13:18:38 -080051 *
52 * @param deviceId
53 * @param direction
54 * @return endpoint or nullptr
55 */
Phil Burk71f35bb2017-04-13 16:05:07 -070056 AAudioServiceEndpoint *openEndpoint(android::AAudioService &audioService,
Eric Laurenta17ae742017-06-29 15:43:55 -070057 const AAudioStreamConfiguration& configuration,
Phil Burkc0c70e32017-02-09 13:18:38 -080058 aaudio_direction_t direction);
59
Phil Burk71f35bb2017-04-13 16:05:07 -070060 void closeEndpoint(AAudioServiceEndpoint *serviceEndpoint);
Phil Burkc0c70e32017-02-09 13:18:38 -080061
62private:
63
Andy Hung47c5e532017-06-26 18:28:00 -070064 mutable std::mutex mLock;
Phil Burkc0c70e32017-02-09 13:18:38 -080065
Eric Laurenta17ae742017-06-29 15:43:55 -070066 std::vector<AAudioServiceEndpointCapture *> mInputs;
67 std::vector<AAudioServiceEndpointPlay *> mOutputs;
Phil Burkc0c70e32017-02-09 13:18:38 -080068
69};
70
71} /* namespace aaudio */
72
73#endif //AAUDIO_AAUDIO_ENDPOINT_MANAGER_H