footage: check files for changes
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
@@ -60,11 +60,6 @@ FFmpegDecoder::FFmpegDecoder() :
|
||||
{
|
||||
}
|
||||
|
||||
FFmpegDecoder::~FFmpegDecoder()
|
||||
{
|
||||
CloseInternal();
|
||||
}
|
||||
|
||||
bool FFmpegDecoder::OpenInternal()
|
||||
{
|
||||
if (instance_.Open(stream().filename().toUtf8(), stream().stream())) {
|
||||
|
||||
@@ -53,7 +53,7 @@ public:
|
||||
FFmpegDecoder();
|
||||
|
||||
// Destructor
|
||||
virtual ~FFmpegDecoder() override;
|
||||
DECODER_DEFAULT_DESTRUCTOR(FFmpegDecoder)
|
||||
|
||||
virtual QString id() const override;
|
||||
|
||||
|
||||
@@ -41,11 +41,6 @@ OIIODecoder::OIIODecoder() :
|
||||
{
|
||||
}
|
||||
|
||||
OIIODecoder::~OIIODecoder()
|
||||
{
|
||||
CloseInternal();
|
||||
}
|
||||
|
||||
QString OIIODecoder::id() const
|
||||
{
|
||||
return QStringLiteral("oiio");
|
||||
|
||||
@@ -34,7 +34,7 @@ class OIIODecoder : public Decoder
|
||||
public:
|
||||
OIIODecoder();
|
||||
|
||||
virtual ~OIIODecoder() override;
|
||||
DECODER_DEFAULT_DESTRUCTOR(OIIODecoder)
|
||||
|
||||
virtual QString id() const override;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>;
|
||||
|
||||
}
|
||||
|
||||
@@ -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++;
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user