Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures
@ 2026-11-30 13:02 Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 1/7] media: s5p-mfc: clear the EOS flag when a buffer is queued Shigeaki Asai via B4 Relay
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Shigeaki Asai via B4 Relay @ 2026-11-30 13:02 UTC (permalink / raw)
  To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
	Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel, Shigeaki Asai

On the ODROID-XU4 (Exynos5422), MFC decoding stops after a seek in
Kodi on LibreELEC, which uses the FFmpeg v4l2m2m decoder.

Patches 1, 2 and 4 fix seeking. FFmpeg drains the decoder with
V4L2_DEC_CMD_STOP before a seek and resumes it with V4L2_DEC_CMD_START,
but the driver did not handle this sequence correctly.
(FFmpeg also needs a fix to queue the empty capture buffer again after
a drain. I will send it to FFmpeg separately.)

Patch 3 reports the supported H.264 profiles, so that applications can
use another decoder for profiles that the MFC cannot decode (e.g. High
10).
(FFmpeg does not check this control yet. I will send a patch for it to
FFmpeg separately.)

Patches 5, 6 and 7 fix failures found by v4l2-compliance.

Tested on the ODROID-XU4 (Exynos5422, MFC v8) with a 7.3.4 kernel
(LibreELEC):

- Kodi plays and seeks H.264 and MPEG-2 videos, with no errors or
  warnings in dmesg.
- fluster, JVT-AVC_V1 with FFmpeg-H.264-v4l2m2m: 122/135 passed. The
  other 13 use features that the MFC does not support (Extended
  profile, FMO), are decoded wrongly by the MFC itself, or hit a crop
  offset issue in FFmpeg.
- v4l2-compliance 1.32.0: 42/49 passed without this series, 44/49 with
  it. The remaining 5 failures come from reading controls and formats
  before the stream header is parsed, and from the limit on the number
  of instances.

The analysis, the code and the changelogs were prepared with the help
of Claude (Anthropic), an AI assistant. I wrote this cover letter
myself, and Claude checked my English. I reviewed the code and tested
it on the hardware myself.

Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
---
Shigeaki Asai (7):
      media: s5p-mfc: clear the EOS flag when a buffer is queued
      media: s5p-mfc: support V4L2_DEC_CMD_START
      media: s5p-mfc: report the supported H.264 decoder profiles
      media: s5p-mfc: keep the remaining capture buffers queued after a drain
      media: s5p-mfc: support VIDIOC_TRY_DECODER_CMD
      media: s5p-mfc: allow subscribing to control events
      media: s5p-mfc: do not fail V4L2_DEC_CMD_STOP when not streaming

 drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c   | 17 ++++--
 .../media/platform/samsung/s5p-mfc/s5p_mfc_dec.c   | 66 +++++++++++++++++++++-
 2 files changed, 76 insertions(+), 7 deletions(-)
---
base-commit: 0b19af378cd5004bdf6bfaf7b3809fbbb0711a9b
change-id: 20261126-s5p-mfc-seek-10faff7c28e3

Best regards,
--  
Shigeaki Asai <y-asai.0816@docomonet.jp>




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/7] media: s5p-mfc: clear the EOS flag when a buffer is queued
  2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
@ 2026-11-30 13:02 ` Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 2/7] media: s5p-mfc: support V4L2_DEC_CMD_START Shigeaki Asai via B4 Relay
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Shigeaki Asai via B4 Relay @ 2026-11-30 13:02 UTC (permalink / raw)
  To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
	Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel, Shigeaki Asai

From: Shigeaki Asai <y-asai.0816@docomonet.jp>

V4L2_DEC_CMD_STOP marks the last queued source buffer with
MFC_BUF_FLAG_EOS. The flag is kept in the per-index buffer state and is
never cleared, so it is still set when the application queues the same
buffer index again after the drain. Decoding then stops (the context
enters the FINISHING state) every time that buffer is used, for example
after a seek in Kodi, which drains the decoder first.

The same applies to the destination buffers, which are marked with
MFC_BUF_FLAG_EOS when all frames are extracted.

Clear MFC_BUF_FLAG_EOS together with MFC_BUF_FLAG_USED when a buffer is
queued.

Tested on an ODROID-XU4 (Exynos5422) with Kodi/FFmpeg on a 7.3.4
kernel (LibreELEC).

The problem was investigated and this patch was prepared with the help
of Claude (AI).

Fixes: a34026e75bd1 ("[media] s5p-mfc: Add support for EOS command and EOS event in video decoder")
Fixes: 4d0b0ed63660 ("[media] s5p-mfc: use MFC_BUF_FLAG_EOS to identify last buffers in decoder capture queue")
Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
index afd28beabfde..1b6ea99bd415 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
@@ -1137,14 +1137,14 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
 
 	if (vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
 		mfc_buf = &ctx->src_bufs[vb->index];
-		mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
+		mfc_buf->flags &= ~(MFC_BUF_FLAG_USED | MFC_BUF_FLAG_EOS);
 		spin_lock_irqsave(&dev->irqlock, flags);
 		list_add_tail(&mfc_buf->list, &ctx->src_queue);
 		ctx->src_queue_cnt++;
 		spin_unlock_irqrestore(&dev->irqlock, flags);
 	} else if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) {
 		mfc_buf = &ctx->dst_bufs[vb->index];
-		mfc_buf->flags &= ~MFC_BUF_FLAG_USED;
+		mfc_buf->flags &= ~(MFC_BUF_FLAG_USED | MFC_BUF_FLAG_EOS);
 		/* Mark destination as available for use by MFC */
 		spin_lock_irqsave(&dev->irqlock, flags);
 		set_bit(vb->index, &ctx->dec_dst_flag);

-- 
2.43.0




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/7] media: s5p-mfc: support V4L2_DEC_CMD_START
  2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 1/7] media: s5p-mfc: clear the EOS flag when a buffer is queued Shigeaki Asai via B4 Relay
@ 2026-11-30 13:02 ` Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 3/7] media: s5p-mfc: report the supported H.264 decoder profiles Shigeaki Asai via B4 Relay
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Shigeaki Asai via B4 Relay @ 2026-11-30 13:02 UTC (permalink / raw)
  To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
	Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel, Shigeaki Asai

From: Shigeaki Asai <y-asai.0816@docomonet.jp>

The stateful decoder interface requires V4L2_DEC_CMD_START to resume
decoding after a drain, but the driver only implements
V4L2_DEC_CMD_STOP and returns -EINVAL for START. Clients such as
FFmpeg issue START after a seek, so the capture queue stays in the
"last buffer dequeued" state and decoding does not resume.

Implement START the same way as restarting the capture queue: put the
instance back into the running state, clear the last buffer state of
the capture queue and schedule the context if it is ready. If the
CAPTURE queue is not streaming, return 0 without doing anything, as
the specification says that the command does not fail in that case.

Tested on an ODROID-XU4 (Exynos5422) with Kodi/FFmpeg on a 7.3.4
kernel (LibreELEC).

The problem was investigated and this patch was prepared with the help
of Claude (AI).

Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
index 1b6ea99bd415..b46ccc0d9f3d 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
@@ -888,6 +888,25 @@ static int vidioc_decoder_cmd(struct file *file, void *priv,
 			spin_unlock_irqrestore(&dev->irqlock, flags);
 		}
 		break;
+	case V4L2_DEC_CMD_START:
+		if (cmd->flags != 0)
+			return -EINVAL;
+
+		if (!vb2_is_streaming(&ctx->vq_dst))
+			return 0;
+
+		spin_lock_irqsave(&dev->irqlock, flags);
+		if (ctx->state == MFCINST_FINISHING ||
+		    ctx->state == MFCINST_FINISHED)
+			ctx->state = MFCINST_RUNNING;
+		spin_unlock_irqrestore(&dev->irqlock, flags);
+
+		vb2_clear_last_buffer_dequeued(&ctx->vq_dst);
+
+		if (s5p_mfc_ctx_ready(ctx))
+			set_work_bit_irqsave(ctx);
+		s5p_mfc_hw_call(dev->mfc_ops, try_run, dev);
+		break;
 	default:
 		return -EINVAL;
 	}

-- 
2.43.0




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/7] media: s5p-mfc: report the supported H.264 decoder profiles
  2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 1/7] media: s5p-mfc: clear the EOS flag when a buffer is queued Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 2/7] media: s5p-mfc: support V4L2_DEC_CMD_START Shigeaki Asai via B4 Relay
@ 2026-11-30 13:02 ` Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 4/7] media: s5p-mfc: keep the remaining capture buffers queued after a drain Shigeaki Asai via B4 Relay
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Shigeaki Asai via B4 Relay @ 2026-11-30 13:02 UTC (permalink / raw)
  To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
	Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel, Shigeaki Asai

From: Shigeaki Asai <y-asai.0816@docomonet.jp>

The MFC decodes H.264 up to the High profile only: it supports neither
more than 8 bits nor other chroma formats than 4:2:0. The firmware does
not reject such streams (e.g. High 10) either, but outputs corrupted
frames, so applications have no way to know that they should use
another decoder.

Add a read-only V4L2_CID_MPEG_VIDEO_H264_PROFILE menu control to the
decoder, listing the profiles that can be decoded (Baseline,
Constrained Baseline, Main and High), as other stateful decoders do.
The stateful decoder interface lets clients query the supported
profiles with this control.

Tested on an ODROID-XU4 (Exynos5422) with Kodi/FFmpeg on a 7.3.4
kernel (LibreELEC).

The problem was investigated and this patch was prepared with the help
of Claude (AI).

Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
index b46ccc0d9f3d..281bb733ffa8 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
@@ -1207,6 +1207,7 @@ const struct v4l2_ioctl_ops *get_dec_v4l2_ioctl_ops(void)
 int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx)
 {
 	struct v4l2_ctrl_config cfg;
+	struct v4l2_ctrl *ctrl;
 	int i;
 
 	v4l2_ctrl_handler_init(&ctx->ctrl_handler, NUM_CTRLS);
@@ -1245,6 +1246,25 @@ int s5p_mfc_dec_ctrls_setup(struct s5p_mfc_ctx *ctx)
 		if (controls[i].is_volatile && ctx->ctrls[i])
 			ctx->ctrls[i]->flags |= V4L2_CTRL_FLAG_VOLATILE;
 	}
+
+	/*
+	 * Report the H.264 profiles that can be decoded, so that applications
+	 * can use another decoder for the others: there is no support for
+	 * more than 8 bits or for other chroma formats than 4:2:0 (High 10,
+	 * High 4:2:2, High 4:4:4), and the firmware does not reject such
+	 * streams but outputs corrupted frames.
+	 */
+	ctrl = v4l2_ctrl_new_std_menu(&ctx->ctrl_handler, &s5p_mfc_dec_ctrl_ops,
+				      V4L2_CID_MPEG_VIDEO_H264_PROFILE,
+				      V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
+				      BIT(V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED),
+				      V4L2_MPEG_VIDEO_H264_PROFILE_HIGH);
+	if (ctx->ctrl_handler.error) {
+		mfc_err("Adding H264 profile control failed\n");
+		return ctx->ctrl_handler.error;
+	}
+	ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
 	return 0;
 }
 

-- 
2.43.0




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/7] media: s5p-mfc: keep the remaining capture buffers queued after a drain
  2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
                   ` (2 preceding siblings ...)
  2026-11-30 13:02 ` [PATCH 3/7] media: s5p-mfc: report the supported H.264 decoder profiles Shigeaki Asai via B4 Relay
@ 2026-11-30 13:02 ` Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 5/7] media: s5p-mfc: support VIDIOC_TRY_DECODER_CMD Shigeaki Asai via B4 Relay
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Shigeaki Asai via B4 Relay @ 2026-11-30 13:02 UTC (permalink / raw)
  To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
	Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel, Shigeaki Asai

From: Shigeaki Asai <y-asai.0816@docomonet.jp>

When all frames have been extracted at the end of a drain, the driver
returns every queued capture buffer empty and marked with
V4L2_BUF_FLAG_LAST. The stateful decoder interface only expects a
single buffer marked with V4L2_BUF_FLAG_LAST. Clients such as FFmpeg
stop dequeuing after that buffer, so the other buffers are not queued
again and decoding stalls after V4L2_DEC_CMD_START because fewer than
pb_count buffers are available.

Return only one buffer at the end of a drain and keep the others queued.
On a resolution change all buffers are still returned, as they have to
be reallocated.

Tested on an ODROID-XU4 (Exynos5422) with Kodi/FFmpeg on a 7.3.4
kernel (LibreELEC).

The problem was investigated and this patch was prepared with the help
of Claude (AI).

Fixes: 52722ca8c532 ("[media] s5p-mfc: Set last buffer flag")
Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
index 03e7eac8d1f7..ea0fbf970340 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
@@ -222,7 +222,8 @@ static void s5p_mfc_watchdog_worker(struct work_struct *work)
 		mutex_unlock(&dev->mfc_mutex);
 }
 
-static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
+static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx,
+					       bool return_all)
 {
 	struct s5p_mfc_buf *dst_buf;
 	struct s5p_mfc_dev *dev = ctx->dev;
@@ -250,6 +251,14 @@ static void s5p_mfc_handle_frame_all_extracted(struct s5p_mfc_ctx *ctx)
 
 		ctx->dec_dst_flag &= ~(1 << dst_buf->b->vb2_buf.index);
 		vb2_buffer_done(&dst_buf->b->vb2_buf, VB2_BUF_STATE_DONE);
+
+		/*
+		 * At the end of a drain only one buffer is needed to signal
+		 * the last buffer. Keep the others queued so that they can be
+		 * used when decoding is restarted.
+		 */
+		if (!return_all)
+			break;
 	}
 }
 
@@ -409,13 +418,13 @@ static void s5p_mfc_handle_frame(struct s5p_mfc_ctx *ctx,
 					V4L2_EVENT_SRC_CH_RESOLUTION,
 			};
 
-			s5p_mfc_handle_frame_all_extracted(ctx);
+			s5p_mfc_handle_frame_all_extracted(ctx, true);
 			ctx->state = MFCINST_RES_CHANGE_END;
 			v4l2_event_queue_fh(&ctx->fh, &ev_src_ch);
 
 			goto leave_handle_frame;
 		} else {
-			s5p_mfc_handle_frame_all_extracted(ctx);
+			s5p_mfc_handle_frame_all_extracted(ctx, false);
 		}
 	}
 

-- 
2.43.0




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/7] media: s5p-mfc: support VIDIOC_TRY_DECODER_CMD
  2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
                   ` (3 preceding siblings ...)
  2026-11-30 13:02 ` [PATCH 4/7] media: s5p-mfc: keep the remaining capture buffers queued after a drain Shigeaki Asai via B4 Relay
@ 2026-11-30 13:02 ` Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 6/7] media: s5p-mfc: allow subscribing to control events Shigeaki Asai via B4 Relay
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Shigeaki Asai via B4 Relay @ 2026-11-30 13:02 UTC (permalink / raw)
  To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
	Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel, Shigeaki Asai

From: Shigeaki Asai <y-asai.0816@docomonet.jp>

The stateful decoder interface lets clients check a decoder command
with VIDIOC_TRY_DECODER_CMD, but the driver only implements
VIDIOC_DECODER_CMD, so v4l2-compliance reports:

  fail: v4l2-test-codecs.cpp(119): ret == ENOTTY
  test VIDIOC_(TRY_)DECODER_CMD: FAIL

Add a try_decoder_cmd handler that accepts V4L2_DEC_CMD_STOP and
V4L2_DEC_CMD_START and clears the fields the driver does not support,
like v4l2_m2m_ioctl_try_decoder_cmd() does for mem2mem drivers. The
driver does not use the mem2mem framework, so that helper cannot be
used directly.

Tested on an ODROID-XU4 (Exynos5422) with Kodi/FFmpeg and
v4l2-compliance 1.32.0 on a 7.3.4 kernel (LibreELEC).

The problem was investigated and this patch was prepared with the help
of Claude (AI).

Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
index 281bb733ffa8..99df8f5e36c8 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
@@ -853,6 +853,24 @@ static int vidioc_g_selection(struct file *file, void *priv,
 	return 0;
 }
 
+static int vidioc_try_decoder_cmd(struct file *file, void *priv,
+				  struct v4l2_decoder_cmd *cmd)
+{
+	switch (cmd->cmd) {
+	case V4L2_DEC_CMD_STOP:
+		cmd->stop.pts = 0;
+		break;
+	case V4L2_DEC_CMD_START:
+		cmd->start.speed = 0;
+		cmd->start.format = V4L2_DEC_START_FMT_NONE;
+		break;
+	default:
+		return -EINVAL;
+	}
+	cmd->flags = 0;
+	return 0;
+}
+
 static int vidioc_decoder_cmd(struct file *file, void *priv,
 			      struct v4l2_decoder_cmd *cmd)
 {
@@ -946,6 +964,7 @@ static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
 	.vidioc_streamon = vidioc_streamon,
 	.vidioc_streamoff = vidioc_streamoff,
 	.vidioc_g_selection = vidioc_g_selection,
+	.vidioc_try_decoder_cmd = vidioc_try_decoder_cmd,
 	.vidioc_decoder_cmd = vidioc_decoder_cmd,
 	.vidioc_subscribe_event = vidioc_subscribe_event,
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,

-- 
2.43.0




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/7] media: s5p-mfc: allow subscribing to control events
  2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
                   ` (4 preceding siblings ...)
  2026-11-30 13:02 ` [PATCH 5/7] media: s5p-mfc: support VIDIOC_TRY_DECODER_CMD Shigeaki Asai via B4 Relay
@ 2026-11-30 13:02 ` Shigeaki Asai via B4 Relay
  2026-11-30 13:02 ` [PATCH 7/7] media: s5p-mfc: do not fail V4L2_DEC_CMD_STOP when not streaming Shigeaki Asai via B4 Relay
  2026-12-01 12:53 ` [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Hans Verkuil
  7 siblings, 0 replies; 9+ messages in thread
From: Shigeaki Asai via B4 Relay @ 2026-11-30 13:02 UTC (permalink / raw)
  To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
	Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel, Shigeaki Asai

From: Shigeaki Asai <y-asai.0816@docomonet.jp>

The decoder has controls, but vidioc_subscribe_event() only accepts
V4L2_EVENT_EOS and V4L2_EVENT_SOURCE_CHANGE, so subscribing to control
events fails with -EINVAL. v4l2-compliance reports:

  fail: v4l2-test-controls.cpp(1128): subscribe event for control 'User Controls' failed
  test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: FAIL
  fail: v4l2-test-time32-64.cpp(141): doioctl(node, VIDIOC_SUBSCRIBE_EVENT, &sub)
  test TIME32/64: FAIL

Handle V4L2_EVENT_CTRL with v4l2_ctrl_subscribe_event(). The file
handle already points to the control handler of the context.

Control events are removed in v4l2_fh_exit(), which looks up the
controls in the handler, so free the control handler after
v4l2_fh_exit() in s5p_mfc_release(). Otherwise closing the device after
subscribing to a control event uses the freed handler:

  WARNING: kernel/locking/mutex.c:625 at __mutex_lock+0xba8/0x1088
  DEBUG_LOCKS_WARN_ON(lock->magic != lock)
   v4l2_ctrl_find [videodev] from v4l2_ctrl_del_event+0x1c/0x78 [videodev]
   ...
   v4l2_fh_exit [videodev] from s5p_mfc_release+0xfc/0x25c [s5p_mfc]

Tested on an ODROID-XU4 (Exynos5422) with Kodi/FFmpeg and
v4l2-compliance 1.32.0 on a 7.3.4 kernel (LibreELEC).

The problem was investigated and this patch was prepared with the help
of Claude (AI).

Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c     | 2 +-
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
index ea0fbf970340..0450c762e5ac 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c
@@ -1018,11 +1018,11 @@ static int s5p_mfc_release(struct file *file)
 	}
 	if (dev)
 		dev->ctx[ctx->num] = NULL;
-	s5p_mfc_dec_ctrls_delete(ctx);
 	v4l2_fh_del(&ctx->fh, file);
 	/* vdev is gone if dev is null */
 	if (dev)
 		v4l2_fh_exit(&ctx->fh);
+	s5p_mfc_dec_ctrls_delete(ctx);
 	kfree(ctx);
 	mfc_debug_leave();
 	if (dev)
diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
index 99df8f5e36c8..6b52617254d9 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
@@ -939,6 +939,8 @@ static int vidioc_subscribe_event(struct v4l2_fh *fh,
 		return v4l2_event_subscribe(fh, sub, 2, NULL);
 	case V4L2_EVENT_SOURCE_CHANGE:
 		return v4l2_src_change_event_subscribe(fh, sub);
+	case V4L2_EVENT_CTRL:
+		return v4l2_ctrl_subscribe_event(fh, sub);
 	default:
 		return -EINVAL;
 	}

-- 
2.43.0




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 7/7] media: s5p-mfc: do not fail V4L2_DEC_CMD_STOP when not streaming
  2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
                   ` (5 preceding siblings ...)
  2026-11-30 13:02 ` [PATCH 6/7] media: s5p-mfc: allow subscribing to control events Shigeaki Asai via B4 Relay
@ 2026-11-30 13:02 ` Shigeaki Asai via B4 Relay
  2026-12-01 12:53 ` [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Hans Verkuil
  7 siblings, 0 replies; 9+ messages in thread
From: Shigeaki Asai via B4 Relay @ 2026-11-30 13:02 UTC (permalink / raw)
  To: Marek Szyprowski, Andrzej Hajda, Mauro Carvalho Chehab,
	Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel, Shigeaki Asai

From: Shigeaki Asai <y-asai.0816@docomonet.jp>

The stateful decoder interface says that VIDIOC_DECODER_CMD with
V4L2_DEC_CMD_STOP does not fail if a queue is not streaming; it only
does not start the drain sequence. The driver returns -EINVAL when the
OUTPUT queue is not streaming, so v4l2-compliance reports:

  fail: v4l2-test-codecs.cpp(165): ret
  test VIDIOC_(TRY_)DECODER_CMD: FAIL

Return 0 in that case, without starting the drain sequence.

Tested on an ODROID-XU4 (Exynos5422) with Kodi/FFmpeg and
v4l2-compliance 1.32.0 on a 7.3.4 kernel (LibreELEC).

The problem was investigated and this patch was prepared with the help
of Claude (AI).

Fixes: a34026e75bd1 ("[media] s5p-mfc: Add support for EOS command and EOS event in video decoder")
Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
---
 drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
index 6b52617254d9..211301d902c3 100644
--- a/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/samsung/s5p-mfc/s5p_mfc_dec.c
@@ -885,7 +885,7 @@ static int vidioc_decoder_cmd(struct file *file, void *priv,
 			return -EINVAL;
 
 		if (!vb2_is_streaming(&ctx->vq_src))
-			return -EINVAL;
+			return 0;
 
 		spin_lock_irqsave(&dev->irqlock, flags);
 		if (list_empty(&ctx->src_queue)) {

-- 
2.43.0




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures
  2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
                   ` (6 preceding siblings ...)
  2026-11-30 13:02 ` [PATCH 7/7] media: s5p-mfc: do not fail V4L2_DEC_CMD_STOP when not streaming Shigeaki Asai via B4 Relay
@ 2026-12-01 12:53 ` Hans Verkuil
  7 siblings, 0 replies; 9+ messages in thread
From: Hans Verkuil @ 2026-12-01 12:53 UTC (permalink / raw)
  To: y-asai.0816, Marek Szyprowski, Andrzej Hajda,
	Mauro Carvalho Chehab, Kyngmin Park, Kamil Debski, Philipp Zabel
  Cc: linux-arm-kernel, linux-media, linux-kernel

On 30/11/2026 14:02, Shigeaki Asai via B4 Relay wrote:
> On the ODROID-XU4 (Exynos5422), MFC decoding stops after a seek in
> Kodi on LibreELEC, which uses the FFmpeg v4l2m2m decoder.
> 
> Patches 1, 2 and 4 fix seeking. FFmpeg drains the decoder with
> V4L2_DEC_CMD_STOP before a seek and resumes it with V4L2_DEC_CMD_START,
> but the driver did not handle this sequence correctly.
> (FFmpeg also needs a fix to queue the empty capture buffer again after
> a drain. I will send it to FFmpeg separately.)
> 
> Patch 3 reports the supported H.264 profiles, so that applications can
> use another decoder for profiles that the MFC cannot decode (e.g. High
> 10).
> (FFmpeg does not check this control yet. I will send a patch for it to
> FFmpeg separately.)
> 
> Patches 5, 6 and 7 fix failures found by v4l2-compliance.
> 
> Tested on the ODROID-XU4 (Exynos5422, MFC v8) with a 7.3.4 kernel
> (LibreELEC):
> 
> - Kodi plays and seeks H.264 and MPEG-2 videos, with no errors or
>   warnings in dmesg.
> - fluster, JVT-AVC_V1 with FFmpeg-H.264-v4l2m2m: 122/135 passed. The
>   other 13 use features that the MFC does not support (Extended
>   profile, FMO), are decoded wrongly by the MFC itself, or hit a crop
>   offset issue in FFmpeg.
> - v4l2-compliance 1.32.0: 42/49 passed without this series, 44/49 with
>   it. The remaining 5 failures come from reading controls and formats
>   before the stream header is parsed, and from the limit on the number
>   of instances.
> 
> The analysis, the code and the changelogs were prepared with the help
> of Claude (Anthropic), an AI assistant. I wrote this cover letter
> myself, and Claude checked my English. I reviewed the code and tested
> it on the hardware myself.

Nice series! Thank you for working on this, I'll merge it.

Regards,

	Hans

> 
> Signed-off-by: Shigeaki Asai <y-asai.0816@docomonet.jp>
> ---
> Shigeaki Asai (7):
>       media: s5p-mfc: clear the EOS flag when a buffer is queued
>       media: s5p-mfc: support V4L2_DEC_CMD_START
>       media: s5p-mfc: report the supported H.264 decoder profiles
>       media: s5p-mfc: keep the remaining capture buffers queued after a drain
>       media: s5p-mfc: support VIDIOC_TRY_DECODER_CMD
>       media: s5p-mfc: allow subscribing to control events
>       media: s5p-mfc: do not fail V4L2_DEC_CMD_STOP when not streaming
> 
>  drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c   | 17 ++++--
>  .../media/platform/samsung/s5p-mfc/s5p_mfc_dec.c   | 66 +++++++++++++++++++++-
>  2 files changed, 76 insertions(+), 7 deletions(-)
> ---
> base-commit: 0b19af378cd5004bdf6bfaf7b3809fbbb0711a9b
> change-id: 20261126-s5p-mfc-seek-10faff7c28e3
> 
> Best regards,
> --  
> Shigeaki Asai <y-asai.0816@docomonet.jp>
> 
> 
> 



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-12-01 12:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 13:02 [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Shigeaki Asai via B4 Relay
2026-11-30 13:02 ` [PATCH 1/7] media: s5p-mfc: clear the EOS flag when a buffer is queued Shigeaki Asai via B4 Relay
2026-11-30 13:02 ` [PATCH 2/7] media: s5p-mfc: support V4L2_DEC_CMD_START Shigeaki Asai via B4 Relay
2026-11-30 13:02 ` [PATCH 3/7] media: s5p-mfc: report the supported H.264 decoder profiles Shigeaki Asai via B4 Relay
2026-11-30 13:02 ` [PATCH 4/7] media: s5p-mfc: keep the remaining capture buffers queued after a drain Shigeaki Asai via B4 Relay
2026-11-30 13:02 ` [PATCH 5/7] media: s5p-mfc: support VIDIOC_TRY_DECODER_CMD Shigeaki Asai via B4 Relay
2026-11-30 13:02 ` [PATCH 6/7] media: s5p-mfc: allow subscribing to control events Shigeaki Asai via B4 Relay
2026-11-30 13:02 ` [PATCH 7/7] media: s5p-mfc: do not fail V4L2_DEC_CMD_STOP when not streaming Shigeaki Asai via B4 Relay
2026-12-01 12:53 ` [PATCH 0/7] media: s5p-mfc: fix seeking and some v4l2-compliance failures Hans Verkuil

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox