From ecc434802d1c89637e4547b6994c087b7a3d2b75 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Tue, 5 Aug 2008 23:48:35 +0000 Subject: [PATCH] * Clean up profiles handling * Add separate X11 and XVideo drivers for SDL, where X11 disables hardware accel svn path=/branches/KDE4/; revision=2364 --- src/kdenlivedoc.cpp | 14 ++-- src/kdenlivedoc.h | 2 +- src/kdenlivesettingsdialog.cpp | 3 +- src/mainwindow.cpp | 33 ++++----- src/mainwindow.h | 1 - src/monitor.cpp | 4 +- src/monitor.h | 2 +- src/monitormanager.cpp | 6 +- src/monitormanager.h | 2 +- src/renderer.cpp | 128 +++++++++++---------------------- src/renderer.h | 3 +- 11 files changed, 74 insertions(+), 124 deletions(-) diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 9e1769f1..561f411f 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -37,10 +37,8 @@ #include "mainwindow.h" -KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_profile(profile), m_fps((double)profile.frame_rate_num / profile.frame_rate_den), m_width(profile.width), m_height(profile.height), m_commandStack(new QUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(7) { - kDebug() << "// init profile, ratnum: " << profile.frame_rate_num << ", " << profile.frame_rate_num << ", width: " << profile.width; +KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, MainWindow *parent): QObject(parent), m_render(NULL), m_url(url), m_projectFolder(projectFolder), m_commandStack(new QUndoStack(undoGroup)), m_modified(false), m_documentLoadingProgress(0), m_documentLoadingStep(0.0), m_startPos(0), m_zoom(7) { m_clipManager = new ClipManager(this); - KdenliveSettings::setProject_fps(m_fps); if (!url.isEmpty()) { QString tmpFile; if (KIO::NetAccess::download(url.path(), tmpFile, parent)) { @@ -54,7 +52,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoPro QString profilePath = infoXml.attribute("profile"); m_startPos = infoXml.attribute("position").toInt(); m_zoom = infoXml.attribute("zoom", "7").toInt(); - if (!profilePath.isEmpty()) setProfilePath(profilePath); + setProfilePath(profilePath); double version = infoXml.attribute("version").toDouble(); if (version < 0.7) convertDocument(version); else { @@ -263,9 +261,7 @@ void KdenliveDoc::convertDocument(double version) { QDomNode props = m_document.elementsByTagName("properties").at(0).toElement(); QString profile = props.toElement().attribute("videoprofile"); if (profile == "dv_wide") profile = "dv_pal_wide"; - if (!profile.isEmpty()) { - setProfilePath(profile); - } else setProfilePath("dv_pal"); + setProfilePath(profile); // move playlists outside of tractor and add the tracks instead int max = playlists.count(); @@ -409,12 +405,12 @@ QString KdenliveDoc::profilePath() const { } void KdenliveDoc::setProfilePath(QString path) { - KdenliveSettings::setCurrent_profile(path); + if (path.isEmpty()) path = KdenliveSettings::default_profile(); + if (path.isEmpty()) path = "dv_pal"; m_profile = ProfilesDialog::getVideoProfile(path); m_fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den; m_width = m_profile.width; m_height = m_profile.height; - KdenliveSettings::setProject_fps(m_fps); kDebug() << "KDEnnlive document, init timecode from path: " << path << ", " << m_fps; if (m_fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true); else m_timecode.setFormat((int) m_fps); diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index 391fe90b..8dbdae19 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -45,7 +45,7 @@ class MainWindow; class KdenliveDoc: public QObject { Q_OBJECT public: - KdenliveDoc(const KUrl &url, const KUrl &projectFolder, MltVideoProfile profile, QUndoGroup *undoGroup, MainWindow *parent = 0); + KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, MainWindow *parent = 0); ~KdenliveDoc(); QDomNodeList producersList(); double fps() const; diff --git a/src/kdenlivesettingsdialog.cpp b/src/kdenlivesettingsdialog.cpp index c2b5736d..8c230108 100644 --- a/src/kdenlivesettingsdialog.cpp +++ b/src/kdenlivesettingsdialog.cpp @@ -127,7 +127,8 @@ void KdenliveSettingsDialog::initDevices() { // Fill video drivers m_configSdl.kcfg_video_driver->addItem(i18n("Automatic"), QString()); - m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11"); + m_configSdl.kcfg_video_driver->addItem(i18n("XVideo"), "x11"); + m_configSdl.kcfg_video_driver->addItem(i18n("X11"), "x11_noaccel"); m_configSdl.kcfg_video_driver->addItem(i18n("XFREE86 DGA 2.0"), "dga"); m_configSdl.kcfg_video_driver->addItem(i18n("Nano X"), "nanox"); m_configSdl.kcfg_video_driver->addItem(i18n("Framebuffer console"), "fbcon"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 106fb0e0..99b25521 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -747,13 +747,10 @@ void MainWindow::newFile() { projectFolder = w->selectedFolder(); delete w; } - MltVideoProfile prof; - if (!profileName.isEmpty()) prof = ProfilesDialog::getVideoProfile(profileName); - else prof = ProfilesDialog::getVideoProfile("dv_pal"); - if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal"); - KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, prof, m_commandStack, this); + KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, this); + doc->setProfilePath(profileName); TrackView *trackView = new TrackView(doc, this); - m_timelineArea->addTab(trackView, KIcon("kdenlive"), i18n("Untitled") + " / " + prof.description); + m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description()); if (m_timelineArea->count() == 1) { connectDocumentInfo(doc); connectDocument(trackView, doc); @@ -840,14 +837,16 @@ void MainWindow::openFile(const KUrl &url) { } //TODO: get video profile from url before opening it - MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile()); + /*MltVideoProfile prof = ProfilesDialog::getVideoProfile(KdenliveSettings::default_profile()); if (prof.width == 0) prof = ProfilesDialog::getVideoProfile("dv_pal"); + + KdenliveSettings::setCurrent_profile(prof.path);*/ KdenliveDoc *doc; if (recovery) { - doc = new KdenliveDoc(recoveryUrl, KUrl(), prof, m_commandStack, this); + doc = new KdenliveDoc(recoveryUrl, KUrl(), m_commandStack, this); doc->setUrl(url); doc->setModified(true); - } else doc = new KdenliveDoc(url, KUrl(), prof, m_commandStack, this); + } else doc = new KdenliveDoc(url, KUrl(), m_commandStack, this); connectDocumentInfo(doc); TrackView *trackView = new TrackView(doc, this); m_timelineArea->setCurrentIndex(m_timelineArea->addTab(trackView, KIcon("kdenlive"), doc->description())); @@ -855,7 +854,6 @@ void MainWindow::openFile(const KUrl &url) { if (m_timelineArea->count() > 1) m_timelineArea->setTabBarHidden(false); slotGotProgressInfo(QString(), -1); m_projectMonitor->refreshMonitor(true); - //connectDocument(trackView, doc); } @@ -923,9 +921,10 @@ void MainWindow::slotEditProjectSettings() { if (w->exec() == QDialog::Accepted) { QString profile = w->selectedProfile(); m_activeDocument->setProfilePath(profile); - m_monitorManager->resetProfiles(profile); + KdenliveSettings::setCurrent_profile(profile); + KdenliveSettings::setProject_fps(m_activeDocument->fps()); setCaption(m_activeDocument->description()); - KdenliveSettings::setCurrent_profile(m_activeDocument->profilePath()); + m_monitorManager->resetProfiles(); if (m_renderWidget) m_renderWidget->setDocumentStandard(m_activeDocument->getDocumentStandard()); m_monitorManager->setTimecode(m_activeDocument->timecode()); m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description()); @@ -1041,8 +1040,9 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha disconnect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *))); m_clipMonitor->stop(); } + KdenliveSettings::setCurrent_profile(doc->profilePath()); KdenliveSettings::setProject_fps(doc->fps()); - m_monitorManager->resetProfiles(doc->profilePath()); + m_monitorManager->resetProfiles(); m_projectList->setDocument(doc); connect(m_projectList, SIGNAL(clipSelected(DocClipBase *)), m_clipMonitor, SLOT(slotSetXml(DocClipBase *))); connect(trackView, SIGNAL(cursorMoved()), m_projectMonitor, SLOT(activateMonitor())); @@ -1084,7 +1084,6 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) { //cha connect(trackView->projectView(), SIGNAL(activateDocumentMonitor()), m_projectMonitor, SLOT(activateMonitor())); trackView->projectView()->setContextMenu(m_timelineContextMenu, m_timelineContextClipMenu, m_timelineContextTransitionMenu); m_activeTimeline = trackView; - KdenliveSettings::setCurrent_profile(doc->profilePath()); if (m_renderWidget) m_renderWidget->setDocumentStandard(doc->getDocumentStandard()); m_monitorManager->setTimecode(doc->timecode()); doc->setRenderer(m_projectMonitor->render); @@ -1116,7 +1115,7 @@ void MainWindow::slotPreferences(int page, int option) { // create it : KdenliveSettingsDialog* dialog = new KdenliveSettingsDialog(this); connect(dialog, SIGNAL(settingsChanged(const QString&)), this, SLOT(updateConfiguration())); - connect(dialog, SIGNAL(doResetProfile()), this, SLOT(resetProfiles())); + connect(dialog, SIGNAL(doResetProfile()), m_monitorManager, SLOT(resetProfiles())); dialog->show(); if (page != -1) dialog->showPage(page, option); } @@ -1135,10 +1134,6 @@ void MainWindow::updateConfiguration() { } -void MainWindow::resetProfiles() { - m_monitorManager->resetProfiles(m_activeDocument->profilePath()); -} - void MainWindow::slotSwitchVideoThumbs() { KdenliveSettings::setVideothumbnails(!KdenliveSettings::videothumbnails()); if (m_activeTimeline) { diff --git a/src/mainwindow.h b/src/mainwindow.h index a0bd27e3..640d8032 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -230,7 +230,6 @@ private slots: void slotPasteEffects(); void slotReloadEffects(); void slotChangeClipSpeed(); - void resetProfiles(); }; diff --git a/src/monitor.cpp b/src/monitor.cpp index 0048c04a..83572f93 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -325,9 +325,9 @@ void Monitor::slotOpenFile(const QString &file) { render->setSceneList(doc, 0); } -void Monitor::resetProfile(QString prof) { +void Monitor::resetProfile() { if (render == NULL) return; - render->resetProfile(prof); + render->resetProfile(); } void Monitor::saveSceneList(QString path, QDomElement info) { diff --git a/src/monitor.h b/src/monitor.h index 579e3fa0..d0814a71 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -49,7 +49,7 @@ class Monitor : public QWidget { public: Monitor(QString name, MonitorManager *manager, QWidget *parent = 0); Render *render; - void resetProfile(QString prof); + void resetProfile(); QString name() const; diff --git a/src/monitormanager.cpp b/src/monitormanager.cpp index a8045c1d..62b1773d 100644 --- a/src/monitormanager.cpp +++ b/src/monitormanager.cpp @@ -111,11 +111,11 @@ void MonitorManager::slotEnd() { else m_projectMonitor->slotEnd(); } -void MonitorManager::resetProfiles(QString prof) { +void MonitorManager::resetProfiles() { activateMonitor("clip"); - m_clipMonitor->resetProfile(prof); + m_clipMonitor->resetProfile(); activateMonitor("project"); - m_projectMonitor->resetProfile(prof); + m_projectMonitor->resetProfile(); //m_projectMonitor->refreshMonitor(true); } diff --git a/src/monitormanager.h b/src/monitormanager.h index 972dfdb9..d0470d08 100644 --- a/src/monitormanager.h +++ b/src/monitormanager.h @@ -34,7 +34,6 @@ public: void initMonitors(Monitor *clipMonitor, Monitor *projectMonitor); Timecode timecode(); void setTimecode(Timecode tc); - void resetProfiles(QString prof); void switchMonitors(); bool projectMonitorFocused(); @@ -47,6 +46,7 @@ public slots: void slotForwardOneFrame(); void slotStart(); void slotEnd(); + void resetProfiles(); private: Monitor *m_clipMonitor; diff --git a/src/renderer.cpp b/src/renderer.cpp index 12312dde..c413b931 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -28,6 +28,8 @@ extern "C" { #include } +#include + #include #include #include @@ -64,8 +66,7 @@ static void consumer_frame_show(mlt_consumer, Render * self, mlt_frame frame_ptr } Render::Render(const QString & rendererName, int winid, int extid, QWidget *parent): QObject(parent), m_name(rendererName), m_mltConsumer(NULL), m_mltProducer(NULL), m_mltTextProducer(NULL), m_winid(-1), m_framePosition(0), m_generateScenelist(false), m_isBlocked(true), m_blackClip(NULL), m_isSplitView(false) { - kDebug() << "////////// USING PROFILE: " << (char *)KdenliveSettings::current_profile().toUtf8().data(); - m_mltProfile = new Mlt::Profile((char*) KdenliveSettings::current_profile().data()); + kDebug() << "////////// USING PROFILE: " << (char*)KdenliveSettings::current_profile().toUtf8().data(); refreshTimer = new QTimer(this); connect(refreshTimer, SIGNAL(timeout()), this, SLOT(refresh())); @@ -75,66 +76,18 @@ Render::Render(const QString & rendererName, int winid, int extid, QWidget *pare connect(osdTimer, SIGNAL(timeout()), this, SLOT(slotOsdTimeout())); m_osdProfile = KStandardDirs::locate("data", "kdenlive/profiles/metadata.properties"); - //if (rendererName == "clip") - { - //Mlt::Consumer *consumer = new Mlt::Consumer( profile , "sdl_preview"); - m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer; - m_mltConsumer->set("resize", 1); - m_mltConsumer->set("window_id", winid); - m_mltConsumer->set("terminate_on_pause", 1); - m_mltConsumer->set("rescale", "nearest"); - m_mltConsumer->set("progressive", 1); - char *tmp; - - QString audioDevice = KdenliveSettings::audiodevicename(); - if (!audioDevice.isEmpty()) { - tmp = decodedString(audioDevice); - m_mltConsumer->set("audio_device", tmp); - delete[] tmp; - } - - QString videoDriver = KdenliveSettings::videodrivername(); - if (!videoDriver.isEmpty()) { - tmp = decodedString(videoDriver); - m_mltConsumer->set("video_driver", tmp); - delete[] tmp; - } - - QString audioDriver = KdenliveSettings::audiodrivername(); - if (!audioDriver.isEmpty()) { - tmp = decodedString(audioDriver); - m_mltConsumer->set("audio_driver", tmp); - delete[] tmp; - } - - m_mltConsumer->set("audio_buffer", 1024); - m_mltConsumer->set("frequency", 48000); - m_externalwinid = extid; - m_winid = winid; - m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); - Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black"); - m_mltProducer = producer; - if (m_blackClip) delete m_blackClip; - m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black"); - m_blackClip->set("id", "black"); - m_mltConsumer->connect(*m_mltProducer); - m_mltProducer->set_speed(0.0); - - //m_mltConsumer->start(); - //refresh(); - //initSceneList(); - } - /*m_osdInfo = new Mlt::Filter("data_show"); - char *tmp = decodedString(m_osdProfile); - m_osdInfo->set("resource", tmp); - delete[] tmp;*/ - // Does it do anything usefull? I mean, RenderThread doesn't do anything useful at the moment - // (except being cpu hungry :) + buildConsumer(); - /* if(!s_renderThread) { - s_renderThread = new RenderThread; - s_renderThread->start(); - } */ + m_externalwinid = extid; + m_winid = winid; + m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); + Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "colour", "black"); + m_mltProducer = producer; + if (m_blackClip) delete m_blackClip; + m_blackClip = new Mlt::Producer(*m_mltProfile , "colour", "black"); + m_blackClip->set("id", "black"); + m_mltConsumer->connect(*m_mltProducer); + m_mltProducer->set_speed(0.0); } Render::~Render() { @@ -154,32 +107,17 @@ void Render::closeMlt() { } - -int Render::resetProfile(QString profile) { - - if (!m_mltConsumer) return 0; - if (m_isSplitView) slotSplitView(false); - if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); - m_mltConsumer->purge(); - delete m_mltConsumer; - - m_mltConsumer = NULL; - QString scene = sceneList(); - if (m_mltProducer) delete m_mltProducer; - m_mltProducer = NULL; - if (m_mltProfile) delete m_mltProfile; - m_mltProfile = NULL; - - char *tmp = decodedString(profile); +void Render::buildConsumer() { + char *tmp; + tmp = decodedString(KdenliveSettings::current_profile()); m_mltProfile = new Mlt::Profile(tmp); delete[] tmp; - m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); //consumer; + m_mltConsumer = new Mlt::Consumer(*m_mltProfile , "sdl_preview"); m_mltConsumer->set("resize", 1); m_mltConsumer->set("window_id", m_winid); m_mltConsumer->set("terminate_on_pause", 1); m_mltConsumer->listen("consumer-frame-show", this, (mlt_listener) consumer_frame_show); m_mltConsumer->set("rescale", "nearest"); - QString audioDevice = KdenliveSettings::audiodevicename(); if (!audioDevice.isEmpty()) { tmp = decodedString(audioDevice); @@ -189,9 +127,15 @@ int Render::resetProfile(QString profile) { QString videoDriver = KdenliveSettings::videodrivername(); if (!videoDriver.isEmpty()) { - tmp = decodedString(videoDriver); - m_mltConsumer->set("video_driver", tmp); - delete[] tmp; + if (videoDriver == "x11_noaccel") { + setenv("SDL_VIDEO_YUV_HWACCEL", "0", 1); + m_mltConsumer->set("video_driver", "x11"); + } else { + unsetenv("SDL_VIDEO_YUV_HWACCEL"); + tmp = decodedString(videoDriver); + m_mltConsumer->set("video_driver", tmp); + delete[] tmp; + } } QString audioDriver = KdenliveSettings::audiodrivername(); @@ -205,11 +149,26 @@ int Render::resetProfile(QString profile) { m_mltConsumer->set("progressive", 1); m_mltConsumer->set("audio_buffer", 1024); m_mltConsumer->set("frequency", 48000); +} + +int Render::resetProfile() { + if (!m_mltConsumer) return 0; + if (m_isSplitView) slotSplitView(false); + if (!m_mltConsumer->is_stopped()) m_mltConsumer->stop(); + m_mltConsumer->purge(); + delete m_mltConsumer; + m_mltConsumer = NULL; + QString scene = sceneList(); + if (m_mltProducer) delete m_mltProducer; + m_mltProducer = NULL; + if (m_mltProfile) delete m_mltProfile; + m_mltProfile = NULL; + buildConsumer(); kDebug() << "//RESET WITHSCENE: " << scene; setSceneList(scene); - tmp = decodedString(scene); + char *tmp = decodedString(scene); Mlt::Producer *producer = new Mlt::Producer(*m_mltProfile , "westley-xml", tmp); delete[] tmp; m_mltProducer = producer; @@ -226,7 +185,6 @@ int Render::resetProfile(QString profile) { //mlt_properties_set(properties, "profile", "hdv_1080_50i"); //m_mltConsumer->set("profile", (char *) profile.toUtf8().data()); //m_mltProfile = new Mlt::Profile((char*) profile.toUtf8().data()); - kDebug() << " ++++++++++ RESET CONSUMER WITH PROFILE: " << profile << ", WIDTH: " << m_mltProfile->width(); //apply_profile_properties( m_mltProfile, m_mltConsumer->get_consumer(), properties ); //refresh(); diff --git a/src/renderer.h b/src/renderer.h index b0a1cc38..b2b57881 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -140,7 +140,7 @@ Q_OBJECT public: /** Turn on or off on screen display */ void refreshDisplay(); - int resetProfile(QString profile); + int resetProfile(); const double fps() const; const int renderWidth() const; const int renderHeight() const; @@ -215,6 +215,7 @@ private: // Private attributes & methods void mltCheckLength(bool reload = true); QMap mltGetTransitionParamsFromXml(QDomElement xml); QMap m_slowmotionProducers; + void buildConsumer(); private slots: // Private slots /** refresh monitor display */ -- 2.39.2