fd4b53766af6f36d22cd44f5cdb7a14c42312c6d
[openwrt/staging/jow.git] /
1 From 043eaabdbaf803e7db06f970b29d64f48e628fae 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 513/782] staging: bcm2835-codec: Add support for setting
5 S_PARM and G_PARM
6
7 Video encode can use the frame rate for rate control calculations,
8 therefore plumb it through from V4L2's [S|G]_PARM ioctl.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
11 ---
12 .../bcm2835-codec/bcm2835-v4l2-codec.c | 52 +++++++++++++++++--
13 1 file changed, 48 insertions(+), 4 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 @@ -447,6 +447,8 @@ struct bcm2835_codec_ctx {
18 /* Source and destination queue data */
19 struct bcm2835_codec_q_data q_data[2];
20 s32 bitrate;
21 + unsigned int framerate_num;
22 + unsigned int framerate_denom;
23
24 bool aborting;
25 int num_ip_buffers;
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;
34 } else {
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;
43 }
44 - port->es.video.frame_rate.num = 0;
45 - port->es.video.frame_rate.den = 1;
46 }
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
50 return 0;
51 }
52
53 +static int vidioc_s_parm(struct file *file, void *priv,
54 + struct v4l2_streamparm *parm)
55 +{
56 + struct bcm2835_codec_ctx *ctx = file2ctx(file);
57 +
58 + if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
59 + return -EINVAL;
60 +
61 + ctx->framerate_num =
62 + parm->parm.output.timeperframe.denominator;
63 + ctx->framerate_denom =
64 + parm->parm.output.timeperframe.numerator;
65 +
66 + parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
67 +
68 + return 0;
69 +}
70 +
71 +static int vidioc_g_parm(struct file *file, void *priv,
72 + struct v4l2_streamparm *parm)
73 +{
74 + struct bcm2835_codec_ctx *ctx = file2ctx(file);
75 +
76 + if (parm->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
77 + return -EINVAL;
78 +
79 + parm->parm.output.capability = V4L2_CAP_TIMEPERFRAME;
80 + parm->parm.output.timeperframe.denominator =
81 + ctx->framerate_num;
82 + parm->parm.output.timeperframe.numerator =
83 + ctx->framerate_denom;
84 +
85 + return 0;
86 +}
87 +
88 static int vidioc_subscribe_evt(struct v4l2_fh *fh,
89 const struct v4l2_event_subscription *sub)
90 {
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,
94
95 + .vidioc_g_parm = vidioc_g_parm,
96 + .vidioc_s_parm = vidioc_s_parm,
97 +
98 .vidioc_subscribe_event = vidioc_subscribe_evt,
99 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
100
101 @@ -2546,6 +2586,8 @@ static int bcm2835_codec_create(struct p
102 case DECODE:
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;
108 break;
109 case ENCODE:
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;
117 break;
118 default: