From: Sakari Ailus <sakari.ailus@linux.intel.com>
To: pj.assis@gmail.com
Cc: remi@remlab.net, notasas@gmail.com, linux-media@vger.kernel.org,
laurent.pinchart@ideasonboard.com, hans.verkuil@cisco.com
Subject: [RFC 1/2] uvc: Add a quirk flag for cameras that do not produce correct timestamps
Date: Wed, 5 Nov 2014 18:12:33 +0200 [thread overview]
Message-ID: <1415203954-16718-1-git-send-email-sakari.ailus@linux.intel.com> (raw)
In-Reply-To: <20141105161147.GW3136@valkosipuli.retiisi.org.uk>
The UVC devices do produce hardware timestamps according to the spec, but
not all cameras implement it or implement it correctly. Add a quirk flag for
such devices, and use monotonic timestamp from the end of the frame instead.
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/media/usb/uvc/uvc_queue.c | 6 ++++--
drivers/media/usb/uvc/uvc_video.c | 14 +++++++++++++-
drivers/media/usb/uvc/uvcvideo.h | 4 +++-
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index 6e92d20..3f6432f 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -141,7 +141,7 @@ static struct vb2_ops uvc_queue_qops = {
};
int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
- int drop_corrupted)
+ bool drop_corrupted, bool tstamp_eof)
{
int ret;
@@ -152,7 +152,9 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
queue->queue.ops = &uvc_queue_qops;
queue->queue.mem_ops = &vb2_vmalloc_memops;
queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
- | V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
+ | (tstamp_eof ? V4L2_BUF_FLAG_TSTAMP_SRC_EOF
+ : V4L2_BUF_FLAG_TSTAMP_SRC_SOE);
+
ret = vb2_queue_init(&queue->queue);
if (ret)
return ret;
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index df81b9c..f599112 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -382,6 +382,9 @@ uvc_video_clock_decode(struct uvc_streaming *stream, struct uvc_buffer *buf,
u16 host_sof;
u16 dev_sof;
+ if (stream->dev->quirks & UVC_QUIRK_BAD_TIMESTAMP)
+ return;
+
switch (data[1] & (UVC_STREAM_PTS | UVC_STREAM_SCR)) {
case UVC_STREAM_PTS | UVC_STREAM_SCR:
header_size = 12;
@@ -490,6 +493,9 @@ static int uvc_video_clock_init(struct uvc_streaming *stream)
{
struct uvc_clock *clock = &stream->clock;
+ if (stream->dev->quirks & UVC_QUIRK_BAD_TIMESTAMP)
+ return 0;
+
spin_lock_init(&clock->lock);
clock->size = 32;
@@ -615,6 +621,11 @@ void uvc_video_clock_update(struct uvc_streaming *stream,
u32 rem;
u64 y;
+ if (stream->dev->quirks & UVC_QUIRK_BAD_TIMESTAMP) {
+ v4l2_get_timestamp(&v4l2_buf->timestamp);
+ return;
+ }
+
spin_lock_irqsave(&clock->lock, flags);
if (clock->count < clock->size)
@@ -1779,7 +1790,8 @@ int uvc_video_init(struct uvc_streaming *stream)
atomic_set(&stream->active, 0);
/* Initialize the video buffers queue. */
- ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param);
+ ret = uvc_queue_init(&stream->queue, stream->type, !uvc_no_drop_param,
+ stream->dev->quirks & UVC_QUIRK_BAD_TIMESTAMP);
if (ret)
return ret;
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index 864ada7..89a638c 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -148,6 +148,7 @@
#define UVC_QUIRK_PROBE_DEF 0x00000100
#define UVC_QUIRK_RESTRICT_FRAME_RATE 0x00000200
#define UVC_QUIRK_RESTORE_CTRLS_ON_INIT 0x00000400
+#define UVC_QUIRK_BAD_TIMESTAMP 0x00000800
/* Format flags */
#define UVC_FMT_FLAG_COMPRESSED 0x00000001
@@ -622,7 +623,8 @@ extern struct uvc_entity *uvc_entity_by_id(struct uvc_device *dev, int id);
/* Video buffers queue management. */
extern int uvc_queue_init(struct uvc_video_queue *queue,
- enum v4l2_buf_type type, int drop_corrupted);
+ enum v4l2_buf_type type, bool drop_corrupted,
+ bool tstamp_eof);
extern int uvc_alloc_buffers(struct uvc_video_queue *queue,
struct v4l2_requestbuffers *rb);
extern void uvc_free_buffers(struct uvc_video_queue *queue);
--
2.1.0.231.g7484e3b
next prev parent reply other threads:[~2014-11-05 16:14 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-02 2:03 (bisected) Logitech C920 (uvcvideo) stutters since 3.9 Grazvydas Ignotas
2014-11-02 22:57 ` Sakari Ailus
2014-11-03 23:16 ` Grazvydas Ignotas
2014-11-04 11:58 ` Sakari Ailus
2014-11-04 12:42 ` Rémi Denis-Courmont
2014-11-04 15:02 ` Paulo Assis
2014-11-04 15:36 ` Sakari Ailus
2014-11-04 23:32 ` Sakari Ailus
2014-11-05 10:13 ` Paulo Assis
2014-11-05 14:05 ` Laurent Pinchart
2014-11-05 22:29 ` Paulo Assis
2014-11-05 16:11 ` Sakari Ailus
2014-11-05 16:12 ` Sakari Ailus [this message]
2014-11-05 16:12 ` [RFC 2/2] uvc: Use UVC_QUIRK_BAD_TIMESTAMP quirk flag for Logitech C920 Sakari Ailus
2015-11-09 16:18 ` [RFC 1/2] uvc: Add a quirk flag for cameras that do not produce correct timestamps Laurent Pinchart
2014-12-05 14:58 ` (bisected) Logitech C920 (uvcvideo) stutters since 3.9 Laurent Pinchart
2014-11-04 20:41 ` Rémi Denis-Courmont
2014-11-05 14:05 ` Laurent Pinchart
2014-11-05 22:29 ` Grazvydas Ignotas
2014-11-17 15:36 ` Grazvydas Ignotas
2014-11-18 8:39 ` Hans Verkuil
2014-12-05 11:46 ` Laurent Pinchart
2014-12-06 0:25 ` Grazvydas Ignotas
2014-12-07 19:23 ` Laurent Pinchart
2014-12-07 21:23 ` Grazvydas Ignotas
2015-03-29 20:59 ` Milos Ivanovic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1415203954-16718-1-git-send-email-sakari.ailus@linux.intel.com \
--to=sakari.ailus@linux.intel.com \
--cc=hans.verkuil@cisco.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=notasas@gmail.com \
--cc=pj.assis@gmail.com \
--cc=remi@remlab.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).