1 From a89e41616615bc55db4946aad1b0ec0afeb71bb4 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 240/773] staging: bcm2835-camera: Ensure H264 header bytes get
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.
13 https://github.com/raspberrypi/linux/issues/1836
15 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
17 .../bcm2835-camera/bcm2835-camera.c | 30 +++++++++++++++++--
18 .../bcm2835-camera/bcm2835-camera.h | 2 ++
19 2 files changed, 29 insertions(+), 3 deletions(-)
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_
26 if (dev->capture.frame_count) {
27 - if (dev->capture.vc_start_timestamp != -1 &&
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);
35 + } else if (pts != 0) {
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);
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,
49 + "Buffer time set as last timestamp - %lld",
50 + buf->vb.vb2_buf.timestamp);
52 + buf->vb.vb2_buf.timestamp =
53 + ktime_to_ns(dev->capture.kernel_start_ts);
54 + v4l2_dbg(1, bcm2835_v4l2_debug,
56 + "Buffer time set as start timestamp - %lld",
57 + buf->vb.vb2_buf.timestamp);
60 + dev->capture.last_timestamp = buf->vb.vb2_buf.timestamp;
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);
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);
72 dev->capture.kernel_start_ts = ktime_get();
73 + dev->capture.last_timestamp = 0;
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 */
86 struct vchiq_mmal_port *port; /* port being used for capture */
87 /* camera port being used for capture */