From da4e79bb6b617b36e9e9de44de27012274e92253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 27 May 2011 14:28:46 +0200 Subject: [PATCH] ffmpegcolorspace: Optimize transform_caps() If the second and next caps structures are a subset of the already existing transformed caps we can safely skip them because we would transform them to the same caps again. --- gst/ffmpegcolorspace/gstffmpegcolorspace.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/gst/ffmpegcolorspace/gstffmpegcolorspace.c b/gst/ffmpegcolorspace/gstffmpegcolorspace.c index 3fdb4ea471..9c825b0501 100644 --- a/gst/ffmpegcolorspace/gstffmpegcolorspace.c +++ b/gst/ffmpegcolorspace/gstffmpegcolorspace.c @@ -101,13 +101,20 @@ gst_ffmpegcsp_caps_remove_format_info (GstCaps * caps) { GstStructure *yuvst, *rgbst, *grayst; gint i, n; + GstCaps *res; - caps = gst_caps_copy (caps); + res = gst_caps_new_empty (); n = gst_caps_get_size (caps); for (i = 0; i < n; i++) { yuvst = gst_caps_get_structure (caps, i); + /* If this is already expressed by the existing caps + * skip this structure */ + if (i > 0 && gst_caps_is_subset_structure (res, yuvst)) + continue; + + yuvst = gst_structure_copy (yuvst); gst_structure_set_name (yuvst, "video/x-raw-yuv"); gst_structure_remove_fields (yuvst, "format", "endianness", "depth", "bpp", "red_mask", "green_mask", "blue_mask", "alpha_mask", @@ -120,11 +127,12 @@ gst_ffmpegcsp_caps_remove_format_info (GstCaps * caps) grayst = gst_structure_copy (rgbst); gst_structure_set_name (grayst, "video/x-raw-gray"); - gst_caps_merge_structure (caps, rgbst); - gst_caps_merge_structure (caps, grayst); + gst_caps_append_structure (res, yuvst); + gst_caps_append_structure (res, rgbst); + gst_caps_append_structure (res, grayst); } - return caps; + return res; } /* The caps can be transformed into any other caps with format info removed. @@ -134,17 +142,11 @@ static GstCaps * gst_ffmpegcsp_transform_caps (GstBaseTransform * btrans, GstPadDirection direction, GstCaps * caps, GstCaps * filter) { - GstCaps *template; GstCaps *tmp, *tmp2; GstCaps *result; - template = gst_static_pad_template_get_caps (&gst_ffmpegcsp_src_template); - /* Get all possible caps that we can transform to */ tmp = gst_ffmpegcsp_caps_remove_format_info (caps); - tmp2 = gst_caps_intersect_full (tmp, template, GST_CAPS_INTERSECT_FIRST); - gst_caps_unref (tmp); - tmp = tmp2; if (filter) { tmp2 = gst_caps_intersect_full (filter, tmp, GST_CAPS_INTERSECT_FIRST);