diff --git a/src/push-widget.cpp b/src/push-widget.cpp index b21f42f4..86828e02 100644 --- a/src/push-widget.cpp +++ b/src/push-widget.cpp @@ -351,7 +351,7 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder sprintf(strDuration, "%02d:%02d:%02d", (int)hh.count(), (int)mm.count(), (int)ss.count()); char strFps[32] = { 0 }; - sprintf(strFps, "%d FPS", (int)std::round((new_frames - total_frames_) / interval)); + sprintf(strFps, "%d FPS", static_cast(std::round((new_frames - total_frames_) / interval))); auto bps = (new_bytes - total_bytes_) * 8 / interval; auto strBps = [&]()-> std::string { @@ -432,10 +432,11 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder { ReleaseOutput(); } - bool StartStreaming() override { - if (IsRunning() == false) - return true; + void StartStreaming() override { + if (IsRunning()) + return; + // recreate output ReleaseOutput(); @@ -466,44 +467,43 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder if (!PrepareOutputService()) { SetMsg(obs_module_text("Error.CreateRtmpService")); - return false; + return; } if (!PrepareOutputEncoders()) { SetMsg(obs_module_text("Error.CreateEncoder")); - return false; + return; } if (!obs_output_start(output_)) { SetMsg(obs_module_text("Error.StartOutput")); - return false; } - - return true; } - void StopStreaming() override { - if (IsRunning() == true && output_ != nullptr) - { - bool useForce = false; - if (isUseDelay_) { - auto res = QMessageBox(QMessageBox::Icon::Information, - "?", - obs_module_text("Ques.DropDelay"), - QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, - this - ).exec(); - if (res == QMessageBox::Yes) - useForce = true; - } - if (!useForce) - obs_output_stop(output_); - else - obs_output_force_stop(output_); + void StopStreaming() override { + if (!IsRunning()) + return; + + bool useForce = false; + if (isUseDelay_) { + auto res = QMessageBox(QMessageBox::Icon::Information, + "?", + obs_module_text("Ques.DropDelay"), + QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, + this + ).exec(); + if (res == QMessageBox::Yes) + useForce = true; } + + if (!useForce) + obs_output_stop(output_); + else + obs_output_force_stop(output_); } + QJsonObject Config() override { return conf_; @@ -534,7 +534,6 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder void ResetInfo() { - begin_time_ = clock::now(); total_frames_ = 0; total_bytes_ = 0; last_info_time_ = clock::now(); @@ -555,69 +554,13 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder void StartStop() { - if (IsRunning() == false){ - // recreate output - ReleaseOutput(); - - if (output_ == nullptr) - { - output_ = obs_output_create("rtmp_output", "multi-output", nullptr, nullptr); - SetAsHandler(output_); - } - - if (output_) { - isUseDelay_ = false; - - auto profileConfig = obs_frontend_get_profile_config(); - if (profileConfig) { - bool useDelay = config_get_bool(profileConfig, "Output", "DelayEnable"); - bool preserveDelay = config_get_bool(profileConfig, "Output", "DelayPreserve"); - int delaySec = config_get_int(profileConfig, "Output", "DelaySec"); - obs_output_set_delay(output_, - useDelay ? delaySec : 0, - preserveDelay ? OBS_OUTPUT_DELAY_PRESERVE : 0 - ); - - if (useDelay && delaySec > 0) - isUseDelay_ = true; - } - } - - if (!PrepareOutputService()) - { - SetMsg(obs_module_text("Error.CreateRtmpService")); - return; - } - - if (!PrepareOutputEncoders()) - { - SetMsg(obs_module_text("Error.CreateEncoder")); - return; - } - - if (!obs_output_start(output_)) - { - SetMsg(obs_module_text("Error.StartOutput")); - } + if (IsRunning() == false) + { + StartStreaming(); } else if (output_ != nullptr) { - bool useForce = false; - if (isUseDelay_) { - auto res = QMessageBox(QMessageBox::Icon::Information, - "?", - obs_module_text("Ques.DropDelay"), - QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No, - this - ).exec(); - if (res == QMessageBox::Yes) - useForce = true; - } - - if (!useForce) - obs_output_stop(output_); - else - obs_output_force_stop(output_); + StopStreaming(); } } @@ -652,8 +595,8 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder // obs logical void OnStarting() override { - GetGlobalService().RunInUIThread([this]() - { + GetGlobalService().RunInUIThread([this]() { + begin_time_ = clock::now(); remove_btn_->setEnabled(false); btn_->setText(obs_module_text("Status.Stop")); btn_->setEnabled(true); @@ -695,6 +638,7 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder btn_->setEnabled(true); SetMsg(obs_module_text("Status.Streaming")); + ResetInfo(); timer_->start(); }); } diff --git a/src/push-widget.h b/src/push-widget.h index a167dd8b..ced7c3f9 100644 --- a/src/push-widget.h +++ b/src/push-widget.h @@ -5,7 +5,7 @@ class PushWidget : virtual public QWidget { virtual ~PushWidget() {} virtual QJsonObject Config() = 0; virtual bool ShowEditDlg() = 0; - virtual bool StartStreaming() = 0; + virtual void StartStreaming() = 0; virtual void StopStreaming() = 0; virtual void OnOBSEvent(obs_frontend_event ev) = 0; };