Skip to contentSkip to conversation

media: iris: fix the decoder source change, seek and START sequences

PATCH New Neil Armstrong 1 participant 12 messages Nov 25

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover media: iris: fix the decoder source change, seek and START sequences

The iris stateful decoder fails the v4l2-compliance streaming tests on streams with resolution changes, and FFmpeg stops after the first frame of some streams. This series fixes the decoder sequences of the specification a player uses: source change completed with STREAMOFF/STREAMON(CAPTURE) or V4L2_DEC_CMD_START, seek with STREAMOFF/STREAMON(OUTPUT), drain, and CAPTURE started before the first source change.

FFMpeg is largely not compliant with the V4L2 M2M spec for DRC and seek handling, freezing and stopping for such streams. While the kernel can't and won't fix an userspace program, we made sure the basic FFMpeg kept working when fixing DRC and Seeking. Proper fixes for multiple DRCs should be done in the FFMpeg code instead of the kernel.

Depends on:
- https://lore.kernel.org/all/[email protected]/
- https://lore.kernel.org/all/20261031-fix_v4l2_compliance_unlimited_opens-v1-1-f20cc9231ee3@oss.qualcomm.com/
- https://lore.kernel.org/all/[email protected]/

Log of v4l2-compliance run with an H.264 stream with the following DRC changes:
- 176x144
- 1600x900
- 1264x800
- 1592x1080
- 1024x768
- 532x312

v4l2-compliance 1.33.0-5524, 64 bits, 64-bit time_t v4l2-compliance SHA: d2e89246cefc 2026-10-30 13:45:36

Compliance test for iris_driver device /dev/video0:

Driver Info:

	Driver name      : iris_driver
	Card type        : Iris Decoder
	Bus info         : platform:aa00000.video-codec:de
	Driver version   : 7.4.0
	Capabilities     : 0x84204000

Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Device Capabilities
Device Caps : 0x04204000
Video Memory-to-Memory Multiplanar Streaming
Extended Pix Format
Detected Stateful Decoder

Required ioctls:
test VIDIOC_QUERYCAP: OK
test invalid ioctls: OK

Allow for multiple opens:
test second /dev/video0 open: OK
test VIDIOC_QUERYCAP: OK
test VIDIOC_G/S_PRIORITY: OK
test for unlimited opens: OK

Debug ioctls:
test VIDIOC_DBG_G/S_REGISTER: OK (Not Supported) test VIDIOC_LOG_STATUS: OK (Not Supported)

Input ioctls:
test VIDIOC_G/S_TUNER/ENUM_FREQ_BANDS: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_S_HW_FREQ_SEEK: OK (Not Supported) test VIDIOC_ENUMAUDIO: OK (Not Supported)
test VIDIOC_G/S/ENUMINPUT: OK (Not Supported) test VIDIOC_G/S_AUDIO: OK (Not Supported)
Inputs: 0 Audio Inputs: 0 Tuners: 0

Output ioctls:
test VIDIOC_G/S_MODULATOR: OK (Not Supported) test VIDIOC_G/S_FREQUENCY: OK (Not Supported) test VIDIOC_ENUMAUDOUT: OK (Not Supported) test VIDIOC_G/S/ENUMOUTPUT: OK (Not Supported) test VIDIOC_G/S_AUDOUT: OK (Not Supported)
Outputs: 0 Audio Outputs: 0 Modulators: 0

Input/Output configuration ioctls:
test VIDIOC_ENUM/G/S/QUERY_STD: OK (Not Supported) test VIDIOC_ENUM/G/S/QUERY_DV_TIMINGS: OK (Not Supported) test VIDIOC_DV_TIMINGS_CAP: OK (Not Supported) test VIDIOC_G/S_EDID: OK (Not Supported)

Control ioctls:
test VIDIOC_QUERY_EXT_CTRL/QUERYMENU: OK test VIDIOC_QUERYCTRL: OK
test VIDIOC_G/S_CTRL: OK
test VIDIOC_G/S/TRY_EXT_CTRLS: OK test VIDIOC_(UN)SUBSCRIBE_EVENT/DQEVENT: OK test VIDIOC_G/S_JPEGCOMP: OK (Not Supported) Standard Controls: 12 Private Controls: 0

Format ioctls:
test VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS: OK test VIDIOC_G/S_PARM: OK (Not Supported) test VIDIOC_G_FBUF: OK (Not Supported) test VIDIOC_G_FMT: OK
test VIDIOC_TRY_FMT: OK
test VIDIOC_S_FMT: OK
test VIDIOC_G_SLICED_VBI_CAP: OK (Not Supported) test Cropping: OK
test Composing: OK
test Scaling: OK (Not Supported)

Codec ioctls:
test VIDIOC_(TRY_)ENCODER_CMD: OK (Not Supported) test VIDIOC_G_ENC_INDEX: OK (Not Supported) test VIDIOC_(TRY_)DECODER_CMD: OK

Buffer ioctls:
test VIDIOC_REQBUFS/CREATE_BUFS/QUERYBUF: OK test CREATE_BUFS maximum buffers: OK test VIDIOC_REMOVE_BUFS: OK
test VIDIOC_EXPBUF: OK
test Requests: OK (Not Supported) test blocking wait: OK

Test input 0:

Streaming ioctls:
test read/write: OK (Not Supported)
Video Capture Multiplanar: Captured 556 buffers
test MMAP (select, REQBUFS): OK
Video Capture Multiplanar: Captured 556 buffers
test MMAP (epoll, REQBUFS): OK
Video Capture Multiplanar: Captured 556 buffers
test MMAP (select, CREATE_BUFS): OK
Video Capture Multiplanar: Captured 556 buffers
test MMAP (epoll, CREATE_BUFS): OK
test USERPTR (select): OK (Not Supported)
warn: v4l2-test-buffers.cpp(2223): Cannot test DMABUF, specify --expbuf-device
test DMABUF (select): OK (Not Supported)

Total for iris_driver device /dev/video0: 55, Succeeded: 55, Failed: 0, Warnings: 1

Similar check was done with HEVC, VP9 and AV1 with modified compliance tool to allow setting the default decoder format.

Assisted by an LLM for generating test suite, test streams and issues pointing in the mainline iris driver against the dowstream driver and behaviour of the firmware on a SM8650 HDK device.

---
Neil Armstrong (11):
media: iris: vdec: accept V4L2_DEC_CMD_START on a running decoder
media: iris: restart the buffer sequence numbers at each STREAMON
media: iris: vdec: update the minimum CAPTURE buffer count on S_FMT
media: iris: vdec: reconfigure the decoder on START after a source change
media: iris: clear the stopped state when the decoder resumes
media: iris: don't return a spurious LAST buffer
media: iris: vdec: keep the visible rectangle on S_FMT(CAPTURE)
media: iris: gen2: don't align the decoder input resolution
media: iris: vdec: resume an unchanged VP9 settings change after a seek
media: iris: vdec: complete an unchanged first settings change for FFmpeg
media: iris: record the LAST buffer returned with an error

 drivers/media/platform/qcom/iris/iris_buffer.c     |  41 ++++++
 drivers/media/platform/qcom/iris/iris_buffer.h     |   1 +
 drivers/media/platform/qcom/iris/iris_common.c     |   5 +-
 .../platform/qcom/iris/iris_hfi_gen1_response.c    |   9 +-
 .../platform/qcom/iris/iris_hfi_gen2_command.c     |   3 +-
 .../platform/qcom/iris/iris_hfi_gen2_response.c    |  53 +++++--
 drivers/media/platform/qcom/iris/iris_instance.h   |  10 ++
 drivers/media/platform/qcom/iris/iris_vb2.c        |  24 ++-
 drivers/media/platform/qcom/iris/iris_vdec.c       | 161 ++++++++++++++++++++-
 drivers/media/platform/qcom/iris/iris_vdec.h       |   9 ++
 drivers/media/platform/qcom/iris/iris_vidc.c       |   5 +
 11 files changed, 294 insertions(+), 27 deletions(-)

---
base-commit: a78785697f5d3851eecc3f6bdcc05f357fd89695
change-id: 20261125-topic-iris-decoder-drc-fixes-e16b5460f474

Best regards,

Signature · 1 line
Neil Armstrong <[email protected]>
#1 lore raw

PATCH 1/11 media: iris: vdec: accept V4L2_DEC_CMD_START on a running decoder

V4L2_DEC_CMD_START on a running decoder is not an error: the specification only makes it fail with -EBUSY while a drain is in progress, and v4l2_m2m_decoder_cmd() returns 0 for it.

iris_allow_cmd() only accepts START while a source change or a drain is pending. v4l2-compliance completes a source change with STREAMOFF/STREAMON(CAPTURE), which restarts the decoder, then sends START and fails on the -EBUSY.

Return 0 for START when no source change or drain is pending.

Fixes d09100763bed ("media: iris: add support for drain sequence")
---
 drivers/media/platform/qcom/iris/iris_vidc.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/media/platform/qcom/iris/iris_vidc.c +5 -0
index 931221564a33..7b5a607f94ba 100644
@@ -601,6 +601,11 @@ static int iris_dec_cmd(struct file *filp, void *fh,
 	if (inst->state == IRIS_INST_DEINIT)
 		goto unlock;
 
+	/* No source change or drain to resume */
+	if (dec->cmd == V4L2_DEC_CMD_START && inst->state != IRIS_INST_ERROR &&
+	    !(inst->sub_state & (IRIS_INST_SUB_DRC | IRIS_INST_SUB_DRAIN)))
+		goto unlock;
+
 	if (!iris_allow_cmd(inst, dec->cmd)) {
 		ret = -EBUSY;
 		goto unlock;
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/11 media: iris: restart the buffer sequence numbers at each STREAMON

In reply to Neil Armstrong

The buffer sequence count starts at zero when a queue starts streaming. The OUTPUT and CAPTURE counters are only zeroed when the instance is allocated, so after a STREAMOFF/STREAMON on either queue, e.g. to complete a source change or for a seek, v4l2-compliance warns:

warn: v4l2-test-buffers.cpp(470): got sequence number 12, expected 0

Reset the counter of a queue when it starts streaming.

Fixes 17f2a485ca67 ("media: iris: implement vb2 ops for buf_queue and firmware response")
---
 drivers/media/platform/qcom/iris/iris_vb2.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/media/platform/qcom/iris/iris_vb2.c +2 -0
index 2460778c408d..426810c848a4 100644
@@ -181,11 +181,13 @@ int iris_vb2_start_streaming(struct vb2_queue *q, unsigned int count)
 		goto error;
 
 	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+		inst->sequence_out = 0;
 		if (inst->domain == DECODER)
 			ret = iris_vdec_streamon_input(inst);
 		else
 			ret = iris_venc_streamon_input(inst);
 	} else if (V4L2_TYPE_IS_CAPTURE(q->type)) {
+		inst->sequence_cap = 0;
 		if (inst->domain == DECODER)
 			ret = iris_vdec_streamon_output(inst);
 		else
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/11 media: iris: vdec: update the minimum CAPTURE buffer count on S_FMT

In reply to Neil Armstrong

V4L2_CID_MIN_BUFFERS_FOR_CAPTURE and the CAPTURE queue min_reqbufs_allocation are only updated on a source change. Until then they keep the default of 4 while S_FMT already computed a minimum of 9 for VP9 and 11 for AV1, so a client that allocates CAPTURE buffers before the first source change gets fewer than the decoder needs.

After a new S_FMT(OUTPUT), the firmware count of the previous stream also still sizes the CAPTURE minimum, the internal buffers and the minimum output count sent to the firmware for the new stream.

Update both whenever the minimum is computed, and reset the firmware count on S_FMT(OUTPUT).

---
 .../media/platform/qcom/iris/iris_hfi_gen1_response.c    |  9 +--------
 .../media/platform/qcom/iris/iris_hfi_gen2_response.c    |  9 +--------
 drivers/media/platform/qcom/iris/iris_vdec.c             | 16 ++++++++++++++++
 drivers/media/platform/qcom/iris/iris_vdec.h             |  1 +
 4 files changed, 19 insertions(+), 16 deletions(-)
drivers/media/platform/qcom/iris/iris_hfi_gen1_response.c +1 -8
index ffa98139f0eb..70b97902ca2d 100644
@@ -32,8 +32,6 @@ static void iris_hfi_gen1_read_changed_params(struct iris_inst *inst,
 	struct hfi_bit_depth *pixel_depth;
 	struct hfi_pic_struct *pic_struct;
 	struct hfi_framesize *frame_sz;
-	struct vb2_queue *dst_q;
-	struct v4l2_ctrl *ctrl;
 	u32 full_range, ptype;
 
 	do {
@@ -158,12 +156,7 @@ static void iris_hfi_gen1_read_changed_params(struct iris_inst *inst,
 	inst->fw_min_count = event.buf_count;
 	inst->buffers[BUF_OUTPUT].min_count = iris_vpu_buf_count(inst, BUF_OUTPUT);
 	inst->buffers[BUF_OUTPUT].size = pixmp_op->plane_fmt[0].sizeimage;
-	ctrl = v4l2_ctrl_find(&inst->ctrl_handler, V4L2_CID_MIN_BUFFERS_FOR_CAPTURE);
-	if (ctrl)
-		v4l2_ctrl_s_ctrl(ctrl, inst->buffers[BUF_OUTPUT].min_count);
-
-	dst_q = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
-	dst_q->min_reqbufs_allocation = inst->buffers[BUF_OUTPUT].min_count;
+	iris_vdec_update_min_capture_bufs(inst);
 
 	if (event.bit_depth || !event.pic_struct) {
 		dev_err(core->dev, "unsupported content, bit depth: %x, pic_struct = %x\n",
drivers/media/platform/qcom/iris/iris_hfi_gen2_response.c +1 -8
index b4fe9066fcb8..baaab9608da0 100644
@@ -537,8 +537,6 @@ static void iris_hfi_gen2_read_input_subcr_params(struct iris_inst *inst)
 	u32 video_signal_type_present_flag;
 	struct iris_core *core = inst->core;
 	u32 full_range, width, height;
-	struct vb2_queue *dst_q;
-	struct v4l2_ctrl *ctrl;
 
 	subsc_params = inst_hfi_gen2->src_subcr_params;
 	width = (subsc_params.bitstream_resolution &
@@ -661,12 +659,7 @@ static void iris_hfi_gen2_read_input_subcr_params(struct iris_inst *inst)
 	inst->fw_min_count = subsc_params.fw_min_count;
 	inst->buffers[BUF_OUTPUT].min_count = iris_vpu_buf_count(inst, BUF_OUTPUT);
 	inst->buffers[BUF_OUTPUT].size = pixmp_op->plane_fmt[0].sizeimage;
-	ctrl = v4l2_ctrl_find(&inst->ctrl_handler, V4L2_CID_MIN_BUFFERS_FOR_CAPTURE);
-	if (ctrl)
-		v4l2_ctrl_s_ctrl(ctrl, inst->buffers[BUF_OUTPUT].min_count);
-
-	dst_q = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
-	dst_q->min_reqbufs_allocation = inst->buffers[BUF_OUTPUT].min_count;
+	iris_vdec_update_min_capture_bufs(inst);
 }
 
 static int iris_hfi_gen2_handle_src_change(struct iris_inst *inst,
drivers/media/platform/qcom/iris/iris_vdec.c +16 -0
index 472e8e50830d..656e69d2c942 100644
@@ -63,6 +63,18 @@ int iris_vdec_inst_init(struct iris_inst *inst)
 	return iris_ctrls_init(inst);
 }
 
+void iris_vdec_update_min_capture_bufs(struct iris_inst *inst)
+{
+	u32 count = inst->buffers[BUF_OUTPUT].min_count;
+	struct v4l2_ctrl *ctrl;
+
+	ctrl = v4l2_ctrl_find(&inst->ctrl_handler, V4L2_CID_MIN_BUFFERS_FOR_CAPTURE);
+	if (ctrl)
+		v4l2_ctrl_s_ctrl(ctrl, count);
+
+	v4l2_m2m_get_dst_vq(inst->m2m_ctx)->min_reqbufs_allocation = count;
+}
+
 static const u32 iris_vdec_formats_cap[] = {
 	V4L2_PIX_FMT_NV12,
 	V4L2_PIX_FMT_QC08C,
@@ -271,6 +283,8 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
 		fmt->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE;
 		fmt->fmt.pix_mp.pixelformat = f->fmt.pix_mp.pixelformat;
 		inst->codec = fmt->fmt.pix_mp.pixelformat;
+		/* the firmware count is the one of the previous stream */
+		inst->fw_min_count = 0;
 		codec_align = inst->codec == V4L2_PIX_FMT_HEVC ? 32 : 16;
 		fmt->fmt.pix_mp.width = ALIGN(f->fmt.pix_mp.width, codec_align);
 		fmt->fmt.pix_mp.height = ALIGN(f->fmt.pix_mp.height, codec_align);
@@ -294,6 +308,7 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
 		/* Update capture format based on new ip w/h */
 		iris_vdec_set_capture_size(inst, f->fmt.pix_mp.width,
 					   f->fmt.pix_mp.height);
+		iris_vdec_update_min_capture_bufs(inst);
 
 		inst->crop.left = 0;
 		inst->crop.top = 0;
@@ -310,6 +325,7 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
 		fmt->fmt.pix_mp.num_planes = 1;
 		iris_vdec_set_capture_size(inst, f->fmt.pix_mp.width,
 					   f->fmt.pix_mp.height);
+		iris_vdec_update_min_capture_bufs(inst);
 
 		inst->crop.top = 0;
 		inst->crop.left = 0;
drivers/media/platform/qcom/iris/iris_vdec.h +1 -0
index 5123d2a340e1..4b903da58056 100644
@@ -15,6 +15,7 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f);
 int iris_vdec_validate_format(struct iris_inst *inst, u32 pixelformat);
 int iris_vdec_subscribe_event(struct iris_inst *inst, const struct v4l2_event_subscription *sub);
 void iris_vdec_src_change(struct iris_inst *inst);
+void iris_vdec_update_min_capture_bufs(struct iris_inst *inst);
 int iris_vdec_streamon_input(struct iris_inst *inst);
 int iris_vdec_streamon_output(struct iris_inst *inst);
 int iris_vdec_qbuf(struct iris_inst *inst, struct vb2_v4l2_buffer *vbuf);
Signature · 1 line
2.34.1
#4 lore raw

PATCH 4/11 media: iris: vdec: reconfigure the decoder on START after a source change

In reply to Neil Armstrong

The specification lets the client complete a source change with V4L2_DEC_CMD_START when the allocated CAPTURE buffers fit the new format. iris_vdec_start_cmd() then only resumes the firmware ports, without the configuration STREAMON(CAPTURE) sends for the new stream, and the decoder:

- writes the following frames with the stride and scanline of the previous resolution;
- fails to resume with HFI_ERROR_INSUFFICIENT_RESOURCES when the input internal buffers are too small for the new resolution, and the instance goes to the error state.

Before resuming, send the CAPTURE port configuration, reallocate the input internal buffers, set stage and pipe, and add DPB buffers of the new size up to the minimum count of the new stream. The attached DPB buffers are
kept: the firmware fails to release them while the CAPTURE port is paused.

Fixes 84e17adae3e3 ("media: iris: add support for dynamic resolution change")
---
 drivers/media/platform/qcom/iris/iris_buffer.c | 37 ++++++++++++++++++++++++++
 drivers/media/platform/qcom/iris/iris_buffer.h |  1 +
 drivers/media/platform/qcom/iris/iris_vdec.c   | 29 ++++++++++++++++++++
 3 files changed, 67 insertions(+)
drivers/media/platform/qcom/iris/iris_buffer.c +37 -0
index 178e50eadcf7..38bdf366b384 100644
@@ -747,6 +747,43 @@ static int iris_release_input_internal_buffers(struct iris_inst *inst)
 	return 0;
 }
 
+/*
+ * Buffers the firmware holds are kept: it fails to release them while the
+ * CAPTURE port is paused. Only buffers of the new size count for the minimum.
+ */
+int iris_alloc_and_queue_additional_output_int_bufs(struct iris_inst *inst)
+{
+	u32 internal_buffer_count, i, count, fit;
+	const u32 *internal_buf_type;
+	struct iris_buffers *buffers;
+	struct iris_buffer *buf;
+	int ret;
+
+	iris_get_int_buf_tbl(inst, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
+			     &internal_buf_type, &internal_buffer_count);
+
+	for (i = 0; i < internal_buffer_count; i++) {
+		buffers = &inst->buffers[internal_buf_type[i]];
+		iris_fill_internal_buf_info(inst, internal_buf_type[i]);
+
+		count = 0;
+		fit = 0;
+		list_for_each_entry(buf, &buffers->list, list) {
+			count++;
+			if (buf->buffer_size >= buffers->size)
+				fit++;
+		}
+
+		for (; fit < buffers->min_count; fit++, count++) {
+			ret = iris_create_internal_buffer(inst, internal_buf_type[i], count);
+			if (ret)
+				return ret;
+		}
+	}
+
+	return iris_queue_internal_buffers(inst, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+}
+
 int iris_alloc_and_queue_persist_bufs(struct iris_inst *inst, enum iris_buffer_type buffer_type)
 {
 	struct iris_buffers *buffers = &inst->buffers[buffer_type];
drivers/media/platform/qcom/iris/iris_buffer.h +1 -0
index a8d2002e00ee..7cf69046f036 100644
@@ -117,6 +117,7 @@ int iris_destroy_all_internal_buffers(struct iris_inst *inst, u32 plane);
 int iris_destroy_dequeued_internal_buffers(struct iris_inst *inst, u32 plane);
 int iris_alloc_and_queue_persist_bufs(struct iris_inst *inst, enum iris_buffer_type buf_type);
 int iris_alloc_and_queue_input_int_bufs(struct iris_inst *inst);
+int iris_alloc_and_queue_additional_output_int_bufs(struct iris_inst *inst);
 int iris_queue_buffer(struct iris_inst *inst, struct iris_buffer *buf);
 int iris_queue_deferred_buffers(struct iris_inst *inst, enum iris_buffer_type buf_type);
 int iris_vb2_buffer_done(struct iris_inst *inst, struct iris_buffer *buf);
drivers/media/platform/qcom/iris/iris_vdec.c +29 -0
index 656e69d2c942..d35a1eb62d30 100644
@@ -495,6 +495,31 @@ int iris_vdec_qbuf(struct iris_inst *inst, struct vb2_v4l2_buffer *vbuf)
 	return iris_queue_buffer(inst, buf);
 }
 
+/* Configure the firmware for the new stream, as on STREAMON(CAPTURE) */
+static int iris_vdec_drc_reconfigure(struct iris_inst *inst)
+{
+	const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
+	int ret;
+
+	ret = hfi_ops->session_set_config_params(inst, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+	if (ret)
+		return ret;
+
+	ret = iris_alloc_and_queue_input_int_bufs(inst);
+	if (ret)
+		return ret;
+
+	ret = iris_set_stage(inst, STAGE);
+	if (ret)
+		return ret;
+
+	ret = iris_set_pipe(inst, PIPE);
+	if (ret)
+		return ret;
+
+	return iris_alloc_and_queue_additional_output_int_bufs(inst);
+}
+
 int iris_vdec_start_cmd(struct iris_inst *inst)
 {
 	const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
@@ -506,6 +531,10 @@ int iris_vdec_start_cmd(struct iris_inst *inst)
 
 	if (inst->sub_state & IRIS_INST_SUB_DRC &&
 	    inst->sub_state & IRIS_INST_SUB_DRC_LAST) {
+		ret = iris_vdec_drc_reconfigure(inst);
+		if (ret)
+			return ret;
+
 		vb2_clear_last_buffer_dequeued(dst_vq);
 		clear_sub_state = IRIS_INST_SUB_DRC | IRIS_INST_SUB_DRC_LAST;
 
Signature · 1 line
2.34.1
#5 lore raw

PATCH 5/11 media: iris: clear the stopped state when the decoder resumes

In reply to Neil Armstrong

V4L2_DEC_CMD_START resumes the decoder after a drain or a source change but leaves inst->last_buffer_dequeued and the m2m stopped state set, and STREAMON(CAPTURE) leaves the m2m stopped state set:

- the LAST buffer of the next drain or source change is not flagged on gen1, and iris_vb2_buf_queue() does not return one either;
- iris_vb2_signal_eos() does not signal V4L2_EVENT_EOS at the end of the next drain.

Clear both on START, and the m2m stopped state on STREAMON(CAPTURE), which already clears inst->last_buffer_dequeued.

Fixes d09100763bed ("media: iris: add support for drain sequence")
---
 drivers/media/platform/qcom/iris/iris_common.c | 1 +
 drivers/media/platform/qcom/iris/iris_vdec.c   | 9 ++++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/iris/iris_common.c +1 -0
index 25836561bcf3..61634df56797 100644
@@ -151,6 +151,7 @@ int iris_process_streamon_output(struct iris_inst *inst)
 		return ret;
 
 	inst->last_buffer_dequeued = false;
+	v4l2_m2m_clear_state(inst->m2m_ctx);
 
 	return iris_inst_change_sub_state(inst, clear_sub_state, 0);
 }
drivers/media/platform/qcom/iris/iris_vdec.c +8 -1
index d35a1eb62d30..6369370a04a2 100644
@@ -584,7 +584,14 @@ int iris_vdec_start_cmd(struct iris_inst *inst)
 		return -EBUSY;
 	}
 
-	return iris_inst_change_sub_state(inst, clear_sub_state, 0);
+	ret = iris_inst_change_sub_state(inst, clear_sub_state, 0);
+	if (ret)
+		return ret;
+
+	inst->last_buffer_dequeued = false;
+	v4l2_m2m_clear_state(inst->m2m_ctx);
+
+	return 0;
 }
 
 int iris_vdec_stop_cmd(struct iris_inst *inst)
Signature · 1 line
2.34.1
#6 lore raw

PATCH 6/11 media: iris: don't return a spurious LAST buffer

In reply to Neil Armstrong

While a source change or a drain is pending and inst->last_buffer_dequeued is not set, iris_vb2_buf_queue() returns a queued CAPTURE buffer as an empty LAST buffer. The client then gets a LAST buffer the specification does not expect in two cases:

- iris_process_streamon_input() clears last_buffer_dequeued on every STREAMON(OUTPUT). After a seek done while a source change is pending and its LAST buffer was dequeued, the next queued CAPTURE buffer is returned as a second LAST buffer;

- vb2 calls buf_queue() for the buffers queued before STREAMON(CAPTURE) before start_streaming(), which completes the pending source change or drain. One of them is returned as LAST although that STREAMON resumes the decoder.

Keep last_buffer_dequeued on STREAMON(OUTPUT) while a source change is pending, and only return a LAST buffer from iris_vb2_buf_queue() once start_streaming() has been called.

Fixes f15cb8652b4f ("media: iris: Improve last flag handling")
Fixes 92e007ca5ab6 ("media: iris: Add V4L2 streaming support for encoder video device")
---
 drivers/media/platform/qcom/iris/iris_common.c | 4 +++-
 drivers/media/platform/qcom/iris/iris_vb2.c    | 7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/iris/iris_common.c +3 -1
index 61634df56797..c3712a29ca85 100644
@@ -83,7 +83,9 @@ int iris_process_streamon_input(struct iris_inst *inst)
 	if (ret)
 		return ret;
 
-	inst->last_buffer_dequeued = false;
+	/* A seek does not complete a pending source change */
+	if (!(inst->domain == DECODER && inst->sub_state & IRIS_INST_SUB_DRC))
+		inst->last_buffer_dequeued = false;
 
 	return iris_inst_change_sub_state(inst, 0, set_sub_state);
 }
drivers/media/platform/qcom/iris/iris_vb2.c +6 -1
index 426810c848a4..b56c855567a6 100644
@@ -335,7 +335,12 @@ void iris_vb2_buf_queue(struct vb2_buffer *vb2)
 		goto exit;
 	}
 
-	if (!inst->last_buffer_dequeued && V4L2_TYPE_IS_CAPTURE(vb2->vb2_queue->type)) {
+	/*
+	 * Buffers queued before STREAMON(CAPTURE) come here before
+	 * start_streaming(), which completes the source change or drain.
+	 */
+	if (!inst->last_buffer_dequeued && V4L2_TYPE_IS_CAPTURE(vb2->vb2_queue->type) &&
+	    vb2_start_streaming_called(vb2->vb2_queue)) {
 		if ((inst->sub_state & IRIS_INST_SUB_DRC &&
 		     inst->sub_state & IRIS_INST_SUB_DRC_LAST) ||
 		    (inst->sub_state & IRIS_INST_SUB_DRAIN &&
Signature · 1 line
2.34.1
#7 lore raw

PATCH 7/11 media: iris: vdec: keep the visible rectangle on S_FMT(CAPTURE)

In reply to Neil Armstrong

S_FMT(CAPTURE) sets inst->crop to the requested CAPTURE size, which try_fmt sets to the coded resolution. inst->crop is the visible rectangle of the stream: VIDIOC_G_SELECTION returns it for the CROP and COMPOSE targets, and gen2 sends it as input crop offsets on STREAMON(OUTPUT).

A client following the specification calls S_FMT(CAPTURE) with the format from G_FMT after a source change. The selection targets then return the coded resolution instead of the visible rectangle, e.g. 1920x1088 for a 1920x1080 H.264 stream, and the next STREAMON(OUTPUT), e.g. for a seek, programs crop offsets that do not match the stream.

Only bound the visible rectangle by the new CAPTURE size.

Fixes b530b95de22c ("media: iris: implement s_fmt, g_fmt and try_fmt ioctls")
---
 drivers/media/platform/qcom/iris/iris_vdec.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/media/platform/qcom/iris/iris_vdec.c +7 -4
index 6369370a04a2..f7f3171ed6ad 100644
@@ -327,10 +327,13 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f)
 					   f->fmt.pix_mp.height);
 		iris_vdec_update_min_capture_bufs(inst);
 
-		inst->crop.top = 0;
-		inst->crop.left = 0;
-		inst->crop.width = f->fmt.pix_mp.width;
-		inst->crop.height = f->fmt.pix_mp.height;
+		/* inst->crop is the visible rectangle of the stream */
+		inst->crop.left = min(inst->crop.left, fmt->fmt.pix_mp.width);
+		inst->crop.top = min(inst->crop.top, fmt->fmt.pix_mp.height);
+		inst->crop.width = min(inst->crop.width,
+				       fmt->fmt.pix_mp.width - inst->crop.left);
+		inst->crop.height = min(inst->crop.height,
+					fmt->fmt.pix_mp.height - inst->crop.top);
 		break;
 	default:
 		return -EINVAL;
Signature · 1 line
2.34.1
#8 lore raw

PATCH 8/11 media: iris: gen2: don't align the decoder input resolution

In reply to Neil Armstrong

Since commit 49a940f37de3 ("media: qcom: iris: Add rotation support for encoder"), the decoder input resolution sent to the firmware is aligned to 16, or 32 for HEVC.

For VP9 and AV1 the firmware reports the visible size as bitstream resolution, and ignores the input crop offsets. After a source change to a size that is not aligned, the STREAMON(OUTPUT) of a seek programs a resolution that differs from the stream. The firmware then raises a settings change for the next frame on the input port only, without the PSC_LAST buffer that ends a source change, and decoding stalls.

Send the decoder input resolution as reported, as before that commit.

Fixes 49a940f37de3 ("media: qcom: iris: Add rotation support for encoder")
---
 drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/iris/iris_hfi_gen2_command.c +2 -1
index 9464543836c0..608fc405ea05 100644
@@ -197,9 +197,10 @@ static int iris_hfi_gen2_set_bitstream_resolution(struct iris_inst *inst, u32 pl
 	u32 resolution;
 
 	if (inst->domain == DECODER) {
+		/* Send the resolution as reported by the firmware */
 		width = inst->fmt_src->fmt.pix_mp.width;
 		height = inst->fmt_src->fmt.pix_mp.height;
-		resolution = iris_hfi_get_aligned_resolution(inst, width, height);
+		resolution = width << 16 | height;
 		inst_hfi_gen2->src_subcr_params.bitstream_resolution = resolution;
 		payload_type = HFI_PAYLOAD_U32;
 	} else {
Signature · 1 line
2.34.1
#9 lore raw

PATCH 9/11 media: iris: vdec: resume an unchanged VP9 settings change after a seek

In reply to Neil Armstrong

After a seek, the VP9 firmware raises an input port settings change for the next keyframe even when the stream format did not change, then only waits for the input port to be resumed: no PSC_LAST buffer follows. The driver signals it as a source change, and a client following the specification waits forever for the LAST buffer.

When such a settings change leaves the CAPTURE format, the colorimetry, the visible rectangle and the minimum CAPTURE buffer count unchanged, the client has nothing to reconfigure: resume the input port without signalling it. Other codecs pause the output port for any settings change and need the full source change sequence.

The check is armed by STREAMON(OUTPUT) while CAPTURE streams, and ends when a settings change is resumed without being signalled or OUTPUT is stopped. Frames decoded before the seek can be returned after it, so a decoded frame does not end it.

The settings change for the bitstream queued before a seek can arrive while STREAMOFF(OUTPUT) waits, without the instance lock, for the firmware to stop the input port. Keep the check armed until the stop completes and do not resume the input port then: the next STREAMON(OUTPUT) restarts it.

Should the firmware still pause the output port, resume it and do not return the PSC_LAST buffer as LAST.

---
 .../platform/qcom/iris/iris_hfi_gen2_response.c    | 28 ++++++++++-
 drivers/media/platform/qcom/iris/iris_instance.h   |  6 +++
 drivers/media/platform/qcom/iris/iris_vb2.c        | 10 ++++
 drivers/media/platform/qcom/iris/iris_vdec.c       | 57 ++++++++++++++++++++++
 drivers/media/platform/qcom/iris/iris_vdec.h       |  5 ++
 5 files changed, 104 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/iris/iris_hfi_gen2_response.c +26 -2
index baaab9608da0..4f685efbeae9 100644
@@ -350,8 +350,8 @@ static int iris_hfi_gen2_handle_output_buffer(struct iris_inst *inst,
 {
 	struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx;
 	struct v4l2_m2m_buffer *m2m_buffer, *n;
+	bool found = false, unsignalled_psc_last = false;
 	struct iris_buffer *buf;
-	bool found = false;
 	int ret;
 
 	if (hfi_buffer->flags & HFI_BUF_FW_FLAG_LAST) {
@@ -360,7 +360,15 @@ static int iris_hfi_gen2_handle_output_buffer(struct iris_inst *inst,
 			return ret;
 	}
 
-	if (hfi_buffer->flags & HFI_BUF_FW_FLAG_PSC_LAST) {
+	/* The firmware may still pause the output port after an input resume */
+	if ((hfi_buffer->flags & HFI_BUF_FW_FLAG_PSC_LAST) && inst->drc_resumed_in_place &&
+	    !(inst->sub_state & IRIS_INST_SUB_DRC)) {
+		ret = inst->hfi_session_ops->session_resume_drc(inst,
+							       V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
+		if (ret)
+			return ret;
+		unsignalled_psc_last = true;
+	} else if (hfi_buffer->flags & HFI_BUF_FW_FLAG_PSC_LAST) {
 		ret = iris_inst_sub_state_change_drc_last(inst);
 		if (ret)
 			return ret;
@@ -381,6 +389,14 @@ static int iris_hfi_gen2_handle_output_buffer(struct iris_inst *inst,
 	if (!(buf->attr & BUF_ATTR_QUEUED))
 		return -EINVAL;
 
+	if (unsignalled_psc_last) {
+		inst->drc_resumed_in_place = false;
+		if (!hfi_buffer->data_size) {
+			buf->attr &= ~BUF_ATTR_QUEUED;
+			return iris_queue_buffer(inst, buf);
+		}
+	}
+
 	buf->data_offset = hfi_buffer->data_offset;
 	buf->data_size = hfi_buffer->data_size;
 	buf->timestamp = hfi_buffer->timestamp;
@@ -389,6 +405,8 @@ static int iris_hfi_gen2_handle_output_buffer(struct iris_inst *inst,
 	buf->attr |= BUF_ATTR_DEQUEUED;
 
 	buf->flags = iris_hfi_gen2_get_driver_buffer_flags(inst, hfi_buffer->flags);
+	if (unsignalled_psc_last)
+		buf->flags &= ~V4L2_BUF_FLAG_LAST;
 
 	/*
 	 * The empty buffer that ends a drain (LAST) or a source change
@@ -665,6 +683,9 @@ static void iris_hfi_gen2_read_input_subcr_params(struct iris_inst *inst)
 static int iris_hfi_gen2_handle_src_change(struct iris_inst *inst,
 					   struct iris_hfi_packet *pkt)
 {
+	struct v4l2_pix_format_mplane old_fmt = inst->fmt_dst->fmt.pix_mp;
+	u32 old_min_count = inst->buffers[BUF_OUTPUT].min_count;
+	struct iris_hfi_rect_desc old_crop = inst->crop;
 	int ret;
 
 	if (pkt->port != HFI_PORT_BITSTREAM)
@@ -675,6 +696,9 @@ static int iris_hfi_gen2_handle_src_change(struct iris_inst *inst,
 		return ret;
 
 	iris_hfi_gen2_read_input_subcr_params(inst);
+	if (iris_vdec_src_change_after_seek(inst, &old_fmt, &old_crop, old_min_count))
+		return iris_vdec_src_change_resume_input(inst);
+
 	iris_vdec_src_change(inst);
 
 	return 0;
drivers/media/platform/qcom/iris/iris_instance.h +6 -0
index d852299d3f05..53693bc53a8e 100644
@@ -57,6 +57,9 @@ struct iris_hfi_session_ops;
  * @metadata_idx: index for metadata buffer
  * @codec: codec type
  * @last_buffer_dequeued: a flag to indicate that last buffer is sent by driver
+ * @vp9_seek_psc: a VP9 seek may raise a settings change that changes nothing
+ * @drc_resumed_in_place: a settings change was not signalled, its PSC_LAST may follow
+ * @input_stopping: STREAMOFF(OUTPUT) waits for the firmware to stop the input
  * @drc_wq: woken when IRIS_INST_SUB_DRC_LAST is set
  * @last_buf_ns: start time of received input buffer for current one second FPS window
  * @frame_counter: input buffer counter for current one second FPS window
@@ -106,6 +109,9 @@ struct iris_inst {
 	u32				metadata_idx;
 	u32				codec;
 	bool				last_buffer_dequeued;
+	bool				vp9_seek_psc;
+	bool				drc_resumed_in_place;
+	bool				input_stopping;
 	wait_queue_head_t		drc_wq;
 	u64				last_buf_ns;
 	u32				frame_counter;
drivers/media/platform/qcom/iris/iris_vb2.c +10 -0
index b56c855567a6..c19de89945e3 100644
@@ -262,11 +262,21 @@ void iris_vb2_stop_streaming(struct vb2_queue *q)
 
 	mutex_lock(&inst->lock);
 
+	inst->drc_resumed_in_place = false;
+
 	if (!V4L2_TYPE_IS_OUTPUT(q->type) &&
 	    !V4L2_TYPE_IS_CAPTURE(q->type))
 		goto exit;
 
+	/*
+	 * The lock is released while the firmware stops the port: a settings
+	 * change for the flushed bitstream can still be handled meanwhile.
+	 */
+	inst->input_stopping = V4L2_TYPE_IS_OUTPUT(q->type);
 	ret = iris_session_streamoff(inst, q->type);
+	inst->input_stopping = false;
+	if (V4L2_TYPE_IS_OUTPUT(q->type))
+		inst->vp9_seek_psc = false;
 	if (ret)
 		goto exit;
 
drivers/media/platform/qcom/iris/iris_vdec.c +57 -0

69 lines not on this page · raw message

drivers/media/platform/qcom/iris/iris_vdec.h +5 -0
index 4b903da58056..5b55354cc25f 100644
@@ -15,6 +15,11 @@ int iris_vdec_s_fmt(struct iris_inst *inst, struct v4l2_format *f);
 int iris_vdec_validate_format(struct iris_inst *inst, u32 pixelformat);
 int iris_vdec_subscribe_event(struct iris_inst *inst, const struct v4l2_event_subscription *sub);
 void iris_vdec_src_change(struct iris_inst *inst);
+bool iris_vdec_src_change_after_seek(struct iris_inst *inst,
+				     const struct v4l2_pix_format_mplane *old_fmt,
+				     const struct iris_hfi_rect_desc *old_crop,
+				     u32 old_min_count);
+int iris_vdec_src_change_resume_input(struct iris_inst *inst);
 void iris_vdec_update_min_capture_bufs(struct iris_inst *inst);
 int iris_vdec_streamon_input(struct iris_inst *inst);
 int iris_vdec_streamon_output(struct iris_inst *inst);
Signature · 1 line
2.34.1
#10 lore raw

PATCH 10/11 media: iris: vdec: complete an unchanged first settings change for FFmpeg

In reply to Neil Armstrong

FFmpeg starts CAPTURE with the size from the container, before the decoder reports the stream format. When the firmware parses the first sequence header after that, its settings change pauses the output port and ends with a PSC_LAST buffer, and the driver signals a source change even if the CAPTURE format did not change.

FFmpeg then sees an unchanged format and sends V4L2_DEC_CMD_START at once, which fails with -EBUSY as the LAST buffer did not come yet, and takes the LAST buffer for the end of the stream: it outputs an empty frame and stops decoding.

When the first settings change after such an early STREAMON(CAPTURE) leaves the CAPTURE format unchanged and the allocated CAPTURE buffers sufficient, do not signal it, and complete it on its PSC_LAST buffer as V4L2_DEC_CMD_START does. The visible rectangle and the colorimetry, which the client could not know yet, are updated without an event. If a queue is stopped before the PSC_LAST buffer, signal the source change.

---
 .../platform/qcom/iris/iris_hfi_gen2_response.c    | 16 ++++++++++
 drivers/media/platform/qcom/iris/iris_instance.h   |  4 +++
 drivers/media/platform/qcom/iris/iris_vb2.c        |  5 +++
 drivers/media/platform/qcom/iris/iris_vdec.c       | 37 ++++++++++++++++++++++
 drivers/media/platform/qcom/iris/iris_vdec.h       |  3 ++
 5 files changed, 65 insertions(+)
drivers/media/platform/qcom/iris/iris_hfi_gen2_response.c +16 -0
index 4f685efbeae9..b1c4e68de2db 100644
@@ -368,11 +368,18 @@ static int iris_hfi_gen2_handle_output_buffer(struct iris_inst *inst,
 		if (ret)
 			return ret;
 		unsignalled_psc_last = true;
+	} else if ((hfi_buffer->flags & HFI_BUF_FW_FLAG_PSC_LAST) && inst->drc_unsignalled) {
+		ret = iris_vdec_src_change_complete(inst);
+		if (ret)
+			return ret;
+		unsignalled_psc_last = true;
 	} else if (hfi_buffer->flags & HFI_BUF_FW_FLAG_PSC_LAST) {
 		ret = iris_inst_sub_state_change_drc_last(inst);
 		if (ret)
 			return ret;
 	}
+	if (hfi_buffer->data_size)
+		inst->early_capture = false;
 
 	v4l2_m2m_for_each_dst_buf_safe(m2m_ctx, m2m_buffer, n) {
 		buf = to_iris_buffer(&m2m_buffer->vb);
@@ -686,11 +693,15 @@ static int iris_hfi_gen2_handle_src_change(struct iris_inst *inst,
 	struct v4l2_pix_format_mplane old_fmt = inst->fmt_dst->fmt.pix_mp;
 	u32 old_min_count = inst->buffers[BUF_OUTPUT].min_count;
 	struct iris_hfi_rect_desc old_crop = inst->crop;
+	bool early_capture;
 	int ret;
 
 	if (pkt->port != HFI_PORT_BITSTREAM)
 		return 0;
 
+	early_capture = inst->early_capture;
+	inst->early_capture = false;
+
 	ret = iris_inst_sub_state_change_drc(inst);
 	if (ret)
 		return ret;
@@ -699,6 +710,11 @@ static int iris_hfi_gen2_handle_src_change(struct iris_inst *inst,
 	if (iris_vdec_src_change_after_seek(inst, &old_fmt, &old_crop, old_min_count))
 		return iris_vdec_src_change_resume_input(inst);
 
+	if (early_capture && iris_vdec_first_src_change_unchanged(inst, &old_fmt)) {
+		inst->drc_unsignalled = true;
+		return 0;
+	}
+
 	iris_vdec_src_change(inst);
 
 	return 0;
drivers/media/platform/qcom/iris/iris_instance.h +4 -0
index 53693bc53a8e..b85f7ad460bf 100644
@@ -60,6 +60,8 @@ struct iris_hfi_session_ops;
  * @vp9_seek_psc: a VP9 seek may raise a settings change that changes nothing
  * @drc_resumed_in_place: a settings change was not signalled, its PSC_LAST may follow
  * @input_stopping: STREAMOFF(OUTPUT) waits for the firmware to stop the input
+ * @early_capture: CAPTURE was started before the first settings change
+ * @drc_unsignalled: an unsignalled settings change waits for its PSC_LAST
  * @drc_wq: woken when IRIS_INST_SUB_DRC_LAST is set
  * @last_buf_ns: start time of received input buffer for current one second FPS window
  * @frame_counter: input buffer counter for current one second FPS window
@@ -112,6 +114,8 @@ struct iris_inst {
 	bool				vp9_seek_psc;
 	bool				drc_resumed_in_place;
 	bool				input_stopping;
+	bool				early_capture;
+	bool				drc_unsignalled;
 	wait_queue_head_t		drc_wq;
 	u64				last_buf_ns;
 	u32				frame_counter;
drivers/media/platform/qcom/iris/iris_vb2.c +5 -0
index c19de89945e3..f83ea1a5f5ba 100644
@@ -263,6 +263,11 @@ void iris_vb2_stop_streaming(struct vb2_queue *q)
 	mutex_lock(&inst->lock);
 
 	inst->drc_resumed_in_place = false;
+	inst->early_capture = false;
+	if (inst->drc_unsignalled) {
+		inst->drc_unsignalled = false;
+		iris_vdec_src_change(inst);
+	}
 
 	if (!V4L2_TYPE_IS_OUTPUT(q->type) &&
 	    !V4L2_TYPE_IS_CAPTURE(q->type))
drivers/media/platform/qcom/iris/iris_vdec.c +37 -0
index edd58c0dd4a5..8512693e3ff3 100644
@@ -429,6 +429,36 @@ int iris_vdec_src_change_resume_input(struct iris_inst *inst)
 	return iris_inst_change_sub_state(inst, IRIS_INST_SUB_DRC | IRIS_INST_SUB_INPUT_PAUSE, 0);
 }
 
+/*
+ * A client may start CAPTURE before the first settings change, with the size
+ * from the container as FFmpeg does. That settings change pauses the output
+ * port and ends with a PSC_LAST buffer even if it changes nothing.
+ */
+bool iris_vdec_first_src_change_unchanged(struct iris_inst *inst,
+					  const struct v4l2_pix_format_mplane *old_fmt)
+{
+	struct vb2_queue *dst_q = v4l2_m2m_get_dst_vq(inst->m2m_ctx);
+
+	return inst->state == IRIS_INST_STREAMING &&
+	       inst->sub_state == (IRIS_INST_SUB_DRC | IRIS_INST_SUB_INPUT_PAUSE) &&
+	       iris_vdec_capture_fmt_unchanged(inst, old_fmt) &&
+	       inst->buffers[BUF_OUTPUT].min_count <= vb2_get_num_buffers(dst_q);
+}
+
+/* Complete an unsignalled settings change on its PSC_LAST buffer */
+int iris_vdec_src_change_complete(struct iris_inst *inst)
+{
+	int ret;
+
+	inst->drc_unsignalled = false;
+
+	ret = iris_inst_sub_state_change_drc_last(inst);
+	if (ret)
+		return ret;
+
+	return iris_vdec_start_cmd(inst);
+}
+
 void iris_vdec_src_change(struct iris_inst *inst)
 {
 	struct v4l2_m2m_ctx *m2m_ctx = inst->m2m_ctx;
@@ -483,6 +513,13 @@ int iris_vdec_streamon_output(struct iris_inst *inst)
 	const struct iris_hfi_session_ops *hfi_ops = inst->hfi_session_ops;
 	int ret;
 
+	/* On gen2, fw_min_count is only set by a settings change */
+	inst->early_capture = inst->state == IRIS_INST_INPUT_STREAMING &&
+			      !inst->fw_min_count &&
+			      !(inst->sub_state & (IRIS_INST_SUB_FIRST_IPSC |
+						   IRIS_INST_SUB_DRC |
+						   IRIS_INST_SUB_DRAIN));
+
 	ret = hfi_ops->session_set_config_params(inst, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE);
 	if (ret)
 		return ret;
drivers/media/platform/qcom/iris/iris_vdec.h +3 -0
index 5b55354cc25f..24dadee0a19c 100644
@@ -20,6 +20,9 @@ bool iris_vdec_src_change_after_seek(struct iris_inst *inst,
 				     const struct iris_hfi_rect_desc *old_crop,
 				     u32 old_min_count);
 int iris_vdec_src_change_resume_input(struct iris_inst *inst);
+bool iris_vdec_first_src_change_unchanged(struct iris_inst *inst,
+					  const struct v4l2_pix_format_mplane *old_fmt);
+int iris_vdec_src_change_complete(struct iris_inst *inst);
 void iris_vdec_update_min_capture_bufs(struct iris_inst *inst);
 int iris_vdec_streamon_input(struct iris_inst *inst);
 int iris_vdec_streamon_output(struct iris_inst *inst);
Signature · 1 line
2.34.1
#11 lore raw

PATCH 11/11 media: iris: record the LAST buffer returned with an error

In reply to Neil Armstrong

The empty buffer that ends a drain or a source change can come with V4L2_BUF_FLAG_ERROR, e.g. from the frame information of a frame flushed by a seek. iris_vb2_buffer_done() returns it without setting inst->last_buffer_dequeued, nor signalling the end of a drain.

A client following the specification may queue its CAPTURE buffers again before V4L2_DEC_CMD_START. iris_vb2_buf_queue() then returns one of them as a second LAST buffer, as none was recorded for the pending source change.

Record the LAST buffer whatever its state.

Fixes b791dcfcba3a ("media: iris: Add handling for corrupt and drop frames")
---
 drivers/media/platform/qcom/iris/iris_buffer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/media/platform/qcom/iris/iris_buffer.c +4 -0
index 38bdf366b384..b9ec8d0cce83 100644
@@ -951,6 +951,10 @@ int iris_vb2_buffer_done(struct iris_inst *inst, struct iris_buffer *buf)
 	vbuf->flags |= buf->flags;
 
 	if (buf->flags & V4L2_BUF_FLAG_ERROR) {
+		if (vbuf->flags & V4L2_BUF_FLAG_LAST) {
+			iris_vb2_signal_eos(inst);
+			inst->last_buffer_dequeued = true;
+		}
 		state = VB2_BUF_STATE_ERROR;
 		vb2_set_plane_payload(vb2, 0, 0);
 		vb2->timestamp = 0;
Signature · 1 line
2.34.1