diff options
Diffstat (limited to 'client/decoder.cc')
-rw-r--r-- | client/decoder.cc | 70 |
1 files changed, 30 insertions, 40 deletions
diff --git a/client/decoder.cc b/client/decoder.cc index 1193710..48dc67d 100644 --- a/client/decoder.cc +++ b/client/decoder.cc @@ -28,7 +28,7 @@ #include "info.h" -#define READ_DV_FROM_FILE +//#define READ_DV_FROM_FILE #include "dv.h" #ifdef READ_DV_FROM_FILE @@ -44,12 +44,11 @@ #include "libdv_wrapper.h" -Decoder::Decoder(): semaphore(1), screenshotsemaphore(1) +Decoder::Decoder(): closesem(1) { - frame = NULL; running = true; + memset(pframe, 0, sizeof(pframe)); // Init an empty frame qApp->installEventFilter(this); - screenshotsemaphore.acquire(); // Lock the screenshot method } Decoder::~Decoder() @@ -58,7 +57,7 @@ Decoder::~Decoder() void Decoder::run() { - semaphore.acquire(); // Lock the shutdown process + closesem.acquire(); // Lock the shutdown process #ifdef READ_DV_FROM_FILE dvfile reader; @@ -67,38 +66,40 @@ void Decoder::run() reader.connect(); #endif/* READ_DV_FROM_FILE*/ - fprintf(stderr, "init done\n"); - while(running) { - char *tmp = (char*)reader.readFrame(); - - if(MIaV::control.isScreenshot()) { - memcpy(screenshotframe, tmp, DVPACKAGE_SIZE); - screenshotsemaphore.release(); - } + char *frame = (char*)reader.readFrame(); + if(!frame) continue; // An empty frame if(MIaV::control.isFrozen() == false) { - mutex.lock(); - if(frame) free(frame); - frame = tmp; - mutex.unlock(); - } else { - free(tmp); + pmutex.lock(); + memcpy(pframe, frame, DVPACKAGE_SIZE); + pmutex.unlock(); } + + free(frame); } - semaphore.release(); // Unlock the shutdown process + closesem.release(); // Unlock the shutdown process } -char *Decoder::getFrame() +char *Decoder::pframeAcquire() { - char *tmp; + pmutex.lock(); + return pframe; +} - mutex.lock(); - tmp = frame; - frame = NULL; - mutex.unlock(); +void Decoder::pframeRelease() +{ + pmutex.unlock(); +} - return tmp; +void Decoder::snapshot(char *rgb) +{ + LibDVWrapper dv; + dv.setOutputBuffer(rgb, DV::BGR0); + + pmutex.lock(); + dv.decode(pframe); + pmutex.unlock(); } bool Decoder::eventFilter(QObject *o, QEvent *e) @@ -107,21 +108,10 @@ bool Decoder::eventFilter(QObject *o, QEvent *e) // printf("QUIT from: %p, this: %p, testing: %p\n", o, this, qApp->activeWindow()); if(qApp->activeWindow() == (QWidget*)o) { // Ignore close events from non top level widgets running = false; // Tell the thread to stop. - semaphore.acquire(); // Wait for the thread to stop. + closesem.acquire(); // Wait for the thread to stop. } } - + // standard event processing return false; } - - -void Decoder::snapshot(char *rgb) -{ - LibDVWrapper dv; - dv.setOutputBuffer(rgb, DV::BGR0); - - MIaV::control.takeScreenshot(); - screenshotsemaphore.acquire(); // Wait for screenshot - dv.decode(screenshotframe); -} |