msdk: Use gst_clear_object()
authorNirbheek Chauhan <nirbheek@centricular.com>
Fri, 17 Jan 2020 08:15:35 +0000 (13:45 +0530)
committerHaihao Xiang <haihao.xiang@intel.com>
Tue, 21 Jan 2020 00:38:41 +0000 (00:38 +0000)
`gst_object_replace()` is not supposed to be used for unreffing and
NULLing objects.

sys/msdk/gstmsdkdec.c
sys/msdk/gstmsdkenc.c
sys/msdk/gstmsdkvpp.c

index 5296ad5..6efa1a8 100644 (file)
@@ -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)) {
index 8570285..943ae1d 100644 (file)
@@ -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);
 }
index 23c2dbc..b39d133 100644 (file)
@@ -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;
 }