[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241116031724.15694-6-yunfei.dong@mediatek.com>
Date: Sat, 16 Nov 2024 11:17:19 +0800
From: Yunfei Dong <yunfei.dong@...iatek.com>
To: NĂcolas F . R . A . Prado
<nfraprado@...labora.com>, Sebastian Fricke <sebastian.fricke@...labora.com>,
Nicolas Dufresne <nicolas.dufresne@...labora.com>, Hans Verkuil
<hverkuil-cisco@...all.nl>, AngeloGioacchino Del Regno
<angelogioacchino.delregno@...labora.com>, Benjamin Gaignard
<benjamin.gaignard@...labora.com>, Nathan Hebert <nhebert@...omium.org>,
Daniel Almeida <daniel.almeida@...labora.com>
CC: Hsin-Yi Wang <hsinyi@...omium.org>, Fritz Koenig <frkoenig@...omium.org>,
Daniel Vetter <daniel@...ll.ch>, Steve Cho <stevecho@...omium.org>, Yunfei
Dong <yunfei.dong@...iatek.com>, <linux-media@...r.kernel.org>,
<devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>, <linux-mediatek@...ts.infradead.org>,
<Project_Global_Chrome_Upstream_Group@...iatek.com>
Subject: [PATCH v7 5/5] media: mediatek: vcodec: store current vb2 buffer to decode again
All the src vb2 buffer are removed from ready list when STREAMOFF
capture queue, may remove a non exist vb2 buffer if lat is working
currently. The driver also need to use current vb2 buffer to decode
again to wait for enough resource when lat decode error.
Signed-off-by: Yunfei Dong <yunfei.dong@...iatek.com>
---
.../vcodec/decoder/mtk_vcodec_dec_drv.h | 2 ++
.../vcodec/decoder/mtk_vcodec_dec_stateless.c | 29 ++++++++++++++-----
2 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h
index ac568ed14fa2..e70e97e401ba 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h
@@ -155,6 +155,7 @@ struct mtk_vcodec_dec_pdata {
* @last_decoded_picinfo: pic information get from latest decode
* @empty_flush_buf: a fake size-0 capture buffer that indicates flush. Used
* for stateful decoder.
+ * @cur_src_buffer: current vb2 buffer for the latest decode.
* @is_flushing: set to true if flushing is in progress.
*
* @current_codec: current set input codec, in V4L2 pixel format
@@ -201,6 +202,7 @@ struct mtk_vcodec_dec_ctx {
struct work_struct decode_work;
struct vdec_pic_info last_decoded_picinfo;
struct v4l2_m2m_buffer empty_flush_buf;
+ struct vb2_v4l2_buffer *cur_src_buffer;
bool is_flushing;
u32 current_codec;
diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
index dd6ee694382e..ad3c585e339d 100644
--- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
+++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c
@@ -316,7 +316,7 @@ static void mtk_vdec_worker(struct work_struct *work)
struct mtk_vcodec_dec_ctx *ctx =
container_of(work, struct mtk_vcodec_dec_ctx, decode_work);
struct mtk_vcodec_dec_dev *dev = ctx->dev;
- struct vb2_v4l2_buffer *vb2_v4l2_src;
+ struct vb2_v4l2_buffer *vb2_v4l2_src = ctx->cur_src_buffer;
struct vb2_buffer *vb2_src;
struct mtk_vcodec_mem *bs_src;
struct mtk_video_dec_buf *dec_buf_src;
@@ -325,7 +325,7 @@ static void mtk_vdec_worker(struct work_struct *work)
bool res_chg = false;
int ret;
- vb2_v4l2_src = v4l2_m2m_next_src_buf(ctx->m2m_ctx);
+ vb2_v4l2_src = vb2_v4l2_src ? vb2_v4l2_src : v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
if (!vb2_v4l2_src) {
v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
mtk_v4l2_vdec_dbg(1, ctx, "[%d] no available source buffer", ctx->id);
@@ -375,13 +375,26 @@ static void mtk_vdec_worker(struct work_struct *work)
v4l2_m2m_buf_done_and_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx, state);
v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
media_request_manual_complete(src_buf_req);
- } else {
- if (ret != -EAGAIN) {
- v4l2_m2m_src_buf_remove(ctx->m2m_ctx);
- v4l2_m2m_buf_done(vb2_v4l2_src, state);
- }
- v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
+
+ return;
}
+
+ /*
+ * If each codec return -EAGAIN to decode again, need to backup current source
+ * buffer, then the driver will get this buffer next time.
+ *
+ * If each codec decode error, must to set buffer done with error status for
+ * this buffer have been removed from ready list.
+ */
+ ctx->cur_src_buffer = (ret != -EAGAIN) ? NULL : vb2_v4l2_src;
+ if (ret && ret != -EAGAIN) {
+ v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl);
+ media_request_manual_complete(src_buf_req);
+ }
+
+ if (ret != -EAGAIN)
+ v4l2_m2m_buf_done(vb2_v4l2_src, state);
+ v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx);
}
static void vb2ops_vdec_stateless_buf_queue(struct vb2_buffer *vb)
--
2.46.0
Powered by blists - more mailing lists