2010-03-04 17:39:01 +00:00
|
|
|
/*
|
|
|
|
* gstvaapisurface.c - VA surface abstraction
|
|
|
|
*
|
|
|
|
* gstreamer-vaapi (C) 2010 Splitted-Desktop Systems
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2010-03-04 17:39:01 +00:00
|
|
|
#include "config.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"
|
2010-03-18 15:28:59 +00:00
|
|
|
#include "gstvaapiimage.h"
|
2010-04-01 09:47:59 +00:00
|
|
|
#include "gstvaapi_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-23 16:21:28 +00:00
|
|
|
G_DEFINE_TYPE(GstVaapiSurface, gst_vaapi_surface, GST_VAAPI_TYPE_OBJECT);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
|
|
|
#define GST_VAAPI_SURFACE_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
|
|
|
|
GST_VAAPI_TYPE_SURFACE, \
|
|
|
|
GstVaapiSurfacePrivate))
|
|
|
|
|
|
|
|
struct _GstVaapiSurfacePrivate {
|
|
|
|
guint width;
|
|
|
|
guint height;
|
2010-03-11 13:58:32 +00:00
|
|
|
GstVaapiChromaType chroma_type;
|
2010-03-23 10:36:20 +00:00
|
|
|
GPtrArray *subpictures;
|
2010-03-04 17:39:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_WIDTH,
|
|
|
|
PROP_HEIGHT,
|
2010-03-11 13:58:32 +00:00
|
|
|
PROP_CHROMA_TYPE
|
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);
|
2010-03-23 10:36:20 +00:00
|
|
|
g_object_unref(subpicture);
|
|
|
|
}
|
|
|
|
|
2010-03-04 17:39:01 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_surface_destroy(GstVaapiSurface *surface)
|
|
|
|
{
|
2010-03-24 17:40:19 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-04 17:39:01 +00:00
|
|
|
GstVaapiSurfacePrivate * const priv = surface->priv;
|
2010-03-24 13:19:58 +00:00
|
|
|
VASurfaceID surface_id;
|
2010-03-04 17:39:01 +00:00
|
|
|
VAStatus status;
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
surface_id = GST_VAAPI_OBJECT_ID(surface);
|
|
|
|
GST_DEBUG("surface %" GST_VAAPI_ID_FORMAT, GST_VAAPI_ID_ARGS(surface_id));
|
2010-03-23 10:49:33 +00:00
|
|
|
|
2010-03-24 14:57:33 +00:00
|
|
|
if (priv->subpictures) {
|
2010-03-24 15:11:26 +00:00
|
|
|
g_ptr_array_foreach(priv->subpictures, destroy_subpicture_cb, surface);
|
2010-03-24 14:57:33 +00:00
|
|
|
g_ptr_array_free(priv->subpictures, TRUE);
|
|
|
|
priv->subpictures = NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
gst_vaapi_surface_create(GstVaapiSurface *surface)
|
|
|
|
{
|
2010-03-24 17:40:19 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_DISPLAY(surface);
|
2010-03-04 17:39:01 +00:00
|
|
|
GstVaapiSurfacePrivate * const priv = surface->priv;
|
|
|
|
VASurfaceID surface_id;
|
|
|
|
VAStatus status;
|
2010-03-11 13:58:32 +00:00
|
|
|
guint format;
|
|
|
|
|
|
|
|
switch (priv->chroma_type) {
|
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV420:
|
|
|
|
format = VA_RT_FORMAT_YUV420;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV422:
|
|
|
|
format = VA_RT_FORMAT_YUV422;
|
|
|
|
break;
|
|
|
|
case GST_VAAPI_CHROMA_TYPE_YUV444:
|
|
|
|
format = VA_RT_FORMAT_YUV444;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
GST_DEBUG("unsupported chroma-type %u\n", priv->chroma_type);
|
|
|
|
return FALSE;
|
|
|
|
}
|
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),
|
2010-03-04 17:39:01 +00:00
|
|
|
priv->width,
|
|
|
|
priv->height,
|
2010-03-11 13:58:32 +00:00
|
|
|
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;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_surface_finalize(GObject *object)
|
|
|
|
{
|
|
|
|
gst_vaapi_surface_destroy(GST_VAAPI_SURFACE(object));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(gst_vaapi_surface_parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-11 13:58:32 +00:00
|
|
|
gst_vaapi_surface_set_property(
|
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
|
|
|
GstVaapiSurface * const surface = GST_VAAPI_SURFACE(object);
|
|
|
|
GstVaapiSurfacePrivate * const priv = surface->priv;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_WIDTH:
|
|
|
|
priv->width = g_value_get_uint(value);
|
|
|
|
break;
|
|
|
|
case PROP_HEIGHT:
|
|
|
|
priv->height = g_value_get_uint(value);
|
|
|
|
break;
|
2010-03-11 13:58:32 +00:00
|
|
|
case PROP_CHROMA_TYPE:
|
|
|
|
priv->chroma_type = g_value_get_uint(value);
|
2010-03-04 17:39:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-03-11 13:58:32 +00:00
|
|
|
gst_vaapi_surface_get_property(
|
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2010-03-09 12:00:32 +00:00
|
|
|
GstVaapiSurface * const surface = GST_VAAPI_SURFACE(object);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_WIDTH:
|
|
|
|
g_value_set_uint(value, gst_vaapi_surface_get_width(surface));
|
|
|
|
break;
|
|
|
|
case PROP_HEIGHT:
|
|
|
|
g_value_set_uint(value, gst_vaapi_surface_get_height(surface));
|
|
|
|
break;
|
2010-03-11 13:58:32 +00:00
|
|
|
case PROP_CHROMA_TYPE:
|
|
|
|
g_value_set_uint(value, gst_vaapi_surface_get_chroma_type(surface));
|
2010-03-04 17:39:01 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-10 13:02:45 +00:00
|
|
|
static void
|
|
|
|
gst_vaapi_surface_constructed(GObject *object)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
2010-03-10 13:02:45 +00:00
|
|
|
GstVaapiSurface * const surface = GST_VAAPI_SURFACE(object);
|
2010-03-04 17:39:01 +00:00
|
|
|
GObjectClass *parent_class;
|
|
|
|
|
2010-03-10 13:02:45 +00:00
|
|
|
gst_vaapi_surface_create(surface);
|
2010-03-04 17:39:01 +00:00
|
|
|
|
|
|
|
parent_class = G_OBJECT_CLASS(gst_vaapi_surface_parent_class);
|
2010-03-10 13:02:45 +00:00
|
|
|
if (parent_class->constructed)
|
|
|
|
parent_class->constructed(object);
|
2010-03-04 17:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_surface_class_init(GstVaapiSurfaceClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
|
|
|
|
|
|
|
|
g_type_class_add_private(klass, sizeof(GstVaapiSurfacePrivate));
|
|
|
|
|
|
|
|
object_class->finalize = gst_vaapi_surface_finalize;
|
|
|
|
object_class->set_property = gst_vaapi_surface_set_property;
|
|
|
|
object_class->get_property = gst_vaapi_surface_get_property;
|
2010-03-10 13:02:45 +00:00
|
|
|
object_class->constructed = gst_vaapi_surface_constructed;
|
2010-03-04 17:39:01 +00:00
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class,
|
|
|
|
PROP_WIDTH,
|
|
|
|
g_param_spec_uint("width",
|
2010-03-19 15:45:21 +00:00
|
|
|
"Width",
|
|
|
|
"The width of the surface",
|
2010-03-04 17:39:01 +00:00
|
|
|
0, G_MAXINT32, 0,
|
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class,
|
|
|
|
PROP_HEIGHT,
|
|
|
|
g_param_spec_uint("height",
|
2010-03-19 15:45:21 +00:00
|
|
|
"Height",
|
|
|
|
"The height of the surface",
|
2010-03-04 17:39:01 +00:00
|
|
|
0, G_MAXINT32, 0,
|
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
|
|
|
g_object_class_install_property
|
|
|
|
(object_class,
|
2010-03-11 13:58:32 +00:00
|
|
|
PROP_CHROMA_TYPE,
|
|
|
|
g_param_spec_uint("chroma-type",
|
2010-03-19 15:45:21 +00:00
|
|
|
"Chroma type",
|
|
|
|
"The chroma type of the surface",
|
2010-03-04 17:39:01 +00:00
|
|
|
0, G_MAXUINT32, 0,
|
|
|
|
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_surface_init(GstVaapiSurface *surface)
|
|
|
|
{
|
|
|
|
GstVaapiSurfacePrivate *priv = GST_VAAPI_SURFACE_GET_PRIVATE(surface);
|
|
|
|
|
|
|
|
surface->priv = priv;
|
|
|
|
priv->width = 0;
|
|
|
|
priv->height = 0;
|
2010-03-17 07:59:31 +00:00
|
|
|
priv->chroma_type = 0;
|
2010-03-23 10:36:20 +00:00
|
|
|
priv->subpictures = NULL;
|
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
|
|
|
{
|
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
|
|
|
|
|
|
|
return g_object_new(GST_VAAPI_TYPE_SURFACE,
|
2010-03-11 13:58:32 +00:00
|
|
|
"display", display,
|
2010-03-24 17:38:23 +00:00
|
|
|
"id", GST_VAAPI_ID(VA_INVALID_ID),
|
2010-03-11 13:58:32 +00:00
|
|
|
"width", width,
|
|
|
|
"height", height,
|
|
|
|
"chroma-type", chroma_type,
|
2010-03-04 17:39:01 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), VA_INVALID_SURFACE);
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), 0);
|
|
|
|
|
2010-03-11 13:58:32 +00:00
|
|
|
return surface->priv->chroma_type;
|
2010-03-04 17:39:01 +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
|
2010-03-11 13:58:32 +00:00
|
|
|
gst_vaapi_surface_get_width(GstVaapiSurface *surface)
|
2010-03-04 17:39:01 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), 0);
|
|
|
|
|
2010-03-11 13:58:32 +00:00
|
|
|
return surface->priv->width;
|
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
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), 0);
|
|
|
|
|
2010-03-11 13:58:32 +00:00
|
|
|
return surface->priv->height;
|
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
|
|
|
|
)
|
|
|
|
{
|
|
|
|
g_return_if_fail(GST_VAAPI_IS_SURFACE(surface));
|
|
|
|
|
|
|
|
if (pwidth)
|
|
|
|
*pwidth = gst_vaapi_surface_get_width(surface);
|
|
|
|
|
|
|
|
if (pheight)
|
|
|
|
*pheight = gst_vaapi_surface_get_height(surface);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
* g_object_unref().
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
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;
|
|
|
|
|
2010-03-15 11:49:03 +00:00
|
|
|
gst_vaapi_image_get_size(image, &width, &height);
|
|
|
|
if (width != surface->priv->width || height != surface->priv->height)
|
|
|
|
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;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
|
|
|
|
|
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;
|
|
|
|
|
2010-03-15 11:49:03 +00:00
|
|
|
gst_vaapi_image_get_size(image, &width, &height);
|
|
|
|
if (width != surface->priv->width || height != surface->priv->height)
|
|
|
|
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
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SUBPICTURE(subpicture), FALSE);
|
|
|
|
|
|
|
|
if (!gst_vaapi_surface_deassociate_subpicture(surface, subpicture))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!surface->priv->subpictures) {
|
|
|
|
surface->priv->subpictures = g_ptr_array_new();
|
|
|
|
if (!surface->priv->subpictures)
|
|
|
|
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;
|
|
|
|
|
|
|
|
g_ptr_array_add(surface->priv->subpictures, g_object_ref(subpicture));
|
|
|
|
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;
|
|
|
|
gst_vaapi_image_get_size(
|
|
|
|
image,
|
|
|
|
&src_rect_default.width,
|
|
|
|
&src_rect_default.height
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dst_rect) {
|
|
|
|
dst_rect = &dst_rect_default;
|
|
|
|
dst_rect_default.x = 0;
|
|
|
|
dst_rect_default.y = 0;
|
|
|
|
dst_rect_default.width = surface->priv->width;
|
|
|
|
dst_rect_default.height = surface->priv->height;
|
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
0
|
|
|
|
);
|
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
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SUBPICTURE(subpicture), FALSE);
|
|
|
|
|
|
|
|
if (!surface->priv->subpictures)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* First, check subpicture was really associated with this surface */
|
|
|
|
if (!g_ptr_array_remove_fast(surface->priv->subpictures, subpicture)) {
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_DEBUG("subpicture %" GST_VAAPI_ID_FORMAT "was not bound to "
|
|
|
|
"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);
|
|
|
|
g_object_unref(subpicture);
|
|
|
|
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;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|