OSDN Git Service

Adapted "update" dialog for recent MUtils changes + allow user to cancel the update...
[x264-launcher/x264-launcher.git] / src / thread_encode.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2017 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 SysinfoModel;
33 class PreferencesModel;
34 class OptionsModel;
35 class QProcess;
36 class JobObject;
37 class AbstractEncoder;
38 class AbstractSource;
39
40 class EncodeThread : public QThread
41 {
42         Q_OBJECT
43
44 public:
45         EncodeThread(const QString &sourceFileName, const QString &outputFileName, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const m_preferences);
46         ~EncodeThread(void);
47
48         QUuid getId(void) { return this->m_jobId; };
49         const QString &sourceFileName(void) const { return this->m_sourceFileName; }
50         const QString &outputFileName(void) const { return this->m_outputFileName; }
51         const OptionsModel *options(void)   const { return m_options; }
52         
53         void pauseJob(void)
54         {
55                 m_pause = true;
56         }
57
58         void resumeJob(void)
59         {
60                 m_pause = false;
61                 m_semaphorePaused.release();
62         }
63
64         void abortJob(void)
65         {
66                 m_abort = true;
67                 m_pause = false;
68                 m_semaphorePaused.release();
69         }
70
71 protected:
72         //Globals
73         const SysinfoModel *const m_sysinfo;
74         const PreferencesModel *const m_preferences;
75
76         //Constants
77         const QUuid m_jobId;
78         const OptionsModel *m_options;
79         const QString m_sourceFileName;
80         const QString m_outputFileName;
81
82         //Flags
83         volatile bool m_abort;
84         volatile bool m_pause;
85         
86         //Synchronization
87         QSemaphore m_semaphorePaused;
88
89         //Job Object
90         JobObject *m_jobObject;
91
92         //Internal status values
93         JobStatus m_status;
94         unsigned int m_progress;
95         QString m_details;
96
97         //Encoder and Source objects
98         AbstractEncoder *m_encoder;
99         AbstractSource *m_pipedSource;
100
101         //Entry point
102         virtual void run(void);
103         virtual void checkedRun(void);
104         
105         //Main encoding functions
106         void encode(void);
107
108         //Static functions
109         static QString getPasslogFile(const QString &outputFile);
110
111 signals:
112         void statusChanged(const QUuid &jobId, const JobStatus &newStatus);
113         void progressChanged(const QUuid &jobId, const unsigned int &newProgress);
114         void messageLogged(const QUuid &jobId, qint64, const QString &text);
115         void detailsChanged(const QUuid &jobId, const QString &details);
116
117 private slots:
118         void log(const QString &text);
119         void setStatus(const JobStatus &newStatus);
120         void setProgress(const unsigned int &newProgress);
121         void setDetails(const QString &text);
122
123 public slots:
124         void start(Priority priority = InheritPriority);
125 };