surfaceproxy: drop user-data support from GstVaapiSurfaceProxy.

Drop user-data support from GstVaapiSurfaceProxy. Rather make it explicit
to call some user-provided function when the surface proxy is released.
This commit is contained in:
Gwenole Beauchesne 2013-04-16 13:48:00 +02:00
parent 2db47c0ade
commit 0bd929dfa2
5 changed files with 36 additions and 52 deletions

View file

@ -523,11 +523,10 @@ GST_VAAPI_DECODER_VC1_GET_CLASS
<TITLE>GstVaapiSurfaceProxy</TITLE>
gst_vaapi_surface_proxy_get_surface
gst_vaapi_surface_proxy_get_surface_id
gst_vaapi_surface_proxy_get_user_data
gst_vaapi_surface_proxy_new_from_pool
gst_vaapi_surface_proxy_ref
gst_vaapi_surface_proxy_replace
gst_vaapi_surface_proxy_set_user_data
gst_vaapi_surface_proxy_set_destroy_notify
gst_vaapi_surface_proxy_unref
<SUBSECTION Standard>
GST_VAAPI_SURFACE_PROXY_SURFACE

View file

@ -45,11 +45,16 @@ struct _GstVaapiSurfaceProxy {
GstVaapiVideoPool *pool;
GstVaapiSurface *surface;
GDestroyNotify destroy_func;
gpointer destroy_data;
};
static void
gst_vaapi_surface_proxy_finalize(GstVaapiSurfaceProxy *proxy)
{
if (proxy->destroy_func)
proxy->destroy_func(proxy->destroy_data);
if (proxy->surface) {
if (proxy->pool)
gst_vaapi_video_pool_put_object(proxy->pool, proxy->surface);
@ -85,6 +90,7 @@ gst_vaapi_surface_proxy_new_from_pool(GstVaapiSurfacePool *pool)
proxy->surface = gst_vaapi_video_pool_get_object(proxy->pool);
if (!proxy->surface)
goto error;
proxy->destroy_func = NULL;
g_object_ref(proxy->surface);
return proxy;
@ -144,45 +150,6 @@ gst_vaapi_surface_proxy_replace(GstVaapiSurfaceProxy **old_proxy_ptr,
GST_VAAPI_MINI_OBJECT(new_proxy));
}
/**
* gst_vaapi_surface_proxy_get_user_data:
* @proxy: a #GstVaapiSurfaceProxy
*
* Gets user-provided data set on the object via a previous call to
* gst_vaapi_surface_proxy_set_user_data().
*
* Returns: (transfer none): The previously set user_data
*/
gpointer
gst_vaapi_surface_proxy_get_user_data(GstVaapiSurfaceProxy *proxy)
{
g_return_val_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy), NULL);
return gst_vaapi_mini_object_get_user_data(GST_VAAPI_MINI_OBJECT(proxy));
}
/**
* gst_vaapi_surface_proxy_set_user_data:
* @proxy: a #GstVaapiSurfaceProxy
* @user_data: user-provided data
* @destroy_notify: (closure user_data): a #GDestroyNotify
*
* Sets @user_data on the object and the #GDestroyNotify that will be
* called when the data is freed.
*
* If some @user_data was previously set, then the former @destroy_notify
* function will be called before the @user_data is replaced.
*/
void
gst_vaapi_surface_proxy_set_user_data(GstVaapiSurfaceProxy *proxy,
gpointer user_data, GDestroyNotify destroy_notify)
{
g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
gst_vaapi_mini_object_set_user_data(GST_VAAPI_MINI_OBJECT(proxy),
user_data, destroy_notify);
}
/**
* gst_vaapi_surface_proxy_get_surface:
* @proxy: a #GstVaapiSurfaceProxy
@ -215,3 +182,24 @@ gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy)
return GST_VAAPI_OBJECT_ID(proxy->surface);
}
/**
* gst_vaapi_surface_proxy_set_destroy_notify:
* @proxy: a @GstVaapiSurfaceProxy
* @destroy_func: a #GDestroyNotify function
* @user_data: some extra data to pass to the @destroy_func function
*
* Sets @destroy_func as the function to call when the surface @proxy
* was released. At this point, the proxy object is considered
* released, i.e. the underlying data storage is no longer valid and
* the callback function shall not expect anything from that.
*/
void
gst_vaapi_surface_proxy_set_destroy_notify(GstVaapiSurfaceProxy *proxy,
GDestroyNotify destroy_func, gpointer user_data)
{
g_return_if_fail(GST_VAAPI_IS_SURFACE_PROXY(proxy));
proxy->destroy_func = destroy_func;
proxy->destroy_data = user_data;
}

View file

@ -50,19 +50,16 @@ void
gst_vaapi_surface_proxy_replace(GstVaapiSurfaceProxy **old_proxy_ptr,
GstVaapiSurfaceProxy *new_proxy);
gpointer
gst_vaapi_surface_proxy_get_user_data(GstVaapiSurfaceProxy *proxy);
void
gst_vaapi_surface_proxy_set_user_data(GstVaapiSurfaceProxy *proxy,
gpointer user_data, GDestroyNotify destroy_notify);
GstVaapiSurface *
gst_vaapi_surface_proxy_get_surface(GstVaapiSurfaceProxy *proxy);
GstVaapiID
gst_vaapi_surface_proxy_get_surface_id(GstVaapiSurfaceProxy *proxy);
void
gst_vaapi_surface_proxy_set_destroy_notify(GstVaapiSurfaceProxy *proxy,
GDestroyNotify destroy_func, gpointer user_data);
G_END_DECLS
#endif /* GST_VAAPI_SURFACE_PROXY_H */

View file

@ -284,8 +284,8 @@ gst_vaapidecode_push_decoded_frames(GstVideoDecoder *vdec)
if (!GST_VIDEO_CODEC_FRAME_IS_DECODE_ONLY(out_frame)) {
proxy = gst_video_codec_frame_get_user_data(out_frame);
gst_vaapi_surface_proxy_set_user_data(proxy,
decode, (GDestroyNotify)gst_vaapidecode_release);
gst_vaapi_surface_proxy_set_destroy_notify(proxy,
(GDestroyNotify)gst_vaapidecode_release, decode);
#if GST_CHECK_VERSION(1,0,0)
ret = gst_video_decoder_allocate_output_frame(vdec, out_frame);

View file

@ -266,8 +266,8 @@ decoder_thread(gpointer data)
status = gst_vaapi_decoder_get_surface(app->decoder, &proxy);
switch (status) {
case GST_VAAPI_DECODER_STATUS_SUCCESS:
gst_vaapi_surface_proxy_set_user_data(proxy,
app, (GDestroyNotify)decoder_release);
gst_vaapi_surface_proxy_set_destroy_notify(proxy,
(GDestroyNotify)decoder_release, app);
rfp = render_frame_new();
if (!rfp)
SEND_ERROR("failed to allocate render frame");