00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00024
00025 #ifndef QVMPLAYERREADER_H
00026 #define QVMPLAYERREADER_H
00027
00028 #include <QFile>
00029 #include <QProcess>
00030 #include <QString>
00031 #include <QThread>
00032 #include <QUrl>
00033
00034 #include <QNamedPipe>
00035 #include <QVImage>
00036
00037 #ifndef DOXYGEN_IGNORE_THIS
00038
00039
00040
00041
00042
00043
00044 class QVCheckOKMPlayer: public QThread
00045 {
00046 friend class QVMPlayerReader;
00047
00048 Q_OBJECT
00049 private:
00050 QVCheckOKMPlayer(QFile & fifo_file,int max_time_ms_to_wait_for_open);
00051
00052 QFile & _fifo_file;
00053 int _max_time_ms_to_wait_for_open;
00054
00055 void run();
00056
00057 private slots:
00058 void writeErrorInFifo();
00059 };
00060 #endif
00061
00145 class QVMPlayerReader : public QObject
00146 {
00147 Q_OBJECT
00148 public:
00150 QVMPlayerReader(): open_options(Default), path(QString()), schema(QString()), camera_opened(FALSE), frames_grabbed(0), live_camera(FALSE), imgY(QVImage<uChar>()), imgU(QVImage<uChar>()), imgV(QVImage<uChar>()), cols(0), rows(0), fps(0), time_length(0), time_pos(0), end_of_video(FALSE) { };
00151
00153 ~QVMPlayerReader() { if (camera_opened) close(); };
00154
00156 enum OpenOption {
00158 Default = 0x0,
00160 RealTime = 0x1,
00162 Deinterlaced = 0x2,
00164 NoLoop = 0x4
00165 };
00166
00168 typedef enum { SeekCurrent = 0, SeekPercentage = 1, SeekAbsolute = 2 } TSeekType;
00169
00170 Q_DECLARE_FLAGS(OpenOptions,OpenOption);
00171
00183 bool open(const QString & urlstring, OpenOptions opts = Default, unsigned int suggested_cols = 0, unsigned int suggested_rows = 0);
00184
00189 bool grab(QVImage<uChar,1> &image);
00190
00198 #ifdef QVIPP
00199 bool grab(QVImage<uChar,3> & imageRGB);
00200 #endif
00201
00212 bool grab(QVImage<uChar> &imgY, QVImage<uChar> &imgU, QVImage<uChar> &imgV);
00213
00214 public slots:
00216 void close();
00217
00224 void seekCam(TSeekType type, double pos);
00225
00226 signals:
00227 void camOpened();
00228 void camClosed();
00229 void newGrab();
00230
00231 public:
00235 const QString getUrlBase() const { return path.split("/").last(); }
00236
00239 OpenOptions getOptions() const { return open_options; };
00240
00243 unsigned int getCols() const { return cols; };
00244
00247 unsigned int getRows() const { return rows; };
00248
00251 double getFPS() const { return fps; };
00252
00260 double getTimeLength() const { return time_length; };
00261
00264 double getTimePos() const { return time_pos; };
00265
00268 unsigned int getFramesGrabbed() const { return frames_grabbed; };
00269
00272 bool isLiveCamera() const { return live_camera; };
00273
00274 private:
00275 OpenOptions open_options;
00276 QStringList mplayer_args;
00277 QProcess *mplayer;
00278 QString path, schema;
00279 QNamedPipe *namedPipe;
00280 QFile fifoInput;
00281 bool camera_opened;
00282 unsigned int frames_grabbed;
00283 bool live_camera;
00284 QVImage<uChar> imgY, imgU, imgV;
00285 int cols, rows, fps;
00286 double time_length, time_pos;
00287 bool end_of_video;
00288
00289 void initMPlayerArgs(QString urlString, unsigned int suggested_cols, unsigned int suggested_rows);
00290 int interpretMPlayerOutput();
00291 bool performGrab();
00292
00293 };
00294
00295
00296 Q_DECLARE_OPERATORS_FOR_FLAGS(QVMPlayerReader::OpenOptions)
00297
00298 #endif