Skip to content

Commit

Permalink
fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
sorayuki committed Mar 4, 2023
1 parent 670e0ad commit dcd88d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 91 deletions.
124 changes: 34 additions & 90 deletions src/push-widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(std::round((new_frames - total_frames_) / interval)));

auto bps = (new_bytes - total_bytes_) * 8 / interval;
auto strBps = [&]()-> std::string {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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_;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -695,6 +638,7 @@ class PushWidgetImpl : public PushWidget, public IOBSOutputEventHanlder
btn_->setEnabled(true);
SetMsg(obs_module_text("Status.Streaming"));

ResetInfo();
timer_->start();
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/push-widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit dcd88d9

Please sign in to comment.