overhauled render classes to support video AND audio

Major refactoring work to try sharing as much code as possible between the
video renderers and audio renderers, as well as make them as
platform-independent as possible.
This commit is contained in:
itsmattkc
2019-11-15 13:50:58 +09:00
parent 9a44e656b5
commit 40b3879440
26 changed files with 628 additions and 299 deletions
+53 -1
View File
@@ -1,13 +1,34 @@
#include "audiobackend.h"
#include "audioworker.h"
AudioBackend::AudioBackend(QObject *parent) :
AudioRenderBackend(parent)
{
}
AudioBackend::~AudioBackend()
{
Close();
}
QIODevice *AudioBackend::GetAudioPullDevice()
{
pull_device_.setFileName(CachePathName());
return &pull_device_;
}
bool AudioBackend::InitInternal()
{
// This backend doesn't init anything yet
// Initiate one thread per CPU core
for (int i=0;i<threads().size();i++) {
// Create one processor object for each thread
AudioWorker* processor = new AudioWorker(decoder_cache());
processor->SetParameters(params());
processors_.append(processor);
}
return true;
}
@@ -26,3 +47,34 @@ void AudioBackend::DecompileInternal()
{
// This backend doesn't compile anything yet
}
void AudioBackend::ConnectWorkerToThis(RenderWorker *worker)
{
connect(worker, SIGNAL(CompletedCache(NodeDependency)), this, SLOT(ThreadCompletedCache(NodeDependency)));
}
void AudioBackend::ThreadCompletedCache(NodeDependency dep)
{
caching_ = false;
QByteArray cached_samples = dep.node()->get_cached_value(dep.range()).toByteArray();
int offset = params().time_to_bytes(dep.in());
int length = params().time_to_bytes(dep.range().length());
int out_point = offset + length;
if (pcm_data_.size() < out_point) {
pcm_data_.resize(out_point);
}
// Replace data with this data
memcpy(pcm_data_.data() + offset, cached_samples.data(), static_cast<size_t>(length));
QFile f(CachePathName());
if (f.open(QFile::WriteOnly)) {
f.write(pcm_data_);
f.close();
}
CacheNext();
}