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-01-29 13:14:45 +00:00
|
|
|
* Copyright (C) 2011-2013 Intel Corporation
|
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"
|
2013-07-26 10:57:19 +00:00
|
|
|
#include "gstvaapiimage_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
|
|
|
|
_gst_vaapi_surface_associate_subpicture(
|
|
|
|
GstVaapiSurface *surface,
|
|
|
|
GstVaapiSubpicture *subpicture,
|
|
|
|
const GstVaapiRectangle *src_rect,
|
|
|
|
const GstVaapiRectangle *dst_rect
|
|
|
|
);
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_gst_vaapi_surface_deassociate_subpicture(
|
|
|
|
GstVaapiSurface *surface,
|
|
|
|
GstVaapiSubpicture *subpicture
|
|
|
|
);
|
|
|
|
|
2010-03-23 10:36:20 +00:00
|
|
|
static void
|
2010-03-24 15:11:26 +00:00
|
|
|
destroy_subpicture_cb(gpointer subpicture, gpointer surface)
|
2010-03-23 10:36:20 +00:00
|
|
|
{
|
2010-03-24 15:11:26 +00:00
|
|
|
_gst_vaapi_surface_deassociate_subpicture(surface, subpicture);
|
2013-04-30 15:22:15 +00:00
|
|
|
gst_vaapi_object_unref(subpicture);
|
2010-03-23 10:36:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-04 17:39:01 +00:00
|
|
|
static void
|
2011-11-25 19:59:56 +00:00
|
|
|
gst_vaapi_surface_destroy_subpictures(GstVaapiSurface *surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2013-04-30 15:22:15 +00:00
|
|
|
if (surface->subpictures) {
|
|
|
|
g_ptr_array_foreach(surface->subpictures, destroy_subpicture_cb,
|
|
|
|
surface);
|
|
|
|
g_ptr_array_free(surface->subpictures, TRUE);
|
|
|
|
surface->subpictures = NULL;
|
2010-03-24 14:57:33 +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
|
|
|
|
gst_vaapi_surface_destroy(GstVaapiSurface *surface)
|
|
|
|
{
|
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
surface_id = GST_VAAPI_OBJECT_ID(surface);
|
|
|
|
GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
|
|
|
|
|
|
|
|
gst_vaapi_surface_destroy_subpictures(surface);
|
2011-12-13 15:53:15 +00:00
|
|
|
gst_vaapi_surface_set_parent_context(surface, NULL);
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
if (surface_id != VA_INVALID_SURFACE) {
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-17 07:59:31 +00:00
|
|
|
status = vaDestroySurfaces(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
&surface_id, 1
|
2010-03-17 07:59:31 +00:00
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
if (!vaapi_check_status(status, "vaDestroySurfaces()"))
|
2010-03-24 15:12:56 +00:00
|
|
|
g_warning("failed to destroy surface %" GST_VAAPI_ID_FORMAT,
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_ID_ARGS(surface_id));
|
|
|
|
GST_VAAPI_OBJECT_ID(surface) = VA_INVALID_SURFACE;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2013-04-30 15:22:15 +00:00
|
|
|
gst_vaapi_surface_create(GstVaapiSurface *surface,
|
|
|
|
GstVaapiChromaType chroma_type, guint width, guint height)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2010-03-24 17:40:19 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-04 17:39:01 +00:00
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
2013-07-09 17:13:39 +00:00
|
|
|
guint va_chroma_format;
|
|
|
|
|
|
|
|
va_chroma_format = from_GstVaapiChromaType(chroma_type);
|
|
|
|
if (!va_chroma_format)
|
|
|
|
goto error_unsupported_chroma_type;
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
status = vaCreateSurfaces(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2013-07-09 17:13:39 +00:00
|
|
|
width, height, va_chroma_format,
|
2010-03-04 17:39:01 +00:00
|
|
|
1, &surface_id
|
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-04 17:39:01 +00:00
|
|
|
if (!vaapi_check_status(status, "vaCreateSurfaces()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2013-07-10 11:58:55 +00:00
|
|
|
surface->format = GST_VIDEO_FORMAT_UNKNOWN;
|
2013-04-30 15:22:15 +00:00
|
|
|
surface->chroma_type = chroma_type;
|
|
|
|
surface->width = width;
|
|
|
|
surface->height = height;
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
|
|
|
|
GST_VAAPI_OBJECT_ID(surface) = surface_id;
|
2010-03-04 17:39:01 +00:00
|
|
|
return TRUE;
|
2013-07-09 17:13:39 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_unsupported_chroma_type:
|
|
|
|
GST_ERROR("unsupported chroma-type %u", chroma_type);
|
|
|
|
return FALSE;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:08:37 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vaapi_surface_create_with_format(GstVaapiSurface *surface,
|
|
|
|
GstVideoFormat format, guint width, guint height)
|
|
|
|
{
|
|
|
|
#if VA_CHECK_VERSION(0,34,0)
|
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
|
|
|
guint chroma_type, va_chroma_format;
|
|
|
|
const VAImageFormat *va_format;
|
|
|
|
VASurfaceAttrib attrib;
|
|
|
|
|
2013-07-15 12:42:33 +00:00
|
|
|
va_format = gst_vaapi_video_format_to_va_format(format);
|
2013-07-09 17:08:37 +00:00
|
|
|
if (!va_format)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
2013-07-15 12:42:33 +00:00
|
|
|
chroma_type = gst_vaapi_video_format_get_chroma_type(format);
|
2013-07-09 17:08:37 +00:00
|
|
|
if (!chroma_type)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
|
|
|
va_chroma_format = from_GstVaapiChromaType(chroma_type);
|
|
|
|
if (!va_chroma_format)
|
|
|
|
goto error_unsupported_format;
|
|
|
|
|
|
|
|
attrib.flags = VA_SURFACE_ATTRIB_SETTABLE;
|
|
|
|
attrib.type = VASurfaceAttribPixelFormat;
|
|
|
|
attrib.value.type = VAGenericValueTypeInteger;
|
|
|
|
attrib.value.value.i = va_format->fourcc;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
|
|
|
status = vaCreateSurfaces(
|
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
|
|
|
va_chroma_format, width, height,
|
|
|
|
&surface_id, 1,
|
|
|
|
&attrib, 1
|
|
|
|
);
|
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
|
|
|
if (!vaapi_check_status(status, "vaCreateSurfaces()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
surface->format = format;
|
|
|
|
surface->chroma_type = chroma_type;
|
|
|
|
surface->width = width;
|
|
|
|
surface->height = height;
|
|
|
|
|
|
|
|
GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
|
|
|
|
GST_VAAPI_OBJECT_ID(surface) = surface_id;
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
error_unsupported_format:
|
2013-07-22 13:15:48 +00:00
|
|
|
GST_ERROR("unsupported format %u", gst_vaapi_video_format_to_string(format));
|
2013-07-09 17:08:37 +00:00
|
|
|
return FALSE;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
#define gst_vaapi_surface_finalize gst_vaapi_surface_destroy
|
|
|
|
GST_VAAPI_OBJECT_DEFINE_CLASS(GstVaapiSurface, gst_vaapi_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.
|
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiSurface object
|
|
|
|
*/
|
2010-03-04 17:39:01 +00:00
|
|
|
GstVaapiSurface *
|
2010-03-11 13:58:32 +00:00
|
|
|
gst_vaapi_surface_new(
|
|
|
|
GstVaapiDisplay *display,
|
|
|
|
GstVaapiChromaType chroma_type,
|
|
|
|
guint width,
|
|
|
|
guint height
|
|
|
|
)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2013-04-30 15:22:15 +00:00
|
|
|
GstVaapiSurface *surface;
|
|
|
|
|
2010-03-11 13:58:32 +00:00
|
|
|
GST_DEBUG("size %ux%u, chroma type 0x%x", width, height, chroma_type);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
surface = gst_vaapi_object_new(gst_vaapi_surface_class(), display);
|
|
|
|
if (!surface)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!gst_vaapi_surface_create(surface, chroma_type, width, height))
|
|
|
|
goto error;
|
|
|
|
return surface;
|
|
|
|
|
|
|
|
error:
|
|
|
|
gst_vaapi_object_unref(surface);
|
|
|
|
return NULL;
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
2013-07-09 17:08:37 +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
|
|
|
|
*
|
|
|
|
* 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,
|
|
|
|
GstVideoFormat format,
|
|
|
|
guint width,
|
|
|
|
guint height
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiSurface *surface;
|
|
|
|
|
|
|
|
GST_DEBUG("size %ux%u, format %s", width, height,
|
2013-07-22 13:15:48 +00:00
|
|
|
gst_vaapi_video_format_to_string(format));
|
2013-07-09 17:08:37 +00:00
|
|
|
|
|
|
|
surface = gst_vaapi_object_new(gst_vaapi_surface_class(), display);
|
|
|
|
if (!surface)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!gst_vaapi_surface_create_with_format(surface, format, width, height))
|
|
|
|
goto error;
|
|
|
|
return surface;
|
|
|
|
|
|
|
|
error:
|
|
|
|
gst_vaapi_object_unref(surface);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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
|
2010-03-25 09:49:17 +00:00
|
|
|
gst_vaapi_surface_get_id(GstVaapiSurface *surface)
|
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, VA_INVALID_SURFACE);
|
2010-03-25 09:49:17 +00:00
|
|
|
|
|
|
|
return GST_VAAPI_OBJECT_ID(surface);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_surface_get_chroma_type(GstVaapiSurface *surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-07-08 09:43:27 +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
|
|
|
|
gst_vaapi_surface_get_format(GstVaapiSurface *surface)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(surface != NULL, 0);
|
|
|
|
|
2013-07-10 11:58:55 +00:00
|
|
|
/* Try to determine the underlying VA surface format */
|
|
|
|
if (surface->format == GST_VIDEO_FORMAT_UNKNOWN) {
|
|
|
|
GstVaapiImage * const image = gst_vaapi_surface_derive_image(surface);
|
|
|
|
if (image) {
|
2013-07-26 10:57:19 +00:00
|
|
|
surface->format = GST_VAAPI_IMAGE_FORMAT(image);
|
2013-07-10 11:58:55 +00:00
|
|
|
gst_vaapi_object_unref(image);
|
|
|
|
}
|
|
|
|
if (surface->format == GST_VIDEO_FORMAT_UNKNOWN)
|
|
|
|
surface->format = GST_VIDEO_FORMAT_ENCODED;
|
|
|
|
}
|
2013-07-09 17:08:37 +00:00
|
|
|
return GST_VAAPI_SURFACE_FORMAT(surface);
|
|
|
|
}
|
|
|
|
|
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
|
2010-03-11 13:58:32 +00:00
|
|
|
gst_vaapi_surface_get_width(GstVaapiSurface *surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-07-08 09:43:27 +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
|
2010-03-11 13:58:32 +00:00
|
|
|
gst_vaapi_surface_get_height(GstVaapiSurface *surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, 0);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
2013-07-08 09:43:27 +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
|
2010-03-23 13:32:36 +00:00
|
|
|
* @pwidth: return location for the width, or %NULL
|
|
|
|
* @pheight: 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
|
|
|
|
gst_vaapi_surface_get_size(
|
|
|
|
GstVaapiSurface *surface,
|
|
|
|
guint *pwidth,
|
|
|
|
guint *pheight
|
|
|
|
)
|
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_if_fail(surface != NULL);
|
2010-03-12 17:39:11 +00:00
|
|
|
|
|
|
|
if (pwidth)
|
2013-07-08 09:43:27 +00:00
|
|
|
*pwidth = GST_VAAPI_SURFACE_WIDTH(surface);
|
2010-03-12 17:39:11 +00:00
|
|
|
|
|
|
|
if (pheight)
|
2013-07-08 09:43:27 +00:00
|
|
|
*pheight = GST_VAAPI_SURFACE_HEIGHT(surface);
|
2010-03-12 17:39:11 +00:00
|
|
|
}
|
|
|
|
|
2011-12-13 15:53:15 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_set_parent_context:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
* @context: a #GstVaapiContext
|
|
|
|
*
|
|
|
|
* Sets new parent context, or clears any parent context if @context
|
|
|
|
* is %NULL. This function owns an extra reference to the context,
|
|
|
|
* which will be released when the surface is destroyed.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_surface_set_parent_context(
|
|
|
|
GstVaapiSurface *surface,
|
|
|
|
GstVaapiContext *context
|
|
|
|
)
|
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_if_fail(surface != NULL);
|
2011-12-13 15:53:15 +00:00
|
|
|
|
surface: fix memory leak through unreleased parent context.
Break the circular references between GstVaapiContext and its children
GstVaapiSurfaces. Since the VA surfaces held an extra reference to the
context, which holds a reference to its VA surfaces, then none of those
were released.
How does this impact support for subpictures?
The only situation when the parent context needs to disappear is when
it is replaced with another one because of a resolution change in the
video stream for instance, or a normal destroy. In this case, it does
not really matter to apply subpictures to the peer surfaces since they
are either gone, or those that are left in the pipe can probably bear
a reinstantiation of the subpictures for it.
So, parent_context is set to NULL when the parent context is destroyed,
other VA surfaces can still get subpictures attached to them, individually
not as a whole. i.e. subpictures for surface S1 will be created from
active composition buffers and associated to S1, subpictures for S2 will
be created from the next active composition buffers, etc. We don't try
to cache the subpictures in those cases (pending surfaces until EOS
is reached, or pending surfaces until new surfaces matching new VA context
get to be used instead).
2013-05-30 16:17:07 +00:00
|
|
|
surface->parent_context = NULL;
|
2011-12-13 15:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_surface_get_parent_context:
|
|
|
|
* @surface: a #GstVaapiSurface
|
|
|
|
*
|
|
|
|
* Retrieves the parent #GstVaapiContext, or %NULL if there is
|
|
|
|
* none. The surface shall still own a reference to the context.
|
|
|
|
* i.e. the caller shall not unreference the returned context object.
|
|
|
|
*
|
|
|
|
* Return value: the parent context, if any.
|
|
|
|
*/
|
|
|
|
GstVaapiContext *
|
|
|
|
gst_vaapi_surface_get_parent_context(GstVaapiSurface *surface)
|
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, NULL);
|
2011-12-13 15:53:15 +00:00
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
return surface->parent_context;
|
2011-12-13 15:53:15 +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
|
2013-04-30 15:22:15 +00:00
|
|
|
* gst_vaapi_object_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 *
|
|
|
|
gst_vaapi_surface_derive_image(GstVaapiSurface *surface)
|
|
|
|
{
|
2010-03-23 16:21:28 +00:00
|
|
|
GstVaapiDisplay *display;
|
2010-03-18 15:28:59 +00:00
|
|
|
VAImage va_image;
|
|
|
|
VAStatus status;
|
|
|
|
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, NULL);
|
2010-03-18 15:28:59 +00:00
|
|
|
|
2010-03-24 17:40:19 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-18 15:28:59 +00:00
|
|
|
va_image.image_id = VA_INVALID_ID;
|
|
|
|
va_image.buf = VA_INVALID_ID;
|
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-18 15:28:59 +00:00
|
|
|
status = vaDeriveImage(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_OBJECT_ID(surface),
|
2010-03-18 15:28:59 +00:00
|
|
|
&va_image
|
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-18 15:28:59 +00:00
|
|
|
if (!vaapi_check_status(status, "vaDeriveImage()"))
|
|
|
|
return NULL;
|
|
|
|
if (va_image.image_id == VA_INVALID_ID || va_image.buf == VA_INVALID_ID)
|
|
|
|
return NULL;
|
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
return gst_vaapi_image_new_with_image(display, &va_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
|
|
|
|
gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image)
|
|
|
|
{
|
2010-03-23 16:21:28 +00:00
|
|
|
GstVaapiDisplay *display;
|
2010-03-15 11:49:03 +00:00
|
|
|
VAImageID image_id;
|
|
|
|
VAStatus status;
|
|
|
|
guint width, height;
|
|
|
|
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, FALSE);
|
|
|
|
g_return_val_if_fail(image != NULL, FALSE);
|
2010-03-15 11:49:03 +00:00
|
|
|
|
2010-03-24 17:40:19 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-23 16:21:28 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-07-26 10:57:19 +00:00
|
|
|
width = GST_VAAPI_IMAGE_WIDTH(image);
|
|
|
|
height = GST_VAAPI_IMAGE_HEIGHT(image);
|
2013-04-30 15:22:15 +00:00
|
|
|
if (width != surface->width || height != surface->height)
|
2010-03-15 11:49:03 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
image_id = GST_VAAPI_OBJECT_ID(image);
|
2010-03-15 11:49:03 +00:00
|
|
|
if (image_id == VA_INVALID_ID)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-15 11:49:03 +00:00
|
|
|
status = vaGetImage(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_OBJECT_ID(surface),
|
2010-03-15 11:49:03 +00:00
|
|
|
0, 0, width, height,
|
|
|
|
image_id
|
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-15 11:49:03 +00:00
|
|
|
if (!vaapi_check_status(status, "vaGetImage()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_surface_put_image(GstVaapiSurface *surface, GstVaapiImage *image)
|
|
|
|
{
|
2010-03-23 16:21:28 +00:00
|
|
|
GstVaapiDisplay *display;
|
2010-03-15 11:49:03 +00:00
|
|
|
VAImageID image_id;
|
|
|
|
VAStatus status;
|
|
|
|
guint width, height;
|
|
|
|
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, FALSE);
|
|
|
|
g_return_val_if_fail(image != NULL, FALSE);
|
2010-03-15 11:49:03 +00:00
|
|
|
|
2010-03-24 17:40:19 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-23 16:21:28 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-07-26 10:57:19 +00:00
|
|
|
width = GST_VAAPI_IMAGE_WIDTH(image);
|
|
|
|
height = GST_VAAPI_IMAGE_HEIGHT(image);
|
2013-04-30 15:22:15 +00:00
|
|
|
if (width != surface->width || height != surface->height)
|
2010-03-15 11:49:03 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
image_id = GST_VAAPI_OBJECT_ID(image);
|
2010-03-15 11:49:03 +00:00
|
|
|
if (image_id == VA_INVALID_ID)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-15 11:49:03 +00:00
|
|
|
status = vaPutImage(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_OBJECT_ID(surface),
|
2010-03-15 11:49:03 +00:00
|
|
|
image_id,
|
|
|
|
0, 0, width, height,
|
|
|
|
0, 0, width, height
|
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-15 11:49:03 +00:00
|
|
|
if (!vaapi_check_status(status, "vaPutImage()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
gboolean success;
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2013-05-23 16:15:48 +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
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
if (!surface->subpictures) {
|
|
|
|
surface->subpictures = g_ptr_array_new();
|
|
|
|
if (!surface->subpictures)
|
2010-03-23 10:36:20 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
if (g_ptr_array_remove_fast(surface->subpictures, subpicture)) {
|
|
|
|
success = _gst_vaapi_surface_deassociate_subpicture(surface,
|
|
|
|
subpicture);
|
|
|
|
gst_vaapi_object_unref(subpicture);
|
2011-12-14 13:13:58 +00:00
|
|
|
if (!success)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-03-24 15:11:26 +00:00
|
|
|
success = _gst_vaapi_surface_associate_subpicture(
|
|
|
|
surface,
|
|
|
|
subpicture,
|
|
|
|
src_rect,
|
|
|
|
dst_rect
|
|
|
|
);
|
|
|
|
if (!success)
|
|
|
|
return FALSE;
|
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
g_ptr_array_add(surface->subpictures, gst_vaapi_object_ref(subpicture));
|
2010-03-24 15:11:26 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gst_vaapi_surface_associate_subpicture(
|
|
|
|
GstVaapiSurface *surface,
|
|
|
|
GstVaapiSubpicture *subpicture,
|
|
|
|
const GstVaapiRectangle *src_rect,
|
|
|
|
const GstVaapiRectangle *dst_rect
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDisplay *display;
|
|
|
|
GstVaapiRectangle src_rect_default, dst_rect_default;
|
|
|
|
GstVaapiImage *image;
|
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
|
|
|
|
2010-03-24 17:40:19 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-24 15:11:26 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
surface_id = GST_VAAPI_OBJECT_ID(surface);
|
|
|
|
if (surface_id == VA_INVALID_SURFACE)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-23 10:36:20 +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;
|
2013-07-26 10:57:19 +00:00
|
|
|
src_rect_default.width = GST_VAAPI_IMAGE_WIDTH(image);
|
|
|
|
src_rect_default.height = GST_VAAPI_IMAGE_HEIGHT(image);
|
2010-03-23 10:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!dst_rect) {
|
|
|
|
dst_rect = &dst_rect_default;
|
|
|
|
dst_rect_default.x = 0;
|
|
|
|
dst_rect_default.y = 0;
|
2013-04-30 15:22:15 +00:00
|
|
|
dst_rect_default.width = surface->width;
|
|
|
|
dst_rect_default.height = surface->height;
|
2010-03-23 10:36:20 +00:00
|
|
|
}
|
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-23 10:36:20 +00:00
|
|
|
status = vaAssociateSubpicture(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_OBJECT_ID(subpicture),
|
|
|
|
&surface_id, 1,
|
2010-03-23 10:36:20 +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,
|
2012-05-15 08:24:08 +00:00
|
|
|
from_GstVaapiSubpictureFlags(gst_vaapi_subpicture_get_flags(subpicture))
|
2010-03-23 10:36:20 +00:00
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-23 10:36:20 +00:00
|
|
|
if (!vaapi_check_status(status, "vaAssociateSubpicture()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
gst_vaapi_surface_deassociate_subpicture(
|
|
|
|
GstVaapiSurface *surface,
|
|
|
|
GstVaapiSubpicture *subpicture
|
|
|
|
)
|
|
|
|
{
|
2010-03-24 15:11:26 +00:00
|
|
|
gboolean success;
|
2010-03-23 10:36:20 +00:00
|
|
|
|
2013-05-23 16:15:48 +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
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
if (!surface->subpictures)
|
2010-03-23 10:36:20 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* First, check subpicture was really associated with this surface */
|
2013-04-30 15:22:15 +00:00
|
|
|
if (!g_ptr_array_remove_fast(surface->subpictures, subpicture)) {
|
2011-12-14 12:46:26 +00:00
|
|
|
GST_DEBUG("subpicture %" GST_VAAPI_ID_FORMAT " was not bound to "
|
2010-03-24 13:19:58 +00:00
|
|
|
"surface %" GST_VAAPI_ID_FORMAT,
|
|
|
|
GST_VAAPI_ID_ARGS(GST_VAAPI_OBJECT_ID(subpicture)),
|
|
|
|
GST_VAAPI_ID_ARGS(GST_VAAPI_OBJECT_ID(surface)));
|
2010-03-23 10:36:20 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-03-24 15:11:26 +00:00
|
|
|
success = _gst_vaapi_surface_deassociate_subpicture(surface, subpicture);
|
2013-04-30 15:22:15 +00:00
|
|
|
gst_vaapi_object_unref(subpicture);
|
2010-03-24 15:11:26 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gst_vaapi_surface_deassociate_subpicture(
|
|
|
|
GstVaapiSurface *surface,
|
|
|
|
GstVaapiSubpicture *subpicture
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDisplay *display;
|
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
|
|
|
|
2010-03-24 17:40:19 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-24 15:11:26 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
surface_id = GST_VAAPI_OBJECT_ID(surface);
|
|
|
|
if (surface_id == VA_INVALID_SURFACE)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-23 10:36:20 +00:00
|
|
|
status = vaDeassociateSubpicture(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_OBJECT_ID(subpicture),
|
|
|
|
&surface_id, 1
|
2010-03-23 10:36:20 +00:00
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-23 10:36:20 +00:00
|
|
|
if (!vaapi_check_status(status, "vaDeassociateSubpicture()"))
|
|
|
|
return FALSE;
|
2010-03-24 15:11:26 +00:00
|
|
|
|
2010-03-23 10:36:20 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_surface_sync(GstVaapiSurface *surface)
|
|
|
|
{
|
2010-03-23 16:21:28 +00:00
|
|
|
GstVaapiDisplay *display;
|
2010-03-15 16:13:51 +00:00
|
|
|
VAStatus status;
|
|
|
|
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, FALSE);
|
2010-03-15 16:13:51 +00:00
|
|
|
|
2010-03-24 17:40:19 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-23 16:21:28 +00:00
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-15 16:13:51 +00:00
|
|
|
status = vaSyncSurface(
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_OBJECT_ID(surface)
|
2010-03-15 16:13:51 +00:00
|
|
|
);
|
2010-03-23 16:21:28 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-15 16:13:51 +00:00
|
|
|
if (!vaapi_check_status(status, "vaSyncSurface()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
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
|
|
|
|
gst_vaapi_surface_query_status(
|
|
|
|
GstVaapiSurface *surface,
|
|
|
|
GstVaapiSurfaceStatus *pstatus
|
|
|
|
)
|
|
|
|
{
|
|
|
|
VASurfaceStatus surface_status;
|
|
|
|
VAStatus status;
|
|
|
|
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, FALSE);
|
2010-03-30 08:11:50 +00:00
|
|
|
|
|
|
|
GST_VAAPI_OBJECT_LOCK_DISPLAY(surface);
|
|
|
|
status = vaQuerySurfaceStatus(
|
|
|
|
GST_VAAPI_OBJECT_VADISPLAY(surface),
|
|
|
|
GST_VAAPI_OBJECT_ID(surface),
|
|
|
|
&surface_status
|
|
|
|
);
|
|
|
|
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(surface);
|
|
|
|
if (!vaapi_check_status(status, "vaQuerySurfaceStatus()"))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (pstatus)
|
|
|
|
*pstatus = to_GstVaapiSurfaceStatus(surface_status);
|
|
|
|
return TRUE;
|
|
|
|
}
|
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
|
2011-12-14 13:40:37 +00:00
|
|
|
* @propagate_context: a flag specifying whether to apply composition
|
|
|
|
* to the parent context, if any
|
2011-11-25 19:59:56 +00:00
|
|
|
*
|
|
|
|
* 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
|
2011-12-13 14:51:58 +00:00
|
|
|
gst_vaapi_surface_set_subpictures_from_composition(
|
2011-12-14 13:40:37 +00:00
|
|
|
GstVaapiSurface *surface,
|
|
|
|
GstVideoOverlayComposition *composition,
|
|
|
|
gboolean propagate_context
|
2011-11-25 19:59:56 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiDisplay *display;
|
|
|
|
guint n, nb_rectangles;
|
|
|
|
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(surface != NULL, FALSE);
|
2011-11-25 19:59:56 +00:00
|
|
|
|
2013-04-30 15:22:15 +00:00
|
|
|
if (propagate_context && surface->parent_context)
|
|
|
|
return gst_vaapi_context_apply_composition(surface->parent_context,
|
|
|
|
composition);
|
2011-12-14 13:40:37 +00:00
|
|
|
|
2011-11-25 19:59:56 +00:00
|
|
|
display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
|
|
|
if (!display)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Clear current subpictures */
|
|
|
|
gst_vaapi_surface_destroy_subpictures(surface);
|
|
|
|
|
|
|
|
if (!composition)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
nb_rectangles = gst_video_overlay_composition_n_rectangles (composition);
|
|
|
|
|
|
|
|
/* Overlay all the rectangles cantained in the overlay composition */
|
|
|
|
for (n = 0; n < nb_rectangles; ++n) {
|
|
|
|
GstVideoOverlayRectangle *rect;
|
|
|
|
GstVaapiRectangle sub_rect;
|
|
|
|
GstVaapiSubpicture *subpicture;
|
|
|
|
|
|
|
|
rect = gst_video_overlay_composition_get_rectangle (composition, n);
|
2011-12-14 12:16:21 +00:00
|
|
|
subpicture = gst_vaapi_subpicture_new_from_overlay_rectangle (display,
|
|
|
|
rect);
|
2011-11-25 19:59:56 +00:00
|
|
|
|
|
|
|
gst_video_overlay_rectangle_get_render_rectangle (rect,
|
|
|
|
(gint *)&sub_rect.x, (gint *)&sub_rect.y,
|
|
|
|
&sub_rect.width, &sub_rect.height);
|
|
|
|
|
|
|
|
if (!gst_vaapi_surface_associate_subpicture (surface, subpicture,
|
|
|
|
NULL, &sub_rect)) {
|
|
|
|
GST_WARNING ("could not render overlay rectangle %p", rect);
|
2013-04-30 15:22:15 +00:00
|
|
|
gst_vaapi_object_unref (subpicture);
|
2011-11-25 19:59:56 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-04-30 15:22:15 +00:00
|
|
|
gst_vaapi_object_unref (subpicture);
|
2011-11-25 19:59:56 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|