media: Add V4L2 H.264 stateless encode and VC8000E support
cover media: Add V4L2 H.264 stateless encode and VC8000E support
This series introduces support for the V4L2 H.264 stateless encode uAPI, core and support in the hantro driver for the Verisilicon VC8000E.
While this is a first version that will likely need some level of rework, it is already usable for most common use-cases and supports constant bitrate rate-control.
A GStreamer tree can be used to test the series at:
https://github.com/paulkocialkowski/gstreamer/tree/v4l2codecs/h264enc
And an example pipeline would look like:
gst-launch-1.0 videotestsrc pattern=smpte num-buffers=25 ! video/x-raw,width=640,height=480 ! v4l2slh264enc rate-control=cbr bitrate=8000000 qp-min=8 qp-max=42 ! h264parse ! matroskamux ! filesink location=encode.mkv
Note that documentation for the new uAPI is intentionally left out of this series since it has not yet received approval.
Marco Felsch (2):
media: hantro: use hantro_decoded_buffer only for dst_vq
arm64: dts: imx8mp: add VC8000E encoder node
Paul Kocialkowski (12):
media: h264: Add a more generic reflist builder init
media: uapi: Add H.264 stateless encode support
media: h264: Add SPS video definitions
media: h264: Add stateless encode core
media: h264: Add stateless encode rbsp
media: h264: Add stateless encode reference management
media: h264: Add stateless encode rate control
media: verisilicon: Report default pixel coding for non-JPEG and fix
JPEG case
media: verisilicon: Cancel job with runtime pm put/clk disable on
failure
media: verisilicon: Add common encoder parm and frameintervals ioctls
media: verisilicon: Add support for the VC8000E H.264 encoder
media: verilisicon: imx8m: Add support for the VC8000E on i.MX8MP
arch/arm64/boot/dts/freescale/imx8mp.dtsi | 11 + drivers/media/platform/verisilicon/Kconfig | 1 + drivers/media/platform/verisilicon/Makefile | 2 + drivers/media/platform/verisilicon/hantro.h | 17 + .../media/platform/verisilicon/hantro_drv.c | 180 +- .../media/platform/verisilicon/hantro_h264.c | 6 +- .../media/platform/verisilicon/hantro_hw.h | 28 + .../media/platform/verisilicon/hantro_v4l2.c | 123 +- .../platform/verisilicon/hantro_vc8000e.c | 68 + .../verisilicon/hantro_vc8000e_h264_enc.c | 883 +++++++ .../verisilicon/hantro_vc8000e_regs.h | 2129 +++++++++++++++++ .../media/platform/verisilicon/imx8m_vpu_hw.c | 113 + drivers/media/v4l2-core/Kconfig | 4 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-ctrls-core.c | 62 + drivers/media/v4l2-core/v4l2-ctrls-defs.c | 4 + drivers/media/v4l2-core/v4l2-h264-enc-rbsp.c | 1173 +++++++++ drivers/media/v4l2-core/v4l2-h264-enc-rc.c | 558 +++++ drivers/media/v4l2-core/v4l2-h264-enc.c | 1322 ++++++++++ drivers/media/v4l2-core/v4l2-h264.c | 69 + include/media/v4l2-ctrls.h | 2 + include/media/v4l2-h264-enc-rbsp.h | 72 + include/media/v4l2-h264-enc-rc.h | 108 + include/media/v4l2-h264-enc.h | 135 ++ include/media/v4l2-h264.h | 146 ++ include/uapi/linux/v4l2-controls.h | 33 + include/uapi/linux/videodev2.h | 1 + 27 files changed, 7231 insertions(+), 21 deletions(-) create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e.c create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e_h264_enc.c create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e_regs.h create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc-rbsp.c create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc-rc.c create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc.c create mode 100644 include/media/v4l2-h264-enc-rbsp.h create mode 100644 include/media/v4l2-h264-enc-rc.h create mode 100644 include/media/v4l2-h264-enc.h
Signature · 1 line
2.53.0
PATCH 1/14 media: h264: Add a more generic reflist builder init
This should become part of a larger reflist builder rework.
--- drivers/media/v4l2-core/v4l2-h264.c | 69 +++++++++++++++++++++++++++++ include/media/v4l2-h264.h | 7 +++ 2 files changed, 76 insertions(+)
drivers/media/v4l2-core/v4l2-h264.c +69 -0
@@ -105,6 +105,75 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b, }EXPORT_SYMBOL_GPL (v4l2_h264_init_reflist_builder); +void +v4l2_h264_init_reflist_builder_gen (struct v4l2_h264_reflist_builder *b, +const struct v4l2_ctrl_h264_sps *sps, +const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ], +unsigned int pic_order_count,unsigned int frame_num,unsigned int fields) +{ +int cur_frame_num, max_frame_num; +unsigned int i; + + max_frame_num =1 << (sps->log2_max_frame_num_minus4 +4 ); + cur_frame_num = frame_num; + +memset (b,0 ,sizeof (*b)); + b->cur_pic_order_count = pic_order_count; + b->cur_pic_fields = fields; + +for (i =0 ; i <V4L2_H264_NUM_DPB_ENTRIES ; i++) { +if (!(dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE )) +continue ; + +if (dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM ) + b->refs[i].longterm = true; + +/* +* Handle frame_num wraparound as described in section +* '8.2.4.1 Decoding process for picture numbers' of the spec. +* For long term references, frame_num is set to +* long_term_frame_idx which requires no wrapping. +*/ +if (!b->refs[i].longterm && dpb[i].frame_num > cur_frame_num) + b->refs[i].frame_num = (int )dpb[i].frame_num - + max_frame_num; +else + b->refs[i].frame_num = dpb[i].frame_num; + + b->refs[i].top_field_order_cnt = dpb[i].top_field_order_cnt; + b->refs[i].bottom_field_order_cnt = dpb[i].bottom_field_order_cnt; + +if (b->cur_pic_fields ==V4L2_H264_FRAME_REF ) { +u8 fields =V4L2_H264_FRAME_REF ; + + b->unordered_reflist[b->num_valid].index = i; + b->unordered_reflist[b->num_valid].fields = fields; + b->num_valid++; +continue ; + } + +if (dpb[i].fields &V4L2_H264_TOP_FIELD_REF ) { +u8 fields =V4L2_H264_TOP_FIELD_REF ; + + b->unordered_reflist[b->num_valid].index = i; + b->unordered_reflist[b->num_valid].fields = fields; + b->num_valid++; + } + +if (dpb[i].fields &V4L2_H264_BOTTOM_FIELD_REF ) { +u8 fields =V4L2_H264_BOTTOM_FIELD_REF ; + + b->unordered_reflist[b->num_valid].index = i; + b->unordered_reflist[b->num_valid].fields = fields; + b->num_valid++; + } + } + +for (i = b->num_valid; i <ARRAY_SIZE (b->unordered_reflist); i++) + b->unordered_reflist[i].index = i; +} +EXPORT_SYMBOL_GPL (v4l2_h264_init_reflist_builder_gen); +static s32 v4l2_h264_get_poc (const struct v4l2_h264_reflist_builder *b,const struct v4l2_h264_reference *ref) {
include/media/v4l2-h264.h +7 -0
@@ -42,6 +42,7 @@ struct v4l2_h264_reflist_builder {u8 cur_pic_fields;struct v4l2_h264_reference unordered_reflist[V4L2_H264_REF_LIST_LEN ]; +/* FIXME: confusing with valid flag (active is checked). Proper terminology is "used" */ u8 num_valid; };
@@ -51,6 +52,12 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,const struct v4l2_ctrl_h264_sps *sps, const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]); +void +v4l2_h264_init_reflist_builder_gen (struct v4l2_h264_reflist_builder *b, +const struct v4l2_ctrl_h264_sps *sps, +const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ], +unsigned int pic_order_count,unsigned int frame_num,unsigned int fields); +/** * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists *
Signature · 1 line
2.53.0
Nicolas Dufresne
maintainerRe: [PATCH 01/14] media: h264: Add a more generic reflist builder init
Hi,
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 1 line
This should become part of a larger reflist builder rework.
Maybe a tiny bit more meet would help? What am I reviewing, what is this new builder used for?
Quoted 12 lines
Signed-off-by Paul Kocialkowski <[email protected]>--- drivers/media/v4l2-core/v4l2-h264.c | 69 +++++++++++++++++++++++++++++ include/media/v4l2-h264.h | 7 +++ 2 files changed, 76 insertions(+)drivers/media/v4l2-core/v4l2-h264.c +0
-0
drivers/media/v4l2-core/v4l2-h264.c v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b, · line 112
Quoted 8 lines
drivers/media/v4l2-core/v4l2-h264.c +5
-0@@ -105,6 +105,75 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b, }EXPORT_SYMBOL_GPL (v4l2_h264_init_reflist_builder); +void +v4l2_h264_init_reflist_builder_gen (struct v4l2_h264_reflist_builder *b, +const struct v4l2_ctrl_h264_sps *sps, +const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ], +unsigned int pic_order_count,unsigned int frame_num,unsigned int fields)
Add a doc comment.
Quoted 72 lines
drivers/media/v4l2-core/v4l2-h264.c +64
-0+{ +int cur_frame_num, max_frame_num; +unsigned int i; + + max_frame_num =1 << (sps->log2_max_frame_num_minus4 +4 ); + cur_frame_num = frame_num; + +memset (b,0 ,sizeof (*b)); + b->cur_pic_order_count = pic_order_count; + b->cur_pic_fields = fields; + +for (i =0 ; i <V4L2_H264_NUM_DPB_ENTRIES ; i++) { +if (!(dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE )) +continue ; + +if (dpb[i].flags &V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM ) + b->refs[i].longterm = true; + +/* +* Handle frame_num wraparound as described in section +* '8.2.4.1 Decoding process for picture numbers' of the spec. +* For long term references, frame_num is set to +* long_term_frame_idx which requires no wrapping. +*/ +if (!b->refs[i].longterm && dpb[i].frame_num > cur_frame_num) + b->refs[i].frame_num = (int )dpb[i].frame_num - + max_frame_num; +else + b->refs[i].frame_num = dpb[i].frame_num; + + b->refs[i].top_field_order_cnt = dpb[i].top_field_order_cnt; + b->refs[i].bottom_field_order_cnt = dpb[i].bottom_field_order_cnt; + +if (b->cur_pic_fields ==V4L2_H264_FRAME_REF ) { +u8 fields =V4L2_H264_FRAME_REF ; + + b->unordered_reflist[b->num_valid].index = i; + b->unordered_reflist[b->num_valid].fields = fields; + b->num_valid++; +continue ; + } + +if (dpb[i].fields &V4L2_H264_TOP_FIELD_REF ) { +u8 fields =V4L2_H264_TOP_FIELD_REF ; + + b->unordered_reflist[b->num_valid].index = i; + b->unordered_reflist[b->num_valid].fields = fields; + b->num_valid++; + } + +if (dpb[i].fields &V4L2_H264_BOTTOM_FIELD_REF ) { +u8 fields =V4L2_H264_BOTTOM_FIELD_REF ; + + b->unordered_reflist[b->num_valid].index = i; + b->unordered_reflist[b->num_valid].fields = fields; + b->num_valid++; + } + } + +for (i = b->num_valid; i <ARRAY_SIZE (b->unordered_reflist); i++) + b->unordered_reflist[i].index = i; +} +EXPORT_SYMBOL_GPL (v4l2_h264_init_reflist_builder_gen); +static s32 v4l2_h264_get_poc (const struct v4l2_h264_reflist_builder *b,const struct v4l2_h264_reference *ref) {include/media/v4l2-h264.h +0
-0
include/media/v4l2-h264.h struct v4l2_h264_reflist_builder { · line 45
Quoted 4 lines
include/media/v4l2-h264.h +1
-0@@ -42,6 +42,7 @@ struct v4l2_h264_reflist_builder {u8 cur_pic_fields;struct v4l2_h264_reference unordered_reflist[V4L2_H264_REF_LIST_LEN ]; +/* FIXME: confusing with valid flag (active is checked). Proper terminology is "used" */
Just drop a patch before that rename it?
Quoted 17 lines
include/media/v4l2-h264.h +6
-0u8 num_valid; };@@ -51,6 +52,12 @@ v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b,const struct v4l2_ctrl_h264_sps *sps, const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES]); +void +v4l2_h264_init_reflist_builder_gen (struct v4l2_h264_reflist_builder *b, +const struct v4l2_ctrl_h264_sps *sps, +const struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ], +unsigned int pic_order_count,unsigned int frame_num,unsigned int fields); +/** * v4l2_h264_build_b_ref_lists() - Build the B0/B1 reference lists *
PATCH 2/14 media: uapi: Add H.264 stateless encode support
In reply to Paul KocialkowskiThis introduces the stateless H.264 encode params control that allows configuring an H.264 encode run.
Note that the current uAPI does not support explicit passing of references and works following the sliding window decoded reference picture marking process. This may change in the future.
--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 62 +++++++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 4 ++ include/media/v4l2-ctrls.h | 2 + include/uapi/linux/v4l2-controls.h | 33 ++++++++++++ include/uapi/linux/videodev2.h | 1 + 5 files changed, 102 insertions(+)
drivers/media/v4l2-core/v4l2-ctrls-core.c +62 -0
@@ -382,6 +382,9 @@ void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl)case V4L2_CTRL_TYPE_H264_PRED_WEIGHTS :pr_cont ("H264_PRED_WEIGHTS" );break ; +case V4L2_CTRL_TYPE_H264_ENCODE_PARAMS : +pr_cont ("H264_ENCODE_PARAMS" ); +break ;case V4L2_CTRL_TYPE_FWHT_PARAMS :pr_cont ("FWHT_PARAMS" );break ;
@@ -880,6 +883,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;struct v4l2_ctrl_h264_decode_params *p_h264_dec_params; +struct v4l2_ctrl_h264_encode_params *p_h264_enc_params;struct v4l2_ctrl_hevc_sps *p_hevc_sps;struct v4l2_ctrl_hevc_pps *p_hevc_pps;struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;
@@ -1102,6 +1106,61 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,zero_reserved (*p_h264_dec_params);break ; +case V4L2_CTRL_TYPE_H264_ENCODE_PARAMS : + p_h264_enc_params = p; + +if (p_h264_enc_params->slice_type !=V4L2_H264_SLICE_TYPE_B ) + p_h264_enc_params->flags &= + ~V4L2_H264_ENCODE_FLAG_DIRECT_SPATIAL_MV_PRED ; +if (!(p_h264_enc_params->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC ) || + !p_h264_enc_params->nal_ref_idc) + p_h264_enc_params->flags &= + ~V4L2_H264_ENCODE_FLAG_LONG_TERM_REFERENCE ; + +if (p_h264_enc_params->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC && + p_h264_enc_params->slice_type !=V4L2_H264_SLICE_TYPE_I ) +return -EINVAL ; +if (p_h264_enc_params->colour_plane_id >2 ) +return -EINVAL ; +if (p_h264_enc_params->cabac_init_idc >2 ) +return -EINVAL ; +if (p_h264_enc_params->disable_deblocking_filter_idc >2 ) +return -EINVAL ; +if (p_h264_enc_params->slice_alpha_c0_offset_div2 <-6 || + p_h264_enc_params->slice_alpha_c0_offset_div2 >6 ) +return -EINVAL ; +if (p_h264_enc_params->slice_beta_offset_div2 <-6 || + p_h264_enc_params->slice_beta_offset_div2 >6 ) +return -EINVAL ; + +if (p_h264_enc_params->slice_type ==V4L2_H264_SLICE_TYPE_I || + p_h264_enc_params->slice_type ==V4L2_H264_SLICE_TYPE_SI ) + p_h264_enc_params->num_ref_idx_l0_active_minus1 =0 ; +if (p_h264_enc_params->slice_type !=V4L2_H264_SLICE_TYPE_B ) + p_h264_enc_params->num_ref_idx_l1_active_minus1 =0 ; + +if (p_h264_enc_params->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC ) { + p_h264_enc_params->frame_num =0 ; + p_h264_enc_params->pic_order_cnt_lsb =0 ; + p_h264_enc_params->delta_pic_order_cnt_bottom =0 ; + p_h264_enc_params->delta_pic_order_cnt0 =0 ; + p_h264_enc_params->delta_pic_order_cnt1 =0 ; + }else { + p_h264_enc_params->idr_pic_id =0 ; + } + +if (p_h264_enc_params->num_ref_idx_l0_active_minus1 > + (V4L2_H264_REF_LIST_LEN -1 )) +return -EINVAL ; +if (p_h264_enc_params->num_ref_idx_l1_active_minus1 > + (V4L2_H264_REF_LIST_LEN -1 )) +return -EINVAL ; +memset (&p_h264_enc_params->reserved0,0 , +sizeof (p_h264_enc_params->reserved0)); +memset (&p_h264_enc_params->reserved1,0 , +sizeof (p_h264_enc_params->reserved1)); +break ; +case V4L2_CTRL_TYPE_VP8_FRAME : p_vp8_frame = p;
@@ -1913,6 +1972,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,case V4L2_CTRL_TYPE_H264_PRED_WEIGHTS : elem_size =sizeof (struct v4l2_ctrl_h264_pred_weights );break ; +case V4L2_CTRL_TYPE_H264_ENCODE_PARAMS : + elem_size =sizeof (struct v4l2_ctrl_h264_encode_params ); +break ;case V4L2_CTRL_TYPE_VP8_FRAME : elem_size =sizeof (struct v4l2_ctrl_vp8_frame );break ;
drivers/media/v4l2-core/v4l2-ctrls-defs.c +4 -0
@@ -1216,6 +1216,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_STATELESS_H264_PPS :return "H264 Picture Parameter Set" ;case V4L2_CID_STATELESS_H264_SCALING_MATRIX :return "H264 Scaling Matrix" ;case V4L2_CID_STATELESS_H264_PRED_WEIGHTS :return "H264 Prediction Weight Table" ; +case V4L2_CID_STATELESS_H264_ENCODE_PARAMS :return "H264 Encode Parameters" ;case V4L2_CID_STATELESS_H264_SLICE_PARAMS :return "H264 Slice Parameters" ;case V4L2_CID_STATELESS_H264_DECODE_PARAMS :return "H264 Decode Parameters" ;case V4L2_CID_STATELESS_FWHT_PARAMS :return "FWHT Stateless Parameters" ;
@@ -1555,6 +1556,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_STATELESS_H264_PRED_WEIGHTS : *type =V4L2_CTRL_TYPE_H264_PRED_WEIGHTS ;break ; +case V4L2_CID_STATELESS_H264_ENCODE_PARAMS : + *type =V4L2_CTRL_TYPE_H264_ENCODE_PARAMS ; +break ;case V4L2_CID_STATELESS_VP8_FRAME : *type =V4L2_CTRL_TYPE_VP8_FRAME ;break ;
include/media/v4l2-ctrls.h +2 -0
@@ -42,6 +42,7 @@ struct video_device;* @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix. * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params. * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params. +* @p_h264_encode_params: Pointer to a struct v4l2_ctrl_h264_encode_params. * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights. * @p_vp8_frame: Pointer to a VP8 frame params structure. * @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure.
@@ -76,6 +77,7 @@ union v4l2_ctrl_ptr {struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;struct v4l2_ctrl_h264_decode_params *p_h264_decode_params; +struct v4l2_ctrl_h264_encode_params *p_h264_encode_params;struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;struct v4l2_ctrl_vp8_frame *p_vp8_frame;struct v4l2_ctrl_hevc_sps *p_hevc_sps;
include/uapi/linux/v4l2-controls.h +33 -0
@@ -1568,6 +1568,7 @@ struct v4l2_h264_reference {#define V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED 0x01#define V4L2_H264_SLICE_FLAG_SP_FOR_SWITCH 0x02 +#define V4L2_H264_SLICE_FLAG_NUM_REF_IDX_ACTIVE_OVERRIDE 0x04#define V4L2_CID_STATELESS_H264_SLICE_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 6)/**
@@ -1707,6 +1708,38 @@ struct v4l2_ctrl_h264_decode_params {__u32 flags; }; +#define V4L2_H264_ENCODE_FLAG_IDR_PIC 0x01 +#define V4L2_H264_ENCODE_FLAG_FIELD_PIC 0x02 +#define V4L2_H264_ENCODE_FLAG_BOTTOM_FIELD 0x04 +#define V4L2_H264_ENCODE_FLAG_DIRECT_SPATIAL_MV_PRED 0x08 +#define V4L2_H264_ENCODE_FLAG_NUM_REF_IDX_ACTIVE_OVERRIDE 0x10 +#define V4L2_H264_ENCODE_FLAG_NO_OUTPUT_OF_PRIOR_PICS 0x20 +#define V4L2_H264_ENCODE_FLAG_LONG_TERM_REFERENCE 0x40 + +#define V4L2_CID_STATELESS_H264_ENCODE_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 8) +struct v4l2_ctrl_h264_encode_params { +__u8 nal_ref_idc; +__u8 slice_type; +__u8 pic_parameter_set_id; +__u8 colour_plane_id; +__u16 frame_num; +__u16 idr_pic_id; +__u16 pic_order_cnt_lsb; +__u8 reserved0[2 ]; +__s32 delta_pic_order_cnt_bottom; +__s32 delta_pic_order_cnt0; +__s32 delta_pic_order_cnt1; +__u8 num_ref_idx_l0_active_minus1; +__u8 num_ref_idx_l1_active_minus1; +__u8 cabac_init_idc; +__s8 slice_qp_delta; +__u8 disable_deblocking_filter_idc; +__s8 slice_alpha_c0_offset_div2; +__s8 slice_beta_offset_div2; +__u8 reserved1[6 ]; +__u32 flags;/* V4L2_H264_ENCODE_FLAG_ */ +}; +/* Stateless FWHT control, used by the vicodec driver */ /* Current FWHT version */
include/uapi/linux/videodev2.h +1 -0
@@ -1964,6 +1964,7 @@ enum v4l2_ctrl_type {V4L2_CTRL_TYPE_H264_SLICE_PARAMS =0x0203 ,V4L2_CTRL_TYPE_H264_DECODE_PARAMS =0x0204 ,V4L2_CTRL_TYPE_H264_PRED_WEIGHTS =0x0205 , +V4L2_CTRL_TYPE_H264_ENCODE_PARAMS =0x0206 , V4L2_CTRL_TYPE_FWHT_PARAMS = 0x0220,
Signature · 1 line
2.53.0
Nicolas Dufresne
maintainerRe: [PATCH 02/14] media: uapi: Add H.264 stateless encode support
Hi,
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 6 lines
This introduces the stateless H.264 encode params control that allows configuring an H.264 encode run.
Note that the current uAPI does not support explicit passing of references and works following the sliding window decoded reference picture marking process. This may change in the future.
Since its no longer an RFC, you have to support this with a how it can change in the future without breaking the API. Its fine to create a entry profile for encoders of course, we need a plan though.
Quoted 159 lines
Signed-off-by Paul Kocialkowski <[email protected]>--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 62 +++++++++++++++++++++++ drivers/media/v4l2-core/v4l2-ctrls-defs.c | 4 ++ include/media/v4l2-ctrls.h | 2 + include/uapi/linux/v4l2-controls.h | 33 ++++++++++++ include/uapi/linux/videodev2.h | 1 + 5 files changed, 102 insertions(+)drivers/media/v4l2-core/v4l2-ctrls-core.c +62
-0@@ -382,6 +382,9 @@ void v4l2_ctrl_type_op_log(const struct v4l2_ctrl *ctrl)case V4L2_CTRL_TYPE_H264_PRED_WEIGHTS :pr_cont ("H264_PRED_WEIGHTS" );break ; +case V4L2_CTRL_TYPE_H264_ENCODE_PARAMS : +pr_cont ("H264_ENCODE_PARAMS" ); +break ;case V4L2_CTRL_TYPE_FWHT_PARAMS :pr_cont ("FWHT_PARAMS" );break ;@@ -880,6 +883,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;struct v4l2_ctrl_h264_decode_params *p_h264_dec_params; +struct v4l2_ctrl_h264_encode_params *p_h264_enc_params;struct v4l2_ctrl_hevc_sps *p_hevc_sps;struct v4l2_ctrl_hevc_pps *p_hevc_pps;struct v4l2_ctrl_hdr10_mastering_display *p_hdr10_mastering;@@ -1102,6 +1106,61 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,zero_reserved (*p_h264_dec_params);break ; +case V4L2_CTRL_TYPE_H264_ENCODE_PARAMS : + p_h264_enc_params = p; + +if (p_h264_enc_params->slice_type !=V4L2_H264_SLICE_TYPE_B ) + p_h264_enc_params->flags &= + ~V4L2_H264_ENCODE_FLAG_DIRECT_SPATIAL_MV_PRED ; +if (!(p_h264_enc_params->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC ) || + !p_h264_enc_params->nal_ref_idc) + p_h264_enc_params->flags &= + ~V4L2_H264_ENCODE_FLAG_LONG_TERM_REFERENCE ; + +if (p_h264_enc_params->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC && + p_h264_enc_params->slice_type !=V4L2_H264_SLICE_TYPE_I ) +return -EINVAL ; +if (p_h264_enc_params->colour_plane_id >2 ) +return -EINVAL ; +if (p_h264_enc_params->cabac_init_idc >2 ) +return -EINVAL ; +if (p_h264_enc_params->disable_deblocking_filter_idc >2 ) +return -EINVAL ; +if (p_h264_enc_params->slice_alpha_c0_offset_div2 <-6 || + p_h264_enc_params->slice_alpha_c0_offset_div2 >6 ) +return -EINVAL ; +if (p_h264_enc_params->slice_beta_offset_div2 <-6 || + p_h264_enc_params->slice_beta_offset_div2 >6 ) +return -EINVAL ; + +if (p_h264_enc_params->slice_type ==V4L2_H264_SLICE_TYPE_I || + p_h264_enc_params->slice_type ==V4L2_H264_SLICE_TYPE_SI ) + p_h264_enc_params->num_ref_idx_l0_active_minus1 =0 ; +if (p_h264_enc_params->slice_type !=V4L2_H264_SLICE_TYPE_B ) + p_h264_enc_params->num_ref_idx_l1_active_minus1 =0 ; + +if (p_h264_enc_params->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC ) { + p_h264_enc_params->frame_num =0 ; + p_h264_enc_params->pic_order_cnt_lsb =0 ; + p_h264_enc_params->delta_pic_order_cnt_bottom =0 ; + p_h264_enc_params->delta_pic_order_cnt0 =0 ; + p_h264_enc_params->delta_pic_order_cnt1 =0 ; + }else { + p_h264_enc_params->idr_pic_id =0 ; + } + +if (p_h264_enc_params->num_ref_idx_l0_active_minus1 > + (V4L2_H264_REF_LIST_LEN -1 )) +return -EINVAL ; +if (p_h264_enc_params->num_ref_idx_l1_active_minus1 > + (V4L2_H264_REF_LIST_LEN -1 )) +return -EINVAL ; +memset (&p_h264_enc_params->reserved0,0 , +sizeof (p_h264_enc_params->reserved0)); +memset (&p_h264_enc_params->reserved1,0 , +sizeof (p_h264_enc_params->reserved1)); +break ; +case V4L2_CTRL_TYPE_VP8_FRAME : p_vp8_frame = p;@@ -1913,6 +1972,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,case V4L2_CTRL_TYPE_H264_PRED_WEIGHTS : elem_size =sizeof (struct v4l2_ctrl_h264_pred_weights );break ; +case V4L2_CTRL_TYPE_H264_ENCODE_PARAMS : + elem_size =sizeof (struct v4l2_ctrl_h264_encode_params ); +break ;case V4L2_CTRL_TYPE_VP8_FRAME : elem_size =sizeof (struct v4l2_ctrl_vp8_frame );break ;drivers/media/v4l2-core/v4l2-ctrls-defs.c +4
-0@@ -1216,6 +1216,7 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_STATELESS_H264_PPS :return "H264 Picture Parameter Set" ;case V4L2_CID_STATELESS_H264_SCALING_MATRIX :return "H264 Scaling Matrix" ;case V4L2_CID_STATELESS_H264_PRED_WEIGHTS :return "H264 Prediction Weight Table" ; +case V4L2_CID_STATELESS_H264_ENCODE_PARAMS :return "H264 Encode Parameters" ;case V4L2_CID_STATELESS_H264_SLICE_PARAMS :return "H264 Slice Parameters" ;case V4L2_CID_STATELESS_H264_DECODE_PARAMS :return "H264 Decode Parameters" ;case V4L2_CID_STATELESS_FWHT_PARAMS :return "FWHT Stateless Parameters" ;@@ -1555,6 +1556,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,case V4L2_CID_STATELESS_H264_PRED_WEIGHTS : *type =V4L2_CTRL_TYPE_H264_PRED_WEIGHTS ;break ; +case V4L2_CID_STATELESS_H264_ENCODE_PARAMS : + *type =V4L2_CTRL_TYPE_H264_ENCODE_PARAMS ; +break ;case V4L2_CID_STATELESS_VP8_FRAME : *type =V4L2_CTRL_TYPE_VP8_FRAME ;break ;include/media/v4l2-ctrls.h +2
-0@@ -42,6 +42,7 @@ struct video_device;* @p_h264_scaling_matrix: Pointer to a struct v4l2_ctrl_h264_scaling_matrix. * @p_h264_slice_params: Pointer to a struct v4l2_ctrl_h264_slice_params. * @p_h264_decode_params: Pointer to a struct v4l2_ctrl_h264_decode_params. +* @p_h264_encode_params: Pointer to a struct v4l2_ctrl_h264_encode_params. * @p_h264_pred_weights: Pointer to a struct v4l2_ctrl_h264_pred_weights. * @p_vp8_frame: Pointer to a VP8 frame params structure. * @p_vp9_compressed_hdr_probs: Pointer to a VP9 frame compressed header probs structure. @@ -76,6 +77,7 @@ union v4l2_ctrl_ptr {struct v4l2_ctrl_h264_scaling_matrix *p_h264_scaling_matrix;struct v4l2_ctrl_h264_slice_params *p_h264_slice_params;struct v4l2_ctrl_h264_decode_params *p_h264_decode_params; +struct v4l2_ctrl_h264_encode_params *p_h264_encode_params;struct v4l2_ctrl_h264_pred_weights *p_h264_pred_weights;struct v4l2_ctrl_vp8_frame *p_vp8_frame;struct v4l2_ctrl_hevc_sps *p_hevc_sps;include/uapi/linux/v4l2-controls.h +1
-0@@ -1568,6 +1568,7 @@ struct v4l2_h264_reference {#define V4L2_H264_SLICE_FLAG_DIRECT_SPATIAL_MV_PRED 0x01#define V4L2_H264_SLICE_FLAG_SP_FOR_SWITCH 0x02 +#define V4L2_H264_SLICE_FLAG_NUM_REF_IDX_ACTIVE_OVERRIDE 0x04#define V4L2_CID_STATELESS_H264_SLICE_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 6)/**
include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_h264_decode_params { · line 1713
Quoted 6 lines
include/uapi/linux/v4l2-controls.h +3
-0@@ -1707,6 +1708,38 @@ struct v4l2_ctrl_h264_decode_params {__u32 flags; }; +#define V4L2_H264_ENCODE_FLAG_IDR_PIC 0x01 +#define V4L2_H264_ENCODE_FLAG_FIELD_PIC 0x02 +#define V4L2_H264_ENCODE_FLAG_BOTTOM_FIELD 0x04
Just notice you are ahead of Vulkan here, they don't seem to have inerlaced encoding, maybe they just want to discourage people to use that, and that's why they only decode it :-D
include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_h264_decode_params { · line 1721
Quoted 8 lines
include/uapi/linux/v4l2-controls.h +8
-0+#define V4L2_H264_ENCODE_FLAG_DIRECT_SPATIAL_MV_PRED 0x08 +#define V4L2_H264_ENCODE_FLAG_NUM_REF_IDX_ACTIVE_OVERRIDE 0x10 +#define V4L2_H264_ENCODE_FLAG_NO_OUTPUT_OF_PRIOR_PICS 0x20 +#define V4L2_H264_ENCODE_FLAG_LONG_TERM_REFERENCE 0x40 + +#define V4L2_CID_STATELESS_H264_ENCODE_PARAMS (V4L2_CID_CODEC_STATELESS_BASE + 8) +struct v4l2_ctrl_h264_encode_params { +__u8 nal_ref_idc;
This is fixed in this implementation, and will be derivable with support for other reference model. I'd remove.
include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_h264_decode_params { · line 1722
Quoted 1 line
include/uapi/linux/v4l2-controls.h +1
-0+__u8 slice_type;
I think we should do like Vulkan here though. They split the frame invariant (StdVideoEncodeH264PictureInfo) from the slice parameters (StdVideoEncodeH264SliceHeader). slice_type does not have to be the same on all slices, just like many more below.
include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_h264_decode_params { · line 1724
Quoted 2 lines
include/uapi/linux/v4l2-controls.h +2
-0+__u8 pic_parameter_set_id; +__u8 colour_plane_id;
I'm not aware of any HW capable of != 0 here, so I'd be keen on dropping. We can make it an encode_params_professional in the future, there will likely be more things to add by then.
Quoted 5 lines
include/uapi/linux/v4l2-controls.h +5
-0+__u16 frame_num; +__u16 idr_pic_id; +__u16 pic_order_cnt_lsb; +__u8 reserved0[2 ]; +__s32 delta_pic_order_cnt_bottom;
include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_h264_decode_params { · line 1739
Quoted 10 lines
include/uapi/linux/v4l2-controls.h +10
-0+__s32 delta_pic_order_cnt0; +__s32 delta_pic_order_cnt1; +__u8 num_ref_idx_l0_active_minus1; +__u8 num_ref_idx_l1_active_minus1; +__u8 cabac_init_idc; +__s8 slice_qp_delta; +__u8 disable_deblocking_filter_idc; +__s8 slice_alpha_c0_offset_div2; +__s8 slice_beta_offset_div2; +__u8 reserved1[6 ];
This leads the next flag 1 byte off 32bit alignment, what the compiler will do next can't be predicted. Did you forgot to run pahole?
include/uapi/linux/v4l2-controls.h struct v4l2_ctrl_h264_decode_params { · line 1740
Quoted 1 line
include/uapi/linux/v4l2-controls.h +1
-0+__u32 flags;/* V4L2_H264_ENCODE_FLAG_ */
Missing something like temporal_id, first_mb_in_slice, while splitting the slice params, these would become a dybamic array and that will define the number of slices. No long term support I think?
That's all I could find on this pass.
Nicolas
Quoted 17 lines
include/uapi/linux/v4l2-controls.h +2
-0+}; +/* Stateless FWHT control, used by the vicodec driver */ /* Current FWHT version */ include/uapi/linux/videodev2.h +1
-0@@ -1964,6 +1964,7 @@ enum v4l2_ctrl_type {V4L2_CTRL_TYPE_H264_SLICE_PARAMS =0x0203 ,V4L2_CTRL_TYPE_H264_DECODE_PARAMS =0x0204 ,V4L2_CTRL_TYPE_H264_PRED_WEIGHTS =0x0205 , +V4L2_CTRL_TYPE_H264_ENCODE_PARAMS =0x0206 , V4L2_CTRL_TYPE_FWHT_PARAMS = 0x0220,
PATCH 3/14 media: h264: Add SPS video definitions
In reply to Paul KocialkowskiThese definitions are used to build the video part of the SPS, including important fields such as frame cropping, timing info (frame rate) and pixel coding.
--- include/media/v4l2-h264.h | 115 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+)
include/media/v4l2-h264.h +115 -0
@@ -12,6 +12,121 @@#include <media/v4l2-ctrls.h> +#define V4L2_H264_START_CODE_ANNEX_B 0x00000001 + +#define V4L2_H264_NALU_TYPE_SLICE_NON_IDR 1 +#define V4L2_H264_NALU_TYPE_SLICE_IDR 5 +#define V4L2_H264_NALU_TYPE_SPS 7 +#define V4L2_H264_NALU_TYPE_PPS 8 +#define V4L2_H264_NALU_TYPE_AUD 9 + +#define V4L2_H264_PRIMARY_PIC_TYPE_I 0 +#define V4L2_H264_PRIMARY_PIC_TYPE_IP 1 +#define V4L2_H264_PRIMARY_PIC_TYPE_IPB 2 + +#define V4L2_H264_VUI_ASPECT_RATIO_IDC_EXTENDED 255 + +#define V4L2_H264_VUI_VIDEO_COMPONENT 0 +#define V4L2_H264_VUI_VIDEO_PAL 1 +#define V4L2_H264_VUI_VIDEO_NTSC 2 +#define V4L2_H264_VUI_VIDEO_SECAM 3 +#define V4L2_H264_VUI_VIDEO_MAC 4 +#define V4L2_H264_VUI_VIDEO_UNSPECIFIED 5 + +#define V4L2_H264_VUI_COLOUR_BT709 1 +#define V4L2_H264_VUI_COLOUR_UNSPECIFIED 2 +#define V4L2_H264_VUI_COLOUR_BT470_SYSTEM_M 4 +#define V4L2_H264_VUI_COLOUR_BT470_SYSTEM_BG 5 +#define V4L2_H264_VUI_COLOUR_SMPTE170M 6 +#define V4L2_H264_VUI_COLOUR_SMPTE240M 7 +#define V4L2_H264_VUI_COLOUR_BT2020 9 + +#define V4L2_H264_VUI_TRANSFER_BT709 1 +#define V4L2_H264_VUI_TRANSFER_UNSPECIFIED 2 +#define V4L2_H264_VUI_TRANSFER_BT470_SYSTEM_M 4 +#define V4L2_H264_VUI_TRANSFER_BT470_SYSTEM_BG 5 +#define V4L2_H264_VUI_TRANSFER_SMPTE170M 6 +#define V4L2_H264_VUI_TRANSFER_SMPTE240M 7 +#define V4L2_H264_VUI_TRANSFER_LINEAR 8 +#define V4L2_H264_VUI_TRANSFER_SRGB 13 + +#define V4L2_H264_VUI_MATRIX_IDENTITY 0 +#define V4L2_H264_VUI_MATRIX_BT709 1 +#define V4L2_H264_VUI_MATRIX_UNSPECIFIED 2 +#define V4L2_H264_VUI_MATRIX_BT470_SYSTEM_M 4 +#define V4L2_H264_VUI_MATRIX_BT470_SYSTEM_BG 5 +#define V4L2_H264_VUI_MATRIX_SMPTE170M 6 +#define V4L2_H264_VUI_MATRIX_SMPTE240M 7 +#define V4L2_H264_VUI_MATRIX_BT2020 9 +#define V4L2_H264_VUI_MATRIX_BT2020_CONST_LUM 10 + +#define V4L2_H264_SPS_VIDEO_FLAG_FRAME_CROPPING BIT(0) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_PARAMETERS_PRESENT BIT(1) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_ASPECT_RATIO_INFO_PRESENT BIT(2) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_OVERSCAN_INFO_PRESENT BIT(3) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_OVERSCAN_APPROPRIATE BIT(4) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_VIDEO_SIGNAL_TYPE_PRESENT BIT(5) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_VIDEO_FULL_RANGE BIT(6) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_COLOUR_DESCRIPTION_PRESENT BIT(7) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_CHROMA_LOC_INFO_PRESENT BIT(8) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_TIMING_INFO_PRESENT BIT(9) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_FIXED_FRAME_RATE BIT(10) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_NAL_HRD_PARAMETERS_PRESENT BIT(11) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_VCL_HRD_PARAMETERS_PRESENT BIT(12) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_LOW_DELAY_HRD BIT(13) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_PIC_STRUCT_PRESENT BIT(14) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_BITSTREAM_RESTRICTION BIT(15) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_MOTION_VECTORS_OVER_PIC_BOUNDARIES BIT(16) + +struct v4l2_h264_sps_video_hrd { +u8 cpb_cnt_minus1; +u8 bit_rate_scale; +u8 cpb_size_scale; + +u32 bit_rate_value_minus1[32 ]; +u32 cpb_size_value_minus1[32 ]; +u8 cbr_flag[32 ]; + +u8 initial_cpb_removal_delay_length_minus1; +u8 cpb_removal_delay_length_minus1; +u8 dpb_output_delay_length_minus1; +u8 time_offset_length; +}; + +struct v4l2_h264_sps_video { +u32 frame_crop_left_offset; +u32 frame_crop_right_offset; +u32 frame_crop_top_offset; +u32 frame_crop_bottom_offset; + +u8 aspect_ratio_idc; +u16 sar_width; +u16 sar_height; + +u8 video_format; +u8 colour_primaries; +u8 transfer_characteristics; +u8 matrix_coefficients; + +u8 chroma_sample_loc_type_top_field; +u8 chroma_sample_loc_type_bottom_field; + +u32 num_units_in_tick; +u32 time_scale; + +struct v4l2_h264_sps_video_hrd nal_hrd; +struct v4l2_h264_sps_video_hrd vcl_hrd; + +u32 max_bytes_per_pic_denom; +u32 max_bits_per_mb_denom; +u32 log2_max_mv_length_horizontal; +u32 log2_max_mv_length_vertical; +u32 max_num_reorder_frames; +u32 max_dec_frame_buffering; + +u32 flags; +}; +/** * struct v4l2_h264_reflist_builder - Reference list builder object *
Signature · 1 line
2.53.0
Nicolas Dufresne
maintainerRe: [PATCH 03/14] media: h264: Add SPS video definitions
Hi,
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 3 lines
These definitions are used to build the video part of the SPS, including important fields such as frame cropping, timing info (frame rate) and pixel coding.
Since the kernel take control of bitstream generation, maybe it should offer to insert SEIs ?
Nicolas
Quoted 132 lines
Signed-off-by Paul Kocialkowski <[email protected]>--- include/media/v4l2-h264.h | 115 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+)include/media/v4l2-h264.h +115
-0@@ -12,6 +12,121 @@#include <media/v4l2-ctrls.h> +#define V4L2_H264_START_CODE_ANNEX_B 0x00000001 + +#define V4L2_H264_NALU_TYPE_SLICE_NON_IDR 1 +#define V4L2_H264_NALU_TYPE_SLICE_IDR 5 +#define V4L2_H264_NALU_TYPE_SPS 7 +#define V4L2_H264_NALU_TYPE_PPS 8 +#define V4L2_H264_NALU_TYPE_AUD 9 + +#define V4L2_H264_PRIMARY_PIC_TYPE_I 0 +#define V4L2_H264_PRIMARY_PIC_TYPE_IP 1 +#define V4L2_H264_PRIMARY_PIC_TYPE_IPB 2 + +#define V4L2_H264_VUI_ASPECT_RATIO_IDC_EXTENDED 255 + +#define V4L2_H264_VUI_VIDEO_COMPONENT 0 +#define V4L2_H264_VUI_VIDEO_PAL 1 +#define V4L2_H264_VUI_VIDEO_NTSC 2 +#define V4L2_H264_VUI_VIDEO_SECAM 3 +#define V4L2_H264_VUI_VIDEO_MAC 4 +#define V4L2_H264_VUI_VIDEO_UNSPECIFIED 5 + +#define V4L2_H264_VUI_COLOUR_BT709 1 +#define V4L2_H264_VUI_COLOUR_UNSPECIFIED 2 +#define V4L2_H264_VUI_COLOUR_BT470_SYSTEM_M 4 +#define V4L2_H264_VUI_COLOUR_BT470_SYSTEM_BG 5 +#define V4L2_H264_VUI_COLOUR_SMPTE170M 6 +#define V4L2_H264_VUI_COLOUR_SMPTE240M 7 +#define V4L2_H264_VUI_COLOUR_BT2020 9 + +#define V4L2_H264_VUI_TRANSFER_BT709 1 +#define V4L2_H264_VUI_TRANSFER_UNSPECIFIED 2 +#define V4L2_H264_VUI_TRANSFER_BT470_SYSTEM_M 4 +#define V4L2_H264_VUI_TRANSFER_BT470_SYSTEM_BG 5 +#define V4L2_H264_VUI_TRANSFER_SMPTE170M 6 +#define V4L2_H264_VUI_TRANSFER_SMPTE240M 7 +#define V4L2_H264_VUI_TRANSFER_LINEAR 8 +#define V4L2_H264_VUI_TRANSFER_SRGB 13 + +#define V4L2_H264_VUI_MATRIX_IDENTITY 0 +#define V4L2_H264_VUI_MATRIX_BT709 1 +#define V4L2_H264_VUI_MATRIX_UNSPECIFIED 2 +#define V4L2_H264_VUI_MATRIX_BT470_SYSTEM_M 4 +#define V4L2_H264_VUI_MATRIX_BT470_SYSTEM_BG 5 +#define V4L2_H264_VUI_MATRIX_SMPTE170M 6 +#define V4L2_H264_VUI_MATRIX_SMPTE240M 7 +#define V4L2_H264_VUI_MATRIX_BT2020 9 +#define V4L2_H264_VUI_MATRIX_BT2020_CONST_LUM 10 + +#define V4L2_H264_SPS_VIDEO_FLAG_FRAME_CROPPING BIT(0) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_PARAMETERS_PRESENT BIT(1) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_ASPECT_RATIO_INFO_PRESENT BIT(2) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_OVERSCAN_INFO_PRESENT BIT(3) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_OVERSCAN_APPROPRIATE BIT(4) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_VIDEO_SIGNAL_TYPE_PRESENT BIT(5) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_VIDEO_FULL_RANGE BIT(6) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_COLOUR_DESCRIPTION_PRESENT BIT(7) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_CHROMA_LOC_INFO_PRESENT BIT(8) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_TIMING_INFO_PRESENT BIT(9) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_FIXED_FRAME_RATE BIT(10) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_NAL_HRD_PARAMETERS_PRESENT BIT(11) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_VCL_HRD_PARAMETERS_PRESENT BIT(12) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_LOW_DELAY_HRD BIT(13) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_PIC_STRUCT_PRESENT BIT(14) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_BITSTREAM_RESTRICTION BIT(15) +#define V4L2_H264_SPS_VIDEO_FLAG_VUI_MOTION_VECTORS_OVER_PIC_BOUNDARIES BIT(16) + +struct v4l2_h264_sps_video_hrd { +u8 cpb_cnt_minus1; +u8 bit_rate_scale; +u8 cpb_size_scale; + +u32 bit_rate_value_minus1[32 ]; +u32 cpb_size_value_minus1[32 ]; +u8 cbr_flag[32 ]; + +u8 initial_cpb_removal_delay_length_minus1; +u8 cpb_removal_delay_length_minus1; +u8 dpb_output_delay_length_minus1; +u8 time_offset_length; +}; + +struct v4l2_h264_sps_video { +u32 frame_crop_left_offset; +u32 frame_crop_right_offset; +u32 frame_crop_top_offset; +u32 frame_crop_bottom_offset; + +u8 aspect_ratio_idc; +u16 sar_width; +u16 sar_height; + +u8 video_format; +u8 colour_primaries; +u8 transfer_characteristics; +u8 matrix_coefficients; + +u8 chroma_sample_loc_type_top_field; +u8 chroma_sample_loc_type_bottom_field; + +u32 num_units_in_tick; +u32 time_scale; + +struct v4l2_h264_sps_video_hrd nal_hrd; +struct v4l2_h264_sps_video_hrd vcl_hrd; + +u32 max_bytes_per_pic_denom; +u32 max_bits_per_mb_denom; +u32 log2_max_mv_length_horizontal; +u32 log2_max_mv_length_vertical; +u32 max_num_reorder_frames; +u32 max_dec_frame_buffering; + +u32 flags; +}; +/** * struct v4l2_h264_reflist_builder - Reference list builder object *
Nicolas Dufresne
maintainerRe: [PATCH 03/14] media: h264: Add SPS video definitions
In reply to Paul KocialkowskiHi,
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
include/media/v4l2-h264.h line 100
Quoted 4 lines
include/media/v4l2-h264.h +4
-0+u32 frame_crop_left_offset; +u32 frame_crop_right_offset; +u32 frame_crop_top_offset; +u32 frame_crop_bottom_offset;
We may or may not prefer using SELECTION API? Similar generalization is used in Vulkan when I compare.
Nicolas
PATCH 4/14 media: h264: Add stateless encode core
In reply to Paul KocialkowskiThe H.264 stateless encode core is the common implementation called by drivers to coordinate stateless encoding. It provides all the relevant configuration parameters to drivers, through a state mechanism.
States are built from controls (some of which are optional) with various inter-control checks along the way. A state can be constrained by the driver through a dedicated operation callback in order to disable unsupported features that may have been requested by userspace. The general philosophy is to adapt parameters provided by userspace to reach a state that can be handled by the hardware and bail out if no such accommodation can be made.
Adapted parameters are returned to userspace by updating the controls. This is currently not attached to the inbound media request but should be when support for it becomes available.
--- drivers/media/v4l2-core/Kconfig | 4 + drivers/media/v4l2-core/Makefile | 1 + drivers/media/v4l2-core/v4l2-h264-enc.c | 555 ++++++++++++++++++++++++ include/media/v4l2-h264-enc.h | 79 ++++ 4 files changed, 639 insertions(+) create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc.c create mode 100644 include/media/v4l2-h264-enc.h
drivers/media/v4l2-core/Kconfig +4 -0
@@ -44,6 +44,10 @@ config V4L2_JPEG_HELPER config V4L2_H264 tristate +# Used by drivers that need v4l2-h264-enc.ko +config V4L2_H264_ENC + tristate + # Used by drivers that need v4l2-vp9.ko config V4L2_VP9 tristate
drivers/media/v4l2-core/Makefile +1 -0
@@ -29,6 +29,7 @@ obj-$(CONFIG_V4L2_CCI) += v4l2-cci.o obj-$(CONFIG_V4L2_FLASH_LED_CLASS) += v4l2-flash-led-class.o obj-$(CONFIG_V4L2_FWNODE) += v4l2-fwnode.o obj-$(CONFIG_V4L2_H264) += v4l2-h264.o +obj-$(CONFIG_V4L2_H264_ENC) += v4l2-h264-enc.o obj-$(CONFIG_V4L2_JPEG_HELPER) += v4l2-jpeg.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o obj-$(CONFIG_V4L2_VP9) += v4l2-vp9.o
drivers/media/v4l2-core/v4l2-h264-enc.c new file +555 -0
555 lines not on this page · raw message
include/media/v4l2-h264-enc.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.53.0
Nicolas Dufresne
maintainerRe: [PATCH 04/14] media: h264: Add stateless encode core
Hi,
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 12 lines
The H.264 stateless encode core is the common implementation called by drivers to coordinate stateless encoding. It provides all the relevant configuration parameters to drivers, through a state mechanism.
States are built from controls (some of which are optional) with various inter-control checks along the way. A state can be constrained by the driver through a dedicated operation callback in order to disable unsupported features that may have been requested by userspace. The general philosophy is to adapt parameters provided by userspace to reach a state that can be handled by the hardware and bail out if no such accommodation can be made.
Quoted 6 lines
Adapted parameters are returned to userspace by updating the controls. This is currently not attached to the inbound media request but should be when support for it becomes available.
Signed-off-by Paul Kocialkowski <[email protected]>
Nice idea.
drivers/media/v4l2-core/v4l2-h264-enc.c line 420
Quoted 9 lines
drivers/media/v4l2-core/v4l2-h264-enc.c new file +9
-0+ +static void state_debug (struct v4l2_h264_enc *enc) +{ +struct v4l2_h264_enc_state *state = &enc->state_active; +struct v4l2_ctrl_h264_sps *sps = &state->sps; +struct v4l2_ctrl_h264_pps *pps = &state->pps; +struct v4l2_ctrl_h264_encode_params *encode = &state->encode; + +pr_debug ("+ v4l2-h264-enc: state" );
Imagine you get two of these concurrently tracing, it will be hard to see what is what, consider combining like we do for ref list.
Nicolas
PATCH 5/14 media: h264: Add stateless encode rbsp
In reply to Paul KocialkowskiThe H.264 stateless encode rbsp implementation allows generating H.264 bitstream headers to accommodate hardware that does not do it (which is rather common with stateless encoders).
It currently supports the following NAL unit types: AUD, SPS, PPS, slice header, with or without start codes.
Dedicated low-level operations are supported in order to accommodate hardware with dedicated hardware for bitstream storage. It is generally better to use such mechanisms to ensure slice NAL unit continuation, especially in unaligned cases.
It is deliberately not too tied to the H.264 stateless encode core so that it can be reused by stateful drivers that may need to do the same.
--- drivers/media/v4l2-core/Makefile | 2 +- drivers/media/v4l2-core/v4l2-h264-enc-rbsp.c | 1173 ++++++++++++++++++ drivers/media/v4l2-core/v4l2-h264-enc.c | 153 +++ include/media/v4l2-h264-enc-rbsp.h | 72 ++ include/media/v4l2-h264-enc.h | 5 + 5 files changed, 1404 insertions(+), 1 deletion(-) create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc-rbsp.c create mode 100644 include/media/v4l2-h264-enc-rbsp.h
drivers/media/v4l2-core/Makefile +1 -1
@@ -29,7 +29,7 @@ obj-$(CONFIG_V4L2_CCI) += v4l2-cci.o obj-$(CONFIG_V4L2_FLASH_LED_CLASS) += v4l2-flash-led-class.o obj-$(CONFIG_V4L2_FWNODE) += v4l2-fwnode.o obj-$(CONFIG_V4L2_H264) += v4l2-h264.o -obj-$(CONFIG_V4L2_H264_ENC) += v4l2-h264-enc.o +obj-$(CONFIG_V4L2_H264_ENC) += v4l2-h264-enc.o v4l2-h264-enc-rbsp.o obj-$(CONFIG_V4L2_JPEG_HELPER) += v4l2-jpeg.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o obj-$(CONFIG_V4L2_VP9) += v4l2-vp9.o
drivers/media/v4l2-core/v4l2-h264-enc-rbsp.c new file +1173 -0
1,173 lines not on this page · raw message
drivers/media/v4l2-core/v4l2-h264-enc.c +153 -0
185 lines not on this page · raw message
include/media/v4l2-h264-enc-rbsp.h new file +72 -0
72 lines not on this page · raw message
include/media/v4l2-h264-enc.h +5 -0
@@ -10,6 +10,7 @@#include <linux/v4l2-controls.h> #include <linux/videodev2.h> +#include <media/v4l2-h264-enc-rbsp.h> #include <media/videobuf2-v4l2.h> #define V4L2_H264_ENC_MB_UNIT 16
@@ -55,6 +56,7 @@ struct v4l2_h264_enc_ops {struct v4l2_h264_enc {const struct v4l2_h264_enc_ops *ops; +const struct v4l2_h264_enc_rbsp_ops *rbsp_ops;void *private_data;struct v4l2_pix_format *format;
@@ -66,6 +68,9 @@ struct v4l2_h264_enc {struct v4l2_h264_enc_state state_next;unsigned int state_serial; +struct v4l2_h264_enc_rbsp rbsp; +unsigned int rbsp_update; +unsigned int flags; };
Signature · 1 line
2.53.0
PATCH 6/14 media: h264: Add stateless encode reference management
In reply to Paul KocialkowskiThe H.264 stateless encode reference management implementation is responsible for allocating and tracking reconstruction buffers that need to be used by hardware as well as track references in the DPB following the sliding window decoded reference picture marking process.
It is also responsible for building the L0 and L1 reference lists from the DPB, using the common v4l2 h264 reflist builder.
--- drivers/media/v4l2-core/v4l2-h264-enc.c | 418 ++++++++++++++++++++++++ include/media/v4l2-h264-enc.h | 33 ++ 2 files changed, 451 insertions(+)
drivers/media/v4l2-core/v4l2-h264-enc.c +418 -0
@@ -12,9 +12,90 @@#include <media/v4l2-h264-enc-rbsp.h> #include <media/videobuf2-v4l2.h> +static int rec_buffer_alloc (struct v4l2_h264_enc *enc, +struct v4l2_h264_enc_rec_buffer *buffer) +{ +int ret; + + ret =v4l2_h264_enc_op (enc, rec_buffer_alloc, buffer); +if (ret) +return ret; + + buffer->allocated = true; + enc->ref.slots_count++; + +return 0 ; +} + +static void rec_buffer_free (struct v4l2_h264_enc *enc, +struct v4l2_h264_enc_rec_buffer *buffer) +{ +if (WARN_ON (!enc->ref.slots_count)) +return ; + +v4l2_h264_enc_op (enc, rec_buffer_free, buffer); + + buffer->allocated = false; + enc->ref.slots_count--; +} + +static int rec_buffers_alloc (struct v4l2_h264_enc *enc, +unsigned int slots_count) +{ +struct v4l2_h264_enc_ref *ref = &enc->ref; +unsigned int i; +int ret; + + ret =rec_buffer_alloc (enc, &ref->buffer_current); +if (ret) +return ret; + +if (!(enc->flags & (V4L2_H264_ENC_FLAG_INTER_PRED | +V4L2_H264_ENC_FLAG_INTER_BIPRED ))) +return 0 ; + +for (i =0 ; i < slots_count; i++) { + ret =rec_buffer_alloc (enc, &ref->buffers[i]); +if (ret) + goto error; + } + +return 0 ; + +error: +while (i >0 ) { + i--; +rec_buffer_free (enc, &ref->buffers[i]); + } + +rec_buffer_free (enc, &ref->buffer_current); + +return ret; +} + +static void rec_buffers_free (struct v4l2_h264_enc *enc) +{ +struct v4l2_h264_enc_ref *ref = &enc->ref; +unsigned int i; + +rec_buffer_free (enc, &ref->buffer_current); + +if (!(enc->flags & (V4L2_H264_ENC_FLAG_INTER_PRED | +V4L2_H264_ENC_FLAG_INTER_BIPRED ))) +return ; + +for (i =0 ; i <V4L2_H264_NUM_DPB_ENTRIES ; i++) { +if (!ref->buffers[i].allocated) +continue ; + +rec_buffer_free (enc, &ref->buffers[i]); + } +} +int v4l2_h264_enc_init (struct v4l2_h264_enc *enc) {struct v4l2_h264_enc_rbsp *rbsp = &enc->rbsp; +unsigned int slots_count =0 ;int ret; if ((!enc->format && !enc->format_mplane) || !enc->timeperframe ||
@@ -25,6 +106,23 @@ int v4l2_h264_enc_init(struct v4l2_h264_enc *enc)memset (&enc->state_next,0 ,sizeof (enc->state_next)); enc->state_serial =0 ; +memset (&enc->ref,0 ,sizeof (enc->ref)); + +if (enc->flags & (V4L2_H264_ENC_FLAG_INTER_PRED | +V4L2_H264_ENC_FLAG_INTER_BIPRED )) { +if (!enc->ref_slots_count_init) + slots_count =V4L2_H264_NUM_DPB_ENTRIES /2 ; +else if (WARN_ON (enc->ref_slots_count_init > +V4L2_H264_NUM_DPB_ENTRIES )) + slots_count =V4L2_H264_NUM_DPB_ENTRIES ; +else + slots_count = enc->ref_slots_count_init; + } + + ret =rec_buffers_alloc (enc, slots_count); +if (ret) +return ret; + rbsp->ops = enc->rbsp_ops; rbsp->private_data = enc->private_data;
@@ -34,6 +132,7 @@ EXPORT_SYMBOL_GPL(v4l2_h264_enc_init);void v4l2_h264_enc_exit (struct v4l2_h264_enc *enc) { +rec_buffers_free (enc); }EXPORT_SYMBOL_GPL (v4l2_h264_enc_exit);
@@ -665,6 +764,317 @@ static int rbsp_step(struct v4l2_h264_enc *enc,return 0 ; } +static struct v4l2_h264_enc_rec_buffer * +ref_step_buffers_slot_find (struct v4l2_h264_enc *enc) +{ +struct v4l2_h264_enc_rec_buffer *buffer; +unsigned int i; + +for (i =0 ; i <V4L2_H264_NUM_DPB_ENTRIES ; i++) { + buffer = &enc->ref.buffers[i]; + +if (buffer->allocated) +continue ; + +return buffer; + } + +return NULL ; +} + +static int ref_step_buffers (struct v4l2_h264_enc *enc) +{ +struct v4l2_h264_enc_state *state = &enc->state_active; +struct v4l2_ctrl_h264_sps *sps = &state->sps; +struct v4l2_h264_enc_ref *ref = &enc->ref; +struct v4l2_h264_enc_rec_buffer *buffer; +unsigned int count; +unsigned int i; +int ret; + +/* +* Only increase the number of slots. It avoids the cost of free +* (including on the first frame) and the cost of possible future +* allocations, at the expense of memory. +*/ +if (sps->max_num_ref_frames <= ref->slots_count) +return 0 ; + + count = sps->max_num_ref_frames - ref->slots_count; + +for (i =0 ; i < count; i++) { + buffer =ref_step_buffers_slot_find (enc); +if (WARN_ON (!buffer)) +return -ENOMEM ; + + ret =rec_buffer_alloc (enc, buffer); +if (ret) +return ret; + } + +return 0 ; +} + +static int ref_step_poc (struct v4l2_h264_enc *enc) +{ +struct v4l2_h264_enc_state *state = &enc->state_active; +struct v4l2_ctrl_h264_sps *sps = &state->sps; +struct v4l2_ctrl_h264_pps *pps = &state->pps; +struct v4l2_ctrl_h264_encode_params *encode = &state->encode; +struct v4l2_h264_enc_ref *ref = &enc->ref; +unsigned int pic_order_cnt_lsb; +unsigned int pic_order_cnt_msb; +unsigned int prev_pic_order_cnt_msb; +unsigned int prev_pic_order_cnt_lsb; +unsigned int max_pic_order_cnt_lsb; +unsigned int delta_pic_order_cnt_bottom; +unsigned int top_field_order_cnt; +unsigned int bottom_field_order_cnt; + +/* Only pic_order_cnt_type = 0 is currently supported. */ +if (sps->pic_order_cnt_type) +return -EINVAL ; + + max_pic_order_cnt_lsb =BIT (sps->log2_max_pic_order_cnt_lsb_minus4 +4 ); + pic_order_cnt_lsb = encode->pic_order_cnt_lsb; + +if (encode->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC ) { + prev_pic_order_cnt_msb =0 ; + prev_pic_order_cnt_lsb =0 ; + }else { + prev_pic_order_cnt_msb = ref->prev_pic_order_cnt_msb; + prev_pic_order_cnt_lsb = ref->prev_pic_order_cnt_lsb; + } + +if ((pic_order_cnt_lsb < prev_pic_order_cnt_lsb) && + ((prev_pic_order_cnt_lsb - pic_order_cnt_lsb) >= + (max_pic_order_cnt_lsb /2 ))) + pic_order_cnt_msb = prev_pic_order_cnt_msb + + max_pic_order_cnt_lsb; +else if ((pic_order_cnt_lsb > prev_pic_order_cnt_lsb) && + ((pic_order_cnt_lsb - prev_pic_order_cnt_lsb) > + (max_pic_order_cnt_lsb /2 ))) + pic_order_cnt_msb = prev_pic_order_cnt_msb - + max_pic_order_cnt_lsb; +else + pic_order_cnt_msb = prev_pic_order_cnt_msb; + + top_field_order_cnt = pic_order_cnt_msb + pic_order_cnt_lsb; + +if (pps->flags &V4L2_H264_PPS_FLAG_BOTTOM_FIELD_PIC_ORDER_IN_FRAME_PRESENT ) + delta_pic_order_cnt_bottom = encode->delta_pic_order_cnt_bottom; +else + delta_pic_order_cnt_bottom =0 ; + +if (!(encode->flags &V4L2_H264_ENCODE_FLAG_FIELD_PIC )) + bottom_field_order_cnt = top_field_order_cnt + + delta_pic_order_cnt_bottom; +else + bottom_field_order_cnt = top_field_order_cnt; + + ref->pic_order_cnt_msb = pic_order_cnt_msb; + ref->pic_order_cnt_lsb = pic_order_cnt_lsb; + ref->top_field_order_cnt = top_field_order_cnt; + ref->bottom_field_order_cnt = bottom_field_order_cnt; + ref->pic_order_cnt =min (top_field_order_cnt, bottom_field_order_cnt); + +return 0 ; +} + +static int ref_step (struct v4l2_h264_enc *enc) +{ +struct v4l2_h264_enc_state *state = &enc->state_active; +struct v4l2_ctrl_h264_sps *sps = &state->sps; +struct v4l2_ctrl_h264_pps *pps = &state->pps; +struct v4l2_ctrl_h264_encode_params *encode = &state->encode; +struct v4l2_h264_enc_ref *ref = &enc->ref; +unsigned int l0_active_count_max; +unsigned int l1_active_count_max; +int ret; + + ret =ref_step_buffers (enc); +if (ret) +return ret; + + ret =ref_step_poc (enc); +if (ret) +return ret; + + ref->l0_active_count =0 ; + ref->l1_active_count =0 ; + +if (encode->slice_type ==V4L2_H264_SLICE_TYPE_I ) { +/* Flush the DPB on IDR pictures. */ +if (encode->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC ) +memset (ref->dpb,0 ,sizeof (ref->dpb)); + +return 0 ; + } + +/* Generate reference lists. */ + +v4l2_h264_init_reflist_builder_gen (&ref->builder, sps, ref->dpb, + ref->pic_order_cnt, + encode->frame_num, +V4L2_H264_FRAME_REF ); + +if (encode->flags &V4L2_H264_ENCODE_FLAG_NUM_REF_IDX_ACTIVE_OVERRIDE ) { + l0_active_count_max = encode->num_ref_idx_l0_active_minus1 +1 ; + l1_active_count_max = encode->num_ref_idx_l1_active_minus1 +1 ; + }else { + l0_active_count_max = + pps->num_ref_idx_l0_default_active_minus1 +1 ; + l1_active_count_max = + pps->num_ref_idx_l1_default_active_minus1 +1 ; + } + +switch (encode->slice_type) { +case V4L2_H264_SLICE_TYPE_P : +v4l2_h264_build_p_ref_list (&ref->builder, ref->l0); + +if (ref->builder.num_valid > l0_active_count_max) + ref->l0_active_count = l0_active_count_max; +else + ref->l0_active_count = ref->builder.num_valid; + +WARN_ON (!ref->l0_active_count); + +break ; +case V4L2_H264_SLICE_TYPE_B : +v4l2_h264_build_b_ref_lists (&ref->builder, ref->l0, ref->l1); + +if (ref->builder.num_valid > l0_active_count_max) + ref->l0_active_count = l0_active_count_max; +else + ref->l0_active_count = ref->builder.num_valid; + +WARN_ON (!ref->l0_active_count); + +if (ref->builder.num_valid > l1_active_count_max) + ref->l1_active_count = l1_active_count_max; +else + ref->l1_active_count = ref->builder.num_valid; + +WARN_ON (!ref->l1_active_count); + +break ; + } + +pr_debug ("+ v4l2-h264-enc: ref" ); +pr_debug (" ref active l0: %u, l1: %u" , ref->l0_active_count, + ref->l1_active_count); + +return 0 ; +} + +static int ref_complete_slot_find (struct v4l2_h264_enc *enc, +unsigned int *index) +{ +struct v4l2_h264_enc_state *state = &enc->state_active; +struct v4l2_ctrl_h264_sps *sps = &state->sps; +struct v4l2_ctrl_h264_encode_params *encode = &state->encode; +struct v4l2_h264_enc_ref *ref = &enc->ref; +unsigned int max_frame_num =BIT (sps->log2_max_frame_num_minus4 +4 ); +unsigned int frame_num_wrap_smallest = encode->frame_num; +unsigned int frame_num_wrap_smallest_index; +unsigned int frame_num_wrap; +struct v4l2_h264_enc_rec_buffer *buffer; +struct v4l2_h264_dpb_entry *dpb_entry; +unsigned int i; + +for (i =0 ; i <V4L2_H264_NUM_DPB_ENTRIES ; i++) { + buffer = &ref->buffers[i]; + dpb_entry = &ref->dpb[i]; + +if (!buffer->allocated) +continue ; + +/* Return an unused slot. */ +if (!(dpb_entry->flags &V4L2_H264_DPB_ENTRY_FLAG_ACTIVE )) { + *index = i; +return 0 ; + } + +/* Track the smallest FrameNumWrap value. */ +if (dpb_entry->frame_num > encode->frame_num) + frame_num_wrap = dpb_entry->frame_num - max_frame_num; +else + frame_num_wrap = dpb_entry->frame_num; + +if (frame_num_wrap < frame_num_wrap_smallest) { + frame_num_wrap_smallest = frame_num_wrap; + frame_num_wrap_smallest_index = i; + } + } + +/* Clear the evicted DPB entry. */ + dpb_entry = &ref->dpb[frame_num_wrap_smallest_index]; +memset (dpb_entry,0 ,sizeof (*dpb_entry)); + + *index = frame_num_wrap_smallest_index; + +return 0 ; +} + +static int ref_complete_swap (struct v4l2_h264_enc *enc,unsigned int index, +u64 ts) +{ +struct v4l2_h264_enc_state *state = &enc->state_active; +struct v4l2_ctrl_h264_encode_params *encode = &state->encode; +struct v4l2_h264_enc_ref *ref = &enc->ref; +struct v4l2_h264_dpb_entry *dpb_entry = &ref->dpb[index]; +struct v4l2_h264_enc_rec_buffer *buffer = &ref->buffers[index]; +struct v4l2_h264_enc_rec_buffer *buffer_current = + &ref->buffer_current; + +/* Set the DPB entry of the available slot. */ +memset (dpb_entry,0 ,sizeof (*dpb_entry)); + dpb_entry->reference_ts = ts; + dpb_entry->pic_num = encode->frame_num; + dpb_entry->frame_num = encode->frame_num; + dpb_entry->fields =V4L2_H264_FRAME_REF ; + dpb_entry->top_field_order_cnt = ref->top_field_order_cnt; + dpb_entry->bottom_field_order_cnt = ref->bottom_field_order_cnt; + dpb_entry->flags =V4L2_H264_DPB_ENTRY_FLAG_VALID | +V4L2_H264_DPB_ENTRY_FLAG_ACTIVE ; + +if (encode->flags &V4L2_H264_ENCODE_FLAG_LONG_TERM_REFERENCE ) + dpb_entry->flags |=V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM ; + +/* Swap the current buffer with the available slot. */ +swap (*buffer_current, *buffer); + +return 0 ; +} + +static int ref_complete (struct v4l2_h264_enc *enc, +struct vb2_v4l2_buffer *buffer) +{ +struct v4l2_h264_enc_state *state = &enc->state_active; +struct v4l2_ctrl_h264_encode_params *encode = &state->encode; +struct v4l2_h264_enc_ref *ref = &enc->ref; +unsigned int index; +int ret; + +if (!encode->nal_ref_idc) +return 0 ; + +/* Keep the POC as last reference. */ + ref->prev_pic_order_cnt_msb = ref->pic_order_cnt_msb; + ref->prev_pic_order_cnt_lsb = ref->pic_order_cnt_lsb; + + ret =ref_complete_slot_find (enc, &index); +if (ret) +return ret; + +/* Move our current picture to the DPB. */ + ret =ref_complete_swap (enc, index, buffer->vb2_buf.timestamp); +if (ret) +return ret; + +return 0 ; +} +int v4l2_h264_enc_step (struct v4l2_h264_enc *enc,struct vb2_v4l2_buffer *buffer) {
@@ -682,6 +1092,10 @@ int v4l2_h264_enc_step(struct v4l2_h264_enc *enc,if (ret)return ret; + ret =ref_step (enc); +if (ret) +return ret; + ret =rbsp_step (enc, buffer);if (ret)return ret;
@@ -699,6 +1113,10 @@ int v4l2_h264_enc_complete(struct v4l2_h264_enc *enc,if (ret)return ret; + ret =ref_complete (enc, buffer); +if (ret) +return ret; +return 0 ; }EXPORT_SYMBOL_GPL (v4l2_h264_enc_complete);
include/media/v4l2-h264-enc.h +33 -0
@@ -35,6 +35,33 @@struct v4l2_h264_enc ; +struct v4l2_h264_enc_rec_buffer { +void *private_data; +bool allocated; +}; + +struct v4l2_h264_enc_ref { +struct v4l2_h264_enc_rec_buffer buffer_current; +struct v4l2_h264_enc_rec_buffer buffers[V4L2_H264_NUM_DPB_ENTRIES ]; +struct v4l2_h264_dpb_entry dpb[V4L2_H264_NUM_DPB_ENTRIES ]; +unsigned int slots_count; + +struct v4l2_h264_reference l0[V4L2_H264_REF_LIST_LEN ]; +unsigned int l0_active_count; +struct v4l2_h264_reference l1[V4L2_H264_REF_LIST_LEN ]; +unsigned int l1_active_count; + +struct v4l2_h264_reflist_builder builder; + +unsigned int prev_pic_order_cnt_msb; +unsigned int prev_pic_order_cnt_lsb; +unsigned int pic_order_cnt_msb; +unsigned int pic_order_cnt_lsb; +unsigned int top_field_order_cnt; +unsigned int bottom_field_order_cnt; +unsigned int pic_order_cnt; +}; +struct v4l2_h264_enc_state {struct v4l2_ctrl_h264_sps sps;struct v4l2_h264_sps_video sps_video;
@@ -52,6 +79,10 @@ struct v4l2_h264_enc_state {struct v4l2_h264_enc_ops {int (*state_constrain)(struct v4l2_h264_enc *enc,struct v4l2_h264_enc_state *state); +int (*rec_buffer_alloc)(struct v4l2_h264_enc *enc, +struct v4l2_h264_enc_rec_buffer *rec_buffer); +int (*rec_buffer_free)(struct v4l2_h264_enc *enc, +struct v4l2_h264_enc_rec_buffer *rec_buffer); };struct v4l2_h264_enc {
@@ -63,11 +94,13 @@ struct v4l2_h264_enc {struct v4l2_pix_format_mplane *format_mplane;struct v4l2_fract *timeperframe;struct v4l2_ctrl_handler *ctrl_handler; +unsigned int ref_slots_count_init;struct v4l2_h264_enc_state state_active;struct v4l2_h264_enc_state state_next;unsigned int state_serial; +struct v4l2_h264_enc_ref ref;struct v4l2_h264_enc_rbsp rbsp;unsigned int rbsp_update;
Signature · 1 line
2.53.0
PATCH 7/14 media: h264: Add stateless encode rate control
In reply to Paul KocialkowskiThe H.264 stateless encode rate control implementation currently supports:
- A direct QP mode;
- A constant quality (CQ) mode, with a linear quality to QP mapping;
- A constant bitrate (CBR) mode.
Related controls from the v4l2 stateful uAPI are reused directly.
The CBR mode is implemented using a size budget approach which allocates a given size to the current frame in order to match the bitrate.
The size is then used to derive a QP estimation, through a static table for the initial case and using collected statistics from the past few frames of the same type in the general case. A size difference ratio from previous frames is calculated (using up to 3 frames) and a QP diff is estimated from a static table depending on that ratio. The newly obtained QPs from the statistics of the previous frames are then averaged with a different weight (penalty) based on their temporal difference and size difference with the target.
--- drivers/media/v4l2-core/Makefile | 3 +- drivers/media/v4l2-core/v4l2-h264-enc-rc.c | 558 +++++++++++++++++++++ drivers/media/v4l2-core/v4l2-h264-enc.c | 196 ++++++++ include/media/v4l2-h264-enc-rc.h | 108 ++++ include/media/v4l2-h264-enc.h | 18 + include/media/v4l2-h264.h | 24 + 6 files changed, 906 insertions(+), 1 deletion(-) create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc-rc.c create mode 100644 include/media/v4l2-h264-enc-rc.h
drivers/media/v4l2-core/Makefile +2 -1
@@ -29,7 +29,8 @@ obj-$(CONFIG_V4L2_CCI) += v4l2-cci.o obj-$(CONFIG_V4L2_FLASH_LED_CLASS) += v4l2-flash-led-class.o obj-$(CONFIG_V4L2_FWNODE) += v4l2-fwnode.o obj-$(CONFIG_V4L2_H264) += v4l2-h264.o -obj-$(CONFIG_V4L2_H264_ENC) += v4l2-h264-enc.o v4l2-h264-enc-rbsp.o +obj-$(CONFIG_V4L2_H264_ENC) += v4l2-h264-enc.o v4l2-h264-enc-rbsp.o \ + v4l2-h264-enc-rc.o obj-$(CONFIG_V4L2_JPEG_HELPER) += v4l2-jpeg.o obj-$(CONFIG_V4L2_MEM2MEM_DEV) += v4l2-mem2mem.o obj-$(CONFIG_V4L2_VP9) += v4l2-vp9.o
drivers/media/v4l2-core/v4l2-h264-enc-rc.c new file +558 -0
558 lines not on this page · raw message
drivers/media/v4l2-core/v4l2-h264-enc.c +196 -0
259 lines not on this page · raw message
include/media/v4l2-h264-enc-rc.h new file +108 -0
108 lines not on this page · raw message
include/media/v4l2-h264-enc.h +18 -0
@@ -11,6 +11,7 @@#include <linux/v4l2-controls.h> #include <linux/videodev2.h> #include <media/v4l2-h264-enc-rbsp.h> +#include <media/v4l2-h264-enc-rc.h> #include <media/videobuf2-v4l2.h> #define V4L2_H264_ENC_MB_UNIT 16
@@ -74,6 +75,21 @@ struct v4l2_h264_enc_state {unsigned int width_aligned;unsigned int height_mbs;unsigned int height_aligned; + +bool frame_rc_enable; + +unsigned int qp_min; +unsigned int qp_max; +unsigned int qp_i; +unsigned int qp_p; +unsigned int qp_b; + +int bitrate_mode; +unsigned int quality; +unsigned int quality_min; +unsigned int quality_max; +unsigned int bitrate; +unsigned int bitrate_peak; };struct v4l2_h264_enc_ops {
@@ -87,6 +103,7 @@ struct v4l2_h264_enc_ops {struct v4l2_h264_enc {const struct v4l2_h264_enc_ops *ops; +const struct v4l2_h264_enc_rc_ops *rc_ops;const struct v4l2_h264_enc_rbsp_ops *rbsp_ops;void *private_data;
@@ -100,6 +117,7 @@ struct v4l2_h264_enc {struct v4l2_h264_enc_state state_next;unsigned int state_serial; +struct v4l2_h264_enc_rc rc;struct v4l2_h264_enc_ref ref;struct v4l2_h264_enc_rbsp rbsp;unsigned int rbsp_update;
include/media/v4l2-h264.h +24 -0
@@ -161,6 +161,30 @@ struct v4l2_h264_reflist_builder {u8 num_valid; }; +static inline char v4l2_h264_slice_type_char (unsigned char slice_type) +{ +if (slice_type ==V4L2_H264_SLICE_TYPE_I ) +return 'I' ; +else if (slice_type ==V4L2_H264_SLICE_TYPE_P ) +return 'P' ; +else if (slice_type ==V4L2_H264_SLICE_TYPE_B ) +return 'B' ; +else +return 'X' ; +} + +static inline const char *v4l2_h264_slice_type_name (unsigned char slice_type) +{ +if (slice_type ==V4L2_H264_SLICE_TYPE_I ) +return "intra" ; +else if (slice_type ==V4L2_H264_SLICE_TYPE_P ) +return "inter-pred" ; +else if (slice_type ==V4L2_H264_SLICE_TYPE_B ) +return "inter-bipred" ; +else +return "invalid" ; +} + void v4l2_h264_init_reflist_builder(struct v4l2_h264_reflist_builder *b, const struct v4l2_ctrl_h264_decode_params *dec_params,
Signature · 1 line
2.53.0
PATCH 8/14 media: verisilicon: Report default pixel coding for non-JPEG and fix JPEG case
In reply to Paul KocialkowskiThe JPEG colorspace is very specific to the JPEG coded format and is not relevant as a default for other types of coded (or non-coded) formats. These would typically use ITU-R Rec. BT.709 but it could be a number of other ones as well so reporting the default value is best.
Furthermore other pixel coding attributes are best set accordingly instead of keeping default values in the JPEG case.
--- .../media/platform/verisilicon/hantro_v4l2.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/media/platform/verisilicon/hantro_v4l2.c +14 -4
@@ -415,10 +415,20 @@ hantro_reset_fmt(struct v4l2_pix_format_mplane *fmt, fmt->pixelformat = vpu_fmt->fourcc; fmt->field =V4L2_FIELD_NONE ; - fmt->colorspace =V4L2_COLORSPACE_JPEG ; - fmt->ycbcr_enc =V4L2_YCBCR_ENC_DEFAULT ; - fmt->quantization =V4L2_QUANTIZATION_DEFAULT ; - fmt->xfer_func =V4L2_XFER_FUNC_DEFAULT ; + +if (fmt->pixelformat ==V4L2_PIX_FMT_JPEG ) { + fmt->colorspace =V4L2_COLORSPACE_JPEG ; + fmt->ycbcr_enc =V4L2_MAP_YCBCR_ENC_DEFAULT (fmt->colorspace); + fmt->quantization = +V4L2_MAP_QUANTIZATION_DEFAULT (false, fmt->colorspace, + fmt->ycbcr_enc); + fmt->xfer_func =V4L2_MAP_XFER_FUNC_DEFAULT (fmt->colorspace); + }else { + fmt->colorspace =V4L2_COLORSPACE_DEFAULT ; + fmt->ycbcr_enc =V4L2_XFER_FUNC_DEFAULT ; + fmt->quantization =V4L2_QUANTIZATION_DEFAULT ; + fmt->xfer_func =V4L2_XFER_FUNC_DEFAULT ; + } } static void
Signature · 1 line
2.53.0
PATCH 9/14 media: verisilicon: Cancel job with runtime pm put/clk disable on failure
In reply to Paul KocialkowskiThe no-pm variant of hantro_job_finish is only good to use directly if runtime pm get failed. In other cases, we need to do a runtime pm put and bulk clk disable to correctly undo what was set up.
--- .../media/platform/verisilicon/hantro_drv.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +12 -7
@@ -169,29 +169,34 @@ void hantro_end_prepare_run(struct hantro_ctx *ctx)static void device_run (void *priv) {struct hantro_ctx *ctx = priv; +struct hantro_dev *vpu = ctx->dev;struct vb2_v4l2_buffer *src, *dst;int ret; src =hantro_get_src_buf (ctx); dst =hantro_get_dst_buf (ctx); - ret =pm_runtime_resume_and_get (ctx->dev->dev); + ret =pm_runtime_resume_and_get (vpu->dev);if (ret <0 ) - goto err_cancel_job; + goto err_cancel_job_no_pm; - ret =clk_bulk_enable (ctx->dev->variant->num_clocks, ctx->dev->clocks); + ret =clk_bulk_enable (vpu->variant->num_clocks, vpu->clocks);if (ret) - goto err_cancel_job; + goto err_cancel_job_pm;v4l2_m2m_buf_copy_metadata (src, dst, true);if (ctx->codec_ops->run (ctx)) - goto err_cancel_job; + goto err_cancel_job_clk;return ; -err_cancel_job: -hantro_job_finish_no_pm (ctx->dev, ctx,VB2_BUF_STATE_ERROR ); +err_cancel_job_clk: +clk_bulk_disable (vpu->variant->num_clocks, vpu->clocks); +err_cancel_job_pm: +pm_runtime_put_autosuspend (vpu->dev); +err_cancel_job_no_pm: +hantro_job_finish_no_pm (vpu, ctx,VB2_BUF_STATE_ERROR ); }static const struct v4l2_m2m_ops vpu_m2m_ops = {
Signature · 1 line
2.53.0
Nicolas Dufresne
maintainerRe: [PATCH 09/14] media: verisilicon: Cancel job with runtime pm put/clk disable on failure
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 6 lines
The no-pm variant of
hantro_job_finishis only good to use directly if runtime pm get failed. In other cases, we need to do a runtime pm put and bulk clk disable to correctly undo what was set up.Fixes 892bb6ecead9 ("media: hantro: do a PM resume earlier")Signed-off-by Paul Kocialkowski <[email protected]>
Seems already fixed by 556ab0b2741d6 ("media: hantro: release runtime resources when device_run fails".
Quoted 50 lines
--- .../media/platform/verisilicon/hantro_drv.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)drivers/media/platform/verisilicon/hantro_drv.c +12
-7@@ -169,29 +169,34 @@ void hantro_end_prepare_run(struct hantro_ctx *ctx)static void device_run (void *priv) {struct hantro_ctx *ctx = priv; +struct hantro_dev *vpu = ctx->dev;struct vb2_v4l2_buffer *src, *dst;int ret; src =hantro_get_src_buf (ctx); dst =hantro_get_dst_buf (ctx); - ret =pm_runtime_resume_and_get (ctx->dev->dev); + ret =pm_runtime_resume_and_get (vpu->dev);if (ret <0 ) - goto err_cancel_job; + goto err_cancel_job_no_pm; - ret =clk_bulk_enable (ctx->dev->variant->num_clocks, ctx->dev->clocks); + ret =clk_bulk_enable (vpu->variant->num_clocks, vpu->clocks);if (ret) - goto err_cancel_job; + goto err_cancel_job_pm;v4l2_m2m_buf_copy_metadata (src, dst, true);if (ctx->codec_ops->run (ctx)) - goto err_cancel_job; + goto err_cancel_job_clk;return ; -err_cancel_job: -hantro_job_finish_no_pm (ctx->dev, ctx,VB2_BUF_STATE_ERROR ); +err_cancel_job_clk: +clk_bulk_disable (vpu->variant->num_clocks, vpu->clocks); +err_cancel_job_pm: +pm_runtime_put_autosuspend (vpu->dev); +err_cancel_job_no_pm: +hantro_job_finish_no_pm (vpu, ctx,VB2_BUF_STATE_ERROR ); }static const struct v4l2_m2m_ops vpu_m2m_ops = {
PATCH 10/14 media: hantro: use hantro_decoded_buffer only for dst_vq
In reply to Paul KocialkowskiFrom: Marco Felsch <[email protected]>
The dst_vq buffer size for encoders should not use the size of the 'hantro_decoded_buffer'. Make use of 'v4l2_m2m_buffer' instead till some encoder requires pre buffer extra data.
--- drivers/media/platform/verisilicon/hantro_drv.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/media/platform/verisilicon/hantro_drv.c +4 -1
@@ -248,7 +248,10 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq) dst_vq->io_modes =VB2_MMAP |VB2_DMABUF ; dst_vq->drv_priv = ctx; dst_vq->ops = &hantro_queue_ops; - dst_vq->buf_struct_size =sizeof (struct hantro_decoded_buffer ); +if (ctx->is_encoder) + dst_vq->buf_struct_size =sizeof (struct v4l2_m2m_buffer ); +else + dst_vq->buf_struct_size =sizeof (struct hantro_decoded_buffer ); dst_vq->timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_COPY ; dst_vq->lock = &ctx->dev->vpu_mutex; dst_vq->dev = ctx->dev->v4l2_dev.dev;
Signature · 1 line
2.53.0
Re: [PATCH 10/14] media: hantro: use hantro_decoded_buffer only for dst_vq
Hi,
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 7 lines
From: Marco Felsch <[email protected]>
The
dst_vqbuffer size for encoders should not use the size of the 'hantro_decoded_buffer'. Make use of 'v4l2_m2m_buffer' instead till some encoder requires pre buffer extra data.Signed-off-by Marco Felsch <[email protected]>
Its independent, so I picked it and added a Fixes tag.
cheers,
Nicolas
PATCH 11/14 media: verisilicon: Add common encoder parm and frameintervals ioctls
In reply to Paul KocialkowskiThis introduces the required encoder ioctls for configuring the frame rate (via the parm timeperframe field) and enumerating available frame rates (via enum_frameintervals) for the encoder.
--- drivers/media/platform/verisilicon/hantro.h | 3 + .../media/platform/verisilicon/hantro_drv.c | 3 + .../media/platform/verisilicon/hantro_v4l2.c | 99 +++++++++++++++++++ 3 files changed, 105 insertions(+)
drivers/media/platform/verisilicon/hantro.h +3 -0
@@ -258,6 +258,9 @@ struct hantro_ctx {struct v4l2_pix_format_mplane dst_fmt;struct v4l2_pix_format_mplane ref_fmt; +struct v4l2_fract src_timeperframe; +struct v4l2_fract dst_timeperframe; +struct v4l2_ctrl_handler ctrl_handler;int jpeg_quality;int bit_depth;
drivers/media/platform/verisilicon/hantro_drv.c +3 -0
@@ -923,8 +923,11 @@ static int hantro_add_func(struct hantro_dev *vpu, unsigned int funcid) vpu->decoder = func;v4l2_disable_ioctl (vfd,VIDIOC_TRY_ENCODER_CMD );v4l2_disable_ioctl (vfd,VIDIOC_ENCODER_CMD ); +v4l2_disable_ioctl (vfd,VIDIOC_ENUM_FRAMEINTERVALS );v4l2_disable_ioctl (vfd,VIDIOC_G_SELECTION );v4l2_disable_ioctl (vfd,VIDIOC_S_SELECTION ); +v4l2_disable_ioctl (vfd,VIDIOC_G_PARM ); +v4l2_disable_ioctl (vfd,VIDIOC_S_PARM ); }video_set_drvdata (vfd, vpu);
drivers/media/platform/verisilicon/hantro_v4l2.c +99 -0
133 lines not on this page · raw message
Signature · 1 line
2.53.0
Re: [PATCH 11/14] media: verisilicon: Add common encoder parm and frameintervals ioctls
Hi,
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 5 lines
This introduces the required encoder ioctls for configuring the frame rate (via the parm timeperframe field) and enumerating available frame rates (via
enum_frameintervals) for the encoder.Signed-off-by Paul Kocialkowski <[email protected]>
Perhaps add a word or two about what it is used for (rate control right?).
PATCH 12/14 media: verisilicon: Add support for the VC8000E H.264 encoder
In reply to Paul KocialkowskiThis introduces support for the Hantro VC8000E H.264 encoder, a stateless hardware encoder from Verisilicon.
This driver is the first user of the V4L2 H.264 stateless encoding core and uAPI.
The hardware needs to be programmed in a sequential way (registers written in ascending offset order) so the registers are programmed in a memory buffer first and copied in order at the end. They are described as packed structured for convenience and should also contain all required definitions for HEVC and JPEG support.
Only a single reference frame is currently supported, even though the registers seems to indicate that two could be supported. More research and investigation is needed to operate two.
The lambda tables are currently hardcoded to generally reasonable values but could be recalculated for each target QP to give more accurate results.
Most other features of the encoder are supported, except ROI and intra areas support which are currently disabled.
--- drivers/media/platform/verisilicon/Kconfig | 1 + drivers/media/platform/verisilicon/Makefile | 2 + drivers/media/platform/verisilicon/hantro.h | 14 + .../media/platform/verisilicon/hantro_drv.c | 152 +- .../media/platform/verisilicon/hantro_h264.c | 6 +- .../media/platform/verisilicon/hantro_hw.h | 27 + .../media/platform/verisilicon/hantro_v4l2.c | 6 + .../platform/verisilicon/hantro_vc8000e.c | 68 + .../verisilicon/hantro_vc8000e_h264_enc.c | 883 +++++++ .../verisilicon/hantro_vc8000e_regs.h | 2129 +++++++++++++++++ 10 files changed, 3279 insertions(+), 9 deletions(-) create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e.c create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e_h264_enc.c create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e_regs.h
drivers/media/platform/verisilicon/Kconfig +1 -0
@@ -12,6 +12,7 @@ config VIDEO_HANTRO select VIDEOBUF2_VMALLOC select V4L2_MEM2MEM_DEV select V4L2_H264 + select V4L2_H264_ENC select V4L2_JPEG_HELPER select V4L2_VP9 help
drivers/media/platform/verisilicon/Makefile +2 -0
@@ -7,6 +7,8 @@ hantro-vpu-y += \ hantro_v4l2.o \ hantro_postproc.o \ hantro_h1_jpeg_enc.o \ + hantro_vc8000e.o \ + hantro_vc8000e_h264_enc.o \ hantro_g1.o \ hantro_g1_h264_dec.o \ hantro_g1_mpeg2_dec.o \
drivers/media/platform/verisilicon/hantro.h +14 -0
@@ -32,6 +32,7 @@ struct hantro_codec_ops;struct hantro_postproc_ops ;#define HANTRO_JPEG_ENCODER BIT(0) +#define HANTRO_H264_ENCODER BIT(1)#define HANTRO_ENCODERS 0x0000ffff#define HANTRO_MPEG2_DECODER BIT(16)#define HANTRO_VP8_DECODER BIT(17)
@@ -107,6 +108,7 @@ struct hantro_variant {* enum hantro_codec_mode - codec operating mode. * @HANTRO_MODE_NONE: No operating mode. Used for RAW video formats. * @HANTRO_MODE_JPEG_ENC: JPEG encoder. +* @HANTRO_MODE_H264_ENC: H264 encoder. * @HANTRO_MODE_H264_DEC: H264 decoder. * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder. * @HANTRO_MODE_VP8_DEC: VP8 decoder.
@@ -117,6 +119,7 @@ struct hantro_variant {enum hantro_codec_mode {HANTRO_MODE_NONE =-1 ,HANTRO_MODE_JPEG_ENC , +HANTRO_MODE_H264_ENC ,HANTRO_MODE_H264_DEC ,HANTRO_MODE_MPEG2_DEC ,HANTRO_MODE_VP8_DEC ,
@@ -272,6 +275,7 @@ struct hantro_ctx {/* Specific for particular codec modes. */ union {struct hantro_h264_dec_hw_ctx h264_dec; +struct hantro_h264_enc_hw_ctx h264_enc;struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;struct hantro_vp8_dec_hw_ctx vp8_dec;struct hantro_hevc_dec_hw_ctx hevc_dec;
@@ -466,6 +470,16 @@ static __always_inline void hantro_reg_write_relaxed(struct hantro_dev *vpu,vdpu_write_relaxed (vpu,vdpu_read_mask (vpu, reg, val), reg->base); } +static __always_inline void hantro_io_copy(void __iomem *dst, void *src, +size_t size) +{ +#ifdef CONFIG_ARM64 +__iowrite32_copy (dst, src, size /4 ); +#else +memcpy_toio (dst, src, size); +#endif +} +void *hantro_get_ctrl (struct hantro_ctx *ctx,u32 id);dma_addr_t hantro_get_ref (struct hantro_ctx *ctx,u64 ts);
drivers/media/platform/verisilicon/hantro_drv.c +147 -5
195 lines not on this page · raw message
drivers/media/platform/verisilicon/hantro_h264.c +2 -4
@@ -453,13 +453,11 @@ int hantro_h264_dec_prepare_run(struct hantro_ctx *ctx)if (WARN_ON (!ctrls->decode))return -EINVAL ; - ctrls->sps = -hantro_get_ctrl (ctx,V4L2_CID_STATELESS_H264_SPS ); + ctrls->sps =hantro_get_ctrl (ctx,V4L2_CID_STATELESS_H264_SPS );if (WARN_ON (!ctrls->sps))return -EINVAL ; - ctrls->pps = -hantro_get_ctrl (ctx,V4L2_CID_STATELESS_H264_PPS ); + ctrls->pps =hantro_get_ctrl (ctx,V4L2_CID_STATELESS_H264_PPS );if (WARN_ON (!ctrls->pps))return -EINVAL ;
drivers/media/platform/verisilicon/hantro_hw.h +27 -0
@@ -12,11 +12,13 @@#include <linux/interrupt.h> #include <linux/v4l2-controls.h> #include <media/v4l2-ctrls.h> +#include <media/v4l2-h264-enc.h> #include <media/v4l2-vp9.h> #include <media/videobuf2-core.h> #include "rockchip_av1_entropymode.h" #include "rockchip_av1_filmgrain.h" +#include "hantro_vc8000e_regs.h" #define DEC_8190_ALIGN_MASK 0x07U
@@ -69,6 +71,22 @@ struct hantro_aux_buf {unsigned long attrs; }; +struct hantro_vc8000e_rec_buf { +struct hantro_aux_buf luma; +struct hantro_aux_buf chroma; +struct hantro_aux_buf luma_4n; +struct hantro_aux_buf colctbs; +}; + +struct hantro_h264_enc_hw_ctx { +struct v4l2_h264_enc enc; +struct hantro_aux_buf nal_tbl; + +union { +struct hantro_vc8000e_regs vc8000e_regs; + }; +}; +/* Max. number of entries in the DPB (HW limitation). */ #define HANTRO_H264_DPB_SIZE 16
@@ -451,6 +469,15 @@ int hantro_g1_h264_dec_run(struct hantro_ctx *ctx);int hantro_h264_dec_init (struct hantro_ctx *ctx);void hantro_h264_dec_exit (struct hantro_ctx *ctx); +irqreturn_t hantro_vc8000e_irq (int irq,void *dev_id); +int hantro_vc8000e_h264_enc_init (struct hantro_ctx *ctx); +void hantro_vc8000e_h264_enc_exit (struct hantro_ctx *ctx); +void hantro_vc8000e_h264_enc_done (struct hantro_ctx *ctx); +int hantro_vc8000e_h264_enc_run (struct hantro_ctx *ctx); +int hantro_h264_enc_prepare_run (struct hantro_ctx *ctx); +int hantro_h264_enc_init (struct hantro_ctx *ctx); +void hantro_h264_enc_exit (struct hantro_ctx *ctx); +int hantro_hevc_dec_init (struct hantro_ctx *ctx);void hantro_hevc_dec_exit (struct hantro_ctx *ctx);int hantro_g2_hevc_dec_run (struct hantro_ctx *ctx);
drivers/media/platform/verisilicon/hantro_v4l2.c +6 -0
@@ -629,6 +629,12 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx,hantro_get_format_depth (pix_mp->pixelformat), need_postproc); +/* Propagate dimensions for encoders. */ +if (ctx->is_encoder) { + ctx->dst_fmt.width = pix_mp->width; + ctx->dst_fmt.height = pix_mp->height; + } +/* Colorimetry information are always propagated. */ ctx->dst_fmt.colorspace = pix_mp->colorspace; ctx->dst_fmt.ycbcr_enc = pix_mp->ycbcr_enc;
drivers/media/platform/verisilicon/hantro_vc8000e.c new file +68 -0
68 lines not on this page · raw message
drivers/media/platform/verisilicon/hantro_vc8000e_h264_enc.c new file +883 -0
883 lines not on this page · raw message
drivers/media/platform/verisilicon/hantro_vc8000e_regs.h new file +2129 -0
1,718 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.53.0
Part of the diff is not shown here. View the raw message.
Nicolas Dufresne
maintainerRe: [PATCH 12/14] media: verisilicon: Add support for the VC8000E H.264 encoder
Hi,
warning: partial review.
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 160 lines
This introduces support for the Hantro VC8000E H.264 encoder, a stateless hardware encoder from Verisilicon.
This driver is the first user of the V4L2 H.264 stateless encoding core and uAPI.
The hardware needs to be programmed in a sequential way (registers written in ascending offset order) so the registers are programmed in a memory buffer first and copied in order at the end. They are described as packed structured for convenience and should also contain all required definitions for HEVC and JPEG support.
Only a single reference frame is currently supported, even though the registers seems to indicate that two could be supported. More research and investigation is needed to operate two.
The lambda tables are currently hardcoded to generally reasonable values but could be recalculated for each target QP to give more accurate results.
Most other features of the encoder are supported, except ROI and intra areas support which are currently disabled.
Signed-off-by Paul Kocialkowski <[email protected]>--- drivers/media/platform/verisilicon/Kconfig | 1 + drivers/media/platform/verisilicon/Makefile | 2 + drivers/media/platform/verisilicon/hantro.h | 14 + .../media/platform/verisilicon/hantro_drv.c | 152 +- .../media/platform/verisilicon/hantro_h264.c | 6 +- .../media/platform/verisilicon/hantro_hw.h | 27 + .../media/platform/verisilicon/hantro_v4l2.c | 6 + .../platform/verisilicon/hantro_vc8000e.c | 68 + .../verisilicon/hantro_vc8000e_h264_enc.c | 883 +++++++ .../verisilicon/hantro_vc8000e_regs.h | 2129 +++++++++++++++++ 10 files changed, 3279 insertions(+), 9 deletions(-) create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e.c create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e_h264_enc.c create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e_regs.hdrivers/media/platform/verisilicon/Kconfig +1
-0@@ -12,6 +12,7 @@ config VIDEO_HANTRO select VIDEOBUF2_VMALLOC select V4L2_MEM2MEM_DEV select V4L2_H264 + select V4L2_H264_ENC select V4L2_JPEG_HELPER select V4L2_VP9 helpdrivers/media/platform/verisilicon/Makefile +2
-0@@ -7,6 +7,8 @@ hantro-vpu-y += \ hantro_v4l2.o \ hantro_postproc.o \ hantro_h1_jpeg_enc.o \ + hantro_vc8000e.o \ + hantro_vc8000e_h264_enc.o \ hantro_g1.o \ hantro_g1_h264_dec.o \ hantro_g1_mpeg2_dec.o \drivers/media/platform/verisilicon/hantro.h +14
-0@@ -32,6 +32,7 @@ struct hantro_codec_ops;struct hantro_postproc_ops ;#define HANTRO_JPEG_ENCODER BIT(0) +#define HANTRO_H264_ENCODER BIT(1)#define HANTRO_ENCODERS 0x0000ffff#define HANTRO_MPEG2_DECODER BIT(16)#define HANTRO_VP8_DECODER BIT(17)@@ -107,6 +108,7 @@ struct hantro_variant {* enum hantro_codec_mode - codec operating mode. * @HANTRO_MODE_NONE: No operating mode. Used for RAW video formats. * @HANTRO_MODE_JPEG_ENC: JPEG encoder. +* @HANTRO_MODE_H264_ENC: H264 encoder. * @HANTRO_MODE_H264_DEC: H264 decoder. * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder. * @HANTRO_MODE_VP8_DEC: VP8 decoder. @@ -117,6 +119,7 @@ struct hantro_variant {enum hantro_codec_mode {HANTRO_MODE_NONE =-1 ,HANTRO_MODE_JPEG_ENC , +HANTRO_MODE_H264_ENC ,HANTRO_MODE_H264_DEC ,HANTRO_MODE_MPEG2_DEC ,HANTRO_MODE_VP8_DEC ,@@ -272,6 +275,7 @@ struct hantro_ctx {/* Specific for particular codec modes. */ union {struct hantro_h264_dec_hw_ctx h264_dec; +struct hantro_h264_enc_hw_ctx h264_enc;struct hantro_mpeg2_dec_hw_ctx mpeg2_dec;struct hantro_vp8_dec_hw_ctx vp8_dec;struct hantro_hevc_dec_hw_ctx hevc_dec;@@ -466,6 +470,16 @@ static __always_inline void hantro_reg_write_relaxed(struct hantro_dev *vpu,vdpu_write_relaxed (vpu,vdpu_read_mask (vpu, reg, val), reg->base); } +static __always_inline void hantro_io_copy(void __iomem *dst, void *src, +size_t size) +{ +#ifdef CONFIG_ARM64 +__iowrite32_copy (dst, src, size /4 ); +#else +memcpy_toio (dst, src, size); +#endif +} +void *hantro_get_ctrl (struct hantro_ctx *ctx,u32 id);dma_addr_t hantro_get_ref (struct hantro_ctx *ctx,u64 ts);drivers/media/platform/verisilicon/hantro_drv.c +27
-0@@ -420,6 +420,8 @@ static const struct v4l2_ctrl_ops hantro_av1_ctrl_ops = { V4L2_JPEG_ACTIVE_MARKER_DHT) static const struct hantro_ctrl controls[] = { +/* JPEG Encoder */ + { .codec =HANTRO_JPEG_ENCODER , .cfg = {@@ -446,7 +448,127 @@ static const struct hantro_ctrl controls[] = {*/ .flags = V4L2_CTRL_FLAG_READ_ONLY, }, + }, + +/* H.264 Encoder */ + + { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_STATELESS_H264_ENCODE_PARAMS, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_STATELESS_H264_SPS, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_STATELESS_H264_PPS, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_STATELESS_H264_START_CODE, + .min = V4L2_STATELESS_H264_START_CODE_NONE, + .max = V4L2_STATELESS_H264_START_CODE_ANNEX_B,
drivers/media/platform/verisilicon/hantro_drv.c static const struct hantro_ctrl controls[] = { · line 485
Quoted 10 lines
drivers/media/platform/verisilicon/hantro_drv.c +10
-0+ .def = V4L2_STATELESS_H264_START_CODE_ANNEX_B, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_AU_DELIMITER, + .step = 1, + .min = 0, + .max = 1, + .def = 0,
Any rational not to always insert AUD ?
drivers/media/platform/verisilicon/hantro_drv.c static const struct hantro_ctrl controls[] = { · line 494
Quoted 9 lines
drivers/media/platform/verisilicon/hantro_drv.c +9
-0+ }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_PREPEND_SPSPPS_TO_IDR, + .step = 1, + .min = 0, + .max = 1, + .def = 0,
Same.
drivers/media/platform/verisilicon/hantro_drv.c static const struct hantro_ctrl controls[] = { · line 503
Quoted 9 lines
drivers/media/platform/verisilicon/hantro_drv.c +9
-0+ }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE, + .step = 1, + .min = 0, + .max = 1, + .def = 0,
Same, why not having some default? Of course VBR RC is more common default, but this disable RC completely?
Quoted 247 lines
drivers/media/platform/verisilicon/hantro_drv.c +92
-5+ }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_H264_MIN_QP, + .step = 1, + .min = 0, + .max = 51, + .def = 0, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_H264_MAX_QP, + .step = 1, + .min = 0, + .max = 51, + .def = 51, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP, + .step = 1, + .min = 0, + .max = 51, + .def = 24, + }, }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP, + .step = 1, + .min = 0, + .max = 51, + .def = 28, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_BITRATE_MODE, + .min = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, + .max = V4L2_MPEG_VIDEO_BITRATE_MODE_CQ, + .def = V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_CONSTANT_QUALITY, + .step = 1, + .min = 0, + .max = 100, + .def = 80, + }, + }, { + .codec = HANTRO_H264_ENCODER, + .cfg = { + .id = V4L2_CID_MPEG_VIDEO_BITRATE, + .step = 1, + .min = 1000, + .max = 96000000, + .def = 2000000, + }, + }, + +/* MPEG-2 Decoder */ + + { .codec = HANTRO_MPEG2_DECODER, .cfg = { .id = V4L2_CID_STATELESS_MPEG2_SEQUENCE,@@ -461,7 +583,11 @@ static const struct hantro_ctrl controls[] = { .cfg = { .id = V4L2_CID_STATELESS_MPEG2_QUANTISATION, }, - }, { + }, + +/* VP8 Decoder */ + + { .codec = HANTRO_VP8_DECODER, .cfg = { .id = V4L2_CID_STATELESS_VP8_FRAME,@@ -471,7 +597,11 @@ static const struct hantro_ctrl controls[] = { .cfg = { .id = V4L2_CID_STATELESS_H264_DECODE_PARAMS, }, - }, { + }, + +/* H.264 Decoder */ + + { .codec = HANTRO_H264_DECODER, .cfg = { .id = V4L2_CID_STATELESS_H264_SPS,@@ -513,7 +643,11 @@ static const struct hantro_ctrl controls[] = { BIT(V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED), .def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN, } - }, { + }, + + /* HEVC Decoder */ + + { .codec = HANTRO_HEVC_DECODER, .cfg = { .id = V4L2_CID_STATELESS_HEVC_DECODE_MODE,@@ -565,7 +699,11 @@ static const struct hantro_ctrl controls[] = { .cfg = { .id = V4L2_CID_STATELESS_HEVC_SCALING_MATRIX, }, - }, { + }, + +/* VP9 Decoder */ + + { .codec = HANTRO_VP9_DECODER, .cfg = { .id = V4L2_CID_STATELESS_VP9_FRAME,@@ -576,7 +714,11 @@ static const struct hantro_ctrl controls[] = { .cfg = { .id = V4L2_CID_STATELESS_VP9_COMPRESSED_HDR, }, - }, { + }, + +/* AV1 Decoder */ + + { .codec = HANTRO_AV1_DECODER, .cfg = { .id = V4L2_CID_STATELESS_AV1_FRAME,drivers/media/platform/verisilicon/hantro_h264.c +2
-4@@ -453,13 +453,11 @@ int hantro_h264_dec_prepare_run(struct hantro_ctx *ctx)if (WARN_ON (!ctrls->decode))return -EINVAL ; - ctrls->sps = -hantro_get_ctrl (ctx,V4L2_CID_STATELESS_H264_SPS ); + ctrls->sps =hantro_get_ctrl (ctx,V4L2_CID_STATELESS_H264_SPS );if (WARN_ON (!ctrls->sps))return -EINVAL ; - ctrls->pps = -hantro_get_ctrl (ctx,V4L2_CID_STATELESS_H264_PPS ); + ctrls->pps =hantro_get_ctrl (ctx,V4L2_CID_STATELESS_H264_PPS );if (WARN_ON (!ctrls->pps))return -EINVAL ;drivers/media/platform/verisilicon/hantro_hw.h +27
-0@@ -12,11 +12,13 @@#include <linux/interrupt.h> #include <linux/v4l2-controls.h> #include <media/v4l2-ctrls.h> +#include <media/v4l2-h264-enc.h> #include <media/v4l2-vp9.h> #include <media/videobuf2-core.h> #include "rockchip_av1_entropymode.h" #include "rockchip_av1_filmgrain.h" +#include "hantro_vc8000e_regs.h" #define DEC_8190_ALIGN_MASK 0x07U@@ -69,6 +71,22 @@ struct hantro_aux_buf {unsigned long attrs; }; +struct hantro_vc8000e_rec_buf { +struct hantro_aux_buf luma; +struct hantro_aux_buf chroma; +struct hantro_aux_buf luma_4n; +struct hantro_aux_buf colctbs; +}; + +struct hantro_h264_enc_hw_ctx { +struct v4l2_h264_enc enc; +struct hantro_aux_buf nal_tbl; + +union { +struct hantro_vc8000e_regs vc8000e_regs; + }; +}; +/* Max. number of entries in the DPB (HW limitation). */ #define HANTRO_H264_DPB_SIZE 16@@ -451,6 +469,15 @@ int hantro_g1_h264_dec_run(struct hantro_ctx *ctx);int hantro_h264_dec_init (struct hantro_ctx *ctx);void hantro_h264_dec_exit (struct hantro_ctx *ctx); +irqreturn_t hantro_vc8000e_irq (int irq,void *dev_id); +int hantro_vc8000e_h264_enc_init (struct hantro_ctx *ctx); +void hantro_vc8000e_h264_enc_exit (struct hantro_ctx *ctx); +void hantro_vc8000e_h264_enc_done (struct hantro_ctx *ctx); +int hantro_vc8000e_h264_enc_run (struct hantro_ctx *ctx); +int hantro_h264_enc_prepare_run (struct hantro_ctx *ctx); +int hantro_h264_enc_init (struct hantro_ctx *ctx); +void hantro_h264_enc_exit (struct hantro_ctx *ctx); +int hantro_hevc_dec_init (struct hantro_ctx *ctx);void hantro_hevc_dec_exit (struct hantro_ctx *ctx);int hantro_g2_hevc_dec_run (struct hantro_ctx *ctx);drivers/media/platform/verisilicon/hantro_v4l2.c +6
-0@@ -629,6 +629,12 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx,hantro_get_format_depth (pix_mp->pixelformat), need_postproc); +/* Propagate dimensions for encoders. */ +if (ctx->is_encoder) { + ctx->dst_fmt.width = pix_mp->width; + ctx->dst_fmt.height = pix_mp->height; + } +/* Colorimetry information are always propagated. */ ctx->dst_fmt.colorspace = pix_mp->colorspace; ctx->dst_fmt.ycbcr_enc = pix_mp->ycbcr_enc;drivers/media/platform/verisilicon/hantro_vc8000e.c new file +11
-0@@ -0,0 +1,68 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Hantro VPU codec driver +* +* Copyright (C) 2025-2026 Paul Kocialkowski <[email protected]> +*/ + +#include "hantro.h" +#include "hantro_vc8000e_regs.h" + +irqreturn_t hantro_vc8000e_irq (int irq,void *dev_id)
drivers/media/platform/verisilicon/hantro_vc8000e.c line 21
Quoted 10 lines
drivers/media/platform/verisilicon/hantro_vc8000e.c new file +10
-0+{ +struct hantro_dev *vpu = dev_id; +u32 regs_buffer[HANTRO_VC8000E_SWREG_OFFSET (swreg6) /4 ]; +struct hantro_vc8000e_regs *regs = + (struct hantro_vc8000e_regs *)regs_buffer; +enum vb2_buffer_state state; + +hantro_vc8000e_swreg_read (vpu, regs, swreg1); + + pr_debug("+ hantro-vc8000e-irq: %#x\n",
vpu_debug() ? and drop the +?
Quoted 10 lines
drivers/media/platform/verisilicon/hantro_vc8000e.c new file +10
-0+ regs_buffer[HANTRO_VC8000E_SWREG_OFFSET(swreg1) / 4]); + +if (regs->swreg1.irq) +pr_debug (" - irq\n" ); +if (regs->swreg1.frame_rdy_status) +pr_debug (" - frame ready\n" ); +if (regs->swreg1.bus_error_status) +pr_debug (" - bus error\n" ); +if (regs->swreg1.sw_reset) +pr_debug (" - sw reset\n" );
drivers/media/platform/verisilicon/hantro_vc8000e.c line 41
Quoted 10 lines
drivers/media/platform/verisilicon/hantro_vc8000e.c new file +10
-0+if (regs->swreg1.buffer_full) +pr_debug (" - buffer full\n" ); +if (regs->swreg1.timeout) +pr_debug (" - timeout\n" ); +if (regs->swreg1.slice_rdy_status) +pr_debug (" - slice ready\n" ); +if (regs->swreg1.irq_fuse_error) +pr_debug (" - fuse error\n" ); +if (regs->swreg1.strm_segment_rdy_int) +pr_debug (" - segment ready\n" );
We rate limit these, and to follow vpu_debug(), it should be backed by dev_dbg, so dev_dbg_ratelimited().
Quoted 1,028 lines
drivers/media/platform/verisilicon/hantro_vc8000e.c new file +27
-0+ +hantro_vc8000e_swreg_read (vpu, regs, swreg4); +hantro_vc8000e_swreg_read (vpu, regs, swreg5); + +/* Make sure to disble the encoder on error for safety. */ +if ((regs->swreg1.bus_error_status || + regs->swreg1.buffer_full || + regs->swreg1.timeout || + regs->swreg1.irq_fuse_error) && + (regs->swreg4.mode ==HANTRO_VC8000E_SWREG4_MODE_H264 || + regs->swreg4.mode ==HANTRO_VC8000E_SWREG4_MODE_HEVC )) { + regs->swreg5.enable =0 ; +hantro_vc8000e_swreg_write (vpu, regs, swreg5); + } + + state = regs->swreg1.frame_rdy_status ?VB2_BUF_STATE_DONE : +VB2_BUF_STATE_ERROR ; + + regs->swreg1.irq_dis =1 ; + regs->swreg1.timeout_int =0 ; + +hantro_vc8000e_swreg_write (vpu, regs, swreg1); + +hantro_irq_done (vpu, state); + +return IRQ_HANDLED ; +}drivers/media/platform/verisilicon/hantro_vc8000e_h264_enc.c new file +883
-0@@ -0,0 +1,883 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Hantro VPU codec driver +* +* Copyright (C) 2024 Pengutronix, Marco Felsch <[email protected]> +* Copyright (C) 2025-2026 Paul Kocialkowski <[email protected]> +*/ + +#include <linux/unaligned.h> +#include <linux/delay.h> +#include <media/v4l2-mem2mem.h> +#include <media/v4l2-h264-enc-rbsp.h> + +#include "hantro.h" +#include "hantro_hw.h" +#include "hantro_vc8000e_regs.h" + +static int +hantro_vc8000e_h264_enc_state_constrain (struct v4l2_h264_enc *enc, +struct v4l2_h264_enc_state *state) +{ +struct v4l2_ctrl_h264_sps *sps = &state->sps; +struct v4l2_ctrl_h264_pps *pps = &state->pps; +struct v4l2_ctrl_h264_encode_params *encode = &state->encode; + +/* SPS */ + +if (V4L2_H264_SPS_HAS_CHROMA_FORMAT (sps)) { + sps->chroma_format_idc =1 ; + sps->flags &= ~V4L2_H264_SPS_FLAG_SEPARATE_COLOUR_PLANE ; + sps->bit_depth_luma_minus8 =0 ; + sps->bit_depth_chroma_minus8 =0 ; + sps->flags &= ~V4L2_H264_SPS_FLAG_QPPRIME_Y_ZERO_TRANSFORM_BYPASS ; + } + +/* Only one reference frame is currently supported. */ +if (sps->max_num_ref_frames >1 ) + sps->max_num_ref_frames =1 ; + +if (!(sps->flags &V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY )) { + sps->flags |=V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY ; + sps->flags &= ~V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD ; + } + + sps->flags |=V4L2_H264_SPS_FLAG_DIRECT_8X8_INFERENCE ; + +/* PPS */ + +/* Only one reference frame is currently supported. */ + pps->num_ref_idx_l0_default_active_minus1 =0 ; + pps->num_ref_idx_l1_default_active_minus1 =0 ; + +/* Encode */ + +/* Only a single bit is available for idr_pic_id. */ +if (encode->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC ) + encode->idr_pic_id &=1 ; + +/* The hardware doesn't allow overriding the active list numbers. */ +if (encode->flags &V4L2_H264_SLICE_FLAG_NUM_REF_IDX_ACTIVE_OVERRIDE ) { + encode->flags &= ~V4L2_H264_SLICE_FLAG_NUM_REF_IDX_ACTIVE_OVERRIDE ; + + encode->num_ref_idx_l0_active_minus1 =0 ; + encode->num_ref_idx_l1_active_minus1 =0 ; + } + +/* Only a single bit is available for cabac_init_idc. */ +if (encode->cabac_init_idc >1 ) + encode->cabac_init_idc =1 ; + +/* Only a single bit is available for disable_deblocking_filter_idc. */ +if (encode->disable_deblocking_filter_idc >1 ) + encode->disable_deblocking_filter_idc =1 ; + +return 0 ; +} + +static int +hantro_vc8000e_h264_enc_rec_buffer_alloc (struct v4l2_h264_enc *enc, +struct v4l2_h264_enc_rec_buffer *buffer) +{ +struct hantro_ctx *ctx = enc->private_data; +struct device *dev = ctx->dev->dev; +struct hantro_vc8000e_rec_buf *rec_buf; +unsigned int width_mbs, height_mbs; + + width_mbs =MB_WIDTH (ctx->src_fmt.width); + height_mbs =MB_HEIGHT (ctx->src_fmt.height); + + rec_buf =kzalloc (sizeof (*rec_buf),GFP_KERNEL ); +if (!rec_buf) + goto error; + + rec_buf->luma.size = ctx->src_fmt.width * ctx->src_fmt.height; + rec_buf->luma.cpu =dma_alloc_coherent (dev, rec_buf->luma.size, + &rec_buf->luma.dma,GFP_KERNEL ); +if (!rec_buf->luma.cpu) + goto error; + + rec_buf->chroma.size = rec_buf->luma.size /2 ; + rec_buf->chroma.cpu =dma_alloc_coherent (dev, rec_buf->chroma.size, + &rec_buf->chroma.dma, +GFP_KERNEL ); +if (!rec_buf->chroma.cpu) + goto error; + + rec_buf->luma_4n.size = width_mbs *4 * height_mbs *4 ; + rec_buf->luma_4n.cpu =dma_alloc_coherent (dev, rec_buf->luma_4n.size, + &rec_buf->luma_4n.dma, +GFP_KERNEL ); +if (!rec_buf->luma_4n.cpu) + goto error; + + rec_buf->colctbs.size =DIV_ROUND_UP (width_mbs * height_mbs,2 ); + rec_buf->colctbs.cpu =dma_alloc_coherent (dev, rec_buf->colctbs.size, + &rec_buf->colctbs.dma, +GFP_KERNEL ); +if (!rec_buf->colctbs.cpu) + goto error; + + buffer->private_data = rec_buf; + +return 0 ; + +error: +if (rec_buf) +kfree (rec_buf); + +return -ENOMEM ; +} + +static int +hantro_vc8000e_h264_enc_rec_buffer_free (struct v4l2_h264_enc *enc, +struct v4l2_h264_enc_rec_buffer *buffer) +{ +struct hantro_ctx *ctx = enc->private_data; +struct device *dev = ctx->dev->dev; +struct hantro_vc8000e_rec_buf *rec_buf = buffer->private_data; + +if (!rec_buf) +return -EINVAL ; + +dma_free_coherent (dev, rec_buf->luma.size, rec_buf->luma.cpu, + rec_buf->luma.dma); + +dma_free_coherent (dev, rec_buf->luma_4n.size, rec_buf->luma_4n.cpu, + rec_buf->luma_4n.dma); + +dma_free_coherent (dev, rec_buf->chroma.size, rec_buf->chroma.cpu, + rec_buf->chroma.dma); + +dma_free_coherent (dev, rec_buf->colctbs.size, rec_buf->colctbs.cpu, + rec_buf->colctbs.dma); + +kfree (rec_buf); + buffer->private_data =NULL ; + +return 0 ; +} + +static const struct v4l2_h264_enc_ops hantro_vc8000e_h264_enc_ops = { + .state_constrain = hantro_vc8000e_h264_enc_state_constrain, + .rec_buffer_alloc = hantro_vc8000e_h264_enc_rec_buffer_alloc, + .rec_buffer_free = hantro_vc8000e_h264_enc_rec_buffer_free, +}; + +int hantro_vc8000e_h264_enc_init (struct hantro_ctx *ctx) +{ +struct hantro_h264_enc_hw_ctx *h264_ctx = &ctx->h264_enc; +struct hantro_aux_buf *nal_tbl = &h264_ctx->nal_tbl; +struct v4l2_h264_enc *enc = &h264_ctx->enc; +struct device *dev = ctx->dev->dev; + + nal_tbl->size =ALIGN (MB_HEIGHT (ctx->src_fmt.height),8 ); + nal_tbl->cpu =dma_alloc_coherent (dev, nal_tbl->size, + &nal_tbl->dma,GFP_KERNEL ); +if (!nal_tbl->cpu) +return -ENOMEM ; + + enc->ops = &hantro_vc8000e_h264_enc_ops; + enc->private_data = ctx; + enc->format_mplane = &ctx->dst_fmt; + enc->timeperframe = &ctx->dst_timeperframe; + enc->ctrl_handler = &ctx->ctrl_handler; + enc->ref_slots_count_init =2 ; + enc->flags =V4L2_H264_ENC_FLAG_INTER_PRED | +V4L2_H264_ENC_FLAG_HW_SLICE_HEADER ; + +return v4l2_h264_enc_init (enc); +} + +void hantro_vc8000e_h264_enc_exit (struct hantro_ctx *ctx) +{ +struct hantro_h264_enc_hw_ctx *h264_ctx = &ctx->h264_enc; +struct hantro_aux_buf *nal_tbl = &h264_ctx->nal_tbl; +struct device *dev = ctx->dev->dev; + +if (nal_tbl->cpu) +dma_free_coherent (dev, nal_tbl->size, nal_tbl->cpu, + nal_tbl->dma); + +v4l2_h264_enc_exit (&h264_ctx->enc); +} + +static int ref_setup (struct hantro_ctx *ctx) +{ +struct hantro_h264_enc_hw_ctx *h264_ctx = &ctx->h264_enc; +struct hantro_vc8000e_regs *regs = &h264_ctx->vc8000e_regs; +struct v4l2_h264_enc *enc = &h264_ctx->enc; +struct v4l2_h264_enc_ref *ref = &enc->ref; +struct v4l2_h264_enc_state *state = &enc->state_active; +struct v4l2_ctrl_h264_encode_params *encode = &state->encode; +struct v4l2_h264_dpb_entry *dpb_entry; +struct v4l2_h264_enc_rec_buffer *buffer; +struct hantro_vc8000e_rec_buf *rec_buf; +bool ltr_present = false; +unsigned int index; + + regs->swreg193.nal_ref_idc = encode->nal_ref_idc !=0 ; + +if (encode->flags &V4L2_H264_ENCODE_FLAG_LONG_TERM_REFERENCE ) { + regs->swreg198.mark_current_longterm =1 ; +/* We only get a single long-term reference without MMCO. */ + regs->swreg194.cur_longtermidx =0 ; + } + + regs->swreg193.l0_used_by_next_pic0 =1 ; + regs->swreg193.l0_used_by_next_pic1 =1 ; + regs->swreg194.l1_used_by_next_pic0 =1 ; + regs->swreg194.l1_used_by_next_pic1 =1 ; + + regs->swreg17.active_l0_cnt = ref->l0_active_count; + regs->swreg91.active_l1_cnt = ref->l1_active_count; + regs->swreg4.active_override_flag =1 ; + +if (ref->l0_active_count >0 ) { + index = ref->l0[0 ].index; + dpb_entry = &ref->dpb[index]; + buffer = &ref->buffers[index]; + rec_buf = buffer->private_data; + + regs->swreg18.refpic_recon_l0_y0 = rec_buf->luma.dma; + regs->swreg19.refpic_recon_l0_chroma0 = rec_buf->chroma.dma; + regs->swreg74.refpic_recon_l0_4n0_base = rec_buf->luma_4n.dma; + + regs->swreg17.l0_used_by_curr_pic0 =1 ; +/* TODO: diff with wrap. */ + regs->swreg17.l0_delta_poc0 =1 ; + regs->swreg193.l0_delta_framenum0 =1 ; + +if (dpb_entry->flags &V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM ) { + regs->swreg17.l0_long_term_flag0 =1 ; + regs->swreg198.l0_longtermidx0 =0 ; + ltr_present = true; + } + } + +if (ref->l0_active_count >1 ) { + index = ref->l0[1 ].index; + dpb_entry = &ref->dpb[index]; + buffer = &ref->buffers[index]; + rec_buf = buffer->private_data; + + regs->swreg20.refpic_recon_l0_y1 = rec_buf->luma.dma; + regs->swreg21.refpic_recon_l0_chroma1 = rec_buf->chroma.dma; + regs->swreg76.refpic_recon_l0_4n1_base = rec_buf->luma_4n.dma; + + regs->swreg17.l0_used_by_curr_pic1 =1 ; +/* TODO: diff with wrap. */ + regs->swreg17.l0_delta_poc1 =1 ; + regs->swreg193.l0_delta_framenum1 =1 ; + +if (dpb_entry->flags &V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM ) { + regs->swreg17.l0_long_term_flag1 =1 ; + regs->swreg198.l0_longtermidx1 =0 ; + ltr_present = true; + } + } + +if (ltr_present) + regs->swreg91.long_term_ref_pics_present_flag =1 ; + +return 0 ; +} + +static int lambda_setup (struct hantro_ctx *ctx) +{ +struct hantro_h264_enc_hw_ctx *h264_ctx = &ctx->h264_enc; +struct hantro_vc8000e_regs *regs = &h264_ctx->vc8000e_regs; + +/* Intra SATD */ + + regs->swreg125.intra_satd_lambda_0 =0x47 ; + regs->swreg125.intra_satd_lambda_1 =0x3f ; + regs->swreg126.intra_satd_lambda_2 =0x38 ; + regs->swreg126.intra_satd_lambda_3 =0x32 ; + regs->swreg127.intra_satd_lambda_4 =0 ; + regs->swreg127.intra_satd_lambda_5 =0 ; + regs->swreg128.intra_satd_lambda_6 =0 ; + regs->swreg128.intra_satd_lambda_7 =0 ; + regs->swreg129.intra_satd_lambda_8 =0 ; + regs->swreg129.intra_satd_lambda_9 =0 ; + regs->swreg130.intra_satd_lambda_10 =0 ; + regs->swreg130.intra_satd_lambda_11 =0 ; + regs->swreg131.intra_satd_lambda_12 =0 ; + regs->swreg131.intra_satd_lambda_13 =0 ; + regs->swreg132.intra_satd_lambda_14 =0 ; + regs->swreg132.intra_satd_lambda_15 =0 ; + regs->swreg174.intra_satd_lambda_16 =0x1c4 ; + regs->swreg174.intra_satd_lambda_17 =0x192 ; + regs->swreg175.intra_satd_lambda_18 =0x166 ; + regs->swreg175.intra_satd_lambda_19 =0x13f ; + regs->swreg176.intra_satd_lambda_20 =0x11c ; + regs->swreg176.intra_satd_lambda_21 =0xfd ; + regs->swreg177.intra_satd_lambda_22 =0xe2 ; + regs->swreg177.intra_satd_lambda_23 =0xc9 ; + regs->swreg178.intra_satd_lambda_24 =0xb3 ; + regs->swreg178.intra_satd_lambda_25 =0xa0 ; + regs->swreg179.intra_satd_lambda_26 =0x8e ; + regs->swreg179.intra_satd_lambda_27 =0x7f ; + regs->swreg180.intra_satd_lambda_28 =0x71 ; + regs->swreg180.intra_satd_lambda_29 =0x65 ; + regs->swreg181.intra_satd_lambda_30 =0x5a ; + regs->swreg181.intra_satd_lambda_31 =0x50 ; + +/* Inter SATD */ + + regs->swreg28.lambda_satd_me_0 =0x24 ; + regs->swreg28.lambda_satd_me_1 =0x20 ; + regs->swreg29.lambda_satd_me_2 =0x1c ; + regs->swreg29.lambda_satd_me_3 =0x19 ; + regs->swreg30.lambda_satd_me_4 =0x16 ; + regs->swreg30.lambda_satd_me_5 =0x14 ; + regs->swreg31.lambda_satd_me_6 =0x12 ; + regs->swreg31.lambda_satd_me_7 =0x10 ; + regs->swreg32.lambda_satd_me_8 =0xe ; + regs->swreg32.lambda_satd_me_9 =0xd ; + regs->swreg33.lambda_satd_me_10 =0xb ; + regs->swreg33.lambda_satd_me_11 =0xa ; + regs->swreg34.lambda_satd_me_12 =0x9 ; + regs->swreg34.lambda_satd_me_13 =0x8 ; + regs->swreg78.lambda_satd_me_14 =0x7 ; + regs->swreg78.lambda_satd_me_15 =0x6 ; + regs->swreg150.lambda_satd_me_16 =0 ; + regs->swreg150.lambda_satd_me_17 =0 ; + regs->swreg151.lambda_satd_me_18 =0 ; + regs->swreg151.lambda_satd_me_19 =0 ; + regs->swreg152.lambda_satd_me_20 =0x88 ; + regs->swreg152.lambda_satd_me_21 =0 ; + regs->swreg153.lambda_satd_me_22 =0 ; + regs->swreg153.lambda_satd_me_23 =0 ; + regs->swreg154.lambda_satd_me_24 =0 ; + regs->swreg154.lambda_satd_me_25 =0 ; + regs->swreg155.lambda_satd_me_26 =0 ; + regs->swreg155.lambda_satd_me_27 =0 ; + regs->swreg156.lambda_satd_me_28 =0 ; + regs->swreg156.lambda_satd_me_29 =0 ; + regs->swreg157.lambda_satd_me_30 =0 ; + regs->swreg157.lambda_satd_me_31 =0 ; + +/* Inter SSE */ + + regs->swreg79.lambda_sse_me_0 =0x4f ; + regs->swreg122.lambda_sse_me_1 =0x3f ; + regs->swreg123.lambda_sse_me_2 =0x32 ; + regs->swreg124.lambda_sse_me_3 =0x28 ; + regs->swreg138.lambda_sse_me_4 =0 ; + regs->swreg139.lambda_sse_me_5 =0 ; + regs->swreg140.lambda_sse_me_6 =0 ; + regs->swreg141.lambda_sse_me_7 =0 ; + regs->swreg142.lambda_sse_me_8 =0 ; + regs->swreg143.lambda_sse_me_9 =0 ; + regs->swreg144.lambda_sse_me_10 =0 ; + regs->swreg145.lambda_sse_me_11 =0 ; + regs->swreg146.lambda_sse_me_12 =0 ; + regs->swreg147.lambda_sse_me_13 =0 ; + regs->swreg148.lambda_sse_me_14 =0 ; + regs->swreg149.lambda_sse_me_15 =0 ; + regs->swreg158.lambda_sse_me_16 =0 ; + regs->swreg159.lambda_sse_me_17 =0x800 ; + regs->swreg160.lambda_sse_me_18 =0 ; + regs->swreg161.lambda_sse_me_19 =0 ; + regs->swreg162.lambda_sse_me_20 =0 ; + regs->swreg163.lambda_sse_me_21 =0 ; + regs->swreg164.lambda_sse_me_22 =0 ; + regs->swreg165.lambda_sse_me_23 =0 ; + regs->swreg166.lambda_sse_me_24 =0 ; + regs->swreg167.lambda_sse_me_25 =0 ; + regs->swreg168.lambda_sse_me_26 =0x13c ; + regs->swreg169.lambda_sse_me_27 =0xfb ; + regs->swreg172.lambda_sse_me_30 =0x7d ; + regs->swreg173.lambda_sse_me_31 =0x64 ; + + regs->swreg35.lambda_motion_sse =0 ; + +if (regs->swreg214.hwabsqpsupport) { +/* Used for lambda calculation, different intra/inter value. */ + regs->swreg170_qp_absolute.sse_qp_factor =0x1f5c ; + regs->swreg171_qp_absolute.sad_qp_factor =0x2ccd ; + } + +return 0 ; +} + +static int areas_setup (struct hantro_ctx *ctx) +{ +struct hantro_h264_enc_hw_ctx *h264_ctx = &ctx->h264_enc; +struct hantro_vc8000e_regs *regs = &h264_ctx->vc8000e_regs; + +/* Intra */ + + regs->swreg23.intra_area_left =0xff ; + regs->swreg195.intra_area_left_msb =1 ; + regs->swreg249.intra_area_left_msb2 =1 ; + + regs->swreg23.intra_area_right =0xff ; + regs->swreg195.intra_area_right_msb =1 ; + regs->swreg249.intra_area_right_msb2 =1 ; + + regs->swreg23.intra_area_top =0xff ; + regs->swreg195.intra_area_top_msb =1 ; + regs->swreg249.intra_area_top_msb2 =1 ; + + regs->swreg23.intra_area_bottom =0xff ; + regs->swreg195.intra_area_bottom_msb =1 ; + regs->swreg249.intra_area_bottom_msb2 =1 ; + +/* IPCM1 */ + + regs->swreg208_h264.ipcm1_left =0x1ff ; + regs->swreg249.ipcm1_left_msb =1 ; + + regs->swreg209.ipcm1_right =0x1ff ; + regs->swreg249.ipcm1_right_msb =1 ; + + regs->swreg209.ipcm1_top =0x1ff ; + regs->swreg209.ipcm1_bottom =0x1ff ; + + regs->swreg249.ipcm1_top_msb =1 ; + regs->swreg249.ipcm1_bottom_msb =1 ; + +/* IPCM2 */ + + regs->swreg210.ipcm2_left =0x1ff ; + regs->swreg249.ipcm2_left_msb =1 ; + + regs->swreg211.ipcm2_right =0x1ff ; + regs->swreg249.ipcm2_right_msb =1 ; + + regs->swreg212.ipcm2_top =0x1ff ; + regs->swreg249.ipcm2_top_msb =1 ; + + regs->swreg213.ipcm2_bottom =0x1ff ; + regs->swreg249.ipcm2_bottom_msb =1 ; + +/* ROI1 */ + + regs->swreg24.roi1_left =0xff ; + regs->swreg195.roi1_left_msb =1 ; + regs->swreg249.roi1_left_msb2 =1 ; + + regs->swreg24.roi1_right =0xff ; + regs->swreg195.roi1_right_msb =1 ; + regs->swreg249.roi1_right_msb2 =1 ; + + regs->swreg24.roi1_top =0xff ; + regs->swreg195.roi1_top_msb =1 ; + regs->swreg249.roi1_top_msb2 =1 ; + + regs->swreg24.roi1_bottom =0xff ; + regs->swreg195.roi1_bottom_msb =1 ; + regs->swreg249.roi1_bottom_msb2 =1 ; + +/* ROI2 */ + + regs->swreg25.roi2_left =0xff ; + regs->swreg195.roi2_left_msb =1 ; + regs->swreg249.roi2_left_msb2 =1 ; + + regs->swreg25.roi2_right =0xff ; + regs->swreg195.roi2_right_msb =1 ; + regs->swreg249.roi2_right_msb2 =1 ; + + regs->swreg25.roi2_top =0xff ; + regs->swreg195.roi2_top_msb =1 ; + regs->swreg249.roi2_top_msb2 =1 ; + + regs->swreg25.roi2_bottom =0xff ; + regs->swreg195.roi2_bottom_msb =1 ; + regs->swreg249.roi2_bottom_msb2 =1 ; + +if (regs->swreg226.hwroi8support) { +/* ROI3 */ + + regs->swreg252.roi3_left =0x3ff ; + regs->swreg252.roi3_right =0x3ff ; + regs->swreg252.roi3_top =0x3ff ; + regs->swreg253.roi3_bottom =0x3ff ; + +/* ROI4 */ + + regs->swreg253.roi4_left =0x3ff ; + regs->swreg254.roi4_right =0x3ff ; + regs->swreg253.roi4_top =0x3ff ; + regs->swreg254.roi4_bottom =0x3ff ; + +/* ROI5 */ + + regs->swreg254.roi5_left =0x3ff ; + regs->swreg255.roi5_right =0x3ff ; + regs->swreg255.roi5_top =0x3ff ; + regs->swreg255.roi5_bottom =0x3ff ; + +/* ROI6 */ + + regs->swreg256.roi6_left =0x3ff ; + regs->swreg256.roi6_right =0x3ff ; + regs->swreg256.roi6_top =0x3ff ; + regs->swreg257.roi6_bottom =0x3ff ; + +/* ROI7 */ + + regs->swreg257.roi7_left =0x3ff ; + regs->swreg258.roi7_right =0x3ff ; + regs->swreg257.roi7_top =0x3ff ; + regs->swreg258.roi7_bottom =0x3ff ; + +/* ROI8 */ + + regs->swreg258.roi8_left =0x3ff ; + regs->swreg259.roi8_right =0x3ff ; + regs->swreg259.roi8_top =0x3ff ; + regs->swreg259.roi8_bottom =0x3ff ; + } + +return 0 ; +} + +int hantro_vc8000e_h264_enc_run (struct hantro_ctx *ctx) +{ +struct hantro_dev *vpu = ctx->dev; +struct v4l2_pix_format_mplane *src_fmt = &ctx->src_fmt; +struct hantro_h264_enc_hw_ctx *h264_ctx = &ctx->h264_enc; +struct hantro_vc8000e_regs *regs = &h264_ctx->vc8000e_regs; +struct v4l2_h264_enc *enc = &h264_ctx->enc; +struct v4l2_h264_enc_state *state = &enc->state_active; +const struct v4l2_ctrl_h264_sps *sps; +const struct v4l2_ctrl_h264_pps *pps; +const struct v4l2_ctrl_h264_encode_params *encode; +struct vb2_v4l2_buffer *src_buf, *dst_buf; +struct hantro_vc8000e_rec_buf *rec_buf; +const struct v4l2_format_info *info; +unsigned int luma_stride; +unsigned int chroma_stride; +int ret; + +hantro_start_prepare_run (ctx); + + info =v4l2_format_info (src_fmt->pixelformat); +if (!info) +return -EINVAL ; + + src_buf =hantro_get_src_buf (ctx); + dst_buf =hantro_get_dst_buf (ctx); + + ret =v4l2_h264_enc_step (enc, dst_buf); +if (ret) +return ret; + + sps = &state->sps; + pps = &state->pps; + encode = &state->encode; + +memset (regs,0 ,sizeof (*regs)); + +/* Read relevant read-only registers. */ +hantro_vc8000e_swreg_read (vpu, regs, swreg0); +hantro_vc8000e_swreg_read (vpu, regs, swreg80); +hantro_vc8000e_swreg_read (vpu, regs, swreg214); +hantro_vc8000e_swreg_read (vpu, regs, swreg226); +hantro_vc8000e_swreg_read (vpu, regs, swreg287); + +/* Mode */ + +if (!regs->swreg80.hwh264support) +return -ENODEV ; + + regs->swreg4.mode =HANTRO_VC8000E_SWREG4_MODE_H264 ; + +/* Input */ + + regs->swreg38.input_format = ctx->vpu_src_fmt->enc_fmt; + regs->swreg38.input_rotation =HANTRO_VC8000E_SWREG38_INPUT_ROTATION_0 ; + + luma_stride = src_fmt->plane_fmt[0 ].bytesperline; + +/* +* The hardware seems to expect the luma stride to represent pixels per +* line for packed cases, instead of the usual bytes per line. +*/ +if (info->comp_planes ==1 ) + luma_stride /= info->bpp[0 ]; + + regs->swreg210.input_lu_stride = luma_stride; + +if (info->comp_planes >1 ) { +if (src_fmt->num_planes >1 ) + chroma_stride = src_fmt->plane_fmt[1 ].bytesperline; +else if (info->comp_planes >2 ) + chroma_stride = luma_stride /2 ; +else + chroma_stride = luma_stride; + + regs->swreg211.input_ch_stride = chroma_stride; + } + + regs->swreg12.input_y_base = +vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf,0 ); + +if (info->comp_planes >1 ) { +if (src_fmt->num_planes >1 ) + regs->swreg13.input_cb_base = +vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf, +1 ); +else + regs->swreg13.input_cb_base = +vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf, +0 ) + + luma_stride * src_fmt->height; + } + +if (info->comp_planes >2 ) { +if (src_fmt->num_planes >1 ) + regs->swreg14.input_cr_base = +vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf, +2 ); +else + regs->swreg14.input_cr_base = +vb2_dma_contig_plane_dma_addr (&src_buf->vb2_buf, +0 ) + + luma_stride * src_fmt->height + + chroma_stride * src_fmt->height; + } + +/* Output */ + +if (enc->rbsp_update &V4L2_H264_ENC_RBSP_UPDATE_START_CODE ) + regs->swreg4.output_strm_mode = +HANTRO_VC8000E_SWREG4_OUTPUT_STRM_MODE_BYTE_STREAM ; +else + regs->swreg4.output_strm_mode = +HANTRO_VC8000E_SWREG4_OUTPUT_STRM_MODE_NAL_STREAM ; + + regs->swreg8.output_strm_base = +vb2_dma_contig_plane_dma_addr (&dst_buf->vb2_buf,0 ) + +v4l2_h264_enc_rbsp_bytes_count (&enc->rbsp); + regs->swreg9.output_strm_buffer_limit = +vb2_plane_size (&dst_buf->vb2_buf,0 ) - +v4l2_h264_enc_rbsp_bytes_count (&enc->rbsp); + +if (!regs->swreg9.output_strm_buffer_limit) +return -ENOMEM ; + + regs->swreg10.size_tbl_base = h264_ctx->nal_tbl.dma; + regs->swreg6.nal_size_write =1 ; + + regs->swreg196.num_ctb_rows_per_sync =1 ; + + regs->swreg199.hash_type =HANTRO_VC8000E_SWREG199_HASH_TYPE_NONE ; + +/* Picture */ + + regs->swreg5.pic_width = src_fmt->width /8 ; + regs->swreg5.pic_height = src_fmt->height /8 ; + regs->swreg38.rowlength = src_fmt->width; + + regs->swreg281.chroma_format_idc = sps->chroma_format_idc; + regs->swreg38.output_bitwidth_lum = +HANTRO_VC8000E_SWREG38_OUTPUT_BITWIDTH_LUM_8_BIT ; + + regs->swreg11.poc = enc->ref.pic_order_cnt; + regs->swreg277.pic_order_cnt_type = sps->pic_order_cnt_type; +if (!sps->pic_order_cnt_type) + regs->swreg277.log2_max_pic_order_cnt_lsb = + sps->log2_max_pic_order_cnt_lsb_minus4 +4 ; + + regs->swreg192.framenum = encode->frame_num; + regs->swreg277.log2_max_frame_num = sps->log2_max_frame_num_minus4 +4 ; + +/* Reconstruction */ + + regs->swreg212.ref_lu_stride = src_fmt->width *4 ; + regs->swreg237.ref_ch_stride = src_fmt->width *4 ; + regs->swreg213.ref_ds_lu_stride = src_fmt->width; + + rec_buf = enc->ref.buffer_current.private_data; + + regs->swreg15.recon_y_base = rec_buf->luma.dma; + regs->swreg16.recon_chroma_base = rec_buf->chroma.dma; + regs->swreg72.recon_luma_4n_base = rec_buf->luma_4n.dma; + regs->swreg114.colctbs_store_base = rec_buf->colctbs.dma; + +/* Reference */ + + ret =ref_setup (ctx); +if (ret) +return ret; + +/* Slice */ + +if (encode->slice_type ==V4L2_H264_SLICE_TYPE_I ) + regs->swreg5.frame_coding_type = +HANTRO_VC8000E_SWREG5_FRAME_CODING_TYPE_I ; +else if (encode->slice_type ==V4L2_H264_SLICE_TYPE_P ) + regs->swreg5.frame_coding_type = +HANTRO_VC8000E_SWREG5_FRAME_CODING_TYPE_P ; +else +return -EINVAL ; + +if (encode->flags &V4L2_H264_ENCODE_FLAG_IDR_PIC ) { + regs->swreg191.nal_unit_type =V4L2_H264_NALU_TYPE_SLICE_IDR ; + regs->swreg193.idr_pic_id = encode->idr_pic_id; + }else { + regs->swreg191.nal_unit_type = +V4L2_H264_NALU_TYPE_SLICE_NON_IDR ; + } + + regs->swreg191.pps_id = encode->pic_parameter_set_id; + +/* Quantization */ + + regs->swreg172.qp_min = state->qp_min; + regs->swreg173.qp_max = state->qp_max; + regs->swreg7.pic_init_qp = pps->pic_init_qp_minus26 +26 ; + regs->swreg7.pic_qp = enc->rc.qp; + regs->swreg4.chroma_qp_offset = pps->chroma_qp_index_offset; + +/* Coding */ + +if (pps->flags &V4L2_H264_PPS_FLAG_ENTROPY_CODING_MODE ) { + regs->swreg193.entropy_coding_mode =1 ; + regs->swreg7.cabac_init_flag = encode->cabac_init_idc; + } + +if (pps->flags &V4L2_H264_PPS_FLAG_TRANSFORM_8X8_MODE ) + regs->swreg193.transform8x8_enable =1 ; + +if (pps->flags &V4L2_H264_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT ) { + regs->swreg5.pps_deblocking_filter_override_enabled_flag =1 ; + regs->swreg5.slice_deblocking_filter_override_flag =1 ; + + regs->swreg6.deblocking_filter_dis = + encode->disable_deblocking_filter_idc; + regs->swreg6.deblocking_tc_offset = + encode->slice_alpha_c0_offset_div2; + regs->swreg6.deblocking_beta_offset = + encode->slice_beta_offset_div2; + } + + regs->swreg4.min_trb_size =HANTRO_VC8000E_SWREG4_TRB_SIZE_4X4 ; + regs->swreg4.max_trb_size =HANTRO_VC8000E_SWREG4_TRB_SIZE_16X16 ; + regs->swreg4.min_cb_size =HANTRO_VC8000E_SWREG4_CB_SIZE_8X8 ; + regs->swreg4.max_cb_size =HANTRO_VC8000E_SWREG4_CB_SIZE_16X16 ; + regs->swreg4.max_trans_hierarchy_depth_inter =2 ; + regs->swreg4.max_trans_hierarchy_depth_intra =1 ; + + regs->swreg36.bits_est_1n_cu_penalty =15 ; + regs->swreg35.bits_est_tu_split_penalty =3 ; + + regs->swreg35.bits_est_bias_intra_cu_8 =22 ; + regs->swreg35.bits_est_bias_intra_cu_16 =40 ; + regs->swreg36.bits_est_bias_intra_cu_32 =86 ; + regs->swreg36.bits_est_bias_intra_cu_64 =304 ; + regs->swreg36.inter_skip_bias =124 ; + + regs->swreg201.mean_thr0 =5 ; + regs->swreg201.mean_thr1 =5 ; + regs->swreg201.mean_thr2 =5 ; + regs->swreg201.mean_thr3 =5 ; + + regs->swreg203_h264.lum_dc_sum_thr =5 ; + regs->swreg203_h264.cb_dc_sum_thr =1 ; + regs->swreg203_h264.cr_dc_sum_thr =1 ; + + regs->swreg26.intra_size_factor_0 =506 ; + regs->swreg26.intra_size_factor_1 =506 ; + regs->swreg26.intra_size_factor_2 =709 ; + regs->swreg27.intra_size_factor_3 =709 ; + + regs->swreg27.intra_mode_factor_0 =24 ; + regs->swreg27.intra_mode_factor_1 =12 ; + regs->swreg27.intra_mode_factor_2 =48 ; + + regs->swreg182.qp_delta_gain =313 ; + +/* Lambda */ + + ret =lambda_setup (ctx); +if (ret) +return ret; + +/* Areas */ + + ret =areas_setup (ctx); +if (ret) +return ret; + +/* Urgent thresholds */ + + regs->swreg272.wr_urgent_disable_threshold = +HANTRO_VC8000E_SWREG272_URGENT_THRESHOLD_DISABLE ; + regs->swreg272.wr_urgent_enable_threshold = +HANTRO_VC8000E_SWREG272_URGENT_THRESHOLD_DISABLE ; + regs->swreg272.rd_urgent_disable_threshold = +HANTRO_VC8000E_SWREG272_URGENT_THRESHOLD_DISABLE ; + regs->swreg272.rd_urgent_enable_threshold = +HANTRO_VC8000E_SWREG272_URGENT_THRESHOLD_DISABLE ; + +/* AXI bus */ + + regs->swreg81.max_burst =16 ; + regs->swreg261.axi_read_outstanding_num =64 ; + regs->swreg246.axi_write_outstanding_num =64 ; + regs->swreg320.axi_burst_align_rd_lu_ref_prefetch =1 ; + +/* Automatic clock gating */ + + regs->swreg3.clock_gate_inter_h264_e =1 ; + regs->swreg3.clock_gate_inter_h265_e =1 ; + regs->swreg3.clock_gate_inter_e =1 ; + regs->swreg3.clock_gate_encoder_h264_e =1 ; + regs->swreg3.clock_gate_encoder_h265_e =1 ; + regs->swreg3.clock_gate_encoder_e =1 ; + +/* IRQ status */ + + regs->swreg1.irq =1 ; + regs->swreg1.frame_rdy_status =1 ; + regs->swreg1.bus_error_status =1 ; + regs->swreg1.sw_reset =1 ; + regs->swreg1.buffer_full =1 ; + regs->swreg1.timeout =1 ; + regs->swreg1.irq_line_buffer =1 ; + regs->swreg1.slice_rdy_status =1 ; + +/* IRQ */ + + regs->swreg1.irq_dis =0 ; + regs->swreg1.timeout_int =1 ; + +/* Register write */ + +hantro_io_copy (vpu->enc_base, regs,sizeof (*regs)); + +hantro_end_prepare_run (ctx); + +/* Enable */ + + regs->swreg5.enable =1 ; + +hantro_vc8000e_swreg_write (vpu, regs, swreg5); + +return 0 ; +} + +void hantro_vc8000e_h264_enc_done (struct hantro_ctx *ctx) +{ +struct hantro_dev *vpu = ctx->dev; +struct hantro_h264_enc_hw_ctx *h264_ctx = &ctx->h264_enc; +struct hantro_vc8000e_regs *regs = &h264_ctx->vc8000e_regs; +struct v4l2_h264_enc *enc = &h264_ctx->enc; +struct vb2_v4l2_buffer *dst_buf =hantro_get_dst_buf (ctx); +u32 bytesused; + +hantro_vc8000e_swreg_read (vpu, regs, swreg9); + + bytesused = regs->swreg9.output_strm_buffer_limit + +v4l2_h264_enc_rbsp_bytes_count (&enc->rbsp); + +vb2_set_plane_payload (&dst_buf->vb2_buf,0 , bytesused); + +v4l2_h264_enc_complete (enc, dst_buf); +}drivers/media/platform/verisilicon/hantro_vc8000e_regs.h new file +106
-0@@ -0,0 +1,2129 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Hantro VPU codec driver +* +* Copyright (C) 2025-2026 Paul Kocialkowski <[email protected]> +*/ + +#ifndef HANTRO_VC8000E_REGS_H_ +#define HANTRO_VC8000E_REGS_H_ + +#include <linux/types.h> + +#define HANTRO_VC8000E_SWREG_OFFSET (s) \ + offsetof(struct hantro_vc8000e_regs, s) + +#define hantro_vc8000e_swreg_read (v, r, s) \ + ({ \ + u32 *pointer = (u32 *)&(r)->s; \ + *pointer = vepu_read(v, HANTRO_VC8000E_SWREG_OFFSET(s)); \ + }) + +#define hantro_vc8000e_swreg_write (v, r, s) \ + ({ \ + u32 *pointer = (u32 *)&(r)->s; \ + vepu_write(v, *pointer, HANTRO_VC8000E_SWREG_OFFSET(s)); \ + }) + +#define HANTRO_VC8000E_SWREG0_MAJOR_NUMBER_V6_0 0x60 +#define HANTRO_VC8000E_SWREG0_MAJOR_NUMBER_V6_1 0x61 +#define HANTRO_VC8000E_SWREG0_MAJOR_NUMBER_V6_2 0x62 +#define HANTRO_VC8000E_SWREG0_PRODUCT_ID_VC8000E 0x8000 + +#define HANTRO_VC8000E_SWREG4_OUTPUT_STRM_MODE_BYTE_STREAM 0x0 +#define HANTRO_VC8000E_SWREG4_OUTPUT_STRM_MODE_NAL_STREAM 0x1 +#define HANTRO_VC8000E_SWREG4_TRB_SIZE_4X4 0x0 +#define HANTRO_VC8000E_SWREG4_TRB_SIZE_8X8 0x1 +#define HANTRO_VC8000E_SWREG4_TRB_SIZE_16X16 0x2 +#define HANTRO_VC8000E_SWREG4_TRB_SIZE_32X32 0x3 +#define HANTRO_VC8000E_SWREG4_CB_SIZE_8X8 0x0 +#define HANTRO_VC8000E_SWREG4_CB_SIZE_16X16 0x1 +#define HANTRO_VC8000E_SWREG4_CB_SIZE_32X32 0x2 +#define HANTRO_VC8000E_SWREG4_CB_SIZE_64X64 0x3 +#define HANTRO_VC8000E_SWREG4_MODE_HEVC 0x1 +#define HANTRO_VC8000E_SWREG4_MODE_H264 0x2 +#define HANTRO_VC8000E_SWREG4_MODE_JPEG 0x4 + +#define HANTRO_VC8000E_SWREG5_FRAME_CODING_TYPE_P 0x0 +#define HANTRO_VC8000E_SWREG5_FRAME_CODING_TYPE_I 0x1 +#define HANTRO_VC8000E_SWREG5_FRAME_CODING_TYPE_B 0x2 + +#define HANTRO_VC8000E_SWREG36_OUTPUT_BITWIDTH_CHROMA_8_BIT 0x0 +#define HANTRO_VC8000E_SWREG36_OUTPUT_BITWIDTH_CHROMA_9_BIT 0x1 +#define HANTRO_VC8000E_SWREG36_OUTPUT_BITWIDTH_CHROMA_10_BIT 0x2 + +#define HANTRO_VC8000E_SWREG38_OUTPUT_BITWIDTH_LUM_8_BIT 0x0 +#define HANTRO_VC8000E_SWREG38_OUTPUT_BITWIDTH_LUM_9_BIT 0x1 +#define HANTRO_VC8000E_SWREG38_OUTPUT_BITWIDTH_LUM_10_BIT 0x2 +#define HANTRO_VC8000E_SWREG38_INPUT_ROTATION_0 0x0 +#define HANTRO_VC8000E_SWREG38_INPUT_ROTATION_90 0x1 +#define HANTRO_VC8000E_SWREG38_INPUT_ROTATION_270 0x2 +#define HANTRO_VC8000E_SWREG38_INPUT_ROTATION_180 0x3 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_YUV420P 0x0 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_YUV420SP 0x1 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_YUYV422 0x2 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_UYVY422 0x3 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_RGB565 0x4 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_RGB555 0x5 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_RGB444 0x6 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_RGB888 0x7 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_RGB101010 0x8 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_I010 0x9 +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_P010 0xa +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_PACKED10BITPLANAR 0xb +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_Y0L2 0xc +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_DAHUAHEVC 0xd +#define HANTRO_VC8000E_SWREG38_INPUT_FORMAT_DAHUAH264 0xe + +#define HANTRO_VC8000E_SWREG80_HWBUSWIDTH_32_BIT 0x0 +#define HANTRO_VC8000E_SWREG80_HWBUSWIDTH_64_BIT 0x1 +#define HANTRO_VC8000E_SWREG80_HWBUSWIDTH_128_BIT 0x2 +#define HANTRO_VC8000E_SWREG80_HWBUS_AHB 0x1 +#define HANTRO_VC8000E_SWREG80_HWBUS_OCP 0x2 +#define HANTRO_VC8000E_SWREG80_HWBUS_AXI 0x3 +#define HANTRO_VC8000E_SWREG80_HWBUS_PCI 0x4 +#define HANTRO_VC8000E_SWREG80_HWBUS_AXIAHB 0x5 +#define HANTRO_VC8000E_SWREG80_HWBUS_AXIAPB 0x6 + +#define HANTRO_VC8000E_SWREG_ROI_QP_TYPE_DELTA 0x0 +#define HANTRO_VC8000E_SWREG_ROI_QP_TYPE_ABSOLUTE 0x1 + +#define HANTRO_VC8000E_SWREG181_RC_BLOCK_SIZE_64X64 0x0 +#define HANTRO_VC8000E_SWREG181_RC_BLOCK_SIZE_32X32 0x1 +#define HANTRO_VC8000E_SWREG181_RC_BLOCK_SIZE_16X16 0x2 + +#define HANTRO_VC8000E_SWREG199_HASH_TYPE_NONE 0x0 +#define HANTRO_VC8000E_SWREG199_HASH_TYPE_CRC32 0x1 +#define HANTRO_VC8000E_SWREG199_HASH_TYPE_CHECKSUM32 0x2 + +#define HANTRO_VC8000E_SWREG214_HWROIMAPVERSION_4_BPP 0x0 +#define HANTRO_VC8000E_SWREG214_HWROIMAPVERSION_8_BPP 0x1 + +#define HANTRO_VC8000E_SWREG226_HWINLOOPDSRATIO_1_1 0x0 +#define HANTRO_VC8000E_SWREG226_HWINLOOPDSRATIO_1_2 0x1 +#define HANTRO_VC8000E_SWREG226_BFRAME_ME4N_HOR_SEARCHRANGE_64 0x0 +#define HANTRO_VC8000E_SWREG226_BFRAME_ME4N_HOR_SEARCHRANGE_128 0x1 +#define HANTRO_VC8000E_SWREG226_BFRAME_ME4N_HOR_SEARCHRANGE_192 0x2
drivers/media/platform/verisilicon/hantro_vc8000e_regs.h line 116
Quoted 10 lines
drivers/media/platform/verisilicon/hantro_vc8000e_regs.h new file +10
-0+#define HANTRO_VC8000E_SWREG226_BFRAME_ME4N_HOR_SEARCHRANGE_256 0x3 +#define HANTRO_VC8000E_SWREG226_HWP010REFSUPPORT_NORMAL 0x0 +#define HANTRO_VC8000E_SWREG226_HWP010REFSUPPORT_TILED_P010 0x1 + +#define HANTRO_VC8000E_SWREG272_URGENT_THRESHOLD_DISABLE 0xff + +#define HANTRO_VC8000E_SWREG281_CHROMA_FORMAT_IDC_400 0x0 +#define HANTRO_VC8000E_SWREG281_CHROMA_FORMAT_IDC_420 0x1 + +struct hantro_vc8000e_regs {
I like register structure, not everyone do, but I do and I think its good firt for group of 32 bit. But I also very like consistent code and this bring a third style to this old driver. Please sync with Benjamin on the direction here and find a direction. I think he was looking at buffered register, but not regmap and not bit field.
Nicolas
Quoted 2,013 lines
drivers/media/platform/verisilicon/hantro_vc8000e_regs.h new file +2013
-0+struct { +u32 minor_number :8 ; +u32 major_number :8 ; +u32 product_id :16 ; + } swreg0; + +struct { +u32 irq :1 ; +u32 irq_dis :1 ; +u32 frame_rdy_status :1 ; +u32 bus_error_status :1 ; +u32 sw_reset :1 ; +u32 buffer_full :1 ; +u32 timeout :1 ; +u32 irq_line_buffer :1 ; +u32 slice_rdy_status :1 ; +u32 irq_fuse_error :1 ; +u32 reserved0 :1 ; +u32 timeout_int :1 ; +u32 strm_segment_rdy_int :1 ; +u32 reserved1 :19 ; + } swreg1; + +struct { +u32 ctb_rc_mem_out_swap :4 ; +u32 roi_map_qp_delta_map_swap :4 ; +u32 pic_swap :4 ; +u32 strm_swap :4 ; +u32 axi_read_id :8 ; +u32 axi_write_id :8 ; + } swreg2; + +struct { +u32 reserved0 :1 ; +u32 strm_segment_int :1 ; +u32 line_buffer_int :1 ; +u32 slice_int :1 ; +u32 reserved1 :16 ; +u32 cu_info_mem_out_swap :4 ; +u32 axi_rd_id_e :1 ; +u32 axi_wr_id_e :1 ; +u32 clock_gate_inter_h264_e :1 ; +u32 clock_gate_inter_h265_e :1 ; +u32 clock_gate_inter_e :1 ; +u32 clock_gate_encoder_h264_e :1 ; +u32 clock_gate_encoder_h265_e :1 ; +u32 clock_gate_encoder_e :1 ; + } swreg3; + +struct { +u32 max_trans_hierarchy_depth_inter :3 ; +u32 max_trans_hierarchy_depth_intra :3 ; +u32 sao_enable :1 ; +u32 active_override_flag :1 ; +u32 scaling_list_enabled_flag :1 ; +u32 reserved0 :2 ; +u32 bw_linebuf_disable :1 ; +u32 strong_intra_smoothing_enabled_flag :1 ; +u32 chroma_qp_offset :5 ; +u32 output_strm_mode :1 ; +u32 max_trb_size :2 ; +u32 min_trb_size :2 ; +u32 max_cb_size :2 ; +u32 min_cb_size :2 ; +u32 reserved1 :2 ; +u32 mode :3 ; + } swreg4; + +union { +struct { +u32 enable :1 ; +u32 frame_coding_type :2 ; +u32 ref_frames :2 ; +u32 buffer_full_continue :1 ; +u32 output_cu_info_enabled :1 ; +u32 reserved0 :1 ; +u32 slice_deblocking_filter_override_flag :1 ; +u32 pps_deblocking_filter_override_enabled_flag :1 ; +u32 reserved1 :1 ; +u32 pic_height :11 ; +u32 pic_width :10 ; + } swreg5; + +struct { +u32 reserved :8 ; +u32 jpeg_pic_height :12 ; +u32 jpeg_pic_width :12 ; + } swreg5_jpeg; + }; + +struct { +u32 cu_qp_delta_enabled :1 ; +u32 nal_size_write :1 ; +u32 rps_id :5 ; +u32 deblocking_beta_offset :4 ; +u32 deblocking_tc_offset :4 ; +u32 deblocking_filter_dis :1 ; +u32 num_positive_pics :2 ; +u32 num_negative_pics :2 ; +u32 num_short_term_ref_pic_sets :5 ; +u32 slice_size :7 ; + } swreg6; + +struct { +u32 roi2_delta_qp :4 ; +u32 roi1_delta_qp :4 ; +u32 pic_qp :6 ; +u32 diff_cu_qp_delta_depth :2 ; +u32 reserved :1 ; +u32 num_slices_ready :8 ; +u32 cabac_init_flag :1 ; +u32 pic_init_qp :6 ; + } swreg7; + +struct { +u32 output_strm_base :32 ; + } swreg8; + +struct { +u32 output_strm_buffer_limit :32 ; + } swreg9; + +struct { +u32 size_tbl_base :32 ; + } swreg10; + +struct { +u32 poc :32 ; + } swreg11; + +struct { +u32 input_y_base :32 ; + } swreg12; + +struct { +u32 input_cb_base :32 ; + } swreg13; + +struct { +u32 input_cr_base :32 ; + } swreg14; + +struct { +u32 recon_y_base :32 ; + } swreg15; + +struct { +u32 recon_chroma_base :32 ; + } swreg16; + +struct { +u32 l0_ref1_chroma_compressor_enable :1 ; +u32 l0_ref1_luma_compressor_enable :1 ; +u32 l0_ref0_chroma_compressor_enable :1 ; +u32 l0_ref0_luma_compressor_enable :1 ; +u32 recon_chroma_compressor_enable :1 ; +u32 recon_luma_compressor_enable :1 ; +u32 active_l0_cnt :2 ; +u32 l0_used_by_curr_pic1 :1 ; +u32 l0_long_term_flag1 :1 ; +u32 l0_delta_poc1 :10 ; +u32 l0_used_by_curr_pic0 :1 ; +u32 l0_long_term_flag0 :1 ; +u32 l0_delta_poc0 :10 ; + } swreg17; + +union { +struct { +u32 refpic_recon_l0_y0 :32 ; + } swreg18; + +struct { +u32 jpeg_rst :16 ; +u32 jpeg_rstint :8 ; +u32 jpeg_mode :1 ; +u32 jpeg_slice :1 ; +u32 strm_startoffset :6 ; + } swreg18_jpeg; + }; + +union { +struct { +u32 refpic_recon_l0_chroma0 :32 ; + } swreg19; + +struct { +u32 strm_hdrrem1 :32 ; + } swreg19_jpeg; + }; + +union { +struct { +u32 refpic_recon_l0_y1 :32 ; + } swreg20; + +struct { +u32 reserved :8 ; +u32 ljpeg_pt :3 ; +u32 ljpeg_psv :3 ; +u32 ljpeg_format :2 ; +u32 ljpeg_en :1 ; +u32 jpeg_rowlength :15 ; + } swreg20_jpeg; + }; + +union { +struct { +u32 refpic_recon_l0_chroma1 :32 ; + } swreg21; + +struct { +u32 strm_hdrrem2 :32 ; + } swreg21_jpeg; + }; + +struct { +u32 roi_area_enable :1 ; +u32 roi_map_enable :1 ; +u32 qadj_enable :1 ; +u32 rc_enable :1 ; +u32 cir_interval :14 ; +u32 cir_start :14 ; + } swreg22; + +struct { +u32 intra_area_bottom :8 ; +u32 intra_area_top :8 ; +u32 intra_area_right :8 ; +u32 intra_area_left :8 ; + } swreg23; + +struct { +u32 roi1_bottom :8 ; +u32 roi1_top :8 ; +u32 roi1_right :8 ; +u32 roi1_left :8 ; + } swreg24; + +struct { +u32 roi2_bottom :8 ; +u32 roi2_top :8 ; +u32 roi2_right :8 ; +u32 roi2_left :8 ; + } swreg25; + +struct { +u32 reserved :2 ; +u32 intra_size_factor_2 :10 ; +u32 intra_size_factor_1 :10 ; +u32 intra_size_factor_0 :10 ; + } swreg26; + +struct { +u32 reserved :4 ; +u32 intra_mode_factor_2 :7 ; +u32 intra_mode_factor_1 :6 ; +u32 intra_mode_factor_0 :5 ; +u32 intra_size_factor_3 :10 ; + } swreg27; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_1 :13 ; +u32 lambda_satd_me_0 :13 ; + } swreg28; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_3 :13 ; +u32 lambda_satd_me_2 :13 ; + } swreg29; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_5 :13 ; +u32 lambda_satd_me_4 :13 ; + } swreg30; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_7 :13 ; +u32 lambda_satd_me_6 :13 ; + } swreg31; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_9 :13 ; +u32 lambda_satd_me_8 :13 ; + } swreg32; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_11 :13 ; +u32 lambda_satd_me_10 :13 ; + } swreg33; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_13 :13 ; +u32 lambda_satd_me_12 :13 ; + } swreg34; + +struct { +u32 bits_est_bias_intra_cu_16 :8 ; +u32 bits_est_bias_intra_cu_8 :7 ; +u32 bits_est_tu_split_penalty :3 ; +u32 lambda_motion_sse :14 ; + } swreg35; + +struct { +u32 output_bitwidth_chroma :2 ; +u32 bits_est_1n_cu_penalty :4 ; +u32 inter_skip_bias :7 ; +u32 bits_est_bias_intra_cu_64 :10 ; +u32 bits_est_bias_intra_cu_32 :9 ; + } swreg36; + +struct { +u32 chroffset :4 ; +u32 lambda_sao_luma :14 ; +u32 lambda_sao_chroma :14 ; + } swreg37; + +struct { +u32 mirror :1 ; +u32 yfill :3 ; +u32 xfill :2 ; +u32 rowlength :14 ; +u32 lumoffset :4 ; +u32 output_bitwidth_lum :2 ; +u32 input_rotation :2 ; +u32 input_format :4 ; + } swreg38; + +struct { +u32 rgbcoeffb :16 ; +u32 rgbcoeffa :16 ; + } swreg39; + +struct { +u32 rgbcoeffe :16 ; +u32 rgbcoeffc :16 ; + } swreg40; + +struct { +u32 reserved :1 ; +u32 bmaskmsb :5 ; +u32 gmaskmsb :5 ; +u32 rmaskmsb :5 ; +u32 rgbcoefff :16 ; + } swreg41; + +struct { +u32 basescaledoutlum :32 ; + } swreg42; + +struct { +u32 scale_mode :2 ; +u32 scaledoutwidthmsb :1 ; +u32 scaledoutwidthratio :16 ; +u32 scaledoutwidth :13 ; + } swreg43; + +struct { +u32 input_format_msb :2 ; +u32 scaledoutheightratio :16 ; +u32 scaledoutheight :14 ; + } swreg44; + +struct { +u32 reserved :2 ; +u32 scaledout_format :1 ; +u32 nalunitsize_swap :4 ; +u32 scaledverticalcopy :1 ; +u32 scaledhorizontalcopy :1 ; +u32 vscale_weight_en :1 ; +u32 scaledskiptoppixelrow :2 ; +u32 scaledskipleftpixelcolumn :2 ; +u32 encoded_ctb_number :13 ; +u32 chroma_swap :1 ; +u32 scaledout_swap :4 ; + } swreg45; + +struct { +u32 compressedcoeff_base :32 ; + } swreg46; + +struct { +u32 compressedcoeff_base_msb :32 ; + } swreg47; + +struct { +u32 basescaledoutlum_msb :32 ; + } swreg48; + +struct { +u32 refpic_recon_l0_y0_msb :32 ; + } swreg49; + +struct { +u32 refpic_recon_l0_chroma0_msb :32 ; + } swreg50; + +struct { +u32 refpic_recon_l0_y1_msb :32 ; + } swreg51; + +struct { +u32 refpic_recon_l0_chroma1_msb :32 ; + } swreg52; + +struct { +u32 input_y_base_msb :32 ; + } swreg53; + +struct { +u32 input_cb_base_msb :32 ; + } swreg54; + +struct { +u32 input_cr_base_msb :32 ; + } swreg55; + +struct { +u32 recon_y_base_msb :32 ; + } swreg56; + +struct { +u32 recon_chroma_base_msb :32 ; + } swreg57; + +struct { +u32 size_tbl_base_msb :32 ; + } swreg58; + +struct { +u32 output_strm_base_msb :32 ; + } swreg59; + +struct { +u32 recon_luma_compress_table_base :32 ; + } swreg60; + +struct { +u32 recon_luma_compress_table_base_msb :32 ; + } swreg61; + +struct { +u32 recon_chroma_compress_table_base :32 ; + } swreg62; + +struct { +u32 recon_chroma_compress_table_base_msb :32 ; + } swreg63; + +struct { +u32 l0_ref0_luma_compress_table_base :32 ; + } swreg64; + +struct { +u32 l0_ref0_luma_compress_table_base_msb :32 ; + } swreg65; + +struct { +u32 l0_ref0_chroma_compress_table_base :32 ; + } swreg66; + +struct { +u32 l0_ref0_chroma_compress_table_base_msb :32 ; + } swreg67; + +struct { +u32 l0_ref1_luma_compress_table_base :32 ; + } swreg68; + +struct { +u32 l0_ref1_luma_compress_table_base_msb :32 ; + } swreg69; + +struct { +u32 l0_ref1_chroma_compress_table_base :32 ; + } swreg70; + +struct { +u32 l0_ref1_chroma_compress_table_base_msb :32 ; + } swreg71; + +struct { +u32 recon_luma_4n_base :32 ; + } swreg72; + +struct { +u32 recon_luma_4n_base_msb :32 ; + } swreg73; + +struct { +u32 refpic_recon_l0_4n0_base :32 ; + } swreg74; + +struct { +u32 refpic_recon_l0_4n0_base_msb :32 ; + } swreg75; + +struct { +u32 refpic_recon_l0_4n1_base :32 ; + } swreg76; + +struct { +u32 refpic_recon_l0_4n1_base_msb :32 ; + } swreg77; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_15 :13 ; +u32 lambda_satd_me_14 :13 ; + } swreg78; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_0 :21 ; + } swreg79; + +struct { +u32 hwmaxvideowidth :13 ; +u32 hwbuswidth :2 ; +u32 hwjpegsupport :1 ; +u32 hwtu32support :1 ; +u32 hwrfcsupport :1 ; +u32 hwprogrdosupport :1 ; +u32 hwlinebufsupport :1 ; +u32 hwcavlcsupport :1 ; +u32 hwbus :3 ; +u32 hwmain10support :1 ; +u32 hwdenoisesupport :1 ; +u32 hwvp9support :1 ; +u32 hwhevcsupport :1 ; +u32 hwrgbsupport :1 ; +u32 hwbframesupport :1 ; +u32 hwscalingsupport :1 ; +u32 hwh264support :1 ; + } swreg80; + +struct { +u32 timeout_cycles :23 ; +u32 timeout_override_e :1 ; +u32 max_burst :8 ; + } swreg81; + +struct { +u32 hw_performance :32 ; + } swreg82; + +struct { +u32 refpic_recon_l1_y0 :32 ; + } swreg83; + +struct { +u32 refpic_recon_l1_chroma0 :32 ; + } swreg84; + +struct { +u32 refpic_recon_l1_y1 :32 ; + } swreg85; + +struct { +u32 refpic_recon_l1_chroma1 :32 ; + } swreg86; + +struct { +u32 refpic_recon_l1_y0_msb :32 ; + } swreg87; + +struct { +u32 refpic_recon_l1_chroma0_msb :32 ; + } swreg88; + +struct { +u32 refpic_recon_l1_y1_msb :32 ; + } swreg89; + +struct { +u32 refpic_recon_l1_chroma1_msb :32 ; + } swreg90; + +struct { +u32 l1_ref1_chroma_compressor_enable :1 ; +u32 l1_ref1_luma_compressor_enable :1 ; +u32 l1_ref0_chroma_compressor_enable :1 ; +u32 l1_ref0_luma_compressor_enable :1 ; +u32 long_term_ref_pics_present_flag :1 ; +u32 reserved :1 ; +u32 active_l1_cnt :2 ; +u32 l1_used_by_curr_pic1 :1 ; +u32 l1_long_term_flag1 :1 ; +u32 l1_delta_poc1 :10 ; +u32 l1_used_by_curr_pic0 :1 ; +u32 l1_long_term_flag0 :1 ; +u32 l1_delta_poc0 :10 ; + } swreg91; + +struct { +u32 refpic_recon_l1_4n0_base :32 ; + } swreg92; + +struct { +u32 refpic_recon_l1_4n0_base_msb :32 ; + } swreg93; + +struct { +u32 refpic_recon_l1_4n1_base :32 ; + } swreg94; + +struct { +u32 refpic_recon_l1_4n1_base_msb :32 ; + } swreg95; + +struct { +u32 l1_ref0_luma_compress_table_base :32 ; + } swreg96; + +struct { +u32 l1_ref0_luma_compress_table_base_msb :32 ; + } swreg97; + +struct { +u32 l1_ref0_chroma_compress_table_base :32 ; + } swreg98; + +struct { +u32 l1_ref0_chroma_compress_table_base_msb :32 ; + } swreg99; + +struct { +u32 l1_ref1_luma_compress_table_base :32 ; + } swreg100; + +struct { +u32 l1_ref1_luma_compress_table_base_msb :32 ; + } swreg101; + +struct { +u32 l1_ref1_chroma_compress_table_base :32 ; + } swreg102; + +struct { +u32 l1_ref1_chroma_compress_table_base_msb :32 ; + } swreg103; + +struct { +u32 ref_pic_list_modi_flag_l0 :1 ; +u32 list_entry_l0_pic0 :4 ; +u32 list_entry_l0_pic1 :4 ; +u32 reserved0 :7 ; +u32 ref_pic_list_modi_flag_l1 :1 ; +u32 list_entry_l1_pic0 :4 ; +u32 list_entry_l1_pic1 :4 ; +u32 reserved1 :4 ; +u32 rdo_level :2 ; +u32 lists_modi_present_flag :1 ; + } swreg104; + +struct { +u32 targetpicsize :32 ; + } swreg105; + +struct { +u32 minpicsize :32 ; + } swreg106; + +struct { +u32 maxpicsize :32 ; + } swreg107; + +struct { +u32 nonzerocount :24 ; +u32 averageqp :8 ; + } swreg108; + +struct { +u32 roimapdeltaqpaddr :32 ; + } swreg109; + +struct { +u32 roimapdeltaqpaddr_msb :32 ; + } swreg110; + +struct { +u32 reserved :12 ; +u32 intracu8num :20 ; + } swreg111; + +struct { +u32 reserved :12 ; +u32 skipcu8num :20 ; + } swreg112; + +struct { +u32 pbframe4nrdcost :32 ; + } swreg113; + +struct { +u32 colctbs_store_base :32 ; + } swreg114; + +struct { +u32 colctbs_store_base_msb :32 ; + } swreg115; + +struct { +u32 colctbs_load_base :32 ; + } swreg116; + +struct { +u32 colctbs_load_base_msb :32 ; + } swreg117; + +struct { +u32 ctbrcthrdmax :16 ; +u32 ctbrcthrdmin :16 ; + } swreg118; + +struct { +u32 ctbbitsmax :16 ; +u32 ctbbitsmin :16 ; + } swreg119; + +struct { +u32 totallcubits :32 ; + } swreg120; + +struct { +u32 bitsratio :32 ; + } swreg121; + +union { +struct { +u32 reserved :11 ; +u32 lambda_sse_me_1 :21 ; + } swreg122; + +struct { +u32 av1_enable_order_hint :1 ; +u32 av1_allow_update_cdf :1 ; +u32 av1_interp_filter :3 ; +u32 av1_switchable_motion_mode :1 ; +u32 av1_cur_frame_force_integer_mv :1 ; +u32 av1_enable_dual_filter :1 ; +u32 av1_enable_interintra_compound :1 ; +u32 av1_list1_ref_frame :4 ; +u32 av1_list0_ref_frame :4 ; +u32 av1_reference_mode :2 ; +u32 av1_skip_mode_flag :1 ; +u32 av1_allow_high_precision_mv :1 ; +u32 av1_seg_enable :1 ; +u32 av1_reduced_tx_set_used :1 ; +u32 av1_tx_mode :2 ; +u32 av1_enable_filter_intra :1 ; +u32 av1_delta_q_res :4 ; +u32 av1_coded_lossless :1 ; +u32 av1_allow_intrabc :1 ; + } swreg122_av1; + }; + +union { +struct { +u32 ctbrc_qpdelta_flag_reverse :1 ; +u32 reserved :10 ; +u32 lambda_sse_me_2 :21 ; + } swreg123; + +struct { +u32 reserved :1 ; +u32 av1_btxtypesearch :1 ; +u32 av1_primary_ref_frame :3 ; +u32 av1_sharpness_lvl :3 ; +u32 av1_db_filter_lvl_v :6 ; +u32 av1_db_filter_lvl_u :6 ; +u32 av1_db_filter_lvl1 :6 ; +u32 av1_db_filter_lvl0 :6 ; + } swreg123_av1; + }; + +union { +struct { +u32 reserved :11 ; +u32 lambda_sse_me_3 :21 ; + } swreg124; + +struct { +u32 reserved :15 ; +u32 av1_cdef_bits :2 ; +u32 av1_cdef_uv_strengths :6 ; +u32 av1_cdef_strengths :6 ; +u32 av1_cdef_damping :3 ; + } swreg124_av1; + }; + +union { +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_1 :14 ; +u32 intra_satd_lambda_0 :14 ; + } swreg125; + +struct { +u32 av1_framectx_base :32 ; + } swreg125_av1; + }; + +union { +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_3 :14 ; +u32 intra_satd_lambda_2 :14 ; + } swreg126; + +struct { +u32 av1_framectx_base_msb :32 ; + } swreg126_av1; + }; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_5 :14 ; +u32 intra_satd_lambda_4 :14 ; + } swreg127; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_7 :14 ; +u32 intra_satd_lambda_6 :14 ; + } swreg128; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_9 :14 ; +u32 intra_satd_lambda_8 :14 ; + } swreg129; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_11 :14 ; +u32 intra_satd_lambda_10 :14 ; + } swreg130; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_13 :14 ; +u32 intra_satd_lambda_12 :14 ; + } swreg131; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_15 :14 ; +u32 intra_satd_lambda_14 :14 ; + } swreg132; + +struct { +u32 sse_div_256 :32 ; + } swreg133; + +struct { +u32 nr_mbnum_invert_reg :16 ; +u32 reserved :8 ; +u32 noise_low :6 ; +u32 noise_reduction_enable :2 ; + } swreg134; + +struct { +u32 reserved :5 ; +u32 thresh_sigma_cur :21 ; +u32 sliceqp_prev :6 ; + } swreg135; + +struct { +u32 frame_sigma_calced :16 ; +u32 sigma_cur :16 ; + } swreg136; + +struct { +u32 reserved :11 ; +u32 thresh_sigma_calced :21 ; + } swreg137; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_4 :21 ; + } swreg138; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_5 :21 ; + } swreg139; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_6 :21 ; + } swreg140; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_7 :21 ; + } swreg141; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_8 :21 ; + } swreg142; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_9 :21 ; + } swreg143; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_10 :21 ; + } swreg144; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_11 :21 ; + } swreg145; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_12 :21 ; + } swreg146; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_13 :21 ; + } swreg147; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_14 :21 ; + } swreg148; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_15 :21 ; + } swreg149; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_17 :13 ; +u32 lambda_satd_me_16 :13 ; + } swreg150; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_19 :13 ; +u32 lambda_satd_me_18 :13 ; + } swreg151; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_21 :13 ; +u32 lambda_satd_me_20 :13 ; + } swreg152; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_23 :13 ; +u32 lambda_satd_me_22 :13 ; + } swreg153; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_25 :13 ; +u32 lambda_satd_me_24 :13 ; + } swreg154; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_27 :13 ; +u32 lambda_satd_me_26 :13 ; + } swreg155; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_29 :13 ; +u32 lambda_satd_me_28 :13 ; + } swreg156; + +struct { +u32 reserved :6 ; +u32 lambda_satd_me_31 :13 ; +u32 lambda_satd_me_30 :13 ; + } swreg157; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_16 :21 ; + } swreg158; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_17 :21 ; + } swreg159; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_18 :21 ; + } swreg160; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_19 :21 ; + } swreg161; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_20 :21 ; + } swreg162; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_21 :21 ; + } swreg163; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_22 :21 ; + } swreg164; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_23 :21 ; + } swreg165; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_24 :21 ; + } swreg166; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_25 :21 ; + } swreg167; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_26 :21 ; + } swreg168; + +struct { +u32 reserved :11 ; +u32 lambda_sse_me_27 :21 ; + } swreg169; + +union { +struct { +u32 roi1_delta_qp_rc :5 ; +u32 rc_ctbrc_sliceqpoffset :6 ; +u32 lambda_sse_me_28 :21 ; + } swreg170_qp_delta; + +struct { +u32 roi1_qp_type :1 ; +u32 roi1_qp_value :7 ; +u32 sse_qp_factor :15 ; +u32 reserved :8 ; +u32 lambda_depth :1 ; + } swreg170_qp_absolute; + }; + +union { +struct { +u32 roi2_delta_qp_rc :5 ; +u32 reserved :6 ; +u32 lambda_sse_me_29 :21 ; + } swreg171_qp_delta; + +struct { +u32 roi2_qp_type :1 ; +u32 roi2_qp_value :7 ; +u32 sad_qp_factor :15 ; +u32 reserved :9 ; + } swreg171_qp_absolute; + }; + +struct { +u32 complexity_offset :5 ; +u32 qp_min :6 ; +u32 lambda_sse_me_30 :21 ; + } swreg172; + +struct { +u32 rc_qpdelta_range :4 ; +u32 reserved :1 ; +u32 qp_max :6 ; +u32 lambda_sse_me_31 :21 ; + } swreg173; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_17 :14 ; +u32 intra_satd_lambda_16 :14 ; + } swreg174; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_19 :14 ; +u32 intra_satd_lambda_18 :14 ; + } swreg175; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_21 :14 ; +u32 intra_satd_lambda_20 :14 ; + } swreg176; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_23 :14 ; +u32 intra_satd_lambda_22 :14 ; + } swreg177; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_25 :14 ; +u32 intra_satd_lambda_24 :14 ; + } swreg178; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_27 :14 ; +u32 intra_satd_lambda_26 :14 ; + } swreg179; + +struct { +u32 reserved :4 ; +u32 intra_satd_lambda_29 :14 ; +u32 intra_satd_lambda_28 :14 ; + } swreg180; + +struct { +u32 reserved :2 ; +u32 rc_block_size :2 ; +u32 intra_satd_lambda_31 :14 ; +u32 intra_satd_lambda_30 :14 ; + } swreg181; + +struct { +u32 qp_delta_gain :16 ; +u32 qp_fractional :16 ; + } swreg182; + +struct { +u32 reserved :6 ; +u32 qp_sum :26 ; + } swreg183; + +struct { +u32 reserved :12 ; +u32 qp_num :20 ; + } swreg184; + +struct { +u32 timeout_cycles_msb :9 ; +u32 pic_complexity :23 ; + } swreg185; + +struct { +u32 cu_information_table_base :32 ; + } swreg186; + +struct { +u32 cu_information_table_base_msb :32 ; + } swreg187; + +struct { +u32 cu_information_base :32 ; + } swreg188; + +struct { +u32 cu_information_base_msb :32 ; + } swreg189; + +struct { +u32 reserved :30 ; +u32 num_long_term_pics :2 ; + } swreg190; + +struct { +u32 slice_header_size :16 ; +u32 prefixnal_svc_ext :1 ; +u32 pps_id :6 ; +u32 nuh_temporal_id :3 ; +u32 nal_unit_type :6 ; + } swreg191; + +struct { +u32 framenum :32 ; + } swreg192; + +struct { +u32 entropy_coding_mode :1 ; +u32 transform8x8_enable :1 ; +u32 idr_pic_id :1 ; +u32 nal_ref_idc :1 ; +u32 yfill_msb :2 ; +u32 xfill_msb :2 ; +u32 l0_used_by_next_pic1 :1 ; +u32 l0_delta_framenum1 :11 ; +u32 l0_used_by_next_pic0 :1 ; +u32 l0_delta_framenum0 :11 ; + } swreg193; + +struct { +u32 reserved :2 ; +u32 cur_longtermidx :3 ; +u32 max_longtermidx_plus1 :3 ; +u32 l1_used_by_next_pic1 :1 ; +u32 l1_delta_framenum1 :11 ; +u32 l1_used_by_next_pic0 :1 ; +u32 l1_delta_framenum0 :11 ; + } swreg194; + +struct { +u32 reserved :2 ; +u32 pic_width_msb :2 ; +u32 roi2_bottom_msb :1 ; +u32 roi2_top_msb :1 ; +u32 roi2_right_msb :1 ; +u32 roi2_left_msb :1 ; +u32 roi1_bottom_msb :1 ; +u32 roi1_top_msb :1 ; +u32 roi1_right_msb :1 ; +u32 roi1_left_msb :1 ; +u32 intra_area_bottom_msb :1 ; +u32 intra_area_top_msb :1 ; +u32 intra_area_right_msb :1 ; +u32 intra_area_left_msb :1 ; +u32 cir_interval_msb :4 ; +u32 cir_start_msb :4 ; +u32 slice_size_msb :2 ; +u32 num_slices_ready_msb :2 ; +u32 encoded_ctb_number_msb :4 ; + } swreg195; + +struct { +u32 ctb_row_wr_ptr :10 ; +u32 ctb_row_rd_ptr :10 ; +u32 num_ctb_rows_per_sync :9 ; +u32 input_buf_loopback_en :1 ; +u32 low_latency_en :1 ; +u32 low_latency_hw_sync_en :1 ; + } swreg196; + +union { +struct { +u32 reserved :2 ; +u32 l1_delta_poc0_msb :10 ; +u32 l0_delta_poc1_msb :10 ; +u32 l0_delta_poc0_msb :10 ; + } swreg197; + +struct { +u32 ctb_row_rd_ptr_jpeg_msb :5 ; +u32 ctb_row_wr_ptr_jpeg_msb :5 ; +u32 reserved :22 ; + } swreg197_jpeg; + }; + +struct { +u32 l1_longtermidx1 :3 ; +u32 l1_longtermidx0 :3 ; +u32 l0_longtermidx1 :3 ; +u32 l0_longtermidx0 :3 ; +u32 mark_current_longterm :1 ; +u32 l0_delta_framenum0_msb :9 ; +u32 l1_delta_poc1_msb :10 ; + } swreg198; + +struct { +u32 osd_alphablend_enable :1 ; +u32 hash_offset :2 ; +u32 hash_type :2 ; +u32 l1_delta_framenum1_msb :9 ; +u32 l1_delta_framenum0_msb :9 ; +u32 l0_delta_framenum1_msb :9 ; + } swreg199; + +struct { +u32 hash_val :32 ; + } swreg200; + +struct { +u32 mean_thr3 :8 ; +u32 mean_thr2 :8 ; +u32 mean_thr1 :8 ; +u32 mean_thr0 :8 ; + } swreg201; + +struct { +u32 thr_dc_chroma_8x8 :16 ; +u32 thr_dc_lum_8x8 :16 ; + } swreg202; + +union { +struct { +u32 cr_dc_sum_thr :8 ; +u32 cb_dc_sum_thr :8 ; +u32 reserved :8 ; +u32 lum_dc_sum_thr :8 ; + } swreg203_h264; + +struct { +u32 thr_dc_chroma_16x16 :16 ; +u32 thr_dc_lum_16x16 :16 ; + } swreg203_hevc; + }; + +struct { +u32 thr_dc_chroma_32x32 :16 ; +u32 thr_dc_lum_32x32 :16 ; + } swreg204; + +struct { +u32 thr_ac_num_chroma_8x8 :16 ; +u32 thr_ac_num_lum_8x8 :16 ; + } swreg205; + +struct { +u32 thr_ac_num_chroma_16x16 :16 ; +u32 thr_ac_num_lum_16x16 :16 ; + } swreg206; + +struct { +u32 thr_ac_num_chroma_32x32 :16 ; +u32 thr_ac_num_lum_32x32 :16 ; + } swreg207; + +union { +struct { +u32 reserved0 :3 ; +u32 skip_map_enable :1 ; +u32 ipcm1_left :9 ; +u32 enable_smart :1 ; +u32 foreground_pixel_thx :6 ; +u32 reserved1 :6 ; +u32 smart_qp :6 ; + } swreg208_h264; + +struct { +u32 reserved :3 ; +u32 skip_map_enable :1 ; +u32 ipcm1_left :9 ; +u32 enable_smart :1 ; +u32 foreground_pixel_thx :6 ; +u32 mdqpc :6 ; +u32 mdqpy :6 ; + } swreg208_hevc; + }; + +struct { +u32 reserved :3 ; +u32 ipcm_map_enable :1 ; +u32 pcm_filter_disable :1 ; +u32 ipcm1_bottom :9 ; +u32 ipcm1_top :9 ; +u32 ipcm1_right :9 ; + } swreg209; + +struct { +u32 reserved :3 ; +u32 ipcm2_left :9 ; +u32 input_lu_stride :20 ; + } swreg210; + +struct { +u32 reserved :3 ; +u32 ipcm2_right :9 ; +u32 input_ch_stride :20 ; + } swreg211; + +struct { +u32 reserved :3 ; +u32 ipcm2_top :9 ; +u32 ref_lu_stride :20 ; + } swreg212; + +struct { +u32 reserved :5 ; +u32 ipcm2_bottom :9 ; +u32 ref_ds_lu_stride :18 ; + } swreg213; + +struct { +u32 hwmaxvideowidthjpeg :13 ; +u32 hwmaxvideowidthh264 :13 ; +u32 hwroimapversion :3 ; +u32 hwintratu32support :1 ; +u32 hwabsqpsupport :1 ; +u32 hwljpegsupport :1 ; + } swreg214; + +struct { +u32 totalarlen :32 ; + } swreg215; + +struct { +u32 totalr :32 ; + } swreg216; + +struct { +u32 totalar :32 ; + } swreg217; + +struct { +u32 totalrlast :32 ; + } swreg218; + +struct { +u32 totalawlen :32 ; + } swreg219; + +struct { +u32 totalw :32 ; + } swreg220; + +struct { +u32 totalaw :32 ; + } swreg221; + +struct { +u32 totalwlast :32 ; + } swreg222; + +struct { +u32 totalb :32 ; + } swreg223; + +struct { +u32 cb_const_pixel :10 ; +u32 cr_const_pixel :10 ; +u32 skipframe_en :1 ; +u32 ssim_en :1 ; +u32 reserved :9 ; +u32 chroma_const_en :1 ; + } swreg224; + +struct { +u32 reserved :6 ; +u32 roimap_qpdelta_ver :3 ; +u32 roimap_cuctrl_ver :3 ; +u32 roimap_cuctrl_enable :1 ; +u32 roimap_cuctrl_index_enable :1 ; +u32 loop_filter_across_tiles_enabled_flag :1 ; +u32 tiles_enabled_flag :1 ; +u32 num_tile_rows :8 ; +u32 num_tile_columns :8 ; + } swreg225; + +struct { +u32 hwdynamicmaxtusize :1 ; +u32 hwiframeonly :1 ; +u32 hwstreamsegmentsupport :1 ; +u32 hwstreambufchain :1 ; +u32 hwinloopdsratio :1 ; +u32 hwmultipasssupport :1 ; +u32 hwrdoqsupport :1 ; +u32 bframe_me4n_hor_searchrange :2 ; +u32 hwroi8support :1 ; +u32 hwgmvsupport :1 ; +u32 hwjpeg422support :1 ; +u32 hwctbrcversion :3 ; +u32 me_vert_searchrange_h264 :6 ; +u32 me_vert_searchrange_hevc :6 ; +u32 hwcuinforversion :3 ; +u32 hwp010refsupport :1 ; +u32 hwssimsupport :1 ; + } swreg226; + +struct { +u32 ssim_y_numerator_lsb :32 ; + } swreg227; + +struct { +u32 ssim_y_numerator_msb :32 ; + } swreg228; + +struct { +u32 ssim_u_numerator_lsb :32 ; + } swreg229; + +struct { +u32 ssim_u_numerator_msb :32 ; + } swreg230; + +struct { +u32 ssim_v_numerator_lsb :32 ; + } swreg231; + +struct { +u32 ssim_v_numerator_msb :32 ; + } swreg232; + +struct { +u32 ssim_y_denominator :32 ; + } swreg233; + +struct { +u32 ssim_uv_denominator :32 ; + } swreg234; + +struct { +u32 rps_used_by_cur_1 :1 ; +u32 rps_used_by_cur_0 :1 ; +u32 rps_delta_poc_2 :10 ; +u32 rps_delta_poc_1 :10 ; +u32 rps_delta_poc_0 :10 ; + } swreg235; + +struct { +u32 reserved :12 ; +u32 p010_ref_enable :1 ; +u32 short_term_ref_pic_set_sps_flag :1 ; +u32 rps_pos_pic_num :3 ; +u32 rps_neg_pic_num :3 ; +u32 rps_used_by_cur_3 :1 ; +u32 rps_used_by_cur_2 :1 ; +u32 rps_delta_poc_3 :10 ; + } swreg236; + +struct { +u32 reserved :11 ; +u32 dummyreaden :1 ; +u32 ref_ch_stride :20 ; + } swreg237; + +struct { +u32 dummyreadaddr :32 ; + } swreg238; + +struct { +u32 current_ctb_mad_base :32 ; + } swreg239; + +struct { +u32 current_ctb_mad_base_msb :32 ; + } swreg240; + +struct { +u32 previous_ctb_mad_base :32 ; + } swreg241; + +struct { +u32 previous_ctb_mad_base_msb :32 ; + } swreg242; + +struct { +u32 reserved :11 ; +u32 ctb_rc_model_param0 :21 ; + } swreg243; + +struct { +u32 reserved :2 ; +u32 roi3_qp_type :1 ; +u32 roi3_qp_value :7 ; +u32 ctb_rc_model_param1 :22 ; + } swreg244; + +struct { +u32 rc_qpdelta_range_msb :2 ; +u32 ctb_rc_row_factor :16 ; +u32 ctb_rc_model_param_min :14 ; + } swreg245; + +struct { +u32 reserved :3 ; +u32 ctb_rc_delay :3 ; +u32 axi_write_outstanding_num :8 ; +u32 ctb_rc_qp_step :18 ; + } swreg246; + +struct { +u32 reserved0 :1 ; +u32 ctb_rc_prev_mad_valid :1 ; +u32 reserved1 :4 ; +u32 prev_pic_lum_mad :26 ; + } swreg247; + +struct { +u32 roi4_qp_type :1 ; +u32 roi4_qp_value :7 ; +u32 ctb_qp_sum_for_rc :24 ; + } swreg248; + +union { +struct { +u32 reserved :3 ; +u32 ipcm2_bottom_msb :1 ; +u32 ipcm2_top_msb :1 ; +u32 ipcm2_right_msb :1 ; +u32 ipcm2_left_msb :1 ; +u32 ipcm1_bottom_msb :1 ; +u32 ipcm1_top_msb :1 ; +u32 ipcm1_right_msb :1 ;Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
PATCH 13/14 media: verilisicon: imx8m: Add support for the VC8000E on i.MX8MP
In reply to Paul KocialkowskiAdd the required platform-specific bits for driving the VC8000E found on the NXP i.MX8MP SoC.
--- .../media/platform/verisilicon/hantro_drv.c | 1 + .../media/platform/verisilicon/hantro_hw.h | 1 + .../media/platform/verisilicon/imx8m_vpu_hw.c | 113 ++++++++++++++++++ 3 files changed, 115 insertions(+)
drivers/media/platform/verisilicon/hantro_drv.c +1 -0
@@ -874,6 +874,7 @@ static const struct of_device_id of_hantro_match[] = {#endif #ifdef CONFIG_VIDEO_HANTRO_IMX8M { .compatible = "nxp,imx8mm-vpu-g1", .data = &imx8mm_vpu_g1_variant, }, + { .compatible = "nxp,imx8mp-vpu-vc8000e", .data = &imx8mp_vpu_vc8000e_variant, }, { .compatible = "nxp,imx8mq-vpu", .data = &imx8mq_vpu_variant, }, { .compatible = "nxp,imx8mq-vpu-g1", .data = &imx8mq_vpu_g1_variant }, { .compatible = "nxp,imx8mq-vpu-g2", .data = &imx8mq_vpu_g2_variant },
drivers/media/platform/verisilicon/hantro_hw.h +1 -0
@@ -420,6 +420,7 @@ enum hantro_enc_fmt { ROCKCHIP_VPU_ENC_FMT_UYVY422 = 3, }; +extern const struct hantro_variant imx8mp_vpu_vc8000e_variant;extern const struct hantro_variant imx8mm_vpu_g1_variant;extern const struct hantro_variant imx8mq_vpu_g1_variant;extern const struct hantro_variant imx8mq_vpu_g2_variant;
drivers/media/platform/verisilicon/imx8m_vpu_hw.c +113 -0
134 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 14/14 arm64: dts: imx8mp: add VC8000E encoder node
In reply to Paul KocialkowskiFrom: Marco Felsch <[email protected]>
Add support for the Versilicon VC8000E multi-codec stateless encoder. The IP integrated on the i.MX8MP supports H.264 and H.265 encoding.
--- arch/arm64/boot/dts/freescale/imx8mp.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/freescale/imx8mp.dtsi +11 -0
@@ -2290,6 +2290,17 @@ vpu_g2: video-codec@38310000 { power-domains = <&vpumix_blk_ctrl IMX8MP_VPUBLK_PD_G2>; }; + vpu_vc8000e: video-codec@38320000 { + compatible = "nxp,imx8mp-vpu-vc8000e"; + reg = <0x38320000 0x10000>; + interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk IMX8MP_CLK_VPU_VC8KE_ROOT>; + assigned-clocks = <&clk IMX8MP_CLK_VPU_VC8000E>; + assigned-clock-parents = <&clk IMX8MP_SYS_PLL1_800M>; + assigned-clock-rates = <400000000>; + power-domains = <&vpumix_blk_ctrl IMX8MP_VPUBLK_PD_VC8000E>; + }; + vpumix_blk_ctrl: blk-ctrl@38330000 { compatible = "fsl,imx8mp-vpu-blk-ctrl", "syscon"; reg = <0x38330000 0x100>;
Signature · 1 line
2.53.0
Fabio Estevam
reviewerRe: [PATCH 14/14] arm64: dts: imx8mp: add VC8000E encoder node
Hi Paul,
Thanks for working on this.
Quoted 4 lines · Paul Kocialkowski
From: Marco Felsch <[email protected]>
Add support for the Versilicon VC8000E multi-codec stateless encoder.
Typo: Verisilicon
Quoted 3 lines
The IP integrated on the i.MX8MP supports H.264 and H.265 encoding.
Signed-off-by Marco Felsch <[email protected]>
You need to add your Signed-off-by tag as well.
Quoted 9 lines
--- arch/arm64/boot/dts/freescale/imx8mp.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/arm64/boot/dts/freescale/imx8mp.dtsi +0
-0
arch/arm64/boot/dts/freescale/imx8mp.dtsi vpu_g2: video-codec@38310000 { · line 2294
Quoted 5 lines
arch/arm64/boot/dts/freescale/imx8mp.dtsi +2
-0@@ -2290,6 +2290,17 @@ vpu_g2: video-codec@38310000 { power-domains = <&vpumix_blk_ctrl IMX8MP_VPUBLK_PD_G2>; }; + vpu_vc8000e: video-codec@38320000 { + compatible = "nxp,imx8mp-vpu-vc8000e";
This compatible must be documented in a dt-bindings yaml file.
Nicolas Dufresne
maintainerRe: [PATCH 14/14] arm64: dts: imx8mp: add VC8000E encoder node
In reply to Paul KocialkowskiLe vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 15 lines
From: Marco Felsch <[email protected]>
Add support for the Versilicon VC8000E multi-codec stateless encoder. The IP integrated on the i.MX8MP supports H.264 and H.265 encoding.
Signed-off-by Marco Felsch <[email protected]>--- arch/arm64/boot/dts/freescale/imx8mp.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+)arch/arm64/boot/dts/freescale/imx8mp.dtsi +0
-0
arch/arm64/boot/dts/freescale/imx8mp.dtsi vpu_g2: video-codec@38310000 { · line 2294
Quoted 5 lines
arch/arm64/boot/dts/freescale/imx8mp.dtsi +2
-0@@ -2290,6 +2290,17 @@ vpu_g2: video-codec@38310000 { power-domains = <&vpumix_blk_ctrl IMX8MP_VPUBLK_PD_G2>; }; + vpu_vc8000e: video-codec@38320000 { + compatible = "nxp,imx8mp-vpu-vc8000e";
Not in any binding.
Nicolas
Quoted 12 lines
arch/arm64/boot/dts/freescale/imx8mp.dtsi +9
-0+ reg = <0x38320000 0x10000>; + interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk IMX8MP_CLK_VPU_VC8KE_ROOT>; + assigned-clocks = <&clk IMX8MP_CLK_VPU_VC8000E>; + assigned-clock-parents = <&clk IMX8MP_SYS_PLL1_800M>; + assigned-clock-rates = <400000000>; + power-domains = <&vpumix_blk_ctrl IMX8MP_VPUBLK_PD_VC8000E>; + }; + vpumix_blk_ctrl: blk-ctrl@38330000 { compatible = "fsl,imx8mp-vpu-blk-ctrl", "syscon"; reg = <0x38330000 0x100>;
Nicolas Dufresne
maintainerHi Paul,
Le vendredi 22 mai 2026 à 12:16 +0200, Paul Kocialkowski a écrit :
Quoted 7 lines
This series introduces support for the V4L2 H.264 stateless encode uAPI, core and support in the hantro driver for the Verisilicon VC8000E.
While this is a first version that will likely need some level of rework, it is already usable for most common use-cases and supports constant bitrate rate-control.
Quoted 7 lines
A GStreamer tree can be used to test the series at:
https://github.com/paulkocialkowski/gstreamer/tree/v4l2codecs/h264enc
And an example pipeline would look like:
gst-launch-1.0 videotestsrc pattern=smpte num-buffers=25 ! video/x-raw,width=640,height=480 ! v4l2slh264enc rate-control=cbr bitrate=8000000 qp-min=8 qp-max=42 ! h264parse ! matroskamux ! filesink location=encode.mkvNote that documentation for the new uAPI is intentionally left out of this series since it has not yet received approval.
The unfortunate part is that the spec is important for the actual review and interops analyses. That omission qualify this submission as RFC from my point of view. Any chances you can reply to this cover filling the blank for the few important bit (something similar but non spec style of:
- Querying capabilities
- Initialization
- Encoding
- Dynamic Resolution Changes**
The other sections are just going to be the same imho. The ** for the DRC is because H.264 is not that complicated, its intra only, so you can reset the encoder (use the drain flow). So that's probably something for future us (VP9/AV1). Adding your view on these topics (or just matching what you have implemented) will make review more constructive.
cheers,
Nicolas
Quoted 56 lines
Marco Felsch (2):
media: hantro: usehantro_decoded_bufferonly fordst_vq
arm64: dts: imx8mp: add VC8000E encoder nodePaul Kocialkowski (12):
media: h264: Add a more generic reflist builder init
media: uapi: Add H.264 stateless encode support
media: h264: Add SPS video definitions
media: h264: Add stateless encode core
media: h264: Add stateless encode rbsp
media: h264: Add stateless encode reference management
media: h264: Add stateless encode rate control
media: verisilicon: Report default pixel coding for non-JPEG and fix JPEG case
media: verisilicon: Cancel job with runtime pm put/clk disable on failure
media: verisilicon: Add common encoder parm and frameintervals ioctls
media: verisilicon: Add support for the VC8000E H.264 encoder
media: verilisicon: imx8m: Add support for the VC8000E on i.MX8MParch/arm64/boot/dts/freescale/imx8mp.dtsi | 11 + drivers/media/platform/verisilicon/Kconfig | 1 +
drivers/media/platform/verisilicon/Makefile | 2 + drivers/media/platform/verisilicon/hantro.h | 17 + .../media/platform/verisilicon/hantro_drv.c | 180 +-.../media/platform/verisilicon/hantro_h264.c | 6 +- .../media/platform/verisilicon/hantro_hw.h | 28 + .../media/platform/verisilicon/hantro_v4l2.c | 123 +- .../platform/verisilicon/hantro_vc8000e.c | 68 + .../verisilicon/hantro_vc8000e_h264_enc.c | 883 +++++++ .../verisilicon/hantro_vc8000e_regs.h | 2129 +++++++++++++++++
.../media/platform/verisilicon/imx8m_vpu_hw.c| 113 + drivers/media/v4l2-core/Kconfig | 4 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-ctrls-core.c | 62 + drivers/media/v4l2-core/v4l2-ctrls-defs.c | 4 + drivers/media/v4l2-core/v4l2-h264-enc-rbsp.c | 1173 +++++++++ drivers/media/v4l2-core/v4l2-h264-enc-rc.c | 558 +++++ drivers/media/v4l2-core/v4l2-h264-enc.c | 1322 ++++++++++ drivers/media/v4l2-core/v4l2-h264.c | 69 + include/media/v4l2-ctrls.h | 2 + include/media/v4l2-h264-enc-rbsp.h | 72 + include/media/v4l2-h264-enc-rc.h | 108 + include/media/v4l2-h264-enc.h | 135 ++ include/media/v4l2-h264.h | 146 ++ include/uapi/linux/v4l2-controls.h | 33 + include/uapi/linux/videodev2.h | 1 +27 files changed, 7231 insertions(+), 21 deletions(-)create mode 100644
drivers/media/platform/verisilicon/hantro_vc8000e.ccreate mode 100644drivers/media/platform/verisilicon/hantro_vc8000e_h264_enc.ccreate mode 100644drivers/media/platform/verisilicon/hantro_vc8000e_regs.hcreate mode 100644drivers/media/v4l2-core/v4l2-h264-enc-rbsp.ccreate mode 100644drivers/media/v4l2-core/v4l2-h264-enc-rc.ccreate mode 100644drivers/media/v4l2-core/v4l2-h264-enc.c
create mode 100644include/media/v4l2-h264-enc-rbsp.h
create mode 100644include/media/v4l2-h264-enc-rc.h
create mode 100644include/media/v4l2-h264-enc.h
Hi
Quoted 31 lines · Nicolas Dufresne
Hi Paul,
Quoted 7 lines · Paul Kocialkowski
This series introduces support for the V4L2 H.264 stateless encode uAPI, core and support in the hantro driver for the Verisilicon VC8000E.
While this is a first version that will likely need some level of rework, it is already usable for most common use-cases and supports constant bitrate rate-control.
Quoted 7 lines
A GStreamer tree can be used to test the series at:
https://github.com/paulkocialkowski/gstreamer/tree/v4l2codecs/h264enc
And an example pipeline would look like:
gst-launch-1.0 videotestsrc pattern=smpte num-buffers=25 ! video/x-raw,width=640,height=480 ! v4l2slh264enc rate-control=cbr bitrate=8000000 qp-min=8 qp-max=42 ! h264parse ! matroskamux ! filesink location=encode.mkvNote that documentation for the new uAPI is intentionally left out of this series since it has not yet received approval.
The unfortunate part is that the spec is important for the actual review and interops analyses. That omission qualify this submission as RFC from my point of view. Any chances you can reply to this cover filling the blank for the few important bit (something similar but non spec style of:
- Querying capabilities
- Initialization
- Encoding
- Dynamic Resolution Changes**
Quoted 65 lines
The other sections are just going to be the same imho. The ** for the DRC is because H.264 is not that complicated, its intra only, so you can reset the encoder (use the drain flow). So that's probably something for future us (VP9/AV1). Adding your view on these topics (or just matching what you have implemented) will make review more constructive.
cheers,
NicolasQuoted 56 lines
Marco Felsch (2):
media: hantro: usehantro_decoded_bufferonly fordst_vq
arm64: dts: imx8mp: add VC8000E encoder nodePaul Kocialkowski (12):
media: h264: Add a more generic reflist builder init
media: uapi: Add H.264 stateless encode support
media: h264: Add SPS video definitions
media: h264: Add stateless encode core
media: h264: Add stateless encode rbsp
media: h264: Add stateless encode reference management
media: h264: Add stateless encode rate control
media: verisilicon: Report default pixel coding for non-JPEG and fix JPEG case
media: verisilicon: Cancel job with runtime pm put/clk disable on failure
media: verisilicon: Add common encoder parm and frameintervals ioctls
media: verisilicon: Add support for the VC8000E H.264 encoder
media: verilisicon: imx8m: Add support for the VC8000E on i.MX8MParch/arm64/boot/dts/freescale/imx8mp.dtsi | 11 + drivers/media/platform/verisilicon/Kconfig | 1 + drivers/media/platform/verisilicon/Makefile | 2 + drivers/media/platform/verisilicon/hantro.h | 17 + .../media/platform/verisilicon/hantro_drv.c | 180 +- .../media/platform/verisilicon/hantro_h264.c | 6 +- .../media/platform/verisilicon/hantro_hw.h | 28 + .../media/platform/verisilicon/hantro_v4l2.c | 123 +- .../platform/verisilicon/hantro_vc8000e.c | 68 + .../verisilicon/hantro_vc8000e_h264_enc.c | 883 +++++++ .../verisilicon/hantro_vc8000e_regs.h | 2129 +++++++++++++++++ .../media/platform/verisilicon/imx8m_vpu_hw.c | 113 + drivers/media/v4l2-core/Kconfig | 4 + drivers/media/v4l2-core/Makefile | 2 + drivers/media/v4l2-core/v4l2-ctrls-core.c | 62 + drivers/media/v4l2-core/v4l2-ctrls-defs.c | 4 + drivers/media/v4l2-core/v4l2-h264-enc-rbsp.c | 1173 +++++++++ drivers/media/v4l2-core/v4l2-h264-enc-rc.c | 558 +++++ drivers/media/v4l2-core/v4l2-h264-enc.c | 1322 ++++++++++ drivers/media/v4l2-core/v4l2-h264.c | 69 + include/media/v4l2-ctrls.h | 2 + include/media/v4l2-h264-enc-rbsp.h | 72 + include/media/v4l2-h264-enc-rc.h | 108 + include/media/v4l2-h264-enc.h | 135 ++ include/media/v4l2-h264.h | 146 ++ include/uapi/linux/v4l2-controls.h | 33 + include/uapi/linux/videodev2.h | 1 + 27 files changed, 7231 insertions(+), 21 deletions(-) create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e.c create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e_h264_enc.c create mode 100644 drivers/media/platform/verisilicon/hantro_vc8000e_regs.h create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc-rbsp.c create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc-rc.c create mode 100644 drivers/media/v4l2-core/v4l2-h264-enc.c create mode 100644 include/media/v4l2-h264-enc-rbsp.h create mode 100644 include/media/v4l2-h264-enc-rc.h create mode 100644 include/media/v4l2-h264-enc.h
I tested on px30 and achieved working H.264 encoding with some small changes
Michael
Hi Michael,
Quoted 1 line · Michael Nazzareno Trimarchi
I tested on px30 and achieved working H.264 encoding with some small changes
That is a bit surprising, the Rockchip PX30 should come with a Hantro H1 (using a modified register layout) while this driver is for the Hantro VC8000E, which is a newer generation with very different registers.
Maybe you ended up using CPU-based decoding when testing?
All the best,
Paul
Signature · 6 lines
Paul Kocialkowski, Independent contractor - sys-base - https://www.sys-base.io/ Free software developer - https://www.paulk.fr/ Expert in multimedia, graphics and embedded hardware support with Linux.
Hi Paul
Quoted 11 lines · Paul Kocialkowski
Hi Michael,
Quoted 1 line · Michael Nazzareno Trimarchi
I tested on px30 and achieved working H.264 encoding with some small changes
That is a bit surprising, the Rockchip PX30 should come with a Hantro H1 (using a modified register layout) while this driver is for the Hantro VC8000E, which is a newer generation with very different registers.
Maybe you ended up using CPU-based decoding when testing?
Using
Quoted 5 lines
All the best,
Paul
Quoted 7 lines
--
Paul Kocialkowski,Independent contractor - sys-base - https://www.sys-base.io/
Free software developer - https://www.paulk.fr/Expert in multimedia, graphics and embedded hardware support with Linux.
I have added your patch to gstreamer
v4l2codecs: add the stateless H.264 and VP8 encoder elements
Backport of the encoder work from the branch v4l2codecs/h264enc of
https://github.com/paulkocialkowski/gstreamer (commit f59de5779ef1, based on release 1.26.0) onto the gstreamer1.0-plugins-bad 1.28.5 this build uses.
Generate the right element and encode stream:
gst-launch-1.0 videotestsrc num-buffers=100 ! video/x-raw,width=720,height=576 ! v4l2slh264enc ! h264parse ! matroskamux ! filesink location=/tmp/t2.mkv
And playback over Wayland.
Solve some problem. I have implemented:
const struct hantro_variant px30_vpu_variant = {
.enc_offset = 0x0,
.enc_fmts = rockchip_vpu_enc_fmts, .num_enc_fmts = ARRAY_SIZE(rockchip_vpu_enc_fmts), .dec_offset = 0x400,
.dec_fmts = rockchip_vdpu2_dec_fmts, .num_dec_fmts = ARRAY_SIZE(rockchip_vdpu2_dec_fmts), .codec = HANTRO_JPEG_ENCODER | HANTRO_H264_ENCODER |
HANTRO_MPEG2_DECODER | HANTRO_VP8_DECODER | HANTRO_H264_DECODER,
.codec_ops = px30_vpu_codec_ops,
.irqs = rockchip_vpu2_irqs,
.num_irqs = ARRAY_SIZE(rockchip_vpu2_irqs), .init = rk3036_vpu_hw_init,
.clk_names = rockchip_vpu_clk_names, .num_clocks = ARRAY_SIZE(rockchip_vpu_clk_names)
};
I have advertised the:
{
.fourcc = V4L2_PIX_FMT_H264_SLICE,
.codec_mode = HANTRO_MODE_H264_ENC,
.max_depth = 2,
.header_size = H264_ENC_HEADER_SIZE,
.frmsize = {
.min_width = FMT_MIN_WIDTH,
.max_width = FMT_FHD_WIDTH,
.step_width = MB_DIM,
.min_height = FMT_MIN_HEIGHT,
.max_height = FMT_FHD_HEIGHT,
.step_height = MB_DIM,
},
},Create the rockchip_vpu_hw_h264_enc.c. I need to test this on rk3399
I have a small change only in the common part. Hope that it's a bit clear.
Michael
Hi Michael,
Quoted 8 lines · Michael Nazzareno Trimarchi
I have added your patch to gstreamer
v4l2codecs: add the stateless H.264 and VP8 encoder elements
Backport of the encoder work from the branch v4l2codecs/h264enc of
https://github.com/paulkocialkowski/gstreamer (commitf59de5779ef1, based on release 1.26.0) onto the gstreamer1.0-plugins-bad 1.28.5 this build uses.
Yes this is the right gstreamer branch to use here.
Quoted 45 lines
Generate the right element and encode stream:
gst-launch-1.0 videotestsrc num-buffers=100 ! video/x-raw,width=720,height=576 ! v4l2slh264enc ! h264parse ! matroskamux ! filesink location=/tmp/t2.mkv
And playback over Wayland.
Solve some problem. I have implemented:
const struct
hantro_variantpx30_vpu_variant= {
.enc_offset =0x0,
.enc_fmts =rockchip_vpu_enc_fmts, .num_enc_fmts =ARRAY_SIZE(rockchip_vpu_enc_fmts), .dec_offset =0x400,
.dec_fmts =rockchip_vdpu2_dec_fmts, .num_dec_fmts =ARRAY_SIZE(rockchip_vdpu2_dec_fmts), .codec =HANTRO_JPEG_ENCODER|HANTRO_H264_ENCODER|
HANTRO_MPEG2_DECODER|HANTRO_VP8_DECODER|HANTRO_H264_DECODER,
.codec_ops =px30_vpu_codec_ops,
.irqs =rockchip_vpu2_irqs,
.num_irqs =ARRAY_SIZE(rockchip_vpu2_irqs), .init =rk3036_vpu_hw_init,
.clk_names =rockchip_vpu_clk_names, .num_clocks =ARRAY_SIZE(rockchip_vpu_clk_names)
};I have advertised the:
{ .fourcc = V4L2_PIX_FMT_H264_SLICE, .codec_mode = HANTRO_MODE_H264_ENC, .max_depth = 2, .header_size = H264_ENC_HEADER_SIZE, .frmsize = { .min_width = FMT_MIN_WIDTH, .max_width = FMT_FHD_WIDTH, .step_width = MB_DIM, .min_height = FMT_MIN_HEIGHT, .max_height = FMT_FHD_HEIGHT, .step_height = MB_DIM, }, },
Quoted 1 line
Create the
rockchip_vpu_hw_h264_enc.c. I need to test this on rk3399
Then I guess this is using register configuration from the earlier H.264 encoding work that I've done at Bootlin, adapted for the new stateless encode helpers? That part is probably not quite trivial, which is why I was a bit surprised.
Quoted 1 line
I have a small change only in the common part. Hope that it's a bit clear.
Yes in comparison to the register configuration code, the platform changes are rather small indeed.
All the best,
Paul
Signature · 6 lines
Paul Kocialkowski, Independent contractor - sys-base - https://www.sys-base.io/ Free software developer - https://www.paulk.fr/ Expert in multimedia, graphics and embedded hardware support with Linux.
HI Paul
Quoted 60 lines · Paul Kocialkowski
Hi Michael,
Quoted 8 lines · Michael Nazzareno Trimarchi
I have added your patch to gstreamer
v4l2codecs: add the stateless H.264 and VP8 encoder elements
Backport of the encoder work from the branch v4l2codecs/h264enc of
https://github.com/paulkocialkowski/gstreamer (commitf59de5779ef1, based on release 1.26.0) onto the gstreamer1.0-plugins-bad 1.28.5 this build uses.Yes this is the right gstreamer branch to use here.
Quoted 45 lines
Generate the right element and encode stream:
gst-launch-1.0 videotestsrc num-buffers=100 ! video/x-raw,width=720,height=576 ! v4l2slh264enc ! h264parse ! matroskamux ! filesink location=/tmp/t2.mkv
And playback over Wayland.
Solve some problem. I have implemented:
const struct
hantro_variantpx30_vpu_variant= {
.enc_offset =0x0,
.enc_fmts =rockchip_vpu_enc_fmts, .num_enc_fmts =ARRAY_SIZE(rockchip_vpu_enc_fmts), .dec_offset =0x400,
.dec_fmts =rockchip_vdpu2_dec_fmts, .num_dec_fmts =ARRAY_SIZE(rockchip_vdpu2_dec_fmts), .codec =HANTRO_JPEG_ENCODER|HANTRO_H264_ENCODER|
HANTRO_MPEG2_DECODER|HANTRO_VP8_DECODER|HANTRO_H264_DECODER,
.codec_ops =px30_vpu_codec_ops,
.irqs =rockchip_vpu2_irqs,
.num_irqs =ARRAY_SIZE(rockchip_vpu2_irqs), .init =rk3036_vpu_hw_init,
.clk_names =rockchip_vpu_clk_names, .num_clocks =ARRAY_SIZE(rockchip_vpu_clk_names)
};I have advertised the:
{ .fourcc = V4L2_PIX_FMT_H264_SLICE, .codec_mode = HANTRO_MODE_H264_ENC, .max_depth = 2, .header_size = H264_ENC_HEADER_SIZE, .frmsize = { .min_width = FMT_MIN_WIDTH, .max_width = FMT_FHD_WIDTH, .step_width = MB_DIM, .min_height = FMT_MIN_HEIGHT, .max_height = FMT_FHD_HEIGHT, .step_height = MB_DIM, }, },
Quoted 4 lines
Quoted 1 line
Create the
rockchip_vpu_hw_h264_enc.c. I need to test this on rk3399Then I guess this is using register configuration from the earlier H.264 encoding work that I've done at Bootlin, adapted for the new stateless
I need to check mpp code too
Quoted 3 lines
encode helpers? That part is probably not quite trivial, which is why I was a bit surprised.
I would like to clean up the patches before sending, and check all the code to not make trivial mistakes. I'm not persistent, so if we aren't, one of my colleagues will take over.
Quoted 5 lines
Quoted 1 line
I have a small change only in the common part. Hope that it's a bit clear.
Yes in comparison to the register configuration code, the platform changes are rather small indeed.
I wrote this email to state that this change would be impossible without your work.
I'm currently working on other things, but I had some spare time. Now apart from that,
I would like to ask about the status of the entire proposal and uapi change.
Michael
Quoted 11 lines
All the best,
Paul
--
Paul Kocialkowski,Independent contractor - sys-base - https://www.sys-base.io/
Free software developer - https://www.paulk.fr/Expert in multimedia, graphics and embedded hardware support with Linux.
Nicolas Dufresne
maintainerHi,
Le jeudi 24 septembre 2026 à 21:38 +0200, Michael Nazzareno Trimarchi a écrit :
Quoted 1 line
I would like to ask about the status of the entire proposal and uapi change.
From my perspective, the main part missing the the V4L2 m2m stateless encoder spec. We made one for stateful decoder/encoder and stateless decoder, and that made a huge different in interoperability.
A second implementation, not just a variant of the same brand would also be nice.
Nicolas
Hi,
Quoted 2 lines · Nicolas Dufresne
Le jeudi 24 septembre 2026 à 21:38 +0200, Michael Nazzareno Trimarchi a écrit :
Quoted 1 line
I would like to ask about the status of the entire proposal and uapi change.
By the way (in case you missed it Michael), this topic was discussed at the 2026 Linux Media Summit and you can find my slides at:
https://www.paulk.fr/talks#2026-linux-media-summit-v4l2-stateless-video-encoding-uapi-progress-update
The discussion helped clarify a number of points and expectations for the next iteration of the proposal, which I am currently working on. It involves some rework of core support and helpers but the technical side remains rather similar.
Quoted 3 lines
From my perspective, the main part missing the the V4L2 m2m stateless encoder spec. We made one for stateful decoder/encoder and stateless decoder, and that made a huge different in interoperability.
Yes adding the spec is part of the ongoing work for v2. It will be a mix of what is already done for stateful encoders with more flexibility and specific aspects for the stateless aspect.
By the way if you have ideas about specific problems with the stateful API that should not be reproduced in the stateless one, feel free to mention them.
Quoted 2 lines
A second implementation, not just a variant of the same brand would also be nice.
I still have it in mind to add support for the Allwinner encoder based on my earlier stateful-ish attempt. Hopefully that work can be funded.
All the best,
Paul
Signature · 6 lines
Paul Kocialkowski, Independent contractor - sys-base - https://www.sys-base.io/ Free software developer - https://www.paulk.fr/ Expert in multimedia, graphics and embedded hardware support with Linux.
Nicolas Dufresne
maintainerHi Paul
[...]
Quoted 3 lines
By the way if you have ideas about specific problems with the stateful API that should not be reproduced in the stateless one, feel free to mention them.
Few things:
- Drain flow should be as simple as for stateless decoder, there is no reordering, and so no holding on frames.
- Capability query should mimic the stateless decoders (but up-side down). Basically, we don't add a pseudo unset state, that was bogus. V4L2_FMTDESC_FLAG_ENUM_ALL could be made mandatory, this is only partially implemented decoders today :-S
- Capture/Output S_PARM, maybe review/revisit, but likely still needed, otherwise the rate controller can't know the rate.
- S_SELECTION, maybe make it mandatory for codec with a conformance window ?
- Of course, encoding process requires a request
- Anything about keyframe insertion can be dropped, since frame type is explicit and per codec.
One ambiguity we have in all decoders at least is weather or not the enumerate sized are coded or display resolution. I believe technically, all stateless decoder exposes constraints in coded resolutions, and display resolutions are not easily enumerated. Not a blocker, just a remark.
Hope this is helpful,
Nicolas
Quoted 10 lines
Quoted 3 lines
A second implementation, not just a variant of the same brand would also be nice.
I still have it in mind to add support for the Allwinner encoder based on my earlier stateful-ish attempt. Hopefully that work can be funded.
All the best,
Paul
Quoted 25 lines · Nicolas Dufresne
Hi Paul
[...]
Quoted 3 lines
By the way if you have ideas about specific problems with the stateful API that should not be reproduced in the stateless one, feel free to mention them.
Few things:
- Drain flow should be as simple as for stateless decoder, there is no reordering, and so no holding on frames.
- Capability query should mimic the stateless decoders (but up-side down). Basically, we don't add a pseudo unset state, that was bogus.
V4L2_FMTDESC_FLAG_ENUM_ALLcould be made mandatory, this is only partially implemented decoders today :-S- Capture/Output
S_PARM, maybe review/revisit, but likely still needed, otherwise the rate controller can't know the rate.-
S_SELECTION, maybe make it mandatory for codec with a conformance window ?- Of course, encoding process requires a request
Quoted 7 lines
- Anything about keyframe insertion can be dropped, since frame type is explicit and per codec.
One ambiguity we have in all decoders at least is weather or not the enumerate sized are coded or display resolution. I believe technically, all stateless decoder exposes constraints in coded resolutions, and display resolutions are not easily enumerated. Not a blocker, just a remark.
IIRC from working on bringing the Chromium V4L2 code up-to-date, userspace programs coded resolutions as the frame dimensions, and uses the selection API for the display resolutions. And yes, the decoder exposes constraints in coded resolutions, like having the resolution steps match the macroblock sizes.
ChenYu
Quoted 13 lines
Hope this is helpful,
NicolasQuoted 10 lines
Quoted 3 lines
A second implementation, not just a variant of the same brand would also be nice.
I still have it in mind to add support for the Allwinner encoder based on my earlier stateful-ish attempt. Hopefully that work can be funded.
All the best,
Paul