The H.264 decoder outputs wrong luma until the second IDR picture of a stream. Chroma is correct. The top-left macroblocks of the first IDR picture hold garbage that is different on each run. Intra prediction spreads the error over the picture, and inter prediction carries it to the following pictures. vdec_1_start() resets the VDEC1 blocks with DOS_SW_RESET0 before it powers on the VDEC memories with DOS_MEM_PD_VDEC. The VLD then starts in an undefined state. The vendor driver resets the VLD, IQIDCT and MC again in vh264_prot_init(), after the memories are on. This driver does not. Reset the VLD (DOS_SW_RESET0 bit 4) in codec_h264_start(). The VLD reset alone fixes the corruption. The other resets that the vendor driver does (IQIDCT, MC, DBLK, PIC_DC) make no difference. On G12A, every decode session is affected. On GXBB, only the first session after power-on is affected. Fixes: d7647e7c90f5 ("media: meson: vdec: add H.264 decoding support") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: John O'Callaghan --- How this patch was made: the bug was found and the fix written with an LLM coding assistant (Claude Code). I reviewed the fix and ran every test below on my boards. checkpatch is clean; W=1 and sparse give no new warnings. Users see this bug in normal playback. On G12A, every H.264 video plays with the wrong brightness until the second IDR picture: the first 8 seconds of my test clip, with a band 72 levels too bright on the left. Tested with H.264 High profile clips (1080p and 720p, 600 frames, IDR every 250 frames), GStreamer 1.26 (v4l2h264dec) and FFmpeg 7.1 (h264_v4l2m2m). Every decoded frame was compared by MD5 with the FFmpeg software decoder. Radxa Zero (S905Y2, G12A), Armbian kernels 6.18.45 and 7.3, staging vdec with Armbian's patches: - before: frames 0-249 wrong in every run (10 of 10) - after: all 600 frames bit-exact (32 of 32 runs) Odroid C2 (S905, GXBB), Armbian kernel 6.18.44: - before: frames 0-249 wrong in the first decode after power-on, later decodes bit-exact - after: bit-exact, including the first decode after power-on Odroid C2, plain v7.3 (no out-of-tree vdec patches), GStreamer: - before: frames 0-249 wrong in the first decode after power-on - after: bit-exact. Two GStreamer starts failed first with the known poll() start race, so the decoder had already run before this decode. (v7.3 also drops the second-to-last frame at the end of the stream. That is a separate bug and is not addressed here.) The DOS_SW_RESET0 bits were tested one at a time: only bit 4 (VLD) changes the result. Not tested: GXL, GXLX, GXM, SM1, interlaced streams, 4K. On G12A the tests ran on Armbian kernels; their vdec patches do not touch codec_h264_start(). The same fix is in Armbian: https://github.com/armbian/build/pull/11098 drivers/staging/media/meson/vdec/codec_h264.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/staging/media/meson/vdec/codec_h264.c b/drivers/staging/media/meson/vdec/codec_h264.c index a6074de15..497fbada6 100644 --- a/drivers/staging/media/meson/vdec/codec_h264.c +++ b/drivers/staging/media/meson/vdec/codec_h264.c @@ -182,6 +182,14 @@ static int codec_h264_start(struct amvdec_session *sess) if (!h264->sei_vaddr) return -ENOMEM; + /* + * vdec_1_start() resets the VLD before the VDEC memories are powered + * on. Reset it again, or the luma of the first pictures is corrupt. + */ + amvdec_write_dos(core, DOS_SW_RESET0, BIT(4)); + amvdec_write_dos(core, DOS_SW_RESET0, 0); + amvdec_read_dos(core, DOS_SW_RESET0); + amvdec_write_dos_bits(core, POWER_CTL_VLD, BIT(9) | BIT(6)); workspace_offset = h264->workspace_paddr - WORKSPACE_BUF_OFFSET; -- 2.50.1