media: rkvdec: set ctx->image_fmt in rkvdec_s_capture_fmt
Subsystems (3)
PATCH 1/1 media: rkvdec: set ctx->image_fmt in rkvdec_s_capture_fmt
ctx->image_fmt is initialized as RKVDEC_IMG_FMT_ANY at rkvdec_s_output_fmt, and get set at rkvdec_s_ctrl when userspace sends SPS info via VIDIOC_S_EXT_CTRLS. This works fine with gstreamer because it sends SPS info to kernel driver before requesting capture queue bufs.
But chromium requests capture queue bufs first and then sends SPS info to kernel, then rkvdec_s_ctrl will return -EBUSY, and the video is displayed green.
Chromium calls VIDIOC_S_FMT to capture queue instead before requesting capture queue bufs, so setting ctx->image_fmt in rkvdec_s_capture_fmt will make rkvdec_s_ctrl return 0 when the first SPS info sent to driver.
---
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/media/platform/rockchip/rkvdec/rkvdec.c +12 -0
@@ -537,6 +537,18 @@ static int rkvdec_s_capture_fmt(struct file *file, void *priv,return ret; ctx->decoded_fmt = *f; + +u32 fourcc = f->fmt.pix_mp.pixelformat; + +if (fourcc ==V4L2_PIX_FMT_NV12 ) + ctx->image_fmt =RKVDEC_IMG_FMT_420_8BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV15 ) + ctx->image_fmt =RKVDEC_IMG_FMT_420_10BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV16 ) + ctx->image_fmt =RKVDEC_IMG_FMT_422_8BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV20 ) + ctx->image_fmt =RKVDEC_IMG_FMT_422_10BIT ; +return 0 ; }
Signature · 1 line
2.43.0
Hi,
Quoted 29 lines · Jianfeng Liu
ctx->image_fmtis initialized asRKVDEC_IMG_FMT_ANYatrkvdec_s_output_fmt, and get set atrkvdec_s_ctrlwhen userspace sends SPS info viaVIDIOC_S_EXT_CTRLS. This works fine with gstreamer because it sends SPS info to kernel driver before requesting capture queue bufs.But chromium requests capture queue bufs first and then sends SPS info to kernel, then
rkvdec_s_ctrlwill return-EBUSY, and the video is displayed green.Chromium calls
VIDIOC_S_FMTto capture queue instead before requesting capture queue bufs, so settingctx->image_fmtinrkvdec_s_capture_fmtwill makerkvdec_s_ctrlreturn 0 when the first SPS info sent to driver.Signed-off-by Jianfeng Liu <[email protected]>Fixes d35c64eccf3b1 ("media: rkvdec: Add get_image_fmt ops")---
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/media/platform/rockchip/rkvdec/rkvdec.c +1
-0@@ -537,6 +537,18 @@ static int rkvdec_s_capture_fmt(struct file *file, void *priv,return ret; ctx->decoded_fmt = *f; +
drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_s_capture_fmt(struct file *file, void *priv, · line 550
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10
-0+u32 fourcc = f->fmt.pix_mp.pixelformat; + +if (fourcc ==V4L2_PIX_FMT_NV12 ) + ctx->image_fmt =RKVDEC_IMG_FMT_420_8BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV15 ) + ctx->image_fmt =RKVDEC_IMG_FMT_420_10BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV16 ) + ctx->image_fmt =RKVDEC_IMG_FMT_422_8BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV20 ) + ctx->image_fmt =RKVDEC_IMG_FMT_422_10BIT ;
ctx->image_fmt is used to limit what CAPTURE pixel format can be set and forcing it here violates this.
Chromium should be fixed to follow spec at 4.5.3.2. Initialization [1]:
1. Set the coded format on the OUTPUT queue via VIDIOC_S_FMT().
2. Call VIDIOC_S_EXT_CTRLS() to set all the controls (parsed headers, etc.) required by the OUTPUT format to enumerate the CAPTURE formats.
...
5. [optional] Choose a different CAPTURE format than suggested via VIDIOC_S_FMT() on CAPTURE queue.
Regards,
Jonas
[1] https://docs.kernel.org/userspace-api/media/v4l/dev-stateless-decoder.html
Quoted 4 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +1
-0+return 0 ; }
Quoted 1 line · Jonas Karlman
Chromium should be fixed to follow spec at 4.5.3.2. Initialization [1]:
Hi Jonas,
Thank you for guiding me to the spec, I will look into chromium and try to fix it.
Best regards,
Jianfeng
Hi,
Le vendredi 12 décembre 2025 à 23:41 +0800, Jianfeng Liu a écrit :
Quoted 5 lines
ctx->image_fmtis initialized asRKVDEC_IMG_FMT_ANYatrkvdec_s_output_fmt, and get set atrkvdec_s_ctrlwhen userspace sends SPS info viaVIDIOC_S_EXT_CTRLS. This works fine with gstreamer because it sends SPS info to kernel driver before requesting capture queue bufs.
Quoted 7 lines
But chromium requests capture queue bufs first and then sends SPS info to kernel, then
rkvdec_s_ctrlwill return-EBUSY, and the video is displayed green.Chromium calls
VIDIOC_S_FMTto capture queue instead before requesting capture queue bufs, so settingctx->image_fmtinrkvdec_s_capture_fmtwill makerkvdec_s_ctrlreturn 0 when the first SPS info sent to driver.
I'm reading you here, and reading the spec again [0], and you are saying the Chromium isn't following the initialization process. That means, it should be impossible to allocate 10bit capture buffer, since the SPS in place specify the color depth. Other parameters in other codec can influence the reference buffer size, so you could endup with the wrong allocation.
Quoted 19 lines
Signed-off-by Jianfeng Liu <[email protected]>Fixes d35c64eccf3b1 ("media: rkvdec: Add get_image_fmt ops")---
drivers/media/platform/rockchip/rkvdec/rkvdec.c | 12 ++++++++++++
1 file changed, 12 insertions(+)drivers/media/platform/rockchip/rkvdec/rkvdec.c +0
-0@@ -537,6 +537,18 @@ static int rkvdec_s_capture_fmt(struct file *file, void *priv, return ret;
ctx->decoded_fmt= *f;drivers/media/platform/rockchip/rkvdec/rkvdec.c +1
-0+
drivers/media/platform/rockchip/rkvdec/rkvdec.c static int rkvdec_s_capture_fmt(struct file *file, void *priv, · line 550
Quoted 10 lines
drivers/media/platform/rockchip/rkvdec/rkvdec.c +10
-0+u32 fourcc = f->fmt.pix_mp.pixelformat; + +if (fourcc ==V4L2_PIX_FMT_NV12 ) + ctx->image_fmt =RKVDEC_IMG_FMT_420_8BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV15 ) + ctx->image_fmt =RKVDEC_IMG_FMT_420_10BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV16 ) + ctx->image_fmt =RKVDEC_IMG_FMT_422_8BIT ; +else if (fourcc ==V4L2_PIX_FMT_NV20 ) + ctx->image_fmt =RKVDEC_IMG_FMT_422_10BIT ;
You cannot accept a format that falls against the color depth in the SPS control, and rkvdec does not do color conversion implicitly. This can otherwise lead to letting the HW overrun the buffer (forcing 8bit with 10bit content). Can you check with Chromium dev if they can perhaps adhere to the spec instead ? This is all news to me, but I probably never had to test 10bit playback in Chromium outside of MTK (which might not be less strict, hopefully done the right way).
regards,
Nicolas
Quoted 4 lines
+
return 0;
}
Hi,
Quoted 5 lines · Nicolas Dufresne
I'm reading you here, and reading the spec again [0], and you are saying the Chromium isn't following the initialization process. That means, it should be impossible to allocate 10bit capture buffer, since the SPS in place specify the color depth. Other parameters in other codec can influence the reference buffer size, so you could endup with the wrong allocation.
Chromium does follow the spec when decoding 10bit videos[1], but that is still limited to hevc and vp9. For h264 and 8bit video chromium thinks this is unnecessary.
Quoted 7 lines
You cannot accept a format that falls against the color depth in the SPS control, and rkvdec does not do color conversion implicitly. This can otherwise lead to letting the HW overrun the buffer (forcing 8bit with 10bit content). Can you check with Chromium dev if they can perhaps adhere to the spec instead ? This is all news to me, but I probably never had to test 10bit playback in Chromium outside of MTK (which might not be less strict, hopefully done the right way).
I will try to fix chromium to follow the spec. Since rkvdec driver is the only driver related, I didn't check the stateless spec.
Best regards,
Jianfeng
Hi,
Le samedi 13 décembre 2025 à 13:59 +0800, Jianfeng Liu a écrit :
Quoted 3 lines
Chromium does follow the spec when decoding 10bit videos[1], but that is still limited to hevc and vp9. For h264 and 8bit video chromium thinks this is unnecessary.
thanks for the pointer, that explains a lot my surprise and slight confusion. Now that you mention, on relevant chromebooks, 10bit is only supported with HEVC/VP9 (perhaps AV1 too, not sure).
Nicolas