Skip to content

Commit

Permalink
eventhandler: Add InputSettingsChanged
Browse files Browse the repository at this point in the history
Fired when an input's settings change, like via the properties dialog
or via `SetInputSettings`.

Closes #1157
  • Loading branch information
tt2468 committed Jan 16, 2024
1 parent 52733dd commit 81b307e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/eventhandler/EventHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ EventHandler::EventHandler()
signal_handler_connect(coreSignalHandler, "source_destroy", SourceDestroyedMultiHandler, this);
signal_handler_connect(coreSignalHandler, "source_remove", SourceRemovedMultiHandler, this);
signal_handler_connect(coreSignalHandler, "source_rename", SourceRenamedMultiHandler, this);
signal_handler_connect(coreSignalHandler, "source_update", SourceUpdatedMultiHandler, this);
} else {
blog(LOG_ERROR, "[EventHandler::EventHandler] Unable to get libobs signal handler!");
}
Expand All @@ -50,6 +51,7 @@ EventHandler::~EventHandler()
signal_handler_disconnect(coreSignalHandler, "source_destroy", SourceDestroyedMultiHandler, this);
signal_handler_disconnect(coreSignalHandler, "source_remove", SourceRemovedMultiHandler, this);
signal_handler_disconnect(coreSignalHandler, "source_rename", SourceRenamedMultiHandler, this);
signal_handler_disconnect(coreSignalHandler, "source_update", SourceUpdatedMultiHandler, this);
} else {
blog(LOG_ERROR, "[EventHandler::~EventHandler] Unable to get libobs signal handler!");
}
Expand Down Expand Up @@ -588,6 +590,23 @@ void EventHandler::SourceRenamedMultiHandler(void *param, calldata_t *data)
}
}

void EventHandler::SourceUpdatedMultiHandler(void *param, calldata_t *data)
{
auto eventHandler = static_cast<EventHandler *>(param);

obs_source_t *source = GetCalldataPointer<obs_source_t>(data, "source");
if (!source)
return;

switch (obs_source_get_type(source)) {
case OBS_SOURCE_TYPE_INPUT:
eventHandler->HandleInputSettingsChanged(source);
break;
default:
break;
}
}

void EventHandler::StreamOutputReconnectHandler(void *param, calldata_t *)
{
auto eventHandler = static_cast<EventHandler *>(param);
Expand Down
8 changes: 5 additions & 3 deletions src/eventhandler/EventHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ class EventHandler {
static void SourceCreatedMultiHandler(void *param, calldata_t *data);
static void SourceDestroyedMultiHandler(void *param, calldata_t *data);
static void SourceRemovedMultiHandler(void *param, calldata_t *data);

// Signal handler: source
static void SourceRenamedMultiHandler(void *param, calldata_t *data);
static void SourceUpdatedMultiHandler(void *param, calldata_t *data);

// Signal handler: media sources
static void SourceMediaPauseMultiHandler(void *param, calldata_t *data);
static void SourceMediaPlayMultiHandler(void *param, calldata_t *data);
static void SourceMediaRestartMultiHandler(void *param, calldata_t *data);
Expand Down Expand Up @@ -106,7 +107,7 @@ class EventHandler {
void HandleInputCreated(obs_source_t *source);
void HandleInputRemoved(obs_source_t *source);
void HandleInputNameChanged(obs_source_t *source, std::string oldInputName, std::string inputName);
void HandleInputVolumeMeters(std::vector<json> inputs); // AudioMeter::Handler callback
void HandleInputSettingsChanged(obs_source_t *source);
static void HandleInputActiveStateChanged(void *param,
calldata_t *data); // Direct callback
static void HandleInputShowStateChanged(void *param,
Expand All @@ -123,6 +124,7 @@ class EventHandler {
calldata_t *data); // Direct callback
static void HandleInputAudioMonitorTypeChanged(void *param,
calldata_t *data); // Direct callback
void HandleInputVolumeMeters(std::vector<json> inputs); // AudioMeter::Handler callback

// Transitions
void HandleCurrentSceneTransitionChanged();
Expand Down
26 changes: 26 additions & 0 deletions src/eventhandler/EventHandler_Inputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,32 @@ void EventHandler::HandleInputNameChanged(obs_source_t *, std::string oldInputNa
BroadcastEvent(EventSubscription::Inputs, "InputNameChanged", eventData);
}

/**
* An input's settings have changed (been updated).
*
* Note: On some inputs, changing values in the properties dialog will cause an immediate update. Pressing the "Cancel" button will revert the settings, resulting in another event being fired.
*
* @dataField inputName | String | Name of the input
* @dataField inputSettings | Object | New settings object of the input
*
* @eventType InputSettingsChanged
* @eventSubscription Inputs
* @complexity 3
* @rpcVersion -1
* @initialVersion 5.4.0
* @api events
* @category inputs
*/
void EventHandler::HandleInputSettingsChanged(obs_source_t *source)
{
OBSDataAutoRelease inputSettings = obs_source_get_settings(source);

json eventData;
eventData["inputName"] = obs_source_get_name(source);
eventData["inputSettings"] = Utils::Json::ObsDataToJson(inputSettings);
BroadcastEvent(EventSubscription::Inputs, "InputSettingsChanged", eventData);
}

/**
* An input's active state has changed.
*
Expand Down

0 comments on commit 81b307e

Please sign in to comment.