fixes jitters by using signals/slots to pass image buffers around
Updating values rapidly would cause strange jitters as a byproduct of the viewer trying to update from the renderer while it was still working. Rather than the viewer trying to access the the renderer, we now send textures in the initial update signal to keep everything synchronized.
This commit is contained in:
@@ -12,7 +12,7 @@ void AudioRenderWorker::SetParameters(const AudioRenderingParams &audio_params)
|
||||
audio_params_ = audio_params;
|
||||
}
|
||||
|
||||
void AudioRenderWorker::RenderAsSibling(NodeDependency dep)
|
||||
QVariant AudioRenderWorker::RenderAsSibling(NodeDependency dep)
|
||||
{
|
||||
NodeOutput* output = dep.node();
|
||||
Node* node = output->parent();
|
||||
@@ -49,6 +49,8 @@ void AudioRenderWorker::RenderAsSibling(NodeDependency dep)
|
||||
|
||||
// End this working state
|
||||
working_--;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
bool AudioRenderWorker::InitInternal()
|
||||
|
||||
@@ -12,7 +12,7 @@ public:
|
||||
void SetParameters(const AudioRenderingParams& audio_params);
|
||||
|
||||
public slots:
|
||||
virtual void RenderAsSibling(NodeDependency dep) override;
|
||||
virtual QVariant RenderAsSibling(NodeDependency dep) override;
|
||||
|
||||
protected:
|
||||
virtual bool InitInternal() override;
|
||||
|
||||
@@ -6,9 +6,7 @@
|
||||
#include "functions.h"
|
||||
|
||||
OpenGLBackend::OpenGLBackend(QObject *parent) :
|
||||
VideoRenderBackend(parent),
|
||||
push_texture_(nullptr),
|
||||
push_time_(-1)
|
||||
VideoRenderBackend(parent)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -58,21 +56,11 @@ void OpenGLBackend::CloseInternal()
|
||||
|
||||
//copy_buffer_.Destroy();
|
||||
master_texture_ = nullptr;
|
||||
push_texture_ = nullptr;
|
||||
//copy_pipeline_ = nullptr;
|
||||
}
|
||||
|
||||
OpenGLTexturePtr OpenGLBackend::GetCachedFrameAsTexture(const rational &time)
|
||||
{
|
||||
if (push_time_ >= 0) {
|
||||
rational temp_push_time = push_time_;
|
||||
push_time_ = -1;
|
||||
|
||||
if (time == temp_push_time) {
|
||||
return push_texture_;
|
||||
}
|
||||
}
|
||||
|
||||
const char* cached_frame = GetCachedFrame(time);
|
||||
|
||||
if (cached_frame != nullptr) {
|
||||
@@ -167,11 +155,16 @@ bool OpenGLBackend::TraverseCompiling(Node *n)
|
||||
return true;
|
||||
}
|
||||
|
||||
void OpenGLBackend::ThreadCompletedFrame(NodeDependency path, QByteArray hash)
|
||||
bool OpenGLBackend::TimeIsCached(const TimeRange &time)
|
||||
{
|
||||
return cache_queue_.contains(time);
|
||||
}
|
||||
|
||||
void OpenGLBackend::ThreadCompletedFrame(NodeDependency path, QByteArray hash, QVariant value)
|
||||
{
|
||||
caching_ = false;
|
||||
|
||||
OpenGLTexturePtr texture = path.node()->get_cached_value(path.range()).value<OpenGLTexturePtr>();
|
||||
OpenGLTexturePtr texture = value.value<OpenGLTexturePtr>();
|
||||
|
||||
if (texture == nullptr) {
|
||||
// No frame received, we set hash to an empty
|
||||
@@ -197,9 +190,9 @@ void OpenGLBackend::ThreadCompletedFrame(NodeDependency path, QByteArray hash)
|
||||
}
|
||||
|
||||
// Set as push texture
|
||||
push_time_ = path.in();
|
||||
push_texture_ = texture;
|
||||
emit CachedFrameReady(push_time_);
|
||||
if (!TimeIsCached(TimeRange(path.in(), path.in()))) {
|
||||
emit CachedFrameReady(path.in(), value);
|
||||
}
|
||||
|
||||
CacheNext();
|
||||
}
|
||||
@@ -208,7 +201,7 @@ void OpenGLBackend::ThreadCompletedDownload(NodeDependency dep, QByteArray hash)
|
||||
{
|
||||
frame_cache()->SetHash(dep.in(), hash);
|
||||
|
||||
emit CachedFrameReady(dep.in());
|
||||
emit CachedTimeReady(dep.in());
|
||||
}
|
||||
|
||||
void OpenGLBackend::ThreadSkippedFrame()
|
||||
|
||||
@@ -30,9 +30,9 @@ protected:
|
||||
private:
|
||||
bool TraverseCompiling(Node* n);
|
||||
|
||||
bool TimeIsCached(const TimeRange &time);
|
||||
|
||||
OpenGLTexturePtr master_texture_;
|
||||
OpenGLTexturePtr push_texture_;
|
||||
rational push_time_;
|
||||
|
||||
/*OpenGLFramebuffer copy_buffer_;
|
||||
OpenGLShaderPtr copy_pipeline_;*/
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
OpenGLShaderCache shader_cache_;
|
||||
|
||||
private slots:
|
||||
void ThreadCompletedFrame(NodeDependency path, QByteArray hash);
|
||||
void ThreadCompletedFrame(NodeDependency path, QByteArray hash, QVariant value);
|
||||
void ThreadCompletedDownload(NodeDependency dep, QByteArray hash);
|
||||
void ThreadSkippedFrame();
|
||||
void ThreadHashAlreadyExists(NodeDependency dep, QByteArray hash);
|
||||
|
||||
@@ -26,7 +26,7 @@ public slots:
|
||||
|
||||
void Render(NodeDependency path);
|
||||
|
||||
virtual void RenderAsSibling(NodeDependency dep) = 0;
|
||||
virtual QVariant RenderAsSibling(NodeDependency dep) = 0;
|
||||
|
||||
signals:
|
||||
void RequestSibling(NodeDependency path);
|
||||
|
||||
@@ -165,7 +165,7 @@ void VideoRenderBackend::CacheIDChangedEvent(const QString &id)
|
||||
|
||||
void VideoRenderBackend::ConnectWorkerToThis(RenderWorker *processor)
|
||||
{
|
||||
connect(processor, SIGNAL(CompletedFrame(NodeDependency, QByteArray)), this, SLOT(ThreadCompletedFrame(NodeDependency, QByteArray)));
|
||||
connect(processor, SIGNAL(CompletedFrame(NodeDependency, QByteArray, QVariant)), this, SLOT(ThreadCompletedFrame(NodeDependency, QByteArray, QVariant)));
|
||||
connect(processor, SIGNAL(HashAlreadyBeingCached()), this, SLOT(ThreadSkippedFrame()));
|
||||
connect(processor, SIGNAL(CompletedDownload(NodeDependency, QByteArray)), this, SLOT(ThreadCompletedDownload(NodeDependency, QByteArray)));
|
||||
connect(processor, SIGNAL(HashAlreadyExists(NodeDependency, QByteArray)), this, SLOT(ThreadHashAlreadyExists(NodeDependency, QByteArray)));
|
||||
|
||||
@@ -93,7 +93,8 @@ protected:
|
||||
virtual void ConnectWorkerToThis(RenderWorker* processor) override;
|
||||
|
||||
signals:
|
||||
void CachedFrameReady(const rational& time);
|
||||
void CachedFrameReady(const rational& time, QVariant value);
|
||||
void CachedTimeReady(const rational& time);
|
||||
|
||||
private:
|
||||
VideoRenderingParams params_;
|
||||
|
||||
@@ -29,9 +29,9 @@ void VideoRenderWorker::RenderInternal(const NodeDependency& path)
|
||||
emit HashAlreadyExists(path, hash);
|
||||
} else if (frame_cache_->TryCache(hash)) {
|
||||
// This hash is available for us to cache, start traversing graph
|
||||
RenderAsSibling(path);
|
||||
QVariant value = RenderAsSibling(path);
|
||||
|
||||
emit CompletedFrame(path, hash);
|
||||
emit CompletedFrame(path, hash, value);
|
||||
} else {
|
||||
// Another thread must be caching this already, nothing to be done
|
||||
emit HashAlreadyBeingCached();
|
||||
@@ -115,7 +115,7 @@ void VideoRenderWorker::CloseInternal()
|
||||
download_buffer_.clear();
|
||||
}
|
||||
|
||||
void VideoRenderWorker::RenderAsSibling(NodeDependency dep)
|
||||
QVariant VideoRenderWorker::RenderAsSibling(NodeDependency dep)
|
||||
{
|
||||
NodeOutput* output = dep.node();
|
||||
Node* original_node = output->parent();
|
||||
@@ -158,6 +158,8 @@ void VideoRenderWorker::RenderAsSibling(NodeDependency dep)
|
||||
|
||||
// End this working state
|
||||
working_--;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void VideoRenderWorker::Download(NodeDependency dep, QByteArray hash, QVariant texture, QString filename)
|
||||
|
||||
@@ -16,12 +16,12 @@ public:
|
||||
void SetParameters(const VideoRenderingParams& video_params);
|
||||
|
||||
public slots:
|
||||
virtual void RenderAsSibling(NodeDependency dep) override;
|
||||
virtual QVariant RenderAsSibling(NodeDependency dep) override;
|
||||
|
||||
void Download(NodeDependency dep, QByteArray hash, QVariant texture, QString filename);
|
||||
|
||||
signals:
|
||||
void CompletedFrame(NodeDependency path, QByteArray hash);
|
||||
void CompletedFrame(NodeDependency path, QByteArray hash, QVariant value);
|
||||
|
||||
void CompletedDownload(NodeDependency path, QByteArray hash);
|
||||
|
||||
|
||||
@@ -77,7 +77,8 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
|
||||
|
||||
// Start background renderers
|
||||
video_renderer_ = new OpenGLBackend(this);
|
||||
connect(video_renderer_, SIGNAL(CachedFrameReady(const rational&)), this, SLOT(RendererCachedFrame(const rational&)));
|
||||
connect(video_renderer_, SIGNAL(CachedFrameReady(const rational&, QVariant)), this, SLOT(RendererCachedFrame(const rational&, QVariant)));
|
||||
connect(video_renderer_, SIGNAL(CachedTimeReady(const rational&)), this, SLOT(RendererCachedTime(const rational&)));
|
||||
audio_renderer_ = new AudioBackend(this);
|
||||
}
|
||||
|
||||
@@ -347,7 +348,14 @@ void ViewerWidget::PlaybackTimerUpdate()
|
||||
SetTime(current_time);
|
||||
}
|
||||
|
||||
void ViewerWidget::RendererCachedFrame(const rational &time)
|
||||
void ViewerWidget::RendererCachedFrame(const rational &time, QVariant value)
|
||||
{
|
||||
if (GetTime() == time) {
|
||||
SetTexture(value.value<OpenGLTexturePtr>());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::RendererCachedTime(const rational &time)
|
||||
{
|
||||
if (GetTime() == time) {
|
||||
UpdateTextureFromNode(GetTime());
|
||||
|
||||
@@ -143,7 +143,8 @@ private slots:
|
||||
|
||||
void PlaybackTimerUpdate();
|
||||
|
||||
void RendererCachedFrame(const rational& time);
|
||||
void RendererCachedFrame(const rational& time, QVariant value);
|
||||
void RendererCachedTime(const rational& time);
|
||||
|
||||
void SizeChangedSlot(int width, int height);
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ void olive::MainWindow::closeEvent(QCloseEvent *e)
|
||||
// FIXME: Test code - We have no cache management and the cache is very much testing only, so we delete it on close
|
||||
// as to not clog up HDD space
|
||||
QDir(GetMediaCacheLocation()).removeRecursively();
|
||||
QDir(GetMediaIndexLocation()).removeRecursively();
|
||||
//QDir(GetMediaIndexLocation()).removeRecursively();
|
||||
// End test code
|
||||
|
||||
QMainWindow::closeEvent(e);
|
||||
|
||||
Reference in New Issue
Block a user