vaapidecode: add support for VideoAlignment bufferpool option.
[platform/upstream/gstreamer-vaapi.git] / gst / vaapi / gstvaapivideobufferpool.c
index f35dcbc..fe5c2a3 100644 (file)
@@ -24,6 +24,9 @@
 #include "gstvaapivideobufferpool.h"
 #include "gstvaapivideobuffer.h"
 #include "gstvaapivideomemory.h"
+#if GST_CHECK_VERSION(1,1,0) && USE_GLX
+#include "gstvaapivideometa_texture.h"
+#endif
 
 GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapivideopool);
 #define GST_CAT_DEFAULT gst_debug_vaapivideopool
@@ -43,7 +46,9 @@ struct _GstVaapiVideoBufferPoolPrivate {
     guint               video_info_index;
     GstAllocator       *allocator;
     GstVaapiDisplay    *display;
-    guint               has_video_meta  : 1;
+    guint               has_video_meta          : 1;
+    guint               has_video_alignment     : 1;
+    guint               has_texture_upload_meta : 1;
 };
 
 #define GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE(obj)    \
@@ -97,12 +102,27 @@ gst_vaapi_video_buffer_pool_get_property(GObject *object, guint prop_id,
     }
 }
 
+static void
+fill_video_alignment(GstVaapiVideoBufferPool *pool, GstVideoAlignment *align)
+{
+    GstVideoInfo * const vip =
+        &GST_VAAPI_VIDEO_ALLOCATOR_CAST(pool->priv->allocator)->image_info;
+    guint i;
+
+    gst_video_alignment_reset(align);
+    for (i = 0; i < GST_VIDEO_INFO_N_PLANES(vip); i++)
+        align->stride_align[i] =
+            (1U << g_bit_nth_lsf(GST_VIDEO_INFO_PLANE_STRIDE(vip, i), 0)) - 1;
+}
+
 static const gchar **
 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,
+        GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT,
         NULL,
     };
     return g_options;
@@ -117,6 +137,7 @@ gst_vaapi_video_buffer_pool_set_config(GstBufferPool *pool,
     GstCaps *caps = NULL;
     GstVideoInfo * const cur_vip = &priv->video_info[priv->video_info_index];
     GstVideoInfo * const new_vip = &priv->video_info[!priv->video_info_index];
+    GstVideoAlignment align;
     GstAllocator *allocator;
     gboolean changed_caps;
 
@@ -147,6 +168,16 @@ 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_video_alignment = gst_buffer_pool_config_has_option(config,
+        GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
+    if (priv->has_video_alignment) {
+        fill_video_alignment(GST_VAAPI_VIDEO_BUFFER_POOL(pool), &align);
+        gst_buffer_pool_config_set_video_alignment(config, &align);
+    }
+
+    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 +245,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) && USE_GLX
+    if (priv->has_texture_upload_meta)
+        gst_buffer_add_texture_upload_meta(buffer);
+#endif
+
     *out_buffer_ptr = buffer;
     return GST_FLOW_OK;