imagefreeze: Always generate a perfectly timestamped stream

Before there could be rounding errors when calculating the duration,
resulting in timestamp + duration being smaller than the next buffer's
timestamp.
This commit is contained in:
Sebastian Dröge 2010-08-20 09:14:59 +02:00
parent 998adeb974
commit d8ef9bb691

View file

@ -717,7 +717,7 @@ gst_image_freeze_src_loop (GstPad * pad)
GstImageFreeze *self = GST_IMAGE_FREEZE (GST_PAD_PARENT (pad)); GstImageFreeze *self = GST_IMAGE_FREEZE (GST_PAD_PARENT (pad));
GstBuffer *buffer; GstBuffer *buffer;
guint64 offset; guint64 offset;
GstClockTime timestamp, duration; GstClockTime timestamp, timestamp_end, duration;
gint64 cstart, cstop; gint64 cstart, cstop;
gboolean in_seg, eos; gboolean in_seg, eos;
@ -770,24 +770,28 @@ gst_image_freeze_src_loop (GstPad * pad)
if (self->fps_n != 0) { if (self->fps_n != 0) {
timestamp = timestamp =
gst_util_uint64_scale (offset, self->fps_d * GST_SECOND, self->fps_n); gst_util_uint64_scale (offset, self->fps_d * GST_SECOND, self->fps_n);
duration = gst_util_uint64_scale_int (GST_SECOND, self->fps_d, self->fps_n); timestamp_end =
gst_util_uint64_scale (offset + 1, self->fps_d * GST_SECOND,
self->fps_n);
duration = timestamp_end - timestamp;
} else { } else {
timestamp = self->segment.start; timestamp = self->segment.start;
timestamp_end = GST_CLOCK_TIME_NONE;
duration = GST_CLOCK_TIME_NONE; duration = GST_CLOCK_TIME_NONE;
} }
eos = (self->fps_n == 0 && offset > 0) || eos = (self->fps_n == 0 && offset > 0) ||
(self->segment.rate >= 0 && self->segment.stop != -1 (self->segment.rate >= 0 && self->segment.stop != -1
&& timestamp > self->segment.stop) || (self->segment.rate < 0 && timestamp > self->segment.stop) || (self->segment.rate < 0
&& offset == 0) || (self->segment.rate < 0 && offset == 0) || (self->segment.rate < 0
&& self->segment.start != -1 && self->segment.start != -1 && timestamp_end < self->segment.start);
&& timestamp + duration < self->segment.start);
if (self->fps_n == 0 && offset > 0) if (self->fps_n == 0 && offset > 0)
in_seg = FALSE; in_seg = FALSE;
else else
in_seg = in_seg =
gst_segment_clip (&self->segment, GST_FORMAT_TIME, timestamp, gst_segment_clip (&self->segment, GST_FORMAT_TIME, timestamp,
timestamp + duration, &cstart, &cstop); timestamp_end, &cstart, &cstop);
if (in_seg) if (in_seg)
gst_segment_set_last_stop (&self->segment, GST_FORMAT_TIME, cstart); gst_segment_set_last_stop (&self->segment, GST_FORMAT_TIME, cstart);