1
/* This file is part of the KDE project
3
* Copyright (C) 2003 Koos Vriezen <koos.vriezen@xs4all.nl>
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.
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.
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.
21
#ifndef _KMPLAYERPROCESS_H_
22
#define _KMPLAYERPROCESS_H_
25
#include <qguardedptr.h>
28
#include <qstringlist.h>
32
#include <kio/global.h>
34
#include "kmplayerconfig.h"
35
#include "kmplayersource.h"
54
* Base class for all backend processes
56
class KMPLAYER_EXPORT Process : public QObject {
60
NotRunning = 0, Ready, Buffering, Playing
62
Process (QObject * parent, Settings * settings, const char * n);
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; }
80
void grabReady (const QString & path);
82
virtual bool ready (Viewer *);
83
bool play (Source *, NodePtr mrl);
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);
97
void rescheduledStateChanged ();
98
void result (KIO::Job *);
100
void setState (State newstate);
101
virtual bool deMediafiedPlay ();
102
virtual void terminateJobs ();
104
Settings * m_settings;
108
KProcess * m_process;
112
const char ** m_supported_sources;
114
QGuardedPtr <Viewer> m_viewer;
118
* Base class for all MPlayer based processes
120
class MPlayerBase : public Process {
123
MPlayerBase (QObject * parent, Settings * settings, const char * n);
125
void initProcess (Viewer *);
127
virtual bool stop ();
128
virtual bool quit ();
130
bool sendCommand (const QString &);
131
QStringList commands;
132
bool m_use_slave : 1;
134
virtual void processStopped (KProcess *);
136
void dataWritten (KProcess *);
139
class MPlayerPreferencesPage;
140
class MPlayerPreferencesFrame;
145
class KDE_EXPORT MPlayer : public MPlayerBase {
148
MPlayer (QObject * parent, Settings * settings);
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);
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 *);
170
void processStopped (KProcess *);
172
void processOutput (KProcess *, char *, int);
174
QString m_process_output;
177
MPlayerPreferencesPage * m_configpage;
180
LangInfo (int i, const QString & n) : id (i), name (n) {}
181
int id; QString name; SharedPtr <LangInfo> next;
183
SharedPtr <LangInfo> alanglist;
184
WeakPtr <LangInfo> alanglist_end;
185
SharedPtr <LangInfo> slanglist;
186
WeakPtr <LangInfo> slanglist_end;
189
bool m_needs_restarted;
193
* MPlayer preferences page
195
class KMPLAYER_NO_EXPORT MPlayerPreferencesPage : public PreferencesPage {
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,
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];
213
QString mplayer_path;
214
QString additionalarguments;
215
bool alwaysbuildindex;
218
MPlayerPreferencesFrame * m_configframe;
222
* Base class for all recorders
224
class KMPLAYER_EXPORT Recorder {
226
KDE_NO_EXPORT const KURL & recordURL () const { return m_recordurl; }
227
KDE_NO_EXPORT void setURL (const KURL & url) { m_recordurl = url; }
235
class MEncoder : public MPlayerBase, public Recorder {
238
MEncoder (QObject * parent, Settings * settings);
240
virtual void init ();
241
virtual bool deMediafiedPlay ();
243
virtual bool stop ();
247
* MPlayer recorder, runs 'mplayer -dumpstream'
249
class KMPLAYER_NO_EXPORT MPlayerDumpstream
250
: public MPlayerBase, public Recorder {
253
MPlayerDumpstream (QObject * parent, Settings * settings);
254
~MPlayerDumpstream ();
255
virtual void init ();
256
virtual bool deMediafiedPlay ();
258
virtual bool stop ();
261
class XMLPreferencesPage;
262
class XMLPreferencesFrame;
265
* Base class for all backend processes having the KMPlayer::Backend interface
267
class KMPLAYER_EXPORT CallbackProcess : public Process {
269
friend class Callback;
271
CallbackProcess (QObject * parent, Settings * settings, const char * n, const QString & menu);
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 &);
290
NodePtr configDocument () { return configdoc; }
291
void initProcess (Viewer *);
292
virtual bool deMediafiedPlay ();
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);
304
void configReceived ();
306
void processStopped (KProcess *);
307
void processOutput (KProcess *, char *, int);
309
Callback * m_callback;
310
Backend_stub * m_backend;
312
QByteArray m_configdata;
313
QByteArray m_changeddata;
314
XMLPreferencesPage * m_configpage;
317
enum { config_unknown, config_probe, config_yes, config_no } m_have_config;
318
enum { send_no, send_try, send_new } m_send_config;
322
* Config document as used by kxineplayer backend
324
struct KMPLAYER_NO_EXPORT ConfigDocument : public Document {
327
NodePtr childFromTag (const QString & tag);
331
* Element for ConfigDocument
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);
341
* Element for ConfigDocument, defining type of config item
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 (); }
354
* Preference page for XML type of docuement
356
class KMPLAYER_NO_EXPORT XMLPreferencesPage : public PreferencesPage {
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);
366
CallbackProcess * m_process;
367
XMLPreferencesFrame * m_configframe;
371
* Xine backend process
373
class KMPLAYER_NO_EXPORT Xine : public CallbackProcess, public Recorder {
376
Xine (QObject * parent, Settings * settings);
379
bool ready (Viewer *);
383
* GStreamer backend process
385
class KMPLAYER_NO_EXPORT GStreamer : public CallbackProcess {
388
GStreamer (QObject * parent, Settings * settings);
391
virtual bool ready (Viewer *);
395
* ffmpeg backend recorder
397
class KMPLAYER_EXPORT FFMpeg : public Process, public Recorder {
400
FFMpeg (QObject * parent, Settings * settings);
402
virtual void init ();
403
virtual bool deMediafiedPlay ();
405
virtual bool stop ();
406
virtual bool quit ();
408
void processStopped (KProcess *);
415
class KMPLAYER_NO_EXPORT NpStream : public QObject {
420
BecauseDone = 0, BecauseError = 1, BecauseStopped = 2
423
NpStream (QObject *parent, Q_UINT32 stream_id, const KURL & url);
430
QByteArray pending_buf;
431
KIO::TransferJob *job;
432
timeval data_arrival;
435
Q_UINT32 content_length;
436
Reason finish_reason;
439
void stateChanged ();
440
void redirected (Q_UINT32, const KURL &);
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);
449
class KMPLAYER_NO_EXPORT NpPlayer : public Process {
452
NpPlayer (QObject * parent, Settings * settings, const QString & srv);
454
virtual void init ();
455
virtual bool deMediafiedPlay ();
456
virtual void initProcess (Viewer * viewer);
457
virtual QString menuName () const;
459
void setStarted (const QString & srv);
460
void requestStream (const QString & path, const QString & url, const QString & target);
461
void destroyStream (const QString & path);
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);
468
void evaluate (const QString & scr, QString & result);
469
void openUrl (const KURL & url, const QString & target);
471
virtual bool stop ();
472
virtual bool quit ();
474
bool ready (Viewer *);
476
void processOutput (KProcess *, char *, int);
477
void processStopped (KProcess *);
478
void wroteStdin (KProcess *);
479
void streamStateChanged ();
480
void streamRedirected (Q_UINT32, const KURL &);
482
virtual void terminateJobs ();
484
void sendFinish (Q_UINT32 sid, Q_UINT32 total, NpStream::Reason because);
485
void processStreams ();
490
typedef QMap <Q_UINT32, NpStream *> StreamMap;
492
QString remote_service;
494
bool write_in_progress;
499
#endif //_KMPLAYERPROCESS_H_