summaryrefslogtreecommitdiff
path: root/client/decoder.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/decoder.cc')
-rw-r--r--client/decoder.cc39
1 files changed, 33 insertions, 6 deletions
diff --git a/client/decoder.cc b/client/decoder.cc
index e181516..fd2464b 100644
--- a/client/decoder.cc
+++ b/client/decoder.cc
@@ -28,13 +28,23 @@
#include "info.h"
+#define READ_DV_FROM_FILE
+
#include "dv.h"
-//#include "dvfile.h"
+#ifdef READ_DV_FROM_FILE
+#include "dvfile.h"
+#else/* READ_DV_FROM_FILE*/
#include "dv1394.h"
+#endif/* READ_DV_FROM_FILE*/
+
+#include <QEvent>
+#include <QApplication>
-Decoder::Decoder()
+Decoder::Decoder(): semaphore(1)
{
frame = NULL;
+ running = true;
+ qApp->installEventFilter(this);
}
Decoder::~Decoder()
@@ -42,16 +52,33 @@ Decoder::~Decoder()
void Decoder::run()
{
- dv1394 reader;
+ semaphore.acquire(); // Lock the shutdown process
+#ifdef READ_DV_FROM_FILE
+ dvfile reader;
+#else/* READ_DV_FROM_FILE*/
+ dv1394 reader;
reader.connect();
+#endif/* READ_DV_FROM_FILE*/
- while(1) {
- frame = reader.readFrame();
+ while(running) {
+ frame = new Frame(reader.readFrame());
}
+ semaphore.release(); // Unlock the shutdown process
}
-unsigned char *Decoder::getFrame()
+Frame *Decoder::getFrame()
{
return frame;
}
+
+bool Decoder::eventFilter(QObject *o, QEvent *e)
+{
+ if (e->type() == QEvent::Close) {
+ running = false; // Tell the thread to stop.
+ semaphore.acquire(); // Wait for the thread to stop.
+ }
+
+ // standard event processing
+ return false;
+}