b431bb76f11daaa1b26bf13afef4724cac47c2f9
[openwrt/staging/rmilecki.git] /
1 From 9fd39b1fe86a26b942fc0ebf2138076758547c44 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 2 Feb 2021 15:50:18 +0000
4 Subject: [PATCH] staging/bcm2835-codec: Add support for pixel aspect
5 ratio
6
7 If the format is detected by the driver and a V4L2_EVENT_SOURCE_CHANGE
8 event is generated, then pass on the pixel aspect ratio as well.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12 .../bcm2835-codec/bcm2835-v4l2-codec.c | 31 +++++++++++++++++++
13 1 file changed, 31 insertions(+)
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 @@ -602,6 +602,7 @@ struct bcm2835_codec_q_data {
18 unsigned int crop_width;
19 unsigned int crop_height;
20 bool selection_set;
21 + struct v4l2_fract aspect_ratio;
22
23 unsigned int sizeimage;
24 unsigned int sequence;
25 @@ -981,6 +982,9 @@ static void handle_fmt_changed(struct bc
26 if (format->es.video.color_space)
27 color_mmal2v4l(ctx, format->es.video.color_space);
28
29 + q_data->aspect_ratio.numerator = format->es.video.par.num;
30 + q_data->aspect_ratio.denominator = format->es.video.par.den;
31 +
32 queue_res_chg_event(ctx);
33 }
34
35 @@ -1657,6 +1661,29 @@ static int vidioc_g_parm(struct file *fi
36 return 0;
37 }
38
39 +static int vidioc_g_pixelaspect(struct file *file, void *fh, int type,
40 + struct v4l2_fract *f)
41 +{
42 + struct bcm2835_codec_ctx *ctx = file2ctx(file);
43 +
44 + /*
45 + * The selection API takes V4L2_BUF_TYPE_VIDEO_CAPTURE and
46 + * V4L2_BUF_TYPE_VIDEO_OUTPUT, even if the device implements the MPLANE
47 + * API. The V4L2 core will have converted the MPLANE variants to
48 + * non-MPLANE.
49 + * Open code this instead of using get_q_data in this case.
50 + */
51 + if (ctx->dev->role != DECODE)
52 + return -ENOIOCTLCMD;
53 +
54 + if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
55 + return -EINVAL;
56 +
57 + *f = ctx->q_data[V4L2_M2M_DST].aspect_ratio;
58 +
59 + return 0;
60 +}
61 +
62 static int vidioc_subscribe_evt(struct v4l2_fh *fh,
63 const struct v4l2_event_subscription *sub)
64 {
65 @@ -2082,6 +2109,8 @@ static const struct v4l2_ioctl_ops bcm28
66 .vidioc_g_parm = vidioc_g_parm,
67 .vidioc_s_parm = vidioc_s_parm,
68
69 + .vidioc_g_pixelaspect = vidioc_g_pixelaspect,
70 +
71 .vidioc_subscribe_event = vidioc_subscribe_evt,
72 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
73
74 @@ -2640,6 +2669,8 @@ static int bcm2835_codec_open(struct fil
75 ctx->q_data[V4L2_M2M_DST].crop_width,
76 ctx->q_data[V4L2_M2M_DST].height,
77 ctx->q_data[V4L2_M2M_DST].fmt);
78 + ctx->q_data[V4L2_M2M_DST].aspect_ratio.numerator = 1;
79 + ctx->q_data[V4L2_M2M_DST].aspect_ratio.denominator = 1;
80
81 ctx->colorspace = V4L2_COLORSPACE_REC709;
82 ctx->bitrate = 10 * 1000 * 1000;