mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 00:36:51 +00:00
av: Fix some memory leaks and misuse of libav API
This commit is contained in:
parent
d69dda0391
commit
022ab84288
7 changed files with 18 additions and 45 deletions
|
@ -158,15 +158,11 @@ gst_ffmpegauddec_finalize (GObject * object)
|
|||
static void
|
||||
gst_ffmpegauddec_close (GstFFMpegAudDec * ffmpegdec)
|
||||
{
|
||||
if (!ffmpegdec->opened)
|
||||
return;
|
||||
|
||||
GST_LOG_OBJECT (ffmpegdec, "closing libav codec");
|
||||
|
||||
gst_caps_replace (&ffmpegdec->last_caps, NULL);
|
||||
gst_buffer_replace (&ffmpegdec->outbuf, NULL);
|
||||
|
||||
if (ffmpegdec->opened)
|
||||
gst_ffmpeg_avcodec_close (ffmpegdec->context);
|
||||
ffmpegdec->opened = FALSE;
|
||||
|
||||
|
@ -297,9 +293,6 @@ gst_ffmpegauddec_set_format (GstAudioDecoder * decoder, GstCaps * caps)
|
|||
gst_ffmpegauddec_drain (ffmpegdec);
|
||||
GST_OBJECT_LOCK (ffmpegdec);
|
||||
gst_ffmpegauddec_close (ffmpegdec);
|
||||
|
||||
/* and reset the defaults that were set when a context is created */
|
||||
avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin);
|
||||
}
|
||||
|
||||
/* get size and so */
|
||||
|
|
|
@ -192,10 +192,8 @@ gst_ffmpegaudenc_stop (GstAudioEncoder * encoder)
|
|||
GstFFMpegAudEnc *ffmpegaudenc = (GstFFMpegAudEnc *) encoder;
|
||||
|
||||
/* close old session */
|
||||
if (ffmpegaudenc->opened) {
|
||||
gst_ffmpeg_avcodec_close (ffmpegaudenc->context);
|
||||
ffmpegaudenc->opened = FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -243,9 +241,6 @@ gst_ffmpegaudenc_set_format (GstAudioEncoder * encoder, GstAudioInfo * info)
|
|||
ffmpegaudenc->opened = FALSE;
|
||||
}
|
||||
|
||||
/* set defaults */
|
||||
avcodec_get_context_defaults3 (ffmpegaudenc->context, oclass->in_plugin);
|
||||
|
||||
/* if we set it in _getcaps we should set it also in _link */
|
||||
ffmpegaudenc->context->strict_std_compliance = -1;
|
||||
|
||||
|
|
|
@ -738,10 +738,8 @@ gst_ffmpeg_cfg_install_property (GstFFMpegVidEncClass * klass, guint base)
|
|||
prop_id = base;
|
||||
g_return_if_fail (base > 0);
|
||||
|
||||
ctx = avcodec_alloc_context3 (NULL);
|
||||
if (ctx)
|
||||
avcodec_get_context_defaults3 (ctx, NULL);
|
||||
else
|
||||
ctx = avcodec_alloc_context3 (klass->in_plugin);
|
||||
if (!ctx)
|
||||
g_warning ("could not get context");
|
||||
|
||||
for (list = property_list; list; list = list->next) {
|
||||
|
|
|
@ -336,7 +336,11 @@ gst_ffmpegdemux_close (GstFFMpegDemux * demux)
|
|||
gst_ffmpegdata_close (demux->context->pb);
|
||||
else
|
||||
gst_ffmpeg_pipe_close (demux->context->pb);
|
||||
demux->context->pb = NULL;
|
||||
avformat_close_input (&demux->context);
|
||||
if (demux->context)
|
||||
avformat_free_context (demux->context);
|
||||
demux->context = NULL;
|
||||
|
||||
GST_OBJECT_LOCK (demux);
|
||||
demux->opened = FALSE;
|
||||
|
|
|
@ -324,7 +324,7 @@ gst_ffmpegmux_init (GstFFMpegMux * ffmpegmux, GstFFMpegMuxClass * g_class)
|
|||
gst_collect_pads_set_function (ffmpegmux->collect,
|
||||
(GstCollectPadsFunction) gst_ffmpegmux_collected, ffmpegmux);
|
||||
|
||||
ffmpegmux->context = g_new0 (AVFormatContext, 1);
|
||||
ffmpegmux->context = avformat_alloc_context ();
|
||||
ffmpegmux->context->oformat = oclass->in_plugin;
|
||||
ffmpegmux->context->nb_streams = 0;
|
||||
ffmpegmux->opened = FALSE;
|
||||
|
@ -382,7 +382,9 @@ gst_ffmpegmux_finalize (GObject * object)
|
|||
{
|
||||
GstFFMpegMux *ffmpegmux = (GstFFMpegMux *) object;
|
||||
|
||||
g_free (ffmpegmux->context);
|
||||
avformat_free_context (ffmpegmux->context);
|
||||
ffmpegmux->context = NULL;
|
||||
|
||||
gst_object_unref (ffmpegmux->collect);
|
||||
|
||||
if (G_OBJECT_CLASS (parent_class)->finalize)
|
||||
|
|
|
@ -268,10 +268,7 @@ gst_ffmpegviddec_finalize (GObject * object)
|
|||
ffmpegdec->context = NULL;
|
||||
}
|
||||
|
||||
if (ffmpegdec->picture != NULL) {
|
||||
av_free (ffmpegdec->picture);
|
||||
ffmpegdec->picture = NULL;
|
||||
}
|
||||
avcodec_free_frame (&ffmpegdec->picture);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
@ -281,9 +278,6 @@ gst_ffmpegviddec_finalize (GObject * object)
|
|||
static void
|
||||
gst_ffmpegviddec_close (GstFFMpegVidDec * ffmpegdec)
|
||||
{
|
||||
if (!ffmpegdec->opened)
|
||||
return;
|
||||
|
||||
GST_LOG_OBJECT (ffmpegdec, "closing ffmpeg codec");
|
||||
|
||||
gst_caps_replace (&ffmpegdec->last_caps, NULL);
|
||||
|
@ -393,9 +387,6 @@ gst_ffmpegviddec_set_format (GstVideoDecoder * decoder,
|
|||
gst_ffmpegviddec_drain (ffmpegdec);
|
||||
GST_OBJECT_LOCK (ffmpegdec);
|
||||
gst_ffmpegviddec_close (ffmpegdec);
|
||||
|
||||
/* and reset the defaults that were set when a context is created */
|
||||
avcodec_get_context_defaults3 (ffmpegdec->context, oclass->in_plugin);
|
||||
}
|
||||
|
||||
/* set buffer functions */
|
||||
|
|
|
@ -253,15 +253,9 @@ gst_ffmpegvidenc_finalize (GObject * object)
|
|||
|
||||
gst_ffmpeg_cfg_finalize (ffmpegenc);
|
||||
|
||||
/* close old session */
|
||||
if (ffmpegenc->opened) {
|
||||
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||
ffmpegenc->opened = FALSE;
|
||||
}
|
||||
|
||||
/* clean up remaining allocated data */
|
||||
av_free (ffmpegenc->context);
|
||||
av_free (ffmpegenc->picture);
|
||||
avcodec_free_frame (&ffmpegenc->picture);
|
||||
|
||||
g_free (ffmpegenc->filename);
|
||||
|
||||
|
@ -300,9 +294,6 @@ gst_ffmpegvidenc_set_format (GstVideoEncoder * encoder,
|
|||
ffmpegenc->opened = FALSE;
|
||||
}
|
||||
|
||||
/* set defaults */
|
||||
avcodec_get_context_defaults3 (ffmpegenc->context, oclass->in_plugin);
|
||||
|
||||
/* if we set it in _getcaps we should set it also in _link */
|
||||
ffmpegenc->context->strict_std_compliance = -1;
|
||||
|
||||
|
@ -808,10 +799,9 @@ gst_ffmpegvidenc_stop (GstVideoEncoder * encoder)
|
|||
GstFFMpegVidEnc *ffmpegenc = (GstFFMpegVidEnc *) encoder;
|
||||
|
||||
gst_ffmpegvidenc_flush_buffers (ffmpegenc, FALSE);
|
||||
if (ffmpegenc->opened) {
|
||||
gst_ffmpeg_avcodec_close (ffmpegenc->context);
|
||||
ffmpegenc->opened = FALSE;
|
||||
}
|
||||
|
||||
if (ffmpegenc->file) {
|
||||
fclose (ffmpegenc->file);
|
||||
ffmpegenc->file = NULL;
|
||||
|
|
Loading…
Reference in a new issue