Browse Source

libobs: Remove redundant async_color_format member

jpark37 3 years ago
parent
commit
72224f0fae
3 changed files with 28 additions and 42 deletions
  1. 6 16
      libobs/obs-internal.h
  2. 7 12
      libobs/obs-source-deinterlace.c
  3. 15 14
      libobs/obs-source.c

+ 6 - 16
libobs/obs-internal.h

@@ -721,7 +721,6 @@ struct obs_source {
 	enum video_format async_format;
 	bool async_full_range;
 	uint8_t async_trc;
-	enum gs_color_format async_color_format;
 	enum video_format async_cache_format;
 	bool async_cache_full_range;
 	uint8_t async_cache_trc;
@@ -897,22 +896,13 @@ convert_video_format(enum video_format format)
 	}
 }
 
-static inline enum gs_color_space
-convert_video_space(enum video_format format, enum video_trc trc,
-		    enum gs_color_format color_format, size_t count,
-		    const enum gs_color_space *preferred_spaces)
+static inline enum gs_color_space convert_video_space(enum video_format format,
+						      enum video_trc trc)
 {
-	enum gs_color_space video_space = GS_CS_SRGB;
-	if (color_format == GS_RGBA16F) {
-		video_space = (trc == VIDEO_TRC_SRGB) ? GS_CS_SRGB_16F
-						      : GS_CS_709_EXTENDED;
-	}
-
-	enum gs_color_space space = video_space;
-	for (size_t i = 0; i < count; ++i) {
-		space = preferred_spaces[i];
-		if (space == video_space)
-			break;
+	enum gs_color_space space = GS_CS_SRGB;
+	if (convert_video_format(format) == GS_RGBA16F) {
+		space = (trc == VIDEO_TRC_SRGB) ? GS_CS_SRGB_16F
+						: GS_CS_709_EXTENDED;
 	}
 
 	return space;

+ 7 - 12
libobs/obs-source-deinterlace.c

@@ -233,9 +233,12 @@ void deinterlace_process_last_frame(obs_source_t *s, uint64_t sys_time)
 
 void set_deinterlace_texture_size(obs_source_t *source)
 {
+	const enum gs_color_format format =
+		convert_video_format(source->async_format);
+
 	if (source->async_gpu_conversion) {
-		source->async_prev_texrender = gs_texrender_create(
-			source->async_color_format, GS_ZS_NONE);
+		source->async_prev_texrender =
+			gs_texrender_create(format, GS_ZS_NONE);
 
 		for (int c = 0; c < source->async_channel_count; c++)
 			source->async_prev_textures[c] = gs_texture_create(
@@ -243,11 +246,7 @@ void set_deinterlace_texture_size(obs_source_t *source)
 				source->async_convert_height[c],
 				source->async_texture_formats[c], 1, NULL,
 				GS_DYNAMIC);
-
 	} else {
-		enum gs_color_format format =
-			convert_video_format(source->async_format);
-
 		source->async_prev_textures[0] = gs_texture_create(
 			source->async_width, source->async_height, format, 1,
 			NULL, GS_DYNAMIC);
@@ -393,12 +392,8 @@ void deinterlace_render(obs_source_t *s)
 	if (!cur_tex || !prev_tex || !s->async_width || !s->async_height)
 		return;
 
-	enum gs_color_space source_space = GS_CS_SRGB;
-	if (s->async_color_format == GS_RGBA16F) {
-		source_space = (s->async_trc == VIDEO_TRC_SRGB)
-				       ? GS_CS_SRGB_16F
-				       : GS_CS_709_EXTENDED;
-	}
+	const enum gs_color_space source_space =
+		convert_video_space(s->async_format, s->async_trc);
 
 	const bool linear_srgb =
 		(source_space != GS_CS_SRGB) || gs_get_linear_srgb() ||

+ 15 - 14
libobs/obs-source.c

@@ -1920,13 +1920,11 @@ bool set_async_texture_size(struct obs_source *source,
 	enum convert_type cur =
 		get_convert_type(frame->format, frame->full_range, frame->trc);
 
-	const enum gs_color_format format = convert_video_format(frame->format);
 	if (source->async_width == frame->width &&
 	    source->async_height == frame->height &&
 	    source->async_format == frame->format &&
 	    source->async_full_range == frame->full_range &&
-	    source->async_trc == frame->trc &&
-	    source->async_color_format == format)
+	    source->async_trc == frame->trc)
 		return true;
 
 	source->async_width = frame->width;
@@ -1949,7 +1947,7 @@ bool set_async_texture_size(struct obs_source *source,
 	source->async_texrender = NULL;
 	source->async_prev_texrender = NULL;
 
-	source->async_color_format = format;
+	const enum gs_color_format format = convert_video_format(frame->format);
 	const bool async_gpu_conversion = (cur != CONVERT_NONE) &&
 					  init_gpu_conversion(source, frame);
 	source->async_gpu_conversion = async_gpu_conversion;
@@ -2344,12 +2342,8 @@ static void rotate_async_video(obs_source_t *source, long rotation)
 static inline void obs_source_render_async_video(obs_source_t *source)
 {
 	if (source->async_textures[0] && source->async_active) {
-		enum gs_color_space source_space = GS_CS_SRGB;
-		if (source->async_color_format == GS_RGBA16F) {
-			source_space = (source->async_trc == VIDEO_TRC_SRGB)
-					       ? GS_CS_SRGB_16F
-					       : GS_CS_709_EXTENDED;
-		}
+		const enum gs_color_space source_space = convert_video_space(
+			source->async_format, source->async_trc);
 
 		gs_effect_t *const effect =
 			obs_get_base_effect(OBS_EFFECT_DEFAULT);
@@ -2816,10 +2810,17 @@ obs_source_get_color_space(obs_source_t *source, size_t count,
 	}
 
 	if (source->info.output_flags & OBS_SOURCE_ASYNC) {
-		return convert_video_space(source->async_format,
-					   source->async_trc,
-					   source->async_color_format, count,
-					   preferred_spaces);
+		const enum gs_color_space video_space = convert_video_space(
+			source->async_format, source->async_trc);
+
+		enum gs_color_space space = video_space;
+		for (size_t i = 0; i < count; ++i) {
+			space = preferred_spaces[i];
+			if (space == video_space)
+				break;
+		}
+
+		return space;
 	}
 
 	assert(source->context.data);