From 13d0106feb1ae67e95a8458c15d571c95bf78542 Mon Sep 17 00:00:00 2001 From: loki Date: Sun, 8 Aug 2021 13:41:09 +0200 Subject: [PATCH] Don't shutdown stream if audio capture fails --- sunshine/audio.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/sunshine/audio.cpp b/sunshine/audio.cpp index cb4fac28..4279eb4c 100644 --- a/sunshine/audio.cpp +++ b/sunshine/audio.cpp @@ -130,7 +130,7 @@ void capture(safe::mail_t mail, config_t config, void *channel_data) { auto &control = ref->control; if(!control) { - BOOST_LOG(error) << "Couldn't create audio control"sv; + shutdown_event->view(); return; } @@ -223,21 +223,29 @@ int map_stream(int channels, bool quality) { } int start_audio_control(audio_ctx_t &ctx) { + auto fg = util::fail_guard([]() { + BOOST_LOG(warning) << "There will be no audio"sv; + }); + ctx.sink_flag = std::make_unique(false); - if(!(ctx.control = platf::audio_control())) { - return -1; - } - - auto sink = ctx.control->sink_info(); - if(!sink) { - return -1; - } - // The default sink has not been replaced yet. ctx.restore_sink = false; + if(!(ctx.control = platf::audio_control())) { + return 0; + } + + auto sink = ctx.control->sink_info(); + if(!sink) { + // Let the calling code know it failed + ctx.control.reset(); + return 0; + } + ctx.sink = std::move(*sink); + + fg.disable(); return 0; }