mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:36:20 +00:00
msdk: Fix memory leaks
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5819>
This commit is contained in:
parent
fe64e68cc4
commit
0d04660c5d
6 changed files with 50 additions and 13 deletions
|
@ -42,6 +42,13 @@
|
||||||
|
|
||||||
#define GST_MSDK_FRAME_SURFACE gst_msdk_frame_surface_quark_get ()
|
#define GST_MSDK_FRAME_SURFACE gst_msdk_frame_surface_quark_get ()
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_msdk_surface_list_free (GstMsdkSurface * surface)
|
||||||
|
{
|
||||||
|
gst_buffer_unref (surface->buf);
|
||||||
|
g_slice_free (GstMsdkSurface, surface);
|
||||||
|
}
|
||||||
|
|
||||||
mfxStatus
|
mfxStatus
|
||||||
gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
|
gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
|
||||||
mfxFrameAllocResponse * resp)
|
mfxFrameAllocResponse * resp)
|
||||||
|
@ -55,8 +62,6 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
|
||||||
mfxU32 fourcc = req->Info.FourCC;
|
mfxU32 fourcc = req->Info.FourCC;
|
||||||
mfxU16 surfaces_num = req->NumFrameSuggested;
|
mfxU16 surfaces_num = req->NumFrameSuggested;
|
||||||
GList *tmp_list = NULL;
|
GList *tmp_list = NULL;
|
||||||
GList *l;
|
|
||||||
GstMsdkSurface *tmp_surface = NULL;
|
|
||||||
VAStatus va_status;
|
VAStatus va_status;
|
||||||
|
|
||||||
/* MFX_MAKEFOURCC('V','P','8','S') is used for MFX_FOURCC_VP9_SEGMAP surface
|
/* MFX_MAKEFOURCC('V','P','8','S') is used for MFX_FOURCC_VP9_SEGMAP surface
|
||||||
|
@ -210,17 +215,15 @@ gst_msdk_frame_alloc (mfxHDL pthis, mfxFrameAllocRequest * req,
|
||||||
|
|
||||||
gst_msdk_context_add_alloc_response (context, msdk_resp);
|
gst_msdk_context_add_alloc_response (context, msdk_resp);
|
||||||
|
|
||||||
/* We need to put all the buffers back to the pool */
|
g_list_free_full (tmp_list, (GDestroyNotify) gst_msdk_surface_list_free);
|
||||||
for (l = tmp_list; l; l = l->next) {
|
|
||||||
tmp_surface = (GstMsdkSurface *) l->data;
|
|
||||||
gst_buffer_unref (tmp_surface->buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
error_alloc:
|
error_alloc:
|
||||||
g_slice_free1 (surfaces_num * sizeof (mfxMemId), mids);
|
g_slice_free1 (surfaces_num * sizeof (mfxMemId), mids);
|
||||||
g_slice_free (GstMsdkAllocResponse, msdk_resp);
|
g_slice_free (GstMsdkAllocResponse, msdk_resp);
|
||||||
|
if (tmp_list)
|
||||||
|
g_list_free_full (tmp_list, (GDestroyNotify) gst_msdk_surface_list_free);
|
||||||
return MFX_ERR_MEMORY_ALLOC;
|
return MFX_ERR_MEMORY_ALLOC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,6 +625,19 @@ error_create_surface:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_msdk_qdata_free (gpointer data)
|
||||||
|
{
|
||||||
|
mfxFrameSurface1 *mfx_surface = data;
|
||||||
|
|
||||||
|
if (mfx_surface->Data.Locked == 0) {
|
||||||
|
GstMsdkMemoryID *msdk_mid = (GstMsdkMemoryID *) mfx_surface->Data.MemId;
|
||||||
|
|
||||||
|
g_slice_free (GstMsdkMemoryID, msdk_mid);
|
||||||
|
g_slice_free (mfxFrameSurface1, mfx_surface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Currently parameter map_flag is not useful on Linux */
|
/* Currently parameter map_flag is not useful on Linux */
|
||||||
GstMsdkSurface *
|
GstMsdkSurface *
|
||||||
gst_msdk_import_to_msdk_surface (GstBuffer * buf, GstMsdkContext * msdk_context,
|
gst_msdk_import_to_msdk_surface (GstBuffer * buf, GstMsdkContext * msdk_context,
|
||||||
|
@ -633,6 +649,7 @@ gst_msdk_import_to_msdk_surface (GstBuffer * buf, GstMsdkContext * msdk_context,
|
||||||
GstMsdkSurface *msdk_surface = NULL;
|
GstMsdkSurface *msdk_surface = NULL;
|
||||||
mfxFrameSurface1 *mfx_surface = NULL;
|
mfxFrameSurface1 *mfx_surface = NULL;
|
||||||
GstMsdkMemoryID *msdk_mid = NULL;
|
GstMsdkMemoryID *msdk_mid = NULL;
|
||||||
|
GDestroyNotify qdata_destroy = NULL;
|
||||||
|
|
||||||
mem = gst_buffer_peek_memory (buf, 0);
|
mem = gst_buffer_peek_memory (buf, 0);
|
||||||
msdk_surface = g_slice_new0 (GstMsdkSurface);
|
msdk_surface = g_slice_new0 (GstMsdkSurface);
|
||||||
|
@ -662,9 +679,10 @@ gst_msdk_import_to_msdk_surface (GstBuffer * buf, GstMsdkContext * msdk_context,
|
||||||
gst_msdk_set_mfx_frame_info_from_video_info (&frame_info, vinfo);
|
gst_msdk_set_mfx_frame_info_from_video_info (&frame_info, vinfo);
|
||||||
mfx_surface->Info = frame_info;
|
mfx_surface->Info = frame_info;
|
||||||
|
|
||||||
|
qdata_destroy = gst_msdk_qdata_free;
|
||||||
/* Set mfxFrameSurface1 as qdata in buffer */
|
/* Set mfxFrameSurface1 as qdata in buffer */
|
||||||
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (mem),
|
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (mem),
|
||||||
GST_MSDK_FRAME_SURFACE, mfx_surface, NULL);
|
GST_MSDK_FRAME_SURFACE, mfx_surface, qdata_destroy);
|
||||||
|
|
||||||
msdk_surface->surface = mfx_surface;
|
msdk_surface->surface = mfx_surface;
|
||||||
|
|
||||||
|
@ -795,5 +813,6 @@ gst_msdk_get_supported_modifiers (GstMsdkContext * context,
|
||||||
gst_video_format_to_string (format), DRM_FORMAT_MOD_INVALID);
|
gst_video_format_to_string (format), DRM_FORMAT_MOD_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gst_object_unref (display);
|
||||||
g_value_unset (&gmod);
|
g_value_unset (&gmod);
|
||||||
}
|
}
|
||||||
|
|
|
@ -876,6 +876,8 @@ _enc_get_supported_formats_and_profiles (mfxSession * session,
|
||||||
g_strfreev (profs);
|
g_strfreev (profs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_value_unset (&fmts);
|
||||||
|
|
||||||
if (gst_value_list_get_size (supported_fmts) == 0 ||
|
if (gst_value_list_get_size (supported_fmts) == 0 ||
|
||||||
gst_value_list_get_size (supported_profs) == 0)
|
gst_value_list_get_size (supported_profs) == 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -2018,6 +2020,8 @@ gst_msdkcaps_set_strings (GstCaps * caps,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gst_caps_features_free (f);
|
||||||
|
|
||||||
if (!s)
|
if (!s)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
|
|
@ -178,11 +178,12 @@ gst_msdk_context_use_vaapi (GstMsdkContext * context)
|
||||||
}
|
}
|
||||||
|
|
||||||
display_drm = gst_va_display_drm_new_from_path (path);
|
display_drm = gst_va_display_drm_new_from_path (path);
|
||||||
|
g_free (path);
|
||||||
|
|
||||||
if (!display_drm) {
|
if (!display_drm) {
|
||||||
GST_ERROR ("Couldn't create a VA DRM display");
|
GST_ERROR ("Couldn't create a VA DRM display");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
g_free (path);
|
|
||||||
|
|
||||||
priv->display = display_drm;
|
priv->display = display_drm;
|
||||||
|
|
||||||
|
|
|
@ -536,6 +536,7 @@ pad_accept_memory (GstMsdkDec * thiz, const gchar * mem_type, GstCaps ** filter)
|
||||||
gst_video_dma_drm_fourcc_to_string (fourcc, thiz->modifier);
|
gst_video_dma_drm_fourcc_to_string (fourcc, thiz->modifier);
|
||||||
gst_msdkcaps_set_strings (caps, mem_type, "drm-format", drm_str);
|
gst_msdkcaps_set_strings (caps, mem_type, "drm-format", drm_str);
|
||||||
gst_caps_set_simple (caps, "format", G_TYPE_STRING, "DMA_DRM", NULL);
|
gst_caps_set_simple (caps, "format", G_TYPE_STRING, "DMA_DRM", NULL);
|
||||||
|
g_free (drm_str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -598,6 +599,7 @@ gst_msdkdec_fixate_format (GstMsdkDec * thiz, GstCaps * caps,
|
||||||
gchar *drm_str =
|
gchar *drm_str =
|
||||||
gst_video_dma_drm_fourcc_to_string (fourcc, thiz->modifier);
|
gst_video_dma_drm_fourcc_to_string (fourcc, thiz->modifier);
|
||||||
g_value_set_string (&gfmt, drm_str);
|
g_value_set_string (&gfmt, drm_str);
|
||||||
|
g_free (drm_str);
|
||||||
if (!gst_value_can_intersect (&gfmt, drm_fmts))
|
if (!gst_value_can_intersect (&gfmt, drm_fmts))
|
||||||
goto failed;
|
goto failed;
|
||||||
gst_structure_set_value (s, "drm-format", &gfmt);
|
gst_structure_set_value (s, "drm-format", &gfmt);
|
||||||
|
@ -667,6 +669,7 @@ gst_msdkdec_set_src_caps (GstMsdkDec * thiz, gboolean need_allocation)
|
||||||
(GstVaDisplay *) gst_msdk_context_get_va_display (thiz->context);
|
(GstVaDisplay *) gst_msdk_context_get_va_display (thiz->context);
|
||||||
thiz->modifier = gst_va_dmabuf_get_modifier_for_format (display, format,
|
thiz->modifier = gst_va_dmabuf_get_modifier_for_format (display, format,
|
||||||
VA_SURFACE_ATTRIB_USAGE_HINT_DECODER);
|
VA_SURFACE_ATTRIB_USAGE_HINT_DECODER);
|
||||||
|
gst_object_unref (display);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (MFX_VERSION >= 1022)
|
#if (MFX_VERSION >= 1022)
|
||||||
|
@ -694,6 +697,9 @@ gst_msdkdec_set_src_caps (GstMsdkDec * thiz, gboolean need_allocation)
|
||||||
gst_caps_set_value (temp_caps, "width", &v_width);
|
gst_caps_set_value (temp_caps, "width", &v_width);
|
||||||
gst_caps_set_value (temp_caps, "height", &v_height);
|
gst_caps_set_value (temp_caps, "height", &v_height);
|
||||||
|
|
||||||
|
g_value_unset (&v_width);
|
||||||
|
g_value_unset (&v_height);
|
||||||
|
|
||||||
if (gst_caps_is_empty (gst_pad_peer_query_caps (GST_VIDEO_DECODER
|
if (gst_caps_is_empty (gst_pad_peer_query_caps (GST_VIDEO_DECODER
|
||||||
(thiz)->srcpad, temp_caps))) {
|
(thiz)->srcpad, temp_caps))) {
|
||||||
if (!gst_util_fraction_multiply (width, height,
|
if (!gst_util_fraction_multiply (width, height,
|
||||||
|
@ -1173,6 +1179,8 @@ gst_msdkdec_stop (GstVideoDecoder * decoder)
|
||||||
gst_object_unref (thiz->other_pool);
|
gst_object_unref (thiz->other_pool);
|
||||||
thiz->other_pool = NULL;
|
thiz->other_pool = NULL;
|
||||||
}
|
}
|
||||||
|
gst_object_replace ((GstObject **) & thiz->alloc_pool, NULL);
|
||||||
|
|
||||||
gst_video_info_init (&thiz->non_msdk_pool_info);
|
gst_video_info_init (&thiz->non_msdk_pool_info);
|
||||||
|
|
||||||
gst_msdkdec_close_decoder (thiz, TRUE);
|
gst_msdkdec_close_decoder (thiz, TRUE);
|
||||||
|
@ -1757,6 +1765,8 @@ gst_msdk_create_va_pool (GstMsdkDec * thiz, GstVideoInfo * info,
|
||||||
allocator = gst_va_allocator_new (display, formats);
|
allocator = gst_va_allocator_new (display, formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gst_object_unref (display);
|
||||||
|
|
||||||
if (!allocator) {
|
if (!allocator) {
|
||||||
GST_ERROR_OBJECT (thiz, "Failed to create allocator");
|
GST_ERROR_OBJECT (thiz, "Failed to create allocator");
|
||||||
if (formats)
|
if (formats)
|
||||||
|
@ -1852,6 +1862,8 @@ gst_msdkdec_create_buffer_pool (GstMsdkDec * thiz, GstVideoInfo * info,
|
||||||
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
GST_BUFFER_POOL_OPTION_VIDEO_ALIGNMENT);
|
||||||
gst_buffer_pool_config_set_video_alignment (config, &align);
|
gst_buffer_pool_config_set_video_alignment (config, &align);
|
||||||
|
|
||||||
|
gst_caps_unref (caps);
|
||||||
|
|
||||||
if (!gst_buffer_pool_set_config (pool, config))
|
if (!gst_buffer_pool_set_config (pool, config))
|
||||||
goto error_pool_config;
|
goto error_pool_config;
|
||||||
|
|
||||||
|
@ -2075,25 +2087,21 @@ gst_msdkdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query)
|
||||||
gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
|
gst_query_set_nth_allocation_pool (query, 0, pool, size, min_buffers,
|
||||||
max_buffers);
|
max_buffers);
|
||||||
|
|
||||||
gst_caps_unref (pool_caps);
|
|
||||||
gst_object_unref (pool);
|
gst_object_unref (pool);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
failed_to_parse_caps:
|
failed_to_parse_caps:
|
||||||
GST_ERROR_OBJECT (decoder, "failed to set buffer pool config");
|
GST_ERROR_OBJECT (decoder, "failed to set buffer pool config");
|
||||||
gst_caps_unref (pool_caps);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
failed_to_create_pool:
|
failed_to_create_pool:
|
||||||
GST_ERROR_OBJECT (decoder, "failed to set buffer pool config");
|
GST_ERROR_OBJECT (decoder, "failed to set buffer pool config");
|
||||||
gst_caps_unref (pool_caps);
|
|
||||||
gst_object_unref (pool);
|
gst_object_unref (pool);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
error_set_config:
|
error_set_config:
|
||||||
GST_ERROR_OBJECT (decoder, "failed to set buffer pool config");
|
GST_ERROR_OBJECT (decoder, "failed to set buffer pool config");
|
||||||
gst_caps_unref (pool_caps);
|
|
||||||
gst_object_unref (pool);
|
gst_object_unref (pool);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1186,6 +1186,8 @@ gst_msdk_create_va_pool (GstMsdkEnc * thiz, GstVideoInfo * info,
|
||||||
allocator = gst_va_allocator_new (display, formats);
|
allocator = gst_va_allocator_new (display, formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gst_object_unref (display);
|
||||||
|
|
||||||
if (!allocator) {
|
if (!allocator) {
|
||||||
GST_ERROR_OBJECT (thiz, "failed to create allocator");
|
GST_ERROR_OBJECT (thiz, "failed to create allocator");
|
||||||
if (formats)
|
if (formats)
|
||||||
|
|
|
@ -413,6 +413,9 @@ gst_msdk_create_va_pool (GstMsdkVPP * thiz, GstVideoInfo * info,
|
||||||
}
|
}
|
||||||
allocator = gst_va_allocator_new (display, formats);
|
allocator = gst_va_allocator_new (display, formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gst_object_unref (display);
|
||||||
|
|
||||||
if (!allocator) {
|
if (!allocator) {
|
||||||
GST_ERROR ("Failed to create allocator");
|
GST_ERROR ("Failed to create allocator");
|
||||||
if (formats)
|
if (formats)
|
||||||
|
|
Loading…
Reference in a new issue