msdk: bufferpool: set alignment to video meta
authorXu Guangxin <guangxin.xu@intel.com>
Wed, 29 Apr 2020 08:19:08 +0000 (16:19 +0800)
committerHaihao Xiang <haihao.xiang@intel.com>
Thu, 7 May 2020 05:45:36 +0000 (05:45 +0000)
else gst_video_meta_validate_alignment will report error like
"videometa gstvideometa.c:416:gst_video_meta_validate_alignment: Stride of plane 0 defined in meta (384) is different from the one computed from the alignment (320)"

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1224>

sys/msdk/gstmsdkbufferpool.c

index 465800f..de24114 100644 (file)
@@ -54,6 +54,9 @@ struct _GstMsdkBufferPoolPrivate
   mfxFrameAllocResponse *alloc_response;
   GstMsdkMemoryType memory_type;
   gboolean add_videometa;
+  gboolean need_alignment;
+  GstVideoAlignment alignment;
+
 };
 
 #define gst_msdk_buffer_pool_parent_class parent_class
@@ -131,13 +134,13 @@ gst_msdk_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
   priv->add_videometa = gst_buffer_pool_config_has_option (config,
       GST_BUFFER_POOL_OPTION_VIDEO_META);
 
-  if (priv->add_videometa && gst_buffer_pool_config_has_option (config,
-          GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT)) {
-    GstVideoAlignment alignment;
+  priv->need_alignment = gst_buffer_pool_config_has_option (config,
+      GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
 
-    gst_msdk_set_video_alignment (&video_info, 0, 0, &alignment);
-    gst_video_info_align (&video_info, &alignment);
-    gst_buffer_pool_config_set_video_alignment (config, &alignment);
+  if (priv->add_videometa && priv->need_alignment) {
+    gst_msdk_set_video_alignment (&video_info, 0, 0, &priv->alignment);
+    gst_video_info_align (&video_info, &priv->alignment);
+    gst_buffer_pool_config_set_video_alignment (config, &priv->alignment);
   }
 
   priv->memory_type = _msdk_get_memory_type (config);
@@ -246,6 +249,13 @@ gst_msdk_buffer_pool_alloc_buffer (GstBufferPool * pool,
         GST_VIDEO_INFO_WIDTH (info), GST_VIDEO_INFO_HEIGHT (info),
         GST_VIDEO_INFO_N_PLANES (info), info->offset, info->stride);
 
+    if (priv->need_alignment) {
+      if (!gst_video_meta_set_alignment (vmeta, priv->alignment)) {
+        GST_ERROR_OBJECT (pool, "failed to set alignment");
+        return GST_FLOW_ERROR;
+      }
+    }
+
     if (priv->memory_type == GST_MSDK_MEMORY_TYPE_VIDEO) {
       vmeta->map = gst_video_meta_map_msdk_memory;
       vmeta->unmap = gst_video_meta_unmap_msdk_memory;