msdk: free mfx frames to avoid memory leaks in encoder and vpp

This commit is contained in:
Haihao Xiang 2019-08-21 12:45:37 +08:00 committed by Víctor Manuel Jáquez Leal
parent 2d4b0a5649
commit 38c55de132
2 changed files with 17 additions and 3 deletions

View file

@ -359,7 +359,7 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz)
if (status < MFX_ERR_NONE) {
GST_ERROR_OBJECT (thiz, "Init failed (%s)",
msdk_status_to_string (status));
goto no_vpp;
goto no_vpp_free_resource;
} else if (status > MFX_ERR_NONE) {
GST_WARNING_OBJECT (thiz, "Init returned: %s",
msdk_status_to_string (status));
@ -375,7 +375,7 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz)
GST_WARNING_OBJECT (thiz, "VPP close failed (%s)",
msdk_status_to_string (status1));
goto no_vpp;
goto no_vpp_free_resource;
} else if (status > MFX_ERR_NONE) {
GST_WARNING_OBJECT (thiz, "Get VPP Parameters returned: %s",
msdk_status_to_string (status));
@ -529,6 +529,9 @@ gst_msdkenc_init_encoder (GstMsdkEnc * thiz)
return TRUE;
no_vpp_free_resource:
if (thiz->use_video_memory)
gst_msdk_frame_free (thiz->context, &thiz->vpp_alloc_resp);
no_vpp:
failed:
GST_OBJECT_UNLOCK (thiz);

View file

@ -804,6 +804,11 @@ gst_msdkvpp_close (GstMsdkVPP * thiz)
if (!thiz->context)
return;
if (thiz->use_video_memory) {
gst_msdk_frame_free (thiz->context, &thiz->in_alloc_resp);
gst_msdk_frame_free (thiz->context, &thiz->out_alloc_resp);
}
GST_DEBUG_OBJECT (thiz, "Closing VPP 0x%p", thiz->context);
status = MFXVideoVPP_Close (gst_msdk_context_get_session (thiz->context));
if (status != MFX_ERR_NONE && status != MFX_ERR_NOT_INITIALIZED) {
@ -956,8 +961,14 @@ gst_msdkvpp_initialize (GstMsdkVPP * thiz)
* otherwise the subsequent function call of MFXVideoVPP_Init() will
* fail
*/
if (thiz->initialized)
if (thiz->initialized) {
if (thiz->use_video_memory) {
gst_msdk_frame_free (thiz->context, &thiz->in_alloc_resp);
gst_msdk_frame_free (thiz->context, &thiz->out_alloc_resp);
}
MFXVideoVPP_Close (session);
}
if (thiz->use_video_memory) {
gst_msdk_set_frame_allocator (thiz->context);