requesthandler, eventhandler: Add outputPath fields when record stops

Closes #934
This commit is contained in:
tt2468 2022-07-02 07:00:51 -07:00
parent 3deea2b5da
commit 4201664c7b
5 changed files with 37 additions and 5 deletions

View File

@ -62,6 +62,7 @@ void EventHandler::HandleStreamStateChanged(ObsOutputState state)
* *
* @dataField outputActive | Boolean | Whether the output is active * @dataField outputActive | Boolean | Whether the output is active
* @dataField outputState | String | The specific state of the output * @dataField outputState | String | The specific state of the output
* @dataField outputPath | String | File name for the saved recording, if record stopped. `null` otherwise
* *
* @eventType RecordStateChanged * @eventType RecordStateChanged
* @eventSubscription Outputs * @eventSubscription Outputs
@ -76,6 +77,11 @@ void EventHandler::HandleRecordStateChanged(ObsOutputState state)
json eventData; json eventData;
eventData["outputActive"] = GetOutputStateActive(state); eventData["outputActive"] = GetOutputStateActive(state);
eventData["outputState"] = state; eventData["outputState"] = state;
if (state == OBS_WEBSOCKET_OUTPUT_STOPPED) {
eventData["outputPath"] = Utils::Obs::StringHelper::GetLastRecordFileName();
} else {
eventData["outputPath"] = nullptr;
}
BroadcastEvent(EventSubscription::Outputs, "RecordStateChanged", eventData); BroadcastEvent(EventSubscription::Outputs, "RecordStateChanged", eventData);
} }
@ -139,6 +145,6 @@ void EventHandler::HandleVirtualcamStateChanged(ObsOutputState state)
void EventHandler::HandleReplayBufferSaved() void EventHandler::HandleReplayBufferSaved()
{ {
json eventData; json eventData;
eventData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFilePath(); eventData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFileName();
BroadcastEvent(EventSubscription::Outputs, "ReplayBufferSaved", eventData); BroadcastEvent(EventSubscription::Outputs, "ReplayBufferSaved", eventData);
} }

View File

@ -272,6 +272,6 @@ RequestResult RequestHandler::GetLastReplayBufferReplay(const Request &)
return RequestResult::Error(RequestStatus::OutputNotRunning); return RequestResult::Error(RequestStatus::OutputNotRunning);
json responseData; json responseData;
responseData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFilePath(); responseData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFileName();
return RequestResult::Success(responseData); return RequestResult::Success(responseData);
} }

View File

@ -99,6 +99,8 @@ RequestResult RequestHandler::StartRecord(const Request &)
/** /**
* Stops the record output. * Stops the record output.
* *
* @responseField outputPath | String | File name for the saved recording
*
* @requestType StopRecord * @requestType StopRecord
* @complexity 1 * @complexity 1
* @rpcVersion -1 * @rpcVersion -1
@ -114,7 +116,10 @@ RequestResult RequestHandler::StopRecord(const Request &)
// TODO: Call signal directly to perform blocking wait // TODO: Call signal directly to perform blocking wait
obs_frontend_recording_stop(); obs_frontend_recording_stop();
return RequestResult::Success(); json responseData;
responseData["outputPath"] = Utils::Obs::StringHelper::GetLastRecordFileName();
return RequestResult::Success(responseData);
} }
/** /**

View File

@ -179,7 +179,8 @@ namespace Utils {
std::string GetCurrentProfile(); std::string GetCurrentProfile();
std::string GetCurrentProfilePath(); std::string GetCurrentProfilePath();
std::string GetCurrentRecordOutputPath(); std::string GetCurrentRecordOutputPath();
std::string GetLastReplayBufferFilePath(); std::string GetLastRecordFileName();
std::string GetLastReplayBufferFileName();
std::string DurationToTimecode(uint64_t); std::string DurationToTimecode(uint64_t);
} }

View File

@ -72,7 +72,27 @@ std::string Utils::Obs::StringHelper::GetCurrentRecordOutputPath()
return ret; return ret;
} }
std::string Utils::Obs::StringHelper::GetLastReplayBufferFilePath() std::string Utils::Obs::StringHelper::GetLastRecordFileName()
{
OBSOutputAutoRelease output = obs_frontend_get_recording_output();
if (!output)
return "";
OBSDataAutoRelease outputSettings = obs_output_get_settings(output);
obs_data_item_t *item = obs_data_item_byname(outputSettings, "url");
if (!item) {
item = obs_data_item_byname(outputSettings, "path");
if (!item)
return "";
}
std::string ret = obs_data_item_get_string(item);
obs_data_item_release(&item);
return ret;
}
std::string Utils::Obs::StringHelper::GetLastReplayBufferFileName()
{ {
OBSOutputAutoRelease output = obs_frontend_get_replay_buffer_output(); OBSOutputAutoRelease output = obs_frontend_get_replay_buffer_output();
if (!output) if (!output)