From a45f29c44a560b4a817cd8a4c9aec4e48d6ba868 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Sat, 26 Jun 2004 15:58:35 +0000 Subject: [PATCH] fix videorate decision, add latency offset to v4l Original commit message from CVS: fix videorate decision, add latency offset to v4l --- ChangeLog | 21 ++++++++++++++++++++- gst/videorate/gstvideorate.c | 4 ++-- sys/v4l/gstv4lsrc.c | 33 ++++++++++++++++++++++++++++++--- sys/v4l/gstv4lsrc.h | 1 + 4 files changed, 53 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index af9a307e62..5b5453bce5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,23 @@ -2004-06-26 set REAL_NAME environment variable +2004-06-26 Thomas Vander Stichele + + * gst/videorate/gstvideorate.c: (gst_videorate_chain): + fix decision for when getting frames with same timestamp + * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_class_init), (gst_v4lsrc_init), + (gst_v4lsrc_get), (gst_v4lsrc_set_property), + (gst_v4lsrc_get_property): + * sys/v4l/gstv4lsrc.h: + add latency offset property + +2004-06-26 Thomas Vander Stichele + + * gst/tcp/gsttcpserversink.c: (gst_tcpserversink_queue_buffer): + * gst/videorate/gstvideorate.c: (gst_videorate_chain): + * sys/v4l/gstv4lsrc.c: (gst_v4lsrc_class_init), (gst_v4lsrc_init), + (gst_v4lsrc_get), (gst_v4lsrc_set_property), + (gst_v4lsrc_get_property): + * sys/v4l/gstv4lsrc.h: + +2004-06-26 Thomas Vander Stichele * gst/videorate/gstvideorate.c: (gst_videorate_chain), (plugin_init): diff --git a/gst/videorate/gstvideorate.c b/gst/videorate/gstvideorate.c index 77159d5a43..829b3430de 100644 --- a/gst/videorate/gstvideorate.c +++ b/gst/videorate/gstvideorate.c @@ -369,7 +369,7 @@ gst_videorate_chain (GstPad * pad, GstData * data) GST_TIME_ARGS (videorate->next_ts)); /* output first one when its the best */ - if (diff1 <= diff2) { + if (diff1 < diff2) { GstBuffer *outbuf; count++; @@ -389,7 +389,7 @@ gst_videorate_chain (GstPad * pad, GstData * data) } /* continue while the first one was the best */ } - while (diff1 <= diff2); + while (diff1 < diff2); /* if we outputed the first buffer more then once, we have dups */ if (count > 1) { diff --git a/sys/v4l/gstv4lsrc.c b/sys/v4l/gstv4lsrc.c index 357026a0bc..0be9d37c61 100644 --- a/sys/v4l/gstv4lsrc.c +++ b/sys/v4l/gstv4lsrc.c @@ -63,7 +63,8 @@ enum ARG_BUFSIZE, ARG_SYNC_MODE, ARG_COPY_MODE, - ARG_AUTOPROBE + ARG_AUTOPROBE, + ARG_LATENCY_OFFSET }; GST_FORMATS_FUNCTION (GstPad *, gst_v4lsrc_get_formats, @@ -212,6 +213,10 @@ gst_v4lsrc_class_init (GstV4lSrcClass * klass) g_param_spec_boolean ("autoprobe", "Autoprobe", "Whether the device should be probed for all possible features", TRUE, G_PARAM_READWRITE)); + g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LATENCY_OFFSET, + g_param_spec_int ("latency-offset", "Latency offset", + "A latency offset subtracted from timestamps set on buffers (in ns)", + G_MININT, G_MAXINT, 0, G_PARAM_READWRITE)); /* signals */ gst_v4lsrc_signals[SIGNAL_FRAME_CAPTURE] = @@ -273,6 +278,8 @@ gst_v4lsrc_init (GstV4lSrc * v4lsrc) v4lsrc->is_capturing = FALSE; v4lsrc->autoprobe = TRUE; + + v4lsrc->latency_offset = 0; } static void @@ -956,9 +963,20 @@ gst_v4lsrc_get (GstPad * pad) case GST_V4LSRC_SYNC_MODE_CLOCK: if (v4lsrc->clock) { GstClockTime time = gst_element_get_time (GST_ELEMENT (v4lsrc)); + GstClockTimeDiff target_ts = 0; - /* FIXME: figure out a way to add the capture latency here */ - GST_BUFFER_TIMESTAMP (buf) = time /* + 0.5 * GST_SECOND / fps */ ; + /* we can't go negative for timestamps. FIXME: latency querying + * in the core generally should solve this */ + target_ts = GST_CLOCK_DIFF (time, v4lsrc->latency_offset); + if (target_ts < 0) + target_ts = 0; + /* FIXME: create GST_TIME_DIFF_ARGS for target_ts */ + GST_LOG_OBJECT (v4lsrc, "time: %" GST_TIME_FORMAT + ", latency-offset: %" GST_TIME_FORMAT + ", timestamp: %" GST_TIME_FORMAT, + GST_TIME_ARGS (time), GST_TIME_ARGS (v4lsrc->latency_offset), + GST_TIME_ARGS (target_ts)); + GST_BUFFER_TIMESTAMP (buf) = target_ts; } else { GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE; } @@ -1047,6 +1065,11 @@ gst_v4lsrc_set_property (GObject * object, } break; + case ARG_LATENCY_OFFSET: + v4lsrc->latency_offset = g_value_get_int (value); + break; + + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -1088,6 +1111,10 @@ gst_v4lsrc_get_property (GObject * object, g_value_set_boolean (value, v4lsrc->autoprobe); break; + case ARG_LATENCY_OFFSET: + g_value_set_int (value, v4lsrc->latency_offset); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; diff --git a/sys/v4l/gstv4lsrc.h b/sys/v4l/gstv4lsrc.h index 27797f7134..0edfe48de9 100644 --- a/sys/v4l/gstv4lsrc.h +++ b/sys/v4l/gstv4lsrc.h @@ -76,6 +76,7 @@ struct _GstV4lSrc gint num_queued; gint sync_frame, queue_frame; gboolean is_capturing; + GstClockTimeDiff latency_offset; /* True if we want to stop */ gboolean quit;