|
From: Tapio V. <aa...@us...> - 2011-01-20 10:45:51
|
Module: editor
Branch: master
Commit: 45b23754e3f423813a5928a861b03fa3be291736
Author: Tapio Vierros <tap...@gm...>
Date: Thu Jan 20 12:44:40 2011 +0200
Fix analyzer thread causing crashing by implementing cancel mechanism.
---
pitchvis.cc | 4 ++++
pitchvis.hh | 3 +++
2 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/pitchvis.cc b/pitchvis.cc
index e1c44ef..61cfc97 100644
--- a/pitchvis.cc
+++ b/pitchvis.cc
@@ -51,6 +51,8 @@ void PitchVis::run()
}
for (unsigned x = 0; x < width; ++x) {
+ if (cancelled) return;
+
// Get decoded samples from ffmpeg
std::vector<float> data(step*2);
mpeg.audioQueue(&*data.begin(), &*data.end(), x * step * 2);
@@ -60,6 +62,7 @@ void PitchVis::run()
da::step_iterator<float> endIt(&*data.end(), 2);
// Analyze
+ if (cancelled) return;
analyzer.input(beginIt, endIt);
analyzer.process();
@@ -93,6 +96,7 @@ void PitchVis::run()
// Draw
{
+ if (cancelled) return;
QMutexLocker locker(&mutex);
unsigned* rgba = reinterpret_cast<unsigned*>(image.bits());
for (unsigned y = 0; y < height; ++y) {
diff --git a/pitchvis.hh b/pitchvis.hh
index 8cb3500..21ae0ca 100644
--- a/pitchvis.hh
+++ b/pitchvis.hh
@@ -40,13 +40,16 @@ class PitchVis: public QWidget, public QThread {
QString fileName;
QImage image;
bool moreAvailable;
+ bool cancelled;
QMutex mutex;
public:
const std::size_t height;
PitchVis(QString const& filename, QWidget *parent = NULL);
+ ~PitchVis() { stop(); wait(); }
void run(); // Thread runs here
+ void stop() { cancelled = true; }
QImage getImage() { QMutexLocker locker(&mutex); moreAvailable = false; return image; }
bool newDataAvailable() const { return moreAvailable; }
|