X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Frenderer.cpp;h=d141a4f6ace583e4a1570853cb2540c2e733c64e;hb=a3eee7be24126f5a3458d488f44cd61c66135e17;hp=4971ce0f9a307fb687aa8c9d2c9aba2496882348;hpb=b01ea4492797423d21852d87ee942bb4b15783b6;p=kdenlive diff --git a/src/renderer.cpp b/src/renderer.cpp index 4971ce0f..d141a4f6 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include @@ -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,27 +128,35 @@ 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"); analyseAudio = KdenliveSettings::monitor_audio(); - if (profile.isEmpty()) profile = KdenliveSettings::current_profile(); + if (profile.isEmpty()) + profile = KdenliveSettings::current_profile(); buildConsumer(profile); m_mltProducer = m_blackClip->cut(0, 1); m_mltConsumer->connect(*m_mltProducer); 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,QList,stringMap)), this, SLOT(slotMultiStreamProducerFound(QString,QList,QList,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; } @@ -157,10 +165,10 @@ void Render::closeMlt() //delete m_osdTimer; m_requestList.clear(); m_infoThread.waitForFinished(); - if (m_showFrameEvent) delete m_showFrameEvent; - if (m_pauseEvent) delete m_pauseEvent; - if (m_mltConsumer) delete m_mltConsumer; - if (m_mltProducer) delete m_mltProducer; + delete m_showFrameEvent; + delete m_pauseEvent; + delete m_mltConsumer; + delete m_mltProducer; /*if (m_mltProducer) { Mlt::Service service(m_mltProducer->parent().get_service()); service.lock(); @@ -191,13 +199,14 @@ void Render::closeMlt() }*/ //kDebug() << "// // // CLOSE RENDERER " << m_name; - if (m_blackClip) delete m_blackClip; + delete m_blackClip; //delete m_osdInfo; } void Render::slotSwitchFullscreen() { - if (m_mltConsumer) m_mltConsumer->set("full_screen", 1); + if (m_mltConsumer) + m_mltConsumer->set("full_screen", 1); } void Render::buildConsumer(const QString &profileName) @@ -216,8 +225,7 @@ void Render::buildConsumer(const QString &profileName) m_mltProfile->set_sample_aspect(tmpProfile.sample_aspect_num(), tmpProfile.sample_aspect_den()); m_mltProfile->get_profile()->display_aspect_num = tmpProfile.display_aspect_num(); m_mltProfile->get_profile()->display_aspect_den = tmpProfile.display_aspect_den(); - } - else { + } else { m_mltProfile = new Mlt::Profile(m_activeProfile.toUtf8().constData()); } setenv("MLT_PROFILE", m_activeProfile.toUtf8().constData(), 1); @@ -226,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) { @@ -266,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()); @@ -332,8 +340,9 @@ Mlt::Producer *Render::invalidProducer(const QString &id) char *tmp = qstrdup(txt.toUtf8().constData()); clip = new Mlt::Producer(*m_mltProfile, tmp); delete[] tmp; - if (clip == NULL) clip = new Mlt::Producer(*m_mltProfile, "colour", "red"); - else { + if (clip == NULL) { + clip = new Mlt::Producer(*m_mltProfile, "colour", "red"); + } else { clip->set("bgcolour", "0xff0000ff"); clip->set("pad", "10"); } @@ -364,12 +373,15 @@ int Render::resetProfile(const QString &profileName, bool dropSceneList) } } - if (m_isSplitView) slotSplitView(false); - if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); + if (m_isSplitView) + slotSplitView(false); + if (!m_mltConsumer->is_stopped()) + m_mltConsumer->stop(); m_mltConsumer->purge(); } QString scene; - if (!dropSceneList) scene = sceneList(); + if (!dropSceneList) + scene = sceneList(); int pos = 0; double current_fps = m_mltProfile->fps(); double current_dar = m_mltProfile->dar(); @@ -475,7 +487,7 @@ int Render::renderHeight() const return m_mltProfile->height(); } -QImage Render::extractFrame(int frame_position, QString path, int width, int height) +QImage Render::extractFrame(int frame_position, const QString &path, int width, int height) { if (width == -1) { width = frameRenderWidth(); @@ -699,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()) { @@ -726,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()); @@ -832,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(); @@ -887,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()) { @@ -1408,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"); @@ -1454,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); @@ -1519,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 @@ -1533,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); } @@ -1627,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()) { @@ -3032,7 +3049,7 @@ bool Render::mltEditTrackEffect(int track, EffectsParameterList params) return true; } -bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList params) +bool Render::mltEditEffect(int track, const GenTime &position, EffectsParameterList params) { int index = params.paramValue("kdenlive_ix").toInt(); QString tag = params.paramValue("tag"); @@ -3112,7 +3129,8 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par delete clip; service.unlock(); - if (doRefresh) refresh(); + if (doRefresh) + refresh(); return true; } if (params.hasParam("_sync_in_out")) { @@ -3121,22 +3139,23 @@ bool Render::mltEditEffect(int track, GenTime position, EffectsParameterList par filter->set_in_and_out(clip->get_in(), clip->get_out()); } - for (int j = 0; j < params.count(); j++) { + for (int j = 0; j < params.count(); ++j) { filter->set(params.at(j).name().toUtf8().constData(), params.at(j).value().toUtf8().constData()); } - for (int j = 0; j < filtersList.count(); j++) { + for (int j = 0; j < filtersList.count(); ++j) { clip->attach(*(filtersList.at(j))); } delete clip; service.unlock(); - if (doRefresh) refresh(); + if (doRefresh) + refresh(); return true; } -bool Render::mltEnableEffects(int track, GenTime position, QList effectIndexes, bool disable) +bool Render::mltEnableEffects(int track, const GenTime &position, const QList &effectIndexes, bool disable) { if (position < GenTime()) { return mltEnableTrackEffects(track, effectIndexes, disable); @@ -3163,6 +3182,7 @@ bool Render::mltEnableEffects(int track, GenTime position, QList effectInd 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); @@ -3178,7 +3198,7 @@ bool Render::mltEnableEffects(int track, GenTime position, QList effectInd return true; } -bool Render::mltEnableTrackEffects(int track, QList effectIndexes, bool disable) +bool Render::mltEnableTrackEffects(int track, const QList &effectIndexes, bool disable) { Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); @@ -3188,6 +3208,7 @@ bool Render::mltEnableTrackEffects(int track, QList effectIndexes, bool di 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); @@ -3201,7 +3222,7 @@ bool Render::mltEnableTrackEffects(int track, QList effectIndexes, bool di return true; } -void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos) +void Render::mltUpdateEffectPosition(int track, const GenTime &position, int oldPos, int newPos) { Mlt::Service service(m_mltProducer->parent().get_service()); Mlt::Tractor tractor(service); @@ -3235,7 +3256,7 @@ void Render::mltUpdateEffectPosition(int track, GenTime position, int oldPos, in if (doRefresh) refresh(); } -void Render::mltMoveEffect(int track, GenTime position, int oldPos, int newPos) +void Render::mltMoveEffect(int track, const GenTime &position, int oldPos, int newPos) { if (position < GenTime()) { mltMoveTrackEffect(track, oldPos, newPos); @@ -4083,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 Render::mltGetTransitionParamsFromXml(QDomElement xml) +QMap Render::mltGetTransitionParamsFromXml(const QDomElement &xml) { QDomNodeList attribs = xml.elementsByTagName("parameter"); QMap map; @@ -4559,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 @@ -4726,7 +4747,7 @@ bool Render::getBlackMagicOutputDeviceList(KComboBox *devicelist, bool force) return true; } -void Render::slotMultiStreamProducerFound(const QString path, QList audio_list, QList video_list, stringMap data) +void Render::slotMultiStreamProducerFound(const QString &path, QList audio_list, QList video_list, stringMap data) { if (KdenliveSettings::automultistreams()) { for (int i = 1; i < video_list.count(); ++i) {