From 6483dcaef0a33f9206b373253cdd3af81dfbbe68 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Fri, 7 Jun 2024 01:28:00 -0700 Subject: [PATCH] requesthandler: Add `CreateRecordChapter` The new `Hybrid MP4 [BETA]` output added in OBS adds support for writing chapter markers to the file. --- src/requesthandler/RequestHandler.cpp | 1 + src/requesthandler/RequestHandler.h | 1 + src/requesthandler/RequestHandler_Record.cpp | 35 ++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index 88ca3308..d8ef94ef 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -178,6 +178,7 @@ const std::unordered_map RequestHandler::_han {"PauseRecord", &RequestHandler::PauseRecord}, {"ResumeRecord", &RequestHandler::ResumeRecord}, {"SplitRecordFile", &RequestHandler::SplitRecordFile}, + {"CreateRecordChapter", &RequestHandler::CreateRecordChapter}, // Media Inputs {"GetMediaInputStatus", &RequestHandler::GetMediaInputStatus}, diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index 032dc9e3..ea023afd 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -197,6 +197,7 @@ class RequestHandler { RequestResult PauseRecord(const Request &); RequestResult ResumeRecord(const Request &); RequestResult SplitRecordFile(const Request &); + RequestResult CreateRecordChapter(const Request &); // Media Inputs RequestResult GetMediaInputStatus(const Request &); diff --git a/src/requesthandler/RequestHandler_Record.cpp b/src/requesthandler/RequestHandler_Record.cpp index 118e92a4..e2ad3e2c 100644 --- a/src/requesthandler/RequestHandler_Record.cpp +++ b/src/requesthandler/RequestHandler_Record.cpp @@ -211,3 +211,38 @@ RequestResult RequestHandler::SplitRecordFile(const Request &) return RequestResult::Success(); } + +/** + * Adds a new chapter marker to the file currently being recorded. + * + * Note: As of OBS 30.2.0, the only file format supporting this feature is Hybrid MP4. + * + * @requestField ?chapterName | String | Name of the new chapter + * + * @requestType CreateRecordChapter + * @complexity 2 + * @rpcVersion -1 + * @initialVersion 5.5.0 + * @api requests + * @category record + */ +RequestResult RequestHandler::CreateRecordChapter(const Request &request) +{ + std::string chapterName; + if (request.Contains("chapterName")) { + RequestStatus::RequestStatus statusCode; + std::string comment; + if (!request.ValidateOptionalString("chapterName", statusCode, comment)) + return RequestResult::Error(statusCode, comment); + chapterName = request.RequestData["chapterName"]; + } + + if (!obs_frontend_recording_active()) + return RequestResult::Error(RequestStatus::OutputNotRunning); + + if (!obs_frontend_recording_add_chapter(chapterName.empty() ? nullptr : chapterName.c_str())) + return RequestResult::Error(RequestStatus::RequestProcessingFailed, + "Verify that the output being used supports chapter markers."); + + return RequestResult::Success(); +}