From 098b42f36b9ab0a41be5d35f076dd2a335a3b2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 22 Dec 2014 11:33:14 +0100 Subject: [PATCH] video{en,de}coder: Reset the codec after calling the stop() vfunc The stop() vfunc might mess with some of our fields we have just reset, which could cause memory leaks or invalid state taken over to later. Also the stop() vfunc, or anything called until it from another thread, might want to be able to use the fields that were just resetted and become confused because of that. In the decoder we already had a workaround for things like this happening, this workaround is not needed anymore. --- gst-libs/gst/video/gstvideodecoder.c | 15 +++------------ gst-libs/gst/video/gstvideoencoder.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/gst-libs/gst/video/gstvideodecoder.c b/gst-libs/gst/video/gstvideodecoder.c index ecd7c2fc2f..74717baf3c 100644 --- a/gst-libs/gst/video/gstvideodecoder.c +++ b/gst-libs/gst/video/gstvideodecoder.c @@ -2292,22 +2292,13 @@ gst_video_decoder_change_state (GstElement * element, GstStateChange transition) case GST_STATE_CHANGE_PAUSED_TO_READY:{ gboolean stopped = TRUE; + if (decoder_class->stop) + stopped = decoder_class->stop (decoder); + GST_VIDEO_DECODER_STREAM_LOCK (decoder); gst_video_decoder_reset (decoder, TRUE, TRUE); GST_VIDEO_DECODER_STREAM_UNLOCK (decoder); - if (decoder_class->stop) { - stopped = decoder_class->stop (decoder); - - /* the subclass might have released frames and events from freed frames - * are stored in the pending_events list */ - GST_VIDEO_DECODER_STREAM_LOCK (decoder); - g_list_free_full (decoder->priv->pending_events, (GDestroyNotify) - gst_event_unref); - decoder->priv->pending_events = NULL; - GST_VIDEO_DECODER_STREAM_UNLOCK (decoder); - } - if (!stopped) goto stop_failed; diff --git a/gst-libs/gst/video/gstvideoencoder.c b/gst-libs/gst/video/gstvideoencoder.c index 6fc807fc5b..5028ccf296 100644 --- a/gst-libs/gst/video/gstvideoencoder.c +++ b/gst-libs/gst/video/gstvideoencoder.c @@ -1425,13 +1425,20 @@ gst_video_encoder_change_state (GstElement * element, GstStateChange transition) ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); switch (transition) { - case GST_STATE_CHANGE_PAUSED_TO_READY: + case GST_STATE_CHANGE_PAUSED_TO_READY:{ + gboolean stopped = TRUE; + + if (encoder_class->stop) + stopped = encoder_class->stop (encoder); + GST_VIDEO_ENCODER_STREAM_LOCK (encoder); gst_video_encoder_reset (encoder, TRUE); GST_VIDEO_ENCODER_STREAM_UNLOCK (encoder); - if (encoder_class->stop && !encoder_class->stop (encoder)) + + if (!stopped) goto stop_failed; break; + } case GST_STATE_CHANGE_READY_TO_NULL: /* close device/library if needed */ if (encoder_class->close && !encoder_class->close (encoder))