From e08ff749d9136e3a796b2399a66540055dc3f8bf Mon Sep 17 00:00:00 2001 From: Naeem Malik <104218167+malik-na@users.noreply.github.com> Date: Sun, 22 Nov 2026 12:11:46 +0530 Subject: [PATCH] media: apple: avd: decode VP9 frames smaller than 64x64 on the legacy transport validate_dec_params() refuses every VP9 frame narrower or shorter than 64 pixels, and requires the frame size, aligned to 64x16, to equal the CAPTURE format. The CAPTURE format is never smaller than the 64x64 minimum of the VP9 frame size range, so a frame below 64 in either dimension could not pass either check. Such a stream fails its first frame ("unexpected bitstream resolution") and stops. The 64-pixel floor came from rkvdec; H.264, HEVC and AV1 frames as small as 16x16 already decode on this decoder. Raise the aligned frame size to the 64x64 minimum before comparing it with the CAPTURE format, as the CAPTURE format is. A frame larger than the CAPTURE format is still refused. Drop the floor on the legacy transport only, where it was measured. The firmware transports (queued firmware, Apple firmware) keep it until sub-64 frames are measured there: an input their firmware does not expect can reset the engine instead of failing the frame. Add avd_backend_is_open() for that check. Tested on a J516c (M3 Max, T6031, legacy transport). Of the 64 libvpx vp90-2-02-size-WxH conformance vectors (8 to 66 pixels), 4 decoded before (those 64 or larger in both dimensions) and all 64 now match FFmpeg's software decode, which matches the libvpx MD5s. H.264, HEVC, VP9 and AV1 at other sizes and throughput are unchanged. The VP9 host test now checks that a 32x16 frame into a 64x64 CAPTURE format is refused on the firmware transport, decodes on the legacy transport, and that a larger frame is still refused there. Signed-off-by: Naeem Malik <104218167+malik-na@users.noreply.github.com> --- .../platform/apple/avd/avd-backend-open.c | 5 +++++ drivers/media/platform/apple/avd/avd-vp9.c | 21 +++++++++++++++---- drivers/media/platform/apple/avd/avd.h | 1 + .../platform/apple/avd/tests/vp9-test.py | 15 +++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/apple/avd/avd-backend-open.c b/drivers/media/platform/apple/avd/avd-backend-open.c index d2054d06f948b..525c7848b4edc 100644 --- a/drivers/media/platform/apple/avd/avd-backend-open.c +++ b/drivers/media/platform/apple/avd/avd-backend-open.c @@ -177,6 +177,11 @@ static irqreturn_t avd_open_irq(struct avd_dev *avd) return IRQ_HANDLED; } +bool avd_backend_is_open(const struct avd_dev *avd) +{ + return avd->backend == &avd_open_backend; +} + const struct avd_backend_ops avd_open_backend = { .name = "open-compat", .boot = avd_boot, diff --git a/drivers/media/platform/apple/avd/avd-vp9.c b/drivers/media/platform/apple/avd/avd-vp9.c index bf2d8b80854e6..a596b420ac2c7 100644 --- a/drivers/media/platform/apple/avd/avd-vp9.c +++ b/drivers/media/platform/apple/avd/avd-vp9.c @@ -670,12 +670,25 @@ static int validate_dec_params(struct avd_ctx *ctx, { unsigned int aligned_width, aligned_height; - if (dec_params->frame_height_minus_1 + 1 < 64 || - dec_params->frame_width_minus_1 + 1 < 64) + /* + * The CAPTURE format is at least 64x64, the minimum of the VP9 frame + * size range, so a smaller frame is decoded into a 64x64 buffer, as + * H.264, HEVC and AV1 frames are. That is measured on the legacy + * transport only. The firmware transports keep the 64-pixel floor + * until it is measured there: an input their firmware does not + * expect can reset the engine instead of failing the frame. + */ + if (!avd_backend_is_open(ctx->dev) && + (dec_params->frame_width_minus_1 + 1 < 64 || + dec_params->frame_height_minus_1 + 1 < 64)) return -EINVAL; - aligned_width = round_up(dec_params->frame_width_minus_1 + 1, 64); - aligned_height = round_up(dec_params->frame_height_minus_1 + 1, 16); + aligned_width = max_t(unsigned int, + round_up(dec_params->frame_width_minus_1 + 1, 64), + 64); + aligned_height = max_t(unsigned int, + round_up(dec_params->frame_height_minus_1 + 1, 16), + 64); /* * Userspace should update the capture/decoded format when the diff --git a/drivers/media/platform/apple/avd/avd.h b/drivers/media/platform/apple/avd/avd.h index 568cbfc6d06f8..85f75303cf3b9 100644 --- a/drivers/media/platform/apple/avd/avd.h +++ b/drivers/media/platform/apple/avd/avd.h @@ -418,6 +418,7 @@ void avd_qfw_select(struct avd_dev *avd); void avd_qfw_prepare_boot(struct avd_dev *avd); void avd_qfw_debug(struct avd_dev *avd, struct avd_frame *f, const char *where); bool avd_backend_is_qfw(const struct avd_dev *avd); +bool avd_backend_is_open(const struct avd_dev *avd); bool avd_qfw_has_vp_done(const struct avd_dev *avd); unsigned int avd_qfw_picture_banks(const struct avd_dev *avd, unsigned int codec); int avd_backend_select(struct avd_dev *avd); diff --git a/drivers/media/platform/apple/avd/tests/vp9-test.py b/drivers/media/platform/apple/avd/tests/vp9-test.py index 7c60bbb168843..083c06e095a1f 100644 --- a/drivers/media/platform/apple/avd/tests/vp9-test.py +++ b/drivers/media/platform/apple/avd/tests/vp9-test.py @@ -62,6 +62,7 @@ #define kfree free static bool vp_feature = true; static bool avd_qfw_has_vp_done(const struct avd_dev *d) { return d->queued && vp_feature; } +static bool avd_backend_is_open(const struct avd_dev *d) { return !d->queued; } static void *vb2_plane_vaddr(struct vb2_buffer *b,int p) { (void)p;return b->cpu; } static size_t vb2_get_plane_payload(struct vb2_buffer *b,int p) { (void)p;return b->payload; } static struct vb2_v4l2_buffer *current_src,*current_dst; @@ -208,12 +209,26 @@ def without_includes(s): assert(p->bank[0].busy&&p->bank[1].busy); avd_vp9_done(&ctx,&src,&dst[0].base.vb,VB2_BUF_STATE_DONE);avd_vp9_done(&ctx,&src,&dst[1].base.vb,VB2_BUF_STATE_DONE); } + /* The firmware transport keeps the 64-pixel floor. */ + ctx.decoded_fmt.fmt.pix_mp.width=64;ctx.decoded_fmt.fmt.pix_mp.height=64; + ctx.decoded_fmt.fmt.pix_mp.plane_fmt[0].bytesperline=64; + params=(struct v4l2_ctrl_vp9_frame){.flags=V4L2_VP9_FRAME_FLAG_KEY_FRAME|V4L2_VP9_FRAME_FLAG_SHOW_FRAME, + .frame_width_minus_1=31,.frame_height_minus_1=15,.bit_depth=8}; + current_dst=&dst[0].base.vb;frame.idx=0;assert(avd_vp9_run(&ctx)==-EINVAL); avd_vp9_stop(&ctx);assert(!avd_vp9_ready(&ctx)); /* Old firmware and the legacy transport allocate only one bank. */ for(unsigned int mode=0;mode<2;mode++) { dev.queued=mode;vp_feature=false;assert(!avd_vp9_start(&ctx));p=ctx.priv; assert(p->nbanks==1&&ctx.max_frames==1);avd_vp9_stop(&ctx); } + /* On the legacy transport a frame below 64x64 decodes into a 64x64 CAPTURE buffer. */ + dev.queued=false;vp_feature=false;assert(!avd_vp9_start(&ctx));p=ctx.priv; + current_dst=&dst[0].base.vb;frame.idx=0;assert(!avd_vp9_run(&ctx)); + avd_vp9_done(&ctx,&src,&dst[0].base.vb,VB2_BUF_STATE_DONE); + /* A frame larger than the CAPTURE format is still refused. */ + params.frame_width_minus_1=1919;params.frame_height_minus_1=1087; + assert(avd_vp9_run(&ctx)==-EINVAL); + avd_vp9_stop(&ctx); dev.queued=true;vp_feature=true;fail_alloc_after=13;allocating_ctx=&ctx; assert(avd_vp9_start(&ctx)==-ENOMEM);allocating_ctx=NULL; assert(!ctx.priv&&!avd_vp9_ready(&ctx)&&ctx.max_frames==1);