events: fix crash caused by early StreamStatus call

This commit is contained in:
Stéphane L 2019-04-19 23:09:25 +02:00
parent c476649f3e
commit a99da27ff6
2 changed files with 21 additions and 14 deletions

View File

@ -19,7 +19,6 @@
#include <util/platform.h> #include <util/platform.h>
#include <QTimer>
#include <QPushButton> #include <QPushButton>
#include "Config.h" #include "Config.h"
@ -28,6 +27,8 @@
#include "obs-websocket.h" #include "obs-websocket.h"
#define STATUS_INTERVAL 2000
bool transitionIsCut(obs_source_t* transition) { bool transitionIsCut(obs_source_t* transition) {
if (!transition) if (!transition)
return false; return false;
@ -72,30 +73,29 @@ void WSEvents::ResetCurrent(WSServerPtr srv) {
_instance = WSEventsPtr(new WSEvents(srv)); _instance = WSEventsPtr(new WSEvents(srv));
} }
WSEvents::WSEvents(WSServerPtr srv) { WSEvents::WSEvents(WSServerPtr srv) :
_srv = srv; _srv(srv),
streamStatusTimer(),
currentScene(nullptr),
HeartbeatIsActive(false),
_streamStarttime(0),
_recStarttime(0),
pulse(false)
{
obs_frontend_add_event_callback(WSEvents::FrontendEventHandler, this); obs_frontend_add_event_callback(WSEvents::FrontendEventHandler, this);
QSpinBox* durationControl = Utils::GetTransitionDurationControl(); QSpinBox* durationControl = Utils::GetTransitionDurationControl();
connect(durationControl, SIGNAL(valueChanged(int)), connect(durationControl, SIGNAL(valueChanged(int)),
this, SLOT(TransitionDurationChanged(int))); this, SLOT(TransitionDurationChanged(int)));
QTimer* statusTimer = new QTimer(); connect(&streamStatusTimer, SIGNAL(timeout()),
connect(statusTimer, SIGNAL(timeout()),
this, SLOT(StreamStatus())); this, SLOT(StreamStatus()));
pulse = false; connect(&heartbeatTimer, SIGNAL(timeout()),
connect(statusTimer, SIGNAL(timeout()),
this, SLOT(Heartbeat())); this, SLOT(Heartbeat()));
statusTimer->start(2000); // equal to frontend's constant BITRATE_UPDATE_SECONDS
currentScene = nullptr; heartbeatTimer.start(STATUS_INTERVAL);
QTimer::singleShot(1000, this, SLOT(deferredInitOperations())); QTimer::singleShot(1000, this, SLOT(deferredInitOperations()));
HeartbeatIsActive = false;
_streamStarttime = 0;
_recStarttime = 0;
} }
WSEvents::~WSEvents() { WSEvents::~WSEvents() {
@ -145,9 +145,13 @@ void WSEvents::FrontendEventHandler(enum obs_frontend_event event, void* private
owner->OnStreamStarting(); owner->OnStreamStarting();
} }
else if (event == OBS_FRONTEND_EVENT_STREAMING_STARTED) { else if (event == OBS_FRONTEND_EVENT_STREAMING_STARTED) {
owner->streamStatusTimer.start(STATUS_INTERVAL);
owner->StreamStatus();
owner->OnStreamStarted(); owner->OnStreamStarted();
} }
else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPING) { else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPING) {
owner->streamStatusTimer.stop();
owner->OnStreamStopping(); owner->OnStreamStopping();
} }
else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPED) { else if (event == OBS_FRONTEND_EVENT_STREAMING_STOPPED) {

View File

@ -24,6 +24,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include <QListWidgetItem> #include <QListWidgetItem>
#include <QSharedPointer> #include <QSharedPointer>
#include <QtCore/QTimer>
#include "WSServer.h" #include "WSServer.h"
@ -63,6 +64,8 @@ private:
static WSEventsPtr _instance; static WSEventsPtr _instance;
WSServerPtr _srv; WSServerPtr _srv;
QTimer streamStatusTimer;
QTimer heartbeatTimer;
OBSSource currentScene; OBSSource currentScene;
bool pulse; bool pulse;