History

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.

Michael Tretter committed 5 years ago

Commit 7aea2c01 parent 98f1cbf2 files · +35 −2Browse files

Unified · Split

2 files
  1. drivers/media/platform/allegro-dvt/allegro-core.c +30 −2
  2. include/uapi/linux/v4l2-controls.h +5 −0
drivers/media/platform/allegro-dvt/allegro-core.c+30−2
@@ -105,6 +105,12 @@ · 104 unmodified lines
105105 #define BETA_OFFSET_DIV_2 -1
106106 #define TC_OFFSET_DIV_2 -1
107107
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+
108114 static int debug;
109115 module_param(debug, int, 0644);
110116 MODULE_PARM_DESC(debug, "Debug level (0-2)");
@@ -275,6 +281,8 @@ struct allegro_channel { · 164 unmodified lines
275281 struct v4l2_ctrl *mpeg_video_cpb_size;
276282 struct v4l2_ctrl *mpeg_video_gop_size;
277283
284+ struct v4l2_ctrl *encoder_buffer;
285+
278286 /* user_id is used to identify the channel during CREATE_CHANNEL */
279287 /* not sure, what to set here and if this is actually required */
280288 int user_id;
@@ -1255,7 +1263,7 @@ static int fill_create_channel_param(struct allegro_channel *channel, · 974 unmodified lines
12551263 param->max_transfo_depth_intra = channel->max_transfo_depth_intra;
12561264 param->max_transfo_depth_inter = channel->max_transfo_depth_inter;
12571265
1258− param->encoder_buffer_enabled = channel->dev->has_encoder_buffer;
1266+ param->encoder_buffer_enabled = v4l2_ctrl_g_ctrl(channel->encoder_buffer);
12591267 param->encoder_buffer_offset = 0;
12601268
12611269 param->rate_control_mode = channel->frame_rc_enable ?
@@ -1381,7 +1389,7 @@ static int allegro_mcu_send_encode_frame(struct allegro_dev *dev, · 119 unmodified lines
13811389 u64 src_handle)
13821390 {
13831391 struct mcu_msg_encode_frame msg;
1384− bool use_encoder_buffer = channel->dev->has_encoder_buffer;
1392+ bool use_encoder_buffer = v4l2_ctrl_g_ctrl(channel->encoder_buffer);
13851393
13861394 memset(&msg, 0, sizeof(msg));
13871395
@@ -2466,6 +2474,8 @@ static void allegro_destroy_channel(struct allegro_channel *channel) · 1078 unmodified lines
24662474 v4l2_ctrl_grab(channel->mpeg_video_cpb_size, false);
24672475 v4l2_ctrl_grab(channel->mpeg_video_gop_size, false);
24682476
2477+ v4l2_ctrl_grab(channel->encoder_buffer, false);
2478+
24692479 if (channel->user_id != -1) {
24702480 clear_bit(channel->user_id, &dev->channel_user_ids);
24712481 channel->user_id = -1;
@@ -2532,6 +2542,8 @@ static int allegro_create_channel(struct allegro_channel *channel) · 60 unmodified lines
25322542 v4l2_ctrl_grab(channel->mpeg_video_cpb_size, true);
25332543 v4l2_ctrl_grab(channel->mpeg_video_gop_size, true);
25342544
2545+ v4l2_ctrl_grab(channel->encoder_buffer, true);
2546+
25352547 reinit_completion(&channel->completion);
25362548 allegro_mcu_send_create_channel(dev, channel);
25372549 timeout = wait_for_completion_timeout(&channel->completion,
@@ -2915,6 +2927,10 @@ static int allegro_try_ctrl(struct v4l2_ctrl *ctrl) · 377 unmodified lines
29152927 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:
29162928 allegro_clamp_bitrate(channel, ctrl);
29172929 break;
2930+ case V4L2_CID_USER_ALLEGRO_ENCODER_BUFFER:
2931+ if (!channel->dev->has_encoder_buffer)
2932+ ctrl->val = 0;
2933+ break;
29182934 }
29192935
29202936 return 0;
@@ -2955,6 +2971,16 @@ static const struct v4l2_ctrl_ops allegro_ctrl_ops = { · 34 unmodified lines
29552971 .s_ctrl = allegro_s_ctrl,
29562972 };
29572973
2974+static const struct v4l2_ctrl_config allegro_encoder_buffer_ctrl_config = {
2975+ .id = V4L2_CID_USER_ALLEGRO_ENCODER_BUFFER,
2976+ .name = "Encoder Buffer Enable",
2977+ .type = V4L2_CTRL_TYPE_BOOLEAN,
2978+ .min = 0,
2979+ .max = 1,
2980+ .step = 1,
2981+ .def = 1,
2982+};
2983+
29582984 static int allegro_open(struct file *file)
29592985 {
29602986 struct video_device *vdev = video_devdata(file);
@@ -3106,6 +3132,8 @@ static int allegro_open(struct file *file) · 145 unmodified lines
31063132 V4L2_CID_MPEG_VIDEO_GOP_SIZE,
31073133 0, ALLEGRO_GOP_SIZE_MAX,
31083134 1, ALLEGRO_GOP_SIZE_DEFAULT);
3135+ channel->encoder_buffer = v4l2_ctrl_new_custom(handler,
3136+ &allegro_encoder_buffer_ctrl_config, NULL);
31093137 v4l2_ctrl_new_std(handler,
31103138 &allegro_ctrl_ops,
31113139 V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
include/uapi/linux/v4l2-controls.h+5−0
@@ -211,6 +211,11 @@ enum v4l2_colorfx { · 210 unmodified lines
211211 * We reserve 128 controls for this driver.
212212 */
213213 #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)
214219
215220 /* MPEG-class control IDs */
216221 /* The MPEG controls are applicable to all codec controls

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t