2010-03-04 17:39:58 +00:00
|
|
|
/*
|
|
|
|
* gstvaapisubpicture.c - VA subpicture 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:gstvaapisubpicture
|
|
|
|
* @short_description: VA subpicture abstraction
|
2010-03-19 15:45:21 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-04 17:39:58 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include <string.h>
|
2010-03-16 09:15:48 +00:00
|
|
|
#include "gstvaapiutils.h"
|
2010-03-04 17:39:58 +00:00
|
|
|
#include "gstvaapisubpicture.h"
|
2010-03-24 08:32:12 +00:00
|
|
|
#include "gstvaapiobject_priv.h"
|
2010-03-04 17:39:58 +00:00
|
|
|
|
|
|
|
#define DEBUG 1
|
2010-03-16 09:17:41 +00:00
|
|
|
#include "gstvaapidebug.h"
|
2010-03-04 17:39:58 +00:00
|
|
|
|
2010-03-23 16:21:28 +00:00
|
|
|
G_DEFINE_TYPE(GstVaapiSubpicture, gst_vaapi_subpicture, GST_VAAPI_TYPE_OBJECT);
|
2010-03-04 17:39:58 +00:00
|
|
|
|
|
|
|
#define GST_VAAPI_SUBPICTURE_GET_PRIVATE(obj) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
|
|
|
|
GST_VAAPI_TYPE_SUBPICTURE, \
|
|
|
|
GstVaapiSubpicturePrivate))
|
|
|
|
|
|
|
|
struct _GstVaapiSubpicturePrivate {
|
|
|
|
GstVaapiImage *image;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
|
|
|
|
PROP_IMAGE
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_subpicture_destroy(GstVaapiSubpicture *subpicture)
|
|
|
|
{
|
2010-03-23 16:21:28 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_GET_DISPLAY(subpicture);
|
2010-03-04 17:39:58 +00:00
|
|
|
GstVaapiSubpicturePrivate * const priv = subpicture->priv;
|
2010-03-24 13:19:58 +00:00
|
|
|
VASubpictureID subpicture_id;
|
2010-03-04 17:39:58 +00:00
|
|
|
VAStatus status;
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
subpicture_id = GST_VAAPI_OBJECT_ID(subpicture);
|
|
|
|
GST_DEBUG("subpicture %" GST_VAAPI_ID_FORMAT,
|
|
|
|
GST_VAAPI_ID_ARGS(subpicture_id));
|
2010-03-23 10:49:33 +00:00
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
if (subpicture_id != VA_INVALID_ID) {
|
2010-03-04 17:39:58 +00:00
|
|
|
if (display) {
|
2010-03-17 07:59:31 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-04 17:39:58 +00:00
|
|
|
status = vaDestroySubpicture(
|
2010-03-17 07:59:31 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
subpicture_id
|
2010-03-04 17:39:58 +00:00
|
|
|
);
|
2010-03-17 07:59:31 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-04 17:39:58 +00:00
|
|
|
if (!vaapi_check_status(status, "vaDestroySubpicture()"))
|
2010-03-24 13:19:58 +00:00
|
|
|
g_warning("failed to destroy subpicture %" GST_VAAPI_ID_FORMAT "\n",
|
|
|
|
GST_VAAPI_ID_ARGS(subpicture_id));
|
2010-03-04 17:39:58 +00:00
|
|
|
}
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_OBJECT_ID(subpicture) = VA_INVALID_ID;
|
2010-03-04 17:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->image) {
|
|
|
|
g_object_unref(priv->image);
|
|
|
|
priv->image = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vaapi_subpicture_create(GstVaapiSubpicture *subpicture)
|
|
|
|
{
|
2010-03-23 16:21:28 +00:00
|
|
|
GstVaapiDisplay * const display = GST_VAAPI_OBJECT_GET_DISPLAY(subpicture);
|
2010-03-04 17:39:58 +00:00
|
|
|
GstVaapiSubpicturePrivate * const priv = subpicture->priv;
|
|
|
|
VASubpictureID subpicture_id;
|
|
|
|
VAStatus status;
|
|
|
|
|
|
|
|
if (!priv->image)
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-17 07:59:31 +00:00
|
|
|
GST_VAAPI_DISPLAY_LOCK(display);
|
2010-03-04 17:39:58 +00:00
|
|
|
status = vaCreateSubpicture(
|
2010-03-17 07:59:31 +00:00
|
|
|
GST_VAAPI_DISPLAY_VADISPLAY(display),
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_VAAPI_OBJECT_ID(priv->image),
|
2010-03-04 17:39:58 +00:00
|
|
|
&subpicture_id
|
|
|
|
);
|
2010-03-17 07:59:31 +00:00
|
|
|
GST_VAAPI_DISPLAY_UNLOCK(display);
|
2010-03-04 17:39:58 +00:00
|
|
|
if (!vaapi_check_status(status, "vaCreateSubpicture()"))
|
|
|
|
return FALSE;
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_DEBUG("subpicture %" GST_VAAPI_ID_FORMAT,
|
|
|
|
GST_VAAPI_ID_ARGS(subpicture_id));
|
|
|
|
GST_VAAPI_OBJECT_ID(subpicture) = subpicture_id;
|
2010-03-04 17:39:58 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_subpicture_finalize(GObject *object)
|
|
|
|
{
|
|
|
|
gst_vaapi_subpicture_destroy(GST_VAAPI_SUBPICTURE(object));
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(gst_vaapi_subpicture_parent_class)->finalize(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_subpicture_set_property(
|
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiSubpicture * const subpicture = GST_VAAPI_SUBPICTURE(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_IMAGE:
|
2010-03-10 13:10:59 +00:00
|
|
|
gst_vaapi_subpicture_set_image(subpicture, g_value_get_object(value));
|
2010-03-04 17:39:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_subpicture_get_property(
|
|
|
|
GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec
|
|
|
|
)
|
|
|
|
{
|
|
|
|
GstVaapiSubpicture * const subpicture = GST_VAAPI_SUBPICTURE(object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_IMAGE:
|
|
|
|
g_value_set_object(value, gst_vaapi_subpicture_get_image(subpicture));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_subpicture_class_init(GstVaapiSubpictureClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass * const object_class = G_OBJECT_CLASS(klass);
|
|
|
|
|
|
|
|
g_type_class_add_private(klass, sizeof(GstVaapiSubpicturePrivate));
|
|
|
|
|
|
|
|
object_class->finalize = gst_vaapi_subpicture_finalize;
|
|
|
|
object_class->set_property = gst_vaapi_subpicture_set_property;
|
|
|
|
object_class->get_property = gst_vaapi_subpicture_get_property;
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* GstVaapiSubpicture:image:
|
|
|
|
*
|
|
|
|
* The #GstVaapiImage this subpicture is bound to.
|
|
|
|
*/
|
2010-03-04 17:39:58 +00:00
|
|
|
g_object_class_install_property
|
|
|
|
(object_class,
|
|
|
|
PROP_IMAGE,
|
|
|
|
g_param_spec_object("image",
|
2010-03-19 15:45:21 +00:00
|
|
|
"Image",
|
|
|
|
"The GstVaapiImage this subpicture is bound to",
|
2010-03-04 17:39:58 +00:00
|
|
|
GST_VAAPI_TYPE_IMAGE,
|
|
|
|
G_PARAM_READWRITE));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vaapi_subpicture_init(GstVaapiSubpicture *subpicture)
|
|
|
|
{
|
|
|
|
GstVaapiSubpicturePrivate *priv = GST_VAAPI_SUBPICTURE_GET_PRIVATE(subpicture);
|
|
|
|
|
|
|
|
subpicture->priv = priv;
|
|
|
|
priv->image = NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_subpicture_new:
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiSubpicture with @image as source pixels. The
|
|
|
|
* newly created object holds a reference on @image.
|
|
|
|
*
|
|
|
|
* Return value: the newly allocated #GstVaapiSubpicture object
|
|
|
|
*/
|
2010-03-04 17:39:58 +00:00
|
|
|
GstVaapiSubpicture *
|
|
|
|
gst_vaapi_subpicture_new(GstVaapiImage *image)
|
|
|
|
{
|
2010-03-10 13:13:51 +00:00
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_IMAGE(image), NULL);
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
GST_DEBUG("create from image %" GST_VAAPI_ID_FORMAT,
|
|
|
|
GST_VAAPI_ID_ARGS(GST_VAAPI_OBJECT_ID(image)));
|
2010-03-04 17:39:58 +00:00
|
|
|
|
|
|
|
return g_object_new(GST_VAAPI_TYPE_SUBPICTURE,
|
2010-03-23 16:21:28 +00:00
|
|
|
"display", GST_VAAPI_OBJECT_GET_DISPLAY(image),
|
|
|
|
"image", image,
|
2010-03-04 17:39:58 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_subpicture_get_image:
|
|
|
|
* @subpicture: a #GstVaapiSubpicture
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiImage this @subpicture is bound to.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiImage this @subpicture is bound to
|
|
|
|
*/
|
2010-03-04 17:39:58 +00:00
|
|
|
GstVaapiImage *
|
|
|
|
gst_vaapi_subpicture_get_image(GstVaapiSubpicture *subpicture)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(GST_VAAPI_IS_SUBPICTURE(subpicture), NULL);
|
|
|
|
|
2010-03-11 12:30:12 +00:00
|
|
|
return subpicture->priv->image;
|
2010-03-04 17:39:58 +00:00
|
|
|
}
|
|
|
|
|
2010-03-19 15:45:21 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_subpicture_set_image:
|
|
|
|
* @subpicture: a #GstVaapiSubpicture
|
|
|
|
* @image: a #GstVaapiImage
|
|
|
|
*
|
|
|
|
* Binds a new #GstVaapiImage to the @subpicture. The reference to the
|
|
|
|
* previous image is released a new one acquired on @image.
|
|
|
|
*/
|
2010-03-04 17:39:58 +00:00
|
|
|
void
|
|
|
|
gst_vaapi_subpicture_set_image(
|
|
|
|
GstVaapiSubpicture *subpicture,
|
|
|
|
GstVaapiImage *image
|
|
|
|
)
|
|
|
|
{
|
|
|
|
g_return_if_fail(GST_VAAPI_IS_SUBPICTURE(subpicture));
|
|
|
|
g_return_if_fail(GST_VAAPI_IS_IMAGE(image));
|
|
|
|
|
|
|
|
gst_vaapi_subpicture_destroy(subpicture);
|
|
|
|
|
|
|
|
subpicture->priv->image = g_object_ref(image);
|
|
|
|
gst_vaapi_subpicture_create(subpicture);
|
|
|
|
}
|