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
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
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.
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
19 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
21 .../bcm2835-codec/bcm2835-v4l2-codec.c | 17 ++++++++++++++++-
22 1 file changed, 16 insertions(+), 1 deletion(-)
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;
29 struct v4l2_ctrl_handler hdl;
30 + struct v4l2_ctrl *gop_size;
32 struct vchiq_mmal_component *component;
33 bool component_enabled;
34 @@ -2286,6 +2287,17 @@ static int bcm2835_codec_s_ctrl(struct v
37 case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD:
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
46 + __v4l2_ctrl_s_ctrl(ctx->gop_size, ctrl->val);
48 + case V4L2_CID_MPEG_VIDEO_GOP_SIZE:
52 @@ -3360,7 +3372,7 @@ static int bcm2835_codec_open(struct fil
56 - v4l2_ctrl_handler_init(hdl, 12);
57 + v4l2_ctrl_handler_init(hdl, 13);
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,
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);
70 goto free_ctrl_handler;