2010-03-04 17:39:01 +00:00
|
|
|
/*
|
|
|
|
* gstvaapisurface.c - VA surface abstraction
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2014-01-22 17:54:14 +00:00
|
|
|
* Copyright (C) 2011-2014 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-03-04 17:39:01 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2.1
|
|
|
|
* of the License, or (at your option) any later version.
|
2010-03-04 17:39:01 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-03-04 17:39:01 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2011-06-14 11:51:41 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-03-04 17:39:01 +00:00
|
|
|
*
|
2011-06-14 11:51:41 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301 USA
|
2010-03-04 17:39:01 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
2010-03-24 08:16:32 +00:00
|
|
|
* SECTION:gstvaapisurface
|
|
|
|
* @short_description: VA surface abstraction
|
2010-03-19 15:45:21 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2010-03-24 16:17:49 +00:00
|
|
|
#include "gstvaapicompat.h"
|
2010-03-16 09:15:48 +00:00
|
|
|
#include "gstvaapiutils.h"
|
2010-03-04 17:39:01 +00:00
|
|
|
#include "gstvaapisurface.h"
|
2011-12-13 15:53:15 +00:00
|
|
|
#include "gstvaapisurface_priv.h"
|
|
|
|
#include "gstvaapicontext.h"
|
2010-03-18 15:28:59 +00:00
|
|
|
#include "gstvaapiimage.h"
|
2019-12-19 13:19:10 +00:00
|
|
|
#include "gstvaapiimage_priv.h"
|
2015-01-27 10:19:58 +00:00
|
|
|
#include "gstvaapibufferproxy_priv.h"
|
2010-03-04 17:39:01 +00:00
|
|
|
|
|
|
|
#define DEBUG 1
|
2010-03-16 09:17:41 +00:00
|
|
|
#include "gstvaapidebug.h"
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-24 15:11:26 +00:00
|
|
|
static gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
_gst_vaapi_surface_associate_subpicture (GstVaapiSurface * surface,
|
|
|
|
GstVaapiSubpicture * subpicture, const GstVaapiRectangle * src_rect,
|
|
|
|
const GstVaapiRectangle * dst_rect);
|
2010-03-24 15:11:26 +00:00
|
|
|
|
|
|
|
static gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
_gst_vaapi_surface_deassociate_subpicture (GstVaapiSurface * surface,
|
|
|
|
GstVaapiSubpicture * subpicture);
|
2010-03-24 15:11:26 +00:00
|
|
|
|
2010-03-23 10:36:20 +00:00
|
|
|
static void
|
2014-09-15 12:57:57 +00:00
|
|
|
destroy_subpicture_cb (gpointer subpicture, gpointer surface)
|
2010-03-23 10:36:20 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
_gst_vaapi_surface_deassociate_subpicture (surface, subpicture);
|
2020-05-23 06:00:58 +00:00
|
|
|
gst_vaapi_subpicture_unref (subpicture);
|
2010-03-23 10:36:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 17:39:01 +00:00
|
|
|
static void
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_destroy_subpictures (GstVaapiSurface * surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
if (surface->subpictures) {
|
|
|
|
g_ptr_array_foreach (surface->subpictures, destroy_subpicture_cb, surface);
|
2020-05-16 18:49:31 +00:00
|
|
|
g_clear_pointer (&surface->subpictures, g_ptr_array_unref);
|
2014-09-15 12:57:57 +00:00
|
|
|
}
|
2011-11-25 19:59:56 +00:00
|
|
|
}
|
2010-03-24 14:57:33 +00:00
|
|
|
|
2011-11-25 19:59:56 +00:00
|
|
|
static void
|
2019-12-19 13:19:10 +00:00
|
|
|
gst_vaapi_surface_free (GstVaapiSurface * surface)
|
2011-11-25 19:59:56 +00:00
|
|
|
{
|
2019-12-19 13:19:10 +00:00
|
|
|
GstVaapiDisplay *const display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
surface_id = GST_VAAPI_SURFACE_ID (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_DEBUG ("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (surface_id));
|
|
|
|
|
|
|
|
gst_vaapi_surface_destroy_subpictures (surface);
|
|
|
|
|
|
|
|
if (surface_id != VA_INVALID_SURFACE) {
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaDestroySurfaces (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
|
|
|
&surface_id, 1);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaDestroySurfaces()"))
|
2018-10-09 15:23:30 +00:00
|
|
|
GST_WARNING ("failed to destroy surface %" GST_VAAPI_ID_FORMAT,
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_VAAPI_ID_ARGS (surface_id));
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_SURFACE_ID (surface) = VA_INVALID_SURFACE;
|
2014-09-15 12:57:57 +00:00
|
|
|
}
|
2015-01-27 10:19:58 +00:00
|
|
|
gst_vaapi_buffer_proxy_replace (&surface->extbuf_proxy, NULL);
|
2019-12-19 13:19:10 +00:00
|
|
|
gst_vaapi_display_replace (&GST_VAAPI_SURFACE_DISPLAY (surface), NULL);
|
|
|
|
|
|
|
|
g_slice_free1 (sizeof (GstVaapiSurface), surface);
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-12-19 17:26:10 +00:00
|
|
|
gst_vaapi_surface_init (GstVaapiSurface * surface,
|
2013-04-30 15:22:15 +00:00
|
|
|
GstVaapiChromaType chroma_type, guint width, guint height)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2019-12-19 13:19:10 +00:00
|
|
|
GstVaapiDisplay *const display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
|
|
|
guint va_chroma_format;
|
|
|
|
|
|
|
|
va_chroma_format = from_GstVaapiChromaType (chroma_type);
|
|
|
|
if (!va_chroma_format)
|
|
|
|
goto error_unsupported_chroma_type;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaCreateSurfaces (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
|
|
|
width, height, va_chroma_format, 1, &surface_id);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaCreateSurfaces()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-12-19 13:17:34 +00:00
|
|
|
GST_VAAPI_SURFACE_FORMAT (surface) = GST_VIDEO_FORMAT_UNKNOWN;
|
|
|
|
GST_VAAPI_SURFACE_CHROMA_TYPE (surface) = chroma_type;
|
|
|
|
GST_VAAPI_SURFACE_WIDTH (surface) = width;
|
|
|
|
GST_VAAPI_SURFACE_HEIGHT (surface) = height;
|
2014-09-15 12:57:57 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (surface_id));
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_SURFACE_ID (surface) = surface_id;
|
2014-09-15 12:57:57 +00:00
|
|
|
return TRUE;
|
2013-07-09 17:13:39 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
/* ERRORS */
|
2013-07-09 17:13:39 +00:00
|
|
|
error_unsupported_chroma_type:
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_ERROR ("unsupported chroma-type %u", chroma_type);
|
|
|
|
return FALSE;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 18:32:52 +00:00
|
|
|
static guint
|
|
|
|
get_usage_hint (guint alloc_flags)
|
|
|
|
{
|
|
|
|
guint usage_hints = VA_SURFACE_ATTRIB_USAGE_HINT_GENERIC;
|
|
|
|
|
|
|
|
/* XXX(victor): So far, only media-driver uses hints for encoders
|
|
|
|
* and it doesn't test it as bitwise */
|
|
|
|
if (alloc_flags & GST_VAAPI_SURFACE_ALLOC_FLAG_HINT_DECODER)
|
|
|
|
usage_hints = VA_SURFACE_ATTRIB_USAGE_HINT_DECODER;
|
|
|
|
else if (alloc_flags & GST_VAAPI_SURFACE_ALLOC_FLAG_HINT_ENCODER)
|
|
|
|
usage_hints = VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER;
|
|
|
|
|
|
|
|
return usage_hints;
|
|
|
|
}
|
|
|
|
|
2013-07-09 17:08:37 +00:00
|
|
|
static gboolean
|
2019-12-19 17:26:10 +00:00
|
|
|
gst_vaapi_surface_init_full (GstVaapiSurface * surface,
|
2020-01-22 09:42:35 +00:00
|
|
|
const GstVideoInfo * vip, guint surface_allocation_flags)
|
2013-07-09 17:08:37 +00:00
|
|
|
{
|
2019-12-19 13:19:10 +00:00
|
|
|
GstVaapiDisplay *const display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2015-01-27 10:16:34 +00:00
|
|
|
const GstVideoFormat format = GST_VIDEO_INFO_FORMAT (vip);
|
2014-09-15 12:57:57 +00:00
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
2015-01-27 10:16:34 +00:00
|
|
|
guint chroma_type, va_chroma_format, i;
|
2014-09-15 12:57:57 +00:00
|
|
|
const VAImageFormat *va_format;
|
2020-01-24 18:32:52 +00:00
|
|
|
VASurfaceAttrib attribs[4], *attrib;
|
2020-01-27 10:49:26 +00:00
|
|
|
VASurfaceAttribExternalBuffers extbuf = { 0, };
|
2015-01-27 10:16:34 +00:00
|
|
|
gboolean extbuf_needed = FALSE;
|
2014-09-15 12:57:57 +00:00
|
|
|
|
|
|
|
va_format = gst_vaapi_video_format_to_va_format (format);
|
|
|
|
if (!va_format)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
|
|
|
chroma_type = gst_vaapi_video_format_get_chroma_type (format);
|
|
|
|
if (!chroma_type)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
|
|
|
va_chroma_format = from_GstVaapiChromaType (chroma_type);
|
|
|
|
if (!va_chroma_format)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
2015-01-27 10:16:34 +00:00
|
|
|
extbuf.pixel_format = va_format->fourcc;
|
|
|
|
extbuf.width = GST_VIDEO_INFO_WIDTH (vip);
|
|
|
|
extbuf.height = GST_VIDEO_INFO_HEIGHT (vip);
|
2020-01-22 09:42:35 +00:00
|
|
|
if (surface_allocation_flags & GST_VAAPI_SURFACE_ALLOC_FLAG_LINEAR_STORAGE) {
|
2015-11-27 05:09:10 +00:00
|
|
|
extbuf.flags &= ~VA_SURFACE_EXTBUF_DESC_ENABLE_TILING;
|
|
|
|
extbuf_needed = TRUE;
|
|
|
|
}
|
2015-01-27 10:16:34 +00:00
|
|
|
|
|
|
|
extbuf.num_planes = GST_VIDEO_INFO_N_PLANES (vip);
|
2020-01-27 10:44:49 +00:00
|
|
|
if (surface_allocation_flags & (GST_VAAPI_SURFACE_ALLOC_FLAG_FIXED_STRIDES |
|
|
|
|
GST_VAAPI_SURFACE_ALLOC_FLAG_FIXED_OFFSETS)) {
|
|
|
|
for (i = 0; i < extbuf.num_planes; i++) {
|
|
|
|
if (surface_allocation_flags & GST_VAAPI_SURFACE_ALLOC_FLAG_FIXED_STRIDES)
|
|
|
|
extbuf.pitches[i] = GST_VIDEO_INFO_PLANE_STRIDE (vip, i);
|
|
|
|
if (surface_allocation_flags & GST_VAAPI_SURFACE_ALLOC_FLAG_FIXED_OFFSETS)
|
|
|
|
extbuf.offsets[i] = GST_VIDEO_INFO_PLANE_OFFSET (vip, i);
|
|
|
|
}
|
2015-01-27 10:16:34 +00:00
|
|
|
extbuf_needed = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
attrib = attribs;
|
|
|
|
attrib->flags = VA_SURFACE_ATTRIB_SETTABLE;
|
|
|
|
attrib->type = VASurfaceAttribPixelFormat;
|
|
|
|
attrib->value.type = VAGenericValueTypeInteger;
|
|
|
|
attrib->value.value.i = va_format->fourcc;
|
|
|
|
attrib++;
|
|
|
|
|
2020-01-24 18:32:52 +00:00
|
|
|
attrib->flags = VA_SURFACE_ATTRIB_SETTABLE;
|
|
|
|
attrib->type = VASurfaceAttribUsageHint;
|
|
|
|
attrib->value.type = VAGenericValueTypeInteger;
|
|
|
|
attrib->value.value.i = get_usage_hint (surface_allocation_flags);
|
|
|
|
attrib++;
|
|
|
|
|
2015-01-27 10:16:34 +00:00
|
|
|
if (extbuf_needed) {
|
|
|
|
attrib->flags = VA_SURFACE_ATTRIB_SETTABLE;
|
|
|
|
attrib->type = VASurfaceAttribMemoryType;
|
|
|
|
attrib->value.type = VAGenericValueTypeInteger;
|
|
|
|
attrib->value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA;
|
|
|
|
attrib++;
|
|
|
|
|
|
|
|
attrib->flags = VA_SURFACE_ATTRIB_SETTABLE;
|
|
|
|
attrib->type = VASurfaceAttribExternalBufferDescriptor;
|
|
|
|
attrib->value.type = VAGenericValueTypePointer;
|
|
|
|
attrib->value.value.p = &extbuf;
|
|
|
|
attrib++;
|
|
|
|
}
|
2014-09-15 12:57:57 +00:00
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaCreateSurfaces (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
2015-01-27 10:16:34 +00:00
|
|
|
va_chroma_format, extbuf.width, extbuf.height, &surface_id, 1,
|
|
|
|
attribs, attrib - attribs);
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaCreateSurfaces()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-12-19 13:17:34 +00:00
|
|
|
GST_VAAPI_SURFACE_FORMAT (surface) = format;
|
|
|
|
GST_VAAPI_SURFACE_CHROMA_TYPE (surface) = chroma_type;
|
|
|
|
GST_VAAPI_SURFACE_WIDTH (surface) = extbuf.width;
|
|
|
|
GST_VAAPI_SURFACE_HEIGHT (surface) = extbuf.height;
|
2014-09-15 12:57:57 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (surface_id));
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_SURFACE_ID (surface) = surface_id;
|
2014-09-15 12:57:57 +00:00
|
|
|
return TRUE;
|
2013-07-09 17:08:37 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
/* ERRORS */
|
2013-07-09 17:08:37 +00:00
|
|
|
error_unsupported_format:
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_ERROR ("unsupported format %s",
|
|
|
|
gst_vaapi_video_format_to_string (format));
|
|
|
|
return FALSE;
|
2013-07-09 17:08:37 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 10:19:58 +00:00
|
|
|
static gboolean
|
2019-12-19 17:26:10 +00:00
|
|
|
gst_vaapi_surface_init_from_buffer_proxy (GstVaapiSurface * surface,
|
2015-01-27 10:19:58 +00:00
|
|
|
GstVaapiBufferProxy * proxy, const GstVideoInfo * vip)
|
|
|
|
{
|
2019-12-19 13:19:10 +00:00
|
|
|
GstVaapiDisplay *const display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2015-01-27 10:19:58 +00:00
|
|
|
GstVideoFormat format;
|
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
|
|
|
guint chroma_type, va_chroma_format;
|
|
|
|
const VAImageFormat *va_format;
|
|
|
|
VASurfaceAttrib attribs[2], *attrib;
|
2020-01-27 10:49:26 +00:00
|
|
|
VASurfaceAttribExternalBuffers extbuf = { 0, };
|
2015-01-27 10:19:58 +00:00
|
|
|
unsigned long extbuf_handle;
|
|
|
|
guint i, width, height;
|
|
|
|
|
|
|
|
format = GST_VIDEO_INFO_FORMAT (vip);
|
|
|
|
width = GST_VIDEO_INFO_WIDTH (vip);
|
|
|
|
height = GST_VIDEO_INFO_HEIGHT (vip);
|
|
|
|
|
|
|
|
gst_vaapi_buffer_proxy_replace (&surface->extbuf_proxy, proxy);
|
|
|
|
|
|
|
|
va_format = gst_vaapi_video_format_to_va_format (format);
|
|
|
|
if (!va_format)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
|
|
|
chroma_type = gst_vaapi_video_format_get_chroma_type (format);
|
|
|
|
if (!chroma_type)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
|
|
|
va_chroma_format = from_GstVaapiChromaType (chroma_type);
|
|
|
|
if (!va_chroma_format)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
|
|
|
extbuf_handle = GST_VAAPI_BUFFER_PROXY_HANDLE (proxy);
|
|
|
|
extbuf.pixel_format = va_format->fourcc;
|
|
|
|
extbuf.width = width;
|
|
|
|
extbuf.height = height;
|
|
|
|
extbuf.data_size = GST_VAAPI_BUFFER_PROXY_SIZE (proxy);
|
|
|
|
extbuf.num_planes = GST_VIDEO_INFO_N_PLANES (vip);
|
|
|
|
for (i = 0; i < extbuf.num_planes; i++) {
|
|
|
|
extbuf.pitches[i] = GST_VIDEO_INFO_PLANE_STRIDE (vip, i);
|
|
|
|
extbuf.offsets[i] = GST_VIDEO_INFO_PLANE_OFFSET (vip, i);
|
|
|
|
}
|
2018-02-27 12:10:09 +00:00
|
|
|
extbuf.buffers = (uintptr_t *) & extbuf_handle;
|
2015-01-27 10:19:58 +00:00
|
|
|
extbuf.num_buffers = 1;
|
|
|
|
extbuf.flags = 0;
|
|
|
|
extbuf.private_data = NULL;
|
|
|
|
|
|
|
|
attrib = attribs;
|
|
|
|
attrib->type = VASurfaceAttribExternalBufferDescriptor;
|
|
|
|
attrib->flags = VA_SURFACE_ATTRIB_SETTABLE;
|
|
|
|
attrib->value.type = VAGenericValueTypePointer;
|
|
|
|
attrib->value.value.p = &extbuf;
|
|
|
|
attrib++;
|
|
|
|
attrib->type = VASurfaceAttribMemoryType;
|
|
|
|
attrib->flags = VA_SURFACE_ATTRIB_SETTABLE;
|
|
|
|
attrib->value.type = VAGenericValueTypeInteger;
|
|
|
|
attrib->value.value.i =
|
|
|
|
from_GstVaapiBufferMemoryType (GST_VAAPI_BUFFER_PROXY_TYPE (proxy));
|
|
|
|
attrib++;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaCreateSurfaces (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
|
|
|
va_chroma_format, width, height, &surface_id, 1, attribs,
|
|
|
|
attrib - attribs);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaCreateSurfaces()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-12-19 13:17:34 +00:00
|
|
|
GST_VAAPI_SURFACE_FORMAT (surface) = format;
|
|
|
|
GST_VAAPI_SURFACE_CHROMA_TYPE (surface) = chroma_type;
|
|
|
|
GST_VAAPI_SURFACE_WIDTH (surface) = width;
|
|
|
|
GST_VAAPI_SURFACE_HEIGHT (surface) = height;
|
2015-01-27 10:19:58 +00:00
|
|
|
|
|
|
|
GST_DEBUG ("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS (surface_id));
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_SURFACE_ID (surface) = surface_id;
|
2015-01-27 10:19:58 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_unsupported_format:
|
|
|
|
GST_ERROR ("unsupported format %s",
|
|
|
|
gst_vaapi_video_format_to_string (format));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_DEFINE_MINI_OBJECT_TYPE (GstVaapiSurface, gst_vaapi_surface);
|
|
|
|
|
|
|
|
static GstVaapiSurface *
|
|
|
|
gst_vaapi_surface_create (GstVaapiDisplay * display)
|
|
|
|
{
|
|
|
|
GstVaapiSurface *surface = g_slice_new (GstVaapiSurface);
|
|
|
|
if (!surface)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gst_mini_object_init (GST_MINI_OBJECT_CAST (surface), 0,
|
|
|
|
GST_TYPE_VAAPI_SURFACE, NULL, NULL,
|
|
|
|
(GstMiniObjectFreeFunction) gst_vaapi_surface_free);
|
|
|
|
|
|
|
|
GST_VAAPI_SURFACE_DISPLAY (surface) = gst_object_ref (display);
|
|
|
|
GST_VAAPI_SURFACE_ID (surface) = VA_INVALID_ID;
|
|
|
|
surface->extbuf_proxy = NULL;
|
|
|
|
surface->subpictures = NULL;
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_display:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiDisplay this @surface is bound to.
|
|
|
|
*
|
|
|
|
* Return value: the parent #GstVaapiDisplay object
|
|
|
|
*/
|
|
|
|
GstVaapiDisplay *
|
|
|
|
gst_vaapi_surface_get_display (GstVaapiSurface * surface)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (surface != NULL, NULL);
|
|
|
|
return GST_VAAPI_SURFACE_DISPLAY (surface);
|
|
|
|
}
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_new:
|
|
|
|
* @display: a #GstVaapiDisplay
|
|
|
|
* @chroma_type: the surface chroma format
|
|
|
|
* @width: the requested surface width
|
|
|
|
* @height: the requested surface height
|
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiSurface with the specified chroma format and
|
|
|
|
* dimensions.
|
|
|
|
*
|
2020-01-23 15:56:44 +00:00
|
|
|
* NOTE: this method for creating surfaces uses deprecated VA API,
|
|
|
|
* which is still used by drivers (v.gr. i965 for jpeg decoding).
|
|
|
|
*
|
2010-03-19 15:45:21 +00:00
|
|
|
* Return value: the newly allocated #GstVaapiSurface object
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
GstVaapiSurface *
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_new (GstVaapiDisplay * display,
|
|
|
|
GstVaapiChromaType chroma_type, guint width, guint height)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiSurface *surface;
|
2013-04-30 15:22:15 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_DEBUG ("size %ux%u, chroma type 0x%x", width, height, chroma_type);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
surface = gst_vaapi_surface_create (display);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!surface)
|
|
|
|
return NULL;
|
2013-04-30 15:22:15 +00:00
|
|
|
|
2019-12-19 17:26:10 +00:00
|
|
|
if (!gst_vaapi_surface_init (surface, chroma_type, width, height))
|
2014-09-15 12:57:57 +00:00
|
|
|
goto error;
|
|
|
|
return surface;
|
2013-04-30 15:22:15 +00:00
|
|
|
|
2016-10-19 17:04:20 +00:00
|
|
|
/* ERRORS */
|
2013-04-30 15:22:15 +00:00
|
|
|
error:
|
2016-10-19 17:04:20 +00:00
|
|
|
{
|
2019-12-19 13:19:10 +00:00
|
|
|
gst_vaapi_surface_unref (surface);
|
2016-10-19 17:04:20 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:08:37 +00:00
|
|
|
/**
|
2015-01-27 10:16:34 +00:00
|
|
|
* gst_vaapi_surface_new_full:
|
2013-07-09 17:08:37 +00:00
|
|
|
* @display: a #GstVaapiDisplay
|
2015-01-27 10:16:34 +00:00
|
|
|
* @vip: the pointer to a #GstVideoInfo
|
2020-01-22 09:42:35 +00:00
|
|
|
* @surface_allocation_flags: (optional) allocation flags
|
2013-07-09 17:08:37 +00:00
|
|
|
*
|
2015-01-27 10:16:34 +00:00
|
|
|
* Creates a new #GstVaapiSurface with the specified video information
|
|
|
|
* and optional #GstVaapiSurfaceAllocFlags
|
2013-07-09 17:08:37 +00:00
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiSurface object, or %NULL
|
|
|
|
* if creation of VA surface with explicit pixel format is not
|
|
|
|
* supported or failed.
|
|
|
|
*/
|
|
|
|
GstVaapiSurface *
|
2020-01-22 09:42:35 +00:00
|
|
|
gst_vaapi_surface_new_full (GstVaapiDisplay * display, const GstVideoInfo * vip,
|
|
|
|
guint surface_allocation_flags)
|
2013-07-09 17:08:37 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiSurface *surface;
|
2013-07-09 17:08:37 +00:00
|
|
|
|
2015-01-27 10:16:34 +00:00
|
|
|
GST_DEBUG ("size %ux%u, format %s, flags 0x%08x", GST_VIDEO_INFO_WIDTH (vip),
|
|
|
|
GST_VIDEO_INFO_HEIGHT (vip),
|
2020-01-22 09:42:35 +00:00
|
|
|
gst_vaapi_video_format_to_string (GST_VIDEO_INFO_FORMAT (vip)),
|
|
|
|
surface_allocation_flags);
|
2013-07-09 17:08:37 +00:00
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
surface = gst_vaapi_surface_create (display);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!surface)
|
|
|
|
return NULL;
|
2013-07-09 17:08:37 +00:00
|
|
|
|
2020-01-22 09:42:35 +00:00
|
|
|
if (!gst_vaapi_surface_init_full (surface, vip, surface_allocation_flags))
|
2014-09-15 12:57:57 +00:00
|
|
|
goto error;
|
|
|
|
return surface;
|
2013-07-09 17:08:37 +00:00
|
|
|
|
2016-10-19 17:04:20 +00:00
|
|
|
/* ERRORS */
|
2013-07-09 17:08:37 +00:00
|
|
|
error:
|
2016-10-19 17:04:20 +00:00
|
|
|
{
|
2019-12-19 13:19:10 +00:00
|
|
|
gst_vaapi_surface_unref (surface);
|
2016-10-19 17:04:20 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-07-09 17:08:37 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 10:16:34 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_new_with_format:
|
|
|
|
* @display: a #GstVaapiDisplay
|
|
|
|
* @format: the surface format
|
|
|
|
* @width: the requested surface width
|
|
|
|
* @height: the requested surface height
|
2020-01-24 21:08:50 +00:00
|
|
|
* @surface_allocation_flags: (optional) allocation flags
|
2015-01-27 10:16:34 +00:00
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiSurface with the specified pixel format and
|
|
|
|
* dimensions.
|
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiSurface object, or %NULL
|
|
|
|
* if creation of VA surface with explicit pixel format is not
|
|
|
|
* supported or failed.
|
|
|
|
*/
|
|
|
|
GstVaapiSurface *
|
|
|
|
gst_vaapi_surface_new_with_format (GstVaapiDisplay * display,
|
2020-01-24 21:08:50 +00:00
|
|
|
GstVideoFormat format, guint width, guint height,
|
|
|
|
guint surface_allocation_flags)
|
2015-01-27 10:16:34 +00:00
|
|
|
{
|
|
|
|
GstVideoInfo vi;
|
|
|
|
|
|
|
|
gst_video_info_set_format (&vi, format, width, height);
|
2020-01-24 21:08:50 +00:00
|
|
|
return gst_vaapi_surface_new_full (display, &vi, surface_allocation_flags);
|
2015-01-27 10:16:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 10:19:58 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_new_from_buffer_proxy:
|
|
|
|
* @display: a #GstVaapiDisplay
|
|
|
|
* @proxy: a #GstVaapiBufferProxy
|
|
|
|
* @info: the #GstVideoInfo structure defining the layout of the buffer
|
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiSurface with the supplied VA buffer proxy
|
|
|
|
* abstraction. The underlying VA buffer memory type could be anything
|
|
|
|
* that is supported by the VA driver.
|
|
|
|
*
|
|
|
|
* The resulting #GstVaapiSurface object owns an extra reference to
|
|
|
|
* the buffer @proxy, so the caller can safely release that handle as
|
|
|
|
* early as on return of this call.
|
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiSurface object, or %NULL
|
|
|
|
* if creation of VA surface failed or is not supported
|
|
|
|
*/
|
|
|
|
GstVaapiSurface *
|
|
|
|
gst_vaapi_surface_new_from_buffer_proxy (GstVaapiDisplay * display,
|
|
|
|
GstVaapiBufferProxy * proxy, const GstVideoInfo * info)
|
|
|
|
{
|
|
|
|
GstVaapiSurface *surface;
|
|
|
|
|
|
|
|
g_return_val_if_fail (proxy != NULL, NULL);
|
|
|
|
g_return_val_if_fail (info != NULL, NULL);
|
2020-03-15 15:29:05 +00:00
|
|
|
g_return_val_if_fail (!proxy->surface, NULL);
|
2015-01-27 10:19:58 +00:00
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
surface = gst_vaapi_surface_create (display);
|
2015-01-27 10:19:58 +00:00
|
|
|
if (!surface)
|
|
|
|
return NULL;
|
|
|
|
|
2019-12-19 17:26:10 +00:00
|
|
|
if (!gst_vaapi_surface_init_from_buffer_proxy (surface, proxy, info))
|
2015-01-27 10:19:58 +00:00
|
|
|
goto error;
|
2020-03-15 15:29:05 +00:00
|
|
|
|
|
|
|
proxy->surface = GST_MINI_OBJECT_CAST (surface);
|
2015-01-27 10:19:58 +00:00
|
|
|
return surface;
|
|
|
|
|
2016-10-19 17:04:20 +00:00
|
|
|
/* ERRORS */
|
2015-01-27 10:19:58 +00:00
|
|
|
error:
|
2016-10-19 17:04:20 +00:00
|
|
|
{
|
2019-12-19 13:19:10 +00:00
|
|
|
gst_vaapi_surface_unref (surface);
|
2016-10-19 17:04:20 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-01-27 10:19:58 +00:00
|
|
|
}
|
|
|
|
|
2010-03-25 09:49:17 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_id:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Returns the underlying VASurfaceID of the @surface.
|
|
|
|
*
|
|
|
|
* Return value: the underlying VA surface id
|
|
|
|
*/
|
2010-03-30 07:39:16 +00:00
|
|
|
GstVaapiID
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_get_id (GstVaapiSurface * surface)
|
2010-03-25 09:49:17 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, VA_INVALID_SURFACE);
|
2010-03-25 09:49:17 +00:00
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
return GST_VAAPI_SURFACE_ID (surface);
|
2010-03-25 09:49:17 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_chroma_type:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiChromaType the @surface was created with.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiChromaType
|
|
|
|
*/
|
2010-03-11 13:58:32 +00:00
|
|
|
GstVaapiChromaType
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_get_chroma_type (GstVaapiSurface * surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
return GST_VAAPI_SURFACE_CHROMA_TYPE (surface);
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:08:37 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_format:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Returns the #GstVideoFormat the @surface was created with.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVideoFormat, or %GST_VIDEO_FORMAT_ENCODED if
|
|
|
|
* the surface was not created with an explicit video format, or if
|
|
|
|
* the underlying video format could not be determined
|
|
|
|
*/
|
|
|
|
GstVideoFormat
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_get_format (GstVaapiSurface * surface)
|
2013-07-09 17:08:37 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, 0);
|
|
|
|
|
|
|
|
/* Try to determine the underlying VA surface format */
|
2019-12-19 13:17:34 +00:00
|
|
|
if (GST_VAAPI_SURFACE_FORMAT (surface) == GST_VIDEO_FORMAT_UNKNOWN) {
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiImage *const image = gst_vaapi_surface_derive_image (surface);
|
|
|
|
if (image) {
|
2019-12-19 13:17:34 +00:00
|
|
|
GST_VAAPI_SURFACE_FORMAT (surface) = GST_VAAPI_IMAGE_FORMAT (image);
|
2019-12-18 11:57:01 +00:00
|
|
|
gst_vaapi_image_unref (image);
|
2013-07-10 11:58:55 +00:00
|
|
|
}
|
2019-12-19 13:17:34 +00:00
|
|
|
if (GST_VAAPI_SURFACE_FORMAT (surface) == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
GST_VAAPI_SURFACE_FORMAT (surface) = GST_VIDEO_FORMAT_ENCODED;
|
2014-09-15 12:57:57 +00:00
|
|
|
}
|
|
|
|
return GST_VAAPI_SURFACE_FORMAT (surface);
|
2013-07-09 17:08:37 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_width:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Returns the @surface width.
|
|
|
|
*
|
|
|
|
* Return value: the surface width, in pixels
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
guint
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_get_width (GstVaapiSurface * surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
return GST_VAAPI_SURFACE_WIDTH (surface);
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_height:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Returns the @surface height.
|
|
|
|
*
|
|
|
|
* Return value: the surface height, in pixels.
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
guint
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_get_height (GstVaapiSurface * surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
return GST_VAAPI_SURFACE_HEIGHT (surface);
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
2010-03-12 17:39:11 +00:00
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_size:
|
|
|
|
* @surface: a #GstVaapiSurface
|
2014-09-15 12:57:57 +00:00
|
|
|
* @width_ptr: return location for the width, or %NULL
|
|
|
|
* @height_ptr: return location for the height, or %NULL
|
2010-03-19 15:45:21 +00:00
|
|
|
*
|
|
|
|
* Retrieves the dimensions of a #GstVaapiSurface.
|
|
|
|
*/
|
2010-03-12 17:39:11 +00:00
|
|
|
void
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_get_size (GstVaapiSurface * surface,
|
|
|
|
guint * width_ptr, guint * height_ptr)
|
2010-03-12 17:39:11 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_if_fail (surface != NULL);
|
2010-03-12 17:39:11 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
if (width_ptr)
|
|
|
|
*width_ptr = GST_VAAPI_SURFACE_WIDTH (surface);
|
2010-03-12 17:39:11 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
if (height_ptr)
|
|
|
|
*height_ptr = GST_VAAPI_SURFACE_HEIGHT (surface);
|
2010-03-12 17:39:11 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_derive_image:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Derives a #GstVaapiImage from the @surface. This image buffer can
|
|
|
|
* then be mapped/unmapped for direct CPU access. This operation is
|
|
|
|
* only possible if the underlying implementation supports direct
|
|
|
|
* rendering capabilities and internal surface formats that can be
|
|
|
|
* represented with a #GstVaapiImage.
|
|
|
|
*
|
|
|
|
* When the operation is not possible, the function returns %NULL and
|
|
|
|
* the user should then fallback to using gst_vaapi_surface_get_image()
|
|
|
|
* or gst_vaapi_surface_put_image() to accomplish the same task in an
|
|
|
|
* indirect manner (additional copy).
|
|
|
|
*
|
|
|
|
* An image created with gst_vaapi_surface_derive_image() should be
|
|
|
|
* unreferenced when it's no longer needed. The image and image buffer
|
|
|
|
* data structures will be destroyed. However, the surface contents
|
|
|
|
* will remain unchanged until destroyed through the last call to
|
2019-12-18 11:57:01 +00:00
|
|
|
* gst_vaapi_image_unref().
|
2010-03-19 15:45:21 +00:00
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiImage object, or %NULL
|
|
|
|
* on failure
|
|
|
|
*/
|
2010-03-18 15:28:59 +00:00
|
|
|
GstVaapiImage *
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_derive_image (GstVaapiSurface * surface)
|
2010-03-18 15:28:59 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
VAImage va_image;
|
|
|
|
VAStatus status;
|
2016-04-07 16:03:42 +00:00
|
|
|
GstVaapiImage *image;
|
2014-09-15 12:57:57 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (surface != NULL, NULL);
|
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
va_image.image_id = VA_INVALID_ID;
|
|
|
|
va_image.buf = VA_INVALID_ID;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaDeriveImage (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_SURFACE_ID (surface), &va_image);
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaDeriveImage()"))
|
|
|
|
return NULL;
|
|
|
|
if (va_image.image_id == VA_INVALID_ID || va_image.buf == VA_INVALID_ID)
|
|
|
|
return NULL;
|
|
|
|
|
2016-04-07 16:03:42 +00:00
|
|
|
image = gst_vaapi_image_new_with_image (display, &va_image);
|
|
|
|
if (!image)
|
|
|
|
vaDestroyImage (GST_VAAPI_DISPLAY_VADISPLAY (display), va_image.image_id);
|
|
|
|
return image;
|
2010-03-18 15:28:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_image
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Retrieves surface data into a #GstVaapiImage. The @image must have
|
|
|
|
* a format supported by the @surface.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
2010-03-15 11:49:03 +00:00
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_get_image (GstVaapiSurface * surface, GstVaapiImage * image)
|
2010-03-15 11:49:03 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
VAImageID image_id;
|
|
|
|
VAStatus status;
|
|
|
|
guint width, height;
|
2010-03-15 11:49:03 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
width = GST_VAAPI_IMAGE_WIDTH (image);
|
|
|
|
height = GST_VAAPI_IMAGE_HEIGHT (image);
|
2019-12-19 13:17:34 +00:00
|
|
|
if (width != GST_VAAPI_SURFACE_WIDTH (surface)
|
|
|
|
|| height != GST_VAAPI_SURFACE_HEIGHT (surface))
|
2014-09-15 12:57:57 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2019-12-18 11:57:01 +00:00
|
|
|
image_id = GST_VAAPI_IMAGE_ID (image);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (image_id == VA_INVALID_ID)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaGetImage (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_SURFACE_ID (surface), 0, 0, width, height, image_id);
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaGetImage()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2010-03-15 11:49:03 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_put_image:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Copies data from a #GstVaapiImage into a @surface. The @image must
|
|
|
|
* have a format supported by the @surface.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
2010-03-15 11:49:03 +00:00
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_put_image (GstVaapiSurface * surface, GstVaapiImage * image)
|
2010-03-15 11:49:03 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
VAImageID image_id;
|
|
|
|
VAStatus status;
|
|
|
|
guint width, height;
|
2010-03-15 11:49:03 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (image != NULL, FALSE);
|
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
width = GST_VAAPI_IMAGE_WIDTH (image);
|
|
|
|
height = GST_VAAPI_IMAGE_HEIGHT (image);
|
2019-12-19 13:17:34 +00:00
|
|
|
if (width != GST_VAAPI_SURFACE_WIDTH (surface)
|
|
|
|
|| height != GST_VAAPI_SURFACE_HEIGHT (surface))
|
2014-09-15 12:57:57 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2019-12-18 11:57:01 +00:00
|
|
|
image_id = GST_VAAPI_IMAGE_ID (image);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (image_id == VA_INVALID_ID)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaPutImage (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_SURFACE_ID (surface), image_id, 0, 0, width, height, 0, 0,
|
|
|
|
width, height);
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaPutImage()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2010-03-15 11:49:03 +00:00
|
|
|
}
|
2010-03-15 16:13:51 +00:00
|
|
|
|
2010-03-23 10:36:20 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_associate_subpicture:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @subpicture: a #GstVaapiSubpicture
|
2010-03-23 13:32:36 +00:00
|
|
|
* @src_rect: the sub-rectangle of the source subpicture
|
2010-03-23 10:36:20 +00:00
|
|
|
* image to extract and process. If %NULL, the entire image will be used.
|
2010-03-23 13:32:36 +00:00
|
|
|
* @dst_rect: the sub-rectangle of the destination
|
2010-03-23 10:36:20 +00:00
|
|
|
* surface into which the image is rendered. If %NULL, the entire
|
|
|
|
* surface will be used.
|
|
|
|
*
|
|
|
|
* Associates the @subpicture with the @surface. The @src_rect
|
|
|
|
* coordinates and size are relative to the source image bound to
|
|
|
|
* @subpicture. The @dst_rect coordinates and size are relative to the
|
2010-03-23 10:51:35 +00:00
|
|
|
* target @surface. Note that the @surface holds an additional
|
|
|
|
* reference to the @subpicture.
|
2010-03-23 10:36:20 +00:00
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_associate_subpicture (GstVaapiSurface * surface,
|
|
|
|
GstVaapiSubpicture * subpicture,
|
|
|
|
const GstVaapiRectangle * src_rect, const GstVaapiRectangle * dst_rect)
|
2010-03-23 10:36:20 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
gboolean success;
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (subpicture != NULL, FALSE);
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!surface->subpictures) {
|
|
|
|
surface->subpictures = g_ptr_array_new ();
|
|
|
|
if (!surface->subpictures)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-12-14 13:13:58 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
if (g_ptr_array_remove_fast (surface->subpictures, subpicture)) {
|
|
|
|
success = _gst_vaapi_surface_deassociate_subpicture (surface, subpicture);
|
2020-05-23 06:00:58 +00:00
|
|
|
gst_vaapi_subpicture_unref (subpicture);
|
2010-03-24 15:11:26 +00:00
|
|
|
if (!success)
|
2014-09-15 12:57:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-03-24 15:11:26 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
success = _gst_vaapi_surface_associate_subpicture (surface,
|
|
|
|
subpicture, src_rect, dst_rect);
|
|
|
|
if (!success)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-05-23 06:00:58 +00:00
|
|
|
g_ptr_array_add (surface->subpictures,
|
|
|
|
gst_mini_object_ref (GST_MINI_OBJECT_CAST (subpicture)));
|
2014-09-15 12:57:57 +00:00
|
|
|
return TRUE;
|
2010-03-24 15:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
_gst_vaapi_surface_associate_subpicture (GstVaapiSurface * surface,
|
|
|
|
GstVaapiSubpicture * subpicture,
|
|
|
|
const GstVaapiRectangle * src_rect, const GstVaapiRectangle * dst_rect)
|
2010-03-24 15:11:26 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
GstVaapiRectangle src_rect_default, dst_rect_default;
|
|
|
|
GstVaapiImage *image;
|
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
surface_id = GST_VAAPI_SURFACE_ID (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (surface_id == VA_INVALID_SURFACE)
|
|
|
|
return FALSE;
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!src_rect) {
|
|
|
|
image = gst_vaapi_subpicture_get_image (subpicture);
|
|
|
|
if (!image)
|
|
|
|
return FALSE;
|
|
|
|
src_rect = &src_rect_default;
|
|
|
|
src_rect_default.x = 0;
|
|
|
|
src_rect_default.y = 0;
|
|
|
|
src_rect_default.width = GST_VAAPI_IMAGE_WIDTH (image);
|
|
|
|
src_rect_default.height = GST_VAAPI_IMAGE_HEIGHT (image);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dst_rect) {
|
|
|
|
dst_rect = &dst_rect_default;
|
|
|
|
dst_rect_default.x = 0;
|
|
|
|
dst_rect_default.y = 0;
|
2019-12-19 13:17:34 +00:00
|
|
|
dst_rect_default.width = GST_VAAPI_SURFACE_WIDTH (surface);
|
|
|
|
dst_rect_default.height = GST_VAAPI_SURFACE_HEIGHT (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaAssociateSubpicture (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
2020-05-23 06:00:58 +00:00
|
|
|
GST_VAAPI_SUBPICTURE_ID (subpicture), &surface_id, 1,
|
2014-09-15 12:57:57 +00:00
|
|
|
src_rect->x, src_rect->y, src_rect->width, src_rect->height,
|
|
|
|
dst_rect->x, dst_rect->y, dst_rect->width, dst_rect->height,
|
|
|
|
from_GstVaapiSubpictureFlags (gst_vaapi_subpicture_get_flags
|
|
|
|
(subpicture)));
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaAssociateSubpicture()"))
|
|
|
|
return FALSE;
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
return TRUE;
|
2010-03-23 10:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_deassociate_subpicture:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @subpicture: a #GstVaapiSubpicture
|
|
|
|
*
|
|
|
|
* Deassociates @subpicture from @surface. Other associations are kept.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_deassociate_subpicture (GstVaapiSurface * surface,
|
|
|
|
GstVaapiSubpicture * subpicture)
|
2010-03-23 10:36:20 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
gboolean success;
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (subpicture != NULL, FALSE);
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!surface->subpictures)
|
|
|
|
return TRUE;
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
/* First, check subpicture was really associated with this surface */
|
|
|
|
if (!g_ptr_array_remove_fast (surface->subpictures, subpicture)) {
|
|
|
|
GST_DEBUG ("subpicture %" GST_VAAPI_ID_FORMAT " was not bound to "
|
|
|
|
"surface %" GST_VAAPI_ID_FORMAT,
|
2020-05-23 06:00:58 +00:00
|
|
|
GST_VAAPI_ID_ARGS (GST_VAAPI_SUBPICTURE_ID (subpicture)),
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_ID_ARGS (GST_VAAPI_SURFACE_ID (surface)));
|
2014-09-15 12:57:57 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
success = _gst_vaapi_surface_deassociate_subpicture (surface, subpicture);
|
2020-05-23 06:00:58 +00:00
|
|
|
gst_vaapi_subpicture_unref (subpicture);
|
2014-09-15 12:57:57 +00:00
|
|
|
return success;
|
2010-03-24 15:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
_gst_vaapi_surface_deassociate_subpicture (GstVaapiSurface * surface,
|
|
|
|
GstVaapiSubpicture * subpicture)
|
2010-03-24 15:11:26 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
2010-03-24 15:11:26 +00:00
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
surface_id = GST_VAAPI_SURFACE_ID (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (surface_id == VA_INVALID_SURFACE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaDeassociateSubpicture (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
2020-05-23 06:00:58 +00:00
|
|
|
GST_VAAPI_SUBPICTURE_ID (subpicture), &surface_id, 1);
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaDeassociateSubpicture()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2010-03-23 10:36:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_sync:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Blocks until all pending operations on the @surface have been
|
|
|
|
* completed.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
2010-03-15 16:13:51 +00:00
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_sync (GstVaapiSurface * surface)
|
2010-03-15 16:13:51 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
VAStatus status;
|
2010-03-15 16:13:51 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, FALSE);
|
2010-03-15 16:13:51 +00:00
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
2010-03-23 16:21:28 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaSyncSurface (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_SURFACE_ID (surface));
|
2014-09-15 12:57:57 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
|
|
|
if (!vaapi_check_status (status, "vaSyncSurface()"))
|
|
|
|
return FALSE;
|
2010-03-15 16:13:51 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
return TRUE;
|
2010-03-15 16:13:51 +00:00
|
|
|
}
|
2010-03-30 08:11:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_query_status:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @pstatus: return location for the #GstVaapiSurfaceStatus
|
|
|
|
*
|
|
|
|
* Finds out any pending operations on the @surface. The
|
|
|
|
* #GstVaapiSurfaceStatus flags are returned into @pstatus.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_query_status (GstVaapiSurface * surface,
|
|
|
|
GstVaapiSurfaceStatus * pstatus)
|
2010-03-30 08:11:50 +00:00
|
|
|
{
|
2019-12-19 13:19:10 +00:00
|
|
|
GstVaapiDisplay *const display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
VASurfaceStatus surface_status;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
g_return_val_if_fail (surface != NULL, FALSE);
|
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK (display);
|
|
|
|
status = vaQuerySurfaceStatus (GST_VAAPI_DISPLAY_VADISPLAY (display),
|
|
|
|
GST_VAAPI_SURFACE_ID (surface), &surface_status);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK (display);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!vaapi_check_status (status, "vaQuerySurfaceStatus()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (pstatus)
|
|
|
|
*pstatus = to_GstVaapiSurfaceStatus (surface_status);
|
|
|
|
return TRUE;
|
2010-03-30 08:11:50 +00:00
|
|
|
}
|
2011-11-25 19:59:56 +00:00
|
|
|
|
|
|
|
/**
|
2011-12-13 14:51:58 +00:00
|
|
|
* gst_vaapi_surface_set_subpictures_from_composition:
|
2011-11-25 19:59:56 +00:00
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @compostion: a #GstVideoOverlayCompositon
|
|
|
|
*
|
|
|
|
* Helper to update the subpictures from #GstVideoOverlayCompositon. Sending
|
|
|
|
* a NULL composition will clear all the current subpictures. Note that this
|
|
|
|
* method will clear existing subpictures.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE on success
|
|
|
|
*/
|
|
|
|
gboolean
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_vaapi_surface_set_subpictures_from_composition (GstVaapiSurface * surface,
|
2019-08-20 14:50:46 +00:00
|
|
|
GstVideoOverlayComposition * composition)
|
2011-11-25 19:59:56 +00:00
|
|
|
{
|
2014-09-15 12:57:57 +00:00
|
|
|
GstVaapiDisplay *display;
|
|
|
|
guint n, nb_rectangles;
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
g_return_val_if_fail (surface != NULL, FALSE);
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2019-12-19 13:19:10 +00:00
|
|
|
display = GST_VAAPI_SURFACE_DISPLAY (surface);
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
/* Clear current subpictures */
|
|
|
|
gst_vaapi_surface_destroy_subpictures (surface);
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!composition)
|
|
|
|
return TRUE;
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
nb_rectangles = gst_video_overlay_composition_n_rectangles (composition);
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
/* Overlay all the rectangles cantained in the overlay composition */
|
|
|
|
for (n = 0; n < nb_rectangles; ++n) {
|
|
|
|
GstVideoOverlayRectangle *rect;
|
|
|
|
GstVaapiRectangle sub_rect;
|
|
|
|
GstVaapiSubpicture *subpicture;
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
rect = gst_video_overlay_composition_get_rectangle (composition, n);
|
|
|
|
subpicture = gst_vaapi_subpicture_new_from_overlay_rectangle (display,
|
|
|
|
rect);
|
2020-05-23 12:48:54 +00:00
|
|
|
if (subpicture == NULL) {
|
|
|
|
GST_WARNING ("could not create subpicture for rectangle %p", rect);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
gst_video_overlay_rectangle_get_render_rectangle (rect,
|
|
|
|
(gint *) & sub_rect.x, (gint *) & sub_rect.y,
|
|
|
|
&sub_rect.width, &sub_rect.height);
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2016-09-07 15:34:08 +00:00
|
|
|
/* ensure that the overlay is not bigger than the surface */
|
2019-12-19 13:17:34 +00:00
|
|
|
sub_rect.y = MIN (sub_rect.y, GST_VAAPI_SURFACE_HEIGHT (surface));
|
|
|
|
sub_rect.width = MIN (sub_rect.width, GST_VAAPI_SURFACE_WIDTH (surface));
|
2016-09-07 15:34:08 +00:00
|
|
|
|
2014-09-15 12:57:57 +00:00
|
|
|
if (!gst_vaapi_surface_associate_subpicture (surface, subpicture,
|
|
|
|
NULL, &sub_rect)) {
|
|
|
|
GST_WARNING ("could not render overlay rectangle %p", rect);
|
2020-05-23 06:00:58 +00:00
|
|
|
gst_vaapi_subpicture_unref (subpicture);
|
2014-09-15 12:57:57 +00:00
|
|
|
return FALSE;
|
2011-11-25 19:59:56 +00:00
|
|
|
}
|
2020-05-23 06:00:58 +00:00
|
|
|
gst_vaapi_subpicture_unref (subpicture);
|
2014-09-15 12:57:57 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
2011-11-25 19:59:56 +00:00
|
|
|
}
|
2016-10-19 14:09:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_set_buffer_proxy:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @proxy: an external #GstVaapiBufferProxy
|
|
|
|
*
|
|
|
|
* Replaces the external buffer proxy in @surface with @proxy.
|
|
|
|
*
|
|
|
|
* This is useful when a dmabuf-based memory is instantiated in order
|
|
|
|
* to relate the generated buffer @proxy with the processed @surface.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gst_vaapi_surface_set_buffer_proxy (GstVaapiSurface * surface,
|
|
|
|
GstVaapiBufferProxy * proxy)
|
|
|
|
{
|
|
|
|
gst_vaapi_buffer_proxy_replace (&surface->extbuf_proxy, proxy);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_peek_buffer_proxy:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* This is useful when a dmabuf-based memory is instantiated in order
|
|
|
|
* to relate the generated buffer @proxy with the processed @surface.
|
|
|
|
*
|
|
|
|
* Returns: (transfer none): the associated external
|
|
|
|
* #GstVaapiBufferProxy
|
|
|
|
**/
|
|
|
|
GstVaapiBufferProxy *
|
|
|
|
gst_vaapi_surface_peek_buffer_proxy (GstVaapiSurface * surface)
|
|
|
|
{
|
|
|
|
return surface->extbuf_proxy;
|
|
|
|
}
|