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

Last change on this file since 130 was 128, checked in by Silvan Scherrer, 13 years ago

SMPlayer: trunk update to latest svn

  • Property svn:eol-style set to LF
File size: 25.7 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
304 // Emulates unknown version
305 //if (line.startsWith("MPlayer SVN")) line = "MPlayer lalksklsjjakksja";
306
307 emit lineAvailable(line);
308
309 // Parse other things
310 qDebug("MplayerProcess::parseLine: '%s'", line.toUtf8().data() );
311
312 // Screenshot
313 if (rx_screenshot.indexIn(line) > -1) {
314 QString shot = rx_screenshot.cap(1);
315 qDebug("MplayerProcess::parseLine: screenshot: '%s'", shot.toUtf8().data());
316 emit receivedScreenshot( shot );
317 }
318 else
319
320 // End of file
321 if (rx_endoffile.indexIn(line) > -1) {
322 qDebug("MplayerProcess::parseLine: detected end of file");
323 if (!received_end_of_file) {
324 // In case of playing VCDs or DVDs, maybe the first title
325 // is not playable, so the GUI doesn't get the info about
326 // available titles. So if we received the end of file
327 // first let's pretend the file has started so the GUI can have
328 // the data.
329 if ( !notified_mplayer_is_running) {
330 emit mplayerFullyLoaded();
331 }
332
333 //emit receivedEndOfFile();
334 // Send signal once the process is finished, not now!
335 received_end_of_file = true;
336 }
337 }
338 else
339
340 // Window resolution
341 if (rx_winresolution.indexIn(line) > -1) {
342 /*
343 md.win_width = rx_winresolution.cap(4).toInt();
344 md.win_height = rx_winresolution.cap(5).toInt();
345 md.video_aspect = (double) md.win_width / md.win_height;
346 */
347
348 int w = rx_winresolution.cap(4).toInt();
349 int h = rx_winresolution.cap(5).toInt();
350
351 emit receivedVO( rx_winresolution.cap(1) );
352 emit receivedWindowResolution( w, h );
353 //emit mplayerFullyLoaded();
354 }
355 else
356
357#if !CHECK_VIDEO_CODEC_FOR_NO_VIDEO
358 // No video
359 if (rx_novideo.indexIn(line) > -1) {
360 md.novideo = TRUE;
361 emit receivedNoVideo();
362 //emit mplayerFullyLoaded();
363 }
364 else
365#endif
366
367 // Pause
368 if (rx_paused.indexIn(line) > -1) {
369 emit receivedPause();
370 }
371
372 // Stream title
373 if (rx_stream_title_and_url.indexIn(line) > -1) {
374 QString s = rx_stream_title_and_url.cap(1);
375 QString url = rx_stream_title_and_url.cap(2);
376 qDebug("MplayerProcess::parseLine: stream_title: '%s'", s.toUtf8().data());
377 qDebug("MplayerProcess::parseLine: stream_url: '%s'", url.toUtf8().data());
378 md.stream_title = s;
379 md.stream_url = url;
380 emit receivedStreamTitleAndUrl( s, url );
381 }
382 else
383 if (rx_stream_title.indexIn(line) > -1) {
384 QString s = rx_stream_title.cap(1);
385 qDebug("MplayerProcess::parseLine: stream_title: '%s'", s.toUtf8().data());
386 md.stream_title = s;
387 emit receivedStreamTitle( s );
388 }
389
390#if NOTIFY_SUB_CHANGES
391 // Subtitles
392 if ((rx_subtitle.indexIn(line) > -1) || (rx_sid.indexIn(line) > -1) || (rx_subtitle_file.indexIn(line) > -1)) {
393 int r = subs.parse(line);
394 //qDebug("MplayerProcess::parseLine: result of parse: %d", r);
395 subtitle_info_received = true;
396 if ((r == SubTracks::SubtitleAdded) || (r == SubTracks::SubtitleChanged)) subtitle_info_changed = true;
397 }
398#endif
399
400#if NOTIFY_AUDIO_CHANGES
401 // Audio
402 if (rx_audio.indexIn(line) > -1) {
403 int ID = rx_audio.cap(1).toInt();
404 qDebug("MplayerProcess::parseLine: ID_AUDIO_ID: %d", ID);
405 if (audios.find(ID) == -1) audio_info_changed = true;
406 audios.addID( ID );
407 }
408
409 if (rx_audio_info.indexIn(line) > -1) {
410 int ID = rx_audio_info.cap(1).toInt();
411 QString lang = rx_audio_info.cap(3);
412 QString t = rx_audio_info.cap(2);
413 qDebug("MplayerProcess::parseLine: Audio: ID: %d, Lang: '%s' Type: '%s'",
414 ID, lang.toUtf8().data(), t.toUtf8().data());
415
416 int idx = audios.find(ID);
417 if (idx == -1) {
418 qDebug("MplayerProcess::parseLine: audio %d doesn't exist, adding it", ID);
419
420 audio_info_changed = true;
421 if ( t == "NAME" )
422 audios.addName(ID, lang);
423 else
424 audios.addLang(ID, lang);
425 } else {
426 qDebug("MplayerProcess::parseLine: audio %d exists, modifing it", ID);
427
428 if (t == "NAME") {
429 //qDebug("MplayerProcess::parseLine: name of audio %d: %s", ID, audios.itemAt(idx).name().toUtf8().constData());
430 if (audios.itemAt(idx).name() != lang) {
431 audio_info_changed = true;
432 audios.addName(ID, lang);
433 }
434 } else {
435 //qDebug("MplayerProcess::parseLine: language of audio %d: %s", ID, audios.itemAt(idx).lang().toUtf8().constData());
436 if (audios.itemAt(idx).lang() != lang) {
437 audio_info_changed = true;
438 audios.addLang(ID, lang);
439 }
440 }
441 }
442 }
443#endif
444
445#if DVDNAV_SUPPORT
446 if (rx_dvdnav_switch_title.indexIn(line) > -1) {
447 int title = rx_dvdnav_switch_title.cap(1).toInt();
448 qDebug("MplayerProcess::parseLine: dvd title: %d", title);
449 emit receivedDVDTitle(title);
450 }
451 if (rx_dvdnav_length.indexIn(line) > -1) {
452 double length = rx_dvdnav_length.cap(1).toDouble();
453 qDebug("MplayerProcess::parseLine: length: %f", length);
454 if (length != md.duration) {
455 md.duration = length;
456 emit receivedDuration(length);
457 }
458 }
459 if (rx_dvdnav_title_is_menu.indexIn(line) > -1) {
460 emit receivedTitleIsMenu();
461 }
462 if (rx_dvdnav_title_is_movie.indexIn(line) > -1) {
463 emit receivedTitleIsMovie();
464 }
465#endif
466
467 // The following things are not sent when the file has started to play
468 // (or if sent, smplayer will ignore anyway...)
469 // So not process anymore, if video is playing to save some time
470 if (notified_mplayer_is_running) {
471 return;
472 }
473
474 if ( (mplayer_svn == -1) && ((line.startsWith("MPlayer ")) || (line.startsWith("MPlayer2 "))) ) {
475 mplayer_svn = MplayerVersion::mplayerVersion(line);
476 qDebug("MplayerProcess::parseLine: MPlayer SVN: %d", mplayer_svn);
477 if (mplayer_svn <= 0) {
478 qWarning("MplayerProcess::parseLine: couldn't parse mplayer version!");
479 emit failedToParseMplayerVersion(line);
480 }
481 }
482
483#if !NOTIFY_SUB_CHANGES
484 // Subtitles
485 if (rx_subtitle.indexIn(line) > -1) {
486 md.subs.parse(line);
487 }
488 else
489 if (rx_sid.indexIn(line) > -1) {
490 md.subs.parse(line);
491 }
492 else
493 if (rx_subtitle_file.indexIn(line) > -1) {
494 md.subs.parse(line);
495 }
496#endif
497 // AO
498 if (rx_ao.indexIn(line) > -1) {
499 emit receivedAO( rx_ao.cap(1) );
500 }
501 else
502
503#if !NOTIFY_AUDIO_CHANGES
504 // Matroska audio
505 if (rx_audio_mat.indexIn(line) > -1) {
506 int ID = rx_audio_mat.cap(1).toInt();
507 QString lang = rx_audio_mat.cap(3);
508 QString t = rx_audio_mat.cap(2);
509 qDebug("MplayerProcess::parseLine: Audio: ID: %d, Lang: '%s' Type: '%s'",
510 ID, lang.toUtf8().data(), t.toUtf8().data());
511
512 if ( t == "NAME" )
513 md.audios.addName(ID, lang);
514 else
515 md.audios.addLang(ID, lang);
516 }
517 else
518#endif
519
520#if PROGRAM_SWITCH
521 // Program
522 if (rx_program.indexIn(line) > -1) {
523 int ID = rx_program.cap(1).toInt();
524 qDebug("MplayerProcess::parseLine: Program: ID: %d", ID);
525 md.programs.addID( ID );
526 }
527 else
528#endif
529
530 // Video tracks
531 if (rx_video.indexIn(line) > -1) {
532 int ID = rx_video.cap(1).toInt();
533 QString lang = rx_video.cap(3);
534 QString t = rx_video.cap(2);
535 qDebug("MplayerProcess::parseLine: Video: ID: %d, Lang: '%s' Type: '%s'",
536 ID, lang.toUtf8().data(), t.toUtf8().data());
537
538 if ( t == "NAME" )
539 md.videos.addName(ID, lang);
540 else
541 md.videos.addLang(ID, lang);
542 }
543 else
544
545 // Matroshka chapters
546 if (rx_mkvchapters.indexIn(line)!=-1) {
547 int c = rx_mkvchapters.cap(1).toInt();
548 qDebug("MplayerProcess::parseLine: mkv chapters: %d", c);
549 if ((c+1) > md.n_chapters) {
550 md.n_chapters = c+1;
551 qDebug("MplayerProcess::parseLine: chapters set to: %d", md.n_chapters);
552 }
553 }
554 else
555 // Chapter info
556 if (rx_chapters.indexIn(line) > -1) {
557 int const chap_ID = rx_chapters.cap(1).toInt();
558 QString const chap_type = rx_chapters.cap(2);
559 QString const chap_value = rx_chapters.cap(3);
560 double const chap_value_d = chap_value.toDouble();
561
562 if(!chap_type.compare("START"))
563 {
564 md.chapters.addStart(chap_ID, chap_value_d/1000);
565 qDebug("MplayerProcess::parseLine: Chapter (ID: %d) starts at: %g",chap_ID, chap_value_d/1000);
566 }
567 else if(!chap_type.compare("END"))
568 {
569 md.chapters.addEnd(chap_ID, chap_value_d/1000);
570 qDebug("MplayerProcess::parseLine: Chapter (ID: %d) ends at: %g",chap_ID, chap_value_d/1000);
571 }
572 else if(!chap_type.compare("NAME"))
573 {
574 md.chapters.addName(chap_ID, chap_value);
575 qDebug("MplayerProcess::parseLine: Chapter (ID: %d) name: %s",chap_ID, chap_value.toUtf8().data());
576 }
577 }
578 else
579
580 // VCD titles
581 if (rx_vcd.indexIn(line) > -1 ) {
582 int ID = rx_vcd.cap(1).toInt();
583 QString length = rx_vcd.cap(2);
584 //md.titles.addID( ID );
585 md.titles.addName( ID, length );
586 }
587 else
588
589 // Audio CD titles
590 if (rx_cdda.indexIn(line) > -1 ) {
591 int ID = rx_cdda.cap(1).toInt();
592 QString length = rx_cdda.cap(2);
593 double duration = 0;
594 QRegExp r("(\\d+):(\\d+):(\\d+)");
595 if ( r.indexIn(length) > -1 ) {
596 duration = r.cap(1).toInt() * 60;
597 duration += r.cap(2).toInt();
598 }
599 md.titles.addID( ID );
600 /*
601 QString name = QString::number(ID) + " (" + length + ")";
602 md.titles.addName( ID, name );
603 */
604 md.titles.addDuration( ID, duration );
605 }
606 else
607
608 // DVD titles
609 if (rx_title.indexIn(line) > -1) {
610 int ID = rx_title.cap(1).toInt();
611 QString t = rx_title.cap(2);
612
613 if (t=="LENGTH") {
614 double length = rx_title.cap(3).toDouble();
615 qDebug("MplayerProcess::parseLine: Title: ID: %d, Length: '%f'", ID, length);
616 md.titles.addDuration(ID, length);
617 }
618 else
619 if (t=="CHAPTERS") {
620 int chapters = rx_title.cap(3).toInt();
621 qDebug("MplayerProcess::parseLine: Title: ID: %d, Chapters: '%d'", ID, chapters);
622 md.titles.addChapters(ID, chapters);
623 }
624 else
625 if (t=="ANGLES") {
626 int angles = rx_title.cap(3).toInt();
627 qDebug("MplayerProcess::parseLine: Title: ID: %d, Angles: '%d'", ID, angles);
628 md.titles.addAngles(ID, angles);
629 }
630 }
631 else
632
633 // Catch cache messages
634 if (rx_cache.indexIn(line) > -1) {
635 emit receivedCacheMessage(line);
636 }
637 else
638
639 // Creating index
640 if (rx_create_index.indexIn(line) > -1) {
641 emit receivedCreatingIndex(line);
642 }
643 else
644
645 // Catch connecting message
646 if (rx_connecting.indexIn(line) > -1) {
647 emit receivedConnectingToMessage(line);
648 }
649 else
650
651 // Catch resolving message
652 if (rx_resolving.indexIn(line) > -1) {
653 emit receivedResolvingMessage(line);
654 }
655 else
656
657 // Aspect ratio for old versions of mplayer
658 if (rx_aspect2.indexIn(line) > -1) {
659 md.video_aspect = rx_aspect2.cap(1).toDouble();
660 qDebug("MplayerProcess::parseLine: md.video_aspect set to %f", md.video_aspect);
661 }
662 else
663
664 // Clip info
665
666 //QString::trimmed() is used for removing leading and trailing whitespaces
667 //Some .mp3 files contain tags with starting and ending whitespaces
668 //Unfortunately MPlayer gives us leading and trailing whitespaces, Winamp for example doesn't show them
669
670 // Name
671 if (rx_clip_name.indexIn(line) > -1) {
672 QString s = rx_clip_name.cap(2).trimmed();
673 qDebug("MplayerProcess::parseLine: clip_name: '%s'", s.toUtf8().data());
674 md.clip_name = s;
675 }
676 else
677
678 // Artist
679 if (rx_clip_artist.indexIn(line) > -1) {
680 QString s = rx_clip_artist.cap(1).trimmed();
681 qDebug("MplayerProcess::parseLine: clip_artist: '%s'", s.toUtf8().data());
682 md.clip_artist = s;
683 }
684 else
685
686 // Author
687 if (rx_clip_author.indexIn(line) > -1) {
688 QString s = rx_clip_author.cap(1).trimmed();
689 qDebug("MplayerProcess::parseLine: clip_author: '%s'", s.toUtf8().data());
690 md.clip_author = s;
691 }
692 else
693
694 // Album
695 if (rx_clip_album.indexIn(line) > -1) {
696 QString s = rx_clip_album.cap(1).trimmed();
697 qDebug("MplayerProcess::parseLine: clip_album: '%s'", s.toUtf8().data());
698 md.clip_album = s;
699 }
700 else
701
702 // Genre
703 if (rx_clip_genre.indexIn(line) > -1) {
704 QString s = rx_clip_genre.cap(1).trimmed();
705 qDebug("MplayerProcess::parseLine: clip_genre: '%s'", s.toUtf8().data());
706 md.clip_genre = s;
707 }
708 else
709
710 // Date
711 if (rx_clip_date.indexIn(line) > -1) {
712 QString s = rx_clip_date.cap(2).trimmed();
713 qDebug("MplayerProcess::parseLine: clip_date: '%s'", s.toUtf8().data());
714 md.clip_date = s;
715 }
716 else
717
718 // Track
719 if (rx_clip_track.indexIn(line) > -1) {
720 QString s = rx_clip_track.cap(1).trimmed();
721 qDebug("MplayerProcess::parseLine: clip_track: '%s'", s.toUtf8().data());
722 md.clip_track = s;
723 }
724 else
725
726 // Copyright
727 if (rx_clip_copyright.indexIn(line) > -1) {
728 QString s = rx_clip_copyright.cap(1).trimmed();
729 qDebug("MplayerProcess::parseLine: clip_copyright: '%s'", s.toUtf8().data());
730 md.clip_copyright = s;
731 }
732 else
733
734 // Comment
735 if (rx_clip_comment.indexIn(line) > -1) {
736 QString s = rx_clip_comment.cap(1).trimmed();
737 qDebug("MplayerProcess::parseLine: clip_comment: '%s'", s.toUtf8().data());
738 md.clip_comment = s;
739 }
740 else
741
742 // Software
743 if (rx_clip_software.indexIn(line) > -1) {
744 QString s = rx_clip_software.cap(1).trimmed();
745 qDebug("MplayerProcess::parseLine: clip_software: '%s'", s.toUtf8().data());
746 md.clip_software = s;
747 }
748 else
749
750 if (rx_fontcache.indexIn(line) > -1) {
751 //qDebug("MplayerProcess::parseLine: updating font cache");
752 emit receivedUpdatingFontCache();
753 }
754 else
755 if (rx_scanning_font.indexIn(line) > -1) {
756 emit receivedScanningFont(line);
757 }
758 else
759
760 // Catch starting message
761 /*
762 pos = rx_play.indexIn(line);
763 if (pos > -1) {
764 emit mplayerFullyLoaded();
765 }
766 */
767
768 //Generic things
769 if (rx.indexIn(line) > -1) {
770 tag = rx.cap(1);
771 value = rx.cap(2);
772 //qDebug("MplayerProcess::parseLine: tag: %s, value: %s", tag.toUtf8().data(), value.toUtf8().data());
773
774#if !NOTIFY_AUDIO_CHANGES
775 // Generic audio
776 if (tag == "ID_AUDIO_ID") {
777 int ID = value.toInt();
778 qDebug("MplayerProcess::parseLine: ID_AUDIO_ID: %d", ID);
779 md.audios.addID( ID );
780 }
781 else
782#endif
783
784 // Video
785 if (tag == "ID_VIDEO_ID") {
786 int ID = value.toInt();
787 qDebug("MplayerProcess::parseLine: ID_VIDEO_ID: %d", ID);
788 md.videos.addID( ID );
789 }
790 else
791 if (tag == "ID_LENGTH") {
792 md.duration = value.toDouble();
793 qDebug("MplayerProcess::parseLine: md.duration set to %f", md.duration);
794 }
795 else
796 if (tag == "ID_VIDEO_WIDTH") {
797 md.video_width = value.toInt();
798 qDebug("MplayerProcess::parseLine: md.video_width set to %d", md.video_width);
799 }
800 else
801 if (tag == "ID_VIDEO_HEIGHT") {
802 md.video_height = value.toInt();
803 qDebug("MplayerProcess::parseLine: md.video_height set to %d", md.video_height);
804 }
805 else
806 if (tag == "ID_VIDEO_ASPECT") {
807 md.video_aspect = value.toDouble();
808 if ( md.video_aspect == 0.0 ) {
809 // I hope width & height are already set.
810 md.video_aspect = (double) md.video_width / md.video_height;
811 }
812 qDebug("MplayerProcess::parseLine: md.video_aspect set to %f", md.video_aspect);
813 }
814 else
815 if (tag == "ID_DVD_DISC_ID") {
816 md.dvd_id = value;
817 qDebug("MplayerProcess::parseLine: md.dvd_id set to '%s'", md.dvd_id.toUtf8().data());
818 }
819 else
820 if (tag == "ID_DEMUXER") {
821 md.demuxer = value;
822 }
823 else
824 if (tag == "ID_VIDEO_FORMAT") {
825 md.video_format = value;
826 }
827 else
828 if (tag == "ID_AUDIO_FORMAT") {
829 md.audio_format = value;
830 }
831 else
832 if (tag == "ID_VIDEO_BITRATE") {
833 md.video_bitrate = value.toInt();
834 }
835 else
836 if (tag == "ID_VIDEO_FPS") {
837 md.video_fps = value;
838 }
839 else
840 if (tag == "ID_AUDIO_BITRATE") {
841 md.audio_bitrate = value.toInt();
842 }
843 else
844 if (tag == "ID_AUDIO_RATE") {
845 md.audio_rate = value.toInt();
846 }
847 else
848 if (tag == "ID_AUDIO_NCH") {
849 md.audio_nch = value.toInt();
850 }
851 else
852 if (tag == "ID_VIDEO_CODEC") {
853 md.video_codec = value;
854 }
855 else
856 if (tag == "ID_AUDIO_CODEC") {
857 md.audio_codec = value;
858 }
859 else
860 if (tag == "ID_CHAPTERS") {
861 md.n_chapters = value.toInt();
862 #ifdef TOO_CHAPTERS_WORKAROUND
863 if (md.n_chapters > 1000) {
864 qDebug("MplayerProcess::parseLine: warning too many chapters: %d", md.n_chapters);
865 qDebug(" chapters will be ignored");
866 md.n_chapters = 0;
867 }
868 #endif
869 }
870 else
871 if (tag == "ID_DVD_CURRENT_TITLE") {
872 dvd_current_title = value.toInt();
873 }
874 }
875 }
876}
877
878// Called when the process is finished
879void MplayerProcess::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
880 qDebug("MplayerProcess::processFinished: exitCode: %d, status: %d", exitCode, (int) exitStatus);
881 // Send this signal before the endoffile one, otherwise
882 // the playlist will start to play next file before all
883 // objects are notified that the process has exited.
884 emit processExited();
885 if (received_end_of_file) emit receivedEndOfFile();
886}
887
888void MplayerProcess::gotError(QProcess::ProcessError error) {
889 qDebug("MplayerProcess::gotError: %d", (int) error);
890}
891
892#ifdef Q_OS_OS2
893PipeThread::PipeThread(const QByteArray t, const HPIPE pipe) {
894 text = t;
895 hpipe = pipe;
896}
897
898PipeThread::~PipeThread() {
899}
900
901void PipeThread::run() {
902 ULONG cbActual;
903 APIRET rc = NO_ERROR;
904
905 rc = DosConnectNPipe( hpipe );
906 if (rc != NO_ERROR)
907 return;
908
909// qDebug("pipe connected");
910 DosWrite( hpipe, text.data(), strlen( text.data() ), &cbActual );
911
912 // Wait for ACK
913 DosRead( hpipe, &cbActual, sizeof( ULONG ), &cbActual );
914 DosDisConnectNPipe( hpipe );
915 return;
916}
917#endif
918
919#include "moc_mplayerprocess.cpp"
Note: See TracBrowser for help on using the repository browser.