bcm27xx: 6.1: add kernel patches
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-6.1 / 950-0609-staging-bcm2835-codec-Add-support-for-V4L2_CID_MPEG_.patch
1 From f096c11828df983c5581bb96e8b238543652c008 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 14 Mar 2023 16:49:46 +0000
4 Subject: [PATCH] staging: bcm2835-codec: Add support for
5 V4L2_CID_MPEG_VIDEO_GOP_SIZE
6
7 For H264, V4L2_CID_MPEG_VIDEO_H264_I_PERIOD is meant to be the intra
8 I-frame period, whilst V4L2_CID_MPEG_VIDEO_GOP_SIZE is the intra IDR
9 frame period.
10 The firmware encoder doesn't produce I-frames that aren't IDR as well,
11 therefore V4L2_CID_MPEG_VIDEO_GOP_SIZE is technically the correct
12 control, however users may have adopted V4L2_CID_MPEG_VIDEO_H264_I_PERIOD.
13
14 Add support for V4L2_CID_MPEG_VIDEO_GOP_SIZE controlling the encoder,
15 and have VIDIOC_S_CTRL for V4L2_CID_MPEG_VIDEO_H264_I_PERIOD update
16 the value for V4L2_CID_MPEG_VIDEO_GOP_SIZE (the reverse is not
17 implemented).
18
19 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
20 ---
21 .../bcm2835-codec/bcm2835-v4l2-codec.c | 17 ++++++++++++++++-
22 1 file changed, 16 insertions(+), 1 deletion(-)
23
24 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
25 +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
26 @@ -705,6 +705,7 @@ struct bcm2835_codec_ctx {
27 struct bcm2835_codec_dev *dev;
28
29 struct v4l2_ctrl_handler hdl;
30 + struct v4l2_ctrl *gop_size;
31
32 struct vchiq_mmal_component *component;
33 bool component_enabled;
34 @@ -2286,6 +2287,17 @@ static int bcm2835_codec_s_ctrl(struct v
35 break;
36
37 case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
38 + /*
39 + * Incorrect initial implementation meant that H264_I_PERIOD
40 + * was implemented to control intra-I period. As the MMAL
41 + * encoder never produces I-frames that aren't IDR frames, it
42 + * should actually have been GOP_SIZE.
43 + * Support both controls, but writing to H264_I_PERIOD will
44 + * update GOP_SIZE.
45 + */
46 + __v4l2_ctrl_s_ctrl(ctx->gop_size, ctrl->val);
47 + fallthrough;
48 + case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
49 if (!ctx->component)
50 break;
51
52 @@ -3360,7 +3372,7 @@ static int bcm2835_codec_open(struct fil
53 case ENCODE:
54 {
55 /* Encode controls */
56 - v4l2_ctrl_handler_init(hdl, 12);
57 + v4l2_ctrl_handler_init(hdl, 13);
58
59 v4l2_ctrl_new_std_menu(hdl, &bcm2835_codec_ctrl_ops,
60 V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
61 @@ -3425,6 +3437,9 @@ static int bcm2835_codec_open(struct fil
62 V4L2_CID_MPEG_VIDEO_B_FRAMES,
63 0, 0,
64 1, 0);
65 + ctx->gop_size = v4l2_ctrl_new_std(hdl, &bcm2835_codec_ctrl_ops,
66 + V4L2_CID_MPEG_VIDEO_GOP_SIZE,
67 + 0, 0x7FFFFFFF, 1, 60);
68 if (hdl->error) {
69 rc = hdl->error;
70 goto free_ctrl_handler;