1 | /* smplayer, GUI front-end for mplayer.
|
---|
2 | Copyright (C) 2006-2011 Ricardo Villalba <rvm@escomposlinux.org>
|
---|
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 "mplayerprocess.h"
|
---|
20 | #include <QRegExp>
|
---|
21 | #include <QStringList>
|
---|
22 | #include <QApplication>
|
---|
23 |
|
---|
24 | #include "global.h"
|
---|
25 | #include "preferences.h"
|
---|
26 | #include "mplayerversion.h"
|
---|
27 | #include "colorutils.h"
|
---|
28 |
|
---|
29 | using namespace Global;
|
---|
30 |
|
---|
31 | MplayerProcess::MplayerProcess(QObject * parent) : MyProcess(parent)
|
---|
32 | {
|
---|
33 | #if NOTIFY_SUB_CHANGES
|
---|
34 | qRegisterMetaType<SubTracks>("SubTracks");
|
---|
35 | #endif
|
---|
36 |
|
---|
37 | #if NOTIFY_AUDIO_CHANGES
|
---|
38 | qRegisterMetaType<Tracks>("Tracks");
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | connect( this, SIGNAL(lineAvailable(QByteArray)),
|
---|
42 | this, SLOT(parseLine(QByteArray)) );
|
---|
43 |
|
---|
44 | connect( this, SIGNAL(finished(int,QProcess::ExitStatus)),
|
---|
45 | this, SLOT(processFinished(int,QProcess::ExitStatus)) );
|
---|
46 |
|
---|
47 | connect( this, SIGNAL(error(QProcess::ProcessError)),
|
---|
48 | this, SLOT(gotError(QProcess::ProcessError)) );
|
---|
49 |
|
---|
50 | notified_mplayer_is_running = false;
|
---|
51 | last_sub_id = -1;
|
---|
52 | mplayer_svn = -1; // Not found yet
|
---|
53 | }
|
---|
54 |
|
---|
55 | MplayerProcess::~MplayerProcess() {
|
---|
56 | }
|
---|
57 |
|
---|
58 | bool MplayerProcess::start() {
|
---|
59 | md.reset();
|
---|
60 | notified_mplayer_is_running = false;
|
---|
61 | last_sub_id = -1;
|
---|
62 | mplayer_svn = -1; // Not found yet
|
---|
63 | received_end_of_file = false;
|
---|
64 |
|
---|
65 | #if NOTIFY_SUB_CHANGES
|
---|
66 | subs.clear();
|
---|
67 | subtitle_info_received = false;
|
---|
68 | subtitle_info_changed = false;
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | #if NOTIFY_AUDIO_CHANGES
|
---|
72 | audios.clear();
|
---|
73 | audio_info_changed = false;
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | #if GENERIC_CHAPTER_SUPPORT
|
---|
77 | dvd_current_title = -1;
|
---|
78 | #endif
|
---|
79 |
|
---|
80 | MyProcess::start();
|
---|
81 |
|
---|
82 | #if !defined(Q_OS_OS2)
|
---|
83 | return waitForStarted();
|
---|
84 | #else
|
---|
85 | bool r = waitForStarted();
|
---|
86 | if (r) {
|
---|
87 | pidMP = QProcess::pid();
|
---|
88 | qDebug("MPlayer PID %i", pidMP);
|
---|
89 | MPpipeOpen();
|
---|
90 | }
|
---|
91 | return r;
|
---|
92 | #endif
|
---|
93 | }
|
---|
94 |
|
---|
95 | void MplayerProcess::writeToStdin(QString text) {
|
---|
96 | if (isRunning()) {
|
---|
97 | //qDebug("MplayerProcess::writeToStdin");
|
---|
98 | #if !defined(Q_OS_OS2)
|
---|
99 | write( text.toLocal8Bit() + "\n");
|
---|
100 | #else
|
---|
101 | MPpipeWrite( text.toLocal8Bit() + "\n");
|
---|
102 | #endif
|
---|
103 | } else {
|
---|
104 | qWarning("MplayerProcess::writeToStdin: process not running");
|
---|
105 | }
|
---|
106 | #ifdef Q_OS_OS2
|
---|
107 | if (text == "quit" || text == "quit\n") {
|
---|
108 | MPpipeClose();
|
---|
109 | }
|
---|
110 | #endif
|
---|
111 | }
|
---|
112 |
|
---|
113 | #ifdef Q_OS_OS2
|
---|
114 | void MplayerProcess::MPpipeOpen() {
|
---|
115 | char szPipeName[ 100 ];
|
---|
116 | sprintf( szPipeName, "\\PIPE\\MPLAYER\\%x", pidMP );
|
---|
117 | DosCreateNPipe( szPipeName, &hpipe, NP_ACCESS_DUPLEX, 1, 1024, 1024, 0 );
|
---|
118 | }
|
---|
119 |
|
---|
120 | void MplayerProcess::MPpipeClose( void ) {
|
---|
121 | DosClose( hpipe );
|
---|
122 | }
|
---|
123 |
|
---|
124 | void MplayerProcess::MPpipeWrite( const QByteArray text ) {
|
---|
125 | // MPlayer quitted ?
|
---|
126 | if ( !isRunning() )
|
---|
127 | return;
|
---|
128 |
|
---|
129 | // as things could hang when pipe communication is done direct here, i do a seperate thread for it
|
---|
130 | pipeThread = new PipeThread(text, hpipe);
|
---|
131 |
|
---|
132 | pipeThread->start();
|
---|
133 | while (!pipeThread->isRunning() && !pipeThread->isFinished()) {
|
---|
134 | qDebug("we sleep");
|
---|
135 | DosSleep(10);
|
---|
136 | }
|
---|
137 | // we wait for max 2 seconds for the thread to be ended (we to this with max 20 loops)
|
---|
138 | int count = 0;
|
---|
139 | while (!pipeThread->wait(100) && count < 20) {
|
---|
140 | count ++;
|
---|
141 | }
|
---|
142 | if (count >= 20) {
|
---|
143 | pipeThread->terminate();
|
---|
144 | qDebug("pipe communication terminated");
|
---|
145 | }
|
---|
146 | delete pipeThread;
|
---|
147 | }
|
---|
148 | #endif
|
---|
149 |
|
---|
150 | static QRegExp rx_av("^[AV]: *([0-9,:.-]+)");
|
---|
151 | static QRegExp rx_frame("^[AV]:.* (\\d+)\\/.\\d+");// [0-9,.]+");
|
---|
152 | static QRegExp rx("^(.*)=(.*)");
|
---|
153 | #if !NOTIFY_AUDIO_CHANGES
|
---|
154 | static QRegExp rx_audio_mat("^ID_AID_(\\d+)_(LANG|NAME)=(.*)");
|
---|
155 | #endif
|
---|
156 | static QRegExp rx_video("^ID_VID_(\\d+)_(LANG|NAME)=(.*)");
|
---|
157 | static QRegExp rx_title("^ID_DVD_TITLE_(\\d+)_(LENGTH|CHAPTERS|ANGLES)=(.*)");
|
---|
158 | static QRegExp rx_winresolution("^VO: \\[(.*)\\] (\\d+)x(\\d+) => (\\d+)x(\\d+)");
|
---|
159 | static QRegExp rx_ao("^AO: \\[(.*)\\]");
|
---|
160 | static QRegExp rx_paused("^ID_PAUSED");
|
---|
161 | #if !CHECK_VIDEO_CODEC_FOR_NO_VIDEO
|
---|
162 | static QRegExp rx_novideo("^Video: no video");
|
---|
163 | #endif
|
---|
164 | static QRegExp rx_cache("^Cache fill:.*");
|
---|
165 | static QRegExp rx_create_index("^Generating Index:.*");
|
---|
166 | static QRegExp rx_play("^Starting playback...");
|
---|
167 | static QRegExp rx_connecting("^Connecting to .*");
|
---|
168 | static QRegExp rx_resolving("^Resolving .*");
|
---|
169 | static QRegExp rx_screenshot("^\\*\\*\\* screenshot '(.*)'");
|
---|
170 | static QRegExp rx_endoffile("^Exiting... \\(End of file\\)|^ID_EXIT=EOF");
|
---|
171 | static QRegExp rx_mkvchapters("\\[mkv\\] Chapter (\\d+) from");
|
---|
172 | static QRegExp rx_aspect2("^Movie-Aspect is ([0-9,.]+):1");
|
---|
173 | static QRegExp rx_fontcache("^\\[ass\\] Updating font cache|^\\[ass\\] Init");
|
---|
174 | static QRegExp rx_scanning_font("Scanning file");
|
---|
175 | #if DVDNAV_SUPPORT
|
---|
176 | static QRegExp rx_dvdnav_switch_title("^DVDNAV, switched to title: (\\d+)");
|
---|
177 | static QRegExp rx_dvdnav_length("^ANS_length=(.*)");
|
---|
178 | static QRegExp rx_dvdnav_title_is_menu("^DVDNAV_TITLE_IS_MENU");
|
---|
179 | static QRegExp rx_dvdnav_title_is_movie("^DVDNAV_TITLE_IS_MOVIE");
|
---|
180 | #endif
|
---|
181 |
|
---|
182 | // VCD
|
---|
183 | static QRegExp rx_vcd("^ID_VCD_TRACK_(\\d+)_MSF=(.*)");
|
---|
184 |
|
---|
185 | // Audio CD
|
---|
186 | static QRegExp rx_cdda("^ID_CDDA_TRACK_(\\d+)_MSF=(.*)");
|
---|
187 |
|
---|
188 | //Subtitles
|
---|
189 | static QRegExp rx_subtitle("^ID_(SUBTITLE|FILE_SUB|VOBSUB)_ID=(\\d+)");
|
---|
190 | static QRegExp rx_sid("^ID_(SID|VSID)_(\\d+)_(LANG|NAME)=(.*)");
|
---|
191 | static QRegExp rx_subtitle_file("^ID_FILE_SUB_FILENAME=(.*)");
|
---|
192 |
|
---|
193 | // Audio
|
---|
194 | #if NOTIFY_AUDIO_CHANGES
|
---|
195 | static QRegExp rx_audio("^ID_AUDIO_ID=(\\d+)");
|
---|
196 | static QRegExp rx_audio_info("^ID_AID_(\\d+)_(LANG|NAME)=(.*)");
|
---|
197 | #endif
|
---|
198 |
|
---|
199 | #if PROGRAM_SWITCH
|
---|
200 | static QRegExp rx_program("^PROGRAM_ID=(\\d+)");
|
---|
201 | #endif
|
---|
202 |
|
---|
203 | //Clip info
|
---|
204 | static QRegExp rx_clip_name("^ (name|title): (.*)", Qt::CaseInsensitive);
|
---|
205 | static QRegExp rx_clip_artist("^ artist: (.*)", Qt::CaseInsensitive);
|
---|
206 | static QRegExp rx_clip_author("^ author: (.*)", Qt::CaseInsensitive);
|
---|
207 | static QRegExp rx_clip_album("^ album: (.*)", Qt::CaseInsensitive);
|
---|
208 | static QRegExp rx_clip_genre("^ genre: (.*)", Qt::CaseInsensitive);
|
---|
209 | static QRegExp rx_clip_date("^ (creation date|year): (.*)", Qt::CaseInsensitive);
|
---|
210 | static QRegExp rx_clip_track("^ track: (.*)", Qt::CaseInsensitive);
|
---|
211 | static QRegExp rx_clip_copyright("^ copyright: (.*)", Qt::CaseInsensitive);
|
---|
212 | static QRegExp rx_clip_comment("^ comment: (.*)", Qt::CaseInsensitive);
|
---|
213 | static QRegExp rx_clip_software("^ software: (.*)", Qt::CaseInsensitive);
|
---|
214 |
|
---|
215 | static QRegExp rx_stream_title("^.* StreamTitle='(.*)';");
|
---|
216 | static QRegExp rx_stream_title_and_url("^.* StreamTitle='(.*)';StreamUrl='(.*)';");
|
---|
217 |
|
---|
218 |
|
---|
219 | void MplayerProcess::parseLine(QByteArray ba) {
|
---|
220 | //qDebug("MplayerProcess::parseLine: '%s'", ba.data() );
|
---|
221 |
|
---|
222 | QString tag;
|
---|
223 | QString value;
|
---|
224 |
|
---|
225 | #if COLOR_OUTPUT_SUPPORT
|
---|
226 | QString line = ColorUtils::stripColorsTags(QString::fromLocal8Bit(ba));
|
---|
227 | #else
|
---|
228 | QString line = QString::fromLocal8Bit(ba);
|
---|
229 | #endif
|
---|
230 |
|
---|
231 | // Parse A: V: line
|
---|
232 | //qDebug("%s", line.toUtf8().data());
|
---|
233 | if (rx_av.indexIn(line) > -1) {
|
---|
234 | double sec = rx_av.cap(1).toDouble();
|
---|
235 | //qDebug("cap(1): '%s'", rx_av.cap(1).toUtf8().data() );
|
---|
236 | //qDebug("sec: %f", sec);
|
---|
237 |
|
---|
238 | #if NOTIFY_SUB_CHANGES
|
---|
239 | if (notified_mplayer_is_running) {
|
---|
240 | if (subtitle_info_changed) {
|
---|
241 | qDebug("MplayerProcess::parseLine: subtitle_info_changed");
|
---|
242 | subtitle_info_changed = false;
|
---|
243 | subtitle_info_received = false;
|
---|
244 | emit subtitleInfoChanged(subs);
|
---|
245 | }
|
---|
246 | if (subtitle_info_received) {
|
---|
247 | qDebug("MplayerProcess::parseLine: subtitle_info_received");
|
---|
248 | subtitle_info_received = false;
|
---|
249 | emit subtitleInfoReceivedAgain(subs);
|
---|
250 | }
|
---|
251 | }
|
---|
252 | #endif
|
---|
253 |
|
---|
254 | #if NOTIFY_AUDIO_CHANGES
|
---|
255 | if (notified_mplayer_is_running) {
|
---|
256 | if (audio_info_changed) {
|
---|
257 | qDebug("MplayerProcess::parseLine: audio_info_changed");
|
---|
258 | audio_info_changed = false;
|
---|
259 | emit audioInfoChanged(audios);
|
---|
260 | }
|
---|
261 | }
|
---|
262 | #endif
|
---|
263 |
|
---|
264 | if (!notified_mplayer_is_running) {
|
---|
265 | qDebug("MplayerProcess::parseLine: starting sec: %f", sec);
|
---|
266 | #if GENERIC_CHAPTER_SUPPORT
|
---|
267 | if ( (md.chapters <= 0) && (dvd_current_title > 0) &&
|
---|
268 | (md.titles.find(dvd_current_title) != -1) )
|
---|
269 | {
|
---|
270 | int idx = md.titles.find(dvd_current_title);
|
---|
271 | md.chapters = md.titles.itemAt(idx).chapters();
|
---|
272 | qDebug("MplayerProcess::parseLine: setting chapters to %d", md.chapters);
|
---|
273 | }
|
---|
274 | #endif
|
---|
275 |
|
---|
276 | #if CHECK_VIDEO_CODEC_FOR_NO_VIDEO
|
---|
277 | // Another way to find out if there's no video
|
---|
278 | if (md.video_codec.isEmpty()) {
|
---|
279 | md.novideo = true;
|
---|
280 | emit receivedNoVideo();
|
---|
281 | }
|
---|
282 | #endif
|
---|
283 |
|
---|
284 | emit receivedStartingTime(sec);
|
---|
285 | emit mplayerFullyLoaded();
|
---|
286 |
|
---|
287 | emit receivedCurrentFrame(0); // Ugly hack: set the frame counter to 0
|
---|
288 |
|
---|
289 | notified_mplayer_is_running = true;
|
---|
290 | }
|
---|
291 |
|
---|
292 | emit receivedCurrentSec( sec );
|
---|
293 |
|
---|
294 | // Check for frame
|
---|
295 | if (rx_frame.indexIn(line) > -1) {
|
---|
296 | int frame = rx_frame.cap(1).toInt();
|
---|
297 | //qDebug(" frame: %d", frame);
|
---|
298 | emit receivedCurrentFrame(frame);
|
---|
299 | }
|
---|
300 | }
|
---|
301 | else {
|
---|
302 | // Emulates mplayer version in Ubuntu:
|
---|
303 | //if (line.startsWith("MPlayer 1.0rc1")) line = "MPlayer 2:1.0~rc1-0ubuntu13.1 (C) 2000-2006 MPlayer Team";
|
---|
304 |
|
---|
305 | // Emulates unknown version
|
---|
306 | //if (line.startsWith("MPlayer SVN")) line = "MPlayer lalksklsjjakksja";
|
---|
307 |
|
---|
308 | emit lineAvailable(line);
|
---|
309 |
|
---|
310 | // Parse other things
|
---|
311 | qDebug("MplayerProcess::parseLine: '%s'", line.toUtf8().data() );
|
---|
312 |
|
---|
313 | // Screenshot
|
---|
314 | if (rx_screenshot.indexIn(line) > -1) {
|
---|
315 | QString shot = rx_screenshot.cap(1);
|
---|
316 | qDebug("MplayerProcess::parseLine: screenshot: '%s'", shot.toUtf8().data());
|
---|
317 | emit receivedScreenshot( shot );
|
---|
318 | }
|
---|
319 | else
|
---|
320 |
|
---|
321 | // End of file
|
---|
322 | if (rx_endoffile.indexIn(line) > -1) {
|
---|
323 | qDebug("MplayerProcess::parseLine: detected end of file");
|
---|
324 | if (!received_end_of_file) {
|
---|
325 | // In case of playing VCDs or DVDs, maybe the first title
|
---|
326 | // is not playable, so the GUI doesn't get the info about
|
---|
327 | // available titles. So if we received the end of file
|
---|
328 | // first let's pretend the file has started so the GUI can have
|
---|
329 | // the data.
|
---|
330 | if ( !notified_mplayer_is_running) {
|
---|
331 | emit mplayerFullyLoaded();
|
---|
332 | }
|
---|
333 |
|
---|
334 | //emit receivedEndOfFile();
|
---|
335 | // Send signal once the process is finished, not now!
|
---|
336 | received_end_of_file = true;
|
---|
337 | }
|
---|
338 | }
|
---|
339 | else
|
---|
340 |
|
---|
341 | // Window resolution
|
---|
342 | if (rx_winresolution.indexIn(line) > -1) {
|
---|
343 | /*
|
---|
344 | md.win_width = rx_winresolution.cap(4).toInt();
|
---|
345 | md.win_height = rx_winresolution.cap(5).toInt();
|
---|
346 | md.video_aspect = (double) md.win_width / md.win_height;
|
---|
347 | */
|
---|
348 |
|
---|
349 | int w = rx_winresolution.cap(4).toInt();
|
---|
350 | int h = rx_winresolution.cap(5).toInt();
|
---|
351 |
|
---|
352 | emit receivedVO( rx_winresolution.cap(1) );
|
---|
353 | emit receivedWindowResolution( w, h );
|
---|
354 | //emit mplayerFullyLoaded();
|
---|
355 | }
|
---|
356 | else
|
---|
357 |
|
---|
358 | #if !CHECK_VIDEO_CODEC_FOR_NO_VIDEO
|
---|
359 | // No video
|
---|
360 | if (rx_novideo.indexIn(line) > -1) {
|
---|
361 | md.novideo = TRUE;
|
---|
362 | emit receivedNoVideo();
|
---|
363 | //emit mplayerFullyLoaded();
|
---|
364 | }
|
---|
365 | else
|
---|
366 | #endif
|
---|
367 |
|
---|
368 | // Pause
|
---|
369 | if (rx_paused.indexIn(line) > -1) {
|
---|
370 | emit receivedPause();
|
---|
371 | }
|
---|
372 |
|
---|
373 | // Stream title
|
---|
374 | if (rx_stream_title_and_url.indexIn(line) > -1) {
|
---|
375 | QString s = rx_stream_title_and_url.cap(1);
|
---|
376 | QString url = rx_stream_title_and_url.cap(2);
|
---|
377 | qDebug("MplayerProcess::parseLine: stream_title: '%s'", s.toUtf8().data());
|
---|
378 | qDebug("MplayerProcess::parseLine: stream_url: '%s'", url.toUtf8().data());
|
---|
379 | md.stream_title = s;
|
---|
380 | md.stream_url = url;
|
---|
381 | emit receivedStreamTitleAndUrl( s, url );
|
---|
382 | }
|
---|
383 | else
|
---|
384 | if (rx_stream_title.indexIn(line) > -1) {
|
---|
385 | QString s = rx_stream_title.cap(1);
|
---|
386 | qDebug("MplayerProcess::parseLine: stream_title: '%s'", s.toUtf8().data());
|
---|
387 | md.stream_title = s;
|
---|
388 | emit receivedStreamTitle( s );
|
---|
389 | }
|
---|
390 |
|
---|
391 | #if NOTIFY_SUB_CHANGES
|
---|
392 | // Subtitles
|
---|
393 | if ((rx_subtitle.indexIn(line) > -1) || (rx_sid.indexIn(line) > -1) || (rx_subtitle_file.indexIn(line) > -1)) {
|
---|
394 | int r = subs.parse(line);
|
---|
395 | //qDebug("MplayerProcess::parseLine: result of parse: %d", r);
|
---|
396 | subtitle_info_received = true;
|
---|
397 | if ((r == SubTracks::SubtitleAdded) || (r == SubTracks::SubtitleChanged)) subtitle_info_changed = true;
|
---|
398 | }
|
---|
399 | #endif
|
---|
400 |
|
---|
401 | #if NOTIFY_AUDIO_CHANGES
|
---|
402 | // Audio
|
---|
403 | if (rx_audio.indexIn(line) > -1) {
|
---|
404 | int ID = rx_audio.cap(1).toInt();
|
---|
405 | qDebug("MplayerProcess::parseLine: ID_AUDIO_ID: %d", ID);
|
---|
406 | if (audios.find(ID) == -1) audio_info_changed = true;
|
---|
407 | audios.addID( ID );
|
---|
408 | }
|
---|
409 |
|
---|
410 | if (rx_audio_info.indexIn(line) > -1) {
|
---|
411 | int ID = rx_audio_info.cap(1).toInt();
|
---|
412 | QString lang = rx_audio_info.cap(3);
|
---|
413 | QString t = rx_audio_info.cap(2);
|
---|
414 | qDebug("MplayerProcess::parseLine: Audio: ID: %d, Lang: '%s' Type: '%s'",
|
---|
415 | ID, lang.toUtf8().data(), t.toUtf8().data());
|
---|
416 |
|
---|
417 | int idx = audios.find(ID);
|
---|
418 | if (idx == -1) {
|
---|
419 | qDebug("MplayerProcess::parseLine: audio %d doesn't exist, adding it", ID);
|
---|
420 |
|
---|
421 | audio_info_changed = true;
|
---|
422 | if ( t == "NAME" )
|
---|
423 | audios.addName(ID, lang);
|
---|
424 | else
|
---|
425 | audios.addLang(ID, lang);
|
---|
426 | } else {
|
---|
427 | qDebug("MplayerProcess::parseLine: audio %d exists, modifing it", ID);
|
---|
428 |
|
---|
429 | if (t == "NAME") {
|
---|
430 | //qDebug("MplayerProcess::parseLine: name of audio %d: %s", ID, audios.itemAt(idx).name().toUtf8().constData());
|
---|
431 | if (audios.itemAt(idx).name() != lang) {
|
---|
432 | audio_info_changed = true;
|
---|
433 | audios.addName(ID, lang);
|
---|
434 | }
|
---|
435 | } else {
|
---|
436 | //qDebug("MplayerProcess::parseLine: language of audio %d: %s", ID, audios.itemAt(idx).lang().toUtf8().constData());
|
---|
437 | if (audios.itemAt(idx).lang() != lang) {
|
---|
438 | audio_info_changed = true;
|
---|
439 | audios.addLang(ID, lang);
|
---|
440 | }
|
---|
441 | }
|
---|
442 | }
|
---|
443 | }
|
---|
444 | #endif
|
---|
445 |
|
---|
446 | #if DVDNAV_SUPPORT
|
---|
447 | if (rx_dvdnav_switch_title.indexIn(line) > -1) {
|
---|
448 | int title = rx_dvdnav_switch_title.cap(1).toInt();
|
---|
449 | qDebug("MplayerProcess::parseLine: dvd title: %d", title);
|
---|
450 | emit receivedDVDTitle(title);
|
---|
451 | }
|
---|
452 | if (rx_dvdnav_length.indexIn(line) > -1) {
|
---|
453 | double length = rx_dvdnav_length.cap(1).toDouble();
|
---|
454 | qDebug("MplayerProcess::parseLine: length: %f", length);
|
---|
455 | if (length != md.duration) {
|
---|
456 | md.duration = length;
|
---|
457 | emit receivedDuration(length);
|
---|
458 | }
|
---|
459 | }
|
---|
460 | if (rx_dvdnav_title_is_menu.indexIn(line) > -1) {
|
---|
461 | emit receivedTitleIsMenu();
|
---|
462 | }
|
---|
463 | if (rx_dvdnav_title_is_movie.indexIn(line) > -1) {
|
---|
464 | emit receivedTitleIsMovie();
|
---|
465 | }
|
---|
466 | #endif
|
---|
467 |
|
---|
468 | // The following things are not sent when the file has started to play
|
---|
469 | // (or if sent, smplayer will ignore anyway...)
|
---|
470 | // So not process anymore, if video is playing to save some time
|
---|
471 | if (notified_mplayer_is_running) {
|
---|
472 | return;
|
---|
473 | }
|
---|
474 |
|
---|
475 | if ( (mplayer_svn == -1) && (line.startsWith("MPlayer ")) ) {
|
---|
476 | mplayer_svn = MplayerVersion::mplayerVersion(line);
|
---|
477 | qDebug("MplayerProcess::parseLine: MPlayer SVN: %d", mplayer_svn);
|
---|
478 | if (mplayer_svn <= 0) {
|
---|
479 | qWarning("MplayerProcess::parseLine: couldn't parse mplayer version!");
|
---|
480 | emit failedToParseMplayerVersion(line);
|
---|
481 | }
|
---|
482 | }
|
---|
483 |
|
---|
484 | #if !NOTIFY_SUB_CHANGES
|
---|
485 | // Subtitles
|
---|
486 | if (rx_subtitle.indexIn(line) > -1) {
|
---|
487 | md.subs.parse(line);
|
---|
488 | }
|
---|
489 | else
|
---|
490 | if (rx_sid.indexIn(line) > -1) {
|
---|
491 | md.subs.parse(line);
|
---|
492 | }
|
---|
493 | else
|
---|
494 | if (rx_subtitle_file.indexIn(line) > -1) {
|
---|
495 | md.subs.parse(line);
|
---|
496 | }
|
---|
497 | #endif
|
---|
498 | // AO
|
---|
499 | if (rx_ao.indexIn(line) > -1) {
|
---|
500 | emit receivedAO( rx_ao.cap(1) );
|
---|
501 | }
|
---|
502 | else
|
---|
503 |
|
---|
504 | #if !NOTIFY_AUDIO_CHANGES
|
---|
505 | // Matroska audio
|
---|
506 | if (rx_audio_mat.indexIn(line) > -1) {
|
---|
507 | int ID = rx_audio_mat.cap(1).toInt();
|
---|
508 | QString lang = rx_audio_mat.cap(3);
|
---|
509 | QString t = rx_audio_mat.cap(2);
|
---|
510 | qDebug("MplayerProcess::parseLine: Audio: ID: %d, Lang: '%s' Type: '%s'",
|
---|
511 | ID, lang.toUtf8().data(), t.toUtf8().data());
|
---|
512 |
|
---|
513 | if ( t == "NAME" )
|
---|
514 | md.audios.addName(ID, lang);
|
---|
515 | else
|
---|
516 | md.audios.addLang(ID, lang);
|
---|
517 | }
|
---|
518 | else
|
---|
519 | #endif
|
---|
520 |
|
---|
521 | #if PROGRAM_SWITCH
|
---|
522 | // Program
|
---|
523 | if (rx_program.indexIn(line) > -1) {
|
---|
524 | int ID = rx_program.cap(1).toInt();
|
---|
525 | qDebug("MplayerProcess::parseLine: Program: ID: %d", ID);
|
---|
526 | md.programs.addID( ID );
|
---|
527 | }
|
---|
528 | else
|
---|
529 | #endif
|
---|
530 |
|
---|
531 | // Video tracks
|
---|
532 | if (rx_video.indexIn(line) > -1) {
|
---|
533 | int ID = rx_video.cap(1).toInt();
|
---|
534 | QString lang = rx_video.cap(3);
|
---|
535 | QString t = rx_video.cap(2);
|
---|
536 | qDebug("MplayerProcess::parseLine: Video: ID: %d, Lang: '%s' Type: '%s'",
|
---|
537 | ID, lang.toUtf8().data(), t.toUtf8().data());
|
---|
538 |
|
---|
539 | if ( t == "NAME" )
|
---|
540 | md.videos.addName(ID, lang);
|
---|
541 | else
|
---|
542 | md.videos.addLang(ID, lang);
|
---|
543 | }
|
---|
544 | else
|
---|
545 |
|
---|
546 | // Matroshka chapters
|
---|
547 | if (rx_mkvchapters.indexIn(line)!=-1) {
|
---|
548 | int c = rx_mkvchapters.cap(1).toInt();
|
---|
549 | qDebug("MplayerProcess::parseLine: mkv chapters: %d", c);
|
---|
550 | #if GENERIC_CHAPTER_SUPPORT
|
---|
551 | if ((c+1) > md.chapters) {
|
---|
552 | md.chapters = c+1;
|
---|
553 | qDebug("MplayerProcess::parseLine: chapters set to: %d", md.chapters);
|
---|
554 | }
|
---|
555 | #else
|
---|
556 | if ((c+1) > md.mkv_chapters) {
|
---|
557 | md.mkv_chapters = c+1;
|
---|
558 | qDebug("MplayerProcess::parseLine: mkv_chapters set to: %d", md.mkv_chapters);
|
---|
559 | }
|
---|
560 | #endif
|
---|
561 | }
|
---|
562 | else
|
---|
563 |
|
---|
564 | // VCD titles
|
---|
565 | if (rx_vcd.indexIn(line) > -1 ) {
|
---|
566 | int ID = rx_vcd.cap(1).toInt();
|
---|
567 | QString length = rx_vcd.cap(2);
|
---|
568 | //md.titles.addID( ID );
|
---|
569 | md.titles.addName( ID, length );
|
---|
570 | }
|
---|
571 | else
|
---|
572 |
|
---|
573 | // Audio CD titles
|
---|
574 | if (rx_cdda.indexIn(line) > -1 ) {
|
---|
575 | int ID = rx_cdda.cap(1).toInt();
|
---|
576 | QString length = rx_cdda.cap(2);
|
---|
577 | double duration = 0;
|
---|
578 | QRegExp r("(\\d+):(\\d+):(\\d+)");
|
---|
579 | if ( r.indexIn(length) > -1 ) {
|
---|
580 | duration = r.cap(1).toInt() * 60;
|
---|
581 | duration += r.cap(2).toInt();
|
---|
582 | }
|
---|
583 | md.titles.addID( ID );
|
---|
584 | /*
|
---|
585 | QString name = QString::number(ID) + " (" + length + ")";
|
---|
586 | md.titles.addName( ID, name );
|
---|
587 | */
|
---|
588 | md.titles.addDuration( ID, duration );
|
---|
589 | }
|
---|
590 | else
|
---|
591 |
|
---|
592 | // DVD titles
|
---|
593 | if (rx_title.indexIn(line) > -1) {
|
---|
594 | int ID = rx_title.cap(1).toInt();
|
---|
595 | QString t = rx_title.cap(2);
|
---|
596 |
|
---|
597 | if (t=="LENGTH") {
|
---|
598 | double length = rx_title.cap(3).toDouble();
|
---|
599 | qDebug("MplayerProcess::parseLine: Title: ID: %d, Length: '%f'", ID, length);
|
---|
600 | md.titles.addDuration(ID, length);
|
---|
601 | }
|
---|
602 | else
|
---|
603 | if (t=="CHAPTERS") {
|
---|
604 | int chapters = rx_title.cap(3).toInt();
|
---|
605 | qDebug("MplayerProcess::parseLine: Title: ID: %d, Chapters: '%d'", ID, chapters);
|
---|
606 | md.titles.addChapters(ID, chapters);
|
---|
607 | }
|
---|
608 | else
|
---|
609 | if (t=="ANGLES") {
|
---|
610 | int angles = rx_title.cap(3).toInt();
|
---|
611 | qDebug("MplayerProcess::parseLine: Title: ID: %d, Angles: '%d'", ID, angles);
|
---|
612 | md.titles.addAngles(ID, angles);
|
---|
613 | }
|
---|
614 | }
|
---|
615 | else
|
---|
616 |
|
---|
617 | // Catch cache messages
|
---|
618 | if (rx_cache.indexIn(line) > -1) {
|
---|
619 | emit receivedCacheMessage(line);
|
---|
620 | }
|
---|
621 | else
|
---|
622 |
|
---|
623 | // Creating index
|
---|
624 | if (rx_create_index.indexIn(line) > -1) {
|
---|
625 | emit receivedCreatingIndex(line);
|
---|
626 | }
|
---|
627 | else
|
---|
628 |
|
---|
629 | // Catch connecting message
|
---|
630 | if (rx_connecting.indexIn(line) > -1) {
|
---|
631 | emit receivedConnectingToMessage(line);
|
---|
632 | }
|
---|
633 | else
|
---|
634 |
|
---|
635 | // Catch resolving message
|
---|
636 | if (rx_resolving.indexIn(line) > -1) {
|
---|
637 | emit receivedResolvingMessage(line);
|
---|
638 | }
|
---|
639 | else
|
---|
640 |
|
---|
641 | // Aspect ratio for old versions of mplayer
|
---|
642 | if (rx_aspect2.indexIn(line) > -1) {
|
---|
643 | md.video_aspect = rx_aspect2.cap(1).toDouble();
|
---|
644 | qDebug("MplayerProcess::parseLine: md.video_aspect set to %f", md.video_aspect);
|
---|
645 | }
|
---|
646 | else
|
---|
647 |
|
---|
648 | // Clip info
|
---|
649 |
|
---|
650 | //QString::trimmed() is used for removing leading and trailing whitespaces
|
---|
651 | //Some .mp3 files contain tags with starting and ending whitespaces
|
---|
652 | //Unfortunately MPlayer gives us leading and trailing whitespaces, Winamp for example doesn't show them
|
---|
653 |
|
---|
654 | // Name
|
---|
655 | if (rx_clip_name.indexIn(line) > -1) {
|
---|
656 | QString s = rx_clip_name.cap(2).trimmed();
|
---|
657 | qDebug("MplayerProcess::parseLine: clip_name: '%s'", s.toUtf8().data());
|
---|
658 | md.clip_name = s;
|
---|
659 | }
|
---|
660 | else
|
---|
661 |
|
---|
662 | // Artist
|
---|
663 | if (rx_clip_artist.indexIn(line) > -1) {
|
---|
664 | QString s = rx_clip_artist.cap(1).trimmed();
|
---|
665 | qDebug("MplayerProcess::parseLine: clip_artist: '%s'", s.toUtf8().data());
|
---|
666 | md.clip_artist = s;
|
---|
667 | }
|
---|
668 | else
|
---|
669 |
|
---|
670 | // Author
|
---|
671 | if (rx_clip_author.indexIn(line) > -1) {
|
---|
672 | QString s = rx_clip_author.cap(1).trimmed();
|
---|
673 | qDebug("MplayerProcess::parseLine: clip_author: '%s'", s.toUtf8().data());
|
---|
674 | md.clip_author = s;
|
---|
675 | }
|
---|
676 | else
|
---|
677 |
|
---|
678 | // Album
|
---|
679 | if (rx_clip_album.indexIn(line) > -1) {
|
---|
680 | QString s = rx_clip_album.cap(1).trimmed();
|
---|
681 | qDebug("MplayerProcess::parseLine: clip_album: '%s'", s.toUtf8().data());
|
---|
682 | md.clip_album = s;
|
---|
683 | }
|
---|
684 | else
|
---|
685 |
|
---|
686 | // Genre
|
---|
687 | if (rx_clip_genre.indexIn(line) > -1) {
|
---|
688 | QString s = rx_clip_genre.cap(1).trimmed();
|
---|
689 | qDebug("MplayerProcess::parseLine: clip_genre: '%s'", s.toUtf8().data());
|
---|
690 | md.clip_genre = s;
|
---|
691 | }
|
---|
692 | else
|
---|
693 |
|
---|
694 | // Date
|
---|
695 | if (rx_clip_date.indexIn(line) > -1) {
|
---|
696 | QString s = rx_clip_date.cap(2).trimmed();
|
---|
697 | qDebug("MplayerProcess::parseLine: clip_date: '%s'", s.toUtf8().data());
|
---|
698 | md.clip_date = s;
|
---|
699 | }
|
---|
700 | else
|
---|
701 |
|
---|
702 | // Track
|
---|
703 | if (rx_clip_track.indexIn(line) > -1) {
|
---|
704 | QString s = rx_clip_track.cap(1).trimmed();
|
---|
705 | qDebug("MplayerProcess::parseLine: clip_track: '%s'", s.toUtf8().data());
|
---|
706 | md.clip_track = s;
|
---|
707 | }
|
---|
708 | else
|
---|
709 |
|
---|
710 | // Copyright
|
---|
711 | if (rx_clip_copyright.indexIn(line) > -1) {
|
---|
712 | QString s = rx_clip_copyright.cap(1).trimmed();
|
---|
713 | qDebug("MplayerProcess::parseLine: clip_copyright: '%s'", s.toUtf8().data());
|
---|
714 | md.clip_copyright = s;
|
---|
715 | }
|
---|
716 | else
|
---|
717 |
|
---|
718 | // Comment
|
---|
719 | if (rx_clip_comment.indexIn(line) > -1) {
|
---|
720 | QString s = rx_clip_comment.cap(1).trimmed();
|
---|
721 | qDebug("MplayerProcess::parseLine: clip_comment: '%s'", s.toUtf8().data());
|
---|
722 | md.clip_comment = s;
|
---|
723 | }
|
---|
724 | else
|
---|
725 |
|
---|
726 | // Software
|
---|
727 | if (rx_clip_software.indexIn(line) > -1) {
|
---|
728 | QString s = rx_clip_software.cap(1).trimmed();
|
---|
729 | qDebug("MplayerProcess::parseLine: clip_software: '%s'", s.toUtf8().data());
|
---|
730 | md.clip_software = s;
|
---|
731 | }
|
---|
732 | else
|
---|
733 |
|
---|
734 | if (rx_fontcache.indexIn(line) > -1) {
|
---|
735 | //qDebug("MplayerProcess::parseLine: updating font cache");
|
---|
736 | emit receivedUpdatingFontCache();
|
---|
737 | }
|
---|
738 | else
|
---|
739 | if (rx_scanning_font.indexIn(line) > -1) {
|
---|
740 | emit receivedScanningFont(line);
|
---|
741 | }
|
---|
742 | else
|
---|
743 |
|
---|
744 | // Catch starting message
|
---|
745 | /*
|
---|
746 | pos = rx_play.indexIn(line);
|
---|
747 | if (pos > -1) {
|
---|
748 | emit mplayerFullyLoaded();
|
---|
749 | }
|
---|
750 | */
|
---|
751 |
|
---|
752 | //Generic things
|
---|
753 | if (rx.indexIn(line) > -1) {
|
---|
754 | tag = rx.cap(1);
|
---|
755 | value = rx.cap(2);
|
---|
756 | //qDebug("MplayerProcess::parseLine: tag: %s, value: %s", tag.toUtf8().data(), value.toUtf8().data());
|
---|
757 |
|
---|
758 | #if !NOTIFY_AUDIO_CHANGES
|
---|
759 | // Generic audio
|
---|
760 | if (tag == "ID_AUDIO_ID") {
|
---|
761 | int ID = value.toInt();
|
---|
762 | qDebug("MplayerProcess::parseLine: ID_AUDIO_ID: %d", ID);
|
---|
763 | md.audios.addID( ID );
|
---|
764 | }
|
---|
765 | else
|
---|
766 | #endif
|
---|
767 |
|
---|
768 | // Video
|
---|
769 | if (tag == "ID_VIDEO_ID") {
|
---|
770 | int ID = value.toInt();
|
---|
771 | qDebug("MplayerProcess::parseLine: ID_VIDEO_ID: %d", ID);
|
---|
772 | md.videos.addID( ID );
|
---|
773 | }
|
---|
774 | else
|
---|
775 | if (tag == "ID_LENGTH") {
|
---|
776 | md.duration = value.toDouble();
|
---|
777 | qDebug("MplayerProcess::parseLine: md.duration set to %f", md.duration);
|
---|
778 | }
|
---|
779 | else
|
---|
780 | if (tag == "ID_VIDEO_WIDTH") {
|
---|
781 | md.video_width = value.toInt();
|
---|
782 | qDebug("MplayerProcess::parseLine: md.video_width set to %d", md.video_width);
|
---|
783 | }
|
---|
784 | else
|
---|
785 | if (tag == "ID_VIDEO_HEIGHT") {
|
---|
786 | md.video_height = value.toInt();
|
---|
787 | qDebug("MplayerProcess::parseLine: md.video_height set to %d", md.video_height);
|
---|
788 | }
|
---|
789 | else
|
---|
790 | if (tag == "ID_VIDEO_ASPECT") {
|
---|
791 | md.video_aspect = value.toDouble();
|
---|
792 | if ( md.video_aspect == 0.0 ) {
|
---|
793 | // I hope width & height are already set.
|
---|
794 | md.video_aspect = (double) md.video_width / md.video_height;
|
---|
795 | }
|
---|
796 | qDebug("MplayerProcess::parseLine: md.video_aspect set to %f", md.video_aspect);
|
---|
797 | }
|
---|
798 | else
|
---|
799 | if (tag == "ID_DVD_DISC_ID") {
|
---|
800 | md.dvd_id = value;
|
---|
801 | qDebug("MplayerProcess::parseLine: md.dvd_id set to '%s'", md.dvd_id.toUtf8().data());
|
---|
802 | }
|
---|
803 | else
|
---|
804 | if (tag == "ID_DEMUXER") {
|
---|
805 | md.demuxer = value;
|
---|
806 | }
|
---|
807 | else
|
---|
808 | if (tag == "ID_VIDEO_FORMAT") {
|
---|
809 | md.video_format = value;
|
---|
810 | }
|
---|
811 | else
|
---|
812 | if (tag == "ID_AUDIO_FORMAT") {
|
---|
813 | md.audio_format = value;
|
---|
814 | }
|
---|
815 | else
|
---|
816 | if (tag == "ID_VIDEO_BITRATE") {
|
---|
817 | md.video_bitrate = value.toInt();
|
---|
818 | }
|
---|
819 | else
|
---|
820 | if (tag == "ID_VIDEO_FPS") {
|
---|
821 | md.video_fps = value;
|
---|
822 | }
|
---|
823 | else
|
---|
824 | if (tag == "ID_AUDIO_BITRATE") {
|
---|
825 | md.audio_bitrate = value.toInt();
|
---|
826 | }
|
---|
827 | else
|
---|
828 | if (tag == "ID_AUDIO_RATE") {
|
---|
829 | md.audio_rate = value.toInt();
|
---|
830 | }
|
---|
831 | else
|
---|
832 | if (tag == "ID_AUDIO_NCH") {
|
---|
833 | md.audio_nch = value.toInt();
|
---|
834 | }
|
---|
835 | else
|
---|
836 | if (tag == "ID_VIDEO_CODEC") {
|
---|
837 | md.video_codec = value;
|
---|
838 | }
|
---|
839 | else
|
---|
840 | if (tag == "ID_AUDIO_CODEC") {
|
---|
841 | md.audio_codec = value;
|
---|
842 | }
|
---|
843 | #if GENERIC_CHAPTER_SUPPORT
|
---|
844 | else
|
---|
845 | if (tag == "ID_CHAPTERS") {
|
---|
846 | md.chapters = value.toInt();
|
---|
847 | }
|
---|
848 | else
|
---|
849 | if (tag == "ID_DVD_CURRENT_TITLE") {
|
---|
850 | dvd_current_title = value.toInt();
|
---|
851 | }
|
---|
852 | #endif
|
---|
853 | }
|
---|
854 | }
|
---|
855 | }
|
---|
856 |
|
---|
857 | // Called when the process is finished
|
---|
858 | void MplayerProcess::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
|
---|
859 | qDebug("MplayerProcess::processFinished: exitCode: %d, status: %d", exitCode, (int) exitStatus);
|
---|
860 | // Send this signal before the endoffile one, otherwise
|
---|
861 | // the playlist will start to play next file before all
|
---|
862 | // objects are notified that the process has exited.
|
---|
863 | emit processExited();
|
---|
864 | if (received_end_of_file) emit receivedEndOfFile();
|
---|
865 | }
|
---|
866 |
|
---|
867 | void MplayerProcess::gotError(QProcess::ProcessError error) {
|
---|
868 | qDebug("MplayerProcess::gotError: %d", (int) error);
|
---|
869 | }
|
---|
870 |
|
---|
871 | #ifdef Q_OS_OS2
|
---|
872 | PipeThread::PipeThread(const QByteArray t, const HPIPE pipe) {
|
---|
873 | text = t;
|
---|
874 | hpipe = pipe;
|
---|
875 | }
|
---|
876 |
|
---|
877 | PipeThread::~PipeThread() {
|
---|
878 | }
|
---|
879 |
|
---|
880 | void PipeThread::run() {
|
---|
881 | ULONG cbActual;
|
---|
882 | APIRET rc = NO_ERROR;
|
---|
883 |
|
---|
884 | rc = DosConnectNPipe( hpipe );
|
---|
885 | if (rc != NO_ERROR)
|
---|
886 | return;
|
---|
887 |
|
---|
888 | // qDebug("pipe connected");
|
---|
889 | DosWrite( hpipe, text.data(), strlen( text.data() ), &cbActual );
|
---|
890 |
|
---|
891 | // Wait for ACK
|
---|
892 | DosRead( hpipe, &cbActual, sizeof( ULONG ), &cbActual );
|
---|
893 | DosDisConnectNPipe( hpipe );
|
---|
894 | return;
|
---|
895 | }
|
---|
896 | #endif
|
---|
897 |
|
---|
898 | #include "moc_mplayerprocess.cpp"
|
---|