if (G_LIKELY (ret == GST_FLOW_OK && *buf)) {
GstClock *clock;
GstClockTime timestamp;
- GstClockTime duration = GST_CLOCK_TIME_NONE;
GST_BUFFER_OFFSET (*buf) = v4l2src->offset++;
GST_BUFFER_OFFSET_END (*buf) = v4l2src->offset;
}
GST_OBJECT_UNLOCK (v4l2src);
- if (clock) {
+ if (G_LIKELY (clock)) {
/* the time now is the time of the clock minus the base time */
timestamp = gst_clock_get_time (clock) - timestamp;
gst_object_unref (clock);
/* if we have a framerate adjust timestamp for frame latency */
- if (v4l2src->fps_n > 0 && v4l2src->fps_d > 0) {
- GstClockTime latency;
-
- latency = gst_util_uint64_scale_int (GST_SECOND, v4l2src->fps_d,
- v4l2src->fps_n);
-
- if (timestamp > latency)
- timestamp -= latency;
+ if (GST_CLOCK_TIME_IS_VALID (v4l2src->duration)) {
+ if (timestamp > v4l2src->duration)
+ timestamp -= v4l2src->duration;
else
timestamp = 0;
-
- duration = latency;
}
}
/* FIXME: use the timestamp from the buffer itself! */
GST_BUFFER_TIMESTAMP (*buf) = timestamp;
- GST_BUFFER_DURATION (*buf) = duration;
+ GST_BUFFER_DURATION (*buf) = v4l2src->duration;
}
return ret;
}
v4l2src->fps_n = fps_n;
v4l2src->fps_d = fps_d;
- GST_INFO_OBJECT (v4l2src, "Set framerate to %u/%u", fps_n, fps_d);
+
+ /* if we have a framerate pre-calculate duration */
+ if (fps_n > 0 && fps_d > 0) {
+ v4l2src->duration = gst_util_uint64_scale_int (GST_SECOND, fps_d, fps_n);
+ } else {
+ v4l2src->duration = GST_CLOCK_TIME_NONE;
+ }
+
+ GST_INFO_OBJECT (v4l2src,
+ "Set framerate to %u/%u and duration to %" GST_TIME_FORMAT, fps_n, fps_d,
+ GST_TIME_ARGS (v4l2src->duration));
+
done: