Skip to content

Commit 001e06e

Browse files
committed
Fix output source canvas support
1 parent fda1938 commit 001e06e

2 files changed

Lines changed: 46 additions & 56 deletions

File tree

‎downstream-keyer-dock.cpp‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern "C" {
3232
size_t get_view_count();
3333
const char *get_view_name(size_t idx);
3434
obs_view_t *get_view_by_name(const char *view_name);
35+
obs_canvas_t *get_canvas_by_name(const char *view_name);
3536
obs_source_t *get_source_from_view(const char *view_name, uint32_t channel);
3637
};
3738

@@ -61,6 +62,15 @@ obs_view_t *get_view_by_name(const char *view_name)
6162
return view;
6263
}
6364

65+
obs_canvas_t *get_canvas_by_name(const char *view_name)
66+
{
67+
auto it = _dsks.find(view_name);
68+
if (it == _dsks.end())
69+
return NULL;
70+
obs_canvas_t *canvas = it->second->GetCanvas();
71+
return canvas;
72+
}
73+
6474
obs_source_t *get_source_from_view(const char *view_name, uint32_t channel)
6575
{
6676
obs_source_t *source = nullptr;
@@ -69,6 +79,12 @@ obs_source_t *get_source_from_view(const char *view_name, uint32_t channel)
6979
obs_view_t *view = it->second->GetView();
7080
if (view) {
7181
source = obs_view_get_source(view, channel);
82+
} else {
83+
obs_canvas_t *canvas = it->second->GetCanvas();
84+
if (canvas) {
85+
source = obs_canvas_get_channel(canvas, channel);
86+
obs_canvas_release(canvas);
87+
}
7288
}
7389
}
7490
return source;

‎output-source.c‎

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct output_source_context {
1919
size_t get_view_count();
2020
const char *get_view_name(size_t idx);
2121
obs_view_t *get_view_by_name(const char *view_name);
22+
obs_canvas_t *get_canvas_by_name(const char *view_name);
2223
obs_source_t *get_source_from_view(const char *view_name, uint32_t channel);
2324

2425
static const char *output_source_get_name(void *type_data)
@@ -37,14 +38,12 @@ static void output_source_update(void *data, obs_data_t *settings)
3738
}
3839

3940
context->channel = (uint32_t)obs_data_get_int(settings, "channel");
40-
vec4_from_rgba(&context->color,
41-
(uint32_t)obs_data_get_int(settings, "color"));
41+
vec4_from_rgba(&context->color, (uint32_t)obs_data_get_int(settings, "color"));
4242
}
4343

4444
static void *output_source_create(obs_data_t *settings, obs_source_t *source)
4545
{
46-
struct output_source_context *context =
47-
bzalloc(sizeof(struct output_source_context));
46+
struct output_source_context *context = bzalloc(sizeof(struct output_source_context));
4847
context->source = source;
4948

5049
output_source_update(context, settings);
@@ -65,13 +64,10 @@ static void output_source_destroy(void *data)
6564

6665
#define channel_name_count 7
6766

68-
static char *channel_names[] = {"StudioMode.Program", "Basic.DesktopDevice1",
69-
"Basic.DesktopDevice2", "Basic.AuxDevice1",
70-
"Basic.AuxDevice2", "Basic.AuxDevice3",
71-
"Basic.AuxDevice4"};
67+
static char *channel_names[] = {"StudioMode.Program", "Basic.DesktopDevice1", "Basic.DesktopDevice2", "Basic.AuxDevice1",
68+
"Basic.AuxDevice2", "Basic.AuxDevice3", "Basic.AuxDevice4"};
7269

73-
static bool view_changed(void *priv, obs_properties_t *props,
74-
obs_property_t *property, obs_data_t *settings)
70+
static bool view_changed(void *priv, obs_properties_t *props, obs_property_t *property, obs_data_t *settings)
7571
{
7672
UNUSED_PARAMETER(priv);
7773
UNUSED_PARAMETER(property);
@@ -80,23 +76,21 @@ static bool view_changed(void *priv, obs_properties_t *props,
8076
bool changed = false;
8177
struct dstr buffer = {0};
8278
obs_view_t *view = get_view_by_name(view_name);
79+
obs_canvas_t *canvas = get_canvas_by_name(view_name);
8380

8481
for (uint32_t i = 0; i < MAX_CHANNELS; i++) {
8582
if (i >= channel_name_count || (strlen(view_name) && i > 0)) {
8683
dstr_printf(&buffer, "%i", i);
8784
} else {
88-
dstr_copy(&buffer, obs_frontend_get_locale_string(
89-
channel_names[i]));
85+
dstr_copy(&buffer, obs_frontend_get_locale_string(channel_names[i]));
9086
}
9187

9288
obs_source_t *source = view ? obs_view_get_source(view, i)
93-
: obs_get_output_source(i);
89+
: (canvas ? obs_canvas_get_channel(canvas, i) : obs_get_output_source(i));
9490
if (source) {
95-
if (obs_source_get_type(source) ==
96-
OBS_SOURCE_TYPE_TRANSITION) {
91+
if (obs_source_get_type(source) == OBS_SOURCE_TYPE_TRANSITION) {
9792
obs_source_t *transition = source;
98-
source = obs_transition_get_active_source(
99-
transition);
93+
source = obs_transition_get_active_source(transition);
10094
if (source) {
10195
obs_source_release(transition);
10296
} else {
@@ -107,14 +101,13 @@ static bool view_changed(void *priv, obs_properties_t *props,
107101
dstr_cat(&buffer, obs_source_get_name(source));
108102
obs_source_release(source);
109103
}
110-
if (strcmp(buffer.array,
111-
obs_property_list_item_name(channels, i)) != 0) {
104+
if (strcmp(buffer.array, obs_property_list_item_name(channels, i)) != 0) {
112105
obs_property_list_item_remove(channels, i);
113-
obs_property_list_insert_int(channels, i, buffer.array,
114-
i);
106+
obs_property_list_insert_int(channels, i, buffer.array, i);
115107
changed = true;
116108
}
117109
}
110+
obs_canvas_release(canvas);
118111
dstr_free(&buffer);
119112
return changed;
120113
}
@@ -125,36 +118,28 @@ static obs_properties_t *output_source_properties(void *data)
125118

126119
size_t c = get_view_count();
127120
if (c > 1) {
128-
obs_property_t *p = obs_properties_add_list(
129-
ppts, "view", obs_module_text("View"),
130-
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
121+
obs_property_t *p = obs_properties_add_list(ppts, "view", obs_module_text("View"), OBS_COMBO_TYPE_LIST,
122+
OBS_COMBO_FORMAT_STRING);
131123
for (size_t i = 0; i < c; i++) {
132124
const char *name = get_view_name(i);
133125
obs_property_list_add_string(p, name, name);
134126
}
135127
obs_property_set_modified_callback2(p, view_changed, data);
136128
}
137-
obs_property_t *p = obs_properties_add_list(ppts, "channel",
138-
obs_module_text("Channel"),
139-
OBS_COMBO_TYPE_LIST,
140-
OBS_COMBO_FORMAT_INT);
129+
obs_property_t *p =
130+
obs_properties_add_list(ppts, "channel", obs_module_text("Channel"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
141131
char buffer[10];
142132

143133
for (int i = 0; i < MAX_CHANNELS; i++) {
144134
if (i < channel_name_count) {
145-
obs_property_list_add_int(
146-
p,
147-
obs_frontend_get_locale_string(
148-
channel_names[i]),
149-
i);
135+
obs_property_list_add_int(p, obs_frontend_get_locale_string(channel_names[i]), i);
150136
} else {
151137
snprintf(buffer, 10, "%i", i);
152138
obs_property_list_add_int(p, buffer, i);
153139
}
154140
}
155141

156-
obs_properties_add_color(ppts, "color",
157-
obs_module_text("FallbackColor"));
142+
obs_properties_add_color(ppts, "color", obs_module_text("FallbackColor"));
158143
return ppts;
159144
}
160145

@@ -171,21 +156,17 @@ static void output_source_video_render(void *data, gs_effect_t *effect)
171156
gs_texture_t *tex = gs_texrender_get_texture(context->render);
172157
if (tex) {
173158
effect = obs_get_base_effect(OBS_EFFECT_DEFAULT);
174-
gs_eparam_t *image =
175-
gs_effect_get_param_by_name(effect, "image");
159+
gs_eparam_t *image = gs_effect_get_param_by_name(effect, "image");
176160
gs_effect_set_texture(image, tex);
177161
while (gs_effect_loop(effect, "Draw"))
178-
gs_draw_sprite(tex, 0, context->width,
179-
context->height);
162+
gs_draw_sprite(tex, 0, context->width, context->height);
180163
return;
181164
}
182165
}
183166

184-
if (context->rendering || context->recurring ||
185-
!context->outputSource) {
167+
if (context->rendering || context->recurring || !context->outputSource) {
186168
gs_effect_t *solid = obs_get_base_effect(OBS_EFFECT_SOLID);
187-
gs_eparam_t *color =
188-
gs_effect_get_param_by_name(solid, "color");
169+
gs_eparam_t *color = gs_effect_get_param_by_name(solid, "color");
189170
gs_technique_t *tech = gs_effect_get_technique(solid, "Solid");
190171

191172
gs_effect_set_vec4(color, &context->color);
@@ -217,8 +198,7 @@ static uint32_t output_source_getheight(void *data)
217198
return context->height;
218199
}
219200

220-
static void check_recursion(obs_source_t *parent, obs_source_t *child,
221-
void *data)
201+
static void check_recursion(obs_source_t *parent, obs_source_t *child, void *data)
222202
{
223203
UNUSED_PARAMETER(parent);
224204
struct output_source_context *context = data;
@@ -231,11 +211,8 @@ static void output_source_video_tick(void *data, float seconds)
231211
{
232212
UNUSED_PARAMETER(seconds);
233213
struct output_source_context *context = data;
234-
obs_source_t *source =
235-
strlen(context->view_name)
236-
? get_source_from_view(context->view_name,
237-
context->channel)
238-
: obs_get_output_source(context->channel);
214+
obs_source_t *source = strlen(context->view_name) ? get_source_from_view(context->view_name, context->channel)
215+
: obs_get_output_source(context->channel);
239216
if (!source) {
240217
if (context->outputSource) {
241218
context->outputSource = NULL;
@@ -252,22 +229,19 @@ static void output_source_video_tick(void *data, float seconds)
252229
obs_enter_graphics();
253230
if (!context->render) {
254231

255-
context->render =
256-
gs_texrender_create(GS_RGBA, GS_ZS_NONE);
232+
context->render = gs_texrender_create(GS_RGBA, GS_ZS_NONE);
257233
} else {
258234
gs_texrender_reset(context->render);
259235
}
260236
gs_blend_state_push();
261237
gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO);
262238

263-
if (gs_texrender_begin(context->render, context->width,
264-
context->height)) {
239+
if (gs_texrender_begin(context->render, context->width, context->height)) {
265240
struct vec4 clear_color;
266241

267242
vec4_zero(&clear_color);
268243
gs_clear(GS_CLEAR_COLOR, &clear_color, 0.0f, 0);
269-
gs_ortho(0.0f, (float)context->width, 0.0f,
270-
(float)context->height, -100.0f, 100.0f);
244+
gs_ortho(0.0f, (float)context->width, 0.0f, (float)context->height, -100.0f, 100.0f);
271245

272246
obs_source_video_render(context->outputSource);
273247

0 commit comments

Comments
 (0)