From 47e7f3f367d3a6d1a120abd81915b98a7ed694c9 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Fri, 19 May 2006 11:50:17 +0000 Subject: [PATCH] sys/xvimage/xvimagesink.*: When performing buffer allocations, remember the caps and image format we return so that i... 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 | 9 +++++++++ common | 2 +- sys/xvimage/xvimagesink.c | 26 +++++++++++++++++++++++++- sys/xvimage/xvimagesink.h | 4 ++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index b01b68da1d..3e94354456 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-05-19 Jan Schmidt + + * 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 * gst-libs/gst/rtp/README: diff --git a/common b/common index 6811863fce..764c5f2510 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit 6811863fce665ce0a466bc03ee2ac5e2d5f47d28 +Subproject commit 764c5f25101d20da7f26942c36ba840ba65c63d7 diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index de35321c6e..c2f26bfcd1 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -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; diff --git a/sys/xvimage/xvimagesink.h b/sys/xvimage/xvimagesink.h index b78634f353..5b5df0490f 100644 --- a/sys/xvimage/xvimagesink.h +++ b/sys/xvimage/xvimagesink.h @@ -121,6 +121,10 @@ struct _GstXContext { GList *channels_list; GstCaps *caps; + + /* Optimisation storage for buffer_alloc return */ + GstCaps *last_caps; + gint last_format; }; /**