va: filter: Enable to pass VASurfaceID in GstVaSample.

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>
This commit is contained in:
Víctor Manuel Jáquez Leal 2021-10-05 13:21:00 +02:00 committed by GStreamer Marge Bot
parent 14156f8270
commit f1e2eb4f1e
3 changed files with 37 additions and 5 deletions

View File

@ -32,6 +32,7 @@
#include "gstvacaps.h" #include "gstvacaps.h"
#include "gstvadisplay_priv.h" #include "gstvadisplay_priv.h"
#include "gstvavideoformat.h" #include "gstvavideoformat.h"
#include "vasurfaceimage.h"
struct _GstVaFilter struct _GstVaFilter
{ {
@ -1508,12 +1509,20 @@ static gboolean
_fill_va_sample (GstVaFilter * self, GstVaSample * sample, _fill_va_sample (GstVaFilter * self, GstVaSample * sample,
GstPadDirection direction) 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) if (sample->surface == VA_INVALID_ID)
return FALSE; 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 */ /* XXX: cropping occurs only in input frames */
if (direction == GST_PAD_SRC) { if (direction == GST_PAD_SRC) {
GST_OBJECT_LOCK (self); 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 */ /* 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); GST_OBJECT_LOCK (self);
if (crop && self->crop_enabled) { if (crop && self->crop_enabled) {
@ -1612,8 +1622,8 @@ gst_va_filter_process (GstVaFilter * self, GstVaSample * src, GstVaSample * dst)
gboolean ret = FALSE; gboolean ret = FALSE;
g_return_val_if_fail (GST_IS_VA_FILTER (self), 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 (src, FALSE);
g_return_val_if_fail (dst && GST_IS_BUFFER (dst->buffer), FALSE); g_return_val_if_fail (dst, FALSE);
if (!gst_va_filter_is_open (self)) if (!gst_va_filter_is_open (self))
return FALSE; return FALSE;

View File

@ -21,6 +21,7 @@
#include "vasurfaceimage.h" #include "vasurfaceimage.h"
#include "gstvavideoformat.h" #include "gstvavideoformat.h"
#include <va/va.h>
gboolean gboolean
va_destroy_surfaces (GstVaDisplay * display, VASurfaceID * surfaces, va_destroy_surfaces (GstVaDisplay * display, VASurfaceID * surfaces,
@ -290,3 +291,22 @@ va_ensure_image (GstVaDisplay * display, VASurfaceID surface,
return ret; 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);
}

View File

@ -44,6 +44,8 @@ gboolean va_export_surface_to_dmabuf (GstVaDisplay * displa
VADRMPRIMESurfaceDescriptor * desc); VADRMPRIMESurfaceDescriptor * desc);
gboolean va_sync_surface (GstVaDisplay * display, gboolean va_sync_surface (GstVaDisplay * display,
VASurfaceID surface); VASurfaceID surface);
gboolean va_check_surface (GstVaDisplay * display,
VASurfaceID surface);
/* images */ /* images */
gboolean va_create_image (GstVaDisplay * display, gboolean va_create_image (GstVaDisplay * display,