From c0d778c2c7a5075f8a26145f9fa3cabd1e6a78e3 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 17 Jan 2020 13:45:35 +0530 Subject: [PATCH] msdk: Use gst_clear_object() `gst_object_replace()` is not supposed to be used for unreffing and NULLing objects. --- sys/msdk/gstmsdkdec.c | 9 ++++----- sys/msdk/gstmsdkenc.c | 12 ++++++------ sys/msdk/gstmsdkvpp.c | 14 ++++---------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/sys/msdk/gstmsdkdec.c b/sys/msdk/gstmsdkdec.c index 5296ad5..6efa1a8 100644 --- a/sys/msdk/gstmsdkdec.c +++ b/sys/msdk/gstmsdkdec.c @@ -761,8 +761,7 @@ gst_msdkdec_close (GstVideoDecoder * decoder) { GstMsdkDec *thiz = GST_MSDKDEC (decoder); - if (thiz->context) - gst_object_replace ((GstObject **) & thiz->context, NULL); + gst_clear_object (&thiz->context); return TRUE; } @@ -1375,8 +1374,7 @@ gst_msdkdec_decide_allocation (GstVideoDecoder * decoder, GstQuery * query) if (thiz->do_realloc || !thiz->pool) { GstVideoCodecState *output_state = gst_video_decoder_get_output_state (GST_VIDEO_DECODER (thiz)); - if (thiz->pool) - gst_object_replace ((GstObject **) & thiz->pool, NULL); + gst_clear_object (&thiz->pool); GST_INFO_OBJECT (decoder, "create new MSDK bufferpool"); thiz->pool = gst_msdkdec_create_buffer_pool (thiz, &output_state->info, min_buffers); @@ -1612,7 +1610,8 @@ gst_msdkdec_finalize (GObject * object) GstMsdkDec *thiz = GST_MSDKDEC (object); g_array_unref (thiz->tasks); - g_object_unref (thiz->adapter); + thiz->tasks = NULL; + g_clear_object (&thiz->adapter); /* NULL is the empty list. */ if (G_UNLIKELY (thiz->decoded_msdk_surfaces != NULL)) { diff --git a/sys/msdk/gstmsdkenc.c b/sys/msdk/gstmsdkenc.c index 8570285..943ae1d 100644 --- a/sys/msdk/gstmsdkenc.c +++ b/sys/msdk/gstmsdkenc.c @@ -700,8 +700,8 @@ gst_msdkenc_close_encoder (GstMsdkEnc * thiz) GST_DEBUG_OBJECT (thiz, "Closing encoder with context %" GST_PTR_FORMAT, thiz->context); - gst_object_replace ((GstObject **) & thiz->msdk_pool, NULL); - gst_object_replace ((GstObject **) & thiz->msdk_converted_pool, NULL); + gst_clear_object (&thiz->msdk_pool); + gst_clear_object (&thiz->msdk_converted_pool); if (thiz->use_video_memory) gst_msdk_frame_free (thiz->context, &thiz->alloc_resp); @@ -1295,7 +1295,7 @@ gst_msdkenc_set_format (GstVideoEncoder * encoder, GstVideoCodecState * state) goto done; } /* Release current pool because we are going to create a new one */ - gst_object_replace ((GstObject **) & thiz->msdk_converted_pool, NULL); + gst_clear_object (&thiz->msdk_converted_pool); } /* Otherwise create a new pool */ @@ -1662,7 +1662,7 @@ gst_msdkenc_stop (GstVideoEncoder * encoder) gst_video_codec_state_unref (thiz->input_state); thiz->input_state = NULL; - gst_object_replace ((GstObject **) & thiz->context, NULL); + gst_clear_object (&thiz->context); return TRUE; } @@ -1760,8 +1760,8 @@ gst_msdkenc_finalize (GObject * object) gst_video_codec_state_unref (thiz->input_state); thiz->input_state = NULL; - gst_object_replace ((GstObject **) & thiz->msdk_pool, NULL); - gst_object_replace ((GstObject **) & thiz->msdk_converted_pool, NULL); + gst_clear_object (&thiz->msdk_pool); + gst_clear_object (&thiz->msdk_converted_pool); G_OBJECT_CLASS (parent_class)->finalize (object); } diff --git a/sys/msdk/gstmsdkvpp.c b/sys/msdk/gstmsdkvpp.c index 23c2dbc..b39d133 100644 --- a/sys/msdk/gstmsdkvpp.c +++ b/sys/msdk/gstmsdkvpp.c @@ -850,17 +850,12 @@ gst_msdkvpp_close (GstMsdkVPP * thiz) msdk_status_to_string (status)); } - if (thiz->context) - gst_object_replace ((GstObject **) & thiz->context, NULL); + gst_clear_object (&thiz->context); memset (&thiz->param, 0, sizeof (thiz->param)); - if (thiz->sinkpad_buffer_pool) - gst_object_unref (thiz->sinkpad_buffer_pool); - thiz->sinkpad_buffer_pool = NULL; - if (thiz->srcpad_buffer_pool) - gst_object_unref (thiz->srcpad_buffer_pool); - thiz->srcpad_buffer_pool = NULL; + gst_clear_object (&thiz->sinkpad_buffer_pool); + gst_clear_object (&thiz->srcpad_buffer_pool); thiz->buffer_duration = GST_CLOCK_TIME_NONE; gst_video_info_init (&thiz->sinkpad_info); @@ -1105,8 +1100,7 @@ gst_msdkvpp_initialize (GstMsdkVPP * thiz) no_vpp: GST_OBJECT_UNLOCK (thiz); - if (thiz->context) - gst_object_replace ((GstObject **) & thiz->context, NULL); + gst_clear_object (&thiz->context); return FALSE; } -- 2.7.4