mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-20 07:16:55 +00:00
ximage: reimplement buffer pooling with metadata
Use the buffer metadata to get back to the extra info we can use to optimize the video rendering.
This commit is contained in:
parent
55c9ca592f
commit
08bfcad434
2 changed files with 33 additions and 38 deletions
|
@ -1634,6 +1634,7 @@ static GstFlowReturn
|
||||||
gst_ximagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
gst_ximagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstXImageSink *ximagesink;
|
GstXImageSink *ximagesink;
|
||||||
|
GstMetaXImage *meta;
|
||||||
|
|
||||||
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
|
g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
|
||||||
|
|
||||||
|
@ -1644,16 +1645,15 @@ gst_ximagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
||||||
if (!ximagesink->xcontext)
|
if (!ximagesink->xcontext)
|
||||||
return GST_FLOW_ERROR;
|
return GST_FLOW_ERROR;
|
||||||
|
|
||||||
#if 0
|
meta = GST_META_XIMAGE_GET (buf, FALSE);
|
||||||
/* If this buffer has been allocated using our buffer management we simply
|
|
||||||
put the ximage which is in the PRIVATE pointer */
|
if (meta) {
|
||||||
if (GST_IS_XIMAGE_BUFFER (buf)) {
|
/* If this buffer has been allocated using our buffer management we simply
|
||||||
|
put the ximage which is in the PRIVATE pointer */
|
||||||
GST_LOG_OBJECT (ximagesink, "buffer from our pool, writing directly");
|
GST_LOG_OBJECT (ximagesink, "buffer from our pool, writing directly");
|
||||||
if (!gst_ximagesink_ximage_put (ximagesink, GST_XIMAGE_BUFFER (buf)))
|
if (!gst_ximagesink_ximage_put (ximagesink, buf))
|
||||||
goto no_window;
|
goto no_window;
|
||||||
} else
|
} else {
|
||||||
#endif
|
|
||||||
{
|
|
||||||
/* Else we have to copy the data into our private image, */
|
/* Else we have to copy the data into our private image, */
|
||||||
/* if we have one... */
|
/* if we have one... */
|
||||||
GST_LOG_OBJECT (ximagesink, "normal buffer, copying from it");
|
GST_LOG_OBJECT (ximagesink, "normal buffer, copying from it");
|
||||||
|
@ -1666,7 +1666,7 @@ gst_ximagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
||||||
goto no_ximage;
|
goto no_ximage;
|
||||||
|
|
||||||
if (GST_BUFFER_SIZE (ximagesink->ximage) < GST_BUFFER_SIZE (buf)) {
|
if (GST_BUFFER_SIZE (ximagesink->ximage) < GST_BUFFER_SIZE (buf)) {
|
||||||
GstMetaXImage *meta = GST_META_XIMAGE_GET (ximagesink->ximage, FALSE);
|
meta = GST_META_XIMAGE_GET (ximagesink->ximage, FALSE);
|
||||||
|
|
||||||
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
|
GST_ELEMENT_ERROR (ximagesink, RESOURCE, WRITE,
|
||||||
("Failed to create output image buffer of %dx%d pixels",
|
("Failed to create output image buffer of %dx%d pixels",
|
||||||
|
@ -1733,7 +1733,6 @@ gst_ximagesink_event (GstBaseSink * sink, GstEvent * event)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Buffer management
|
/* Buffer management
|
||||||
*
|
*
|
||||||
* The buffer_alloc function must either return a buffer with given size and
|
* The buffer_alloc function must either return a buffer with given size and
|
||||||
|
@ -1749,7 +1748,8 @@ gst_ximagesink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
|
||||||
GstCaps * caps, GstBuffer ** buf)
|
GstCaps * caps, GstBuffer ** buf)
|
||||||
{
|
{
|
||||||
GstXImageSink *ximagesink;
|
GstXImageSink *ximagesink;
|
||||||
GstXImageBuffer *ximage = NULL;
|
GstMetaXImage *meta = NULL;
|
||||||
|
GstBuffer *ximage = NULL;
|
||||||
GstStructure *structure = NULL;
|
GstStructure *structure = NULL;
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
GstCaps *alloc_caps;
|
GstCaps *alloc_caps;
|
||||||
|
@ -1880,15 +1880,17 @@ alloc:
|
||||||
/* Inspect our buffer pool */
|
/* Inspect our buffer pool */
|
||||||
g_mutex_lock (ximagesink->pool_lock);
|
g_mutex_lock (ximagesink->pool_lock);
|
||||||
while (ximagesink->buffer_pool) {
|
while (ximagesink->buffer_pool) {
|
||||||
ximage = (GstXImageBuffer *) ximagesink->buffer_pool->data;
|
ximage = ximagesink->buffer_pool->data;
|
||||||
|
|
||||||
if (ximage) {
|
if (ximage) {
|
||||||
|
meta = GST_META_XIMAGE_GET (ximage, FALSE);
|
||||||
|
|
||||||
/* Removing from the pool */
|
/* Removing from the pool */
|
||||||
ximagesink->buffer_pool = g_slist_delete_link (ximagesink->buffer_pool,
|
ximagesink->buffer_pool = g_slist_delete_link (ximagesink->buffer_pool,
|
||||||
ximagesink->buffer_pool);
|
ximagesink->buffer_pool);
|
||||||
|
|
||||||
/* If the ximage is invalid for our need, destroy */
|
/* If the ximage is invalid for our need, destroy */
|
||||||
if ((ximage->width != width) || (ximage->height != height)) {
|
if ((meta->width != width) || (meta->height != height)) {
|
||||||
gst_ximage_buffer_free (ximage);
|
gst_ximage_buffer_free (ximage);
|
||||||
ximage = NULL;
|
ximage = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1907,19 +1909,18 @@ alloc:
|
||||||
if (ximage) {
|
if (ximage) {
|
||||||
/* Make sure the buffer is cleared of any previously used flags */
|
/* Make sure the buffer is cleared of any previously used flags */
|
||||||
GST_MINI_OBJECT_CAST (ximage)->flags = 0;
|
GST_MINI_OBJECT_CAST (ximage)->flags = 0;
|
||||||
gst_buffer_set_caps (GST_BUFFER_CAST (ximage), alloc_caps);
|
gst_buffer_set_caps (ximage, alloc_caps);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* could be our new reffed suggestion or the original unreffed caps */
|
/* could be our new reffed suggestion or the original unreffed caps */
|
||||||
if (alloc_unref)
|
if (alloc_unref)
|
||||||
gst_caps_unref (alloc_caps);
|
gst_caps_unref (alloc_caps);
|
||||||
|
|
||||||
*buf = GST_BUFFER_CAST (ximage);
|
*buf = ximage;
|
||||||
|
|
||||||
beach:
|
beach:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Interfaces stuff */
|
/* Interfaces stuff */
|
||||||
|
|
||||||
|
@ -2418,10 +2419,8 @@ gst_ximagesink_class_init (GstXImageSinkClass * klass)
|
||||||
|
|
||||||
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_getcaps);
|
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_getcaps);
|
||||||
gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_setcaps);
|
gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_setcaps);
|
||||||
#if 0
|
|
||||||
gstbasesink_class->buffer_alloc =
|
gstbasesink_class->buffer_alloc =
|
||||||
GST_DEBUG_FUNCPTR (gst_ximagesink_buffer_alloc);
|
GST_DEBUG_FUNCPTR (gst_ximagesink_buffer_alloc);
|
||||||
#endif
|
|
||||||
gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_ximagesink_get_times);
|
gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_ximagesink_get_times);
|
||||||
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_ximagesink_event);
|
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_ximagesink_event);
|
||||||
|
|
||||||
|
|
|
@ -2333,20 +2333,19 @@ static GstFlowReturn
|
||||||
gst_xvimagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
gst_xvimagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
||||||
{
|
{
|
||||||
GstXvImageSink *xvimagesink;
|
GstXvImageSink *xvimagesink;
|
||||||
|
GstMetaXvImage *meta;
|
||||||
|
|
||||||
xvimagesink = GST_XVIMAGESINK (vsink);
|
xvimagesink = GST_XVIMAGESINK (vsink);
|
||||||
|
|
||||||
#if 0
|
meta = GST_META_XVIMAGE_GET (buf, FALSE);
|
||||||
/* If this buffer has been allocated using our buffer management we simply
|
|
||||||
put the ximage which is in the PRIVATE pointer */
|
if (meta) {
|
||||||
if (GST_IS_XVIMAGE_BUFFER (buf)) {
|
/* If this buffer has been allocated using our buffer management we simply
|
||||||
|
put the ximage which is in the PRIVATE pointer */
|
||||||
GST_LOG_OBJECT (xvimagesink, "fast put of bufferpool buffer %p", buf);
|
GST_LOG_OBJECT (xvimagesink, "fast put of bufferpool buffer %p", buf);
|
||||||
if (!gst_xvimagesink_xvimage_put (xvimagesink,
|
if (!gst_xvimagesink_xvimage_put (xvimagesink, buf))
|
||||||
GST_XVIMAGE_BUFFER_CAST (buf)))
|
|
||||||
goto no_window;
|
goto no_window;
|
||||||
} else
|
} else {
|
||||||
#endif
|
|
||||||
{
|
|
||||||
GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, xvimagesink,
|
GST_CAT_LOG_OBJECT (GST_CAT_PERFORMANCE, xvimagesink,
|
||||||
"slow copy into bufferpool buffer %p", buf);
|
"slow copy into bufferpool buffer %p", buf);
|
||||||
/* Else we have to copy the data into our private image, */
|
/* Else we have to copy the data into our private image, */
|
||||||
|
@ -2362,8 +2361,7 @@ gst_xvimagesink_show_frame (GstVideoSink * vsink, GstBuffer * buf)
|
||||||
goto no_image;
|
goto no_image;
|
||||||
|
|
||||||
if (GST_BUFFER_SIZE (xvimagesink->xvimage) < GST_BUFFER_SIZE (buf)) {
|
if (GST_BUFFER_SIZE (xvimagesink->xvimage) < GST_BUFFER_SIZE (buf)) {
|
||||||
GstMetaXvImage *meta =
|
meta = GST_META_XVIMAGE_GET (xvimagesink->xvimage, FALSE);
|
||||||
GST_META_XVIMAGE_GET (xvimagesink->xvimage, FALSE);
|
|
||||||
|
|
||||||
GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
|
GST_ELEMENT_ERROR (xvimagesink, RESOURCE, WRITE,
|
||||||
("Failed to create output image buffer of %dx%d pixels",
|
("Failed to create output image buffer of %dx%d pixels",
|
||||||
|
@ -2432,9 +2430,7 @@ gst_xvimagesink_event (GstBaseSink * sink, GstEvent * event)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* Buffer management */
|
/* Buffer management */
|
||||||
|
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
gst_xvimage_sink_different_size_suggestion (GstXvImageSink * xvimagesink,
|
gst_xvimage_sink_different_size_suggestion (GstXvImageSink * xvimagesink,
|
||||||
GstCaps * caps)
|
GstCaps * caps)
|
||||||
|
@ -2489,7 +2485,8 @@ gst_xvimagesink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size,
|
||||||
{
|
{
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
GstFlowReturn ret = GST_FLOW_OK;
|
||||||
GstXvImageSink *xvimagesink;
|
GstXvImageSink *xvimagesink;
|
||||||
GstMetaXvImage *xvimage = NULL;
|
GstBuffer *xvimage = NULL;
|
||||||
|
GstMetaXvImage *meta = NULL;
|
||||||
GstCaps *intersection = NULL;
|
GstCaps *intersection = NULL;
|
||||||
GstStructure *structure = NULL;
|
GstStructure *structure = NULL;
|
||||||
gint width, height, image_format;
|
gint width, height, image_format;
|
||||||
|
@ -2623,13 +2620,15 @@ reuse_last_caps:
|
||||||
xvimage = xvimagesink->image_pool->data;
|
xvimage = xvimagesink->image_pool->data;
|
||||||
|
|
||||||
if (xvimage) {
|
if (xvimage) {
|
||||||
|
meta = GST_META_XVIMAGE_GET (xvimage, FALSE);
|
||||||
|
|
||||||
/* Removing from the pool */
|
/* Removing from the pool */
|
||||||
xvimagesink->image_pool = g_slist_delete_link (xvimagesink->image_pool,
|
xvimagesink->image_pool = g_slist_delete_link (xvimagesink->image_pool,
|
||||||
xvimagesink->image_pool);
|
xvimagesink->image_pool);
|
||||||
|
|
||||||
/* We check for geometry or image format changes */
|
/* We check for geometry or image format changes */
|
||||||
if ((xvimage->width != width) ||
|
if ((meta->width != width) ||
|
||||||
(xvimage->height != height) || (xvimage->im_format != image_format)) {
|
(meta->height != height) || (meta->im_format != image_format)) {
|
||||||
/* This image is unusable. Destroying... */
|
/* This image is unusable. Destroying... */
|
||||||
gst_xvimage_buffer_free (xvimage);
|
gst_xvimage_buffer_free (xvimage);
|
||||||
xvimage = NULL;
|
xvimage = NULL;
|
||||||
|
@ -2654,7 +2653,7 @@ reuse_last_caps:
|
||||||
gst_buffer_set_caps (GST_BUFFER_CAST (xvimage), intersection);
|
gst_buffer_set_caps (GST_BUFFER_CAST (xvimage), intersection);
|
||||||
}
|
}
|
||||||
|
|
||||||
*buf = GST_BUFFER_CAST (xvimage);
|
*buf = xvimage;
|
||||||
|
|
||||||
beach:
|
beach:
|
||||||
if (intersection) {
|
if (intersection) {
|
||||||
|
@ -2690,7 +2689,6 @@ invalid_caps:
|
||||||
goto beach;
|
goto beach;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Interfaces stuff */
|
/* Interfaces stuff */
|
||||||
|
|
||||||
|
@ -3656,10 +3654,8 @@ gst_xvimagesink_class_init (GstXvImageSinkClass * klass)
|
||||||
|
|
||||||
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_getcaps);
|
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_getcaps);
|
||||||
gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_setcaps);
|
gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_setcaps);
|
||||||
#if 0
|
|
||||||
gstbasesink_class->buffer_alloc =
|
gstbasesink_class->buffer_alloc =
|
||||||
GST_DEBUG_FUNCPTR (gst_xvimagesink_buffer_alloc);
|
GST_DEBUG_FUNCPTR (gst_xvimagesink_buffer_alloc);
|
||||||
#endif
|
|
||||||
gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_xvimagesink_get_times);
|
gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_xvimagesink_get_times);
|
||||||
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_xvimagesink_event);
|
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_xvimagesink_event);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue