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

Last change on this file since 102 was 93, checked in by Silvan Scherrer, 15 years ago

smplayer: 0.6.9

File size: 25.7 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2010 Ricardo Villalba <rvm@escomposlinux.org>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "mplayerprocess.h"
20#include <QRegExp>
21#include <QStringList>
22#include <QApplication>
23
24#include "global.h"
25#include "preferences.h"
26#include "mplayerversion.h"
27#include "colorutils.h"
28
29using namespace Global;
30
31MplayerProcess::MplayerProcess(QObject * parent) : MyProcess(parent)
32{
33#if NOTIFY_SUB_CHANGES
34 qRegisterMetaType<SubTracks>("SubTracks");
35#endif
36
37#if NOTIFY_AUDIO_CHANGES
38 qRegisterMetaType<Tracks>("Tracks");
39#endif
40
41 connect( this, SIGNAL(lineAvailable(QByteArray)),
42 this, SLOT(parseLine(QByteArray)) );
43
44 connect( this, SIGNAL(finished(int,QProcess::ExitStatus)),
45 this, SLOT(processFinished(int,QProcess::ExitStatus)) );
46
47 connect( this, SIGNAL(error(QProcess::ProcessError)),
48 this, SLOT(gotError(QProcess::ProcessError)) );
49
50 notified_mplayer_is_running = false;
51 last_sub_id = -1;
52 mplayer_svn = -1; // Not found yet
53}
54
55MplayerProcess::~MplayerProcess() {
56}
57
58bool MplayerProcess::start() {
59 md.reset();
60 notified_mplayer_is_running = false;
61 last_sub_id = -1;
62 mplayer_svn = -1; // Not found yet
63 received_end_of_file = false;
64
65#if NOTIFY_SUB_CHANGES
66 subs.clear();
67 subtitle_info_received = false;
68 subtitle_info_changed = false;
69#endif
70
71#if NOTIFY_AUDIO_CHANGES
72 audios.clear();
73 audio_info_changed = false;
74#endif
75
76#if GENERIC_CHAPTER_SUPPORT
77 dvd_current_title = -1;
78#endif
79
80 MyProcess::start();
81
82#if !defined(Q_OS_OS2)
83 return waitForStarted();
84#else
85 bool r = waitForStarted();
86 if (r) {
87 pidMP = QProcess::pid();
88 qDebug("MPlayer PID %i", pidMP);
89 MPpipeOpen();
90 }
91 return r;
92#endif
93}
94
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#ifdef Q_OS_OS2
113void MplayerProcess::MPpipeOpen()
114{
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{
122 DosClose( hpipe );
123}
124
125void MplayerProcess::MPpipeWrite( const QByteArray text )
126{
127 // MPlayer quitted ?
128 if ( !isRunning() )
129 return;
130
131// as things could hang when pipe communication is done direct here, i do a seperate thread for it */
132 pipeThread = new PipeThread(text, hpipe);
133
134 pipeThread->start();
135 while (!pipeThread->isRunning() && !pipeThread->isFinished()) {
136 qDebug("we spleep");
137 DosSleep(10);
138 }
139 if (!pipeThread->wait(2000)) {
140 pipeThread->terminate();
141 qDebug("pipe communication terminated");
142 }
143 delete pipeThread;
144
145}
146
147#endif
148
149static QRegExp rx_av("^[AV]: *([0-9,:.-]+)");
150static QRegExp rx_frame("^[AV]:.* (\\d+)\\/.\\d+");// [0-9,.]+");
151static QRegExp rx("^(.*)=(.*)");
152#if !NOTIFY_AUDIO_CHANGES
153static QRegExp rx_audio_mat("^ID_AID_(\\d+)_(LANG|NAME)=(.*)");
154#endif
155static QRegExp rx_video("^ID_VID_(\\d+)_(LANG|NAME)=(.*)");
156static QRegExp rx_title("^ID_DVD_TITLE_(\\d+)_(LENGTH|CHAPTERS|ANGLES)=(.*)");
157static QRegExp rx_winresolution("^VO: \\[(.*)\\] (\\d+)x(\\d+) => (\\d+)x(\\d+)");
158static QRegExp rx_ao("^AO: \\[(.*)\\]");
159static QRegExp rx_paused("^ID_PAUSED");
160#if !CHECK_VIDEO_CODEC_FOR_NO_VIDEO
161static QRegExp rx_novideo("^Video: no video");
162#endif
163static QRegExp rx_cache("^Cache fill:.*");
164static QRegExp rx_create_index("^Generating Index:.*");
165static QRegExp rx_play("^Starting playback...");
166static QRegExp rx_connecting("^Connecting to .*");
167static QRegExp rx_resolving("^Resolving .*");
168static QRegExp rx_screenshot("^\\*\\*\\* screenshot '(.*)'");
169static QRegExp rx_endoffile("^Exiting... \\(End of file\\)|^ID_EXIT=EOF");
170static QRegExp rx_mkvchapters("\\[mkv\\] Chapter (\\d+) from");
171static QRegExp rx_aspect2("^Movie-Aspect is ([0-9,.]+):1");
172static QRegExp rx_fontcache("^\\[ass\\] Updating font cache|^\\[ass\\] Init");
173static QRegExp rx_scanning_font("Scanning file");
174#if DVDNAV_SUPPORT
175static QRegExp rx_dvdnav_switch_title("^DVDNAV, switched to title: (\\d+)");
176static QRegExp rx_dvdnav_length("^ANS_length=(.*)");
177static QRegExp rx_dvdnav_title_is_menu("^DVDNAV_TITLE_IS_MENU");
178static QRegExp rx_dvdnav_title_is_movie("^DVDNAV_TITLE_IS_MOVIE");
179#endif
180
181// VCD
182static QRegExp rx_vcd("^ID_VCD_TRACK_(\\d+)_MSF=(.*)");
183
184// Audio CD
185static QRegExp rx_cdda("^ID_CDDA_TRACK_(\\d+)_MSF=(.*)");
186
187//Subtitles
188static QRegExp rx_subtitle("^ID_(SUBTITLE|FILE_SUB|VOBSUB)_ID=(\\d+)");
189static QRegExp rx_sid("^ID_(SID|VSID)_(\\d+)_(LANG|NAME)=(.*)");
190static QRegExp rx_subtitle_file("^ID_FILE_SUB_FILENAME=(.*)");
191
192// Audio
193#if NOTIFY_AUDIO_CHANGES
194static QRegExp rx_audio("^ID_AUDIO_ID=(\\d+)");
195static QRegExp rx_audio_info("^ID_AID_(\\d+)_(LANG|NAME)=(.*)");
196#endif
197
198#if PROGRAM_SWITCH
199static QRegExp rx_program("^PROGRAM_ID=(\\d+)");
200#endif
201
202//Clip info
203static QRegExp rx_clip_name("^ (name|title): (.*)", Qt::CaseInsensitive);
204static QRegExp rx_clip_artist("^ artist: (.*)", Qt::CaseInsensitive);
205static QRegExp rx_clip_author("^ author: (.*)", Qt::CaseInsensitive);
206static QRegExp rx_clip_album("^ album: (.*)", Qt::CaseInsensitive);
207static QRegExp rx_clip_genre("^ genre: (.*)", Qt::CaseInsensitive);
208static QRegExp rx_clip_date("^ (creation date|year): (.*)", Qt::CaseInsensitive);
209static QRegExp rx_clip_track("^ track: (.*)", Qt::CaseInsensitive);
210static QRegExp rx_clip_copyright("^ copyright: (.*)", Qt::CaseInsensitive);
211static QRegExp rx_clip_comment("^ comment: (.*)", Qt::CaseInsensitive);
212static QRegExp rx_clip_software("^ software: (.*)", Qt::CaseInsensitive);
213
214static QRegExp rx_stream_title("^.* StreamTitle='(.*)';");
215static QRegExp rx_stream_title_and_url("^.* StreamTitle='(.*)';StreamUrl='(.*)';");
216
217
218void MplayerProcess::parseLine(QByteArray ba) {
219 //qDebug("MplayerProcess::parseLine: '%s'", ba.data() );
220
221 QString tag;
222 QString value;
223
224#if COLOR_OUTPUT_SUPPORT
225 QString line = ColorUtils::stripColorsTags(QString::fromLocal8Bit(ba));
226#else
227 QString line = QString::fromLocal8Bit(ba);
228#endif
229
230 // Parse A: V: line
231 //qDebug("%s", line.toUtf8().data());
232 if (rx_av.indexIn(line) > -1) {
233 double sec = rx_av.cap(1).toDouble();
234 //qDebug("cap(1): '%s'", rx_av.cap(1).toUtf8().data() );
235 //qDebug("sec: %f", sec);
236
237#if NOTIFY_SUB_CHANGES
238 if (notified_mplayer_is_running) {
239 if (subtitle_info_changed) {
240 qDebug("MplayerProcess::parseLine: subtitle_info_changed");
241 subtitle_info_changed = false;
242 subtitle_info_received = false;
243 emit subtitleInfoChanged(subs);
244 }
245 if (subtitle_info_received) {
246 qDebug("MplayerProcess::parseLine: subtitle_info_received");
247 subtitle_info_received = false;
248 emit subtitleInfoReceivedAgain(subs);
249 }
250 }
251#endif
252
253#if NOTIFY_AUDIO_CHANGES
254 if (notified_mplayer_is_running) {
255 if (audio_info_changed) {
256 qDebug("MplayerProcess::parseLine: audio_info_changed");
257 audio_info_changed = false;
258 emit audioInfoChanged(audios);
259 }
260 }
261#endif
262
263 if (!notified_mplayer_is_running) {
264 qDebug("MplayerProcess::parseLine: starting sec: %f", sec);
265#if GENERIC_CHAPTER_SUPPORT
266 if ( (md.chapters <= 0) && (dvd_current_title > 0) &&
267 (md.titles.find(dvd_current_title) != -1) )
268 {
269 int idx = md.titles.find(dvd_current_title);
270 md.chapters = md.titles.itemAt(idx).chapters();
271 qDebug("MplayerProcess::parseLine: setting chapters to %d", md.chapters);
272 }
273#endif
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 ")) ) {
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 GENERIC_CHAPTER_SUPPORT
550 if ((c+1) > md.chapters) {
551 md.chapters = c+1;
552 qDebug("MplayerProcess::parseLine: chapters set to: %d", md.chapters);
553 }
554#else
555 if ((c+1) > md.mkv_chapters) {
556 md.mkv_chapters = c+1;
557 qDebug("MplayerProcess::parseLine: mkv_chapters set to: %d", md.mkv_chapters);
558 }
559#endif
560 }
561 else
562
563 // VCD titles
564 if (rx_vcd.indexIn(line) > -1 ) {
565 int ID = rx_vcd.cap(1).toInt();
566 QString length = rx_vcd.cap(2);
567 //md.titles.addID( ID );
568 md.titles.addName( ID, length );
569 }
570 else
571
572 // Audio CD titles
573 if (rx_cdda.indexIn(line) > -1 ) {
574 int ID = rx_cdda.cap(1).toInt();
575 QString length = rx_cdda.cap(2);
576 double duration = 0;
577 QRegExp r("(\\d+):(\\d+):(\\d+)");
578 if ( r.indexIn(length) > -1 ) {
579 duration = r.cap(1).toInt() * 60;
580 duration += r.cap(2).toInt();
581 }
582 md.titles.addID( ID );
583 /*
584 QString name = QString::number(ID) + " (" + length + ")";
585 md.titles.addName( ID, name );
586 */
587 md.titles.addDuration( ID, duration );
588 }
589 else
590
591 // DVD titles
592 if (rx_title.indexIn(line) > -1) {
593 int ID = rx_title.cap(1).toInt();
594 QString t = rx_title.cap(2);
595
596 if (t=="LENGTH") {
597 double length = rx_title.cap(3).toDouble();
598 qDebug("MplayerProcess::parseLine: Title: ID: %d, Length: '%f'", ID, length);
599 md.titles.addDuration(ID, length);
600 }
601 else
602 if (t=="CHAPTERS") {
603 int chapters = rx_title.cap(3).toInt();
604 qDebug("MplayerProcess::parseLine: Title: ID: %d, Chapters: '%d'", ID, chapters);
605 md.titles.addChapters(ID, chapters);
606 }
607 else
608 if (t=="ANGLES") {
609 int angles = rx_title.cap(3).toInt();
610 qDebug("MplayerProcess::parseLine: Title: ID: %d, Angles: '%d'", ID, angles);
611 md.titles.addAngles(ID, angles);
612 }
613 }
614 else
615
616 // Catch cache messages
617 if (rx_cache.indexIn(line) > -1) {
618 emit receivedCacheMessage(line);
619 }
620 else
621
622 // Creating index
623 if (rx_create_index.indexIn(line) > -1) {
624 emit receivedCreatingIndex(line);
625 }
626 else
627
628 // Catch connecting message
629 if (rx_connecting.indexIn(line) > -1) {
630 emit receivedConnectingToMessage(line);
631 }
632 else
633
634 // Catch resolving message
635 if (rx_resolving.indexIn(line) > -1) {
636 emit receivedResolvingMessage(line);
637 }
638 else
639
640 // Aspect ratio for old versions of mplayer
641 if (rx_aspect2.indexIn(line) > -1) {
642 md.video_aspect = rx_aspect2.cap(1).toDouble();
643 qDebug("MplayerProcess::parseLine: md.video_aspect set to %f", md.video_aspect);
644 }
645 else
646
647 // Clip info
648
649 //QString::trimmed() is used for removing leading and trailing whitespaces
650 //Some .mp3 files contain tags with starting and ending whitespaces
651 //Unfortunately MPlayer gives us leading and trailing whitespaces, Winamp for example doesn't show them
652
653 // Name
654 if (rx_clip_name.indexIn(line) > -1) {
655 QString s = rx_clip_name.cap(2).trimmed();
656 qDebug("MplayerProcess::parseLine: clip_name: '%s'", s.toUtf8().data());
657 md.clip_name = s;
658 }
659 else
660
661 // Artist
662 if (rx_clip_artist.indexIn(line) > -1) {
663 QString s = rx_clip_artist.cap(1).trimmed();
664 qDebug("MplayerProcess::parseLine: clip_artist: '%s'", s.toUtf8().data());
665 md.clip_artist = s;
666 }
667 else
668
669 // Author
670 if (rx_clip_author.indexIn(line) > -1) {
671 QString s = rx_clip_author.cap(1).trimmed();
672 qDebug("MplayerProcess::parseLine: clip_author: '%s'", s.toUtf8().data());
673 md.clip_author = s;
674 }
675 else
676
677 // Album
678 if (rx_clip_album.indexIn(line) > -1) {
679 QString s = rx_clip_album.cap(1).trimmed();
680 qDebug("MplayerProcess::parseLine: clip_album: '%s'", s.toUtf8().data());
681 md.clip_album = s;
682 }
683 else
684
685 // Genre
686 if (rx_clip_genre.indexIn(line) > -1) {
687 QString s = rx_clip_genre.cap(1).trimmed();
688 qDebug("MplayerProcess::parseLine: clip_genre: '%s'", s.toUtf8().data());
689 md.clip_genre = s;
690 }
691 else
692
693 // Date
694 if (rx_clip_date.indexIn(line) > -1) {
695 QString s = rx_clip_date.cap(2).trimmed();
696 qDebug("MplayerProcess::parseLine: clip_date: '%s'", s.toUtf8().data());
697 md.clip_date = s;
698 }
699 else
700
701 // Track
702 if (rx_clip_track.indexIn(line) > -1) {
703 QString s = rx_clip_track.cap(1).trimmed();
704 qDebug("MplayerProcess::parseLine: clip_track: '%s'", s.toUtf8().data());
705 md.clip_track = s;
706 }
707 else
708
709 // Copyright
710 if (rx_clip_copyright.indexIn(line) > -1) {
711 QString s = rx_clip_copyright.cap(1).trimmed();
712 qDebug("MplayerProcess::parseLine: clip_copyright: '%s'", s.toUtf8().data());
713 md.clip_copyright = s;
714 }
715 else
716
717 // Comment
718 if (rx_clip_comment.indexIn(line) > -1) {
719 QString s = rx_clip_comment.cap(1).trimmed();
720 qDebug("MplayerProcess::parseLine: clip_comment: '%s'", s.toUtf8().data());
721 md.clip_comment = s;
722 }
723 else
724
725 // Software
726 if (rx_clip_software.indexIn(line) > -1) {
727 QString s = rx_clip_software.cap(1).trimmed();
728 qDebug("MplayerProcess::parseLine: clip_software: '%s'", s.toUtf8().data());
729 md.clip_software = s;
730 }
731 else
732
733 if (rx_fontcache.indexIn(line) > -1) {
734 //qDebug("MplayerProcess::parseLine: updating font cache");
735 emit receivedUpdatingFontCache();
736 }
737 else
738 if (rx_scanning_font.indexIn(line) > -1) {
739 emit receivedScanningFont(line);
740 }
741 else
742
743 // Catch starting message
744 /*
745 pos = rx_play.indexIn(line);
746 if (pos > -1) {
747 emit mplayerFullyLoaded();
748 }
749 */
750
751 //Generic things
752 if (rx.indexIn(line) > -1) {
753 tag = rx.cap(1);
754 value = rx.cap(2);
755 //qDebug("MplayerProcess::parseLine: tag: %s, value: %s", tag.toUtf8().data(), value.toUtf8().data());
756
757#if !NOTIFY_AUDIO_CHANGES
758 // Generic audio
759 if (tag == "ID_AUDIO_ID") {
760 int ID = value.toInt();
761 qDebug("MplayerProcess::parseLine: ID_AUDIO_ID: %d", ID);
762 md.audios.addID( ID );
763 }
764 else
765#endif
766
767 // Video
768 if (tag == "ID_VIDEO_ID") {
769 int ID = value.toInt();
770 qDebug("MplayerProcess::parseLine: ID_VIDEO_ID: %d", ID);
771 md.videos.addID( ID );
772 }
773 else
774 if (tag == "ID_LENGTH") {
775 md.duration = value.toDouble();
776 qDebug("MplayerProcess::parseLine: md.duration set to %f", md.duration);
777 }
778 else
779 if (tag == "ID_VIDEO_WIDTH") {
780 md.video_width = value.toInt();
781 qDebug("MplayerProcess::parseLine: md.video_width set to %d", md.video_width);
782 }
783 else
784 if (tag == "ID_VIDEO_HEIGHT") {
785 md.video_height = value.toInt();
786 qDebug("MplayerProcess::parseLine: md.video_height set to %d", md.video_height);
787 }
788 else
789 if (tag == "ID_VIDEO_ASPECT") {
790 md.video_aspect = value.toDouble();
791 if ( md.video_aspect == 0.0 ) {
792 // I hope width & height are already set.
793 md.video_aspect = (double) md.video_width / md.video_height;
794 }
795 qDebug("MplayerProcess::parseLine: md.video_aspect set to %f", md.video_aspect);
796 }
797 else
798 if (tag == "ID_DVD_DISC_ID") {
799 md.dvd_id = value;
800 qDebug("MplayerProcess::parseLine: md.dvd_id set to '%s'", md.dvd_id.toUtf8().data());
801 }
802 else
803 if (tag == "ID_DEMUXER") {
804 md.demuxer = value;
805 }
806 else
807 if (tag == "ID_VIDEO_FORMAT") {
808 md.video_format = value;
809 }
810 else
811 if (tag == "ID_AUDIO_FORMAT") {
812 md.audio_format = value;
813 }
814 else
815 if (tag == "ID_VIDEO_BITRATE") {
816 md.video_bitrate = value.toInt();
817 }
818 else
819 if (tag == "ID_VIDEO_FPS") {
820 md.video_fps = value;
821 }
822 else
823 if (tag == "ID_AUDIO_BITRATE") {
824 md.audio_bitrate = value.toInt();
825 }
826 else
827 if (tag == "ID_AUDIO_RATE") {
828 md.audio_rate = value.toInt();
829 }
830 else
831 if (tag == "ID_AUDIO_NCH") {
832 md.audio_nch = value.toInt();
833 }
834 else
835 if (tag == "ID_VIDEO_CODEC") {
836 md.video_codec = value;
837 }
838 else
839 if (tag == "ID_AUDIO_CODEC") {
840 md.audio_codec = value;
841 }
842#if GENERIC_CHAPTER_SUPPORT
843 else
844 if (tag == "ID_CHAPTERS") {
845 md.chapters = value.toInt();
846 }
847 else
848 if (tag == "ID_DVD_CURRENT_TITLE") {
849 dvd_current_title = value.toInt();
850 }
851#endif
852 }
853 }
854}
855
856// Called when the process is finished
857void MplayerProcess::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
858 qDebug("MplayerProcess::processFinished: exitCode: %d, status: %d", exitCode, (int) exitStatus);
859 // Send this signal before the endoffile one, otherwise
860 // the playlist will start to play next file before all
861 // objects are notified that the process has exited.
862 emit processExited();
863 if (received_end_of_file) emit receivedEndOfFile();
864}
865
866void MplayerProcess::gotError(QProcess::ProcessError error) {
867 qDebug("MplayerProcess::gotError: %d", (int) error);
868}
869
870#ifdef Q_OS_OS2
871PipeThread::PipeThread(const QByteArray t, const HPIPE pipe)
872{
873 text = t;
874 hpipe = pipe;
875}
876
877PipeThread::~PipeThread()
878{
879
880}
881
882void PipeThread::run()
883{
884 ULONG cbActual;
885 APIRET rc = NO_ERROR;
886
887 rc = DosConnectNPipe( hpipe );
888 if (rc != NO_ERROR)
889 return;
890
891 qDebug("pipe connected");
892 DosWrite( hpipe, text.data(), strlen( text.data() ), &cbActual );
893
894 // Wait for ACK
895 DosRead( hpipe, &cbActual, sizeof( ULONG ), &cbActual );
896 DosDisConnectNPipe( hpipe );
897 return;
898}
899
900#endif
901
902#include "moc_mplayerprocess.cpp"
Note: See TracBrowser for help on using the repository browser.