2010-03-23 16:21:28 +00:00
|
|
|
/*
|
|
|
|
* gstvaapiobject.c - Base VA object
|
|
|
|
*
|
2012-01-16 09:41:10 +00:00
|
|
|
* Copyright (C) 2010-2011 Splitted-Desktop Systems
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
|
2013-11-22 05:37:12 +00:00
|
|
|
* Copyright (C) 2012-2013 Intel Corporation
|
2013-11-22 04:57:18 +00:00
|
|
|
* Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
|
2010-03-23 16:21:28 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +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-23 16:21:28 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
2010-03-23 16:21:28 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-05-03 07:07:27 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2010-03-23 16:21:28 +00:00
|
|
|
*
|
2010-05-03 07:07:27 +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-23 16:21:28 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-24 08:16:32 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstvaapiobject
|
|
|
|
* @short_description: Base VA object
|
|
|
|
*/
|
|
|
|
|
2012-01-30 17:12:59 +00:00
|
|
|
#include "sysdeps.h"
|
2010-03-23 16:21:28 +00:00
|
|
|
#include "gstvaapiobject.h"
|
2013-04-30 15:20:46 +00:00
|
|
|
#include "gstvaapiobject_priv.h"
|
|
|
|
#include "gstvaapiminiobject.h"
|
|
|
|
#include "gstvaapidisplay_priv.h"
|
2010-03-23 16:21:28 +00:00
|
|
|
|
|
|
|
#define DEBUG 1
|
|
|
|
#include "gstvaapidebug.h"
|
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
/* Ensure those symbols are actually defined in the resulting libraries */
|
|
|
|
#undef gst_vaapi_object_ref
|
|
|
|
#undef gst_vaapi_object_unref
|
|
|
|
#undef gst_vaapi_object_replace
|
2010-03-23 17:12:40 +00:00
|
|
|
|
|
|
|
static void
|
2013-04-30 15:20:46 +00:00
|
|
|
gst_vaapi_object_finalize(GstVaapiObject *object)
|
2010-03-23 17:12:40 +00:00
|
|
|
{
|
2013-04-30 15:20:46 +00:00
|
|
|
const GstVaapiObjectClass * const klass =
|
|
|
|
GST_VAAPI_OBJECT_GET_CLASS(object);
|
2010-03-23 17:12:40 +00:00
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
if (klass->finalize)
|
|
|
|
klass->finalize(object);
|
2013-05-07 09:39:34 +00:00
|
|
|
gst_vaapi_display_replace(&object->display, NULL);
|
2010-03-23 17:12:40 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
void
|
|
|
|
gst_vaapi_object_class_init(GstVaapiObjectClass *klass, guint size)
|
2010-03-23 16:21:28 +00:00
|
|
|
{
|
2013-04-30 15:20:46 +00:00
|
|
|
GstVaapiMiniObjectClass * const object_class =
|
|
|
|
GST_VAAPI_MINI_OBJECT_CLASS(klass);
|
2010-03-24 13:19:58 +00:00
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
object_class->size = size;
|
|
|
|
object_class->finalize = (GDestroyNotify)gst_vaapi_object_finalize;
|
2010-03-23 16:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_object_new:
|
|
|
|
* @object_class: The object class
|
|
|
|
*
|
|
|
|
* Creates a new #GstVaapiObject. If @object_class is NULL, then the
|
|
|
|
* size of the allocated object is the same as sizeof(GstVaapiObject).
|
|
|
|
* If @object_class is not NULL, typically when a sub-class is implemented,
|
|
|
|
* that pointer shall reference a statically allocated descriptor.
|
|
|
|
*
|
|
|
|
* This function zero-initializes the derived object data. Also note
|
|
|
|
* that this is an internal function that shall not be used outside of
|
|
|
|
* libgstvaapi libraries.
|
|
|
|
*
|
|
|
|
* Returns: The newly allocated #GstVaapiObject
|
|
|
|
*/
|
|
|
|
gpointer
|
|
|
|
gst_vaapi_object_new(const GstVaapiObjectClass *klass, GstVaapiDisplay *display)
|
2010-03-23 16:21:28 +00:00
|
|
|
{
|
2013-04-30 15:20:46 +00:00
|
|
|
const GstVaapiMiniObjectClass * const object_class =
|
|
|
|
GST_VAAPI_MINI_OBJECT_CLASS(klass);
|
|
|
|
GstVaapiObject *object;
|
|
|
|
guint sub_size;
|
2010-03-23 16:21:28 +00:00
|
|
|
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(display != NULL, NULL);
|
2010-03-23 16:21:28 +00:00
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
object = (GstVaapiObject *)gst_vaapi_mini_object_new(object_class);
|
|
|
|
if (!object)
|
|
|
|
return NULL;
|
|
|
|
|
2013-05-07 09:39:34 +00:00
|
|
|
object->display = gst_vaapi_display_ref(display);
|
2013-04-30 15:20:46 +00:00
|
|
|
object->object_id = VA_INVALID_ID;
|
2010-03-23 16:21:28 +00:00
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
sub_size = object_class->size - sizeof(*object);
|
|
|
|
if (sub_size > 0)
|
|
|
|
memset(((guchar *)object) + sizeof(*object), 0, sub_size);
|
|
|
|
return object;
|
2010-03-23 16:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_object_ref:
|
|
|
|
* @object: a #GstVaapiObject
|
|
|
|
*
|
|
|
|
* Atomically increases the reference count of the given @object by one.
|
|
|
|
*
|
|
|
|
* Returns: The same @object argument
|
|
|
|
*/
|
|
|
|
gpointer
|
|
|
|
gst_vaapi_object_ref(gpointer object)
|
2010-03-23 16:21:28 +00:00
|
|
|
{
|
2013-04-30 15:20:46 +00:00
|
|
|
return gst_vaapi_object_ref_internal(object);
|
2010-03-23 16:21:28 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_object_unref:
|
|
|
|
* @object: a #GstVaapiObject
|
|
|
|
*
|
|
|
|
* Atomically decreases the reference count of the @object by one. If
|
|
|
|
* the reference count reaches zero, the object will be free'd.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_object_unref(gpointer object)
|
2010-03-23 16:21:28 +00:00
|
|
|
{
|
2013-04-30 15:20:46 +00:00
|
|
|
gst_vaapi_object_unref_internal(object);
|
|
|
|
}
|
2010-03-23 16:21:28 +00:00
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_object_replace:
|
|
|
|
* @old_object_ptr: a pointer to a #GstVaapiObject
|
|
|
|
* @new_object: a #GstVaapiObject
|
|
|
|
*
|
|
|
|
* Atomically replaces the object object held in @old_object_ptr with
|
|
|
|
* @new_object. This means that @old_object_ptr shall reference a
|
|
|
|
* valid object. However, @new_object can be NULL.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_object_replace(gpointer old_object_ptr, gpointer new_object)
|
|
|
|
{
|
|
|
|
gst_vaapi_object_replace_internal(old_object_ptr, new_object);
|
2010-03-23 16:21:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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)
|
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(object != NULL, NULL);
|
2010-03-23 16:21:28 +00:00
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
return GST_VAAPI_OBJECT_DISPLAY(object);
|
2010-03-23 16:21:28 +00:00
|
|
|
}
|
2010-03-24 13:19:58 +00:00
|
|
|
|
2010-03-26 15:22:00 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_object_lock_display:
|
|
|
|
* @object: a #GstVaapiObject
|
|
|
|
*
|
|
|
|
* Locks @object parent display. If display is already locked by
|
|
|
|
* another thread, the current thread will block until display is
|
|
|
|
* unlocked by the other thread.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_object_lock_display(GstVaapiObject *object)
|
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_if_fail(object != NULL);
|
2010-03-26 15:22:00 +00:00
|
|
|
|
|
|
|
GST_VAAPI_OBJECT_LOCK_DISPLAY(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_vaapi_object_unlock_display:
|
|
|
|
* @object: a #GstVaapiObject
|
|
|
|
*
|
|
|
|
* Unlocks @object parent display. If another thread is blocked in a
|
|
|
|
* gst_vaapi_object_lock_display() call, it will be woken and can lock
|
|
|
|
* display itself.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_vaapi_object_unlock_display(GstVaapiObject *object)
|
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_if_fail(object != NULL);
|
2010-03-26 15:22:00 +00:00
|
|
|
|
|
|
|
GST_VAAPI_OBJECT_UNLOCK_DISPLAY(object);
|
|
|
|
}
|
|
|
|
|
2010-03-24 13:19:58 +00:00
|
|
|
/**
|
|
|
|
* gst_vaapi_object_get_id:
|
|
|
|
* @object: a #GstVaapiObject
|
|
|
|
*
|
|
|
|
* Returns the #GstVaapiID contained in the @object.
|
|
|
|
*
|
|
|
|
* Return value: the #GstVaapiID of the @object
|
|
|
|
*/
|
|
|
|
GstVaapiID
|
|
|
|
gst_vaapi_object_get_id(GstVaapiObject *object)
|
|
|
|
{
|
2013-05-23 16:15:48 +00:00
|
|
|
g_return_val_if_fail(object != NULL, 0);
|
2010-03-24 13:19:58 +00:00
|
|
|
|
2013-04-30 15:20:46 +00:00
|
|
|
return GST_VAAPI_OBJECT_ID(object);
|
2010-03-24 13:19:58 +00:00
|
|
|
}
|