Utils: Add output state util to utils

This commit is contained in:
tt2468 2021-12-19 02:17:48 -08:00
parent 2e8622e8d7
commit f566ccd76b
3 changed files with 23 additions and 21 deletions

View File

@ -19,21 +19,7 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#include "EventHandler.h"
#define CASE(x) case x: return #x;
std::string GetOutputStateString(ObsOutputState state) {
switch (state) {
default:
CASE(OBS_WEBSOCKET_OUTPUT_STARTING)
CASE(OBS_WEBSOCKET_OUTPUT_STARTED)
CASE(OBS_WEBSOCKET_OUTPUT_STOPPING)
CASE(OBS_WEBSOCKET_OUTPUT_STOPPED)
CASE(OBS_WEBSOCKET_OUTPUT_PAUSED)
CASE(OBS_WEBSOCKET_OUTPUT_RESUMED)
}
}
bool GetOutputStateActive(ObsOutputState state) {
static bool GetOutputStateActive(ObsOutputState state) {
switch(state) {
case OBS_WEBSOCKET_OUTPUT_STARTED:
case OBS_WEBSOCKET_OUTPUT_RESUMED:
@ -52,7 +38,7 @@ void EventHandler::HandleStreamStateChanged(ObsOutputState state)
{
json eventData;
eventData["outputActive"] = GetOutputStateActive(state);
eventData["outputState"] = GetOutputStateString(state);
eventData["outputState"] = Utils::Obs::StringHelper::GetOutputState(state);
BroadcastEvent(EventSubscription::Outputs, "StreamStateChanged", eventData);
}
@ -60,7 +46,7 @@ void EventHandler::HandleRecordStateChanged(ObsOutputState state)
{
json eventData;
eventData["outputActive"] = GetOutputStateActive(state);
eventData["outputState"] = GetOutputStateString(state);
eventData["outputState"] = Utils::Obs::StringHelper::GetOutputState(state);
BroadcastEvent(EventSubscription::Outputs, "RecordStateChanged", eventData);
}
@ -68,7 +54,7 @@ void EventHandler::HandleReplayBufferStateChanged(ObsOutputState state)
{
json eventData;
eventData["outputActive"] = GetOutputStateActive(state);
eventData["outputState"] = GetOutputStateString(state);
eventData["outputState"] = Utils::Obs::StringHelper::GetOutputState(state);
BroadcastEvent(EventSubscription::Outputs, "ReplayBufferStateChanged", eventData);
}
@ -76,7 +62,7 @@ void EventHandler::HandleVirtualcamStateChanged(ObsOutputState state)
{
json eventData;
eventData["outputActive"] = GetOutputStateActive(state);
eventData["outputState"] = GetOutputStateString(state);
eventData["outputState"] = Utils::Obs::StringHelper::GetOutputState(state);
BroadcastEvent(EventSubscription::Outputs, "VirtualcamStateChanged", eventData);
}

View File

@ -66,13 +66,14 @@ template <typename T> T* GetCalldataPointer(const calldata_t *data, const char*
}
enum ObsOutputState {
OBS_WEBSOCKET_OUTPUT_UNKNOWN,
OBS_WEBSOCKET_OUTPUT_STARTING,
OBS_WEBSOCKET_OUTPUT_STARTED,
OBS_WEBSOCKET_OUTPUT_STOPPING,
OBS_WEBSOCKET_OUTPUT_STOPPED,
OBS_WEBSOCKET_OUTPUT_RECONNECTING,
OBS_WEBSOCKET_OUTPUT_PAUSED,
OBS_WEBSOCKET_OUTPUT_RESUMED
OBS_WEBSOCKET_OUTPUT_RESUMED,
};
enum ObsMediaInputAction {
@ -82,7 +83,7 @@ enum ObsMediaInputAction {
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_STOP,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_RESTART,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_NEXT,
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PREVIOUS
OBS_WEBSOCKET_MEDIA_INPUT_ACTION_PREVIOUS,
};
namespace Utils {
@ -99,6 +100,7 @@ namespace Utils {
std::string GetLastReplayBufferFilePath();
std::string GetSceneItemBoundsType(enum obs_bounds_type type);
std::string DurationToTimecode(uint64_t);
std::string GetOutputState(ObsOutputState state);
}
namespace EnumHelper {

View File

@ -152,3 +152,17 @@ std::string Utils::Obs::StringHelper::DurationToTimecode(uint64_t ms)
QString formatted = QString::asprintf("%02" PRIu64 ":%02" PRIu64 ":%02" PRIu64 ".%03" PRIu64, hoursPart, minutesPart, secsPart, msPart);
return formatted.toStdString();
}
std::string Utils::Obs::StringHelper::GetOutputState(ObsOutputState state)
{
switch (state) {
default:
CASE(OBS_WEBSOCKET_OUTPUT_UNKNOWN)
CASE(OBS_WEBSOCKET_OUTPUT_STARTING)
CASE(OBS_WEBSOCKET_OUTPUT_STARTED)
CASE(OBS_WEBSOCKET_OUTPUT_STOPPING)
CASE(OBS_WEBSOCKET_OUTPUT_STOPPED)
CASE(OBS_WEBSOCKET_OUTPUT_PAUSED)
CASE(OBS_WEBSOCKET_OUTPUT_RESUMED)
}
}