From f160625ea674538be81d41c9286c7dd437c7a034 Mon Sep 17 00:00:00 2001 From: Peter Seiderer Date: Fri, 27 Mar 2015 21:09:44 +0100 Subject: [PATCH] v4l2src: device sequence/offset correction in case of renegotiation The v4l2 device restarts the sequence counter in case of streamoff/streamon, the GST offset values are supposed to increment strictly monotonic, so adjust the sequence counter/offset values in case of caps renegotiation. https://bugzilla.gnome.org/show_bug.cgi?id=745441 --- sys/v4l2/gstv4l2src.c | 10 ++++++++-- sys/v4l2/gstv4l2src.h | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sys/v4l2/gstv4l2src.c b/sys/v4l2/gstv4l2src.c index ab36a58..633e46f 100644 --- a/sys/v4l2/gstv4l2src.c +++ b/sys/v4l2/gstv4l2src.c @@ -459,9 +459,10 @@ gst_v4l2src_set_caps (GstBaseSrc * src, GstCaps * caps) * Basesrc will do an allocation query that * should indirectly reclaim buffers, after that we can * set the format and then configure our pool */ - if (gst_v4l2_object_try_format (obj, caps)) + if (gst_v4l2_object_try_format (obj, caps)) { + v4l2src->renegotiation_adjust = v4l2src->offset + 1; v4l2src->pending_set_fmt = TRUE; - else + } else return FALSE; } else { /* make sure we stop capturing and dealloc buffers */ @@ -588,6 +589,7 @@ gst_v4l2src_start (GstBaseSrc * src) GstV4l2Src *v4l2src = GST_V4L2SRC (src); v4l2src->offset = 0; + v4l2src->renegotiation_adjust = 0; /* activate settings for first frame */ v4l2src->ctrl_time = 0; @@ -813,6 +815,10 @@ retry: GST_BUFFER_OFFSET (*buf) = v4l2src->offset++; GST_BUFFER_OFFSET_END (*buf) = v4l2src->offset; } else { + /* adjust raw v4l2 device sequence, will restart at null in case of renegotiation + * (streamoff/streamon) */ + GST_BUFFER_OFFSET (*buf) += v4l2src->renegotiation_adjust; + GST_BUFFER_OFFSET_END (*buf) += v4l2src->renegotiation_adjust; /* check for frame loss with given (from v4l2 device) buffer offset */ if ((v4l2src->offset != 0) && (GST_BUFFER_OFFSET (*buf) != (v4l2src->offset + 1))) { guint64 lost_frame_count = GST_BUFFER_OFFSET (*buf) - v4l2src->offset - 1; diff --git a/sys/v4l2/gstv4l2src.h b/sys/v4l2/gstv4l2src.h index 79dec17..90a0dd6 100644 --- a/sys/v4l2/gstv4l2src.h +++ b/sys/v4l2/gstv4l2src.h @@ -59,6 +59,9 @@ struct _GstV4l2Src guint64 offset; + /* offset adjust after renegotiation */ + guint64 renegotiation_adjust; + GstClockTime ctrl_time; gboolean pending_set_fmt; -- 2.7.4