Repository navigation
Conversation
When a P picture has no forward reference or a B picture has no references (a stream starting with a B picture, the leading B pictures of an open GOP, the first P picture after a reset, corrupted data), impeg2d_pre_pic_dec_proc() uses the current picture buffer as the reference. With more than one core, impeg2d_dec_pic_data() then decodes the slices of that picture on several threads at once, and motion compensation in one thread reads rows of the picture that another thread is writing. The output depends on thread scheduling, and ThreadSanitizer reports data races between impeg2_mc_*_sse42 writes and reads. Decode such a picture on the calling thread only.
There was a problem hiding this comment.
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.
Member
|
The scenario described above is an error case and decoder output is not guaranteed to produce same output in each run. Given this, can we close this PR? |
Contributor
Author
|
Thank you for the explanation, that makes sense. I'm fine with closing this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a P picture has no forward reference or a B picture has no references (a stream starting with a B picture, the leading B pictures of an open GOP, the first P picture after a reset, corrupted data),
impeg2d_pre_pic_dec_proc()uses the current picture buffer as the reference. With more than one core,impeg2d_dec_pic_data()decodes the slices of that picture on several threads at once, so motion compensation in one thread reads rows of the picture that another thread is writing. The output then depends on thread scheduling: decoding the same stream that starts with a B picture 50 times with 4 cores gave 4 to 6 different outputs (always 1 with 1 core), and ThreadSanitizer reports data races between theimpeg2_mc_*_sse42writes and reads.This change decodes such a picture on the calling thread only. Both loops (thread start and wait) use the reduced count, so it also works with
u4_keep_threads_active= 1.Tested on
main(275c536) with clang 21, withu4_keep_threads_active0 and 1: with 4 cores the 50 decodes now give a single output, and ThreadSanitizer reports no races (before: 4 to 6 outputs, 15 to 35 race reports). The program and the streams are in this gist: https://gist.github.com/GeekQAQ/5ed01c5783f91f35cdf4c74d964cb269 The default CMake build (Release, gcc and clang) has no new warnings.mpeg2dec --num_cores 4on the stream that starts with a B picture gave 3 different outputs in 12 runs onmainand the same output in 12 of 12 runs with the change (the 1-core output); on the other 15 short test streamsmpeg2decgives byte-identical output before and after the change with 1 and 4 cores.