footage: check files for changes

This commit is contained in:
itsmattkc
2021-05-16 10:29:05 +10:00
parent a675e0ccbb
commit ba9ed99849
9 changed files with 44 additions and 30 deletions
+2
View File
@@ -44,6 +44,8 @@ namespace olive {
class Decoder;
using DecoderPtr = std::shared_ptr<Decoder>;
#define DECODER_DEFAULT_DESTRUCTOR(x) virtual ~x() override {CloseInternal();}
/**
* @brief A decoder's is the main class for bringing external media into Olive
*
-5
View File
@@ -60,11 +60,6 @@ FFmpegDecoder::FFmpegDecoder() :
{
}
FFmpegDecoder::~FFmpegDecoder()
{
CloseInternal();
}
bool FFmpegDecoder::OpenInternal()
{
if (instance_.Open(stream().filename().toUtf8(), stream().stream())) {
+1 -1
View File
@@ -53,7 +53,7 @@ public:
FFmpegDecoder();
// Destructor
virtual ~FFmpegDecoder() override;
DECODER_DEFAULT_DESTRUCTOR(FFmpegDecoder)
virtual QString id() const override;
-5
View File
@@ -41,11 +41,6 @@ OIIODecoder::OIIODecoder() :
{
}
OIIODecoder::~OIIODecoder()
{
CloseInternal();
}
QString OIIODecoder::id() const
{
return QStringLiteral("oiio");
+1 -1
View File
@@ -34,7 +34,7 @@ class OIIODecoder : public Decoder
public:
OIIODecoder();
virtual ~OIIODecoder() override;
DECODER_DEFAULT_DESTRUCTOR(OIIODecoder)
virtual QString id() const override;
+17 -9
View File
@@ -20,7 +20,7 @@
#include "footage.h"
#include <QCoreApplication>
#include <QApplication>
#include <QDir>
#include <QStandardPaths>
@@ -56,6 +56,11 @@ Footage::Footage(const QString &filename) :
Clear();
set_filename(filename);
QTimer *check_timer = new QTimer(this);
check_timer->setInterval(5000);
connect(check_timer, &QTimer::timeout, this, &Footage::CheckFootage);
check_timer->start();
}
void Footage::Retranslate()
@@ -511,17 +516,20 @@ void Footage::UpdateTooltip()
void Footage::CheckFootage()
{
QString fn = filename();
// Don't check files if not the active window
if (qApp->activeWindow()) {
QString fn = filename();
if (!fn.isEmpty()) {
QFileInfo info(fn);
if (!fn.isEmpty()) {
QFileInfo info(fn);
qint64 current_file_timestamp = info.lastModified().toMSecsSinceEpoch();
qint64 current_file_timestamp = info.lastModified().toMSecsSinceEpoch();
if (current_file_timestamp != timestamp()) {
// File has changed!
set_timestamp(current_file_timestamp);
InvalidateAll(kFilenameInput);
if (current_file_timestamp != timestamp()) {
// File has changed!
set_timestamp(current_file_timestamp);
InvalidateAll(kFilenameInput);
}
}
}
}
+12 -1
View File
@@ -39,7 +39,18 @@ private:
};
using DecoderCache = RenderCache<Decoder::CodecStream, DecoderPtr>;
struct DecoderPair {
DecoderPair()
{
decoder = nullptr;
last_modified = 0;
}
DecoderPtr decoder;
qint64 last_modified;
};
using DecoderCache = RenderCache<Decoder::CodecStream, DecoderPair>;
using ShaderCache = RenderCache<QString, QVariant>;
}
+3 -3
View File
@@ -91,10 +91,10 @@ void RenderManager::ClearOldDecoders()
qint64 min_age = QDateTime::currentMSecsSinceEpoch() - kDecoderMaximumInactivity;
for (auto it=decoder_cache_->begin(); it!=decoder_cache_->end(); ) {
DecoderPtr decoder = it.value();
DecoderPair decoder = it.value();
if (decoder->GetLastAccessedTime() < min_age) {
decoder->Close();
if (decoder.decoder->GetLastAccessedTime() < min_age) {
decoder.decoder->Close();
it = decoder_cache_->erase(it);
} else {
it++;
+8 -5
View File
@@ -187,13 +187,16 @@ DecoderPtr RenderProcessor::ResolveDecoderFromInput(const QString& decoder_id, c
QMutexLocker locker(decoder_cache_->mutex());
DecoderPtr decoder = decoder_cache_->value(stream);
DecoderPair decoder = decoder_cache_->value(stream);
if (!decoder) {
qint64 file_last_modified = QFileInfo(stream.filename()).lastModified().toMSecsSinceEpoch();
if (!decoder.decoder || decoder.last_modified != file_last_modified) {
// No decoder
decoder = Decoder::CreateFromID(decoder_id);
decoder.decoder = Decoder::CreateFromID(decoder_id);
decoder.last_modified = file_last_modified;
if (decoder->Open(stream)) {
if (decoder.decoder->Open(stream)) {
decoder_cache_->insert(stream, decoder);
} else {
qWarning() << "Failed to open decoder for" << stream.filename()
@@ -202,7 +205,7 @@ DecoderPtr RenderProcessor::ResolveDecoderFromInput(const QString& decoder_id, c
}
}
return decoder;
return decoder.decoder;
}
void RenderProcessor::Process(RenderTicketPtr ticket, Renderer *render_ctx, StillImageCache *still_image_cache, DecoderCache *decoder_cache, ShaderCache *shader_cache, QVariant default_shader)