summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/decoder.cc26
-rw-r--r--client/decoder.h14
-rw-r--r--client/mainwindow.cc16
-rw-r--r--client/mainwindow.h3
-rw-r--r--client/networksender.cc37
-rw-r--r--client/networksender.h6
6 files changed, 94 insertions, 8 deletions
diff --git a/client/decoder.cc b/client/decoder.cc
index 0ed2032..c5b2876 100644
--- a/client/decoder.cc
+++ b/client/decoder.cc
@@ -85,8 +85,19 @@ void Decoder::run()
sender->start();
newconnection = false;
}
- senders.front()->pushFrame(frame, false, false);
+ senders.back()->pushFrame(frame, false, false);
} else {
+ // Remove idle senders
+ QLinkedList<NetworkSender*>::iterator i;
+ for (i = senders.begin(); i != senders.end(); i++) {
+ NetworkSender *ns = *i;
+ if(ns->queueSize() == 0) {
+ i = senders.erase(i);
+ ns->stop();
+ delete ns;
+ }
+ }
+
free(frame);
newconnection = true;
}
@@ -129,3 +140,16 @@ bool Decoder::eventFilter(QObject *o, QEvent *e)
// standard event processing
return false;
}
+
+Status Decoder::status()
+{
+ Status s;
+
+ QLinkedList<NetworkSender*>::iterator i;
+ for(i = senders.begin(); i != senders.end(); i++) {
+ NetworkSender *ns = *i;
+ s.queue_sizes.push_back(ns->queueSize());
+ }
+
+ return s;
+}
diff --git a/client/decoder.h b/client/decoder.h
index 26d86d7..717f10a 100644
--- a/client/decoder.h
+++ b/client/decoder.h
@@ -31,11 +31,19 @@
#include <QSemaphore>
#include <QMutex>
-#include <QList>
+#include <QLinkedList>
+//#include <QList>
#include "dv.h"
#include "networksender.h"
+class Status {
+public:
+ QList<unsigned int> queue_sizes;
+ unsigned int server_diskspace;
+ unsigned int server_ping;
+};
+
class Decoder : public QThread
{
Q_OBJECT
@@ -52,6 +60,8 @@ public:
char *pframeAcquire();
void pframeRelease();
+ Status status();
+
protected:
bool eventFilter(QObject *o, QEvent *e);
@@ -64,7 +74,7 @@ private:
QMutex mutex;
- QList<NetworkSender *> senders;
+ QLinkedList<NetworkSender *> senders;
};
#endif/*__MIAV_DECODER_H__*/
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index da2785b..0e7270d 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -134,6 +134,7 @@ MainWindow::MainWindow(Decoder *d)
statusbar = new QStatusBar(this);
outerlayout->addWidget(statusbar, 1,0, 1,1);
statusbar->showMessage("Ready!");
+ startTimer(100);
show();
// setWindowState(Qt::WindowFullScreen);
@@ -151,6 +152,21 @@ MainWindow::~MainWindow()
MIaV::info->log("MIaV is shut down.");
}
+void MainWindow::timerEvent(QTimerEvent *event)
+{
+ Status s = decoder->status();
+ QString statusmsg;
+
+ for(int cnt = 0; cnt < s.queue_sizes.size(); cnt++) {
+ QString next;
+ next.sprintf("(%d)", s.queue_sizes[cnt]);
+ statusmsg.prepend(next);
+ }
+
+ statusbar->showMessage(statusmsg);
+}
+
+
void MainWindow::about_clicked()
{
AboutWindow about;
diff --git a/client/mainwindow.h b/client/mainwindow.h
index b94f5c5..f02d60f 100644
--- a/client/mainwindow.h
+++ b/client/mainwindow.h
@@ -47,6 +47,9 @@ public:
QWidget *getVideoWidget() { return video; }
+protected:
+ void timerEvent(QTimerEvent *event);
+
public slots:
void cpr_clicked();
void clear_clicked();
diff --git a/client/networksender.cc b/client/networksender.cc
index 675bdb9..2f1d8b0 100644
--- a/client/networksender.cc
+++ b/client/networksender.cc
@@ -28,17 +28,28 @@
#include "info.h"
+#include <util.h>
+
NetworkSender::NetworkSender(QString cpr)
{
ip = "192.168.0.10";
port = 6666;
// Connect
+ // sleep(1);
+
+ fprintf(stderr, "Connect [%p]\n", this);
}
NetworkSender::~NetworkSender()
{
// Disconnect
+ sleep_1_frame();
+ sleep_1_frame();
+ sleep_1_frame();
+ sleep_1_frame();
+
+ fprintf(stderr, "Disconnect [%p]\n", this);
}
void NetworkSender::pushFrame(char* framedata, bool freeze, bool snapshot)
@@ -54,10 +65,21 @@ void NetworkSender::pushFrame(char* framedata, bool freeze, bool snapshot)
semaphore.release();
}
+unsigned int NetworkSender::queueSize()
+{
+ unsigned int sz;
+
+ mutex.lock();
+ sz = framelist.size();
+ mutex.unlock();
+
+ return sz;
+}
+
void NetworkSender::run()
{
while(running) {
- semaphore.acquire();
+ if(queueSize()) semaphore.acquire();
Frame *frame = NULL;
mutex.lock();
@@ -66,8 +88,19 @@ void NetworkSender::run()
if(frame) {
// TODO: Send it over the network
-
+ sleep_1_frame();
+ sleep_1_frame();
+ sleep_1_frame();
+ sleep_1_frame();
delete frame;
}
}
+ terminatesemaphore.release(); // Signal the stop method that the thread has stopped running.
+}
+
+void NetworkSender::stop()
+{
+ running = false;
+ semaphore.release(); // Kick the thread active
+ terminatesemaphore.acquire(); // Wait for the thread to stop
}
diff --git a/client/networksender.h b/client/networksender.h
index 43bb797..a25dfaf 100644
--- a/client/networksender.h
+++ b/client/networksender.h
@@ -41,11 +41,11 @@ public:
NetworkSender(QString cpr);
~NetworkSender();
- void newConnection(QString cpr);
void pushFrame(char* frame, bool freeze, bool snapshot);
- void endConnection();
+ unsigned int queueSize();
void run();
+ void stop();
private:
QString ip;
@@ -54,9 +54,9 @@ private:
volatile bool running;
QMutex mutex;
+ QSemaphore terminatesemaphore;
QSemaphore semaphore;
QLinkedList<Frame*> framelist;
-
};
#endif/*__MIAV_NETWORKSENDER_H__*/