Skip to content

Commit 748dba6

Browse files
committed
requesthandler: Add Canvas support
1 parent 1c9306b commit 748dba6

15 files changed

+297
-56
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ target_sources(
8080
src/requesthandler/RequestBatchHandler.h
8181
src/requesthandler/RequestHandler.cpp
8282
src/requesthandler/RequestHandler.h
83+
src/requesthandler/RequestHandler_Canvases.cpp
8384
src/requesthandler/RequestHandler_Config.cpp
8485
src/requesthandler/RequestHandler_Filters.cpp
8586
src/requesthandler/RequestHandler_General.cpp

src/requesthandler/RequestHandler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
5353
{"GetRecordDirectory", &RequestHandler::GetRecordDirectory},
5454
{"SetRecordDirectory", &RequestHandler::SetRecordDirectory},
5555

56+
// Canvases
57+
{"GetCanvasList", &RequestHandler::GetCanvasList},
58+
5659
// Sources
5760
{"GetSourceActive", &RequestHandler::GetSourceActive},
5861
{"GetSourceScreenshot", &RequestHandler::GetSourceScreenshot},

src/requesthandler/RequestHandler.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class RequestHandler {
7272
RequestResult GetRecordDirectory(const Request &);
7373
RequestResult SetRecordDirectory(const Request &);
7474

75+
// Canvases
76+
RequestResult GetCanvasList(const Request &);
77+
7578
// Sources
7679
RequestResult GetSourceActive(const Request &);
7780
RequestResult GetSourceScreenshot(const Request &);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
obs-websocket
3+
Copyright (C) 2016-2021 Stephane Lepin <[email protected]>
4+
Copyright (C) 2020-2021 Kyle Manning <[email protected]>
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation; either version 2 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License along
17+
with this program. If not, see <https://www.gnu.org/licenses/>
18+
*/
19+
20+
#include "RequestHandler.h"
21+
22+
/**
23+
* Gets an array of canvases in OBS.
24+
*
25+
* @responseField canvases | Array<Object> | Array of canvases
26+
*
27+
* @requestType GetCanvasList
28+
* @complexity 2
29+
* @rpcVersion -1
30+
* @initialVersion 5.0.0
31+
* @api requests
32+
* @category scenes
33+
*/
34+
RequestResult RequestHandler::GetCanvasList(const Request &request)
35+
{
36+
json responseData;
37+
std::vector<json> ret;
38+
39+
obs_enum_canvases(
40+
[](void *param, obs_canvas_t *canvas) {
41+
auto ret = static_cast<std::vector<json> *>(param);
42+
json canvasJson;
43+
canvasJson["canvasName"] = obs_canvas_get_name(canvas);
44+
canvasJson["canvasUuid"] = obs_canvas_get_uuid(canvas);
45+
struct obs_video_info ovi;
46+
if (obs_canvas_get_video_info(canvas, &ovi)) {
47+
canvasJson["fpsNumerator"] = ovi.fps_num;
48+
canvasJson["fpsDenominator"] = ovi.fps_den;
49+
canvasJson["baseWidth"] = ovi.base_width;
50+
canvasJson["baseHeight"] = ovi.base_height;
51+
canvasJson["outputWidth"] = ovi.output_width;
52+
canvasJson["outputHeight"] = ovi.output_height;
53+
}
54+
ret->push_back(canvasJson);
55+
return true;
56+
},
57+
&ret);
58+
responseData["canvases"] = ret;
59+
60+
return RequestResult::Success(responseData);
61+
}

src/requesthandler/RequestHandler_Filters.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ RequestResult RequestHandler::GetSourceFilterKindList(const Request &)
4343
/**
4444
* Gets an array of all of a source's filters.
4545
*
46+
* @requestField ?canvasName | String | Name of the canvas the source is in
47+
* @requestField ?canvasUuid | String | UUID of the canvas the source is in
4648
* @requestField ?sourceName | String | Name of the source
4749
* @requestField ?sourceUuid | String | UUID of the source
4850
*
@@ -107,6 +109,8 @@ RequestResult RequestHandler::GetSourceFilterDefaultSettings(const Request &requ
107109
/**
108110
* Creates a new filter, adding it to the specified source.
109111
*
112+
* @requestField ?canvasName | String | Name of the canvas the source is in
113+
* @requestField ?canvasUuid | String | UUID of the canvas the source is in
110114
* @requestField ?sourceName | String | Name of the source to add the filter to
111115
* @requestField ?sourceUuid | String | UUID of the source to add the filter to
112116
* @requestField filterName | String | Name of the new filter to be created
@@ -161,6 +165,8 @@ RequestResult RequestHandler::CreateSourceFilter(const Request &request)
161165
/**
162166
* Removes a filter from a source.
163167
*
168+
* @requestField ?canvasName | String | Name of the canvas the source is in
169+
* @requestField ?canvasUuid | String | UUID of the canvas the source is in
164170
* @requestField ?sourceName | String | Name of the source the filter is on
165171
* @requestField ?sourceUuid | String | UUID of the source the filter is on
166172
* @requestField filterName | String | Name of the filter to remove
@@ -188,6 +194,8 @@ RequestResult RequestHandler::RemoveSourceFilter(const Request &request)
188194
/**
189195
* Sets the name of a source filter (rename).
190196
*
197+
* @requestField ?canvasName | String | Name of the canvas the source is in
198+
* @requestField ?canvasUuid | String | UUID of the canvas the source is in
191199
* @requestField ?sourceName | String | Name of the source the filter is on
192200
* @requestField ?sourceUuid | String | UUID of the source the filter is on
193201
* @requestField filterName | String | Current name of the filter
@@ -222,6 +230,8 @@ RequestResult RequestHandler::SetSourceFilterName(const Request &request)
222230
/**
223231
* Gets the info for a specific source filter.
224232
*
233+
* @requestField ?canvasName | String | Name of the canvas the source is in
234+
* @requestField ?canvasUuid | String | UUID of the canvas the source is in
225235
* @requestField ?sourceName | String | Name of the source
226236
* @requestField ?sourceUuid | String | UUID of the source
227237
* @requestField filterName | String | Name of the filter
@@ -262,6 +272,8 @@ RequestResult RequestHandler::GetSourceFilter(const Request &request)
262272
/**
263273
* Sets the index position of a filter on a source.
264274
*
275+
* @requestField ?canvasName | String | Name of the canvas the source is in
276+
* @requestField ?canvasUuid | String | UUID of the canvas the source is in
265277
* @requestField ?sourceName | String | Name of the source the filter is on
266278
* @requestField ?sourceUuid | String | UUID of the source the filter is on
267279
* @requestField filterName | String | Name of the filter
@@ -292,6 +304,8 @@ RequestResult RequestHandler::SetSourceFilterIndex(const Request &request)
292304
/**
293305
* Sets the settings of a source filter.
294306
*
307+
* @requestField ?canvasName | String | Name of the canvas the source is in
308+
* @requestField ?canvasUuid | String | UUID of the canvas the source is in
295309
* @requestField ?sourceName | String | Name of the source the filter is on
296310
* @requestField ?sourceUuid | String | UUID of the source the filter is on
297311
* @requestField filterName | String | Name of the filter to set the settings of
@@ -341,6 +355,8 @@ RequestResult RequestHandler::SetSourceFilterSettings(const Request &request)
341355
/**
342356
* Sets the enable state of a source filter.
343357
*
358+
* @requestField ?canvasName | String | Name of the canvas the source is in
359+
* @requestField ?canvasUuid | String | UUID of the canvas the source is in
344360
* @requestField ?sourceName | String | Name of the source the filter is on
345361
* @requestField ?sourceUuid | String | UUID of the source the filter is on
346362
* @requestField filterName | String | Name of the filter

src/requesthandler/RequestHandler_Inputs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ RequestResult RequestHandler::GetSpecialInputs(const Request &)
123123
/**
124124
* Creates a new input, adding it as a scene item to the specified scene.
125125
*
126+
* @requestField ?canvasName | String | Name of the canvas the scene is in
127+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
126128
* @requestField ?sceneName | String | Name of the scene to add the input to as a scene item
127129
* @requestField ?sceneUuid | String | UUID of the scene to add the input to as a scene item
128130
* @requestField inputName | String | Name of the new input to created

src/requesthandler/RequestHandler_SceneItems.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ with this program. If not, see <https://www.gnu.org/licenses/>
2424
*
2525
* Scenes only
2626
*
27-
* @requestField ?sceneName | String | Name of the scene to get the items of
28-
* @requestField ?sceneUuid | String | UUID of the scene to get the items of
27+
* @requestField ?canvasName | String | Name of the canvas the scene is in
28+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
29+
* @requestField ?sceneName | String | Name of the scene to get the items of
30+
* @requestField ?sceneUuid | String | UUID of the scene to get the items of
2931
*
3032
* @responseField sceneItems | Array<Object> | Array of scene items in the scene
3133
*
@@ -57,8 +59,10 @@ RequestResult RequestHandler::GetSceneItemList(const Request &request)
5759
*
5860
* Groups only
5961
*
60-
* @requestField ?sceneName | String | Name of the group to get the items of
61-
* @requestField ?sceneUuid | String | UUID of the group to get the items of
62+
* @requestField ?canvasName | String | Name of the canvas the group is in
63+
* @requestField ?canvasUuid | String | UUID of the canvas the group is in
64+
* @requestField ?sceneName | String | Name of the group to get the items of
65+
* @requestField ?sceneUuid | String | UUID of the group to get the items of
6266
*
6367
* @responseField sceneItems | Array<Object> | Array of scene items in the group
6468
*
@@ -88,6 +92,8 @@ RequestResult RequestHandler::GetGroupSceneItemList(const Request &request)
8892
*
8993
* Scenes and Groups
9094
*
95+
* @requestField ?canvasName | String | Name of the canvas the scene or group is in
96+
* @requestField ?canvasUuid | String | UUID of the canvas the scene or group is in
9197
* @requestField ?sceneName | String | Name of the scene or group to search in
9298
* @requestField ?sceneUuid | String | UUID of the scene or group to search in
9399
* @requestField sourceName | String | Name of the source to find
@@ -133,6 +139,8 @@ RequestResult RequestHandler::GetSceneItemId(const Request &request)
133139
/**
134140
* Gets the source associated with a scene item.
135141
*
142+
* @requestField ?canvasName | String | Name of the canvas the scene is in
143+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
136144
* @requestField ?sceneName | String | Name of the scene the item is in
137145
* @requestField ?sceneUuid | String | UUID of the scene the item is in
138146
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -169,6 +177,8 @@ RequestResult RequestHandler::GetSceneItemSource(const Request &request)
169177
*
170178
* Scenes only
171179
*
180+
* @requestField ?canvasName | String | Name of the canvas the scene is in
181+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
172182
* @requestField ?sceneName | String | Name of the scene to create the new item in
173183
* @requestField ?sceneUuid | String | UUID of the scene to create the new item in
174184
* @requestField ?sourceName | String | Name of the source to add to the scene
@@ -223,6 +233,8 @@ RequestResult RequestHandler::CreateSceneItem(const Request &request)
223233
*
224234
* Scenes only
225235
*
236+
* @requestField ?canvasName | String | Name of the canvas the scene is in
237+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
226238
* @requestField ?sceneName | String | Name of the scene the item is in
227239
* @requestField ?sceneUuid | String | UUID of the scene the item is in
228240
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -253,6 +265,8 @@ RequestResult RequestHandler::RemoveSceneItem(const Request &request)
253265
*
254266
* Scenes only
255267
*
268+
* @requestField ?canvasName | String | Name of the canvas the scene is in
269+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
256270
* @requestField ?sceneName | String | Name of the scene the item is in
257271
* @requestField ?sceneUuid | String | UUID of the scene the item is in
258272
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -330,6 +344,8 @@ RequestResult RequestHandler::DuplicateSceneItem(const Request &request)
330344
*
331345
* Scenes and Groups
332346
*
347+
* @requestField ?canvasName | String | Name of the canvas the scene is in
348+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
333349
* @requestField ?sceneName | String | Name of the scene the item is in
334350
* @requestField ?sceneUuid | String | UUID of the scene the item is in
335351
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -361,6 +377,8 @@ RequestResult RequestHandler::GetSceneItemTransform(const Request &request)
361377
/**
362378
* Sets the transform and crop info of a scene item.
363379
*
380+
* @requestField ?canvasName | String | Name of the canvas the scene is in
381+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
364382
* @requestField ?sceneName | String | Name of the scene the item is in
365383
* @requestField ?sceneUuid | String | UUID of the scene the item is in
366384
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -526,6 +544,8 @@ RequestResult RequestHandler::SetSceneItemTransform(const Request &request)
526544
*
527545
* Scenes and Groups
528546
*
547+
* @requestField ?canvasName | String | Name of the canvas the scene is in
548+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
529549
* @requestField ?sceneName | String | Name of the scene the item is in
530550
* @requestField ?sceneUuid | String | UUID of the scene the item is in
531551
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -559,6 +579,8 @@ RequestResult RequestHandler::GetSceneItemEnabled(const Request &request)
559579
*
560580
* Scenes and Groups
561581
*
582+
* @requestField ?canvasName | String | Name of the canvas the scene is in
583+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
562584
* @requestField ?sceneName | String | Name of the scene the item is in
563585
* @requestField ?sceneUuid | String | UUID of the scene the item is in
564586
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -592,6 +614,8 @@ RequestResult RequestHandler::SetSceneItemEnabled(const Request &request)
592614
*
593615
* Scenes and Groups
594616
*
617+
* @requestField ?canvasName | String | Name of the canvas the scene is in
618+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
595619
* @requestField ?sceneName | String | Name of the scene the item is in
596620
* @requestField ?sceneUuid | String | UUID of the scene the item is in
597621
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -625,6 +649,8 @@ RequestResult RequestHandler::GetSceneItemLocked(const Request &request)
625649
*
626650
* Scenes and Group
627651
*
652+
* @requestField ?canvasName | String | Name of the canvas the scene is in
653+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
628654
* @requestField ?sceneName | String | Name of the scene the item is in
629655
* @requestField ?sceneUuid | String | UUID of the scene the item is in
630656
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -660,6 +686,8 @@ RequestResult RequestHandler::SetSceneItemLocked(const Request &request)
660686
*
661687
* Scenes and Groups
662688
*
689+
* @requestField ?canvasName | String | Name of the canvas the scene is in
690+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
663691
* @requestField ?sceneName | String | Name of the scene the item is in
664692
* @requestField ?sceneUuid | String | UUID of the scene the item is in
665693
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -693,6 +721,8 @@ RequestResult RequestHandler::GetSceneItemIndex(const Request &request)
693721
*
694722
* Scenes and Groups
695723
*
724+
* @requestField ?canvasName | String | Name of the canvas the scene is in
725+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
696726
* @requestField ?sceneName | String | Name of the scene the item is in
697727
* @requestField ?sceneUuid | String | UUID of the scene the item is in
698728
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -736,6 +766,8 @@ RequestResult RequestHandler::SetSceneItemIndex(const Request &request)
736766
*
737767
* Scenes and Groups
738768
*
769+
* @requestField ?canvasName | String | Name of the canvas the scene is in
770+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
739771
* @requestField ?sceneName | String | Name of the scene the item is in
740772
* @requestField ?sceneUuid | String | UUID of the scene the item is in
741773
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0
@@ -771,6 +803,8 @@ RequestResult RequestHandler::GetSceneItemBlendMode(const Request &request)
771803
*
772804
* Scenes and Groups
773805
*
806+
* @requestField ?canvasName | String | Name of the canvas the scene is in
807+
* @requestField ?canvasUuid | String | UUID of the canvas the scene is in
774808
* @requestField ?sceneName | String | Name of the scene the item is in
775809
* @requestField ?sceneUuid | String | UUID of the scene the item is in
776810
* @requestField sceneItemId | Number | Numeric ID of the scene item | >= 0

0 commit comments

Comments
 (0)