From 866f132821086359c699f0058b73b4e12e1dc2f6 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Tue, 8 Oct 2013 00:08:34 -0300 Subject: [PATCH] videotestsrc: implement reverse playback 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 | 18 ++++++++++++++++-- gst/videotestsrc/gstvideotestsrc.h | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/gst/videotestsrc/gstvideotestsrc.c b/gst/videotestsrc/gstvideotestsrc.c index b180a7e871..87e00ebba3 100644 --- a/gst/videotestsrc/gstvideotestsrc.c +++ b/gst/videotestsrc/gstvideotestsrc.c @@ -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 */ diff --git a/gst/videotestsrc/gstvideotestsrc.h b/gst/videotestsrc/gstvideotestsrc.h index 39ec442127..468aad7c95 100644 --- a/gst/videotestsrc/gstvideotestsrc.h +++ b/gst/videotestsrc/gstvideotestsrc.h @@ -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 */