diff options
author | deva <deva> | 2006-05-25 18:18:48 +0000 |
---|---|---|
committer | deva <deva> | 2006-05-25 18:18:48 +0000 |
commit | d86028ba3e6c0db3c1f56077f481b3bebf883d86 (patch) | |
tree | 4d53aa133d92b40f7de46ac07f9817111379166a /client | |
parent | 7d547a29164cf9318a7eca918705bbc30e93b81d (diff) |
*** empty log message ***
Diffstat (limited to 'client')
-rw-r--r-- | client/decoder.cc | 35 | ||||
-rw-r--r-- | client/decoder.h | 9 | ||||
-rw-r--r-- | client/mainwindow.cc | 37 | ||||
-rw-r--r-- | client/mainwindow.h | 5 | ||||
-rw-r--r-- | client/networksender.cc | 37 | ||||
-rw-r--r-- | client/networksender.h | 13 | ||||
-rw-r--r-- | client/status.h | 42 |
7 files changed, 167 insertions, 11 deletions
diff --git a/client/decoder.cc b/client/decoder.cc index c5b2876..d8bf430 100644 --- a/client/decoder.cc +++ b/client/decoder.cc @@ -81,12 +81,25 @@ void Decoder::run() if(MIaV::control.isRecording()) { if(newconnection) { NetworkSender *sender = new NetworkSender(MIaV::control.getCpr()); + + sendersmutex.lock(); senders.push_back(sender); + sendersmutex.unlock(); + sender->start(); newconnection = false; } - senders.back()->pushFrame(frame, false, false); + + sendersmutex.lock(); + if(senders.isEmpty() == false) + senders.back()->pushFrame(frame, + MIaV::control.isFrozen(), + false); + sendersmutex.unlock(); + } else { + + sendersmutex.lock(); // Remove idle senders QLinkedList<NetworkSender*>::iterator i; for (i = senders.begin(); i != senders.end(); i++) { @@ -97,6 +110,8 @@ void Decoder::run() delete ns; } } + sendersmutex.unlock(); + free(frame); newconnection = true; @@ -107,7 +122,7 @@ void Decoder::run() char *Decoder::pframeAcquire() { - pmutex.lock(); + pmutex.lock();; return pframe; } @@ -145,11 +160,27 @@ Status 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; + + 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()); } + sendersmutex.unlock(); return s; } diff --git a/client/decoder.h b/client/decoder.h index 717f10a..2f8d575 100644 --- a/client/decoder.h +++ b/client/decoder.h @@ -32,17 +32,11 @@ #include <QMutex> #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; -}; +#include "status.h" class Decoder : public QThread { @@ -75,6 +69,7 @@ private: QMutex mutex; QLinkedList<NetworkSender *> senders; + QMutex sendersmutex; }; #endif/*__MIAV_DECODER_H__*/ diff --git a/client/mainwindow.cc b/client/mainwindow.cc index 0e7270d..a158c09 100644 --- a/client/mainwindow.cc +++ b/client/mainwindow.cc @@ -133,7 +133,22 @@ MainWindow::MainWindow(Decoder *d) // Create statusbar statusbar = new QStatusBar(this); outerlayout->addWidget(statusbar, 1,0, 1,1); - statusbar->showMessage("Ready!"); + + server_diskspace = new QProgressBar(statusbar); + server_diskspace->setRange(0, 100); + server_diskspace->setValue(0); + + server_load = new QProgressBar(statusbar); + server_load->setRange(0, 100); + server_load->setValue(0); + + messagefield = new QLabel(statusbar); + + statusbar->addWidget(messagefield, 80); + statusbar->addWidget(server_diskspace, 10); + statusbar->addWidget(server_load, 10); + + // statusbar->showMessage("Ready!"); startTimer(100); show(); @@ -163,7 +178,25 @@ void MainWindow::timerEvent(QTimerEvent *event) statusmsg.prepend(next); } - statusbar->showMessage(statusmsg); + messagefield->setText(statusmsg); + + if(s.server_diskspace_max != 0xffffffff) { + server_diskspace->setRange(0, s.server_diskspace_max); + server_diskspace->setValue(s.server_diskspace); + server_diskspace->setEnabled(true); + } else { + server_diskspace->setRange(0, 0); + server_diskspace->setEnabled(false); + } + + if(s.server_load_max != 0xffffffff) { + server_load->setRange(0, s.server_load_max); + server_load->setValue(s.server_load); + server_load->setEnabled(true); + } else { + server_load->setRange(0, 0); + server_load->setEnabled(false); + } } diff --git a/client/mainwindow.h b/client/mainwindow.h index f02d60f..5b38397 100644 --- a/client/mainwindow.h +++ b/client/mainwindow.h @@ -33,6 +33,8 @@ #include <QLabel> #include <QStatusBar> +#include <QProgressBar> + #include "historyframe.h" #include "videowidget.h" @@ -81,6 +83,9 @@ private: // Statusbar QStatusBar *statusbar; + QLabel *messagefield; + QProgressBar *server_diskspace; + QProgressBar *server_load; }; #endif/*__MIAV_MAINWINDOW_H__*/ diff --git a/client/networksender.cc b/client/networksender.cc index 2f1d8b0..dcb1919 100644 --- a/client/networksender.cc +++ b/client/networksender.cc @@ -37,6 +37,14 @@ NetworkSender::NetworkSender(QString cpr) // Connect // sleep(1); + server_diskspace = 0xffffffff; + server_diskspace_max = 0xffffffff; + server_load = 0xffffffff; + server_load_max = 0xffffffff; + server_ping_ms = 0xffffffff; + server_fps = -1.0; + + running = true; fprintf(stderr, "Connect [%p]\n", this); } @@ -78,6 +86,8 @@ unsigned int NetworkSender::queueSize() void NetworkSender::run() { + fprintf(stderr, " Run %p\n", this); + while(running) { if(queueSize()) semaphore.acquire(); @@ -93,9 +103,24 @@ void NetworkSender::run() sleep_1_frame(); sleep_1_frame(); delete frame; + + // TODO: Read status from network + // Set status + statusmutex.lock(); + server_diskspace_max = 1000000; + if(server_diskspace == 0xffffffff) server_diskspace = server_diskspace_max; + server_diskspace -= (int)(((double)rand() / (double)RAND_MAX) * 10.0); + + server_load = 90 + (int)(((double)rand() / (double)RAND_MAX) * 10.0); + server_load_max = 100; + server_ping_ms = (int)(((double)rand() / (double)RAND_MAX) * 100); + server_fps = 25.0; + statusmutex.unlock(); } } terminatesemaphore.release(); // Signal the stop method that the thread has stopped running. + + fprintf(stderr, " Stop %p\n", this); } void NetworkSender::stop() @@ -104,3 +129,15 @@ void NetworkSender::stop() semaphore.release(); // Kick the thread active terminatesemaphore.acquire(); // Wait for the thread to stop } + +void NetworkSender::getServerStatus(Status *status) +{ + 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; + statusmutex.unlock(); +} diff --git a/client/networksender.h b/client/networksender.h index a25dfaf..e3beb5a 100644 --- a/client/networksender.h +++ b/client/networksender.h @@ -35,6 +35,8 @@ #include <frame.h> +#include "status.h" + class NetworkSender : public QThread { public: @@ -47,6 +49,8 @@ public: void run(); void stop(); + void getServerStatus(Status *status); + private: QString ip; unsigned short port; @@ -57,6 +61,15 @@ private: QSemaphore terminatesemaphore; QSemaphore semaphore; QLinkedList<Frame*> framelist; + + // 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; }; #endif/*__MIAV_NETWORKSENDER_H__*/ diff --git a/client/status.h b/client/status.h new file mode 100644 index 0000000..6a7bca2 --- /dev/null +++ b/client/status.h @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * status.h + * + * Thu May 25 12:40:31 CEST 2006 + * Copyright 2006 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MIaV is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __MIAV_STATUS_H__ +#define __MIAV_STATUS_H__ + +class Status { +public: + QList<unsigned int> queue_sizes; + + 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; +}; + +#endif/*__MIAV_STATUS_H__*/ |