Skip to content

Commit 0f64f80

Browse files
ribaldagregkh
authored andcommitted
media: uvcvideo: Fix buffer sequence in frame gaps
commit 2f24ac8 upstream. In UVC, the FID flips with every frame. For every FID flip, we increase the stream sequence number. Now, if a FID flips multiple times and there is no data transferred between the flips, the buffer sequence number will be set to the value of the stream sequence number after the first flip. Userspace uses the buffer sequence number to determine if there have been missing frames. With the current behaviour, userspace will think that the gap is in the wrong location. This patch modifies uvc_video_decode_start() to provide the correct buffer sequence number and timestamp. Cc: stable@kernel.org Fixes: 650b95f ("[media] uvcvideo: Generate discontinuous sequence numbers when frames are lost") Signed-off-by: Ricardo Ribalda <ribalda@chromium.org> Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com> Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com> Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1a9baac commit 0f64f80

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

drivers/media/usb/uvc/uvc_video.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,6 +1186,19 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
11861186
stream->sequence++;
11871187
if (stream->sequence)
11881188
uvc_video_stats_update(stream);
1189+
1190+
/*
1191+
* On a FID flip initialize sequence number and timestamp.
1192+
*
1193+
* The driver already takes care of injecting FID flips for
1194+
* UVC_QUIRK_STREAM_NO_FID and UVC_QUIRK_MJPEG_NO_EOF.
1195+
*/
1196+
if (buf) {
1197+
buf->buf.field = V4L2_FIELD_NONE;
1198+
buf->buf.sequence = stream->sequence;
1199+
buf->buf.vb2_buf.timestamp =
1200+
ktime_to_ns(uvc_video_get_time());
1201+
}
11891202
}
11901203

11911204
uvc_video_clock_decode(stream, buf, data, len);
@@ -1226,10 +1239,6 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
12261239
return -ENODATA;
12271240
}
12281241

1229-
buf->buf.field = V4L2_FIELD_NONE;
1230-
buf->buf.sequence = stream->sequence;
1231-
buf->buf.vb2_buf.timestamp = ktime_to_ns(uvc_video_get_time());
1232-
12331242
/* TODO: Handle PTS and SCR. */
12341243
buf->state = UVC_BUF_STATE_ACTIVE;
12351244
if (meta_buf)

0 commit comments

Comments
 (0)