Commit 7cf732a8 authored by Nicolas Carion's avatar Nicolas Carion

add better check of presence of audio in producers

parent 1583149b
......@@ -56,6 +56,9 @@ ClipController::ClipController(const QString clipId, std::shared_ptr<Mlt::Produc
qCDebug(KDENLIVE_LOG) << "// WARNING, USING INVALID PRODUCER";
return;
}
if (m_masterProducer) {
checkAudio();
}
if (m_properties) {
setProducerProperty(QStringLiteral("kdenlive:id"), m_controllerBinId);
m_service = m_properties->get("mlt_service");
......@@ -68,7 +71,8 @@ ClipController::ClipController(const QString clipId, std::shared_ptr<Mlt::Produc
path.prepend(pCore->currentDoc()->documentRoot());
}
m_usesProxy = true;
} else if (m_service != QLatin1String("color") && m_service != QLatin1String("colour") && !path.isEmpty() && QFileInfo(path).isRelative()) {
} else if (m_service != QLatin1String("color") && m_service != QLatin1String("colour") && !path.isEmpty() && QFileInfo(path).isRelative() &&
path != QLatin1String("<producer>")) {
path.prepend(pCore->currentDoc()->documentRoot());
}
m_path = path.isEmpty() ? QString() : QFileInfo(path).absoluteFilePath();
......@@ -107,6 +111,7 @@ void ClipController::addMasterProducer(const std::shared_ptr<Mlt::Producer> &pro
m_producerLock.unlock();
qCDebug(KDENLIVE_LOG) << "// WARNING, USING INVALID PRODUCER";
} else {
checkAudio();
m_producerLock.unlock();
QString proxy = m_properties->get("kdenlive:proxy");
m_service = m_properties->get("mlt_service");
......@@ -298,6 +303,7 @@ void ClipController::updateProducer(const std::shared_ptr<Mlt::Producer> &produc
passProperties.pass_list(*m_properties, getPassPropertiesList(m_usesProxy));
delete m_properties;
*m_masterProducer = producer.get();
checkAudio();
m_properties = new Mlt::Properties(m_masterProducer->get_properties());
// Pass properties from previous producer
m_properties->pass_list(passProperties, getPassPropertiesList(m_usesProxy));
......@@ -559,6 +565,18 @@ const QSize ClipController::getFrameSize() const
return QSize(width, height);
}
bool ClipController::hasAudio() const
{
return m_hasAudio;
}
void ClipController::checkAudio()
{
m_masterProducer->seek(0);
Mlt::Frame *frame = m_masterProducer->get_frame();
// test_audio returns 1 if there is NO audio (strange but at the time this code is written)
m_hasAudio = frame->get_int("test_audio") == 0;
}
QPixmap ClipController::pixmap(int framePosition, int width, int height)
{
// TODO refac this should use the new thumb infrastructure
......
......@@ -171,6 +171,8 @@ public:
void updateEffect(const QDomElement &e, int ix);
/** @brief Returns true if the bin clip has effects */
bool hasEffects() const;
/** @brief Returns true if the clip contains at least one audio stream */
bool hasAudio() const;
/** @brief Returns info about clip audio */
const std::unique_ptr<AudioStreamInfo> &audioInfo() const;
/** @brief Returns true if audio thumbnails for this clip are cached */
......@@ -202,6 +204,9 @@ protected:
virtual void emitProducerChanged(const QString &, const std::shared_ptr<Mlt::Producer> &){};
virtual void connectEffectStack(){};
// This is the helper function that checks the clip for audio and stores the result
void checkAudio();
std::shared_ptr<Mlt::Producer> m_masterProducer;
Mlt::Properties *m_properties;
bool m_usesProxy;
......@@ -217,6 +222,7 @@ protected:
// void rebuildEffectList(ProfileInfo info);
std::shared_ptr<EffectStackModel> m_effectStack;
std::shared_ptr<MarkerListModel> m_markerModel;
bool m_hasAudio;
private:
QMutex m_producerLock;
......
......@@ -274,7 +274,14 @@ bool ClipModel::hasAudio() const
// Playlist clip, assume audio
return true;
}
return (service.contains(QStringLiteral("avformat")) || service == QLatin1String("timewarp")) && (getIntProperty(QStringLiteral("audio_index")) > -1);
qDebug() << "checking audio:" << service
<< ((service.contains(QStringLiteral("avformat")) || service == QLatin1String("timewarp")) &&
(getIntProperty(QStringLiteral("audio_index")) > -1));
if ((service.contains(QStringLiteral("avformat")) || service == QLatin1String("timewarp")) && (getIntProperty(QStringLiteral("audio_index")) > -1)) {
return true;
}
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(m_binClipId);
return binClip->hasAudio();
}
bool ClipModel::isAudioOnly() const
......
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