summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/decoder.cc30
-rw-r--r--client/decoder.h9
-rw-r--r--client/networksender.cc76
-rw-r--r--client/networksender.h25
-rw-r--r--client/status.h4
-rw-r--r--client/statusbar.cc50
-rw-r--r--client/statusbar.h7
7 files changed, 123 insertions, 78 deletions
diff --git a/client/decoder.cc b/client/decoder.cc
index afc09c9..a86dbd6 100644
--- a/client/decoder.cc
+++ b/client/decoder.cc
@@ -30,7 +30,7 @@
#include "transcoder.h"
-#define READ_DV_FROM_FILE
+//#define READ_DV_FROM_FILE
#include "dv.h"
#ifdef READ_DV_FROM_FILE
@@ -191,32 +191,24 @@ bool Decoder::eventFilter(QObject *o, QEvent *e)
return false;
}
-Status Decoder::status()
+std::vector<thread_status_t> Decoder::status()
{
- Status s;
-
- s.server_diskspace = 0xffffffff;
- s.server_diskspace_max = 0xffffffff;
- s.server_load = 0xffffffff;
- s.server_load_max = 0xffffffff;
- s.server_ping_ms = 0xffffffff;
- s.server_fps = -1.0;
+ std::vector<thread_status_t> v;
sendersmutex.lock();
- // Get the server disk status etc.
- if(senders.isEmpty() == false) senders.back()->getServerStatus(&s);
-
- // fprintf(stderr, "Load: %d of %d - ", s.server_load, s.server_load_max);
- // fprintf(stderr, "Space: %d of %d\n", s.server_diskspace, s.server_diskspace_max);
-
- // Read out the queue sizes
QLinkedList<NetworkSender*>::iterator i;
for(i = senders.begin(); i != senders.end(); i++) {
NetworkSender *ns = *i;
- s.queue_sizes.push_back(ns->queueSize());
+
+ // TODO: Cleanup (get both in one call)
+ thread_status_t s;
+ s.queuelen = ns->queueSize();
+ s.fps = ns->getfps();
+
+ v.push_back(s);
}
sendersmutex.unlock();
- return s;
+ return v;
}
diff --git a/client/decoder.h b/client/decoder.h
index 99cdd58..50c0307 100644
--- a/client/decoder.h
+++ b/client/decoder.h
@@ -36,7 +36,12 @@
#include "dv.h"
#include "networksender.h"
-#include "status.h"
+#include <vector>
+
+typedef struct {
+ double fps;
+ int queuelen;
+} thread_status_t;
class Decoder : public QThread
{
@@ -55,7 +60,7 @@ public:
void pframeAcquire();
void pframeRelease();
- Status status();
+ std::vector<thread_status_t> status();
protected:
bool eventFilter(QObject *o, QEvent *e);
diff --git a/client/networksender.cc b/client/networksender.cc
index e51fbe3..0aa1036 100644
--- a/client/networksender.cc
+++ b/client/networksender.cc
@@ -25,35 +25,41 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
#include "networksender.h"
-#include "status.h"
#include "configuration.h"
#include "info.h"
+#include <sys/time.h>
+
#include <util.h>
NetworkSender::NetworkSender(QString cpr)
{
if(MIaV::config->get("server_addr", &ip))
- MIaV::info->error("Could not read the symbol [server_addr] from the donf file!");
+ MIaV::info->error("Could not read the symbol [server_addr] from the conf file!");
if(MIaV::config->get("server_port", &port))
- MIaV::info->error("Could not read the symbol [server_port] from the donf file!");
+ MIaV::info->error("Could not read the symbol [server_port] from the conf file!");
// Connect
- socket = new Socket(port);
- socket->sconnect((char*)ip.c_str());
+ socket = new TCPSocket(port, ip);
+ if(socket->connect()) {
+ MIaV::info->error("Could not connect to %s on port %d because: %s",
+ ip.c_str(), port, socket->error().c_str());
+ }
network = new Network(socket);
- server_diskspace = 0xffffffff;
- server_diskspace_max = 0xffffffff;
- server_load = 0xffffffff;
- server_load_max = 0xffffffff;
- server_ping_ms = 0xffffffff;
- server_fps = -1.0;
+ fps = 0.0;
running = true;
+ gettimeofday(&oldtime, NULL);
+ for(int cnt = 0; cnt < BUFFERSIZE; cnt++) {
+ frametime[cnt] = 41660;
+ }
+ gettimeofday(&time, NULL);
+ interval = 0;
+
fprintf(stderr, "Connect [%p]\n", this);
}
@@ -115,20 +121,9 @@ void NetworkSender::run()
if(frame->aframe) delete frame->aframe;
delete frame;
- // Status status;
- // network->recvStatus(&status);
-
// Set status
statusmutex.lock();
- server_diskspace_max = 0;//status.diskspace_max;
- server_diskspace = 0;//status.server_diskspace;
- server_load = 0;//status.load;
- server_load_max = 0;//status.load_max;
-
- // TODO: Calculate these values.
- server_ping_ms = 0;
- server_fps = 0;
-
+ checkPoint();
statusmutex.unlock();
}
}
@@ -144,14 +139,35 @@ void NetworkSender::stop()
terminatesemaphore.acquire(); // Wait for the thread to stop
}
-void NetworkSender::getServerStatus(Status *status)
+double NetworkSender::getfps()
{
+ double f;
+
statusmutex.lock();
- status->server_diskspace = server_diskspace;
- status->server_diskspace_max = server_diskspace_max;
- status->server_load = server_load;
- status->server_load_max = server_load_max;
- status->server_ping_ms = server_ping_ms;
- status->server_fps = server_fps;
+ f = fps;
statusmutex.unlock();
+
+ return f;
}
+
+void NetworkSender::checkPoint()
+{
+ for(int cnt = BUFFERSIZE - 1; cnt > 0; cnt--) {
+ frametime[cnt] = frametime[cnt-1];
+ }
+
+ frametime[0] = (1000000 * time.tv_sec + time.tv_usec) - (1000000 * oldtime.tv_sec + oldtime.tv_usec);
+
+ oldtime.tv_sec = time.tv_sec;
+ oldtime.tv_usec = time.tv_usec;
+
+ gettimeofday(&time, NULL);
+
+ double total = 0.0;
+ for(int cnt = 0; cnt < BUFFERSIZE; cnt++) {
+ total += (double)frametime[cnt];
+ }
+ fps = 1000000.0 / (total / (double)BUFFERSIZE);
+
+}
+
diff --git a/client/networksender.h b/client/networksender.h
index 589004b..e752a18 100644
--- a/client/networksender.h
+++ b/client/networksender.h
@@ -35,13 +35,14 @@
#include <frame.h>
-#include "status.h"
-
-#include "socket.h"
+#include "tcp_socket.h"
#include "network.h"
#include <string>
+// How many steps to do avarage calculation over.
+#define BUFFERSIZE 100
+
class NetworkSender : public QThread
{
public:
@@ -54,10 +55,10 @@ public:
void run();
void stop();
- void getServerStatus(Status *status);
+ double getfps();
private:
- Socket *socket;
+ TCPSocket *socket;
Network *network;
std::string ip;
@@ -72,12 +73,14 @@ private:
// Server stats
QMutex statusmutex;
- unsigned int server_diskspace;
- unsigned int server_diskspace_max;
- unsigned int server_load;
- unsigned int server_load_max;
- unsigned int server_ping_ms;
- double server_fps;
+ double fps;
+
+ // Timer stuff (to calc the fps)
+ long long interval;
+ unsigned int frametime[BUFFERSIZE];
+ struct timeval time;
+ struct timeval oldtime;
+ void checkPoint();
};
#endif/*__MIAV_NETWORKSENDER_H__*/
diff --git a/client/status.h b/client/status.h
index a3ccad7..b91d673 100644
--- a/client/status.h
+++ b/client/status.h
@@ -26,7 +26,7 @@
*/
#ifndef __MIAV_STATUS_H__
#define __MIAV_STATUS_H__
-
+/*
#define UNKNOWN 0xffffffff
class Status {
@@ -40,5 +40,5 @@ public:
unsigned int server_ping_ms;
double server_fps;
};
-
+*/
#endif/*__MIAV_STATUS_H__*/
diff --git a/client/statusbar.cc b/client/statusbar.cc
index 1e25ebe..e49d45a 100644
--- a/client/statusbar.cc
+++ b/client/statusbar.cc
@@ -26,8 +26,21 @@
*/
#include "statusbar.h"
+#include "configuration.h"
+
+#include "info.h"
+
StatusBar::StatusBar(QWidget *parent, Decoder *decoder): QStatusBar(parent)
{
+ if(MIaV::config->get("server_addr", &ip))
+ MIaV::info->error("Could not read the symbol [server_addr] from the conf file!");
+
+ if(MIaV::config->get("server_port", &port))
+ MIaV::info->error("Could not read the symbol [server_port] from the conf file!");
+
+ // socket.setPort(port);
+ // socket.setAddress(ip);
+
this->decoder = decoder;
diskspace = new QProgressBar(this);
@@ -59,15 +72,23 @@ StatusBar::StatusBar(QWidget *parent, Decoder *decoder): QStatusBar(parent)
startTimer(100);
}
+#define UNKNOWN 0
void StatusBar::timerEvent(QTimerEvent *event)
{
- Status s = decoder->status();
+ UDPSocket socket(port, ip);
+
+ status_request_t request;
+ status_t status;
+ if(socket.write(&request, sizeof(request))==-1) fprintf(stderr, "ERROR! WRITE %s\n", socket.error().c_str());
+ if(socket.read(&status, sizeof(status))==-1) fprintf(stderr, "ERROR! READ %s\n", socket.error().c_str());
+
+ std::vector<thread_status_t> s = decoder->status();
QString statusmsg;
- if(s.queue_sizes.size() > 0) {
- for(int cnt = 0; cnt < s.queue_sizes.size(); cnt++) {
+ if(s.size() > 0) {
+ for(int cnt = 0; cnt < s.size(); cnt++) {
QString next;
- next.sprintf("[%d]", s.queue_sizes[cnt]);
+ next.sprintf("[%d]", s[cnt].queuelen);
statusmsg.prepend(next);
}
statusmsg.prepend("Queue: ");
@@ -77,24 +98,25 @@ void StatusBar::timerEvent(QTimerEvent *event)
}
QString dummy;
- if(s.server_ping_ms != UNKNOWN) ping->setText(dummy.sprintf("ping %d ms", s.server_ping_ms));
- else ping->setText("ping N/A");
-
- if(s.server_fps != -1) fps->setText(dummy.sprintf("fps %.2f", s.server_fps));
+ if(s.size() && s[0].fps != -1) fps->setText(dummy.sprintf("fps %.2f", s[0].fps));
else fps->setText("fps N/A");
- if(s.server_diskspace_max != UNKNOWN) {
- diskspace->setRange(0, s.server_diskspace_max);
- diskspace->setValue(s.server_diskspace);
+ /*
+ if(s.server_ping_ms != UNKNOWN) ping->setText(dummy.sprintf("ping %d ms", s.server_ping_ms));
+ else ping->setText("ping N/A");
+ */
+ if(status.diskspace_max != UNKNOWN) {
+ diskspace->setRange(0, status.diskspace_max);
+ diskspace->setValue(status.diskspace);
diskspace->setEnabled(true);
} else {
diskspace->setRange(0, 0);
diskspace->setEnabled(false);
}
- if(s.server_load_max != UNKNOWN) {
- load->setRange(0, s.server_load_max);
- load->setValue(s.server_load);
+ if(status.load_max != UNKNOWN) {
+ load->setRange(0, status.load_max);
+ load->setValue(status.load);
load->setEnabled(true);
} else {
load->setRange(0, 0);
diff --git a/client/statusbar.h b/client/statusbar.h
index 1b0a2c5..991483c 100644
--- a/client/statusbar.h
+++ b/client/statusbar.h
@@ -34,6 +34,9 @@
#include <QLabel>
#include <QProgressBar>
+#include <string>
+#include "udp_socket.h"
+
class StatusBar : public QStatusBar
{
public:
@@ -47,6 +50,10 @@ protected:
private:
Decoder *decoder;
+ std::string ip;
+ int port;
+ // UDPSocket socket;
+
// Content
QLabel *messagefield;
QProgressBar *diskspace;