OSDN Git Service

Refactored encoder version detection into encoder-specific classes.
[x264-launcher/x264-launcher.git] / src / encoder_x264.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2014 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 "encoder_x264.h"
23
24 #include "model_options.h"
25
26 #include <QStringList>
27 #include <QRegExp>
28
29 //x264 version info
30 static const unsigned int X264_VERSION_X264_MINIMUM_REV = 2380;
31 static const unsigned int X264_VERSION_X264_CURRENT_API = 142;
32
33 X264Encoder::X264Encoder(const QUuid *jobId, JobObject *jobObject, const OptionsModel *options, const SysinfoModel *const sysinfo, const PreferencesModel *const preferences, volatile bool *abort)
34 :
35         AbstractEncoder(jobId, jobObject, options, sysinfo, preferences, abort)
36 {
37         if(options->encType() != OptionsModel::EncType_X264)
38         {
39                 throw "Invalid encoder type!";
40         }
41
42 }
43
44 X264Encoder::~X264Encoder(void)
45 {
46         /*Nothing to do here*/
47 }
48
49 void X264Encoder::checkVersion_init(QList<QRegExp*> &patterns, QStringList &cmdLine)
50 {
51         cmdLine << "--version";
52         patterns << new QRegExp("\\bx264\\s(\\d)\\.(\\d+)\\.(\\d+)\\s([a-f0-9]{7})", Qt::CaseInsensitive);
53         patterns << new QRegExp("\\bx264 (\\d)\\.(\\d+)\\.(\\d+)", Qt::CaseInsensitive);
54 }
55
56 void X264Encoder::checkVersion_parseLine(const QString &line, QList<QRegExp*> &patterns, unsigned int &coreVers, unsigned int &revision, bool &modified)
57 {
58         int offset = -1;
59         if((offset = patterns[0]->lastIndexIn(line)) >= 0)
60         {
61                 bool ok1 = false, ok2 = false;
62                 unsigned int temp1 = patterns[0]->cap(2).toUInt(&ok1);
63                 unsigned int temp2 = patterns[0]->cap(3).toUInt(&ok2);
64                 if(ok1) coreVers = temp1;
65                 if(ok2) revision = temp2;
66         }
67         else if((offset = patterns[1]->lastIndexIn(line)) >= 0)
68         {
69                 bool ok1 = false, ok2 = false;
70                 unsigned int temp1 = patterns[1]->cap(2).toUInt(&ok1);
71                 unsigned int temp2 = patterns[1]->cap(3).toUInt(&ok2);
72                 if(ok1) coreVers = temp1;
73                 if(ok2) revision = temp2;
74                 modified = true;
75         }
76 }
77
78 void X264Encoder::printVersion(const unsigned int &revision, const bool &modified)
79 {
80         log(tr("\nx264 revision: %1 (core #%2)").arg(QString::number(revision % REV_MULT), QString::number(revision / REV_MULT)).append(modified ? tr(" - with custom patches!") : QString()));
81 }
82
83 bool X264Encoder::isVersionSupported(const unsigned int &revision, const bool &modified)
84 {
85         if((revision % REV_MULT) < X264_VERSION_X264_MINIMUM_REV)
86         {
87                 log(tr("\nERROR: Your revision of x264 is too old! (Minimum required revision is %1)").arg(QString::number(X264_VERSION_X264_MINIMUM_REV)));
88                 return false;
89         }
90         
91         if((revision / REV_MULT) != X264_VERSION_X264_CURRENT_API)
92         {
93                 log(tr("\nWARNING: Your revision of x264 uses an unsupported core (API) version, take care!"));
94                 log(tr("This application works best with x264 core (API) version %2.").arg(QString::number(X264_VERSION_X264_CURRENT_API)));
95         }
96
97         return true;
98 }