mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-18 07:47:17 +00:00
v4l2: precalculate duration
Have frame duration in the instance struct and calculate it after changing the caps.
This commit is contained in:
parent
ac8e87bb2c
commit
23106e243b
3 changed files with 18 additions and 14 deletions
|
@ -913,7 +913,6 @@ gst_v4l2src_create (GstPushSrc * src, GstBuffer ** buf)
|
|||
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;
|
||||
|
@ -930,30 +929,23 @@ gst_v4l2src_create (GstPushSrc * src, GstBuffer ** buf)
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ struct _GstV4l2Src
|
|||
guint64 offset;
|
||||
|
||||
gint fps_d, fps_n; /* framerate if device is open */
|
||||
GstClockTime duration; /* duration of one frame */
|
||||
|
||||
GstV4l2SrcGetFunc get_frame;
|
||||
};
|
||||
|
|
|
@ -272,7 +272,18 @@ gst_v4l2src_set_capture (GstV4l2Src * v4l2src, guint32 pixelformat,
|
|||
|
||||
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:
|
||||
|
||||
|
|
Loading…
Reference in a new issue