9da6ac4642de7f5a8eb89dac922acdecad681ea6
[openwrt/staging/jow.git] /
1 From aa6e148bb75f76291e9625316f1f7c73458daf47 Mon Sep 17 00:00:00 2001
2 From: David H <davidjhu@gmail.com>
3 Date: Wed, 4 Oct 2017 04:43:07 -0700
4 Subject: [PATCH 200/454] bcm2835-camera: Fix timestamp calculation problem
5 (#2214)
6
7 * bcm2835-camera: Fix timestamp calculation problem
8
9 Use div_s64_rem() to convert usec timestamp to timeval
10 to avoid integer signedness bug.
11
12 * bcm2835-camera: Store kernel start time in NSEC instead of USEC
13
14 * bcm2835-camera: Reword debug message for clarity
15 ---
16 .../bcm2835-camera/bcm2835-camera.c | 41 +++++--------------
17 .../bcm2835-camera/bcm2835-camera.h | 2 +-
18 2 files changed, 11 insertions(+), 32 deletions(-)
19
20 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
21 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
22 @@ -348,37 +348,17 @@ static void buffer_cb(struct vchiq_mmal_
23 buf->vb.vb2_buf.timestamp);
24
25 } else if(pts != 0) {
26 - struct timeval timestamp;
27 s64 runtime_us = pts -
28 dev->capture.vc_start_timestamp;
29 - u32 div = 0;
30 - u32 rem = 0;
31 -
32 - div =
33 - div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
34 - timestamp.tv_sec =
35 - dev->capture.kernel_start_ts.tv_sec + div;
36 - timestamp.tv_usec =
37 - dev->capture.kernel_start_ts.tv_usec + rem;
38 -
39 - if (timestamp.tv_usec >=
40 - USEC_PER_SEC) {
41 - timestamp.tv_sec++;
42 - timestamp.tv_usec -=
43 - USEC_PER_SEC;
44 - }
45 + buf->vb.vb2_buf.timestamp = (runtime_us * NSEC_PER_USEC) +
46 + dev->capture.kernel_start_timestamp;
47 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
48 - "Convert start time %d.%06d and %llu "
49 - "with offset %llu to %d.%06d\n",
50 - (int)dev->capture.kernel_start_ts.
51 - tv_sec,
52 - (int)dev->capture.kernel_start_ts.
53 - tv_usec,
54 - dev->capture.vc_start_timestamp, pts,
55 - (int)timestamp.tv_sec,
56 - (int)timestamp.tv_usec);
57 - buf->vb.vb2_buf.timestamp = timestamp.tv_sec * 1000000000ULL +
58 - timestamp.tv_usec * 1000ULL;
59 + "Buffer time set as converted timestamp - %llu "
60 + "= (pts [%lld usec] - vc start time [%llu usec]) "
61 + "+ kernel start time [%llu nsec]\n",
62 + buf->vb.vb2_buf.timestamp,
63 + pts, dev->capture.vc_start_timestamp,
64 + dev->capture.kernel_start_timestamp);
65 } else {
66 if (dev->capture.last_timestamp) {
67 buf->vb.vb2_buf.timestamp = dev->capture.last_timestamp;
68 @@ -388,8 +368,7 @@ static void buffer_cb(struct vchiq_mmal_
69 }
70 else {
71 buf->vb.vb2_buf.timestamp =
72 - dev->capture.kernel_start_ts.tv_sec * 1000000000ULL +
73 - dev->capture.kernel_start_ts.tv_usec * 1000ULL;
74 + dev->capture.kernel_start_timestamp;
75 v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
76 "Buffer time set as start timestamp - %lld",
77 buf->vb.vb2_buf.timestamp);
78 @@ -574,7 +553,7 @@ static int start_streaming(struct vb2_qu
79
80 dev->capture.last_timestamp = 0;
81
82 - v4l2_get_timestamp(&dev->capture.kernel_start_ts);
83 + dev->capture.kernel_start_timestamp = ktime_get_ns();
84
85 /* enable the camera port */
86 dev->capture.port->cb_ctx = dev;
87 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
88 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
89 @@ -92,7 +92,7 @@ struct bm2835_mmal_dev {
90 /* VC start timestamp for streaming */
91 s64 vc_start_timestamp;
92 /* Kernel start timestamp for streaming */
93 - struct timeval kernel_start_ts;
94 + u64 kernel_start_timestamp;
95 /* Timestamp of last frame */
96 u64 last_timestamp;
97