Skip to content

Commit

Permalink
UI: Restart multitrack output if stream key has become invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
dsaedtler committed Oct 27, 2024
1 parent 4aa2192 commit 81aaed2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
14 changes: 12 additions & 2 deletions UI/multitrack-video-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ void MultitrackVideoOutput::PrepareStreaming(
return;
}
}

restart_on_error = false;

std::optional<GoLiveApi::Config> go_live_config;
std::optional<GoLiveApi::Config> custom;
bool is_custom_config = custom_config.has_value();
Expand Down Expand Up @@ -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};
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -811,6 +815,12 @@ void MultitrackVideoOutput::ReleaseOnMainThread(std::optional<OBSOutputObjects>
QApplication::instance()->thread(), [objects = std::move(objects)] {}, Qt::QueuedConnection);
}

void StreamStartHandler(void *arg, calldata_t *)
{
auto self = static_cast<MultitrackVideoOutput *>(arg);
self->restart_on_error = true;
}

void StreamStopHandler(void *arg, calldata_t *data)
{
auto self = static_cast<MultitrackVideoOutput *>(arg);
Expand Down
6 changes: 6 additions & 0 deletions UI/multitrack-video-output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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_;
Expand All @@ -61,6 +64,9 @@ struct MultitrackVideoOutput {
std::mutex current_stream_dump_mutex;
std::optional<OBSOutputObjects> 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 *);
Expand Down
10 changes: 10 additions & 0 deletions UI/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 81aaed2

Please sign in to comment.