va: filter: Enable to pass VASurfaceID in GstVaSample.
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Tue, 5 Oct 2021 11:21:00 +0000 (13:21 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Sun, 10 Oct 2021 17:03:29 +0000 (17:03 +0000)
Initially GstVaSample processed its GstBuffer member to get the
VASurfaceID. But it might cases where we already have the VASurfaceID
to process by the filter.

This patch enables the possibility to pass the surfaces rather than
the buffers. In order to validate the surfaces a function to check
surfaces were added.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1023>

subprojects/gst-plugins-bad/sys/va/gstvafilter.c
subprojects/gst-plugins-bad/sys/va/vasurfaceimage.c
subprojects/gst-plugins-bad/sys/va/vasurfaceimage.h

index 3eed9af..58a4b2f 100644 (file)
@@ -32,6 +32,7 @@
 #include "gstvacaps.h"
 #include "gstvadisplay_priv.h"
 #include "gstvavideoformat.h"
+#include "vasurfaceimage.h"
 
 struct _GstVaFilter
 {
@@ -1508,12 +1509,20 @@ static gboolean
 _fill_va_sample (GstVaFilter * self, GstVaSample * sample,
     GstPadDirection direction)
 {
-  GstVideoCropMeta *crop;
+  GstVideoCropMeta *crop = NULL;
 
-  sample->surface = gst_va_buffer_get_surface (sample->buffer);
+  if (sample->buffer)
+    sample->surface = gst_va_buffer_get_surface (sample->buffer);
   if (sample->surface == VA_INVALID_ID)
     return FALSE;
 
+  /* @FIXME: in gallium vaQuerySurfaceStatus only seems to work with
+   * encoder's surfaces */
+  if (!GST_VA_DISPLAY_IS_IMPLEMENTATION (self->display, MESA_GALLIUM)) {
+    if (!va_check_surface (self->display, sample->surface))
+      return FALSE;
+  }
+
   /* XXX: cropping occurs only in input frames */
   if (direction == GST_PAD_SRC) {
     GST_OBJECT_LOCK (self);
@@ -1524,7 +1533,8 @@ _fill_va_sample (GstVaFilter * self, GstVaSample * sample,
   }
 
   /* if buffer has crop meta, its real size is in video meta */
-  crop = gst_buffer_get_video_crop_meta (sample->buffer);
+  if (sample->buffer)
+    crop = gst_buffer_get_video_crop_meta (sample->buffer);
 
   GST_OBJECT_LOCK (self);
   if (crop && self->crop_enabled) {
@@ -1612,8 +1622,8 @@ gst_va_filter_process (GstVaFilter * self, GstVaSample * src, GstVaSample * dst)
   gboolean ret = FALSE;
 
   g_return_val_if_fail (GST_IS_VA_FILTER (self), FALSE);
-  g_return_val_if_fail (src && GST_IS_BUFFER (src->buffer), FALSE);
-  g_return_val_if_fail (dst && GST_IS_BUFFER (dst->buffer), FALSE);
+  g_return_val_if_fail (src, FALSE);
+  g_return_val_if_fail (dst, FALSE);
 
   if (!gst_va_filter_is_open (self))
     return FALSE;
index 2f0015d..4b1b098 100644 (file)
@@ -21,6 +21,7 @@
 #include "vasurfaceimage.h"
 
 #include "gstvavideoformat.h"
+#include <va/va.h>
 
 gboolean
 va_destroy_surfaces (GstVaDisplay * display, VASurfaceID * surfaces,
@@ -290,3 +291,22 @@ va_ensure_image (GstVaDisplay * display, VASurfaceID surface,
 
   return ret;
 }
+
+gboolean
+va_check_surface (GstVaDisplay * display, VASurfaceID surface)
+{
+  VADisplay dpy = gst_va_display_get_va_dpy (display);
+  VAStatus status;
+  VASurfaceStatus state;
+
+  gst_va_display_lock (display);
+  status = vaQuerySurfaceStatus (dpy, surface, &state);
+  gst_va_display_unlock (display);
+
+  if (status != VA_STATUS_SUCCESS)
+    GST_ERROR ("vaQuerySurfaceStatus: %s", vaErrorStr (status));
+
+  GST_LOG ("surface %#x status %d", surface, state);
+
+  return (status == VA_STATUS_SUCCESS);
+}
index 96b85c4..787d8ca 100644 (file)
@@ -44,6 +44,8 @@ gboolean              va_export_surface_to_dmabuf         (GstVaDisplay * displa
                                                            VADRMPRIMESurfaceDescriptor * desc);
 gboolean              va_sync_surface                     (GstVaDisplay * display,
                                                            VASurfaceID surface);
+gboolean              va_check_surface                    (GstVaDisplay * display,
+                                                           VASurfaceID surface);
 
 /* images */
 gboolean              va_create_image                     (GstVaDisplay * display,