Skip to contentSkip to conversation

media: verisilicon: Create AV1 helper library

PATCH Superseded Benjamin Gaignard 2 participants 2 messages Mar 12 – Apr 8

Subsystems (3)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Benjamin Gaignard

author maintainer
#0 lore raw

PATCH v2 1/1 media: verisilicon: Create AV1 helper library

Regroup all none hardware related AV1 functions into a helper library. The goal is to avoid code duplication for futur AV1 codecs.

Tested on rock 5b board Fluster score remains the same 204/241.

---
change in v2
- rockchip av1 codec use hantro_av1_get_hardware_tx_mode() and no more it own function.

 drivers/media/platform/verisilicon/Makefile   |   7 +-
 .../media/platform/verisilicon/hantro_av1.c   | 780 +++++++++++++++
 .../media/platform/verisilicon/hantro_av1.h   |  62 ++
 ...entropymode.c => hantro_av1_entropymode.c} |  18 +-
 ...entropymode.h => hantro_av1_entropymode.h} |  18 +-
 ...av1_filmgrain.c => hantro_av1_filmgrain.c} |  82 +-
 .../verisilicon/hantro_av1_filmgrain.h        |  44 +
 .../media/platform/verisilicon/hantro_hw.h    |   4 +-
 .../verisilicon/rockchip_av1_filmgrain.h      |  36 -
 .../verisilicon/rockchip_vpu981_hw_av1_dec.c  | 942 ++----------------
 10 files changed, 1048 insertions(+), 945 deletions(-)
 create mode 100644 drivers/media/platform/verisilicon/hantro_av1.c
 create mode 100644 drivers/media/platform/verisilicon/hantro_av1.h
 rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.c => hantro_av1_entropymode.c} (99%)
 rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.h => hantro_av1_entropymode.h} (95%)
 rename drivers/media/platform/verisilicon/{rockchip_av1_filmgrain.c => hantro_av1_filmgrain.c} (92%)
 create mode 100644 drivers/media/platform/verisilicon/hantro_av1_filmgrain.h
 delete mode 100644 drivers/media/platform/verisilicon/rockchip_av1_filmgrain.h
drivers/media/platform/verisilicon/Makefile +4 -3
index f6f019d04ff0..a1dd6c2d29be 100644
@@ -19,7 +19,10 @@ hantro-vpu-y += \
 		hantro_hevc.o \
 		hantro_mpeg2.o \
 		hantro_vp8.o \
-		hantro_vp9.o
+		hantro_vp9.o \
+		hantro_av1.o \
+		hantro_av1_filmgrain.o \
+		hantro_av1_entropymode.o
 
 hantro-vpu-$(CONFIG_VIDEO_HANTRO_IMX8M) += \
 		imx8m_vpu_hw.o
@@ -33,8 +36,6 @@ hantro-vpu-$(CONFIG_VIDEO_HANTRO_ROCKCHIP) += \
 		rockchip_vpu2_hw_mpeg2_dec.o \
 		rockchip_vpu2_hw_vp8_dec.o \
 		rockchip_vpu981_hw_av1_dec.o \
-		rockchip_av1_filmgrain.o \
-		rockchip_av1_entropymode.o \
 		rockchip_vpu_hw.o
 
 hantro-vpu-$(CONFIG_VIDEO_HANTRO_SUNXI) += \
drivers/media/platform/verisilicon/hantro_av1.c new file +780 -0

780 lines not on this page · raw message

drivers/media/platform/verisilicon/hantro_av1.h new file +62 -0

62 lines not on this page · raw message

drivers/media/platform/verisilicon/hantro_av1_entropymode.c renamed from drivers/media/platform/verisilicon/rockchip_av1_entropymode.c +9 -9
similarity index 99%
rename from drivers/media/platform/verisilicon/rockchip_av1_entropymode.c
rename to drivers/media/platform/verisilicon/hantro_av1_entropymode.c
index b1ae72ad675e..4f7bfec73668 100644
@@ -11,7 +11,7 @@
  */
 
 #include "hantro.h"
-#include "rockchip_av1_entropymode.h"
+#include "hantro_av1_entropymode.h"
 
 #define AOM_ICDF ICDF
 #define AOM_CDF2(a0) AOM_ICDF(a0)
@@ -4195,7 +4195,7 @@ static const u16 default_bits_cdf[][10] = {
 	}
 };
 
-static int rockchip_av1_get_q_ctx(int q)
+static int hantro_av1_get_q_ctx(int q)
 {
 	if (q <= 20)
 		return 0;
@@ -4206,10 +4206,10 @@ static int rockchip_av1_get_q_ctx(int q)
 	return 3;
 }
 
-void rockchip_av1_default_coeff_probs(u32 base_qindex, void *ptr)
+void hantro_av1_default_coeff_probs(u32 base_qindex, void *ptr)
 {
 	struct av1cdfs *cdfs = (struct av1cdfs *)ptr;
-	const int index = rockchip_av1_get_q_ctx(base_qindex);
+	const int index = hantro_av1_get_q_ctx(base_qindex);
 
 	memcpy(cdfs->txb_skip_cdf, av1_default_txb_skip_cdfs[index],
 	       sizeof(av1_default_txb_skip_cdfs[0]));
@@ -4240,8 +4240,8 @@ void rockchip_av1_default_coeff_probs(u32 base_qindex, void *ptr)
 	       sizeof(av1_default_eob_multi1024_cdfs[0]));
 }
 
-void rockchip_av1_set_default_cdfs(struct av1cdfs *cdfs,
-				   struct mvcdfs *cdfs_ndvc)
+void hantro_av1_set_default_cdfs(struct av1cdfs *cdfs,
+				 struct mvcdfs *cdfs_ndvc)
 {
 	memcpy(cdfs->partition_cdf, default_partition_cdf,
 	       sizeof(cdfs->partition_cdf));
@@ -4398,7 +4398,7 @@ void rockchip_av1_set_default_cdfs(struct av1cdfs *cdfs,
 	       sizeof(cdfs->compound_idx_cdf));
 }
 
-void rockchip_av1_get_cdfs(struct hantro_ctx *ctx, u32 ref_idx)
+void hantro_av1_get_cdfs(struct hantro_ctx *ctx, u32 ref_idx)
 {
 	struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
 
@@ -4406,8 +4406,8 @@ void rockchip_av1_get_cdfs(struct hantro_ctx *ctx, u32 ref_idx)
 	av1_dec->cdfs_ndvc = &av1_dec->cdfs_last_ndvc[ref_idx];
 }
 
-void rockchip_av1_store_cdfs(struct hantro_ctx *ctx,
-			     u32 refresh_frame_flags)
+void hantro_av1_store_cdfs(struct hantro_ctx *ctx,
+			   u32 refresh_frame_flags)
 {
 	struct hantro_av1_dec_hw_ctx *av1_dec = &ctx->av1_dec;
 	int i;
drivers/media/platform/verisilicon/hantro_av1_entropymode.h renamed from drivers/media/platform/verisilicon/rockchip_av1_entropymode.h +9 -9
similarity index 95%
rename from drivers/media/platform/verisilicon/rockchip_av1_entropymode.h
rename to drivers/media/platform/verisilicon/hantro_av1_entropymode.h
index bbf8424c7d2c..abbc660ecce3 100644
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 
-#ifndef _ROCKCHIP_AV1_ENTROPYMODE_H_
-#define _ROCKCHIP_AV1_ENTROPYMODE_H_
+#ifndef _HANTRO_AV1_ENTROPYMODE_H_
+#define _HANTRO_AV1_ENTROPYMODE_H_
 
 #include <linux/types.h>
 
@@ -262,11 +262,11 @@ struct av1cdfs {
 	u16 dummy3[16];
 };
 
-void rockchip_av1_store_cdfs(struct hantro_ctx *ctx,
-			     u32 refresh_frame_flags);
-void rockchip_av1_get_cdfs(struct hantro_ctx *ctx, u32 ref_idx);
-void rockchip_av1_set_default_cdfs(struct av1cdfs *cdfs,
-				   struct mvcdfs *cdfs_ndvc);
-void rockchip_av1_default_coeff_probs(u32 base_qindex, void *ptr);
+void hantro_av1_store_cdfs(struct hantro_ctx *ctx,
+			   u32 refresh_frame_flags);
+void hantro_av1_get_cdfs(struct hantro_ctx *ctx, u32 ref_idx);
+void hantro_av1_set_default_cdfs(struct av1cdfs *cdfs,
+				 struct mvcdfs *cdfs_ndvc);
+void hantro_av1_default_coeff_probs(u32 base_qindex, void *ptr);
 
-#endif /* _ROCKCHIP_AV1_ENTROPYMODE_H_ */
+#endif /* _HANTRO_AV1_ENTROPYMODE_H_ */
drivers/media/platform/verisilicon/hantro_av1_filmgrain.c renamed from drivers/media/platform/verisilicon/rockchip_av1_filmgrain.c +41 -41

147 lines not on this page · raw message

drivers/media/platform/verisilicon/hantro_av1_filmgrain.h new file +44 -0

44 lines not on this page · raw message

drivers/media/platform/verisilicon/hantro_hw.h +2 -2
index 5f2011529f02..f0e4bca4b2b2 100644
@@ -15,8 +15,8 @@
 #include <media/v4l2-vp9.h>
 #include <media/videobuf2-core.h>
 
-#include "rockchip_av1_entropymode.h"
-#include "rockchip_av1_filmgrain.h"
+#include "hantro_av1_entropymode.h"
+#include "hantro_av1_filmgrain.h"
 
 #define DEC_8190_ALIGN_MASK	0x07U
 
drivers/media/platform/verisilicon/rockchip_av1_filmgrain.h deleted +0 -36
deleted file mode 100644
index 31a8b7920c31..000000000000
@@ -1,36 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#ifndef _ROCKCHIP_AV1_FILMGRAIN_H_
-#define _ROCKCHIP_AV1_FILMGRAIN_H_
-
-#include <linux/types.h>
-
-void rockchip_av1_generate_luma_grain_block(s32 (*luma_grain_block)[73][82],
-					    s32 bitdepth,
-					    u8 num_y_points,
-					    s32 grain_scale_shift,
-					    s32 ar_coeff_lag,
-					    s32 (*ar_coeffs_y)[24],
-					    s32 ar_coeff_shift,
-					    s32 grain_min,
-					    s32 grain_max,
-					    u16 random_seed);
-
-void rockchip_av1_generate_chroma_grain_block(s32 (*luma_grain_block)[73][82],
-					      s32 (*cb_grain_block)[38][44],
-					      s32 (*cr_grain_block)[38][44],
-					      s32 bitdepth,
-					      u8 num_y_points,
-					      u8 num_cb_points,
-					      u8 num_cr_points,
-					      s32 grain_scale_shift,
-					      s32 ar_coeff_lag,
-					      s32 (*ar_coeffs_cb)[25],
-					      s32 (*ar_coeffs_cr)[25],
-					      s32 ar_coeff_shift,
-					      s32 grain_min,
-					      s32 grain_max,
-					      u8 chroma_scaling_from_luma,
-					      u16 random_seed);
-
-#endif
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +97 -845

1,222 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer Reviewed-by on v2 1/1
#1 lore raw

Le jeudi 12 mars 2026 à 10:15 +0100, Benjamin Gaignard a écrit :

Quoted 21 lines

Regroup all none hardware related AV1 functions into a helper library. The goal is to avoid code duplication for futur AV1 codecs.

Tested on rock 5b board Fluster score remains the same 204/241.

---
change in v2
- rockchip av1 codec use hantro_av1_get_hardware_tx_mode() and no more it own function.

 drivers/media/platform/verisilicon/Makefile   |   7 +-
 .../media/platform/verisilicon/hantro_av1.c   | 780 +++++++++++++++
 .../media/platform/verisilicon/hantro_av1.h   |  62 ++
 ...entropymode.c => hantro_av1_entropymode.c} |  18 +-
 ...entropymode.h => hantro_av1_entropymode.h} |  18 +-
 ...av1_filmgrain.c => hantro_av1_filmgrain.c} |  82 +-

 .../verisilicon/hantro_av1_filmgrain.h        |  44 + .../media/platform/verisilicon/hantro_hw.h    |   4 +- .../verisilicon/rockchip_av1_filmgrain.h      |  36 - .../verisilicon/rockchip_vpu981_hw_av1_dec.c  | 942 ++----------------

Quoted 8 lines
 10 files changed, 1048 insertions(+), 945 deletions(-)

 create mode 100644 drivers/media/platform/verisilicon/hantro_av1.c
 create mode 100644 drivers/media/platform/verisilicon/hantro_av1.h
 rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.c => hantro_av1_entropymode.c} (99%) rename drivers/media/platform/verisilicon/{rockchip_av1_entropymode.h => hantro_av1_entropymode.h} (95%) rename drivers/media/platform/verisilicon/{rockchip_av1_filmgrain.c => hantro_av1_filmgrain.c} (92%) create mode 100644 drivers/media/platform/verisilicon/hantro_av1_filmgrain.h
 delete mode 100644 drivers/media/platform/verisilicon/rockchip_av1_filmgrain.h

[...]

Quoted 7 lines

  rockchip_vpu981_av1_dec_set_parameters(ctx); rockchip_vpu981_av1_dec_set_global_model(ctx);

drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +0 -0
@@ -2197,6 +1439,16 @@ int rockchip_vpu981_av1_dec_run(struct hantro_ctx *ctx)
  	return ret;
  }


+int rockchip_vpu981_av1_dec_init(struct hantro_ctx *ctx)

nit: The wrapper is no longer needed, you can change rockchip_vpu_hw.c code to:

.init = hantro_av1_init

drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c int rockchip_vpu981_av1_dec_run(struct hantro_ctx *ctx) · line 1449

Quoted 7 lines
drivers/media/platform/verisilicon/rockchip_vpu981_hw_av1_dec.c +7 -0
+{
+	return hantro_av1_init(ctx);
+}
+
+void rockchip_vpu981_av1_dec_exit(struct hantro_ctx *ctx)
+{
+	hantro_av1_exit(ctx);

Same nit, different function. Appart from that:

Quoted 5 lines
(quoted diff) +2 -0
+}
+

 static void rockchip_vpu981_postproc_enable(struct hantro_ctx *ctx) {
  struct hantro_dev *vpu = ctx->dev;