From 6b6c10d94d927602f7d47a0bec57cc64431a893f Mon Sep 17 00:00:00 2001 From: Matthieu Bouron Date: Wed, 20 Nov 2013 17:20:07 +0000 Subject: [PATCH] plugins: request GLTextureUpload meta on buffers in the buffer pool. 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 --- gst/vaapi/gstvaapidecode.c | 7 +++++-- gst/vaapi/gstvaapivideobufferpool.c | 15 ++++++++++++++- gst/vaapi/gstvaapivideobufferpool.h | 15 +++++++++++++++ gst/vaapi/gstvaapivideometa_texture.c | 7 +++++++ gst/vaapi/gstvaapivideometa_texture.h | 4 ++++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index 3225a95..9f399b7 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -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) diff --git a/gst/vaapi/gstvaapivideobufferpool.c b/gst/vaapi/gstvaapivideobufferpool.c index f35dcbc..e0bc98f 100644 --- a/gst/vaapi/gstvaapivideobufferpool.c +++ b/gst/vaapi/gstvaapivideobufferpool.c @@ -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; diff --git a/gst/vaapi/gstvaapivideobufferpool.h b/gst/vaapi/gstvaapivideobufferpool.h index ae284f9..ed646c2 100644 --- a/gst/vaapi/gstvaapivideobufferpool.h +++ b/gst/vaapi/gstvaapivideobufferpool.h @@ -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. diff --git a/gst/vaapi/gstvaapivideometa_texture.c b/gst/vaapi/gstvaapivideometa_texture.c index 593950a..18eb3e7 100644 --- a/gst/vaapi/gstvaapivideometa_texture.c +++ b/gst/vaapi/gstvaapivideometa_texture.c @@ -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 diff --git a/gst/vaapi/gstvaapivideometa_texture.h b/gst/vaapi/gstvaapivideometa_texture.h index 289e98f..a3367b4 100644 --- a/gst/vaapi/gstvaapivideometa_texture.h +++ b/gst/vaapi/gstvaapivideometa_texture.h @@ -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 */ -- 2.7.4