videotestsrc: implement reverse playback
authorThiago Santos <ts.santos@partner.samsung.com>
Tue, 8 Oct 2013 03:08:34 +0000 (00:08 -0300)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Tue, 8 Oct 2013 13:34:47 +0000 (09:34 -0400)
Decrement the n_frames counter when doing reverse playback to
have timestamps and offsets reducing instead of increasing

https://bugzilla.gnome.org/show_bug.cgi?id=701813

gst/videotestsrc/gstvideotestsrc.c
gst/videotestsrc/gstvideotestsrc.h

index b180a7e..87e00eb 100644 (file)
@@ -813,6 +813,7 @@ gst_video_test_src_do_seek (GstBaseSrc * bsrc, GstSegment * segment)
 
   segment->time = segment->start;
   position = segment->position;
+  src->reverse = segment->rate < 0;
 
   /* now move to the position indicated */
   if (src->info.fps_n) {
@@ -862,6 +863,11 @@ gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
   if (G_UNLIKELY (src->info.fps_n == 0 && src->n_frames == 1))
     goto eos;
 
+  if (G_UNLIKELY (src->n_frames == -1)) {
+    /* EOS for reverse playback */
+    goto eos;
+  }
+
   GST_LOG_OBJECT (src,
       "creating buffer from pool for frame %d", (gint) src->n_frames);
 
@@ -890,12 +896,20 @@ gst_video_test_src_fill (GstPushSrc * psrc, GstBuffer * buffer)
       GST_TIME_ARGS (src->timestamp_offset), GST_TIME_ARGS (src->running_time));
 
   GST_BUFFER_OFFSET (buffer) = src->accum_frames + src->n_frames;
-  src->n_frames++;
+  if (src->reverse) {
+    src->n_frames--;
+  } else {
+    src->n_frames++;
+  }
   GST_BUFFER_OFFSET_END (buffer) = GST_BUFFER_OFFSET (buffer) + 1;
   if (src->info.fps_n) {
     next_time = gst_util_uint64_scale_int (src->n_frames * GST_SECOND,
         src->info.fps_d, src->info.fps_n);
-    GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
+    if (src->reverse) {
+      GST_BUFFER_DURATION (buffer) = src->running_time - next_time;
+    } else {
+      GST_BUFFER_DURATION (buffer) = next_time - src->running_time;
+    }
   } else {
     next_time = src->timestamp_offset;
     /* NONE means forever */
index 39ec442..468aad7 100644 (file)
@@ -139,6 +139,7 @@ struct _GstVideoTestSrc {
   /* running time and frames for current caps */
   GstClockTime running_time;            /* total running time */
   gint64 n_frames;                      /* total frames sent */
+  gboolean reverse;
 
   /* previous caps running time and frames */
   GstClockTime accum_rtime;              /* accumulated running_time */