QtAV icon indicating copy to clipboard operation
QtAV copied to clipboard

VideoFrameExtractor: Fix race condition in synchronous extraction mode

Open Tereius opened this issue 4 years ago • 0 comments

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.

Tereius avatar Oct 24 '21 21:10 Tereius