various changes to rendering flow and structure

This commit is contained in:
itsmattkc
2019-10-23 00:42:52 +11:00
parent 5f86b9b9c7
commit 7dec79ceaa
42 changed files with 663 additions and 888 deletions
+2
View File
@@ -16,6 +16,8 @@
set(OLIVE_SOURCES
${OLIVE_SOURCES}
render/audio/audioparams.h
render/audio/audioparams.cpp
render/audio/audiorenderer.h
render/audio/audiorenderer.cpp
render/audio/audiorendererdownloadthread.h
+89
View File
@@ -0,0 +1,89 @@
#include "audioparams.h"
extern "C" {
#include <libavformat/avformat.h>
}
AudioParams::AudioParams() :
sample_rate_(0),
channel_layout_(0)
{
}
AudioParams::AudioParams(const int &sample_rate, const uint64_t &channel_layout) :
sample_rate_(sample_rate),
channel_layout_(channel_layout)
{
}
const int &AudioParams::sample_rate() const
{
return sample_rate_;
}
const uint64_t &AudioParams::channel_layout() const
{
return channel_layout_;
}
AudioRenderingParams::AudioRenderingParams() :
format_(olive::SAMPLE_FMT_INVALID)
{
}
AudioRenderingParams::AudioRenderingParams(const int &sample_rate, const uint64_t &channel_layout, const olive::SampleFormat &format) :
AudioParams(sample_rate, channel_layout),
format_(format)
{
}
AudioRenderingParams::AudioRenderingParams(const AudioParams &params, const olive::SampleFormat &format) :
AudioParams(params),
format_(format)
{
}
const olive::SampleFormat &AudioRenderingParams::format() const
{
return format_;
}
int AudioRenderingParams::time_to_bytes(const rational &time) const
{
Q_ASSERT(is_valid());
return qFloor(time.toDouble() * sample_rate()) * channel_count() * sample_size();
}
int AudioRenderingParams::channel_count() const
{
return av_get_channel_layout_nb_channels(channel_layout());
}
int AudioRenderingParams::sample_size() const
{
switch (format_) {
case olive::SAMPLE_FMT_U8:
return 1;
case olive::SAMPLE_FMT_S16:
return 2;
case olive::SAMPLE_FMT_S32:
case olive::SAMPLE_FMT_FLT:
return 4;
case olive::SAMPLE_FMT_DBL:
return 8;
case olive::SAMPLE_FMT_INVALID:
case olive::SAMPLE_FMT_COUNT:
break;
}
return 0;
}
bool AudioRenderingParams::is_valid() const
{
return (sample_rate() > 0
&& channel_layout() > 0
&& format_ != olive::SAMPLE_FMT_INVALID
&& format_ != olive::SAMPLE_FMT_COUNT);
}
+42
View File
@@ -0,0 +1,42 @@
#ifndef AUDIOPARAMS_H
#define AUDIOPARAMS_H
#include <QtMath>
#include "audio/sampleformat.h"
#include "common/rational.h"
class AudioParams
{
public:
AudioParams();
AudioParams(const int& sample_rate, const uint64_t& channel_layout);
const int& sample_rate() const;
const uint64_t& channel_layout() const;
private:
int sample_rate_;
uint64_t channel_layout_;
};
class AudioRenderingParams : public AudioParams {
public:
AudioRenderingParams();
AudioRenderingParams(const int& sample_rate, const uint64_t& channel_layout, const olive::SampleFormat& format);
AudioRenderingParams(const AudioParams& params, const olive::SampleFormat& format);
int time_to_bytes(const rational& time) const;
int channel_count() const;
int sample_size() const;
bool is_valid() const;
const olive::SampleFormat& format() const;
private:
olive::SampleFormat format_;
};
#endif // AUDIOPARAMS_H
+58 -288
View File
@@ -36,11 +36,7 @@
AudioRendererProcessor::AudioRendererProcessor(QObject *parent) :
QObject(parent),
started_(false),
width_(0),
height_(0),
divider_(1),
caching_(false),
push_time_(-1),
starting_(false),
viewer_node_(nullptr)
{
@@ -63,10 +59,6 @@ void AudioRendererProcessor::SetCacheName(const QString &s)
void AudioRendererProcessor::InvalidateCache(const rational &start_range, const rational &end_range)
{
if (timebase_.isNull()) {
return;
}
// Adjust range to min/max values
rational start_range_adj = qMax(rational(0), start_range);
rational end_range_adj = qMin(viewer_node_->Length(), end_range);
@@ -76,101 +68,45 @@ void AudioRendererProcessor::InvalidateCache(const rational &start_range, const
<< "and"
<< end_range_adj.toDouble();
// Snap start_range to timebase
double start_range_dbl = start_range_adj.toDouble();
double start_range_numf = start_range_dbl * static_cast<double>(timebase_.denominator());
int64_t start_range_numround = qFloor(start_range_numf/static_cast<double>(timebase_.numerator())) * timebase_.numerator();
rational true_start_range(start_range_numround, timebase_.denominator());
bool append = true;
for (rational r=true_start_range;r<=end_range_adj;r+=timebase_) {
// Try to order the queue from closest to the playhead to furthest
rational last_time = last_time_requested_;
for (int i=0;i<cache_queue_.size();i++) {
const TimeRange& const_range = cache_queue_.at(i);
rational diff = r - last_time;
if (diff < 0) {
// FIXME: Hardcoded number
// If the number is before the playhead, we still prioritize its closeness but not nearly as much (5:1 in this
// example)
diff = qAbs(diff) * 5;
}
bool contains = false;
bool added = false;
QLinkedList<rational>::iterator insert_iterator;
for (QLinkedList<rational>::iterator i = cache_queue_.begin();i != cache_queue_.end();i++) {
rational compare = *i;
if (!added) {
rational compare_diff = compare - last_time;
if (compare_diff > diff) {
insert_iterator = i;
added = true;
}
if (start_range_adj >= const_range.in()
&& start_range_adj <= const_range.out()) {
append = false;
if (const_range.out() < end_range_adj) {
// Same in point but longer, extend
cache_queue_[i].set_out(end_range_adj);
}
if (compare == r) {
contains = true;
break;
break;
} else if (end_range_adj <= const_range.out()
&& end_range_adj >= const_range.in()) {
append = false;
if (const_range.in() > start_range_adj) {
// Same out point but longer, extend
cache_queue_[i].set_in(start_range_adj);
}
break;
}
}
if (!contains) {
if (added) {
cache_queue_.insert(insert_iterator, r);
} else {
cache_queue_.append(r);
}
}
if (append) {
cache_queue_.append(TimeRange(start_range_adj, end_range_adj));
}
CacheNext();
}
void AudioRendererProcessor::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
timebase_dbl_ = timebase_.toDouble();
}
void AudioRendererProcessor::SetParameters(const int &width,
const int &height,
const olive::PixelFormat &format,
const olive::RenderMode &mode,
const int& divider)
void AudioRendererProcessor::SetParameters(const AudioRenderingParams& params)
{
// Since we're changing parameters, all the existing threads are invalid and must be removed. They will start again
// next time this Node has to process anything.
Stop();
// Set new parameters
width_ = width;
height_ = height;
format_ = format;
mode_ = mode;
// divider's default value is 0, so we can assume if it's 0 a divider wasn't specified
if (divider > 0) {
divider_ = divider;
}
CalculateEffectiveDimensions();
// Regenerate the cache ID
GenerateCacheIDInternal();
}
void AudioRendererProcessor::SetDivider(const int &divider)
{
Q_ASSERT(divider_ > 0);
Stop();
divider_ = divider;
CalculateEffectiveDimensions();
params_ = params;
// Regenerate the cache ID
GenerateCacheIDInternal();
@@ -193,7 +129,7 @@ void AudioRendererProcessor::Start()
threads_.resize(background_thread_count);
for (int i=0;i<threads_.size();i++) {
threads_[i] = std::make_shared<AudioRendererProcessThread>(this, ctx, effective_width_, effective_height_, divider_, format_, mode_);
threads_[i] = std::make_shared<AudioRendererProcessThread>(this, params_);
threads_[i]->StartThread(QThread::LowPriority);
// Ensure this connection is "Queued" so that it always runs in this object's threaded rather than any of the
@@ -207,46 +143,14 @@ void AudioRendererProcessor::Start()
// Connect first thread (master thread) to the callback
connect(threads_.first().get(),
SIGNAL(CachedFrame(RenderTexturePtr, const rational&, const QByteArray&)),
SIGNAL(CachedFrame(const QByteArray&, const rational&, const rational&)),
this,
SLOT(ThreadCallback(RenderTexturePtr, const rational&, const QByteArray&)),
SLOT(ThreadCallback(const QByteArray&, const rational&, const rational&)),
Qt::QueuedConnection);
connect(threads_.first().get(),
SIGNAL(FrameSkipped(const rational&, const QByteArray&)),
this,
SLOT(ThreadSkippedFrame(const rational&, const QByteArray&)),
Qt::QueuedConnection);
download_threads_.resize(background_thread_count);
for (int i=0;i<download_threads_.size();i++) {
// Create download thread
download_threads_[i] = std::make_shared<AudioRendererDownloadThread>(ctx, effective_width_, effective_height_, divider_, format_, mode_);
download_threads_[i]->StartThread(QThread::LowPriority);
connect(download_threads_[i].get(),
SIGNAL(Downloaded(const QByteArray&)),
this,
SLOT(DownloadThreadComplete(const QByteArray&)),
Qt::QueuedConnection);
}
last_download_thread_ = 0;
// Restore context now that thread creation is complete
ctx->makeCurrent(old_surface);
// Create master texture (the one sent to the viewer)
master_texture_ = std::make_shared<RenderTexture>();
master_texture_->Create(ctx, effective_width_, effective_height_, format_);
// Create internal FBO for copying textures
copy_buffer_.Create(ctx);
copy_buffer_.Attach(master_texture_);
copy_pipeline_ = olive::ShaderGenerator::DefaultPipeline();
cache_frame_load_buffer_.resize(PixelService::GetBufferSize(format_, effective_width_, effective_height_));
started_ = true;
}
@@ -258,26 +162,15 @@ void AudioRendererProcessor::Stop()
started_ = false;
foreach (AudioRendererDownloadThreadPtr download_thread_, download_threads_) {
download_thread_->Cancel();
}
download_threads_.clear();
foreach (AudioRendererProcessThreadPtr process_thread, threads_) {
process_thread->Cancel();
}
threads_.clear();
copy_buffer_.Destroy();
master_texture_ = nullptr;
copy_pipeline_ = nullptr;
cache_frame_load_buffer_.clear();
}
void AudioRendererProcessor::GenerateCacheIDInternal()
{
if (cache_name_.isEmpty() || effective_width_ == 0 || effective_height_ == 0) {
if (cache_name_.isEmpty() || !params_.is_valid()) {
return;
}
@@ -285,10 +178,9 @@ void AudioRendererProcessor::GenerateCacheIDInternal()
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(cache_name_.toUtf8());
hash.addData(QString::number(cache_time_).toUtf8());
hash.addData(QString::number(width_).toUtf8());
hash.addData(QString::number(height_).toUtf8());
hash.addData(QString::number(format_).toUtf8());
hash.addData(QString::number(divider_).toUtf8());
hash.addData(QString::number(params_.sample_rate()).toUtf8());
hash.addData(QString::number(params_.channel_layout()).toUtf8());
hash.addData(QString::number(params_.format()).toUtf8());
QByteArray bytes = hash.result();
cache_id_ = bytes.toHex();
@@ -303,9 +195,9 @@ void AudioRendererProcessor::CacheNext()
// Make sure cache has started
Start();
rational cache_frame = cache_queue_.takeFirst();
TimeRange cache_frame = cache_queue_.takeFirst();
qDebug() << "Caching" << cache_frame.toDouble();
qDebug() << "Caching" << cache_frame.in().toDouble() << "-" << cache_frame.out().toDouble();
threads_.first()->Queue(NodeDependency(viewer_node_->texture_input()->get_connected_output(), cache_frame), true, false);
@@ -317,90 +209,25 @@ QString AudioRendererProcessor::CachePathName(const QByteArray &hash)
QDir this_cache_dir = QDir(GetMediaCacheLocation()).filePath(cache_id_);
this_cache_dir.mkpath(".");
QString filename = QString("%1.exr").arg(QString(hash.toHex()));
QString filename = QString("%1.pcm").arg(QString(hash.toHex()));
return this_cache_dir.filePath(filename);
}
void AudioRendererProcessor::DeferMap(const rational &time, const QByteArray &hash)
{
deferred_maps_.append({time, hash});
}
bool AudioRendererProcessor::HasHash(const QByteArray &hash)
{
return QFileInfo::exists(CachePathName(hash));
}
bool AudioRendererProcessor::IsCaching(const QByteArray &hash)
{
cache_hash_list_mutex_.lock();
bool is_caching = cache_hash_list_.contains(hash);
cache_hash_list_mutex_.unlock();
return is_caching;
}
bool AudioRendererProcessor::TryCache(const QByteArray &hash)
{
cache_hash_list_mutex_.lock();
bool is_caching = cache_hash_list_.contains(hash);
if (!is_caching) {
cache_hash_list_.append(hash);
}
cache_hash_list_mutex_.unlock();
return !is_caching;
}
void AudioRendererProcessor::CalculateEffectiveDimensions()
{
effective_width_ = width_ / divider_;
effective_height_ = height_ / divider_;
}
void AudioRendererProcessor::ThreadCallback(RenderTexturePtr texture, const rational& time, const QByteArray& hash)
void AudioRendererProcessor::ThreadCallback(const QByteArray& samples, const rational& in, const rational& out)
{
// Threads are all done now, time to proceed
caching_ = false;
DeferMap(time, hash);
int start_offset = params_.time_to_bytes(in);
int end_offset = params_.time_to_bytes(out);
if (texture != nullptr) {
// We received a texture, time to start downloading it
QString fn = CachePathName(hash);
download_threads_[last_download_thread_%download_threads_.size()]->Queue(texture,
fn,
hash);
last_download_thread_++;
} else {
// There was no texture here, we must update the viewer
DownloadThreadComplete(hash);
// Ensure sample cache is at least large enough for this
if (sample_cache_.size() < end_offset) {
sample_cache_.resize(end_offset);
}
// If the connected output is using this time, signal it to update
if (last_time_requested_ == time) {
copy_buffer_.Bind();
texture->Bind();
QOpenGLContext::currentContext()->functions()->glViewport(0, 0, master_texture_->width(), master_texture_->height());
olive::gl::Blit(copy_pipeline_);
texture->Release();
copy_buffer_.Release();
push_time_ = time;
emit CachedFrameReady(time);
}
sample_cache_.replace(start_offset, samples.size(), samples);
CacheNext();
}
@@ -415,107 +242,53 @@ void AudioRendererProcessor::ThreadRequestSibling(NodeDependency dep)
}
}
void AudioRendererProcessor::ThreadSkippedFrame(const rational& time, const QByteArray& hash)
{
caching_ = false;
DeferMap(time, hash);
if (!IsCaching(hash)) {
DownloadThreadComplete(hash);
// Signal output to update value
emit CachedFrameReady(time);
}
CacheNext();
}
void AudioRendererProcessor::DownloadThreadComplete(const QByteArray &hash)
{
cache_hash_list_mutex_.lock();
cache_hash_list_.removeAll(hash);
cache_hash_list_mutex_.unlock();
for (int i=0;i<deferred_maps_.size();i++) {
const HashTimeMapping& deferred = deferred_maps_.at(i);
if (deferred_maps_.at(i).hash == hash) {
// Insert into hash map
time_hash_map_.insert(deferred.time, deferred.hash);
deferred_maps_.removeAt(i);
i--;
}
}
}
AudioRendererThreadBase* AudioRendererProcessor::CurrentThread()
{
return dynamic_cast<AudioRendererThreadBase*>(QThread::currentThread());
}
RenderInstance *AudioRendererProcessor::CurrentInstance()
AudioParams *AudioRendererProcessor::CurrentInstance()
{
AudioRendererThreadBase* thread = CurrentThread();
if (thread != nullptr) {
return thread->render_instance();
return thread->params();
}
return nullptr;
}
RenderTexturePtr AudioRendererProcessor::GetCachedFrame(const rational &time)
QByteArray AudioRendererProcessor::GetCachedSamples(const rational &in, const rational &out)
{
last_time_requested_ = time;
if (push_time_ >= 0) {
rational temp_push_time = push_time_;
push_time_ = -1;
if (time == temp_push_time) {
return master_texture_;
}
}
if (viewer_node_ == nullptr) {
if (viewer_node_ == nullptr || in == out) {
// Nothing is connected - nothing to show or render
return nullptr;
}
if (!params_.is_valid()) {
qWarning() << "Invalid parameters";
return nullptr;
}
if (cache_id_.isEmpty()) {
qWarning() << "RendererProcessor has no cache ID";
qWarning() << "No cache ID";
return nullptr;
}
if (timebase_.isNull()) {
qWarning() << "RendererProcessor has no timebase";
if (out < in || in < 0 || out < 0) {
qWarning() << "Invalid time requested";
return nullptr;
}
// Find frame in map
if (time_hash_map_.contains(time)) {
QString fn = CachePathName(time_hash_map_[time]);
int start_offset = qMin(params_.time_to_bytes(in), sample_cache_.size());
int end_offset = qMin(params_.time_to_bytes(out), sample_cache_.size());
int length = end_offset - start_offset;
if (QFileInfo::exists(fn)) {
auto in = OIIO::ImageInput::open(fn.toStdString());
if (in) {
in->read_image(PixelService::GetPixelFormatInfo(format_).oiio_desc, cache_frame_load_buffer_.data());
in->close();
master_texture_->Upload(cache_frame_load_buffer_.data());
return master_texture_;
} else {
qWarning() << "OIIO Error:" << OIIO::geterror().c_str();
}
}
if (length == 0) {
return nullptr;
}
return nullptr;
return sample_cache_.mid(start_offset, length);
}
void AudioRendererProcessor::SetViewerNode(ViewerOutput *viewer)
@@ -530,9 +303,6 @@ void AudioRendererProcessor::SetViewerNode(ViewerOutput *viewer)
connect(viewer_node_, SIGNAL(TextureChangedBetween(const rational&, const rational&)), this, SLOT(InvalidateCache(const rational&, const rational&)));
// FIXME: Hardcoded format and mode
SetParameters(viewer_node_->ViewerWidth(),
viewer_node_->ViewerHeight(),
olive::PIX_FMT_RGBA16F,
olive::kOffline);
AudioRenderingParams(viewer_node_->audio_params(), olive::SAMPLE_FMT_FLT);
}
}
+9 -78
View File
@@ -24,6 +24,7 @@
#include <QLinkedList>
#include <QOpenGLTexture>
#include "common/timerange.h"
#include "node/output/viewer/viewer.h"
#include "render/pixelformat.h"
#include "render/rendermodes.h"
@@ -49,8 +50,6 @@ public:
void SetCacheName(const QString& s);
void SetTimebase(const rational& timebase);
/**
* @brief Set parameters of the Renderer
*
@@ -69,28 +68,7 @@ public:
*
* Buffer pixel format
*/
void SetParameters(const int& width,
const int& height,
const olive::PixelFormat& format,
const olive::RenderMode& mode,
const int &divider = 0);
void SetDivider(const int& divider);
/**
* @brief Return whether a frame with this hash already exists
*/
bool HasHash(const QByteArray& hash);
/**
* @brief Return whether a frame is currently being cached
*/
bool IsCaching(const QByteArray& hash);
/**
* @brief Check if a frame is currently being cached, and if not reserve it
*/
bool TryCache(const QByteArray& hash);
void SetParameters(const AudioRenderingParams &params);
/**
* @brief Return current instance of a RenderThread (or nullptr if there is none)
@@ -100,21 +78,13 @@ public:
*/
static AudioRendererThreadBase* CurrentThread();
static RenderInstance* CurrentInstance();
static AudioParams* CurrentInstance();
RenderTexturePtr GetCachedFrame(const rational& time);
QByteArray GetCachedSamples(const rational& in, const rational& out);
void SetViewerNode(ViewerOutput* viewer);
signals:
void CachedFrameReady(const rational& time);
private:
struct HashTimeMapping {
rational time;
QByteArray hash;
};
/**
* @brief Allocate and start the multithreaded backend
*/
@@ -137,15 +107,11 @@ private:
*/
void CacheNext();
bool ShouldPushTexture(const rational &time);
/**
* @brief Return the path of the cached image at this time
*/
QString CachePathName(const QByteArray &hash);
void DeferMap(const rational &time, const QByteArray &hash);
/**
* @brief Internal list of RenderProcessThreads
*/
@@ -156,63 +122,28 @@ private:
*/
bool started_;
int width_;
int height_;
AudioRenderingParams params_;
void CalculateEffectiveDimensions();
int divider_;
int effective_width_;
int effective_height_;
olive::PixelFormat format_;
olive::RenderMode mode_;
rational last_time_requested_;
rational timebase_;
double timebase_dbl_;
QLinkedList<rational> cache_queue_;
QList<TimeRange> cache_queue_;
QString cache_name_;
qint64 cache_time_;
QString cache_id_;
bool caching_;
QVector<uchar*> cache_frame_load_buffer_;
QVector<AudioRendererDownloadThreadPtr> download_threads_;
int last_download_thread_;
RenderTexturePtr master_texture_;
rational push_time_;
RenderFramebuffer copy_buffer_;
ShaderPtr copy_pipeline_;
QMap<rational, QByteArray> time_hash_map_;
QMutex cache_hash_list_mutex_;
QVector<QByteArray> cache_hash_list_;
QList<HashTimeMapping> deferred_maps_;
bool starting_;
ViewerOutput* viewer_node_;
QByteArray sample_cache_;
private slots:
void InvalidateCache(const rational &start_range, const rational &end_range);
void ThreadCallback(RenderTexturePtr texture, const rational& time, const QByteArray& hash);
void ThreadCallback(const QByteArray& samples, const rational& in, const rational &out);
void ThreadRequestSibling(NodeDependency dep);
void ThreadSkippedFrame(const rational &time, const QByteArray &hash);
void DownloadThreadComplete(const QByteArray &hash);
};
#endif // AUDIORENDERER_H
@@ -7,7 +7,7 @@
#include "common/define.h"
#include "render/pixelservice.h"
AudioRendererDownloadThread::AudioRendererDownloadThread(QOpenGLContext *share_ctx,
/*AudioRendererDownloadThread::AudioRendererDownloadThread(QOpenGLContext *share_ctx,
const int &width,
const int &height,
const int &divider,
@@ -125,4 +125,4 @@ void AudioRendererDownloadThread::ProcessLoop()
}
f->glDeleteFramebuffers(1, &read_buffer_);
}
}*/
@@ -3,7 +3,7 @@
#include "audiorendererthreadbase.h"
class AudioRendererDownloadThread : public AudioRendererThreadBase
/*class AudioRendererDownloadThread : public AudioRendererThreadBase
{
Q_OBJECT
public:
@@ -44,6 +44,6 @@ private:
};
using AudioRendererDownloadThreadPtr = std::shared_ptr<AudioRendererDownloadThread>;
using AudioRendererDownloadThreadPtr = std::shared_ptr<AudioRendererDownloadThread>;*/
#endif // AUDIORENDERERDOWNLOADTHREAD_H
+12 -51
View File
@@ -23,13 +23,8 @@
#include "audiorenderer.h"
AudioRendererProcessThread::AudioRendererProcessThread(AudioRendererProcessor* parent,
QOpenGLContext *share_ctx,
const int &width,
const int &height,
const int &divider,
const olive::PixelFormat &format,
const olive::RenderMode &mode) :
AudioRendererThreadBase(share_ctx, width, height, divider, format, mode),
const AudioRenderingParams &params) :
AudioRendererThreadBase(params),
parent_(parent),
cancelled_(false)
{
@@ -93,49 +88,20 @@ void AudioRendererProcessThread::ProcessLoop()
NodeOutput* output_to_process = path_.node();
Node* node_to_process = output_to_process->parent();
texture_ = nullptr;
QList<Node*> all_deps;
bool has_hash = false;
bool can_cache = true;
if (!sibling_) {
node_to_process->Lock();
QList<NodeDependency> deps = node_to_process->RunDependencies(output_to_process, path_.in());
all_deps = node_to_process->GetDependencies();
foreach (Node* dep, all_deps) {
dep->Lock();
}
// Check hash
QCryptographicHash hasher(QCryptographicHash::Sha1);
node_to_process->Hash(&hasher, output_to_process, path_.time());
hash_ = hasher.result();
has_hash = parent_->HasHash(hash_);
can_cache = false;
}
if (!has_hash){
if ((can_cache = parent_->TryCache(hash_))) {
QList<NodeDependency> deps = node_to_process->RunDependencies(output_to_process, path_.time());
// Ask for other threads to run these deps while we're here
if (!deps.isEmpty()) {
for (int i=1;i<deps.size();i++) {
emit RequestSibling(deps.at(i));
}
}
// Get the requested value
texture_ = output_to_process->get_value(path_.time(), path_.time()).value<RenderTexturePtr>();
render_instance()->context()->functions()->glFinish();
// Ask for other threads to run these deps while we're here
if (!deps.isEmpty()) {
for (int i=1;i<deps.size();i++) {
emit RequestSibling(deps.at(i));
}
}
// Get the requested value
QByteArray samples = output_to_process->get_value(path_.in(), path_.out()).toByteArray();
if (!sibling_) {
foreach (Node* dep, all_deps) {
dep->Unlock();
@@ -144,12 +110,7 @@ void AudioRendererProcessThread::ProcessLoop()
node_to_process->Unlock();
}
if (can_cache) {
// We cached this frame, signal that it will need to be downloaded to disk
emit CachedFrame(texture_, path_.time(), hash_);
} else {
// This hash already exists, no need to cache, just map it
emit FrameSkipped(path_.time(), hash_);
}
// Signal that we cached some samples
emit CachedSamples(samples, path_.in(), path_.out());
}
}
+2 -12
View File
@@ -30,11 +30,7 @@ class AudioRendererProcessThread : public AudioRendererThreadBase
Q_OBJECT
public:
AudioRendererProcessThread(AudioRendererProcessor* parent,
QOpenGLContext* share_ctx,
const int& width,
const int& height, const int &divider,
const olive::PixelFormat& format,
const olive::RenderMode& mode);
const AudioRenderingParams &params);
bool Queue(const NodeDependency &dep, bool wait, bool sibling);
@@ -47,19 +43,13 @@ protected:
signals:
void RequestSibling(NodeDependency dep);
void CachedFrame(RenderTexturePtr texture, const rational& time, const QByteArray& hash);
void FrameSkipped(const rational& time, const QByteArray& hash);
void CachedSamples(const QByteArray& samples, const rational& in, const rational& out);
private:
AudioRendererProcessor* parent_;
NodeDependency path_;
QByteArray hash_;
RenderTexturePtr texture_;
QAtomicInt cancelled_;
bool sibling_;
+6 -20
View File
@@ -22,16 +22,14 @@
#include <QDebug>
AudioRendererThreadBase::AudioRendererThreadBase(QOpenGLContext *share_ctx, const int &width, const int &height, const int &divider, const olive::PixelFormat &format, const olive::RenderMode &mode) :
share_ctx_(share_ctx),
render_instance_(width, height, divider, format, mode)
AudioRendererThreadBase::AudioRendererThreadBase(const AudioRenderingParams &params) :
params_(params)
{
connect(share_ctx_, SIGNAL(aboutToBeDestroyed()), this, SLOT(Cancel()));
}
RenderInstance *AudioRendererThreadBase::render_instance()
AudioParams *AudioRendererThreadBase::params()
{
return &render_instance_;
return &params_;
}
void AudioRendererThreadBase::run()
@@ -39,23 +37,11 @@ void AudioRendererThreadBase::run()
// Lock mutex for main loop
mutex_.lock();
render_instance_.SetShareContext(share_ctx_);
// Allocate and create resources
bool started = render_instance_.Start();
// Signal that main thread can continue now
WakeCaller();
if (started) {
// Main loop (use Cancel() to exit it)
ProcessLoop();
}
// Free all resources
render_instance_.Stop();
// Main loop (use Cancel() to exit it)
ProcessLoop();
// Unlock mutex before exiting
mutex_.unlock();
+4 -11
View File
@@ -26,21 +26,16 @@
#include <QThread>
#include <QWaitCondition>
#include "audioparams.h"
#include "node/node.h"
#include "render/renderinstance.h"
class AudioRendererThreadBase : public QThread
{
Q_OBJECT
public:
AudioRendererThreadBase(QOpenGLContext* share_ctx,
const int& width,
const int& height,
const int& divider,
const olive::PixelFormat& format,
const olive::RenderMode& mode);
AudioRendererThreadBase(const AudioRenderingParams &params);
RenderInstance* render_instance();
AudioParams* params();
void StartThread(Priority priority = InheritPriority);
@@ -61,9 +56,7 @@ protected:
private:
void WakeCaller();
QOpenGLContext* share_ctx_;
RenderInstance render_instance_;
AudioRenderingParams params_;
};