Hello,

The attached patch makes the vaapi buffer pool requests the
GLTextureUpload meta on buffers and prevent this meta from being
de-allocated when the buffer is released in the sink.

This is particulary useful in terms of performance when using the
GLTextureUploadMeta API since the VaapiTexture associated with the target
texture is stored in the meta.

Best regards,
Matthieu Bouron
>From bbf58b682f48b3137d41cde95c1838939425db06 Mon Sep 17 00:00:00 2001
From: Matthieu Bouron <matthieu.bou...@collabora.com>
Date: Wed, 20 Nov 2013 17:20:07 +0000
Subject: [PATCH] vaapidecode: request GLTextureUpload meta on buffers in the
 bufferpool

Requesting the GLTextureUpload meta on buffers in the bufferpool
prevents such metas from being de-allocated when buffers are released
in the sink.

This is particulary useful in terms of performance when using the
GLTextureUploadMeta API since the VaapiTexture associated with the
target texture is stored in the meta.

The GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META option added
here might be implemented in gstreamer later on.
---
 gst/vaapi/gstvaapidecode.c          |  7 +++++--
 gst/vaapi/gstvaapivideobufferpool.c | 10 ++++++++++
 gst/vaapi/gstvaapivideobufferpool.h | 12 ++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c
index 1b926f8..398f8cb 100644
--- a/gst/vaapi/gstvaapidecode.c
+++ b/gst/vaapi/gstvaapidecode.c
@@ -347,7 +347,8 @@ gst_vaapidecode_push_decoded_frame(GstVideoDecoder *vdec)
         }
 
 #if GST_CHECK_VERSION(1,1,0)
-        if (decode->has_texture_upload_meta)
+        if (decode->has_texture_upload_meta &&
+            !gst_buffer_get_video_gl_texture_upload_meta (out_frame->output_buffer))
             gst_buffer_add_texture_upload_meta(out_frame->output_buffer);
 #endif
 #else
@@ -541,11 +542,13 @@ gst_vaapidecode_decide_allocation(GstVideoDecoder *vdec, GstQuery *query)
         config = gst_buffer_pool_get_config(pool);
         gst_buffer_pool_config_add_option(config,
             GST_BUFFER_POOL_OPTION_VIDEO_META);
-        gst_buffer_pool_set_config(pool, config);
 #if GST_CHECK_VERSION(1,1,0)
         decode->has_texture_upload_meta = gst_query_find_allocation_meta(query,
             GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, NULL);
+        gst_buffer_pool_config_add_option(config,
+            GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META);
 #endif
+        gst_buffer_pool_set_config(pool, config);
     }
 
     if (update_pool)
diff --git a/gst/vaapi/gstvaapivideobufferpool.c b/gst/vaapi/gstvaapivideobufferpool.c
index c293ad1..c12787e 100644
--- a/gst/vaapi/gstvaapivideobufferpool.c
+++ b/gst/vaapi/gstvaapivideobufferpool.c
@@ -43,6 +43,7 @@ struct _GstVaapiVideoBufferPoolPrivate {
     GstAllocator       *allocator;
     GstVaapiDisplay    *display;
     guint               has_video_meta  : 1;
+    guint               has_texture_upload_meta;
 };
 
 #define GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE(obj)    \
@@ -102,6 +103,7 @@ gst_vaapi_video_buffer_pool_get_options(GstBufferPool *pool)
     static const gchar *g_options[] = {
         GST_BUFFER_POOL_OPTION_VIDEO_META,
         GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META,
+        GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META,
         NULL,
     };
     return g_options;
@@ -146,6 +148,9 @@ gst_vaapi_video_buffer_pool_set_config(GstBufferPool *pool,
     priv->has_video_meta = gst_buffer_pool_config_has_option(config,
         GST_BUFFER_POOL_OPTION_VIDEO_META);
 
+    priv->has_texture_upload_meta = gst_buffer_pool_config_has_option(config,
+        GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META);
+
     return GST_BUFFER_POOL_CLASS(gst_vaapi_video_buffer_pool_parent_class)->
         set_config(pool, config);
 
@@ -211,6 +216,11 @@ gst_vaapi_video_buffer_pool_alloc_buffer(GstBufferPool *pool,
             &GST_VIDEO_INFO_PLANE_STRIDE(vip, 0));
         vmeta->map = gst_video_meta_map_vaapi_memory;
         vmeta->unmap = gst_video_meta_unmap_vaapi_memory;
+
+#if GST_CHECK_VERSION(1,1,0)
+        if (priv->has_texture_upload_meta)
+            gst_buffer_add_texture_upload_meta(buffer);
+#endif
     }
 
     *out_buffer_ptr = buffer;
diff --git a/gst/vaapi/gstvaapivideobufferpool.h b/gst/vaapi/gstvaapivideobufferpool.h
index 1b97bb1..3bae032 100644
--- a/gst/vaapi/gstvaapivideobufferpool.h
+++ b/gst/vaapi/gstvaapivideobufferpool.h
@@ -59,6 +59,18 @@ typedef struct _GstVaapiVideoBufferPoolPrivate  GstVaapiVideoBufferPoolPrivate;
 #define GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META "GstBufferPoolOptionVaapiVideoMeta"
 
 /**
+ *
+ * GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META:
+ *
+ * An option that can be activated on bufferpool to request gl texture
+ * upload on buffers from the pool.
+ *
+ * When this option is enabled on the bufferpool,
+ * #GST_BUFFER_POOL_OPTION_VIDEO_META should also be enabled.
+ */
+#define GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META "GstBufferPoolOptionVideoGLTextureUploadMeta"
+
+/**
  * GstVaapiVideoBufferPool:
  *
  * A VA video buffer pool object.
-- 
1.8.4.2

_______________________________________________
Libva mailing list
Libva@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libva

Reply via email to