[PATCH v7 12/19] media: meson: vdec: Coordinate m2m task execution inside async loop
Anand Moon
linux.amoon at gmail.com
Mon Jul 13 05:07:07 PDT 2026
Introduce proper V4L2 Memory-to-Memory (m2m) scheduler pipeline tracking
by handling job finalisation inside the asynchronous esparser workqueue.
Because the meson video decoder offloads raw hardware register processing
and bitstream feeding to an internal workqueue engine, calling the helper
v4l2_m2m_job_finish() prematurely within the primary device execution
trigger context (vdec_m2m_device_run) drops the active task transaction
state too early. This timing gap creates a state mismatch in user-space
multimedia layers like GStreamer, resulting in a fatal "poll error 1"
event abort that breaks streaming setup sequences during pipeline preroll.
Resolve this architectural loop collision by deferring the scheduling call
to v4l2_m2m_job_finish() to execute exclusively within the worker routine
esparser_queue_all_src() at the precise microsecond after an input buffer
payload is fully validated, cleared, and returned via v4l2_m2m_buf_done().
Additionally, protect hardware session context mappings with core mutex
locks and implement volatile early exit gates within vdec_m2m_device_run()
to ensure stable teardowns.
Cc: Nicolas Dufresne <nicolas at ndufresne.ca>
Signed-off-by: Anand Moon <linux.amoon at gmail.com>
---
drivers/staging/media/meson/vdec/esparser.c | 4 ++++
drivers/staging/media/meson/vdec/vdec.c | 11 +++++++++++
2 files changed, 15 insertions(+)
diff --git a/drivers/staging/media/meson/vdec/esparser.c b/drivers/staging/media/meson/vdec/esparser.c
index b9f36fef4be12..939b239c2af47 100644
--- a/drivers/staging/media/meson/vdec/esparser.c
+++ b/drivers/staging/media/meson/vdec/esparser.c
@@ -399,6 +399,7 @@ void esparser_queue_all_src(struct work_struct *work)
struct amvdec_session *sess =
container_of(work, struct amvdec_session, esparser_queue_work);
struct device *dev = sess->core->dev_dec;
+ struct amvdec_core *core = sess->core;
int ret;
while (1) {
@@ -437,6 +438,9 @@ void esparser_queue_all_src(struct work_struct *work)
else
v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_DONE);
+ /* Safely notify the V4L2 core sub-framework */
+ v4l2_m2m_job_finish(core->m2m_dev, sess->m2m_ctx);
+
/* Set tracking flag indicating transaction completion */
processed_frame = true;
}
diff --git a/drivers/staging/media/meson/vdec/vdec.c b/drivers/staging/media/meson/vdec/vdec.c
index 0eb39aa6014ee..b3e1d99e8889f 100644
--- a/drivers/staging/media/meson/vdec/vdec.c
+++ b/drivers/staging/media/meson/vdec/vdec.c
@@ -149,6 +149,17 @@ vdec_queue_recycle(struct amvdec_session *sess, struct vb2_buffer *vb)
static void vdec_m2m_device_run(void *priv)
{
struct amvdec_session *sess = priv;
+ struct amvdec_core *core = sess->core;
+
+ if (READ_ONCE(sess->should_stop)) {
+ v4l2_m2m_job_finish(core->m2m_dev, sess->m2m_ctx);
+ return;
+ }
+
+ mutex_lock(&core->lock);
+ if (!core->cur_sess)
+ core->cur_sess = sess;
+ mutex_unlock(&core->lock);
schedule_work(&sess->esparser_queue_work);
}
--
2.50.1
More information about the linux-amlogic
mailing list