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