• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
22 namespace android {
23 
getAudioDeviceOutAllSet()24 const 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 
getAudioDeviceOutAllA2dpSet()31 const 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 
getAudioDeviceOutAllScoSet()38 const 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 
getAudioDeviceOutAllUsbSet()45 const 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 
getAudioDeviceInAllSet()52 const 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 
getAudioDeviceInAllUsbSet()59 const 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 
deviceTypesToString(const DeviceTypeSet & deviceTypes,std::string & str)66 bool deviceTypesToString(const DeviceTypeSet &deviceTypes, std::string &str) {
67     if (deviceTypes.empty()) {
68         str = "Empty device types";
69         return true;
70     }
71     bool ret = true;
72     for (auto it = deviceTypes.begin(); it != deviceTypes.end();) {
73         std::string deviceTypeStr;
74         ret = audio_is_output_device(*it) ?
75               OutputDeviceConverter::toString(*it, deviceTypeStr) :
76               InputDeviceConverter::toString(*it, deviceTypeStr);
77         if (!ret) {
78             break;
79         }
80         str.append(deviceTypeStr);
81         if (++it != deviceTypes.end()) {
82             str.append(" , ");
83         }
84     }
85     if (!ret) {
86         str = "Unknown values";
87     }
88     return ret;
89 }
90 
dumpDeviceTypes(const DeviceTypeSet & deviceTypes)91 std::string dumpDeviceTypes(const DeviceTypeSet &deviceTypes) {
92     std::string ret;
93     for (auto it = deviceTypes.begin(); it != deviceTypes.end();) {
94         std::stringstream ss;
95         ss << "0x" << std::hex << (*it);
96         ret.append(ss.str());
97         if (++it != deviceTypes.end()) {
98             ret.append(" , ");
99         }
100     }
101     return ret;
102 }
103 
toString(const DeviceTypeSet & deviceTypes)104 std::string toString(const DeviceTypeSet& deviceTypes) {
105     std::string ret;
106     deviceTypesToString(deviceTypes, ret);
107     return ret;
108 }
109 
110 } // namespace android
111