1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2012 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
3 |
|
---|
4 | This program is free software; you can redistribute it and/or modify
|
---|
5 | it under the terms of the GNU General Public License as published by
|
---|
6 | the Free Software Foundation; either version 2 of the License, or
|
---|
7 | (at your option) any later version.
|
---|
8 |
|
---|
9 | This program is distributed in the hope that it will be useful,
|
---|
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | GNU General Public License for more details.
|
---|
13 |
|
---|
14 | You should have received a copy of the GNU General Public License
|
---|
15 | along with this program; if not, write to the Free Software
|
---|
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include "inforeader.h"
|
---|
20 | #include <QStringList>
|
---|
21 | #include <QApplication>
|
---|
22 | #include <QRegExp>
|
---|
23 |
|
---|
24 | #include "colorutils.h"
|
---|
25 | #include "global.h"
|
---|
26 | #include "preferences.h"
|
---|
27 | #include "mplayerversion.h"
|
---|
28 |
|
---|
29 | #if USE_QPROCESS
|
---|
30 | #include <QProcess>
|
---|
31 | #else
|
---|
32 | #include "myprocess.h"
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | using namespace Global;
|
---|
36 |
|
---|
37 | #define NOME 0
|
---|
38 | #define VO 1
|
---|
39 | #define AO 2
|
---|
40 | #define DEMUXER 3
|
---|
41 | #define VC 4
|
---|
42 | #define AC 5
|
---|
43 |
|
---|
44 | InfoReader * InfoReader::static_obj = 0;
|
---|
45 |
|
---|
46 | InfoReader * InfoReader::obj() {
|
---|
47 | if (!static_obj) {
|
---|
48 | static_obj = new InfoReader( pref->mplayer_bin );
|
---|
49 | static_obj->getInfo();
|
---|
50 | }
|
---|
51 | return static_obj;
|
---|
52 | }
|
---|
53 |
|
---|
54 | InfoReader::InfoReader( QString mplayer_bin, QObject * parent )
|
---|
55 | : QObject(parent)
|
---|
56 | {
|
---|
57 | mplayerbin = mplayer_bin;
|
---|
58 |
|
---|
59 | #if USE_QPROCESS
|
---|
60 | proc = new QProcess(this);
|
---|
61 | proc->setProcessChannelMode( QProcess::MergedChannels );
|
---|
62 | #else
|
---|
63 | proc = new MyProcess(this);
|
---|
64 |
|
---|
65 | connect( proc, SIGNAL(lineAvailable(QByteArray)),
|
---|
66 | this, SLOT(readLine(QByteArray)) );
|
---|
67 | #endif
|
---|
68 | }
|
---|
69 |
|
---|
70 | InfoReader::~InfoReader() {
|
---|
71 | }
|
---|
72 |
|
---|
73 | void InfoReader::getInfo() {
|
---|
74 | waiting_for_key = TRUE;
|
---|
75 | vo_list.clear();
|
---|
76 | ao_list.clear();
|
---|
77 | demuxer_list.clear();
|
---|
78 | mplayer_svn = -1;
|
---|
79 |
|
---|
80 | run("-identify -vo help -ao help -demuxer help -vc help -ac help");
|
---|
81 |
|
---|
82 | //list();
|
---|
83 | }
|
---|
84 |
|
---|
85 | void InfoReader::list() {
|
---|
86 | qDebug("InfoReader::list");
|
---|
87 |
|
---|
88 | InfoList::iterator it;
|
---|
89 |
|
---|
90 | qDebug(" vo_list:");
|
---|
91 | for ( it = vo_list.begin(); it != vo_list.end(); ++it ) {
|
---|
92 | qDebug( "driver: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
93 | }
|
---|
94 |
|
---|
95 | qDebug(" ao_list:");
|
---|
96 | for ( it = ao_list.begin(); it != ao_list.end(); ++it ) {
|
---|
97 | qDebug( "driver: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
98 | }
|
---|
99 |
|
---|
100 | qDebug(" demuxer_list:");
|
---|
101 | for ( it = demuxer_list.begin(); it != demuxer_list.end(); ++it ) {
|
---|
102 | qDebug( "demuxer: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
103 | }
|
---|
104 |
|
---|
105 | qDebug(" vc_list:");
|
---|
106 | for ( it = vc_list.begin(); it != vc_list.end(); ++it ) {
|
---|
107 | qDebug( "codec: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
108 | }
|
---|
109 |
|
---|
110 | qDebug(" ac_list:");
|
---|
111 | for ( it = ac_list.begin(); it != ac_list.end(); ++it ) {
|
---|
112 | qDebug( "codec: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
113 | }
|
---|
114 |
|
---|
115 | }
|
---|
116 |
|
---|
117 | static QRegExp rx_vo_key("^ID_VIDEO_OUTPUTS");
|
---|
118 | static QRegExp rx_ao_key("^ID_AUDIO_OUTPUTS");
|
---|
119 | static QRegExp rx_demuxer_key("^ID_DEMUXERS");
|
---|
120 | static QRegExp rx_ac_key("^ID_AUDIO_CODECS");
|
---|
121 | static QRegExp rx_vc_key("^ID_VIDEO_CODECS");
|
---|
122 |
|
---|
123 | static QRegExp rx_driver("\\t(.*)\\t(.*)");
|
---|
124 | static QRegExp rx_demuxer("^\\s+([A-Z,a-z,0-9]+)\\s+(\\d+)\\s+(\\S.*)");
|
---|
125 | static QRegExp rx_codec("^([A-Z,a-z,0-9]+)\\s+([A-Z,a-z,0-9]+)\\s+([A-Z,a-z,0-9]+)\\s+(\\S.*)");
|
---|
126 |
|
---|
127 | void InfoReader::readLine(QByteArray ba) {
|
---|
128 | #if COLOR_OUTPUT_SUPPORT
|
---|
129 | QString line = ColorUtils::stripColorsTags(QString::fromLocal8Bit(ba));
|
---|
130 | #else
|
---|
131 | QString line = QString::fromLocal8Bit(ba);
|
---|
132 | #endif
|
---|
133 |
|
---|
134 | qDebug("InfoReader::readLine: line: '%s'", line.toUtf8().data());
|
---|
135 | //qDebug("waiting_for_key: %d", waiting_for_key);
|
---|
136 |
|
---|
137 | if (!waiting_for_key) {
|
---|
138 | if ( rx_driver.indexIn(line) > -1 ) {
|
---|
139 | QString name = rx_driver.cap(1);
|
---|
140 | QString desc = rx_driver.cap(2);
|
---|
141 | qDebug("InfoReader::readLine: found driver: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
|
---|
142 | if (reading_type==VO) {
|
---|
143 | vo_list.append( InfoData(name, desc) );
|
---|
144 | }
|
---|
145 | else
|
---|
146 | if (reading_type==AO) {
|
---|
147 | ao_list.append( InfoData(name, desc) );
|
---|
148 | }
|
---|
149 | else
|
---|
150 | qWarning("InfoReader::readLine: Unknown type! Ignoring");
|
---|
151 | }
|
---|
152 | else
|
---|
153 | if ( rx_demuxer.indexIn(line) > -1 ) {
|
---|
154 | QString name = rx_demuxer.cap(1);
|
---|
155 | QString desc = rx_demuxer.cap(3);
|
---|
156 | qDebug("InfoReader::readLine: found demuxer: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
|
---|
157 | demuxer_list.append( InfoData(name, desc) );
|
---|
158 | }
|
---|
159 | else
|
---|
160 | if ( rx_codec.indexIn(line) > -1 ) {
|
---|
161 | QString name = rx_codec.cap(1);
|
---|
162 | QString desc = rx_codec.cap(4);
|
---|
163 | qDebug("InfoReader::readLine: found codec: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
|
---|
164 | if (reading_type==VC) {
|
---|
165 | vc_list.append( InfoData(name, desc) );
|
---|
166 | }
|
---|
167 | else
|
---|
168 | if (reading_type==AC) {
|
---|
169 | ac_list.append( InfoData(name, desc) );
|
---|
170 | }
|
---|
171 | else
|
---|
172 | qWarning("InfoReader::readLine: Unknown type! Ignoring");
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 | if ( rx_vo_key.indexIn(line) > -1 ) {
|
---|
177 | reading_type = VO;
|
---|
178 | waiting_for_key = FALSE;
|
---|
179 | qDebug("InfoReader::readLine: found key: vo");
|
---|
180 | }
|
---|
181 |
|
---|
182 | if ( rx_ao_key.indexIn(line) > -1 ) {
|
---|
183 | reading_type = AO;
|
---|
184 | waiting_for_key = FALSE;
|
---|
185 | qDebug("InfoReader::readLine: found key: ao");
|
---|
186 | }
|
---|
187 |
|
---|
188 | if ( rx_demuxer_key.indexIn(line) > -1 ) {
|
---|
189 | reading_type = DEMUXER;
|
---|
190 | waiting_for_key = FALSE;
|
---|
191 | qDebug("InfoReader::readLine: found key: demuxer");
|
---|
192 | }
|
---|
193 |
|
---|
194 | if ( rx_ac_key.indexIn(line) > -1 ) {
|
---|
195 | reading_type = AC;
|
---|
196 | waiting_for_key = FALSE;
|
---|
197 | qDebug("InfoReader::readLine: found key: ac");
|
---|
198 | }
|
---|
199 |
|
---|
200 | if ( rx_vc_key.indexIn(line) > -1 ) {
|
---|
201 | reading_type = VC;
|
---|
202 | waiting_for_key = FALSE;
|
---|
203 | qDebug("InfoReader::readLines: found key: vc");
|
---|
204 | }
|
---|
205 |
|
---|
206 | if (line.startsWith("MPlayer ")) {
|
---|
207 | mplayer_svn = MplayerVersion::mplayerVersion(line);
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | #if USE_QPROCESS
|
---|
212 | bool InfoReader::run(QString options) {
|
---|
213 | qDebug("InfoReader::run: '%s'", options.toUtf8().data());
|
---|
214 | qDebug("InfoReader::run: using QProcess");
|
---|
215 |
|
---|
216 | if (proc->state() == QProcess::Running) {
|
---|
217 | qWarning("InfoReader::run: process already running");
|
---|
218 | return false;
|
---|
219 | }
|
---|
220 |
|
---|
221 | QStringList args = options.split(" ");
|
---|
222 |
|
---|
223 | proc->start(mplayerbin, args);
|
---|
224 | if (!proc->waitForStarted()) {
|
---|
225 | qWarning("InfoReader::run: process can't start!");
|
---|
226 | return false;
|
---|
227 | }
|
---|
228 |
|
---|
229 | //Wait until finish
|
---|
230 | if (!proc->waitForFinished()) {
|
---|
231 | qWarning("InfoReader::run: process didn't finish. Killing it...");
|
---|
232 | proc->kill();
|
---|
233 | }
|
---|
234 |
|
---|
235 | qDebug("InfoReader::run : terminating");
|
---|
236 |
|
---|
237 | QByteArray ba;
|
---|
238 | while (proc->canReadLine()) {
|
---|
239 | ba = proc->readLine();
|
---|
240 | ba.replace("\n", "");
|
---|
241 | ba.replace("\r", "");
|
---|
242 | readLine( ba );
|
---|
243 | }
|
---|
244 |
|
---|
245 | return true;
|
---|
246 | }
|
---|
247 | #else
|
---|
248 | bool InfoReader::run(QString options) {
|
---|
249 | qDebug("InfoReader::run: '%s'", options.toUtf8().data());
|
---|
250 | qDebug("InfoReader::run: using myprocess");
|
---|
251 |
|
---|
252 | if (proc->isRunning()) {
|
---|
253 | qWarning("InfoReader::run: process already running");
|
---|
254 | return false;
|
---|
255 | }
|
---|
256 |
|
---|
257 | proc->clearArguments();
|
---|
258 |
|
---|
259 | proc->addArgument(mplayerbin);
|
---|
260 |
|
---|
261 | QStringList args = options.split(" ");
|
---|
262 | QStringList::Iterator it = args.begin();
|
---|
263 | while( it != args.end() ) {
|
---|
264 | proc->addArgument( (*it) );
|
---|
265 | ++it;
|
---|
266 | }
|
---|
267 |
|
---|
268 | proc->start();
|
---|
269 | if (!proc->waitForStarted()) {
|
---|
270 | qWarning("InfoReader::run: process can't start!");
|
---|
271 | return false;
|
---|
272 | }
|
---|
273 |
|
---|
274 | //Wait until finish
|
---|
275 | if (!proc->waitForFinished()) {
|
---|
276 | qWarning("InfoReader::run: process didn't finish. Killing it...");
|
---|
277 | proc->kill();
|
---|
278 | }
|
---|
279 |
|
---|
280 | qDebug("InfoReader::run : terminating");
|
---|
281 |
|
---|
282 | return true;
|
---|
283 | }
|
---|
284 | #endif
|
---|
285 |
|
---|
286 | #include "moc_inforeader.cpp"
|
---|