Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoFrameExtractor: Fix race condition in synchronous extraction mode #1390

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Tereius
Copy link

@Tereius Tereius commented Oct 24, 2021

There is a race condition between the ExtractThread running p->releaseResourceInternal() (and unloading the demuxer) and the main thread calling extract() and loading the demuxer inside checkAndOpen() if run in synchronous extraction mode.

// Run in main thread
auto mpExtractor = new QtAV::VideoFrameExtractor();
mpExtractor->setAsync(false);
mpExtractor->setSource("file://whatever.mp4"); // This call will unnecessarily start the ExtractThread which will unload the demuxer in p->releaseResourceInternal()
mpExtractor->setPosition(0);
mpExtractor->extract(); // The frame extraction is only successful if the demuxer is loaded. Racing happens because the ExtractThread simultaneously unloads the demuxer while the main thread loads the demuxer in checkAndOpen()

The solution is not to start the ExtractThread at all if async equals false.

…tract() in synchronous extraction mode (async equals false).

Only start ExtractionThread if it is necessary (async equals true).
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.

1 participant