2 * gstvaapicodedbufferproxy.c - VA coded buffer proxy
4 * Copyright (C) 2013 Intel Corporation
5 * Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
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 #include "gstvaapicodedbufferproxy.h"
25 #include "gstvaapicodedbufferproxy_priv.h"
26 #include "gstvaapivideopool_priv.h"
29 #include "gstvaapidebug.h"
32 coded_buffer_proxy_set_user_data (GstVaapiCodedBufferProxy * proxy,
33 gpointer user_data, GDestroyNotify destroy_func)
35 if (proxy->user_data_destroy)
36 proxy->user_data_destroy (proxy->user_data);
38 proxy->user_data = user_data;
39 proxy->user_data_destroy = destroy_func;
43 coded_buffer_proxy_finalize (GstVaapiCodedBufferProxy * proxy)
47 gst_vaapi_video_pool_put_object (proxy->pool, proxy->buffer);
48 gst_vaapi_coded_buffer_unref (proxy->buffer);
51 gst_vaapi_video_pool_replace (&proxy->pool, NULL);
52 coded_buffer_proxy_set_user_data (proxy, NULL, NULL);
54 /* Notify the user function that the object is now destroyed */
55 if (proxy->destroy_func)
56 proxy->destroy_func (proxy->destroy_data);
59 static inline const GstVaapiMiniObjectClass *
60 gst_vaapi_coded_buffer_proxy_class (void)
62 static const GstVaapiMiniObjectClass GstVaapiCodedBufferProxyClass = {
63 sizeof (GstVaapiCodedBufferProxy),
64 (GDestroyNotify) coded_buffer_proxy_finalize
66 return &GstVaapiCodedBufferProxyClass;
70 * gst_vaapi_coded_buffer_proxy_new_from_pool:
71 * @pool: a #GstVaapiCodedBufferPool
73 * Allocates a new coded buffer from the supplied @pool and creates
74 * the wrapped coded buffer proxy object from it. When the last
75 * reference to the proxy object is released, then the underlying VA
76 * coded buffer is pushed back to its parent pool.
78 * Returns: The same newly allocated @proxy object, or %NULL on error
80 GstVaapiCodedBufferProxy *
81 gst_vaapi_coded_buffer_proxy_new_from_pool (GstVaapiCodedBufferPool * pool)
83 GstVaapiCodedBufferProxy *proxy;
85 g_return_val_if_fail (pool != NULL, NULL);
86 g_return_val_if_fail (GST_VAAPI_VIDEO_POOL (pool)->object_type ==
87 GST_VAAPI_VIDEO_POOL_OBJECT_TYPE_CODED_BUFFER, NULL);
89 proxy = (GstVaapiCodedBufferProxy *)
90 gst_vaapi_mini_object_new (gst_vaapi_coded_buffer_proxy_class ());
94 proxy->destroy_func = NULL;
95 proxy->user_data_destroy = NULL;
96 proxy->pool = gst_vaapi_video_pool_ref (GST_VAAPI_VIDEO_POOL (pool));
97 proxy->buffer = gst_vaapi_video_pool_get_object (proxy->pool);
100 gst_mini_object_ref (GST_MINI_OBJECT_CAST (proxy->buffer));
106 gst_vaapi_coded_buffer_proxy_unref (proxy);
112 * gst_vaapi_coded_buffer_proxy_ref:
113 * @proxy: a #GstVaapiCodedBufferProxy
115 * Atomically increases the reference count of the given @proxy by one.
117 * Returns: The same @proxy argument
119 GstVaapiCodedBufferProxy *
120 gst_vaapi_coded_buffer_proxy_ref (GstVaapiCodedBufferProxy * proxy)
122 g_return_val_if_fail (proxy != NULL, NULL);
124 return GST_VAAPI_CODED_BUFFER_PROXY (gst_vaapi_mini_object_ref
125 (GST_VAAPI_MINI_OBJECT (proxy)));
129 * gst_vaapi_coded_buffer_proxy_unref:
130 * @proxy: a #GstVaapiCodedBufferProxy
132 * Atomically decreases the reference count of the @proxy by one. If
133 * the reference count reaches zero, the object will be free'd.
136 gst_vaapi_coded_buffer_proxy_unref (GstVaapiCodedBufferProxy * proxy)
138 g_return_if_fail (proxy != NULL);
140 gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (proxy));
144 * gst_vaapi_coded_buffer_proxy_replace:
145 * @old_proxy_ptr: a pointer to a #GstVaapiCodedBufferProxy
146 * @new_proxy: a #GstVaapiCodedBufferProxy
148 * Atomically replaces the proxy object held in @old_proxy_ptr with
149 * @new_proxy. This means that @old_proxy_ptr shall reference a valid
150 * object. However, @new_proxy can be NULL.
153 gst_vaapi_coded_buffer_proxy_replace (GstVaapiCodedBufferProxy ** old_proxy_ptr,
154 GstVaapiCodedBufferProxy * new_proxy)
156 g_return_if_fail (old_proxy_ptr != NULL);
158 gst_vaapi_mini_object_replace ((GstVaapiMiniObject **) old_proxy_ptr,
159 GST_VAAPI_MINI_OBJECT (new_proxy));
163 * gst_vaapi_coded_buffer_proxy_get_buffer:
164 * @proxy: a #GstVaapiCodedBufferProxy
166 * Returns the #GstVaapiCodedBuffer stored in the @proxy.
168 * Return value: the #GstVaapiCodedBuffer, or %NULL if an error occurred
170 GstVaapiCodedBuffer *
171 gst_vaapi_coded_buffer_proxy_get_buffer (GstVaapiCodedBufferProxy * proxy)
173 g_return_val_if_fail (proxy != NULL, NULL);
175 return GST_VAAPI_CODED_BUFFER_PROXY_BUFFER (proxy);
179 * gst_vaapi_coded_buffer_proxy_get_buffer_size:
180 * @proxy: a #GstVaapiCodedBufferProxy
182 * Returns the size of the underlying #GstVaapiCodedBuffer object
183 * stored in the @proxy.
185 * Return value: the underlying #GstVaapiCodedBuffer size, or -1 if an
189 gst_vaapi_coded_buffer_proxy_get_buffer_size (GstVaapiCodedBufferProxy * proxy)
191 g_return_val_if_fail (proxy != NULL, -1);
193 return GST_VAAPI_CODED_BUFFER_PROXY_BUFFER_SIZE (proxy);
197 * gst_vaapi_coded_buffer_proxy_set_destroy_notify:
198 * @proxy: a @GstVaapiCodedBufferProxy
199 * @destroy_func: a #GDestroyNotify function
200 * @user_data: some extra data to pass to the @destroy_func function
202 * Sets @destroy_func as the function to call when the coded buffer
203 * @proxy was released. At this point, the proxy object is considered
204 * released, i.e. the underlying data storage is no longer valid and
205 * the callback function shall not expect anything from that.
208 gst_vaapi_coded_buffer_proxy_set_destroy_notify (GstVaapiCodedBufferProxy *
209 proxy, GDestroyNotify destroy_func, gpointer user_data)
211 g_return_if_fail (proxy != NULL);
213 proxy->destroy_func = destroy_func;
214 proxy->destroy_data = user_data;
218 * gst_vaapi_coded_buffer_proxy_get_user_data:
219 * @proxy: a #GstVaapiCodedBufferProxy
221 * Gets private data previously set on the VA coded buffer proxy
222 * object through the gst_vaapi_coded_buffer_proxy_set_user_data()
225 * Return value: the previously set user-data
228 gst_vaapi_coded_buffer_proxy_get_user_data (GstVaapiCodedBufferProxy * proxy)
230 g_return_val_if_fail (proxy != NULL, NULL);
232 return proxy->user_data;
236 * gst_vaapi_coded_buffer_proxy_set_user_data:
237 * @proxy: a #GstVaapiCodedBufferProxy
238 * @user_data: user-defined data
239 * @destroy_func: a #GDestroyNotify
241 * Sets @user_data on the VA coded buffer proxy object and the
242 * #GDestroyNotify function that will be called when the coded buffer
243 * proxy object is released.
245 * If a @user_data was previously set, then the previously set
246 * @destroy_func function, if any, will be called before the
247 * @user_data is replaced.
250 gst_vaapi_coded_buffer_proxy_set_user_data (GstVaapiCodedBufferProxy * proxy,
251 gpointer user_data, GDestroyNotify destroy_func)
253 g_return_if_fail (proxy != NULL);
255 coded_buffer_proxy_set_user_data (proxy, user_data, destroy_func);