diff --git a/src/requesthandler/RequestHandler.cpp b/src/requesthandler/RequestHandler.cpp index ca1275ab..075ade1d 100644 --- a/src/requesthandler/RequestHandler.cpp +++ b/src/requesthandler/RequestHandler.cpp @@ -143,6 +143,7 @@ const std::unordered_map RequestHandler::_han {"ToggleStream", &RequestHandler::ToggleStream}, {"StartStream", &RequestHandler::StartStream}, {"StopStream", &RequestHandler::StopStream}, + {"SendStreamCaption", &RequestHandler::SendStreamCaption}, // Record {"GetRecordStatus", &RequestHandler::GetRecordStatus}, diff --git a/src/requesthandler/RequestHandler.h b/src/requesthandler/RequestHandler.h index 2e5927de..d678ecf4 100644 --- a/src/requesthandler/RequestHandler.h +++ b/src/requesthandler/RequestHandler.h @@ -161,6 +161,7 @@ class RequestHandler { RequestResult ToggleStream(const Request&); RequestResult StartStream(const Request&); RequestResult StopStream(const Request&); + RequestResult SendStreamCaption(const Request&); // Record RequestResult GetRecordStatus(const Request&); diff --git a/src/requesthandler/RequestHandler_Stream.cpp b/src/requesthandler/RequestHandler_Stream.cpp index 98c9e60b..367ebd48 100644 --- a/src/requesthandler/RequestHandler_Stream.cpp +++ b/src/requesthandler/RequestHandler_Stream.cpp @@ -122,3 +122,35 @@ RequestResult RequestHandler::StopStream(const Request&) return RequestResult::Success(); } + +/** + * Sends CEA-608 caption text over the stream output. + * + * @requestField captionText | String | Caption text + * + * @requestType SendStreamCaption + * @complexity 2 + * @rpcVersion -1 + * @initialVersion 5.0.0 + * @category stream + * @api requests + */ +RequestResult RequestHandler::SendStreamCaption(const Request& request) +{ + RequestStatus::RequestStatus statusCode; + std::string comment; + if (!request.ValidateString("captionText", statusCode, comment, true)) + return RequestResult::Error(statusCode, comment); + + if (!obs_frontend_streaming_active()) + return RequestResult::Error(RequestStatus::OutputNotRunning); + + std::string captionText = request.RequestData["captionText"]; + + OBSOutputAutoRelease output = obs_frontend_get_streaming_output(); + + // 0.0 means no delay until the next caption can be sent + obs_output_output_caption_text2(output, captionText.c_str(), 0.0); + + return RequestResult::Success(); +}