codecs: mpeg2decoder: Move frame_unref to handle_frame.
authorHe Junyan <junyan.he@intel.com>
Thu, 11 Feb 2021 08:04:12 +0000 (16:04 +0800)
committerHe Junyan <junyan.he@intel.com>
Thu, 11 Feb 2021 08:18:29 +0000 (16:18 +0800)
In the current code, we call frame_unref only when the frame is
outputted. This is OK for normal playback, but when seek happens,
the frames stored in DPB is not outputted and causes some memory
leak.
The correct way is that we should call frame_unref every time we
finish the handle_frame(), which is also the behaviour of H264/H265
decoder.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2014>

gst-libs/gst/codecs/gstmpeg2decoder.c

index 18b11ed..d9c2753 100644 (file)
@@ -1053,8 +1053,6 @@ gst_mpeg2_decoder_do_output_picture (GstMpeg2Decoder * decoder,
       GST_TIME_ARGS (frame->pts));
   ret = klass->output_picture (decoder, frame, to_output);
 
-  gst_video_codec_frame_unref (frame);
-
   return ret;
 }
 
@@ -1159,6 +1157,7 @@ gst_mpeg2_decoder_handle_frame (GstVideoDecoder * decoder,
   ret = gst_mpeg2_decoder_output_current_picture (self);
   gst_mpeg2_picture_clear (&priv->current_picture);
   gst_mpeg2_picture_clear (&priv->first_field);
+  gst_video_codec_frame_unref (priv->current_frame);
   priv->current_frame = NULL;
   return ret;