blob: 117d18848bd21c60209b4297c6ec49182f31f332 [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
jiabindaf49952019-11-22 14:10:57 -080045const DeviceTypeSet& getAudioDeviceOutAllUsbSet() {
46 static const DeviceTypeSet audioDeviceOutAllUsbSet = DeviceTypeSet(
47 std::begin(AUDIO_DEVICE_OUT_ALL_USB_ARRAY),
48 std::end(AUDIO_DEVICE_OUT_ALL_USB_ARRAY));
49 return audioDeviceOutAllUsbSet;
50}
51
jiabin9a3361e2019-10-01 09:38:30 -070052const DeviceTypeSet& getAudioDeviceInAllSet() {
53 static const DeviceTypeSet audioDeviceInAllSet = DeviceTypeSet(
54 std::begin(AUDIO_DEVICE_IN_ALL_ARRAY),
55 std::end(AUDIO_DEVICE_IN_ALL_ARRAY));
56 return audioDeviceInAllSet;
57}
58
jiabindaf49952019-11-22 14:10:57 -080059const DeviceTypeSet& getAudioDeviceInAllUsbSet() {
60 static const DeviceTypeSet audioDeviceInAllUsbSet = DeviceTypeSet(
61 std::begin(AUDIO_DEVICE_IN_ALL_USB_ARRAY),
62 std::end(AUDIO_DEVICE_IN_ALL_USB_ARRAY));
63 return audioDeviceInAllUsbSet;
64}
65
Pattydd807582021-11-04 21:01:03 +080066const DeviceTypeSet& getAudioDeviceOutAllBleSet() {
67 static const DeviceTypeSet audioDeviceOutAllBleSet = DeviceTypeSet(
68 std::begin(AUDIO_DEVICE_OUT_ALL_BLE_ARRAY),
69 std::end(AUDIO_DEVICE_OUT_ALL_BLE_ARRAY));
70 return audioDeviceOutAllBleSet;
71}
72
Mikhail Naganovfcfb5162021-12-02 01:35:15 +000073std::string deviceTypesToString(const DeviceTypeSet &deviceTypes) {
jiabinc52b1ff2019-10-31 17:20:42 -070074 if (deviceTypes.empty()) {
Mikhail Naganovfcfb5162021-12-02 01:35:15 +000075 return "Empty device types";
jiabinc52b1ff2019-10-31 17:20:42 -070076 }
Mikhail Naganovfcfb5162021-12-02 01:35:15 +000077 std::stringstream ss;
78 for (auto it = deviceTypes.begin(); it != deviceTypes.end(); ++it) {
79 if (it != deviceTypes.begin()) {
80 ss << ", ";
jiabin9a3361e2019-10-01 09:38:30 -070081 }
Mikhail Naganovfcfb5162021-12-02 01:35:15 +000082 const char* strType = audio_device_to_string(*it);
83 if (strlen(strType) != 0) {
84 ss << strType;
85 } else {
86 ss << "unknown type:0x" << std::hex << *it;
jiabin9a3361e2019-10-01 09:38:30 -070087 }
88 }
Mikhail Naganovfcfb5162021-12-02 01:35:15 +000089 return ss.str();
jiabin9a3361e2019-10-01 09:38:30 -070090}
91
92std::string dumpDeviceTypes(const DeviceTypeSet &deviceTypes) {
Mikhail Naganovfcfb5162021-12-02 01:35:15 +000093 std::stringstream ss;
94 for (auto it = deviceTypes.begin(); it != deviceTypes.end(); ++it) {
95 if (it != deviceTypes.begin()) {
96 ss << ", ";
jiabin9a3361e2019-10-01 09:38:30 -070097 }
Mikhail Naganovfcfb5162021-12-02 01:35:15 +000098 ss << "0x" << std::hex << (*it);
jiabin9a3361e2019-10-01 09:38:30 -070099 }
Mikhail Naganovfcfb5162021-12-02 01:35:15 +0000100 return ss.str();
jiabinc52b1ff2019-10-31 17:20:42 -0700101}
102
jiabin9a3361e2019-10-01 09:38:30 -0700103} // namespace android