+void ProjectList::slotCreateProxy(const QString id)
+{
+ ProjectItem *item = getItemById(id);
+ if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
+ QString path = item->referencedClip()->getProperty("proxy");
+ if (path.isEmpty()) {
+ setProxyStatus(item, JOBCRASHED);
+ return;
+ }
+ setProxyStatus(item, JOBWAITING);
+ if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
+ if (m_processingProxy.contains(path)) {
+ // Proxy is already being generated
+ return;
+ }
+ if (QFileInfo(path).size() > 0) {
+ // Proxy already created
+ setProxyStatus(item, JOBDONE);
+ slotGotProxy(path);
+ return;
+ }
+ m_processingProxy.append(path);
+
+ /*PROXYINFO info;
+ info.dest = path;
+ info.src = item->clipUrl().path();
+ info.type = item->clipType();
+ info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();*/
+ ProxyJob *job = new ProxyJob(PROXYJOB, item->clipType(), item->clipId(), QStringList() << path << item->clipUrl().path() << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
+ m_jobList.append(job);
+ int ct = 0;
+ if (!m_proxyThreads.futures().isEmpty()) {
+ // Remove inactive threads
+ QList <QFuture<void> > futures = m_proxyThreads.futures();
+ m_proxyThreads.clearFutures();
+ for (int i = 0; i < futures.count(); i++)
+ if (!futures.at(i).isFinished()) {
+ m_proxyThreads.addFuture(futures.at(i));
+ ct++;
+ }
+ }
+ emit jobCount(ct + m_jobList.count());
+
+ if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy));
+}
+
+void ProjectList::slotAbortProxy(const QString id, const QString path)
+{
+ QTreeWidgetItemIterator it(m_listView);
+ ProjectItem *item = getItemById(id);
+ if (!item) return;
+ if (!path.isEmpty() && m_processingProxy.contains(path)) {
+ m_abortProxy << path;
+ }
+ else {
+ // Should only be done if we were already using a proxy producer
+ if (!item->isProxyRunning()) slotGotProxy(item);
+ }
+}
+
+void ProjectList::slotGenerateProxy()
+{
+ while (!m_jobList.isEmpty() && !m_abortAllJobs) {
+ emit projectModified();
+ AbstractClipJob *job = m_jobList.takeFirst();
+ // Get jobs count
+ int ct = 0;
+ QList <QFuture<void> > futures = m_proxyThreads.futures();
+ for (int i = 0; i < futures.count(); i++)
+ if (futures.at(i).isRunning()) {
+ ct++;
+ }
+ emit jobCount(ct + m_jobList.count());
+
+ if (job->jobType == PROXYJOB) {
+ //ProxyJob *pjob = static_cast<ProxyJob *> (job);
+ kDebug()<<"// STARTING JOB: "<<job->destination();
+ if (m_abortProxy.contains(job->destination())) {
+ m_abortProxy.removeAll(job->destination());
+ m_processingProxy.removeAll(job->destination());
+ emit cancelRunningJob(job->clipId(), job->cancelProperties());
+ delete job;
+ continue;
+ }
+ }
+
+ // Get the list of clips that will need to get progress info
+ QTreeWidgetItemIterator it(m_listView);
+ QList <ProjectItem *> processingItems;
+ ProjectItem *item = getItemById(job->clipId());
+ processingItems.append(item);
+
+ /*while (*it && !m_abortAllJobs) {
+ if ((*it)->type() == PROJECTCLIPTYPE) {
+ ProjectItem *item = static_cast <ProjectItem *>(*it);
+ if (item->referencedClip()->getProperty("proxy") == job->destination()) {
+ processingItems.append(item);
+ }
+ }
+ ++it;
+ }*/
+
+ // Make sure proxy path is writable
+ QFile file(job->destination());
+ if (!file.open(QIODevice::WriteOnly)) {
+ for (int i = 0; i < processingItems.count(); i++)
+ setProxyStatus(processingItems.at(i), JOBCRASHED);
+ m_processingProxy.removeAll(job->destination());
+ delete job;
+ continue;
+ }
+ file.close();
+ QFile::remove(job->destination());
+
+ for (int i = 0; i < processingItems.count(); i++)
+ setProxyStatus(processingItems.at(i), CREATINGJOB, 0); //, job->description);
+ bool success;
+ QProcess *jobProcess = job->startJob(&success);
+
+ int result = -1;
+ if (jobProcess == NULL) {
+ // job is finished
+ for (int i = 0; i < processingItems.count(); i++)
+ setProxyStatus(processingItems.at(i), success ? JOBDONE : JOBCRASHED);
+ if (success) {
+ slotGotProxy(job->destination());
+ }
+ else {
+ QFile::remove(job->destination());
+ }
+ m_abortProxy.removeAll(job->destination());
+ m_processingProxy.removeAll(job->destination());
+ delete job;
+ continue;
+ }
+ else while (jobProcess->state() != QProcess::NotRunning) {
+ // building proxy file
+ if (m_abortProxy.contains(job->destination()) || m_abortAllJobs) {
+ jobProcess->close();
+ jobProcess->waitForFinished();
+ QFile::remove(job->destination());
+ m_abortProxy.removeAll(job->destination());
+ m_processingProxy.removeAll(job->destination());
+ if (!m_closing) {
+ emit cancelRunningJob(job->clipId(), job->cancelProperties());
+ /*for (int i = 0; i < processingItems.count(); i++)
+ setProxyStatus(processingItems.at(i), NOJOB);*/
+ }
+ else continue;
+ result = -2;
+ }
+ else {
+ int progress = job->processLogInfo();
+ if (progress > -1) processLogInfo(processingItems, progress);
+ }
+ jobProcess->waitForFinished(500);
+ }
+ jobProcess->waitForFinished();
+ m_processingProxy.removeAll(job->destination());
+ if (result == -1) result = jobProcess->exitStatus();
+
+ if (result != -2 && QFileInfo(job->destination()).size() == 0) {
+ result = QProcess::CrashExit;
+ }
+
+ if (result == QProcess::NormalExit) {
+ // proxy successfully created
+ for (int i = 0; i < processingItems.count(); i++)
+ setProxyStatus(processingItems.at(i), JOBDONE);
+ slotGotProxy(job->destination());
+ }
+ else if (result == QProcess::CrashExit) {
+ // Proxy process crashed
+ QFile::remove(job->destination());
+ for (int i = 0; i < processingItems.count(); i++)
+ setProxyStatus(processingItems.at(i), JOBCRASHED);
+ }
+ delete job;
+ continue;
+ }
+ // Thread finished, update count
+ int ct = -1; // -1 because we don't want to count this terminating thread
+ QList <QFuture<void> > futures = m_proxyThreads.futures();
+ for (int i = 0; i < futures.count(); i++)
+ if (futures.at(i).isRunning()) {
+ ct++;
+ }
+ emit jobCount(ct + m_jobList.count());
+}
+
+
+void ProjectList::processLogInfo(QList <ProjectItem *>items, int progress)
+{
+ for (int i = 0; i < items.count(); i++)
+ setProxyStatus(items.at(i), CREATINGJOB, progress);
+}
+