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
+37 -7
View File
@@ -10,11 +10,6 @@ RenderBackend::RenderBackend(QObject *parent) :
started_(false),
viewer_node_(nullptr)
{
}
RenderBackend::~RenderBackend()
{
}
bool RenderBackend::Init()
@@ -35,6 +30,9 @@ bool RenderBackend::Init()
started_ = InitInternal();
// Connects workers and moves them to their respective threads
InitWorkers();
if (!started_) {
Close();
}
@@ -163,7 +161,7 @@ void RenderBackend::CacheNext()
TimeRange cache_frame = cache_queue_.takeFirst();
qDebug() << "Caching FRAME" << cache_frame.in() << "to" << cache_frame.out();
//qDebug() << "Caching FRAME" << cache_frame.in() << "to" << cache_frame.out();
caching_ = GenerateData(cache_frame);
}
@@ -175,7 +173,7 @@ bool RenderBackend::GenerateData(const TimeRange &range)
return false;
}
NodeDependency dep = NodeDependency(viewer_node()->texture_input()->get_connected_output(), range.in(), range.out());
NodeDependency dep = NodeDependency(GetDependentInput()->get_connected_output(), range.in(), range.out());
foreach (RenderWorker* worker, processors_) {
if (worker->IsAvailable() || worker == processors_.last()) {
@@ -214,3 +212,35 @@ void RenderBackend::CacheIDChangedEvent(const QString &id)
{
Q_UNUSED(id)
}
void RenderBackend::InitWorkers()
{
for (int i=0;i<processors_.size();i++) {
RenderWorker* processor = processors_.at(i);
QThread* thread = threads().at(i);
// Connect to it
connect(processor, SIGNAL(RequestSibling(NodeDependency)), this, SLOT(ThreadRequestedSibling(NodeDependency)));
ConnectWorkerToThis(processor);
// Finally, we can move it to its own thread
processor->moveToThread(thread);
// This function blocks the main thread intentionally. See the documentation for this function to see why.
processor->Init();
}
}
void RenderBackend::ThreadRequestedSibling(NodeDependency dep)
{
// Try to queue another thread to run this dep in advance
foreach (RenderWorker* worker, processors_) {
if (worker->IsAvailable()) {
QMetaObject::invokeMethod(worker,
"RenderAsSibling",
Qt::QueuedConnection,
Q_ARG(NodeDependency, dep));
return;
}
}
}