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 <qvutils/qnamedpipe.h>
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
00061 #endif
00062
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
00195 bool grab(QVImage<uChar,3> & imageRGB);
00196
00207 bool grab(QVImage<uChar> &imgY, QVImage<uChar> &imgU, QVImage<uChar> &imgV);
00208
00209 public slots:
00211 void close();
00212
00219 void seekCam(TSeekType type, double pos);
00220
00221 signals:
00222 void camOpened();
00223 void camClosed();
00224 void newGrab();
00225
00226 public:
00230 const QString getUrlBase() const { return path.split("/").last(); }
00231
00234 OpenOptions getOptions() const { return open_options; };
00235
00238 unsigned int getCols() const { return cols; };
00239
00242 unsigned int getRows() const { return rows; };
00243
00246 double getFPS() const { return fps; };
00247
00255 double getTimeLength() const { return time_length; };
00256
00259 double getTimePos() const { return time_pos; };
00260
00263 unsigned int getFramesGrabbed() const { return frames_grabbed; };
00264
00267 bool isLiveCamera() const { return live_camera; };
00268
00269 private:
00270 OpenOptions open_options;
00271 QStringList mplayer_args;
00272 QProcess *mplayer;
00273 QString path, schema;
00274 QNamedPipe *namedPipe;
00275 QFile fifoInput;
00276 bool camera_opened;
00277 unsigned int frames_grabbed;
00278 bool live_camera;
00279 QVImage<uChar> imgY, imgU, imgV;
00280 int cols, rows, fps;
00281 double time_length, time_pos;
00282 bool end_of_video;
00283
00284 void initMPlayerArgs(QString urlString, unsigned int suggested_cols, unsigned int suggested_rows);
00285 int interpretMPlayerOutput();
00286 bool performGrab();
00287
00288 };
00289
00290
00291 Q_DECLARE_OPERATORS_FOR_FLAGS(QVMPlayerReader::OpenOptions)
00292
00293 #endif