source: smplayer/trunk/src/mplayerprocess.cpp@ 188

Last change on this file since 188 was 188, checked in by Silvan Scherrer, 8 years ago

SMPlayer: update trunk to version 17.1.0

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