~ubuntu-branches/ubuntu/lucid/kmplayer/lucid

« back to all changes in this revision

Viewing changes to src/kmplayerprocess.h.orig

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2009-01-31 23:59:43 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090131235943-9py6tgmhb3pmkv3e
Tags: 1:0.11.0a+svn919425-0ubuntu1
* New upstream version released.
* SVN snapshot to fix FTBFS with 4.2
* Rewrite packaging for KDE4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE project
2
 
 *
3
 
 * Copyright (C) 2003 Koos Vriezen <koos.vriezen@xs4all.nl>
4
 
 *
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Library General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Library General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Library General Public License
16
 
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 
 * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
18
 
 * Boston, MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
#ifndef _KMPLAYERPROCESS_H_
22
 
#define _KMPLAYERPROCESS_H_
23
 
 
24
 
#include <qobject.h>
25
 
#include <qguardedptr.h>
26
 
#include <qstring.h>
27
 
#include <qcstring.h>
28
 
#include <qstringlist.h>
29
 
#include <qregexp.h>
30
 
 
31
 
#include <kurl.h>
32
 
#include <kio/global.h>
33
 
 
34
 
#include "kmplayerconfig.h"
35
 
#include "kmplayersource.h"
36
 
 
37
 
class QWidget;
38
 
class KProcess;
39
 
 
40
 
namespace KIO {
41
 
    class Job;
42
 
    class TransferJob;
43
 
}
44
 
 
45
 
namespace KMPlayer {
46
 
    
47
 
class Settings;
48
 
class Viewer;
49
 
class Source;
50
 
class Callback;
51
 
class Backend_stub;
52
 
 
53
 
/*
54
 
 * Base class for all backend processes
55
 
 */
56
 
class KMPLAYER_EXPORT Process : public QObject {
57
 
    Q_OBJECT
58
 
public:
59
 
    enum State {
60
 
        NotRunning = 0, Ready, Buffering, Playing
61
 
    };
62
 
    Process (QObject * parent, Settings * settings, const char * n);
63
 
    virtual ~Process ();
64
 
    virtual void init ();
65
 
    virtual void initProcess (Viewer *);
66
 
    virtual QString menuName () const;
67
 
    virtual void setAudioLang (int, const QString &);
68
 
    virtual void setSubtitle (int, const QString &);
69
 
    bool playing () const;
70
 
    KDE_NO_EXPORT KProcess * process () const { return m_process; }
71
 
    KDE_NO_EXPORT Source * source () const { return m_source; }
72
 
    virtual WId widget ();
73
 
    Viewer * viewer () const;
74
 
    void setSource (Source * src) { m_source = src; }
75
 
    virtual bool grabPicture (const KURL & url, int pos);
76
 
    bool supports (const char * source) const;
77
 
    State state () const { return m_state; }
78
 
    NodePtr mrl () const { return m_mrl; }
79
 
signals:
80
 
    void grabReady (const QString & path);
81
 
public slots:
82
 
    virtual bool ready (Viewer *);
83
 
    bool play (Source *, NodePtr mrl);
84
 
    virtual bool stop ();
85
 
    virtual bool quit ();
86
 
    virtual bool pause ();
87
 
    /* seek (pos, abs) seek position in deci-seconds */
88
 
    virtual bool seek (int pos, bool absolute);
89
 
    /* volume from 0 to 100 */
90
 
    virtual bool volume (int pos, bool absolute);
91
 
    /* saturation/hue/contrast/brightness from -100 to 100 */
92
 
    virtual bool saturation (int pos, bool absolute);
93
 
    virtual bool hue (int pos, bool absolute);
94
 
    virtual bool contrast (int pos, bool absolute);
95
 
    virtual bool brightness (int pos, bool absolute);
96
 
protected slots:
97
 
    void rescheduledStateChanged ();
98
 
    void result (KIO::Job *);
99
 
protected:
100
 
    void setState (State newstate);
101
 
    virtual bool deMediafiedPlay ();
102
 
    virtual void terminateJobs ();
103
 
    Source * m_source;
104
 
    Settings * m_settings;
105
 
    NodePtrW m_mrl;
106
 
    State m_state;
107
 
    State m_old_state;
108
 
    KProcess * m_process;
109
 
    KIO::Job * m_job;
110
 
    QString m_url;
111
 
    int m_request_seek;
112
 
    const char ** m_supported_sources;
113
 
private:
114
 
    QGuardedPtr <Viewer> m_viewer;
115
 
};
116
 
 
117
 
/*
118
 
 * Base class for all MPlayer based processes
119
 
 */
120
 
class MPlayerBase : public Process {
121
 
    Q_OBJECT
122
 
public:
123
 
    MPlayerBase (QObject * parent, Settings * settings, const char * n);
124
 
    ~MPlayerBase ();
125
 
    void initProcess (Viewer *);
126
 
public slots:
127
 
    virtual bool stop ();
128
 
    virtual bool quit ();
129
 
protected:
130
 
    bool sendCommand (const QString &);
131
 
    QStringList commands;
132
 
    bool m_use_slave : 1;
133
 
protected slots:
134
 
    virtual void processStopped (KProcess *);
135
 
private slots:
136
 
    void dataWritten (KProcess *);
137
 
};
138
 
 
139
 
class MPlayerPreferencesPage;
140
 
class MPlayerPreferencesFrame;
141
 
 
142
 
/*
143
 
 * MPlayer process
144
 
 */
145
 
class KDE_EXPORT MPlayer : public MPlayerBase {
146
 
    Q_OBJECT
147
 
public:
148
 
    MPlayer (QObject * parent, Settings * settings);
149
 
    ~MPlayer ();
150
 
    virtual void init ();
151
 
    virtual QString menuName () const;
152
 
    virtual WId widget ();
153
 
    virtual bool grabPicture (const KURL & url, int pos);
154
 
    virtual void setAudioLang (int, const QString &);
155
 
    virtual void setSubtitle (int, const QString &);
156
 
    bool run (const char * args, const char * pipe = 0L);
157
 
public slots:
158
 
    virtual bool deMediafiedPlay ();
159
 
    virtual bool stop ();
160
 
    virtual bool pause ();
161
 
    virtual bool seek (int pos, bool absolute);
162
 
    virtual bool volume (int pos, bool absolute);
163
 
    virtual bool saturation (int pos, bool absolute);
164
 
    virtual bool hue (int pos, bool absolute);
165
 
    virtual bool contrast (int pos, bool absolute);
166
 
    virtual bool brightness (int pos, bool absolute);
167
 
    MPlayerPreferencesPage * configPage () const { return m_configpage; }
168
 
    bool ready (Viewer *);
169
 
protected slots:
170
 
    void processStopped (KProcess *);
171
 
private slots:
172
 
    void processOutput (KProcess *, char *, int);
173
 
private:
174
 
    QString m_process_output;
175
 
    QString m_grabfile;
176
 
    QWidget * m_widget;
177
 
    MPlayerPreferencesPage * m_configpage;
178
 
    QString m_tmpURL;
179
 
    struct LangInfo {
180
 
        LangInfo (int i, const QString & n) : id (i), name (n) {}
181
 
        int id; QString name; SharedPtr <LangInfo> next;
182
 
    };
183
 
    SharedPtr <LangInfo> alanglist;
184
 
    WeakPtr <LangInfo> alanglist_end;
185
 
    SharedPtr <LangInfo> slanglist;
186
 
    WeakPtr <LangInfo> slanglist_end;
187
 
    int aid, sid;
188
 
    int old_volume;
189
 
    bool m_needs_restarted;
190
 
};
191
 
 
192
 
/*
193
 
 * MPlayer preferences page
194
 
 */
195
 
class KMPLAYER_NO_EXPORT MPlayerPreferencesPage : public PreferencesPage {
196
 
public:
197
 
    enum Pattern {
198
 
        pat_size = 0, pat_cache, pat_pos, pat_index,
199
 
        pat_refurl, pat_ref, pat_start,
200
 
        pat_dvdlang, pat_dvdsub, pat_dvdtitle, pat_dvdchapter,
201
 
        pat_vcdtrack, pat_cdromtracks,
202
 
        pat_last
203
 
    };
204
 
    MPlayerPreferencesPage (MPlayer *);
205
 
    KDE_NO_CDTOR_EXPORT ~MPlayerPreferencesPage () {}
206
 
    void write (KConfig *);
207
 
    void read (KConfig *);
208
 
    void sync (bool fromUI);
209
 
    void prefLocation (QString & item, QString & icon, QString & tab);
210
 
    QFrame * prefPage (QWidget * parent);
211
 
    QRegExp m_patterns[pat_last];
212
 
    int cachesize;
213
 
    QString mplayer_path;
214
 
    QString additionalarguments;
215
 
    bool alwaysbuildindex;
216
 
private:
217
 
    MPlayer * m_process;
218
 
    MPlayerPreferencesFrame * m_configframe;
219
 
};
220
 
 
221
 
/*
222
 
 * Base class for all recorders
223
 
 */
224
 
class KMPLAYER_EXPORT Recorder {
225
 
public:
226
 
    KDE_NO_EXPORT const KURL & recordURL () const { return m_recordurl; }
227
 
    KDE_NO_EXPORT void setURL (const KURL & url) { m_recordurl = url; }
228
 
protected:
229
 
    KURL m_recordurl;
230
 
};
231
 
 
232
 
/*
233
 
 * MEncoder recorder
234
 
 */
235
 
class MEncoder : public MPlayerBase, public Recorder {
236
 
    Q_OBJECT
237
 
public:
238
 
    MEncoder (QObject * parent, Settings * settings);
239
 
    ~MEncoder ();
240
 
    virtual void init ();
241
 
    virtual bool deMediafiedPlay ();
242
 
public slots:
243
 
    virtual bool stop ();
244
 
};
245
 
 
246
 
/*
247
 
 * MPlayer recorder, runs 'mplayer -dumpstream'
248
 
 */
249
 
class KMPLAYER_NO_EXPORT MPlayerDumpstream
250
 
  : public MPlayerBase, public Recorder {
251
 
    Q_OBJECT
252
 
public:
253
 
    MPlayerDumpstream (QObject * parent, Settings * settings);
254
 
    ~MPlayerDumpstream ();
255
 
    virtual void init ();
256
 
    virtual bool deMediafiedPlay ();
257
 
public slots:
258
 
    virtual bool stop ();
259
 
};
260
 
 
261
 
class XMLPreferencesPage;
262
 
class XMLPreferencesFrame;
263
 
 
264
 
/*
265
 
 * Base class for all backend processes having the KMPlayer::Backend interface
266
 
 */
267
 
class KMPLAYER_EXPORT CallbackProcess : public Process {
268
 
    Q_OBJECT
269
 
    friend class Callback;
270
 
public:
271
 
    CallbackProcess (QObject * parent, Settings * settings, const char * n, const QString & menu);
272
 
    ~CallbackProcess ();
273
 
    virtual void setStatusMessage (const QString & msg);
274
 
    virtual void setErrorMessage (int code, const QString & msg);
275
 
    virtual void setFinished ();
276
 
    virtual void setPlaying ();
277
 
    virtual void setStarted (QCString dcopname, QByteArray & data);
278
 
    virtual void setMovieParams (int length, int width, int height, float aspect, const QStringList & alang, const QStringList & slang);
279
 
    virtual void setMoviePosition (int position);
280
 
    virtual void setLoadingProgress (int percentage);
281
 
    virtual void setAudioLang (int, const QString &);
282
 
    virtual void setSubtitle (int, const QString &);
283
 
    virtual QString menuName () const;
284
 
    virtual WId widget ();
285
 
    KDE_NO_EXPORT QByteArray & configData () { return m_configdata; }
286
 
    KDE_NO_EXPORT bool haveConfig () { return m_have_config == config_yes; }
287
 
    bool getConfigData ();
288
 
    void setChangedData (const QByteArray &);
289
 
    QString dcopName ();
290
 
    NodePtr configDocument () { return configdoc; }
291
 
    void initProcess (Viewer *);
292
 
    virtual bool deMediafiedPlay ();
293
 
public slots:
294
 
    bool stop ();
295
 
    bool quit ();
296
 
    bool pause ();
297
 
    bool seek (int pos, bool absolute);
298
 
    bool volume (int pos, bool absolute);
299
 
    bool saturation (int pos, bool absolute);
300
 
    bool hue (int pos, bool absolute);
301
 
    bool contrast (int pos, bool absolute);
302
 
    bool brightness (int pos, bool absolute);
303
 
signals:
304
 
    void configReceived ();
305
 
protected slots:
306
 
    void processStopped (KProcess *);
307
 
    void processOutput (KProcess *, char *, int);
308
 
protected:
309
 
    Callback * m_callback;
310
 
    Backend_stub * m_backend;
311
 
    QString m_menuname;
312
 
    QByteArray m_configdata;
313
 
    QByteArray m_changeddata;
314
 
    XMLPreferencesPage * m_configpage;
315
 
    NodePtr configdoc;
316
 
    bool in_gui_update;
317
 
    enum { config_unknown, config_probe, config_yes, config_no } m_have_config;
318
 
    enum { send_no, send_try, send_new } m_send_config;
319
 
};
320
 
 
321
 
/*
322
 
 * Config document as used by kxineplayer backend
323
 
 */
324
 
struct KMPLAYER_NO_EXPORT ConfigDocument : public Document {
325
 
    ConfigDocument ();
326
 
    ~ConfigDocument ();
327
 
    NodePtr childFromTag (const QString & tag);
328
 
};
329
 
 
330
 
/*
331
 
 * Element for ConfigDocument
332
 
 */
333
 
struct KMPLAYER_NO_EXPORT ConfigNode : public DarkNode {
334
 
    ConfigNode (NodePtr & d, const QString & tag);
335
 
    KDE_NO_CDTOR_EXPORT ~ConfigNode () {}
336
 
    NodePtr childFromTag (const QString & tag);
337
 
    QWidget * w;
338
 
};
339
 
 
340
 
/*
341
 
 * Element for ConfigDocument, defining type of config item
342
 
 */
343
 
struct KMPLAYER_NO_EXPORT TypeNode : public ConfigNode {
344
 
    TypeNode (NodePtr & d, const QString & t);
345
 
    KDE_NO_CDTOR_EXPORT ~TypeNode () {}
346
 
    NodePtr childFromTag (const QString & tag);
347
 
    void changedXML (QTextStream & out);
348
 
    QWidget * createWidget (QWidget * parent);
349
 
    const char * nodeName () const { return tag.ascii (); }
350
 
    QString tag;
351
 
};
352
 
 
353
 
/*
354
 
 * Preference page for XML type of docuement
355
 
 */
356
 
class KMPLAYER_NO_EXPORT XMLPreferencesPage : public PreferencesPage {
357
 
public:
358
 
    XMLPreferencesPage (CallbackProcess *);
359
 
    ~XMLPreferencesPage ();
360
 
    void write (KConfig *);
361
 
    void read (KConfig *);
362
 
    void sync (bool fromUI);
363
 
    void prefLocation (QString & item, QString & icon, QString & tab);
364
 
    QFrame * prefPage (QWidget * parent);
365
 
private:
366
 
    CallbackProcess * m_process;
367
 
    XMLPreferencesFrame * m_configframe;
368
 
};
369
 
 
370
 
/*
371
 
 * Xine backend process
372
 
 */
373
 
class KMPLAYER_NO_EXPORT Xine : public CallbackProcess, public Recorder {
374
 
    Q_OBJECT
375
 
public:
376
 
    Xine (QObject * parent, Settings * settings);
377
 
    ~Xine ();
378
 
public slots:
379
 
    bool ready (Viewer *);
380
 
};
381
 
 
382
 
/*
383
 
 * GStreamer backend process
384
 
 */
385
 
class KMPLAYER_NO_EXPORT GStreamer : public CallbackProcess {
386
 
    Q_OBJECT
387
 
public:
388
 
    GStreamer (QObject * parent, Settings * settings);
389
 
    ~GStreamer ();
390
 
public slots:
391
 
    virtual bool ready (Viewer *);
392
 
};
393
 
 
394
 
/*
395
 
 * ffmpeg backend recorder
396
 
 */
397
 
class KMPLAYER_EXPORT FFMpeg : public Process, public Recorder {
398
 
    Q_OBJECT
399
 
public:
400
 
    FFMpeg (QObject * parent, Settings * settings);
401
 
    ~FFMpeg ();
402
 
    virtual void init ();
403
 
    virtual bool deMediafiedPlay ();
404
 
public slots:
405
 
    virtual bool stop ();
406
 
    virtual bool quit ();
407
 
private slots:
408
 
    void processStopped (KProcess *);
409
 
};
410
 
 
411
 
/*
412
 
 * npplayer backend
413
 
 */
414
 
 
415
 
class KMPLAYER_NO_EXPORT NpStream : public QObject {
416
 
    Q_OBJECT
417
 
public:
418
 
    enum Reason {
419
 
        NoReason = -1,
420
 
        BecauseDone = 0, BecauseError = 1, BecauseStopped = 2
421
 
    };
422
 
 
423
 
    NpStream (QObject *parent, Q_UINT32 stream_id, const KURL & url);
424
 
    ~NpStream ();
425
 
 
426
 
    void open ();
427
 
    void close ();
428
 
 
429
 
    KURL url;
430
 
    QByteArray pending_buf;
431
 
    KIO::TransferJob *job;
432
 
    timeval data_arrival;
433
 
    Q_UINT32 bytes;
434
 
    Q_UINT32 stream_id;
435
 
    Q_UINT32 content_length;
436
 
    Reason finish_reason;
437
 
    QString mimetype;
438
 
signals:
439
 
    void stateChanged ();
440
 
    void redirected (Q_UINT32, const KURL &);
441
 
private slots:
442
 
    void slotResult (KIO::Job*);
443
 
    void slotData (KIO::Job*, const QByteArray& qb);
444
 
    void redirection (KIO::Job *, const KURL &url);
445
 
    void slotMimetype (KIO::Job *, const QString &mime);
446
 
    void slotTotalSize (KIO::Job *, KIO::filesize_t sz);
447
 
};
448
 
 
449
 
class KMPLAYER_NO_EXPORT NpPlayer : public Process {
450
 
    Q_OBJECT
451
 
public:
452
 
    NpPlayer (QObject * parent, Settings * settings, const QString & srv);
453
 
    ~NpPlayer ();
454
 
    virtual void init ();
455
 
    virtual bool deMediafiedPlay ();
456
 
    virtual void initProcess (Viewer * viewer);
457
 
    virtual QString menuName () const;
458
 
 
459
 
    void setStarted (const QString & srv);
460
 
    void requestStream (const QString & path, const QString & url, const QString & target);
461
 
    void destroyStream (const QString & path);
462
 
 
463
 
    KDE_NO_EXPORT const QString & destination () const { return service; }
464
 
    KDE_NO_EXPORT const QString & interface () const { return iface; }
465
 
    KDE_NO_EXPORT QString objectPath () const { return path; }
466
 
    QString evaluateScript (const QString & scr);
467
 
signals:
468
 
    void evaluate (const QString & scr, QString & result);
469
 
    void openUrl (const KURL & url, const QString & target);
470
 
public slots:
471
 
    virtual bool stop ();
472
 
    virtual bool quit ();
473
 
public slots:
474
 
    bool ready (Viewer *);
475
 
private slots:
476
 
    void processOutput (KProcess *, char *, int);
477
 
    void processStopped (KProcess *);
478
 
    void wroteStdin (KProcess *);
479
 
    void streamStateChanged ();
480
 
    void streamRedirected (Q_UINT32, const KURL &);
481
 
protected:
482
 
    virtual void terminateJobs ();
483
 
private:
484
 
    void sendFinish (Q_UINT32 sid, Q_UINT32 total, NpStream::Reason because);
485
 
    void processStreams ();
486
 
    QString service;
487
 
    QString iface;
488
 
    QString path;
489
 
    QString filter;
490
 
    typedef QMap <Q_UINT32, NpStream *> StreamMap;
491
 
    StreamMap streams;
492
 
    QString remote_service;
493
 
    QByteArray send_buf;
494
 
    bool write_in_progress;
495
 
};
496
 
 
497
 
} // namespace
498
 
 
499
 
#endif //_KMPLAYERPROCESS_H_