PARP Research Group University of Murcia, Spain


src/qvio/qvmplayerreader.h

Go to the documentation of this file.
00001 /*
00002  *      Copyright (C) 2007, 2008, 2009. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
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 // Auxiliary QVCheckOKMPlayer Class:
00040 // This is an internal convenience thread used only to unblock the open function
00041 // when it is waiting for mplayer to write in the fifo, in the case when
00042 // mplayer aborted when starting (due to bad URL, or wrong file format, for
00043 // example).
00044 class QVCheckOKMPlayer: public QThread
00045 {
00046         friend class QVMPlayerReader; // Only QVMPlayerReader will have access to this class.
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) closeCam(); };
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 openCam(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 closeCam();
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;               // MPlayer arguments
00272                 QProcess *mplayer;                      // Mplayer process
00273                 QString path, schema;                   // Path and schema extracted from the URL
00274                 QNamedPipe *namedPipe;                  // The named fifo
00275                 QFile fifoInput;                        // The fifo file
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 // Camera opening flags | operator:
00291 Q_DECLARE_OPERATORS_FOR_FLAGS(QVMPlayerReader::OpenOptions)
00292 
00293 #endif



QVision framework. PARP research group, copyright 2007, 2008.