summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authordeva <deva>2006-03-06 19:14:16 +0000
committerdeva <deva>2006-03-06 19:14:16 +0000
commit8daee5ab8d878fb1819ba6b615e6ee96a4a11742 (patch)
tree9ba9d5bbb1ffec8e4689f2dcf14092692a5b33d3 /client
parentbbc621fdb9ad7cebba643145e7d923a0998bf59f (diff)
*** empty log message ***
Diffstat (limited to 'client')
-rw-r--r--client/Makefile.am6
-rw-r--r--client/aboutwindow.cc4
-rw-r--r--client/camera.cc182
-rw-r--r--client/camera.h109
-rw-r--r--client/decoder.cc286
-rw-r--r--client/decoder.h99
-rw-r--r--client/encoder.cc273
-rw-r--r--client/encoder.h118
-rw-r--r--client/mainwindow.cc14
-rw-r--r--client/player.cc322
-rw-r--r--client/player.h142
11 files changed, 12 insertions, 1543 deletions
diff --git a/client/Makefile.am b/client/Makefile.am
index 4a86c37..001916c 100644
--- a/client/Makefile.am
+++ b/client/Makefile.am
@@ -9,13 +9,12 @@ bin_PROGRAMS = miav_client
miav_client_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; fi ) \
miav_client.cc \
aboutwindow.cc \
- camera.cc \
cprlisten.cc \
cprquerydialog.cc \
decoder.cc \
dv1394.cc \
dvfile.cc \
- encoder.cc \
+ networksender.cc \
historywidget.cc \
info_gui.cc \
mainwindow.cc \
@@ -26,7 +25,6 @@ miav_client_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; f
EXTRA_DIST = \
aboutwindow.h \
- camera.h \
config.h \
cprlisten.h \
cprquerydialog.h \
@@ -34,7 +32,7 @@ EXTRA_DIST = \
decoder.h \
dv1394.h \
dvfile.h \
- encoder.h \
+ networksender.h \
historywidget.h \
info_gui.h \
mainwindow.h \
diff --git a/client/aboutwindow.cc b/client/aboutwindow.cc
index 849608d..9be7c32 100644
--- a/client/aboutwindow.cc
+++ b/client/aboutwindow.cc
@@ -44,7 +44,9 @@ AboutWindow::AboutWindow( QWidget* parent)
resize(pix_about->width(), pix_about->height());
- // setBackgroundColor(QColor(200,200,200));
+ QPalette palette;
+ palette.setColor(backgroundRole(), QColor(200,200,200));
+ setPalette(palette);
btn_ok = new QPushButton(this);
btn_ok->setText("OK");
diff --git a/client/camera.cc b/client/camera.cc
deleted file mode 100644
index 5dbec13..0000000
--- a/client/camera.cc
+++ /dev/null
@@ -1,182 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * camera.cc
- *
- * Fri Oct 29 12:46:38 CEST 2004
- * Copyright 2004 Bent Bisballe
- * 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.
- */
-#include <config.h>
-#ifdef USE_GUI
-
-#include "camera.h"
-
-Camera::Camera(Info *ginfo)
-{
- info = ginfo;
-}
-
-void Camera::connect(const char *ip, const int port, int width, int height)
-{
- initialized = false;
-
- pthread_mutex_init (&mutex, NULL);
- //mutex = PTHREAD_MUTEX_INITIALIZER;
-
- running = 1;
-
- encode_queue = new Queue<Frame>(); // infinite size
- player_queue = new Queue<Frame>(1); // fixed size of 1
-
- sem_init(&encode_sem, 0, 0);
- sem_init(&player_sem, 0, 0);
-
- decoder = new Decoder(info,
- &encode_sem,
- &player_sem,
- encode_queue,
- player_queue,
- &mutex,
- &running);
-
- encoder = new Encoder(info,
- ip, port,
- &encode_sem,
- encode_queue,
- &mutex,
- &running);
-
- player = new Player(info,
- width, height,
- &running,
- &player_sem,
- player_queue,
- &mutex);
-
- decoder->run();
- encoder->run();
- player->run();
-
- initialized = true;
-}
-
-Camera::~Camera()
-{
- // Signal to the threads to stop
- running = 0;
-
- // Wait for the threads to stop
- decoder->wait_stop();
- encoder->wait_stop();
- player->wait_stop();
-
- delete decoder;
- delete encoder;
- delete player;
-
- sem_destroy(&encode_sem);
- sem_destroy(&player_sem);
-
- delete player_queue;
- delete encode_queue;
-}
-
-void Camera::setCpr(char *newcpr, char* name)
-{
-
- if(initialized) {
- encoder->setCpr(newcpr);
- player->setCpr(newcpr, name); // For the text overlay
- } else {
- info->error("Camera not initialized.");
- }
-}
-
-
-void Camera::start()
-{
- if(initialized) {
- player->startrecord(); // For the text overlay
- encoder->start();
- decoder->start();
- } else {
- info->error("Camera not initialized.");
- }
-}
-
-void Camera::stop(n_savestate save)
-{
- if(initialized) {
- player->stoprecord(); // For the textoverlay
- encoder->stop(save);
- decoder->stop(save);
- } else {
- info->error("Camera not initialized.");
- }
-}
-
-void Camera::freeze()
-{
- if(initialized) {
- player->stop();
- decoder->freeze();
- } else {
- info->error("Camera not initialized.");
- }
-}
-
-void Camera::unfreeze()
-{
- if(initialized) {
- player->start();
- decoder->unfreeze();
- } else {
- info->error("Camera not initialized.");
- }
-}
-
-void Camera::snapshot(unsigned char *rgb)
-{
- if(initialized) {
- decoder->shoot(rgb);
- encoder->shoot();
- } else {
- info->error("Camera not initialized.");
- }
-}
-
-int Camera::getQueueLength()
-{
- return encode_queue->length();
-}
-
-void Camera::resize(int w, int h, bool s)
-{
- player->resize(w,h,s);
-}
-
-void Camera::setMute(bool mute)
-{
- decoder->setMute(mute);
- player->setMute(mute);
-}
-
-#endif/* USE_GUI */
diff --git a/client/camera.h b/client/camera.h
deleted file mode 100644
index 410b9f5..0000000
--- a/client/camera.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * camera.h
- *
- * Fri Oct 29 12:46:38 CEST 2004
- * Copyright 2004 Bent Bisballe
- * 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.
- */
-#include "config.h"
-#ifdef USE_GUI
-
-#ifndef __CAMERA_H__
-#define __CAMERA_H__
-
-#include <string>
-using namespace std;
-#include "info.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <getopt.h>
-//#include <avformat.h>
-
-#include "util.h"
-#include "queue.h"
-#include "decoder.h"
-#include "encoder.h"
-#include "player.h"
-#include "package.h"
-
-#include "thread.h"
-#include "frame.h"
-
-#include <QWidget>
-
-/**
- * This class represents the symbolic representation of the camera and
- * the network functionality.
- */
-class Camera {
-public:
- Camera(Info *ginfo);
- ~Camera();
- void connect(const char *ip,
- const int port,
- int width, int height);
-
- void setCpr(char *newcpr, char* name);
-
- // Camera actions
- void start();
- void stop(n_savestate save);
- void freeze();
- void unfreeze();
- void snapshot(unsigned char *rgb);
-
- int getQueueLength();
-
- // Indirect call to player->resize
- void resize(int width, int height, bool showtext);
-
- void setMute(bool mute);
-
-private:
- // Info object passed to all sub objects.
- Info *info;
- bool initialized;
-
- /* // No need for these anymore
- pthread_t playertid;
- pthread_t decodetid;
- pthread_t encodetid;
- */
- volatile int running;
-
- Encoder *encoder;
- Decoder *decoder;
- Player *player;
-
- Queue<Frame> *encode_queue;
- Queue<Frame> *player_queue;
- sem_t encode_sem;
- sem_t player_sem;
- pthread_mutex_t mutex;// = PTHREAD_MUTEX_INITIALIZER;
-};
-
-
-#endif/*__CAMERA_H__*/
-
-#endif/* USE_GUI */
diff --git a/client/decoder.cc b/client/decoder.cc
deleted file mode 100644
index 0d56aca..0000000
--- a/client/decoder.cc
+++ /dev/null
@@ -1,286 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * decoder.cc
- *
- * Sat Feb 19 17:05:43 CET 2005
- * Copyright 2005 Bent Bisballe
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * Originally from:
- * RTVideoRec Realtime video recoder and encoder for Linux
- *
- * Copyright (C) 2004 B. Stultiens
- * Copyright (C) 2004 Koen Otter and Glenn van der Meyden
- */
-
-/*
- * 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.
- */
-#include <config.h>
-#ifdef USE_GUI
-
-#include "frame_stream.h"
-
-#include "miav_config.h"
-
-#include <time.h>
-
-// Use libdv
-#include <libdv/dv.h>
-#include <libdv/dv_types.h>
-
-#include <SDL/SDL.h>
-
-#include "dv.h"
-#include "dvfile.h"
-#include "dv1394.h"
-
-#include "decoder.h"
-#include "debug.h"
-
-Decoder::Decoder(Info *ginfo,
- sem_t *gencode_sem,
- sem_t *gplayer_sem,
- Queue<Frame> *gencode_queue,
- Queue<Frame> *gplayer_queue,
- pthread_mutex_t *gmutex,
- volatile int *grunning)
-{
- info = ginfo;
-
- encode_sem = gencode_sem;
- player_sem = gplayer_sem;
- encode_queue = gencode_queue;
- player_queue = gplayer_queue;
- mutex = gmutex;
- running = grunning;
-
- b_shoot = false;
- b_freeze = false;
- b_record = false; // Initially no recording is done.
-
- pthread_mutex_init (&shot_mutex, NULL);
- shot = NULL;
-
- mute = false;
-}
-
-Decoder::~Decoder()
-{
- pthread_mutex_destroy(&shot_mutex);
-}
-
-void Decoder::decode()
-{
- frame_stream *dvstream;
-
- bool local_shoot;
- int local_freeze;
- bool local_record = false;
- bool old_record;
-
- bool skip_frames = config->readInt("player_skip_frames");
-
- dv1394 dv1394_stream = dv1394(info); // Use default port and channel.
- dvfile dvfile_stream = dvfile(info);
- if(dv1394_stream.connect()) {
- // Use the dv1394 stream for input.
- dvstream = &dv1394_stream;
- } else {
- // Use the fallback dv filereader for input.
- dvstream = &dvfile_stream;
- }
-
- while(*running) {
- uint8_t *ptr;
- SDL_Event user_event;
-
- // Read a dvframe
- ptr = dvstream->readFrame();
- if(!ptr) return; // No frame read. (Due to dv read error)
-
- old_record = local_record;
- local_shoot = b_shoot;
- b_shoot = false;
- local_freeze = b_freeze;
- b_freeze = false;
- local_record = b_record;
-
- if(local_shoot) {
- pthread_mutex_lock(&shot_mutex);
- if(!shot) shot = new Frame(ptr, DVPACKAGE_SIZE);
- pthread_mutex_unlock(&shot_mutex);
- }
-
- if(local_freeze == 1) {
- pthread_mutex_lock(&shot_mutex);
- if(shot) delete shot;
- shot = new Frame(ptr, DVPACKAGE_SIZE);
- pthread_mutex_unlock(&shot_mutex);
- }
-
- static int showframe = 1;
- if(skip_frames != 0) showframe = 1 - showframe;
- if(showframe) {
- Frame *pframe = new Frame(ptr, DVPACKAGE_SIZE);
-
- pframe->shoot = local_shoot;
- pframe->freeze = local_freeze;
- pframe->record = local_record;
-
- player_queue->push(pframe);
-
- // Create and send SDL event.
- user_event.type = SDL_USEREVENT;
- user_event.user.code = 0;
- user_event.user.data1 = NULL;
- user_event.user.data2 = NULL;
- SDL_PushEvent(&user_event);
- }
-
- if(local_record | (local_record != old_record) | local_shoot | local_freeze) {
- Frame *eframe = new Frame(NULL, 0);
- eframe->data = ptr;
- eframe->size = DVPACKAGE_SIZE;
-
- eframe->shoot = local_shoot;
- eframe->freeze = local_freeze;
- eframe->record = local_record;
- eframe->mute = mute;
-
- encode_queue->push(eframe);
-
- sem_post(encode_sem);
- } else {
- free(ptr);
- }
- }
-
- // Kick the others so they wake up with empty queues
- sem_post(encode_sem);
-}
-
-void Decoder::thread_main() {
- decode();
- fprintf(stderr, "Decoder thread stopped.\n"); fflush(stderr);
-}
-
-/*
- * Set freeze bit on current frame.
- */
-void Decoder::freeze()
-{
- b_freeze = 1;
-}
-
-/*
- * Remove frozen frame.
- */
-void Decoder::unfreeze()
-{
- b_freeze = -1;
-
- pthread_mutex_lock(&shot_mutex);
- delete shot;
- shot = NULL;
- pthread_mutex_unlock(&shot_mutex);
-}
-
-/*
- * Set shoot bit on current frame.
- */
-void Decoder::shoot(unsigned char *rgb)
-{
- struct timespec ts;
-
- b_shoot = true;
-
- // Wait for shot to be taken
- while(1) {
- pthread_mutex_lock(&shot_mutex);
- if(shot) {
- getScreenshot(shot, rgb);
- delete shot;
- shot = NULL;
- pthread_mutex_unlock(&shot_mutex);
- return;
- }
- pthread_mutex_unlock(&shot_mutex);
-
- ts.tv_sec = 0;
- ts.tv_nsec = 100000000L; // 100ms
- nanosleep(&ts, NULL);
- }
-}
-
-/*
- * Set the record bit to true in all following frames.
- */
-void Decoder::start()
-{
- b_record = true;
-}
-
-/*
- * Set the record bit to false in all following frames.
- */
-void Decoder::stop(n_savestate save)
-{
- b_record = false;
-}
-
-void Decoder::getScreenshot(Frame *frame, unsigned char *rgb)
-{
- unsigned char *pixels[3];
- int pitches[3];
-
- pixels[ 0 ] = rgb;
- pixels[ 1 ] = NULL;
- pixels[ 2 ] = NULL;
-
- pitches[ 0 ] = 720 * 4;
- pitches[ 1 ] = 0;
- pitches[ 2 ] = 0;
-
- dv_decoder_t *decoder = dv_decoder_new(FALSE/*this value is unused*/, FALSE, FALSE);
- decoder->quality = DV_QUALITY_BEST;
-
- dv_parse_header(decoder, frame->data);
-
- decoder->system = e_dv_system_625_50; // PAL lines, PAL framerate
- decoder->sampling = e_dv_sample_422; // 4 bytes y, 2 bytes u, 2 bytes v
- decoder->std = e_dv_std_iec_61834;
- decoder->num_dif_seqs = 12;
-
- // libdv img decode to rgb
- dv_decode_full_frame(decoder,
- frame->data,
- e_dv_color_bgr0,
- pixels,
- pitches);
-
- dv_decoder_free(decoder);
-}
-
-void Decoder::setMute(bool m)
-{
- mute = m;
-}
-
-#endif /*USE_GUI*/
diff --git a/client/decoder.h b/client/decoder.h
deleted file mode 100644
index 20878c7..0000000
--- a/client/decoder.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * decoder.h
- *
- * Sat Feb 19 17:05:42 CET 2005
- * Copyright 2005 Bent Bisballe
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * Originally from:
- * RTVideoRec Realtime video recoder and encoder for Linux
- *
- * Copyright (C) 2004 B. Stultiens
- */
-
-/*
- * 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.
- */
-#include "config.h"
-#ifdef USE_GUI
-
-#ifndef __RTVIDEOREC_DECODER_H
-#define __RTVIDEOREC_DECODER_H
-
-#include "info.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "queue.h"
-#include "encoder.h"
-#include "player.h"
-
-#include "thread.h"
-#include "frame.h"
-
-class Decoder : public Thread {
-public:
- Decoder(Info *ginfo,
- sem_t *gencode_sem,
- sem_t *gplayer_sem,
- Queue<Frame> *gencode_queue,
- Queue<Frame> *gplayer_queue,
- pthread_mutex_t *gmutex,
- volatile int *grunning);
- ~Decoder();
- void thread_main();
-
- void freeze();
- void unfreeze();
- void shoot(unsigned char *rgb);
- void start();
- void stop(n_savestate save);
- void setMute(bool mute);
-
-private:
- volatile bool mute;
-
- void getScreenshot(Frame *frame, unsigned char *rgb);
-
- pthread_mutex_t shot_mutex;
- Frame* shot;
-
- volatile int b_freeze;
- volatile bool b_shoot;
- volatile bool b_record;
-
- Info *info;
- // AVCodecContext dvcodec;
-
- sem_t *encode_sem;
- sem_t *player_sem;
- Queue<Frame> *encode_queue;
- Queue<Frame> *player_queue;
- pthread_mutex_t *mutex;
- volatile int *running;
-
- void decode();
-};
-
-#endif/* __RTVIDEOREC_DECODER_H*/
-
-#endif/*USE_GUI*/
diff --git a/client/encoder.cc b/client/encoder.cc
deleted file mode 100644
index e7b79bf..0000000
--- a/client/encoder.cc
+++ /dev/null
@@ -1,273 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * encoder.cc
- *
- * Tue Apr 19 12:10:34 CEST 2005
- * Copyright 2005 Bent Bisballe
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * Originally from:
- * RTVideoRec Realtime video recoder and encoder for Linux
- *
- * Copyright (C) 2004 B. Stultiens
- * Copyright (C) 2004 Koen Otter and Glenn van der Meyden
- */
-
-/*
- * 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.
- */
-#include <config.h>
-#ifdef USE_GUI
-
-#include "util.h"
-#include "encoder.h"
-
-Encoder::Encoder(Info *ginfo,
- const char *gip,
- const int gport,
- sem_t *gsem,
- Queue<Frame> *gqueue,
- pthread_mutex_t *gmutex,
- volatile int *grunning)
-{
- info = ginfo;
-
- strcpy(ip, gip);
- port = gport;
- memset(cpr, 0, sizeof(cpr));
-
- sem = gsem;
- queue = gqueue;
- mutex = gmutex;
- running = grunning;
-
- // record = 0;
-
- sem_init(&record_sem, 0, 0);
-
- s = NULL;
- n = NULL;
-
- frozen = false;
-
- savestate_sent = false;
- savestate = NO_CHANGE;
-
- // shoot_request = 0;
- // shoot_value = 0;
- // freeze_request = 0;
- // freeze_value = 0;
-}
-
-
-Encoder::~Encoder()
-{
- // If a hanging connection exists, we better close it.
- /* // Already deleted in thread_main
- if(s) {
- if(n) delete n;
- delete s;
- s = NULL;
- n = NULL;
- }
- */
-}
-
-
-void Encoder::encode()
-{
- Frame *frame;
-
- while(*running) {
- sem_wait(sem);
-
- frame = queue->pop();
-
- if(frame) {
- if(frame->freeze == 1) frozen = true;
- if(frame->freeze == -1) frozen = false;
- if(frame->shoot) frozen = false;
-
- if(frame->record ||
- (frame->freeze == 1) ||
- frame->shoot) {
-
- // If no connection is present, make a new one
- if(!s) {
- s = new Socket(port, info);
- s->sconnect(ip);
- n = new Network(s, info);
- }
-
- n_header h;
-
- if(savestate != NO_CHANGE) savestate_sent = true;
-
- h.header_type = DATA_HEADER;
- sprintf(h.header.h_data.cpr, cpr);
- h.header.h_data.freeze = frame->freeze;
- h.header.h_data.snapshot = frame->shoot;
- h.header.h_data.record = frame->record;
- h.header.h_data.savestate = savestate;//NO_CHANGE;
- h.header.h_data.mute = frame->mute;
-
- savestate = NO_CHANGE; // only transmit once!
-
- // if(freeze_request != freeze_value) freeze_value = freeze_request;
- // if(shoot_request != shoot_value) shoot_value = shoot_request;
-
- n->sendPackage(&h, frame->data, frame->size);
- } else {
- // When frozen we need to preserve the connection in order to
- // remember the frozen frame on the server side.
- if(!frozen) {
- // No data is to be sent, if we have a connection, destroy it.
- if(s) {
- if(n) delete n;
- delete s;
- s = NULL;
- n = NULL;
- }
- }
- }
-
- if(frame->shoot && !frozen && !frame->record) {
- // FIXME: This is ugly!
- // Bugfix... connection not cleared, when an 'unfrozen' snapshot is taken,
- // and no recording is done.
- if(s) {
- if(n) delete n;
- delete s;
- s = NULL;
- n = NULL;
- }
- }
-
- if(frame) delete frame;
- }
- }
-}
-
-
-void Encoder::setCpr(char *newcpr)
-{
- strcpy(cpr, newcpr);
-}
-
-
-void Encoder::freeze()
-{
- /*
- if(!s) {
- s = new Socket(port, errobj);
- s->sconnect(ip);
- n = new Network(s, errobj);
- }
- */
- // if(!errobj->hasError()) freeze_request = 1 - freeze_request;
-}
-
-
-/*
- * shoot
- * Set the shoot bit in the network header on the current frame.
- * return the decodet (rgba) version af that frame, for thumbnail show.
- */
-void Encoder::shoot()
-{
- /*
- if(!s) {
- s = new Socket(port, errobj);
- s->sconnect(ip);
- n = new Network(s, errobj);
- }
- */
- // if(!errobj->hasError()) shoot_request = 1 - shoot_request;
- // getScreenshot(rgb);
-}
-
-
-void Encoder::thread_main()
-{
- encode();
- if(s) {
- if(n) delete n;
- delete s;
- s = NULL;
- n = NULL;
- }
- fprintf(stderr, "Encoder thread stopped.\n"); fflush(stderr);
-}
-
-
-void Encoder::start()
-{
- savestate = NO_CHANGE;
- savestate_sent = false;
- /*
- if(!s) {
- s = new Socket(port, errobj);
- s->sconnect(ip);
- n = new Network(s, errobj);
- }
- */
- // if(!errobj->hasError()) record = 1;
-}
-
-
-void Encoder::stop(n_savestate save)
-{
- savestate = save;
- // Don't return until we are sure the savestate has been sent.
- while(savestate_sent == false) {
- // Just wait a while (in a while!)
- sleep_0_2_frame();
- }
-/*
- struct timespec ts;
- // TODO: set save state in package header.
-
- // Lock the queue and wait until all elements are sent on the network.
- queue->lock();
- fprintf(stderr, "Emptying queue"); fflush(stderr);
- while(queue->peek()) {
- // Remove any late buffer
- // We don't care, the encoder finishes them all
- ts.tv_sec = 0;
- ts.tv_nsec = 500000000L; // 100ms
- fprintf(stderr, "."); fflush(stderr);
- nanosleep(&ts, NULL);
- }
- fprintf(stderr, "done!\n"); fflush(stderr);
-
- record = 0;
-
- queue->unlock();
-*/
-/*
- if(s) {
- if(n) delete n;
- delete s;
- s = NULL;
- n = NULL;
- }
-*/
-}
-
-#endif /*USE_GUI*/
diff --git a/client/encoder.h b/client/encoder.h
deleted file mode 100644
index de29646..0000000
--- a/client/encoder.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * encoder.h
- *
- * Thu Apr 14 19:29:55 CEST 2005
- * Copyright 2005 Bent Bisballe
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * Originally from:
- * RTVideoRec Realtime video recoder and encoder for Linux
- *
- * Copyright (C) 2004 B. Stultiens
- */
-
-/*
- * 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.
- */
-#include "config.h"
-#ifdef USE_GUI
-
-#ifndef __RTVIDEOREC_ENCODER_H
-#define __RTVIDEOREC_ENCODER_H
-
-#include "thread.h"
-
-#include "info.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-//#include <avformat.h>
-
-#include "miav_client.h"
-#include "util.h"
-#include "package.h"
-#include "frame.h"
-#include "queue.h"
-
-// FIXME: One size fits all...
-#define VIDEO_BUFFER_SIZE (1024*1024)
-
-
-/**
- * This class contains code for sending the video stream and the snapshots
- * over the network, to the MIaV server.
- */
-class Encoder : public Thread {
-public:
- Encoder(Info* ginfo,
- const char *gip,
- const int gport,
- sem_t *gsem,
- Queue<Frame> *gqueue,
- pthread_mutex_t *gmutex,
- volatile int *grunning);
- ~Encoder();
-
- void setCpr(char *newcpr);
-
- void start();
- void stop(n_savestate save);
-
- void freeze();
- void shoot();
-
- void thread_main();
-
- // AVFormatContext *fc;
- sem_t *sem;
- Queue<Frame> *queue;
- pthread_mutex_t *mutex;
- volatile int *running;
-
-private:
- Info *info;
-
- int port;
- char ip[32];
- char cpr[32];
-
- bool frozen;
-
- // volatile int record;
-
- // volatile int shoot_request;
- // int shoot_value;
- // volatile int freeze_request;
- // int freeze_value;
-
- volatile bool savestate_sent;
- volatile n_savestate savestate;
-
- sem_t record_sem;
- void encode();
-
- Socket *s;
- Network *n;
-};
-
-#endif
-
-#endif /*USE_GUI*/
diff --git a/client/mainwindow.cc b/client/mainwindow.cc
index 0978120..e813d00 100644
--- a/client/mainwindow.cc
+++ b/client/mainwindow.cc
@@ -186,7 +186,7 @@ void MainWindow::createGui()
QGridLayout *g1 = new QGridLayout();
g0->addLayout(g1, 0, 0);
- QGroupBox *gb = new QGroupBox(this);
+ QGroupBox *gb = new QGroupBox();
/*
gb->setColumns(1);
gb->setInsideMargin(HISTORY_LIST_MARGIN);
@@ -209,7 +209,7 @@ void MainWindow::createGui()
g1->margin() * 5 -
g0->margin() * 3;
- img_recedge = new QLabel(this);
+ img_recedge = new QLabel();
QPalette palette;
palette.setColor(img_recedge->backgroundRole(), QColor(160,160,160));
img_recedge->setPalette(palette);
@@ -218,11 +218,11 @@ void MainWindow::createGui()
img_live = new VideoWidget(img_recedge, camera);
img_live->setFixedSize(output_width - 20, output_height - 20);
img_live->move(10,10);
- g1->addWidget( img_recedge, 0, 0, 0, 3, Qt::AlignHCenter);
+ g1->addWidget( img_recedge, 0, 0, 1, 3, Qt::AlignHCenter);
// CPR/NAME LABEL + CPR button
lbl_cpr = createLabel("", output_width - (int)(BUTTON_WIDTH * unit), BUTTON_HEIGHT);
- g1->addWidget( lbl_cpr, 1, 1, 0, 2);
+ g1->addWidget( lbl_cpr, 1, 0, 1, 2);
btn_cpr = createButton("");
btn_cpr->setFocus();
@@ -233,7 +233,7 @@ void MainWindow::createGui()
g1->addWidget(btn_cpr, 1, 3);
lbl_name = createLabel("", output_width, (int)(BUTTON_HEIGHT * 0.8f));
- g1->addWidget( lbl_name, 2, 2, 0, 3);
+ g1->addWidget( lbl_name, 2, 0, 1, 2);
/*
btn_clear = createButton("");
btn_clear->setPixmap(*img_clear);
@@ -292,7 +292,7 @@ void MainWindow::createGui()
status = new QStatusBar(this);
status->setSizeGripEnabled(FALSE);
// status->setFont(QFont( "Sans Serif", (int)(unit * height / 3), QFont::Normal ));
- g0->addWidget(status, 4, 4, 0, 1);
+ g0->addWidget(status, 4, 0, 4, 1);
lbl_recordtime = createLabel("", BUTTON_WIDTH, 1);
lbl_recordtime->setFixedWidth((int)(BUTTON_WIDTH * unit) +
@@ -302,7 +302,7 @@ void MainWindow::createGui()
status->addWidget(lbl_recordtime, 0);
// About button
- btn_about = new QPushButton("", this);
+ btn_about = new QPushButton();
btn_about->setFixedHeight((int)unit);
pixmap.fromImage(*img_logo);
btn_about->setIcon(pixmap);
diff --git a/client/player.cc b/client/player.cc
deleted file mode 100644
index e57211d..0000000
--- a/client/player.cc
+++ /dev/null
@@ -1,322 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * plsyer.cc
- *
- * Wed Nov 3 21:23:14 CET 2004
- * Copyright 2004 Bent Bisballe
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * Originally from:
- * RTVideoRec Realtime video recoder and encoder for Linux
- *
- * Copyright (C) 2004 B. Stultiens
- * Copyright (C) 2004 Koen Otter and Glenn van der Meyden
- */
-
-/*
- * 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.
- */
-#include <config.h>
-#ifdef USE_GUI
-
-#include "player.h"
-
-// Use libdv
-#include <libdv/dv.h>
-#include <libdv/dv_types.h>
-
-#include <time.h>
-
-// For sleep
-#include <unistd.h>
-
-Player::Player(Info *ginfo,
- int w, int h,
- volatile int *grunning,
- sem_t *gsem,
- Queue<Frame> *gqueue,
- pthread_mutex_t *gmutex)
-{
- // No errors has ocurred... yet!
- noErrors = true;
-
- yuv_draw = new YUVDraw();
-
- width = w;
- height = h;
-
- info = ginfo;
-
- running = grunning;
- sem = gsem;
- queue = gqueue;
- mutex = gmutex;
-
- sem_init(&play_sem, 0, 1);
-
- initSDL();
-
- bypass = false;
-
- // Do not show the text
- showtext = false;
- recording = false;
- recording_prev = !recording;
- cprchanged = false;
-
- muted = false;
- muted_prev = !muted;
-}
-
-Player::~Player()
-{
- deinitSDL();
- if(yuv_draw) delete yuv_draw;
-}
-
-void Player::reinitSDL()
-{
- deinitSDL();
- initSDL();
-}
-
-void Player::deinitSDL()
-{
- SDL_FreeYUVOverlay(overlay);
- SDL_Quit();
-}
-
-void Player::initSDL()
-{
- if(SDL_Init(SDL_INIT_VIDEO) < 0) {
- info->error("Unable to init SDL: %s.", SDL_GetError());
- noErrors = false;
- printf("failed!\n");
- return;
- }
-
- screen = SDL_SetVideoMode(width,
- height,
- 0, // 0 bpp means 'use current display depth'
- SDL_HWSURFACE |
- SDL_ANYFORMAT |
- SDL_HWACCEL );
-
- if(!screen) {
- info->error("Unable to set %dx%d video: %s.",
- 720, 576, SDL_GetError());
- noErrors = false;
- printf("failed!\n");
- return;
- }
-
- overlay = SDL_CreateYUVOverlay(720,
- 576,
- SDL_YUY2_OVERLAY, // Match for the libdv decoder output
- screen);
- if(!overlay) {
- info->error("Unable to create SDL overlay: %s.", SDL_GetError());
- noErrors = false;
- printf("failed!\n");
- return;
- }
-
- // Setup the displayarea.
- rect.x = 0;
- rect.y = 0;
- rect.w = width;
- rect.h = height;
-
- yuv_draw->setOverlay(overlay);
-}
-
-void Player::player()
-{
- SDL_Event event;
- Frame *frame;
-
- int pitches[3];
-
- if(!noErrors) return; // FIXME: Gracefully exit...
-
- bool first = true;
- dv_decoder_t *decoder = dv_decoder_new(FALSE/*this value is unused*/, FALSE, FALSE);
- decoder->quality = DV_QUALITY_BEST;
-
- while(*running) {
- // Wait for the semaphore to be free... then run
- sem_wait(&play_sem);
- sem_post(&play_sem);
-
- if(bypass) continue;
-
- if(!SDL_WaitEvent(&event)) break; // FIXME: Gracefully exit...
-
- switch(event.type) {
- case SDL_KEYDOWN:
- switch(event.key.keysym.sym) {
- case SDLK_q:
- case SDLK_ESCAPE:
- goto quitit;
- default:
- break;
- }
- break;
-
- case SDL_USEREVENT:
- frame = queue->pop();
- if(!frame) break;
-
- if(first) {
- pitches[0] = overlay->pitches[0];
- pitches[1] = overlay->pitches[1];
- pitches[2] = overlay->pitches[2];
-
- dv_parse_header(decoder, frame->data);
- //dv_parse_packs(decoder, frame->data); // Not needed anyway!
-
- decoder->system = e_dv_system_625_50; // PAL lines, PAL framerate
- decoder->sampling = e_dv_sample_422; // 4 bytes y, 2 bytes u, 2 bytes v
- decoder->std = e_dv_std_iec_61834;
- decoder->num_dif_seqs = 12;
- first = false;
- }
-
- if(SDL_LockYUVOverlay(overlay) == -1) info->error("SDL_LockYUVOverlay failed.");
-
- // libdv img decode to yuv
- dv_decode_full_frame(decoder,
- frame->data,
- e_dv_color_yuv,
- overlay->pixels,
- pitches);
-
- // Set status text
- // if(muted != muted_prev) {
- yuv_draw->mute(muted);
- // muted_prev = muted;
- // }
- if(recording != recording_prev) {
- if(recording) yuv_draw->setTopText(TEXT_RECORDING);
- else yuv_draw->setTopText(TEXT_STOPPED);
- recording_prev = recording;
- }
-
- // Draw overlaytext (if enabled)
- if(showtext) {
- if(cprchanged) {
- yuv_draw->setBottomText(cpr);
- cprchanged = false;
- }
- yuv_draw->draw();
- }
-
- SDL_UnlockYUVOverlay(overlay);
- SDL_DisplayYUVOverlay(overlay, &rect);
- delete frame;
- break;
-
- case SDL_QUIT:
- quitit:
- *running = 0;
- break;
-
- default:
- break;
- }
- }
- if(decoder) dv_decoder_free(decoder);
-
- struct timespec ts;
-
- /* Remove any late buffer */
- /* We don't care, the encoder finishes them all */
- ts.tv_sec = 0;
- ts.tv_nsec = 100000000L; // 100ms
- nanosleep(&ts, NULL);
-
- frame = queue->pop();
- if(frame) delete frame;
-}
-
-void Player::thread_main()
-{
- player();
- fprintf(stderr, "Player thread stopped.\n"); fflush(stderr);
-}
-
-void Player::start()
-{
- sem_post(&play_sem);
-}
-
-void Player::stop()
-{
- sem_wait(&play_sem);
-}
-
-// FIXME: Worst case genario: the loop takes more than 1 second
-// to stop displaying => crash, due to deinitialization
-// of SDL, while calling it.!
-void Player::resize(int w, int h, bool s)
-{
- // Tell loop to stop
- bypass = true;
-
- // Wait to ensure the current frame is done being displayed
- sleep(1);
-
- // Deinitialize SDL
- deinitSDL();
-
- // Set new size
- width = w;
- height = h;
-
- // Initialize SDL
- initSDL();
-
- // Tell loop to go on.
- bypass = false;
-
- showtext = s;
-}
-
-void Player::setCpr(char *newcpr, char* name)
-{
- sprintf(cpr, "ID: %s - %s", newcpr, name);
- cprchanged = true;
-}
-
-void Player::startrecord()
-{
- recording = true;
-}
-
-void Player::stoprecord()
-{
- recording = false;
-}
-
-void Player::setMute(bool m)
-{
- muted = m;
-}
-
-#endif /* USE_GUI */
diff --git a/client/player.h b/client/player.h
deleted file mode 100644
index 4e826ad..0000000
--- a/client/player.h
+++ /dev/null
@@ -1,142 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/***************************************************************************
- * player.h
- *
- * Fri Feb 25 20:23:19 CET 2005
- * Copyright 2005 Bent Bisballe
- * deva@aasimon.org
- ****************************************************************************/
-
-/*
- * Originally from:
- * RTVideoRec Realtime video recoder and encoder for Linux
- *
- * Copyright (C) 2004 Bent Bisballe
- *
- */
-
-/*
- * 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.
- */
-#include "config.h"
-#ifdef USE_GUI
-
-#ifndef __RTVIDEOREC_PLAYER_H
-#define __RTVIDEOREC_PLAYER_H
-
-#include "info.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <SDL/SDL.h>
-//#include <avformat.h>
-
-#include "util.h"
-#include "queue.h"
-
-#include "thread.h"
-#include "frame.h"
-
-#include <QWidget>
-
-#include "yuv_draw.h"
-
-#define TEXT_RECORDING "Optager"
-#define TEXT_STOPPED "Stoppet"
-
-//#define DISPLAYWIDTH 720 // FIXME: These numbers suck!
-//#define DISPLAYHEIGHT 576
-
-/**
- * This class contains the SDL code, for displaying the movie frames
- * in the widget, using hardware overlay.
- */
-class Player : public Thread {
-public:
- Player(Info *ginfo,
- int width, int height,
- volatile int *grunning,
- sem_t *gsem,
- Queue<Frame> *gqueue,
- pthread_mutex_t *gmutex);
- ~Player();
-
- // These functions are used to set the overlay text.
- void setCpr(char *newcpr, char* name);
- void startrecord();
- void stoprecord();
-
- // Start and stop runnning video (freeze/unfreeze)
- void start();
- void stop();
-
- // Used to reinitialize the SDL output width a new size
- void resize(int width, int height, bool showtext);
-
- void thread_main();
-
- void setMute(bool mute);
-
-private:
-
- void initSDL();
- void deinitSDL();
- void reinitSDL();
-
- // Output dimensions (overlay)
- volatile int width;
- volatile int height;
-
- SDL_Rect rect;
-
- // Set to true, whenever a resize is requested.
- volatile bool bypass;
-
- // Vars for the text overlay
- volatile bool showtext;
- volatile bool recording;
- bool recording_prev;
-
- volatile bool muted;
- bool muted_prev;
-
- volatile bool cprchanged;
- char cpr[256];
-
- Info *info;
-
- void player();
-
- // Used to verify if errors ha ocurred previously.
- bool noErrors;
-
- volatile int *running;
- sem_t *sem;
- Queue<Frame> *queue;
- pthread_mutex_t *mutex;
-
- sem_t play_sem;
-
- SDL_Surface *screen;
- SDL_Overlay *overlay;
-
- YUVDraw *yuv_draw;
-};
-
-#endif/*__RTVIDEOREC_PLAYER_H*/
-
-#endif /* USE_GUI */