-
Notifications
You must be signed in to change notification settings - Fork 0
/
list-devices.cc
62 lines (51 loc) · 1.37 KB
/
list-devices.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
Copyright (C) 2019 Andrew Sveikauskas
Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
*/
#include <AudioDevice.h>
#include <common/logger.h>
#include <stdio.h>
#if defined(_WINDOWS)
int wmain(int argc, wchar_t **argv)
#else
int main(int argc, char **argv)
#endif
{
log_register_callback(
[] (void *np, const char *p) -> void { fputs(p, stderr); },
nullptr
);
error err;
int ndevs;
common::Pointer<audio::DeviceEnumerator> devEnum;
audio::GetDeviceEnumerator(devEnum.GetAddressOf(), &err);
ERROR_CHECK(&err);
ndevs = devEnum->GetDeviceCount(&err);
ERROR_CHECK(&err);
printf("%d audio devices.\n", ndevs);
for (int i=0; i<ndevs; ++i)
{
common::Pointer<audio::Device> dev;
const char *descr = nullptr;
devEnum->GetDevice(i, dev.GetAddressOf(), &err);
if (ERROR_FAILED(&err) || !dev.Get())
{
error_clear(&err);
descr = "Failed to open";
}
else
{
descr = dev->GetName(&err);
if (ERROR_FAILED(&err))
{
error_clear(&err);
descr = "Failed to get name";
}
}
printf("Device %d: %s\n", i, descr);
}
exit:
return ERROR_FAILED(&err) ? 1 : 0;
}