blob: 1bfe3f94c484d77ff6e76993d2ded9f55b544f93 [file] [log] [blame]
jiabin9a3361e2019-10-01 09:38:30 -07001/*
2 * Copyright (C) 2019 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#include <sstream>
18#include <string>
19
20#include <media/AudioContainers.h>
21
22namespace android {
23
24const DeviceTypeSet& getAudioDeviceOutAllSet() {
25 static const DeviceTypeSet audioDeviceOutAllSet = DeviceTypeSet(
26 std::begin(AUDIO_DEVICE_OUT_ALL_ARRAY),
27 std::end(AUDIO_DEVICE_OUT_ALL_ARRAY));
28 return audioDeviceOutAllSet;
29}
30
31const DeviceTypeSet& getAudioDeviceOutAllA2dpSet() {
32 static const DeviceTypeSet audioDeviceOutAllA2dpSet = DeviceTypeSet(
33 std::begin(AUDIO_DEVICE_OUT_ALL_A2DP_ARRAY),
34 std::end(AUDIO_DEVICE_OUT_ALL_A2DP_ARRAY));
35 return audioDeviceOutAllA2dpSet;
36}
37
38const DeviceTypeSet& getAudioDeviceOutAllScoSet() {
39 static const DeviceTypeSet audioDeviceOutAllScoSet = DeviceTypeSet(
40 std::begin(AUDIO_DEVICE_OUT_ALL_SCO_ARRAY),
41 std::end(AUDIO_DEVICE_OUT_ALL_SCO_ARRAY));
42 return audioDeviceOutAllScoSet;
43}
44
45const DeviceTypeSet& getAudioDeviceInAllSet() {
46 static const DeviceTypeSet audioDeviceInAllSet = DeviceTypeSet(
47 std::begin(AUDIO_DEVICE_IN_ALL_ARRAY),
48 std::end(AUDIO_DEVICE_IN_ALL_ARRAY));
49 return audioDeviceInAllSet;
50}
51
52bool deviceTypesToString(const DeviceTypeSet &deviceTypes, std::string &str) {
jiabinc52b1ff2019-10-31 17:20:42 -070053 if (deviceTypes.empty()) {
54 str = "Empty device types";
55 return true;
56 }
jiabin9a3361e2019-10-01 09:38:30 -070057 bool ret = true;
58 for (auto it = deviceTypes.begin(); it != deviceTypes.end();) {
59 std::string deviceTypeStr;
60 ret = audio_is_output_device(*it) ?
61 OutputDeviceConverter::toString(*it, deviceTypeStr) :
62 InputDeviceConverter::toString(*it, deviceTypeStr);
63 if (!ret) {
64 break;
65 }
66 str.append(deviceTypeStr);
67 if (++it != deviceTypes.end()) {
68 str.append(" , ");
69 }
70 }
71 if (!ret) {
72 str = "Unknown values";
73 }
74 return ret;
75}
76
77std::string dumpDeviceTypes(const DeviceTypeSet &deviceTypes) {
78 std::string ret;
79 for (auto it = deviceTypes.begin(); it != deviceTypes.end();) {
80 std::stringstream ss;
81 ss << "0x" << std::hex << (*it);
82 ret.append(ss.str());
83 if (++it != deviceTypes.end()) {
84 ret.append(" , ");
85 }
86 }
87 return ret;
88}
89
jiabinc52b1ff2019-10-31 17:20:42 -070090std::string toString(const DeviceTypeSet& deviceTypes) {
91 std::string ret;
92 deviceTypesToString(deviceTypes, ret);
93 return ret;
94}
95
jiabin9a3361e2019-10-01 09:38:30 -070096} // namespace android