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

Last change on this file since 143 was 142, checked in by Silvan Scherrer, 12 years ago

SMPlayer: update trunk to 0.8.5

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