8b387ba24b99385d679eab8df85f35202384147a
[openwrt/staging/pepe2k.git] /
1 From d93df875705016c8b767b679ad6d16bf26b2d132 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Tue, 24 Jul 2018 12:08:29 +0100
4 Subject: [PATCH 408/454] staging: bcm2835-camera: Ensure timestamps never go
5 backwards.
6
7 There is an awkward situation with H264 header bytes. Currently
8 they are returned with a PTS of 0 because they aren't associated
9 with a timestamped frame to encode. These are handled by either
10 returning the timestamp of the last buffer to have been received,
11 or in the case of the first buffer the timestamp taken at
12 start_streaming.
13 This results in a race where the current frame may have started
14 before we take the start time, which results in the first encoded
15 frame having an earlier timestamp than the header bytes.
16
17 Ensure that we never return a negative delta to the user by checking
18 against the previous timestamp.
19
20 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
21 ---
22 .../staging/vc04_services/bcm2835-camera/bcm2835-camera.c | 5 +++++
23 1 file changed, 5 insertions(+)
24
25 --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
26 +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c
27 @@ -400,6 +400,11 @@ static void buffer_cb(struct vchiq_mmal_
28 ktime_to_ns(dev->capture.kernel_start_ts),
29 dev->capture.vc_start_timestamp, pts,
30 ktime_to_ns(timestamp));
31 + if (timestamp < dev->capture.last_timestamp) {
32 + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
33 + "Negative delta - using last time\n");
34 + timestamp = dev->capture.last_timestamp;
35 + }
36 buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp);
37 } else {
38 if (dev->capture.last_timestamp) {