OSDN Git Service

Updated copyright year.
[x264-launcher/x264-launcher.git] / src / thread_encode.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2022 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 "thread_abstract.h"
25 #include "model_status.h"
26
27 #include <QThread>
28 #include <QUuid>
29 #include <QMutex>
30 #include <QStringList>
31 #include <QSemaphore>
32
33 class SysinfoModel;
34 class PreferencesModel;
35 class OptionsModel;
36 class QProcess;
37 class JobObject;
38 class AbstractEncoder;
39 class AbstractSource;
40
41 class EncodeThread : public AbstractThread
42 {
43         Q_OBJECT
44
45 public:
46         EncodeThread(const QString &sourceFileName, const QString &outputFileName, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const m_preferences);
47         ~EncodeThread(void);
48
49         QUuid getId(void) { return this->m_jobId; };
50         const QString &sourceFileName(void) const { return this->m_sourceFileName; }
51         const QString &outputFileName(void) const { return this->m_outputFileName; }
52         const OptionsModel *options(void)   const { return m_options; }
53         
54         void pauseJob(void)
55         {
56                 m_pause = true;
57         }
58
59         void resumeJob(void)
60         {
61                 m_pause = false;
62                 m_semaphorePaused.release();
63         }
64
65         void abortJob(void)
66         {
67                 m_abort = true;
68                 m_pause = false;
69                 m_semaphorePaused.release();
70         }
71
72 protected:
73         //Globals
74         const SysinfoModel *const m_sysinfo;
75         const PreferencesModel *const m_preferences;
76
77         //Constants
78         const QUuid m_jobId;
79         const OptionsModel *m_options;
80         const QString m_sourceFileName;
81         const QString m_outputFileName;
82
83         //Flags
84         volatile bool m_abort;
85         volatile bool m_pause;
86         
87         //Synchronization
88         QSemaphore m_semaphorePaused;
89
90         //Job Object
91         JobObject *m_jobObject;
92
93         //Internal status values
94         JobStatus m_status;
95         unsigned int m_progress;
96         QString m_details;
97
98         //Encoder and Source objects
99         AbstractEncoder *m_encoder;
100         AbstractSource *m_pipedSource;
101
102         //Entry point
103         virtual void run(void);
104         
105         //Thread main
106         virtual int threadMain(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 };