From 7c457546f1e94a7dac8ed2c54d1bd807944df1b3 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Thu, 9 May 2019 05:58:55 +1000 Subject: [PATCH 1/6] Create an endpoint to view basic video info eg canvas size --- src/WSRequestHandler.cpp | 1 + src/WSRequestHandler.h | 1 + src/WSRequestHandler_General.cpp | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+) 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..e1c3383f 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -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); +} From b0e3ea8765bc294a9dbddcbefa0d3682ef6573ff Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Thu, 9 May 2019 06:03:14 +1000 Subject: [PATCH 2/6] Update docs to include GetVideoInfo --- docs/generated/comments.json | 49 ++++++++++++++++++++++++++++++++++++ docs/generated/protocol.md | 22 ++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/docs/generated/comments.json b/docs/generated/comments.json index cda71eec..d0552f66 100644 --- a/docs/generated/comments.json +++ b/docs/generated/comments.json @@ -2824,6 +2824,55 @@ "lead": "", "type": "class", "examples": [] + }, + { + "subheads": [], + "description": "Get basic OBS video information", + "return": [ + "{Number} `base_width` Base (canvas) width", + "{Number} `base_height` Base (canvas) height" + ], + "api": "requests", + "name": "GetVideoInfo", + "category": "general", + "since": "4.6.0", + "returns": [ + { + "type": "Number", + "name": "base_width", + "description": "Base (canvas) width" + }, + { + "type": "Number", + "name": "base_height", + "description": "Base (canvas) height" + } + ], + "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 24484f53..4680a0cd 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,27 @@ _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 | +| ---- | :---: | ------------| +| `base_width` | _Number_ | Base (canvas) width | +| `base_height` | _Number_ | Base (canvas) height | + + --- ## Profiles From d3a7a6ef55dba98334a2edb65dd69d01301f7158 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Fri, 10 May 2019 04:06:09 +1000 Subject: [PATCH 3/6] Make small tweaks to formatting and layout. * Switch to camelCase for output properties * Remove done TODO * Properly document all of the information returned --- src/WSRequestHandler_General.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index e1c3383f..23fcbcb7 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -185,8 +185,11 @@ HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) { /** * Get basic OBS video information * - * @return {Number} `base_width` Base (canvas) width - * @return {Number} `base_height` Base (canvas) height + * @return {Number} `baseWidth` Base (canvas) width + * @return {Number} `baseHeight` Base (canvas) height + * @return {Number} `outputWidth` Output width + * @return {Number} `outputHeight` Output height + * @return {double} `fps` Frames rendered per second * * @api requests * @name GetVideoInfo @@ -194,12 +197,13 @@ HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) { * @since 4.6.0 */ HandlerResponse WSRequestHandler::HandleGetVideoInfo(WSRequestHandler* req) { - obs_video_info ovi; obs_get_video_info(&ovi); + 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? + 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); return req->SendOKResponse(response); } From b0512b3ba75e066c8c61cc68d69e6f0f1dd6bae0 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Fri, 10 May 2019 04:33:37 +1000 Subject: [PATCH 4/6] Provide info about color space and scaling --- docs/generated/comments.json | 50 ++++++++++++++++++++++++++--- docs/generated/protocol.md | 11 +++++-- src/WSRequestHandler_General.cpp | 55 ++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 6 deletions(-) diff --git a/docs/generated/comments.json b/docs/generated/comments.json index d0552f66..7e783099 100644 --- a/docs/generated/comments.json +++ b/docs/generated/comments.json @@ -2829,8 +2829,15 @@ "subheads": [], "description": "Get basic OBS video information", "return": [ - "{Number} `base_width` Base (canvas) width", - "{Number} `base_height` Base (canvas) height" + "{Number} `baseWidth` Base (canvas) width", + "{Number} `baseHeight` Base (canvas) height", + "{Number} `outputWidth` Output width", + "{Number} `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", @@ -2839,13 +2846,48 @@ "returns": [ { "type": "Number", - "name": "base_width", + "name": "baseWidth", "description": "Base (canvas) width" }, { "type": "Number", - "name": "base_height", + "name": "baseHeight", "description": "Base (canvas) height" + }, + { + "type": "Number", + "name": "outputWidth", + "description": "Output width" + }, + { + "type": "Number", + "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": [ diff --git a/docs/generated/protocol.md b/docs/generated/protocol.md index 4680a0cd..78fbfc09 100644 --- a/docs/generated/protocol.md +++ b/docs/generated/protocol.md @@ -1199,8 +1199,15 @@ _No specified parameters._ | Name | Type | Description | | ---- | :---: | ------------| -| `base_width` | _Number_ | Base (canvas) width | -| `base_height` | _Number_ | Base (canvas) height | +| `baseWidth` | _Number_ | Base (canvas) width | +| `baseHeight` | _Number_ | Base (canvas) height | +| `outputWidth` | _Number_ | Output width | +| `outputHeight` | _Number_ | 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) | --- diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index 23fcbcb7..b258f98e 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -189,7 +189,11 @@ HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) { * @return {Number} `baseHeight` Base (canvas) height * @return {Number} `outputWidth` Output width * @return {Number} `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 @@ -205,5 +209,56 @@ HandlerResponse WSRequestHandler::HandleGetVideoInfo(WSRequestHandler* req) { 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); + + switch (ovi.output_format) { + #define CASE(x) case x: obs_data_set_string(response, "videoFormat", #x); break; + 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) + #undef CASE + default: + obs_data_set_int(response, "videoFormat", ovi.output_format); + } + + switch (ovi.colorspace) { + #define CASE(x) case x: obs_data_set_string(response, "colorSpace", #x); break; + CASE(VIDEO_CS_DEFAULT) + CASE(VIDEO_CS_601) + CASE(VIDEO_CS_709) + #undef CASE + default: + obs_data_set_int(response, "colorSpace", ovi.colorspace); + } + + switch (ovi.range) { + #define CASE(x) case x: obs_data_set_string(response, "colorRange", #x); break; + CASE(VIDEO_RANGE_DEFAULT) + CASE(VIDEO_RANGE_PARTIAL) + CASE(VIDEO_RANGE_FULL) + #undef CASE + default: + obs_data_set_int(response, "colorRange", ovi.range); + } + + switch (ovi.scale_type) { + #define CASE(x) case x: obs_data_set_string(response, "scaleType", #x); break; + CASE(VIDEO_SCALE_DEFAULT) + CASE(VIDEO_SCALE_POINT) + CASE(VIDEO_SCALE_FAST_BILINEAR) + CASE(VIDEO_SCALE_BILINEAR) + CASE(VIDEO_SCALE_BICUBIC) + #undef CASE + default: + obs_data_set_int(response, "scaleType", ovi.scale_type); + } + return req->SendOKResponse(response); } From 5834c6ed5476e3d97f5628903b9ab6b697923294 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Fri, 10 May 2019 18:48:51 +1000 Subject: [PATCH 5/6] Switch doc type from Number to int for clarity and precision --- docs/generated/comments.json | 16 ++++++++-------- docs/generated/protocol.md | 8 ++++---- src/WSRequestHandler_General.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/docs/generated/comments.json b/docs/generated/comments.json index 7e783099..107fb4e1 100644 --- a/docs/generated/comments.json +++ b/docs/generated/comments.json @@ -2829,10 +2829,10 @@ "subheads": [], "description": "Get basic OBS video information", "return": [ - "{Number} `baseWidth` Base (canvas) width", - "{Number} `baseHeight` Base (canvas) height", - "{Number} `outputWidth` Output width", - "{Number} `outputHeight` Output height", + "{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", @@ -2845,22 +2845,22 @@ "since": "4.6.0", "returns": [ { - "type": "Number", + "type": "int", "name": "baseWidth", "description": "Base (canvas) width" }, { - "type": "Number", + "type": "int", "name": "baseHeight", "description": "Base (canvas) height" }, { - "type": "Number", + "type": "int", "name": "outputWidth", "description": "Output width" }, { - "type": "Number", + "type": "int", "name": "outputHeight", "description": "Output height" }, diff --git a/docs/generated/protocol.md b/docs/generated/protocol.md index 78fbfc09..f37dbe67 100644 --- a/docs/generated/protocol.md +++ b/docs/generated/protocol.md @@ -1199,10 +1199,10 @@ _No specified parameters._ | Name | Type | Description | | ---- | :---: | ------------| -| `baseWidth` | _Number_ | Base (canvas) width | -| `baseHeight` | _Number_ | Base (canvas) height | -| `outputWidth` | _Number_ | Output width | -| `outputHeight` | _Number_ | Output height | +| `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 | diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index b258f98e..62b6fcf3 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -185,10 +185,10 @@ HandlerResponse WSRequestHandler::HandleGetStats(WSRequestHandler* req) { /** * Get basic OBS video information * - * @return {Number} `baseWidth` Base (canvas) width - * @return {Number} `baseHeight` Base (canvas) height - * @return {Number} `outputWidth` Output width - * @return {Number} `outputHeight` Output height + * @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 From d7d8d23de731e14106c3f3f72a8962cbedaae414 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Sat, 11 May 2019 01:40:44 +1000 Subject: [PATCH 6/6] Refactor enum-to-string conversions into functions --- src/WSRequestHandler_General.cpp | 103 ++++++++++++++++--------------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index 62b6fcf3..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. * @@ -209,56 +257,9 @@ HandlerResponse WSRequestHandler::HandleGetVideoInfo(WSRequestHandler* req) { 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); - - switch (ovi.output_format) { - #define CASE(x) case x: obs_data_set_string(response, "videoFormat", #x); break; - 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) - #undef CASE - default: - obs_data_set_int(response, "videoFormat", ovi.output_format); - } - - switch (ovi.colorspace) { - #define CASE(x) case x: obs_data_set_string(response, "colorSpace", #x); break; - CASE(VIDEO_CS_DEFAULT) - CASE(VIDEO_CS_601) - CASE(VIDEO_CS_709) - #undef CASE - default: - obs_data_set_int(response, "colorSpace", ovi.colorspace); - } - - switch (ovi.range) { - #define CASE(x) case x: obs_data_set_string(response, "colorRange", #x); break; - CASE(VIDEO_RANGE_DEFAULT) - CASE(VIDEO_RANGE_PARTIAL) - CASE(VIDEO_RANGE_FULL) - #undef CASE - default: - obs_data_set_int(response, "colorRange", ovi.range); - } - - switch (ovi.scale_type) { - #define CASE(x) case x: obs_data_set_string(response, "scaleType", #x); break; - CASE(VIDEO_SCALE_DEFAULT) - CASE(VIDEO_SCALE_POINT) - CASE(VIDEO_SCALE_FAST_BILINEAR) - CASE(VIDEO_SCALE_BILINEAR) - CASE(VIDEO_SCALE_BICUBIC) - #undef CASE - default: - obs_data_set_int(response, "scaleType", ovi.scale_type); - } - + 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); }