8#include <QCoreApplication>
13 QObject(parent),timer(this)
16 b_saveSetFrameMode =
false;
17 b_saveCurrentFrameMode =
false;
19 b_synchRateMode =
false;
20 b_autosizeMode =
false;
21 defaultNameCounter = 0;
22 customNameCounter = 0;
25 checkDefaultNameCounterCount();
27 fpsTimer.setSingleShot(
false);
28 fpsTimer.setInterval(3000);
30 timer.setTimerType(Qt::PreciseTimer);
33 this,SLOT(internalReceiveFrame(QVideoFrame)),Qt::QueuedConnection);
35 connect(&timer,
SIGNAL(timeout()),
this,SLOT(onTimerElapsed()),Qt::QueuedConnection);
38 &timer,SLOT(start()),Qt::QueuedConnection);
40 connect(&fpsTimer,
SIGNAL(timeout()),
41 this,SLOT(onFpsTimer()),Qt::DirectConnection);
50 this,SLOT(internalReceiveFrame(QVideoFrame)));
52 disconnect(&timer,
SIGNAL(timeout()),
this,SLOT(onTimerElapsed()));
65void SignalHandler::onSelfStartTimer()
86 if(!timer.isActive()){
93 if(b_saveCurrentFrameMode){
94 b_saveCurrentFrameMode =
false;
95 f.map(QAbstractVideoBuffer::ReadOnly);
96 QImage img = QImage(f.bits(),f.width(),f.height(),QImage::Format_RGB32);
101 if(b_saveSetFrameMode){
102 f.map(QAbstractVideoBuffer::ReadOnly);
103 QImage img = QImage(f.bits(),f.width(),f.height(),QImage::Format_RGB32);
117void SignalHandler::internalReceiveFrame(QVideoFrame f)
130 b_synchRateMode = check;
132 if(timer.isActive()){
136 if(frame.isValid() && !timer.isActive()){
148 b_autosizeMode = check;
153 return b_autosizeMode;
162 b_freezeMode = check;
171 timer.setInterval(interval);
176void SignalHandler::onTimerElapsed()
180 internalReceiveFrame(frame);
188 b_saveCurrentFrameMode =
true;
198 this->fileName = url.toLocalFile();
199 customNameCounter = 0;
200 checkCustomNameCounterCount(this->fileName);
207void SignalHandler::saveFrame(QImage img)
209 if(fileName.isEmpty()){
210 QString dir = QCoreApplication::applicationDirPath();
211 QString name = QString(
"%1/frame%2.ppm").arg(dir).arg(defaultNameCounter,3,10,QChar(
'0'));
212 img.save(name,
"PPM");
213 defaultNameCounter++;
215 QString name = QString(
"%1%2.ppm").arg(fileName).arg(customNameCounter,3,10,QChar(
'0'));
216 img.save(name,
"PPM");
226void SignalHandler::saveFrameSet(QImage img)
228 if(fileNames.isEmpty()){
229 QString dir = QCoreApplication::applicationDirPath();
230 QString name = QString(
"%1/frameset%2.ppm").arg(dir).arg(framesetCounter);
231 img.save(name,
"PPM");
234 QString name = QString(
"%1%2.ppm").arg(fileNames).arg(framesetCounter);
235 img.save(name,
"PPM");
245void SignalHandler::checkDefaultNameCounterCount()
247 QDir dir = QDir(QCoreApplication::applicationDirPath());
249 filter.append(
"*.ppm");
250 QFileInfoList fil = dir.entryInfoList(filter,QDir::Files|QDir::NoDotAndDotDot);
251 QListIterator<QFileInfo> li(fil);
254 QFileInfo fi = li.next();
255 if (fi.fileName().contains(
"frame")) {
256 defaultNameCounter++;
266void SignalHandler::checkCustomNameCounterCount(QString file)
268 int index = file.lastIndexOf(
"/");
269 QString sdir = file.left(index);
270 QString sfile = file.right(file.length() - index -1);
272 QDir dir = QDir(sdir);
274 filter.append(
"*.ppm");
275 QFileInfoList fil = dir.entryInfoList(filter,QDir::Files|QDir::NoDotAndDotDot);
276 QListIterator<QFileInfo> li(fil);
279 QFileInfo fi = li.next();
280 if (fi.fileName().contains(sfile)) {
293 if (b_saveSetFrameMode ==
false) {
294 this->fileNames = url.toLocalFile();
302 b_saveSetFrameMode =
true;
308 b_saveSetFrameMode =
false;
312void SignalHandler::onFpsTimer()
314 double pAvg,pMin,pMax,dAvg,dMin,dMax;
317 displayFps.
getStats(dAvg,dMin,dMax);
320 emit
sendFps(pAvg,pMin,pMax,dAvg,dMin,dMax);
int SIGNAL(int pid, int signum)
void update()
This function must be called each time you want to track a frame.
void getStats(double &av, double &m, double &M)
This function returns the Minimum, Maximum and Average values.
void reset()
This function must be called each time you want to reset the acquiring data period Typically if you w...
void sendVideoFrame(QVideoFrame)
Gets a videoframe.
void setFileNames(QUrl url)
Sets the filename used for saving a video frame set.
void sendFrame(QVideoFrame *)
void stopDumpFrames()
Stops the Dump frame modality (Save frame set).
void saveCurrentFrame()
Enable the save curretn frame mode.
void internalSendFrame(QVideoFrame)
void changeRefreshInterval(int ineterval)
Sets the refresh interval.
void freeze(bool check)
Enable/Disable the freeze mode.
void setFileName(QUrl url)
Sets the filename used for saving a video frame.
void sendFps(double portAvg, double portMin, double portMax, double dispAvg, double dispMin, double dispMax)
void startDumpFrames()
Enables the Dump frame modality (Save frame set).
void synchDisplayPeriod(bool check)
Enable/Disable the synch mode.
void synchDisplaySize(bool check)
Enable/Disable the synch size mode.
SignalHandler(QObject *parent=0)