summaryrefslogtreecommitdiff
path: root/drivers/mxc/vpu-encoder-b0/vpu_encoder_ctrl.c
blob: 37aee18aabf6c43ab4256c5d29d1ca5d46e0ad53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
/*
 * Copyright(c) 2018 NXP. All rights reserved.
 *
 * The code contained herein is licensed under the GNU General Public
 * License. You may obtain a copy of the GNU General Public License
 * Version 2 or later at the following locations:
 *
 * http://www.opensource.org/licenses/gpl-license.html
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @file vpu_encoder_ctrl.c
 *
 * Author Ming Qian<ming.qian@nxp.com>
 */

#define TAG	"[VPU Encoder Ctrl]\t "
#include <media/v4l2-ctrls.h>

#include "vpu_encoder_b0.h"
#include "vpu_encoder_ctrl.h"

// H264 level is maped like level 5.1 to uLevel 51, except level 1b to uLevel 14
const u_int32 h264_level[] = {
	[V4L2_MPEG_VIDEO_H264_LEVEL_1_0] = 10,
	[V4L2_MPEG_VIDEO_H264_LEVEL_1B]  = 14,
	[V4L2_MPEG_VIDEO_H264_LEVEL_1_1] = 11,
	[V4L2_MPEG_VIDEO_H264_LEVEL_1_2] = 12,
	[V4L2_MPEG_VIDEO_H264_LEVEL_1_3] = 13,
	[V4L2_MPEG_VIDEO_H264_LEVEL_2_0] = 20,
	[V4L2_MPEG_VIDEO_H264_LEVEL_2_1] = 21,
	[V4L2_MPEG_VIDEO_H264_LEVEL_2_2] = 22,
	[V4L2_MPEG_VIDEO_H264_LEVEL_3_0] = 30,
	[V4L2_MPEG_VIDEO_H264_LEVEL_3_1] = 31,
	[V4L2_MPEG_VIDEO_H264_LEVEL_3_2] = 32,
	[V4L2_MPEG_VIDEO_H264_LEVEL_4_0] = 40,
	[V4L2_MPEG_VIDEO_H264_LEVEL_4_1] = 41,
	[V4L2_MPEG_VIDEO_H264_LEVEL_4_2] = 42,
	[V4L2_MPEG_VIDEO_H264_LEVEL_5_0] = 50,
	[V4L2_MPEG_VIDEO_H264_LEVEL_5_1] = 51
};

static int set_h264_profile(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	mutex_lock(&ctx->instance_mutex);
	switch (ctrl->val) {
	case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
		vpu_dbg(LVL_CTRL, "set h264 profile baseline\n");
		param->eProfile = MEDIAIP_ENC_PROF_H264_BP;
		break;
	case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
		vpu_dbg(LVL_CTRL, "set h264 profile main\n");
		param->eProfile = MEDIAIP_ENC_PROF_H264_MP;
		break;
	case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
		vpu_dbg(LVL_CTRL, "set h264 profile high\n");
		param->eProfile = MEDIAIP_ENC_PROF_H264_HP;
		break;
	default:
		vpu_err("not support H264 profile %d, set to main\n",
				ctrl->val);
		param->eProfile = MEDIAIP_ENC_PROF_H264_MP;
		break;
	}
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int set_h264_level(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	mutex_lock(&ctx->instance_mutex);
	param->uLevel = h264_level[ctrl->val];
	mutex_unlock(&ctx->instance_mutex);

	vpu_dbg(LVL_CTRL, "set h264 level to %d (%d)\n",
			ctrl->val, h264_level[ctrl->val]);

	return 0;
}

static int set_bitrate_mode(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	mutex_lock(&ctx->instance_mutex);
	switch (ctrl->val) {
	case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
		vpu_dbg(LVL_CTRL, "set bitrate mode VBR\n");
		param->eBitRateMode =
				MEDIAIP_ENC_BITRATECONTROLMODE_CONSTANT_QP;
		break;
	case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
		vpu_dbg(LVL_CTRL, "set bitrate mode CBR\n");
		param->eBitRateMode = MEDIAIP_ENC_BITRATECONTROLMODE_CBR;
		break;
	default:
		vpu_err("not support bitrate mode %d, set to cbr\n",
				ctrl->val);
		param->eBitRateMode = MEDIAIP_ENC_BITRATECONTROLMODE_CBR;
		break;
	}
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int set_bitrate(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	vpu_dbg(LVL_CTRL, "set bitrate %d\n", ctrl->val);
	mutex_lock(&ctx->instance_mutex);
	param->uTargetBitrate = ctrl->val / BITRATE_COEF;
	if (param->uMaxBitRate < param->uTargetBitrate)
		param->uMaxBitRate = param->uTargetBitrate;
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int set_bitrate_peak(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	vpu_dbg(LVL_CTRL, "set peak bitrate %d\n", ctrl->val);
	mutex_lock(&ctx->instance_mutex);
	param->uMaxBitRate = ctrl->val / BITRATE_COEF;
	if (param->uTargetBitrate > param->uMaxBitRate)
		param->uTargetBitrate = param->uMaxBitRate;
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int set_gop_size(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	vpu_dbg(LVL_CTRL, "set gop size %d\n", ctrl->val);
	mutex_lock(&ctx->instance_mutex);
	param->uIFrameInterval = ctrl->val;
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int set_i_period(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	vpu_dbg(LVL_CTRL, "set iframe interval %d\n", ctrl->val);
	mutex_lock(&ctx->instance_mutex);
	param->uIFrameInterval = ctrl->val;
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int get_gop_size(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	vpu_dbg(LVL_CTRL, "get gop size\n");
	ctrl->val = param->uIFrameInterval;

	return 0;
}

static int set_b_frames(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	vpu_dbg(LVL_CTRL, "set bframes %d\n", ctrl->val);
	mutex_lock(&ctx->instance_mutex);
	param->uGopBLength = ctrl->val;
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int set_qp(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	vpu_dbg(LVL_CTRL, "set qp %d\n", ctrl->val);
	mutex_lock(&ctx->instance_mutex);
	param->uInitSliceQP = ctrl->val;
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int get_min_buffers_for_output(struct v4l2_ctrl *ctrl)
{
	vpu_dbg(LVL_CTRL, "get min buffers for output\n");

	ctrl->val = MIN_BUFFER_COUNT;

	return 0;
}

static int set_display_re_ordering(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);
	struct vpu_attr *attr = get_vpu_ctx_attr(ctx);
	pMEDIAIP_ENC_PARAM  param = &attr->param;

	vpu_dbg(LVL_CTRL, "set lowlatencymode %d\n", ctrl->val);
	mutex_lock(&ctx->instance_mutex);
	if (ctrl->val)
		param->uLowLatencyMode = 1;
	else
		param->uLowLatencyMode = 0;
	mutex_unlock(&ctx->instance_mutex);

	return 0;
}

static int set_force_key_frame(struct v4l2_ctrl *ctrl)
{
	struct vpu_ctx *ctx = v4l2_ctrl_to_ctx(ctrl);

	vpu_dbg(LVL_CTRL, "force key frame\n");
	set_bit(VPU_ENC_STATUS_KEY_FRAME, &ctx->status);

	return 0;
}

static int add_ctrl_h264_profile(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_h264_profile_ops = {
		.s_ctrl = set_h264_profile,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrl_handler,
				      &ctrl_h264_profile_ops,
				      V4L2_CID_MPEG_VIDEO_H264_PROFILE,
				      V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
				      0xa,
				      V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE);
	if (!ctrl) {
		vpu_err("add ctrl h264 profile fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_h264_level(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_h264_level_ops = {
		.s_ctrl = set_h264_level,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrl_handler,
				      &ctrl_h264_level_ops,
				      V4L2_CID_MPEG_VIDEO_H264_LEVEL,
				      V4L2_MPEG_VIDEO_H264_LEVEL_5_1,
				      0x0,
				      V4L2_MPEG_VIDEO_H264_LEVEL_4_0);
	if (!ctrl) {
		vpu_err("add ctrl h264 level fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_bitrate_mode(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_bitrate_mode_ops = {
		.s_ctrl = set_bitrate_mode,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrl_handler,
				      &ctrl_bitrate_mode_ops,
				      V4L2_CID_MPEG_VIDEO_BITRATE_MODE,
				      V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
				      0x0,
				      V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
	if (!ctrl) {
		vpu_err("add ctrl bitrate mode fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_bitrate(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_bitrate_ops = {
		.s_ctrl = set_bitrate,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
				 &ctrl_bitrate_ops,
				 V4L2_CID_MPEG_VIDEO_BITRATE,
				 BITRATE_LOW_THRESHOLD * BITRATE_COEF,
				 BITRATE_HIGH_THRESHOLD * BITRATE_COEF,
				 BITRATE_COEF,
				 BITRATE_DEFAULT_TARGET * BITRATE_COEF);
	if (!ctrl) {
		vpu_err("add ctrl bitrate fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_bitrate_peak(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_bitrate_ops = {
		.s_ctrl = set_bitrate_peak,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
				 &ctrl_bitrate_ops,
				 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK,
				 BITRATE_LOW_THRESHOLD * BITRATE_COEF,
				 BITRATE_HIGH_THRESHOLD * BITRATE_COEF,
				 BITRATE_COEF,
				 BITRATE_DEFAULT_PEAK * BITRATE_COEF);
	if (!ctrl) {
		vpu_err("add ctrl bitrate peak fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_gop_size(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_gop_ops = {
		.s_ctrl = set_gop_size,
		.g_volatile_ctrl = get_gop_size,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
				 &ctrl_gop_ops,
				 V4L2_CID_MPEG_VIDEO_GOP_SIZE,
				 GOP_L_THRESHOLD,
				 GOP_H_THRESHOLD,
				 1,
				 GOP_DEFAULT);
	if (!ctrl) {
		vpu_err("add ctrl gop size fail\n");
		return -EINVAL;
	}

	ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
	ctrl->flags |= V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;

	return 0;
}

static int add_ctrl_i_period(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_i_period_ops = {
		.s_ctrl = set_i_period,
		.g_volatile_ctrl = get_gop_size,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
			&ctrl_i_period_ops,
			V4L2_CID_MPEG_VIDEO_H264_I_PERIOD,
			GOP_L_THRESHOLD,
			GOP_H_THRESHOLD,
			1,
			GOP_DEFAULT);

	if (!ctrl) {
		vpu_err("add ctrl i period fail\n");
		return -EINVAL;
	}

	ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;
	ctrl->flags |= V4L2_CTRL_FLAG_EXECUTE_ON_WRITE;

	return 0;
}

static int add_ctrl_b_frames(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_b_frames = {
		.s_ctrl = set_b_frames,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
			&ctrl_b_frames,
			V4L2_CID_MPEG_VIDEO_B_FRAMES,
			BFRAMES_L_THRESHOLD,
			BFRAMES_H_THRESHOLD,
			1,
			BFRAMES_DEFAULT);

	if (!ctrl) {
		vpu_err("add ctrl b frames fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_i_frame_qp(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_iframe_qp_ops = {
		.s_ctrl = set_qp,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
				 &ctrl_iframe_qp_ops,
				 V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP,
				 QP_MIN,
				 QP_MAX,
				 1,
				 QP_DEFAULT);
	if (!ctrl) {
		vpu_err("add ctrl h264 I frame qp fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_p_frame_qp(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_pframe_qp_ops = {
		.s_ctrl = set_qp,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
				 &ctrl_pframe_qp_ops,
				 V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP,
				 QP_MIN,
				 QP_MAX,
				 1,
				 QP_DEFAULT);
	if (!ctrl) {
		vpu_err("add ctrl h264 P frame qp fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_b_frame_qp(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_bframe_qp_ops = {
		.s_ctrl = set_qp,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
				 &ctrl_bframe_qp_ops,
				 V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP,
				 QP_MIN,
				 QP_MAX,
				 1,
				 QP_DEFAULT);
	if (!ctrl) {
		vpu_err("add ctrl h264 B frame qp fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_min_buffers_for_output(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops ctrl_min_buffers_ops = {
		.g_volatile_ctrl = get_min_buffers_for_output,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
				 &ctrl_min_buffers_ops,
				 V4L2_CID_MIN_BUFFERS_FOR_OUTPUT,
				 1,
				 32,
				 1,
				 MIN_BUFFER_COUNT);
	if (!ctrl) {
		vpu_err("add ctrl min buffers for output fail\n");
		return -EINVAL;
	}

	ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE;

	return 0;
}

static int add_ctrl_display_re_ordering(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops re_ordering_ops = {
		.s_ctrl = set_display_re_ordering,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
			&re_ordering_ops,
			V4L2_CID_MPEG_VIDEO_H264_ASO,
			0, 1, 1, 1);
	if (!ctrl) {
		vpu_err("add ctrl display re ordering fail\n");
		return -EINVAL;
	}

	return 0;
}

static int add_ctrl_force_key_frame(struct vpu_ctx *ctx)
{
	static const struct v4l2_ctrl_ops force_key_frame_ops = {
		.s_ctrl = set_force_key_frame,
	};
	struct v4l2_ctrl *ctrl;

	ctrl = v4l2_ctrl_new_std(&ctx->ctrl_handler,
			&force_key_frame_ops,
			V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME,
			0, 0, 0, 0);
	if (!ctrl) {
		vpu_err("add ctrl force key frame fail\n");
		return -EINVAL;
	}

	return 0;
}

static int vpu_enc_register_ctrls(struct vpu_ctx *ctx)
{
	add_ctrl_h264_profile(ctx);
	add_ctrl_h264_level(ctx);
	add_ctrl_bitrate_mode(ctx);
	add_ctrl_bitrate(ctx);
	add_ctrl_bitrate_peak(ctx);
	add_ctrl_gop_size(ctx);
	add_ctrl_i_period(ctx);
	add_ctrl_b_frames(ctx);
	add_ctrl_i_frame_qp(ctx);
	add_ctrl_p_frame_qp(ctx);
	add_ctrl_b_frame_qp(ctx);
	add_ctrl_min_buffers_for_output(ctx);
	add_ctrl_display_re_ordering(ctx);
	add_ctrl_force_key_frame(ctx);

	return 0;
}

int vpu_enc_setup_ctrls(struct vpu_ctx *ctx)
{
	vpu_log_func();

	v4l2_ctrl_handler_init(&ctx->ctrl_handler, 11);
	vpu_enc_register_ctrls(ctx);
	if (ctx->ctrl_handler.error) {
		vpu_err("control initialization error (%d)\n",
			ctx->ctrl_handler.error);
		return -EINVAL;
	}
	ctx->ctrl_inited = true;
	return v4l2_ctrl_handler_setup(&ctx->ctrl_handler);
}

int vpu_enc_free_ctrls(struct vpu_ctx *ctx)
{
	vpu_log_func();

	if (ctx->ctrl_inited) {
		v4l2_ctrl_handler_free(&ctx->ctrl_handler);
		ctx->ctrl_inited = false;
	}

	return 0;
}