mirror of
https://github.com/LizardByte/Sunshine.git
synced 2025-03-28 19:20:26 +00:00
Allow streaming even if no audio sink is available
This commit is contained in:
parent
e8963b8255
commit
86c854ce97
@ -135,10 +135,16 @@ namespace audio {
|
||||
return;
|
||||
}
|
||||
|
||||
auto init_failure_fg = util::fail_guard([&shutdown_event]() {
|
||||
BOOST_LOG(error) << "Unable to initialize audio capture. The stream will not have audio."sv;
|
||||
|
||||
// Wait for shutdown to be signalled if we fail init.
|
||||
// This allows streaming to continue without audio.
|
||||
shutdown_event->view();
|
||||
});
|
||||
|
||||
auto &control = ref->control;
|
||||
if (!control) {
|
||||
shutdown_event->view();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -181,6 +187,15 @@ namespace audio {
|
||||
}
|
||||
}
|
||||
|
||||
auto frame_size = config.packetDuration * stream->sampleRate / 1000;
|
||||
auto mic = control->microphone(stream->mapping, stream->channelCount, stream->sampleRate, frame_size);
|
||||
if (!mic) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Audio is initialized, so we don't want to print the failure message
|
||||
init_failure_fg.disable();
|
||||
|
||||
// Capture takes place on this thread
|
||||
platf::adjust_thread_priority(platf::thread_priority_e::critical);
|
||||
|
||||
@ -194,16 +209,8 @@ namespace audio {
|
||||
shutdown_event->view();
|
||||
});
|
||||
|
||||
auto frame_size = config.packetDuration * stream->sampleRate / 1000;
|
||||
int samples_per_frame = frame_size * stream->channelCount;
|
||||
|
||||
auto mic = control->microphone(stream->mapping, stream->channelCount, stream->sampleRate, frame_size);
|
||||
if (!mic) {
|
||||
BOOST_LOG(error) << "Couldn't create audio input"sv;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
while (!shutdown_event->peek()) {
|
||||
std::vector<std::int16_t> sample_buffer;
|
||||
sample_buffer.resize(samples_per_frame);
|
||||
|
@ -666,7 +666,13 @@ namespace platf::audio {
|
||||
for (int x = 0; x < (int) ERole_enum_count; ++x) {
|
||||
auto status = policy->SetDefaultEndpoint(wstring_device_id->c_str(), (ERole) x);
|
||||
if (status) {
|
||||
BOOST_LOG(warning) << "Couldn't set ["sv << sink << "] to role ["sv << x << ']';
|
||||
// Depending on the format of the string, we could get either of these errors
|
||||
if (status == HRESULT_FROM_WIN32(ERROR_NOT_FOUND) || status == E_INVALIDARG) {
|
||||
BOOST_LOG(warning) << "Audio sink not found: "sv << sink;
|
||||
}
|
||||
else {
|
||||
BOOST_LOG(warning) << "Couldn't set ["sv << sink << "] to role ["sv << x << "]: 0x"sv << util::hex(status).to_string_view();
|
||||
}
|
||||
|
||||
++failure;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user