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

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