RequestHandler: Add SendStreamCaption

This commit is contained in:
tt2468 2022-02-13 15:19:53 -08:00
parent ab137ce8a4
commit fa8a091a3e
3 changed files with 34 additions and 0 deletions

View File

@ -143,6 +143,7 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
{"ToggleStream", &RequestHandler::ToggleStream},
{"StartStream", &RequestHandler::StartStream},
{"StopStream", &RequestHandler::StopStream},
{"SendStreamCaption", &RequestHandler::SendStreamCaption},
// Record
{"GetRecordStatus", &RequestHandler::GetRecordStatus},

View File

@ -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&);

View File

@ -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();
}