Add lock to new Clear() method to prevent crashes

This commit is contained in:
Jonathan Thomas
2022-10-06 21:59:11 -05:00
parent 934ca786ed
commit 32a89cfce9
2 changed files with 10 additions and 7 deletions

View File

@@ -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<std::recursive_mutex> lock(processingMutex);
// Initialize format context
pFormatCtx = NULL;
{
@@ -2035,9 +2038,6 @@ std::shared_ptr<Frame> FFmpegReader::CreateFrame(int64_t requested_frame) {
std::shared_ptr<Frame> output = working_cache.GetFrame(requested_frame);
if (!output) {
// Lock
const std::lock_guard<std::recursive_mutex> lock(processingMutex);
// (re-)Check working cache
output = working_cache.GetFrame(requested_frame);
if(output) return output;

View File

@@ -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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> lock(getFrameMutex);
// Close timeline before we do anything (this closes all clips)
bool was_open = is_open;
Close();