aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2010-08-04 11:07:27 (GMT)
committerHans Verkuil <hverkuil@xs4all.nl>2010-08-04 11:07:27 (GMT)
commit70c36440159d1986e226dde98d51bada4f217837 (patch)
tree23c7ed58ecba8943c94f30377e419911d9578aaa
parent08021d5dc81769eead1bd6546e9a2dcd4c2db7cf (diff)
qv4l2: fix broken fps determination
The fps determination was done based on a 2s-period timer. However, this timer would become unreliable if there is a heavy CPU load. Replaced the timer with gettimeofday calculations. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
-rw-r--r--utils/qv4l2/capture-win.cpp29
-rw-r--r--utils/qv4l2/capture-win.h8
-rw-r--r--utils/qv4l2/qv4l2.cpp1
3 files changed, 14 insertions, 24 deletions
diff --git a/utils/qv4l2/capture-win.cpp b/utils/qv4l2/capture-win.cpp
index 4acf465..6628b94 100644
--- a/utils/qv4l2/capture-win.cpp
+++ b/utils/qv4l2/capture-win.cpp
@@ -16,10 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-
+#include <stdio.h>
#include <QLabel>
#include <QImage>
-#include <QTimer>
#include <QVBoxLayout>
#include <QCloseEvent>
@@ -33,8 +32,6 @@ CaptureWin::CaptureWin()
m_frame = 0;
m_label = new QLabel();
m_msg = new QLabel("No frame");
- m_timer = new QTimer(this);
- connect(m_timer, SIGNAL(timeout()), this, SLOT(update()));
vbox->addWidget(m_label);
vbox->addWidget(m_msg);
@@ -47,25 +44,23 @@ void CaptureWin::setImage(const QImage &image, bool init)
m_frame = m_lastFrame = m_fps = 0;
m_msg->setText("No frame");
} else {
- if (m_frame == 0) {
- m_timer->start(2000);
+ struct timeval tv, res;
+
+ if (m_frame == 0)
+ gettimeofday(&m_tv, NULL);
+ gettimeofday(&tv, NULL);
+ timersub(&tv, &m_tv, &res);
+ if (res.tv_sec) {
+ m_fps = (100 * (m_frame - m_lastFrame)) /
+ (res.tv_sec * 100 + res.tv_usec / 10000);
+ m_lastFrame = m_frame;
+ m_tv = tv;
}
m_msg->setText(QString("Frame: %1 Fps: %2")
.arg(++m_frame).arg(m_fps));
}
}
-void CaptureWin::stop()
-{
- m_timer->stop();
-}
-
-void CaptureWin::update()
-{
- m_fps = (m_frame - m_lastFrame + 1) / 2;
- m_lastFrame = m_frame;
-}
-
void CaptureWin::closeEvent(QCloseEvent *event)
{
QWidget::closeEvent(event);
diff --git a/utils/qv4l2/capture-win.h b/utils/qv4l2/capture-win.h
index 5546056..51e554d 100644
--- a/utils/qv4l2/capture-win.h
+++ b/utils/qv4l2/capture-win.h
@@ -21,10 +21,10 @@
#define CAPTURE_WIN_H
#include <QWidget>
+#include <sys/time.h>
class QImage;
class QLabel;
-class QTimer;
class CaptureWin : public QWidget
{
@@ -35,15 +35,11 @@ public:
virtual ~CaptureWin() {}
void setImage(const QImage &image, bool init = false);
- void stop();
unsigned frame() const { return m_frame; }
protected:
virtual void closeEvent(QCloseEvent *event);
-private slots:
- void update();
-
signals:
void close();
@@ -53,7 +49,7 @@ private:
unsigned m_frame;
unsigned m_lastFrame;
unsigned m_fps;
- QTimer *m_timer;
+ struct timeval m_tv;
};
#endif
diff --git a/utils/qv4l2/qv4l2.cpp b/utils/qv4l2/qv4l2.cpp
index 82fd691..2931cae 100644
--- a/utils/qv4l2/qv4l2.cpp
+++ b/utils/qv4l2/qv4l2.cpp
@@ -370,7 +370,6 @@ void ApplicationWindow::stopCapture()
}
free(m_buffers);
m_buffers = NULL;
- m_capture->stop();
refresh();
}

Privacy Policy