~ubuntu-branches/debian/experimental/smplayer/experimental

« back to all changes in this revision

Viewing changes to src/mplayerprocess.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2009-01-03 17:08:06 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090103170806-eodntb2slv6g2pb6
Tags: 0.6.6-0ubuntu1
* The "just before FF" release.
* New upstream release.
* debian/control: Bumped Standards-Version to 3.8.0.
* debian/copyright: Changed (C) to © to fix Lintian warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  smplayer, GUI front-end for mplayer.
 
2
    Copyright (C) 2006-2008 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 "helper.h"
 
28
 
 
29
using namespace Global;
 
30
 
 
31
MplayerProcess::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
 
 
55
MplayerProcess::~MplayerProcess() {
 
56
}
 
57
 
 
58
bool 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
        return waitForStarted();
 
82
}
 
83
 
 
84
void MplayerProcess::writeToStdin(QString text) {
 
85
        if (isRunning()) {
 
86
                //qDebug("MplayerProcess::writeToStdin");
 
87
                write( text.toLocal8Bit() + "\n");
 
88
        } else {
 
89
                qWarning("MplayerProcess::writeToStdin: process not running");
 
90
        }
 
91
}
 
92
 
 
93
static QRegExp rx_av("^[AV]: *([0-9,:.-]+)");
 
94
static QRegExp rx_frame("^[AV]:.* (\\d+)\\/.\\d+");// [0-9,.]+");
 
95
static QRegExp rx("^(.*)=(.*)");
 
96
#if !NOTIFY_AUDIO_CHANGES
 
97
static QRegExp rx_audio_mat("^ID_AID_(\\d+)_(LANG|NAME)=(.*)");
 
98
#endif
 
99
static QRegExp rx_video("^ID_VID_(\\d+)_(LANG|NAME)=(.*)");
 
100
static QRegExp rx_title("^ID_DVD_TITLE_(\\d+)_(LENGTH|CHAPTERS|ANGLES)=(.*)");
 
101
static QRegExp rx_winresolution("^VO: \\[(.*)\\] (\\d+)x(\\d+) => (\\d+)x(\\d+)");
 
102
static QRegExp rx_ao("^AO: \\[(.*)\\]");
 
103
static QRegExp rx_paused("^ID_PAUSED");
 
104
#if !CHECK_VIDEO_CODEC_FOR_NO_VIDEO
 
105
static QRegExp rx_novideo("^Video: no video");
 
106
#endif
 
107
static QRegExp rx_cache("^Cache fill:.*");
 
108
static QRegExp rx_create_index("^Generating Index:.*");
 
109
static QRegExp rx_play("^Starting playback...");
 
110
static QRegExp rx_connecting("^Connecting to .*");
 
111
static QRegExp rx_resolving("^Resolving .*");
 
112
static QRegExp rx_screenshot("^\\*\\*\\* screenshot '(.*)'");
 
113
static QRegExp rx_endoffile("^Exiting... \\(End of file\\)|^ID_EXIT=EOF");
 
114
static QRegExp rx_mkvchapters("\\[mkv\\] Chapter (\\d+) from");
 
115
static QRegExp rx_aspect2("^Movie-Aspect is ([0-9,.]+):1");
 
116
static QRegExp rx_fontcache("^\\[ass\\] Updating font cache|^\\[ass\\] Init");
 
117
 
 
118
// VCD
 
119
static QRegExp rx_vcd("^ID_VCD_TRACK_(\\d+)_MSF=(.*)");
 
120
 
 
121
// Audio CD
 
122
static QRegExp rx_cdda("^ID_CDDA_TRACK_(\\d+)_MSF=(.*)");
 
123
 
 
124
 
 
125
//Subtitles
 
126
static QRegExp rx_subtitle("^ID_(SUBTITLE|FILE_SUB|VOBSUB)_ID=(\\d+)");
 
127
static QRegExp rx_sid("^ID_(SID|VSID)_(\\d+)_(LANG|NAME)=(.*)");
 
128
static QRegExp rx_subtitle_file("^ID_FILE_SUB_FILENAME=(.*)");
 
129
 
 
130
// Audio
 
131
#if NOTIFY_AUDIO_CHANGES
 
132
static QRegExp rx_audio("^ID_AUDIO_ID=(\\d+)");
 
133
static QRegExp rx_audio_info("^ID_AID_(\\d+)_(LANG|NAME)=(.*)");
 
134
#endif
 
135
 
 
136
//Clip info
 
137
static QRegExp rx_clip_name("^ (name|title): (.*)", Qt::CaseInsensitive);
 
138
static QRegExp rx_clip_artist("^ artist: (.*)", Qt::CaseInsensitive);
 
139
static QRegExp rx_clip_author("^ author: (.*)", Qt::CaseInsensitive);
 
140
static QRegExp rx_clip_album("^ album: (.*)", Qt::CaseInsensitive);
 
141
static QRegExp rx_clip_genre("^ genre: (.*)", Qt::CaseInsensitive);
 
142
static QRegExp rx_clip_date("^ (creation date|year): (.*)", Qt::CaseInsensitive);
 
143
static QRegExp rx_clip_track("^ track: (.*)", Qt::CaseInsensitive);
 
144
static QRegExp rx_clip_copyright("^ copyright: (.*)", Qt::CaseInsensitive);
 
145
static QRegExp rx_clip_comment("^ comment: (.*)", Qt::CaseInsensitive);
 
146
static QRegExp rx_clip_software("^ software: (.*)", Qt::CaseInsensitive);
 
147
 
 
148
static QRegExp rx_stream_title("^.* StreamTitle='(.*)';StreamUrl='(.*)';");
 
149
 
 
150
 
 
151
void MplayerProcess::parseLine(QByteArray ba) {
 
152
        //qDebug("MplayerProcess::parseLine: '%s'", ba.data() );
 
153
 
 
154
        QString tag;
 
155
        QString value;
 
156
 
 
157
#if COLOR_OUTPUT_SUPPORT
 
158
    QString line = Helper::stripColorsTags(QString::fromLocal8Bit(ba));
 
159
#else
 
160
        QString line = QString::fromLocal8Bit(ba);
 
161
#endif
 
162
 
 
163
        // Parse A: V: line
 
164
        //qDebug("%s", line.toUtf8().data());
 
165
    if (rx_av.indexIn(line) > -1) {
 
166
                double sec = rx_av.cap(1).toDouble();
 
167
                //qDebug("cap(1): '%s'", rx_av.cap(1).toUtf8().data() );
 
168
                //qDebug("sec: %f", sec);
 
169
 
 
170
#if NOTIFY_SUB_CHANGES
 
171
                if (notified_mplayer_is_running) {
 
172
                        if (subtitle_info_changed) {
 
173
                                qDebug("MplayerProcess::parseLine: subtitle_info_changed");
 
174
                                subtitle_info_changed = false;
 
175
                                subtitle_info_received = false;
 
176
                                emit subtitleInfoChanged(subs);
 
177
                        }
 
178
                        if (subtitle_info_received) {
 
179
                                qDebug("MplayerProcess::parseLine: subtitle_info_received");
 
180
                                subtitle_info_received = false;
 
181
                                emit subtitleInfoReceivedAgain(subs);
 
182
                        }
 
183
                }
 
184
#endif
 
185
 
 
186
#if NOTIFY_AUDIO_CHANGES
 
187
                if (notified_mplayer_is_running) {
 
188
                        if (audio_info_changed) {
 
189
                                qDebug("MplayerProcess::parseLine: audio_info_changed");
 
190
                                audio_info_changed = false;
 
191
                                emit audioInfoChanged(audios);
 
192
                        }
 
193
                }
 
194
#endif
 
195
 
 
196
                if (!notified_mplayer_is_running) {
 
197
                        qDebug("MplayerProcess::parseLine: starting sec: %f", sec);
 
198
#if GENERIC_CHAPTER_SUPPORT
 
199
                        if ( (md.chapters <= 0) && (dvd_current_title > 0) && 
 
200
                 (md.titles.find(dvd_current_title) != -1) )
 
201
                        {
 
202
                                int idx = md.titles.find(dvd_current_title);
 
203
                                md.chapters = md.titles.itemAt(idx).chapters();
 
204
                                qDebug("MplayerProcess::parseLine: setting chapters to %d", md.chapters);
 
205
                        }
 
206
#endif
 
207
 
 
208
#if CHECK_VIDEO_CODEC_FOR_NO_VIDEO
 
209
                        // Another way to find out if there's no video
 
210
                        if (md.video_codec.isEmpty()) {
 
211
                                md.novideo = true;
 
212
                                emit receivedNoVideo();
 
213
                        }
 
214
#endif
 
215
 
 
216
                        emit receivedStartingTime(sec);
 
217
                        emit mplayerFullyLoaded();
 
218
 
 
219
                        emit receivedCurrentFrame(0); // Ugly hack: set the frame counter to 0
 
220
 
 
221
                        notified_mplayer_is_running = true;
 
222
                }
 
223
                
 
224
            emit receivedCurrentSec( sec );
 
225
 
 
226
                // Check for frame
 
227
        if (rx_frame.indexIn(line) > -1) {
 
228
                        int frame = rx_frame.cap(1).toInt();
 
229
                        //qDebug(" frame: %d", frame);
 
230
                        emit receivedCurrentFrame(frame);
 
231
                }
 
232
        }
 
233
        else {
 
234
                // Emulates mplayer version in Ubuntu:
 
235
                //if (line.startsWith("MPlayer 1.0rc1")) line = "MPlayer 2:1.0~rc1-0ubuntu13.1 (C) 2000-2006 MPlayer Team";
 
236
 
 
237
                emit lineAvailable(line);
 
238
 
 
239
                // Parse other things
 
240
                qDebug("MplayerProcess::parseLine: '%s'", line.toUtf8().data() );
 
241
 
 
242
                // Screenshot
 
243
                if (rx_screenshot.indexIn(line) > -1) {
 
244
                        QString shot = rx_screenshot.cap(1);
 
245
                        qDebug("MplayerProcess::parseLine: screenshot: '%s'", shot.toUtf8().data());
 
246
                        emit receivedScreenshot( shot );
 
247
                }
 
248
                else
 
249
 
 
250
                // End of file
 
251
                if (rx_endoffile.indexIn(line) > -1)  {
 
252
                        qDebug("MplayerProcess::parseLine: detected end of file");
 
253
                        if (!received_end_of_file) {
 
254
                                // In case of playing VCDs or DVDs, maybe the first title
 
255
                // is not playable, so the GUI doesn't get the info about
 
256
                    // available titles. So if we received the end of file
 
257
                // first let's pretend the file has started so the GUI can have
 
258
                    // the data.
 
259
                                if ( !notified_mplayer_is_running) {
 
260
                                        emit mplayerFullyLoaded();
 
261
                                }
 
262
 
 
263
                                //emit receivedEndOfFile();
 
264
                                // Send signal once the process is finished, not now!
 
265
                                received_end_of_file = true;
 
266
                        }
 
267
                }
 
268
                else
 
269
 
 
270
                // Window resolution
 
271
                if (rx_winresolution.indexIn(line) > -1) {
 
272
                        /*
 
273
                        md.win_width = rx_winresolution.cap(4).toInt();
 
274
                        md.win_height = rx_winresolution.cap(5).toInt();
 
275
                    md.video_aspect = (double) md.win_width / md.win_height;
 
276
                        */
 
277
 
 
278
                        int w = rx_winresolution.cap(4).toInt();
 
279
                        int h = rx_winresolution.cap(5).toInt();
 
280
 
 
281
                        emit receivedVO( rx_winresolution.cap(1) );
 
282
                        emit receivedWindowResolution( w, h );
 
283
                        //emit mplayerFullyLoaded();
 
284
                }
 
285
                else
 
286
 
 
287
#if !CHECK_VIDEO_CODEC_FOR_NO_VIDEO
 
288
                // No video
 
289
                if (rx_novideo.indexIn(line) > -1) {
 
290
                        md.novideo = TRUE;
 
291
                        emit receivedNoVideo();
 
292
                        //emit mplayerFullyLoaded();
 
293
                }
 
294
                else
 
295
#endif
 
296
 
 
297
                // Pause
 
298
                if (rx_paused.indexIn(line) > -1) {
 
299
                        emit receivedPause();
 
300
                }
 
301
 
 
302
                // Stream title
 
303
                if (rx_stream_title.indexIn(line) > -1) {
 
304
                        QString s = rx_stream_title.cap(1);
 
305
                        QString url = rx_stream_title.cap(2);
 
306
                        qDebug("MplayerProcess::parseLine: stream_title: '%s'", s.toUtf8().data());
 
307
                        qDebug("MplayerProcess::parseLine: stream_url: '%s'", url.toUtf8().data());
 
308
                        md.stream_title = s;
 
309
                        md.stream_url = url;
 
310
                        emit receivedStreamTitleAndUrl( s, url );
 
311
                }
 
312
 
 
313
#if NOTIFY_SUB_CHANGES
 
314
                // Subtitles
 
315
                if ((rx_subtitle.indexIn(line) > -1) || (rx_sid.indexIn(line) > -1) || (rx_subtitle_file.indexIn(line) > -1)) {
 
316
                        int r = subs.parse(line);
 
317
                        subtitle_info_received = true;
 
318
                        subtitle_info_changed = ((r == SubTracks::SubtitleAdded) || (r == SubTracks::SubtitleChanged));
 
319
                }
 
320
#endif
 
321
 
 
322
#if NOTIFY_AUDIO_CHANGES
 
323
                // Audio
 
324
                if (rx_audio.indexIn(line) > -1) {
 
325
                        int ID = rx_audio.cap(1).toInt();
 
326
                        qDebug("MplayerProcess::parseLine: ID_AUDIO_ID: %d", ID);
 
327
                        if (audios.find(ID) == -1) audio_info_changed = true;
 
328
                        audios.addID( ID );
 
329
                }
 
330
 
 
331
                if (rx_audio_info.indexIn(line) > -1) {
 
332
                        int ID = rx_audio_info.cap(1).toInt();
 
333
                        QString lang = rx_audio_info.cap(3);
 
334
                        QString t = rx_audio_info.cap(2);
 
335
                        qDebug("MplayerProcess::parseLine: Audio: ID: %d, Lang: '%s' Type: '%s'", 
 
336
                    ID, lang.toUtf8().data(), t.toUtf8().data());
 
337
 
 
338
                        int idx = audios.find(ID);
 
339
                        if (idx == -1) {
 
340
                                qDebug("MplayerProcess::parseLine: audio %d doesn't exist, adding it", ID);
 
341
 
 
342
                                audio_info_changed = true;
 
343
                                if ( t == "NAME" ) 
 
344
                                        audios.addName(ID, lang);
 
345
                                else
 
346
                                        audios.addLang(ID, lang);
 
347
                        } else {
 
348
                                qDebug("MplayerProcess::parseLine: audio %d exists, modifing it", ID);
 
349
 
 
350
                                if (t == "NAME") {
 
351
                                        //qDebug("MplayerProcess::parseLine: name of audio %d: %s", ID, audios.itemAt(idx).name().toUtf8().constData());
 
352
                                        if (audios.itemAt(idx).name() != lang) {
 
353
                                                audio_info_changed = true;
 
354
                                                audios.addName(ID, lang);
 
355
                                        }
 
356
                                } else {
 
357
                                        //qDebug("MplayerProcess::parseLine: language of audio %d: %s", ID, audios.itemAt(idx).lang().toUtf8().constData());
 
358
                                        if (audios.itemAt(idx).lang() != lang) {
 
359
                                                audio_info_changed = true;
 
360
                                                audios.addLang(ID, lang);
 
361
                                        }
 
362
                                }
 
363
                        }
 
364
                }
 
365
#endif
 
366
 
 
367
                // The following things are not sent when the file has started to play
 
368
                // (or if sent, smplayer will ignore anyway...)
 
369
                // So not process anymore, if video is playing to save some time
 
370
                if (notified_mplayer_is_running) {
 
371
                        return;
 
372
                }
 
373
 
 
374
                if ( (mplayer_svn == -1) && (line.startsWith("MPlayer ")) ) {
 
375
                        mplayer_svn = MplayerVersion::mplayerVersion(line);
 
376
                        qDebug("MplayerProcess::parseLine: MPlayer SVN: %d", mplayer_svn);
 
377
                        if (mplayer_svn <= 0) {
 
378
                                qWarning("MplayerProcess::parseLine: couldn't parse mplayer version!");
 
379
                                emit failedToParseMplayerVersion(line);
 
380
                        }
 
381
                }
 
382
 
 
383
#if !NOTIFY_SUB_CHANGES
 
384
                // Subtitles
 
385
                if (rx_subtitle.indexIn(line) > -1) {
 
386
                        md.subs.parse(line);
 
387
                }
 
388
                else
 
389
                if (rx_sid.indexIn(line) > -1) {
 
390
                        md.subs.parse(line);
 
391
                }
 
392
                else
 
393
                if (rx_subtitle_file.indexIn(line) > -1) {
 
394
                        md.subs.parse(line);
 
395
                }
 
396
#endif
 
397
                // AO
 
398
                if (rx_ao.indexIn(line) > -1) {
 
399
                        emit receivedAO( rx_ao.cap(1) );
 
400
                }
 
401
                else
 
402
 
 
403
#if !NOTIFY_AUDIO_CHANGES
 
404
                // Matroska audio
 
405
                if (rx_audio_mat.indexIn(line) > -1) {
 
406
                        int ID = rx_audio_mat.cap(1).toInt();
 
407
                        QString lang = rx_audio_mat.cap(3);
 
408
                        QString t = rx_audio_mat.cap(2);
 
409
                        qDebug("MplayerProcess::parseLine: Audio: ID: %d, Lang: '%s' Type: '%s'", 
 
410
                    ID, lang.toUtf8().data(), t.toUtf8().data());
 
411
 
 
412
                        if ( t == "NAME" ) 
 
413
                                md.audios.addName(ID, lang);
 
414
                        else
 
415
                                md.audios.addLang(ID, lang);
 
416
                }
 
417
                else
 
418
#endif
 
419
 
 
420
                // Video tracks
 
421
                if (rx_video.indexIn(line) > -1) {
 
422
                        int ID = rx_video.cap(1).toInt();
 
423
                        QString lang = rx_video.cap(3);
 
424
                        QString t = rx_video.cap(2);
 
425
                        qDebug("MplayerProcess::parseLine: Video: ID: %d, Lang: '%s' Type: '%s'", 
 
426
                    ID, lang.toUtf8().data(), t.toUtf8().data());
 
427
 
 
428
                        if ( t == "NAME" ) 
 
429
                                md.videos.addName(ID, lang);
 
430
                        else
 
431
                                md.videos.addLang(ID, lang);
 
432
                }
 
433
                else
 
434
 
 
435
                // Matroshka chapters
 
436
                if (rx_mkvchapters.indexIn(line)!=-1) {
 
437
                        int c = rx_mkvchapters.cap(1).toInt();
 
438
                        qDebug("MplayerProcess::parseLine: mkv chapters: %d", c);
 
439
#if GENERIC_CHAPTER_SUPPORT
 
440
                        if ((c+1) > md.chapters) {
 
441
                                md.chapters = c+1;
 
442
                                qDebug("MplayerProcess::parseLine: chapters set to: %d", md.chapters);
 
443
                        }
 
444
#else
 
445
                        if ((c+1) > md.mkv_chapters) {
 
446
                                md.mkv_chapters = c+1;
 
447
                                qDebug("MplayerProcess::parseLine: mkv_chapters set to: %d", md.mkv_chapters);
 
448
                        }
 
449
#endif
 
450
                }
 
451
                else
 
452
 
 
453
                // VCD titles
 
454
                if (rx_vcd.indexIn(line) > -1 ) {
 
455
                        int ID = rx_vcd.cap(1).toInt();
 
456
                        QString length = rx_vcd.cap(2);
 
457
                        //md.titles.addID( ID );
 
458
                        md.titles.addName( ID, length );
 
459
                }
 
460
                else
 
461
 
 
462
                // Audio CD titles
 
463
                if (rx_cdda.indexIn(line) > -1 ) {
 
464
                        int ID = rx_cdda.cap(1).toInt();
 
465
                        QString length = rx_cdda.cap(2);
 
466
                        double duration = 0;
 
467
                        QRegExp r("(\\d+):(\\d+):(\\d+)");
 
468
                        if ( r.indexIn(length) > -1 ) {
 
469
                                duration = r.cap(1).toInt() * 60;
 
470
                                duration += r.cap(2).toInt();
 
471
                        }
 
472
                        md.titles.addID( ID );
 
473
                        /*
 
474
                        QString name = QString::number(ID) + " (" + length + ")";
 
475
                        md.titles.addName( ID, name );
 
476
                        */
 
477
                        md.titles.addDuration( ID, duration );
 
478
                }
 
479
                else
 
480
 
 
481
                // DVD titles
 
482
                if (rx_title.indexIn(line) > -1) {
 
483
                        int ID = rx_title.cap(1).toInt();
 
484
                        QString t = rx_title.cap(2);
 
485
 
 
486
                        if (t=="LENGTH") {
 
487
                                double length = rx_title.cap(3).toDouble();
 
488
                                qDebug("MplayerProcess::parseLine: Title: ID: %d, Length: '%f'", ID, length);
 
489
                                md.titles.addDuration(ID, length);
 
490
                        } 
 
491
                        else
 
492
                        if (t=="CHAPTERS") {
 
493
                                int chapters = rx_title.cap(3).toInt();
 
494
                                qDebug("MplayerProcess::parseLine: Title: ID: %d, Chapters: '%d'", ID, chapters);
 
495
                                md.titles.addChapters(ID, chapters);
 
496
                        }
 
497
                        else
 
498
                        if (t=="ANGLES") {
 
499
                                int angles = rx_title.cap(3).toInt();
 
500
                                qDebug("MplayerProcess::parseLine: Title: ID: %d, Angles: '%d'", ID, angles);
 
501
                                md.titles.addAngles(ID, angles);
 
502
                        }
 
503
                }
 
504
                else
 
505
 
 
506
                // Catch cache messages
 
507
                if (rx_cache.indexIn(line) > -1) {
 
508
                        emit receivedCacheMessage(line);
 
509
                }
 
510
                else
 
511
 
 
512
                // Creating index
 
513
                if (rx_create_index.indexIn(line) > -1) {
 
514
                        emit receivedCreatingIndex(line);
 
515
                }
 
516
                else
 
517
 
 
518
                // Catch connecting message
 
519
                if (rx_connecting.indexIn(line) > -1) {
 
520
                        emit receivedConnectingToMessage(line);
 
521
                }
 
522
                else
 
523
 
 
524
                // Catch resolving message
 
525
                if (rx_resolving.indexIn(line) > -1) {
 
526
                        emit receivedResolvingMessage(line);
 
527
                }
 
528
                else
 
529
 
 
530
                // Aspect ratio for old versions of mplayer
 
531
                if (rx_aspect2.indexIn(line) > -1) {
 
532
                        md.video_aspect = rx_aspect2.cap(1).toDouble();
 
533
                        qDebug("MplayerProcess::parseLine: md.video_aspect set to %f", md.video_aspect);
 
534
                }
 
535
                else
 
536
 
 
537
                // Clip info
 
538
 
 
539
                //QString::trimmed() is used for removing leading and trailing whitespaces
 
540
                //Some .mp3 files contain tags with starting and ending whitespaces
 
541
                //Unfortunately MPlayer gives us leading and trailing whitespaces, Winamp for example doesn't show them
 
542
 
 
543
                // Name
 
544
                if (rx_clip_name.indexIn(line) > -1) {
 
545
                        QString s = rx_clip_name.cap(2).trimmed();
 
546
                        qDebug("MplayerProcess::parseLine: clip_name: '%s'", s.toUtf8().data());
 
547
                        md.clip_name = s;
 
548
                }
 
549
                else
 
550
 
 
551
                // Artist
 
552
                if (rx_clip_artist.indexIn(line) > -1) {
 
553
                        QString s = rx_clip_artist.cap(1).trimmed();
 
554
                        qDebug("MplayerProcess::parseLine: clip_artist: '%s'", s.toUtf8().data());
 
555
                        md.clip_artist = s;
 
556
                }
 
557
                else
 
558
 
 
559
                // Author
 
560
                if (rx_clip_author.indexIn(line) > -1) {
 
561
                        QString s = rx_clip_author.cap(1).trimmed();
 
562
                        qDebug("MplayerProcess::parseLine: clip_author: '%s'", s.toUtf8().data());
 
563
                        md.clip_author = s;
 
564
                }
 
565
                else
 
566
 
 
567
                // Album
 
568
                if (rx_clip_album.indexIn(line) > -1) {
 
569
                        QString s = rx_clip_album.cap(1).trimmed();
 
570
                        qDebug("MplayerProcess::parseLine: clip_album: '%s'", s.toUtf8().data());
 
571
                        md.clip_album = s;
 
572
                }
 
573
                else
 
574
 
 
575
                // Genre
 
576
                if (rx_clip_genre.indexIn(line) > -1) {
 
577
                        QString s = rx_clip_genre.cap(1).trimmed();
 
578
                        qDebug("MplayerProcess::parseLine: clip_genre: '%s'", s.toUtf8().data());
 
579
                        md.clip_genre = s;
 
580
                }
 
581
                else
 
582
 
 
583
                // Date
 
584
                if (rx_clip_date.indexIn(line) > -1) {
 
585
                        QString s = rx_clip_date.cap(2).trimmed();
 
586
                        qDebug("MplayerProcess::parseLine: clip_date: '%s'", s.toUtf8().data());
 
587
                        md.clip_date = s;
 
588
                }
 
589
                else
 
590
 
 
591
                // Track
 
592
                if (rx_clip_track.indexIn(line) > -1) {
 
593
                        QString s = rx_clip_track.cap(1).trimmed();
 
594
                        qDebug("MplayerProcess::parseLine: clip_track: '%s'", s.toUtf8().data());
 
595
                        md.clip_track = s;
 
596
                }
 
597
                else
 
598
 
 
599
                // Copyright
 
600
                if (rx_clip_copyright.indexIn(line) > -1) {
 
601
                        QString s = rx_clip_copyright.cap(1).trimmed();
 
602
                        qDebug("MplayerProcess::parseLine: clip_copyright: '%s'", s.toUtf8().data());
 
603
                        md.clip_copyright = s;
 
604
                }
 
605
                else
 
606
 
 
607
                // Comment
 
608
                if (rx_clip_comment.indexIn(line) > -1) {
 
609
                        QString s = rx_clip_comment.cap(1).trimmed();
 
610
                        qDebug("MplayerProcess::parseLine: clip_comment: '%s'", s.toUtf8().data());
 
611
                        md.clip_comment = s;
 
612
                }
 
613
                else
 
614
 
 
615
                // Software
 
616
                if (rx_clip_software.indexIn(line) > -1) {
 
617
                        QString s = rx_clip_software.cap(1).trimmed();
 
618
                        qDebug("MplayerProcess::parseLine: clip_software: '%s'", s.toUtf8().data());
 
619
                        md.clip_software = s;
 
620
                }
 
621
                else
 
622
 
 
623
                if (rx_fontcache.indexIn(line) > -1) {
 
624
                        //qDebug("MplayerProcess::parseLine: updating font cache");
 
625
                        emit receivedUpdatingFontCache();
 
626
                }
 
627
                else
 
628
 
 
629
                // Catch starting message
 
630
                /*
 
631
                pos = rx_play.indexIn(line);
 
632
                if (pos > -1) {
 
633
                        emit mplayerFullyLoaded();
 
634
                }
 
635
                */
 
636
 
 
637
                //Generic things
 
638
                if (rx.indexIn(line) > -1) {
 
639
                        tag = rx.cap(1);
 
640
                        value = rx.cap(2);
 
641
                        //qDebug("MplayerProcess::parseLine: tag: %s, value: %s", tag.toUtf8().data(), value.toUtf8().data());
 
642
 
 
643
#if !NOTIFY_AUDIO_CHANGES
 
644
                        // Generic audio
 
645
                        if (tag == "ID_AUDIO_ID") {
 
646
                                int ID = value.toInt();
 
647
                                qDebug("MplayerProcess::parseLine: ID_AUDIO_ID: %d", ID);
 
648
                                md.audios.addID( ID );
 
649
                        }
 
650
                        else
 
651
#endif
 
652
 
 
653
                        // Video
 
654
                        if (tag == "ID_VIDEO_ID") {
 
655
                                int ID = value.toInt();
 
656
                                qDebug("MplayerProcess::parseLine: ID_VIDEO_ID: %d", ID);
 
657
                                md.videos.addID( ID );
 
658
                        }
 
659
                        else
 
660
                        if (tag == "ID_LENGTH") {
 
661
                                md.duration = value.toDouble();
 
662
                                qDebug("MplayerProcess::parseLine: md.duration set to %f", md.duration);
 
663
                        }
 
664
                        else
 
665
                        if (tag == "ID_VIDEO_WIDTH") {
 
666
                                md.video_width = value.toInt();
 
667
                                qDebug("MplayerProcess::parseLine: md.video_width set to %d", md.video_width);
 
668
                        }
 
669
                        else
 
670
                        if (tag == "ID_VIDEO_HEIGHT") {
 
671
                                md.video_height = value.toInt();
 
672
                                qDebug("MplayerProcess::parseLine: md.video_height set to %d", md.video_height);
 
673
                        }
 
674
                        else
 
675
                        if (tag == "ID_VIDEO_ASPECT") {
 
676
                                md.video_aspect = value.toDouble();
 
677
                                if ( md.video_aspect == 0.0 ) {
 
678
                                        // I hope width & height are already set.
 
679
                                        md.video_aspect = (double) md.video_width / md.video_height;
 
680
                                }
 
681
                                qDebug("MplayerProcess::parseLine: md.video_aspect set to %f", md.video_aspect);
 
682
                        }
 
683
                        else
 
684
                        if (tag == "ID_DVD_DISC_ID") {
 
685
                                md.dvd_id = value;
 
686
                                qDebug("MplayerProcess::parseLine: md.dvd_id set to '%s'", md.dvd_id.toUtf8().data());
 
687
                        }
 
688
                        else
 
689
                        if (tag == "ID_DEMUXER") {
 
690
                                md.demuxer = value;
 
691
                        }
 
692
                        else
 
693
                        if (tag == "ID_VIDEO_FORMAT") {
 
694
                                md.video_format = value;
 
695
                        }
 
696
                        else
 
697
                        if (tag == "ID_AUDIO_FORMAT") {
 
698
                                md.audio_format = value;
 
699
                        }
 
700
                        else
 
701
                        if (tag == "ID_VIDEO_BITRATE") {
 
702
                                md.video_bitrate = value.toInt();
 
703
                        }
 
704
                        else
 
705
                        if (tag == "ID_VIDEO_FPS") {
 
706
                                md.video_fps = value;
 
707
                        }
 
708
                        else
 
709
                        if (tag == "ID_AUDIO_BITRATE") {
 
710
                                md.audio_bitrate = value.toInt();
 
711
                        }
 
712
                        else
 
713
                        if (tag == "ID_AUDIO_RATE") {
 
714
                                md.audio_rate = value.toInt();
 
715
                        }
 
716
                        else
 
717
                        if (tag == "ID_AUDIO_NCH") {
 
718
                                md.audio_nch = value.toInt();
 
719
                        }
 
720
                        else
 
721
                        if (tag == "ID_VIDEO_CODEC") {
 
722
                                md.video_codec = value;
 
723
                        }
 
724
                        else
 
725
                        if (tag == "ID_AUDIO_CODEC") {
 
726
                                md.audio_codec = value;
 
727
                        }
 
728
#if GENERIC_CHAPTER_SUPPORT
 
729
                        else
 
730
                        if (tag == "ID_CHAPTERS") {
 
731
                                md.chapters = value.toInt();
 
732
                        }
 
733
                        else
 
734
                        if (tag == "ID_DVD_CURRENT_TITLE") {
 
735
                                dvd_current_title = value.toInt();
 
736
                        }
 
737
#endif
 
738
                }
 
739
        }
 
740
}
 
741
 
 
742
// Called when the process is finished
 
743
void MplayerProcess::processFinished(int exitCode, QProcess::ExitStatus exitStatus) {
 
744
        qDebug("MplayerProcess::processFinished: exitCode: %d, status: %d", exitCode, (int) exitStatus);
 
745
        // Send this signal before the endoffile one, otherwise
 
746
        // the playlist will start to play next file before all
 
747
        // objects are notified that the process has exited.
 
748
        emit processExited();
 
749
        if (received_end_of_file) emit receivedEndOfFile();
 
750
}
 
751
 
 
752
void MplayerProcess::gotError(QProcess::ProcessError error) {
 
753
        qDebug("MplayerProcess::gotError: %d", (int) error);
 
754
}
 
755
 
 
756
#include "moc_mplayerprocess.cpp"