forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmltxmlchecker.cpp
More file actions
782 lines (736 loc) · 30 KB
/
mltxmlchecker.cpp
File metadata and controls
782 lines (736 loc) · 30 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
/*
* Copyright (c) 2014-2021 Meltytech, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mltxmlchecker.h"
#include "mltcontroller.h"
#include "shotcut_mlt_properties.h"
#include "util.h"
#include "proxymanager.h"
#include "settings.h"
#include <QLocale>
#include <QDir>
#include <QCoreApplication>
#include <QUrl>
#include <QRegExp>
#include <Logger.h>
#include <clocale>
#include <utime.h>
static QString getPrefix(const QString &name, const QString &value);
static bool isMltClass(const QStringRef &name)
{
return name == "profile" || name == "producer" ||
name == "filter" || name == "playlist" ||
name == "tractor" || name == "track" ||
name == "transition" || name == "consumer" ||
name == "chain" || name == "link";
}
static bool isNetworkResource(const QString &string)
{
// Check if it looks like a qualified URL. Try parsing it and see.
QRegExp schemaTest(QLatin1String("^[a-zA-Z]{2,}\\:.*"));
// Not actually checking network URL due to latency and transience.
return (schemaTest.exactMatch(string) && QUrl(string).isValid() && !string.startsWith("plain:"));
}
static bool isNumericProperty(const QString &name)
{
return name == "length" || name == "geometry" ||
name == "rect" || name == "warp_speed";
}
MltXmlChecker::MltXmlChecker()
: m_needsGPU(false)
, m_needsCPU(false)
, m_hasEffects(false)
, m_isCorrected(false)
, m_isUpdated(false)
, m_usesLocale(false)
, m_decimalPoint('.')
, m_numericValueChanged(false)
{
m_unlinkedFilesModel.setColumnCount(ColumnCount);
}
QXmlStreamReader::Error MltXmlChecker::check(const QString &fileName)
{
LOG_DEBUG() << "begin";
QFile file(fileName);
m_tempFile.reset(new QTemporaryFile(
QFileInfo(fileName).dir().filePath("shotcut-XXXXXX.mlt")));
if (file.open(QIODevice::ReadOnly | QIODevice::Text) && m_tempFile->open()) {
m_tempFile->resize(0);
m_fileInfo = QFileInfo(fileName);
m_xml.setDevice(&file);
m_newXml.setDevice(m_tempFile.data());
m_newXml.setAutoFormatting(true);
m_newXml.setAutoFormattingIndent(2);
if (m_xml.readNextStartElement()) {
if (m_xml.name() == "mlt") {
m_newXml.writeStartDocument();
m_newXml.writeCharacters("\n");
m_newXml.writeStartElement("mlt");
foreach (QXmlStreamAttribute a, m_xml.attributes()) {
if (a.name().toString().toUpper() == "LC_NUMERIC") {
QString value = a.value().toString().toUpper();
// Determine whether this document uses a non-POSIX/-generic numeric locale.
m_usesLocale = (value != "" && value != "C" && value != "POSIX" && QLocale().decimalPoint() != '.');
// Upon correcting the document to conform to current system,
// update the declared LC_NUMERIC.
m_newXml.writeAttribute("LC_NUMERIC", m_usesLocale ? QLocale().name() : "C");
} else if (a.name().toString().toLower() == "version") {
m_mltVersion = QVersionNumber::fromString(a.value());
} else if (a.name().toString().toLower() == "title") {
m_newXml.writeAttribute(a.name().toString(), "Shotcut version " SHOTCUT_VERSION);
auto parts = a.value().split(' ');
LOG_DEBUG() << parts;
if (parts.size() > 2 && parts[1] == "version") {
m_shotcutVersion = parts[2].toString();
}
} else {
m_newXml.writeAttribute(a);
}
}
if (!checkMltVersion()) {
return QXmlStreamReader::CustomError;
}
// We cannot apply the locale change to the session at this point
// because we are merely checking at this point and not loading.
// Save the current locale state.
bool isCLocale = (::qgetenv(MLT_LC_NAME).toUpper() == "C");
// Apply the chosen locale temporarily.
setLocale();
// Get the decimal point expected based on the current system
// locale or POSIX/C if the document is using POSIX.
m_decimalPoint = MLT.decimalPoint();
LOG_INFO() << "decimal point" << m_decimalPoint;
// Restore the current locale state.
if (isCLocale) {
::qputenv(MLT_LC_NAME, "C");
::setlocale(MLT_LC_CATEGORY, "C");
} else {
::qunsetenv(MLT_LC_NAME);
::setlocale(MLT_LC_CATEGORY, "");
}
readMlt();
m_newXml.writeEndElement();
m_newXml.writeEndDocument();
m_isCorrected = m_isCorrected || m_numericValueChanged;
} else {
m_xml.raiseError(QObject::tr("The file is not a MLT XML file."));
}
}
}
LOG_DEBUG() << m_tempFile->fileName();
if (m_tempFile->isOpen()) {
m_tempFile->close();
// Useful for debugging
// m_tempFile->open();
// LOG_DEBUG() << m_tempFile->readAll().constData();
// m_tempFile->close();
}
LOG_DEBUG() << "end" << m_xml.errorString();
return m_xml.error();
}
QString MltXmlChecker::errorString() const
{
return m_xml.errorString();
}
void MltXmlChecker::setLocale()
{
// Returns whether this document uses a non-POSIX/-generic numeric locale.
if (m_usesLocale) {
::qunsetenv(MLT_LC_NAME);
::setlocale(MLT_LC_CATEGORY, "");
} else {
::qputenv(MLT_LC_NAME, "C");
::setlocale(MLT_LC_CATEGORY, "C");
}
}
void MltXmlChecker::readMlt()
{
Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "mlt");
bool isPropertyElement = false;
while (!m_xml.atEnd()) {
switch (m_xml.readNext()) {
case QXmlStreamReader::Characters:
if (!isPropertyElement)
m_newXml.writeCharacters(m_xml.text().toString());
break;
case QXmlStreamReader::Comment:
m_newXml.writeComment(m_xml.text().toString());
break;
case QXmlStreamReader::DTD:
m_newXml.writeDTD(m_xml.text().toString());
break;
case QXmlStreamReader::EntityReference:
m_newXml.writeEntityReference(m_xml.name().toString());
break;
case QXmlStreamReader::ProcessingInstruction:
m_newXml.writeProcessingInstruction(m_xml.processingInstructionTarget().toString(),
m_xml.processingInstructionData().toString());
break;
case QXmlStreamReader::StartDocument:
m_newXml.writeStartDocument(m_xml.documentVersion().toString(), m_xml.isStandaloneDocument());
break;
case QXmlStreamReader::EndDocument:
m_newXml.writeEndDocument();
break;
case QXmlStreamReader::StartElement: {
const QString element = m_xml.name().toString();
isPropertyElement = false;
if (element == "property") {
isPropertyElement = true;
if (isMltClass(&mlt_class)) {
const QString name = m_xml.attributes().value("name").toString();
m_properties << MltProperty(name, m_xml.readElementText());
}
} else {
processProperties();
m_newXml.writeStartElement(m_xml.namespaceUri().toString(), element);
if (isMltClass(m_xml.name()))
mlt_class = element;
checkInAndOutPoints(); // This also copies the attributes.
}
break;
}
case QXmlStreamReader::EndElement:
if (m_xml.name() != "property") {
processProperties();
m_newXml.writeEndElement();
if (isMltClass(m_xml.name())) {
mlt_class.clear();
}
}
break;
default:
break;
}
}
}
void MltXmlChecker::processProperties()
{
QString mlt_service;
QVector<MltProperty> newProperties;
m_resource.clear();
// First pass: collect information about mlt_service and resource.
foreach (MltProperty p, m_properties) {
// Get the name of the MLT service.
if (p.first == "mlt_service") {
mlt_service = p.second;
} else if (p.first == kShotcutHashProperty) {
m_resource.hash = p.second;
} else if (isNumericProperty(p.first)) {
checkNumericString(p.second);
} else if (p.first == "resource" && mlt_service == "webvfx" && fixWebVfxPath(p.second)) {
} else if (readResourceProperty(p.first, p.second)) {
#ifdef Q_OS_WIN
fixVersion1701WindowsPathBug(p.second);
#endif
// Check timewarp producer's resource property prefix.
QString prefix = getPrefix(p.first, p.second);
if (!prefix.isEmpty() && prefix != "plain:") {
if (checkNumericString(prefix))
p.second = prefix + p.second.mid(p.second.indexOf(':') + 1);
}
fixUnlinkedFile(p.second);
}
newProperties << MltProperty(p.first, p.second);
}
if (mlt_class == "filter" || mlt_class == "transition" || mlt_class == "producer"
|| mlt_class == "chain" || mlt_class == "link") {
checkGpuEffects(mlt_service);
checkCpuEffects(mlt_service);
checkUnlinkedFile(mlt_service);
checkIncludesSelf(newProperties);
checkLumaAlphaOver(mlt_service, newProperties);
#if LIBMLT_VERSION_INT >= ((6<<16)+(23<<8))
replaceWebVfxCropFilters(mlt_service, newProperties);
replaceWebVfxChoppyFilter(mlt_service, newProperties);
#endif
if (Settings.proxyEnabled())
checkForProxy(mlt_service, newProperties);
// Second pass: amend property values.
m_properties = newProperties;
newProperties.clear();
foreach (MltProperty p, m_properties) {
// Fix some properties if re-linked file.
if (p.first == kShotcutHashProperty) {
if (!m_resource.newHash.isEmpty())
p.second = m_resource.newHash;
} else if (p.first == kShotcutCaptionProperty) {
if (!m_resource.newDetail.isEmpty())
p.second = Util::baseName(m_resource.newDetail);
} else if (p.first == kShotcutDetailProperty) {
// We no longer save this (leaks absolute paths).
p.second.clear();
} else if (p.first == "audio_index" || p.first == "video_index") {
fixStreamIndex(p);
}
if (!p.second.isEmpty())
newProperties << MltProperty(p.first, p.second);
}
}
// Write all of the properties.
foreach (MltProperty p, newProperties) {
m_newXml.writeStartElement("property");
m_newXml.writeAttribute("name", p.first);
m_newXml.writeCharacters(p.second);
m_newXml.writeEndElement();
}
m_properties.clear();
}
void MltXmlChecker::checkInAndOutPoints()
{
Q_ASSERT(m_xml.isStartElement());
// Fix numeric values of in and out point attributes.
foreach (QXmlStreamAttribute a, m_xml.attributes()) {
if (a.name() == "in" || a.name() == "out") {
QString value = a.value().toString();
if (checkNumericString(value)) {
m_newXml.writeAttribute(a.name().toString(), value);
continue;
}
}
m_newXml.writeAttribute(a);
}
}
bool MltXmlChecker::checkNumericString(QString &value)
{
// Determine if there is a decimal point inconsistent with locale.
if (!value.contains(m_decimalPoint) &&
(value.contains('.') || value.contains(','))) {
value.replace(',', m_decimalPoint);
value.replace('.', m_decimalPoint);
m_numericValueChanged = true;
return true;
}
return false;
}
bool MltXmlChecker::fixWebVfxPath(QString &resource)
{
// The path, if absolute, should start with the Shotcut executable path.
QFileInfo fi(resource);
if (fi.isAbsolute() || Util::hasDriveLetter(resource)) {
QDir appPath(QCoreApplication::applicationDirPath());
#if defined(Q_OS_MAC)
// Leave the MacOS directory
appPath.cdUp();
#elif defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
// Leave the bin directory on Linux.
appPath.cdUp();
#endif
if (!resource.startsWith(appPath.path())) {
// Locate "share/shotcut" and replace the front of it with appPath.
int i = resource.indexOf("/share/shotcut/");
#if defined(Q_OS_MAC)
if (i == -1)
i = resource.indexOf("/Resources/shotcut/");
#endif
if (i >= 0) {
resource.replace(0, i, appPath.path());
m_isUpdated = true;
return true;
}
}
}
return false;
}
static QString getPrefix(const QString &name, const QString &value)
{
int length = 0;
// Webvfx and timewarp are only using "resource".
if (name == "resource") {
const QString plain("plain:");
// webvfx "plain:"
if (value.startsWith(plain)) {
return plain;
} else {
// timewarp speed parameter
length = value.indexOf(':');
if (length > 0) {
bool isNumeric = true;
for (int i = 0; i < length && isNumeric; i++) {
if (!value[i].isDigit() && value[i] != '.' && value[i] != ',')
isNumeric = false;
}
if (isNumeric)
return value.left(length + 1); // include the colon
}
}
}
return QString();
}
static QString getSuffix(const QString &name, const QString &value)
{
// avformat is only using "resource"
if (name == "resource") {
const QString queryDelimiter("\\?");
const auto i = value.lastIndexOf(queryDelimiter);
// webvfx "plain:"
if (i > 0) {
return value.mid(i);
}
}
return QString();
}
bool MltXmlChecker::readResourceProperty(const QString &name, QString &value)
{
if (mlt_class == "filter" || mlt_class == "transition" || mlt_class == "producer"
|| mlt_class == "chain" || mlt_class == "link")
if (name == "resource" || name == "src" || name == "filename"
|| name == "luma" || name == "luma.resource" || name == "composite.luma"
|| name == "producer.resource" || name == "av.file" || name == "warp_resource") {
// Handle special prefix such as "plain:" or speed.
m_resource.prefix = getPrefix(name, value);
m_resource.suffix = getSuffix(name, value);
auto filePath = value.mid(m_resource.prefix.size());
filePath = filePath.left(filePath.size() - m_resource.suffix.size());
// Save the resource name (minus prefix) for later check for unlinked files.
m_resource.info.setFile(filePath);
if (!isNetworkResource(value) && m_resource.info.isRelative() && !Util::hasDriveLetter(value))
m_resource.info.setFile(m_fileInfo.canonicalPath(), m_resource.info.filePath());
return true;
}
return false;
}
void MltXmlChecker::checkGpuEffects(const QString &mlt_service)
{
// Check for GPU effects.
if (!MLT.isAudioFilter(mlt_service))
m_hasEffects = true;
if (mlt_service.startsWith("movit.") || mlt_service.startsWith("glsl."))
m_needsGPU = true;
}
void MltXmlChecker::checkCpuEffects(const QString &mlt_service)
{
if (mlt_service.startsWith("dynamictext") || mlt_service.startsWith("vidstab"))
m_needsCPU = true;
}
void MltXmlChecker::checkUnlinkedFile(const QString &mlt_service)
{
// Check for an unlinked file.
const QString fileName = m_resource.info.fileName();
const QString filePath = QDir::toNativeSeparators(m_resource.info.filePath());
// not the color producer
if (!mlt_service.isEmpty() && mlt_service != "color" && mlt_service != "colour")
// not a builtin luma wipe file
if ((mlt_service != "luma" && mlt_service != "movit.luma_mix") || !fileName.startsWith('%'))
// not a Stabilize filter without Analyze results
if (fileName != "vidstab.trf")
// not the generic <producer> resource
if (fileName != "<producer>")
// not an invalid <tractor>
if (fileName != "<tractor>")
// not an invalid blank
if (mlt_service != "blank" || fileName != "blank")
// not a URL
if (!m_resource.info.filePath().isEmpty() && !isNetworkResource(m_resource.info.filePath()))
// not an image sequence
if ((mlt_service != "pixbuf" && mlt_service != "qimage") || fileName.indexOf('%') == -1)
// file does not exist
if (!m_resource.info.exists())
// not already in the model
if (m_unlinkedFilesModel.findItems(filePath,
Qt::MatchFixedString | Qt::MatchCaseSensitive).isEmpty()) {
LOG_ERROR() << "file not found: " << m_resource.info.filePath();
QIcon icon(":/icons/oxygen/32x32/status/task-reject.png");
QStandardItem *item = new QStandardItem(icon, filePath);
item->setToolTip(item->text());
item->setData(m_resource.hash, ShotcutHashRole);
m_unlinkedFilesModel.appendRow(item);
}
}
bool MltXmlChecker::fixUnlinkedFile(QString &value)
{
// Replace unlinked files if model is populated with replacements.
for (int row = 0; row < m_unlinkedFilesModel.rowCount(); ++row) {
const QStandardItem *replacement = m_unlinkedFilesModel.item(row, ReplacementColumn);
if (replacement && !replacement->text().isEmpty() &&
m_unlinkedFilesModel.item(row,
MissingColumn)->text() == QDir::toNativeSeparators(m_resource.info.filePath())) {
m_resource.info.setFile(replacement->text());
m_resource.newDetail = replacement->text();
m_resource.newHash = replacement->data(ShotcutHashRole).toString();
value = QDir::fromNativeSeparators(replacement->text());
// Convert to relative path if possible.
if (value.startsWith(m_fileInfo.canonicalPath() + "/"))
value = value.mid(m_fileInfo.canonicalPath().size() + 1);
// Restore special prefix such as "plain:" or speed value.
value.prepend(m_resource.prefix);
value.append(m_resource.suffix);
m_isCorrected = true;
Mlt::Producer producer(MLT.profile(), m_resource.info.filePath().toUtf8().constData());
if (producer.is_valid() && !::qstrcmp(producer.get("mlt_service"), "avformat")) {
m_resource.audio_index = producer.get_int("audio_index");
m_resource.video_index = producer.get_int("video_index");
}
return true;
}
}
return false;
}
void MltXmlChecker::fixStreamIndex(MltProperty &property)
{
// Remove a stream index property if re-linked file is different.
if (!m_resource.hash.isEmpty() && !m_resource.newHash.isEmpty()
&& m_resource.hash != m_resource.newHash) {
if (property.first == "audio_index") {
property.second = QString::number(m_resource.audio_index);
} else if (property.first == "video_index") {
property.second = QString::number(m_resource.video_index);
}
}
}
bool MltXmlChecker::fixVersion1701WindowsPathBug(QString &value)
{
if (value.size() >= 3 && value[0] == '/' && value[2] == ':') {
value.remove(0, 1);
m_isCorrected = true;
return true;
}
return false;
}
void MltXmlChecker::checkIncludesSelf(QVector<MltProperty> &properties)
{
if (m_resource.info.canonicalFilePath() == m_fileInfo.canonicalFilePath()) {
LOG_WARNING() << "This project tries to include itself; breaking that!";
for (auto &p : properties) {
if (p.first == "mlt_service")
p.second.clear();
else if (p.first == "resource")
p.second = "+INVALID.txt";
}
properties << MltProperty(kShotcutCaptionProperty, "INVALID");
m_isCorrected = true;
}
}
void MltXmlChecker::checkLumaAlphaOver(const QString &mlt_service,
QVector<MltXmlChecker::MltProperty> &properties)
{
if (mlt_service == "luma") {
bool found = false;
for (auto &p : properties) {
if (p.first == "alpha_over") {
found = true;
}
}
if (!found) {
properties << MltProperty("alpha_over", "1");
m_isUpdated = true;
}
}
}
void MltXmlChecker::replaceWebVfxCropFilters(QString &mlt_service,
QVector<MltXmlChecker::MltProperty> &properties)
{
if (mlt_service == "webvfx") {
auto isCrop = false;
for (auto &p : properties) {
if (p.first == "shotcut:filter" && p.second == "webvfxCircularFrame") {
p.second = "cropCircle";
properties << MltProperty("circle", "1");
m_isUpdated = isCrop = true;
break;
}
if (p.first == "shotcut:filter" && p.second == "webvfxClip") {
p.second = "cropRectangle";
m_isUpdated = isCrop = true;
break;
}
}
if (isCrop) {
mlt_service = "qtcrop";
for (auto &p : properties) {
if (p.first == "resource") {
properties.removeOne(p);
break;
}
}
for (auto &p : properties) {
if (p.first == "mlt_service") {
p.second = "qtcrop";
break;
}
}
}
}
}
void MltXmlChecker::replaceWebVfxChoppyFilter(QString &mlt_service,
QVector<MltXmlChecker::MltProperty> &properties)
{
if (mlt_service == "webvfx") {
auto isChoppy = false;
QString shotcutFilter;
for (auto &p : properties) {
if (p.first == "shotcut:filter") {
shotcutFilter = p.second;
if (p.second == "webvfxChoppy") {
properties.removeOne(p);
m_isUpdated = isChoppy = true;
break;
}
}
}
if (isChoppy) {
mlt_service = "choppy";
for (auto &p : properties) {
if (p.first == "resource") {
properties.removeOne(p);
break;
}
}
for (auto &p : properties) {
if (p.first == "mlt_service") {
p.second = "choppy";
break;
}
}
} else if (shotcutFilter.isEmpty()) {
mlt_service = "qtext";
m_isUpdated = true;
for (auto &p : properties) {
if (p.first == "resource") {
auto pathName = p.second;
auto plain = QLatin1String("plain:");
if (pathName.startsWith(plain)) {
pathName = pathName.mid(plain.size());
}
if (QFileInfo(pathName).isRelative()) {
QDir projectDir(QFileInfo(m_tempFile->fileName()).dir());
pathName = projectDir.filePath(pathName);
}
QFile file(pathName);
if (file.open(QIODevice::ReadOnly)) {
p.first = "html";
p.second = QString::fromUtf8(file.readAll());
}
break;
}
}
for (auto &p : properties) {
if (p.first == "mlt_service") {
p.second = "qtext";
break;
}
}
properties << MltProperty("shotcut:filter", "richText");
}
}
}
void MltXmlChecker::checkForProxy(const QString &mlt_service,
QVector<MltXmlChecker::MltProperty> &properties)
{
bool isTimewarp = mlt_service == "timewarp";
if (mlt_service.startsWith("avformat") || isTimewarp) {
QString resource;
QString hash;
QString speed = "1";
for (auto &p : properties) {
if ((!isTimewarp && p.first == "resource") || p.first == "warp_resource") {
QFileInfo info(p.second);
if (info.isRelative())
info.setFile(m_fileInfo.canonicalPath(), p.second);
resource = info.filePath();
} else if (p.first == kShotcutHashProperty) {
hash = p.second;
} else if (p.first == "warp_speed") {
speed = p.second;
} else if (p.first == kDisableProxyProperty && p.second == "1") {
return;
}
}
// Use GoPro LRV if available
if (QFile::exists(ProxyManager::GoProProxyFilePath(resource))) {
for (auto &p : properties) {
if (p.first == "resource") {
p.second = ProxyManager::GoProProxyFilePath(resource);
if (isTimewarp) {
p.second = QString("%1:%2").arg(speed).arg(p.second);
}
properties << MltProperty(kIsProxyProperty, "1");
properties << MltProperty(kOriginalResourceProperty, resource);
m_isUpdated = true;
return;
}
}
}
QDir proxyDir(Settings.proxyFolder());
QDir projectDir(QFileInfo(m_tempFile->fileName()).dir());
QString fileName = hash + ProxyManager::videoFilenameExtension();
projectDir.cd("proxies");
if (proxyDir.exists(fileName) || projectDir.exists(fileName)) {
::utime(proxyDir.filePath(fileName).toUtf8().constData(), nullptr);
::utime(projectDir.filePath(fileName).toUtf8().constData(), nullptr);
for (auto &p : properties) {
if (p.first == "resource") {
if (projectDir.exists(fileName)) {
p.second = projectDir.filePath(fileName);
} else {
p.second = proxyDir.filePath(fileName);
}
if (isTimewarp) {
p.second = QString("%1:%2").arg(speed).arg(p.second);
}
break;
}
}
properties << MltProperty(kIsProxyProperty, "1");
properties << MltProperty(kOriginalResourceProperty, resource);
m_isUpdated = true;
}
} else if ((mlt_service == "qimage" || mlt_service == "pixbuf")
&& !properties.contains(MltProperty(kShotcutSequenceProperty, "1"))) {
QString resource;
QString hash;
for (auto &p : properties) {
if (p.first == "resource") {
QFileInfo info(p.second);
if (info.isRelative())
info.setFile(m_fileInfo.canonicalPath(), p.second);
resource = info.filePath();
} else if (p.first == kShotcutHashProperty) {
hash = p.second;
} else if (p.first == kDisableProxyProperty && p.second == "1") {
return;
}
}
QDir proxyDir(Settings.proxyFolder());
QDir projectDir(QFileInfo(m_tempFile->fileName()).dir());
QString fileName = hash + ProxyManager::imageFilenameExtension();
projectDir.cd("proxies");
if (proxyDir.exists(fileName) || projectDir.exists(fileName)) {
::utime(proxyDir.filePath(fileName).toUtf8().constData(), nullptr);
::utime(projectDir.filePath(fileName).toUtf8().constData(), nullptr);
for (auto &p : properties) {
if (p.first == "resource") {
if (projectDir.exists(fileName)) {
p.second = projectDir.filePath(fileName);
} else {
p.second = proxyDir.filePath(fileName);
}
break;
}
}
properties << MltProperty(kIsProxyProperty, "1");
properties << MltProperty(kOriginalResourceProperty, resource);
m_isUpdated = true;
}
}
}
bool MltXmlChecker::checkMltVersion()
{
if (m_mltVersion.majorVersion() > 7) {
return false;
}
return true;
}