- Protect AddClip(), RemoveClip(), update_open_clips(), sort_clips(), sort_effects() methods with mutex, making them thread safe

- Refactor sorting of clips & effects, and only sort these arrays when the arrays change (instead of each call to GetFrame)
- Cache max timeline duration, and make Timeline::GetMaxTime() thread safe
- New multi-threaded unit tests, which are designed to verify no seg faults on multi-threaded calls to Timeline::GetFrame(), Timeline::AddClip(), and Timeline::RemoveClip()
- New public Timeline::SortTimeline() method which is called by child Clips automatically, when certain properties are changed
This commit is contained in:
Jonathan Thomas
2022-10-22 22:55:40 -05:00
parent 87e14ba616
commit 389bf33adb
5 changed files with 194 additions and 50 deletions

View File

@@ -11,9 +11,55 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "ClipBase.h"
#include "Timeline.h"
using namespace openshot;
// Set position on timeline (in seconds)
void ClipBase::Position(float value) {
position = value;
if (ParentTimeline()) {
// Resort timeline items (internal clips/effects arrays)
Timeline *parentTimeline = (Timeline *) ParentTimeline();
parentTimeline->SortTimeline();
}
}
// Set layer of clip on timeline (lower number is covered by higher numbers)
void ClipBase::Layer(int value) {
layer = value;
if (ParentTimeline()) {
// Resort timeline items (internal clips/effects arrays)
Timeline *parentTimeline = (Timeline *) ParentTimeline();
parentTimeline->SortTimeline();
}
}
// Set start position (in seconds) of clip (trim start of video)
void ClipBase::Start(float value) {
start = value;
if (ParentTimeline()) {
// Resort timeline items (internal clips/effects arrays)
Timeline *parentTimeline = (Timeline *) ParentTimeline();
parentTimeline->SortTimeline();
}
}
// Set end position (in seconds) of clip (trim end of video)
void ClipBase::End(float value) {
end = value;
if (ParentTimeline()) {
// Resort timeline items (internal clips/effects arrays)
Timeline *parentTimeline = (Timeline *) ParentTimeline();
parentTimeline->SortTimeline();
}
}
// Generate Json::Value for this object
Json::Value ClipBase::JsonValue() const {