Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Fix glwidget crash because of null producer

parent cc7a0e25
......@@ -693,7 +693,7 @@
<label>Show ratings in project tree view.</label>
<default>false</default>
</entry>
<entry name="showdatecolumn" type="Bool">
<label>Show dates in project tree view.</label>
<default>false</default>
......
......@@ -1952,7 +1952,6 @@ void MainWindow::connectDocument()
connect(project, &KdenliveDoc::startAutoSave, pCore->projectManager(), &ProjectManager::slotStartAutoSave);
connect(project, &KdenliveDoc::reloadEffects, this, &MainWindow::slotReloadEffects);
KdenliveSettings::setProject_fps(pCore->getCurrentFps());
m_clipMonitorDock->raise();
// TODO REFAC: reconnect to new timeline
/*
......@@ -2058,7 +2057,6 @@ void MainWindow::connectDocument()
m_normalEditTool->setChecked(true);
connect(m_projectMonitor, &Monitor::durationChanged, this, &MainWindow::slotUpdateProjectDuration);
pCore->monitorManager()->setDocument(project);
// TODO REFAC: fix
// trackView->updateProfile(1.0);
// Init document zone
......
......@@ -119,7 +119,9 @@ GLWidget::GLWidget(int id, QObject *parent)
m_refreshTimer.setInterval(50);
m_blackClip.reset(new Mlt::Producer(*m_monitorProfile, "color:black"));
m_blackClip->set("kdenlive:id", "black");
m_blackClip->set("out", 3);
connect(&m_refreshTimer, &QTimer::timeout, this, &GLWidget::refresh);
m_producer = &*m_blackClip;
if (KdenliveSettings::gpu_accel()) {
m_glslManager = new Mlt::Filter(*m_monitorProfile, "glsl.manager");
......@@ -158,6 +160,7 @@ GLWidget::~GLWidget()
delete m_frameRenderer;
}
}
m_blackClip.reset();
delete m_shareContext;
delete m_shader;
delete m_monitorProfile;
......@@ -239,6 +242,7 @@ void GLWidget::initializeGL()
connect(this, &GLWidget::textureUpdated, this, &GLWidget::update, Qt::QueuedConnection);
m_initSem.release();
m_isInitialized = true;
reconfigure();
}
void GLWidget::resizeGL(int width, int height)
......@@ -581,6 +585,9 @@ void GLWidget::wheelEvent(QWheelEvent *event)
void GLWidget::requestSeek()
{
if (m_producer == nullptr) {
return;
}
if (m_proxy->seekPosition() != SEEK_INACTIVE) {
if (m_producer->get_speed() != 0) {
m_consumer->purge();
......@@ -825,17 +832,33 @@ void GLWidget::slotSwitchAudioOverlay(bool enable)
removeAudioOverlay();
}
}
if (enable && !m_audioWaveDisplayed) {
if (enable && !m_audioWaveDisplayed && m_producer != nullptr) {
createAudioOverlay(m_producer->get_int("video_index") == -1);
}
}
int GLWidget::setProducer(Mlt::Producer *producer)
int GLWidget::setProducer(Mlt::Producer *producer, int position)
{
int error = 0; // Controller::setProducer(producer, isMulti);
m_producer = producer;
m_producer->set_speed(0);
int error = 0;
QString currentId;
int consumerPosition = 0;
if (producer != nullptr) {
currentId = m_producer->get("kdenlive:id");
m_producer = producer;
} else {
if (m_audioWaveDisplayed) {
removeAudioOverlay();
}
m_producer = &*m_blackClip;
}
if (m_producer) {
m_producer->set_speed(0);
if (m_consumer) {
consumerPosition = m_consumer->position();
if (!m_consumer->is_stopped()) {
m_consumer->stop();
}
}
error = reconfigure();
if (error == 0) {
// The profile display aspect ratio may have changed.
......@@ -847,6 +870,7 @@ int GLWidget::setProducer(Mlt::Producer *producer)
if (!m_consumer) {
return error;
}
consumerPosition = m_consumer->position();
if (m_producer->get_int("video_index") == -1) {
// This is an audio only clip, attach visualization filter. Currently, the filter crashes MLT when Movit accel is used
if (!m_audioWaveDisplayed) {
......@@ -868,6 +892,17 @@ int GLWidget::setProducer(Mlt::Producer *producer)
} else if (KdenliveSettings::displayAudioOverlay()) {
createAudioOverlay(false);
}
if (position == -1 && m_producer->get("kdenlive:id") == currentId) {
position = consumerPosition;
}
if (position != -1) {
m_producer->seek(position);
}
//if (isActive) {
startConsumer();
// emit durationChanged(m_producer->get_length() - 1, m_producer->get_in());
position = m_producer->position();
rootObject()->setProperty("consumerPosition", position);
return error;
}
......@@ -1734,7 +1769,7 @@ void GLWidget::setRulerInfo(int duration, std::shared_ptr<MarkerListModel> model
}
}
bool GLWidget::setProducer(Mlt::Producer *producer, int position, bool isActive)
bool GLWidget::replaceProducer(Mlt::Producer *producer, int position, bool isActive)
{
m_refreshTimer.stop();
m_proxy->setSeekPosition(SEEK_INACTIVE);
......@@ -1752,18 +1787,17 @@ bool GLWidget::setProducer(Mlt::Producer *producer, int position, bool isActive)
// We need to make some cleanup
Mlt::Tractor trac(*m_producer);
for (int i = 0; i < trac.count(); i++) {
trac.set_track(*m_blackClip, i);
trac.set_track(*new Mlt::Producer(*m_blackClip), i);
}
}
delete m_producer;
m_producer = nullptr;
//delete m_producer;
m_producer = &*m_blackClip;
}
if (m_consumer) {
if (!m_consumer->is_stopped()) {
isActive = true;
m_consumer->stop();
}
consumerPosition = m_consumer->position();
}
if ((producer == nullptr) || !producer->is_valid()) {
producer = m_blackClip.data()->cut(0, 1);
......
......@@ -60,6 +60,7 @@ class GLWidget : public QQuickView, protected QOpenGLFunctions
public:
friend class MonitorController;
friend class Monitor;
GLWidget(int id, QObject *parent = nullptr);
~GLWidget();
......@@ -69,8 +70,6 @@ public:
void startGlsl();
void stopGlsl();
void clear();
/** @brief Update producer, should ONLY be called from renderer.cpp */
int setProducer(Mlt::Producer *producer);
int reconfigureMulti(const QString &params, const QString &path, Mlt::Profile *profile);
void stopCapture();
int reconfigure(Mlt::Profile *profile = nullptr);
......@@ -114,7 +113,7 @@ public:
MonitorProxy *getControllerProxy();
bool playZone(bool loop = false);
bool loopClip();
bool setProducer(Mlt::Producer *producer, int position, bool isActive);
bool replaceProducer(Mlt::Producer *producer, int position, bool isActive);
void startConsumer();
void stop();
int rulerHeight() const;
......@@ -133,6 +132,8 @@ protected:
void mouseReleaseEvent(QMouseEvent *event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override;
/** @brief Update producer, should ONLY be called from monitor */
int setProducer(Mlt::Producer *producer, int position = -1);
public slots:
void seek(int pos);
......
......@@ -1305,7 +1305,7 @@ void Monitor::slotLoopClip()
void Monitor::updateClipProducer(Mlt::Producer *prod)
{
if (m_glMonitor->setProducer(prod, -1, false)) {
if (m_glMonitor->setProducer(prod, -1)) {
prod->set_speed(1.0);
}
}
......@@ -1314,7 +1314,7 @@ void Monitor::updateClipProducer(const QString &playlist)
{
//TODO
Mlt::Producer *prod = new Mlt::Producer(*m_glMonitor->profile(), playlist.toUtf8().constData());
//m_glMonitor->setProducer(prod, render->seekFramePosition(), true);
//m_glMonitor->setProducer(prod, render->seekFramePosition());
m_glMonitor->switchPlay(true);
}
......@@ -1350,12 +1350,12 @@ void Monitor::slotOpenClip(std::shared_ptr<ProjectClip> controller, int in, int
if (m_playAction->isActive()) {
m_playAction->setActive(false);
}
m_glMonitor->setProducer(m_controller->masterProducer(), in, isActive());
m_glMonitor->setProducer(m_controller->masterProducer(), in);
m_audioMeterWidget->audioChannels = controller->audioInfo() ? controller->audioInfo()->channels() : 0;
emit requestAudioThumb(controller->AbstractProjectItem::clipId());
// hasEffects = controller->hasEffects();
} else {
m_glMonitor->setProducer(nullptr, -1, isActive());
m_glMonitor->setProducer(nullptr);
m_glMonitor->setAudioThumb();
m_audioMeterWidget->audioChannels = 0;
}
......
......@@ -53,6 +53,7 @@ Timecode MonitorManager::timecode() const
void MonitorManager::setDocument(KdenliveDoc *doc)
{
m_document = doc;
activateMonitor(Kdenlive::ProjectMonitor);
}
QAction *MonitorManager::getAction(const QString &name)
......@@ -154,6 +155,7 @@ bool MonitorManager::activateMonitor(Kdenlive::MonitorId name, bool forceRefresh
}
}
if (m_activeMonitor) {
qDebug()<<"Acrivate mon 2";
m_activeMonitor->blockSignals(true);
m_activeMonitor->parentWidget()->raise();
if (name == Kdenlive::ClipMonitor) {
......
......@@ -81,7 +81,7 @@ Render::Render(Kdenlive::MonitorId rendererName, BinController *binController, G
m_blackClip->set("aspect_ratio", 1);
m_blackClip->set("set.test_audio", 0);
m_mltProducer = m_blackClip->cut(0, 1);
m_qmlView->setProducer(m_mltProducer);
//m_qmlView->setProducer(m_mltProducer);
m_mltConsumer = qmlView->consumer();
}
/*m_mltConsumer->connect(*m_mltProducer);
......@@ -328,7 +328,7 @@ bool Render::updateProducer(Mlt::Producer *producer)
m_fps = producer->get_fps();
m_mltProducer = producer;
if (m_qmlView) {
m_qmlView->setProducer(producer);
//m_qmlView->setProducer(producer);
m_mltConsumer = m_qmlView->consumer();
}
return true;
......@@ -383,7 +383,7 @@ bool Render::setProducer(Mlt::Producer *producer, int position, bool isActive)
m_mltProducer = producer;
m_mltProducer->set_speed(0);
if (m_qmlView) {
m_qmlView->setProducer(producer);
//m_qmlView->setProducer(producer);
m_mltConsumer = m_qmlView->consumer();
// m_mltConsumer->set("refresh", 1);
}
......
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