linux-sunxi.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] media: cedrus: hevc: add support for multiple slices
@ 2021-06-06  8:23 Jernej Skrabec
  2021-06-06  8:23 ` [PATCH 1/2] media: hevc: Add segment address field Jernej Skrabec
  2021-06-06  8:23 ` [PATCH 2/2] media: cedrus: hevc: Add support for multiple slices Jernej Skrabec
  0 siblings, 2 replies; 4+ messages in thread
From: Jernej Skrabec @ 2021-06-06  8:23 UTC (permalink / raw)
  To: mripard, paul.kocialkowski
  Cc: mchehab, gregkh, wens, hverkuil-cisco, ezequiel,
	benjamin.gaignard, linux-media, linux-staging, linux-arm-kernel,
	linux-sunxi, linux-kernel, Jernej Skrabec

HEVC frames can be encoded in multiple slices. This short series add
supports for them. First patch adds slice_segment_address to HEVC slice
parameters and second patch implements HEVC multi slice support in
Cedrus.

Question 1: HEVC specs talk about slice_segment_address, but "slice_"
prefix seems redundant in our case, because this field is part of slice
params structure. Should I drop it or leave it?

Question 2: I made slice_segment_address __u32 but __u16 might be
already enough. Which one should it be?

Note: These patches depends on following pull request:
https://www.spinics.net/lists/linux-media/msg193744.html

Jernej Skrabec (2):
  media: hevc: Add segment address field
  media: cedrus: hevc: Add support for multiple slices

 .../media/v4l/ext-ctrls-codec.rst             |  3 +++
 .../staging/media/sunxi/cedrus/cedrus_h265.c  | 26 ++++++++++++-------
 .../staging/media/sunxi/cedrus/cedrus_video.c |  1 +
 include/media/hevc-ctrls.h                    |  3 ++-
 4 files changed, 22 insertions(+), 11 deletions(-)

-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] media: hevc: Add segment address field
  2021-06-06  8:23 [PATCH 0/2] media: cedrus: hevc: add support for multiple slices Jernej Skrabec
@ 2021-06-06  8:23 ` Jernej Skrabec
  2021-06-07  7:43   ` Benjamin Gaignard
  2021-06-06  8:23 ` [PATCH 2/2] media: cedrus: hevc: Add support for multiple slices Jernej Skrabec
  1 sibling, 1 reply; 4+ messages in thread
From: Jernej Skrabec @ 2021-06-06  8:23 UTC (permalink / raw)
  To: mripard, paul.kocialkowski
  Cc: mchehab, gregkh, wens, hverkuil-cisco, ezequiel,
	benjamin.gaignard, linux-media, linux-staging, linux-arm-kernel,
	linux-sunxi, linux-kernel, Jernej Skrabec

If HEVC frame consists of multiple slices, segment address has to be
known in order to properly decode it.

Add segment address field to slice parameters.

Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
 Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst | 3 +++
 include/media/hevc-ctrls.h                                | 3 ++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
index 9120c5bcaf90..fac4b477da82 100644
--- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
+++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
@@ -2997,6 +2997,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
     * - __u8
       - ``pic_struct``
       -
+    * - __u32
+      - ``slice_segment_addr``
+      -
     * - __u8
       - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
       - The list of L0 reference elements as indices in the DPB.
diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
index dc964ff7cd29..19f8e2ad3375 100644
--- a/include/media/hevc-ctrls.h
+++ b/include/media/hevc-ctrls.h
@@ -197,10 +197,11 @@ struct v4l2_ctrl_hevc_slice_params {
 	__u8	pic_struct;
 
 	/* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
+	__u32	slice_segment_addr;
 	__u8	ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
 	__u8	ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
 
-	__u8	padding[5];
+	__u8	padding;
 
 	/* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */
 	struct v4l2_hevc_pred_weight_table pred_weight_table;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/2] media: cedrus: hevc: Add support for multiple slices
  2021-06-06  8:23 [PATCH 0/2] media: cedrus: hevc: add support for multiple slices Jernej Skrabec
  2021-06-06  8:23 ` [PATCH 1/2] media: hevc: Add segment address field Jernej Skrabec
@ 2021-06-06  8:23 ` Jernej Skrabec
  1 sibling, 0 replies; 4+ messages in thread
From: Jernej Skrabec @ 2021-06-06  8:23 UTC (permalink / raw)
  To: mripard, paul.kocialkowski
  Cc: mchehab, gregkh, wens, hverkuil-cisco, ezequiel,
	benjamin.gaignard, linux-media, linux-staging, linux-arm-kernel,
	linux-sunxi, linux-kernel, Jernej Skrabec

Now that segment address is available, support for multi-slice frames
can be easily added.

Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
---
 .../staging/media/sunxi/cedrus/cedrus_h265.c  | 26 ++++++++++++-------
 .../staging/media/sunxi/cedrus/cedrus_video.c |  1 +
 2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
index 6821e3d05d34..ef0311a16d01 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
@@ -247,6 +247,8 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 	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;
+	unsigned int width_in_ctb_luma, ctb_size_luma;
+	unsigned int log2_max_luma_coding_block_size;
 	dma_addr_t src_buf_addr;
 	dma_addr_t src_buf_end_addr;
 	u32 chroma_log2_weight_denom;
@@ -260,15 +262,17 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 	decode_params = run->h265.decode_params;
 	pred_weight_table = &slice_params->pred_weight_table;
 
+	log2_max_luma_coding_block_size =
+		sps->log2_min_luma_coding_block_size_minus3 + 3 +
+		sps->log2_diff_max_min_luma_coding_block_size;
+	ctb_size_luma = 1UL << log2_max_luma_coding_block_size;
+	width_in_ctb_luma =
+		DIV_ROUND_UP(sps->pic_width_in_luma_samples, ctb_size_luma);
+
 	/* MV column buffer size and allocation. */
 	if (!ctx->codec.h265.mv_col_buf_size) {
 		unsigned int num_buffers =
 			run->dst->vb2_buf.vb2_queue->num_buffers;
-		unsigned int log2_max_luma_coding_block_size =
-			sps->log2_min_luma_coding_block_size_minus3 + 3 +
-			sps->log2_diff_max_min_luma_coding_block_size;
-		unsigned int ctb_size_luma =
-			1UL << log2_max_luma_coding_block_size;
 
 		/*
 		 * Each CTB requires a MV col buffer with a specific unit size.
@@ -322,15 +326,17 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 	reg = VE_DEC_H265_BITS_END_ADDR_BASE(src_buf_end_addr);
 	cedrus_write(dev, VE_DEC_H265_BITS_END_ADDR, reg);
 
-	/* Coding tree block address: start at the beginning. */
-	reg = VE_DEC_H265_DEC_CTB_ADDR_X(0) | VE_DEC_H265_DEC_CTB_ADDR_Y(0);
+	/* Coding tree block address */
+	reg = VE_DEC_H265_DEC_CTB_ADDR_X(slice_params->slice_segment_addr % width_in_ctb_luma);
+	reg |= VE_DEC_H265_DEC_CTB_ADDR_Y(slice_params->slice_segment_addr / width_in_ctb_luma);
 	cedrus_write(dev, VE_DEC_H265_DEC_CTB_ADDR, reg);
 
 	cedrus_write(dev, VE_DEC_H265_TILE_START_CTB, 0);
 	cedrus_write(dev, VE_DEC_H265_TILE_END_CTB, 0);
 
 	/* Clear the number of correctly-decoded coding tree blocks. */
-	cedrus_write(dev, VE_DEC_H265_DEC_CTB_NUM, 0);
+	if (ctx->fh.m2m_ctx->new_frame)
+		cedrus_write(dev, VE_DEC_H265_DEC_CTB_NUM, 0);
 
 	/* Initialize bitstream access. */
 	cedrus_write(dev, VE_DEC_H265_TRIGGER, VE_DEC_H265_TRIGGER_INIT_SWDEC);
@@ -482,8 +488,8 @@ static void cedrus_h265_setup(struct cedrus_ctx *ctx,
 				V4L2_HEVC_SLICE_PARAMS_FLAG_DEPENDENT_SLICE_SEGMENT,
 				slice_params->flags);
 
-	/* FIXME: For multi-slice support. */
-	reg |= VE_DEC_H265_DEC_SLICE_HDR_INFO0_FLAG_FIRST_SLICE_SEGMENT_IN_PIC;
+	if (ctx->fh.m2m_ctx->new_frame)
+		reg |= VE_DEC_H265_DEC_SLICE_HDR_INFO0_FLAG_FIRST_SLICE_SEGMENT_IN_PIC;
 
 	cedrus_write(dev, VE_DEC_H265_DEC_SLICE_HDR_INFO0, reg);
 
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index 9ddd789d0b1f..247ff90a26b9 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -340,6 +340,7 @@ static int cedrus_s_fmt_vid_out(struct file *file, void *priv,
 
 	switch (ctx->src_fmt.pixelformat) {
 	case V4L2_PIX_FMT_H264_SLICE:
+	case V4L2_PIX_FMT_HEVC_SLICE:
 		vq->subsystem_flags |=
 			VB2_V4L2_FL_SUPPORTS_M2M_HOLD_CAPTURE_BUF;
 		break;
-- 
2.31.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] media: hevc: Add segment address field
  2021-06-06  8:23 ` [PATCH 1/2] media: hevc: Add segment address field Jernej Skrabec
@ 2021-06-07  7:43   ` Benjamin Gaignard
  0 siblings, 0 replies; 4+ messages in thread
From: Benjamin Gaignard @ 2021-06-07  7:43 UTC (permalink / raw)
  To: Jernej Skrabec, mripard, paul.kocialkowski
  Cc: mchehab, gregkh, wens, hverkuil-cisco, ezequiel, linux-media,
	linux-staging, linux-arm-kernel, linux-sunxi, linux-kernel


Le 06/06/2021 à 10:23, Jernej Skrabec a écrit :
> If HEVC frame consists of multiple slices, segment address has to be
> known in order to properly decode it.
>
> Add segment address field to slice parameters.
>
> Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>

Reviewed-by Benjamin Gaignard <benjamin.gaignard@collabora.com>

> ---
>   Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst | 3 +++
>   include/media/hevc-ctrls.h                                | 3 ++-
>   2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
> index 9120c5bcaf90..fac4b477da82 100644
> --- a/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
> +++ b/Documentation/userspace-api/media/v4l/ext-ctrls-codec.rst
> @@ -2997,6 +2997,9 @@ enum v4l2_mpeg_video_hevc_size_of_length_field -
>       * - __u8
>         - ``pic_struct``
>         -
> +    * - __u32
> +      - ``slice_segment_addr``
> +      -
>       * - __u8
>         - ``ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX]``
>         - The list of L0 reference elements as indices in the DPB.
> diff --git a/include/media/hevc-ctrls.h b/include/media/hevc-ctrls.h
> index dc964ff7cd29..19f8e2ad3375 100644
> --- a/include/media/hevc-ctrls.h
> +++ b/include/media/hevc-ctrls.h
> @@ -197,10 +197,11 @@ struct v4l2_ctrl_hevc_slice_params {
>   	__u8	pic_struct;
>   
>   	/* ISO/IEC 23008-2, ITU-T Rec. H.265: General slice segment header */
> +	__u32	slice_segment_addr;
>   	__u8	ref_idx_l0[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
>   	__u8	ref_idx_l1[V4L2_HEVC_DPB_ENTRIES_NUM_MAX];
>   
> -	__u8	padding[5];
> +	__u8	padding;
>   
>   	/* ISO/IEC 23008-2, ITU-T Rec. H.265: Weighted prediction parameter */
>   	struct v4l2_hevc_pred_weight_table pred_weight_table;

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-07  7:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-06  8:23 [PATCH 0/2] media: cedrus: hevc: add support for multiple slices Jernej Skrabec
2021-06-06  8:23 ` [PATCH 1/2] media: hevc: Add segment address field Jernej Skrabec
2021-06-07  7:43   ` Benjamin Gaignard
2021-06-06  8:23 ` [PATCH 2/2] media: cedrus: hevc: Add support for multiple slices Jernej Skrabec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).