staging: media: cedrus: add VP9 decoding for H616
Jernej Skrabec
maintainercover staging: media: cedrus: add VP9 decoding for H616
This series adds VP9 decoding to the Cedrus driver for the H616 video engine, which runs VP9 in its H.265 engine.
The backward probability adaptation is done in the driver with the v4l2 VP9 helpers, using the symbol counts the hardware writes back.
Patches 1 and 2 are preparation: the output line stride is taken from the capture format, and the format check is moved into a helper.
Patch 3 adds VP9 decoding. Like H.265, 10-bit frames are output with 8 bits per sample for now. P010 output for 10-bit VP9 and H.265 will follow in a separate series. The decoder core is reset after every VP9 frame, as an H.265 picture of another context decoded next fails otherwise.
The series is based on my Cedrus fixes series [1], which it depends on. It doesn't depend on any other pending Cedrus work.
Testing
-------
All testing was done on an H616 board (T95 Max, 4 GiB DDR3, VE at 600 MHz) with FFmpeg's v4l2-request hwaccel. Hardware output was compared per frame with the libvpx MD5 files or with FFmpeg's software decoder; the other capture formats were compared plane by plane against NV12 output, using an LD_PRELOAD shim that forces the capture format. The 10-bit decoding itself was also checked with the P010 output of the follow-up series, which matches the libvpx MD5 files.
Results:
- libvpx test vectors (303 profile 0, the profile 2 4:2:0 10-bit one):
275 match the libvpx MD5 files frame by frame, the failures are listed below.
- fluster VP9-TEST-VECTORS: 242/305, the same vectors fail with FFmpeg's software decoder (FFmpeg rescales frames after a size change, so the stream MD5 of resized vectors can't match).
VP9-TEST-VECTORS-HIGH: 5/6, the 10-bit 4:2:0 vector fails as its output has 8 bits per sample, the others are 4:2:2, 4:4:4 or 12-bit and decoded in software.
- fluster JCT-VC-HEVC_V1 (129/147), JVT-AVC_V1 (130/135), VP8-TEST-VECTORS (59/61) and MPEG2_VIDEO-MAIN (7/43): same results as without this series.
- v4l2-compliance: 49 tests, 0 failures, 0 warnings. A test program for invalid VP9 controls, formats and jobs (57 cases) passes.
- NV21, YU12, YV12 and, for 8-bit, ST12 output of 12 8-bit and 10-bit VP9 streams (66x66 to 1920x1080) match NV12 output.
- Decoding VP9 and H.265 streams in parallel instances, in 46 combinations with each other and with H.264 and MPEG-2, gives the same output as decoding them alone. Heavier parallel loads need the decoder reset before every picture from a follow-up series.
- No IOMMU faults or timeouts in any of the above.
Known failures:
- vp92-2-20-10bit-yuv420: the output has 8 bits per sample.
- resize vectors (vp90-2-21-resize_inter_*, vp90-2-05-resize, vp90-2-18-resize): FFmpeg reallocates the capture buffers on the frame size change and then refers to frames of a different size, which the hardware can't scale with this buffer layout.
- vp90-2-13-largescaling: not supported by the hardware.
- vp90-2-22-svc_1280x720_3: inter-layer prediction from a different size, for the same reason as the resize vectors. FFmpeg's software decoder fails it as well.
[1] https://lore.kernel.org/r/[email protected]
Please take a look.
Best regards,
Jernej
Jernej Skrabec (3):
staging: media: cedrus: take the output line stride from the capture
format
staging: media: cedrus: factor out the format check
staging: media: cedrus: add VP9 decoding support
drivers/staging/media/sunxi/cedrus/Makefile | 2 +- drivers/staging/media/sunxi/cedrus/cedrus.c | 53 +- drivers/staging/media/sunxi/cedrus/cedrus.h | 35 + .../staging/media/sunxi/cedrus/cedrus_dec.c | 7 + .../staging/media/sunxi/cedrus/cedrus_hw.c | 28 +- .../staging/media/sunxi/cedrus/cedrus_hw.h | 1 + .../staging/media/sunxi/cedrus/cedrus_regs.h | 131 ++ .../staging/media/sunxi/cedrus/cedrus_video.c | 50 +- .../staging/media/sunxi/cedrus/cedrus_vp9.c | 1253 +++++++++++++++++ 9 files changed, 1548 insertions(+), 12 deletions(-) create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_vp9.c
base-commit: 27285b099fbc5cb2ae3aef20f3bbd7b3c88b3005
prerequisite-patch-id: 032ac086f7ba6944b648a3581a1c287ee06c42c9
prerequisite-patch-id: 30e6f5a647b929dcf501225d403dc1f68436079f
prerequisite-patch-id: 309f0f4b5228ee3b0d3e3b80426429a67e238d53
prerequisite-patch-id: a448a9c72886221eb9b1aea1778a88e163d96309
prerequisite-patch-id: c49f2932a2258bcf000e0e4907e9636b2958b350
prerequisite-patch-id: 3c5110c4b6f13079a09733b972de4cbf38d3119a
prerequisite-patch-id: 78a7e370ba08a94aaaf4cbce49f89432151a9089
prerequisite-patch-id: f62f865eccdab559e9effea5b002b227fc0e3bbf
prerequisite-patch-id: 9a09dbecbbba3731dd2518606a02e12d58e433a6
prerequisite-patch-id: a952ffa6ed148ba0f6b9f5253848b7c8fb2f89a8
prerequisite-patch-id: 9879769cc1ed540f2739c2bf8b43b42a41c6ad8b
Signature · 1 line
2.43.0
Jernej Skrabec
maintainerPATCH 1/3 staging: media: cedrus: take the output line stride from the capture format
cedrus_dst_format_set() programs the line stride of the untiled output formats as the width aligned to 16, which is the bytesperline that cedrus_prepare_format() gives these formats. Program bytesperline itself instead, so that a decoder can use a larger stride, and so that the stride is the one of the buffer when a decoder sets the format up for a frame smaller than it.
Likewise, take the height as it is: cedrus_prepare_format() already aligns it to 16 for these formats.
No functional change.
--- drivers/staging/media/sunxi/cedrus/cedrus_hw.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/staging/media/sunxi/cedrus/cedrus_hw.c +4 -4
@@ -84,7 +84,7 @@ void cedrus_engine_disable(struct cedrus_dev *dev)void cedrus_dst_format_set (struct cedrus_dev *dev,struct v4l2_pix_format *fmt) { -unsigned int width = fmt->width; +unsigned int bytesperline = fmt->bytesperline;unsigned int height = fmt->height;u32 chroma_size;u32 reg;
@@ -94,7 +94,7 @@ void cedrus_dst_format_set(struct cedrus_dev *dev,case V4L2_PIX_FMT_NV21 :case V4L2_PIX_FMT_YUV420 :case V4L2_PIX_FMT_YVU420 : - chroma_size =ALIGN (width,16 ) *ALIGN (height,16 ) /2 ; + chroma_size = bytesperline * height /2 ;switch (fmt->pixelformat) {case V4L2_PIX_FMT_NV12 :
@@ -116,8 +116,8 @@ void cedrus_dst_format_set(struct cedrus_dev *dev, reg = chroma_size /2 ;cedrus_write (dev,VE_PRIMARY_CHROMA_BUF_LEN , reg); - reg =VE_PRIMARY_FB_LINE_STRIDE_LUMA (ALIGN (width,16 )) | -VE_PRIMARY_FB_LINE_STRIDE_CHROMA (ALIGN (width,16 ) /2 ); + reg =VE_PRIMARY_FB_LINE_STRIDE_LUMA (bytesperline) | +VE_PRIMARY_FB_LINE_STRIDE_CHROMA (bytesperline /2 );cedrus_write (dev,VE_PRIMARY_FB_LINE_STRIDE , reg);break ;
Signature · 1 line
2.43.0
Jernej Skrabec
maintainerPATCH 2/3 staging: media: cedrus: factor out the format check
In reply to Jernej Skrabeccedrus_find_format() and cedrus_enum_fmt() check the capabilities and the direction of a format in the same way. Move the check into a helper, so that the VP9 decoder, added later, can exclude formats in one place.
No functional change.
--- .../staging/media/sunxi/cedrus/cedrus_video.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/staging/media/sunxi/cedrus/cedrus_video.c +13 -6
@@ -78,6 +78,17 @@ static struct cedrus_format cedrus_formats[] = {#define CEDRUS_FORMATS_COUNT ARRAY_SIZE(cedrus_formats) +static bool cedrus_check_format (struct cedrus_ctx *ctx, +const struct cedrus_format *fmt, +u32 directions) +{ +if (!cedrus_is_capable (ctx, fmt->capabilities) || + !(fmt->directions & directions)) +return false; + +return true; +} +static struct cedrus_format *cedrus_find_format (struct cedrus_ctx *ctx,u32 pixelformat,u32 directions) {
@@ -88,8 +99,7 @@ static struct cedrus_format *cedrus_find_format(struct cedrus_ctx *ctx,for (i =0 ; i <CEDRUS_FORMATS_COUNT ; i++) { fmt = &cedrus_formats[i]; -if (!cedrus_is_capable (ctx, fmt->capabilities) || - !(fmt->directions & directions)) +if (!cedrus_check_format (ctx, fmt, directions))continue ;if (fmt->pixelformat == pixelformat)
@@ -191,10 +201,7 @@ static int cedrus_enum_fmt(struct file *file, struct v4l2_fmtdesc *f, index =0 ;for (i =0 ; i <CEDRUS_FORMATS_COUNT ; i++) { -if (!cedrus_is_capable (ctx, cedrus_formats[i].capabilities)) -continue ; - -if (!(cedrus_formats[i].directions & direction)) +if (!cedrus_check_format (ctx, &cedrus_formats[i], direction))continue ;if (index == f->index)
Signature · 1 line
2.43.0
Jernej Skrabec
maintainerPATCH 3/3 staging: media: cedrus: add VP9 decoding support
In reply to Jernej SkrabecAdd VP9 decoding for the H616 video engine, which decodes VP9 in its H.265 engine. The backward probability adaptation is done by the driver, from the symbol counts the hardware writes back.
Limitations:
- Only profiles 0 and 2 (8 and 10-bit 4:2:0) are supported, up to 4096x2304. 10-bit frames are output with 8 bits per sample.
- The hardware derives the line stride of the references from their width and a power of two alignment, so the capture formats use a stride aligned to it. A frame can only be used as a reference if its width, rounded up to that alignment, matches the line stride of the capture buffers, so reference scaling is mostly unsupported.
- The tiled NV12_32L32 format is only offered for 8-bit streams, as the hardware can put the plane of the two low bits of 10-bit frames inside its chroma plane.
The engine keeps state of a VP9 frame which is not all in registers. An H.265 picture of another context decoded after it fails, its setup reads back zeros from the bitstream. Reset the decoder core after every VP9 frame. Clearing the registers is not enough.
Tested on H616.
--- drivers/staging/media/sunxi/cedrus/Makefile | 2 +- drivers/staging/media/sunxi/cedrus/cedrus.c | 53 +- drivers/staging/media/sunxi/cedrus/cedrus.h | 35 + .../staging/media/sunxi/cedrus/cedrus_dec.c | 7 + .../staging/media/sunxi/cedrus/cedrus_hw.c | 20 + .../staging/media/sunxi/cedrus/cedrus_hw.h | 1 + .../staging/media/sunxi/cedrus/cedrus_regs.h | 131 ++ .../staging/media/sunxi/cedrus/cedrus_video.c | 31 + .../staging/media/sunxi/cedrus/cedrus_vp9.c | 1253 +++++++++++++++++ 9 files changed, 1531 insertions(+), 2 deletions(-) create mode 100644 drivers/staging/media/sunxi/cedrus/cedrus_vp9.c
drivers/staging/media/sunxi/cedrus/Makefile +1 -1
@@ -3,4 +3,4 @@ obj-$(CONFIG_VIDEO_SUNXI_CEDRUS) += sunxi-cedrus.o sunxi-cedrus-y = cedrus.o cedrus_video.o cedrus_hw.o cedrus_dec.o \ cedrus_mpeg2.o cedrus_h264.o cedrus_h265.o \ - cedrus_vp8.o + cedrus_vp8.o cedrus_vp9.o
drivers/staging/media/sunxi/cedrus/cedrus.c +52 -1
71 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus.h +35 -0
@@ -34,6 +34,27 @@#define CEDRUS_CAPABILITY_MPEG2_DEC BIT(3)#define CEDRUS_CAPABILITY_VP8_DEC BIT(4)#define CEDRUS_CAPABILITY_H265_10_DEC BIT(5) +#define CEDRUS_CAPABILITY_VP9_DEC BIT(6) + +/* +* VP9 needs 1 KiB aligned chroma planes and derives the reference stride +* from the width aligned to a power of two. +*/ +static inline bool cedrus_vp9_is_planar (u32 pixelformat) +{ +return pixelformat ==V4L2_PIX_FMT_YUV420 || + pixelformat ==V4L2_PIX_FMT_YVU420 ; +} + +static inline unsigned int cedrus_vp9_stride_align (u32 pixelformat) +{ +if (cedrus_vp9_is_planar (pixelformat)) +return 128 ; +if (pixelformat ==V4L2_PIX_FMT_NV12_32L32 ) +return 32 ; + +return 64 ; +}enum cedrus_irq_status {CEDRUS_IRQ_NONE ,
@@ -81,6 +102,11 @@ struct cedrus_vp8_run {const struct v4l2_ctrl_vp8_frame *frame_params; }; +struct cedrus_vp9_run { +const struct v4l2_ctrl_vp9_frame *frame_params; +const struct v4l2_ctrl_vp9_compressed_hdr *prob_updates; +}; +struct cedrus_run {struct vb2_v4l2_buffer *src;struct vb2_v4l2_buffer *dst;
@@ -90,9 +116,12 @@ struct cedrus_run {struct cedrus_mpeg2_run mpeg2;struct cedrus_h265_run h265;struct cedrus_vp8_run vp8; +struct cedrus_vp9_run vp9; }; }; +struct cedrus_vp9_ctx ; +struct cedrus_buffer {struct v4l2_m2m_buffer m2m_buf;
@@ -109,6 +138,10 @@ struct cedrus_buffer {dma_addr_t mv_col_buf_dma;ssize_t mv_col_buf_size; } h265; +struct { +u32 width; +u32 height; + } vp9; } codec; };
@@ -164,6 +197,7 @@ struct cedrus_ctx {dma_addr_t intra_pred_buf_dma;ssize_t intra_pred_buf_size; } vp8; +struct cedrus_vp9_ctx *vp9; } codec; };
@@ -221,6 +255,7 @@ extern struct cedrus_dec_ops cedrus_dec_ops_mpeg2;extern struct cedrus_dec_ops cedrus_dec_ops_h264;extern struct cedrus_dec_ops cedrus_dec_ops_h265;extern struct cedrus_dec_ops cedrus_dec_ops_vp8; +extern struct cedrus_dec_ops cedrus_dec_ops_vp9;static inline void cedrus_write (struct cedrus_dev *dev,u32 reg,u32 val) {
drivers/staging/media/sunxi/cedrus/cedrus_dec.c +7 -0
@@ -86,6 +86,13 @@ void cedrus_device_run(void *priv) V4L2_CID_STATELESS_VP8_FRAME);break ; +case V4L2_PIX_FMT_VP9_FRAME : + run.vp9.frame_params =cedrus_find_control_data (ctx, +V4L2_CID_STATELESS_VP9_FRAME ); + run.vp9.prob_updates =cedrus_find_control_data (ctx, +V4L2_CID_STATELESS_VP9_COMPRESSED_HDR ); +break ; +default :break ; }
drivers/staging/media/sunxi/cedrus/cedrus_hw.c +20 -0
@@ -62,6 +62,11 @@ int cedrus_engine_enable(struct cedrus_ctx *ctx) reg |=VE_MODE_DEC_H265 ;break ; +case V4L2_PIX_FMT_VP9_FRAME : + reg |=VE_MODE_RAMPD |VE_MODE_H616_VP9_RESERVED | +VE_MODE_DEC_H265 ; +break ; +default :return -EINVAL ; }
@@ -81,6 +86,21 @@ void cedrus_engine_disable(struct cedrus_dev *dev)cedrus_write (dev,VE_MODE ,VE_MODE_DISABLED ); } +void cedrus_engine_reset (struct cedrus_dev *dev) +{ +u32 reg; + +readl_poll_timeout_atomic (dev->base +VE_RESET , reg, + reg &VE_RESET_SYNC_IDLE ,1 ,1000 ); + + reg =cedrus_read (dev,VE_RESET ); +cedrus_write (dev,VE_RESET , + reg |VE_RESET_DEC |VE_RESET_DEC_REQ_MASK ); +cedrus_read (dev,VE_RESET ); +cedrus_write (dev,VE_RESET , + reg & ~(VE_RESET_DEC |VE_RESET_DEC_REQ_MASK )); +} +void cedrus_dst_format_set (struct cedrus_dev *dev,struct v4l2_pix_format *fmt) {
drivers/staging/media/sunxi/cedrus/cedrus_hw.h +1 -0
@@ -18,6 +18,7 @@int cedrus_engine_enable (struct cedrus_ctx *ctx);void cedrus_engine_disable (struct cedrus_dev *dev); +void cedrus_engine_reset (struct cedrus_dev *dev);void cedrus_dst_format_set (struct cedrus_dev *dev,struct v4l2_pix_format *fmt);
drivers/staging/media/sunxi/cedrus/cedrus_regs.h +131 -0
147 lines not on this page · raw message
drivers/staging/media/sunxi/cedrus/cedrus_video.c +31 -0
@@ -50,6 +50,11 @@ static struct cedrus_format cedrus_formats[] = { .directions = CEDRUS_DECODE_SRC, .capabilities = CEDRUS_CAPABILITY_VP8_DEC, }, + { + .pixelformat = V4L2_PIX_FMT_VP9_FRAME, + .directions = CEDRUS_DECODE_SRC, + .capabilities = CEDRUS_CAPABILITY_VP9_DEC, + }, { .pixelformat = V4L2_PIX_FMT_NV12, .directions = CEDRUS_DECODE_DST,
@@ -86,6 +91,12 @@ static bool cedrus_check_format(struct cedrus_ctx *ctx, !(fmt->directions & directions))return false; +/* The 10-bit VP9 2-bit plane would overlap the tiled chroma plane. */ +if (ctx->src_fmt.pixelformat ==V4L2_PIX_FMT_VP9_FRAME && + ctx->bit_depth >8 && + fmt->pixelformat ==V4L2_PIX_FMT_NV12_32L32 ) +return false; +return true; }
@@ -133,10 +144,14 @@ void cedrus_prepare_format(struct v4l2_pix_format *pix_fmt)case V4L2_PIX_FMT_H264_SLICE :case V4L2_PIX_FMT_HEVC_SLICE :case V4L2_PIX_FMT_VP8_FRAME : +case V4L2_PIX_FMT_VP9_FRAME :/* Zero bytes per line for encoded source. */ bytesperline =0 ;/* Choose some minimum size since this can't be 0 */ sizeimage =max_t (u32,SZ_1K , sizeimage); +/* 1 KiB end address granularity, rounding up could wrap. */ +if (pix_fmt->pixelformat ==V4L2_PIX_FMT_VP9_FRAME ) + sizeimage =ALIGN_DOWN (sizeimage,SZ_1K );break ;case V4L2_PIX_FMT_NV12_32L32 :
@@ -265,6 +280,19 @@ static int cedrus_try_fmt_vid_cap_p(struct cedrus_ctx *ctx, pix_fmt->height = ctx->src_fmt.height;cedrus_prepare_format (pix_fmt); +/* See cedrus_vp9_stride_align(). */ +if (ctx->src_fmt.pixelformat ==V4L2_PIX_FMT_VP9_FRAME && + (pix_fmt->pixelformat ==V4L2_PIX_FMT_NV12 || + pix_fmt->pixelformat ==V4L2_PIX_FMT_NV21 || +cedrus_vp9_is_planar (pix_fmt->pixelformat))) { +if (cedrus_vp9_is_planar (pix_fmt->pixelformat)) + pix_fmt->height =ALIGN (ctx->src_fmt.height,8 ); + pix_fmt->bytesperline = +ALIGN (pix_fmt->width, +cedrus_vp9_stride_align (pix_fmt->pixelformat)); + pix_fmt->sizeimage = pix_fmt->bytesperline * pix_fmt->height *3 /2 ; + } +if (ctx->current_codec->extra_cap_size) pix_fmt->sizeimage += ctx->current_codec->extra_cap_size (ctx, pix_fmt);
@@ -365,6 +393,9 @@ static int cedrus_s_fmt_vid_out_p(struct cedrus_ctx *ctx,case V4L2_PIX_FMT_VP8_FRAME : ctx->current_codec = &cedrus_dec_ops_vp8;break ; +case V4L2_PIX_FMT_VP9_FRAME : + ctx->current_codec = &cedrus_dec_ops_vp9; +break ; }/* Propagate format information to capture. */
drivers/staging/media/sunxi/cedrus/cedrus_vp9.c new file +1253 -0
1,253 lines not on this page · raw message
Signature · 1 line
2.43.0