changed shown variable to atomic

This commit is contained in:
lostjared
2017-02-20 18:40:49 -08:00
parent b3e603079a
commit 9ca3de598c
2 changed files with 3 additions and 10 deletions

View File

@@ -45,9 +45,7 @@ void Playback::setOptions(bool n, int c) {
} }
void Playback::setDisplayed(bool shown) { void Playback::setDisplayed(bool shown) {
mutex_shown.lock();
video_shown = shown; video_shown = shown;
mutex_shown.unlock();
} }
void Playback::run() { void Playback::run() {
@@ -86,12 +84,7 @@ void Playback::run() {
writer.write(frame); writer.write(frame);
} }
mutex.unlock(); mutex.unlock();
bool shown_var; if(video_shown == true) {
mutex_shown.lock();
shown_var = video_shown;
mutex_shown.unlock();
if(shown_var == true) {
if(frame.channels()==3) { if(frame.channels()==3) {
cv::cvtColor(frame, rgb_frame, CV_BGR2RGB); cv::cvtColor(frame, rgb_frame, CV_BGR2RGB);
img = QImage((const unsigned char*)(rgb_frame.data), rgb_frame.cols, rgb_frame.rows, QImage::Format_RGB888); img = QImage((const unsigned char*)(rgb_frame.data), rgb_frame.cols, rgb_frame.rows, QImage::Format_RGB888);

View File

@@ -9,7 +9,8 @@ class Playback : public QThread {
Q_OBJECT Q_OBJECT
private: private:
std::atomic<bool> stop; std::atomic<bool> stop;
QMutex mutex,mutex_shown,mutex_add, mutex_start; std::atomic<bool> video_shown;
QMutex mutex, mutex_shown, mutex_add;
QWaitCondition condition; QWaitCondition condition;
cv::Mat frame; cv::Mat frame;
int frame_rate; int frame_rate;
@@ -20,7 +21,6 @@ private:
QImage img; QImage img;
std::vector<std::pair<int, int>> current; std::vector<std::pair<int, int>> current;
bool isPaused, isStep; bool isPaused, isStep;
bool video_shown;
public: public:
Playback(QObject *parent = 0); Playback(QObject *parent = 0);
~Playback(); ~Playback();