video{en,de}coder: Add new flush vfunc as a replacement for reset
authorSebastian Dröge <slomo@circular-chaos.org>
Thu, 15 Aug 2013 10:44:56 +0000 (12:44 +0200)
committerSebastian Dröge <slomo@circular-chaos.org>
Thu, 15 Aug 2013 11:26:39 +0000 (13:26 +0200)
gst-libs/gst/video/gstvideodecoder.c
gst-libs/gst/video/gstvideodecoder.h
gst-libs/gst/video/gstvideoencoder.c
gst-libs/gst/video/gstvideoencoder.h

index 8bbad996fc4d21b3983830fbae4ef18ca237d6ce..6d3f3b5388acf3c1fe083693164e37c5f4b3d4c1 100644 (file)
@@ -864,13 +864,11 @@ gst_video_decoder_flush (GstVideoDecoder * dec, gboolean hard)
     klass->reset (dec, hard);
   }
 
-  /* FIXME make some more distinction between hard and soft,
-   * but subclass may not be prepared for that */
-  /* FIXME perhaps also clear pending frames ?,
-   * but again, subclass may still come up with one of those */
-  if (!hard) {
-    /* TODO ? finish/drain some stuff */
-  } else {
+  if (klass->flush) {
+    klass->flush (dec);
+  }
+
+  if (hard) {
     gst_segment_init (&dec->input_segment, GST_FORMAT_UNDEFINED);
     gst_segment_init (&dec->output_segment, GST_FORMAT_UNDEFINED);
     gst_video_decoder_clear_queues (dec);
index 2c30805bfc176763b6de4489675c1f797373a616..7c16c0ea098cb0154754240644919a9a99f8f0e2 100644 (file)
@@ -242,6 +242,9 @@ struct _GstVideoDecoder
  *                      Propose buffer allocation parameters for upstream elements.
  *                      Subclasses should chain up to the parent implementation to
  *                      invoke the default handler.
+ * @flush:              Optional.
+ *                      Flush all remaining data from the decoder without
+ *                      pushing it downstream. Since: 1.2
  *
  * Subclasses can override any of the available virtual methods or not, as
  * needed. At minimum @handle_frame needs to be overridden, and @set_format
@@ -290,8 +293,10 @@ struct _GstVideoDecoderClass
 
   gboolean      (*propose_allocation) (GstVideoDecoder *decoder, GstQuery * query);
 
+  gboolean      (*flush)              (GstVideoDecoder *decoder);
+
   /*< private >*/
-  void         *padding[GST_PADDING_LARGE];
+  void         *padding[GST_PADDING_LARGE-1];
 };
 
 GType    gst_video_decoder_get_type (void);
index 1d758846c23eb6fac548607a71fbe25371f9b672..6bc476b382ee044ada0fdce243b3fb717194c65c 100644 (file)
@@ -298,7 +298,6 @@ gst_video_encoder_class_init (GstVideoEncoderClass * klass)
 static gboolean
 gst_video_encoder_reset (GstVideoEncoder * encoder, gboolean hard)
 {
-  GstVideoEncoderClass *klass = GST_VIDEO_ENCODER_GET_CLASS (encoder);
   GstVideoEncoderPrivate *priv = encoder->priv;
   gboolean ret = TRUE;
 
@@ -355,6 +354,21 @@ gst_video_encoder_reset (GstVideoEncoder * encoder, gboolean hard)
   return ret;
 }
 
+/* Always call reset() in one way or another after this */
+static gboolean
+gst_video_encoder_flush (GstVideoEncoder * encoder)
+{
+  GstVideoEncoderClass *klass = GST_VIDEO_ENCODER_GET_CLASS (encoder);
+  gboolean ret = TRUE;
+
+  GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
+  if (klass->flush)
+    ret = klass->flush (encoder);
+
+  GST_VIDEO_ENCODER_STREAM_UNLOCK (encoder);
+  return ret;
+}
+
 static void
 gst_video_encoder_init (GstVideoEncoder * encoder, GstVideoEncoderClass * klass)
 {
@@ -1000,6 +1014,7 @@ gst_video_encoder_sink_event_default (GstVideoEncoder * encoder,
     }
     case GST_EVENT_FLUSH_STOP:{
       GST_VIDEO_ENCODER_STREAM_LOCK (encoder);
+      gst_video_encoder_flush (encoder);
       gst_segment_init (&encoder->input_segment, GST_FORMAT_TIME);
       gst_segment_init (&encoder->output_segment, GST_FORMAT_TIME);
       gst_video_encoder_reset (encoder, FALSE);
index 30515753797c749dd123490c4e096c32bbf0646d..7d49173436b6073bcb61aebf275d0f4a50aa45b1 100644 (file)
@@ -211,6 +211,9 @@ struct _GstVideoEncoder
  *                      Propose buffer allocation parameters for upstream elements.
  *                      Subclasses should chain up to the parent implementation to
  *                      invoke the default handler.
+ * @flush:              Optional.
+ *                      Flush all remaining data from the encoder without
+ *                      pushing it downstream. Since: 1.2
  *
  * Subclasses can override any of the available virtual methods or not, as
  * needed. At minimum @handle_frame needs to be overridden, and @set_format
@@ -260,9 +263,10 @@ struct _GstVideoEncoderClass
 
   gboolean      (*propose_allocation) (GstVideoEncoder * encoder,
                                        GstQuery * query);
+  gboolean      (*flush)              (GstVideoEncoder *encoder);
 
   /*< private >*/
-  gpointer       _gst_reserved[GST_PADDING_LARGE];
+  gpointer       _gst_reserved[GST_PADDING_LARGE-1];
 };
 
 GType                gst_video_encoder_get_type (void);