1 /*
2 * gstvaapiobject.c - Base VA object
3 *
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>
8 *
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.
13 *
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.
18 *
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
23 */
24
25 /**
26 * SECTION:gstvaapiobject
27 * @short_description: Base VA object
28 */
29
30 #include "sysdeps.h"
31 #include "gstvaapiobject.h"
32 #include "gstvaapiobject_priv.h"
33 #include "gstvaapiminiobject.h"
34 #include "gstvaapidisplay_priv.h"
35
36 #define DEBUG 1
37 #include "gstvaapidebug.h"
38
39 static void
gst_vaapi_object_finalize(GstVaapiObject * object)40 gst_vaapi_object_finalize (GstVaapiObject * object)
41 {
42 const GstVaapiObjectClass *const klass = GST_VAAPI_OBJECT_GET_CLASS (object);
43
44 if (klass->finalize)
45 klass->finalize (object);
46 gst_vaapi_display_replace (&object->display, NULL);
47 }
48
49 void
gst_vaapi_object_class_init(GstVaapiObjectClass * klass,guint size)50 gst_vaapi_object_class_init (GstVaapiObjectClass * klass, guint size)
51 {
52 GstVaapiMiniObjectClass *const object_class =
53 GST_VAAPI_MINI_OBJECT_CLASS (klass);
54
55 object_class->size = size;
56 object_class->finalize = (GDestroyNotify) gst_vaapi_object_finalize;
57 }
58
59 /**
60 * gst_vaapi_object_new:
61 * @klass: The object class
62 * @display: The #GstVaapiDisplay
63 *
64 * Creates a new #GstVaapiObject. The @klass argument shall not be
65 * %NULL, and it must reference a statically allocated descriptor.
66 *
67 * This function zero-initializes the derived object data. Also note
68 * that this is an internal function that shall not be used outside of
69 * libgstvaapi libraries.
70 *
71 * Returns: The newly allocated #GstVaapiObject
72 */
73 gpointer
gst_vaapi_object_new(const GstVaapiObjectClass * klass,GstVaapiDisplay * display)74 gst_vaapi_object_new (const GstVaapiObjectClass * klass,
75 GstVaapiDisplay * display)
76 {
77 const GstVaapiMiniObjectClass *const object_class =
78 GST_VAAPI_MINI_OBJECT_CLASS (klass);
79 GstVaapiObject *object;
80 guint sub_size;
81
82 g_return_val_if_fail (klass != NULL, NULL);
83 g_return_val_if_fail (display != NULL, NULL);
84
85 object = (GstVaapiObject *) gst_vaapi_mini_object_new (object_class);
86 if (!object)
87 return NULL;
88
89 object->display = gst_object_ref (display);
90 object->object_id = VA_INVALID_ID;
91
92 sub_size = object_class->size - sizeof (*object);
93 if (sub_size > 0)
94 memset (((guchar *) object) + sizeof (*object), 0, sub_size);
95
96 if (klass->init)
97 klass->init (object);
98 return object;
99 }
100
101 /**
102 * gst_vaapi_object_ref:
103 * @object: a #GstVaapiObject
104 *
105 * Atomically increases the reference count of the given @object by one.
106 *
107 * Returns: The same @object argument
108 */
109 gpointer
gst_vaapi_object_ref(gpointer object)110 gst_vaapi_object_ref (gpointer object)
111 {
112 return gst_vaapi_mini_object_ref (object);
113 }
114
115 /**
116 * gst_vaapi_object_unref:
117 * @object: a #GstVaapiObject
118 *
119 * Atomically decreases the reference count of the @object by one. If
120 * the reference count reaches zero, the object will be free'd.
121 */
122 void
gst_vaapi_object_unref(gpointer object)123 gst_vaapi_object_unref (gpointer object)
124 {
125 gst_vaapi_mini_object_unref (object);
126 }
127
128 /**
129 * gst_vaapi_object_replace:
130 * @old_object_ptr: a pointer to a #GstVaapiObject
131 * @new_object: a #GstVaapiObject
132 *
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.
136 */
137 void
gst_vaapi_object_replace(gpointer old_object_ptr,gpointer new_object)138 gst_vaapi_object_replace (gpointer old_object_ptr, gpointer new_object)
139 {
140 gst_vaapi_mini_object_replace ((GstVaapiMiniObject **) old_object_ptr,
141 new_object);
142 }
143
144 /**
145 * gst_vaapi_object_get_display:
146 * @object: a #GstVaapiObject
147 *
148 * Returns the #GstVaapiDisplay this @object is bound to.
149 *
150 * Return value: the parent #GstVaapiDisplay object
151 */
152 GstVaapiDisplay *
gst_vaapi_object_get_display(GstVaapiObject * object)153 gst_vaapi_object_get_display (GstVaapiObject * object)
154 {
155 g_return_val_if_fail (object != NULL, NULL);
156
157 return GST_VAAPI_OBJECT_DISPLAY (object);
158 }
159
160 /**
161 * gst_vaapi_object_lock_display:
162 * @object: a #GstVaapiObject
163 *
164 * Locks @object parent display. If display is already locked by
165 * another thread, the current thread will block until display is
166 * unlocked by the other thread.
167 */
168 void
gst_vaapi_object_lock_display(GstVaapiObject * object)169 gst_vaapi_object_lock_display (GstVaapiObject * object)
170 {
171 g_return_if_fail (object != NULL);
172
173 GST_VAAPI_OBJECT_LOCK_DISPLAY (object);
174 }
175
176 /**
177 * gst_vaapi_object_unlock_display:
178 * @object: a #GstVaapiObject
179 *
180 * Unlocks @object parent display. If another thread is blocked in a
181 * gst_vaapi_object_lock_display() call, it will be woken and can lock
182 * display itself.
183 */
184 void
gst_vaapi_object_unlock_display(GstVaapiObject * object)185 gst_vaapi_object_unlock_display (GstVaapiObject * object)
186 {
187 g_return_if_fail (object != NULL);
188
189 GST_VAAPI_OBJECT_UNLOCK_DISPLAY (object);
190 }
191
192 /**
193 * gst_vaapi_object_get_id:
194 * @object: a #GstVaapiObject
195 *
196 * Returns the #GstVaapiID contained in the @object.
197 *
198 * Return value: the #GstVaapiID of the @object
199 */
200 GstVaapiID
gst_vaapi_object_get_id(GstVaapiObject * object)201 gst_vaapi_object_get_id (GstVaapiObject * object)
202 {
203 g_return_val_if_fail (object != NULL, 0);
204
205 return GST_VAAPI_OBJECT_ID (object);
206 }
207