bcm27xx: add linux 5.4 support
[openwrt/staging/jogo.git] / target / linux / bcm27xx / patches-5.4 / 950-0130-staging-bcm2835-camera-Ensure-H264-header-bytes-get-.patch
1 From a35f45d887635bd04b626b8733f1449f0acd1109 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 | 28 +++++++++++++++++--
18 .../bcm2835-camera/bcm2835-camera.h | 2 ++
19 2 files changed, 28 insertions(+), 2 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 @@ -364,7 +364,12 @@ static void buffer_cb(struct vchiq_mmal_
24 return;
25 }
26
27 - if (dev->capture.vc_start_timestamp != -1 && pts) {
28 + if (dev->capture.vc_start_timestamp == -1) {
29 + buf->vb.vb2_buf.timestamp = ktime_get_ns();
30 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
31 + "Buffer time set as current time - %lld",
32 + buf->vb.vb2_buf.timestamp);
33 + } else if (mmal_buf->pts != 0) {
34 ktime_t timestamp;
35 s64 runtime_us = pts -
36 dev->capture.vc_start_timestamp;
37 @@ -377,8 +382,23 @@ static void buffer_cb(struct vchiq_mmal_
38 ktime_to_ns(timestamp));
39 buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
40 } else {
41 - buf->vb.vb2_buf.timestamp = ktime_get_ns();
42 + if (dev->capture.last_timestamp) {
43 + buf->vb.vb2_buf.timestamp =
44 + dev->capture.last_timestamp;
45 + v4l2_dbg(1, bcm2835_v4l2_debug,
46 + &dev->v4l2_dev,
47 + "Buffer time set as last timestamp - %lld",
48 + buf->vb.vb2_buf.timestamp);
49 + } else {
50 + buf->vb.vb2_buf.timestamp =
51 + ktime_to_ns(dev->capture.kernel_start_ts);
52 + v4l2_dbg(1, bcm2835_v4l2_debug,
53 + &dev->v4l2_dev,
54 + "Buffer time set as start timestamp - %lld",
55 + buf->vb.vb2_buf.timestamp);
56 + }
57 }
58 + dev->capture.last_timestamp = buf->vb.vb2_buf.timestamp;
59 buf->vb.sequence = dev->capture.sequence++;
60 buf->vb.field = V4L2_FIELD_NONE;
61
62 @@ -386,6 +406,9 @@ static void buffer_cb(struct vchiq_mmal_
63 if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
64 buf->vb.flags |= V4L2_BUF_FLAG_KEYFRAME;
65
66 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
67 + "Buffer has ts %llu",
68 + dev->capture.last_timestamp);
69 vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
70
71 if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
72 @@ -549,6 +572,7 @@ static int start_streaming(struct vb2_qu
73 }
74
75 dev->capture.kernel_start_ts = ktime_get();
76 + dev->capture.last_timestamp = 0;
77
78 /* enable the camera port */
79 dev->capture.port->cb_ctx = dev;
80 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
81 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.h
82 @@ -93,6 +93,8 @@ struct bm2835_mmal_dev {
83 ktime_t kernel_start_ts;
84 /* Sequence number of last buffer */
85 u32 sequence;
86 + /* Timestamp of last frame */
87 + u64 last_timestamp;
88
89 struct vchiq_mmal_port *port; /* port being used for capture */
90 /* camera port being used for capture */