summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2006-04-14 14:37:56 +0000
committerdeva <deva>2006-04-14 14:37:56 +0000
commitafdd0a07be6a669cdd8343fc033f170395b470c0 (patch)
treef5422200c992ae43e9aef42136aab24578fbbfd0
parente5dc1f42337228bf367ae8ea28469a8eef4861bd (diff)
*** empty log message ***
-rw-r--r--client/control.cc19
-rw-r--r--client/control.h5
-rw-r--r--client/decoder.cc35
-rw-r--r--client/decoder.h7
-rw-r--r--client/mainwindow.cc5
-rw-r--r--client/mainwindow.h6
-rw-r--r--client/miav_client.cc3
-rw-r--r--client/player.cc25
-rw-r--r--client/player.h2
9 files changed, 67 insertions, 40 deletions
diff --git a/client/control.cc b/client/control.cc
index 143e11c..92bd74c 100644
--- a/client/control.cc
+++ b/client/control.cc
@@ -87,6 +87,13 @@ void Control::stop()
mutex.unlock();
}
+void Control::takeScreenshot()
+{
+ mutex.lock();
+ screenshot = true;
+ mutex.unlock();
+}
+
bool Control::isFrozen()
{
bool isfrozen;
@@ -105,8 +112,16 @@ bool Control::isRecording()
return isrecording;
}
+bool Control::isScreenshot()
+{
+ bool isscreenshot;
+ mutex.lock();
+ isscreenshot = screenshot;
+ screenshot = false;
+ mutex.unlock();
+ return isscreenshot;
+}
+
// Global control object
Control MIaV::control;
-
-
diff --git a/client/control.h b/client/control.h
index 5f28f0a..a72ed82 100644
--- a/client/control.h
+++ b/client/control.h
@@ -29,7 +29,6 @@
#include <QMutex>
#include <QString>
-#include <QImage>
/**
* Class for the global control object.
@@ -52,9 +51,13 @@ public:
bool isFrozen();
bool isRecording();
+ bool isScreenshot();
+ void takeScreenshot();
+
private:
bool frozen;
bool recording;
+ bool screenshot;
QMutex mutex;
QString cpr;
diff --git a/client/decoder.cc b/client/decoder.cc
index ea67d68..1193710 100644
--- a/client/decoder.cc
+++ b/client/decoder.cc
@@ -42,15 +42,19 @@
#include "control.h"
-Decoder::Decoder(): semaphore(1)
+#include "libdv_wrapper.h"
+
+Decoder::Decoder(): semaphore(1), screenshotsemaphore(1)
{
frame = NULL;
running = true;
qApp->installEventFilter(this);
+ screenshotsemaphore.acquire(); // Lock the screenshot method
}
Decoder::~Decoder()
-{}
+{
+}
void Decoder::run()
{
@@ -63,9 +67,16 @@ 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();
+ }
+
if(MIaV::control.isFrozen() == false) {
mutex.lock();
if(frame) free(frame);
@@ -93,10 +104,24 @@ char *Decoder::getFrame()
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.
+ // 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.
+ }
}
-
+
// 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 6638189..0913858 100644
--- a/client/decoder.h
+++ b/client/decoder.h
@@ -31,6 +31,8 @@
#include <QSemaphore>
#include <QMutex>
+#include "dv.h"
+
class Decoder : public QThread
{
Q_OBJECT
@@ -42,6 +44,8 @@ public:
void run();
+ void snapshot(char *rgb);
+
protected:
bool eventFilter(QObject *o, QEvent *e);
@@ -49,6 +53,9 @@ private:
volatile bool running;
char *frame;
QSemaphore semaphore;
+
+ char screenshotframe[DVPACKAGE_SIZE];
+ QSemaphore screenshotsemaphore;
QMutex mutex;
};
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index 49cd634..8d7c04f 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -165,12 +165,11 @@ void MainWindow::snapshot_clicked()
char rgb[720 * 576 * 4];
- QImage *screenshot = new QImage((uchar*)rgb, 720, 576, QImage::Format_RGB32);
+ QImage screenshot((uchar*)rgb, 720, 576, QImage::Format_RGB32);
decoder->snapshot(rgb);
QPixmap *p = new QPixmap();
- *p = QPixmap::fromImage(*screenshot);
- delete screenshot;
+ *p = QPixmap::fromImage(screenshot);
history->addHistoryItem(new HistoryWidget(p));
}
diff --git a/client/mainwindow.h b/client/mainwindow.h
index e3a4411..9425d40 100644
--- a/client/mainwindow.h
+++ b/client/mainwindow.h
@@ -33,6 +33,8 @@
#include "historyframe.h"
#include "videowidget.h"
+#include "decoder.h"
+
/**
* Images
*/
@@ -56,7 +58,7 @@ class MainWindow : public QWidget
{
Q_OBJECT
public:
- MainWindow();
+ MainWindow(Decoder *decoder);
~MainWindow();
QWidget *getVideoWidget() { return video; }
@@ -71,6 +73,8 @@ public slots:
void mute_clicked();
private:
+ Decoder *decoder;
+
HistoryFrame *history;
VideoWidget *video;
diff --git a/client/miav_client.cc b/client/miav_client.cc
index 81cde56..e34eaf6 100644
--- a/client/miav_client.cc
+++ b/client/miav_client.cc
@@ -45,10 +45,9 @@ int main(int argc, char *argv[])
InfoGui info(MIaV::config);
MIaV::initInfo(&info);
- MainWindow mainwindow;
-
NetworkSender sender;
Decoder decoder;
+ MainWindow mainwindow(&decoder);
Player player(mainwindow.getVideoWidget(), &decoder);
int fps = 24;
diff --git a/client/player.cc b/client/player.cc
index 5ee0ccd..ba2250f 100644
--- a/client/player.cc
+++ b/client/player.cc
@@ -56,33 +56,10 @@ void Player::show_frame()
frame = decoder->getFrame();
if(frame) {
dvdecoder.decode(frame);
- free(frame);
+ // free(frame);
}
render.width = widget->width();
render.height = widget->height();
render.display(WIDTH, HEIGHT);
}
-
-//Hmm ... is this how it should work?
-void Player::getScreenShot(QImage *image)
-{
- double R, G, B;
- double Y, U, V;
-
- char *yuv = render.getDisplayData();
-
- for(int x = 0; x < WIDTH; x++) {
- for(int y = 0; y < HEIGHT; y++) {
- Y = yuv[(x + y * WIDTH)];
- U = yuv[(x + y * WIDTH)];
- V = yuv[(x + y * WIDTH)];
-
- R = Y + 1.4075 * (V - 128);
- G = Y - (0.3455 * (U - 128)) - (0.7169 * (V - 128));
- B = Y + 1.7790 * (U - 128);
- // QRgb qRgb((unsigned int)R,(unsigned int)G,(unsigned int)B);
- image->setPixel(x, y, qRgb((unsigned int)R,(unsigned int)G,(unsigned int)B));
- }
- }
- }
diff --git a/client/player.h b/client/player.h
index 84c2674..4aedb05 100644
--- a/client/player.h
+++ b/client/player.h
@@ -50,8 +50,6 @@ public:
Player(QWidget *widget, Decoder *decoder);
~Player();
- void getScreenShot(QImage *image);
-
public slots:
void show_frame();