V4L/DVB (13827): uvcvideo: Switch to a monotonic clock for V4L2 buffers timestamps
[safe/jmp/linux-2.6] / drivers / media / video / uvc / uvc_video.c
index 7dcf534..6b0666b 100644 (file)
@@ -410,6 +410,8 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
         * when the EOF bit is set to force synchronisation on the next packet.
         */
        if (buf->state != UVC_BUF_STATE_ACTIVE) {
+               struct timespec ts;
+
                if (fid == stream->last_fid) {
                        uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of "
                                "sync).\n");
@@ -419,6 +421,14 @@ static int uvc_video_decode_start(struct uvc_streaming *stream,
                        return -ENODATA;
                }
 
+               if (uvc_clock_param == CLOCK_MONOTONIC)
+                       ktime_get_ts(&ts);
+               else
+                       ktime_get_real_ts(&ts);
+
+               buf->buf.timestamp.tv_sec = ts.tv_sec;
+               buf->buf.timestamp.tv_usec = ts.tv_nsec / NSEC_PER_USEC;
+
                /* TODO: Handle PTS and SCR. */
                buf->state = UVC_BUF_STATE_ACTIVE;
        }