media: mediatek: vcodec: support stateless AV1 decoder
Subsystems (3)
PATCH v9 1/1 media: mediatek: vcodec: support stateless AV1 decoder
Add mediatek av1 decoder linux driver which use the stateless API in MT8195.
---
Changes from v8:
- remove RFC tag in subject.
- test by av1 fluster, results are 173/239(10bit/film grain are not support),11/13(film grain is not support),0(10bit is not support).
Changes from v7:
- change V4L2_CID_STATELESS_AV1_PROFILE to V4L2_CID_MPEG_VIDEO_AV1_PROFILE,V4L2_CID_STATELESS_AV1_LEVEL to V4L2_CID_MPEG_VIDEO_AV1_LEVEL to match av1 uAPI V4.
- remove vsi and ctx null check in vdec_av1_slice_init_cdf_table, vdec_av1_slice_init_iq_table for the never true condition.
- add inline in function vdec_av1_slice_clear_fb, vdec_av1_slice_vsi_from_remote, vdec_av1_slice_vsi_to_remote, vdec_av1_slice_setup_state, vdec_av1_slice_setup_operating_mode and vdec_av1_slice_get_dpb_size.
- remove fb_idx check in vdec_av1_slice_decrease_ref_count.
- add define AV1_CDF_TABLE_BUFFER_SIZE for magic number 16384.
- remove intermediate variable "size" at the end of vdec_av1_slice_alloc_working_buffer.
- use define V4L2_AV1_WARP_MODEL_AFFINE to replace magic number 3 in vdec_av1_slice_setup_gm.
- change api name vdec_av1_slice_get_relative_dist to vdec_av1_slice_get_sign_bias and return 0 or 1 for the caller directly use.
- add define AV1_PRIMARY_REF_NONE for magic number 7.
- remove TODO comment in vdec_av1_slice_update_core.
- change name irq to irq_enabled in struct vdec_av1_slice_instance.
- Add newline before return statememt in vdec_av1_slice_init and vdec_av1_slice_flush.
- remove work_buffer assignment and merge 3 loops with one in vdec_av1_slice_alloc_working_buffer.
- remove va null check in vdec_av1_slice_free_working_buffer.
- swap order between vdec_av1_slice_clear_fb and vdec_msg_queue_wait_lat_buf_full in vdec_av1_slice_flush.
- test by av1 fluster, result is 173/239
Changes from v6:
- change slot_id type from u8 to s8
- test by av1 fluster, result is 173/239
Changes from v5:
- change av1 PROFILE and LEVEL cfg
- test by av1 fluster, result is 173/239
Changes from v4:
- convert vb2_find_timestamp to vb2_find_buffer
- test by av1 fluster, result is 173/239
Changes from v3:
- modify comment for struct vdec_av1_slice_slot
- add define SEG_LVL_ALT_Q
- change use_lr/use_chroma_lr parse from av1 spec
- use ARRAY_SIZE to replace size for loop_filter_level and loop_filter_mode_deltas
- change array size of loop_filter_mode_deltas from 4 to 2
- add define SECONDARY_FILTER_STRENGTH_NUM_BITS
- change some hex values from upper case to lower case
- change *dpb_sz equal to V4L2_AV1_TOTAL_REFS_PER_FRAME + 1
- test by av1 fluster, result is 173/239
Changes from v2:
- Match with av1 uapi v3 modify
- test by av1 fluster, result is 173/239
---
Reference series:
[1]: v7 of this series is presend by Daniel Almeida.
message-id: [email protected]
.../media/platform/mediatek/vcodec/Makefile | 1 + .../vcodec/mtk_vcodec_dec_stateless.c | 47 +- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 1 + .../vcodec/vdec/vdec_av1_req_lat_if.c | 2203 +++++++++++++++++ .../platform/mediatek/vcodec/vdec_drv_if.c | 4 + .../platform/mediatek/vcodec/vdec_drv_if.h | 1 + .../platform/mediatek/vcodec/vdec_msg_queue.c | 27 + .../platform/mediatek/vcodec/vdec_msg_queue.h | 4 + 8 files changed, 2287 insertions(+), 1 deletion(-) create mode 100644 drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c
drivers/media/platform/mediatek/vcodec/Makefile +1 -0
@@ -10,6 +10,7 @@ mtk-vcodec-dec-y := vdec/vdec_h264_if.o \ vdec/vdec_vp8_req_if.o \ vdec/vdec_vp9_if.o \ vdec/vdec_vp9_req_lat_if.o \ + vdec/vdec_av1_req_lat_if.o \ vdec/vdec_h264_req_if.o \ vdec/vdec_h264_req_common.o \ vdec/vdec_h264_req_multi_if.o \
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_stateless.c +46 -1
69 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +1 -0
@@ -344,6 +344,7 @@ enum mtk_vdec_format_types {MTK_VDEC_FORMAT_H264_SLICE =0x100 ,MTK_VDEC_FORMAT_VP8_FRAME =0x200 ,MTK_VDEC_FORMAT_VP9_FRAME =0x400 , +MTK_VDEC_FORMAT_AV1_FRAME =0x800 , MTK_VCODEC_INNER_RACING = 0x20000, };
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c new file +2203 -0
2,203 lines not on this page · raw message
drivers/media/platform/mediatek/vcodec/vdec_drv_if.c +4 -0
@@ -49,6 +49,10 @@ int vdec_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) ctx->dec_if = &vdec_vp9_slice_lat_if; ctx->hw_id =IS_VDEC_LAT_ARCH (hw_arch) ?MTK_VDEC_LAT0 :MTK_VDEC_CORE ;break ; +case V4L2_PIX_FMT_AV1_FRAME : + ctx->dec_if = &vdec_av1_slice_lat_if; + ctx->hw_id =MTK_VDEC_LAT0 ; +break ;default :return -EINVAL ; }
drivers/media/platform/mediatek/vcodec/vdec_drv_if.h +1 -0
@@ -61,6 +61,7 @@ extern const struct vdec_common_if vdec_vp8_if;extern const struct vdec_common_if vdec_vp8_slice_if;extern const struct vdec_common_if vdec_vp9_if;extern const struct vdec_common_if vdec_vp9_slice_lat_if; +extern const struct vdec_common_if vdec_av1_slice_lat_if;/** * vdec_if_init() - initialize decode driver
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.c +27 -0
@@ -20,6 +20,9 @@/* the size used to store avc error information */ #define VDEC_ERR_MAP_SZ_AVC (17 * SZ_1K) +#define VDEC_RD_MV_BUFFER_SZ (((SZ_4K * 2304 >> 4) + SZ_1K) << 1) +#define VDEC_LAT_TILE_SZ (64 * V4L2_AV1_MAX_TILE_COUNT) +/* core will read the trans buffer which decoded by lat to decode again. * The trans buffer size of FHD and 4K bitstreams are different. */
@@ -255,6 +258,14 @@ void vdec_msg_queue_deinit(struct vdec_msg_queue *msg_queue,if (mem->va)mtk_vcodec_mem_free (ctx, mem); + mem = &lat_buf->rd_mv_addr; +if (mem->va) +mtk_vcodec_mem_free (ctx, mem); + + mem = &lat_buf->tile_addr; +if (mem->va) +mtk_vcodec_mem_free (ctx, mem); +kfree (lat_buf->private_data); } }
@@ -347,6 +358,22 @@ int vdec_msg_queue_init(struct vdec_msg_queue *msg_queue, goto mem_alloc_err; } +if (ctx->current_codec ==V4L2_PIX_FMT_AV1_FRAME ) { + lat_buf->rd_mv_addr.size =VDEC_RD_MV_BUFFER_SZ ; + err =mtk_vcodec_mem_alloc (ctx, &lat_buf->rd_mv_addr); +if (err) { +mtk_v4l2_err ("failed to allocate rd_mv_addr buf[%d]" , i); +return -ENOMEM ; + } + + lat_buf->tile_addr.size =VDEC_LAT_TILE_SZ ; + err =mtk_vcodec_mem_alloc (ctx, &lat_buf->tile_addr); +if (err) { +mtk_v4l2_err ("failed to allocate tile_addr buf[%d]" , i); +return -ENOMEM ; + } + } + lat_buf->private_data =kzalloc (private_size,GFP_KERNEL );if (!lat_buf->private_data) { err = -ENOMEM ;
drivers/media/platform/mediatek/vcodec/vdec_msg_queue.h +4 -0
@@ -42,6 +42,8 @@ struct vdec_msg_queue_ctx {* struct vdec_lat_buf - lat buffer message used to store lat info for core decode * @wdma_err_addr: wdma error address used for lat hardware * @slice_bc_addr: slice bc address used for lat hardware +* @rd_mv_addr: mv addr for av1 lat hardware output, core hardware input +* @tile_addr: tile buffer for av1 core input * @ts_info: need to set timestamp from output to capture * @src_buf_req: output buffer media request object *
@@ -54,6 +56,8 @@ struct vdec_msg_queue_ctx {struct vdec_lat_buf {struct mtk_vcodec_mem wdma_err_addr;struct mtk_vcodec_mem slice_bc_addr; +struct mtk_vcodec_mem rd_mv_addr; +struct mtk_vcodec_mem tile_addr;struct vb2_v4l2_buffer ts_info;struct media_request *src_buf_req;
Signature · 1 line
2.18.0
Quoted 8 lines · Xiaoyong Lu
Add mediatek av1 decoder linux driver which use the stateless API in MT8195.
Signed-off-by Xiaoyong Lu<[email protected]>Tested-by Nicolas Dufresne <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>
Hmm, I get this compile error:
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c: In function ‘vdec_av1_slice_setup_uh’:drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:48:58: error: ‘V4L2_AV1_FRAME_FLAG_UNIFORM_TILE_SPACING’ undeclared (first use in this function); did you mean ‘V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING’?
48 | #define FH_FLAG(x, name) (!!((x)->flags & V4L2_AV1_FRAME_FLAG_##name))
| ^~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:1322:41: note: in expansion of macro ‘FH_FLAG’
1322 | uh->uniform_tile_spacing_flag = FH_FLAG(ctrl_fh, UNIFORM_TILE_SPACING);
| ^~~~~~~drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:48:58: note: each undeclared identifier is reported only once for each function it appears in
48 | #define FH_FLAG(x, name) (!!((x)->flags & V4L2_AV1_FRAME_FLAG_##name))
| ^~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:1322:41: note: in expansion of macro ‘FH_FLAG’
1322 | uh->uniform_tile_spacing_flag = FH_FLAG(ctrl_fh, UNIFORM_TILE_SPACING);
| ^~~~~~~
This flag was renamed from V4L2_AV1_FRAME_FLAG_UNIFORM_TILE_SPACING to V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING in v5 of the AV1 uAPI.
So this suggests to me that you are testing with an old version of the AV1 uAPI. The correct one is v7:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
You have to compile and test with that v7 patch since that's the version we want to merge.
Regards,
Hans
AngeloGioacchino Del Regno
maintainerIl 12/04/23 14:22, Hans Verkuil ha scritto:
Quoted 30 lines · Xiaoyong Lu
Quoted 8 lines
Add mediatek av1 decoder linux driver which use the stateless API in MT8195.
Signed-off-by Xiaoyong Lu<[email protected]>Tested-by Nicolas Dufresne <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>Hmm, I get this compile error:
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c: In function ‘vdec_av1_slice_setup_uh’:drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:48:58: error: ‘V4L2_AV1_FRAME_FLAG_UNIFORM_TILE_SPACING’ undeclared (first use in this function); did you mean ‘V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING’?48 | #define FH_FLAG(x, name) (!!((x)->flags & V4L2_AV1_FRAME_FLAG_##name)) | ^~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:1322:41: note: in expansion of macro ‘FH_FLAG’
1322 |uh->uniform_tile_spacing_flag=FH_FLAG(ctrl_fh, UNIFORM_TILE_SPACING);
| ^~~~~~~drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:48:58: note: each undeclared identifier is reported only once for each function it appears in48 | #define FH_FLAG(x, name) (!!((x)->flags & V4L2_AV1_FRAME_FLAG_##name)) | ^~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:1322:41: note: in expansion of macro ‘FH_FLAG’
1322 |uh->uniform_tile_spacing_flag=FH_FLAG(ctrl_fh, UNIFORM_TILE_SPACING);
| ^~~~~~~This flag was renamed from
V4L2_AV1_FRAME_FLAG_UNIFORM_TILE_SPACINGtoV4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACINGin v5 of the AV1 uAPI.
Quoted 7 lines
So this suggests to me that you are testing with an old version of the AV1 uAPI. The correct one is v7:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
You have to compile and test with that v7 patch since that's the version we want to merge.
I was about to say the same.
Please Xiaoyong, update your patch and resend.
Thanks,
Angelo
Quoted 30 lines · Hans Verkuil
Quoted 8 lines · Xiaoyong Lu
Add mediatek av1 decoder linux driver which use the stateless API in MT8195.
Signed-off-by Xiaoyong Lu<[email protected]>Tested-by Nicolas Dufresne <[email protected]>Reviewed-by Nicolas Dufresne <[email protected]>Reviewed-by AngeloGioacchino Del Regno <[email protected]>Hmm, I get this compile error:
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c: In function ‘vdec_av1_slice_setup_uh’:drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:48:58: error: ‘V4L2_AV1_FRAME_FLAG_UNIFORM_TILE_SPACING’ undeclared (first use in this function); did you mean ‘V4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACING’?
48 | #defineFH_FLAG(x, name)(!!((x)->flags & V4L2_AV1_FRAME_FLAG_##name))| ^~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:1322:41: note: in expansion of macro ‘FH_FLAG’
1322 |uh->uniform_tile_spacing_flag=FH_FLAG(ctrl_fh, UNIFORM_TILE_SPACING);
| ^~~~~~~drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:48:58: note: each undeclared identifier is reported only once for each function it appears in
48 | #defineFH_FLAG(x, name)(!!((x)->flags & V4L2_AV1_FRAME_FLAG_##name))| ^~~~~~~~~~~~~~~~~~~~
drivers/media/platform/mediatek/vcodec/vdec/vdec_av1_req_lat_if.c:1322:41: note: in expansion of macro ‘FH_FLAG’
1322 |uh->uniform_tile_spacing_flag=FH_FLAG(ctrl_fh, UNIFORM_TILE_SPACING);
| ^~~~~~~This flag was renamed from
V4L2_AV1_FRAME_FLAG_UNIFORM_TILE_SPACINGtoV4L2_AV1_TILE_INFO_FLAG_UNIFORM_TILE_SPACINGin v5 of the AV1 uAPI.
Quoted 7 lines
So this suggests to me that you are testing with an old version of the AV1 uAPI. The correct one is v7:
https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/
You have to compile and test with that v7 patch since that's the version we want to merge.
smatch also gave this error:
vdec_av1_req_lat_if.c:2121 vdec_av1_slice_lat_decode() error: we previously assumed 'pfc' could be null (see line 2056)
Regards,
Hans