footage: use version number on cache

Will allow us to easily discard cache later
This commit is contained in:
itsmattkc
2022-05-11 09:32:05 -07:00
parent e9ebef1de8
commit 6212f675a2
3 changed files with 25 additions and 7 deletions
+2 -6
View File
@@ -90,12 +90,8 @@ void Footage::InputValueChangedEvent(const QString &input, int element)
FootageDescription footage_info;
if (QFileInfo::exists(meta_cache_file)) {
// Load meta cache file
footage_info.Load(meta_cache_file);
} else {
// Try to load footage info from cache
if (!QFileInfo::exists(meta_cache_file) || !footage_info.Load(meta_cache_file)) {
// Probe and create cache
QVector<DecoderPtr> decoder_list = Decoder::ReceiveListOfAllDecoders();
@@ -40,6 +40,20 @@ bool FootageDescription::Load(const QString &filename)
while (XMLReadNextStartElement(&reader)) {
if (reader.name() == QStringLiteral("streamcache")) {
// Default to first version of metadata (which wasn't versioned at all)
unsigned version = 1;
XMLAttributeLoop((&reader), attr) {
if (attr.name() == QStringLiteral("version")) {
version = attr.value().toUInt();
}
}
if (version != kFootageMetaVersion) {
// If this is a different version, discard so we can probe new data
return false;
}
while (XMLReadNextStartElement(&reader)) {
if (reader.name() == QStringLiteral("decoder")) {
decoder_ = reader.readElementText();
@@ -68,7 +82,11 @@ bool FootageDescription::Load(const QString &filename)
file.close();
return true;
if (reader.hasError()) {
qWarning() << "Failed to load footage description for" << filename << reader.errorString();
} else {
return true;
}
}
return false;
@@ -88,6 +106,8 @@ bool FootageDescription::Save(const QString &filename) const
writer.writeStartElement(QStringLiteral("streamcache"));
writer.writeAttribute(QStringLiteral("version"), QString::number(kFootageMetaVersion));
writer.writeTextElement(QStringLiteral("decoder"), decoder_);
writer.writeStartElement(QStringLiteral("streams"));
@@ -112,6 +112,8 @@ public:
}
private:
static constexpr unsigned kFootageMetaVersion = 1;
QString decoder_;
QVector<VideoParams> video_streams_;