Skip to content

decoder: Clear the mismatch control flag in MPEG-1 inverse quantization - #39

Merged
harishdm merged 1 commit into
ittiam-systems:mainfrom
GeekQAQ:mpeg1-last-value-one
Nov 20, 2026
Merged

harishdm merged 1 commit into
ittiam-systems:mainfrom
GeekQAQ:mpeg1-last-value-one

Conversation

@GeekQAQ

@GeekQAQ GeekQAQ commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

The I, P and B picture reconstruction selects the IDCT with pf_idct_recon[idx * 2 + i4_last_value_one]. impeg2d_vld_inv_quant_mpeg2() sets i4_last_value_one for every block (mismatch control), but impeg2d_vld_inv_quant_mpeg1() never touches it, and neither IVD_CMD_CTL_RESET nor the MPEG-1 initialization clears it. A new decoder has it at 0.

So when the last block of an MPEG-2 stream leaves it at 1, an MPEG-1 stream decoded after a reset is reconstructed with the mismatch control IDCT: in our test, 5 of the 8 output pictures of an MPEG-1 stream differed from those of a new decoder.

MPEG-1 has no mismatch control, so this change sets the flag to 0 in impeg2d_vld_inv_quant_mpeg1().

Tested on main (275c536) with clang 21 and AddressSanitizer: after an interlaced MPEG-2 stream and a reset, the MPEG-1 stream now decodes to the same pictures as on a new decoder. The program and the streams are in this gist: https://gist.github.com/GeekQAQ/733c6bb6a114008b275e9246a6d2329d The default CMake build (Release, gcc and clang) has no new warnings, and mpeg2dec gives byte-identical output before and after the change on 16 short test streams with 1 core, and with 4 cores except for a stream that starts with a B picture, whose 4-core output already varies from run to run on main (a separate issue, sent as its own PR).

The I, P and B picture reconstruction selects the IDCT with
pf_idct_recon[idx * 2 + i4_last_value_one]. impeg2d_vld_inv_quant_mpeg2()
sets i4_last_value_one for every block, but
impeg2d_vld_inv_quant_mpeg1() never touches it, and neither
IVD_CMD_CTL_RESET nor the MPEG-1 initialization clears it. After an
MPEG-2 stream whose last block left it at 1, an MPEG-1 stream decoded
after a reset was reconstructed with the mismatch control IDCT, and its
pictures differed from those of a new decoder.

MPEG-1 has no mismatch control, so set the flag to 0 in
impeg2d_vld_inv_quant_mpeg1().
Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

@harishdm
harishdm merged commit 0e733da into ittiam-systems:main Nov 20, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants