1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
24 #include "model_status.h"
29 #include <QStringList>
35 class EncodeThread : public QThread
40 EncodeThread(const QString &sourceFileName, const QString &outputFileName, const OptionsModel *options, const QString &binDir, const QString &vpsDir, const bool &x264_x64, const bool &x264_10bit, const bool &avs2yuv_x64, const bool &skipVersionTest, const int &processPriroity, const bool &abortOnTimeout);
43 QUuid getId(void) { return this->m_jobId; };
44 const QString &sourceFileName(void) { return this->m_sourceFileName; }
45 const QString &outputFileName(void) { return this->m_outputFileName; }
46 const OptionsModel *options(void) { return m_options; }
55 m_semaphorePaused.release();
61 m_semaphorePaused.release();
65 static QMutex m_mutex_startProcess;
66 static const unsigned int m_processTimeoutInterval = 2500;
67 static const unsigned int m_processTimeoutMaxCounter = 120;
68 static const unsigned int m_processTimeoutWarning = 24;
72 const QString m_sourceFileName;
73 const QString m_outputFileName;
74 const OptionsModel *m_options;
75 const QString m_binDir;
76 const QString m_vpsDir;
77 const bool m_x264_x64;
78 const bool m_x264_10bit;
79 const bool m_avs2yuv_x64;
80 const bool m_skipVersionTest;
81 const int m_processPriority;
82 const bool m_abortOnTimeout;
93 volatile bool m_abort;
94 volatile bool m_pause;
97 QSemaphore m_semaphorePaused;
100 void *m_handle_jobObject;
102 //Internal status values
104 unsigned int m_progress;
107 virtual void run(void);
108 virtual void checkedRun(void);
112 bool runEncodingPass(bool x264_x64, bool x264_10bit, bool avs2yuv_x64, int inputType, unsigned int frames, const QString &indexFile, int pass = 0, const QString &passLogFile = QString());
113 QStringList buildCommandLine(bool usePipe, bool use10Bit, unsigned int frames, const QString &indexFile, int pass = 0, const QString &passLogFile = QString());
114 unsigned int checkVersionX264(bool use_x64, bool use_10bit, bool &modified);
115 unsigned int checkVersionAvs2yuv(bool x64);
116 bool checkVersionVapoursynth(void);
117 bool checkPropertiesAvisynth(bool x64, unsigned int &frames);
118 bool checkPropertiesVapoursynth(unsigned int &frames);
121 void log(const QString &text) { emit messageLogged(m_jobId, text); }
122 inline void setStatus(JobStatus newStatus);
123 inline void setProgress(unsigned int newProgress);
124 inline void setDetails(const QString &text);
125 bool startProcess(QProcess &process, const QString &program, const QStringList &args, bool mergeChannels = true);
126 QString pathToLocal(const QString &longPath, bool create = false, bool keep = true);
127 QStringList splitParams(const QString ¶ms);
128 qint64 estimateSize(int progress);
131 static QString commandline2string(const QString &program, const QStringList &arguments);
132 static QString sizeToString(qint64 size);
133 static void setPorcessPriority(void *processId, int priroity);
134 static int getInputType(const QString &fileExt);
137 void statusChanged(const QUuid &jobId, JobStatus newStatus);
138 void progressChanged(const QUuid &jobId, unsigned int newProgress);
139 void messageLogged(const QUuid &jobId, const QString &text);
140 void detailsChanged(const QUuid &jobId, const QString &details);
143 void start(Priority priority = InheritPriority);