Skip to content

Commit

Permalink
Add temp variable support to streaming condition
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmUpTill committed Feb 10, 2024
1 parent 96809f7 commit 668bba1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
5 changes: 5 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,11 @@ AdvSceneSwitcher.tempVar.display.width.description="The width of the display whi
AdvSceneSwitcher.tempVar.display.height="Display height"
AdvSceneSwitcher.tempVar.display.height.description="The height of the display which matched the given pattern"

AdvSceneSwitcher.tempVar.streaming.keyframeInterval="Stream keyframe interval"
AdvSceneSwitcher.tempVar.streaming.keyframeInterval.description="Stream keyframe interval configured in the OBS settings."
AdvSceneSwitcher.tempVar.streaming.durationSeconds="Stream duration"
AdvSceneSwitcher.tempVar.streaming.durationSeconds.description="Seconds passed since the stream was started.\nThis value will be zero if the stream is stopped."

AdvSceneSwitcher.selectScene="--select scene--"
AdvSceneSwitcher.selectPreviousScene="Previous Scene"
AdvSceneSwitcher.selectCurrentScene="Current Scene"
Expand Down
31 changes: 29 additions & 2 deletions plugins/base/macro-condition-streaming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool setupStreamingEventHandler()
return true;
}

int MacroConditionStream::GetKeyFrameInterval()
int MacroConditionStream::GetKeyFrameInterval() const
{
const auto configPath = GetPathInProfileDir("streamEncoder.json");
obs_data_t *settings =
Expand All @@ -72,6 +72,7 @@ bool MacroConditionStream::CheckCondition()

bool streamStarting = streamStartTime != _lastStreamStartingTime;
bool streamStopping = streamStopTime != _lastStreamStoppingTime;
const int keyFrameInterval = GetKeyFrameInterval();

switch (_condition) {
case Condition::STOP:
Expand All @@ -87,7 +88,7 @@ bool MacroConditionStream::CheckCondition()
match = streamStopping;
break;
case Condition::KEYFRAME_INTERVAL:
match = GetKeyFrameInterval() == _keyFrameInterval;
match = keyFrameInterval == _keyFrameInterval;
break;
default:
break;
Expand All @@ -99,6 +100,15 @@ bool MacroConditionStream::CheckCondition()
if (streamStopping) {
_lastStreamStoppingTime = streamStopTime;
}

const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::high_resolution_clock::now() - streamStartTime);
const auto streamDurationSeconds =
obs_frontend_streaming_active() ? seconds.count() : 0;
SetTempVarValue("durationSeconds",
std::to_string(streamDurationSeconds));
SetTempVarValue("keyframeInterval", std::to_string(keyFrameInterval));

return match;
}

Expand All @@ -118,6 +128,23 @@ bool MacroConditionStream::Load(obs_data_t *obj)
return true;
}

void MacroConditionStream::SetupTempVars()
{
MacroCondition::SetupTempVars();
AddTempvar(
"keyframeInterval",
obs_module_text(
"AdvSceneSwitcher.tempVar.streaming.keyframeInterval"),
obs_module_text(
"AdvSceneSwitcher.tempVar.streaming.keyframeInterval.description"));
AddTempvar(
"durationSeconds",
obs_module_text(
"AdvSceneSwitcher.tempVar.streaming.durationSeconds"),
obs_module_text(
"AdvSceneSwitcher.tempVar.streaming.durationSeconds.description"));
}

static inline void populateStateSelection(QComboBox *list)
{
for (auto entry : streamStates) {
Expand Down
3 changes: 2 additions & 1 deletion plugins/base/macro-condition-streaming.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class MacroConditionStream : public MacroCondition {
NumberVariable<int> _keyFrameInterval = 0;

private:
int GetKeyFrameInterval();
void SetupTempVars();
int GetKeyFrameInterval() const;

std::chrono::high_resolution_clock::time_point _lastStreamStartingTime{};
std::chrono::high_resolution_clock::time_point _lastStreamStoppingTime{};
Expand Down

0 comments on commit 668bba1

Please sign in to comment.