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 8bbad99..6d3f3b5 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 2c30805..7c16c0e 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 1d75884..6bc476b 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 3051575..7d49173 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);