Select audio endpoint based on config option audio_sink on Windows

This commit is contained in:
loki 2020-01-24 23:17:05 +01:00
parent afbc7d894f
commit 9f0a5825f0
2 changed files with 24 additions and 8 deletions

View File

@ -62,9 +62,13 @@ fec_percentage = 10
# If you do not specify this variable, pulseaudio will select the default monitor device.
#
# You can find the name of the audio sink using the following command:
# !! Linux only !!
# pacmd list-sources | grep "name:"
# audio_sink = alsa_output.pci-0000_09_00.3.analog-stereo.monitor
#
# !! Windows only !!
# tools\audio-info.exe
# audio_sink = {0.0.0.00000000}.{FD47D9CC-4218-4135-9CE2-0C195C87405B}
# !! Windows only !!
# You can select the video card you want to stream:

View File

@ -6,8 +6,11 @@
#include <mmdeviceapi.h>
#include <audioclient.h>
#include <codecvt>
#include <synchapi.h>
#include "sunshine/config.h"
#include "sunshine/main.h"
#include "common.h"
@ -83,14 +86,23 @@ public:
}
device_t::pointer device_p{};
if(config::audio.sink.empty()) {
status = device_enum->GetDefaultAudioEndpoint(
eRender,
eConsole,
&device_p);
}
else {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
auto wstring_device_id = converter.from_bytes(config::audio.sink);
status = device_enum->GetDevice(wstring_device_id.c_str(), &device_p);
}
device.reset(device_p);
if (FAILED(status)) {
BOOST_LOG(error) << "Couldn't create Device [0x"sv << util::hex(status).to_string_view() << ']';
BOOST_LOG(error) << "Couldn't create audio Device [0x"sv << util::hex(status).to_string_view() << ']';
return -1;
}
@ -104,7 +116,7 @@ public:
audio_client.reset(audio_client_p);
if (FAILED(status)) {
BOOST_LOG(error) << "Couldn't activate Device [0x"sv << util::hex(status).to_string_view() << ']';
BOOST_LOG(error) << "Couldn't activate audio Device [0x"sv << util::hex(status).to_string_view() << ']';
return -1;
}
@ -167,7 +179,7 @@ public:
std::uint32_t frames;
status = audio_client->GetBufferSize(&frames);
if (FAILED(status)) {
BOOST_LOG(error) << "Couldn't acquire the number of frames [0x"sv << util::hex(status).to_string_view() << ']';
BOOST_LOG(error) << "Couldn't acquire the number of audio frames [0x"sv << util::hex(status).to_string_view() << ']';
return -1;
}