summaryrefslogtreecommitdiffstats
path: root/sys
diff options
context:
space:
mode:
authorStefan Kost <ensonic@users.sf.net>2009-03-25 10:08:41 +0200
committerStefan Kost <ensonic@users.sf.net>2009-03-25 10:08:41 +0200
commitad5702d492d35fee3ed5f3ee39ca4ed6cf3d4485 (patch)
treed60a43ea952fc9cd600bfed6b0624bbd1dd8c14c /sys
parent652a7fb91fb3a8601e40900953bfd311114b5001 (diff)
v4l2src: move duplicated timestamping and buffer metadata code to _create()
This will include the latency changes also in the mmap case.
Diffstat (limited to 'sys')
-rw-r--r--sys/v4l2/gstv4l2src.c80
-rw-r--r--sys/v4l2/v4l2src_calls.c30
2 files changed, 42 insertions, 68 deletions
diff --git a/sys/v4l2/gstv4l2src.c b/sys/v4l2/gstv4l2src.c
index 5455056b..a0cc7c69 100644
--- a/sys/v4l2/gstv4l2src.c
+++ b/sys/v4l2/gstv4l2src.c
@@ -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;
}
diff --git a/sys/v4l2/v4l2src_calls.c b/sys/v4l2/v4l2src_calls.c
index b472dc77..30556af4 100644
--- a/sys/v4l2/v4l2src_calls.c
+++ b/sys/v4l2/v4l2src_calls.c
@@ -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,