Skip to content

Commit de33628

Browse files
committed
obs_video_info: add unique id for sceneitem->canvas
Add an id field to obs_video_info so that when a new video_mix is created within maybe_set_up_gpu_rescale() we can effectively reuse a canvas for sceneItems that need to be rendered by an encoder. Resolves issue where we saw a black screen during enhanced rendering.
1 parent c8e9cc2 commit de33628

5 files changed

Lines changed: 17 additions & 2 deletions

File tree

frontend/widgets/OBSBasic.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ int OBSBasic::ResetVideo()
15051505
ovi.adapter = config_get_uint(App()->GetUserConfig(), "Video", "AdapterIdx");
15061506
ovi.gpu_conversion = true;
15071507
ovi.scale_type = GetScaleType(activeConfiguration);
1508+
ovi.id = obs_create_video_info_id();
15081509

15091510
if (ovi.base_width < 32 || ovi.base_height < 32) {
15101511
ovi.base_width = 1920;

libobs/obs-encoder.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ static void maybe_set_up_gpu_rescale(struct obs_encoder *encoder)
274274
ovi->scale_type = encoder->gpu_scale_type;
275275

276276
ovi->gpu_conversion = true;
277+
ovi->id = current_mix->ovi->id; // Copy current id so obs_source->item->canvas render works
277278

278279
mix = obs_create_video_mix(ovi);
279280
if (!mix)

libobs/obs-scene.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,10 +1086,10 @@ static void scene_video_render(void *data, gs_effect_t *effect)
10861086
gs_blend_state_push();
10871087
gs_reset_blend_state();
10881088

1089+
size_t canvas_id = (obs_get_video_rendering_canvas() != NULL) ? obs_get_video_rendering_canvas()->id : -1;
10891090
item = scene->first_item;
10901091
while (item) {
1091-
if (obs_get_video_rendering_canvas() != item->canvas &&
1092-
item->canvas != NULL) {
1092+
if (item->canvas != NULL && canvas_id != item->canvas->id) {
10931093
item = item->next;
10941094
continue;
10951095
}

libobs/obs.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1967,10 +1967,21 @@ struct obs_video_info *obs_create_video_info()
19671967
ovi->scale_type = OBS_SCALE_BILINEAR;
19681968
ovi->adapter = 0;
19691969
ovi->gpu_conversion = true;
1970+
ovi->id = obs_create_video_info_id();
19701971

19711972
return ovi;
19721973
}
19731974

1975+
size_t obs_create_video_info_id()
1976+
{
1977+
static size_t id = 0;
1978+
size_t currId = id++;
1979+
if (id == (size_t)-1) {
1980+
blog(LOG_ERROR, "obs_create_video_info_id wrap around detected!");
1981+
}
1982+
return currId;
1983+
}
1984+
19741985
size_t obs_get_video_info_count()
19751986
{
19761987
return obs->video.canvases.num;

libobs/obs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ struct obs_video_info {
224224
enum video_range_type range; /**< YUV range (if YUV) */
225225

226226
enum obs_scale_type scale_type; /**< How to scale if scaling */
227+
size_t id;
227228
};
228229

229230
/**
@@ -477,6 +478,7 @@ EXPORT bool obs_get_video_info_scene_item(obs_sceneitem_t *item,
477478
EXPORT int obs_remove_video_info(struct obs_video_info *ovi);
478479
/** Adds new video info to array of video info objects, need to be initialized */
479480
EXPORT struct obs_video_info *obs_create_video_info();
481+
EXPORT size_t obs_create_video_info_id();
480482

481483
/**
482484
* Sets base audio output format/channels/samples/etc

0 commit comments

Comments
 (0)