plugins: request GLTextureUpload meta on buffers in the buffer pool.
authorMatthieu Bouron <matthieu.bouron@collabora.com>
Wed, 20 Nov 2013 17:20:07 +0000 (17:20 +0000)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 11 Dec 2013 14:30:51 +0000 (15:30 +0100)
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 GstVaapiTexture associated with
the target texture is stored in the meta.

https://bugzilla.gnome.org/show_bug.cgi?id=712558

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
gst/vaapi/gstvaapidecode.c
gst/vaapi/gstvaapivideobufferpool.c
gst/vaapi/gstvaapivideobufferpool.h
gst/vaapi/gstvaapivideometa_texture.c
gst/vaapi/gstvaapivideometa_texture.h

index 3225a95..9f399b7 100644 (file)
@@ -343,7 +343,7 @@ gst_vaapidecode_push_decoded_frame(GstVideoDecoder *vdec,
 
 #if GST_CHECK_VERSION(1,1,0)
         if (decode->has_texture_upload_meta)
-            gst_buffer_add_texture_upload_meta(out_frame->output_buffer);
+            gst_buffer_ensure_texture_upload_meta(out_frame->output_buffer);
 #endif
 #else
         out_frame->output_buffer =
@@ -552,11 +552,14 @@ 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);
+        if (decode->has_texture_upload_meta)
+            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)
index f35dcbc..e0bc98f 100644 (file)
@@ -24,6 +24,9 @@
 #include "gstvaapivideobufferpool.h"
 #include "gstvaapivideobuffer.h"
 #include "gstvaapivideomemory.h"
+#if GST_CHECK_VERSION(1,1,0)
+#include "gstvaapivideometa_texture.h"
+#endif
 
 GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapivideopool);
 #define GST_CAT_DEFAULT gst_debug_vaapivideopool
@@ -43,7 +46,8 @@ struct _GstVaapiVideoBufferPoolPrivate {
     guint               video_info_index;
     GstAllocator       *allocator;
     GstVaapiDisplay    *display;
-    guint               has_video_meta  : 1;
+    guint               has_video_meta          : 1;
+    guint               has_texture_upload_meta : 1;
 };
 
 #define GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE(obj)    \
@@ -103,6 +107,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;
@@ -147,6 +152,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);
 
@@ -214,6 +222,11 @@ gst_vaapi_video_buffer_pool_alloc_buffer(GstBufferPool *pool,
         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;
     return GST_FLOW_OK;
 
index ae284f9..ed646c2 100644 (file)
@@ -60,6 +60,21 @@ 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.
+ */
+#ifndef GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META
+#define GST_BUFFER_POOL_OPTION_VIDEO_GL_TEXTURE_UPLOAD_META \
+    "GstBufferPoolOptionVideoGLTextureUploadMeta"
+#endif
+
+/**
  * GstVaapiVideoBufferPool:
  *
  * A VA video buffer pool object.
index 593950a..18eb3e7 100644 (file)
@@ -96,4 +96,11 @@ gst_buffer_add_texture_upload_meta(GstBuffer *buffer)
 #endif
     return meta != NULL;
 }
+
+gboolean
+gst_buffer_ensure_texture_upload_meta(GstBuffer *buffer)
+{
+    return gst_buffer_get_video_gl_texture_upload_meta(buffer) ||
+        gst_buffer_add_texture_upload_meta(buffer);
+}
 #endif
index 289e98f..a3367b4 100644 (file)
@@ -35,6 +35,10 @@ G_GNUC_INTERNAL
 gboolean
 gst_buffer_add_texture_upload_meta(GstBuffer *buffer);
 
+G_GNUC_INTERNAL
+gboolean
+gst_buffer_ensure_texture_upload_meta(GstBuffer *buffer);
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_VIDEO_META_TEXTURE_H */