From b81823e7dba96bfe502c376b0539e84ddf45a0c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 6 Mar 2015 18:15:11 +0100 Subject: [PATCH] gl: Remove format info in glcolorconvert's transform_caps function instead of on every caller ... and let glmixer actually transform the caps it is supposed to transform instead of inventing new caps. --- ext/gl/gstglimagesink.c | 41 --------------------- ext/gl/gstglmixer.c | 51 ++------------------------ ext/gl/gstgltestsrc.c | 56 ++++------------------------- gst-libs/gst/gl/gstglcolorconvert.c | 47 +++++++++++++++++++++--- gst-libs/gst/gl/gstglfilter.c | 41 --------------------- 5 files changed, 52 insertions(+), 184 deletions(-) diff --git a/ext/gl/gstglimagesink.c b/ext/gl/gstglimagesink.c index 7c2c70a08e..4ce32115a4 100644 --- a/ext/gl/gstglimagesink.c +++ b/ext/gl/gstglimagesink.c @@ -785,42 +785,6 @@ gst_glimage_sink_get_times (GstBaseSink * bsink, GstBuffer * buf, } } -/* copies the given caps */ -static GstCaps * -gst_glimage_sink_caps_remove_format_info (GstCaps * caps) -{ - GstStructure *st; - GstCapsFeatures *f; - gint i, n; - GstCaps *res; - - res = gst_caps_new_empty (); - - n = gst_caps_get_size (caps); - for (i = 0; i < n; i++) { - st = gst_caps_get_structure (caps, i); - f = gst_caps_get_features (caps, i); - - /* If this is already expressed by the existing caps - * skip this structure */ - if (i > 0 && gst_caps_is_subset_structure_full (res, st, f)) - continue; - - st = gst_structure_copy (st); - /* Only remove format info for the cases when we can actually convert */ - if (!gst_caps_features_is_any (f) - && gst_caps_features_is_equal (f, - GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)) - gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site", - NULL); - gst_structure_remove_fields (st, "width", "height", NULL); - - gst_caps_append_structure_full (res, st, gst_caps_features_copy (f)); - } - - return res; -} - static GstCaps * gst_glimage_sink_get_caps (GstBaseSink * bsink, GstCaps * filter) { @@ -830,11 +794,6 @@ gst_glimage_sink_get_caps (GstBaseSink * bsink, GstCaps * filter) tmp = gst_caps_from_string ("video/x-raw(memory:GLMemory),format=RGBA"); - result = gst_glimage_sink_caps_remove_format_info (tmp); - gst_caps_unref (tmp); - tmp = result; - GST_DEBUG_OBJECT (bsink, "remove format returned caps %" GST_PTR_FORMAT, tmp); - result = gst_gl_color_convert_transform_caps (gl_sink->context, GST_PAD_SRC, tmp, NULL); diff --git a/ext/gl/gstglmixer.c b/ext/gl/gstglmixer.c index 2cdf46fb92..36952f8701 100644 --- a/ext/gl/gstglmixer.c +++ b/ext/gl/gstglmixer.c @@ -326,60 +326,17 @@ gst_gl_mixer_set_caps_features (const GstCaps * caps, return ret; } -/* copies the given caps */ -static GstCaps * -gst_gl_mixer_caps_remove_format_info (GstCaps * caps) -{ - GstStructure *st; - GstCapsFeatures *f; - gint i, n; - GstCaps *res; - - res = gst_caps_new_empty (); - - n = gst_caps_get_size (caps); - for (i = 0; i < n; i++) { - st = gst_caps_get_structure (caps, i); - f = gst_caps_get_features (caps, i); - - /* If this is already expressed by the existing caps - * skip this structure */ - if (i > 0 && gst_caps_is_subset_structure_full (res, st, f)) - continue; - - st = gst_structure_copy (st); - /* Only remove format info for the cases when we can actually convert */ - if (!gst_caps_features_is_any (f) - && gst_caps_features_is_equal (f, - GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)) - gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site", - NULL); - gst_structure_remove_fields (st, "width", "height", NULL); - - gst_caps_append_structure_full (res, st, gst_caps_features_copy (f)); - } - - return res; -} - GstCaps * gst_gl_mixer_update_caps (GstGLMixer * mix, GstCaps * caps) { - GstCaps *result, *tmp, *gl_caps; - - gl_caps = gst_caps_from_string ("video/x-raw(memory:GLMemory),format=RGBA"); + GstCaps *result, *tmp; result = - gst_gl_color_convert_transform_caps (mix->context, GST_PAD_SRC, gl_caps, + gst_gl_color_convert_transform_caps (mix->context, GST_PAD_SRC, caps, NULL); tmp = result; GST_DEBUG_OBJECT (mix, "convert returned caps %" GST_PTR_FORMAT, tmp); - result = gst_gl_mixer_caps_remove_format_info (tmp); - gst_caps_unref (tmp); - tmp = result; - GST_DEBUG_OBJECT (mix, "remove format returned caps %" GST_PTR_FORMAT, tmp); - result = gst_gl_upload_transform_caps (mix->context, GST_PAD_SRC, tmp, NULL); gst_caps_unref (tmp); tmp = result; @@ -740,10 +697,6 @@ gst_gl_mixer_query_caps (GstPad * pad, GstAggregator * agg, GstQuery * query) NULL); retcaps = gst_caps_merge (gl_caps, retcaps); gst_caps_unref (current_caps); - current_caps = retcaps; - - retcaps = gst_gl_mixer_caps_remove_format_info (current_caps); - gst_caps_unref (current_caps); if (filter) { current_caps = diff --git a/ext/gl/gstgltestsrc.c b/ext/gl/gstgltestsrc.c index b760a70ba3..caae141b57 100644 --- a/ext/gl/gstgltestsrc.c +++ b/ext/gl/gstgltestsrc.c @@ -468,42 +468,6 @@ wrong_caps: } } -/* copies the given caps */ -static GstCaps * -gst_gl_test_src_caps_remove_format_info (GstCaps * caps) -{ - GstStructure *st; - GstCapsFeatures *f; - gint i, n; - GstCaps *res; - - res = gst_caps_new_empty (); - - n = gst_caps_get_size (caps); - for (i = 0; i < n; i++) { - st = gst_caps_get_structure (caps, i); - f = gst_caps_get_features (caps, i); - - /* If this is already expressed by the existing caps - * skip this structure */ - if (i > 0 && gst_caps_is_subset_structure_full (res, st, f)) - continue; - - st = gst_structure_copy (st); - /* Only remove format info for the cases when we can actually convert */ - if (!gst_caps_features_is_any (f) - && gst_caps_features_is_equal (f, - GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)) - gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site", - NULL); - gst_structure_remove_fields (st, "width", "height", NULL); - - gst_caps_append_structure_full (res, st, gst_caps_features_copy (f)); - } - - return res; -} - static GstCaps * gst_gl_test_src_set_caps_features (const GstCaps * caps, const gchar * feature_name) @@ -517,32 +481,26 @@ static GstCaps * gst_gl_test_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter) { GstGLTestSrc *src = GST_GL_TEST_SRC (bsrc); - GstCaps *tmp = NULL; + GstCaps *tmp; GstCaps *result = NULL; GstCaps *gl_caps; GstCaps *caps = gst_caps_from_string ("video/x-raw(memory:GLMemory),format=RGBA"); - tmp = gst_gl_test_src_caps_remove_format_info (caps); - GST_DEBUG_OBJECT (bsrc, "remove format returned caps %" GST_PTR_FORMAT, tmp); - gl_caps = - gst_caps_merge (gst_gl_test_src_set_caps_features (tmp, + gst_caps_merge (gst_gl_test_src_set_caps_features (caps, GST_CAPS_FEATURE_MEMORY_GL_MEMORY), - gst_gl_test_src_set_caps_features (tmp, + gst_gl_test_src_set_caps_features (caps, GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META)); result = - gst_gl_download_transform_caps (src->context, GST_PAD_SINK, tmp, NULL); + gst_gl_download_transform_caps (src->context, GST_PAD_SINK, caps, NULL); result = gst_caps_merge (gl_caps, result); - gst_caps_unref (tmp); - tmp = result; - GST_DEBUG_OBJECT (bsrc, "transfer returned caps %" GST_PTR_FORMAT, tmp); + GST_DEBUG_OBJECT (bsrc, "transfer returned caps %" GST_PTR_FORMAT, result); if (filter) { - result = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST); - gst_caps_unref (tmp); - } else { + tmp = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST); + gst_caps_unref (result); result = tmp; } diff --git a/gst-libs/gst/gl/gstglcolorconvert.c b/gst-libs/gst/gl/gstglcolorconvert.c index f6d5368c4b..bce26b531e 100644 --- a/gst-libs/gst/gl/gstglcolorconvert.c +++ b/gst-libs/gst/gl/gstglcolorconvert.c @@ -634,6 +634,39 @@ gst_gl_color_convert_set_caps (GstGLColorConvert * convert, return ret; } +/* copies the given caps */ +static GstCaps * +gst_gl_color_convert_caps_remove_format_info (GstCaps * caps) +{ + GstStructure *st; + GstCapsFeatures *f; + gint i, n; + GstCaps *res; + + res = gst_caps_new_empty (); + + n = gst_caps_get_size (caps); + for (i = 0; i < n; i++) { + st = gst_caps_get_structure (caps, i); + f = gst_caps_get_features (caps, i); + + /* If this is already expressed by the existing caps + * skip this structure */ + if (i > 0 && gst_caps_is_subset_structure_full (res, st, f)) + continue; + + st = gst_structure_copy (st); + gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site", + NULL); + gst_structure_remove_fields (st, "width", "height", NULL); + + gst_caps_append_structure_full (res, st, + gst_caps_features_new (GST_CAPS_FEATURE_MEMORY_GL_MEMORY, NULL)); + } + + return res; +} + GstCaps * gst_gl_color_convert_transform_caps (GstGLContext * convert, GstPadDirection direction, GstCaps * caps, GstCaps * filter) @@ -644,11 +677,17 @@ gst_gl_color_convert_transform_caps (GstGLContext * convert, gst_caps_from_string (GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_GL_MEMORY, GST_GL_COLOR_CONVERT_FORMATS)); + caps = gst_gl_color_convert_caps_remove_format_info (caps); + result = gst_caps_intersect (caps, templ); + gst_caps_unref (caps); + gst_caps_unref (templ); + if (filter) { - result = gst_caps_intersect_full (filter, templ, GST_CAPS_INTERSECT_FIRST); - gst_caps_unref (templ); - } else { - result = templ; + GstCaps *tmp; + + tmp = gst_caps_intersect_full (filter, result, GST_CAPS_INTERSECT_FIRST); + gst_caps_unref (result); + result = tmp; } return result; diff --git a/gst-libs/gst/gl/gstglfilter.c b/gst-libs/gst/gl/gstglfilter.c index 6700da5694..f3987956d0 100644 --- a/gst-libs/gst/gl/gstglfilter.c +++ b/gst-libs/gst/gl/gstglfilter.c @@ -715,42 +715,6 @@ gst_gl_filter_set_caps_features (const GstCaps * caps, return ret; } -/* copies the given caps */ -static GstCaps * -gst_gl_filter_caps_remove_format_info (GstCaps * caps) -{ - GstStructure *st; - GstCapsFeatures *f; - gint i, n; - GstCaps *res; - - res = gst_caps_new_empty (); - - n = gst_caps_get_size (caps); - for (i = 0; i < n; i++) { - st = gst_caps_get_structure (caps, i); - f = gst_caps_get_features (caps, i); - - /* If this is already expressed by the existing caps - * skip this structure */ - if (i > 0 && gst_caps_is_subset_structure_full (res, st, f)) - continue; - - st = gst_structure_copy (st); - /* Only remove format info for the cases when we can actually convert */ - if (!gst_caps_features_is_any (f) - && gst_caps_features_is_equal (f, - GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)) - gst_structure_remove_fields (st, "format", "colorimetry", "chroma-site", - NULL); - gst_structure_remove_fields (st, "width", "height", NULL); - - gst_caps_append_structure_full (res, st, gst_caps_features_copy (f)); - } - - return res; -} - static GstCaps * gst_gl_filter_transform_caps (GstBaseTransform * bt, GstPadDirection direction, GstCaps * caps, GstCaps * filter_caps) @@ -789,11 +753,6 @@ gst_gl_filter_transform_caps (GstBaseTransform * bt, tmp = result; GST_DEBUG_OBJECT (bt, "transfer returned caps %" GST_PTR_FORMAT, tmp); - result = gst_gl_filter_caps_remove_format_info (tmp); - gst_caps_unref (tmp); - tmp = result; - GST_DEBUG_OBJECT (bt, "remove format returned caps %" GST_PTR_FORMAT, tmp); - if (direction == GST_PAD_SRC) { result = gst_gl_color_convert_transform_caps (filter->context, direction, tmp,