source: smplayer/trunk/src/inforeader.cpp@ 167

Last change on this file since 167 was 165, checked in by Silvan Scherrer, 11 years ago

SMPlayer: update trunk to latest 0.8.7

  • Property svn:eol-style set to LF
File size: 8.0 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2014 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
35using 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
44InfoReader * InfoReader::static_obj = 0;
45
46InfoReader * 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
54InfoReader::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
70InfoReader::~InfoReader() {
71}
72
73void 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
85void 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
117static QRegExp rx_vo_key("^ID_VIDEO_OUTPUTS");
118static QRegExp rx_ao_key("^ID_AUDIO_OUTPUTS");
119static QRegExp rx_demuxer_key("^ID_DEMUXERS");
120static QRegExp rx_ac_key("^ID_AUDIO_CODECS");
121static QRegExp rx_vc_key("^ID_VIDEO_CODECS");
122
123static QRegExp rx_driver("\\t(.*)\\t(.*)");
124static QRegExp rx_demuxer("^\\s+([A-Z,a-z,0-9]+)\\s+(\\d+)\\s+(\\S.*)");
125static QRegExp rx_demuxer2("^\\s+([A-Z,a-z,0-9]+)\\s+(\\S.*)");
126static 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.*)");
127
128void InfoReader::readLine(QByteArray ba) {
129#if COLOR_OUTPUT_SUPPORT
130 QString line = ColorUtils::stripColorsTags(QString::fromLocal8Bit(ba));
131#else
132 QString line = QString::fromLocal8Bit(ba);
133#endif
134
135 if (line.isEmpty()) return;
136
137 qDebug("InfoReader::readLine: line: '%s'", line.toUtf8().data());
138 //qDebug("waiting_for_key: %d", waiting_for_key);
139
140 if (!waiting_for_key) {
141 if ((reading_type == VO) || (reading_type == AO)) {
142 if ( rx_driver.indexIn(line) > -1 ) {
143 QString name = rx_driver.cap(1);
144 QString desc = rx_driver.cap(2);
145 qDebug("InfoReader::readLine: found driver: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
146 if (reading_type==VO) {
147 vo_list.append( InfoData(name, desc) );
148 }
149 else
150 if (reading_type==AO) {
151 ao_list.append( InfoData(name, desc) );
152 }
153 } else {
154 qWarning("InfoReader::readLine: can't parse output driver from line '%s'", line.toUtf8().constData());
155 }
156 }
157 else
158 if (reading_type == DEMUXER) {
159 if ( rx_demuxer.indexIn(line) > -1 ) {
160 QString name = rx_demuxer.cap(1);
161 QString desc = rx_demuxer.cap(3);
162 qDebug("InfoReader::readLine: found demuxer: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
163 demuxer_list.append( InfoData(name, desc) );
164 }
165 else
166 if ( rx_demuxer2.indexIn(line) > -1 ) {
167 QString name = rx_demuxer2.cap(1);
168 QString desc = rx_demuxer2.cap(2);
169 qDebug("InfoReader::readLine: found demuxer: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
170 demuxer_list.append( InfoData(name, desc) );
171 }
172 else {
173 qWarning("InfoReader::readLine: can't parse demuxer from line '%s'", line.toUtf8().constData());
174 }
175 }
176 else
177 if ((reading_type == VC) || (reading_type == AC)) {
178 if ( rx_codec.indexIn(line) > -1 ) {
179 QString name = rx_codec.cap(1);
180 QString desc = rx_codec.cap(4);
181 qDebug("InfoReader::readLine: found codec: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
182 if (reading_type==VC) {
183 vc_list.append( InfoData(name, desc) );
184 }
185 else
186 if (reading_type==AC) {
187 ac_list.append( InfoData(name, desc) );
188 }
189 } else {
190 qWarning("InfoReader::readLine: can't parse codec from line '%s'", line.toUtf8().constData());
191 }
192 }
193 }
194
195 if ( rx_vo_key.indexIn(line) > -1 ) {
196 reading_type = VO;
197 waiting_for_key = false;
198 qDebug("InfoReader::readLine: found key: vo");
199 }
200
201 if ( rx_ao_key.indexIn(line) > -1 ) {
202 reading_type = AO;
203 waiting_for_key = false;
204 qDebug("InfoReader::readLine: found key: ao");
205 }
206
207 if ( rx_demuxer_key.indexIn(line) > -1 ) {
208 reading_type = DEMUXER;
209 waiting_for_key = false;
210 qDebug("InfoReader::readLine: found key: demuxer");
211 }
212
213 if ( rx_ac_key.indexIn(line) > -1 ) {
214 reading_type = AC;
215 waiting_for_key = false;
216 qDebug("InfoReader::readLine: found key: ac");
217 }
218
219 if ( rx_vc_key.indexIn(line) > -1 ) {
220 reading_type = VC;
221 waiting_for_key = false;
222 qDebug("InfoReader::readLines: found key: vc");
223 }
224
225 if (line.startsWith("MPlayer ")) {
226 mplayer_svn = MplayerVersion::mplayerVersion(line);
227 }
228}
229
230#if USE_QPROCESS
231bool InfoReader::run(QString options) {
232 qDebug("InfoReader::run: '%s'", options.toUtf8().data());
233 qDebug("InfoReader::run: using QProcess");
234
235 if (proc->state() == QProcess::Running) {
236 qWarning("InfoReader::run: process already running");
237 return false;
238 }
239
240 QStringList args = options.split(" ");
241
242 proc->start(mplayerbin, args);
243 if (!proc->waitForStarted()) {
244 qWarning("InfoReader::run: process can't start!");
245 return false;
246 }
247
248 //Wait until finish
249 if (!proc->waitForFinished()) {
250 qWarning("InfoReader::run: process didn't finish. Killing it...");
251 proc->kill();
252 }
253
254 qDebug("InfoReader::run : terminating");
255
256 QByteArray ba;
257 while (proc->canReadLine()) {
258 ba = proc->readLine();
259 ba.replace("\n", "");
260 ba.replace("\r", "");
261 readLine( ba );
262 }
263
264 return true;
265}
266#else
267bool InfoReader::run(QString options) {
268 qDebug("InfoReader::run: '%s'", options.toUtf8().data());
269 qDebug("InfoReader::run: using myprocess");
270
271 if (proc->isRunning()) {
272 qWarning("InfoReader::run: process already running");
273 return false;
274 }
275
276 proc->clearArguments();
277
278 proc->addArgument(mplayerbin);
279
280 QStringList args = options.split(" ");
281 QStringList::Iterator it = args.begin();
282 while( it != args.end() ) {
283 proc->addArgument( (*it) );
284 ++it;
285 }
286
287 proc->start();
288 if (!proc->waitForStarted()) {
289 qWarning("InfoReader::run: process can't start!");
290 return false;
291 }
292
293 //Wait until finish
294 if (!proc->waitForFinished()) {
295 qWarning("InfoReader::run: process didn't finish. Killing it...");
296 proc->kill();
297 }
298
299 qDebug("InfoReader::run : terminating");
300
301 return true;
302}
303#endif
304
305#include "moc_inforeader.cpp"
Note: See TracBrowser for help on using the repository browser.