Bump version + updated changelog.
[simple-x264-launcher.git] / src / thread_encode.h
blob1d9d9e89ea54b4a7158aaa0ca39f5d4027f1f25f
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2018 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.
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 ///////////////////////////////////////////////////////////////////////////////
22 #pragma once
24 #include "model_status.h"
26 #include <QThread>
27 #include <QUuid>
28 #include <QMutex>
29 #include <QStringList>
30 #include <QSemaphore>
32 class SysinfoModel;
33 class PreferencesModel;
34 class OptionsModel;
35 class QProcess;
36 class JobObject;
37 class AbstractEncoder;
38 class AbstractSource;
40 class EncodeThread : public QThread
42 Q_OBJECT
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);
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; }
53 void pauseJob(void)
55 m_pause = true;
58 void resumeJob(void)
60 m_pause = false;
61 m_semaphorePaused.release();
64 void abortJob(void)
66 m_abort = true;
67 m_pause = false;
68 m_semaphorePaused.release();
71 protected:
72 //Globals
73 const SysinfoModel *const m_sysinfo;
74 const PreferencesModel *const m_preferences;
76 //Constants
77 const QUuid m_jobId;
78 const OptionsModel *m_options;
79 const QString m_sourceFileName;
80 const QString m_outputFileName;
82 //Flags
83 volatile bool m_abort;
84 volatile bool m_pause;
86 //Synchronization
87 QSemaphore m_semaphorePaused;
89 //Job Object
90 JobObject *m_jobObject;
92 //Internal status values
93 JobStatus m_status;
94 unsigned int m_progress;
95 QString m_details;
97 //Encoder and Source objects
98 AbstractEncoder *m_encoder;
99 AbstractSource *m_pipedSource;
101 //Entry point
102 virtual void run(void);
103 virtual void checkedRun(void);
105 //Main encoding functions
106 void encode(void);
108 //Static functions
109 static QString getPasslogFile(const QString &outputFile);
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);
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);
123 public slots:
124 void start(Priority priority = InheritPriority);