timeruler: reworked and improved cache status
This commit is contained in:
@@ -89,10 +89,13 @@ void ViewerOutput::InvalidateCache(const TimeRange &range, NodeInput *from, Node
|
||||
if (from == texture_input_ || from == samples_input_) {
|
||||
emit GraphChangedFrom(source);
|
||||
|
||||
TimeRange invalidated_range(qMax(rational(), range.in()),
|
||||
qMin(GetLength(), range.out()));
|
||||
|
||||
if (from == texture_input_) {
|
||||
video_frame_cache_.Invalidate(range);
|
||||
video_frame_cache_.Invalidate(invalidated_range);
|
||||
} else {
|
||||
audio_playback_cache_.Invalidate(range);
|
||||
audio_playback_cache_.Invalidate(invalidated_range);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,10 +45,10 @@ void PlaybackCache::SetLength(const rational &r)
|
||||
|
||||
if (r > length_) {
|
||||
// If new length is greater, simply extend the invalidated range for now
|
||||
invalidated_.InsertTimeRange(TimeRange(r, length_));
|
||||
invalidated_.InsertTimeRange(TimeRange(length_, r));
|
||||
} else {
|
||||
// If new length is smaller, removed hashes
|
||||
invalidated_.RemoveTimeRange(TimeRange(length_, r));
|
||||
invalidated_.RemoveTimeRange(TimeRange(r, length_));
|
||||
}
|
||||
|
||||
LengthChangedEvent(length_, r);
|
||||
|
||||
@@ -35,6 +35,11 @@ public:
|
||||
|
||||
void Invalidate(const TimeRange& r);
|
||||
|
||||
const rational& GetLength() const
|
||||
{
|
||||
return length_;
|
||||
}
|
||||
|
||||
void SetLength(const rational& r);
|
||||
|
||||
bool IsFullyValidated() const;
|
||||
|
||||
@@ -112,8 +112,6 @@ void TimeBasedWidget::UpdateMaximumScroll()
|
||||
foreach (TimelineViewBase* base, timeline_views_) {
|
||||
base->SetEndTime(length);
|
||||
}
|
||||
|
||||
ruler()->SetCacheStatusLength(length);
|
||||
}
|
||||
|
||||
void TimeBasedWidget::ScrollBarResized(const double &multiplier)
|
||||
|
||||
@@ -239,6 +239,8 @@ void TimelineWidget::ConnectNodeInternal(ViewerOutput *n)
|
||||
connect(n, &ViewerOutput::TimebaseChanged, this, &TimelineWidget::SetTimebase);
|
||||
connect(n, &ViewerOutput::TrackHeightChanged, this, &TimelineWidget::TrackHeightChanged);
|
||||
|
||||
ruler()->SetPlaybackCache(n->video_frame_cache());
|
||||
|
||||
SetTimebase(n->video_params().time_base());
|
||||
|
||||
for (int i=0;i<views_.size();i++) {
|
||||
@@ -266,6 +268,8 @@ void TimelineWidget::DisconnectNodeInternal(ViewerOutput *n)
|
||||
disconnect(n, &ViewerOutput::TimebaseChanged, this, &TimelineWidget::SetTimebase);
|
||||
disconnect(n, &ViewerOutput::TrackHeightChanged, this, &TimelineWidget::TrackHeightChanged);
|
||||
|
||||
ruler()->SetPlaybackCache(nullptr);
|
||||
|
||||
SetTimebase(0);
|
||||
|
||||
Clear();
|
||||
|
||||
@@ -34,7 +34,8 @@ TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* pare
|
||||
SeekableWidget(parent),
|
||||
text_visible_(text_visible),
|
||||
centered_text_(true),
|
||||
show_cache_status_(cache_status_visible)
|
||||
show_cache_status_(cache_status_visible),
|
||||
playback_cache_(nullptr)
|
||||
{
|
||||
QFontMetrics fm = fontMetrics();
|
||||
|
||||
@@ -54,33 +55,27 @@ TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* pare
|
||||
connect(Core::instance(), &Core::TimecodeDisplayChanged, this, static_cast<void (TimeRuler::*)()>(&TimeRuler::update));
|
||||
}
|
||||
|
||||
void TimeRuler::SetCacheStatusLength(const rational &length)
|
||||
void TimeRuler::SetPlaybackCache(PlaybackCache *cache)
|
||||
{
|
||||
if (show_cache_status_) {
|
||||
cache_length_ = length;
|
||||
|
||||
dirty_cache_ranges_.RemoveTimeRange(TimeRange(length, RATIONAL_MAX));
|
||||
|
||||
update();
|
||||
if (!show_cache_status_) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void TimeRuler::CacheInvalidatedRange(const TimeRange& range)
|
||||
{
|
||||
if (show_cache_status_) {
|
||||
dirty_cache_ranges_.InsertTimeRange(range);
|
||||
|
||||
update();
|
||||
if (playback_cache_) {
|
||||
disconnect(playback_cache_, &PlaybackCache::Invalidated, this, static_cast<void(TimeRuler::*)()>(&TimeRuler::update));
|
||||
disconnect(playback_cache_, &PlaybackCache::Validated, this, static_cast<void(TimeRuler::*)()>(&TimeRuler::update));
|
||||
disconnect(playback_cache_, &PlaybackCache::LengthChanged, this, static_cast<void(TimeRuler::*)()>(&TimeRuler::update));
|
||||
}
|
||||
}
|
||||
|
||||
void TimeRuler::CacheTimeReady(const rational &time)
|
||||
{
|
||||
if (show_cache_status_) {
|
||||
dirty_cache_ranges_.RemoveTimeRange(TimeRange(time, time + timebase()));
|
||||
playback_cache_ = cache;
|
||||
|
||||
update();
|
||||
if (playback_cache_) {
|
||||
connect(playback_cache_, &PlaybackCache::Invalidated, this, static_cast<void(TimeRuler::*)()>(&TimeRuler::update));
|
||||
connect(playback_cache_, &PlaybackCache::Validated, this, static_cast<void(TimeRuler::*)()>(&TimeRuler::update));
|
||||
connect(playback_cache_, &PlaybackCache::LengthChanged, this, static_cast<void(TimeRuler::*)()>(&TimeRuler::update));
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void TimeRuler::paintEvent(QPaintEvent *)
|
||||
@@ -253,25 +248,32 @@ void TimeRuler::paintEvent(QPaintEvent *)
|
||||
}
|
||||
|
||||
// If cache status is enabled
|
||||
if (show_cache_status_) {
|
||||
int cache_screen_length = qMin(TimeToScreen(cache_length_), width());
|
||||
if (show_cache_status_ && playback_cache_) {
|
||||
int cache_screen_length = qMin(TimeToScreen(playback_cache_->GetLength()), width());
|
||||
|
||||
if (cache_screen_length > 0) {
|
||||
int cache_y = height() - cache_status_height_;
|
||||
|
||||
p.fillRect(0, cache_y, cache_screen_length , cache_status_height_, Qt::green);
|
||||
|
||||
foreach (const TimeRange& range, dirty_cache_ranges_) {
|
||||
foreach (const TimeRange& range, playback_cache_->GetInvalidatedRanges()) {
|
||||
int range_left = TimeToScreen(range.in());
|
||||
int range_right = TimeToScreen(range.out());
|
||||
if (range_left >= width()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (range_left >= width() || range_right < 0) {
|
||||
int range_right = TimeToScreen(range.out());
|
||||
if (range_right < 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int adjusted_left = qMax(0, range_left);
|
||||
|
||||
p.fillRect(adjusted_left, cache_y, qMin(width(), range_right) - adjusted_left, cache_status_height_, Qt::red);
|
||||
p.fillRect(adjusted_left,
|
||||
cache_y,
|
||||
qMin(width(), range_right) - adjusted_left,
|
||||
cache_status_height_,
|
||||
Qt::red);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include "common/timerange.h"
|
||||
#include "seekablewidget.h"
|
||||
#include "render/playbackcache.h"
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
@@ -37,12 +38,7 @@ public:
|
||||
|
||||
void SetCenteredText(bool c);
|
||||
|
||||
public slots:
|
||||
void CacheInvalidatedRange(const TimeRange &range);
|
||||
|
||||
void CacheTimeReady(const rational& time);
|
||||
|
||||
void SetCacheStatusLength(const rational& length);
|
||||
void SetPlaybackCache(PlaybackCache* cache);
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* e) override;
|
||||
@@ -66,9 +62,7 @@ private:
|
||||
|
||||
bool show_cache_status_;
|
||||
|
||||
rational cache_length_;
|
||||
|
||||
TimeRangeList dirty_cache_ranges_;
|
||||
PlaybackCache* playback_cache_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -157,6 +157,8 @@ void ViewerWidget::ConnectNodeInternal(ViewerOutput *n)
|
||||
connect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedRange);
|
||||
connect(n, &ViewerOutput::GraphChangedFrom, this, &ViewerWidget::UpdateStack);
|
||||
|
||||
ruler()->SetPlaybackCache(n->video_frame_cache());
|
||||
|
||||
n->audio_playback_cache()->SetParameters(AudioRenderingParams(n->audio_params(),
|
||||
SampleFormat::kInternalFormat));
|
||||
|
||||
@@ -206,6 +208,8 @@ void ViewerWidget::DisconnectNodeInternal(ViewerOutput *n)
|
||||
disconnect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedRange);
|
||||
disconnect(n, &ViewerOutput::GraphChangedFrom, this, &ViewerWidget::UpdateStack);
|
||||
|
||||
ruler()->SetPlaybackCache(nullptr);
|
||||
|
||||
// Effectively disables the viewer and clears the state
|
||||
SizeChangedSlot(0, 0);
|
||||
|
||||
@@ -1003,7 +1007,6 @@ void ViewerWidget::SizeChangedSlot(int width, int height)
|
||||
void ViewerWidget::LengthChangedSlot(const rational &length)
|
||||
{
|
||||
controls_->SetEndTime(Timecode::time_to_timestamp(length, timebase()));
|
||||
ruler()->SetCacheStatusLength(length);
|
||||
UpdateMinimumScale();
|
||||
}
|
||||
|
||||
|
||||
@@ -157,8 +157,6 @@ protected:
|
||||
|
||||
virtual void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
RenderBackend* renderer_;
|
||||
|
||||
PlaybackControls* controls_;
|
||||
|
||||
ViewerDisplayWidget* display_widget() const;
|
||||
@@ -225,6 +223,8 @@ private:
|
||||
ViewerQueue playback_queue_;
|
||||
int64_t playback_queue_next_frame_;
|
||||
|
||||
RenderBackend* renderer_;
|
||||
|
||||
private slots:
|
||||
void PlaybackTimerUpdate();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user