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

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

Smplayer: eol-style

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