2 * gstvaapiobject.c - Base VA object
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@splitted-desktop.com>
6 * Copyright (C) 2012-2013 Intel Corporation
7 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301 USA
26 * SECTION:gstvaapiobject
27 * @short_description: Base VA object
31 #include "gstvaapiobject.h"
32 #include "gstvaapiobject_priv.h"
33 #include "gstvaapiminiobject.h"
34 #include "gstvaapidisplay_priv.h"
37 #include "gstvaapidebug.h"
39 /* Ensure those symbols are actually defined in the resulting libraries */
40 #undef gst_vaapi_object_ref
41 #undef gst_vaapi_object_unref
42 #undef gst_vaapi_object_replace
45 gst_vaapi_object_finalize(GstVaapiObject *object)
47 const GstVaapiObjectClass * const klass =
48 GST_VAAPI_OBJECT_GET_CLASS(object);
51 klass->finalize(object);
52 gst_vaapi_display_replace(&object->display, NULL);
56 gst_vaapi_object_class_init(GstVaapiObjectClass *klass, guint size)
58 GstVaapiMiniObjectClass * const object_class =
59 GST_VAAPI_MINI_OBJECT_CLASS(klass);
61 object_class->size = size;
62 object_class->finalize = (GDestroyNotify)gst_vaapi_object_finalize;
66 * gst_vaapi_object_new:
67 * @klass: The object class
68 * @display: The #GstVaapiDisplay
70 * Creates a new #GstVaapiObject. The @klass argument shall not be
71 * %NULL, and it must reference a statically allocated descriptor.
73 * This function zero-initializes the derived object data. Also note
74 * that this is an internal function that shall not be used outside of
75 * libgstvaapi libraries.
77 * Returns: The newly allocated #GstVaapiObject
80 gst_vaapi_object_new(const GstVaapiObjectClass *klass, GstVaapiDisplay *display)
82 const GstVaapiMiniObjectClass * const object_class =
83 GST_VAAPI_MINI_OBJECT_CLASS(klass);
84 GstVaapiObject *object;
87 g_return_val_if_fail(klass != NULL, NULL);
88 g_return_val_if_fail(display != NULL, NULL);
90 object = (GstVaapiObject *)gst_vaapi_mini_object_new(object_class);
94 object->display = gst_vaapi_display_ref(display);
95 object->object_id = VA_INVALID_ID;
97 sub_size = object_class->size - sizeof(*object);
99 memset(((guchar *)object) + sizeof(*object), 0, sub_size);
101 if (klass && klass->init)
102 klass->init (object);
107 * gst_vaapi_object_ref:
108 * @object: a #GstVaapiObject
110 * Atomically increases the reference count of the given @object by one.
112 * Returns: The same @object argument
115 gst_vaapi_object_ref(gpointer object)
117 return gst_vaapi_object_ref_internal(object);
121 * gst_vaapi_object_unref:
122 * @object: a #GstVaapiObject
124 * Atomically decreases the reference count of the @object by one. If
125 * the reference count reaches zero, the object will be free'd.
128 gst_vaapi_object_unref(gpointer object)
130 gst_vaapi_object_unref_internal(object);
134 * gst_vaapi_object_replace:
135 * @old_object_ptr: a pointer to a #GstVaapiObject
136 * @new_object: a #GstVaapiObject
138 * Atomically replaces the object object held in @old_object_ptr with
139 * @new_object. This means that @old_object_ptr shall reference a
140 * valid object. However, @new_object can be NULL.
143 gst_vaapi_object_replace(gpointer old_object_ptr, gpointer new_object)
145 gst_vaapi_object_replace_internal(old_object_ptr, new_object);
149 * gst_vaapi_object_get_display:
150 * @object: a #GstVaapiObject
152 * Returns the #GstVaapiDisplay this @object is bound to.
154 * Return value: the parent #GstVaapiDisplay object
157 gst_vaapi_object_get_display(GstVaapiObject *object)
159 g_return_val_if_fail(object != NULL, NULL);
161 return GST_VAAPI_OBJECT_DISPLAY(object);
165 * gst_vaapi_object_lock_display:
166 * @object: a #GstVaapiObject
168 * Locks @object parent display. If display is already locked by
169 * another thread, the current thread will block until display is
170 * unlocked by the other thread.
173 gst_vaapi_object_lock_display(GstVaapiObject *object)
175 g_return_if_fail(object != NULL);
177 GST_VAAPI_OBJECT_LOCK_DISPLAY(object);
181 * gst_vaapi_object_unlock_display:
182 * @object: a #GstVaapiObject
184 * Unlocks @object parent display. If another thread is blocked in a
185 * gst_vaapi_object_lock_display() call, it will be woken and can lock
189 gst_vaapi_object_unlock_display(GstVaapiObject *object)
191 g_return_if_fail(object != NULL);
193 GST_VAAPI_OBJECT_UNLOCK_DISPLAY(object);
197 * gst_vaapi_object_get_id:
198 * @object: a #GstVaapiObject
200 * Returns the #GstVaapiID contained in the @object.
202 * Return value: the #GstVaapiID of the @object
205 gst_vaapi_object_get_id(GstVaapiObject *object)
207 g_return_val_if_fail(object != NULL, 0);
209 return GST_VAAPI_OBJECT_ID(object);