You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Fixing Timeline::SetJSON to use a lock, and reopen the reader if already open. This fixes an issue when trying to open another project while the current project is being accessed (i.e. during playback).
This commit is contained in:
@@ -486,7 +486,7 @@ tr1::shared_ptr<Frame> 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);
|
||||
|
||||
@@ -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<Frame> 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<Frame> 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<CriticalSection> 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<CriticalSection> 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)
|
||||
|
||||
Reference in New Issue
Block a user