sys/xvimage/xvimagesink.*: When performing buffer allocations, remember the caps...
authorJan Schmidt <thaytan@mad.scientist.com>
Fri, 19 May 2006 11:50:17 +0000 (11:50 +0000)
committerJan Schmidt <thaytan@mad.scientist.com>
Fri, 19 May 2006 11:50:17 +0000 (11:50 +0000)
Original commit message from CVS:
* sys/xvimage/xvimagesink.c: (gst_xvimagesink_xcontext_clear),
(gst_xvimagesink_buffer_alloc):
* sys/xvimage/xvimagesink.h:
When performing buffer allocations, remember the caps and image format
we return so that if the same caps are asked for next time we can
return them immediately without doing any caps intersections.

ChangeLog
common
sys/xvimage/xvimagesink.c
sys/xvimage/xvimagesink.h

index b01b68da1d1664ba6d0f89bfdc3ded69bf59786f..3e9435445623cd81dd5579f0390b5a2100d56f4c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-05-19  Jan Schmidt  <thaytan@mad.scientist.com>
+
+       * sys/xvimage/xvimagesink.c: (gst_xvimagesink_xcontext_clear),
+       (gst_xvimagesink_buffer_alloc):
+       * sys/xvimage/xvimagesink.h:
+       When performing buffer allocations, remember the caps and image format
+       we return so that if the same caps are asked for next time we can
+       return them immediately without doing any caps intersections.
+
 2006-05-18 Philippe Kalaf <philippe.kalaf@collabora.co.uk>      
         
        * gst-libs/gst/rtp/README:
diff --git a/common b/common
index 6811863fce665ce0a466bc03ee2ac5e2d5f47d28..764c5f25101d20da7f26942c36ba840ba65c63d7 160000 (submodule)
--- a/common
+++ b/common
@@ -1 +1 @@
-Subproject commit 6811863fce665ce0a466bc03ee2ac5e2d5f47d28
+Subproject commit 764c5f25101d20da7f26942c36ba840ba65c63d7
index de35321c6e61ec3aa2ba2bb4be7d42562f520b71..c2f26bfcd13a74ff33cddab4cf20b908ee3002f1 100644 (file)
@@ -1497,6 +1497,9 @@ gst_xvimagesink_xcontext_clear (GstXvImageSink * xvimagesink)
     g_list_free (xvimagesink->xcontext->channels_list);
 
   gst_caps_unref (xvimagesink->xcontext->caps);
+  if (xvimagesink->xcontext->last_caps)
+    gst_caps_replace (&xvimagesink->xcontext->last_caps, NULL);
+
   g_free (xvimagesink->xcontext->par);
 
   g_mutex_lock (xvimagesink->x_lock);
@@ -1881,6 +1884,16 @@ gst_xvimagesink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
 
   xvimagesink = GST_XVIMAGESINK (bsink);
 
+  if (G_LIKELY (xvimagesink->xcontext->last_caps &&
+          gst_caps_is_equal (caps, xvimagesink->xcontext->last_caps))) {
+    GST_DEBUG_OBJECT (xvimagesink,
+        "buffer alloc for same last_caps, reusing caps");
+    intersection = gst_caps_ref (caps);
+    image_format = xvimagesink->xcontext->last_format;
+
+    goto reuse_last_caps;
+  }
+
   GST_DEBUG_OBJECT (xvimagesink, "buffer alloc requested with caps %"
       GST_PTR_FORMAT "intersecting with our caps %" GST_PTR_FORMAT, caps,
       xvimagesink->xcontext->caps);
@@ -1936,12 +1949,23 @@ gst_xvimagesink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
 
     GST_DEBUG_OBJECT (xvimagesink, "allocating a buffer with caps %"
         GST_PTR_FORMAT, intersection);
+  } else if (gst_caps_is_equal (intersection, caps)) {
+    /* Things work better if we return a buffer with the same caps ptr
+     * as was asked for when we can */
+    gst_caps_replace (&intersection, caps);
   }
 
   /* Get image format from caps */
   image_format = gst_xvimagesink_get_format_from_caps (xvimagesink,
       intersection);
 
+  /* Store our caps and format as the last_caps to avoid expensive 
+   * caps intersection next time */
+  gst_caps_replace (&xvimagesink->xcontext->last_caps, intersection);
+  xvimagesink->xcontext->last_format = image_format;
+
+reuse_last_caps:
+
   /* Get geometry from caps */
   structure = gst_caps_get_structure (intersection, 0);
   if (!gst_structure_get_int (structure, "width", &width) ||
@@ -1984,7 +2008,7 @@ gst_xvimagesink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
     /* We found no suitable image in the pool. Creating... */
     GST_DEBUG_OBJECT (xvimagesink, "no usable image in pool, creating xvimage");
     xvimage = gst_xvimagesink_xvimage_new (xvimagesink, intersection);
-    if (xvimage->size < size) {
+    if (xvimage && xvimage->size < size) {
       /* This image is unusable. Destroying... */
       gst_xvimage_buffer_free (xvimage);
       xvimage = NULL;
index b78634f3531c42ba6075b968a4567bb7ccc7ba75..5b5df0490fecf2319236f670aac4c7588dd871bc 100644 (file)
@@ -121,6 +121,10 @@ struct _GstXContext {
   GList *channels_list;
 
   GstCaps *caps;
+
+  /* Optimisation storage for buffer_alloc return */
+  GstCaps *last_caps;
+  gint last_format;
 };
 
 /**