mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] media: venus: Fix end-of-stream and seeks on SDM845
@ 2026-11-22  5:13 EMCP333 via B4 Relay
  2026-11-22  5:13 ` [PATCH 1/2] media: venus: Signal end-of-stream with a mapped buffer EMCP333 via B4 Relay
  2026-11-22  5:13 ` [PATCH 2/2] media: venus: vdec: Resume CAPTURE restarted during a seek EMCP333 via B4 Relay
  0 siblings, 2 replies; 5+ messages in thread
From: EMCP333 via B4 Relay @ 2026-11-22  5:13 UTC (permalink / raw)
  To: Vikash Garodia, Dikshita Agarwal
  Cc: Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil,
	Stanimir Varbanov, linux-media, linux-arm-msm, linux-kernel,
	EMCP333

Two fixes for the Venus decoder and encoder, found on a OnePlus 6T
(SDM845, firmware VIDEO.VE.5.2-00050-PROD-1) while using it from
GStreamer, ffmpeg and mpv.

Patch 1 gives the end-of-stream buffer that the STOP commands queue a
real, mapped address instead of the made-up 0xdeadb000. This firmware
rejects the made-up address, which leaves the encoder unusable until
reboot and decoder clients draining forever.

Patch 2 makes a CAPTURE STREAMON issued while OUTPUT is stopped for a
seek take effect when OUTPUT restarts. That is the order GStreamer uses
for every flushing seek, and without it the seek never completes.

Both were tested on the phone with the postmarketOS sdm845 kernel
(6.18). On v7.4-rc2 the driver builds with W=1 and no warnings.

Both also ran on v7.4-rc3: three encodes drained by V4L2_ENC_CMD_STOP
and decoded back (90 of 90 frames), and three flushing seeks through
GStreamer completed in 0.02 s each, with no venus errors.

One related problem is not addressed here: from 1280x720 up, the encoder
bitstream buffer is an eighth of the size used just below 720p, and
this firmware produces nothing with it. Fixing that properly needs the
firmware's own buffer requirement rather than a bigger guess, so it is
left for a separate change.

---
EMCP333 (2):
      media: venus: Signal end-of-stream with a mapped buffer
      media: venus: vdec: Resume CAPTURE restarted during a seek

 drivers/media/platform/qcom/venus/core.h    |  7 +++++
 drivers/media/platform/qcom/venus/helpers.c | 40 +++++++++++++++++++++++++++++
 drivers/media/platform/qcom/venus/helpers.h |  3 +++
 drivers/media/platform/qcom/venus/vdec.c    | 33 +++++++++++++++++++++---
 drivers/media/platform/qcom/venus/venc.c    |  7 ++++-
 5 files changed, 85 insertions(+), 5 deletions(-)
---
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
change-id: 20261122-b4-venus-eos-seek-def2919e88d5

Best regards,
--  
EMCP333 <emcp@enser.io>



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

* [PATCH 1/2] media: venus: Signal end-of-stream with a mapped buffer
  2026-11-22  5:13 [PATCH 0/2] media: venus: Fix end-of-stream and seeks on SDM845 EMCP333 via B4 Relay
@ 2026-11-22  5:13 ` EMCP333 via B4 Relay
  2026-11-22 22:56   ` Bryan O'Donoghue
  2026-11-22  5:13 ` [PATCH 2/2] media: venus: vdec: Resume CAPTURE restarted during a seek EMCP333 via B4 Relay
  1 sibling, 1 reply; 5+ messages in thread
From: EMCP333 via B4 Relay @ 2026-11-22  5:13 UTC (permalink / raw)
  To: Vikash Garodia, Dikshita Agarwal
  Cc: Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil,
	Stanimir Varbanov, linux-media, linux-arm-msm, linux-kernel,
	EMCP333

From: EMCP333 <emcp@enser.io>

V4L2_ENC_CMD_STOP and V4L2_DEC_CMD_STOP signal end-of-stream by queueing
an empty input buffer at the made-up device address 0xdeadb000. The
SDM845 firmware on a OnePlus 6T (VIDEO.VE.5.2-00050-PROD-1) rejects it:

  qcom-venus aa00000.video-codec: session error: event id:1001 (deadb000)

and the LAST buffer never comes back. An encoder session then goes on to
session error 1006 and a system error whose recovery fails ("recovery
failed to init HFI"), and the encoder is unusable until reboot. A decoder
leaves the client draining forever: ffmpeg and mpv with v4l2m2m decoded
1188 of 1200 frames of a clip, then hung at end of file.

A zero-length buffer queued by userspace reaches the firmware with the
EOS flag at its real, mapped address, and is accepted. Do the same for
STOP: allocate one small buffer per instance the first time STOP is
issued, against the core device like the internal buffers, and free it
once the session has been destroyed at close. The IRIS2 branch for old
firmware, which needs address 0, is unchanged.

Tested on a OnePlus 6T with this change on the postmarketOS sdm845
kernel (6.18): three 640x480 H.264 encodes in one boot, each drained
with ENC_CMD_STOP, all reach end-of-stream with a valid stream; decoding
one of them returns all 90 frames and end-of-stream; no session or
system errors are logged.

The code and this changelog were prepared with the help of an AI coding
assistant. The submitter has reviewed both and takes responsibility for
them.

Fixes: e69b987a9759 ("media: venus: reimplement decoder stop command")
Fixes: 7493db46e4c4 ("venus: venc: add handling for VIDIOC_ENCODER_CMD")
Signed-off-by: EMCP333 <emcp@enser.io>
---
 drivers/media/platform/qcom/venus/core.h    |  4 ++++
 drivers/media/platform/qcom/venus/helpers.c | 35 +++++++++++++++++++++++++++++
 drivers/media/platform/qcom/venus/helpers.h |  3 +++
 drivers/media/platform/qcom/venus/vdec.c    | 11 ++++++---
 drivers/media/platform/qcom/venus/venc.c    |  7 +++++-
 5 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h
index 93fa77f058..f521bccfe3 100644
--- a/drivers/media/platform/qcom/venus/core.h
+++ b/drivers/media/platform/qcom/venus/core.h
@@ -463,6 +463,8 @@ enum venus_inst_modes {
  * @drain_active:	Drain sequence is in progress
  * @flags:	bitmask flags describing current instance mode
  * @dpb_ids:	DPB buffer ID's
+ * @eos_va:	CPU address of the empty buffer that carries end-of-stream
+ * @eos_da:	device address of that buffer
  */
 struct venus_inst {
 	struct list_head list;
@@ -534,6 +536,8 @@ struct venus_inst {
 	bool drain_active;
 	enum venus_inst_modes flags;
 	struct ida dpb_ids;
+	void *eos_va;
+	dma_addr_t eos_da;
 };
 
 #define IS_V1(core)	((core)->res->hfi_version == HFI_VERSION_1XX)
diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c
index 59eee3dd9e..e0bd2b0478 100644
--- a/drivers/media/platform/qcom/venus/helpers.c
+++ b/drivers/media/platform/qcom/venus/helpers.c
@@ -3,9 +3,11 @@
  * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
  * Copyright (C) 2017 Linaro Ltd.
  */
+#include <linux/dma-mapping.h>
 #include <linux/idr.h>
 #include <linux/list.h>
 #include <linux/mutex.h>
+#include <linux/sizes.h>
 #include <linux/slab.h>
 #include <linux/kernel.h>
 #include <media/videobuf2-dma-contig.h>
@@ -1541,6 +1543,39 @@ void venus_helper_buffers_done(struct venus_inst *inst, unsigned int type,
 }
 EXPORT_SYMBOL_GPL(venus_helper_buffers_done);
 
+#define VENUS_EOS_BUF_SIZE	SZ_4K
+
+/*
+ * The STOP commands signal end-of-stream with an empty input buffer. Give it
+ * a real, mapped address, as a zero-length buffer queued by userspace has:
+ * SDM845 firmware rejects a made-up one (session error 1001), and the LAST
+ * buffer then never comes back.
+ */
+int venus_helper_eos_buf(struct venus_inst *inst, struct hfi_frame_data *fdata)
+{
+	if (!inst->eos_va) {
+		inst->eos_va = dma_alloc_attrs(inst->core->dev, VENUS_EOS_BUF_SIZE,
+					       &inst->eos_da, GFP_KERNEL, 0);
+		if (!inst->eos_va)
+			return -ENOMEM;
+	}
+	fdata->device_addr = inst->eos_da;
+	fdata->alloc_len = VENUS_EOS_BUF_SIZE;
+	fdata->filled_len = 0;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(venus_helper_eos_buf);
+
+void venus_helper_free_eos(struct venus_inst *inst)
+{
+	if (!inst->eos_va)
+		return;
+	dma_free_attrs(inst->core->dev, VENUS_EOS_BUF_SIZE, inst->eos_va,
+		       inst->eos_da, 0);
+	inst->eos_va = NULL;
+}
+EXPORT_SYMBOL_GPL(venus_helper_free_eos);
+
 void venus_helper_vb2_stop_streaming(struct vb2_queue *q)
 {
 	struct venus_inst *inst = vb2_get_drv_priv(q);
diff --git a/drivers/media/platform/qcom/venus/helpers.h b/drivers/media/platform/qcom/venus/helpers.h
index 358e4f39c9..6acae43459 100644
--- a/drivers/media/platform/qcom/venus/helpers.h
+++ b/drivers/media/platform/qcom/venus/helpers.h
@@ -10,6 +10,7 @@
 
 struct venus_inst;
 struct venus_core;
+struct hfi_frame_data;
 
 bool venus_helper_check_codec(struct venus_inst *inst, u32 v4l2_pixfmt);
 struct vb2_v4l2_buffer *venus_helper_find_buf(struct venus_inst *inst,
@@ -71,4 +72,6 @@ int venus_helper_get_profile_level(struct venus_inst *inst, u32 *profile, u32 *l
 int venus_helper_set_profile_level(struct venus_inst *inst, u32 profile, u32 level);
 int venus_helper_set_stride(struct venus_inst *inst, unsigned int aligned_width,
 			    unsigned int aligned_height);
+int venus_helper_eos_buf(struct venus_inst *inst, struct hfi_frame_data *fdata);
+void venus_helper_free_eos(struct venus_inst *inst);
 #endif
diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
index 6a43ea191d..a49acef5db 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -574,10 +574,13 @@ vdec_decoder_cmd(struct file *file, void *fh, struct v4l2_decoder_cmd *cmd)
 		 * avoids misapplying this quirk and breaking VP9 decode on SC7280.
 		 */
 
-		if (IS_IRIS2(inst->core) && is_fw_rev_or_older(inst->core, 1, 0, 87))
+		if (IS_IRIS2(inst->core) && is_fw_rev_or_older(inst->core, 1, 0, 87)) {
 			fdata.device_addr = 0;
-		else
-			fdata.device_addr = 0xdeadb000;
+		} else {
+			ret = venus_helper_eos_buf(inst, &fdata);
+			if (ret)
+				goto unlock;
+		}
 
 		ret = hfi_session_process_buf(inst, &fdata);
 
@@ -1762,6 +1765,8 @@ static int vdec_close(struct file *file)
 	vdec_pm_get(inst);
 	cancel_work_sync(&inst->delayed_process_work);
 	venus_close_common(inst, file);
+	/* The session is destroyed, so the firmware can no longer touch it. */
+	venus_helper_free_eos(inst);
 	ida_destroy(&inst->dpb_ids);
 	vdec_pm_put(inst, false);
 
diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/venus/venc.c
index 79acf7c1ec..9c2b602568 100644
--- a/drivers/media/platform/qcom/venus/venc.c
+++ b/drivers/media/platform/qcom/venus/venc.c
@@ -548,7 +548,10 @@ venc_encoder_cmd(struct file *file, void *fh, struct v4l2_encoder_cmd *cmd)
 
 		fdata.buffer_type = HFI_BUFFER_INPUT;
 		fdata.flags |= HFI_BUFFERFLAG_EOS;
-		fdata.device_addr = 0xdeadb000;
+
+		ret = venus_helper_eos_buf(inst, &fdata);
+		if (ret)
+			goto unlock;
 
 		ret = hfi_session_process_buf(inst, &fdata);
 
@@ -1538,6 +1541,8 @@ static int venc_close(struct file *file)
 
 	venc_pm_get(inst);
 	venus_close_common(inst, file);
+	/* The session is destroyed, so the firmware can no longer touch it. */
+	venus_helper_free_eos(inst);
 	inst->enc_state = VENUS_ENC_STATE_DEINIT;
 	venc_pm_put(inst, false);
 

-- 
2.47.3



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

* [PATCH 2/2] media: venus: vdec: Resume CAPTURE restarted during a seek
  2026-11-22  5:13 [PATCH 0/2] media: venus: Fix end-of-stream and seeks on SDM845 EMCP333 via B4 Relay
  2026-11-22  5:13 ` [PATCH 1/2] media: venus: Signal end-of-stream with a mapped buffer EMCP333 via B4 Relay
@ 2026-11-22  5:13 ` EMCP333 via B4 Relay
  2026-11-22 23:09   ` Bryan O'Donoghue
  1 sibling, 1 reply; 5+ messages in thread
From: EMCP333 via B4 Relay @ 2026-11-22  5:13 UTC (permalink / raw)
  To: Vikash Garodia, Dikshita Agarwal
  Cc: Bryan O'Donoghue, Mauro Carvalho Chehab, Hans Verkuil,
	Stanimir Varbanov, linux-media, linux-arm-msm, linux-kernel,
	EMCP333

From: EMCP333 <emcp@enser.io>

GStreamer's V4L2 decoder handles a flushing seek by calling STREAMOFF on
both queues, then STREAMON on CAPTURE, then STREAMON on OUTPUT when the
first buffer of the new segment arrives. On a OnePlus 6T (SDM845) the
seek never completes: the decoder takes two OUTPUT buffers, produces
nothing, and the pipeline times out waiting for preroll.

The driver loses CAPTURE in that order:

  STREAMOFF OUTPUT   vdec_stop_output()    DECODING -> SEEK, flush
  STREAMOFF CAPTURE  vdec_stop_capture()   SEEK: buffers cancelled
  STREAMON  CAPTURE  vdec_start_capture()  streamon_out is 0: return 0,
                                           streamon_cap stays 0
  STREAMON  OUTPUT   vdec_start_output()   SEEK -> DECODING, but capture
                                           buffers are queued only if
                                           streamon_cap is set

so the buffers CAPTURE was restarted with stay in the m2m queue and the
firmware has nothing to decode into. A seek that restarts only OUTPUT,
as ffmpeg and mpv do, is not affected.

Remember a CAPTURE restart that happens while OUTPUT is stopped in the
SEEK state, hold the capture buffers queued meanwhile, and hand them to
the firmware together with the DPB buffers when OUTPUT restarts. Clear
the flag whenever CAPTURE is stopped again.

Tested on a OnePlus 6T with this change on the postmarketOS sdm845
kernel (6.18): three flushing seeks through GStreamer's v4l2h264dec, to
5, 2 and 8 s of a 10 s clip, each preroll in 0.04-0.07 s with the first
frame at the exact target timestamp, and playback then runs to
end-of-stream.

The code and this changelog were prepared with the help of an AI coding
assistant. The submitter has reviewed both and takes responsibility for
them.

Fixes: beac82904a87 ("media: venus: make decoder compliant with stateful codec API")
Signed-off-by: EMCP333 <emcp@enser.io>
---
 drivers/media/platform/qcom/venus/core.h    |  3 +++
 drivers/media/platform/qcom/venus/helpers.c |  5 +++++
 drivers/media/platform/qcom/venus/vdec.c    | 22 +++++++++++++++++++++-
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h
index f521bccfe3..a6e898ca83 100644
--- a/drivers/media/platform/qcom/venus/core.h
+++ b/drivers/media/platform/qcom/venus/core.h
@@ -461,6 +461,8 @@ enum venus_inst_modes {
  * @pic_struct:		bitstream progressive vs interlaced
  * @next_buf_last: a flag to mark next queued capture buffer as last
  * @drain_active:	Drain sequence is in progress
+ * @cap_resume:	CAPTURE was restarted while OUTPUT was stopped for a seek;
+ *		its buffers wait until OUTPUT restarts
  * @flags:	bitmask flags describing current instance mode
  * @dpb_ids:	DPB buffer ID's
  * @eos_va:	CPU address of the empty buffer that carries end-of-stream
@@ -534,6 +536,7 @@ struct venus_inst {
 	unsigned int pic_struct;
 	bool next_buf_last;
 	bool drain_active;
+	bool cap_resume;
 	enum venus_inst_modes flags;
 	struct ida dpb_ids;
 	void *eos_va;
diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c
index e0bd2b0478..425caf6b34 100644
--- a/drivers/media/platform/qcom/venus/helpers.c
+++ b/drivers/media/platform/qcom/venus/helpers.c
@@ -1512,6 +1512,11 @@ void venus_helper_vb2_buf_queue(struct vb2_buffer *vb)
 
 	cache_payload(inst, vb);
 
+	/* Held until OUTPUT restarts after a seek: see vdec_start_capture() */
+	if (inst->session_type == VIDC_SESSION_TYPE_DEC &&
+	    V4L2_TYPE_IS_CAPTURE(vb->vb2_queue->type) && inst->cap_resume)
+		return;
+
 	if (inst->session_type == VIDC_SESSION_TYPE_ENC &&
 	    !(inst->streamon_out && inst->streamon_cap))
 		return;
diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
index a49acef5db..9c076379ed 100644
--- a/drivers/media/platform/qcom/venus/vdec.c
+++ b/drivers/media/platform/qcom/venus/vdec.c
@@ -1044,8 +1044,17 @@ static int vdec_start_capture(struct venus_inst *inst)
 {
 	int ret;
 
-	if (!inst->streamon_out)
+	if (!inst->streamon_out) {
+		/*
+		 * CAPTURE restarted while OUTPUT is stopped for a seek, as
+		 * GStreamer does on every flushing seek. Its buffers can only go
+		 * to the firmware once OUTPUT restarts, so remember it for
+		 * vdec_start_output().
+		 */
+		if (inst->codec_state == VENUS_DEC_STATE_SEEK)
+			inst->cap_resume = true;
 		return 0;
+	}
 
 	if (inst->codec_state == VENUS_DEC_STATE_DECODING) {
 		if (inst->reconfig)
@@ -1130,8 +1139,17 @@ static int vdec_start_output(struct venus_inst *inst)
 				ret = venus_helper_queue_dpb_bufs(inst);
 				if (ret)
 					return ret;
+			} else if (inst->cap_resume) {
+				ret = venus_helper_queue_dpb_bufs(inst);
+				if (ret)
+					return ret;
+				ret = venus_helper_process_initial_cap_bufs(inst);
+				if (ret)
+					return ret;
+				inst->streamon_cap = 1;
 			}
 		}
+		inst->cap_resume = false;
 		goto done;
 	}
 
@@ -1236,6 +1254,8 @@ static int vdec_stop_capture(struct venus_inst *inst)
 {
 	int ret = 0;
 
+	inst->cap_resume = false;
+
 	switch (inst->codec_state) {
 	case VENUS_DEC_STATE_DECODING:
 		ret = hfi_session_flush(inst, HFI_FLUSH_ALL, true);

-- 
2.47.3



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

* Re: [PATCH 1/2] media: venus: Signal end-of-stream with a mapped buffer
  2026-11-22  5:13 ` [PATCH 1/2] media: venus: Signal end-of-stream with a mapped buffer EMCP333 via B4 Relay
@ 2026-11-22 22:56   ` Bryan O'Donoghue
  0 siblings, 0 replies; 5+ messages in thread
From: Bryan O'Donoghue @ 2026-11-22 22:56 UTC (permalink / raw)
  To: emcp, Vikash Garodia, Dikshita Agarwal
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Stanimir Varbanov,
	linux-media, linux-arm-msm, linux-kernel

On 22/11/2026 05:13, EMCP333 via B4 Relay wrote:
> From: EMCP333 <emcp@enser.io>
> 
> V4L2_ENC_CMD_STOP and V4L2_DEC_CMD_STOP signal end-of-stream by queueing
> an empty input buffer at the made-up device address 0xdeadb000. The
> SDM845 firmware on a OnePlus 6T (VIDEO.VE.5.2-00050-PROD-1) rejects it:
> 
>    qcom-venus aa00000.video-codec: session error: event id:1001 (deadb000)
> 
> and the LAST buffer never comes back. An encoder session then goes on to
> session error 1006 and a system error whose recovery fails ("recovery
> failed to init HFI"), and the encoder is unusable until reboot. A decoder
> leaves the client draining forever: ffmpeg and mpv with v4l2m2m decoded
> 1188 of 1200 frames of a clip, then hung at end of file.
> 
> A zero-length buffer queued by userspace reaches the firmware with the
> EOS flag at its real, mapped address, and is accepted. Do the same for
> STOP: allocate one small buffer per instance the first time STOP is
> issued, against the core device like the internal buffers, and free it
> once the session has been destroyed at close. The IRIS2 branch for old
> firmware, which needs address 0, is unchanged.
> 
> Tested on a OnePlus 6T with this change on the postmarketOS sdm845
> kernel (6.18): three 640x480 H.264 encodes in one boot, each drained
> with ENC_CMD_STOP, all reach end-of-stream with a valid stream; decoding
> one of them returns all 90 frames and end-of-stream; no session or
> system errors are logged.
> 
> The code and this changelog were prepared with the help of an AI coding
> assistant. The submitter has reviewed both and takes responsibility for
> them.
> 
> Fixes: e69b987a9759 ("media: venus: reimplement decoder stop command")
> Fixes: 7493db46e4c4 ("venus: venc: add handling for VIDIOC_ENCODER_CMD")
> Signed-off-by: EMCP333 <emcp@enser.io>
> ---
>   drivers/media/platform/qcom/venus/core.h    |  4 ++++
>   drivers/media/platform/qcom/venus/helpers.c | 35 +++++++++++++++++++++++++++++
>   drivers/media/platform/qcom/venus/helpers.h |  3 +++
>   drivers/media/platform/qcom/venus/vdec.c    | 11 ++++++---
>   drivers/media/platform/qcom/venus/venc.c    |  7 +++++-
>   5 files changed, 56 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/venus/core.h
> index 93fa77f058..f521bccfe3 100644
> --- a/drivers/media/platform/qcom/venus/core.h
> +++ b/drivers/media/platform/qcom/venus/core.h
> @@ -463,6 +463,8 @@ enum venus_inst_modes {
>    * @drain_active:	Drain sequence is in progress
>    * @flags:	bitmask flags describing current instance mode
>    * @dpb_ids:	DPB buffer ID's
> + * @eos_va:	CPU address of the empty buffer that carries end-of-stream
> + * @eos_da:	device address of that buffer
>    */
>   struct venus_inst {
>   	struct list_head list;
> @@ -534,6 +536,8 @@ struct venus_inst {
>   	bool drain_active;
>   	enum venus_inst_modes flags;
>   	struct ida dpb_ids;
> +	void *eos_va;
> +	dma_addr_t eos_da;
>   };
> 
>   #define IS_V1(core)	((core)->res->hfi_version == HFI_VERSION_1XX)
> diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/venus/helpers.c
> index 59eee3dd9e..e0bd2b0478 100644
> --- a/drivers/media/platform/qcom/venus/helpers.c
> +++ b/drivers/media/platform/qcom/venus/helpers.c
> @@ -3,9 +3,11 @@
>    * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
>    * Copyright (C) 2017 Linaro Ltd.
>    */
> +#include <linux/dma-mapping.h>
>   #include <linux/idr.h>
>   #include <linux/list.h>
>   #include <linux/mutex.h>
> +#include <linux/sizes.h>
>   #include <linux/slab.h>
>   #include <linux/kernel.h>
>   #include <media/videobuf2-dma-contig.h>
> @@ -1541,6 +1543,39 @@ void venus_helper_buffers_done(struct venus_inst *inst, unsigned int type,
>   }
>   EXPORT_SYMBOL_GPL(venus_helper_buffers_done);
> 
> +#define VENUS_EOS_BUF_SIZE	SZ_4K
> +
> +/*
> + * The STOP commands signal end-of-stream with an empty input buffer. Give it
> + * a real, mapped address, as a zero-length buffer queued by userspace has:
> + * SDM845 firmware rejects a made-up one (session error 1001), and the LAST
> + * buffer then never comes back.
> + */
> +int venus_helper_eos_buf(struct venus_inst *inst, struct hfi_frame_data *fdata)
> +{
> +	if (!inst->eos_va) {
> +		inst->eos_va = dma_alloc_attrs(inst->core->dev, VENUS_EOS_BUF_SIZE,
> +					       &inst->eos_da, GFP_KERNEL, 0);
> +		if (!inst->eos_va)
> +			return -ENOMEM;
> +	}
> +	fdata->device_addr = inst->eos_da;
> +	fdata->alloc_len = VENUS_EOS_BUF_SIZE;
> +	fdata->filled_len = 0;
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(venus_helper_eos_buf);
> +
> +void venus_helper_free_eos(struct venus_inst *inst)
> +{
> +	if (!inst->eos_va)
> +		return;
> +	dma_free_attrs(inst->core->dev, VENUS_EOS_BUF_SIZE, inst->eos_va,
> +		       inst->eos_da, 0);
> +	inst->eos_va = NULL;
> +}
> +EXPORT_SYMBOL_GPL(venus_helper_free_eos);
> +
>   void venus_helper_vb2_stop_streaming(struct vb2_queue *q)
>   {
>   	struct venus_inst *inst = vb2_get_drv_priv(q);
> diff --git a/drivers/media/platform/qcom/venus/helpers.h b/drivers/media/platform/qcom/venus/helpers.h
> index 358e4f39c9..6acae43459 100644
> --- a/drivers/media/platform/qcom/venus/helpers.h
> +++ b/drivers/media/platform/qcom/venus/helpers.h
> @@ -10,6 +10,7 @@
> 
>   struct venus_inst;
>   struct venus_core;
> +struct hfi_frame_data;
> 
>   bool venus_helper_check_codec(struct venus_inst *inst, u32 v4l2_pixfmt);
>   struct vb2_v4l2_buffer *venus_helper_find_buf(struct venus_inst *inst,
> @@ -71,4 +72,6 @@ int venus_helper_get_profile_level(struct venus_inst *inst, u32 *profile, u32 *l
>   int venus_helper_set_profile_level(struct venus_inst *inst, u32 profile, u32 level);
>   int venus_helper_set_stride(struct venus_inst *inst, unsigned int aligned_width,
>   			    unsigned int aligned_height);
> +int venus_helper_eos_buf(struct venus_inst *inst, struct hfi_frame_data *fdata);
> +void venus_helper_free_eos(struct venus_inst *inst);
>   #endif
> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/venus/vdec.c
> index 6a43ea191d..a49acef5db 100644
> --- a/drivers/media/platform/qcom/venus/vdec.c
> +++ b/drivers/media/platform/qcom/venus/vdec.c
> @@ -574,10 +574,13 @@ vdec_decoder_cmd(struct file *file, void *fh, struct v4l2_decoder_cmd *cmd)
>   		 * avoids misapplying this quirk and breaking VP9 decode on SC7280.
>   		 */
> 
> -		if (IS_IRIS2(inst->core) && is_fw_rev_or_older(inst->core, 1, 0, 87))
> +		if (IS_IRIS2(inst->core) && is_fw_rev_or_older(inst->core, 1, 0, 87)) {
>   			fdata.device_addr = 0;
> -		else
> -			fdata.device_addr = 0xdeadb000;
> +		} else {
> +			ret = venus_helper_eos_buf(inst, &fdata);
> +			if (ret)
> +				goto unlock;
> +		}

Duplicates: 
https://patchwork.linuxtv.org/project/linux-media/patch/20260928-venus-vdec-eos-v1-1-6e9eb3ce9849@ixit.cz/

---
bod


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

* Re: [PATCH 2/2] media: venus: vdec: Resume CAPTURE restarted during a seek
  2026-11-22  5:13 ` [PATCH 2/2] media: venus: vdec: Resume CAPTURE restarted during a seek EMCP333 via B4 Relay
@ 2026-11-22 23:09   ` Bryan O'Donoghue
  0 siblings, 0 replies; 5+ messages in thread
From: Bryan O'Donoghue @ 2026-11-22 23:09 UTC (permalink / raw)
  To: emcp, Vikash Garodia, Dikshita Agarwal
  Cc: Mauro Carvalho Chehab, Hans Verkuil, Stanimir Varbanov,
	linux-media, linux-arm-msm, linux-kernel

On 22/11/2026 05:13, EMCP333 via B4 Relay wrote:
> From: EMCP333 <emcp@enser.io>
> 
> GStreamer's V4L2 decoder handles a flushing seek by calling STREAMOFF on
> both queues, then STREAMON on CAPTURE, then STREAMON on OUTPUT when the
> first buffer of the new segment arrives. On a OnePlus 6T (SDM845) the
> seek never completes: the decoder takes two OUTPUT buffers, produces
> nothing, and the pipeline times out waiting for preroll.
> 
> The driver loses CAPTURE in that order:
> 
>    STREAMOFF OUTPUT   vdec_stop_output()    DECODING -> SEEK, flush
>    STREAMOFF CAPTURE  vdec_stop_capture()   SEEK: buffers cancelled
>    STREAMON  CAPTURE  vdec_start_capture()  streamon_out is 0: return 0,
>                                             streamon_cap stays 0
>    STREAMON  OUTPUT   vdec_start_output()   SEEK -> DECODING, but capture
>                                             buffers are queued only if
>                                             streamon_cap is set
> 
> so the buffers CAPTURE was restarted with stay in the m2m queue and the
> firmware has nothing to decode into. A seek that restarts only OUTPUT,
> as ffmpeg and mpv do, is not affected.
> 
> Remember a CAPTURE restart that happens while OUTPUT is stopped in the
> SEEK state, hold the capture buffers queued meanwhile, and hand them to
> the firmware together with the DPB buffers when OUTPUT restarts. Clear
> the flag whenever CAPTURE is stopped again.
> 
> Tested on a OnePlus 6T with this change on the postmarketOS sdm845
> kernel (6.18): three flushing seeks through GStreamer's v4l2h264dec, to
> 5, 2 and 8 s of a 10 s clip, each preroll in 0.04-0.07 s with the first
> frame at the exact target timestamp, and playback then runs to
> end-of-stream.
> 
> The code and this changelog were prepared with the help of an AI coding
> assistant. The submitter has reviewed both and takes responsibility for
> them.
> 
> Fixes: beac82904a87 ("media: venus: make decoder compliant with stateful codec API")
> Signed-off-by: EMCP333 <emcp@enser.io>
This also looks similar to : 
https://patchwork.linuxtv.org/project/linux-media/patch/20260928-venus-vdec-eos-v1-2-6e9eb3ce9849@ixit.cz/

Please pick up on David's patches, give Tested-by: as appropriate and 
propose any additional fixes on top.

---
bod

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

end of thread, other threads:[~2026-11-22 23:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-22  5:13 [PATCH 0/2] media: venus: Fix end-of-stream and seeks on SDM845 EMCP333 via B4 Relay
2026-11-22  5:13 ` [PATCH 1/2] media: venus: Signal end-of-stream with a mapped buffer EMCP333 via B4 Relay
2026-11-22 22:56   ` Bryan O'Donoghue
2026-11-22  5:13 ` [PATCH 2/2] media: venus: vdec: Resume CAPTURE restarted during a seek EMCP333 via B4 Relay
2026-11-22 23:09   ` Bryan O'Donoghue

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

all inboxes | Powered by JetHome®