summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/control.cc8
-rw-r--r--client/control.h6
-rw-r--r--client/decoder.cc70
-rw-r--r--client/decoder.h11
-rw-r--r--client/player.cc14
-rw-r--r--client/xvaccelrenderer.cc9
6 files changed, 53 insertions, 65 deletions
diff --git a/client/control.cc b/client/control.cc
index 92bd74c..6dd4b4b 100644
--- a/client/control.cc
+++ b/client/control.cc
@@ -86,14 +86,14 @@ void Control::stop()
recording = false;
mutex.unlock();
}
-
+/*
void Control::takeScreenshot()
{
mutex.lock();
screenshot = true;
mutex.unlock();
}
-
+*/
bool Control::isFrozen()
{
bool isfrozen;
@@ -111,7 +111,7 @@ bool Control::isRecording()
mutex.unlock();
return isrecording;
}
-
+/*
bool Control::isScreenshot()
{
bool isscreenshot;
@@ -121,7 +121,7 @@ bool Control::isScreenshot()
mutex.unlock();
return isscreenshot;
}
-
+*/
// Global control object
Control MIaV::control;
diff --git a/client/control.h b/client/control.h
index a72ed82..1563f3d 100644
--- a/client/control.h
+++ b/client/control.h
@@ -51,13 +51,13 @@ public:
bool isFrozen();
bool isRecording();
- bool isScreenshot();
- void takeScreenshot();
+ // bool isScreenshot();
+ // void takeScreenshot();
private:
bool frozen;
bool recording;
- bool screenshot;
+ // bool screenshot;
QMutex mutex;
QString cpr;
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);
-}
diff --git a/client/decoder.h b/client/decoder.h
index 0913858..6cb6a22 100644
--- a/client/decoder.h
+++ b/client/decoder.h
@@ -46,16 +46,19 @@ public:
void snapshot(char *rgb);
+ char *pframeAcquire();
+ void pframeRelease();
+
protected:
bool eventFilter(QObject *o, QEvent *e);
private:
volatile bool running;
- char *frame;
- QSemaphore semaphore;
+ QSemaphore closesem;
+
+ QMutex pmutex;
+ char pframe[DVPACKAGE_SIZE]; // Player frame
- char screenshotframe[DVPACKAGE_SIZE];
- QSemaphore screenshotsemaphore;
QMutex mutex;
};
diff --git a/client/player.cc b/client/player.cc
index ba2250f..608d53d 100644
--- a/client/player.cc
+++ b/client/player.cc
@@ -29,9 +29,8 @@
#define WIDTH 720
#define HEIGHT 576
-static int num = 0;
-
-Player::Player(QWidget *w, Decoder *d)
+Player::Player(QWidget *w, Decoder *d) :
+ dvdecoder(DV::ColorBest)
{
widget = w;
decoder = d;
@@ -51,13 +50,10 @@ Player::~Player()
void Player::show_frame()
{
char *frame;
- fprintf(stderr, "Frame!%d\n", num++);
- frame = decoder->getFrame();
- if(frame) {
- dvdecoder.decode(frame);
- // free(frame);
- }
+ frame = decoder->pframeAcquire(); // Acquire frame data
+ dvdecoder.decode(frame);
+ decoder->pframeRelease(); // Release frame data
render.width = widget->width();
render.height = widget->height();
diff --git a/client/xvaccelrenderer.cc b/client/xvaccelrenderer.cc
index 7de4510..4ba8a9f 100644
--- a/client/xvaccelrenderer.cc
+++ b/client/xvaccelrenderer.cc
@@ -191,8 +191,8 @@ uint8_t XvAccelRender::GUI_XvInit(QWidget * window, uint32_t w, uint32_t h)
printf("\n Adaptator : %d", i);
printf("\n Base ID : %ld", curai->base_id);
printf("\n Nb Port : %lu", curai->num_ports);
- printf("\n Type : %d,",
- curai->type);
+ printf("\n Type : %d,", curai->type);
+
#define CHECK(x) if(curai->type & x) printf("|"#x);
CHECK(XvInputMask);
CHECK(XvOutputMask);
@@ -200,8 +200,7 @@ uint8_t XvAccelRender::GUI_XvInit(QWidget * window, uint32_t w, uint32_t h)
CHECK(XvStillMask);
CHECK(XvImageMask);
- printf("\n Name : %s",
- curai->name);
+ printf("\n Name : %s", curai->name);
printf("\n Num Adap : %lu", curai->num_adaptors);
printf("\n Num fmt : %lu", curai->num_formats);
#endif
@@ -213,7 +212,7 @@ uint8_t XvAccelRender::GUI_XvInit(QWidget * window, uint32_t w, uint32_t h)
for (k = 0; (k < curai->num_ports) && !port; k++)
{
if (GUI_XvList(WDN, k + curai->base_id, &xv_format))
- port = k + curai->base_id;
+ port = k + curai->base_id + 1; // FIXME: TODO: HACK: It works when +1 is applied! But why!?
}