~ubuntu-branches/debian/sid/v4l-utils/sid

« back to all changes in this revision

Viewing changes to utils/qv4l2/capture-win.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gregor Jasny
  • Date: 2010-10-03 16:26:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101003162640-88djisgfegdp020e
Tags: 0.8.1-1
* New upstream version (Closes: #598969)
* Bumped standards to version 3.9.1 (no changes needed)
* Updated copyright file 

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * along with this program; if not, write to the Free Software
17
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
18
 */
19
 
 
 
19
#include <stdio.h>
20
20
#include <QLabel>
21
21
#include <QImage>
22
 
#include <QTimer>
23
22
#include <QVBoxLayout>
24
23
#include <QCloseEvent>
25
24
 
33
32
        m_frame = 0;
34
33
        m_label = new QLabel();
35
34
        m_msg = new QLabel("No frame");
36
 
        m_timer = new QTimer(this);
37
 
        connect(m_timer, SIGNAL(timeout()), this, SLOT(update()));
38
35
 
39
36
        vbox->addWidget(m_label);
40
37
        vbox->addWidget(m_msg);
47
44
                m_frame = m_lastFrame = m_fps = 0;
48
45
                m_msg->setText("No frame");
49
46
        } else {
50
 
                if (m_frame == 0) {
51
 
                        m_timer->start(2000);
 
47
                struct timeval tv, res;
 
48
 
 
49
                if (m_frame == 0)
 
50
                        gettimeofday(&m_tv, NULL);
 
51
                gettimeofday(&tv, NULL);
 
52
                timersub(&tv, &m_tv, &res);
 
53
                if (res.tv_sec) {
 
54
                        m_fps = (100 * (m_frame - m_lastFrame)) /
 
55
                                (res.tv_sec * 100 + res.tv_usec / 10000);
 
56
                        m_lastFrame = m_frame;
 
57
                        m_tv = tv;
52
58
                }
53
59
                m_msg->setText(QString("Frame: %1 Fps: %2")
54
60
                                .arg(++m_frame).arg(m_fps));
55
61
        }
56
62
}
57
63
 
58
 
void CaptureWin::stop()
59
 
{
60
 
        m_timer->stop();
61
 
}
62
 
 
63
 
void CaptureWin::update()
64
 
{
65
 
        m_fps = (m_frame - m_lastFrame + 1) / 2;
66
 
        m_lastFrame = m_frame;
67
 
}
68
 
 
69
64
void CaptureWin::closeEvent(QCloseEvent *event)
70
65
{
71
66
        QWidget::closeEvent(event);