Make GstVaapi{Surface,Image,Subpicture} derive from a GstVaapiObject.

This commit is contained in:
gb 2010-03-23 16:21:28 +00:00
parent 62df0f9b1c
commit 2155318d12
12 changed files with 358 additions and 154 deletions

View file

@ -16,6 +16,7 @@
<xi:include href="xml/gstvaapidisplay_x11.xml"/>
<xi:include href="xml/gstvaapiwindow.xml"/>
<xi:include href="xml/gstvaapiwindow_x11.xml"/>
<xi:include href="xml/gstvaapiobject.xml"/>
<xi:include href="xml/gstvaapisurface.xml"/>
<xi:include href="xml/gstvaapiimage.xml"/>
<xi:include href="xml/gstvaapiimageformat.xml"/>

View file

@ -189,6 +189,22 @@ GST_VAAPI_IS_WINDOW_CLASS
GST_VAAPI_WINDOW_GET_CLASS
</SECTION>
<SECTION>
<FILE>gstvaapiobject</FILE>
<TITLE>GstVaapiObject</TITLE>
GstVaapiObject
GstVaapiObjectClass
gst_vaapi_object_get_display
<SUBSECTION Standard>
GST_VAAPI_OBJECT
GST_VAAPI_IS_OBJECT
GST_VAAPI_TYPE_OBJECT
gst_vaapi_object_get_type
GST_VAAPI_OBJECT_CLASS
GST_VAAPI_IS_OBJECT_CLASS
GST_VAAPI_OBJECT_GET_CLASS
</SECTION>
<SECTION>
<FILE>gstvaapiimage</FILE>
GST_VAAPI_IMAGE_FORMAT
@ -201,7 +217,6 @@ gst_vaapi_image_new
gst_vaapi_image_new_with_image
gst_vaapi_image_get_id
gst_vaapi_image_get_image
gst_vaapi_image_get_display
gst_vaapi_image_get_format
gst_vaapi_image_get_width
gst_vaapi_image_get_height
@ -234,7 +249,6 @@ GstVaapiSurface
GstVaapiSurfaceClass
gst_vaapi_surface_new
gst_vaapi_surface_get_id
gst_vaapi_surface_get_display
gst_vaapi_surface_get_chroma_type
gst_vaapi_surface_get_width
gst_vaapi_surface_get_height

View file

@ -11,6 +11,7 @@ libgstvaapi_source_c = \
gstvaapiimage.c \
gstvaapiimageformat.c \
gstvaapiimagepool.c \
gstvaapiobject.c \
gstvaapisubpicture.c \
gstvaapisurface.c \
gstvaapisurfacepool.c \
@ -26,6 +27,7 @@ libgstvaapi_source_h = \
gstvaapiimage.h \
gstvaapiimageformat.h \
gstvaapiimagepool.h \
gstvaapiobject.h \
gstvaapisubpicture.h \
gstvaapisurface.h \
gstvaapisurfacepool.h \

View file

@ -32,7 +32,7 @@
#define DEBUG 1
#include "gstvaapidebug.h"
G_DEFINE_TYPE(GstVaapiImage, gst_vaapi_image, G_TYPE_OBJECT);
G_DEFINE_TYPE(GstVaapiImage, gst_vaapi_image, GST_VAAPI_TYPE_OBJECT);
#define GST_VAAPI_IMAGE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
@ -40,7 +40,6 @@ G_DEFINE_TYPE(GstVaapiImage, gst_vaapi_image, G_TYPE_OBJECT);
GstVaapiImagePrivate))
struct _GstVaapiImagePrivate {
GstVaapiDisplay *display;
VAImage internal_image;
VAImage image;
guchar *image_data;
@ -56,7 +55,6 @@ struct _GstVaapiImagePrivate {
enum {
PROP_0,
PROP_DISPLAY,
PROP_IMAGE,
PROP_IMAGE_ID,
PROP_FORMAT,
@ -148,6 +146,7 @@ vaapi_image_is_linear(const VAImage *va_image)
static void
gst_vaapi_image_destroy(GstVaapiImage *image)
{
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_GET_DISPLAY(image);
GstVaapiImagePrivate * const priv = image->priv;
VAStatus status;
@ -156,47 +155,43 @@ gst_vaapi_image_destroy(GstVaapiImage *image)
GST_DEBUG("image 0x%08x", priv->internal_image.image_id);
if (priv->internal_image.image_id != VA_INVALID_ID) {
GST_VAAPI_DISPLAY_LOCK(priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaDestroyImage(
GST_VAAPI_DISPLAY_VADISPLAY(priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
priv->internal_image.image_id
);
GST_VAAPI_DISPLAY_UNLOCK(priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaDestroyImage()"))
g_warning("failed to destroy image 0x%08x\n",
priv->internal_image.image_id);
priv->internal_image.image_id = VA_INVALID_ID;
}
if (priv->display) {
g_object_unref(priv->display);
priv->display = NULL;
}
}
static gboolean
_gst_vaapi_image_create(GstVaapiImage *image, GstVaapiImageFormat format)
{
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_GET_DISPLAY(image);
GstVaapiImagePrivate * const priv = image->priv;
const VAImageFormat *va_format;
VAStatus status;
if (!gst_vaapi_display_has_image_format(priv->display, format))
if (!gst_vaapi_display_has_image_format(display, format))
return FALSE;
va_format = gst_vaapi_image_format_get_va_format(format);
if (!va_format)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaCreateImage(
GST_VAAPI_DISPLAY_VADISPLAY(priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
(VAImageFormat *)va_format,
priv->width,
priv->height,
&priv->internal_image
);
GST_VAAPI_DISPLAY_UNLOCK(priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (status != VA_STATUS_SUCCESS ||
priv->internal_image.format.fourcc != va_format->fourcc)
return FALSE;
@ -274,9 +269,6 @@ gst_vaapi_image_set_property(
GstVaapiImagePrivate * const priv = image->priv;
switch (prop_id) {
case PROP_DISPLAY:
priv->display = g_object_ref(g_value_get_object(value));
break;
case PROP_IMAGE: {
const VAImage * const va_image = g_value_get_boxed(value);
if (va_image)
@ -309,9 +301,6 @@ gst_vaapi_image_get_property(
GstVaapiImage * const image = GST_VAAPI_IMAGE(object);
switch (prop_id) {
case PROP_DISPLAY:
g_value_set_pointer(value, gst_vaapi_image_get_display(image));
break;
case PROP_IMAGE:
g_value_set_boxed(value, &image->priv->image);
break;
@ -358,20 +347,6 @@ gst_vaapi_image_class_init(GstVaapiImageClass *klass)
object_class->get_property = gst_vaapi_image_get_property;
object_class->constructed = gst_vaapi_image_constructed;
/**
* GstVaapiImage:display:
*
* The #GstVaapiDisplay this image is bound to.
*/
g_object_class_install_property
(object_class,
PROP_DISPLAY,
g_param_spec_object("display",
"Display",
"The GstVaapiDisplay this image is bound to",
GST_VAAPI_TYPE_DISPLAY,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property
(object_class,
PROP_IMAGE,
@ -434,7 +409,6 @@ gst_vaapi_image_init(GstVaapiImage *image)
GstVaapiImagePrivate *priv = GST_VAAPI_IMAGE_GET_PRIVATE(image);
image->priv = priv;
priv->display = NULL;
priv->image_data = NULL;
priv->width = 0;
priv->height = 0;
@ -650,23 +624,6 @@ _gst_vaapi_image_set_image(GstVaapiImage *image, const VAImage *va_image)
return TRUE;
}
/**
* gst_vaapi_image_get_display:
* @image: a #GstVaapiImage
*
* Returns the #GstVaapiDisplay this @image is bound to.
*
* Return value: the parent #GstVaapiDisplay object
*/
GstVaapiDisplay *
gst_vaapi_image_get_display(GstVaapiImage *image)
{
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), NULL);
g_return_val_if_fail(image->priv->is_constructed, FALSE);
return image->priv->display;
}
/**
* gst_vaapi_image_get_format:
* @image: a #GstVaapiImage
@ -802,19 +759,24 @@ gst_vaapi_image_map(GstVaapiImage *image)
gboolean
_gst_vaapi_image_map(GstVaapiImage *image)
{
GstVaapiDisplay *display;
void *image_data;
VAStatus status;
if (_gst_vaapi_image_is_mapped(image))
return TRUE;
GST_VAAPI_DISPLAY_LOCK(image->priv->display);
display = GST_VAAPI_OBJECT_GET_DISPLAY(image);
if (!display)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaMapBuffer(
GST_VAAPI_DISPLAY_VADISPLAY(image->priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
image->priv->image.buf,
&image_data
);
GST_VAAPI_DISPLAY_UNLOCK(image->priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaMapBuffer()"))
return FALSE;
@ -843,17 +805,22 @@ gst_vaapi_image_unmap(GstVaapiImage *image)
gboolean
_gst_vaapi_image_unmap(GstVaapiImage *image)
{
GstVaapiDisplay *display;
VAStatus status;
if (!_gst_vaapi_image_is_mapped(image))
return FALSE;
GST_VAAPI_DISPLAY_LOCK(image->priv->display);
display = GST_VAAPI_OBJECT_GET_DISPLAY(image);
if (!display)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaUnmapBuffer(
GST_VAAPI_DISPLAY_VADISPLAY(image->priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
image->priv->image.buf
);
GST_VAAPI_DISPLAY_UNLOCK(image->priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaUnmapBuffer()"))
return FALSE;

View file

@ -22,6 +22,7 @@
#define GST_VAAPI_IMAGE_H
#include <gst/gstbuffer.h>
#include <gst/vaapi/gstvaapiobject.h>
#include <gst/vaapi/gstvaapidisplay.h>
#include <gst/vaapi/gstvaapiimageformat.h>
@ -86,7 +87,7 @@ typedef struct _GstVaapiImageClass GstVaapiImageClass;
*/
struct _GstVaapiImage {
/*< private >*/
GObject parent_instance;
GstVaapiObject parent_instance;
GstVaapiImagePrivate *priv;
};
@ -98,7 +99,7 @@ struct _GstVaapiImage {
*/
struct _GstVaapiImageClass {
/*< private >*/
GObjectClass parent_class;
GstVaapiObjectClass parent_class;
};
GType
@ -121,9 +122,6 @@ gst_vaapi_image_get_id(GstVaapiImage *image);
gboolean
gst_vaapi_image_get_image(GstVaapiImage *image, VAImage *va_image);
GstVaapiDisplay *
gst_vaapi_image_get_display(GstVaapiImage *image);
GstVaapiImageFormat
gst_vaapi_image_get_format(GstVaapiImage *image);

View file

@ -0,0 +1,147 @@
/*
* gstvaapiobject.c - Base VA object
*
* 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
*/
#include "config.h"
#include "gstvaapiobject.h"
#define DEBUG 1
#include "gstvaapidebug.h"
G_DEFINE_TYPE(GstVaapiObject, gst_vaapi_object, G_TYPE_OBJECT);
#define GST_VAAPI_OBJECT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
GST_VAAPI_TYPE_OBJECT, \
GstVaapiObjectPrivate))
struct _GstVaapiObjectPrivate {
GstVaapiDisplay *display;
};
enum {
PROP_0,
PROP_DISPLAY,
};
static void
gst_vaapi_object_finalize(GObject *object)
{
GstVaapiObjectPrivate * const priv = GST_VAAPI_OBJECT(object)->priv;
if (priv->display) {
g_object_unref(priv->display);
priv->display = NULL;
}
G_OBJECT_CLASS(gst_vaapi_object_parent_class)->finalize(object);
}
static void
gst_vaapi_object_set_property(
GObject *gobject,
guint prop_id,
const GValue *value,
GParamSpec *pspec
)
{
GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);
switch (prop_id) {
case PROP_DISPLAY:
object->priv->display = g_object_ref(g_value_get_object(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
break;
}
}
static void
gst_vaapi_object_get_property(
GObject *gobject,
guint prop_id,
GValue *value,
GParamSpec *pspec
)
{
GstVaapiObject * const object = GST_VAAPI_OBJECT(gobject);
switch (prop_id) {
case PROP_DISPLAY:
g_value_set_object(value, gst_vaapi_object_get_display(object));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(gobject, prop_id, pspec);
break;
}
}
static void
gst_vaapi_object_class_init(GstVaapiObjectClass *klass)
{
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
g_type_class_add_private(klass, sizeof(GstVaapiObjectPrivate));
object_class->finalize = gst_vaapi_object_finalize;
object_class->set_property = gst_vaapi_object_set_property;
object_class->get_property = gst_vaapi_object_get_property;
/**
* GstVaapiObject:display:
*
* The #GstVaapiDisplay this object is bound to.
*/
g_object_class_install_property
(object_class,
PROP_DISPLAY,
g_param_spec_object("display",
"Display",
"The GstVaapiDisplay this object is bound to",
GST_VAAPI_TYPE_DISPLAY,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
}
static void
gst_vaapi_object_init(GstVaapiObject *object)
{
GstVaapiObjectPrivate *priv = GST_VAAPI_OBJECT_GET_PRIVATE(object);
object->priv = priv;
priv->display = NULL;
}
/**
* gst_vaapi_object_get_display:
* @object: a #GstVaapiObject
*
* Returns the #GstVaapiDisplay this @object is bound to.
*
* Return value: the parent #GstVaapiDisplay object
*/
GstVaapiDisplay *
gst_vaapi_object_get_display(GstVaapiObject *object)
{
g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), NULL);
return object->priv->display;
}

View file

@ -0,0 +1,96 @@
/*
* gstvaapiobject.h - Base VA object
*
* 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
*/
#ifndef GST_VAAPI_OBJECT_H
#define GST_VAAPI_OBJECT_H
#include <gst/vaapi/gstvaapitypes.h>
#include <gst/vaapi/gstvaapidisplay.h>
G_BEGIN_DECLS
#define GST_VAAPI_TYPE_OBJECT \
(gst_vaapi_object_get_type())
#define GST_VAAPI_OBJECT(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
GST_VAAPI_TYPE_OBJECT, \
GstVaapiObject))
#define GST_VAAPI_OBJECT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
GST_VAAPI_TYPE_OBJECT, \
GstVaapiObjectClass))
#define GST_VAAPI_IS_OBJECT(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_OBJECT))
#define GST_VAAPI_IS_OBJECT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_OBJECT))
#define GST_VAAPI_OBJECT_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS((obj), \
GST_VAAPI_TYPE_OBJECT, \
GstVaapiObjectClass))
/**
* GST_VAAPI_OBJECT_GET_DISPLAY:
* @object: a #GstVaapiObject
*
* Macro that evaluates to the #GstVaapiDisplay @object is bound to.
*/
#define GST_VAAPI_OBJECT_GET_DISPLAY(object) \
gst_vaapi_object_get_display(GST_VAAPI_OBJECT(object))
typedef struct _GstVaapiObject GstVaapiObject;
typedef struct _GstVaapiObjectPrivate GstVaapiObjectPrivate;
typedef struct _GstVaapiObjectClass GstVaapiObjectClass;
/**
* GstVaapiObject:
*
* VA object base.
*/
struct _GstVaapiObject {
/*< private >*/
GObject parent_instance;
GstVaapiObjectPrivate *priv;
};
/**
* GstVaapiObjectClass:
*
* VA object base class.
*/
struct _GstVaapiObjectClass {
/*< private >*/
GObjectClass parent_class;
};
GType
gst_vaapi_object_get_type(void);
GstVaapiDisplay *
gst_vaapi_object_get_display(GstVaapiObject *object);
G_END_DECLS
#endif /* GST_VAAPI_OBJECT_H */

View file

@ -32,7 +32,7 @@
#define DEBUG 1
#include "gstvaapidebug.h"
G_DEFINE_TYPE(GstVaapiSubpicture, gst_vaapi_subpicture, G_TYPE_OBJECT);
G_DEFINE_TYPE(GstVaapiSubpicture, gst_vaapi_subpicture, GST_VAAPI_TYPE_OBJECT);
#define GST_VAAPI_SUBPICTURE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
@ -54,14 +54,13 @@ enum {
static void
gst_vaapi_subpicture_destroy(GstVaapiSubpicture *subpicture)
{
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_GET_DISPLAY(subpicture);
GstVaapiSubpicturePrivate * const priv = subpicture->priv;
GstVaapiDisplay *display;
VAStatus status;
GST_DEBUG("subpicture 0x%08x", priv->subpicture_id);
if (priv->subpicture_id != VA_INVALID_ID) {
display = gst_vaapi_image_get_display(priv->image);
if (display) {
GST_VAAPI_DISPLAY_LOCK(display);
status = vaDestroySubpicture(
@ -85,18 +84,14 @@ gst_vaapi_subpicture_destroy(GstVaapiSubpicture *subpicture)
static gboolean
gst_vaapi_subpicture_create(GstVaapiSubpicture *subpicture)
{
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_GET_DISPLAY(subpicture);
GstVaapiSubpicturePrivate * const priv = subpicture->priv;
GstVaapiDisplay *display;
VASubpictureID subpicture_id;
VAStatus status;
if (!priv->image)
return FALSE;
display = gst_vaapi_image_get_display(priv->image);
if (!display)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaCreateSubpicture(
GST_VAAPI_DISPLAY_VADISPLAY(display),
@ -230,7 +225,8 @@ gst_vaapi_subpicture_new(GstVaapiImage *image)
GST_DEBUG("create from image 0x%08x", gst_vaapi_image_get_id(image));
return g_object_new(GST_VAAPI_TYPE_SUBPICTURE,
"image", image,
"display", GST_VAAPI_OBJECT_GET_DISPLAY(image),
"image", image,
NULL);
}

View file

@ -21,6 +21,7 @@
#ifndef GST_VAAPI_SUBPICTURE_H
#define GST_VAAPI_SUBPICTURE_H
#include <gst/vaapi/gstvaapiobject.h>
#include <gst/vaapi/gstvaapidisplay.h>
#include <gst/vaapi/gstvaapiimage.h>
@ -61,7 +62,7 @@ typedef struct _GstVaapiSubpictureClass GstVaapiSubpictureClass;
*/
struct _GstVaapiSubpicture {
/*< private >*/
GObject parent_instance;
GstVaapiObject parent_instance;
GstVaapiSubpicturePrivate *priv;
};
@ -73,7 +74,7 @@ struct _GstVaapiSubpicture {
*/
struct _GstVaapiSubpictureClass {
/*< private >*/
GObjectClass parent_class;
GstVaapiObjectClass parent_class;
};
GType

View file

@ -32,7 +32,7 @@
#define DEBUG 1
#include "gstvaapidebug.h"
G_DEFINE_TYPE(GstVaapiSurface, gst_vaapi_surface, G_TYPE_OBJECT);
G_DEFINE_TYPE(GstVaapiSurface, gst_vaapi_surface, GST_VAAPI_TYPE_OBJECT);
#define GST_VAAPI_SURFACE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
@ -40,7 +40,6 @@ G_DEFINE_TYPE(GstVaapiSurface, gst_vaapi_surface, G_TYPE_OBJECT);
GstVaapiSurfacePrivate))
struct _GstVaapiSurfacePrivate {
GstVaapiDisplay *display;
VASurfaceID surface_id;
guint width;
guint height;
@ -51,7 +50,6 @@ struct _GstVaapiSurfacePrivate {
enum {
PROP_0,
PROP_DISPLAY,
PROP_SURFACE_ID,
PROP_WIDTH,
PROP_HEIGHT,
@ -67,18 +65,19 @@ destroy_subpicture_cb(gpointer subpicture, gpointer user_data)
static void
gst_vaapi_surface_destroy(GstVaapiSurface *surface)
{
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
GstVaapiSurfacePrivate * const priv = surface->priv;
VAStatus status;
GST_DEBUG("surface 0x%08x", priv->surface_id);
if (priv->surface_id != VA_INVALID_SURFACE) {
GST_VAAPI_DISPLAY_LOCK(priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaDestroySurfaces(
GST_VAAPI_DISPLAY_VADISPLAY(priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
&priv->surface_id, 1
);
GST_VAAPI_DISPLAY_UNLOCK(priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaDestroySurfaces()"))
g_warning("failed to destroy surface 0x%08x\n", priv->surface_id);
priv->surface_id = VA_INVALID_SURFACE;
@ -89,16 +88,12 @@ gst_vaapi_surface_destroy(GstVaapiSurface *surface)
g_ptr_array_free(priv->subpictures, TRUE);
priv->subpictures = NULL;
}
if (priv->display) {
g_object_unref(priv->display);
priv->display = NULL;
}
}
static gboolean
gst_vaapi_surface_create(GstVaapiSurface *surface)
{
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
GstVaapiSurfacePrivate * const priv = surface->priv;
VASurfaceID surface_id;
VAStatus status;
@ -119,15 +114,15 @@ gst_vaapi_surface_create(GstVaapiSurface *surface)
return FALSE;
}
GST_VAAPI_DISPLAY_LOCK(priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaCreateSurfaces(
GST_VAAPI_DISPLAY_VADISPLAY(priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
priv->width,
priv->height,
format,
1, &surface_id
);
GST_VAAPI_DISPLAY_UNLOCK(priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaCreateSurfaces()"))
return FALSE;
@ -156,9 +151,6 @@ gst_vaapi_surface_set_property(
GstVaapiSurfacePrivate * const priv = surface->priv;
switch (prop_id) {
case PROP_DISPLAY:
priv->display = g_object_ref(g_value_get_object(value));
break;
case PROP_WIDTH:
priv->width = g_value_get_uint(value);
break;
@ -185,9 +177,6 @@ gst_vaapi_surface_get_property(
GstVaapiSurface * const surface = GST_VAAPI_SURFACE(object);
switch (prop_id) {
case PROP_DISPLAY:
g_value_set_object(value, gst_vaapi_surface_get_display(surface));
break;
case PROP_SURFACE_ID:
g_value_set_uint(value, gst_vaapi_surface_get_id(surface));
break;
@ -231,20 +220,6 @@ gst_vaapi_surface_class_init(GstVaapiSurfaceClass *klass)
object_class->get_property = gst_vaapi_surface_get_property;
object_class->constructed = gst_vaapi_surface_constructed;
/**
* GstVaapiSurface:display:
*
* The #GstVaapiDisplay this surface is bound to.
*/
g_object_class_install_property
(object_class,
PROP_DISPLAY,
g_param_spec_object("display",
"Display",
"The GstVaapiDisplay this surface is bound to",
GST_VAAPI_TYPE_DISPLAY,
G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
/**
* GstVaapiSurface:id:
*
@ -293,7 +268,6 @@ gst_vaapi_surface_init(GstVaapiSurface *surface)
GstVaapiSurfacePrivate *priv = GST_VAAPI_SURFACE_GET_PRIVATE(surface);
surface->priv = priv;
priv->display = NULL;
priv->surface_id = VA_INVALID_SURFACE;
priv->width = 0;
priv->height = 0;
@ -347,22 +321,6 @@ gst_vaapi_surface_get_id(GstVaapiSurface *surface)
return surface->priv->surface_id;
}
/**
* 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(GST_VAAPI_IS_SURFACE(surface), NULL);
return surface->priv->display;
}
/**
* gst_vaapi_surface_get_chroma_type:
* @surface: a #GstVaapiSurface
@ -462,27 +420,29 @@ gst_vaapi_surface_get_size(
GstVaapiImage *
gst_vaapi_surface_derive_image(GstVaapiSurface *surface)
{
GstVaapiDisplay *display;
VAImage va_image;
VAStatus status;
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), NULL);
display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
va_image.image_id = VA_INVALID_ID;
va_image.buf = VA_INVALID_ID;
GST_VAAPI_DISPLAY_LOCK(surface->priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaDeriveImage(
GST_VAAPI_DISPLAY_VADISPLAY(surface->priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
surface->priv->surface_id,
&va_image
);
GST_VAAPI_DISPLAY_UNLOCK(surface->priv->display);
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;
return gst_vaapi_image_new_with_image(surface->priv->display, &va_image);
return gst_vaapi_image_new_with_image(display, &va_image);
}
/**
@ -498,6 +458,7 @@ gst_vaapi_surface_derive_image(GstVaapiSurface *surface)
gboolean
gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image)
{
GstVaapiDisplay *display;
VAImageID image_id;
VAStatus status;
guint width, height;
@ -505,6 +466,10 @@ gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image)
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
if (!display)
return FALSE;
gst_vaapi_image_get_size(image, &width, &height);
if (width != surface->priv->width || height != surface->priv->height)
return FALSE;
@ -513,14 +478,14 @@ gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image)
if (image_id == VA_INVALID_ID)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(surface->priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaGetImage(
GST_VAAPI_DISPLAY_VADISPLAY(surface->priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
surface->priv->surface_id,
0, 0, width, height,
image_id
);
GST_VAAPI_DISPLAY_UNLOCK(surface->priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaGetImage()"))
return FALSE;
@ -540,6 +505,7 @@ gst_vaapi_surface_get_image(GstVaapiSurface *surface, GstVaapiImage *image)
gboolean
gst_vaapi_surface_put_image(GstVaapiSurface *surface, GstVaapiImage *image)
{
GstVaapiDisplay *display;
VAImageID image_id;
VAStatus status;
guint width, height;
@ -547,6 +513,10 @@ gst_vaapi_surface_put_image(GstVaapiSurface *surface, GstVaapiImage *image)
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), FALSE);
display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
if (!display)
return FALSE;
gst_vaapi_image_get_size(image, &width, &height);
if (width != surface->priv->width || height != surface->priv->height)
return FALSE;
@ -555,15 +525,15 @@ gst_vaapi_surface_put_image(GstVaapiSurface *surface, GstVaapiImage *image)
if (image_id == VA_INVALID_ID)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(surface->priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaPutImage(
GST_VAAPI_DISPLAY_VADISPLAY(surface->priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
surface->priv->surface_id,
image_id,
0, 0, width, height,
0, 0, width, height
);
GST_VAAPI_DISPLAY_UNLOCK(surface->priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaPutImage()"))
return FALSE;
@ -596,6 +566,7 @@ gst_vaapi_surface_associate_subpicture(
const GstVaapiRectangle *dst_rect
)
{
GstVaapiDisplay *display;
GstVaapiRectangle src_rect_default, dst_rect_default;
GstVaapiImage *image;
VAStatus status;
@ -603,6 +574,10 @@ gst_vaapi_surface_associate_subpicture(
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
g_return_val_if_fail(GST_VAAPI_IS_SUBPICTURE(subpicture), FALSE);
display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
if (!display)
return FALSE;
if (!gst_vaapi_surface_deassociate_subpicture(surface, subpicture))
return FALSE;
@ -634,16 +609,16 @@ gst_vaapi_surface_associate_subpicture(
dst_rect_default.height = surface->priv->height;
}
GST_VAAPI_DISPLAY_LOCK(surface->priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaAssociateSubpicture(
GST_VAAPI_DISPLAY_VADISPLAY(surface->priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
gst_vaapi_subpicture_get_id(subpicture),
&surface->priv->surface_id, 1,
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
);
GST_VAAPI_DISPLAY_UNLOCK(surface->priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaAssociateSubpicture()"))
return FALSE;
@ -666,11 +641,16 @@ gst_vaapi_surface_deassociate_subpicture(
GstVaapiSubpicture *subpicture
)
{
GstVaapiDisplay *display;
VAStatus status;
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
g_return_val_if_fail(GST_VAAPI_IS_SUBPICTURE(subpicture), FALSE);
display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
if (!display)
return FALSE;
if (!surface->priv->subpictures)
return TRUE;
@ -682,13 +662,13 @@ gst_vaapi_surface_deassociate_subpicture(
return TRUE;
}
GST_VAAPI_DISPLAY_LOCK(surface->priv->display);
GST_VAAPI_DISPLAY_LOCK(display);
status = vaDeassociateSubpicture(
GST_VAAPI_DISPLAY_VADISPLAY(surface->priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
gst_vaapi_subpicture_get_id(subpicture),
&surface->priv->surface_id, 1
);
GST_VAAPI_DISPLAY_UNLOCK(surface->priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
g_object_unref(subpicture);
if (!vaapi_check_status(status, "vaDeassociateSubpicture()"))
return FALSE;
@ -707,16 +687,21 @@ gst_vaapi_surface_deassociate_subpicture(
gboolean
gst_vaapi_surface_sync(GstVaapiSurface *surface)
{
GstVaapiDisplay *display;
VAStatus status;
g_return_val_if_fail(GST_VAAPI_IS_SURFACE(surface), FALSE);
GST_VAAPI_DISPLAY_LOCK(surface->priv->display);
display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
if (!display)
return FALSE;
GST_VAAPI_DISPLAY_LOCK(display);
status = vaSyncSurface(
GST_VAAPI_DISPLAY_VADISPLAY(surface->priv->display),
GST_VAAPI_DISPLAY_VADISPLAY(display),
surface->priv->surface_id
);
GST_VAAPI_DISPLAY_UNLOCK(surface->priv->display);
GST_VAAPI_DISPLAY_UNLOCK(display);
if (!vaapi_check_status(status, "vaSyncSurface()"))
return FALSE;

View file

@ -21,7 +21,7 @@
#ifndef GST_VAAPI_SURFACE_H
#define GST_VAAPI_SURFACE_H
#include <gst/vaapi/gstvaapitypes.h>
#include <gst/vaapi/gstvaapiobject.h>
#include <gst/vaapi/gstvaapidisplay.h>
#include <gst/vaapi/gstvaapiimage.h>
#include <gst/vaapi/gstvaapisubpicture.h>
@ -107,7 +107,7 @@ typedef struct _GstVaapiSurfaceClass GstVaapiSurfaceClass;
*/
struct _GstVaapiSurface {
/*< private >*/
GObject parent_instance;
GstVaapiObject parent_instance;
GstVaapiSurfacePrivate *priv;
};
@ -119,7 +119,7 @@ struct _GstVaapiSurface {
*/
struct _GstVaapiSurfaceClass {
/*< private >*/
GObjectClass parent_class;
GstVaapiObjectClass parent_class;
};
GType
@ -136,9 +136,6 @@ gst_vaapi_surface_new(
VASurfaceID
gst_vaapi_surface_get_id(GstVaapiSurface *surface);
GstVaapiDisplay *
gst_vaapi_surface_get_display(GstVaapiSurface *surface);
GstVaapiChromaType
gst_vaapi_surface_get_chroma_type(GstVaapiSurface *surface);

View file

@ -399,7 +399,7 @@ gst_vaapi_window_x11_render(
VASurfaceID surface_id;
VAStatus status;
display = gst_vaapi_surface_get_display(surface);
display = GST_VAAPI_OBJECT_GET_DISPLAY(surface);
if (!display)
return FALSE;