From 5c5d0ba9e5055ea4fc961b06d03263ed10920a96 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 9 Sep 2016 07:37:54 -0700 Subject: [PATCH] UI: Add ability to forcibly stop streams/recordings If the user hits the "stop stream" button it'll transition in to "stopping stream..." and will continue to output until the stream reaches the timing in which "stop" was pressed. However, if there is significant congestion, stopping the stream can take far longer than the user may like. So there needs to be an option to forcibly stop the stream in that case; pushing the "stop" button a second time should allow the user to tell the stream/recording to stop right away instead of waiting for the precise stop timing. --- UI/window-basic-main-outputs.cpp | 48 ++++++++++++++++---------------- UI/window-basic-main-outputs.hpp | 5 ++-- UI/window-basic-main.cpp | 10 +++++-- UI/window-basic-main.hpp | 2 ++ 4 files changed, 35 insertions(+), 30 deletions(-) diff --git a/UI/window-basic-main-outputs.cpp b/UI/window-basic-main-outputs.cpp index 2415d75d6..9a864df0a 100644 --- a/UI/window-basic-main-outputs.cpp +++ b/UI/window-basic-main-outputs.cpp @@ -179,9 +179,8 @@ struct SimpleOutput : BasicOutputHandler { virtual bool StartStreaming(obs_service_t *service) override; virtual bool StartRecording() override; - virtual void StopStreaming() override; - virtual void ForceStopStreaming() override; - virtual void StopRecording() override; + virtual void StopStreaming(bool force) override; + virtual void StopRecording(bool force) override; virtual bool StreamingActive() const override; virtual bool RecordingActive() const override; }; @@ -650,19 +649,20 @@ bool SimpleOutput::StartRecording() return false; } -void SimpleOutput::StopStreaming() +void SimpleOutput::StopStreaming(bool force) { - obs_output_stop(streamOutput); + if (force) + obs_output_force_stop(streamOutput); + else + obs_output_stop(streamOutput); } -void SimpleOutput::ForceStopStreaming() +void SimpleOutput::StopRecording(bool force) { - obs_output_force_stop(streamOutput); -} - -void SimpleOutput::StopRecording() -{ - obs_output_stop(fileOutput); + if (force) + obs_output_force_stop(fileOutput); + else + obs_output_stop(fileOutput); } bool SimpleOutput::StreamingActive() const @@ -703,9 +703,8 @@ struct AdvancedOutput : BasicOutputHandler { virtual bool StartStreaming(obs_service_t *service) override; virtual bool StartRecording() override; - virtual void StopStreaming() override; - virtual void ForceStopStreaming() override; - virtual void StopRecording() override; + virtual void StopStreaming(bool force) override; + virtual void StopRecording(bool force) override; virtual bool StreamingActive() const override; virtual bool RecordingActive() const override; }; @@ -1193,19 +1192,20 @@ bool AdvancedOutput::StartRecording() return false; } -void AdvancedOutput::StopStreaming() +void AdvancedOutput::StopStreaming(bool force) { - obs_output_stop(streamOutput); + if (force) + obs_output_force_stop(streamOutput); + else + obs_output_stop(streamOutput); } -void AdvancedOutput::ForceStopStreaming() +void AdvancedOutput::StopRecording(bool force) { - obs_output_force_stop(streamOutput); -} - -void AdvancedOutput::StopRecording() -{ - obs_output_stop(fileOutput); + if (force) + obs_output_force_stop(fileOutput); + else + obs_output_stop(fileOutput); } bool AdvancedOutput::StreamingActive() const diff --git a/UI/window-basic-main-outputs.hpp b/UI/window-basic-main-outputs.hpp index 186d3b4da..74a73a60e 100644 --- a/UI/window-basic-main-outputs.hpp +++ b/UI/window-basic-main-outputs.hpp @@ -24,9 +24,8 @@ struct BasicOutputHandler { virtual bool StartStreaming(obs_service_t *service) = 0; virtual bool StartRecording() = 0; - virtual void StopStreaming() = 0; - virtual void ForceStopStreaming() = 0; - virtual void StopRecording() = 0; + virtual void StopStreaming(bool force = false) = 0; + virtual void StopRecording(bool force = false) = 0; virtual bool StreamingActive() const = 0; virtual bool RecordingActive() const = 0; diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp index eae28ffc9..e4d46492e 100644 --- a/UI/window-basic-main.cpp +++ b/UI/window-basic-main.cpp @@ -3642,7 +3642,7 @@ void OBSBasic::StopStreaming() SaveProject(); if (outputHandler->StreamingActive()) - outputHandler->StopStreaming(); + outputHandler->StopStreaming(streamingStopping); OnDeactivate(); @@ -3659,7 +3659,7 @@ void OBSBasic::ForceStopStreaming() SaveProject(); if (outputHandler->StreamingActive()) - outputHandler->ForceStopStreaming(); + outputHandler->StopStreaming(true); OnDeactivate(); @@ -3734,6 +3734,7 @@ void OBSBasic::StreamStopping() ui->streamButton->setText(QTStr("Basic.Main.StoppingStreaming")); sysTrayStream->setText(ui->streamButton->text()); + streamingStopping = true; if (api) api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPING); } @@ -3773,6 +3774,7 @@ void OBSBasic::StreamingStop(int code) sysTrayStream->setText(ui->streamButton->text()); sysTrayStream->setEnabled(true); + streamingStopping = false; if (api) api->on_event(OBS_FRONTEND_EVENT_STREAMING_STOPPED); @@ -3812,6 +3814,7 @@ void OBSBasic::RecordStopping() ui->recordButton->setText(QTStr("Basic.Main.StoppingRecording")); sysTrayRecord->setText(ui->recordButton->text()); + recordingStopping = true; if (api) api->on_event(OBS_FRONTEND_EVENT_RECORDING_STOPPING); } @@ -3821,7 +3824,7 @@ void OBSBasic::StopRecording() SaveProject(); if (outputHandler->RecordingActive()) - outputHandler->StopRecording(); + outputHandler->StopRecording(recordingStopping); OnDeactivate(); } @@ -3832,6 +3835,7 @@ void OBSBasic::RecordingStart() ui->recordButton->setText(QTStr("Basic.Main.StopRecording")); sysTrayRecord->setText(ui->recordButton->text()); + recordingStopping = false; if (api) api->on_event(OBS_FRONTEND_EVENT_RECORDING_STARTED); diff --git a/UI/window-basic-main.hpp b/UI/window-basic-main.hpp index 426f0d1b5..f7a0b8e19 100644 --- a/UI/window-basic-main.hpp +++ b/UI/window-basic-main.hpp @@ -120,6 +120,8 @@ private: OBSService service; std::unique_ptr outputHandler; + bool streamingStopping = false; + bool recordingStopping = false; gs_vertbuffer_t *box = nullptr; gs_vertbuffer_t *boxLeft = nullptr;