add first draft of auto start of recording / streaming

This commit is contained in:
WarmUpTill 2020-08-16 19:48:54 +02:00
parent 255d10e603
commit 95261ce9bb
5 changed files with 180 additions and 0 deletions

View File

@ -438,6 +438,69 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_50">
<item>
<widget class="QCheckBox" name="autoStartSceneCheckBox">
<property name="text">
<string>Automatically start</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="autoStartType">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_65">
<property name="text">
<string>on scene</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="autoStartScenes">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_55">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_10">
<property name="orientation">

View File

@ -195,10 +195,17 @@ void SwitcherData::Thread()
if (switcher->stop) {
break;
}
setDefaultSceneTransitions();
if (autoStopEnable) {
autoStopStreamAndRecording();
}
if (autoStartEnable) {
autoStartStreamRecording();
}
if (checkPause()) {
continue;
}

View File

@ -159,6 +159,73 @@ void SwitcherData::autoStopStreamAndRecording()
obs_weak_source_release(ws);
}
void SceneSwitcher::on_autoStartType_currentIndexChanged(int index)
{
if (loading)
return;
std::lock_guard<std::mutex> lock(switcher->m);
switcher->autoStartType = (AutoStartType)index;
}
void SceneSwitcher::on_autoStartScenes_currentTextChanged(const QString &text)
{
if (loading)
return;
std::lock_guard<std::mutex> lock(switcher->m);
UpdateAutoStartScene(text);
}
void SceneSwitcher::on_autoStartSceneCheckBox_stateChanged(int state)
{
if (loading)
return;
std::lock_guard<std::mutex> lock(switcher->m);
if (!state) {
ui->autoStartScenes->setDisabled(true);
ui->autoStartType->setDisabled(true);
switcher->autoStartEnable = false;
} else {
ui->autoStartScenes->setDisabled(false);
ui->autoStartType->setDisabled(false);
switcher->autoStartEnable = true;
if (!switcher->autoStartScene)
UpdateAutoStartScene(
ui->autoStartScenes->currentText());
}
}
void SceneSwitcher::UpdateAutoStartScene(const QString &name)
{
obs_source_t *scene = obs_get_source_by_name(name.toUtf8().constData());
obs_weak_source_t *ws = obs_source_get_weak_source(scene);
switcher->autoStartScene = ws;
obs_weak_source_release(ws);
obs_source_release(scene);
}
void SwitcherData::autoStartStreamRecording()
{
obs_source_t *currentSource = obs_frontend_get_current_scene();
obs_weak_source_t *ws = obs_source_get_weak_source(currentSource);
if (ws && autoStartScene == ws) {
if ((switcher->autoStartType == STREAMING ||
switcher->autoStartType == RECORINDGSTREAMING) &&
!obs_frontend_streaming_active())
obs_frontend_streaming_start();
if ((switcher->autoStartType == RECORDING ||
switcher->autoStartType == RECORINDGSTREAMING) &&
!obs_frontend_recording_active())
obs_frontend_recording_start();
}
obs_source_release(currentSource);
obs_weak_source_release(ws);
}
void SceneSwitcher::on_verboseLogging_stateChanged(int state)
{
if (loading)
@ -345,6 +412,13 @@ void SwitcherData::saveGeneralSettings(obs_data_t *obj)
obs_data_set_string(obj, "autoStopSceneName",
autoStopSceneName.c_str());
std::string autoStartSceneName =
GetWeakSourceName(switcher->autoStartScene);
obs_data_set_bool(obj, "autoStartEnable", switcher->autoStartEnable);
obs_data_set_int(obj, "autoStartType", switcher->autoStartType);
obs_data_set_string(obj, "autoStartSceneName",
autoStartSceneName.c_str());
obs_data_set_bool(obj, "verbose", switcher->verbose);
obs_data_set_int(obj, "priority0",
@ -406,6 +480,13 @@ void SwitcherData::loadGeneralSettings(obs_data_t *obj)
switcher->autoStopEnable = obs_data_get_bool(obj, "autoStopEnable");
switcher->autoStopScene = GetWeakSourceByName(autoStopScene.c_str());
std::string autoStartScene =
obs_data_get_string(obj, "autoStartSceneName");
switcher->autoStartEnable = obs_data_get_bool(obj, "autoStartEnable");
switcher->autoStartType =
(AutoStartType)obs_data_get_int(obj, "autoStartType");
switcher->autoStartScene = GetWeakSourceByName(autoStartScene.c_str());
switcher->verbose = obs_data_get_bool(obj, "verbose");
obs_data_set_default_int(obj, "priority0", DEFAULT_PRIORITY_0);
@ -491,6 +572,7 @@ void SceneSwitcher::setupGeneralTab()
{
populateSceneSelection(ui->noMatchSwitchScene, false);
populateSceneSelection(ui->autoStopScenes, false);
populateSceneSelection(ui->autoStartScenes, false);
if (switcher->switchIfNotMatching == SWITCH) {
ui->noMatchSwitch->setChecked(true);
@ -516,6 +598,23 @@ void SceneSwitcher::setupGeneralTab()
ui->autoStopScenes->setDisabled(true);
}
ui->autoStartType->addItem("Recording");
ui->autoStartType->addItem("Streaming");
ui->autoStartType->addItem("Recording and Streaming");
ui->autoStartSceneCheckBox->setChecked(switcher->autoStartEnable);
ui->autoStartScenes->setCurrentText(
GetWeakSourceName(switcher->autoStartScene).c_str());
ui->autoStartType->setCurrentIndex(switcher->autoStartType);
if (ui->autoStartSceneCheckBox->checkState()) {
ui->autoStartScenes->setDisabled(false);
ui->autoStartType->setDisabled(false);
} else {
ui->autoStartScenes->setDisabled(true);
ui->autoStartType->setDisabled(true);
}
ui->verboseLogging->setChecked(switcher->verbose);
for (int p : switcher->functionNamesByPriority) {

View File

@ -46,6 +46,7 @@ public:
void UpdateNonMatchingScene(const QString &name);
void UpdateAutoStopScene(const QString &name);
void UpdateAutoStartScene(const QString &name);
void UpdateIdleDataTransition(const QString &name);
void UpdateIdleDataScene(const QString &name);
@ -112,6 +113,10 @@ public slots:
void on_autoStopSceneCheckBox_stateChanged(int state);
void on_autoStopScenes_currentTextChanged(const QString &text);
void on_autoStartSceneCheckBox_stateChanged(int state);
void on_autoStartType_currentIndexChanged(int index);
void on_autoStartScenes_currentTextChanged(const QString &text);
void on_verboseLogging_stateChanged(int state);
void on_exportSettings_clicked();

View File

@ -254,6 +254,7 @@ struct TimeSwitch {
typedef enum { NO_SWITCH = 0, SWITCH = 1, RANDOM_SWITCH = 2 } NoMatch;
typedef enum { PERSIST = 0, START = 1, STOP = 2 } StartupBehavior;
typedef enum { RECORDING = 0, STREAMING = 1, RECORINDGSTREAMING = 2 } AutoStartType;
class SwitcherThread;
@ -308,6 +309,10 @@ struct SwitcherData {
bool autoStopEnable = false;
OBSWeakSource autoStopScene;
bool autoStartEnable = false;
AutoStartType autoStartType = RECORDING;
OBSWeakSource autoStartScene;
std::vector<SceneTransition> sceneTransitions;
std::vector<DefaultSceneTransition> defaultSceneTransitions;
@ -358,6 +363,7 @@ struct SwitcherData {
void writeSceneInfoToFile();
void setDefaultSceneTransitions();
void autoStopStreamAndRecording();
void autoStartStreamRecording();
bool checkPause();
void checkSceneRoundTrip(bool &match, OBSWeakSource &scene,
OBSWeakSource &transition,