From 275518f6613b0aaed29e9ffdc53d8c9e164a9607 Mon Sep 17 00:00:00 2001 From: Xu Guangxin Date: Tue, 19 May 2020 15:14:34 +0800 Subject: [PATCH] msdkvpp: hold GstBuffer ref count for locked surfaces Part-of: --- sys/msdk/gstmsdkvpp.c | 47 ++++++++++++++++++++++++++++++++++++++++--- sys/msdk/gstmsdkvpp.h | 2 ++ 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/sys/msdk/gstmsdkvpp.c b/sys/msdk/gstmsdkvpp.c index 93421b33aa..e87b18c061 100644 --- a/sys/msdk/gstmsdkvpp.c +++ b/sys/msdk/gstmsdkvpp.c @@ -176,13 +176,52 @@ typedef struct } MsdkSurface; static void -free_msdk_surface (MsdkSurface * surface) +free_msdk_surface (gpointer p) { + MsdkSurface *surface = (MsdkSurface *) p; if (surface->buf) gst_buffer_unref (surface->buf); g_slice_free (MsdkSurface, surface); } +static void +release_msdk_surface (GstMsdkVPP * thiz, MsdkSurface * surface) +{ + if (surface->surface) { + if (surface->surface->Data.Locked) { + thiz->locked_msdk_surfaces = + g_list_append (thiz->locked_msdk_surfaces, surface); + } else { + free_msdk_surface (surface); + } + } +} + +static void +free_unlocked_msdk_surfaces (GstMsdkVPP * thiz) +{ + GList *l; + MsdkSurface *surface; + + for (l = thiz->locked_msdk_surfaces; l;) { + GList *next = l->next; + surface = l->data; + if (surface->surface->Data.Locked == 0) { + free_msdk_surface (surface); + thiz->locked_msdk_surfaces = + g_list_delete_link (thiz->locked_msdk_surfaces, l); + } + l = next; + } +} + +static void +free_all_msdk_surfaces (GstMsdkVPP * thiz) +{ + g_list_free_full (thiz->locked_msdk_surfaces, free_msdk_surface); + thiz->locked_msdk_surfaces = NULL; +} + static void gst_msdkvpp_add_extra_param (GstMsdkVPP * thiz, mfxExtBuffer * param) { @@ -755,6 +794,7 @@ gst_msdkvpp_transform (GstBaseTransform * trans, GstBuffer * inbuf, MsdkSurface *out_surface = NULL; timestamp = GST_BUFFER_TIMESTAMP (inbuf); + free_unlocked_msdk_surfaces (thiz); in_surface = get_msdk_surface_from_input_buffer (thiz, inbuf); if (!in_surface) @@ -855,8 +895,8 @@ error_push_buffer: gst_flow_get_name (ret)); transform_end: - free_msdk_surface (in_surface); - free_msdk_surface (out_surface); + release_msdk_surface (thiz, in_surface); + release_msdk_surface (thiz, out_surface); return ret; } @@ -880,6 +920,7 @@ gst_msdkvpp_close (GstMsdkVPP * thiz) GST_WARNING_OBJECT (thiz, "VPP close failed (%s)", msdk_status_to_string (status)); } + free_all_msdk_surfaces (thiz); gst_clear_object (&thiz->context); diff --git a/sys/msdk/gstmsdkvpp.h b/sys/msdk/gstmsdkvpp.h index 83ff2b7f5c..aa98052ab3 100644 --- a/sys/msdk/gstmsdkvpp.h +++ b/sys/msdk/gstmsdkvpp.h @@ -143,6 +143,8 @@ struct _GstMsdkVPP /* Extended buffers */ mfxExtBuffer *extra_params[MAX_EXTRA_PARAMS]; guint num_extra_params; + + GList* locked_msdk_surfaces; }; struct _GstMsdkVPPClass