Main Page | Class List | Directories | File List

kxinewidget.h

00001 /***************************************************************************
00002                            kxinewidget.h -
00003         A KDE/QT API for the xine-lib. Define USE_QT_ONLY if you use QT only.
00004                              -------------------
00005     begin                : Fre Apr 18 2003
00006     revision             : $Revision: 1.1.1.1 $
00007     last modified        : $Date: 2005/06/24 13:18:33 $ by $Author: marco $
00008     copyright            : (C) 2003-2005 by Jürgen Kofler
00009     email                : kaffeine@gmx.net
00010  ***************************************************************************/
00011 
00012 /***************************************************************************
00013  *                                                                         *
00014  *   This program is free software; you can redistribute it and/or modify  *
00015  *   it under the terms of the GNU General Public License as published by  *
00016  *   the Free Software Foundation; either version 2 of the License, or     *
00017  *   (at your option) any later version.                                   *
00018  *                                                                         *
00019  ***************************************************************************/
00020 
00021 #ifndef KXINEWIDGET_H
00022 #define KXINEWIDGET_H
00023 
00024 /* define this if you want to use QT only - disables post plugin support (except visualization)! */
00025 //#define USE_QT_ONLY 1
00026 
00027 /* Usage:
00028  *
00029  * KXineWidget m_xine = new KXineWidget(parent);
00030  * m_xine->appendToQueue("the_best_song_of_the_world.mp3");
00031  *
00032  * You should at least connect to signalXineFatal(const QString&)!
00033  *
00034  */
00035 
00036 #ifdef HAVE_CONFIG_H
00037 #include <config.h>
00038 #endif
00039 
00040 /* forward declaration */
00041 class QWidget;
00042 class QString;
00043 class QStringList;
00044 class QMouseEvent;
00045 class QTimerEvent;
00046 class QTime;
00047 
00048 #include <qtimer.h>
00049 #include <qthread.h>
00050 #include <qdatetime.h>
00051 #include <qptrlist.h>
00052 #include <X11/Xlib.h>
00053 #include <xine.h>
00054 
00055 #ifndef USE_QT_ONLY
00056 #include "postfilter.h"
00057 #else
00058  typedef int PostFilter; /* dummy type */
00059 #endif
00060 
00061 #define SUPPORTED_PROTOCOLS "file,http,mms,mmst,rtsp,rtp,tcp,pnm,cdda,vcd,vcdo,dvd,dvb,pvr,v4l,net,vdr,smb"
00062 
00063 #define DEFAULT_TVTIME_CONFIG "tvtime:method=LinearBlend,enabled=1,pulldown=none,framerate_mode=half_top,judder_correction=0,use_progressive_frame_flag=1,chroma_filter=0,cheap_mode=1"
00064 
00065 #define DEFAULT_OSD_FONT_SIZE 18
00066 #define DEFAULT_OSD_DURATION  5000
00067 #define OSD_MESSAGE_LOW_PRIORITY    1
00068 #define OSD_MESSAGE_NORMAL_PRIORITY 2
00069 
00070 class KXineWidget : public QWidget, private QThread
00071 {
00072 
00073  Q_OBJECT
00074 
00075 public:
00076   KXineWidget(QWidget *parent=0, const char *name=0,
00077         const QString& pathToConfigFile = QString::null, const QString& pathToLogoFile = QString::null,
00078         const QString& audioDriver = QString::null, const QString& videoDriver = QString::null,
00079         bool startManual = false, bool verbose = false);
00080  ~KXineWidget();
00081 
00082   enum Speed { Normal = 0, Pause, Fast1, Fast2, Slow1, Slow2, Undefined };
00083 
00084   bool initXine(); /* call this only if you set startManual = true in the constructor */
00085   bool isXineReady() const { return m_xineReady; }
00086   bool isPlaying() const;
00087   Speed getSpeed() const { return m_currentSpeed; }
00088   QString getXineLog() const;
00089 
00090   void setQueue(const QStringList& urls) { m_queue = urls; }
00091   void appendToQueue(const QString& url) { m_queue.append(url); } /* file to play; call slotPlay() to play queue... */
00092   void clearQueue() { m_queue.clear(); }
00093   bool isQueueEmpty() const { return m_queue.empty(); }
00094 
00095   void showOSDMessage(const QString& message, uint duration = DEFAULT_OSD_DURATION /* ms */, int priority = OSD_MESSAGE_NORMAL_PRIORITY);
00096 
00097   /* stream info */
00098   const QString& getURL() const { return m_trackURL; }
00099   const QString& getTitle() const { return m_trackTitle; }
00100   const QString& getArtist() const { return m_trackArtist; }
00101   const QString& getAlbum() const { return m_trackAlbum; }
00102   const QString& getGenre() const { return m_trackGenre; }
00103   const QString& getYear() const { return m_trackYear; }
00104   const QString& getComment() const { return m_trackComment; }
00105   const QTime& getLength() const { return m_trackLength; }
00106   const QString& getVideoCodec() const { return m_trackVideoCodec; }
00107   QSize getVideoSize() const { return QSize(m_videoFrameWidth, m_videoFrameHeight); }
00108   uint getVideoBitrate() const { return m_trackVideoBitrate; }
00109   const QString& getAudioCodec() const { return m_trackAudioCodec; }
00110   uint getAudioBitrate() const { return m_trackAudioBitrate; }
00111   const QString& getSubtitleURL() const { return m_trackSubtitleURL; }
00112   const QString& getSaveURL() const { return m_trackSaveURL; }
00113   bool hasVideo() const { return m_trackHasVideo; }
00114   bool hasAudio() const { return m_trackHasAudio; }
00115   bool hasChapters() const { return m_trackHasChapters; }
00116   bool hasSubtitleURL() const { return !m_trackSubtitleURL.isNull(); }
00117   bool hasSaveURL() const { return !m_trackSaveURL.isNull(); }
00118   bool isSeekable() const { return m_trackIsSeekable; }
00119 
00120   uint getVolume() const; /* percent */
00121   QTime getPlaytime() const;
00122   uint getPosition() const; /* 0..65535 */
00123 
00124   void savePosition(const int pos) { (pos > 0) ? m_savedPos = pos : m_savedPos = 0; }
00125 
00126   /* plugin handling */
00127   QStringList getAudioDrivers() const { return m_audioDriverList; }
00128   QStringList getVideoDrivers() const { return m_videoDriverList; }
00129   void getAutoplayPlugins(QStringList& pluginNames) const;
00130   bool getAutoplayPluginURLS(const QString& name, QStringList& urls);
00131   QStringList getVisualPlugins() const;
00132 
00133 #ifndef USE_QT_ONLY
00134   void createDeinterlacePlugin(const QString& configString, QWidget* parent);
00135   const QString getDeinterlaceConfig() const;
00136   QStringList getVideoFilterNames() const;
00137   QStringList getAudioFilterNames() const;
00138   QStringList getAudioFilterConfig();
00139   QStringList getVideoFilterConfig();
00140 #endif
00141 
00142   QString getSupportedExtensions() const;  /* get mime types xine can play */
00143 
00144   void playNextChapter() const;
00145   void playPreviousChapter() const;
00146 
00147   /* config stuff */
00148   void setStreamSaveDir(const QString& dir);
00149   const QString getStreamSaveDir();
00150   void setBroadcasterPort(const uint port);
00151   void getVideoSettings(int& hue, int& sat, int& contrast, int& bright,
00152                         int& avOffset, int& spuOffset) const;
00153  /* disc drives devices*/
00154   QString audiocdDevice() const;
00155   QString vcdDevice() const;
00156   QString dvdDevice() const;
00157 
00158  /* take a screenshot */
00159   QImage getScreenshot() const;
00160   void getScreenshot(uchar*& rgb32BitData, int& videoWidth, int& videoHeight, double& scaleFactor) const;
00161 
00162  /* get the xine engine, needed by the xine configuration dialog */
00163   const xine_t* const getXineEngine() const;
00164   void saveXineConfig();
00165 
00166   /* for fullscreen */
00167   void startMouseHideTimer();
00168   void stopMouseHideTimer();
00169 
00170   void globalPosChanged();  /* call this if global pos of parent was changed */
00171 
00172 signals:
00173   void signalXineFatal(const QString& message);   
00174   void signalXineError(const QString& message);
00175   void signalXineMessage(const QString& message);
00176   void signalXineStatus(const QString& status);
00177   void signalXineReady();
00178   void signalXinePlaying();
00179 
00180   void signalHasChapters(bool);
00181   void signalPlaybackFinished();
00182   void signalNewChannels(const QStringList& audio, const QStringList& sub, int currentAudio, int currentSub);
00183   void signalNewPosition(int, const QTime&);
00184 
00185   void signalTitleChanged();
00186   void signalVideoSizeChanged();
00187   void signalLengthChanged();
00188 
00189   void signalRightClick(const QPoint&);  /* right-click on video window */
00190   void signalLeftClick(const QPoint&);
00191   void signalMiddleClick();
00192   void signalDoubleClick();
00193 
00194 public slots:
00195   virtual void polish();
00196 
00197   void slotPlay();
00198   void slotStop();
00199 
00200   void slotSetVolume(int);
00201   void slotToggleMute();
00202   void slotSpeedPause();
00203   void slotSpeedNormal();
00204   void slotSpeedFaster();
00205   void slotSpeedSlower();
00206   void slotSetVisualPlugin(const QString& name);
00207   void slotSetAudioChannel(int);
00208   void slotSetSubtitleChannel(int);
00209   void slotSetFileSubtitles(QString);
00210   void slotStartSeeking();
00211   void slotSeekToPosition(int pos);
00212   void slotSeekToTime(const QTime&);
00213   void slotStopSeeking();
00214   void slotEnableVideoFilters(bool enable);
00215   void slotEnableAudioFilters(bool enable);
00216   void slotEject();
00217   void slotEnableAutoresize(bool enable);
00218   void slotAspectRatioAuto();
00219   void slotAspectRatio4_3();
00220   void slotAspectRatioAnamorphic(); /* 16:9 */
00221   void slotAspectRatioSquare(); /* 1:1 */
00222   void slotAspectRatioDVB(); /* 2.11:1 */
00223   void slotZoomIn();
00224   void slotZoomOut();
00225   void slotZoomOff();
00226   void slotToggleDeinterlace();
00227   void slotSetDeinterlaceConfig(const QString&);
00228   void slotGetInfoDelayed();
00229 
00230   /* disc drive devices */
00231   void slotSetAudiocdDevice(const QString&);
00232   void slotSetVcdDevice(const QString&);
00233   void slotSetDvdDevice(const QString&);
00234 
00235   void slotSetHue(int hue);
00236   void slotSetSaturation(int sat);
00237   void slotSetContrast(int contrast);
00238   void slotSetBrightness(int bright);
00239   void slotSetAVOffset(int av);
00240   void slotSetSpuOffset(int spu);
00241 
00242   void slotSetEq30(int val);
00243   void slotSetEq60(int val);
00244   void slotSetEq125(int val);
00245   void slotSetEq250(int val);
00246   void slotSetEq500(int val);
00247   void slotSetEq1k(int val);
00248   void slotSetEq2k(int val);
00249   void slotSetEq4k(int val);
00250   void slotSetEq8k(int val);
00251   void slotSetEq16k(int val);
00252   void slotSetVolumeGain(bool gain);
00253 
00254  /* DVD Menus */
00255   void slotMenuToggle();
00256   void slotMenuTitle();
00257   void slotMenuRoot();
00258   void slotMenuSubpicture();
00259   void slotMenuAudio();
00260   void slotMenuAngle();
00261   void slotMenuPart();
00262   void slotDVDMenuLeft();
00263   void slotDVDMenuRight();
00264   void slotDVDMenuUp();
00265   void slotDVDMenuDown();
00266   void slotDVDMenuSelect();
00267 
00268  /***** postprocess filters ****/
00269   void slotCreateVideoFilter(const QString& name, QWidget* parent);
00270   void slotCreateAudioFilter(const QString& name, QWidget* parent);
00271   void slotDeleteVideoFilter(PostFilter* filter);
00272   void slotDeleteAudioFilter(PostFilter* filter);
00273   void slotRemoveAllVideoFilters();
00274   void slotRemoveAllAudioFilters();
00275 
00276 protected slots:
00277   void slotSendPosition();
00278   void slotEmitLengthInfo();
00279   void slotHideMouse();
00280   void slotOSDHide();
00281   void slotNoRecentMessage();
00282 
00283 protected:
00284   void mouseMoveEvent(QMouseEvent*);
00285   void mousePressEvent(QMouseEvent*);
00286   void timerEvent(QTimerEvent*);
00287   void mouseDoubleClickEvent(QMouseEvent*);
00288   void wheelEvent(QWheelEvent*);
00289   void initOSD();
00290 
00291 private:
00292   virtual void run();  /* implement pure virtual QThread method */
00293 
00294  /********* callbacks and threads ************/
00295   static void destSizeCallback(void* p, int video_width, int video_height, double video_aspect,
00296                        int* dest_width, int* dest_height, double* dest_aspect);
00297 
00298   static void frameOutputCallback(void* p, int video_width, int video_height, double video_aspect,
00299                           int* dest_x, int* dest_y, int* dest_width, int* dest_height,
00300                           double* dest_aspect, int* win_x, int* win_y);
00301 
00302   static void videoDriverChangedCallback(void* p, xine_cfg_entry_t* entry);
00303   static void audioDriverChangedCallback(void* p, xine_cfg_entry_t* entry);
00304   static void audioMixerMethodChangedCallback(void* p, xine_cfg_entry_t* entry);
00305   static void showOSDMessagesChangedCallback(void* p, xine_cfg_entry_t* entry);
00306   static void sizeForOSDMessagesChangedCallback(void* p, xine_cfg_entry_t* entry);
00307   static void fontForOSDMessagesChangedCallback(void* p, xine_cfg_entry_t* entry);
00308 
00309   static void xineEventListener(void* p, const xine_event_t*);
00310 
00311 protected:
00312   void sendXineError();
00313   QTime getLengthInfo();
00314 #ifndef USE_QT_ONLY
00315   void wireVideoFilters();
00316   void unwireVideoFilters();
00317   void wireAudioFilters();
00318   void unwireAudioFilters();
00319 #endif
00320 
00321 /* HELPER FUNCTIONS */
00322 public:
00323 #ifdef USE_QT_ONLY
00324   static QString i18n(const char *text);
00325 #endif
00326   static void debugOut(QString);
00327   static void errorOut(QString);
00328   static void warningOut(QString);
00329   static QTime msToTime(int msec);
00330   static void   yuy2Toyv12(uint8_t *y, uint8_t *u, uint8_t *v, uint8_t *input, int width, int height);
00331   static uchar *yv12ToRgb(uint8_t *src_y, uint8_t *src_u, uint8_t *src_v, int width, int height);
00332 
00333 protected:
00334   QStringList m_queue;
00335 
00336   bool m_startXineManual;
00337   bool m_xineReady;
00338   QString m_logoFile;
00339   QString m_preferedAudio;
00340   QString m_preferedVideo;
00341   bool m_xineVerbose;
00342   QString m_configFilePath;
00343   QStringList m_audioDriverList;
00344   QStringList m_videoDriverList;
00345 
00346  /*x11*/
00347   Window m_xineWindow;
00348   Display* m_xineDisplay;
00349   int m_xineScreen;
00350 
00351  /*xine*/
00352   x11_visual_t m_x11Visual;
00353   xine_t* m_xineEngine;
00354   xine_audio_port_t* m_audioDriver;
00355   xine_video_port_t* m_videoDriver;
00356   xine_stream_t* m_xineStream;
00357   xine_event_queue_t* m_eventQueue;
00358   xine_osd_t* m_osd;
00359   bool m_osdUnscaled;
00360   bool m_osdShow;
00361   int m_osdSize;
00362   char* m_osdFont;
00363   char** m_audioChoices;
00364   char* m_audioInfo;
00365   char** m_videoChoices;
00366   char* m_videoInfo;
00367   char* m_mixerInfo;
00368   char* m_osdShowInfo;
00369   char** m_osdSizeOptions;
00370   char* m_osdSizeInfo;
00371   char* m_osdFontInfo;
00372 
00373 #ifndef USE_QT_ONLY
00374  /*postfilter*/
00375   QPtrList<PostFilter> m_videoFilterList;
00376   bool m_videoFiltersEnabled;
00377   QPtrList<PostFilter> m_audioFilterList;
00378   bool m_audioFiltersEnabled;
00379   PostFilter* m_deinterlaceFilter;
00380   bool m_deinterlaceEnabled;
00381   PostFilter* m_visualPlugin;
00382 #else
00383   xine_post_t* m_xinePost;
00384   xine_post_out_t* m_postAudioSource;
00385   xine_post_in_t* m_postInput;
00386 #endif
00387 
00388   QString m_audioDriverName;
00389   QString m_videoDriverName;
00390   QString m_visualPluginName;
00391 
00392   int m_videoFrameWidth;
00393   int m_videoFrameHeight;
00394   double m_videoAspect;
00395   int m_globalX;
00396   int m_globalY;
00397 
00398   Speed m_currentSpeed;
00399   QString m_xineMessage;
00400   QString m_xineError;
00401   QString m_statusString;
00402   bool m_softwareMixer;
00403   bool m_volumeGain;
00404   double m_displayRatio;
00405   QString m_cachedCDPath, m_cachedVCDPath, m_cachedDVDPath;
00406   QSize m_newParentSize;
00407   int m_currentZoom;
00408   QStringList m_audioCh;
00409   QStringList m_subCh;
00410   int m_currentAudio, m_currentSub;
00411   int m_savedPos;
00412   bool m_autoresizeEnabled;
00413   bool m_DVDButtonEntered;
00414   QString m_newMRLReference;
00415 
00416   QTimer m_posTimer;
00417   QTimer m_lengthInfoTimer;
00418   uint m_lengthInfoTries;
00419   QTimer m_mouseHideTimer;
00420   QTimer m_osdTimer;
00421   QTimer m_recentMessagesTimer;
00422 
00423   QString m_trackURL;
00424   QString m_trackTitle;
00425   QString m_trackArtist;
00426   QString m_trackAlbum;
00427   QString m_trackGenre;
00428   QString m_trackYear;
00429   QString m_trackComment;
00430   QTime m_trackLength;
00431   QString m_trackVideoCodec;
00432   uint m_trackVideoBitrate;
00433   QString m_trackAudioCodec;
00434   uint m_trackAudioBitrate;
00435   QString m_trackSubtitleURL;
00436   QString m_trackSaveURL;
00437   bool m_trackHasVideo;
00438   bool m_trackHasAudio;
00439   bool m_trackHasChapters;
00440   bool m_trackIsSeekable;
00441 
00442 /*  dvb  */
00443 signals:
00444   void stopDvb();
00445 
00446 public:
00447   QString TimeShiftFilename;
00448 
00449 public slots:
00450   void setDvb( QString pipeName, QString chanName, int haveVideo );
00451   void setDvbCurrentNext( QStringList list );
00452   bool openDvb();
00453   bool playDvb();
00454   void slotPlayTimeShift();
00455   void dvbShowOSD();
00456   void dvbHideOSD();
00457 
00458 private:
00459   int dvbHaveVideo;
00460   QTimer dvbOSDHideTimer;
00461   xine_osd_t *dvbOSD;
00462   QStringList dvbCurrentNext;
00463   unsigned int dvbColor[256];
00464   unsigned char dvbTrans[256];
00465   unsigned int rgb2yuv( unsigned int R, unsigned int G, unsigned int B );
00466   void initDvbPalette();
00467 };
00468 
00469 
00470 
00471 #endif

Generated on Fri Jun 24 14:53:37 2005 for konverter.kdevelop by  doxygen 1.4.3-20050530