media: cedrus: Convert to MPLANE uAPI
PATCH 1/1 media: cedrus: Convert to MPLANE uAPI
The majority of the V4L2 stateless video decoder drivers use the MPLANE interface.
On the userspace side, Gstreamer supports non-MPLANE and MPLANE interfaces. Chromium only supports the MPLANE interface, and is not yet usable with standard desktop Linux. FFmpeg support for either has not landed.
A fallback route using libv4l is also available. The library translates MPLANE interface ioctl calls to non-MPLANE ones, provided that the pixel format used is single plane.
Convert the Cedrus driver to the MPLANE interface, while keeping the supported formats single plane. Besides backward compatibility through the plugin, the hardware requires that different planes not be located too far apart in memory. Keeping the single plane pixel format makes this easy to enforce.
---
This has been tested with Fluster. The score remained the same with or without the patch. This also helps with getting VP8 decoding working with Chromium's in-tree test program "video_decode_accelerator_tests", though Chromium requires other changes regarding buffer allocation and management.
--- drivers/staging/media/sunxi/cedrus/cedrus.c | 2 +- drivers/staging/media/sunxi/cedrus/cedrus.h | 10 +- .../staging/media/sunxi/cedrus/cedrus_h264.c | 4 +- .../staging/media/sunxi/cedrus/cedrus_h265.c | 8 +- .../staging/media/sunxi/cedrus/cedrus_hw.c | 2 +- .../staging/media/sunxi/cedrus/cedrus_hw.h | 2 +- .../staging/media/sunxi/cedrus/cedrus_mpeg2.c | 2 +- .../staging/media/sunxi/cedrus/cedrus_video.c | 113 +++++++++--------- .../staging/media/sunxi/cedrus/cedrus_video.h | 2 +- 9 files changed, 73 insertions(+), 72 deletions(-)
drivers/staging/media/sunxi/cedrus/cedrus.c +1 -1
@@ -437,7 +437,7 @@ static const struct video_device cedrus_video_device = { .ioctl_ops = &cedrus_ioctl_ops, .minor = -1, .release = video_device_release_empty, - .device_caps = V4L2_CAP_VIDEO_M2M | V4L2_CAP_STREAMING, + .device_caps = V4L2_CAP_VIDEO_M2M_MPLANE | V4L2_CAP_STREAMING, };static const struct v4l2_m2m_ops cedrus_m2m_ops = {
drivers/staging/media/sunxi/cedrus/cedrus.h +5 -5
@@ -116,8 +116,8 @@ struct cedrus_ctx {struct v4l2_fh fh;struct cedrus_dev *dev; -struct v4l2_pix_format src_fmt; -struct v4l2_pix_format dst_fmt; +struct v4l2_pix_format_mplane src_fmt; +struct v4l2_pix_format_mplane dst_fmt;struct cedrus_dec_ops *current_codec;unsigned int bit_depth;
@@ -164,7 +164,7 @@ struct cedrus_dec_ops {void (*stop)(struct cedrus_ctx *ctx);void (*trigger)(struct cedrus_ctx *ctx);unsigned int (*extra_cap_size)(struct cedrus_ctx *ctx, -struct v4l2_pix_format *pix_fmt); +struct v4l2_pix_format_mplane *pix_fmt_mp); };struct cedrus_variant {
@@ -221,12 +221,12 @@ static inline u32 cedrus_wait_for(struct cedrus_dev *dev, u32 reg, u32 flag) }static inline dma_addr_t cedrus_buf_addr (struct vb2_buffer *buf, -struct v4l2_pix_format *pix_fmt, +struct v4l2_pix_format_mplane *pix_fmt,unsigned int plane) {dma_addr_t addr =vb2_dma_contig_plane_dma_addr (buf,0 ); -return addr + (pix_fmt ? (dma_addr_t )pix_fmt->bytesperline * +return addr + (pix_fmt ? (dma_addr_t )pix_fmt->plane_fmt[0 ].bytesperline * pix_fmt->height * plane :0 ); }
drivers/staging/media/sunxi/cedrus/cedrus_h264.c +2 -2
@@ -97,7 +97,7 @@ static int cedrus_write_frame_list(struct cedrus_ctx *ctx,int output =-1 ;unsigned int i; - cap_q =v4l2_m2m_get_vq (ctx->fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE ); + cap_q =v4l2_m2m_get_vq (ctx->fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE );memset (pic_list,0 ,sizeof (pic_list));
@@ -198,7 +198,7 @@ static void _cedrus_write_ref_list(struct cedrus_ctx *ctx,unsigned int i;size_t size; - cap_q =v4l2_m2m_get_vq (ctx->fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE ); + cap_q =v4l2_m2m_get_vq (ctx->fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE );memset (sram_array,0 ,sizeof (sram_array));
drivers/staging/media/sunxi/cedrus/cedrus_h265.c +4 -4
@@ -150,7 +150,7 @@ static void cedrus_h265_frame_info_write_dpb(struct cedrus_ctx *ctx, u8 num_active_dpb_entries) {struct vb2_queue *vq =v4l2_m2m_get_vq (ctx->fh.m2m_ctx, -V4L2_BUF_TYPE_VIDEO_CAPTURE ); +V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE );unsigned int i;for (i =0 ; i < num_active_dpb_entries; i++) {
@@ -818,7 +818,7 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)if (ctx->bit_depth >8 ) {unsigned int stride =ALIGN (ctx->dst_fmt.width /4 ,32 ); - reg = ctx->dst_fmt.sizeimage - + reg = ctx->dst_fmt.plane_fmt[0 ].sizeimage -cedrus_h265_2bit_size (ctx->dst_fmt.width, ctx->dst_fmt.height);cedrus_write (dev,VE_DEC_H265_OFFSET_ADDR_FIRST_OUT , reg);
@@ -900,10 +900,10 @@ static void cedrus_h265_trigger(struct cedrus_ctx *ctx) }static unsigned int cedrus_h265_extra_cap_size (struct cedrus_ctx *ctx, -struct v4l2_pix_format *pix_fmt) +struct v4l2_pix_format_mplane *pix_fmt_mp) {if (ctx->bit_depth >8 ) -return cedrus_h265_2bit_size (pix_fmt->width, pix_fmt->height); +return cedrus_h265_2bit_size (pix_fmt_mp->width, pix_fmt_mp->height);return 0 ; }
drivers/staging/media/sunxi/cedrus/cedrus_hw.c +1 -1
@@ -77,7 +77,7 @@ void cedrus_engine_disable(struct cedrus_dev *dev) }void cedrus_dst_format_set (struct cedrus_dev *dev, -struct v4l2_pix_format *fmt) +struct v4l2_pix_format_mplane *fmt) {unsigned int width = fmt->width;unsigned int height = fmt->height;
drivers/staging/media/sunxi/cedrus/cedrus_hw.h +1 -1
@@ -20,7 +20,7 @@ int cedrus_engine_enable(struct cedrus_ctx *ctx);void cedrus_engine_disable (struct cedrus_dev *dev);void cedrus_dst_format_set (struct cedrus_dev *dev, -struct v4l2_pix_format *fmt); +struct v4l2_pix_format_mplane *fmt_mp);int cedrus_hw_suspend (struct device *device);int cedrus_hw_resume (struct device *device);
drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c +1 -1
@@ -119,7 +119,7 @@ static int cedrus_mpeg2_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)cedrus_write (dev,VE_DEC_MPEG_PICBOUNDSIZE , reg);/* Forward and backward prediction reference buffers. */ - vq =v4l2_m2m_get_vq (ctx->fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE ); + vq =v4l2_m2m_get_vq (ctx->fh.m2m_ctx,V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE ); cedrus_write_ref_buf_addr(ctx, vq, pic->forward_ref_ts, VE_DEC_MPEG_FWD_REF_LUMA_ADDR,
drivers/staging/media/sunxi/cedrus/cedrus_video.c +57 -56
269 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus_video.h +1 -1
@@ -26,7 +26,7 @@ extern const struct v4l2_ioctl_ops cedrus_ioctl_ops;int cedrus_queue_init (void *priv,struct vb2_queue *src_vq,struct vb2_queue *dst_vq); -void cedrus_prepare_format (struct v4l2_pix_format *pix_fmt); +void cedrus_prepare_format (struct v4l2_pix_format_mplane *pix_fmt_mp);void cedrus_reset_cap_format (struct cedrus_ctx *ctx);void cedrus_reset_out_format (struct cedrus_ctx *ctx);
Signature · 1 line
2.38.1.584.g0f3c55d4c2-goog
Jernej Škrabec
maintainerHi Chen-Yu!
Dne torek, 29. november 2022 ob 08:45:30 CET je Chen-Yu Tsai napisal(a):
Quoted 7 lines
The majority of the V4L2 stateless video decoder drivers use the MPLANE interface.
On the userspace side, Gstreamer supports non-MPLANE and MPLANE interfaces. Chromium only supports the MPLANE interface, and is not yet usable with standard desktop Linux. FFmpeg support for either has not landed.
I don't like fixing userspace issues in kernel, if kernel side works fine. Implementing missing non-MPLANE support in Chromium will also allow it to work with older kernels.
Hans, what's linux-media politics about such changes?
Best regards,
Jernej
Quoted 19 lines
A fallback route using libv4l is also available. The library translates MPLANE interface ioctl calls to non-MPLANE ones, provided that the pixel format used is single plane.
Convert the Cedrus driver to the MPLANE interface, while keeping the supported formats single plane. Besides backward compatibility through the plugin, the hardware requires that different planes not be located too far apart in memory. Keeping the single plane pixel format makes this easy to enforce.
Signed-off-by Chen-Yu Tsai <[email protected]>---
This has been tested with Fluster. The score remained the same with or without the patch. This also helps with getting VP8 decoding working with Chromium's in-tree test program "
video_decode_accelerator_tests", though Chromium requires other changes regarding buffer allocation and management.
Quoted 11 lines · Jernej Škrabec
Hi Chen-Yu!
Dne torek, 29. november 2022 ob 08:45:30 CET je Chen-Yu Tsai napisal(a):
Quoted 7 lines
The majority of the V4L2 stateless video decoder drivers use the MPLANE interface.
On the userspace side, Gstreamer supports non-MPLANE and MPLANE interfaces. Chromium only supports the MPLANE interface, and is not yet usable with standard desktop Linux. FFmpeg support for either has not landed.
Quoted 5 lines
I don't like fixing userspace issues in kernel, if kernel side works fine. Implementing missing non-MPLANE support in Chromium will also allow it to work with older kernels.
Hans, what's linux-media politics about such changes?
Not keen on this. Does the cedrus HW even have support for multiple planes? I suspect not, in which case the driver shouldn't suggest that it can do that.
Now, if the hardware *can* support this, then there is an argument to be made for the cedrus driver to move to the multiplanar API before moving it out of staging to allow such future enhancements.
Note that you have to choose whether to support single or multiplanar, you can't support both at the same time.
So the decision to move to multiplanar should be led by the HW capabilities.
And Chromium really needs to support non-multiplanar formats as well. I'm really surprised to hear that it doesn't, to be honest.
Regards,
Hans
Quoted 25 lines
Best regards,
JernejQuoted 19 lines
A fallback route using libv4l is also available. The library translates MPLANE interface ioctl calls to non-MPLANE ones, provided that the pixel format used is single plane.
Convert the Cedrus driver to the MPLANE interface, while keeping the supported formats single plane. Besides backward compatibility through the plugin, the hardware requires that different planes not be located too far apart in memory. Keeping the single plane pixel format makes this easy to enforce.
Signed-off-by Chen-Yu Tsai <[email protected]>---
This has been tested with Fluster. The score remained the same with or without the patch. This also helps with getting VP8 decoding working with Chromium's in-tree test program "
video_decode_accelerator_tests", though Chromium requires other changes regarding buffer allocation and management.
Quoted 17 lines · Hans Verkuil
Quoted 15 lines · Jernej Škrabec
Hi Chen-Yu!
Dne torek, 29. november 2022 ob 08:45:30 CET je Chen-Yu Tsai napisal(a):
Quoted 7 lines
The majority of the V4L2 stateless video decoder drivers use the MPLANE interface.
On the userspace side, Gstreamer supports non-MPLANE and MPLANE interfaces. Chromium only supports the MPLANE interface, and is not yet usable with standard desktop Linux. FFmpeg support for either has not landed.
I don't like fixing userspace issues in kernel, if kernel side works fine. Implementing missing non-MPLANE support in Chromium will also allow it to work with older kernels.
Quoted 8 lines
Quoted 1 line
Hans, what's linux-media politics about such changes?
Not keen on this. Does the cedrus HW even have support for multiple planes? I suspect not, in which case the driver shouldn't suggest that it can do that.
Now, if the hardware *can* support this, then there is an argument to be made for the cedrus driver to move to the multiplanar API before moving it out of staging to allow such future enhancements.
AFAIK it can, but has some limitations on how far apart the buffers for the separate planes can be. Nicolas mentioned that I could support the multiplanar API, but only allow the contiguous single planar formats, so NV12 instead of NV12M.
And I suspect that reference frames have to be contiguous as well. So I guess the overall answer is that it can't. But the same goes for Hantro or rkvdec, which both use the multiplanar API.
This conversion was done so that I could use Cedrus as a testbed for developing new codec support, as I already own an H6 device. Added bonus is trying to get V4L2 decoder support to work for desktop Linux, without the libraries that ChromeOS ships.
Quoted 7 lines
Note that you have to choose whether to support single or multiplanar, you can't support both at the same time.
So the decision to move to multiplanar should be led by the HW capabilities.
And Chromium really needs to support non-multiplanar formats as well. I'm really surprised to hear that it doesn't, to be honest.
Chromium does support non-multiplanar formats, such as NV12. In fact this is the preferred format, unless it's on MediaTek, in which it switches to MM21 as the capture format, and does untiling in software. This support for formats is separate from using the multiplanar API.
Support for video decoders is mostly driven by ChromeOS. Currently all the hardware ChromeOS supports, be it stateful or stateless, use the multiplanar API, so there hasn't been a real need to support it yet.
Regards
ChenYu
Quoted 30 lines
Regards,
Hans
Quoted 25 lines
Best regards,
JernejQuoted 19 lines
A fallback route using libv4l is also available. The library translates MPLANE interface ioctl calls to non-MPLANE ones, provided that the pixel format used is single plane.
Convert the Cedrus driver to the MPLANE interface, while keeping the supported formats single plane. Besides backward compatibility through the plugin, the hardware requires that different planes not be located too far apart in memory. Keeping the single plane pixel format makes this easy to enforce.
Signed-off-by Chen-Yu Tsai <[email protected]>---
This has been tested with Fluster. The score remained the same with or without the patch. This also helps with getting VP8 decoding working with Chromium's in-tree test program "
video_decode_accelerator_tests", though Chromium requires other changes regarding buffer allocation and management.
Le mardi 06 décembre 2022 à 20:23 +0800, Chen-Yu Tsai a écrit :
Quoted 14 lines · Hans Verkuil
Quoted 13 lines · Jernej Škrabec
Quoted 11 lines
Hi Chen-Yu!
Dne torek, 29. november 2022 ob 08:45:30 CET je Chen-Yu Tsai napisal(a):
Quoted 7 lines
The majority of the V4L2 stateless video decoder drivers use the MPLANE interface.
On the userspace side, Gstreamer supports non-MPLANE and MPLANE interfaces. Chromium only supports the MPLANE interface, and is not yet usable with standard desktop Linux. FFmpeg support for either has not landed.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
I don't like fixing userspace issues in kernel, if kernel side works fine. Implementing missing non-MPLANE support in Chromium will also allow it to work with older kernels.
Hans, what's linux-media politics about such changes?
Not keen on this. Does the cedrus HW even have support for multiple planes? I suspect not, in which case the driver shouldn't suggest that it can do that.
Hi Hans,
Quoted 9 lines
Quoted 4 lines
Now, if the hardware *can* support this, then there is an argument to be made for the cedrus driver to move to the multiplanar API before moving it out of staging to allow such future enhancements.
AFAIK it can, but has some limitations on how far apart the buffers for the separate planes can be. Nicolas mentioned that I could support the multiplanar API, but only allow the contiguous single planar formats, so NV12 instead of NV12M.
indeed, MPLANE buffer API is not an advertisement for MPLANE support. The pixel formats exposed through ENUM_FMT are the only possible advertisement, and only single allocation format (NV12) remains exposed.
Putting my userspace hat on, I see see an effort by the author of MPLANE API to make it so it would completely replaced the older API. The effort have imho very bad consequences (duplication of pixel formats), but if we also don't enforce porting existing drivers to the new API, we add yet another consequence, but this time on userspace, which must handle both C structures to actually work generically. I totally understand that from driver maintainer point of view, this change have absolutely no value, but we force userspace complexity simply because we leave it to driver author to pick older or newer (totally equivalent) APIs. To me, the problem is that V4L2 API maintainers didn't adopt the new API despite merging it. The adoption should have deprecated usage of the old API, at least in new drivers (since 2011). This should also have been an unstaging requirement.
regards,
Nicolas
Quoted 61 lines
And I suspect that reference frames have to be contiguous as well. So I guess the overall answer is that it can't. But the same goes for Hantro or rkvdec, which both use the multiplanar API.
This conversion was done so that I could use Cedrus as a testbed for developing new codec support, as I already own an H6 device. Added bonus is trying to get V4L2 decoder support to work for desktop Linux, without the libraries that ChromeOS ships.
Quoted 7 lines
Note that you have to choose whether to support single or multiplanar, you can't support both at the same time.
So the decision to move to multiplanar should be led by the HW capabilities.
And Chromium really needs to support non-multiplanar formats as well. I'm really surprised to hear that it doesn't, to be honest.
Chromium does support non-multiplanar formats, such as NV12. In fact this is the preferred format, unless it's on MediaTek, in which it switches to MM21 as the capture format, and does untiling in software. This support for formats is separate from using the multiplanar API.
Support for video decoders is mostly driven by ChromeOS. Currently all the hardware ChromeOS supports, be it stateful or stateless, use the multiplanar API, so there hasn't been a real need to support it yet.
Regards
ChenYuQuoted 30 lines
Regards,
Hans
Quoted 25 lines
Best regards,
JernejQuoted 19 lines
A fallback route using libv4l is also available. The library translates MPLANE interface ioctl calls to non-MPLANE ones, provided that the pixel format used is single plane.
Convert the Cedrus driver to the MPLANE interface, while keeping the supported formats single plane. Besides backward compatibility through the plugin, the hardware requires that different planes not be located too far apart in memory. Keeping the single plane pixel format makes this easy to enforce.
Signed-off-by Chen-Yu Tsai <[email protected]>---
This has been tested with Fluster. The score remained the same with or without the patch. This also helps with getting VP8 decoding working with Chromium's in-tree test program "
video_decode_accelerator_tests", though Chromium requires other changes regarding buffer allocation and management.
Quoted 40 lines · Nicolas Dufresne
Le mardi 06 décembre 2022 à 20:23 +0800, Chen-Yu Tsai a écrit :
Quoted 14 lines · Hans Verkuil
Quoted 13 lines · Jernej Škrabec
Quoted 11 lines
Hi Chen-Yu!
Dne torek, 29. november 2022 ob 08:45:30 CET je Chen-Yu Tsai napisal(a):
Quoted 7 lines
The majority of the V4L2 stateless video decoder drivers use the MPLANE interface.
On the userspace side, Gstreamer supports non-MPLANE and MPLANE interfaces. Chromium only supports the MPLANE interface, and is not yet usable with standard desktop Linux. FFmpeg support for either has not landed.
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
I don't like fixing userspace issues in kernel, if kernel side works fine. Implementing missing non-MPLANE support in Chromium will also allow it to work with older kernels.
Hans, what's linux-media politics about such changes?
Not keen on this. Does the cedrus HW even have support for multiple planes? I suspect not, in which case the driver shouldn't suggest that it can do that.
Hi Hans,
Quoted 9 lines
Quoted 4 lines
Now, if the hardware *can* support this, then there is an argument to be made for the cedrus driver to move to the multiplanar API before moving it out of staging to allow such future enhancements.
AFAIK it can, but has some limitations on how far apart the buffers for the separate planes can be. Nicolas mentioned that I could support the multiplanar API, but only allow the contiguous single planar formats, so NV12 instead of NV12M.
indeed, MPLANE buffer API is not an advertisement for MPLANE support. The pixel formats exposed through
ENUM_FMTare the only possible advertisement, and only single allocation format (NV12) remains exposed.
Quoted 12 lines
Putting my userspace hat on, I see see an effort by the author of MPLANE API to make it so it would completely replaced the older API. The effort have imho very bad consequences (duplication of pixel formats), but if we also don't enforce porting existing drivers to the new API, we add yet another consequence, but this time on userspace, which must handle both C structures to actually work generically. I totally understand that from driver maintainer point of view, this change have absolutely no value, but we force userspace complexity simply because we leave it to driver author to pick older or newer (totally equivalent) APIs. To me, the problem is that V4L2 API maintainers didn't adopt the new API despite merging it. The adoption should have deprecated usage of the old API, at least in new drivers (since 2011). This should also have been an unstaging requirement.
I know all about it. We made design mistakes in hindsight. It's not just that there are effectively two APIs, it is also that the MPLANE API has awkward data structures. There have been proposals (starting with Helen Koike) to fix this, but it never got the momentum. I still think that is the way to go forward, but someone needs to take that ball and start pestering the core maintainers to give feedback and really give it the time it deserves.
The core issue for the MPLANE API was the gray area in design where you have to decide to go with a completely new API or tweaking an existing API.
Certainly at the time this was designed we tended to be conservative and went with tweaks. Today, after gaining years of additional experience, we would go with a new redesigned API.
Regards,
Hans
Quoted 66 lines
regards,
NicolasQuoted 61 lines
And I suspect that reference frames have to be contiguous as well. So I guess the overall answer is that it can't. But the same goes for Hantro or rkvdec, which both use the multiplanar API.
This conversion was done so that I could use Cedrus as a testbed for developing new codec support, as I already own an H6 device. Added bonus is trying to get V4L2 decoder support to work for desktop Linux, without the libraries that ChromeOS ships.
Quoted 7 lines
Note that you have to choose whether to support single or multiplanar, you can't support both at the same time.
So the decision to move to multiplanar should be led by the HW capabilities.
And Chromium really needs to support non-multiplanar formats as well. I'm really surprised to hear that it doesn't, to be honest.
Chromium does support non-multiplanar formats, such as NV12. In fact this is the preferred format, unless it's on MediaTek, in which it switches to MM21 as the capture format, and does untiling in software. This support for formats is separate from using the multiplanar API.
Support for video decoders is mostly driven by ChromeOS. Currently all the hardware ChromeOS supports, be it stateful or stateless, use the multiplanar API, so there hasn't been a real need to support it yet.
Regards
ChenYuQuoted 30 lines
Regards,
Hans
Quoted 25 lines
Best regards,
JernejQuoted 19 lines
A fallback route using libv4l is also available. The library translates MPLANE interface ioctl calls to non-MPLANE ones, provided that the pixel format used is single plane.
Convert the Cedrus driver to the MPLANE interface, while keeping the supported formats single plane. Besides backward compatibility through the plugin, the hardware requires that different planes not be located too far apart in memory. Keeping the single plane pixel format makes this easy to enforce.
Signed-off-by Chen-Yu Tsai <[email protected]>---
This has been tested with Fluster. The score remained the same with or without the patch. This also helps with getting VP8 decoding working with Chromium's in-tree test program "
video_decode_accelerator_tests", though Chromium requires other changes regarding buffer allocation and management.