Skip to content

decoder: Clear recent reference fields on reset - #36

Merged
harishdm merged 1 commit into
ittiam-systems:mainfrom
GeekQAQ:reset-clear-recent-fld
Oct 23, 2026
Merged

harishdm merged 1 commit into
ittiam-systems:mainfrom
GeekQAQ:reset-clear-recent-fld

Conversation

@GeekQAQ

@GeekQAQ GeekQAQ commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

As suggested in the reply to our private report, here is the reset fix as a regular PR.

impeg2d_api_reset() clears aps_ref_pics[] but not as_recent_fld[][]. After IVD_CMD_CTL_RESET, if the next stream starts with a P picture or an open-GOP B picture, impeg2d_pre_pic_dec_proc() fills the missing reference from as_recent_fld, which still points into the previous stream's picture buffers, where a new decoder would use the current picture buffer:

  • with u4_share_disp_buf = 0, the decoded output of the new stream mixes in pixels from the previous stream;
  • with shared display buffers that the application frees and replaces (IVD_CMD_SET_DISPLAY_FRAME) after the reset, motion compensation reads freed memory.

This change clears as_recent_fld in the reset.

Testing on main (e2dbb98), clang 21: a program that decodes a stream, resets, and decodes a stream starting with an open-GOP B picture now gives the same output as a new decoder (it differed before); in the shared-buffer case above, AddressSanitizer reported a heap-use-after-free read before the change and reports nothing after it. The default CMake build has no new warnings.

Left unchanged (happy to follow up if you want any of these):

  • u4_num_frames_decoded is not reset, so after a reset a stream starting with a B picture outputs its first frame one call earlier than on a new decoder. Resetting it would also reset the NUM_FRAMES_LIMIT count.
  • The internal frame buffers are not cleared, so missing slices in the first picture after a reset show the previous stream's pixels instead of the initial grey/black. Clearing them would add a memset of all frame buffers to every reset.
  • Shared display buffers registered before the reset stay registered (examples/decoder/main.c relies on this).

Copilot AI balanced review requested due to automatic review settings October 23, 2026 14:48

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 reached their quota limit.

Comment thread decoder/impeg2d_api_main.c Resolved
impeg2d_api_reset() clears aps_ref_pics[] but keeps as_recent_fld[][],
which still points into the picture buffers of the previous stream.
When the next stream starts with a P picture or an open-GOP B picture,
impeg2d_pre_pic_dec_proc() takes the missing reference from
as_recent_fld instead of the current picture buffer, so the decoded
output mixes in pixels from the previous stream. With shared display
buffers that the application replaced after the reset, the reference
points into freed memory.

Clear as_recent_fld in the reset so that the decoder behaves as a newly
created instance.
@GeekQAQ
GeekQAQ force-pushed the reset-clear-recent-fld branch from 8e69797 to 4493e90 Compare October 23, 2026 15:07
@GeekQAQ
GeekQAQ requested a review from harishdm October 23, 2026 15:15
@harishdm
harishdm merged commit 275c536 into ittiam-systems:main Oct 23, 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