source: smplayer/trunk/src/inforeadermplayer.cpp@ 184

Last change on this file since 184 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

File size: 7.5 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 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 "inforeadermplayer.h"
20#include <QStringList>
21#include <QApplication>
22#include <QRegExp>
23#include <QProcess>
24
25#include "colorutils.h"
26#include "global.h"
27#include "preferences.h"
28#include "mplayerversion.h"
29
30using namespace Global;
31
32#define NOME 0
33#define VO 1
34#define AO 2
35#define DEMUXER 3
36#define VC 4
37#define AC 5
38
39
40InfoReaderMplayer::InfoReaderMplayer( QString mplayer_bin, QObject * parent )
41 : QObject(parent)
42 , proc(0)
43 , mplayer_svn(0)
44 , is_mplayer2(false)
45{
46 mplayerbin = mplayer_bin;
47
48 proc = new QProcess(this);
49 proc->setProcessChannelMode( QProcess::MergedChannels );
50}
51
52InfoReaderMplayer::~InfoReaderMplayer() {
53}
54
55void InfoReaderMplayer::getInfo() {
56 waiting_for_key = true;
57 vo_list.clear();
58 ao_list.clear();
59#if ALLOW_DEMUXER_CODEC_CHANGE
60 demuxer_list.clear();
61#endif
62 mplayer_svn = -1;
63
64#if ALLOW_DEMUXER_CODEC_CHANGE
65 run("-identify -vo help -ao help -demuxer help -vc help -ac help");
66#else
67 run("-identify -vo help -ao help");
68#endif
69
70 //list();
71}
72
73void InfoReaderMplayer::list() {
74 qDebug("InfoReaderMplayer::list");
75
76 InfoList::iterator it;
77
78 qDebug(" vo_list:");
79 for ( it = vo_list.begin(); it != vo_list.end(); ++it ) {
80 qDebug( "driver: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
81 }
82
83 qDebug(" ao_list:");
84 for ( it = ao_list.begin(); it != ao_list.end(); ++it ) {
85 qDebug( "driver: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
86 }
87
88#if ALLOW_DEMUXER_CODEC_CHANGE
89 qDebug(" demuxer_list:");
90 for ( it = demuxer_list.begin(); it != demuxer_list.end(); ++it ) {
91 qDebug( "demuxer: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
92 }
93
94 qDebug(" vc_list:");
95 for ( it = vc_list.begin(); it != vc_list.end(); ++it ) {
96 qDebug( "codec: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
97 }
98
99 qDebug(" ac_list:");
100 for ( it = ac_list.begin(); it != ac_list.end(); ++it ) {
101 qDebug( "codec: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
102 }
103#endif
104
105}
106
107static QRegExp rx_vo_key("^ID_VIDEO_OUTPUTS");
108static QRegExp rx_ao_key("^ID_AUDIO_OUTPUTS");
109
110#if ALLOW_DEMUXER_CODEC_CHANGE
111static QRegExp rx_demuxer_key("^ID_DEMUXERS");
112static QRegExp rx_ac_key("^ID_AUDIO_CODECS");
113static QRegExp rx_vc_key("^ID_VIDEO_CODECS");
114#endif
115
116static QRegExp rx_driver("\\t(.*)\\t(.*)");
117static QRegExp rx_demuxer("^\\s+([A-Z,a-z,0-9]+)\\s+(\\d+)\\s+(\\S.*)");
118static QRegExp rx_demuxer2("^\\s+([A-Z,a-z,0-9]+)\\s+(\\S.*)");
119static 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.*)");
120
121void InfoReaderMplayer::readLine(QByteArray ba) {
122#if COLOR_OUTPUT_SUPPORT
123 QString line = ColorUtils::stripColorsTags(QString::fromLocal8Bit(ba));
124#else
125 QString line = QString::fromLocal8Bit(ba);
126#endif
127
128 if (line.isEmpty()) return;
129
130 //qDebug("InfoReaderMplayer::readLine: line: '%s'", line.toUtf8().data());
131 //qDebug("waiting_for_key: %d", waiting_for_key);
132
133 if (!waiting_for_key) {
134 if ((reading_type == VO) || (reading_type == AO)) {
135 if ( rx_driver.indexIn(line) > -1 ) {
136 QString name = rx_driver.cap(1);
137 QString desc = rx_driver.cap(2);
138 qDebug("InfoReaderMplayer::readLine: found driver: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
139 if (reading_type==VO) {
140 vo_list.append( InfoData(name, desc) );
141 }
142 else
143 if (reading_type==AO) {
144 ao_list.append( InfoData(name, desc) );
145 }
146 } else {
147 qWarning("InfoReaderMplayer::readLine: can't parse output driver from line '%s'", line.toUtf8().constData());
148 }
149 }
150#if ALLOW_DEMUXER_CODEC_CHANGE
151 else
152 if (reading_type == DEMUXER) {
153 if ( rx_demuxer.indexIn(line) > -1 ) {
154 QString name = rx_demuxer.cap(1);
155 QString desc = rx_demuxer.cap(3);
156 qDebug("InfoReaderMplayer::readLine: found demuxer: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
157 demuxer_list.append( InfoData(name, desc) );
158 }
159 else
160 if ( rx_demuxer2.indexIn(line) > -1 ) {
161 QString name = rx_demuxer2.cap(1);
162 QString desc = rx_demuxer2.cap(2);
163 qDebug("InfoReaderMplayer::readLine: found demuxer: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
164 demuxer_list.append( InfoData(name, desc) );
165 }
166 else {
167 qWarning("InfoReaderMplayer::readLine: can't parse demuxer from line '%s'", line.toUtf8().constData());
168 }
169 }
170 else
171 if ((reading_type == VC) || (reading_type == AC)) {
172 if ( rx_codec.indexIn(line) > -1 ) {
173 QString name = rx_codec.cap(1);
174 QString desc = rx_codec.cap(4);
175 qDebug("InfoReaderMplayer::readLine: found codec: '%s' '%s'", name.toUtf8().data(), desc.toUtf8().data());
176 if (reading_type==VC) {
177 vc_list.append( InfoData(name, desc) );
178 }
179 else
180 if (reading_type==AC) {
181 ac_list.append( InfoData(name, desc) );
182 }
183 } else {
184 qWarning("InfoReaderMplayer::readLine: can't parse codec from line '%s'", line.toUtf8().constData());
185 }
186 }
187#endif
188 }
189
190 if ( rx_vo_key.indexIn(line) > -1 ) {
191 reading_type = VO;
192 waiting_for_key = false;
193 qDebug("InfoReaderMplayer::readLine: found key: vo");
194 }
195
196 if ( rx_ao_key.indexIn(line) > -1 ) {
197 reading_type = AO;
198 waiting_for_key = false;
199 qDebug("InfoReaderMplayer::readLine: found key: ao");
200 }
201
202#if ALLOW_DEMUXER_CODEC_CHANGE
203 if ( rx_demuxer_key.indexIn(line) > -1 ) {
204 reading_type = DEMUXER;
205 waiting_for_key = false;
206 qDebug("InfoReaderMplayer::readLine: found key: demuxer");
207 }
208
209 if ( rx_ac_key.indexIn(line) > -1 ) {
210 reading_type = AC;
211 waiting_for_key = false;
212 qDebug("InfoReaderMplayer::readLine: found key: ac");
213 }
214
215 if ( rx_vc_key.indexIn(line) > -1 ) {
216 reading_type = VC;
217 waiting_for_key = false;
218 qDebug("InfoReaderMplayer::readLines: found key: vc");
219 }
220#endif
221
222 if (line.startsWith("MPlayer ") || line.startsWith("MPlayer2 ")) {
223 mplayer_svn = MplayerVersion::mplayerVersion(line);
224 #ifdef MPLAYER2_SUPPORT
225 mplayer2_version = MplayerVersion::mplayer2Version();
226 is_mplayer2 = MplayerVersion::isMplayer2();
227 #endif
228 }
229}
230
231bool InfoReaderMplayer::run(QString options) {
232 qDebug("InfoReaderMplayer::run: '%s'", options.toUtf8().data());
233
234 if (proc->state() == QProcess::Running) {
235 qWarning("InfoReaderMplayer::run: process already running");
236 return false;
237 }
238
239 QStringList args = options.split(" ");
240
241 proc->start(mplayerbin, args);
242 if (!proc->waitForStarted()) {
243 qWarning("InfoReaderMplayer::run: process can't start!");
244 return false;
245 }
246
247 //Wait until finish
248 if (!proc->waitForFinished()) {
249 qWarning("InfoReaderMplayer::run: process didn't finish. Killing it...");
250 proc->kill();
251 }
252
253 qDebug("InfoReaderMplayer::run : terminating");
254
255 QByteArray ba;
256 while (proc->canReadLine()) {
257 ba = proc->readLine();
258 ba.replace("\n", "");
259 ba.replace("\r", "");
260 readLine( ba );
261 }
262
263 return true;
264}
265
266#include "moc_inforeadermplayer.cpp"
Note: See TracBrowser for help on using the repository browser.