Skip to contentSkip to conversation

Add HANTRO G2/HEVC decoder support for IMX8MQ

PATCH Superseded Benjamin Gaignard 6 participants 27 messages Feb 22, 2021 – Feb 26, 2021

Subsystems (8)

v3 of 13 Superseded Latest is v13 →

lore
Share & tools
lore

Benjamin Gaignard

author maintainer
#0 lore raw

v3 cover Add HANTRO G2/HEVC decoder support for IMX8MQ

The IMX8MQ got two VPUs but until now only G1 has been enabled. This series aim to add the second VPU (aka G2) and provide basic HEVC decoding support.

To be able to decode HEVC it is needed to add/update some of the structures in the uapi. In addition of them one HANTRO dedicated control is required to inform the driver of the numbre of bits to skip at the beginning of the slice header.
The hardware require to allocate few auxiliary buffers to store the references frame or tile size data.

The driver has been tested with fluster test suite stream.
For example with this command: ./fluster.py run -ts JCT-VC-HEVC_V1 -d GStreamer-H.265-V4L2SL-Gst1.0

This series depends of the reset rework posted here: https://www.spinics.net/lists/arm-kernel/msg875766.html

Finally the both VPUs will have a node the device-tree and be independent from v4l2 point of view.

A branch with all the dev is available here:
https://gitlab.collabora.com/benjamin.gaignard/for-upstream/-/commits/upstream_g2_v2

version 3:
- Fix typo in Hantro v4l2 dedicated control
- Add documentation for the new structures and fields
- Rebased on top of media_tree for-linus-5.12-rc1 tag

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic in tile_buffer_reallocate, rework some goto and return cases.
- be more verbose about why I change the bindings
- remove all sign-off expect mime since it is confusing
- remove useless clocks in VPUs nodes

Benjamin

Benjamin Gaignard (9):
media: hevc: Modify structures to follow H265 ITU spec
media: hantro: Define HEVC codec profiles and supported features
media: hantro: Add a field to distinguish the hardware versions
media: uapi: Add a control for HANTRO driver
media: hantro: Introduce G2/HEVC decoder
media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
media: hantro: IMX8M: add variant for G2/HEVC codec
dt-bindings: media: nxp,imx8mq-vpu: Update bindings
arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml        |  54 +-
 .../media/v4l/ext-ctrls-codec.rst             | 126 +++-
 .../media/v4l/vidioc-queryctrl.rst            |   6 +
 arch/arm64/boot/dts/freescale/imx8mq.dtsi     |  41 +-
 drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +-
 drivers/staging/media/hantro/Makefile         |   2 +
 drivers/staging/media/hantro/hantro.h         |  34 +-
 drivers/staging/media/hantro/hantro_drv.c     | 103 +++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++++++++++++++++++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++++++
 drivers/staging/media/hantro/hantro_hevc.c    | 321 ++++++++++
 drivers/staging/media/hantro/hantro_hw.h      |  48 ++
 .../staging/media/hantro/hantro_postproc.c    |  17 +
 drivers/staging/media/hantro/hantro_v4l2.c    |   1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c   |  95 ++-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
 include/media/hevc-ctrls.h                    |  45 +-
 include/uapi/linux/hantro-v4l2-controls.h     |  20 +
 include/uapi/linux/v4l2-controls.h            |   5 +
 22 files changed, 1674 insertions(+), 70 deletions(-)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c
 create mode 100644 include/uapi/linux/hantro-v4l2-controls.h
Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author maintainer
#1 lore raw

PATCH v3 1/9 media: hevc: Modify structures to follow H265 ITU spec

The H.265 ITU specification (section 7.4) define the general slice segment header semantics.
Modified/added fields are:
- video_parameter_set_id: (7.4.3.1) identifies the VPS for reference by other syntax elements.
- seq_parameter_set_id: (7.4.3.2.1) specifies the value of the vps_video_parameter_set_id of the active VPS.
- chroma_format_idc: (7.4.3.2.1) specifies the chroma sampling relative to the luma sampling
- pic_parameter_set_id: (7.4.3.3.1) identifies the PPS for reference by other syntax elements
- num_ref_idx_l0_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l0_active_minus1
- num_ref_idx_l1_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l1_active_minus1
- slice_segment_addr: (7.4.7.1) specifies the address of the first coding tree block in the slice segment
- num_entry_point_offsets: (7.4.7.1) specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Add HEVC decode params contains the information used in section "8.3 Slice decoding process" of the specification to let the hardware perform decoding of a slices.

Adapt Cedrus driver according to these changes.

---
version 3:
- Add documentation about the new structuers and fields.

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields

 .../media/v4l/ext-ctrls-codec.rst             | 126 +++++++++++++++---
 .../media/v4l/vidioc-queryctrl.rst            |   6 +
 drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +++-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
 include/media/hevc-ctrls.h                    |  45 +++++--
 8 files changed, 186 insertions(+), 32 deletions(-)
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +111 -15
index 00944e97d638..5e6d77e858c0 100644
@@ -3109,6 +3109,15 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2
 
+    * - __u8
+      - ``video_parameter_set_id``
+      - Identifies the VPS for reference by other syntax elements
+    * - __u8
+      - ``seq_parameter_set_id̀``
+      - Specifies the value of the vps_video_parameter_set_id of the active VPS
+    * - __u8
+      - ``chroma_format_idc``
+      - Specifies the chroma sampling relative to the luma sampling
     * - __u16
       - ``pic_width_in_luma_samples``
       -
@@ -3172,6 +3181,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``chroma_format_idc``
       -
+    * - __u8
+      - ``num_slices``
+      -
     * - __u64
       - ``flags``
       - See :ref:`Sequence Parameter Set Flags <hevc_sps_flags>`
@@ -3231,9 +3243,18 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2
 
+    * - __u8
+      - ``pic_parameter_set_id``
+      - Identifies the PPS for reference by other syntax elements
     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l0_active_minus1
+    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -
@@ -3342,6 +3363,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
       - 0x00040000
       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+      - 0x00080000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      -
 
 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
     Specifies various slice-specific parameters, especially from the NAL unit
@@ -3366,6 +3393,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u32
       - ``data_bit_offset``
       - Offset (in bits) to the video data in the current slice data.
+    * - __u32
+      - ``slice_segment_addr``
+      - Specifies the address of the first coding tree block in the slice segment
+    * - __u32
+      - ``num_entry_point_offsets``
+      - Specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header
     * - __u8
       - ``nal_unit_type``
       -
@@ -3422,28 +3455,20 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.
     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
     * - __u8
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB.
+    * - __u16
+      - ``short_term_ref_pic_set_size``
+      -
+    * - __u16
+      - ``long_term_ref_pic_set_size``
+      -
     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that come before
-        the current frame.
-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that come after
-        the current frame.
-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.
-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
     * - struct :c:type:`v4l2_hevc_dpb_entry`
       - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
@@ -3646,3 +3671,74 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     so this has to come from client.
     This is applicable to H264 and valid Range is from 0 to 63.
     Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references picture order
+    count (POC) for all the lists (short, long, before, current, after) and the
+    number of entries for each of them.
+    These parameters are defined according to :ref:`hevc`.
+    They are described in section 8.3 "Slice decoding process" of the
+    specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      -
+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:`v4l2_hevc_dpb_entry`
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference frames.
+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that come before
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that come after
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set.
+    * - __u8
+      - ``rps_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u8
+      - ``rps_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u8
+      - ``rps_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u64
+      - ``flags``
+      - See :ref:`Decode Parameters Flags <hevc_decode_params_flags>`
+
+.. _hevc_decode_params_flags:
+
+``Decode Parameters Flags``
+
+.. cssclass:: longtable
+
+.. flat-table::
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - ``V4L2_HEVC_DECODE_PARAM_FLAG_IRAP_PIC``
+      - 0x00000001
+      -
+    * - ``V4L2_HEVC_DECODE_PARAM_FLAG_IDR_PIC``
+      - 0x00000002
+      -
+    * - ``V4L2_HEVC_DECODE_PARAM_FLAG_NO_OUTPUT_OF_PRIOR``
+      - 0x00000004
+      -
Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst +6 -0
index 82f61f1e2fb8..d84ae255bc79 100644
@@ -486,6 +486,12 @@ See also the examples in :ref:`control`.
       - n/a
       - A struct :c:type:`v4l2_ctrl_hevc_slice_params`, containing HEVC
 	slice parameters for stateless video decoders.
+    * - ``V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS``
+      - n/a
+      - n/a
+      - n/a
+      - A struct :c:type:`v4l2_ctrl_hevc_decode_params`, containing HEVC
+	decoding parameters for stateless video decoders.
 
 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
 
drivers/media/v4l2-core/v4l2-ctrls.c +19 -7
index 016cf6204cbb..4060b5bcc3c0 100644
@@ -1028,6 +1028,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_MPEG_VIDEO_HEVC_SPS:			return "HEVC Sequence Parameter Set";
 	case V4L2_CID_MPEG_VIDEO_HEVC_PPS:			return "HEVC Picture Parameter Set";
 	case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:		return "HEVC Slice Parameters";
+	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS:		return "HEVC Decode Parameters";
 	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE:		return "HEVC Decode Mode";
 	case V4L2_CID_MPEG_VIDEO_HEVC_START_CODE:		return "HEVC Start Code";
 
@@ -1482,6 +1483,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS:
 		*type = V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS;
 		break;
+	case V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS:
+		*type = V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS;
+		break;
 	case V4L2_CID_UNIT_CELL_SIZE:
 		*type = V4L2_CTRL_TYPE_AREA;
 		*flags |= V4L2_CTRL_FLAG_READ_ONLY;
@@ -1833,6 +1837,7 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 	struct v4l2_ctrl_hevc_sps *p_hevc_sps;
 	struct v4l2_ctrl_hevc_pps *p_hevc_pps;
 	struct v4l2_ctrl_hevc_slice_params *p_hevc_slice_params;
+	struct v4l2_ctrl_hevc_decode_params *p_hevc_decode_params;
 	struct v4l2_area *area;
 	void *p = ptr.p + idx * ctrl->elem_size;
 	unsigned int i;
@@ -2108,23 +2113,27 @@ static int std_validate_compound(const struct v4l2_ctrl *ctrl, u32 idx,
 		zero_padding(*p_hevc_pps);
 		break;
 
-	case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
-		p_hevc_slice_params = p;
+	case V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS:
+		p_hevc_decode_params = p;
 
-		if (p_hevc_slice_params->num_active_dpb_entries >
+		if (p_hevc_decode_params->num_active_dpb_entries >
 		    V4L2_HEVC_DPB_ENTRIES_NUM_MAX)
 			return -EINVAL;
 
-		zero_padding(p_hevc_slice_params->pred_weight_table);
-
-		for (i = 0; i < p_hevc_slice_params->num_active_dpb_entries;
+		for (i = 0; i < p_hevc_decode_params->num_active_dpb_entries;
 		     i++) {
 			struct v4l2_hevc_dpb_entry *dpb_entry =
-				&p_hevc_slice_params->dpb[i];
+				&p_hevc_decode_params->dpb[i];
 
 			zero_padding(*dpb_entry);
 		}
 
+		break;
+
+	case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
+		p_hevc_slice_params = p;
+
+		zero_padding(p_hevc_slice_params->pred_weight_table);
 		zero_padding(*p_hevc_slice_params);
 		break;
 
@@ -2821,6 +2830,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_HEVC_SLICE_PARAMS:
 		elem_size = sizeof(struct v4l2_ctrl_hevc_slice_params);
 		break;
+	case V4L2_CTRL_TYPE_HEVC_DECODE_PARAMS:
+		elem_size = sizeof(struct v4l2_ctrl_hevc_decode_params);
+		break;
 	case V4L2_CTRL_TYPE_AREA:
 		elem_size = sizeof(struct v4l2_area);
 		break;
drivers/staging/media/sunxi/cedrus/cedrus.c +6 -0
index 7bd9291c8d5f..4cd3cab1a257 100644
@@ -151,6 +151,12 @@ static const struct cedrus_control cedrus_controls[] = {
 		},
 		.codec		= CEDRUS_CODEC_VP8,
 	},
+	{
+		.cfg = {
+			.id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+		},
+		.codec		= CEDRUS_CODEC_H265,
+	},
 };
 
 #define CEDRUS_CONTROLS_COUNT	ARRAY_SIZE(cedrus_controls)
drivers/staging/media/sunxi/cedrus/cedrus.h +1 -0
index 251a6a660351..2ca33ac38b9a 100644
@@ -76,6 +76,7 @@ struct cedrus_h265_run {
 	const struct v4l2_ctrl_hevc_sps			*sps;
 	const struct v4l2_ctrl_hevc_pps			*pps;
 	const struct v4l2_ctrl_hevc_slice_params	*slice_params;
+	const struct v4l2_ctrl_hevc_decode_params	*decode_params;
 };
 
 struct cedrus_vp8_run {
drivers/staging/media/sunxi/cedrus/cedrus_dec.c +2 -0
index a9090daf626a..cd821f417a14 100644
@@ -68,6 +68,8 @@ void cedrus_device_run(void *priv)
 			V4L2_CID_MPEG_VIDEO_HEVC_PPS);
 		run.h265.slice_params = cedrus_find_control_data(ctx,
 			V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS);
+		run.h265.decode_params = cedrus_find_control_data(ctx,
+			V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS);
 		break;
 
 	case V4L2_PIX_FMT_VP8_FRAME:
drivers/staging/media/sunxi/cedrus/cedrus_h265.c +4 -2
index ce497d0197df..dce5db6be13a 100644
@@ -245,6 +245,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 	const struct v4l2_ctrl_hevc_sps *sps;
 	const struct v4l2_ctrl_hevc_pps *pps;
 	const struct v4l2_ctrl_hevc_slice_params *slice_params;
+	const struct v4l2_ctrl_hevc_decode_params *decode_params;
 	const struct v4l2_hevc_pred_weight_table *pred_weight_table;
 	dma_addr_t src_buf_addr;
 	dma_addr_t src_buf_end_addr;
@@ -256,6 +257,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 	sps = run->h265.sps;
 	pps = run->h265.pps;
 	slice_params = run->h265.slice_params;
+	decode_params = run->h265.decode_params;
 	pred_weight_table = &slice_params->pred_weight_table;
 
 	/* MV column buffer size and allocation. */
@@ -487,7 +489,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 
 	reg = VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_TC_OFFSET_DIV2(slice_params->slice_tc_offset_div2) |
 	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_BETA_OFFSET_DIV2(slice_params->slice_beta_offset_div2) |
-	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_POC_BIGEST_IN_RPS_ST(slice_params->num_rps_poc_st_curr_after == 0) |
+	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_POC_BIGEST_IN_RPS_ST(decode_params->num_rps_poc_st_curr_after == 0) |
 	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_CR_QP_OFFSET(slice_params->slice_cr_qp_offset) |
 	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_CB_QP_OFFSET(slice_params->slice_cb_qp_offset) |
 	      VE_DEC_H265_DEC_SLICE_HDR_INFO1_SLICE_QP_DELTA(slice_params->slice_qp_delta);
@@ -528,7 +530,7 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 
 	/* Write decoded picture buffer in pic list. */
 	cedrus_h265_frame_info_write_dpb(ctx, slice_params->dpb,
-					 slice_params->num_active_dpb_entries);
+					 decode_params->num_active_dpb_entries);
 
 	/* Output frame. */
 
include/media/hevc-ctrls.h +37 -8

106 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#2 lore raw

Re: [PATCH v3 1/9] media: hevc: Modify structures to follow H265 ITU spec

Hi Benjamin,

Thanks for the good work.

Quoted 55 lines · Benjamin Gaignard

The H.265 ITU specification (section 7.4) define the general slice segment header semantics.
Modified/added fields are:
- video_parameter_set_id: (7.4.3.1) identifies the VPS for reference by other syntax elements.
- seq_parameter_set_id: (7.4.3.2.1) specifies the value of the vps_video_parameter_set_id of the active VPS.
- chroma_format_idc: (7.4.3.2.1) specifies the chroma sampling relative to the luma sampling
- pic_parameter_set_id: (7.4.3.3.1) identifies the PPS for reference by other syntax elements
- num_ref_idx_l0_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l0_active_minus1
- num_ref_idx_l1_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l1_active_minus1
- slice_segment_addr: (7.4.7.1) specifies the address of the first coding tree block in the slice segment
- num_entry_point_offsets: (7.4.7.1) specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Add HEVC decode params contains the information used in section "8.3 Slice decoding process" of the specification to let the hardware perform decoding of a slices.

Adapt Cedrus driver according to these changes.

---
version 3:
- Add documentation about the new structuers and fields.

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields

 .../media/v4l/ext-ctrls-codec.rst             | 126 +++++++++++++++--- .../media/v4l/vidioc-queryctrl.rst            |   6 + drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +++-

 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
 include/media/hevc-ctrls.h                    |  45 +++++--
 8 files changed, 186 insertions(+), 32 deletions(-)
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
index 00944e97d638..5e6d77e858c0 100644
@@ -3109,6 +3109,15 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -

     :stub-columns: 0
     :widths:       1 1 2

+    * - __u8

Quoted 8 lines

+      - ``video_parameter_set_id``
+      - Identifies the VPS for reference by other syntax elements +    * - __u8
+      - ``seq_parameter_set_id̀``
+      - Specifies the value of the vps_video_parameter_set_id of the active VPS +    * - __u8
+      - ``chroma_format_idc``
+      - Specifies the chroma sampling relative to the luma sampling

None of these fields seem needed for the Hantro G2 driver, so I suggest you drop them for now.

Quoted 10 lines

     * - __u16
       - ``pic_width_in_luma_samples``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3172,6 +3181,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u8

       - ``chroma_format_idc``
       -
+    * - __u8
+      - ``num_slices``
+

Not used, but also doesn't seem part of the SPS syntax. If we have to pass the number of slices, we'll need another mechanism.

Quoted 11 lines

      -
     * - __u64
       - ``flags``
       - See :ref:Sequence Parameter Set Flags <hevc_sps_flags>

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3231,9 +3243,18 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -

     :stub-columns: 0
     :widths:       1 1 2

+    * - __u8
+      - ``pic_parameter_set_id``
+      - Identifies the PPS for reference by other syntax elements

Not used.

Quoted 15 lines

     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l0_active_minus1 +    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3342,6 +3363,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``

       - 0x00040000

Quoted 8 lines

       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT`` +      - 0x00080000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      -

I suggest to do all the PPS control changes in a separate patch, feels easier to review and cleaner as you can explain the changes with more detail in the commit description.

Looking at the PPS syntax for tiles, I'm wondering if these deserve their own control, which would be used if tiles are enabled, i.e. V4L2_HEVC_PPS_FLAG_TILES_ENABLED is set.

        __u8    num_tile_columns_minus1;                                         
        __u8    num_tile_rows_minus1;                                            
        __u8    column_width_minus1[20];                                         
        __u8    row_height_minus1[22];    

Not something we necessarily have to tackle now.

Quoted 9 lines

 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
     Specifies various slice-specific parameters, especially from the NAL unit

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3366,6 +3393,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u32

       - ``data_bit_offset``
       - Offset (in bits) to the video data in the current slice data. +    * - __u32
+      - ``slice_segment_addr``
+      - Specifies the address of the first coding tree block in the slice segment

Not used.

Quoted 3 lines

+    * - __u32
+      - ``num_entry_point_offsets``
+      - Specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Not used.

Quoted 10 lines

     * - __u8
       - ``nal_unit_type``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3422,28 +3455,20 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u8

       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.

Need to explain in the commit description why this field is moved.

Quoted 9 lines

     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
     * - __u8
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB. +    * - __u16
+      - ``short_term_ref_pic_set_size``
+

Not used.

Quoted 4 lines

      -
+    * - __u16
+      - ``long_term_ref_pic_set_size``
+      -

Not used.

Quoted 4 lines

     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that come before -        the current frame.

If this matches NumPocStCurrBefore from section 8.3.2 "Decoding process for reference picture set" then I would document that. And perhaps rename it to num_poc_st_curr_before.

Quoted 4 lines

-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that come after -        the current frame.

Ditto.

Quoted 3 lines

-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.

Ditto.

Also, I'd like the changes that move fields from V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS to the new V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS control, to be in their patch.

That will allow us to put in the commit description a proper explanation of why are fields being moved. Nothing fancy, simply explaining that these variables come from section 8.3.2 "Decoding process for reference picture set", which describes a process invoked once per picture, so they are not per-slice.

Quoted 21 lines

-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
     * - struct :c:type:v4l2_hevc_dpb_entry
       - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3646,3 +3671,74 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -

     so this has to come from client.
     This is applicable to H264 and valid Range is from 0 to 63. Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +11 -0
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references picture order
+    count (POC) for all the lists (short, long, before, current, after) and the
+    number of entries for each of them.
+    These parameters are defined according to :ref:`hevc`.
+    They are described in section 8.3 "Slice decoding process" of the
+    specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3694

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10 -0
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      -

Can be documented as:

"""
PicOrderCntVal as described in section 8.3.1 "Decoding process for picture order count" of the specification.
"""

Note that snake case is used to match the kernel style, but other than that we try to keep the HEVC spec variable names.

Quoted 6 lines

+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:v4l2_hevc_dpb_entry
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference frames.

The DPB is here, but it seems it's also in the slice control?

Quoted 12 lines

+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that come before +        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that come after +        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set.
+    * - __u8

Quoted 8 lines

+      - ``rps_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -
+    * - __u8
+      - ``rps_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -
+    * - __u8
+      - ``rps_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -

Could you document these as well?

Thanks a lot,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#3 lore raw

Re: Re: [PATCH v3 1/9] media: hevc: Modify structures to follow H265 ITU spec

Hi Ezequiel,

Dne četrtek, 25. februar 2021 ob 14:09:52 CET je Ezequiel Garcia napisal(a):

Quoted 51 lines

Hi Benjamin,

Thanks for the good work.

Quoted 46 lines · Benjamin Gaignard

The H.265 ITU specification (section 7.4) define the general slice segment header semantics.
Modified/added fields are:
- video_parameter_set_id: (7.4.3.1) identifies the VPS for reference by other syntax elements.
- seq_parameter_set_id: (7.4.3.2.1) specifies the value of the vps_video_parameter_set_id of the active VPS.
- chroma_format_idc: (7.4.3.2.1) specifies the chroma sampling relative to the luma sampling
- pic_parameter_set_id: (7.4.3.3.1) identifies the PPS for reference by other syntax elements
- num_ref_idx_l0_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l0_active_minus1
- num_ref_idx_l1_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l1_active_minus1
- slice_segment_addr: (7.4.7.1) specifies the address of the first coding tree block in the slice segment
- num_entry_point_offsets: (7.4.7.1) specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Add HEVC decode params contains the information used in section "8.3 Slice decoding process" of the specification to let the hardware perform decoding of a slices.

Adapt Cedrus driver according to these changes.

---
version 3:
- Add documentation about the new structuers and fields.

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields

 .../media/v4l/ext-ctrls-codec.rst             | 126 +++++++++++++++---
 .../media/v4l/vidioc-queryctrl.rst            |   6 +
 drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +++-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
 include/media/hevc-ctrls.h                    |  45 +++++--
 8 files changed, 186 insertions(+), 32 deletions(-)
Quoted 1 line

Review

Quoted 1 line
(quoted diff) renamed from Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst

Quoted 7 lines
Quoted 7 lines

index 00944e97d638..5e6d77e858c0 100644

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3109,6 +3109,15 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2
 
Quoted 6 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 6 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
+    * - __u8
+      - ``video_parameter_set_id``
+      - Identifies the VPS for reference by other syntax elements
+    * - __u8
+      - ``seq_parameter_set_id̀``
+      - Specifies the value of the vps_video_parameter_set_id of the 

active VPS

Quoted 67 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3120

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u8
+      - ``chroma_format_idc``
+      - Specifies the chroma sampling relative to the luma sampling

None of these fields seem needed for the Hantro G2 driver, so I suggest you drop them for now.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3186

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
     * - __u16
       - ``pic_width_in_luma_samples``
       -
@@ -3172,6 +3181,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``chroma_format_idc``
       -
+    * - __u8
+      - ``num_slices``
+

Not used, but also doesn't seem part of the SPS syntax. If we have to pass the number of slices, we'll need another mechanism.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3248

Quoted 11 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
      -
     * - __u64
       - ``flags``

- See :ref:Sequence Parameter Set Flags <hevc_sps_flags>

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3231,9 +3243,18 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2
 
+    * - __u8
+      - ``pic_parameter_set_id``
+      - Identifies the PPS for reference by other syntax elements

Not used.

Quoted 13 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l0_active_minus1
+    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3372

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
@@ -3342,6 +3363,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
       - 0x00040000
       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+      - 0x00080000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      -
 

I suggest to do all the PPS control changes in a separate patch, feels easier to review and cleaner as you can explain the changes with more detail in the commit description.

Looking at the PPS syntax for tiles, I'm wondering if these deserve their own control, which would be used if tiles are enabled, i.e. V4L2_HEVC_PPS_FLAG_TILES_ENABLED is set.

Quoted 9 lines
        __u8    num_tile_columns_minus1;                                         
        __u8    num_tile_rows_minus1;                                            
        __u8    column_width_minus1[20];                                         
        __u8    row_height_minus1[22];    

Not something we necessarily have to tackle now.

Quoted 2 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
     Specifies various slice-specific parameters, especially from the NAL 

unit

Quoted 7 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3398

Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3366,6 +3393,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u32
       - ``data_bit_offset``
       - Offset (in bits) to the video data in the current slice data.
+    * - __u32
+      - ``slice_segment_addr``
+      - Specifies the address of the first coding tree block in the slice 

segment

Quoted 6 lines

Not used.

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u32
+      - ``num_entry_point_offsets``
+      - Specifies the number of entry_point_offset_minus1[ i ] syntax 

elements in the slice header

Quoted 2 lines

Not used.

While above two fields may not be used in Hantro, they are for sure useful for Cedrus and RPi4. I would like to keep them, otherwise with such approach HEVC will stay in staging for a long time. I'm still baffled why scaling matrix control was dropped. It would fit well in Cedrus and RPi4 driver and after a quick look, it seems that it was used in driver in later patch.

Best regards,
Jernej

Quoted 24 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3427

Quoted 11 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
     * - __u8
       - ``nal_unit_type``
       -
@@ -3422,28 +3455,20 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.

Need to explain in the commit description why this field is moved.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 9 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
     * - __u8
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB.
+    * - __u16
+      - ``short_term_ref_pic_set_size``
+
Quoted 12 lines

Not used.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3469

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
      -
+    * - __u16
+      - ``long_term_ref_pic_set_size``
+      -

Not used.

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -2
     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that come 

before

Quoted 3 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3438

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -1
-        the current frame.

If this matches NumPocStCurrBefore from section 8.3.2 "Decoding process for

reference picture set"

Quoted 5 lines

then I would document that. And perhaps rename it to num_poc_st_curr_before.

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that come 

after

Quoted 11 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3442

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -1
-        the current frame.

Ditto.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3444

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.

Ditto.

Also, I'd like the changes that move fields from

V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS

Quoted 9 lines

to the new V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS control, to be in their patch.

That will allow us to put in the commit description a proper explanation of why are fields being moved. Nothing fancy, simply explaining that these variables come from section 8.3.2 "Decoding process for reference picture set", which describes a process invoked once per picture, so they are not per-slice.

Quoted 13 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3676

Quoted 13 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +1 -2
-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
     * - struct :c:type:`v4l2_hevc_dpb_entry`

- ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3646,3 +3671,74 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     so this has to come from client.
     This is applicable to H264 and valid Range is from 0 to 63.
     Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references picture 

order

Quoted 1 line

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3677

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +1 -0
+    count (POC) for all the lists (short, long, before, current, after) 

and the

Quoted 29 lines
Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +7 -0
+    number of entries for each of them.
+    These parameters are defined according to :ref:`hevc`.
+    They are described in section 8.3 "Slice decoding process" of the
+    specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3694

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10 -0
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      -

Can be documented as:

"""
PicOrderCntVal as described in section 8.3.1 "Decoding process for picture order count" of the specification.
"""

Note that snake case is used to match the kernel style, but other than that we try to keep the HEVC spec variable names.

Quoted 12 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3700

Quoted 6 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:`v4l2_hevc_dpb_entry`
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference frames.

The DPB is here, but it seems it's also in the slice control?

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that come 

before

Quoted 4 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +4 -0
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that come 

after

Quoted 14 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3720

Quoted 13 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +13 -0
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set.
+    * - __u8
+      - ``rps_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u8
+      - ``rps_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u8
+      - ``rps_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
Quoted 6 lines

Could you document these as well?

Thanks a lot,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#4 lore raw

Re: Re: [PATCH v3 1/9] media: hevc: Modify structures to follow H265 ITU spec

Hey Jernej,

Quoted 163 lines · Jernej Škrabec

Hi Ezequiel,

Dne četrtek, 25. februar 2021 ob 14:09:52 CET je Ezequiel Garcia napisal(a):

Quoted 51 lines

Hi Benjamin,

Thanks for the good work.

Quoted 46 lines · Benjamin Gaignard

The H.265 ITU specification (section 7.4) define the general slice segment header semantics.
Modified/added fields are:
- video_parameter_set_id: (7.4.3.1) identifies the VPS for reference by other syntax elements.
- seq_parameter_set_id: (7.4.3.2.1) specifies the value of the vps_video_parameter_set_id of the active VPS.
- chroma_format_idc: (7.4.3.2.1) specifies the chroma sampling relative to the luma sampling
- pic_parameter_set_id: (7.4.3.3.1) identifies the PPS for reference by other syntax elements
- num_ref_idx_l0_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l0_active_minus1
- num_ref_idx_l1_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l1_active_minus1
- slice_segment_addr: (7.4.7.1) specifies the address of the first coding tree block in the slice segment
- num_entry_point_offsets: (7.4.7.1) specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Add HEVC decode params contains the information used in section "8.3 Slice decoding process" of the specification to let the hardware perform decoding of a slices.

Adapt Cedrus driver according to these changes.

---
version 3:
- Add documentation about the new structuers and fields.

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields

 .../media/v4l/ext-ctrls-codec.rst             | 126 +++++++++++++++--- .../media/v4l/vidioc-queryctrl.rst            |   6 + drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +++-

 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
 include/media/hevc-ctrls.h                    |  45 +++++--
 8 files changed, 186 insertions(+), 32 deletions(-)
Quoted 1 line

Review

Quoted 1 line
(quoted diff) renamed from Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst

Quoted 5 lines
Quoted 5 lines

index 00944e97d638..5e6d77e858c0 100644

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3109,6 +3109,15 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -

     :stub-columns: 0

Quoted 8 lines
Quoted 8 lines

     :widths:       1 1 2

+    * - __u8
+      - ``video_parameter_set_id``
+      - Identifies the VPS for reference by other syntax elements +    * - __u8
+      - ``seq_parameter_set_id̀``
+      - Specifies the value of the vps_video_parameter_set_id of the

active VPS

Quoted 67 lines
Quoted 3 lines

+    * - __u8
+      - ``chroma_format_idc``
+      - Specifies the chroma sampling relative to the luma sampling

None of these fields seem needed for the Hantro G2 driver, so I suggest you drop them for now.

Quoted 10 lines

     * - __u16
       - ``pic_width_in_luma_samples``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3172,6 +3181,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u8

       - ``chroma_format_idc``
       -
+    * - __u8
+      - ``num_slices``
+

Not used, but also doesn't seem part of the SPS syntax. If we have to pass the number of slices, we'll need another mechanism.

Quoted 11 lines

      -
     * - __u64
       - ``flags``
       - See :ref:Sequence Parameter Set Flags <hevc_sps_flags>

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3231,9 +3243,18 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -

     :stub-columns: 0
     :widths:       1 1 2

+    * - __u8
+      - ``pic_parameter_set_id``
+      - Identifies the PPS for reference by other syntax elements

Not used.

Quoted 15 lines

     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l0_active_minus1 +    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3342,6 +3363,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``

       - 0x00040000

Quoted 8 lines

       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT`` +      - 0x00080000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      -

I suggest to do all the PPS control changes in a separate patch, feels easier to review and cleaner as you can explain the changes with more detail in the commit description.

Looking at the PPS syntax for tiles, I'm wondering if these deserve their own control, which would be used if tiles are enabled, i.e. V4L2_HEVC_PPS_FLAG_TILES_ENABLED is set.

Quoted 9 lines

        __u8    num_tile_columns_minus1;
        __u8    num_tile_rows_minus1;
        __u8    column_width_minus1[20];
        __u8    row_height_minus1[22];

Not something we necessarily have to tackle now.

Quoted 2 lines

 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
     Specifies various slice-specific parameters, especially from the NAL

unit

Quoted 7 lines
Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3366,6 +3393,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u32

       - ``data_bit_offset``
       - Offset (in bits) to the video data in the current slice data. +    * - __u32
+      - ``slice_segment_addr``
+      - Specifies the address of the first coding tree block in the slice

segment

Quoted 6 lines

Not used.

Quoted 3 lines

+    * - __u32
+      - ``num_entry_point_offsets``
+      - Specifies the number of entry_point_offset_minus1[ i ] syntax

elements in the slice header

Quoted 1 line
Quoted 8 lines
Quoted 1 line

Not used.

While above two fields may not be used in Hantro, they are for sure useful for Cedrus and RPi4. I would like to keep them, otherwise with such approach HEVC will stay in staging for a long time. I'm still baffled why scaling matrix control was dropped. It would fit well in Cedrus and RPi4 driver and after a quick look, it seems that it was used in driver in later patch.

I'd like to make sure each modification we are making to the uAPI goes in the right direction, that is in the direction of moving the API out of staging.

Since reviewing each field is quite hard, and opens some discussions, I wanted to keep this patchset specific to what's needed for Hantro G2.

The Scaling matrix control is certainly a good one, as well as the ones needed for Cedrus and RPi4. However, I feel it's better to discuss them in their own "uAPI review" series so we can review all the changes with an API hat.

This way we decouple the Hantro G2 discussion and work from the API work.

Also please feel free to submit RFC patches fo Cedrus and RPi4 (API and driver changes). We can certainly start the discussion around that, with driver changes in context.

Hope I'm making sense here :)

Thanks,
Ezequiel

Quoted 128 lines

Best regards,
Jernej

Quoted 24 lines
Quoted 11 lines

     * - __u8
       - ``nal_unit_type``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3422,28 +3455,20 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u8

       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.

Need to explain in the commit description why this field is moved.

Quoted 9 lines

     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
     * - __u8
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB. +    * - __u16
+      - ``short_term_ref_pic_set_size``
+

Quoted 12 lines

Not used.

Quoted 4 lines

      -
+    * - __u16
+      - ``long_term_ref_pic_set_size``
+      -

Not used.

Quoted 3 lines

     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that come

before

Quoted 3 lines
Quoted 1 line

-        the current frame.

If this matches NumPocStCurrBefore from section 8.3.2 "Decoding process for

reference picture set"

Quoted 5 lines

then I would document that. And perhaps rename it to num_poc_st_curr_before.

Quoted 3 lines

-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that come

after

Quoted 11 lines
Quoted 1 line

-        the current frame.

Ditto.

Quoted 3 lines

-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.

Ditto.

Also, I'd like the changes that move fields from

V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS

Quoted 9 lines

to the new V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS control, to be in their patch.

That will allow us to put in the commit description a proper explanation of why are fields being moved. Nothing fancy, simply explaining that these variables come from section 8.3.2 "Decoding process for reference picture set", which describes a process invoked once per picture, so they are not per-slice.

Quoted 13 lines
Quoted 7 lines

-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
     * - struct :c:type:v4l2_hevc_dpb_entry
       - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3646,3 +3671,74 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
Quoted 6 lines

     so this has to come from client.
     This is applicable to H264 and valid Range is from 0 to 63. Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references picture

order

Quoted 1 line
Quoted 1 line

+    count (POC) for all the lists (short, long, before, current, after)

and the

Quoted 29 lines
Quoted 7 lines

+    number of entries for each of them.
+    These parameters are defined according to :ref:hevc. +    They are described in section 8.3 "Slice decoding process" of the +    specification.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3694

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10 -0
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      -

Can be documented as:

"""
PicOrderCntVal as described in section 8.3.1 "Decoding process for picture order count" of the specification.
"""

Note that snake case is used to match the kernel style, but other than that we try to keep the HEVC spec variable names.

Quoted 12 lines
Quoted 6 lines

+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:v4l2_hevc_dpb_entry
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference frames.

The DPB is here, but it seems it's also in the slice control?

Quoted 3 lines

+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that come

Quoted 28 lines

before

Quoted 4 lines
Quoted 4 lines

+        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that come

after

Quoted 20 lines
Quoted 5 lines

+        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set. +    * - __u8

Quoted 8 lines

+      - ``rps_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -
+    * - __u8
+      - ``rps_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -
+    * - __u8
+      - ``rps_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -

Could you document these as well?

Thanks a lot,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#5 lore raw

Re: Re: Re: [PATCH v3 1/9] media: hevc: Modify structures to follow H265 ITU spec

Dne četrtek, 25. februar 2021 ob 18:34:48 CET je Ezequiel Garcia napisal(a):

Quoted 6 lines

Hey Jernej,

Quoted 3 lines · Jernej Škrabec

Hi Ezequiel,

Dne četrtek, 25. februar 2021 ob 14:09:52 CET je Ezequiel Garcia

napisal(a):

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines

Hi Benjamin,

Thanks for the good work.

Quoted 31 lines · Benjamin Gaignard

The H.265 ITU specification (section 7.4) define the general slice segment header semantics.
Modified/added fields are:
- video_parameter_set_id: (7.4.3.1) identifies the VPS for reference by other syntax elements.
- seq_parameter_set_id: (7.4.3.2.1) specifies the value of the vps_video_parameter_set_id of the active VPS.
- chroma_format_idc: (7.4.3.2.1) specifies the chroma sampling relative to the luma sampling
- pic_parameter_set_id: (7.4.3.3.1) identifies the PPS for reference by other syntax elements
- num_ref_idx_l0_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l0_active_minus1
- num_ref_idx_l1_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l1_active_minus1
- slice_segment_addr: (7.4.7.1) specifies the address of the first coding tree block in the slice segment
- num_entry_point_offsets: (7.4.7.1) specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Add HEVC decode params contains the information used in section "8.3 Slice decoding process" of the specification to let the hardware perform decoding of a slices.

Adapt Cedrus driver according to these changes.

---
version 3:
- Add documentation about the new structuers and fields.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields

 .../media/v4l/ext-ctrls-codec.rst             | 126 ++++++++++++++
+---
> > > >  .../media/v4l/vidioc-queryctrl.rst            |   6 +
> > > >  drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +++-
> > > >  drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
> > > >  drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
> > > >  .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
> > > >  .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
> > > >  include/media/hevc-ctrls.h                    |  45 +++++--
> > > >  8 files changed, 186 insertions(+), 32 deletions(-)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/

Quoted 78 lines
Quoted 78 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst

Quoted 7 lines
Quoted 7 lines

index 00944e97d638..5e6d77e858c0 100644

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3109,6 +3109,15 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2
 
Quoted 6 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 6 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
+    * - __u8
+      - ``video_parameter_set_id``
+      - Identifies the VPS for reference by other syntax elements
+    * - __u8
+      - ``seq_parameter_set_id̀``
+      - Specifies the value of the vps_video_parameter_set_id of the 

active VPS

Quoted 63 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3120

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u8
+      - ``chroma_format_idc``
+      - Specifies the chroma sampling relative to the luma sampling

None of these fields seem needed for the Hantro G2 driver, so I suggest you drop them for now.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3186

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
     * - __u16
       - ``pic_width_in_luma_samples``
       -
@@ -3172,6 +3181,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``chroma_format_idc``
       -
+    * - __u8
+      - ``num_slices``
+

Not used, but also doesn't seem part of the SPS syntax. If we have to pass the number of slices, we'll need another mechanism.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3248

Quoted 11 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
      -
     * - __u64
       - ``flags``

- See :ref:Sequence Parameter Set Flags <hevc_sps_flags>

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3231,9 +3243,18 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2
 
+    * - __u8
+      - ``pic_parameter_set_id``
+      - Identifies the PPS for reference by other syntax elements

Not used.

Quoted 13 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l0_active_minus1
+    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3372

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
@@ -3342,6 +3363,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
       - 0x00040000
       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+      - 0x00080000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      -
 

I suggest to do all the PPS control changes in a separate patch, feels easier to review and cleaner as you can explain the changes with more detail in the commit description.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Looking at the PPS syntax for tiles, I'm wondering if these deserve their own control, which would be used if tiles are enabled, i.e. V4L2_HEVC_PPS_FLAG_TILES_ENABLED is set.

        __u8    

num_tile_columns_minus1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
        __u8    

num_tile_rows_minus1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
        __u8    

column_width_minus1[20];

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
        __u8    row_height_minus1[22];    

Not something we necessarily have to tackle now.

Quoted 2 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
     Specifies various slice-specific parameters, especially from the 

NAL

Quoted 8 lines
Quoted 8 lines

unit

Quoted 7 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3398

Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3366,6 +3393,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u32
       - ``data_bit_offset``
       - Offset (in bits) to the video data in the current slice data.
+    * - __u32
+      - ``slice_segment_addr``
+      - Specifies the address of the first coding tree block in the 

slice

Quoted 4 lines
Quoted 4 lines

segment

Quoted 3 lines

Not used.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u32
+      - ``num_entry_point_offsets``
+      - Specifies the number of entry_point_offset_minus1[ i ] syntax 

elements in the slice header

Quoted 2 lines

Not used.

While above two fields may not be used in Hantro, they are for sure useful

for

Quoted 1 line
Quoted 1 line

Cedrus and RPi4. I would like to keep them, otherwise with such approach

HEVC

Quoted 2 lines
Quoted 2 lines

will stay in staging for a long time. I'm still baffled why scaling matrix control was dropped. It would fit well in Cedrus and RPi4 driver and after

a

Quoted 15 lines
Quoted 2 lines

quick look, it seems that it was used in driver in later patch.

I'd like to make sure each modification we are making to the uAPI goes in the right direction, that is in the direction of moving the API out of staging.

Since reviewing each field is quite hard, and opens some discussions, I wanted to keep this patchset specific to what's needed for Hantro G2.

The Scaling matrix control is certainly a good one, as well as the ones needed for Cedrus and RPi4. However, I feel it's better to discuss them in their own "uAPI review" series so we can review all the changes with an API hat.

Quoted 5 lines

This way we decouple the Hantro G2 discussion and work from the API work.

Also please feel free to submit RFC patches fo Cedrus and RPi4 (API and driver changes). We can certainly start the discussion around that, with driver changes in context.

I don't know much about RPi4 driver, only few implementation details, so you'll have to ping developer who wrote it. Regarding HEVC on Cedrus - it has one pain point - it needs entry point table which in turn needs support for variable arrays in order to be feasable AFAIK. I don't plan to develop that. Patches for scaling matrix and segment address were sent a bit more than a year ago but were turned down because they change control structures (among other things). Sorry to say, but I work on other things now, so Cedrus will have to wait. Alternatively, someone can take my patches from LibreELEC, update and submit them. They are in use for a long time.

Best regards,
Jernej

Quoted 6 lines

Hope I'm making sense here :)

Thanks,
Ezequiel

Quoted 8 lines
Quoted 8 lines

Best regards,
Jernej

Quoted 5 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field

Quoted 5 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
     * - __u8
       - ``nal_unit_type``
       -
@@ -3422,28 +3455,20 @@ enum v4l2_mpeg_video_hevc_size_of_length_field 

-

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3427

Quoted 6 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
     * - __u8
       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.

Need to explain in the commit description why this field is moved.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 9 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
     * - __u8
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB.
+    * - __u16
+      - ``short_term_ref_pic_set_size``
+

Not used.

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
      -
+    * - __u16
+      - ``long_term_ref_pic_set_size``
+      -
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Not used.

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -2
     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that 

come

Quoted 4 lines
Quoted 4 lines

before

Quoted 3 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field · line 3438

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -1
-        the current frame.

If this matches NumPocStCurrBefore from section 8.3.2 "Decoding process

for

Quoted 2 lines
Quoted 2 lines

reference picture set"

Quoted 1 line

then I would document that. And perhaps rename it to

num_poc_st_curr_before.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that 

come

Quoted 9 lines
Quoted 9 lines

after

Quoted 8 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field · line 3442

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -1
-        the current frame.

Ditto.

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Ditto.

Also, I'd like the changes that move fields from

V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS

Quoted 1 line

to the new V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS control, to be in

their

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

patch.

That will allow us to put in the commit description a proper explanation of why are fields being moved. Nothing fancy, simply explaining that these variables come from section 8.3.2 "Decoding process for reference picture set", which describes a process invoked once per picture, so they are not per-slice.

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +1 -2
-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
     * - struct :c:type:`v4l2_hevc_dpb_entry`
Quoted 8 lines
Quoted 8 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3676

Quoted 8 lines

- ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3646,3 +3671,74 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     so this has to come from client.
     This is applicable to H264 and valid Range is from 0 to 63.
     Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references 

picture

Quoted 2 lines
Quoted 2 lines

order

Quoted 1 line
Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +1 -0
+    count (POC) for all the lists (short, long, before, current, 

after)

Quoted 30 lines
Quoted 30 lines

and the

Quoted 29 lines
Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +7 -0
+    number of entries for each of them.
+    These parameters are defined according to :ref:`hevc`.
+    They are described in section 8.3 "Slice decoding process" of the
+    specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3694

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10 -0
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      -

Can be documented as:

"""
PicOrderCntVal as described in section 8.3.1 "Decoding process for picture order count" of the specification.
"""

Note that snake case is used to match the kernel style, but other than that we try to keep the HEVC spec variable names.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 6 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:`v4l2_hevc_dpb_entry`
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference 

frames.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The DPB is here, but it seems it's also in the slice control?

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that 

come

Quoted 5 lines
Quoted 5 lines

before

Quoted 4 lines
Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +4 -0
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that 

come

Quoted 15 lines
Quoted 15 lines

after

Quoted 14 lines
Quoted 13 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +13 -0
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set.
+    * - __u8
+      - ``rps_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u8
+      - ``rps_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u8
+      - ``rps_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines

Could you document these as well?

Thanks a lot,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#6 lore raw

Re: [PATCH v3 1/9] media: hevc: Modify structures to follow H265 ITU spec

Quoted 205 lines · you

Dne ?etrtek, 25. februar 2021 ob 18:34:48 CET je Ezequiel Garcia napisal(a):

Quoted 6 lines

Hey Jernej,

Quoted 3 lines · Jernej Škrabec

Hi Ezequiel,

Dne ?etrtek, 25. februar 2021 ob 14:09:52 CET je Ezequiel Garcia

napisal(a):

Quoted 36 lines
Quoted 36 lines
Quoted 36 lines

Hi Benjamin,

Thanks for the good work.

Quoted 31 lines · Benjamin Gaignard

The H.265 ITU specification (section 7.4) define the general slice segment header semantics.
Modified/added fields are:
- video_parameter_set_id: (7.4.3.1) identifies the VPS for reference by other syntax elements.
- seq_parameter_set_id: (7.4.3.2.1) specifies the value of the vps_video_parameter_set_id of the active VPS.
- chroma_format_idc: (7.4.3.2.1) specifies the chroma sampling relative to the luma sampling
- pic_parameter_set_id: (7.4.3.3.1) identifies the PPS for reference by other syntax elements
- num_ref_idx_l0_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l0_active_minus1
- num_ref_idx_l1_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l1_active_minus1
- slice_segment_addr: (7.4.7.1) specifies the address of the first coding tree block in the slice segment
- num_entry_point_offsets: (7.4.7.1) specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Add HEVC decode params contains the information used in section "8.3 Slice decoding process" of the specification to let the hardware perform decoding of a slices.

Adapt Cedrus driver according to these changes.

---
version 3:
- Add documentation about the new structuers and fields.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields

 .../media/v4l/ext-ctrls-codec.rst             | 126 ++++++++++++++
+---
> > > >  .../media/v4l/vidioc-queryctrl.rst            |   6 +
> > > >  drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +++-
> > > >  drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
> > > >  drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
> > > >  .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
> > > >  .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
> > > >  include/media/hevc-ctrls.h                    |  45 +++++--
> > > >  8 files changed, 186 insertions(+), 32 deletions(-)
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Review

Quoted 2 lines
(quoted diff) +0 -0

b/

Quoted 78 lines
Quoted 78 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst

Quoted 7 lines
Quoted 7 lines

index 00944e97d638..5e6d77e858c0 100644

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3109,6 +3109,15 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2
 
Quoted 6 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 6 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
+    * - __u8
+      - ``video_parameter_set_id``
+      - Identifies the VPS for reference by other syntax elements
+    * - __u8
+      - ``seq_parameter_set_id?``
+      - Specifies the value of the vps_video_parameter_set_id of the 

active VPS

Quoted 63 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3120

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u8
+      - ``chroma_format_idc``
+      - Specifies the chroma sampling relative to the luma sampling

None of these fields seem needed for the Hantro G2 driver, so I suggest you drop them for now.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3186

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
     * - __u16
       - ``pic_width_in_luma_samples``
       -
@@ -3172,6 +3181,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``chroma_format_idc``
       -
+    * - __u8
+      - ``num_slices``
+

Not used, but also doesn't seem part of the SPS syntax. If we have to pass the number of slices, we'll need another mechanism.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3248

Quoted 11 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
      -
     * - __u64
       - ``flags``

- See :ref:Sequence Parameter Set Flags <hevc_sps_flags>

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3231,9 +3243,18 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2
 
+    * - __u8
+      - ``pic_parameter_set_id``
+      - Identifies the PPS for reference by other syntax elements

Not used.

Quoted 13 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l0_active_minus1
+    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3372

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
@@ -3342,6 +3363,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
       - 0x00040000
       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT``
+      - 0x00080000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      -
 

I suggest to do all the PPS control changes in a separate patch, feels easier to review and cleaner as you can explain the changes with more detail in the commit description.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Looking at the PPS syntax for tiles, I'm wondering if these deserve their own control, which would be used if tiles are enabled, i.e. V4L2_HEVC_PPS_FLAG_TILES_ENABLED is set.

        __u8    

num_tile_columns_minus1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
        __u8    

num_tile_rows_minus1;

Quoted 1 line
Quoted 1 line
Quoted 1 line
        __u8    

column_width_minus1[20];

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
        __u8    row_height_minus1[22];    

Not something we necessarily have to tackle now.

Quoted 2 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
     Specifies various slice-specific parameters, especially from the 

NAL

Quoted 8 lines
Quoted 8 lines

unit

Quoted 7 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3398

Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3366,6 +3393,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u32
       - ``data_bit_offset``
       - Offset (in bits) to the video data in the current slice data.
+    * - __u32
+      - ``slice_segment_addr``
+      - Specifies the address of the first coding tree block in the 

slice

Quoted 4 lines
Quoted 4 lines

segment

Quoted 3 lines

Not used.

Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u32
+      - ``num_entry_point_offsets``
+      - Specifies the number of entry_point_offset_minus1[ i ] syntax 

elements in the slice header

Quoted 2 lines

Not used.

While above two fields may not be used in Hantro, they are for sure useful

for

Quoted 1 line
Quoted 1 line

Cedrus and RPi4. I would like to keep them, otherwise with such approach

HEVC

Quoted 2 lines
Quoted 2 lines

will stay in staging for a long time. I'm still baffled why scaling matrix control was dropped. It would fit well in Cedrus and RPi4 driver and after

a

Quoted 15 lines
Quoted 2 lines

quick look, it seems that it was used in driver in later patch.

I'd like to make sure each modification we are making to the uAPI goes in the right direction, that is in the direction of moving the API out of staging.

Since reviewing each field is quite hard, and opens some discussions, I wanted to keep this patchset specific to what's needed for Hantro G2.

The Scaling matrix control is certainly a good one, as well as the ones needed for Cedrus and RPi4. However, I feel it's better to discuss them in their own "uAPI review" series so we can review all the changes with an API hat.

Quoted 5 lines

This way we decouple the Hantro G2 discussion and work from the API work.

Also please feel free to submit RFC patches fo Cedrus and RPi4 (API and driver changes). We can certainly start the discussion around that, with driver changes in context.

Quoted 9 lines

I don't know much about RPi4 driver, only few implementation details, so you'll have to ping developer who wrote it. Regarding HEVC on Cedrus - it has one pain point - it needs entry point table which in turn needs support for variable arrays in order to be feasable AFAIK. I don't plan to develop that. Patches for scaling matrix and segment address were sent a bit more than a year ago but were turned down because they change control structures (among other things). Sorry to say, but I work on other things now, so Cedrus will have to wait. Alternatively, someone can take my patches from LibreELEC, update and submit them. They are in use for a long time.

It seems to me that H.265 should be the source for what fields are needed in the uapi - not whatever happens to be supported by current h/w. The standard defines the list of fields that can occur in the parameter sets and headers, and everything that is needed to decode any slice_seqgment_data should be in the upai. Eventually all those fields are going to be needed (they aren't in the standard just to look pretty) and given the reluctance I've observed to change the uapi once released they should be there from the start.

Now some hardware requires more fields that aren't in the standard - those can (and should) be added in h/w specific extensions.

Regards

JC

Quoted 146 lines

Best regards,
Jernej

Quoted 6 lines

Hope I'm making sense here :)

Thanks,
Ezequiel

Quoted 8 lines
Quoted 8 lines

Best regards,
Jernej

Quoted 5 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field

Quoted 5 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
     * - __u8
       - ``nal_unit_type``
       -
@@ -3422,28 +3455,20 @@ enum v4l2_mpeg_video_hevc_size_of_length_field 

-

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3427

Quoted 6 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
     * - __u8
       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.

Need to explain in the commit description why this field is moved.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 9 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
     * - __u8
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB.
+    * - __u16
+      - ``short_term_ref_pic_set_size``
+

Not used.

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
      -
+    * - __u16
+      - ``long_term_ref_pic_set_size``
+      -
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Not used.

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -2
     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that 

come

Quoted 4 lines
Quoted 4 lines

before

Quoted 3 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field · line 3438

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -1
-        the current frame.

If this matches NumPocStCurrBefore from section 8.3.2 "Decoding process

for

Quoted 2 lines
Quoted 2 lines

reference picture set"

Quoted 1 line

then I would document that. And perhaps rename it to

num_poc_st_curr_before.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that 

come

Quoted 9 lines
Quoted 9 lines

after

Quoted 8 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field · line 3442

Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -1
-        the current frame.

Ditto.

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -3
-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Ditto.

Also, I'd like the changes that move fields from

V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS

Quoted 1 line

to the new V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS control, to be in

their

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

patch.

That will allow us to put in the commit description a proper explanation of why are fields being moved. Nothing fancy, simply explaining that these variables come from section 8.3.2 "Decoding process for reference picture set", which describes a process invoked once per picture, so they are not per-slice.

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +1 -2
-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
     * - struct :c:type:`v4l2_hevc_dpb_entry`
Quoted 8 lines
Quoted 8 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3676

Quoted 8 lines

- ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
@@ -3646,3 +3671,74 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     so this has to come from client.
     This is applicable to H264 and valid Range is from 0 to 63.
     Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references 

picture

Quoted 2 lines
Quoted 2 lines

order

Quoted 1 line
Quoted 1 line
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +1 -0
+    count (POC) for all the lists (short, long, before, current, 

after)

Quoted 30 lines
Quoted 30 lines

and the

Quoted 29 lines
Quoted 7 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +7 -0
+    number of entries for each of them.
+    These parameters are defined according to :ref:`hevc`.
+    They are described in section 8.3 "Slice decoding process" of the
+    specification.
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3694

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10 -0
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      -

Can be documented as:

"""
PicOrderCntVal as described in section 8.3.1 "Decoding process for picture order count" of the specification.
"""

Note that snake case is used to match the kernel style, but other than that we try to keep the HEVC spec variable names.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field -

Quoted 6 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +6 -0
+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:`v4l2_hevc_dpb_entry`
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference 

frames.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The DPB is here, but it seems it's also in the slice control?

Quoted 3 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that 
Quoted 34 lines

come

Quoted 5 lines
Quoted 5 lines

before

Quoted 4 lines
Quoted 4 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +4 -0
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that 

come

Quoted 26 lines
Quoted 23 lines

after

Quoted 20 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3720

Quoted 13 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +13 -0
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set.
+    * - __u8
+      - ``rps_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u8
+      - ``rps_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -
+    * - __u8
+      - ``rps_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      -

Could you document these as well?

Thanks a lot,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

maintainer
#7 lore raw

Re: [PATCH v3 1/9] media: hevc: Modify structures to follow H265 ITU spec

Le jeudi 25 février 2021 à 18:34 +0000, John Cox a écrit :

Quoted 245 lines · you
Quoted 224 lines

Dne ?etrtek, 25. februar 2021 ob 18:34:48 CET je Ezequiel Garcia napisal(a):

Quoted 6 lines

Hey Jernej,

Quoted 3 lines · Jernej Škrabec

Hi Ezequiel,

Dne ?etrtek, 25. februar 2021 ob 14:09:52 CET je Ezequiel Garcia

napisal(a):

Quoted 37 lines
Quoted 37 lines
Quoted 37 lines

Hi Benjamin,

Thanks for the good work.

Quoted 32 lines · Benjamin Gaignard

The H.265 ITU specification (section 7.4) define the general slice segment header semantics.
Modified/added fields are:
- video_parameter_set_id: (7.4.3.1) identifies the VPS for reference by other syntax elements.
- seq_parameter_set_id: (7.4.3.2.1) specifies the value of the vps_video_parameter_set_id of the active VPS.
- chroma_format_idc: (7.4.3.2.1) specifies the chroma sampling relative to the luma sampling
- pic_parameter_set_id: (7.4.3.3.1) identifies the PPS for reference by other syntax elements
- num_ref_idx_l0_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l0_active_minus1
- num_ref_idx_l1_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l1_active_minus1
- slice_segment_addr: (7.4.7.1) specifies the address of the first coding tree block in the slice segment
- num_entry_point_offsets: (7.4.7.1) specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Add HEVC decode params contains the information used in section "8.3 Slice decoding process" of the specification to let the hardware
perform decoding of a slices.

Adapt Cedrus driver according to these changes.

---
version 3:
- Add documentation about the new structuers and fields.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields

 .../media/v4l/ext-ctrls-codec.rst             | 126 ++++++++++++++

+---
> > > >  .../media/v4l/vidioc-queryctrl.rst            |   6 +
> > > >  drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +++-
> > > >  drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
> > > >  drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
> > > >  .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
> > > >  .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
> > > >  include/media/hevc-ctrls.h                    |  45 +++++--
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
 8 files changed, 186 insertions(+), 32 deletions(-)
(quoted diff) +0 -0

codec.rst

b/

Quoted 86 lines
Quoted 86 lines

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst

Quoted 7 lines
Quoted 7 lines

index 00944e97d638..5e6d77e858c0 100644

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3109,6 +3109,15 @@ enum

v4l2_mpeg_video_hevc_size_of_length_field -
     :stub-columns: 0
     :widths:       1 1 2

Quoted 8 lines
Quoted 8 lines


+    * - __u8
+      - ``video_parameter_set_id``
+      - Identifies the VPS for reference by other syntax elements +    * - __u8
+      - ``seq_parameter_set_id?``
+      - Specifies the value of the vps_video_parameter_set_id of the

active VPS

Quoted 69 lines
Quoted 3 lines

+    * - __u8
+      - ``chroma_format_idc``
+      - Specifies the chroma sampling relative to the luma sampling

None of these fields seem needed for the Hantro G2 driver, so I suggest you drop them for now.

Quoted 11 lines

     * - __u16
       - ``pic_width_in_luma_samples``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -1
@@ -3172,6 +3181,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field
-
      * - __u8

       - ``chroma_format_idc``
       -
+    * - __u8
+      - ``num_slices``
+

Not used, but also doesn't seem part of the SPS syntax. If we have to pass the number of slices, we'll need another mechanism.

Quoted 5 lines

      -
     * - __u64
       - ``flags``
       - See :ref:Sequence Parameter Set Flags <hevc_sps_flags>

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3231,9 +3243,18 @@ enum
Quoted 7 lines

v4l2_mpeg_video_hevc_size_of_length_field - :stub-columns: 0
     :widths:       1 1 2

+    * - __u8
+      - ``pic_parameter_set_id``
+      - Identifies the PPS for reference by other syntax elements

Not used.

Quoted 19 lines

     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of
num_ref_idx_l0_active_minus1
+    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of
num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3342,6 +3363,12 @@ enum

v4l2_mpeg_video_hevc_size_of_length_field -
     * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``
       - 0x00040000

Quoted 8 lines

       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT`` +      - 0x00080000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      -

I suggest to do all the PPS control changes in a separate patch, feels easier to review and cleaner as you can explain the changes with more detail in the commit description.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Looking at the PPS syntax for tiles, I'm wondering if these deserve their own control, which would be used if tiles are enabled, i.e. V4L2_HEVC_PPS_FLAG_TILES_ENABLED is set.

        __u8

num_tile_columns_minus1;

Quoted 1 line
Quoted 1 line
Quoted 1 line

        __u8

num_tile_rows_minus1;

Quoted 1 line
Quoted 1 line
Quoted 1 line

        __u8

column_width_minus1[20];

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

        __u8    row_height_minus1[22];

Not something we necessarily have to tackle now.

Quoted 3 lines

 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)`` Specifies various slice-specific parameters, especially from the

NAL

Quoted 10 lines
Quoted 10 lines

unit

Quoted 9 lines
Quoted 9 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3366,6 +3393,12 @@ enum

v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u32
       - ``data_bit_offset``
       - Offset (in bits) to the video data in the current slice data.
+    * - __u32
+      - ``slice_segment_addr``
+      - Specifies the address of the first coding tree block in the

slice

Quoted 8 lines
Quoted 8 lines

segment

Quoted 7 lines

Not used.

Quoted 4 lines

+    * - __u32
+      - ``num_entry_point_offsets``
+      - Specifies the number of entry_point_offset_minus1[ i ] syntax

Quoted 6 lines
Quoted 6 lines

elements in the slice header

Quoted 2 lines

Not used.

While above two fields may not be used in Hantro, they are for sure useful

for

Quoted 1 line
Quoted 1 line

Cedrus and RPi4. I would like to keep them, otherwise with such approach

HEVC

Quoted 4 lines
Quoted 4 lines

will stay in staging for a long time. I'm still baffled why scaling matrix
control was dropped. It would fit well in Cedrus and RPi4 driver and after

a

Quoted 15 lines
Quoted 2 lines

quick look, it seems that it was used in driver in later patch.

I'd like to make sure each modification we are making to the uAPI goes in the right direction, that is in the direction of moving the API out of staging.

Since reviewing each field is quite hard, and opens some discussions, I wanted to keep this patchset specific to what's needed for Hantro G2.

The Scaling matrix control is certainly a good one, as well as the ones needed for Cedrus and RPi4. However, I feel it's better to discuss them in their own "uAPI review" series so we can review all the changes with an API hat.

Quoted 6 lines

This way we decouple the Hantro G2 discussion and work from the API work.

Also please feel free to submit RFC patches fo Cedrus and RPi4 (API and driver changes). We can certainly start the discussion around that,
with driver changes in context.

Quoted 10 lines

I don't know much about RPi4 driver, only few implementation details, so you'll have to ping developer who wrote it. Regarding HEVC on Cedrus - it has
one pain point - it needs entry point table which in turn needs support for variable arrays in order to be feasable AFAIK. I don't plan to develop that. Patches for scaling matrix and segment address were sent a bit more than a year ago but were turned down because they change control structures (among other things). Sorry to say, but I work on other things now, so Cedrus will have to wait. Alternatively, someone can take my patches from LibreELEC, update and submit them. They are in use for a long time.

It seems to me that H.265 should be the source for what fields are needed in the uapi - not whatever happens to be supported by current h/w. The standard defines the list of fields that can occur in the parameter sets and headers, and everything that is needed to decode any slice_seqgment_data should be in the upai.  Eventually all those fields are going to be needed (they aren't in the standard just to look pretty) and given the reluctance I've observed to change the uapi once released they should be there from the start.

Quoted 2 lines

Now some hardware requires more fields that aren't in the standard - those can (and should) be added in h/w specific extensions.

While this is not wrong, there is obvious bitstream parameters that are not of the HW accelerator domain. We did the work of deciding what to omit in the H264 uAPI, and we'll do that for HEVC for sure. But now is not the time yet.

Now the point that you seem to be missing is that Benjamin is trying to stage a driver, not a uAPI. With this third driver, we can have more folks contributing and testing toward our goal of unstaging the uAPI.

After this, we'll be able to iteratively add features (like scaling list) to this driver along with the required uAPI and discuss each of these needed API separatly. Note that previous iteration, the driver implementation for the scaling list wasn't correct, and for this reason, the uAPI wasn't being validated.

When this is getting stable enough, there will be a final stage were someone will have to pick the uAPI and fill in the blank with remaining field that has a strong probability to be used by later HW WITHIN the supported HEVC profiles et have defined.

I emphasis on that because there is a lot of HEVC (and H264) extensions we haven't covered or mentionned, and these will be added with dedicated controls when we have a use case for it of course. Remember that adding controls is not a problem, we need these basic control of the basic decoding, and for sure, over the decade to come we will have to introduce new controls for other stuff we haven't supported yet.

All this may look like taking forever, but as Jernej states, not everyone can afford contributing upstream. So unless someone step in, this pace is about what we can offer, and we strongly believe that it will converge. I do personnally expect HEVC to take more time as the codec rationales are mostly kept secret, and our answers burried into a mountain of reference code. It's also, if you defocus from the film industry, just one CODEC. Notably, for the web, VP9 is more important, and this will likely puts some shadow on this work.

Meawhile, you are strongly encouraged if you can afford it to open the discussion around the RPi4 multi-stage HEVC decoder. While doing this, you could send a patched for staging the RPi4 driver. The benefit would be that we get to update your drivers when we update the uAPI, saving you times, and also giving everyone more data on what is strictly needed.

Quoted 190 lines

Regards

JC

Quoted 184 lines

Best regards,
Jernej

Quoted 10 lines

Hope I'm making sense here :)

Thanks,
Ezequiel

Quoted 4 lines

Best regards,
Jernej

Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

     * - __u8
       - ``nal_unit_type``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3422,28 +3455,20 @@ enum

v4l2_mpeg_video_hevc_size_of_length_field

-

Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 6 lines

     * - __u8
       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.

Need to explain in the commit description why this field is moved.

Quoted 9 lines

     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
     * - __u8
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB. +    * - __u16
+      - ``short_term_ref_pic_set_size``
+

Not used.

Quoted 4 lines

      -
+    * - __u16
+      - ``long_term_ref_pic_set_size``
+      -

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Not used.

Quoted 3 lines

     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that

come

Quoted 5 lines
Quoted 5 lines

before

Quoted 4 lines
Quoted 1 line

-        the current frame.

If this matches NumPocStCurrBefore from section 8.3.2 "Decoding process

for

Quoted 2 lines
Quoted 2 lines

reference picture set"

Quoted 1 line

then I would document that. And perhaps rename it to

num_poc_st_curr_before.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that

come

Quoted 9 lines
Quoted 9 lines

after

Quoted 8 lines
Quoted 1 line

-        the current frame.

Ditto.

Quoted 3 lines

-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

Ditto.

Also, I'd like the changes that move fields from

V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS

Quoted 1 line

to the new V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS control, to be in

their

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

patch.

That will allow us to put in the commit description a proper explanation of why are fields being moved. Nothing fancy, simply explaining that these variables come from section 8.3.2 "Decoding process for reference picture set", which describes a process invoked once per picture, so they are not per-slice.

Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
     * - struct :c:type:v4l2_hevc_dpb_entry
       - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3646,3 +3671,74 @@ enum

v4l2_mpeg_video_hevc_size_of_length_field -
     so this has to come from client.
     This is applicable to H264 and valid Range is from 0 to 63. Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1. +
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references

picture

Quoted 2 lines
Quoted 2 lines

order

Quoted 1 line
Quoted 1 line

+    count (POC) for all the lists (short, long, before, current,

after)

Quoted 31 lines
Quoted 31 lines

and the

Quoted 30 lines
Quoted 8 lines

+    number of entries for each of them.
+    These parameters are defined according to :ref:hevc. +    They are described in section 8.3 "Slice decoding process" of the
+    specification.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3694

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10 -0
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      -

Can be documented as:

"""
PicOrderCntVal as described in section 8.3.1 "Decoding process for picture order count" of the specification.
"""

Note that snake case is used to match the kernel style, but other than that we try to keep the HEVC spec variable names.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:v4l2_hevc_dpb_entry
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference

frames.

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

The DPB is here, but it seems it's also in the slice control?

Quoted 3 lines

+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that

come

Quoted 5 lines
Quoted 5 lines

before

Quoted 4 lines
Quoted 4 lines

+        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that

come

Quoted 26 lines
Quoted 23 lines

after

Quoted 20 lines
Quoted 5 lines

+        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set. +    * - __u8

Quoted 8 lines

+      - ``rps_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -
+    * - __u8
+      - ``rps_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -
+    * - __u8
+      - ``rps_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -

Could you document these as well?

Thanks a lot,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

maintainer
#8 lore raw

Re: [PATCH v3 1/9] media: hevc: Modify structures to follow H265 ITU spec

In reply to Ezequiel Garcia

Le jeudi 25 février 2021 à 10:09 -0300, Ezequiel Garcia a écrit :

Quoted 65 lines

Hi Benjamin,

Thanks for the good work.

Quoted 60 lines · Benjamin Gaignard

The H.265 ITU specification (section 7.4) define the general slice segment header semantics.
Modified/added fields are:
- video_parameter_set_id: (7.4.3.1) identifies the VPS for reference by other syntax elements.
- seq_parameter_set_id: (7.4.3.2.1) specifies the value of the vps_video_parameter_set_id of the active VPS.
- chroma_format_idc: (7.4.3.2.1) specifies the chroma sampling relative to the luma sampling
- pic_parameter_set_id: (7.4.3.3.1) identifies the PPS for reference by other syntax elements
- num_ref_idx_l0_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l0_active_minus1
- num_ref_idx_l1_default_active_minus1: (7.4.3.3.1) specifies the inferred value of num_ref_idx_l1_active_minus1
- slice_segment_addr: (7.4.7.1) specifies the address of the first coding tree block in the slice segment
- num_entry_point_offsets: (7.4.7.1) specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Add HEVC decode params contains the information used in section "8.3 Slice decoding process" of the specification to let the hardware perform decoding of a slices.

Adapt Cedrus driver according to these changes.

---
version 3:
- Add documentation about the new structuers and fields.

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields

 .../media/v4l/ext-ctrls-codec.rst             | 126 +++++++++++++++--- .../media/v4l/vidioc-queryctrl.rst            |   6 + drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +++-

 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +
 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +-
 include/media/hevc-ctrls.h                    |  45 +++++--
 8 files changed, 186 insertions(+), 32 deletions(-)
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
index 00944e97d638..5e6d77e858c0 100644
@@ -3109,6 +3109,15 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -

     :stub-columns: 0
     :widths:       1 1 2

+    * - __u8
+      - ``video_parameter_set_id``
+      - Identifies the VPS for reference by other syntax elements +    * - __u8
+      - ``seq_parameter_set_id̀``

Quoted 8 lines
Quoted 5 lines

+      - Specifies the value of the vps_video_parameter_set_id of the active VPS
+    * - __u8
+      - ``chroma_format_idc``
+      - Specifies the chroma sampling relative to the luma sampling

None of these fields seem needed for the Hantro G2 driver, so I suggest you drop them for now.

You should be using chroma_format_idc in your validation. I think Hantro G2 does not do YUV 4:4:4, which is what chroma_format_idc tells the driver. Our implementation might also be missing 4:0:0 (black and white).

As this value will aftect the buffer size, please keep them, and ideally validate them. Note that it feels rather problematic / unsafe situation as we endup having to trust userspace, hopefully the HW validates it's buffer size ? (do we tell the HW the buffer sizes ?)

Quoted 236 lines
Quoted 11 lines

     * - __u16
       - ``pic_width_in_luma_samples``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3172,6 +3181,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u8

       - ``chroma_format_idc``
       -
+    * - __u8
+      - ``num_slices``
+

Not used, but also doesn't seem part of the SPS syntax. If we have to pass the number of slices, we'll need another mechanism.

Quoted 11 lines

      -
     * - __u64
       - ``flags``
       - See :ref:Sequence Parameter Set Flags <hevc_sps_flags>

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3231,9 +3243,18 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -

     :stub-columns: 0
     :widths:       1 1 2

+    * - __u8
+      - ``pic_parameter_set_id``
+      - Identifies the PPS for reference by other syntax elements

Not used.

Quoted 15 lines

     * - __u8
       - ``num_extra_slice_header_bits``
       -
+    * - __u8
+      - ``num_ref_idx_l0_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l0_active_minus1 +    * - __u8
+      - ``num_ref_idx_l1_default_active_minus1``
+      - Specifies the inferred value of num_ref_idx_l1_active_minus1
     * - __s8
       - ``init_qp_minus26``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3342,6 +3363,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - ``V4L2_HEVC_PPS_FLAG_SLICE_SEGMENT_HEADER_EXTENSION_PRESENT``

       - 0x00040000

Quoted 8 lines

       -
+    * - ``V4L2_HEVC_PPS_FLAG_DEBLOCKING_FILTER_CONTROL_PRESENT`` +      - 0x00080000
+      -
+    * - ``V4L2_HEVC_PPS_FLAG_UNIFORM_SPACING``
+      - 0x00100000
+      -

I suggest to do all the PPS control changes in a separate patch, feels easier to review and cleaner as you can explain the changes with more detail in the commit description.

Looking at the PPS syntax for tiles, I'm wondering if these deserve their own control, which would be used if tiles are enabled, i.e. V4L2_HEVC_PPS_FLAG_TILES_ENABLED is set.

        __u8
num_tile_columns_minus1;
        __u8
num_tile_rows_minus1;
        __u8
column_width_minus1[20];
        __u8    row_height_minus1[22];

Not something we necessarily have to tackle now.

Quoted 11 lines

 ``V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS (struct)``
     Specifies various slice-specific parameters, especially from the NAL unit

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3366,6 +3393,12 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u32

       - ``data_bit_offset``
       - Offset (in bits) to the video data in the current slice data. +    * - __u32
+      - ``slice_segment_addr``
+      - Specifies the address of the first coding tree block in the slice segment

Not used.

Quoted 4 lines

+    * - __u32
+      - ``num_entry_point_offsets``
+      - Specifies the number of entry_point_offset_minus1[ i ] syntax elements in the slice header

Not used.

Quoted 10 lines

     * - __u8
       - ``nal_unit_type``
       -

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3422,28 +3455,20 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
      * - __u8

       - ``pic_struct``
       -
-    * - __u8
-      - ``num_active_dpb_entries``
-      - The number of entries in ``dpb``.

Need to explain in the commit description why this field is moved.

Quoted 9 lines

     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
     * - __u8
       - ``ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L1 reference elements as indices in the DPB. +    * - __u16
+      - ``short_term_ref_pic_set_size``
+

Not used.

Quoted 4 lines

      -
+    * - __u16
+      - ``long_term_ref_pic_set_size``
+      -

Not used.

Quoted 5 lines

     * - __u8
-      - ``num_rps_poc_st_curr_before``
-      - The number of reference pictures in the short-term set that come before
-        the current frame.

If this matches NumPocStCurrBefore from section 8.3.2 "Decoding process for reference picture set"
then I would document that. And perhaps rename it to num_poc_st_curr_before.

Quoted 5 lines

-    * - __u8
-      - ``num_rps_poc_st_curr_after``
-      - The number of reference pictures in the short-term set that come after
-        the current frame.

Ditto.

Quoted 3 lines

-    * - __u8
-      - ``num_rps_poc_lt_curr``
-      - The number of reference pictures in the long-term set.

Ditto.

Also, I'd like the changes that move fields from V4L2_CID_MPEG_VIDEO_HEVC_SLICE_PARAMS
to the new V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS control, to be in their patch.

That will allow us to put in the commit description a proper explanation of why are fields being moved. Nothing fancy, simply explaining that these variables come from section 8.3.2 "Decoding process for reference picture set", which describes a process invoked once per picture, so they are not per-slice.

Quoted 23 lines

-    * - __u8
-      - ``padding[7]``
+      - ``padding``
       - Applications and drivers must set this to zero.
     * - struct :c:type:v4l2_hevc_dpb_entry
       - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +0 -0
@@ -3646,3 +3671,74 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -

     so this has to come from client.
     This is applicable to H264 and valid Range is from 0 to 63. Source Rec. ITU-T H.264 (06/2019); G.7.4.1.1, G.8.8.1.
+
+``V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS (struct)``
+    Specifies various decode parameters, especially the references picture order
+    count (POC) for all the lists (short, long, before, current, after) and the
+    number of entries for each of them.
+    These parameters are defined according to :ref:hevc.
+    They are described in section 8.3 "Slice decoding process" of the +    specification.

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +3 -0
+
+.. c:type:: v4l2_ctrl_hevc_decode_params
+

Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst enum v4l2_mpeg_video_hevc_size_of_length_field - · line 3694

Quoted 10 lines
Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst +10 -0
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_hevc_decode_params
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __s32
+      - ``pic_order_cnt_val``
+      -

Can be documented as:

"""
PicOrderCntVal as described in section 8.3.1 "Decoding process for picture order count" of the specification.
"""

Note that snake case is used to match the kernel style, but other than that we try to keep the HEVC spec variable names.

Quoted 6 lines

+    * - __u8
+      - ``num_active_dpb_entries``
+      - The number of entries in ``dpb``.
+    * - struct :c:type:v4l2_hevc_dpb_entry
+      - ``dpb[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
+      - The decoded picture buffer, for meta-data about reference frames.

The DPB is here, but it seems it's also in the slice control?

Quoted 14 lines

+    * - __u8
+      - ``num_rps_poc_st_curr_before``
+      - The number of reference pictures in the short-term set that come before
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_st_curr_after``
+      - The number of reference pictures in the short-term set that come after
+        the current frame.
+    * - __u8
+      - ``num_rps_poc_lt_curr``
+      - The number of reference pictures in the long-term set. +    * - __u8

Quoted 8 lines

+      - ``rps_st_curr_before[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -
+    * - __u8
+      - ``rps_st_curr_after[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -
+    * - __u8
+      - ``rps_lt_curr[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]`` +      -

Quoted 6 lines

Could you document these as well?

Thanks a lot,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author maintainer
#9 lore raw

PATCH v3 2/9 media: hantro: Define HEVC codec profiles and supported features

In reply to Benjamin Gaignard

Define which HEVC profiles (up to level 5.1) and features (no scaling, no 10 bits) are supported by the driver.

---
 drivers/staging/media/hantro/hantro.h     |  2 +
 drivers/staging/media/hantro/hantro_drv.c | 58 +++++++++++++++++++++++
 2 files changed, 60 insertions(+)
drivers/staging/media/hantro/hantro.h +2 -0
index 65f9f7ea7dcf..bde65231f22f 100644
@@ -99,6 +99,7 @@ struct hantro_variant {
  * @HANTRO_MODE_H264_DEC: H264 decoder.
  * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
  * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
  */
 enum hantro_codec_mode {
 	HANTRO_MODE_NONE = -1,
@@ -106,6 +107,7 @@ enum hantro_codec_mode {
 	HANTRO_MODE_H264_DEC,
 	HANTRO_MODE_MPEG2_DEC,
 	HANTRO_MODE_VP8_DEC,
+	HANTRO_MODE_HEVC_DEC,
 };
 
 /*
drivers/staging/media/hantro/hantro_drv.c +58 -0

70 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#10 lore raw

Re: [PATCH v3 2/9] media: hantro: Define HEVC codec profiles and supported features

Quoted 53 lines · Benjamin Gaignard

Define which HEVC profiles (up to level 5.1) and features (no scaling, no 10 bits) are supported by the driver.

---
 drivers/staging/media/hantro/hantro.h     |  2 + drivers/staging/media/hantro/hantro_drv.c | 58 +++++++++++++++++++++++

 2 files changed, 60 insertions(+)
drivers/staging/media/hantro/hantro.h +2 -0
index 65f9f7ea7dcf..bde65231f22f 100644
@@ -99,6 +99,7 @@ struct hantro_variant {
   * @HANTRO_MODE_H264_DEC: H264 decoder.
   * @HANTRO_MODE_MPEG2_DEC: MPEG-2 decoder.
   * @HANTRO_MODE_VP8_DEC: VP8 decoder.
+ * @HANTRO_MODE_HEVC_DEC: HEVC decoder.
   */
  enum hantro_codec_mode {
         HANTRO_MODE_NONE = -1,
@@ -106,6 +107,7 @@ enum hantro_codec_mode {
         HANTRO_MODE_H264_DEC,
         HANTRO_MODE_MPEG2_DEC,
         HANTRO_MODE_VP8_DEC,
+       HANTRO_MODE_HEVC_DEC,
  };


 /*

drivers/staging/media/hantro/hantro_drv.c +12 -0
index e5f200e64993..d86e322a5980 100644
@@ -243,6 +243,18 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
                 if (sps->bit_depth_luma_minus8 != 0)
                         /* Only 8-bit is supported */
                         return -EINVAL;
+       } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_HEVC_SPS) {
+               const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps;
+
+               if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8)
+                       /* Luma and chroma bit depth mismatch */
+                       return -EINVAL;
+               if (sps->bit_depth_luma_minus8 != 0)
+                       /* Only 8-bit is supported */
+                       return -EINVAL;
+               if (sps->flags & V4L2_HEVC_SPS_FLAG_SCALING_LIST_ENABLED)
+                       /* No scaling support */
+                       return -EINVAL;
         }
         return 0;
  }

drivers/staging/media/hantro/hantro_drv.c static const struct hantro_ctrl controls[] = { · line 364

Quoted 4 lines
drivers/staging/media/hantro/hantro_drv.c +1 -0
@@ -349,6 +361,52 @@ static const struct hantro_ctrl controls[] = {
                         .def = V4L2_MPEG_VIDEO_H264_PROFILE_MAIN,
                 }
         }, {
+               .codec = HANTRO_HEVC_DECODER,

Silly nitpick. Looks like this is not defined yet?

I'm getting:

drivers/staging/media/hantro/hantro_drv.c:364:12: error: ‘HANTRO_HEVC_DECODER’ undeclared here (not in a function); did you mean ‘HANTRO_H264_DECODER’?

  364 |   .codec = HANTRO_HEVC_DECODER,
      |            ^~~~~~~~~~~~~~~~~~~
      |            HANTRO_H264_DECODER

I'll review the G2 driver soon :-)

Thanks,
Ezequiel

Quoted 47 lines
drivers/staging/media/hantro/hantro_drv.c +45 -0
+               .cfg = {
+                       .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_MODE,
+                       .min = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+                       .max = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+                       .def = V4L2_MPEG_VIDEO_HEVC_DECODE_MODE_FRAME_BASED,
+               },
+       }, {
+               .codec = HANTRO_HEVC_DECODER,
+               .cfg = {
+                       .id = V4L2_CID_MPEG_VIDEO_HEVC_START_CODE,
+                       .min = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+                       .max = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+                       .def = V4L2_MPEG_VIDEO_HEVC_START_CODE_ANNEX_B,
+               },
+       }, {
+               .codec = HANTRO_HEVC_DECODER,
+               .cfg = {
+                       .id = V4L2_CID_MPEG_VIDEO_HEVC_PROFILE,
+                       .min = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+                       .max = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN_10,
+                       .def = V4L2_MPEG_VIDEO_HEVC_PROFILE_MAIN,
+               },
+       }, {
+               .codec = HANTRO_HEVC_DECODER,
+               .cfg = {
+                       .id = V4L2_CID_MPEG_VIDEO_HEVC_LEVEL,
+                       .min = V4L2_MPEG_VIDEO_HEVC_LEVEL_1,
+                       .max = V4L2_MPEG_VIDEO_HEVC_LEVEL_5_1,
+               },
+       }, {
+               .codec = HANTRO_HEVC_DECODER,
+               .cfg = {
+                       .id = V4L2_CID_MPEG_VIDEO_HEVC_SPS,
+                       .ops = &hantro_ctrl_ops,
+               },
+       }, {
+               .codec = HANTRO_HEVC_DECODER,
+               .cfg = {
+                       .id = V4L2_CID_MPEG_VIDEO_HEVC_PPS,
+               },
+       }, {
+               .codec = HANTRO_HEVC_DECODER,
+               .cfg = {
+                       .id = V4L2_CID_MPEG_VIDEO_HEVC_DECODE_PARAMS,
+               },
         },
  };
Quoted 1 line

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author maintainer
#11 lore raw

PATCH v3 3/9 media: hantro: Add a field to distinguish the hardware versions

In reply to Benjamin Gaignard

Decoders hardware blocks could exist in multiple versions: add a field to distinguish them at runtime.
G2 hardware block doesn't have postprocessor hantro_needs_postproc function should always returns false in for this hardware. hantro_needs_postproc function becoming to much complex to stay inline in .h file move it to .c file.

Keep the default behavoir to be G1 hardware.

---
version 2:
- squash this commit with the post processor change to show one usage of core_hw_dec_rev

 drivers/staging/media/hantro/hantro.h          | 13 +++++++------
 drivers/staging/media/hantro/hantro_drv.c      |  2 ++
 drivers/staging/media/hantro/hantro_postproc.c | 17 +++++++++++++++++
 3 files changed, 26 insertions(+), 6 deletions(-)
drivers/staging/media/hantro/hantro.h +7 -6
index bde65231f22f..352930bd49fc 100644
@@ -36,6 +36,9 @@ struct hantro_codec_ops;
 #define HANTRO_H264_DECODER	BIT(18)
 #define HANTRO_DECODERS		0xffff0000
 
+#define HANTRO_G1_REV		0x6731
+#define HANTRO_G2_REV		0x6732
+
 /**
  * struct hantro_irq - irq handler and name
  *
@@ -170,6 +173,7 @@ hantro_vdev_to_func(struct video_device *vdev)
  * @enc_base:		Mapped address of VPU encoder register for convenience.
  * @dec_base:		Mapped address of VPU decoder register for convenience.
  * @ctrl_base:		Mapped address of VPU control block.
+ * @core_hw_dec_rev	Runtime detected HW decoder core revision
  * @vpu_mutex:		Mutex to synchronize V4L2 calls.
  * @irqlock:		Spinlock to synchronize access to data structures
  *			shared with interrupt handlers.
@@ -189,6 +193,7 @@ struct hantro_dev {
 	void __iomem *enc_base;
 	void __iomem *dec_base;
 	void __iomem *ctrl_base;
+	u32 core_hw_dec_rev;
 
 	struct mutex vpu_mutex;	/* video_device lock */
 	spinlock_t irqlock;
@@ -411,12 +416,8 @@ hantro_get_dst_buf(struct hantro_ctx *ctx)
 	return v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
 }
 
-static inline bool
-hantro_needs_postproc(const struct hantro_ctx *ctx,
-		      const struct hantro_fmt *fmt)
-{
-	return !ctx->is_encoder && fmt->fourcc != V4L2_PIX_FMT_NV12;
-}
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+			   const struct hantro_fmt *fmt);
 
 static inline dma_addr_t
 hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
drivers/staging/media/hantro/hantro_drv.c +2 -0
index d86e322a5980..0a62beb0bfbd 100644
@@ -834,6 +834,8 @@ static int hantro_probe(struct platform_device *pdev)
 	}
 	vpu->enc_base = vpu->reg_bases[0] + vpu->variant->enc_offset;
 	vpu->dec_base = vpu->reg_bases[0] + vpu->variant->dec_offset;
+	/* by default decoder is G1 */
+	vpu->core_hw_dec_rev = HANTRO_G1_REV;
 
 	ret = dma_set_coherent_mask(vpu->dev, DMA_BIT_MASK(32));
 	if (ret) {
drivers/staging/media/hantro/hantro_postproc.c +17 -0
index 6d2a8f2a8f0b..050880f720d6 100644
@@ -50,6 +50,23 @@ const struct hantro_postproc_regs hantro_g1_postproc_regs = {
 	.display_width = {G1_REG_PP_DISPLAY_WIDTH, 0, 0xfff},
 };
 
+bool hantro_needs_postproc(const struct hantro_ctx *ctx,
+			   const struct hantro_fmt *fmt)
+{
+	struct hantro_dev *vpu = ctx->dev;
+
+	if (ctx->is_encoder)
+		return false;
+
+	if (vpu->core_hw_dec_rev == HANTRO_G1_REV)
+		return fmt->fourcc != V4L2_PIX_FMT_NV12;
+
+	if (vpu->core_hw_dec_rev == HANTRO_G2_REV)
+		return false;
+
+	return false;
+}
+
 void hantro_postproc_enable(struct hantro_ctx *ctx)
 {
 	struct hantro_dev *vpu = ctx->dev;
Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author maintainer
#12 lore raw

PATCH v3 4/9 media: uapi: Add a control for HANTRO driver

In reply to Benjamin Gaignard

The HEVC HANTRO driver needs to know the number of bits to skip at the beginning of the slice header.
That is a hardware specific requirement so create a dedicated control that this purpose.

---
version 3:
- Fix typo in field name

 include/uapi/linux/hantro-v4l2-controls.h | 20 ++++++++++++++++++++
 include/uapi/linux/v4l2-controls.h        |  5 +++++
 2 files changed, 25 insertions(+)
 create mode 100644 include/uapi/linux/hantro-v4l2-controls.h
include/uapi/linux/hantro-v4l2-controls.h new file +20 -0
new file mode 100644
index 000000000000..a8dfd6b1a2a9
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#ifndef __UAPI_HANTRO_V4L2_CONYTROLS_H__
+#define __UAPI_HANTRO_V4L2_CONYTROLS_H__
+
+#include <linux/v4l2-controls.h>
+#include <media/hevc-ctrls.h>
+
+#define V4L2_CID_HANTRO_HEVC_EXTRA_DECODE_PARAMS	(V4L2_CID_USER_HANTRO_BASE + 0)
+
+/**
+ * struct hantro_hevc_extra_decode_params - extra decode parameters for hantro driver
+ * @hevc_hdr_skip_length:	header first bits offset
+ */
+struct hantro_hevc_extra_decode_params {
+	__u32	hevc_hdr_skip_length;
+	__u8	padding[4];
+};
+
+#endif
include/uapi/linux/v4l2-controls.h +5 -0
index 039c0d7add1b..ced7486c7f46 100644
@@ -209,6 +209,11 @@ enum v4l2_colorfx {
  * We reserve 128 controls for this driver.
  */
 #define V4L2_CID_USER_CCS_BASE			(V4L2_CID_USER_BASE + 0x10f0)
+/*
+ * The base for HANTRO driver controls.
+ * We reserve 32 controls for this driver.
+ */
+#define V4L2_CID_USER_HANTRO_BASE		(V4L2_CID_USER_BASE + 0x1170)
 
 /* MPEG-class control IDs */
 /* The MPEG controls are applicable to all codec controls
Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#13 lore raw

Re: [PATCH v3 4/9] media: uapi: Add a control for HANTRO driver

Hi Benjamin,

Quoted 1 line · Benjamin Gaignard

The HEVC HANTRO driver needs to know the number of bits to skip at

s/HANTRO/Hantro

Quoted 1 line

the beginning of the slice header.

As discussed in a different thread, we should describe exactly what the hardware is expecting, so applications can parse that and pass a correct value.

Quoted 28 lines

That is a hardware specific requirement so create a dedicated control that this purpose.

---
version 3:
- Fix typo in field name

 include/uapi/linux/hantro-v4l2-controls.h | 20 ++++++++++++++++++++ include/uapi/linux/v4l2-controls.h        |  5 +++++

 2 files changed, 25 insertions(+)

 create mode 100644 include/uapi/linux/hantro-v4l2-controls.h

include/uapi/linux/hantro-v4l2-controls.h new file +9 -0
new file mode 100644
index 000000000000..a8dfd6b1a2a9
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#ifndef __UAPI_HANTRO_V4L2_CONYTROLS_H__
+#define __UAPI_HANTRO_V4L2_CONYTROLS_H__
+
+#include <linux/v4l2-controls.h>
+#include <media/hevc-ctrls.h>
+
+#define V4L2_CID_HANTRO_HEVC_EXTRA_DECODE_PARAMS       (V4L2_CID_USER_HANTRO_BASE + 0)

include/uapi/linux/hantro-v4l2-controls.h line 19

Quoted 10 lines
include/uapi/linux/hantro-v4l2-controls.h new file +10 -0
+
+/**
+ * struct hantro_hevc_extra_decode_params - extra decode parameters for hantro driver
+ * @hevc_hdr_skip_length:      header first bits offset
+ */
+struct hantro_hevc_extra_decode_params {
+       __u32   hevc_hdr_skip_length;
+       __u8    padding[4];
+};
+

I think we can get away with a simpler solution. Since it's just one integer we need, there's no need for a compound control. Something like this:

                .codec = HANTRO_HEVC_DECODER,                                    
                .cfg = {                                                         
                        .id = V4L2_CID_HANTRO_HEVC_SLICE_HEADER_SKIP,            
                        .name = "Hantro HEVC slice header skip bytes",           
                        .type = V4L2_CTRL_TYPE_INTEGER,                          
                        .min = 0,                                                
                        .max = 0x7fffffff,                                       
                        .step = 1,                                               
                },     

Also see V4L2_CID_CODA_MB_ERR_CNT which is defined in drivers/media/platform/coda/coda.h. The control is sufficiently special that it could be kept in an internal driver header.

Quoted 14 lines
include/uapi/linux/hantro-v4l2-controls.h new file +1 -0
+#endif
include/uapi/linux/v4l2-controls.h +5 -0
index 039c0d7add1b..ced7486c7f46 100644
@@ -209,6 +209,11 @@ enum v4l2_colorfx {
   * We reserve 128 controls for this driver.
   */
  #define V4L2_CID_USER_CCS_BASE                 (V4L2_CID_USER_BASE + 0x10f0)
+/*
+ * The base for HANTRO driver controls.
+ * We reserve 32 controls for this driver.
+ */
+#define V4L2_CID_USER_HANTRO_BASE              (V4L2_CID_USER_BASE + 0x1170)
Quoted 3 lines


 /* MPEG-class control IDs */
 /* The MPEG controls are applicable to all codec controls

Thanks,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author maintainer
#14 lore raw

PATCH v3 5/9 media: hantro: Introduce G2/HEVC decoder

In reply to Benjamin Gaignard

Implement all the logic to get G2 hardware decoding HEVC frames. It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning of the slice header. That is very specific to this hardware so can't go into uapi structures. Compute the needed value is complex and require information from the stream that only the userland knows so let it provide the correct value to the driver.

---
version 2:
- squash multiple commits in this one.
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic in tile_buffer_reallocate, rework some goto and return cases.

 drivers/staging/media/hantro/Makefile         |   2 +
 drivers/staging/media/hantro/hantro.h         |  19 +
 drivers/staging/media/hantro/hantro_drv.c     |  42 ++
 .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++++++++++++++++++
 drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++++++
 drivers/staging/media/hantro/hantro_hevc.c    | 321 ++++++++++
 drivers/staging/media/hantro/hantro_hw.h      |  47 ++
 7 files changed, 1216 insertions(+)
 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c
 create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h
 create mode 100644 drivers/staging/media/hantro/hantro_hevc.c
drivers/staging/media/hantro/Makefile +2 -0
index 743ce08eb184..0357f1772267 100644
@@ -9,12 +9,14 @@ hantro-vpu-y += \
 		hantro_h1_jpeg_enc.o \
 		hantro_g1_h264_dec.o \
 		hantro_g1_mpeg2_dec.o \
+		hantro_g2_hevc_dec.o \
 		hantro_g1_vp8_dec.o \
 		rk3399_vpu_hw_jpeg_enc.o \
 		rk3399_vpu_hw_mpeg2_dec.o \
 		rk3399_vpu_hw_vp8_dec.o \
 		hantro_jpeg.o \
 		hantro_h264.o \
+		hantro_hevc.o \
 		hantro_mpeg2.o \
 		hantro_vp8.o
 
drivers/staging/media/hantro/hantro.h +19 -0
index 352930bd49fc..a9b80b2c9124 100644
@@ -34,6 +34,7 @@ struct hantro_codec_ops;
 #define HANTRO_MPEG2_DECODER	BIT(16)
 #define HANTRO_VP8_DECODER	BIT(17)
 #define HANTRO_H264_DECODER	BIT(18)
+#define HANTRO_HEVC_DECODER	BIT(19)
 #define HANTRO_DECODERS		0xffff0000
 
 #define HANTRO_G1_REV		0x6731
@@ -224,6 +225,7 @@ struct hantro_dev {
  * @jpeg_enc:		JPEG-encoding context.
  * @mpeg2_dec:		MPEG-2-decoding context.
  * @vp8_dec:		VP8-decoding context.
+ * @hevc_dec:		HEVC-decoding context.
  */
 struct hantro_ctx {
 	struct hantro_dev *dev;
@@ -250,6 +252,7 @@ struct hantro_ctx {
 		struct hantro_jpeg_enc_hw_ctx jpeg_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;
 	};
 };
 
@@ -427,6 +430,22 @@ hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb)
 	return vb2_dma_contig_plane_dma_addr(vb, 0);
 }
 
+static inline size_t
+hantro_get_dec_buf_size(struct hantro_ctx *ctx, struct vb2_buffer *vb)
+{
+	if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
+		return ctx->postproc.dec_q[vb->index].size;
+	return vb2_plane_size(vb, 0);
+}
+
+static inline void *
+hantro_get_dec_buf(struct hantro_ctx *ctx, struct vb2_buffer *vb)
+{
+	if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt))
+		return ctx->postproc.dec_q[vb->index].cpu;
+	return vb2_plane_vaddr(vb, 0);
+}
+
 void hantro_postproc_disable(struct hantro_ctx *ctx);
 void hantro_postproc_enable(struct hantro_ctx *ctx);
 void hantro_postproc_free(struct hantro_ctx *ctx);
drivers/staging/media/hantro/hantro_drv.c +42 -0

60 lines not on this page · raw message

drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +587 -0

587 lines not on this page · raw message

drivers/staging/media/hantro/hantro_g2_regs.h new file +198 -0

198 lines not on this page · raw message

drivers/staging/media/hantro/hantro_hevc.c new file +321 -0

321 lines not on this page · raw message

drivers/staging/media/hantro/hantro_hw.h +47 -0

71 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#15 lore raw

Re: [PATCH v3 5/9] media: hantro: Introduce G2/HEVC decoder

Hi Benjamin,

Thanks for the good work!
I mostly have two concerns with this implementation, the tiled output and the allocation path.

More below.

Quoted 31 lines · Benjamin Gaignard

Implement all the logic to get G2 hardware decoding HEVC frames. It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning of the slice header. That is very specific to this hardware so can't go into uapi structures. Compute the needed value is complex and require information from the stream that only the userland knows so let it provide the correct value to the driver.

---
version 2:
- squash multiple commits in this one.
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic in tile_buffer_reallocate, rework some goto and return cases.

 drivers/staging/media/hantro/Makefile         |   2 + drivers/staging/media/hantro/hantro.h         |  19 + drivers/staging/media/hantro/hantro_drv.c     |  42 ++ .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++++++++++++++++++ drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++++++ drivers/staging/media/hantro/hantro_hevc.c    | 321 ++++++++++ drivers/staging/media/hantro/hantro_hw.h      |  47 ++

 7 files changed, 1216 insertions(+)

 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

[snip]

Quoted 20 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +20 -0
+
+static void set_buffers(struct hantro_ctx *ctx)
+{
+       struct vb2_v4l2_buffer *src_buf, *dst_buf;
+       struct hantro_dev *vpu = ctx->dev;
+       const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;
+       const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;
+       size_t cr_offset = hantro_hevc_chroma_offset(sps);
+       dma_addr_t src_dma, dst_dma;
+       u32 src_len, src_buf_len;
+
+       src_buf = hantro_get_src_buf(ctx);
+       dst_buf = hantro_get_dst_buf(ctx);
+
+       /* Source (stream) buffer. */
+       src_dma = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
+       src_len = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
+       src_buf_len = vb2_plane_size(&src_buf->vb2_buf, 0);
+
+       hantro_write_addr(vpu, HEVC_ADDR_STR, src_dma);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c line 514

Quoted 10 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +10 -0
+       hantro_reg_write(vpu, hevc_stream_len, src_len);
+       hantro_reg_write(vpu, hevc_strm_buffer_len, src_buf_len);
+       hantro_reg_write(vpu, hevc_strm_start_offset, 0);
+       hantro_reg_write(vpu, hevc_write_mvs_e, 1);
+
+       /* Destination (decoded frame) buffer. */
+       dst_dma = hantro_get_dec_buf_addr(ctx, &dst_buf->vb2_buf);
+
+       hantro_write_addr(vpu, HEVC_RASTER_SCAN, dst_dma);
+       hantro_write_addr(vpu, HEVC_RASTER_SCAN_CHR, dst_dma + cr_offset);

The way this is done the raster-scan output is the only
output, and the tiled ouput it kept entirely internal, in hantro_hevc_dec_hw_ctx.ref_bufs.

This means there's no way to expose tiled NV12 in i.MX8M VPU tiled format to userspace, which could be desirable for some use cases.

I'm not suggesting to actually expose tiled NV12 in this patch, but to prepare the driver to be able to support that easily in the future.

It should be possible to consider this detiling as post-processing, adding some code in hantro_postproc.c leveraging the existing post-proc support.

IOW, hantro_postproc_ctx.dec_q would hold the tiled output, hantro_postproc_enable() writes the raster-scan buffer destination address, and so on.

Quoted 31 lines

+       hantro_write_addr(vpu, HEVC_ADDR_TILE_SIZE, ctx->hevc_dec.tile_sizes.dma); +       hantro_write_addr(vpu, HEVC_TILE_FILTER, ctx->hevc_dec.tile_filter.dma); +       hantro_write_addr(vpu, HEVC_TILE_SAO, ctx->hevc_dec.tile_sao.dma); +       hantro_write_addr(vpu, HEVC_TILE_BSD, ctx->hevc_dec.tile_bsd.dma);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +27 -0
+}
+
+void hantro_g2_check_idle(struct hantro_dev *vpu)
+{
+       int i;
+
+       for (i = 0; i < 3; i++) {
+               u32 status;
+
+               /* Make sure the VPU is idle */
+               status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+               if (status & HEVC_REG_INTERRUPT_DEC_E) {
+                       pr_warn("%s: still enabled!!! resetting.\n", __func__);
+                       status |= HEVC_REG_INTERRUPT_DEC_ABORT_E | HEVC_REG_INTERRUPT_DEC_IRQ_DIS;
+                       vdpu_write(vpu, status, HEVC_REG_INTERRUPT);
+               }
+       }
+}
+
+void hantro_g2_hevc_dec_run(struct hantro_ctx *ctx)
+{
+       struct hantro_dev *vpu = ctx->dev;
+
+       hantro_g2_check_idle(vpu);
+
+       /* Prepare HEVC decoder context. */
+       if (hantro_hevc_dec_prepare_run(ctx))

drivers/staging/media/hantro/hantro_g2_hevc_dec.c line 555

Quoted 10 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +10 -0
+               return;
+
+       /* Configure hardware registers. */
+       set_params(ctx);
+
+       /* set reference pictures */
+       if (set_ref(ctx))
+               /* something goes wrong */
+               hantro_irq_done(vpu, VB2_BUF_STATE_ERROR);
+

I don't think we want to allow the _run() operation to fail like this. In other words, I would avoid allocating buffers in the _run() path, and doing all allocation at start() time.

That's why hantro_start_streaming() calls hantro_postproc_alloc() if needed.

Quoted 6 lines

+       set_buffers(ctx);
+       prepare_tile_info_buffer(ctx);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +4 -0
+
+       hantro_end_prepare_run(ctx);
+
+       hantro_reg_write(vpu, hevc_mode, HEVC_DEC_MODE);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c line 571

Quoted 10 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +10 -0
+       hantro_reg_write(vpu, hevc_clk_gate_e, 1);
+
+       /* Don't disable output */
+       hantro_reg_write(vpu, hevc_out_dis, 0);
+
+       /* Don't compress buffers */
+       hantro_reg_write(vpu, hevc_ref_compress_bypass, 1);
+
+       /* use NV12 as output format */
+       hantro_reg_write(vpu, hevc_tile_e, 0);

Unless I'm missing something, this ^

Quoted 5 lines

+       hantro_reg_write(vpu, hevc_out_rs_e, 1);

+       hantro_reg_write(vpu, hevc_num_tile_rows, 1); +       hantro_reg_write(vpu, hevc_num_tile_cols, 1); +

and this ^ these shouldn't be here.

HEVC tiles are handled already. See prepare_tile_info_buffer(). Note that HEVC "tiles" are not related to NV12 "tiled" format.

Thanks!
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author maintainer
#16 lore raw

Re: [PATCH v3 5/9] media: hantro: Introduce G2/HEVC decoder

Le 25/02/2021 à 18:55, Ezequiel Garcia a écrit :

Quoted 80 lines

Hi Benjamin,

Thanks for the good work!
I mostly have two concerns with this implementation, the tiled output and the allocation path.

More below.

Quoted 31 lines · Benjamin Gaignard

Implement all the logic to get G2 hardware decoding HEVC frames. It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning of the slice header. That is very specific to this hardware so can't go into uapi structures. Compute the needed value is complex and require information from the stream that only the userland knows so let it provide the correct value to the driver.

---
version 2:
- squash multiple commits in this one.
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic in tile_buffer_reallocate, rework some goto and return cases.

  drivers/staging/media/hantro/Makefile         |   2 +
  drivers/staging/media/hantro/hantro.h         |  19 +
  drivers/staging/media/hantro/hantro_drv.c     |  42 ++
  .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++++++++++++++++++
  drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++++++
  drivers/staging/media/hantro/hantro_hevc.c    | 321 ++++++++++
  drivers/staging/media/hantro/hantro_hw.h      |  47 ++
  7 files changed, 1216 insertions(+)

 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

[snip]

Quoted 20 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +20 -0
+
+static void set_buffers(struct hantro_ctx *ctx)
+{
+       struct vb2_v4l2_buffer *src_buf, *dst_buf;
+       struct hantro_dev *vpu = ctx->dev;
+       const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;
+       const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;
+       size_t cr_offset = hantro_hevc_chroma_offset(sps);
+       dma_addr_t src_dma, dst_dma;
+       u32 src_len, src_buf_len;
+
+       src_buf = hantro_get_src_buf(ctx);
+       dst_buf = hantro_get_dst_buf(ctx);
+
+       /* Source (stream) buffer. */
+       src_dma = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
+       src_len = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
+       src_buf_len = vb2_plane_size(&src_buf->vb2_buf, 0);
+
+       hantro_write_addr(vpu, HEVC_ADDR_STR, src_dma);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c line 514

Quoted 10 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +10 -0
+       hantro_reg_write(vpu, hevc_stream_len, src_len);
+       hantro_reg_write(vpu, hevc_strm_buffer_len, src_buf_len);
+       hantro_reg_write(vpu, hevc_strm_start_offset, 0);
+       hantro_reg_write(vpu, hevc_write_mvs_e, 1);
+
+       /* Destination (decoded frame) buffer. */
+       dst_dma = hantro_get_dec_buf_addr(ctx, &dst_buf->vb2_buf);
+
+       hantro_write_addr(vpu, HEVC_RASTER_SCAN, dst_dma);
+       hantro_write_addr(vpu, HEVC_RASTER_SCAN_CHR, dst_dma + cr_offset);

The way this is done the raster-scan output is the only
output, and the tiled ouput it kept entirely internal, in hantro_hevc_dec_hw_ctx.ref_bufs.

This means there's no way to expose tiled NV12 in i.MX8M VPU tiled format to userspace, which could be desirable for some use cases.

I'm not suggesting to actually expose tiled NV12 in this patch, but to prepare the driver to be able to support that easily in the future.

Quoted 7 lines

It should be possible to consider this detiling as post-processing, adding some code in hantro_postproc.c leveraging the existing post-proc support.

IOW, hantro_postproc_ctx.dec_q would hold the tiled output, hantro_postproc_enable() writes the raster-scan buffer destination address, and so on.

Well the G2 can't use the post-processor so I'm reluctant to do as if it was the case.

To support tiled NV12 for me the solution is to create a hantro_hevc_add_ref_buf() function to add the destination buffer in hevc_dec->ref_bufs.
We can test destination format to set hevc_out_rs_e bit and HEVC_RASTER_SCAN register.

Quoted 46 lines
Quoted 32 lines

+       hantro_write_addr(vpu, HEVC_ADDR_TILE_SIZE, ctx->hevc_dec.tile_sizes.dma); +       hantro_write_addr(vpu, HEVC_TILE_FILTER, ctx->hevc_dec.tile_filter.dma); +       hantro_write_addr(vpu, HEVC_TILE_SAO, ctx->hevc_dec.tile_sao.dma); +       hantro_write_addr(vpu, HEVC_TILE_BSD, ctx->hevc_dec.tile_bsd.dma);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +27 -0
+}
+
+void hantro_g2_check_idle(struct hantro_dev *vpu)
+{
+       int i;
+
+       for (i = 0; i < 3; i++) {
+               u32 status;
+
+               /* Make sure the VPU is idle */
+               status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+               if (status & HEVC_REG_INTERRUPT_DEC_E) {
+                       pr_warn("%s: still enabled!!! resetting.\n", __func__);
+                       status |= HEVC_REG_INTERRUPT_DEC_ABORT_E | HEVC_REG_INTERRUPT_DEC_IRQ_DIS;
+                       vdpu_write(vpu, status, HEVC_REG_INTERRUPT);
+               }
+       }
+}
+
+void hantro_g2_hevc_dec_run(struct hantro_ctx *ctx)
+{
+       struct hantro_dev *vpu = ctx->dev;
+
+       hantro_g2_check_idle(vpu);
+
+       /* Prepare HEVC decoder context. */
+       if (hantro_hevc_dec_prepare_run(ctx))

drivers/staging/media/hantro/hantro_g2_hevc_dec.c line 555

Quoted 10 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +10 -0
+               return;
+
+       /* Configure hardware registers. */
+       set_params(ctx);
+
+       /* set reference pictures */
+       if (set_ref(ctx))
+               /* something goes wrong */
+               hantro_irq_done(vpu, VB2_BUF_STATE_ERROR);
+

I don't think we want to allow the _run() operation to fail like this. In other words, I would avoid allocating buffers in the _run() path, and doing all allocation at start() time.

Quoted 1 line

That's why hantro_start_streaming() calls hantro_postproc_alloc() if needed.

The error could also be that the reference picture isn't found in the list so we can't perform the decode operation.
If we do the allocation at start time we will allocate all the reference frames buffers even if we don't know if we will use them. That could increase a lot memory usage. Note that buffers allocated once and re-used until the end of the session.

Quoted 19 lines
Quoted 7 lines

+       set_buffers(ctx);
+       prepare_tile_info_buffer(ctx);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +4 -0
+
+       hantro_end_prepare_run(ctx);
+
+       hantro_reg_write(vpu, hevc_mode, HEVC_DEC_MODE);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c line 571

Quoted 10 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +10 -0
+       hantro_reg_write(vpu, hevc_clk_gate_e, 1);
+
+       /* Don't disable output */
+       hantro_reg_write(vpu, hevc_out_dis, 0);
+
+       /* Don't compress buffers */
+       hantro_reg_write(vpu, hevc_ref_compress_bypass, 1);
+
+       /* use NV12 as output format */
+       hantro_reg_write(vpu, hevc_tile_e, 0);

Unless I'm missing something, this ^

Quoted 7 lines
Quoted 4 lines

+       hantro_reg_write(vpu, hevc_out_rs_e, 1); +       hantro_reg_write(vpu, hevc_num_tile_rows, 1); +       hantro_reg_write(vpu, hevc_num_tile_cols, 1); +

and this ^ these shouldn't be here.

HEVC tiles are handled already. See prepare_tile_info_buffer().

You are right, I will remove that, thanks.

Benjamin

Quoted 6 lines

Note that HEVC "tiles" are not related to NV12 "tiled" format.

Thanks!
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#17 lore raw

Re: [PATCH v3 5/9] media: hantro: Introduce G2/HEVC decoder

Quoted 86 lines · Benjamin Gaignard

Le 25/02/2021 à 18:55, Ezequiel Garcia a écrit :

Quoted 84 lines

Hi Benjamin,

Thanks for the good work!
I mostly have two concerns with this implementation, the tiled output and the allocation path.

More below.

Quoted 31 lines · Benjamin Gaignard

Implement all the logic to get G2 hardware decoding HEVC frames. It support up level 5.1 HEVC stream.
It doesn't support yet 10 bits formats or scaling feature.

Add HANTRO HEVC dedicated control to skip some bits at the beginning of the slice header. That is very specific to this hardware so can't go into uapi structures. Compute the needed value is complex and require information from the stream that only the userland knows so let it provide the correct value to the driver.

---
version 2:
- squash multiple commits in this one.
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic in tile_buffer_reallocate, rework some goto and return cases.

  drivers/staging/media/hantro/Makefile         |   2 + drivers/staging/media/hantro/hantro.h         |  19 + drivers/staging/media/hantro/hantro_drv.c     |  42 ++ .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++++++++++++++++++ drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++++++ drivers/staging/media/hantro/hantro_hevc.c    | 321 ++++++++++ drivers/staging/media/hantro/hantro_hw.h      |  47 ++

  7 files changed, 1216 insertions(+)

  create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h create mode 100644 drivers/staging/media/hantro/hantro_hevc.c

[snip]

Quoted 20 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +20 -0
+
+static void set_buffers(struct hantro_ctx *ctx)
+{
+       struct vb2_v4l2_buffer *src_buf, *dst_buf;
+       struct hantro_dev *vpu = ctx->dev;
+       const struct hantro_hevc_dec_ctrls *ctrls = &ctx->hevc_dec.ctrls;
+       const struct v4l2_ctrl_hevc_sps *sps = ctrls->sps;
+       size_t cr_offset = hantro_hevc_chroma_offset(sps);
+       dma_addr_t src_dma, dst_dma;
+       u32 src_len, src_buf_len;
+
+       src_buf = hantro_get_src_buf(ctx);
+       dst_buf = hantro_get_dst_buf(ctx);
+
+       /* Source (stream) buffer. */
+       src_dma = vb2_dma_contig_plane_dma_addr(&src_buf->vb2_buf, 0);
+       src_len = vb2_get_plane_payload(&src_buf->vb2_buf, 0);
+       src_buf_len = vb2_plane_size(&src_buf->vb2_buf, 0);
+
+       hantro_write_addr(vpu, HEVC_ADDR_STR, src_dma);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c line 514

Quoted 10 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +10 -0
+       hantro_reg_write(vpu, hevc_stream_len, src_len);
+       hantro_reg_write(vpu, hevc_strm_buffer_len, src_buf_len);
+       hantro_reg_write(vpu, hevc_strm_start_offset, 0);
+       hantro_reg_write(vpu, hevc_write_mvs_e, 1);
+
+       /* Destination (decoded frame) buffer. */
+       dst_dma = hantro_get_dec_buf_addr(ctx, &dst_buf->vb2_buf);
+
+       hantro_write_addr(vpu, HEVC_RASTER_SCAN, dst_dma);
+       hantro_write_addr(vpu, HEVC_RASTER_SCAN_CHR, dst_dma + cr_offset);

The way this is done the raster-scan output is the only
output, and the tiled ouput it kept entirely internal, in hantro_hevc_dec_hw_ctx.ref_bufs.

This means there's no way to expose tiled NV12 in i.MX8M VPU tiled format to userspace, which could be desirable for some use cases.

I'm not suggesting to actually expose tiled NV12 in this patch, but to prepare the driver to be able to support that easily in the future.

It should be possible to consider this detiling as post-processing, adding some code in hantro_postproc.c leveraging the existing post-proc support.

Quoted 6 lines
Quoted 3 lines

IOW, hantro_postproc_ctx.dec_q would hold the tiled output, hantro_postproc_enable() writes the raster-scan buffer destination address, and so on.

Well the G2 can't use the post-processor so I'm reluctant to do as if it was the case.

I don't really see a big difference between G1 post-processing, and G2 raster-scan detiling. As a user of the device, both features offer a post-processing.

In any case, it's not a big deal, it's fine as-is if you are inclined to this implementation.

Quoted 4 lines

To support tiled NV12 for me the solution is to create a hantro_hevc_add_ref_buf() function to add the destination buffer in hevc_dec->ref_bufs.
We can test destination format to set hevc_out_rs_e bit and HEVC_RASTER_SCAN register.

Is it worth adding some boilerplate and/or refactoring things a bit, so it's easier to expose tiled NV12 once that format is exposable?

Quoted 46 lines
Quoted 46 lines
Quoted 32 lines

+       hantro_write_addr(vpu, HEVC_ADDR_TILE_SIZE, ctx->hevc_dec.tile_sizes.dma); +       hantro_write_addr(vpu, HEVC_TILE_FILTER, ctx->hevc_dec.tile_filter.dma); +       hantro_write_addr(vpu, HEVC_TILE_SAO, ctx->hevc_dec.tile_sao.dma); +       hantro_write_addr(vpu, HEVC_TILE_BSD, ctx->hevc_dec.tile_bsd.dma);

drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +27 -0
+}
+
+void hantro_g2_check_idle(struct hantro_dev *vpu)
+{
+       int i;
+
+       for (i = 0; i < 3; i++) {
+               u32 status;
+
+               /* Make sure the VPU is idle */
+               status = vdpu_read(vpu, HEVC_REG_INTERRUPT);
+               if (status & HEVC_REG_INTERRUPT_DEC_E) {
+                       pr_warn("%s: still enabled!!! resetting.\n", __func__);
+                       status |= HEVC_REG_INTERRUPT_DEC_ABORT_E | HEVC_REG_INTERRUPT_DEC_IRQ_DIS;
+                       vdpu_write(vpu, status, HEVC_REG_INTERRUPT);
+               }
+       }
+}
+
+void hantro_g2_hevc_dec_run(struct hantro_ctx *ctx)
+{
+       struct hantro_dev *vpu = ctx->dev;
+
+       hantro_g2_check_idle(vpu);
+
+       /* Prepare HEVC decoder context. */
+       if (hantro_hevc_dec_prepare_run(ctx))

drivers/staging/media/hantro/hantro_g2_hevc_dec.c line 555

Quoted 10 lines
drivers/staging/media/hantro/hantro_g2_hevc_dec.c new file +10 -0
+               return;
+
+       /* Configure hardware registers. */
+       set_params(ctx);
+
+       /* set reference pictures */
+       if (set_ref(ctx))
+               /* something goes wrong */
+               hantro_irq_done(vpu, VB2_BUF_STATE_ERROR);
+

I don't think we want to allow the _run() operation to fail like this. In other words, I would avoid allocating buffers in the _run() path, and doing all allocation at start() time.

Quoted 9 lines
Quoted 1 line

That's why hantro_start_streaming() calls hantro_postproc_alloc() if needed.

The error could also be that the reference picture isn't found in the list so we can't perform the decode operation.
If we do the allocation at start time we will allocate all the reference frames buffers even if we don't know if we will use them. That could increase a lot memory usage. Note that buffers allocated once and re-used until the end of the session.

Improving memory usage is a good point. I wonder if it makes sense to release some buffers under some condition, instead of keeping then allocated (and unused) until the end of the session.

(BTW, the same can be done with the post-processor, as it's basically the same process. It would be interesting to explore.)

I'm still unsure why we'd call hantro_irq_done() (which cancels the timeout handler and returns buffers to userspace), but we would keep programming the operation.

Thanks,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author maintainer
#18 lore raw

PATCH v3 6/9 media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control

In reply to Benjamin Gaignard

Make sure that V4L2_PIX_FMT_HEVC_SLICE is correctly handle by v4l2 of the driver.

---
 drivers/staging/media/hantro/hantro_v4l2.c | 1 +
 1 file changed, 1 insertion(+)
drivers/staging/media/hantro/hantro_v4l2.c +1 -0
index 1bc118e375a1..e16d5fd0b9f7 100644
@@ -390,6 +390,7 @@ hantro_update_requires_request(struct hantro_ctx *ctx, u32 fourcc)
 	case V4L2_PIX_FMT_MPEG2_SLICE:
 	case V4L2_PIX_FMT_VP8_FRAME:
 	case V4L2_PIX_FMT_H264_SLICE:
+	case V4L2_PIX_FMT_HEVC_SLICE:
 		ctx->fh.m2m_ctx->out_q_ctx.q.requires_requests = true;
 		break;
 	default:
Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author maintainer
#19 lore raw

PATCH v3 7/9 media: hantro: IMX8M: add variant for G2/HEVC codec

In reply to Benjamin Gaignard

Add variant to IMX8M to enable G2/HEVC codec.
Define the capabilities for the hardware up to 3840x2160. Retrieve the hardware version at init to distinguish G1 from G2.

---
version 2:
- remove useless clocks

 drivers/staging/media/hantro/hantro_drv.c   |  1 +
 drivers/staging/media/hantro/hantro_hw.h    |  1 +
 drivers/staging/media/hantro/imx8m_vpu_hw.c | 95 ++++++++++++++++++++-
 3 files changed, 93 insertions(+), 4 deletions(-)
drivers/staging/media/hantro/hantro_drv.c +1 -0
index c009941dff3e..b6eb933b008c 100644
@@ -578,6 +578,7 @@ static const struct of_device_id of_hantro_match[] = {
 #endif
 #ifdef CONFIG_VIDEO_HANTRO_IMX8M
 	{ .compatible = "nxp,imx8mq-vpu", .data = &imx8mq_vpu_variant, },
+	{ .compatible = "nxp,imx8mq-vpu-g2", .data = &imx8mq_vpu_g2_variant },
 #endif
 	{ /* sentinel */ }
 };
drivers/staging/media/hantro/hantro_hw.h +1 -0
index 82e19b477173..77d6c065cea1 100644
@@ -190,6 +190,7 @@ extern const struct hantro_variant rk3399_vpu_variant;
 extern const struct hantro_variant rk3328_vpu_variant;
 extern const struct hantro_variant rk3288_vpu_variant;
 extern const struct hantro_variant imx8mq_vpu_variant;
+extern const struct hantro_variant imx8mq_vpu_g2_variant;
 
 extern const struct hantro_postproc_regs hantro_g1_postproc_regs;
 
drivers/staging/media/hantro/imx8m_vpu_hw.c +91 -4

132 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
author maintainer
#20 lore raw

PATCH v3 8/9 dt-bindings: media: nxp,imx8mq-vpu: Update bindings

In reply to Benjamin Gaignard

The current bindings seem to make the assumption that the two VPUs hardware blocks (G1 and G2) are only one set of registers.
After implementing the VPU reset driver and G2 decoder driver it shows that all the VPUs are independent and don't need to know about the registers of the other blocks.
Remove from the bindings the need to set all blocks register but keep reg-names property because removing it from the driver may affect other variants.

---
version 2:
- be more verbose about why I change the bindings
Keep in mind that series comes after: https://www.spinics.net/lists/arm-kernel/msg875766.html
without that review and ack it won't work

 .../bindings/media/nxp,imx8mq-vpu.yaml        | 54 ++++++++++++-------
 1 file changed, 36 insertions(+), 18 deletions(-)
Documentation/devicetree/bindings/media/nxp,imx8mq-vpu.yaml +36 -18
index 762be3f96ce9..468435c70eef 100644
@@ -15,24 +15,25 @@ description:
 
 properties:
   compatible:
-    const: nxp,imx8mq-vpu
+    enum:
+      - nxp,imx8mq-vpu
+      - nxp,imx8mq-vpu-g2
 
   reg:
-    maxItems: 3
+    maxItems: 1
 
   reg-names:
-    items:
-      - const: g1
-      - const: g2
-      - const: ctrl
+    enum:
+      - g1
+      - g2
 
   interrupts:
-    maxItems: 2
+    maxItems: 1
 
   interrupt-names:
-    items:
-      - const: g1
-      - const: g2
+    enum:
+      - g1
+      - g2
 
   clocks:
     maxItems: 3
@@ -46,6 +47,9 @@ properties:
   power-domains:
     maxItems: 1
 
+  resets:
+    maxItems: 1
+
 required:
   - compatible
   - reg
@@ -54,6 +58,7 @@ required:
   - interrupt-names
   - clocks
   - clock-names
+  - resets
 
 additionalProperties: false
 
@@ -61,19 +66,32 @@ examples:
   - |
         #include <dt-bindings/clock/imx8mq-clock.h>
         #include <dt-bindings/interrupt-controller/arm-gic.h>
+        #include <dt-bindings/reset/imx8mq-vpu-reset.h>
 
-        vpu: video-codec@38300000 {
+        vpu_g1: video-codec@38300000 {
                 compatible = "nxp,imx8mq-vpu";
-                reg = <0x38300000 0x10000>,
-                      <0x38310000 0x10000>,
-                      <0x38320000 0x10000>;
-                reg-names = "g1", "g2", "ctrl";
-                interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>,
-                             <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
-                interrupt-names = "g1", "g2";
+                reg = <0x38300000 0x10000>;
+                reg-names = "g1";
+                interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
+                interrupt-names = "g1";
+                clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
+                         <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
+                         <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
+                clock-names = "g1", "g2", "bus";
+                power-domains = <&pgc_vpu>;
+                resets = <&vpu_reset IMX8MQ_RESET_VPU_RESET_G1>;
+        };
+
+        vpu_g2: video-codec@38310000 {
+                compatible = "nxp,imx8mq-vpu-g2";
+                reg = <0x38310000 0x10000>;
+                reg-names = "g2";
+                interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
+                interrupt-names = "g2";
                 clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
                          <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
                          <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
                 clock-names = "g1", "g2", "bus";
                 power-domains = <&pgc_vpu>;
+                resets = <&vpu_reset IMX8MQ_RESET_VPU_RESET_G2>;
         };
Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
maintainer
#21 lore raw

Re: [PATCH v3 8/9] dt-bindings: media: nxp,imx8mq-vpu: Update bindings

Quoted 10 lines · Benjamin Gaignard

The current bindings seem to make the assumption that the two VPUs hardware blocks (G1 and G2) are only one set of registers.
After implementing the VPU reset driver and G2 decoder driver it shows that all the VPUs are independent and don't need to know about the registers of the other blocks.
Remove from the bindings the need to set all blocks register but keep reg-names property because removing it from the driver may affect other variants.

Quoted 6 lines

---
version 2:
- be more verbose about why I change the bindings
Keep in mind that series comes after: https://www.spinics.net/lists/arm-kernel/msg875766.html
without that review and ack it won't work

Better, but you've still mentioned nothing about breaking compatibility. Why is that okay?

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author maintainer
#22 lore raw

Re: [PATCH v3 8/9] dt-bindings: media: nxp,imx8mq-vpu: Update bindings

Le 23/02/2021 à 01:34, Rob Herring a écrit :

Quoted 11 lines · Benjamin Gaignard
Quoted 10 lines

The current bindings seem to make the assumption that the two VPUs hardware blocks (G1 and G2) are only one set of registers.
After implementing the VPU reset driver and G2 decoder driver it shows that all the VPUs are independent and don't need to know about the registers of the other blocks.
Remove from the bindings the need to set all blocks register but keep reg-names property because removing it from the driver may affect other variants.

Quoted 8 lines
Quoted 6 lines

---
version 2:
- be more verbose about why I change the bindings
Keep in mind that series comes after: https://www.spinics.net/lists/arm-kernel/msg875766.html
without that review and ack it won't work

Better, but you've still mentioned nothing about breaking compatibility. Why is that okay?

Because this reg-names wasn't used before for this variant so remove it won't change anything.

Quoted 1 line

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

maintainer
#23 lore raw

Re: [PATCH v3 8/9] dt-bindings: media: nxp,imx8mq-vpu: Update bindings

Quoted 20 lines · Benjamin Gaignard
Quoted 17 lines · Rob Herring
Quoted 16 lines · Benjamin Gaignard

The current bindings seem to make the assumption that the two VPUs hardware blocks (G1 and G2) are only one set of registers.
After implementing the VPU reset driver and G2 decoder driver it shows that all the VPUs are independent and don't need to know about the registers of the other blocks.
Remove from the bindings the need to set all blocks register but keep reg-names property because removing it from the driver may affect other variants.

---
version 2:
- be more verbose about why I change the bindings
Keep in mind that series comes after: https://www.spinics.net/lists/arm-kernel/msg875766.html
without that review and ack it won't work

Quoted 4 lines
Quoted 2 lines

Better, but you've still mentioned nothing about breaking compatibility. Why is that okay?

Because this reg-names wasn't used before for this variant so remove it won't change anything.

It is the reset changes in the driver that break. The driver previously got the 'ctrl' registers whether it went by name or index, right? With an old DTB and a kernel with the changes (and vice-versa), you'll have nothing to handle the VPU resets because the VPU reset node doesn't exist. It could work if the default state is not held in reset.

At least the removal of 'ctrl' registers belongs in the reset changes series.

Rob

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#24 lore raw

Re: [PATCH v3 8/9] dt-bindings: media: nxp,imx8mq-vpu: Update bindings

Hi Rob,

Quoted 22 lines · Rob Herring
Quoted 20 lines · Benjamin Gaignard
Quoted 17 lines · Rob Herring
Quoted 16 lines · Benjamin Gaignard

The current bindings seem to make the assumption that the two VPUs hardware blocks (G1 and G2) are only one set of registers.
After implementing the VPU reset driver and G2 decoder driver it shows that all the VPUs are independent and don't need to know about the registers of the other blocks.
Remove from the bindings the need to set all blocks register but keep reg-names property because removing it from the driver may affect other variants.

---
version 2:
- be more verbose about why I change the bindings
Keep in mind that series comes after: https://www.spinics.net/lists/arm-kernel/msg875766.html
without that review and ack it won't work

Quoted 3 lines
Quoted 3 lines
Quoted 2 lines

Better, but you've still mentioned nothing about breaking compatibility. Why is that okay?

Indeed, the commit description should be clearer about breaking compatibility.

Quoted 12 lines
Quoted 1 line

Because this reg-names wasn't used before for this variant so remove it won't change anything.

It is the reset changes in the driver that break. The driver previously got the 'ctrl' registers whether it went by name or index, right? With an old DTB and a kernel with the changes (and vice-versa), you'll have nothing to handle the VPU resets because the VPU reset node doesn't exist. It could work if the default state is not held in reset.

At least the removal of 'ctrl' registers belongs in the reset changes series.

Considering that FFMPEG patches that are required to support this driver are still floating around, and GStreamer's implementation is also still a bit under discussion, we are certain there aren't many upstreams users (leaving ChromiumOS aside which mostly care for Rockchip variants).

So, given the driver is in staging, and that there aren't users of the i.MX8MQ G1 variant just yet, I think we are safe breaking the compatibility (and I'm not taking it lightly).

It would be important to detect an old devicetree and do some pr_warn about the driver not supporting it.

Thanks,
Ezequiel

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

author maintainer
#25 lore raw

PATCH v3 9/9 arm64: dts: imx8mq: Add node to G2 hardware

In reply to Benjamin Gaignard

Split VPU node in two: one for G1 and one for G2 since they are different hardware blocks.

---
version 2:
- remove useless clocks in VPUs nodes

 arch/arm64/boot/dts/freescale/imx8mq.dtsi | 41 +++++++++++++++++------
 1 file changed, 31 insertions(+), 10 deletions(-)
arch/arm64/boot/dts/freescale/imx8mq.dtsi +31 -10
index d9d9efc8592d..8358e214d696 100644
@@ -1287,17 +1287,15 @@ vpu_reset: vpu-reset@38320000 {
 			#reset-cells = <1>;
 		};
 
-		vpu: video-codec@38300000 {
+		vpu_g1: video-codec@38300000 {
 			compatible = "nxp,imx8mq-vpu";
-			reg = <0x38300000 0x10000>,
-			      <0x38310000 0x10000>;
-			reg-names = "g1", "g2";
-			interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>,
-				     <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
-			interrupt-names = "g1", "g2";
+			reg = <0x38300000 0x10000>;
+			reg-names = "g1";
+			interrupts = <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "g1";
 			clocks = <&clk IMX8MQ_CLK_VPU_G1_ROOT>,
-				 <&clk IMX8MQ_CLK_VPU_G2_ROOT>;
-			clock-names = "g1", "g2";
+				 <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
+			clock-names = "g1", "bus";
 			assigned-clocks = <&clk IMX8MQ_CLK_VPU_G1>,
 					  <&clk IMX8MQ_CLK_VPU_G2>,
 					  <&clk IMX8MQ_CLK_VPU_BUS>,
@@ -1306,12 +1304,35 @@ vpu: video-codec@38300000 {
 						 <&clk IMX8MQ_VPU_PLL_OUT>,
 						 <&clk IMX8MQ_SYS1_PLL_800M>,
 						 <&clk IMX8MQ_VPU_PLL>;
-			assigned-clock-rates = <600000000>, <600000000>,
+			assigned-clock-rates = <600000000>, <300000000>,
 					       <800000000>, <0>;
 			resets = <&vpu_reset IMX8MQ_RESET_VPU_RESET_G1>;
 			power-domains = <&pgc_vpu>;
 		};
 
+		vpu_g2: video-codec@38310000 {
+			compatible = "nxp,imx8mq-vpu-g2";
+			reg = <0x38310000 0x10000>;
+			reg-names = "g2";
+			interrupts = <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>;
+			interrupt-names = "g2";
+			clocks = <&clk IMX8MQ_CLK_VPU_G2_ROOT>,
+				 <&clk IMX8MQ_CLK_VPU_DEC_ROOT>;
+			clock-names = "g2",  "bus";
+			assigned-clocks = <&clk IMX8MQ_CLK_VPU_G1>,
+					  <&clk IMX8MQ_CLK_VPU_G2>,
+					  <&clk IMX8MQ_CLK_VPU_BUS>,
+					  <&clk IMX8MQ_VPU_PLL_BYPASS>;
+			assigned-clock-parents = <&clk IMX8MQ_VPU_PLL_OUT>,
+						 <&clk IMX8MQ_VPU_PLL_OUT>,
+						 <&clk IMX8MQ_SYS1_PLL_800M>,
+						 <&clk IMX8MQ_VPU_PLL>;
+			assigned-clock-rates = <600000000>, <300000000>,
+					       <800000000>, <0>;
+			resets = <&vpu_reset IMX8MQ_RESET_VPU_RESET_G2>;
+			power-domains = <&pgc_vpu>;
+		};
+
 		pcie0: pcie@33800000 {
 			compatible = "fsl,imx8mq-pcie";
 			reg = <0x33800000 0x400000>,
Signature · 7 lines
2.25.1


_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
#26 lore raw
In reply to Benjamin Gaignard

Hi Benjamin,

Quoted 27 lines · Benjamin Gaignard

The IMX8MQ got two VPUs but until now only G1 has been enabled. This series aim to add the second VPU (aka G2) and provide basic HEVC decoding support.

To be able to decode HEVC it is needed to add/update some of the structures in the uapi. In addition of them one HANTRO dedicated control is required to inform the driver of the numbre of bits to skip at the beginning of the slice header.
The hardware require to allocate few auxiliary buffers to store the references frame or tile size data.

The driver has been tested with fluster test suite stream.
For example with this command: ./fluster.py run -ts JCT-VC-HEVC_V1 -d GStreamer-H.265-V4L2SL-Gst1.0
This series depends of the reset rework posted here: https://www.spinics.net/lists/arm-kernel/msg875766.html

Finally the both VPUs will have a node the device-tree and be independent from v4l2 point of view.

A branch with all the dev is available here:
https://gitlab.collabora.com/benjamin.gaignard/for-upstream/-/commits/upstream_g2_v2

version 3:
- Fix typo in Hantro v4l2 dedicated control
- Add documentation for the new structures and fields
- Rebased on top of media_tree for-linus-5.12-rc1 tag

Quoted 9 lines

version 2:
- remove all change related to scaling
- squash commits to a coherent split
- be more verbose about the added fields
- fix the comments done by Ezequiel about dma_alloc_coherent usage
- fix Dan's comments about control copy, reverse the test logic in tile_buffer_reallocate, rework some goto and return cases.
- be more verbose about why I change the bindings
- remove all sign-off expect mime since it is confusing

I don't think it's about having less confusing commits, but trying to describe fairly accurately the origin of the work and the authorship of changes.

In this series I believe we have three cases, please correct me if I'm wrong:

* Changes that you have authored, for instance it would seem to me that "dt-bindings: media: nxp,imx8mq-vpu: Update bindings", and "media: uapi: Add a control for HANTRO driver" would be in that category.

* Changes that Adrian and/or me have initially authored, where both Adrian and me did further work, and also where you did significant work on as well.

IOW, changes where the three of us did significant work.

I guess in this case, the original author could be the author of the patch (git's Author tag), and additionally authorship would be indicated with Co-developed-by tags.

commit 494adacd844e5656b570895a82bc343438b23023
Author: Adrian Ratiu <[email protected]>
Date: Thu Feb 18 12:17:37 2021 +0100

media: hantro: Introduce G2/HEVC decoder

...

* And finally changes with an original author (Adrian or me), which you haven't changed, but you are just submitting (or you did minor work).

Maybe with the current way of splitting commits we don't have these type of patches, but just for the sake of it, let's say there's a commit authored by Adrian that you are mostly picking up, it would be:

commit 896776d3bcd032808e4d5772e6749da5dd4eec42

Author: Adrian Ratiu <[email protected]>
Date:   Fri Feb 5 12:14:16 2021 +0100

media: hantro: Some change

...

Thanks a lot!
Ezequiel

Quoted 37 lines

- remove useless clocks in VPUs nodes

Benjamin

Benjamin Gaignard (9):
  media: hevc: Modify structures to follow H265 ITU spec
  media: hantro: Define HEVC codec profiles and supported features
  media: hantro: Add a field to distinguish the hardware versions
  media: uapi: Add a control for HANTRO driver
  media: hantro: Introduce G2/HEVC decoder
  media: hantro: handle V4L2_PIX_FMT_HEVC_SLICE control
  media: hantro: IMX8M: add variant for G2/HEVC codec
  dt-bindings: media: nxp,imx8mq-vpu: Update bindings
  arm64: dts: imx8mq: Add node to G2 hardware

 .../bindings/media/nxp,imx8mq-vpu.yaml        |  54 +- .../media/v4l/ext-ctrls-codec.rst             | 126 +++- .../media/v4l/vidioc-queryctrl.rst            |   6 + arch/arm64/boot/dts/freescale/imx8mq.dtsi     |  41 +- drivers/media/v4l2-core/v4l2-ctrls.c          |  26 +- drivers/staging/media/hantro/Makefile         |   2 + drivers/staging/media/hantro/hantro.h         |  34 +- drivers/staging/media/hantro/hantro_drv.c     | 103 +++ .../staging/media/hantro/hantro_g2_hevc_dec.c | 587 ++++++++++++++++++ drivers/staging/media/hantro/hantro_g2_regs.h | 198 ++++++ drivers/staging/media/hantro/hantro_hevc.c    | 321 ++++++++++ drivers/staging/media/hantro/hantro_hw.h      |  48 ++ .../staging/media/hantro/hantro_postproc.c    |  17 + drivers/staging/media/hantro/hantro_v4l2.c    |   1 +

 drivers/staging/media/hantro/imx8m_vpu_hw.c   |  95 ++-
 drivers/staging/media/sunxi/cedrus/cedrus.c   |   6 +
 drivers/staging/media/sunxi/cedrus/cedrus.h   |   1 +
 .../staging/media/sunxi/cedrus/cedrus_dec.c   |   2 +

 .../staging/media/sunxi/cedrus/cedrus_h265.c  |   6 +- include/media/hevc-ctrls.h                    |  45 +- include/uapi/linux/hantro-v4l2-controls.h     |  20 + include/uapi/linux/v4l2-controls.h            |   5 +

Quoted 6 lines
 22 files changed, 1674 insertions(+), 70 deletions(-)

 create mode 100644 drivers/staging/media/hantro/hantro_g2_hevc_dec.c create mode 100644 drivers/staging/media/hantro/hantro_g2_regs.h create mode 100644 drivers/staging/media/hantro/hantro_hevc.c create mode 100644 include/uapi/linux/hantro-v4l2-controls.h

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip