Commit 650b95fe authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

[media] uvcvideo: Generate discontinuous sequence numbers when frames are lost

Increase the sequence number of the v4l2_buffer structure regardless of
any buffer states, so that discontinuous sequence numbers allow
applications to detect lost video frames.
Signed-off-by: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 9bb7262d
...@@ -135,7 +135,6 @@ int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers, ...@@ -135,7 +135,6 @@ int uvc_alloc_buffers(struct uvc_video_queue *queue, unsigned int nbuffers,
queue->buffer[i].buf.m.offset = i * bufsize; queue->buffer[i].buf.m.offset = i * bufsize;
queue->buffer[i].buf.length = buflength; queue->buffer[i].buf.length = buflength;
queue->buffer[i].buf.type = queue->type; queue->buffer[i].buf.type = queue->type;
queue->buffer[i].buf.sequence = 0;
queue->buffer[i].buf.field = V4L2_FIELD_NONE; queue->buffer[i].buf.field = V4L2_FIELD_NONE;
queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP; queue->buffer[i].buf.memory = V4L2_MEMORY_MMAP;
queue->buffer[i].buf.flags = 0; queue->buffer[i].buf.flags = 0;
...@@ -410,8 +409,7 @@ unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, ...@@ -410,8 +409,7 @@ unsigned int uvc_queue_poll(struct uvc_video_queue *queue, struct file *file,
* state can be properly initialized before buffers are accessed from the * state can be properly initialized before buffers are accessed from the
* interrupt handler. * interrupt handler.
* *
* Enabling the video queue initializes parameters (such as sequence number, * Enabling the video queue returns -EBUSY if the queue is already enabled.
* sync pattern, ...). If the queue is already enabled, return -EBUSY.
* *
* Disabling the video queue cancels the queue and removes all buffers from * Disabling the video queue cancels the queue and removes all buffers from
* the main queue. * the main queue.
...@@ -430,7 +428,6 @@ int uvc_queue_enable(struct uvc_video_queue *queue, int enable) ...@@ -430,7 +428,6 @@ int uvc_queue_enable(struct uvc_video_queue *queue, int enable)
ret = -EBUSY; ret = -EBUSY;
goto done; goto done;
} }
queue->sequence = 0;
queue->flags |= UVC_QUEUE_STREAMING; queue->flags |= UVC_QUEUE_STREAMING;
queue->buf_used = 0; queue->buf_used = 0;
} else { } else {
...@@ -510,8 +507,6 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, ...@@ -510,8 +507,6 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue,
nextbuf = NULL; nextbuf = NULL;
spin_unlock_irqrestore(&queue->irqlock, flags); spin_unlock_irqrestore(&queue->irqlock, flags);
buf->buf.sequence = queue->sequence++;
wake_up(&buf->wait); wake_up(&buf->wait);
return nextbuf; return nextbuf;
} }
......
...@@ -427,6 +427,12 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, ...@@ -427,6 +427,12 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
fid = data[1] & UVC_STREAM_FID; fid = data[1] & UVC_STREAM_FID;
/* Increase the sequence number regardless of any buffer states, so
* that discontinuous sequence numbers always indicate lost frames.
*/
if (stream->last_fid != fid)
stream->sequence++;
/* Store the payload FID bit and return immediately when the buffer is /* Store the payload FID bit and return immediately when the buffer is
* NULL. * NULL.
*/ */
...@@ -460,6 +466,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream, ...@@ -460,6 +466,7 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
else else
ktime_get_real_ts(&ts); ktime_get_real_ts(&ts);
buf->buf.sequence = stream->sequence;
buf->buf.timestamp.tv_sec = ts.tv_sec; buf->buf.timestamp.tv_sec = ts.tv_sec;
buf->buf.timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC; buf->buf.timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
...@@ -721,6 +728,7 @@ static void uvc_video_encode_bulk(struct urb *urb, struct uvc_streaming *stream, ...@@ -721,6 +728,7 @@ static void uvc_video_encode_bulk(struct urb *urb, struct uvc_streaming *stream,
if (buf->buf.bytesused == stream->queue.buf_used) { if (buf->buf.bytesused == stream->queue.buf_used) {
stream->queue.buf_used = 0; stream->queue.buf_used = 0;
buf->state = UVC_BUF_STATE_READY; buf->state = UVC_BUF_STATE_READY;
buf->buf.sequence = ++stream->sequence;
uvc_queue_next_buffer(&stream->queue, buf); uvc_queue_next_buffer(&stream->queue, buf);
stream->last_fid ^= UVC_STREAM_FID; stream->last_fid ^= UVC_STREAM_FID;
} }
...@@ -979,6 +987,7 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) ...@@ -979,6 +987,7 @@ static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags)
unsigned int i; unsigned int i;
int ret; int ret;
stream->sequence = -1;
stream->last_fid = -1; stream->last_fid = -1;
stream->bulk.header_size = 0; stream->bulk.header_size = 0;
stream->bulk.skip_payload = 0; stream->bulk.skip_payload = 0;
......
...@@ -392,7 +392,6 @@ struct uvc_video_queue { ...@@ -392,7 +392,6 @@ struct uvc_video_queue {
void *mem; void *mem;
unsigned int flags; unsigned int flags;
__u32 sequence;
unsigned int count; unsigned int count;
unsigned int buf_size; unsigned int buf_size;
...@@ -458,6 +457,7 @@ struct uvc_streaming { ...@@ -458,6 +457,7 @@ struct uvc_streaming {
dma_addr_t urb_dma[UVC_URBS]; dma_addr_t urb_dma[UVC_URBS];
unsigned int urb_size; unsigned int urb_size;
__u32 sequence;
__u8 last_fid; __u8 last_fid;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment