48bb146741c9de622e25fe3f0e182eddc309dbb0
[openwrt/staging/linusw.git] /
1 From 3da653227926705fe0dcb7b6057be1ca811f47b8 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Fri, 10 May 2019 14:11:58 +0100
4 Subject: [PATCH] staging: bcm2835-codec: Convert V4L2 nsec timestamps
5 to MMAL usec
6
7 V4L2 uses nsecs, whilst MMAL uses usecs, but the code wasn't converting
8 between them. This upsets video encode rate control.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
11 ---
12 .../vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c | 9 +++++++--
13 1 file changed, 7 insertions(+), 2 deletions(-)
14
15 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
16 +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
17 @@ -823,7 +823,8 @@ static void op_buffer_cb(struct vchiq_mm
18 vb2->flags |= V4L2_BUF_FLAG_LAST;
19 }
20
21 - vb2->vb2_buf.timestamp = mmal_buf->pts;
22 + /* vb2 timestamps in nsecs, mmal in usecs */
23 + vb2->vb2_buf.timestamp = mmal_buf->pts * 1000;
24
25 vb2_set_plane_payload(&vb2->vb2_buf, 0, mmal_buf->length);
26 if (mmal_buf->mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
27 @@ -847,6 +848,7 @@ static void op_buffer_cb(struct vchiq_mm
28 static void vb2_to_mmal_buffer(struct m2m_mmal_buffer *buf,
29 struct vb2_v4l2_buffer *vb2)
30 {
31 + u64 pts;
32 buf->mmal.mmal_flags = 0;
33 if (vb2->flags & V4L2_BUF_FLAG_KEYFRAME)
34 buf->mmal.mmal_flags |= MMAL_BUFFER_HEADER_FLAG_KEYFRAME;
35 @@ -869,7 +871,10 @@ static void vb2_to_mmal_buffer(struct m2
36 if (!buf->mmal.length || vb2->flags & V4L2_BUF_FLAG_LAST)
37 buf->mmal.mmal_flags |= MMAL_BUFFER_HEADER_FLAG_EOS;
38
39 - buf->mmal.pts = vb2->vb2_buf.timestamp;
40 + /* vb2 timestamps in nsecs, mmal in usecs */
41 + pts = vb2->vb2_buf.timestamp;
42 + do_div(pts, 1000);
43 + buf->mmal.pts = pts;
44 buf->mmal.dts = MMAL_TIME_UNKNOWN;
45 }
46