diff --git a/docs/generated/comments.json b/docs/generated/comments.json index ea1702fa..0c6dd592 100644 --- a/docs/generated/comments.json +++ b/docs/generated/comments.json @@ -2824,6 +2824,97 @@ "lead": "", "type": "class", "examples": [] + }, + { + "subheads": [], + "description": "Get basic OBS video information", + "return": [ + "{int} `baseWidth` Base (canvas) width", + "{int} `baseHeight` Base (canvas) height", + "{int} `outputWidth` Output width", + "{int} `outputHeight` Output height", + "{String} `scaleType` Scaling method used if output size differs from base size", + "{double} `fps` Frames rendered per second", + "{String} `videoFormat` Video color format", + "{String} `colorSpace` Color space for YUV", + "{String} `colorRange` Color range (full or partial)" + ], + "api": "requests", + "name": "GetVideoInfo", + "category": "general", + "since": "4.6.0", + "returns": [ + { + "type": "int", + "name": "baseWidth", + "description": "Base (canvas) width" + }, + { + "type": "int", + "name": "baseHeight", + "description": "Base (canvas) height" + }, + { + "type": "int", + "name": "outputWidth", + "description": "Output width" + }, + { + "type": "int", + "name": "outputHeight", + "description": "Output height" + }, + { + "type": "String", + "name": "scaleType", + "description": "Scaling method used if output size differs from base size" + }, + { + "type": "double", + "name": "fps", + "description": "Frames rendered per second" + }, + { + "type": "String", + "name": "videoFormat", + "description": "Video color format" + }, + { + "type": "String", + "name": "colorSpace", + "description": "Color space for YUV" + }, + { + "type": "String", + "name": "colorRange", + "description": "Color range (full or partial)" + } + ], + "names": [ + { + "name": "", + "description": "GetVideoInfo" + } + ], + "categories": [ + { + "name": "", + "description": "general" + } + ], + "sinces": [ + { + "name": "", + "description": "4.6.0" + } + ], + "heading": { + "level": 2, + "text": "GetVideoInfo" + }, + "lead": "", + "type": "class", + "examples": [] } ], "profiles": [ diff --git a/docs/generated/protocol.md b/docs/generated/protocol.md index 9ced7940..96af5b91 100644 --- a/docs/generated/protocol.md +++ b/docs/generated/protocol.md @@ -111,6 +111,7 @@ auth_response = base64_encode(auth_response_hash) + [SetFilenameFormatting](#setfilenameformatting) + [GetFilenameFormatting](#getfilenameformatting) + [GetStats](#getstats) + + [GetVideoInfo](#getvideoinfo) * [Profiles](#profiles-1) + [SetCurrentProfile](#setcurrentprofile) + [GetCurrentProfile](#getcurrentprofile) @@ -1181,6 +1182,34 @@ _No specified parameters._ | `stats` | _OBSStats_ | OBS stats | +--- + +### GetVideoInfo + + +- Added in v4.6.0 + +Get basic OBS video information + +**Request Fields:** + +_No specified parameters._ + +**Response Items:** + +| Name | Type | Description | +| ---- | :---: | ------------| +| `baseWidth` | _int_ | Base (canvas) width | +| `baseHeight` | _int_ | Base (canvas) height | +| `outputWidth` | _int_ | Output width | +| `outputHeight` | _int_ | Output height | +| `scaleType` | _String_ | Scaling method used if output size differs from base size | +| `fps` | _double_ | Frames rendered per second | +| `videoFormat` | _String_ | Video color format | +| `colorSpace` | _String_ | Color space for YUV | +| `colorRange` | _String_ | Color range (full or partial) | + + --- ## Profiles diff --git a/src/WSRequestHandler.cpp b/src/WSRequestHandler.cpp index 379f4204..098b84ee 100644 --- a/src/WSRequestHandler.cpp +++ b/src/WSRequestHandler.cpp @@ -31,6 +31,7 @@ QHash WSRequestHandler::messageM { "GetStats", WSRequestHandler::HandleGetStats }, { "SetHeartbeat", WSRequestHandler::HandleSetHeartbeat }, + { "GetVideoInfo", WSRequestHandler::HandleGetVideoInfo }, { "SetFilenameFormatting", WSRequestHandler::HandleSetFilenameFormatting }, { "GetFilenameFormatting", WSRequestHandler::HandleGetFilenameFormatting }, diff --git a/src/WSRequestHandler.h b/src/WSRequestHandler.h index b483d796..4bae1a53 100644 --- a/src/WSRequestHandler.h +++ b/src/WSRequestHandler.h @@ -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); diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index a53e0e36..5a8d69c7 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -5,6 +5,54 @@ #include "WSRequestHandler.h" +#define CASE(x) case x: return #x; +const char *describe_output_format(int format) { + switch (format) { + default: + CASE(VIDEO_FORMAT_NONE) + CASE(VIDEO_FORMAT_I420) + CASE(VIDEO_FORMAT_NV12) + CASE(VIDEO_FORMAT_YVYU) + CASE(VIDEO_FORMAT_YUY2) + CASE(VIDEO_FORMAT_UYVY) + CASE(VIDEO_FORMAT_RGBA) + CASE(VIDEO_FORMAT_BGRA) + CASE(VIDEO_FORMAT_BGRX) + CASE(VIDEO_FORMAT_Y800) + CASE(VIDEO_FORMAT_I444) + } +} + +const char *describe_color_space(int cs) { + switch (cs) { + default: + CASE(VIDEO_CS_DEFAULT) + CASE(VIDEO_CS_601) + CASE(VIDEO_CS_709) + } +} + +const char *describe_color_range(int range) { + switch (range) { + default: + CASE(VIDEO_RANGE_DEFAULT) + CASE(VIDEO_RANGE_PARTIAL) + CASE(VIDEO_RANGE_FULL) + } +} + +const char *describe_scale_type(int scale) { + switch (scale) { + default: + CASE(VIDEO_SCALE_DEFAULT) + CASE(VIDEO_SCALE_POINT) + CASE(VIDEO_SCALE_FAST_BILINEAR) + CASE(VIDEO_SCALE_BILINEAR) + CASE(VIDEO_SCALE_BICUBIC) + } +} +#undef CASE + /** * Returns the latest version of the plugin and the API. * @@ -181,3 +229,37 @@ HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) { obs_data_set_obj(response, "stats", stats); return req->SendOKResponse(response); } + +/** + * Get basic OBS video information + * + * @return {int} `baseWidth` Base (canvas) width + * @return {int} `baseHeight` Base (canvas) height + * @return {int} `outputWidth` Output width + * @return {int} `outputHeight` Output height + * @return {String} `scaleType` Scaling method used if output size differs from base size + * @return {double} `fps` Frames rendered per second + * @return {String} `videoFormat` Video color format + * @return {String} `colorSpace` Color space for YUV + * @return {String} `colorRange` Color range (full or partial) + * + * @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, "baseWidth", ovi.base_width); + obs_data_set_int(response, "baseHeight", ovi.base_height); + obs_data_set_int(response, "outputWidth", ovi.output_width); + obs_data_set_int(response, "outputHeight", ovi.output_height); + obs_data_set_double(response, "fps", (double)ovi.fps_num / ovi.fps_den); + obs_data_set_string(response, "videoFormat", describe_output_format(ovi.output_format)); + obs_data_set_string(response, "colorSpace", describe_color_space(ovi.colorspace)); + obs_data_set_string(response, "colorRange", describe_color_range(ovi.range)); + obs_data_set_string(response, "scaleType", describe_scale_type(ovi.scale_type)); + return req->SendOKResponse(response); +}