source: smplayer/vendor/0.8.2/src/mplayerprocess.cpp

Last change on this file was 137, checked in by Silvan Scherrer, 13 years ago

SMPlayer: updated vendor to 0.8.2

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