lantiq: fix broadcasts and vlans in two iface mode
[oweals/openwrt.git] / target / linux / brcm2708 / patches-4.9 / 0196-BCM2835-V4L2-Ensure-H264-header-bytes-get-a-sensible.patch
1 From 02ceda02182f6cb538be397b8d8f34b64a254559 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Mon, 13 Feb 2017 11:10:50 +0000
4 Subject: [PATCH] BCM2835-V4L2: Ensure H264 header bytes get a sensible
5  timestamp
6
7 H264 header come off 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  drivers/media/platform/bcm2835/bcm2835-camera.c | 30 ++++++++++++++++++++++---
18  drivers/media/platform/bcm2835/bcm2835-camera.h |  2 ++
19  2 files changed, 29 insertions(+), 3 deletions(-)
20
21 --- a/drivers/media/platform/bcm2835/bcm2835-camera.c
22 +++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
23 @@ -356,8 +356,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                                 struct timeval timestamp;
37                                 s64 runtime_us = pts -
38                                     dev->capture.vc_start_timestamp;
39 @@ -390,10 +395,27 @@ static void buffer_cb(struct vchiq_mmal_
40                                 buf->vb.vb2_buf.timestamp = timestamp.tv_sec * 1000000000ULL +
41                                         timestamp.tv_usec * 1000ULL;
42                         } else {
43 -                               buf->vb.vb2_buf.timestamp = ktime_get_ns();
44 +                               if (dev->capture.last_timestamp) {
45 +                                       buf->vb.vb2_buf.timestamp = dev->capture.last_timestamp;
46 +                                       v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
47 +                                        "Buffer time set as last timestamp - %lld",
48 +                                        buf->vb.vb2_buf.timestamp);
49 +                               }
50 +                               else {
51 +                                       buf->vb.vb2_buf.timestamp =
52 +                                       dev->capture.kernel_start_ts.tv_sec  * 1000000000ULL +
53 +                                       dev->capture.kernel_start_ts.tv_usec * 1000ULL;
54 +                                       v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
55 +                                        "Buffer time set as start timestamp - %lld",
56 +                                        buf->vb.vb2_buf.timestamp);
57 +                               }
58                         }
59 +                       dev->capture.last_timestamp = buf->vb.vb2_buf.timestamp;
60  
61                         vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length);
62 +                       v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
63 +                               "Buffer has ts %llu",
64 +                               dev->capture.last_timestamp);
65                         vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE);
66  
67                         if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
68 @@ -559,6 +581,8 @@ static int start_streaming(struct vb2_qu
69                          "Start time %lld size %d\n",
70                          dev->capture.vc_start_timestamp, parameter_size);
71  
72 +       dev->capture.last_timestamp = 0;
73 +
74         v4l2_get_timestamp(&dev->capture.kernel_start_ts);
75  
76         /* enable the camera port */
77 --- a/drivers/media/platform/bcm2835/bcm2835-camera.h
78 +++ b/drivers/media/platform/bcm2835/bcm2835-camera.h
79 @@ -93,6 +93,8 @@ struct bm2835_mmal_dev {
80                 s64         vc_start_timestamp;
81                 /* Kernel start timestamp for streaming */
82                 struct timeval 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 */