| 237 | } |
| 238 | |
| 239 | int main(int argc, char *argv[]) { |
| 240 | CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY); |
| 241 | |
| 242 | auto fg = util::fail_guard([]() { |
| 243 | CoUninitialize(); |
| 244 | }); |
| 245 | |
| 246 | if (argc > 1) { |
| 247 | device_state_filter = 0; |
| 248 | } |
| 249 | |
| 250 | // Set the locale to support wide characters |
| 251 | std::setlocale(LC_ALL, ""); |
| 252 | |
| 253 | for (auto x = 1; x < argc; ++x) { |
| 254 | for (auto p = argv[x]; *p != '\0'; ++p) { |
| 255 | if (*p == ' ') { |
| 256 | *p = '-'; |
| 257 | |
| 258 | continue; |
| 259 | } |
| 260 | |
| 261 | *p = std::tolower(*p); |
| 262 | } |
| 263 | |
| 264 | if (argv[x] == "active"sv) { |
| 265 | device_state_filter |= DEVICE_STATE_ACTIVE; |
| 266 | } else if (argv[x] == "disabled"sv) { |
| 267 | device_state_filter |= DEVICE_STATE_DISABLED; |
| 268 | } else if (argv[x] == "unplugged"sv) { |
| 269 | device_state_filter |= DEVICE_STATE_UNPLUGGED; |
| 270 | } else if (argv[x] == "not-present"sv) { |
| 271 | device_state_filter |= DEVICE_STATE_NOTPRESENT; |
| 272 | } else { |
| 273 | print_help(); |
| 274 | return 2; |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | HRESULT status; |
| 279 | |
| 280 | audio::device_enum_t device_enum; |
| 281 | status = CoCreateInstance( |
| 282 | CLSID_MMDeviceEnumerator, |
| 283 | nullptr, |
| 284 | CLSCTX_ALL, |
| 285 | IID_IMMDeviceEnumerator, |
| 286 | (void **) &device_enum |
| 287 | ); |
| 288 | |
| 289 | if (FAILED(status)) { |
| 290 | std::cout << "Couldn't create Device Enumerator: [0x"sv << util::hex(status).to_string_view() << ']' << std::endl; |
| 291 | |
| 292 | return -1; |
| 293 | } |
| 294 | |
| 295 | audio::collection_t collection; |
| 296 | status = device_enum->EnumAudioEndpoints(eRender, device_state_filter, &collection); |
nothing calls this directly
no test coverage detected