v4l2src: move duplicated timestamping and buffer metadata code to _create()

This will include the latency changes also in the mmap case.
This commit is contained in:
Stefan Kost 2009-03-25 10:08:41 +02:00
parent 652a7fb91f
commit ad5702d492
2 changed files with 42 additions and 68 deletions

View file

@ -1264,45 +1264,7 @@ gst_v4l2src_get_read (GstV4l2Src * v4l2src, GstBuffer ** buf)
}
} while (TRUE);
GST_BUFFER_OFFSET (*buf) = v4l2src->offset++;
GST_BUFFER_OFFSET_END (*buf) = v4l2src->offset;
/* timestamps, LOCK to get clock and base time. */
{
GstClock *clock;
GstClockTime timestamp;
GST_OBJECT_LOCK (v4l2src);
if ((clock = GST_ELEMENT_CLOCK (v4l2src))) {
/* we have a clock, get base time and ref clock */
timestamp = GST_ELEMENT (v4l2src)->base_time;
gst_object_ref (clock);
} else {
/* no clock, can't set timestamps */
timestamp = GST_CLOCK_TIME_NONE;
}
GST_OBJECT_UNLOCK (v4l2src);
if (clock) {
GstClockTime latency;
/* the time now is the time of the clock minus the base time */
timestamp = gst_clock_get_time (clock) - timestamp;
gst_object_unref (clock);
latency =
gst_util_uint64_scale_int (GST_SECOND, v4l2src->fps_d,
v4l2src->fps_n);
if (timestamp > latency)
timestamp -= latency;
else
timestamp = 0;
}
/* FIXME: use the timestamp from the buffer itself! */
GST_BUFFER_TIMESTAMP (*buf) = timestamp;
}
/* we set the buffer metadata in gst_v4l2src_create() */
return GST_FLOW_OK;
@ -1388,5 +1350,45 @@ gst_v4l2src_create (GstPushSrc * src, GstBuffer ** buf)
} else {
ret = gst_v4l2src_get_read (v4l2src, buf);
}
/* set buffer metadata */
if (ret == GST_FLOW_OK && *buf) {
GstClock *clock;
GstClockTime timestamp;
GST_BUFFER_OFFSET (*buf) = v4l2src->offset++;
GST_BUFFER_OFFSET_END (*buf) = v4l2src->offset;
/* timestamps, LOCK to get clock and base time. */
GST_OBJECT_LOCK (v4l2src);
if ((clock = GST_ELEMENT_CLOCK (v4l2src))) {
/* we have a clock, get base time and ref clock */
timestamp = GST_ELEMENT (v4l2src)->base_time;
gst_object_ref (clock);
} else {
/* no clock, can't set timestamps */
timestamp = GST_CLOCK_TIME_NONE;
}
GST_OBJECT_UNLOCK (v4l2src);
if (clock) {
GstClockTime latency;
/* the time now is the time of the clock minus the base time */
timestamp = gst_clock_get_time (clock) - timestamp;
gst_object_unref (clock);
latency =
gst_util_uint64_scale_int (GST_SECOND, v4l2src->fps_d,
v4l2src->fps_n);
if (timestamp > latency)
timestamp -= latency;
else
timestamp = 0;
}
/* FIXME: use the timestamp from the buffer itself! */
GST_BUFFER_TIMESTAMP (*buf) = timestamp;
}
return ret;
}

View file

@ -1106,35 +1106,6 @@ gst_v4l2src_grab_frame (GstV4l2Src * v4l2src, GstBuffer ** buf)
/* this can change at every frame, esp. with jpeg */
GST_BUFFER_SIZE (pool_buffer) = buffer.bytesused;
GST_BUFFER_OFFSET (pool_buffer) = v4l2src->offset++;
GST_BUFFER_OFFSET_END (pool_buffer) = v4l2src->offset;
/* timestamps, LOCK to get clock and base time. */
{
GstClock *clock;
GstClockTime timestamp;
GST_OBJECT_LOCK (v4l2src);
if ((clock = GST_ELEMENT_CLOCK (v4l2src))) {
/* we have a clock, get base time and ref clock */
timestamp = GST_ELEMENT (v4l2src)->base_time;
gst_object_ref (clock);
} else {
/* no clock, can't set timestamps */
timestamp = GST_CLOCK_TIME_NONE;
}
GST_OBJECT_UNLOCK (v4l2src);
if (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);
}
/* FIXME: use the timestamp from the buffer itself! */
GST_BUFFER_TIMESTAMP (pool_buffer) = timestamp;
}
if (G_UNLIKELY (need_copy)) {
*buf = gst_buffer_copy (pool_buffer);
GST_BUFFER_FLAG_UNSET (*buf, GST_BUFFER_FLAG_READONLY);
@ -1143,6 +1114,7 @@ gst_v4l2src_grab_frame (GstV4l2Src * v4l2src, GstBuffer ** buf)
} else {
*buf = pool_buffer;
}
/* we set the buffer metadata in gst_v4l2src_create() */
GST_LOG_OBJECT (v4l2src, "grabbed frame %d (ix=%d), flags %08x, pool-ct=%d",
buffer.sequence, buffer.index, buffer.flags,