@@ -211,37 +211,45 @@ static void maybe_set_up_gpu_rescale(struct obs_encoder *encoder)
211211 struct obs_core_video_mix * mix , * current_mix ;
212212 bool create_mix = true;
213213 const struct video_output_info * info ;
214+ uint32_t width ;
215+ uint32_t height ;
216+ enum video_format format ;
217+ enum video_colorspace space ;
218+ enum video_range_type range ;
214219
215220 if (!encoder -> media )
216221 return ;
217-
218- info = video_output_get_info (encoder -> media );
219-
220222 if (encoder -> gpu_scale_type == OBS_SCALE_DISABLE )
221223 return ;
222-
223- if (! encoder -> scaled_height && ! encoder -> scaled_width )
224+ if (! encoder -> scaled_height && ! encoder -> scaled_width && encoder -> preferred_format == VIDEO_FORMAT_NONE &&
225+ encoder -> preferred_space == VIDEO_CS_DEFAULT && encoder -> preferred_range == VIDEO_RANGE_DEFAULT )
224226 return ;
225227
228+ info = video_output_get_info (encoder -> media );
229+ width = encoder -> scaled_width ? encoder -> scaled_width : info -> width ;
230+ height = encoder -> scaled_height ? encoder -> scaled_height : info -> height ;
231+ format = encoder -> preferred_format != VIDEO_FORMAT_NONE ? encoder -> preferred_format : info -> format ;
232+ space = encoder -> preferred_space != VIDEO_CS_DEFAULT ? encoder -> preferred_space : info -> colorspace ;
233+ range = encoder -> preferred_range != VIDEO_RANGE_DEFAULT ? encoder -> preferred_range : info -> range ;
234+
226235 current_mix = get_mix_for_video (encoder -> media );
227236 if (!current_mix )
228237 return ;
229238
230239 pthread_mutex_lock (& obs -> video .mixes_mutex );
231240 for (size_t i = 0 ; i < obs -> video .mixes .num ; i ++ ) {
232241 struct obs_core_video_mix * current = obs -> video .mixes .array [i ];
233- const struct video_output_info * voi =
234- video_output_get_info (current -> video );
242+ const struct video_output_info * voi = video_output_get_info (current -> video );
235243 if (current_mix -> view != current -> view )
236244 continue ;
237245
238- if (voi -> width != encoder -> scaled_width ||
239- voi -> height != encoder -> scaled_height )
246+ if (current -> ovi -> scale_type != encoder -> gpu_scale_type )
247+ continue ;
248+
249+ if (voi -> width != width || voi -> height != height )
240250 continue ;
241251
242- if (voi -> format != info -> format ||
243- voi -> colorspace != info -> colorspace ||
244- voi -> range != info -> range )
252+ if (voi -> format != format || voi -> colorspace != space || voi -> range != range )
245253 continue ;
246254
247255 current -> encoder_refs += 1 ;
@@ -255,21 +263,15 @@ static void maybe_set_up_gpu_rescale(struct obs_encoder *encoder)
255263 if (!create_mix )
256264 return ;
257265
258- if (!current_mix -> ovi ) {
259- blog (LOG_ERROR ,
260- "maybe_set_up_gpu_rescale - no obs_video_info for current mix" );
261- return ;
262- }
263-
264266 struct obs_video_info * ovi = bzalloc (sizeof (struct obs_video_info ));
265267 * ovi = * current_mix -> ovi ;
266268
267- ovi -> output_format = info -> format ;
268- ovi -> colorspace = info -> colorspace ;
269- ovi -> range = info -> range ;
269+ ovi -> output_format = format ;
270+ ovi -> colorspace = space ;
271+ ovi -> range = range ;
270272
271- ovi -> output_height = encoder -> scaled_height ;
272- ovi -> output_width = encoder -> scaled_width ;
273+ ovi -> output_height = height ;
274+ ovi -> output_width = width ;
273275 ovi -> scale_type = encoder -> gpu_scale_type ;
274276
275277 ovi -> gpu_conversion = true;
@@ -287,19 +289,17 @@ static void maybe_set_up_gpu_rescale(struct obs_encoder *encoder)
287289 // double check that nobody else added a matching mix while we've created our mix
288290 for (size_t i = 0 ; i < obs -> video .mixes .num ; i ++ ) {
289291 struct obs_core_video_mix * current = obs -> video .mixes .array [i ];
290- const struct video_output_info * voi =
291- video_output_get_info (current -> video );
292-
292+ const struct video_output_info * voi = video_output_get_info (current -> video );
293293 if (current -> view != current_mix -> view )
294294 continue ;
295295
296- if (voi -> width != encoder -> scaled_width ||
297- voi -> height != encoder -> scaled_height )
296+ if (current -> ovi -> scale_type != encoder -> gpu_scale_type )
298297 continue ;
299298
300- if (voi -> format != info -> format ||
301- voi -> colorspace != info -> colorspace ||
302- voi -> range != info -> range )
299+ if (voi -> width != width || voi -> height != height )
300+ continue ;
301+
302+ if (voi -> format != format || voi -> colorspace != space || voi -> range != range )
303303 continue ;
304304
305305 obs_encoder_set_video (encoder , current -> video );
@@ -630,7 +630,7 @@ static void intitialize_audio_encoder(struct obs_encoder *encoder)
630630
631631static THREAD_LOCAL bool can_reroute = false;
632632
633- static inline bool obs_encoder_initialize_internal (obs_encoder_t * encoder )
633+ static bool obs_encoder_initialize_internal (obs_encoder_t * encoder )
634634{
635635 if (!encoder -> media ) {
636636 blog (LOG_ERROR ,
@@ -657,10 +657,12 @@ static inline bool obs_encoder_initialize_internal(obs_encoder_t *encoder)
657657 if (encoder -> orig_info .create ) {
658658 can_reroute = true;
659659 encoder -> info = encoder -> orig_info ;
660+
660661 if (!encoder -> video )
661662 encoder -> video = obs -> video .main_mix ;
662- encoder -> context .data = encoder -> orig_info .create (
663- encoder -> context .settings , encoder );
663+
664+ encoder -> context .data = encoder -> orig_info .create (encoder -> context .settings , encoder );
665+
664666 can_reroute = false;
665667 }
666668 if (!encoder -> context .data )
0 commit comments