Skip to content

Commit 761402d

Browse files
authored
Merge pull request #337 from ferdnyc/create-frame-lock
Add lock to CreateFrame
2 parents c2ac8eb + 1435267 commit 761402d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/FFmpegReader.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,7 +2002,15 @@ AudioLocation FFmpegReader::GetAudioPTSLocation(int64_t pts) {
20022002
std::shared_ptr<Frame> FFmpegReader::CreateFrame(int64_t requested_frame) {
20032003
// Check working cache
20042004
std::shared_ptr<Frame> output = working_cache.GetFrame(requested_frame);
2005+
20052006
if (!output) {
2007+
// Lock
2008+
const GenericScopedLock <CriticalSection> lock(processingCriticalSection);
2009+
2010+
// (re-)Check working cache
2011+
output = working_cache.GetFrame(requested_frame);
2012+
if(output) return output;
2013+
20062014
// Create a new frame on the working cache
20072015
output = std::make_shared<Frame>(requested_frame, info.width, info.height, "#000000", Frame::GetSamplesPerFrame(requested_frame, info.fps, info.sample_rate, info.channels), info.channels);
20082016
output->SetPixelRatio(info.pixel_ratio.num, info.pixel_ratio.den); // update pixel ratio
@@ -2015,8 +2023,7 @@ std::shared_ptr<Frame> FFmpegReader::CreateFrame(int64_t requested_frame) {
20152023
if (requested_frame > largest_frame_processed)
20162024
largest_frame_processed = requested_frame;
20172025
}
2018-
2019-
// Return new frame
2026+
// Return frame
20202027
return output;
20212028
}
20222029

0 commit comments

Comments
 (0)