improved renderer reliability

The renderer backend can now distinguish between jobs. Previously if two jobs
of the same frame were started (which is legal if the user made a change while
frames were still being rendered), an earlier job in some situations could
finish AFTER a later job, and the backend would have no way of distinguishing
between them. This meant a frame could be erroneously set to an old value
rather than the newest. This commit introduces job identification so that old
jobs are automatically discarded.
This commit is contained in:
itsmattkc
2020-01-02 03:21:38 +11:00
parent 62e94ca2cb
commit e8fddc2d5b
12 changed files with 147 additions and 160 deletions
+31 -27
View File
@@ -49,42 +49,46 @@ void AudioBackend::DecompileInternal()
void AudioBackend::ConnectWorkerToThis(RenderWorker *worker)
{
connect(worker, SIGNAL(CompletedCache(NodeDependency, NodeValueTable)), this, SLOT(ThreadCompletedCache(NodeDependency, NodeValueTable)));
connect(worker, &RenderWorker::CompletedCache, this, &AudioBackend::ThreadCompletedCache);
}
void AudioBackend::ThreadCompletedCache(NodeDependency dep, NodeValueTable data)
void AudioBackend::ThreadCompletedCache(NodeDependency dep, NodeValueTable data, qint64 job_time)
{
SetWorkerBusyState(static_cast<RenderWorker*>(sender()), false);
QByteArray cached_samples = data.Get(NodeParam::kSamples).toByteArray();
if (job_time == render_job_info_.value(dep.range())) {
render_job_info_.remove(dep.range());
int offset = params().time_to_bytes(dep.in());
int length = params().time_to_bytes(dep.range().length());
int out_point = offset + length;
QByteArray cached_samples = data.Get(NodeParam::kSamples).toByteArray();
QFile f(CachePathName());
if (f.open(QFile::WriteOnly | QFile::Append)) {
int offset = params().time_to_bytes(dep.in());
int length = params().time_to_bytes(dep.range().length());
int out_point = offset + length;
if (f.size() < out_point) {
f.resize(out_point);
QFile f(CachePathName());
if (f.open(QFile::WriteOnly | QFile::Append)) {
if (f.size() < out_point) {
f.resize(out_point);
}
f.seek(offset);
// Replace data with this data
int copy_length = qMin(length, cached_samples.size());
f.write(cached_samples.data(), copy_length);
if (copy_length < length) {
// Fill in remainder with silence
QByteArray empty_space(length - copy_length, 0);
f.write(empty_space);
}
f.close();
} else {
qWarning() << "Failed to write to cached PCM file";
}
f.seek(offset);
// Replace data with this data
int copy_length = qMin(length, cached_samples.size());
f.write(cached_samples.data(), copy_length);
if (copy_length < length) {
// Fill in remainder with silence
QByteArray empty_space(length - copy_length, 0);
f.write(empty_space);
}
f.close();
} else {
qWarning() << "Failed to write to cached PCM file";
}
CacheNext();