meson: vdec: vp9 & MAINTAINERS fixes
Subsystems (4)
cover meson: vdec: vp9 & MAINTAINERS fixes
This serie fixes VP9 decoding :
- enables the motion compensation reference cache controller
- fixes buffer shortage on VP9 decoding
And update the MAINTAINERS entry to add myself ad co-maintainer and add the missing yaml DT bindings.
Maxime Jourdan (2):
media: meson: vdec: enable mcrcc for VP9
media: meson: vdec: fix another case of VP9 buffer shortage
Neil Armstrong (1):
MAINTAINERS: update the Amlogic VDEC driver maintainer entry
MAINTAINERS | 2 + drivers/staging/media/meson/vdec/codec_vp9.c | 72 ++++++++++++++++---- drivers/staging/media/meson/vdec/esparser.c | 24 +++---- 3 files changed, 71 insertions(+), 27 deletions(-)
Signature · 1 line
2.22.0
PATCH 1/3 media: meson: vdec: enable mcrcc for VP9
From: Maxime Jourdan <[email protected]>
The motion compensation reference cache controller allows caching parts of reference frames for faster decoding.
--- drivers/staging/media/meson/vdec/codec_vp9.c | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/staging/media/meson/vdec/codec_vp9.c +31 -0
@@ -854,6 +854,36 @@ static int codec_vp9_stop(struct amvdec_session *sess)return 0 ; } +/* +* Program LAST & GOLDEN frames into the motion compensation reference cache +* controller +*/ +static void codec_vp9_set_mcrcc (struct amvdec_session *sess) +{ +struct amvdec_core *core = sess->core; +struct codec_vp9 *vp9 = sess->priv; +u32 val; + +/* Reset mcrcc */ +amvdec_write_dos (core,HEVCD_MCRCC_CTL1 ,0x2 ); +/* Disable on I-frame */ +if (vp9->cur_frame->type ==KEY_FRAME || vp9->cur_frame->intra_only) { +amvdec_write_dos (core,HEVCD_MCRCC_CTL1 ,0x0 ); +return ; + } + +amvdec_write_dos (core,HEVCD_MPP_ANC_CANVAS_ACCCONFIG_ADDR ,BIT (1 )); + val =amvdec_read_dos (core,HEVCD_MPP_ANC_CANVAS_DATA_ADDR ) &0xffff ; + val |= (val <<16 ); +amvdec_write_dos (core,HEVCD_MCRCC_CTL2 , val); + val =amvdec_read_dos (core,HEVCD_MPP_ANC_CANVAS_DATA_ADDR ) &0xffff ; + val |= (val <<16 ); +amvdec_write_dos (core,HEVCD_MCRCC_CTL3 , val); + +/* Enable mcrcc progressive-mode */ +amvdec_write_dos (core,HEVCD_MCRCC_CTL1 ,0xff0 ); +} +static void codec_vp9_set_sao (struct amvdec_session *sess,struct vb2_buffer *vb) {
@@ -1267,6 +1297,7 @@ static void codec_vp9_process_frame(struct amvdec_session *sess)amvdec_write_dos (core,HEVC_PARSER_PICTURE_SIZE , (vp9->height <<16 ) | vp9->width); +codec_vp9_set_mcrcc (sess);codec_vp9_set_sao (sess, &vp9->cur_frame->vbuf->vb2_buf); vp9_loop_filter_frame_init(core, &vp9->seg_4lf,
Signature · 1 line
2.22.0
PATCH 2/3 media: meson: vdec: fix another case of VP9 buffer shortage
In reply to Neil ArmstrongFrom: Maxime Jourdan <[email protected]>
- Redo the logic where VP9 gets fresh CAPTURE buffers. The previous code could lead to a hardlock.
- Reserve 4 margin buffers instead of 3, as apparently there are corner cases where 3 is not enough.
--- drivers/staging/media/meson/vdec/codec_vp9.c | 41 +++++++++++++------- drivers/staging/media/meson/vdec/esparser.c | 24 ++++++------ 2 files changed, 38 insertions(+), 27 deletions(-)
drivers/staging/media/meson/vdec/codec_vp9.c +27 -14
@@ -1185,6 +1185,29 @@ static void codec_vp9_set_mc(struct amvdec_session *sess,amvdec_write_dos (core,VP9D_MPP_REF_SCALE_ENBL , scale); } +/* +* Get a free VB2 buffer that isn't currently used. +* VP9 references are held sometimes for so long that it's not really an option +* to hold them until they're no longer referenced, as it would delay the +* CAPTURE queue too much +*/ +static struct vb2_v4l2_buffer *get_free_vbuf (struct amvdec_session *sess) +{ +struct codec_vp9 *vp9 = sess->priv; +struct vb2_v4l2_buffer *vbuf =v4l2_m2m_dst_buf_remove (sess->m2m_ctx); +struct vb2_v4l2_buffer *vbuf2; + +if (!vbuf) +return NULL ; + +if (!codec_vp9_get_frame_by_idx (vp9, vbuf->vb2_buf.index)) +return vbuf; + + vbuf2 =get_free_vbuf (sess); +v4l2_m2m_buf_queue (sess->m2m_ctx, vbuf); +return vbuf2; +} +static struct vp9_frame *codec_vp9_get_new_frame (struct amvdec_session *sess) {struct codec_vp9 *vp9 = sess->priv;
@@ -1196,25 +1219,13 @@ static struct vp9_frame *codec_vp9_get_new_frame(struct amvdec_session *sess)if (!new_frame)return NULL ; - vbuf =v4l2_m2m_dst_buf_remove (sess->m2m_ctx); + vbuf =get_free_vbuf (sess);if (!vbuf) {dev_err (sess->core->dev,"No dst buffer available\n" );kfree (new_frame);return NULL ; } -while (codec_vp9_get_frame_by_idx (vp9, vbuf->vb2_buf.index)) { -struct vb2_v4l2_buffer *old_vbuf = vbuf; - - vbuf =v4l2_m2m_dst_buf_remove (sess->m2m_ctx); -v4l2_m2m_buf_queue (sess->m2m_ctx, old_vbuf); -if (!vbuf) { -dev_err (sess->core->dev,"No dst buffer available\n" ); -kfree (new_frame); -return NULL ; - } - } - new_frame->vbuf = vbuf; new_frame->index = vbuf->vb2_buf.index; new_frame->intra_only = param->p.intra_only;
@@ -1267,8 +1278,10 @@ static void codec_vp9_process_frame(struct amvdec_session *sess)codec_vp9_rm_noshow_frame (sess); vp9->cur_frame =codec_vp9_get_new_frame (sess); -if (!vp9->cur_frame) +if (!vp9->cur_frame) { +amvdec_abort (sess);return ; + } pr_debug("frame %d: type: %08X; show_exist: %u; show: %u, intra_only: %u\n", vp9->cur_frame->index,
drivers/staging/media/meson/vdec/esparser.c +11 -13
@@ -301,21 +301,19 @@ esparser_queue(struct amvdec_session *sess, struct vb2_v4l2_buffer *vbuf)u32 offset;u32 pad_size; -/* -* When max ref frame is held by VP9, this should be -= 3 to prevent a -* shortage of CAPTURE buffers on the decoder side. -* For the future, a good enhancement of the way this is handled could -* be to notify new capture buffers to the decoding modules, so that -* they could pause when there is no capture buffer available and -* resume on this notification. -*/ -if (sess->fmt_out->pixfmt ==V4L2_PIX_FMT_VP9 ) { -if (codec_ops->num_pending_bufs) - num_dst_bufs = codec_ops->num_pending_bufs (sess); - +if (codec_ops->num_pending_bufs) { + num_dst_bufs = codec_ops->num_pending_bufs (sess); num_dst_bufs +=v4l2_m2m_num_dst_bufs_ready (sess->m2m_ctx); +/* +* When max ref frame is held by VP9, this should be -= 4 +* to prevent a shortage of CAPTURE buffers on the decoder side. +* For the future, a good enhancement of the way this is handled +* could be to notify new capture buffers to the decoding +* modules, so that they could pause when there is no capture +* buffer available and resume on this notification. +*/ if (sess->fmt_out->pixfmt ==V4L2_PIX_FMT_VP9 ) - num_dst_bufs -=3 ; + num_dst_bufs -=4 ;if (esparser_vififo_get_free_space (sess) < payload_size ||atomic_read (&sess->esparser_queued_bufs) >= num_dst_bufs)
Signature · 1 line
2.22.0
Re: [PATCH 2/3] media: meson: vdec: fix another case of VP9 buffer shortage
Em Tue, 28 Apr 2020 14:50:35 +0200
Neil Armstrong <[email protected]> escreveu:
Quoted 15 lines
From: Maxime Jourdan <[email protected]>
- Redo the logic where VP9 gets fresh CAPTURE buffers. The previous code could lead to a hardlock.
- Reserve 4 margin buffers instead of 3, as apparently there are corner cases where 3 is not enough.Fixes e9a3eb4819ca ("media: meson: vdec: add VP9 input support")Fixes 00c43088aa68 ("media: meson: vdec: add VP9 decoder support")Signed-off-by Maxime Jourdan <[email protected]>Signed-off-by Neil Armstrong <[email protected]>drivers/staging/media/meson/vdec/codec_vp9.c +3
-0+static struct vb2_v4l2_buffer *get_free_vbuf (struct amvdec_session *sess) +{ +struct codec_vp9 *vp9 = sess->priv;
drivers/staging/media/meson/vdec/codec_vp9.c static void codec_vp9_set_mc(struct amvdec_session *sess, · line 1206
Quoted 10 lines
drivers/staging/media/meson/vdec/codec_vp9.c +10
-0+struct vb2_v4l2_buffer *vbuf =v4l2_m2m_dst_buf_remove (sess->m2m_ctx); +struct vb2_v4l2_buffer *vbuf2; + +if (!vbuf) +return NULL ; + +if (!codec_vp9_get_frame_by_idx (vp9, vbuf->vb2_buf.index)) +return vbuf; + + vbuf2 =get_free_vbuf (sess);
Huh!!!!
Never use recursive functions inside the Kernel! Kernel stack is too limited.
Also, even if Kernel stack would be unlimited, the above logic would endlessly be calling get_free_vbuf(sess).
Thanks,
Mauro
Re: [PATCH 2/3] media: meson: vdec: fix another case of VP9 buffer shortage
Quoted 31 lines · Mauro Carvalho Chehab
Em Tue, 28 Apr 2020 14:50:35 +0200
Neil Armstrong <[email protected]> escreveu:Quoted 15 lines
From: Maxime Jourdan <[email protected]>
- Redo the logic where VP9 gets fresh CAPTURE buffers. The previous code could lead to a hardlock.
- Reserve 4 margin buffers instead of 3, as apparently there are corner cases where 3 is not enough.Fixes e9a3eb4819ca ("media: meson: vdec: add VP9 input support")Fixes 00c43088aa68 ("media: meson: vdec: add VP9 decoder support")Signed-off-by Maxime Jourdan <[email protected]>Signed-off-by Neil Armstrong <[email protected]>drivers/staging/media/meson/vdec/codec_vp9.c +3
-0+static struct vb2_v4l2_buffer *get_free_vbuf (struct amvdec_session *sess) +{ +struct codec_vp9 *vp9 = sess->priv;drivers/staging/media/meson/vdec/codec_vp9.c static void codec_vp9_set_mc(struct amvdec_session *sess, · line 1206
Quoted 10 lines
drivers/staging/media/meson/vdec/codec_vp9.c +10
-0+struct vb2_v4l2_buffer *vbuf =v4l2_m2m_dst_buf_remove (sess->m2m_ctx); +struct vb2_v4l2_buffer *vbuf2; + +if (!vbuf) +return NULL ; + +if (!codec_vp9_get_frame_by_idx (vp9, vbuf->vb2_buf.index)) +return vbuf; + + vbuf2 =get_free_vbuf (sess);Huh!!!!
Quoted 5 lines
Never use recursive functions inside the Kernel! Kernel stack is too limited.
Also, even if Kernel stack would be unlimited, the above logic would endlessly be calling
get_free_vbuf(sess).
Will rework this correctly, thanks for the review.
Neil
Quoted 4 lines
Thanks,
Mauro
PATCH 3/3 MAINTAINERS: update the Amlogic VDEC driver maintainer entry
In reply to Neil ArmstrongAdd myself as co-maintainer of the Amlogic VDEC driver, and add the missing vdec DT yaml bindings.
--- MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
@@ -11009,10 +11009,12 @@ F: drivers/mtd/nand/raw/meson_* MESON VIDEO DECODER DRIVER FOR AMLOGIC SOCS M: Maxime Jourdan <[email protected]> +M: Neil Armstrong <[email protected]> L: [email protected] L: [email protected] S: Supported T: git git://linuxtv.org/media_tree.git +F: Documentation/devicetree/bindings/media/amlogic,gx-vdec.yaml F: drivers/staging/media/meson/vdec/ METHODE UDPU SUPPORT
Signature · 1 line
2.22.0