-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloopplayer.cpp
111 lines (92 loc) · 2.04 KB
/
loopplayer.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "loopplayer.h"
#include <iostream>
using namespace std;
LoopPlayer::LoopPlayer(QObject *parent) : QThread(parent)
{
stop = true;
}
LoopPlayer::~LoopPlayer()
{
mutex.lock();
stop = true;
condition.wakeOne();
mutex.unlock();
wait();
delete this->loopData;
}
void LoopPlayer::loadVideo(string filename)
{
this->pause();
this->loopData = new LoopData(filename);
}
void LoopPlayer::play()
{
if (!isRunning() && this->loopData != nullptr)
{
if (isStopped())
{
stop = false;
}
start(LowPriority);
}
}
void LoopPlayer::run()
{
while (!stop && this->loopData != nullptr) {
cv::Mat frame;
int delay = static_cast<int>(1000.0 / this->loopData->getFPS());
cv::Mat displayFrame = this->loopData->nextFrame();
if (displayFrame.channels() == 3)
{
img = QImage(reinterpret_cast<const unsigned char*>(displayFrame.data),
displayFrame.cols,
displayFrame.rows,
QImage::Format_RGB888);
}
else
{
img = QImage(reinterpret_cast<const unsigned char*>(displayFrame.data),
displayFrame.cols,
displayFrame.rows,
QImage::Format_Indexed8);
}
emit processedImage(img);
this->msleep(delay);
}
}
void LoopPlayer::pause()
{
stop = true;
}
void LoopPlayer::msleep(int ms)
{
struct timespec ts =
{
ms / 1000, (ms % 1000) * 1000 * 1000
};
nanosleep(&ts, nullptr);
}
bool LoopPlayer::isStopped() const
{
return stop;
}
LoopData * LoopPlayer::getLoopData()
{
return this->loopData;
}
void LoopPlayer::setWidth(int width)
{
this->width = width;
if (this->loopData != nullptr)
{
this->loopData->setWidth(width);
}
}
void LoopPlayer::setHeight(int height)
{
this->height = height;
if (this->loopData != nullptr)
{
this->loopData->setHeight(height);
}
}