jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 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 | |
| 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 | |
| 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 | |
| 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 | |
jiabin | daf4995 | 2019-11-22 14:10:57 -0800 | [diff] [blame] | 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 | |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 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 | |
jiabin | daf4995 | 2019-11-22 14:10:57 -0800 | [diff] [blame] | 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 | |
Patty | dd80758 | 2021-11-04 21:01:03 +0800 | [diff] [blame] | 66 | const 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 | |
Eric Laurent | 96d1dda | 2022-03-14 17:14:19 +0100 | [diff] [blame^] | 73 | const DeviceTypeSet& getAudioDeviceOutLeAudioUnicastSet() { |
| 74 | static const DeviceTypeSet audioDeviceOutLeAudioUnicastSet = DeviceTypeSet( |
| 75 | std::begin(AUDIO_DEVICE_OUT_BLE_UNICAST_ARRAY), |
| 76 | std::end(AUDIO_DEVICE_OUT_BLE_UNICAST_ARRAY)); |
| 77 | return audioDeviceOutLeAudioUnicastSet; |
| 78 | } |
| 79 | |
Mikhail Naganov | fcfb516 | 2021-12-02 01:35:15 +0000 | [diff] [blame] | 80 | std::string deviceTypesToString(const DeviceTypeSet &deviceTypes) { |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 81 | if (deviceTypes.empty()) { |
Mikhail Naganov | fcfb516 | 2021-12-02 01:35:15 +0000 | [diff] [blame] | 82 | return "Empty device types"; |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 83 | } |
Mikhail Naganov | fcfb516 | 2021-12-02 01:35:15 +0000 | [diff] [blame] | 84 | std::stringstream ss; |
| 85 | for (auto it = deviceTypes.begin(); it != deviceTypes.end(); ++it) { |
| 86 | if (it != deviceTypes.begin()) { |
| 87 | ss << ", "; |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 88 | } |
Mikhail Naganov | fcfb516 | 2021-12-02 01:35:15 +0000 | [diff] [blame] | 89 | const char* strType = audio_device_to_string(*it); |
| 90 | if (strlen(strType) != 0) { |
| 91 | ss << strType; |
| 92 | } else { |
| 93 | ss << "unknown type:0x" << std::hex << *it; |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 94 | } |
| 95 | } |
Mikhail Naganov | fcfb516 | 2021-12-02 01:35:15 +0000 | [diff] [blame] | 96 | return ss.str(); |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Hongguang | 48dc871 | 2021-12-15 15:35:08 -0800 | [diff] [blame] | 99 | bool deviceTypesToString(const DeviceTypeSet &deviceTypes, std::string &str) { |
| 100 | str = deviceTypesToString(deviceTypes); |
| 101 | return true; |
| 102 | } |
| 103 | |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 104 | std::string dumpDeviceTypes(const DeviceTypeSet &deviceTypes) { |
Mikhail Naganov | fcfb516 | 2021-12-02 01:35:15 +0000 | [diff] [blame] | 105 | std::stringstream ss; |
| 106 | for (auto it = deviceTypes.begin(); it != deviceTypes.end(); ++it) { |
| 107 | if (it != deviceTypes.begin()) { |
| 108 | ss << ", "; |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 109 | } |
Mikhail Naganov | fcfb516 | 2021-12-02 01:35:15 +0000 | [diff] [blame] | 110 | ss << "0x" << std::hex << (*it); |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 111 | } |
Mikhail Naganov | fcfb516 | 2021-12-02 01:35:15 +0000 | [diff] [blame] | 112 | return ss.str(); |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 113 | } |
| 114 | |
jiabin | 9a3361e | 2019-10-01 09:38:30 -0700 | [diff] [blame] | 115 | } // namespace android |