12afc4a1f87583a43420f44fd366672d70c392c7
[openwrt/staging/luka.git] /
1 From bf5bbfec3cb99c469eb59f2b19411146c47feb73 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Mon, 29 Oct 2018 14:21:04 +0000
4 Subject: [PATCH] staging: bcm2835-camera: Ensure H264 header bytes get
5 a sensible timestamp
6
7 H264 header come from VC with 0 timestamps, which means they get a
8 strange timestamp when processed with VC/kernel start times,
9 particularly if used with the inline header option.
10 Remember the last frame timestamp and use that if set, or otherwise
11 use the kernel start time.
12
13 https://github.com/raspberrypi/linux/issues/1836
14
15 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
16 ---
17 .../bcm2835-camera/bcm2835-camera.c | 30 +++++++++++++++++--
18 .../bcm2835-camera/bcm2835-camera.h | 2 ++
19 2 files changed, 29 insertions(+), 3 deletions(-)
20
21 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
22 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
23 @@ -363,8 +363,13 @@ static void buffer_cb(struct vchiq_mmal_
24 }
25 } else {
26 if (dev->capture.frame_count) {
27 - if (dev->capture.vc_start_timestamp != -1 &&
28 - pts != 0) {
29 + if (dev->capture.vc_start_timestamp == -1) {
30 + buf->vb.vb2_buf.timestamp = ktime_get_ns();
31 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
32 + "Buffer time set as current time - %lld",
33 + buf->vb.vb2_buf.timestamp);
34 +
35 + } else if (pts != 0) {
36 ktime_t timestamp;
37 s64 runtime_us = pts -
38 dev->capture.vc_start_timestamp;
39 @@ -377,10 +382,28 @@ static void buffer_cb(struct vchiq_mmal_
40 ktime_to_ns(timestamp));
41 buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
42 } else {
43 - buf->vb.vb2_buf.timestamp = ktime_get_ns();
44 + if (dev->capture.last_timestamp) {
45 + buf->vb.vb2_buf.timestamp =
46 + dev->capture.last_timestamp;
47 + v4l2_dbg(1, bcm2835_v4l2_debug,
48 + &dev->v4l2_dev,
49 + "Buffer time set as last timestamp - %lld",
50 + buf->vb.vb2_buf.timestamp);
51 + } else {
52 + buf->vb.vb2_buf.timestamp =
53 + ktime_to_ns(dev->capture.kernel_start_ts);
54 + v4l2_dbg(1, bcm2835_v4l2_debug,
55 + &dev->v4l2_dev,
56 + "Buffer time set as start timestamp - %lld",
57 + buf->vb.vb2_buf.timestamp);
58 + }
59 }
60 + dev->capture.last_timestamp = buf->vb.vb2_buf.timestamp;
61
62 vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
63 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
64 + "Buffer has ts %llu",
65 + dev->capture.last_timestamp);
66 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
67
68 if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
69 @@ -546,6 +569,7 @@ static int start_streaming(struct vb2_qu
70 dev->capture.vc_start_timestamp, parameter_size);
71
72 dev->capture.kernel_start_ts = ktime_get();
73 + dev->capture.last_timestamp = 0;
74
75 /* enable the camera port */
76 dev->capture.port->cb_ctx = dev;
77 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
78 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
79 @@ -90,6 +90,8 @@ struct bm2835_mmal_dev {
80 s64 vc_start_timestamp;
81 /* Kernel start timestamp for streaming */
82 ktime_t kernel_start_ts;
83 + /* Timestamp of last frame */
84 + u64 last_timestamp;
85
86 struct vchiq_mmal_port *port; /* port being used for capture */
87 /* camera port being used for capture */