remove hashtraverser

This commit is contained in:
itsmattkc
2022-05-09 18:22:32 -07:00
parent 0f99d8a662
commit 0538c01f45
15 changed files with 42 additions and 542 deletions
-2
View File
@@ -38,8 +38,6 @@ set(OLIVE_SOURCES
node/globals.h
node/graph.cpp
node/graph.h
node/hashtraverser.cpp
node/hashtraverser.h
node/inputdragger.cpp
node/inputdragger.h
node/inputimmediate.cpp
-158
View File
@@ -1,158 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 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 <http://www.gnu.org/licenses/>.
***/
#include "hashtraverser.h"
#include <QUuid>
#include "common/filefunctions.h"
namespace olive {
#define super NodeTraverser
HashTraverser::HashTraverser() :
hash_(QCryptographicHash::Sha1) // Appears to be the fastest hashing algorithm
{
}
QByteArray HashTraverser::GetHash(const Node *node, const Node::ValueHint &hint, const VideoParams &params, const TimeRange &range)
{
// Reset hash
hash_.reset();
texture_ids_.clear();
// Set params throughout traverser
SetCacheVideoParams(params);
// Embed video parameters into this hash
Hash(params.effective_width());
Hash(params.effective_height());
Hash(params.format());
Hash(params.interlacing());
//Hash(reference);
// Our overrides will generate a hash from this
NodeValueTable table = GenerateTable(node, hint, range);
NodeValue final_value = GenerateRowValueElement(hint, NodeValue::kTexture, &table);
HashNodeValue(final_value);
// Return the hash
return hash_.result();
}
void HashTraverser::ProcessVideoFootage(TexturePtr destination, const FootageJob &stream, const rational &input_time)
{
Hash(FileFunctions::GetUniqueFileIdentifier(stream.filename()));
Hash(stream.loop_mode());
Hash(stream.video_params().stream_index());
Hash(stream.video_params().colorspace());
Hash(stream.video_params().premultiplied_alpha());
Hash(GetCacheVideoParams().divider());
Hash(stream.video_params().video_type() == VideoParams::kVideoTypeStill ? 0 : input_time);
Hash(stream.video_params().video_type());
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::ProcessAudioFootage(SampleBuffer &destination, const FootageJob &stream, const TimeRange &input_time)
{
}
void HashTraverser::ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob &job)
{
HashGenerateJob(node, &job);
Hash(job.GetShaderID());
Hash(job.GetIterativeInput());
Hash(job.GetIterationCount());
for (auto it=job.GetInterpolationMap().cbegin(); it!=job.GetInterpolationMap().cend(); it++) {
Hash(it.key());
Hash(it.value());
}
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::ProcessColorTransform(TexturePtr destination, const Node *node, const ColorTransformJob &job)
{
Hash(job.GetColorProcessor()->id());
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::ProcessSamples(SampleBuffer &destination, const Node *node, const TimeRange &range, const SampleJob &job)
{
}
void HashTraverser::ProcessFrameGeneration(TexturePtr destination, const Node *node, const GenerateJob &job)
{
HashGenerateJob(node, &job);
texture_ids_.insert(destination.get(), hash_.result());
}
void HashTraverser::HashGenerateJob(const Node *node, const GenerateJob *job)
{
Hash(node->id());
Hash(job->GetAlphaChannelRequired());
for (auto it=job->GetValues().cbegin(); it!=job->GetValues().cend(); it++) {
Hash(it.key());
HashNodeValue(it.value());
}
}
void HashTraverser::Hash(const QByteArray &array)
{
hash_.addData(array);
}
void HashTraverser::Hash(const QString &string)
{
hash_.addData(string.toUtf8());
}
void HashTraverser::HashNodeValue(const NodeValue &value)
{
NodeValue::Type value_type = value.type();
if (value_type == NodeValue::kSamples || value_type == NodeValue::kTexture) {
QByteArray id_for_buffer;
if (value_type == NodeValue::kTexture) {
TexturePtr texture = value.toTexture();
id_for_buffer = texture_ids_.value(texture.get());
}
if (!id_for_buffer.isEmpty()) {
Hash(id_for_buffer);
}
} else {
Hash(NodeValue::ValueToBytes(value));
}
}
template<typename T>
void HashTraverser::Hash(T value)
{
hash_.addData(reinterpret_cast<const char*>(&value), sizeof(value));
}
}
-70
View File
@@ -1,70 +0,0 @@
/***
Olive - Non-Linear Video Editor
Copyright (C) 2021 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 <http://www.gnu.org/licenses/>.
***/
#ifndef HASHTRAVERSER_H
#define HASHTRAVERSER_H
#include "traverser.h"
namespace olive {
class HashTraverser : public NodeTraverser
{
public:
HashTraverser();
QByteArray GetHash(const Node *node, const Node::ValueHint &hint, const VideoParams &params, const TimeRange &range);
protected:
virtual void ProcessVideoFootage(TexturePtr destination, const FootageJob &stream, const rational &input_time) override;
virtual void ProcessAudioFootage(SampleBuffer &destination, const FootageJob &stream, const TimeRange &input_time) override;
virtual void ProcessShader(TexturePtr destination, const Node *node, const TimeRange &range, const ShaderJob& job) override;
virtual void ProcessColorTransform(TexturePtr destination, const Node *node, const ColorTransformJob& job) override;
virtual void ProcessSamples(SampleBuffer &destination, const Node *node, const TimeRange &range, const SampleJob &job) override;
virtual void ProcessFrameGeneration(TexturePtr destination, const Node *node, const GenerateJob& job) override;
private:
void HashGenerateJob(const Node *node, const GenerateJob *job);
void HashFootageJob();
template <typename T>
void Hash(T value);
void Hash(const QByteArray &array);
void Hash(const QString &string);
void HashNodeValue(const NodeValue &value);
QCryptographicHash hash_;
QHash<void*, QByteArray> texture_ids_;
};
}
#endif // HASHTRAVERSER_H
-48
View File
@@ -92,54 +92,6 @@ QString NodeValue::ValueToString(Type data_type, const QVariant &value, bool val
}
}
template<typename T>
QByteArray ValueToBytesInternal(const QVariant &v)
{
QByteArray bytes;
int size_of_type = sizeof(T);
bytes.resize(size_of_type);
T raw_val = v.value<T>();
memcpy(bytes.data(), &raw_val, static_cast<size_t>(size_of_type));
return bytes;
}
QByteArray NodeValue::ValueToBytes(NodeValue::Type type, const QVariant &value)
{
switch (type) {
case kInt: return ValueToBytesInternal<int64_t>(value);
case kFloat: return ValueToBytesInternal<double>(value);
case kColor: return ValueToBytesInternal<Color>(value);
case kText: return value.toString().toUtf8();
case kBoolean: return ValueToBytesInternal<bool>(value);
case kFont: return value.toString().toUtf8();
case kFile: return value.toString().toUtf8();
case kMatrix: return ValueToBytesInternal<QMatrix4x4>(value);
case kRational: return ValueToBytesInternal<rational>(value);
case kVec2: return ValueToBytesInternal<QVector2D>(value);
case kVec3: return ValueToBytesInternal<QVector3D>(value);
case kVec4: return ValueToBytesInternal<QVector4D>(value);
case kCombo: return ValueToBytesInternal<int>(value);
case kBezier: return ValueToBytesInternal<Bezier>(value);
case kVideoParams:
return value.value<VideoParams>().toBytes();
case kAudioParams:
return value.value<AudioParams>().toBytes();
// These types have no persistent input
case kNone:
case kTexture:
case kSamples:
case kDataTypeCount:
break;
}
return QByteArray();
}
QVector<QVariant> NodeValue::split_normal_value_into_track_values(Type type, const QVariant &value)
{
QVector<QVariant> vals(get_number_of_keyframe_tracks(type));
-9
View File
@@ -257,15 +257,6 @@ public:
static QVariant StringToValue(Type data_type, const QString &string, bool value_is_a_key_track);
/**
* @brief Convert a value from a NodeParam into bytes
*/
static QByteArray ValueToBytes(Type type, const QVariant& value);
static QByteArray ValueToBytes(const NodeValue &value)
{
return ValueToBytes(value.type(), value.data_);
}
static QVector<QVariant> split_normal_value_into_track_values(Type type, const QVariant &value);
static QVariant combine_track_values_into_normal_value(Type type, const QVector<QVariant>& split);
+15 -127
View File
@@ -93,40 +93,6 @@ RenderTicketPtr PreviewAutoCacher::GetRangeOfAudio(TimeRange range, bool priorit
return RenderAudio(range, false, prioritize);
}
QVector<PreviewAutoCacher::HashData> PreviewAutoCacher::GenerateHashes(ViewerOutput *viewer, FrameHashCache* cache, const QVector<rational> &times)
{
QVector<HashData> hash_data(times.size());
QVector<QByteArray> existing_hashes;
for (int i=0; i<times.size(); i++) {
const rational &time = times.at(i);
// See if hash already exists in disk cache
QByteArray hash = RenderManager::Hash(viewer->GetConnectedTextureOutput(),
viewer->GetConnectedTextureValueHint(),
viewer->GetVideoParams(),
time);
// Check memory list since disk checking is slow
bool hash_exists = existing_hashes.contains(hash);
if (!hash_exists) {
// FIXME: Using CachePathName here is NOT thread safe and should be replaced
hash_exists = QFileInfo::exists(cache->CachePathName(hash));
if (hash_exists) {
existing_hashes.push_back(hash);
}
}
// Set hash in FrameHashCache's thread rather than in ours to prevent race conditions
hash_data[i] = {time, hash, hash_exists};
}
return hash_data;
}
void PreviewAutoCacher::VideoInvalidated(const TimeRange &range)
{
// Stop any current render tasks because a) they might be out of date now anyway, and b) we
@@ -151,39 +117,6 @@ void PreviewAutoCacher::AudioInvalidated(const TimeRange &range)
}
}
void PreviewAutoCacher::HashesProcessed()
{
// Receive watcher
QFutureWatcher< QVector<HashData> >* watcher = static_cast<QFutureWatcher<QVector<HashData> >*>(sender());
// If the task list doesn't contain this watcher, presumably it was cleared as a result of a
// viewer switch, so we'll completely ignore this watcher
if (hash_tasks_.contains(watcher)) {
// Remove task from hash task list
hash_tasks_.removeOne(watcher);
// Set all hashes we received that are still current
JobTime job_time = watcher->property("job").value<JobTime>();
auto hashes = watcher->result();
foreach (auto hash, hashes) {
if (video_job_tracker_.isCurrent(hash.time, job_time)) {
viewer_node_->video_frame_cache()->SetHash(hash.time, hash.hash, hash.exists);
}
}
// RequeueFrames won't run if hash tasks isn't empty, so if it is, trigger it now
if (hash_tasks_.isEmpty()) {
delayed_requeue_timer_.stop();
delayed_requeue_timer_.start();
}
// Continue rendering
TryRender();
}
delete watcher;
}
void PreviewAutoCacher::AudioRendered()
{
// Receive watcher
@@ -271,24 +204,23 @@ void PreviewAutoCacher::VideoRendered()
// If the task list doesn't contain this watcher, presumably it was cleared as a result of a
// viewer switch, so we'll completely ignore this watcher
if (video_tasks_.contains(watcher)) {
if (video_tasks_.remove(watcher)) {
// Assume that a "result" is a fully completed image and a non-result is a cancelled ticket
QByteArray hash = video_tasks_.take(watcher);
if (watcher->HasResult()) {
qDebug() << "FIXME: oops no frame downloading";
/*
// Download frame in another thread
if (!hash.isEmpty()) {
FramePtr frame = watcher->Get().value<FramePtr>();
RenderTicketWatcher* w = new RenderTicketWatcher();
w->setProperty("job", QVariant::fromValue(last_update_time_));
w->setProperty("frame", QVariant::fromValue(frame));
video_download_tasks_.insert(w, hash);
connect(w, &RenderTicketWatcher::Finished, this, &PreviewAutoCacher::VideoDownloaded);
w->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_node_->video_frame_cache(),
frame,
hash,
true));
}
FramePtr frame = watcher->Get().value<FramePtr>();
RenderTicketWatcher* w = new RenderTicketWatcher();
w->setProperty("job", QVariant::fromValue(last_update_time_));
w->setProperty("frame", QVariant::fromValue(frame));
video_download_tasks_.insert(w, hash);
connect(w, &RenderTicketWatcher::Finished, this, &PreviewAutoCacher::VideoDownloaded);
w->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_node_->video_frame_cache(),
frame,
true));
*/
}
// Continue rendering
@@ -508,13 +440,6 @@ void PreviewAutoCacher::SetPlayhead(const rational &playhead)
RequeueFrames();
}
void PreviewAutoCacher::WaitForHashesToFinish()
{
for (auto it=hash_tasks_.cbegin(); it!=hash_tasks_.cend(); it++) {
(*it)->waitForFinished();
}
}
void PreviewAutoCacher::WaitForVideoDownloadsToFinish()
{
for (auto it=video_download_tasks_.cbegin(); it!=video_download_tasks_.cend(); it++) {
@@ -598,8 +523,7 @@ void PreviewAutoCacher::TryRender()
// Check if we have jobs running in other threads that shouldn't be interrupted right now
// NOTE: We don't check for downloads because, while they run in another thread, they don't
// require any access to the graph and therefore don't risk race conditions.
if (!hash_tasks_.isEmpty()
|| !audio_tasks_.isEmpty()
if (!audio_tasks_.isEmpty()
|| !video_tasks_.isEmpty()) {
return;
}
@@ -649,32 +573,6 @@ void PreviewAutoCacher::TryRender()
// Ensure we are running tasks if we have any
const int max_tasks = RenderManager::GetNumberOfIdealConcurrentJobs();
// Handle hash tasks
while (hash_tasks_.size() < max_tasks && hash_iterator_.HasNext()) {
// Magic number: dunno what the best number for this is yet
static const int kMaxFrames = 1000;
QVector<rational> times(kMaxFrames);
for (int i=0; i<kMaxFrames; i++) {
rational r;
if (hash_iterator_.GetNext(&r)) {
times[i] = r;
} else {
times.resize(i);
break;
}
}
QFutureWatcher< QVector<HashData> >* watcher = new QFutureWatcher< QVector<HashData> >();
watcher->setProperty("job", QVariant::fromValue(last_update_time_));
hash_tasks_.append(watcher);
connect(watcher, &QFutureWatcher< QVector<HashData> >::finished, this, &PreviewAutoCacher::HashesProcessed);
watcher->setFuture(QtConcurrent::run(PreviewAutoCacher::GenerateHashes,
copied_viewer_node_,
viewer_node_->video_frame_cache(),
times));
}
// Handle video tasks
rational t;
while (video_tasks_.size() < max_tasks && queued_frame_iterator_.GetNext(&t)) {
@@ -747,7 +645,6 @@ void PreviewAutoCacher::RequeueFrames()
if (viewer_node_
&& (viewer_node_->GetVideoAutoCacheEnabled() || use_custom_range_)
&& viewer_node_->video_frame_cache()->HasInvalidatedRanges(viewer_node_->GetVideoLength())
&& hash_tasks_.isEmpty()
&& !IsRenderingCustomRange()) {
TimeRange using_range = use_custom_range_ ? custom_autocache_range_ : cache_range_;
@@ -834,15 +731,6 @@ void PreviewAutoCacher::SetViewerNode(ViewerOutput *viewer_node)
// Stop requeue timer if it's running
delayed_requeue_timer_.stop();
// Handle hashes
if (!hash_tasks_.isEmpty()) {
// Wait for hashes to finish
WaitForHashesToFinish();
// Clear the hash list to indicate we're not interested in the results of any of these
hash_tasks_.clear();
}
// Handle video rendering tasks
if (!video_tasks_.isEmpty()) {
// Cancel any video tasks and wait for them to finish
-24
View File
@@ -72,16 +72,6 @@ public:
*/
void SetPlayhead(const rational& playhead);
/**
* @brief If any hashes are currently running, wait for them to finish
*
* Once this function returns, it can be guaranteed that all hash tasks have been finished.
* They will NOT have been removed from the hash task list yet until they run HashesProcessed.
* If you don't want the continued processing in HashesProcessed to run, remove the task manually
* from the list after calling this function. It will still call HashesProcessed, but will be
* largely ignored (that function will simply free it).
*/
void WaitForHashesToFinish();
void WaitForVideoDownloadsToFinish();
/**
@@ -142,14 +132,6 @@ private:
void StartCachingVideoRange(const TimeRange &range);
void StartCachingAudioRange(const TimeRange &range);
struct HashData {
rational time;
QByteArray hash;
bool exists;
};
static QVector<HashData> GenerateHashes(ViewerOutput *viewer, FrameHashCache* cache, const QVector<rational> &times);
class QueuedJob {
public:
enum Type {
@@ -190,7 +172,6 @@ private:
RenderTicketPtr single_frame_render_;
QList<QFutureWatcher< QVector<HashData> >*> hash_tasks_;
QMap<RenderTicketWatcher*, TimeRange> audio_tasks_;
QMap<RenderTicketWatcher*, QByteArray> video_tasks_;
QMap<RenderTicketWatcher*, QByteArray> video_download_tasks_;
@@ -225,11 +206,6 @@ private slots:
*/
void AudioInvalidated(const olive::TimeRange &range);
/**
* @brief Handler for when we have applied all the hashes to the FrameHashCache
*/
void HashesProcessed();
/**
* @brief Handler for when the RenderManager has returned rendered audio
*/
+1 -16
View File
@@ -26,7 +26,6 @@
#include "config/config.h"
#include "core.h"
#include "node/hashtraverser.h"
#include "render/opengl/openglrenderer.h"
#include "render/rendererthreadwrapper.h"
#include "renderprocessor.h"
@@ -100,19 +99,6 @@ void RenderManager::ClearOldDecoders()
}
}
QByteArray RenderManager::Hash(const Node *n, const Node::ValueHint &output, const VideoParams &params, const rational &time)
{
Q_ASSERT(n);
if (n) {
HashTraverser hasher;
return hasher.GetHash(n, output, params, TimeRange(time, time + params.frame_rate_as_time_base()));
} else {
qCritical() << "Hash called with null node";
return QByteArray();
}
}
RenderTicketPtr RenderManager::RenderFrame(ViewerOutput *viewer, ColorManager* color_manager,
const rational& time, RenderMode::Mode mode,
FrameHashCache* cache, bool prioritize, bool texture_only)
@@ -201,14 +187,13 @@ RenderTicketPtr RenderManager::RenderAudio(ViewerOutput* viewer, const TimeRange
return ticket;
}
RenderTicketPtr RenderManager::SaveFrameToCache(FrameHashCache *cache, FramePtr frame, const QByteArray &hash, bool prioritize)
RenderTicketPtr RenderManager::SaveFrameToCache(FrameHashCache *cache, FramePtr frame, bool prioritize)
{
// Create ticket
RenderTicketPtr ticket = std::make_shared<RenderTicket>();
ticket->setProperty("cache", cache->GetCacheDirectory());
ticket->setProperty("frame", QVariant::fromValue(frame));
ticket->setProperty("hash", hash);
ticket->setProperty("type", kTypeVideoDownload);
if (ticket->thread() != this->thread()) {
+1 -6
View File
@@ -63,11 +63,6 @@ public:
return instance_;
}
/**
* @brief Generate a unique identifier for a certain node at a cconst Node *n, const Node::ValueHint &outputertain time
*/
static QByteArray Hash(const Node *n, const Node::ValueHint &output, const VideoParams &params, const rational &time);
/**
* @brief Asynchronously generate a frame at a given time
*
@@ -103,7 +98,7 @@ public:
RenderTicketPtr RenderAudio(ViewerOutput* viewer, const TimeRange& r, const AudioParams& params, RenderMode::Mode mode, bool generate_waveforms, bool prioritize = false);
RenderTicketPtr RenderAudio(ViewerOutput *viewer, const TimeRange& r, RenderMode::Mode mode, bool generate_waveforms, bool prioritize = false);
RenderTicketPtr SaveFrameToCache(FrameHashCache* cache, FramePtr frame, const QByteArray& hash, bool prioritize = false);
RenderTicketPtr SaveFrameToCache(FrameHashCache* cache, FramePtr frame, bool prioritize = false);
virtual void RunTicket(RenderTicketPtr ticket) const override;
+6 -10
View File
@@ -156,20 +156,16 @@ bool ExportTask::Run()
return success;
}
bool ExportTask::FrameDownloaded(FramePtr f, const QByteArray &hash, const QVector<rational> &times)
bool ExportTask::FrameDownloaded(FramePtr f, const rational &time)
{
Q_UNUSED(hash)
rational actual_time = time;
foreach (const rational& t, times) {
rational actual_time = t;
if (params_.has_custom_range()) {
actual_time -= params_.custom_range().in();
}
time_map_.insert(actual_time, f);
if (params_.has_custom_range()) {
actual_time -= params_.custom_range().in();
}
time_map_.insert(actual_time, f);
while (!IsCancelled()) {
rational real_time = Timecode::timestamp_to_time(frame_time_,
video_params().frame_rate_as_time_base());
+1 -1
View File
@@ -38,7 +38,7 @@ public:
protected:
virtual bool Run() override;
virtual bool FrameDownloaded(FramePtr frame, const QByteArray& hash, const QVector<rational>& times) override;
virtual bool FrameDownloaded(FramePtr frame, const rational &time) override;
virtual bool AudioDownloaded(const TimeRange& range, const SampleBuffer &samples) override;
+2 -3
View File
@@ -85,14 +85,13 @@ bool PreCacheTask::Run()
return true;
}
bool PreCacheTask::FrameDownloaded(FramePtr frame, const QByteArray &hash, const QVector<rational> &times)
bool PreCacheTask::FrameDownloaded(FramePtr frame, const rational &time)
{
// Do nothing. Pre-cache essentially just creates more frames in the cache, it doesn't need to do
// anything else.
Q_UNUSED(frame)
Q_UNUSED(hash)
Q_UNUSED(times)
Q_UNUSED(time)
return true;
}
+1 -1
View File
@@ -38,7 +38,7 @@ public:
protected:
virtual bool Run() override;
virtual bool FrameDownloaded(FramePtr frame, const QByteArray& hash, const QVector<rational>& times) override;
virtual bool FrameDownloaded(FramePtr frame, const rational &times) override;
virtual bool AudioDownloaded(const TimeRange& range, const SampleBuffer &samples) override;
+12 -64
View File
@@ -74,58 +74,17 @@ bool RenderTask::Render(ColorManager* manager,
}
// Look up hashes
QMap<QByteArray, QVector<rational> > time_map;
QVector<QPair<rational, QByteArray> > frame_render_order;
if (!video_range.isEmpty() && viewer()->GetConnectedTextureOutput()) {
// Get list of discrete frames from range
TimeRangeListFrameIterator iterator(video_range, video_params().frame_rate_as_time_base());
QVector<rational> times(iterator.size());
QVector<QByteArray> hashes(iterator.size());
// Generate hashes
rational r;
for (int i=0; iterator.GetNext(&r); i++) {
if (IsCancelled()) {
break;
}
times[i] = r;
hashes[i] = RenderManager::instance()->Hash(viewer()->GetConnectedTextureOutput(), viewer()->GetConnectedTextureValueHint(), video_params_, r);
}
// Filter out duplicates
for (int i=0; i<hashes.size(); i++) {
if (IsCancelled()) {
break;
}
const QByteArray& hash = hashes.at(i);
QVector<rational>& hash_time_list = time_map[hash];
hash_time_list.append(times.at(i));
if (hash_time_list.size() == 1) {
frame_render_order.append({times.at(i), hash});
}
}
// Add to "total progress"
total_number_of_frames_ = times.size();
total_number_of_unique_frames_ = time_map.size();
total_length += total_number_of_unique_frames_;
}
TimeRangeListFrameIterator iterator(video_range, video_params().frame_rate_as_time_base());
// Start a render of a limited amount, and then render one frame for each frame that gets
// finished. This prevents rendered frames from stacking up in memory indefinitely while the
// encoder is processing them. The amount is kind of arbitrary, but we use the thread count so
// each of the system's threads are utilized as memory allows.
const int maximum_rendered_frames = QThread::idealThreadCount();
auto frame_iterator = frame_render_order.cbegin();
for (int i=0; i<maximum_rendered_frames && frame_iterator!=frame_render_order.cend(); i++, frame_iterator++) {
StartTicket(frame_iterator->second, &watcher_thread, manager, frame_iterator->first,
mode, cache, force_size, force_matrix, force_format, force_color_output);
rational next_frame;
for (int i=0; i<maximum_rendered_frames && iterator.GetNext(&next_frame); i++) {
StartTicket(&watcher_thread, manager, next_frame, mode, cache, force_size, force_matrix, force_format, force_color_output);
}
bool result = true;
@@ -206,9 +165,7 @@ bool RenderTask::Render(ColorManager* manager,
} else if (ticket_type == RenderManager::kTypeVideo && TwoStepFrameRendering()) {
if (!DownloadFrame(&watcher_thread,
watcher->Get().value<FramePtr>(),
watcher->property("hash").toByteArray())) {
if (!DownloadFrame(&watcher_thread, watcher->Get().value<FramePtr>())) {
result = false;
}
@@ -220,8 +177,7 @@ bool RenderTask::Render(ColorManager* manager,
} else {
// Assume single-step video or video download ticket
QByteArray rendered_hash = watcher->property("hash").toByteArray();
if (!FrameDownloaded(watcher->Get().value<FramePtr>(), rendered_hash, time_map.value(rendered_hash))) {
if (!FrameDownloaded(watcher->Get().value<FramePtr>(), watcher->property("time").value<rational>())) {
result = false;
}
@@ -235,11 +191,8 @@ bool RenderTask::Render(ColorManager* manager,
emit ProgressChanged(progress_counter / total_length);
}
if (frame_iterator != frame_render_order.cend()) {
StartTicket(frame_iterator->second, &watcher_thread, manager, frame_iterator->first,
mode, cache, force_size, force_matrix, force_format, force_color_output);
frame_iterator++;
if (iterator.GetNext(&next_frame)) {
StartTicket(&watcher_thread, manager, next_frame, mode, cache, force_size, force_matrix, force_format, force_color_output);
}
}
@@ -284,17 +237,14 @@ bool RenderTask::Render(ColorManager* manager,
return result;
}
bool RenderTask::DownloadFrame(QThread *thread, FramePtr frame, const QByteArray &hash)
bool RenderTask::DownloadFrame(QThread *thread, FramePtr frame)
{
RenderTicketWatcher* watcher = new RenderTicketWatcher();
watcher->setProperty("hash", hash);
PrepareWatcher(watcher, thread);
IncrementRunningTickets();
watcher->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_->video_frame_cache(),
frame,
hash));
watcher->SetTicket(RenderManager::instance()->SaveFrameToCache(viewer_->video_frame_cache(), frame));
// NOTE: Doesn't reflect the actual return result of SaveFrameToCache
return true;
@@ -320,17 +270,15 @@ void RenderTask::IncrementRunningTickets()
finished_watcher_mutex_.unlock();
}
void RenderTask::StartTicket(const QByteArray& hash, QThread* watcher_thread, ColorManager* manager,
void RenderTask::StartTicket(QThread* watcher_thread, ColorManager* manager,
const rational& time, RenderMode::Mode mode, FrameHashCache* cache,
const QSize &force_size, const QMatrix4x4 &force_matrix,
VideoParams::Format force_format, ColorProcessorPtr force_color_output)
{
RenderTicketWatcher* watcher = new RenderTicketWatcher();
watcher->setProperty("hash", hash);
watcher->setProperty("time", QVariant::fromValue(time));
PrepareWatcher(watcher, watcher_thread);
IncrementRunningTickets();
watcher->SetTicket(RenderManager::instance()->RenderFrame(viewer_, manager, time,
mode, video_params_, audio_params_,
force_size, force_matrix,
+3 -3
View File
@@ -49,9 +49,9 @@ protected:
VideoParams::Format force_format = VideoParams::kFormatInvalid,
ColorProcessorPtr force_color_output = nullptr);
virtual bool DownloadFrame(QThread* thread, FramePtr frame, const QByteArray &hash);
virtual bool DownloadFrame(QThread* thread, FramePtr frame);
virtual bool FrameDownloaded(FramePtr frame, const QByteArray& hash, const QVector<rational>& times) = 0;
virtual bool FrameDownloaded(FramePtr frame, const rational &time) = 0;
virtual bool AudioDownloaded(const TimeRange& range, const SampleBuffer &samples) = 0;
@@ -125,7 +125,7 @@ private:
void IncrementRunningTickets();
void StartTicket(const QByteArray &hash, QThread *watcher_thread, ColorManager *manager, const rational &time, RenderMode::Mode mode, FrameHashCache *cache, const QSize &force_size, const QMatrix4x4 &force_matrix, VideoParams::Format force_format, ColorProcessorPtr force_color_output);
void StartTicket(QThread *watcher_thread, ColorManager *manager, const rational &time, RenderMode::Mode mode, FrameHashCache *cache, const QSize &force_size, const QMatrix4x4 &force_matrix, VideoParams::Format force_format, ColorProcessorPtr force_color_output);
ViewerOutput* viewer_;