From 4201664c7b1d7dd7cec77a85310345518537e2b0 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Sat, 2 Jul 2022 07:00:51 -0700 Subject: [PATCH] requesthandler, eventhandler: Add `outputPath` fields when record stops Closes #934 --- src/eventhandler/EventHandler_Outputs.cpp | 8 ++++++- src/requesthandler/RequestHandler_Outputs.cpp | 2 +- src/requesthandler/RequestHandler_Record.cpp | 7 +++++- src/utils/Obs.h | 3 ++- src/utils/Obs_StringHelper.cpp | 22 ++++++++++++++++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/eventhandler/EventHandler_Outputs.cpp b/src/eventhandler/EventHandler_Outputs.cpp index 034c415d..2792dbd3 100644 --- a/src/eventhandler/EventHandler_Outputs.cpp +++ b/src/eventhandler/EventHandler_Outputs.cpp @@ -62,6 +62,7 @@ void EventHandler::HandleStreamStateChanged(ObsOutputState state) * * @dataField outputActive | Boolean | Whether the output is active * @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 * @eventSubscription Outputs @@ -76,6 +77,11 @@ void EventHandler::HandleRecordStateChanged(ObsOutputState state) json eventData; eventData["outputActive"] = GetOutputStateActive(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); } @@ -139,6 +145,6 @@ void EventHandler::HandleVirtualcamStateChanged(ObsOutputState state) void EventHandler::HandleReplayBufferSaved() { json eventData; - eventData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFilePath(); + eventData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFileName(); BroadcastEvent(EventSubscription::Outputs, "ReplayBufferSaved", eventData); } diff --git a/src/requesthandler/RequestHandler_Outputs.cpp b/src/requesthandler/RequestHandler_Outputs.cpp index 89564c97..f1e59945 100644 --- a/src/requesthandler/RequestHandler_Outputs.cpp +++ b/src/requesthandler/RequestHandler_Outputs.cpp @@ -272,6 +272,6 @@ RequestResult RequestHandler::GetLastReplayBufferReplay(const Request &) return RequestResult::Error(RequestStatus::OutputNotRunning); json responseData; - responseData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFilePath(); + responseData["savedReplayPath"] = Utils::Obs::StringHelper::GetLastReplayBufferFileName(); return RequestResult::Success(responseData); } diff --git a/src/requesthandler/RequestHandler_Record.cpp b/src/requesthandler/RequestHandler_Record.cpp index efea13fa..2e649bfe 100644 --- a/src/requesthandler/RequestHandler_Record.cpp +++ b/src/requesthandler/RequestHandler_Record.cpp @@ -99,6 +99,8 @@ RequestResult RequestHandler::StartRecord(const Request &) /** * Stops the record output. * + * @responseField outputPath | String | File name for the saved recording + * * @requestType StopRecord * @complexity 1 * @rpcVersion -1 @@ -114,7 +116,10 @@ RequestResult RequestHandler::StopRecord(const Request &) // TODO: Call signal directly to perform blocking wait obs_frontend_recording_stop(); - return RequestResult::Success(); + json responseData; + responseData["outputPath"] = Utils::Obs::StringHelper::GetLastRecordFileName(); + + return RequestResult::Success(responseData); } /** diff --git a/src/utils/Obs.h b/src/utils/Obs.h index a599bfd2..6298a691 100644 --- a/src/utils/Obs.h +++ b/src/utils/Obs.h @@ -179,7 +179,8 @@ namespace Utils { std::string GetCurrentProfile(); std::string GetCurrentProfilePath(); std::string GetCurrentRecordOutputPath(); - std::string GetLastReplayBufferFilePath(); + std::string GetLastRecordFileName(); + std::string GetLastReplayBufferFileName(); std::string DurationToTimecode(uint64_t); } diff --git a/src/utils/Obs_StringHelper.cpp b/src/utils/Obs_StringHelper.cpp index 58d98449..04b123b5 100644 --- a/src/utils/Obs_StringHelper.cpp +++ b/src/utils/Obs_StringHelper.cpp @@ -72,7 +72,27 @@ std::string Utils::Obs::StringHelper::GetCurrentRecordOutputPath() 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(); if (!output)