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_object_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 (pool);
97 proxy->buffer = gst_vaapi_video_pool_get_object (proxy->pool);
100 gst_vaapi_object_ref (proxy->buffer);
104 gst_vaapi_coded_buffer_proxy_unref (proxy);
109 * gst_vaapi_coded_buffer_proxy_ref:
110 * @proxy: a #GstVaapiCodedBufferProxy
112 * Atomically increases the reference count of the given @proxy by one.
114 * Returns: The same @proxy argument
116 GstVaapiCodedBufferProxy *
117 gst_vaapi_coded_buffer_proxy_ref (GstVaapiCodedBufferProxy * proxy)
119 g_return_val_if_fail (proxy != NULL, NULL);
121 return GST_VAAPI_CODED_BUFFER_PROXY (gst_vaapi_mini_object_ref
122 (GST_VAAPI_MINI_OBJECT (proxy)));
126 * gst_vaapi_coded_buffer_proxy_unref:
127 * @proxy: a #GstVaapiCodedBufferProxy
129 * Atomically decreases the reference count of the @proxy by one. If
130 * the reference count reaches zero, the object will be free'd.
133 gst_vaapi_coded_buffer_proxy_unref (GstVaapiCodedBufferProxy * proxy)
135 g_return_if_fail (proxy != NULL);
137 gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (proxy));
141 * gst_vaapi_coded_buffer_proxy_replace:
142 * @old_proxy_ptr: a pointer to a #GstVaapiCodedBufferProxy
143 * @new_proxy: a #GstVaapiCodedBufferProxy
145 * Atomically replaces the proxy object held in @old_proxy_ptr with
146 * @new_proxy. This means that @old_proxy_ptr shall reference a valid
147 * object. However, @new_proxy can be NULL.
150 gst_vaapi_coded_buffer_proxy_replace (GstVaapiCodedBufferProxy ** old_proxy_ptr,
151 GstVaapiCodedBufferProxy * new_proxy)
153 g_return_if_fail (old_proxy_ptr != NULL);
155 gst_vaapi_mini_object_replace ((GstVaapiMiniObject **) old_proxy_ptr,
156 GST_VAAPI_MINI_OBJECT (new_proxy));
160 * gst_vaapi_coded_buffer_proxy_get_buffer:
161 * @proxy: a #GstVaapiCodedBufferProxy
163 * Returns the #GstVaapiCodedBuffer stored in the @proxy.
165 * Return value: the #GstVaapiCodedBuffer, or %NULL if an error occurred
167 GstVaapiCodedBuffer *
168 gst_vaapi_coded_buffer_proxy_get_buffer (GstVaapiCodedBufferProxy * proxy)
170 g_return_val_if_fail (proxy != NULL, NULL);
172 return GST_VAAPI_CODED_BUFFER_PROXY_BUFFER (proxy);
176 * gst_vaapi_coded_buffer_proxy_get_buffer_size:
177 * @proxy: a #GstVaapiCodedBufferProxy
179 * Returns the size of the underlying #GstVaapiCodedBuffer object
180 * stored in the @proxy.
182 * Return value: the underlying #GstVaapiCodedBuffer size, or -1 if an
186 gst_vaapi_coded_buffer_proxy_get_buffer_size (GstVaapiCodedBufferProxy * proxy)
188 g_return_val_if_fail (proxy != NULL, -1);
190 return GST_VAAPI_CODED_BUFFER_PROXY_BUFFER_SIZE (proxy);
194 * gst_vaapi_coded_buffer_proxy_set_destroy_notify:
195 * @proxy: a @GstVaapiCodedBufferProxy
196 * @destroy_func: a #GDestroyNotify function
197 * @user_data: some extra data to pass to the @destroy_func function
199 * Sets @destroy_func as the function to call when the coded buffer
200 * @proxy was released. At this point, the proxy object is considered
201 * released, i.e. the underlying data storage is no longer valid and
202 * the callback function shall not expect anything from that.
205 gst_vaapi_coded_buffer_proxy_set_destroy_notify (GstVaapiCodedBufferProxy *
206 proxy, GDestroyNotify destroy_func, gpointer user_data)
208 g_return_if_fail (proxy != NULL);
210 proxy->destroy_func = destroy_func;
211 proxy->destroy_data = user_data;
215 * gst_vaapi_coded_buffer_proxy_get_user_data:
216 * @proxy: a #GstVaapiCodedBufferProxy
218 * Gets private data previously set on the VA coded buffer proxy
219 * object through the gst_vaapi_coded_buffer_proxy_set_user_data()
222 * Return value: the previously set user-data
225 gst_vaapi_coded_buffer_proxy_get_user_data (GstVaapiCodedBufferProxy * proxy)
227 g_return_val_if_fail (proxy != NULL, NULL);
229 return proxy->user_data;
233 * gst_vaapi_coded_buffer_proxy_set_user_data:
234 * @proxy: a #GstVaapiCodedBufferProxy
235 * @user_data: user-defined data
236 * @destroy_func: a #GDestroyNotify
238 * Sets @user_data on the VA coded buffer proxy object and the
239 * #GDestroyNotify function that will be called when the coded buffer
240 * proxy object is released.
242 * If a @user_data was previously set, then the previously set
243 * @destroy_func function, if any, will be called before the
244 * @user_data is replaced.
247 gst_vaapi_coded_buffer_proxy_set_user_data (GstVaapiCodedBufferProxy * proxy,
248 gpointer user_data, GDestroyNotify destroy_func)
250 g_return_if_fail (proxy != NULL);
252 coded_buffer_proxy_set_user_data (proxy, user_data, destroy_func);