Create an endpoint to view basic video info eg canvas size

This commit is contained in:
Chris Angelico 2019-05-09 05:58:55 +10:00
parent 83bef1a840
commit 7c457546f1
3 changed files with 24 additions and 0 deletions

@ -31,6 +31,7 @@ QHash<QString, HandlerResponse(*)(WSRequestHandler*)> WSRequestHandler::messageM
{ "GetStats", WSRequestHandler::HandleGetStats },
{ "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat },
{ "GetVideoInfo", WSRequestHandler::HandleGetVideoInfo },
{ "SetFilenameFormatting", WSRequestHandler::HandleSetFilenameFormatting },
{ "GetFilenameFormatting", WSRequestHandler::HandleGetFilenameFormatting },

@ -65,6 +65,7 @@ class WSRequestHandler : public QObject {
static HandlerResponse HandleGetStats(WSRequestHandler* req);
static HandlerResponse HandleSetHeartbeat(WSRequestHandler* req);
static HandlerResponse HandleGetVideoInfo(WSRequestHandler* req);
static HandlerResponse HandleSetFilenameFormatting(WSRequestHandler* req);
static HandlerResponse HandleGetFilenameFormatting(WSRequestHandler* req);

@ -181,3 +181,25 @@ HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) {
obs_data_set_obj(response, "stats", stats);
return req->SendOKResponse(response);
}
/**
* Get basic OBS video information
*
* @return {Number} `base_width` Base (canvas) width
* @return {Number} `base_height` Base (canvas) height
*
* @api requests
* @name GetVideoInfo
* @category general
* @since 4.6.0
*/
HandlerResponse WSRequestHandler::HandleGetVideoInfo(WSRequestHandler* req) {
obs_video_info ovi; obs_get_video_info(&ovi);
OBSDataAutoRelease response = obs_data_create();
obs_data_set_int(response, "base_width", ovi.base_width);
obs_data_set_int(response, "base_height", ovi.base_height);
obs_data_set_int(response, "output_width", ovi.output_width);
obs_data_set_int(response, "output_height", ovi.output_height);
obs_data_set_double(response, "fps", (double)ovi.fps_num / ovi.fps_den); //TODO: Convert to floating-point FPS?
return req->SendOKResponse(response);
}