clang-format
This commit is contained in:
parent
a6c1649493
commit
3d8a99f541
43 changed files with 1917 additions and 1872 deletions
113
tools/audio.cpp
113
tools/audio.cpp
|
|
@ -2,9 +2,9 @@
|
|||
// Created by loki on 1/24/20.
|
||||
//
|
||||
|
||||
#include <roapi.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <audioclient.h>
|
||||
#include <mmdeviceapi.h>
|
||||
#include <roapi.h>
|
||||
|
||||
#include <synchapi.h>
|
||||
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
#include "sunshine/utility.h"
|
||||
|
||||
DEFINE_PROPERTYKEY(PKEY_Device_DeviceDesc, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 2); // DEVPROP_TYPE_STRING
|
||||
DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14); // DEVPROP_TYPE_STRING
|
||||
DEFINE_PROPERTYKEY(PKEY_Device_DeviceDesc, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 2); // DEVPROP_TYPE_STRING
|
||||
DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14); // DEVPROP_TYPE_STRING
|
||||
DEFINE_PROPERTYKEY(PKEY_DeviceInterface_FriendlyName, 0x026e516e, 0xb814, 0x414b, 0x83, 0xcd, 0x85, 0x6d, 0x6f, 0xef, 0x48, 0x22, 2);
|
||||
|
||||
using namespace std::literals;
|
||||
|
|
@ -27,7 +27,7 @@ const IID IID_IAudioClient = __uuidof(IAudioClient);
|
|||
const IID IID_IAudioCaptureClient = __uuidof(IAudioCaptureClient);
|
||||
|
||||
constexpr auto SAMPLE_RATE = 48000;
|
||||
int device_state_filter = DEVICE_STATE_ACTIVE;
|
||||
int device_state_filter = DEVICE_STATE_ACTIVE;
|
||||
|
||||
namespace audio {
|
||||
template<class T>
|
||||
|
|
@ -73,32 +73,26 @@ struct format_t {
|
|||
std::string_view name;
|
||||
int channels;
|
||||
int channel_mask;
|
||||
} formats [] {
|
||||
{
|
||||
"Mono"sv,
|
||||
} formats[] {
|
||||
{ "Mono"sv,
|
||||
1,
|
||||
SPEAKER_FRONT_CENTER
|
||||
},
|
||||
{
|
||||
"Stereo"sv,
|
||||
SPEAKER_FRONT_CENTER },
|
||||
{ "Stereo"sv,
|
||||
2,
|
||||
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT
|
||||
},
|
||||
{
|
||||
"Surround 5.1"sv,
|
||||
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT },
|
||||
{ "Surround 5.1"sv,
|
||||
6,
|
||||
SPEAKER_FRONT_LEFT |
|
||||
SPEAKER_FRONT_RIGHT |
|
||||
SPEAKER_FRONT_CENTER |
|
||||
SPEAKER_LOW_FREQUENCY |
|
||||
SPEAKER_BACK_LEFT |
|
||||
SPEAKER_BACK_RIGHT
|
||||
}
|
||||
SPEAKER_FRONT_LEFT |
|
||||
SPEAKER_FRONT_RIGHT |
|
||||
SPEAKER_FRONT_CENTER |
|
||||
SPEAKER_LOW_FREQUENCY |
|
||||
SPEAKER_BACK_LEFT |
|
||||
SPEAKER_BACK_RIGHT }
|
||||
};
|
||||
|
||||
void set_wave_format(audio::wave_format_t &wave_format, const format_t &format) {
|
||||
wave_format->nChannels = format.channels;
|
||||
wave_format->nBlockAlign = wave_format->nChannels * wave_format->wBitsPerSample / 8;
|
||||
wave_format->nChannels = format.channels;
|
||||
wave_format->nBlockAlign = wave_format->nChannels * wave_format->wBitsPerSample / 8;
|
||||
wave_format->nAvgBytesPerSec = wave_format->nSamplesPerSec * wave_format->nBlockAlign;
|
||||
|
||||
if(wave_format->wFormatTag == WAVE_FORMAT_EXTENSIBLE) {
|
||||
|
|
@ -112,7 +106,7 @@ audio_client_t make_audio_client(device_t &device, const format_t &format) {
|
|||
IID_IAudioClient,
|
||||
CLSCTX_ALL,
|
||||
nullptr,
|
||||
(void **) &audio_client);
|
||||
(void **)&audio_client);
|
||||
|
||||
if(FAILED(status)) {
|
||||
std::cout << "Couldn't activate Device: [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
|
||||
|
|
@ -123,7 +117,7 @@ audio_client_t make_audio_client(device_t &device, const format_t &format) {
|
|||
wave_format_t wave_format;
|
||||
status = audio_client->GetMixFormat(&wave_format);
|
||||
|
||||
if (FAILED(status)) {
|
||||
if(FAILED(status)) {
|
||||
std::cout << "Couldn't acquire Wave Format [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
|
||||
|
||||
return nullptr;
|
||||
|
|
@ -132,23 +126,23 @@ audio_client_t make_audio_client(device_t &device, const format_t &format) {
|
|||
wave_format->wBitsPerSample = 16;
|
||||
wave_format->nSamplesPerSec = SAMPLE_RATE;
|
||||
switch(wave_format->wFormatTag) {
|
||||
case WAVE_FORMAT_PCM:
|
||||
case WAVE_FORMAT_PCM:
|
||||
break;
|
||||
case WAVE_FORMAT_IEEE_FLOAT:
|
||||
break;
|
||||
case WAVE_FORMAT_EXTENSIBLE: {
|
||||
auto wave_ex = (PWAVEFORMATEXTENSIBLE)wave_format.get();
|
||||
if(IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, wave_ex->SubFormat)) {
|
||||
wave_ex->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
|
||||
wave_ex->Samples.wValidBitsPerSample = 16;
|
||||
break;
|
||||
case WAVE_FORMAT_IEEE_FLOAT:
|
||||
break;
|
||||
case WAVE_FORMAT_EXTENSIBLE: {
|
||||
auto wave_ex = (PWAVEFORMATEXTENSIBLE) wave_format.get();
|
||||
if (IsEqualGUID(KSDATAFORMAT_SUBTYPE_IEEE_FLOAT, wave_ex->SubFormat)) {
|
||||
wave_ex->SubFormat = KSDATAFORMAT_SUBTYPE_PCM;
|
||||
wave_ex->Samples.wValidBitsPerSample = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << "Unsupported Sub Format for WAVE_FORMAT_EXTENSIBLE: [0x"sv << util::hex(wave_ex->SubFormat).to_string_view() << ']' << std::endl;
|
||||
}
|
||||
default:
|
||||
std::cout << "Unsupported Wave Format: [0x"sv << util::hex(wave_format->wFormatTag).to_string_view() << ']' << std::endl;
|
||||
return nullptr;
|
||||
|
||||
std::cout << "Unsupported Sub Format for WAVE_FORMAT_EXTENSIBLE: [0x"sv << util::hex(wave_ex->SubFormat).to_string_view() << ']' << std::endl;
|
||||
}
|
||||
default:
|
||||
std::cout << "Unsupported Wave Format: [0x"sv << util::hex(wave_format->wFormatTag).to_string_view() << ']' << std::endl;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
set_wave_format(wave_format, format);
|
||||
|
|
@ -191,18 +185,18 @@ void print_device(device_t &device) {
|
|||
|
||||
std::wstring device_state_string = L"Unknown"s;
|
||||
switch(device_state) {
|
||||
case DEVICE_STATE_ACTIVE:
|
||||
device_state_string = L"Active"s;
|
||||
break;
|
||||
case DEVICE_STATE_DISABLED:
|
||||
device_state_string = L"Disabled"s;
|
||||
break;
|
||||
case DEVICE_STATE_UNPLUGGED:
|
||||
device_state_string = L"Unplugged"s;
|
||||
break;
|
||||
case DEVICE_STATE_NOTPRESENT:
|
||||
device_state_string = L"Not present"s;
|
||||
break;
|
||||
case DEVICE_STATE_ACTIVE:
|
||||
device_state_string = L"Active"s;
|
||||
break;
|
||||
case DEVICE_STATE_DISABLED:
|
||||
device_state_string = L"Disabled"s;
|
||||
break;
|
||||
case DEVICE_STATE_UNPLUGGED:
|
||||
device_state_string = L"Unplugged"s;
|
||||
break;
|
||||
case DEVICE_STATE_NOTPRESENT:
|
||||
device_state_string = L"Not present"s;
|
||||
break;
|
||||
}
|
||||
|
||||
std::wcout
|
||||
|
|
@ -211,7 +205,8 @@ void print_device(device_t &device) {
|
|||
<< L"Device name : "sv << no_null((LPWSTR)device_friendly_name.prop.pszVal) << std::endl
|
||||
<< L"Adapter name : "sv << no_null((LPWSTR)adapter_friendly_name.prop.pszVal) << std::endl
|
||||
<< L"Device description : "sv << no_null((LPWSTR)device_desc.prop.pszVal) << std::endl
|
||||
<< L"Device state : "sv << device_state_string << std::endl << std::endl;
|
||||
<< L"Device state : "sv << device_state_string << std::endl
|
||||
<< std::endl;
|
||||
|
||||
if(device_state != DEVICE_STATE_ACTIVE) {
|
||||
return;
|
||||
|
|
@ -224,7 +219,7 @@ void print_device(device_t &device) {
|
|||
std::cout << format.name << ": "sv << (!audio_client ? "unsupported"sv : "supported"sv) << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace audio
|
||||
|
||||
void print_help() {
|
||||
std::cout
|
||||
|
|
@ -281,9 +276,9 @@ int main(int argc, char *argv[]) {
|
|||
nullptr,
|
||||
CLSCTX_ALL,
|
||||
IID_IMMDeviceEnumerator,
|
||||
(void **) &device_enum);
|
||||
(void **)&device_enum);
|
||||
|
||||
if (FAILED(status)) {
|
||||
if(FAILED(status)) {
|
||||
std::cout << "Couldn't create Device Enumerator: [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
|
||||
|
||||
return -1;
|
||||
|
|
@ -292,7 +287,7 @@ int main(int argc, char *argv[]) {
|
|||
audio::collection_t collection;
|
||||
status = device_enum->EnumAudioEndpoints(eRender, DEVICE_STATEMASK_ALL, &collection);
|
||||
|
||||
if (FAILED(status)) {
|
||||
if(FAILED(status)) {
|
||||
std::cout << "Couldn't enumerate: [0x"sv << util::hex(status).to_string_view() << ']' << std::endl;
|
||||
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue