Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle [pull] master from olive-editor:master #216

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
294 changes: 104 additions & 190 deletions app/codec/ffmpeg/ffmpegdecoder.cpp

Large diffs are not rendered by default.

241 changes: 110 additions & 131 deletions app/render/backend/opengl/openglproxy.cpp

Large diffs are not rendered by default.

167 changes: 61 additions & 106 deletions app/render/backend/videorenderbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,34 @@
#include "common/timecodefunctions.h"
#include "config/config.h"
#include "render/diskmanager.h"
#include "render/diskmanager.h"
#include "render/pixelformat.h"
#include "videorenderworker.h"

VideoRenderBackend::VideoRenderBackend(QObject *parent) :
RenderBackend(parent),
operating_mode_(VideoRenderWorker::kHashRenderCache),
only_signal_last_frame_requested_(true),
limit_caching_(true)
{
VideoRenderBackend::VideoRenderBackend(QObject *parent)
: RenderBackend(parent),
operating_mode_(VideoRenderWorker::kHashRenderCache),
only_signal_last_frame_requested_(true),
limit_caching_(true) {
connect(DiskManager::instance(), &DiskManager::DeletedFrame, this, &VideoRenderBackend::FrameRemovedFromDiskCache);
}

void VideoRenderBackend::ConnectViewer(ViewerOutput *node)
{
void VideoRenderBackend::ConnectViewer(ViewerOutput *node) {
connect(node, &ViewerOutput::VideoChangedBetween, this, &VideoRenderBackend::InvalidateCache);
connect(node, &ViewerOutput::VideoGraphChanged, this, &VideoRenderBackend::QueueRecompile);
connect(node, &ViewerOutput::LengthChanged, this, &VideoRenderBackend::TruncateFrameCacheLength);
}

void VideoRenderBackend::DisconnectViewer(ViewerOutput *node)
{
void VideoRenderBackend::DisconnectViewer(ViewerOutput *node) {
disconnect(node, &ViewerOutput::VideoChangedBetween, this, &VideoRenderBackend::InvalidateCache);
disconnect(node, &ViewerOutput::VideoGraphChanged, this, &VideoRenderBackend::QueueRecompile);
disconnect(node, &ViewerOutput::LengthChanged, this, &VideoRenderBackend::TruncateFrameCacheLength);

frame_cache_.Clear();
}

const VideoRenderingParams &VideoRenderBackend::params() const
{
return params_;
}
const VideoRenderingParams &VideoRenderBackend::params() const { return params_; }

void VideoRenderBackend::SetParameters(const VideoRenderingParams& params)
{
void VideoRenderBackend::SetParameters(const VideoRenderingParams &params) {
CancelQueue();

// Set new parameters
Expand All @@ -75,47 +67,36 @@ void VideoRenderBackend::SetParameters(const VideoRenderingParams& params)
ParamsChangedEvent();

// Set params on all processors
foreach (RenderWorker* worker, processors_) {
static_cast<VideoRenderWorker*>(worker)->SetParameters(params_);
}
foreach (RenderWorker *worker, processors_) { static_cast<VideoRenderWorker *>(worker)->SetParameters(params_); }

// Regenerate the cache ID
RegenerateCacheID();
}

void VideoRenderBackend::SetOperatingMode(const VideoRenderWorker::OperatingMode &mode)
{
void VideoRenderBackend::SetOperatingMode(const VideoRenderWorker::OperatingMode &mode) {
if (!AllProcessorsAreAvailable()) {
qCritical() << "Attempted to set operating mode on a backend whose workers are still busy";
return;
}

operating_mode_ = mode;

foreach (RenderWorker* worker, processors_) {
static_cast<VideoRenderWorker*>(worker)->SetOperatingMode(operating_mode_);
foreach (RenderWorker *worker, processors_) {
static_cast<VideoRenderWorker *>(worker)->SetOperatingMode(operating_mode_);
}
}

void VideoRenderBackend::SetOnlySignalLastFrameRequested(bool enabled)
{
only_signal_last_frame_requested_ = enabled;
}
void VideoRenderBackend::SetOnlySignalLastFrameRequested(bool enabled) { only_signal_last_frame_requested_ = enabled; }

bool VideoRenderBackend::IsRendered(const rational &time) const
{
bool VideoRenderBackend::IsRendered(const rational &time) const {
TimeRange range(time, time);

return !TimeIsQueued(range) && !render_job_info_.contains(range);
}

void VideoRenderBackend::SetLimitCaching(bool limit)
{
limit_caching_ = limit;
}
void VideoRenderBackend::SetLimitCaching(bool limit) { limit_caching_ = limit; }

bool VideoRenderBackend::GenerateCacheIDInternal(QCryptographicHash& hash)
{
bool VideoRenderBackend::GenerateCacheIDInternal(QCryptographicHash &hash) {
if (!params_.is_valid()) {
return false;
}
Expand All @@ -129,26 +110,26 @@ bool VideoRenderBackend::GenerateCacheIDInternal(QCryptographicHash& hash)
return true;
}

void VideoRenderBackend::CacheIDChangedEvent(const QString &id)
{
frame_cache_.SetCacheID(id);
}
void VideoRenderBackend::CacheIDChangedEvent(const QString &id) { frame_cache_.SetCacheID(id); }

void VideoRenderBackend::ConnectWorkerToThis(RenderWorker *processor)
{
VideoRenderWorker* video_processor = static_cast<VideoRenderWorker*>(processor);
void VideoRenderBackend::ConnectWorkerToThis(RenderWorker *processor) {
VideoRenderWorker *video_processor = static_cast<VideoRenderWorker *>(processor);

video_processor->SetOperatingMode(operating_mode_);

connect(video_processor, &VideoRenderWorker::CompletedFrame, this, &VideoRenderBackend::ThreadCompletedFrame, Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::HashAlreadyBeingCached, this, &VideoRenderBackend::ThreadSkippedFrame, Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::CompletedDownload, this, &VideoRenderBackend::ThreadCompletedDownload, Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::HashAlreadyExists, this, &VideoRenderBackend::ThreadHashAlreadyExists, Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::GeneratedFrame, this, &VideoRenderBackend::GeneratedFrame, Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::CompletedFrame, this, &VideoRenderBackend::ThreadCompletedFrame,
Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::HashAlreadyBeingCached, this, &VideoRenderBackend::ThreadSkippedFrame,
Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::CompletedDownload, this, &VideoRenderBackend::ThreadCompletedDownload,
Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::HashAlreadyExists, this, &VideoRenderBackend::ThreadHashAlreadyExists,
Qt::QueuedConnection);
connect(video_processor, &VideoRenderWorker::GeneratedFrame, this, &VideoRenderBackend::GeneratedFrame,
Qt::QueuedConnection);
}

void VideoRenderBackend::InvalidateCacheInternal(const rational &start_range, const rational &end_range)
{
void VideoRenderBackend::InvalidateCacheInternal(const rational &start_range, const rational &end_range) {
TimeRange invalidated(start_range, end_range);

invalidated_.InsertTimeRange(invalidated);
Expand All @@ -158,13 +139,9 @@ void VideoRenderBackend::InvalidateCacheInternal(const rational &start_range, co
Requeue();
}

VideoRenderFrameCache *VideoRenderBackend::frame_cache()
{
return &frame_cache_;
}
VideoRenderFrameCache *VideoRenderBackend::frame_cache() { return &frame_cache_; }

QString VideoRenderBackend::GetCachedFrame(const rational &time)
{
QString VideoRenderBackend::GetCachedFrame(const rational &time) {
last_time_requested_ = time;

if (viewer_node() == nullptr) {
Expand Down Expand Up @@ -196,18 +173,11 @@ QString VideoRenderBackend::GetCachedFrame(const rational &time)
return QString();
}

NodeInput *VideoRenderBackend::GetDependentInput()
{
return viewer_node()->texture_input();
}
NodeInput *VideoRenderBackend::GetDependentInput() { return viewer_node()->texture_input(); }

bool VideoRenderBackend::CanRender()
{
return params_.is_valid();
}
bool VideoRenderBackend::CanRender() { return params_.is_valid(); }

TimeRange VideoRenderBackend::PopNextFrameFromQueue()
{
TimeRange VideoRenderBackend::PopNextFrameFromQueue() {
// Try to find the frame that's closest to the last time requested (the playhead)

// Set up playhead frame range to see if the queue contains this frame precisely
Expand All @@ -216,13 +186,13 @@ TimeRange VideoRenderBackend::PopNextFrameFromQueue()
// Use this variable to find the closest frame in the range
rational closest_time = -1;

foreach (const TimeRange& range_here, cache_queue_) {
foreach (const TimeRange &range_here, cache_queue_) {
if (range_here.OverlapsWith(test_range, false, false)) {
closest_time = -1;
break;
}

for (int j=0;j<2;j++) {
for (int j = 0; j < 2; j++) {
rational compare;

if (j == 0) {
Expand All @@ -237,8 +207,7 @@ TimeRange VideoRenderBackend::PopNextFrameFromQueue()
}
}

if (closest_time < 0
|| qAbs(compare - last_time_requested_) < qAbs(closest_time - last_time_requested_)) {
if (closest_time < 0 || qAbs(compare - last_time_requested_) < qAbs(closest_time - last_time_requested_)) {
closest_time = compare;
}
}
Expand All @@ -262,25 +231,25 @@ TimeRange VideoRenderBackend::PopNextFrameFromQueue()
return TimeRange(frame_range.in(), frame_range.in());
}

void VideoRenderBackend::ThreadCompletedFrame(NodeDependency path, qint64 job_time, QByteArray hash, QVariant value)
{
if (!only_signal_last_frame_requested_ || last_time_requested_ == path.in() || frame_cache_.TimeToHash(last_time_requested_) == hash) {
void VideoRenderBackend::ThreadCompletedFrame(NodeDependency path, qint64 job_time, QByteArray hash, QVariant value) {
if (!only_signal_last_frame_requested_ || last_time_requested_ == path.in() ||
frame_cache_.TimeToHash(last_time_requested_) == hash) {
Q_UNUSED(job_time)
Q_UNUSED(value)
//EmitCachedFrameReady(path.in(), value, job_time);
// EmitCachedFrameReady(path.in(), value, job_time);
}

if (!(operating_mode_ & VideoRenderWorker::kDownloadOnly)) {
// If we're not downloading, the worker is done here
SetWorkerBusyState(static_cast<RenderWorker*>(sender()), false);
SetWorkerBusyState(static_cast<RenderWorker *>(sender()), false);

CacheNext();
}
}

void VideoRenderBackend::ThreadCompletedDownload(NodeDependency dep, qint64 job_time, QByteArray hash, bool texture_existed)
{
SetWorkerBusyState(static_cast<RenderWorker*>(sender()), false);
void VideoRenderBackend::ThreadCompletedDownload(NodeDependency dep, qint64 job_time, QByteArray hash,
bool texture_existed) {
SetWorkerBusyState(static_cast<RenderWorker *>(sender()), false);

SetFrameHash(dep, hash, job_time);

Expand All @@ -291,30 +260,25 @@ void VideoRenderBackend::ThreadCompletedDownload(NodeDependency dep, qint64 job_

QList<rational> hashes_with_time = frame_cache()->FramesWithHash(hash);

foreach (const rational& t, hashes_with_time) {
emit CachedTimeReady(t, job_time);
}
foreach (const rational &t, hashes_with_time) { emit CachedTimeReady(t, job_time); }

// Queue up a new frame for this worker
CacheNext();
}

void VideoRenderBackend::ThreadSkippedFrame(NodeDependency dep, qint64 job_time, QByteArray hash)
{
SetWorkerBusyState(static_cast<RenderWorker*>(sender()), false);
void VideoRenderBackend::ThreadSkippedFrame(NodeDependency dep, qint64 job_time, QByteArray hash) {
SetWorkerBusyState(static_cast<RenderWorker *>(sender()), false);

if (SetFrameHash(dep, hash, job_time)
&& frame_cache_.HasHash(hash, params_.format())) {
if (SetFrameHash(dep, hash, job_time) && frame_cache_.HasHash(hash, params_.format())) {
emit CachedTimeReady(dep.in(), job_time);
}

// Queue up a new frame for this worker
CacheNext();
}

void VideoRenderBackend::ThreadHashAlreadyExists(NodeDependency dep, qint64 job_time, QByteArray hash)
{
SetWorkerBusyState(static_cast<RenderWorker*>(sender()), false);
void VideoRenderBackend::ThreadHashAlreadyExists(NodeDependency dep, qint64 job_time, QByteArray hash) {
SetWorkerBusyState(static_cast<RenderWorker *>(sender()), false);

if (SetFrameHash(dep, hash, job_time)) {
emit CachedTimeReady(dep.in(), job_time);
Expand All @@ -324,8 +288,7 @@ void VideoRenderBackend::ThreadHashAlreadyExists(NodeDependency dep, qint64 job_
CacheNext();
}

void VideoRenderBackend::TruncateFrameCacheLength(const rational &length)
{
void VideoRenderBackend::TruncateFrameCacheLength(const rational &length) {
// Remove frames after this time code if it's changed
frame_cache_.Truncate(length);

Expand All @@ -341,31 +304,27 @@ void VideoRenderBackend::TruncateFrameCacheLength(const rational &length)
Requeue();
}

void VideoRenderBackend::FrameRemovedFromDiskCache(const QByteArray &hash)
{
void VideoRenderBackend::FrameRemovedFromDiskCache(const QByteArray &hash) {
QList<rational> deleted_frames = frame_cache()->TakeFramesWithHash(hash);

foreach (const rational& frame, deleted_frames) {
TimeRange invalidated(frame, frame+params_.time_base());
foreach (const rational &frame, deleted_frames) {
TimeRange invalidated(frame, frame + params_.time_base());

invalidated_.InsertTimeRange(invalidated);

emit RangeInvalidated(invalidated);
}
}

bool VideoRenderBackend::TimeIsQueued(const TimeRange &time) const
{
bool VideoRenderBackend::TimeIsQueued(const TimeRange &time) const {
return cache_queue_.ContainsTimeRange(time, true, false);
}

bool VideoRenderBackend::JobIsCurrent(const NodeDependency &dep, const qint64& job_time) const
{
bool VideoRenderBackend::JobIsCurrent(const NodeDependency &dep, const qint64 &job_time) const {
return (render_job_info_.value(dep.range()) == job_time && !TimeIsQueued(dep.range()));
}

bool VideoRenderBackend::SetFrameHash(const NodeDependency &dep, const QByteArray &hash, const qint64& job_time)
{
bool VideoRenderBackend::SetFrameHash(const NodeDependency &dep, const QByteArray &hash, const qint64 &job_time) {
if (JobIsCurrent(dep, job_time)) {
frame_cache_.SetHash(dep.in(), hash);
render_job_info_.remove(dep.range());
Expand All @@ -376,20 +335,16 @@ bool VideoRenderBackend::SetFrameHash(const NodeDependency &dep, const QByteArra
return false;
}

void VideoRenderBackend::Requeue()
{
void VideoRenderBackend::Requeue() {
if (limit_caching_) {

// Reset queue around the last time requested
TimeRange queueable_range(last_time_requested_ - Config::Current()["DiskCacheBehind"].value<rational>(),
last_time_requested_ + Config::Current()["DiskCacheAhead"].value<rational>());

cache_queue_ = invalidated_.Intersects(queueable_range);

} else {

cache_queue_ = invalidated_;

}

CacheNext();
Expand Down
Loading