]> git.sesse.net Git - kdenlive/blobdiff - src/renderer.cpp
Various changes for getting an OpenGL context (almost) everywhere it is needed.
[kdenlive] / src / renderer.cpp
index 041f82abd598ec37dc24014e57c620929aef4794..d141a4f6ace583e4a1570853cb2540c2e733c64e 100644 (file)
@@ -35,7 +35,7 @@
 #include <KDebug>
 #include <KStandardDirs>
 #include <KMessageBox>
-#include <KLocale>
+#include <KLocalizedString>
 #include <KTemporaryFile>
 
 #include <QTimer>
@@ -111,7 +111,7 @@ void Render::consumer_gl_frame_show(mlt_consumer consumer, Render * self, mlt_fr
     emit self->mltFrameReceived(new Mlt::Frame(frame_ptr));
 }
 
-Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWidget *parent) :
+Render::Render(Kdenlive::MonitorId rendererName, int winid, QString profile, QWidget *parent, QGLWidget *mainGLContext) :
     AbstractRender(rendererName, parent),
     requestedSeekPosition(SEEK_INACTIVE),
     showFrameSemaphore(1),
@@ -128,7 +128,9 @@ Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWi
     m_blackClip(NULL),
     m_winid(winid),
     m_paused(true),
-    m_isActive(false)
+    m_isActive(false),
+    m_mainGLContext(mainGLContext),
+    m_GLContext(NULL)
 {
     qRegisterMetaType<stringMap> ("stringMap");
     analyseAudio = KdenliveSettings::monitor_audio();
@@ -140,16 +142,21 @@ Render::Render(Kdenlive::MONITORID rendererName, int winid, QString profile, QWi
     m_mltProducer->set_speed(0.0);
     m_refreshTimer.setSingleShot(true);
     m_refreshTimer.setInterval(100);
+    m_glslManager = new Mlt::Filter(*m_mltProfile, "glsl.manager");
     connect(&m_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
     connect(this, SIGNAL(multiStreamFound(QString,QList<int>,QList<int>,stringMap)), this, SLOT(slotMultiStreamProducerFound(QString,QList<int>,QList<int>,stringMap)));
     connect(this, SIGNAL(checkSeeking()), this, SLOT(slotCheckSeeking()));
     connect(this, SIGNAL(mltFrameReceived(Mlt::Frame*)), this, SLOT(showFrame(Mlt::Frame*)), Qt::UniqueConnection);
+
+    m_GLContext = new QGLWidget(0, m_mainGLContext);
+    m_GLContext->resize(0, 0);
 }
 
 Render::~Render()
 {
     closeMlt();
     delete m_mltProfile;
+    delete m_GLContext;
 }
 
 
@@ -227,7 +234,7 @@ void Render::buildConsumer(const QString &profileName)
     m_blackClip = new Mlt::Producer(*m_mltProfile, "colour:black");
     m_blackClip->set("id", "black");
     m_blackClip->set("mlt_type", "producer");
-    if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor && m_winid != 0) {
+    if (KdenliveSettings::external_display() && m_name != Kdenlive::ClipMonitor && m_winid != 0) {
         // Use blackmagic card for video output
         int device = KdenliveSettings::blackmagic_output_device();
         if (device >= 0) {
@@ -267,7 +274,7 @@ void Render::buildConsumer(const QString &profileName)
     if (m_winid == 0) {
         // OpenGL monitor
         if (!m_mltConsumer) {
-            if (KdenliveSettings::external_display() && m_name != Kdenlive::clipMonitor) {
+            if (KdenliveSettings::external_display() && m_name != Kdenlive::ClipMonitor) {
                 int device = KdenliveSettings::blackmagic_output_device();
                 if (device >= 0) {
                     QString decklink = "decklink:" + QString::number(KdenliveSettings::blackmagic_output_device());
@@ -704,6 +711,10 @@ bool Render::isProcessing(const QString &id)
 
 void Render::processFileProperties()
 {
+    // We are in a new thread, so we need a new OpenGL context for the remainder of the function.
+    QGLWidget ctx(0, m_mainGLContext);
+    ctx.makeCurrent();
+
     requestClipInfo info;
     QLocale locale;
     while (!m_requestList.isEmpty()) {
@@ -731,10 +742,10 @@ void Render::processFileProperties()
         }
         KUrl url(path);
         Mlt::Producer *producer = NULL;
-        CLIPTYPE type = (CLIPTYPE)info.xml.attribute("type").toInt();
-        if (type == COLOR) {
+        ClipType type = (ClipType)info.xml.attribute("type").toInt();
+        if (type == Color) {
             producer = new Mlt::Producer(*m_mltProfile, 0, ("colour:" + info.xml.attribute("colour")).toUtf8().constData());
-        } else if (type == TEXT) {
+        } else if (type == Text) {
             producer = new Mlt::Producer(*m_mltProfile, 0, ("kdenlivetitle:" + info.xml.attribute("resource")).toUtf8().constData());
             if (producer && producer->is_valid() && info.xml.hasAttribute("xmldata"))
                 producer->set("xmldata", info.xml.attribute("xmldata").toUtf8().constData());
@@ -837,7 +848,7 @@ void Render::processFileProperties()
         if (info.xml.hasAttribute("out")) clipOut = info.xml.attribute("out").toInt();
 
         // setup length here as otherwise default length (currently 15000 frames in MLT) will be taken even if outpoint is larger
-        if (type == COLOR || type == TEXT || type == IMAGE || type == SLIDESHOW) {
+        if (type == Color || type == Text || type == Image || type == SlideShow) {
             int length;
             if (info.xml.hasAttribute("length")) {
                 length = info.xml.attribute("length").toInt();
@@ -892,7 +903,7 @@ void Render::processFileProperties()
         filePropertyMap["duration"] = QString::number(duration);
         //kDebug() << "///////  PRODUCER: " << url.path() << " IS: " << producer->get_playtime();
 
-        if (type == SLIDESHOW) {
+        if (type == SlideShow) {
             int ttl = info.xml.hasAttribute("ttl") ? info.xml.attribute("ttl").toInt() : 0;
             if (ttl) producer->set("ttl", ttl);
             if (!info.xml.attribute("animation").isEmpty()) {
@@ -1413,6 +1424,7 @@ void Render::checkMaxThreads()
 
 const QString Render::sceneList()
 {
+    if (!m_mltProducer) return QString();
     QString playlist;
     Mlt::Profile profile((mlt_profile) 0);
     Mlt::Consumer xmlConsumer(profile, "xml:kdenlive_playlist");
@@ -1459,7 +1471,7 @@ void Render::saveZone(KUrl url, QString desc, QPoint zone)
     Mlt::Consumer xmlConsumer(*m_mltProfile, ("xml:" + url.path()).toUtf8().constData());
     m_mltProducer->optimise();
     xmlConsumer.set("terminate_on_pause", 1);
-    if (m_name == Kdenlive::clipMonitor) {
+    if (m_name == Kdenlive::ClipMonitor) {
         Mlt::Producer *prod = m_mltProducer->cut(zone.x(), zone.y());
         Mlt::Playlist list;
         list.insert_at(0, prod, 0);
@@ -1524,7 +1536,7 @@ void Render::slotSetVolume(int volume)
 {
     if (!m_mltConsumer || !m_mltProducer) return;
     m_mltProducer->set("meta.volume", (double)volume / 100.0);
-    return;
+    //return;
     /*osdTimer->stop();
     m_mltConsumer->set("refresh", 0);
     // Attach filter for on screen display of timecode
@@ -1538,7 +1550,7 @@ void Render::slotSetVolume(int volume)
     mlt_properties_set_int( properties, "meta.attr.timecode", 0);
      if (m_mltProducer->attach(*m_osdInfo) == 1) kDebug()<<"////// error attaching filter";
     }*/
-    refresh();
+    //refresh();
     //m_osdTimer->setSingleShot(2500);
 }
 
@@ -1632,7 +1644,7 @@ void Render::switchPlay(bool play)
         return;
     if (m_isZoneMode) resetZoneMode();
     if (play && m_paused) {
-        if (m_name == Kdenlive::clipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
+        if (m_name == Kdenlive::ClipMonitor && m_mltConsumer->position() == m_mltProducer->get_out()) m_mltProducer->seek(0);
         m_paused = false;
         m_mltProducer->set_speed(1.0);
         if (m_mltConsumer->is_stopped()) {
@@ -3170,6 +3182,7 @@ bool Render::mltEnableEffects(int track, const GenTime &position, const QList <i
     int ct = 0;
 
     Mlt::Filter *filter = clip->filter(ct);
+    service.lock();
     while (filter) {
         if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
             filter->set("disable", (int) disable);
@@ -3195,6 +3208,7 @@ bool Render::mltEnableTrackEffects(int track, const QList <int> &effectIndexes,
     int ct = 0;
 
     Mlt::Filter *filter = clipService.filter(ct);
+    service.lock();
     while (filter) {
         if (effectIndexes.contains(filter->get_int("kdenlive_ix"))) {
             filter->set("disable", (int) disable);
@@ -4090,7 +4104,7 @@ void Render::mltDeleteTransition(QString tag, int /*a_track*/, int b_track, GenT
     //if (m_isBlocked == 0) m_mltConsumer->set("refresh", 1);
 }
 
-QMap<QString, QString> Render::mltGetTransitionParamsFromXml(QDomElement xml)
+QMap<QString, QString> Render::mltGetTransitionParamsFromXml(const QDomElement &xml)
 {
     QDomNodeList attribs = xml.elementsByTagName("parameter");
     QMap<QString, QString> map;
@@ -4566,7 +4580,7 @@ void Render::updatePreviewSettings()
 }
 
 
-QString Render::updateSceneListFps(double current_fps, double new_fps, QString scene)
+QString Render::updateSceneListFps(double current_fps, double new_fps, const QString &scene)
 {
     // Update all frame positions to the new fps value
     //WARNING: there are probably some effects or other that hold a frame value
@@ -4733,7 +4747,7 @@ bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist, bool force)
     return true;
 }
 
-void Render::slotMultiStreamProducerFound(const QString path, QList<int> audio_list, QList<int> video_list, stringMap data)
+void Render::slotMultiStreamProducerFound(const QString &path, QList<int> audio_list, QList<int> video_list, stringMap data)
 { 
     if (KdenliveSettings::automultistreams()) {
         for (int i = 1; i < video_list.count(); ++i) {