Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: allegro: add control to disable encoder buffer

The encoder buffer can have a negative impact on the quality of the
encoded video.

Add a control to allow user space to disable the encoder buffer per
channel if the VCU supports the encoder buffer but the quality is not
sufficient.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>

authored by

Michael Tretter and committed by
Mauro Carvalho Chehab
7aea2c0b 98f1cbf6

+35 -2
+30 -2
drivers/media/platform/allegro-dvt/allegro-core.c
··· 105 105 #define BETA_OFFSET_DIV_2 -1 106 106 #define TC_OFFSET_DIV_2 -1 107 107 108 + /* 109 + * This control allows applications to explicitly disable the encoder buffer. 110 + * This value is Allegro specific. 111 + */ 112 + #define V4L2_CID_USER_ALLEGRO_ENCODER_BUFFER (V4L2_CID_USER_ALLEGRO_BASE + 0) 113 + 108 114 static int debug; 109 115 module_param(debug, int, 0644); 110 116 MODULE_PARM_DESC(debug, "Debug level (0-2)"); ··· 280 274 }; 281 275 struct v4l2_ctrl *mpeg_video_cpb_size; 282 276 struct v4l2_ctrl *mpeg_video_gop_size; 277 + 278 + struct v4l2_ctrl *encoder_buffer; 283 279 284 280 /* user_id is used to identify the channel during CREATE_CHANNEL */ 285 281 /* not sure, what to set here and if this is actually required */ ··· 1263 1255 param->max_transfo_depth_intra = channel->max_transfo_depth_intra; 1264 1256 param->max_transfo_depth_inter = channel->max_transfo_depth_inter; 1265 1257 1266 - param->encoder_buffer_enabled = channel->dev->has_encoder_buffer; 1258 + param->encoder_buffer_enabled = v4l2_ctrl_g_ctrl(channel->encoder_buffer); 1267 1259 param->encoder_buffer_offset = 0; 1268 1260 1269 1261 param->rate_control_mode = channel->frame_rc_enable ? ··· 1389 1381 u64 src_handle) 1390 1382 { 1391 1383 struct mcu_msg_encode_frame msg; 1392 - bool use_encoder_buffer = channel->dev->has_encoder_buffer; 1384 + bool use_encoder_buffer = v4l2_ctrl_g_ctrl(channel->encoder_buffer); 1393 1385 1394 1386 memset(&msg, 0, sizeof(msg)); 1395 1387 ··· 2474 2466 v4l2_ctrl_grab(channel->mpeg_video_cpb_size, false); 2475 2467 v4l2_ctrl_grab(channel->mpeg_video_gop_size, false); 2476 2468 2469 + v4l2_ctrl_grab(channel->encoder_buffer, false); 2470 + 2477 2471 if (channel->user_id != -1) { 2478 2472 clear_bit(channel->user_id, &dev->channel_user_ids); 2479 2473 channel->user_id = -1; ··· 2541 2531 v4l2_ctrl_grab(channel->mpeg_video_bitrate_peak, true); 2542 2532 v4l2_ctrl_grab(channel->mpeg_video_cpb_size, true); 2543 2533 v4l2_ctrl_grab(channel->mpeg_video_gop_size, true); 2534 + 2535 + v4l2_ctrl_grab(channel->encoder_buffer, true); 2544 2536 2545 2537 reinit_completion(&channel->completion); 2546 2538 allegro_mcu_send_create_channel(dev, channel); ··· 2927 2915 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: 2928 2916 allegro_clamp_bitrate(channel, ctrl); 2929 2917 break; 2918 + case V4L2_CID_USER_ALLEGRO_ENCODER_BUFFER: 2919 + if (!channel->dev->has_encoder_buffer) 2920 + ctrl->val = 0; 2921 + break; 2930 2922 } 2931 2923 2932 2924 return 0; ··· 2969 2953 static const struct v4l2_ctrl_ops allegro_ctrl_ops = { 2970 2954 .try_ctrl = allegro_try_ctrl, 2971 2955 .s_ctrl = allegro_s_ctrl, 2956 + }; 2957 + 2958 + static const struct v4l2_ctrl_config allegro_encoder_buffer_ctrl_config = { 2959 + .id = V4L2_CID_USER_ALLEGRO_ENCODER_BUFFER, 2960 + .name = "Encoder Buffer Enable", 2961 + .type = V4L2_CTRL_TYPE_BOOLEAN, 2962 + .min = 0, 2963 + .max = 1, 2964 + .step = 1, 2965 + .def = 1, 2972 2966 }; 2973 2967 2974 2968 static int allegro_open(struct file *file) ··· 3132 3106 V4L2_CID_MPEG_VIDEO_GOP_SIZE, 3133 3107 0, ALLEGRO_GOP_SIZE_MAX, 3134 3108 1, ALLEGRO_GOP_SIZE_DEFAULT); 3109 + channel->encoder_buffer = v4l2_ctrl_new_custom(handler, 3110 + &allegro_encoder_buffer_ctrl_config, NULL); 3135 3111 v4l2_ctrl_new_std(handler, 3136 3112 &allegro_ctrl_ops, 3137 3113 V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
+5
include/uapi/linux/v4l2-controls.h
··· 211 211 * We reserve 128 controls for this driver. 212 212 */ 213 213 #define V4L2_CID_USER_CCS_BASE (V4L2_CID_USER_BASE + 0x10f0) 214 + /* 215 + * The base for Allegro driver controls. 216 + * We reserve 16 controls for this driver. 217 + */ 218 + #define V4L2_CID_USER_ALLEGRO_BASE (V4L2_CID_USER_BASE + 0x1170) 214 219 215 220 /* MPEG-class control IDs */ 216 221 /* The MPEG controls are applicable to all codec controls