diff --git a/UI/multitrack-video-output.cpp b/UI/multitrack-video-output.cpp index 548b1dc1360e2b..c8449eb31a53ed 100644 --- a/UI/multitrack-video-output.cpp +++ b/UI/multitrack-video-output.cpp @@ -306,6 +306,9 @@ void MultitrackVideoOutput::PrepareStreaming( return; } } + + restart_on_error = false; + std::optional go_live_config; std::optional custom; bool is_custom_config = custom_config.has_value(); @@ -470,6 +473,8 @@ void MultitrackVideoOutput::StartedStreaming() void MultitrackVideoOutput::StopStreaming() { + restart_on_error = false; + OBSOutputAutoRelease current_output; { const std::lock_guard current_lock{current_mutex}; @@ -779,8 +784,7 @@ void SetupSignalHandlers(bool recording, MultitrackVideoOutput *self, obs_output { auto handler = obs_output_get_signal_handler(output); - if (recording) - start.Connect(handler, "start", RecordingStartHandler, self); + start.Connect(handler, "start", !recording ? StreamStartHandler : RecordingStartHandler, self); stop.Connect(handler, "stop", !recording ? StreamStopHandler : RecordingStopHandler, self); } @@ -811,6 +815,12 @@ void MultitrackVideoOutput::ReleaseOnMainThread(std::optional QApplication::instance()->thread(), [objects = std::move(objects)] {}, Qt::QueuedConnection); } +void StreamStartHandler(void *arg, calldata_t *) +{ + auto self = static_cast(arg); + self->restart_on_error = true; +} + void StreamStopHandler(void *arg, calldata_t *data) { auto self = static_cast(arg); diff --git a/UI/multitrack-video-output.hpp b/UI/multitrack-video-output.hpp index 3a09d93def5120..f0b9f24dca4992 100644 --- a/UI/multitrack-video-output.hpp +++ b/UI/multitrack-video-output.hpp @@ -14,6 +14,7 @@ class QString; +void StreamStartHandler(void *arg, calldata_t *); void StreamStopHandler(void *arg, calldata_t *data); void RecordingStartHandler(void *arg, calldata_t *data); @@ -41,6 +42,8 @@ struct MultitrackVideoOutput { return current ? obs_output_get_ref(current->output_) : nullptr; } + bool RestartOnError() { return restart_on_error; } + private: struct OBSOutputObjects { OBSOutputAutoRelease output_; @@ -61,6 +64,9 @@ struct MultitrackVideoOutput { std::mutex current_stream_dump_mutex; std::optional current_stream_dump; + bool restart_on_error = false; + + friend void StreamStartHandler(void *arg, calldata_t *data); friend void StreamStopHandler(void *arg, calldata_t *data); friend void RecordingStartHandler(void *arg, calldata_t *data); friend void RecordingStopHandler(void *arg, calldata_t *); diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index 34a7bb231726f8..82474d73637f7b 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -6878,6 +6878,14 @@ void OBSBasic::StreamingStop(int code, QString last_error) DStr errorMessage; bool use_last_error = false; bool encode_error = false; + bool should_reconnect = false; + + /* Ignore stream key error for multitrack output if its internal reconnect handling is active. */ + if (code == OBS_OUTPUT_INVALID_STREAM && outputHandler->multitrackVideo && + outputHandler->multitrackVideo->RestartOnError()) { + code = OBS_OUTPUT_SUCCESS; + should_reconnect = true; + } switch (code) { case OBS_OUTPUT_BAD_PATH: @@ -6955,6 +6963,8 @@ void OBSBasic::StreamingStop(int code, QString last_error) // Reset broadcast button state/text if (!broadcastActive) SetBroadcastFlowEnabled(auth && auth->broadcastFlow()); + if (should_reconnect) + QMetaObject::invokeMethod(this, "StartStreaming", Qt::QueuedConnection); } void OBSBasic::AutoRemux(QString input, bool no_show)