va: Expose a couple va surface/buffer methods.
authorVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Wed, 30 Mar 2022 16:09:36 +0000 (18:09 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Wed, 20 Apr 2022 15:15:56 +0000 (15:15 +0000)
And use them in va plugin.

Also, set as default logging category the vadisplay one.

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

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

index 6baec64..d6d8f49 100644 (file)
 #include "gstvavideoformat.h"
 #include <va/va.h>
 
+/* XXX: find a better log category */
+#define GST_CAT_DEFAULT gst_va_display_debug
+GST_DEBUG_CATEGORY_EXTERN (gst_va_display_debug);
+
 gboolean
 va_destroy_surfaces (GstVaDisplay * display, VASurfaceID * surfaces,
     gint num_surfaces)
@@ -42,7 +46,6 @@ va_destroy_surfaces (GstVaDisplay * display, VASurfaceID * surfaces,
   }
 
   return TRUE;
-
 }
 
 gboolean
index 4a68ac1..18f88f7 100644 (file)
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include <gst/va/va_fwd.h>
+#include <gst/va/gstva.h>
 #include <gst/video/video.h>
 #include <va/va.h>
 #include <va/va_drmcommon.h>
@@ -42,10 +42,14 @@ gboolean              va_export_surface_to_dmabuf         (GstVaDisplay * displa
                                                            VASurfaceID surface,
                                                            guint32 flags,
                                                            VADRMPRIMESurfaceDescriptor * desc);
+
+GST_VA_API
 gboolean              va_sync_surface                     (GstVaDisplay * display,
                                                            VASurfaceID surface);
+GST_VA_API
 gboolean              va_check_surface                    (GstVaDisplay * display,
                                                            VASurfaceID surface);
+
 gboolean              va_copy_surface                     (GstVaDisplay * display,
                                                            VASurfaceID dst,
                                                            VASurfaceID src);
@@ -73,9 +77,11 @@ gboolean              va_ensure_image                     (GstVaDisplay * displa
                                                            gboolean derived);
 
 /* mapping */
+GST_VA_API
 gboolean              va_map_buffer                       (GstVaDisplay * display,
                                                            VABufferID buffer,
                                                            gpointer * data);
+GST_VA_API
 gboolean              va_unmap_buffer                     (GstVaDisplay * display,
                                                            VABufferID buffer);
 
index 41eb229..b536b6e 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "gstvafilter.h"
 
+#include <gst/va/vasurfaceimage.h>
 #include <gst/video/video.h>
 #include <va/va_drmcommon.h>
 
@@ -1518,23 +1519,6 @@ gst_va_filter_drop_filter_buffers (GstVaFilter * self)
 }
 
 static gboolean
-_check_surface (GstVaDisplay * display, VASurfaceID surface)
-{
-  VADisplay dpy = gst_va_display_get_va_dpy (display);
-  VAStatus status;
-  VASurfaceStatus state;
-
-  status = vaQuerySurfaceStatus (dpy, surface, &state);
-
-  if (status != VA_STATUS_SUCCESS)
-    GST_ERROR ("vaQuerySurfaceStatus: %s", vaErrorStr (status));
-
-  GST_LOG ("surface %#x status %d", surface, state);
-
-  return (status == VA_STATUS_SUCCESS);
-}
-
-static gboolean
 _fill_va_sample (GstVaFilter * self, GstVaSample * sample,
     GstPadDirection direction)
 {
@@ -1548,7 +1532,7 @@ _fill_va_sample (GstVaFilter * self, GstVaSample * sample,
   /* @FIXME: in gallium vaQuerySurfaceStatus only seems to work with
    * encoder's surfaces */
   if (!GST_VA_DISPLAY_IS_IMPLEMENTATION (self->display, MESA_GALLIUM)) {
-    if (!_check_surface (self->display, sample->surface))
+    if (!va_check_surface (self->display, sample->surface))
       return FALSE;
   }
 
index 8c4e864..c0b61c8 100644 (file)
@@ -55,6 +55,7 @@
 
 #include <gst/codecparsers/gsth264bitwriter.h>
 #include <gst/va/gstva.h>
+#include <gst/va/vasurfaceimage.h>
 #include <gst/video/video.h>
 #include <va/va_drmcommon.h>
 
@@ -3199,30 +3200,20 @@ _push_buffer_to_downstream (GstVaH264Enc * self, GstVideoCodecFrame * frame)
   guint coded_size;
   goffset offset;
   GstBuffer *buf;
-  VADisplay dpy;
   VASurfaceID surface;
-  VAStatus status;
   VACodedBufferSegment *seg, *seg_list;
 
-  dpy = gst_va_display_get_va_dpy (self->display);
-
   frame_enc = _enc_frame (frame);
 
   /* Wait for encoding to finish */
   surface = gst_va_encode_picture_get_raw_surface (frame_enc->picture);
-  status = vaSyncSurface (dpy, surface);
-  if (status != VA_STATUS_SUCCESS) {
-    GST_WARNING_OBJECT (self, "vaSyncSurface: %s", vaErrorStr (status));
+  if (!va_sync_surface (self->display, surface))
     goto error;
-  }
 
   seg_list = NULL;
-  status = vaMapBuffer (dpy, frame_enc->picture->coded_buffer,
-      (gpointer *) & seg_list);
-  if (status != VA_STATUS_SUCCESS) {
-    GST_WARNING_OBJECT (self, "vaMapBuffer: %s", vaErrorStr (status));
+  if (!va_map_buffer (self->display, frame_enc->picture->coded_buffer,
+          (gpointer *) & seg_list))
     goto error;
-  }
 
   if (!seg_list) {
     GST_WARNING_OBJECT (self, "coded buffer has no segment list");
@@ -3254,9 +3245,7 @@ _push_buffer_to_downstream (GstVaH264Enc * self, GstVideoCodecFrame * frame)
     offset += seg->size;
   }
 
-  status = vaUnmapBuffer (dpy, frame_enc->picture->coded_buffer);
-  if (status != VA_STATUS_SUCCESS)
-    GST_WARNING ("vaUnmapBuffer: %s", vaErrorStr (status));
+  va_unmap_buffer (self->display, frame_enc->picture->coded_buffer);
 
   frame->pts =
       self->start_pts + self->frame_duration * frame_enc->total_frame_count;