OSDN Git Service

Much improved VapourSynth detection + added option "--no-deadlock-detection" to disab...
[x264-launcher/x264-launcher.git] / src / thread_encode.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
9 //
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.
14 //
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.
18 //
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
21
22 #pragma once
23
24 #include "model_status.h"
25
26 #include <QThread>
27 #include <QUuid>
28 #include <QMutex>
29 #include <QStringList>
30 #include <QSemaphore>
31
32 class OptionsModel;
33 class QProcess;
34
35 class EncodeThread : public QThread
36 {
37         Q_OBJECT
38
39 public:
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);
41         ~EncodeThread(void);
42
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; }
47         
48         void pauseJob(void)
49         {
50                 m_pause = true;
51         }
52         void resumeJob(void)
53         {
54                 m_pause = false;
55                 m_semaphorePaused.release();
56         }
57         void abortJob(void)
58         {
59                 m_abort = true;
60                 m_pause = false;
61                 m_semaphorePaused.release();
62         }
63
64 protected:
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;
69
70         //Constants
71         const QUuid m_jobId;
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;
83
84         //Types
85         enum inputType_t
86         {
87                 INPUT_NATIVE = 0,
88                 INPUT_AVISYN = 1,
89                 INPUT_VAPOUR = 2
90         };
91
92         //Flags
93         volatile bool m_abort;
94         volatile bool m_pause;
95         
96         //Synchronization
97         QSemaphore m_semaphorePaused;
98
99         //Job handle
100         void *m_handle_jobObject;
101
102         //Internal status values
103         JobStatus m_status;
104         unsigned int m_progress;
105
106         //Entry point
107         virtual void run(void);
108         virtual void checkedRun(void);
109         
110         //Encode functions
111         void encode(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);
119
120         //Auxiallary Stuff
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 &params);
128         qint64 estimateSize(int progress);
129
130         //Static functions
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);
135
136 signals:
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);
141
142 public slots:
143         void start(Priority priority = InheritPriority);
144 };
145