/*** Olive - Non-Linear Video Editor Copyright (C) 2019 Olive Team This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #include "playbackcache.h" OLIVE_NAMESPACE_ENTER void PlaybackCache::Invalidate(const TimeRange &r) { QMutexLocker locker(&lock_); NoLockInvalidate(r); locker.unlock(); emit Invalidated(r); } void PlaybackCache::InvalidateAll() { QMutexLocker locker(&lock_); TimeRange invalidate_range(0, length_); NoLockInvalidate(invalidate_range); locker.unlock(); emit Invalidated(invalidate_range); } void PlaybackCache::SetLength(const rational &r) { QMutexLocker locker(&lock_); NoLockSetLength(r); } void PlaybackCache::Shift(const rational &from, const rational &to) { QMutexLocker locker(&lock_); // An region between `from` and `to` will be inserted or spliced out TimeRangeList ranges_to_shift = invalidated_.Intersects(TimeRange(from, RATIONAL_MAX)); // Remove everything from the minimum point invalidated_.RemoveTimeRange(TimeRange(qMin(from, to), RATIONAL_MAX)); // Shift everything in our ranges to shift list // // `diff` is POSITIVE when moving forward -> and NEGATIVE when moving backward <- rational diff = to - from; foreach (const TimeRange& r, ranges_to_shift) { invalidated_.InsertTimeRange(r + diff); } ShiftEvent(from, to); if (diff > rational()) { // If shifting forward, add this section to the invalidated region TimeRange invalidate_range(from, to); NoLockInvalidate(invalidate_range); locker.unlock(); emit Invalidated(invalidate_range); } else { locker.unlock(); } emit Shifted(from, to); } void PlaybackCache::Validate(const TimeRange &r) { QMutexLocker locker(&lock_); NoLockValidate(r); locker.unlock(); emit Validated(r); } void PlaybackCache::NoLockInvalidate(const TimeRange &r) { invalidated_.InsertTimeRange(r); InvalidateEvent(r); } void PlaybackCache::NoLockValidate(const TimeRange &r) { invalidated_.RemoveTimeRange(r); } void PlaybackCache::NoLockSetLength(const rational &r) { if (length_ == r) { // Same length - do nothing return; } if (r > length_) { // If new length is greater, simply extend the invalidated range for now invalidated_.InsertTimeRange(TimeRange(length_, r)); } else { // If new length is smaller, removed hashes invalidated_.RemoveTimeRange(TimeRange(r, length_)); } LengthChangedEvent(length_, r); length_ = r; } void PlaybackCache::LengthChangedEvent(const rational &, const rational &) { } void PlaybackCache::InvalidateEvent(const TimeRange &) { } void PlaybackCache::ShiftEvent(const rational &, const rational &) { } OLIVE_NAMESPACE_EXIT