-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVideoView.cpp
60 lines (49 loc) · 1.1 KB
/
VideoView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "VideoView.h"
#include <QPainter>
#include <QTimer>
#include <QMutex>
VideoView::VideoView(QWidget *parent) :
PaintableView(parent)
{
setFixedSize(800, 600);
_frame_queue = NULL;
_playing = false;
_frame = QImage(":/images/idle_bg.png");
_fps = 30;
}
void VideoView::startPlay()
{
_playing = true;
repaint();
}
void VideoView::stopPlay()
{
_playing = false;
}
void VideoView::setFrameQueue(QQueue<QImage> *queue)
{
_frame_queue = queue;
}
void VideoView::paintEvent(QPaintEvent *event)
{
PaintableView::paintEvent(event);
if( _frame_queue != NULL )
{
if( _playing )
{
if( !_frame_queue->isEmpty())
{
_mutex.lock();
_frame = _frame_queue->dequeue();
_mutex.unlock();
setPixmap(QPixmap::fromImage(_frame));
}
const uint32_t microsecond_per_second = 1000;
uint32_t interval = microsecond_per_second / _fps;
QTimer::singleShot(interval, this, SLOT(repaint()));
}
}
}
VideoView::~VideoView()
{
}