OSDN Git Service

Added options Model.
[x264-launcher/x264-launcher.git] / src / thread_encode.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 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 #include "thread_encode.h"
23
24 #include "global.h"
25 #include "model_options.h"
26
27 #include <QDate>
28 #include <QTime>
29
30 EncodeThread::EncodeThread(const QString &sourceFileName, const QString &outputFileName, const OptionsModel *options)
31 :
32         m_jobId(QUuid::createUuid()),
33         m_sourceFileName(sourceFileName),
34         m_outputFileName(outputFileName),
35         m_options(new OptionsModel(*options))
36 {
37         m_abort = false;
38 }
39
40 EncodeThread::~EncodeThread(void)
41 {
42         X264_DELETE(m_options);
43 }
44
45 ///////////////////////////////////////////////////////////////////////////////
46 // Thread entry point
47 ///////////////////////////////////////////////////////////////////////////////
48
49 void EncodeThread::run(void)
50 {
51         try
52         {
53                 encode();
54         }
55         catch(char *msg)
56         {
57                 emit messageLogged(m_jobId, QString("EXCEPTION ERROR: ").append(QString::fromLatin1(msg)));
58         }
59         catch(...)
60         {
61                 emit messageLogged(m_jobId, QString("EXCEPTION ERROR !!!"));
62         }
63 }
64
65 void EncodeThread::encode(void)
66 {
67         Sleep(1500);
68
69         //Print some basic info
70         log(tr("Job started at %1, %2.\n").arg(QDate::currentDate().toString(Qt::ISODate), QTime::currentTime().toString( Qt::ISODate)));
71         log(tr("Source file: %1").arg(m_sourceFileName));
72         log(tr("Output file: %1").arg(m_outputFileName));
73         log(tr("\n[Encoder Options]"));
74         log(tr("RC Mode: %1").arg(OptionsModel::rcMode2String(m_options->rcMode())));
75         log(tr("Preset: %1").arg(m_options->preset()));
76         log(tr("Tuning: %1").arg(m_options->tune()));
77         log(tr("Profile: %1").arg(m_options->profile()));
78         log(tr("Custom: %1").arg(m_options->custom().isEmpty() ? tr("(None)") : m_options->custom()));
79         log(tr("\n[Input Properties]"));
80
81         for(int i = 0; i <= 100; i += 5)
82         {
83                 emit progressChanged(m_jobId, i);
84                 emit statusChanged(m_jobId, (i % 2) ? JobStatus_Indexing : JobStatus_Running_Pass1);
85                 emit messageLogged(m_jobId, QUuid::createUuid().toString());
86         
87                 for(int j = 0; j < 3; j++)
88                 {
89                         emit detailsChanged(m_jobId, QUuid::createUuid().toString());
90                         Sleep(120);
91                 }
92
93                 if(m_abort)
94                 {
95                         Sleep(500);
96                         emit statusChanged(m_jobId, JobStatus_Aborted);
97                         return;
98                 }
99         }
100
101         Sleep(1500);
102
103         for(int i = 0; i <= 100; i += 5)
104         {
105                 emit progressChanged(m_jobId, i);
106                 emit statusChanged(m_jobId, (i % 2) ? JobStatus_Indexing : JobStatus_Running_Pass2);
107                 emit messageLogged(m_jobId, QUuid::createUuid().toString());
108         
109                 for(int j = 0; j < 3; j++)
110                 {
111                         emit detailsChanged(m_jobId, QUuid::createUuid().toString());
112                         Sleep(120);
113                 }
114
115                 if(m_abort)
116                 {
117                         Sleep(500);
118                         emit statusChanged(m_jobId, JobStatus_Aborted);
119                         return;
120                 }
121         }
122
123         Sleep(250);
124
125         emit statusChanged(m_jobId, JobStatus_Completed);
126 }