Commit a74b771e authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix inconsistencies in profile switch check

parent b25bdb6b
......@@ -955,6 +955,7 @@ void ClipWidget::init(QDockWidget* m_DockClipWidget)
Bin::Bin(std::shared_ptr<ProjectItemModel> model, QWidget *parent, bool isMainBin)
: QWidget(parent)
, isLoading(false)
, shouldCheckProfile(false)
, m_isMainBin(isMainBin)
, m_itemModel(std::move(model))
, m_itemView(nullptr)
......@@ -1870,6 +1871,8 @@ void Bin::cleanDocument()
m_itemModel->clean();
delete m_itemView;
m_itemView = nullptr;
isLoading = false;
shouldCheckProfile = false;
}
const QString Bin::setDocument(KdenliveDoc *project, const QString &id)
......@@ -4542,7 +4545,7 @@ void Bin::checkProfile(const std::shared_ptr<Mlt::Producer> &producer)
}
int height = producer->get_int("meta.media.height");
height += height % 2;
if (width > 100 && height > 100) {
if (width > 100 && height > 100 && pCore->getCurrentFrameSize() != QSize(width, height)) {
std::unique_ptr<ProfileParam> projectProfile(new ProfileParam(pCore->getCurrentProfile().get()));
projectProfile->m_width = width;
projectProfile->m_height = height;
......@@ -4551,7 +4554,7 @@ void Bin::checkProfile(const std::shared_ptr<Mlt::Producer> &producer)
projectProfile->m_display_aspect_num = width;
projectProfile->m_display_aspect_den = height;
projectProfile->m_description.clear();
QMetaObject::invokeMethod(pCore->currentDoc(), "switchProfile", Q_ARG(ProfileParam*,new ProfileParam(projectProfile.get())));
QMetaObject::invokeMethod(pCore->currentDoc(), "switchProfile", Q_ARG(ProfileParam*,new ProfileParam(projectProfile.get())), Q_ARG(QString, QFileInfo(producer->get("resource")).fileName()));
} else {
// Very small image, we probably don't want to use this as profile
}
......@@ -4569,7 +4572,7 @@ void Bin::checkProfile(const std::shared_ptr<Mlt::Producer> &producer)
}
} else {
// Profiles do not match, propose profile adjustment
QMetaObject::invokeMethod(pCore->currentDoc(), "switchProfile", Q_ARG(ProfileParam*,new ProfileParam(clipProfile.get())));
QMetaObject::invokeMethod(pCore->currentDoc(), "switchProfile", Q_ARG(ProfileParam*,new ProfileParam(clipProfile.get())), Q_ARG(QString, QFileInfo(producer->get("resource")).fileName()));
}
}
}
......
......@@ -337,8 +337,10 @@ public:
* @param properties some extra properties that will be set on the producer
* @param createNew if true, the playlist will be added as a new clip in project binId */
void savePlaylist(const QString &binId, const QString &savePath, const QVector<QPoint> &zones, const QMap<QString, QString> &properties, bool createNew);
// Do some checks on the profile
/** @brief Do some checks on the profile */
static void checkProfile(const std::shared_ptr<Mlt::Producer> &producer);
/** @brief Should we process a profile check for added clips */
std::atomic<bool> shouldCheckProfile;
private slots:
void slotAddClip();
......
......@@ -126,9 +126,6 @@ QDomDocument ClipCreator::getXmlFromUrl(const QString &path)
properties.insert(QStringLiteral("resource"), path);
Xml::addXmlProperties(prod, properties);
}
if (pCore->bin()->isEmpty() && (KdenliveSettings::default_profile().isEmpty() || KdenliveSettings::checkfirstprojectclip())) {
prod.setAttribute(QStringLiteral("_checkProfile"), 1);
}
return xml;
}
......@@ -218,6 +215,7 @@ const QString ClipCreator::createClipsFromList(const QList<QUrl> &list, bool che
QList<QUrl> cleanList;
QStringList duplicates;
bool firstClip = topLevel;
pCore->bin()->shouldCheckProfile = (KdenliveSettings::default_profile().isEmpty() || KdenliveSettings::checkfirstprojectclip()) && pCore->bin()->isEmpty();
for (const QUrl &url : list) {
if (!pCore->projectItemModel()->urlExists(url.toLocalFile()) || QFileInfo(url.toLocalFile()).isDir()) {
cleanList << url;
......
......@@ -1426,7 +1426,7 @@ void KdenliveDoc::slotSwitchProfile(const QString &profile_path, bool reloadThum
emit docModified(true);
}
void KdenliveDoc::switchProfile(ProfileParam* pf)
void KdenliveDoc::switchProfile(ProfileParam* pf, const QString clipName)
{
// Request profile update
// Check profile fps so that we don't end up with an fps = 30.003 which would mess things up
......@@ -1476,8 +1476,8 @@ void KdenliveDoc::switchProfile(ProfileParam* pf)
QString currentProfileDesc = pCore->getCurrentProfile()->description();
KMessageBox::ButtonCode answer = KMessageBox::questionYesNoCancel(
QApplication::activeWindow(),
i18n("Your default project profile is %1, but your clip's profile is %2.\nDo you want to change default profile for future projects?",
currentProfileDesc, profile->description()),
i18n("Your default project profile is %1, but your clip's profile (%2) is %3.\nDo you want to change default profile for future projects?",
currentProfileDesc, clipName, profile->description()),
i18n("Change default project profile"), KGuiItem(i18n("Change default to %1", profile->description())),
KGuiItem(i18n("Keep current default %1", currentProfileDesc)), KGuiItem(i18n("Ask me later")));
......@@ -1503,14 +1503,14 @@ void KdenliveDoc::switchProfile(ProfileParam* pf)
connect(ac, &QAction::triggered, this, [this, profilePath]() { this->slotSwitchProfile(profilePath, true); });
QAction *ac2 = new QAction(QIcon::fromTheme(QStringLiteral("dialog-cancel")), i18n("Cancel"), this);
QList<QAction *> list = {ac,ac2};
pCore->displayBinMessage(i18n("Switch to clip profile %1?", profile->descriptiveString()), KMessageWidget::Information, list, false, BinMessage::BinCategory::ProfileMessage);
pCore->displayBinMessage(i18n("Switch to clip (%1) profile %2?", clipName, profile->descriptiveString()), KMessageWidget::Information, list, false, BinMessage::BinCategory::ProfileMessage);
} else {
// No known profile, ask user if he wants to use clip profile anyway
if (qFuzzyCompare(double(profile->m_frame_rate_num) / profile->m_frame_rate_den, fps)) {
adjustMessage = i18n("\nProfile fps adjusted from original %1", QString::number(fps, 'f', 4));
}
if (KMessageBox::warningContinueCancel(pCore->window(),
i18n("No profile found for your clip.\nCreate and switch to new profile (%1x%2, %3fps)?%4", profile->m_width,
i18n("No profile found for your clip %1.\nCreate and switch to new profile (%2x%3, %4fps)?%5", clipName, profile->m_width,
profile->m_height, QString::number(double(profile->m_frame_rate_num) / profile->m_frame_rate_den, 'f', 2),
adjustMessage)) == KMessageBox::Continue) {
profile->m_description = QStringLiteral("%1x%2 %3fps")
......
......@@ -238,7 +238,7 @@ public slots:
void slotAutoSave(const QString &scene);
/** @brief Groups were changed, save to MLT. */
void groupsChanged(const QString &groups);
void switchProfile(ProfileParam* pf);
void switchProfile(ProfileParam* pf, const QString clipName);
private slots:
void slotModified();
......
......@@ -463,7 +463,10 @@ void ClipLoadTask::run()
producer.reset();
}
qDebug()<<"=== MAX DURATION: "<<INT_MAX<<", DURATION: "<<(INT_MAX / 25 / 60)<<"; RES: "<<resource;
emit proposeTranscode(resource);
QMetaObject::invokeMethod(pCore->bin(), "requestTranscoding", Qt::QueuedConnection, Q_ARG(QString, resource), Q_ARG(QString, QString::number(m_owner.second)), Q_ARG(bool, pCore->bin()->shouldCheckProfile));
if (pCore->bin()->shouldCheckProfile) {
pCore->bin()->shouldCheckProfile = false;
}
abort();
return;
}
......@@ -542,6 +545,7 @@ void ClipLoadTask::run()
double fps = -1;
bool isVariableFrameRate = false;
bool seekable = true;
bool checkProfile = pCore->bin()->shouldCheckProfile;
if (mltService == QLatin1String("xml") || mltService == QLatin1String("consumer")) {
// MLT playlist, create producer with blank profile to get real profile info
QString tmpPath = resource;
......@@ -583,16 +587,21 @@ void ClipLoadTask::run()
// Check if file is seekable
seekable = producer->get_int("seekable");
vindex = producer->get_int("video_index");
bool checkProfile = false;
if (m_xml.hasAttribute(QStringLiteral("_checkProfile")) && vindex > -1) {
checkProfile = true;
if (vindex <= -1) {
checkProfile = false;
}
if (!seekable) {
if (checkProfile) {
pCore->bin()->shouldCheckProfile = false;
}
QMetaObject::invokeMethod(pCore->bin(), "requestTranscoding", Qt::QueuedConnection, Q_ARG(QString, resource), Q_ARG(QString, QString::number(m_owner.second)), Q_ARG(bool, checkProfile));
}
// Check for variable frame rate
isVariableFrameRate = producer->get_int("meta.media.variable_frame_rate");
if (isVariableFrameRate && seekable) {
if (checkProfile) {
pCore->bin()->shouldCheckProfile = false;
}
QMetaObject::invokeMethod(pCore->bin(), "requestTranscoding", Qt::QueuedConnection, Q_ARG(QString, resource), Q_ARG(QString, QString::number(m_owner.second)), Q_ARG(bool, checkProfile));
}
// check if there are multiple streams
......@@ -634,7 +643,8 @@ void ClipLoadTask::run()
auto binClip = pCore->projectItemModel()->getClipByBinID(QString::number(m_owner.second));
if (binClip) {
QMetaObject::invokeMethod(binClip.get(), "setProducer", Qt::QueuedConnection, Q_ARG(std::shared_ptr<Mlt::Producer>,producer));
if (m_xml.hasAttribute(QStringLiteral("_checkProfile")) && producer->get_int("video_index") > -1 && !isVariableFrameRate && seekable) {
if (checkProfile && !isVariableFrameRate && seekable) {
pCore->bin()->shouldCheckProfile = false;
QMetaObject::invokeMethod(pCore->bin(), "slotCheckProfile", Qt::QueuedConnection, Q_ARG(QString, QString::number(m_owner.second)));
}
}
......@@ -654,6 +664,8 @@ void ClipLoadTask::abort()
Fun redo = []() { return true; };
m_progress = 100;
pCore->taskManager.taskDone(m_owner.second, this);
qDebug()<<pCore->projectItemModel()->getClipByBinID(QString::number(m_owner.second))->clipUrl();
QString resource = Xml::getXmlProperty(m_xml, QStringLiteral("resource"));
if (!m_softDelete) {
auto binClip = pCore->projectItemModel()->getClipByBinID(QString::number(m_owner.second));
if (binClip) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment