Skip to content

Commit e1052f8

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 3351da8 commit e1052f8

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
@@ -1151,6 +1151,19 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
11511151
stream->sequence++;
11521152
if (stream->sequence)
11531153
uvc_video_stats_update(stream);
1154+
1155+
/*
1156+
* On a FID flip initialize sequence number and timestamp.
1157+
*
1158+
* The driver already takes care of injecting FID flips for
1159+
* UVC_QUIRK_STREAM_NO_FID and UVC_QUIRK_MJPEG_NO_EOF.
1160+
*/
1161+
if (buf) {
1162+
buf->buf.field = V4L2_FIELD_NONE;
1163+
buf->buf.sequence = stream->sequence;
1164+
buf->buf.vb2_buf.timestamp =
1165+
ktime_to_ns(uvc_video_get_time());
1166+
}
11541167
}
11551168

11561169
uvc_video_clock_decode(stream, buf, data, len);
@@ -1191,10 +1204,6 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
11911204
return -ENODATA;
11921205
}
11931206

1194-
buf->buf.field = V4L2_FIELD_NONE;
1195-
buf->buf.sequence = stream->sequence;
1196-
buf->buf.vb2_buf.timestamp = ktime_to_ns(uvc_video_get_time());
1197-
11981207
/* TODO: Handle PTS and SCR. */
11991208
buf->state = UVC_BUF_STATE_ACTIVE;
12001209
if (meta_buf)

0 commit comments

Comments
 (0)