1 From 67c1f9dd0253a1175f77e801b19bd9d923225f9c Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Fri, 10 May 2019 14:13:11 +0100
4 Subject: [PATCH] staging: bcm2835-codec: Add support for setting
7 Video encode can use the frame rate for rate control calculations,
8 therefore plumb it through from V4L2's [S|G]_PARM ioctl.
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
12 .../bcm2835-codec/bcm2835-v4l2-codec.c | 52 +++++++++++++++++--
13 1 file changed, 48 insertions(+), 4 deletions(-)
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 @@ -447,6 +447,8 @@ struct bcm2835_codec_ctx {
18 /* Source and destination queue data */
19 struct bcm2835_codec_q_data q_data[2];
21 + unsigned int framerate_num;
22 + unsigned int framerate_denom;
26 @@ -610,8 +612,8 @@ static void setup_mmal_port_format(struc
27 port->es.video.height = q_data->height;
28 port->es.video.crop.width = q_data->crop_width;
29 port->es.video.crop.height = q_data->crop_height;
30 - port->es.video.frame_rate.num = 0;
31 - port->es.video.frame_rate.den = 1;
32 + port->es.video.frame_rate.num = ctx->framerate_num;
33 + port->es.video.frame_rate.den = ctx->framerate_denom;
35 /* Compressed format - leave resolution as 0 for decode */
36 if (ctx->dev->role == DECODE) {
37 @@ -625,9 +627,9 @@ static void setup_mmal_port_format(struc
38 port->es.video.crop.width = q_data->crop_width;
39 port->es.video.crop.height = q_data->crop_height;
40 port->format.bitrate = ctx->bitrate;
41 + port->es.video.frame_rate.num = ctx->framerate_num;
42 + port->es.video.frame_rate.den = ctx->framerate_denom;
44 - port->es.video.frame_rate.num = 0;
45 - port->es.video.frame_rate.den = 1;
47 port->es.video.crop.x = 0;
48 port->es.video.crop.y = 0;
49 @@ -1361,6 +1363,41 @@ static int vidioc_s_selection(struct fil
53 +static int vidioc_s_parm(struct file *file, void *priv,
54 + struct v4l2_streamparm *parm)
56 + struct bcm2835_codec_ctx *ctx = file2ctx(file);
58 + if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
61 + ctx->framerate_num =
62 + parm->parm.output.timeperframe.denominator;
63 + ctx->framerate_denom =
64 + parm->parm.output.timeperframe.numerator;
66 + parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
71 +static int vidioc_g_parm(struct file *file, void *priv,
72 + struct v4l2_streamparm *parm)
74 + struct bcm2835_codec_ctx *ctx = file2ctx(file);
76 + if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
79 + parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
80 + parm->parm.output.timeperframe.denominator =
82 + parm->parm.output.timeperframe.numerator =
83 + ctx->framerate_denom;
88 static int vidioc_subscribe_evt(struct v4l2_fh *fh,
89 const struct v4l2_event_subscription *sub)
91 @@ -1725,6 +1762,9 @@ static const struct v4l2_ioctl_ops bcm28
92 .vidioc_g_selection = vidioc_g_selection,
93 .vidioc_s_selection = vidioc_s_selection,
95 + .vidioc_g_parm = vidioc_g_parm,
96 + .vidioc_s_parm = vidioc_s_parm,
98 .vidioc_subscribe_event = vidioc_subscribe_evt,
99 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
101 @@ -2546,6 +2586,8 @@ static int bcm2835_codec_create(struct p
103 v4l2_disable_ioctl(vfd, VIDIOC_ENCODER_CMD);
104 v4l2_disable_ioctl(vfd, VIDIOC_TRY_ENCODER_CMD);
105 + v4l2_disable_ioctl(vfd, VIDIOC_S_PARM);
106 + v4l2_disable_ioctl(vfd, VIDIOC_G_PARM);
107 video_nr = decode_video_nr;
110 @@ -2558,6 +2600,8 @@ static int bcm2835_codec_create(struct p
111 v4l2_disable_ioctl(vfd, VIDIOC_TRY_ENCODER_CMD);
112 v4l2_disable_ioctl(vfd, VIDIOC_DECODER_CMD);
113 v4l2_disable_ioctl(vfd, VIDIOC_TRY_DECODER_CMD);
114 + v4l2_disable_ioctl(vfd, VIDIOC_S_PARM);
115 + v4l2_disable_ioctl(vfd, VIDIOC_G_PARM);
116 video_nr = isp_video_nr;