diff --git a/docs/reference/libs/libs-sections.txt b/docs/reference/libs/libs-sections.txt index 33f645b556..81b4b9a5d2 100644 --- a/docs/reference/libs/libs-sections.txt +++ b/docs/reference/libs/libs-sections.txt @@ -523,11 +523,10 @@ GST_VAAPI_DECODER_VC1_GET_CLASS GstVaapiSurfaceProxy 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 GST_VAAPI_SURFACE_PROXY_SURFACE diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c index e802eab40e..83faf19159 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.c @@ -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; +} diff --git a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h index 467699dace..ef8ee691cf 100644 --- a/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h +++ b/gst-libs/gst/vaapi/gstvaapisurfaceproxy.h @@ -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 */ diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index a12c0c8166..f0e5654a0f 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -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); diff --git a/tests/simple-decoder.c b/tests/simple-decoder.c index 04625a627b..7e33f0c641 100644 --- a/tests/simple-decoder.c +++ b/tests/simple-decoder.c @@ -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");