diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 84bbf853..5f54e5d7 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -486,7 +486,7 @@ tr1::shared_ptr FFmpegReader::ReadStream(long int requested_frame) // Minimum number of packets to process (for performance reasons) int packets_processed = 0; int minimum_packets = OPEN_MP_NUM_PROCESSORS; - int max_packets = 1024; + int max_packets = 4096; // Set the number of threads in OpenMP omp_set_num_threads(OPEN_MP_NUM_PROCESSORS); diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 9b77f2c6..028610af 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -631,10 +631,6 @@ bool Timeline::isEqual(double a, double b) // Get an openshot::Frame object for a specific frame number of this reader. tr1::shared_ptr Timeline::GetFrame(long int requested_frame) throw(ReaderClosed, OutOfBoundsFrame) { - // Check for open reader (or throw exception) - if (!is_open) - throw ReaderClosed("The Timeline is closed. Call Open() before calling this method.", ""); - // Adjust out of bounds frame number if (requested_frame < 1) requested_frame = 1; @@ -653,6 +649,10 @@ tr1::shared_ptr Timeline::GetFrame(long int requested_frame) throw(Reader // Create a scoped lock, allowing only a single thread to run the following code at one time const GenericScopedLock lock(getFrameCriticalSection); + // Check for open reader (or throw exception) + if (!is_open) + throw ReaderClosed("The Timeline is closed. Call Open() before calling this method.", ""); + // Check cache again (due to locking) frame = final_cache->GetFrame(requested_frame); if (frame) { @@ -904,6 +904,9 @@ Json::Value Timeline::JsonValue() { // Load JSON string into this object void Timeline::SetJson(string value) throw(InvalidJSON) { + // Get lock (prevent getting frames while this happens) + const GenericScopedLock lock(getFrameCriticalSection); + // Parse JSON string into JSON objects Json::Value root; Json::Reader reader; @@ -928,6 +931,7 @@ void Timeline::SetJson(string value) throw(InvalidJSON) { void Timeline::SetJsonValue(Json::Value root) throw(InvalidFile, ReaderClosed) { // Close timeline before we do anything (this also removes all open and closing clips) + bool was_open = is_open; Close(); // Set parent data @@ -983,6 +987,10 @@ void Timeline::SetJsonValue(Json::Value root) throw(InvalidFile, ReaderClosed) { info.duration = root["duration"].asDouble(); info.video_length = info.fps.ToFloat() * info.duration; } + + // Re-open if needed + if (was_open) + Open(); } // Apply a special formatted JSON object, which represents a change to the timeline (insert, update, delete)