2 * gstvaapiobject.c - Base VA object
4 * Copyright (C) 2010-2011 Splitted-Desktop Systems
5 * Copyright (C) 2012 Intel Corporation
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
24 * SECTION:gstvaapiobject
25 * @short_description: Base VA object
29 #include "gstvaapiobject.h"
30 #include "gstvaapiobject_priv.h"
31 #include "gstvaapiminiobject.h"
32 #include "gstvaapidisplay_priv.h"
35 #include "gstvaapidebug.h"
37 /* Ensure those symbols are actually defined in the resulting libraries */
38 #undef gst_vaapi_object_ref
39 #undef gst_vaapi_object_unref
40 #undef gst_vaapi_object_replace
43 gst_vaapi_object_finalize(GstVaapiObject *object)
45 const GstVaapiObjectClass * const klass =
46 GST_VAAPI_OBJECT_GET_CLASS(object);
49 klass->finalize(object);
50 gst_vaapi_display_replace(&object->display, NULL);
54 gst_vaapi_object_class_init(GstVaapiObjectClass *klass, guint size)
56 GstVaapiMiniObjectClass * const object_class =
57 GST_VAAPI_MINI_OBJECT_CLASS(klass);
59 object_class->size = size;
60 object_class->finalize = (GDestroyNotify)gst_vaapi_object_finalize;
64 * gst_vaapi_object_new:
65 * @object_class: The object class
67 * Creates a new #GstVaapiObject. If @object_class is NULL, then the
68 * size of the allocated object is the same as sizeof(GstVaapiObject).
69 * If @object_class is not NULL, typically when a sub-class is implemented,
70 * that pointer shall reference a statically allocated descriptor.
72 * This function zero-initializes the derived object data. Also note
73 * that this is an internal function that shall not be used outside of
74 * libgstvaapi libraries.
76 * Returns: The newly allocated #GstVaapiObject
79 gst_vaapi_object_new(const GstVaapiObjectClass *klass, GstVaapiDisplay *display)
81 const GstVaapiMiniObjectClass * const object_class =
82 GST_VAAPI_MINI_OBJECT_CLASS(klass);
83 GstVaapiObject *object;
86 g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
88 object = (GstVaapiObject *)gst_vaapi_mini_object_new(object_class);
92 object->display = gst_vaapi_display_ref(display);
93 object->object_id = VA_INVALID_ID;
95 sub_size = object_class->size - sizeof(*object);
97 memset(((guchar *)object) + sizeof(*object), 0, sub_size);
102 * gst_vaapi_object_ref:
103 * @object: a #GstVaapiObject
105 * Atomically increases the reference count of the given @object by one.
107 * Returns: The same @object argument
110 gst_vaapi_object_ref(gpointer object)
112 return gst_vaapi_object_ref_internal(object);
116 * gst_vaapi_object_unref:
117 * @object: a #GstVaapiObject
119 * Atomically decreases the reference count of the @object by one. If
120 * the reference count reaches zero, the object will be free'd.
123 gst_vaapi_object_unref(gpointer object)
125 gst_vaapi_object_unref_internal(object);
129 * gst_vaapi_object_replace:
130 * @old_object_ptr: a pointer to a #GstVaapiObject
131 * @new_object: a #GstVaapiObject
133 * Atomically replaces the object object held in @old_object_ptr with
134 * @new_object. This means that @old_object_ptr shall reference a
135 * valid object. However, @new_object can be NULL.
138 gst_vaapi_object_replace(gpointer old_object_ptr, gpointer new_object)
140 gst_vaapi_object_replace_internal(old_object_ptr, new_object);
144 * gst_vaapi_object_get_display:
145 * @object: a #GstVaapiObject
147 * Returns the #GstVaapiDisplay this @object is bound to.
149 * Return value: the parent #GstVaapiDisplay object
152 gst_vaapi_object_get_display(GstVaapiObject *object)
154 g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), NULL);
156 return GST_VAAPI_OBJECT_DISPLAY(object);
160 * gst_vaapi_object_lock_display:
161 * @object: a #GstVaapiObject
163 * Locks @object parent display. If display is already locked by
164 * another thread, the current thread will block until display is
165 * unlocked by the other thread.
168 gst_vaapi_object_lock_display(GstVaapiObject *object)
170 g_return_if_fail(GST_VAAPI_IS_OBJECT(object));
172 GST_VAAPI_OBJECT_LOCK_DISPLAY(object);
176 * gst_vaapi_object_unlock_display:
177 * @object: a #GstVaapiObject
179 * Unlocks @object parent display. If another thread is blocked in a
180 * gst_vaapi_object_lock_display() call, it will be woken and can lock
184 gst_vaapi_object_unlock_display(GstVaapiObject *object)
186 g_return_if_fail(GST_VAAPI_IS_OBJECT(object));
188 GST_VAAPI_OBJECT_UNLOCK_DISPLAY(object);
192 * gst_vaapi_object_get_id:
193 * @object: a #GstVaapiObject
195 * Returns the #GstVaapiID contained in the @object.
197 * Return value: the #GstVaapiID of the @object
200 gst_vaapi_object_get_id(GstVaapiObject *object)
202 g_return_val_if_fail(GST_VAAPI_IS_OBJECT(object), 0);
204 return GST_VAAPI_OBJECT_ID(object);