fixed bug where scrubbed frames would be cached but not committed to the hashmap

This commit is contained in:
itsmattkc
2020-01-17 18:13:49 +11:00
parent 3c139b8274
commit e6b45c75c3
4 changed files with 44 additions and 41 deletions
+15 -16
View File
@@ -48,9 +48,13 @@ bool TimeRange::operator==(const TimeRange &r) const
return in() == r.in() && out() == r.out();
}
bool TimeRange::OverlapsWith(const TimeRange &a) const
bool TimeRange::OverlapsWith(const TimeRange &a, bool in_inclusive, bool out_inclusive) const
{
return Overlap(a, *this);
bool overlaps_in = (in_inclusive) ? (a.out() < in()) : (a.out() <= in());
bool overlaps_out = (out_inclusive) ? (a.in() > out()) : (a.in() >= out());
return !(overlaps_in || overlaps_out);
}
TimeRange TimeRange::CombineWith(const TimeRange &a) const
@@ -58,18 +62,13 @@ TimeRange TimeRange::CombineWith(const TimeRange &a) const
return Combine(a, *this);
}
bool TimeRange::Contains(const TimeRange &compare, bool inout_inclusive) const
bool TimeRange::Contains(const TimeRange &compare, bool in_inclusive, bool out_inclusive) const
{
if (inout_inclusive) {
return (compare.in() >= in() && compare.out() <= out());
} else {
return (compare.in() > in() && compare.out() < out());
}
}
bool contains_in = (in_inclusive) ? (compare.in() >= in()) : (compare.in() > in());
bool TimeRange::Overlap(const TimeRange &a, const TimeRange &b)
{
return !(a.out() < b.in() || a.in() > b.out());
bool contains_out = (out_inclusive) ? (compare.out() <= out()) : (compare.out() < out());
return contains_in && contains_out;
}
TimeRange TimeRange::Combine(const TimeRange &a, const TimeRange &b)
@@ -100,7 +99,7 @@ void TimeRangeList::InsertTimeRange(const TimeRange &range)
for (int i=0;i<size();i++) {
const TimeRange& compare = at(i);
if (TimeRange::Overlap(range, compare)) {
if (range.OverlapsWith(compare)) {
replace(i, TimeRange::Combine(range, compare));
return;
}
@@ -118,7 +117,7 @@ void TimeRangeList::RemoveTimeRange(const TimeRange &range)
// This element is entirely encompassed in this range, remove it
removeAt(i);
i--;
} else if (compare.Contains(range, false)) {
} else if (compare.Contains(range, false, false)) {
// The remove range is within this element, only choice is to split the element into two
TimeRange first(compare.in(), range.in());
TimeRange last(range.out(), compare.out());
@@ -139,10 +138,10 @@ void TimeRangeList::RemoveTimeRange(const TimeRange &range)
}
}
bool TimeRangeList::ContainsTimeRange(const TimeRange &range) const
bool TimeRangeList::ContainsTimeRange(const TimeRange &range, bool in_inclusive, bool out_inclusive) const
{
for (int i=0;i<size();i++) {
if (at(i).Contains(range)) {
if (at(i).Contains(range, in_inclusive, out_inclusive)) {
return true;
}
}
+5 -5
View File
@@ -18,11 +18,10 @@ public:
bool operator==(const TimeRange& r) const;
bool OverlapsWith(const TimeRange& a) const;
TimeRange CombineWith(const TimeRange& a) const;
bool Contains(const TimeRange& a, bool inout_inclusive = true) const;
bool OverlapsWith(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const;
bool Contains(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const;
static bool Overlap(const TimeRange& a, const TimeRange& b);
TimeRange CombineWith(const TimeRange& a) const;
static TimeRange Combine(const TimeRange &a, const TimeRange &b);
private:
@@ -31,6 +30,7 @@ private:
rational in_;
rational out_;
rational length_;
};
uint qHash(const TimeRange& r, uint seed);
@@ -43,7 +43,7 @@ public:
void RemoveTimeRange(const TimeRange& range);
bool ContainsTimeRange(const TimeRange& range) const;
bool ContainsTimeRange(const TimeRange& range, bool in_inclusive = true, bool out_inclusive = true) const;
TimeRangeList Intersects(const TimeRange& range);
+20 -18
View File
@@ -237,20 +237,30 @@ TimeRange VideoRenderBackend::PopNextFrameFromQueue()
for (int i=0;i<cache_queue_.size();i++) {
const TimeRange& range_here = cache_queue_.at(i);
if (range_here.Contains(test_range)) {
if (range_here.OverlapsWith(test_range, false, false)) {
closest_time = -1;
break;
}
rational compare_in = range_here.in();
rational compare_out = range_here.out() - params_.time_base();
for (int i=0;i<2;i++) {
rational compare;
if (closest_time < 0 || qAbs(compare_in - last_time_requested_) < qAbs(closest_time - last_time_requested_)) {
closest_time = compare_in;
}
if (i == 0) {
compare = Timecode::snap_time_to_timebase(range_here.in(), params_.time_base());
if (compare > range_here.in()) {
compare -= params_.time_base();
}
} else {
compare = Timecode::snap_time_to_timebase(range_here.out(), params_.time_base());
if (compare >= range_here.out()) {
compare -= params_.time_base();
}
}
if (closest_time < 0 || qAbs(compare_out - last_time_requested_) < qAbs(closest_time - last_time_requested_)) {
closest_time = compare_out;
if (closest_time < 0
|| qAbs(compare - last_time_requested_) < qAbs(closest_time - last_time_requested_)) {
closest_time = compare;
}
}
}
@@ -259,15 +269,7 @@ TimeRange VideoRenderBackend::PopNextFrameFromQueue()
if (closest_time == -1) {
frame_range = test_range;
} else {
// Snap the range to a single discrete frame
rational snapped_in = Timecode::snap_time_to_timebase(closest_time, params_.time_base());
// Check if the range starts earlier, in which case we should render that frame instead
if (closest_time < snapped_in) {
frame_range = TimeRange(snapped_in - params_.time_base(), snapped_in);
} else {
frame_range = TimeRange(snapped_in, snapped_in + params_.time_base());
}
frame_range = TimeRange(closest_time, closest_time + params_.time_base());
}
// Remove this particular frame from the queue
@@ -372,7 +374,7 @@ void VideoRenderBackend::FrameRemovedFromDiskCache(const QByteArray &hash)
bool VideoRenderBackend::TimeIsQueued(const TimeRange &time) const
{
return cache_queue_.ContainsTimeRange(time);
return cache_queue_.ContainsTimeRange(time, true, false);
}
bool VideoRenderBackend::JobIsCurrent(const NodeDependency &dep, const qint64& job_time) const
+4 -2
View File
@@ -415,15 +415,17 @@ void ViewerWidget::PlaybackTimerUpdate()
void ViewerWidget::RendererCachedFrame(const rational &time, QVariant value, qint64 job_time)
{
if (GetTime() == time) {
SetTexture(value.value<OpenGLTexturePtr>());
frame_cache_job_time_ = job_time;
SetTexture(value.value<OpenGLTexturePtr>());
}
}
void ViewerWidget::RendererCachedTime(const rational &time, qint64 job_time)
{
if (GetTime() == time && job_time > frame_cache_job_time_) {
frame_cache_job_time_ = job_time;
UpdateTextureFromNode(GetTime());
}
}