diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index cba25cf7..ba3718e7 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -206,6 +206,9 @@ int FFmpegReader::IsHardwareDecodeSupported(int codecid) void FFmpegReader::Open() { // Open reader if not already open if (!is_open) { + // Prevent calls to GetFrame when Closing + const std::lock_guard lock(processingMutex); + // Initialize format context pFormatCtx = NULL; { @@ -2035,9 +2038,6 @@ std::shared_ptr FFmpegReader::CreateFrame(int64_t requested_frame) { std::shared_ptr output = working_cache.GetFrame(requested_frame); if (!output) { - // Lock - const std::lock_guard lock(processingMutex); - // (re-)Check working cache output = working_cache.GetFrame(requested_frame); if(output) return output; diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 52e8af3f..71253f48 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -772,7 +772,10 @@ void Timeline::sort_effects() void Timeline::Clear() { ZmqLogger::Instance()->AppendDebugMethod("Timeline::Clear"); - + + // Get lock (prevent getting frames while this happens) + const std::lock_guard guard(getFrameMutex); + // Close all open clips for (auto clip : clips) { @@ -1100,9 +1103,6 @@ Json::Value Timeline::JsonValue() const { // Load JSON string into this object void Timeline::SetJson(const std::string value) { - // Get lock (prevent getting frames while this happens) - const std::lock_guard lock(getFrameMutex); - // Parse JSON string into JSON objects try { @@ -1120,6 +1120,9 @@ void Timeline::SetJson(const std::string value) { // Load Json::Value into this object void Timeline::SetJsonValue(const Json::Value root) { + // Get lock (prevent getting frames while this happens) + const std::lock_guard lock(getFrameMutex); + // Close timeline before we do anything (this closes all clips) bool was_open = is_open; Close();