From 430524810e67d3c223a2ab819f45b882b419c45d Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 14 Jun 2005 12:29:40 +0000 Subject: Incorporated the use of the Info object everywhere... also using the log functionality. --- TODO | 2 +- configure.in | 1 + etc/miav.conf | 10 ++++- src/Makefile.am | 4 -- src/daemon.cc | 6 +-- src/file.cc | 10 +++-- src/img_file.cc | 42 ------------------- src/img_file.h | 43 ------------------- src/info.cc | 12 +++++- src/info.h | 7 +++- src/info_console.cc | 17 +++++--- src/info_console.h | 4 +- src/info_gui.cc | 13 ++++-- src/info_gui.h | 4 +- src/mainwindow.cc | 5 ++- src/miav.cc | 10 +++-- src/miav_config.cc | 17 +++++--- src/miav_config.h | 9 ++-- src/miav_daemon.cc | 15 +++++-- src/mov_encoder.cc | 18 +++++--- src/mov_encoder.h | 10 ++++- src/mov_encoder_thread.cc | 16 ++++--- src/mov_encoder_thread.h | 9 +++- src/mov_encoder_writer.cc | 103 +++++++++------------------------------------- src/mov_encoder_writer.h | 17 +++++--- src/mov_file.cc | 42 ------------------- src/mov_file.h | 43 ------------------- src/server.cc | 31 ++++++++------ src/server.h | 17 +++----- tools/MIaVAdd | 24 +++++------ 30 files changed, 211 insertions(+), 350 deletions(-) delete mode 100644 src/img_file.cc delete mode 100644 src/img_file.h delete mode 100644 src/mov_file.cc delete mode 100644 src/mov_file.h diff --git a/TODO b/TODO index 7865120..57bb6f5 100644 --- a/TODO +++ b/TODO @@ -53,7 +53,7 @@ Mainwindow: [ ] - Clear / update taskbar. [ ] - Make new messagebox when asking to save movie. (Save, Delete, Cancel, Save in one week) - [ ] - Make "clear" button in mainwindow, to remove last patient, before + [x] - Make "clear" button in mainwindow, to remove last patient, before the next enters. [ ] - Realscale all window components. [ ] - Realscale all icons (use highresolution icons and scale them down) diff --git a/configure.in b/configure.in index 8378fe7..2ec244f 100644 --- a/configure.in +++ b/configure.in @@ -9,6 +9,7 @@ AM_PROG_LIBTOOL AM_CONFIG_HEADER(config.h) AC_STDC_HEADERS +CXXFLAGS="$CXXFLAGS -Wall -Werror" AC_ARG_WITH(gui, [ --without-gui build without GUI support]) if test x$with_gui != xno && test -z "$GUI"; then diff --git a/etc/miav.conf b/etc/miav.conf index 7e7ba7d..51fda2f 100644 --- a/etc/miav.conf +++ b/etc/miav.conf @@ -2,6 +2,10 @@ # The MIaV configuration file # +# Log files of the server and the client +client_log_file = "/tmp/miav_client.log" +server_log_file = "/tmp/miav_server.log" + # Cpr Database configuration cpr_host = "cpr.j.auh.dk" cpr_port = 10301 @@ -23,7 +27,11 @@ player_skip_frames = 1 server_addr = "192.168.0.10" server_port = 18120 -# Where top store the files recieved by the server +# Run the server as the following user: +server_uid = 500 +server_gid = 100 + +# Where to store the files recieved by the server server_root = "/home/miav/miav_files" # Video output controls. A sequence of I and P, where I is keyframes diff --git a/src/Makefile.am b/src/Makefile.am index 9c7d187..0afb24a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,6 @@ miav_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; fi ) \ file.cc \ frame.cc \ img_encoder.cc \ - img_file.cc \ info.cc \ info_console.cc \ info_gui.cc \ @@ -28,7 +27,6 @@ miav_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; fi ) \ mov_encoder.cc \ mov_encoder_thread.cc \ mov_encoder_writer.cc \ - mov_file.cc \ network.cc \ player.cc \ server.cc \ @@ -51,7 +49,6 @@ EXTRA_DIST = \ file.h \ frame.h \ img_encoder.h \ - img_file.h \ info.h \ info_console.h \ info_gui.h \ @@ -63,7 +60,6 @@ EXTRA_DIST = \ mov_encoder.h \ mov_encoder_thread.h \ mov_encoder_writer.h \ - mov_file.h \ network.h \ package.h \ player.h \ diff --git a/src/daemon.cc b/src/daemon.cc index 95cf0df..e80af78 100644 --- a/src/daemon.cc +++ b/src/daemon.cc @@ -40,7 +40,7 @@ Daemon::~Daemon() int Daemon::run(uid_t uid, gid_t gid) { int f; - int fd; + // int fd; chdir("/"); umask(0); @@ -62,13 +62,13 @@ int Daemon::run(uid_t uid, gid_t gid) fprintf(stderr, "Failed to change to uid %d, quitting.\n", uid); return 1; } - + /* // Redirect stdin, stdout and stderr to /dev/null fd = open("/dev/null", O_NOCTTY | O_RDWR, 0666); dup2(0, fd); dup2(1, fd); dup2(2, fd); - + */ setsid(); signal (SIGTERM, SIG_IGN); diff --git a/src/file.cc b/src/file.cc index 1a94150..813a041 100644 --- a/src/file.cc +++ b/src/file.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.3 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.2 2005/06/13 20:38:19 deva * Added some logfile code. * Enhanced the file object... now ready to hook into mov_encoder @@ -120,7 +123,7 @@ int File::Open() seqnum ++; - info->log("Opened the file %s for output.\n", fname); + info->log("Opened the file %s for output.", fname); return 0; } @@ -137,7 +140,7 @@ int File::Write(void* data, int size) w = write(fd, data, size); if(w != size) { info->error("Out of diskspace!\n"); - exit(1); + return -1; } } @@ -155,13 +158,14 @@ int File::createPath(char* path) subpath[strrchr(subpath, '/') - subpath] = '\0'; - printf("%s\n", path); + info->info("Checking and/or generating directory: %s", path); if(strlen(subpath) > 0) createPath(subpath); // stat(path, &stats); //if(!S_ISDIR(stats.st_mode) && S_ISREG(stats.st_mode)) mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH | S_IROTH); + // TODO: Check for creation errors! free(subpath); diff --git a/src/img_file.cc b/src/img_file.cc deleted file mode 100644 index a91aca0..0000000 --- a/src/img_file.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * img_file.cc - * - * Thu Jun 9 15:30:30 CEST 2005 - * Copyright 2005 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. - */ - -/* - * $Id$ - */ - -/* - * $Log$ - * Revision 1.1 2005/06/09 17:54:00 deva - * New file object, that takes care of uniqueness and counts up number in - * filename, when grown too big. - * - */ - -#include -#include "img_file.h" - diff --git a/src/img_file.h b/src/img_file.h deleted file mode 100644 index a1d9262..0000000 --- a/src/img_file.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * img_file.h - * - * Thu Jun 9 15:30:30 CEST 2005 - * Copyright 2005 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. - */ - -/* - * $Id$ - */ - -/* - * $Log$ - * Revision 1.1 2005/06/09 17:54:00 deva - * New file object, that takes care of uniqueness and counts up number in - * filename, when grown too big. - * - */ - -#include -#ifndef __MIAV_IMG_FILE_H__ -#define __MIAV_IMG_FILE_H__ -#endif/*__MIAV_IMG_FILE_H__*/ diff --git a/src/info.cc b/src/info.cc index 4278326..56d1dfd 100644 --- a/src/info.cc +++ b/src/info.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.2 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.1 2005/06/13 20:38:19 deva * Added some logfile code. * Enhanced the file object... now ready to hook into mov_encoder @@ -40,6 +43,8 @@ #include #include "info.h" +#include + Info::Info() { pthread_mutex_init (&mutex, NULL); } @@ -65,7 +70,12 @@ void Info::log(char *fmt, ...) va_end(argp); time_t t = time(NULL); - fprintf(fp, "%s miav[%d]", ctime(&t), buf, getpid()); + char sdate[32]; + memset(sdate, 0, sizeof(sdate)); + strftime(sdate, sizeof(sdate), "%d %b %H:%M:%S", localtime(&t)); + + fprintf(fp, "%s miav[%d] %s\n", sdate, getpid(), buf); + fprintf(stderr, "%s miav[%d] %s\n", sdate, getpid(), buf); fclose(fp); diff --git a/src/info.h b/src/info.h index b142a33..99e55b7 100644 --- a/src/info.h +++ b/src/info.h @@ -37,6 +37,10 @@ #ifndef __MIAV_INFO_H__ #define __MIAV_INFO_H__ +#include "miav_config.h" +// Cyclic include :( +class MiavConfig; + #include #include #include @@ -49,7 +53,6 @@ using namespace std; class Info { public: Info(); - virtual ~Info() {} virtual void error(char* fmt, ...) = 0; @@ -58,6 +61,8 @@ public: void log(char* fmt, ...); protected: + MiavConfig *config; + pthread_mutex_t mutex; string log_filename; }; diff --git a/src/info_console.cc b/src/info_console.cc index f703a3f..a860dd8 100644 --- a/src/info_console.cc +++ b/src/info_console.cc @@ -41,9 +41,10 @@ #include #include -InfoConsole::InfoConsole(): Info() +InfoConsole::InfoConsole(MiavConfig *c): Info() { - log_filename = *config->readString("server_log_file"); + this->config = c; + log_filename = *(this->config->readString("server_log_file")); } InfoConsole::~InfoConsole() @@ -60,12 +61,14 @@ void InfoConsole::error(char *fmt, ...) va_list argp; va_start(argp, fmt); - fprintf(stderr, "Error: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); + // fprintf(stderr, "Error: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); vsprintf(buf, fmt, argp); va_end(argp); // End of safezone pthread_mutex_unlock(&mutex); + + log("Error: %s", buf); } void InfoConsole::warn(char *fmt, ...) @@ -77,12 +80,14 @@ void InfoConsole::warn(char *fmt, ...) va_list argp; va_start(argp, fmt); - fprintf(stderr, "Warning: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); + // fprintf(stderr, "Warning: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); vsprintf(buf, fmt, argp); va_end(argp); // End of safezone pthread_mutex_unlock(&mutex); + + log("Warning: %s", buf); } void InfoConsole::info(char *fmt, ...) @@ -94,10 +99,12 @@ void InfoConsole::info(char *fmt, ...) va_list argp; va_start(argp, fmt); - fprintf(stderr, "Info: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); + // fprintf(stderr, "Info: ["); vfprintf(stderr, fmt, argp); fprintf(stderr, "]\n"); fflush(stderr); vsprintf(buf, fmt, argp); va_end(argp); // End of safezone pthread_mutex_unlock(&mutex); + + log("Info: %s", buf); } diff --git a/src/info_console.h b/src/info_console.h index 5422235..1447071 100644 --- a/src/info_console.h +++ b/src/info_console.h @@ -39,6 +39,8 @@ #include "info.h" +#include "miav_config.h" + #include #include @@ -47,7 +49,7 @@ using namespace std; class InfoConsole: public Info { public: - InfoConsole(); + InfoConsole(MiavConfig *config); ~InfoConsole(); void error(char* fmt, ...); diff --git a/src/info_gui.cc b/src/info_gui.cc index 2559402..0d7d701 100644 --- a/src/info_gui.cc +++ b/src/info_gui.cc @@ -38,8 +38,6 @@ #include "info_gui.h" -#include "miav_config.h" - #include #include @@ -59,9 +57,10 @@ bool InfoEventHandler::eventFilter( QObject *o, QEvent *e ) } } -InfoGui::InfoGui(QApplication *a, QWidget *p): Info() +InfoGui::InfoGui(QApplication *a, QWidget *p, MiavConfig *c): Info() { - log_filename = *config->readString("client_log_file"); + this->config = c; + log_filename = *(this->config->readString("client_log_file")); qapp = a; parent = p; @@ -118,6 +117,8 @@ void InfoGui::error(char *fmt, ...) va_end(argp); showmsg(buf, TXT_ERROR_TITLE, ICON_ERROR); + + log("Error: %s", buf); } void InfoGui::warn(char *fmt, ...) @@ -130,6 +131,8 @@ void InfoGui::warn(char *fmt, ...) va_end(argp); showmsg(buf, TXT_WARNING_TITLE, ICON_WARNING); + + log("Warning: %s", buf); } void InfoGui::info(char *fmt, ...) @@ -142,6 +145,8 @@ void InfoGui::info(char *fmt, ...) va_end(argp); showmsg(buf, TXT_INFO_TITLE, ICON_INFO); + + log("Info: %s", buf); } diff --git a/src/info_gui.h b/src/info_gui.h index 44729c2..2ee3d63 100644 --- a/src/info_gui.h +++ b/src/info_gui.h @@ -45,6 +45,8 @@ #include "info.h" +#include "miav_config.h" + #include #include @@ -72,7 +74,7 @@ protected: class InfoGui: public Info { public: - InfoGui(QApplication *a, QWidget *p); + InfoGui(QApplication *a, QWidget *p, MiavConfig *config); ~InfoGui(); void error(char* fmt, ...); diff --git a/src/mainwindow.cc b/src/mainwindow.cc index c127585..9e5353d 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.29 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.28 2005/06/02 20:45:01 deva * * Added clear button @@ -109,7 +112,7 @@ MainWindow::MainWindow(QApplication *qApp, QWidget* parent, const char* name ) : QWidget( parent, name, WStyle_Customize | WStyle_NoBorder ) { - info = new InfoGui(qApp, this); + info = new InfoGui(qApp, this, config); video_width = config->readInt("video_width"); video_height = config->readInt("video_height"); diff --git a/src/miav.cc b/src/miav.cc index 188b1d7..0f2feb3 100644 --- a/src/miav.cc +++ b/src/miav.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.14 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.13 2005/06/09 11:00:03 deva * Added daemon code, and cleaned up using -Wall and -Werror * @@ -94,7 +97,8 @@ int grab(int argc, char *argv[]) { QApplication miav_grab( argc, argv ); - InfoGui info(&miav_grab, NULL); + MiavConfig cfg(ETC"/miav.conf", NULL); + InfoGui info(&miav_grab, NULL, &cfg); config = new MiavConfig(ETC"/miav.conf", &info); InfoEventHandler *eventhandler = new InfoEventHandler( ); @@ -121,11 +125,9 @@ int grab(int argc, char *argv[]) { */ int server(int argc, char *argv[]) { - InfoConsole info; - MiavDaemon daemon; - MiavConfig cfg(ETC"/miav.conf", &info); + MiavConfig cfg(ETC"/miav.conf", NULL); int uid = cfg.readInt("server_uid"); int gid = cfg.readInt("server_gid"); diff --git a/src/miav_config.cc b/src/miav_config.cc index 2839c5c..f7d56ce 100644 --- a/src/miav_config.cc +++ b/src/miav_config.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.10 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.9 2005/06/09 11:00:03 deva * Added daemon code, and cleaned up using -Wall and -Werror * @@ -46,9 +49,9 @@ MiavConfig *config; -MiavConfig::MiavConfig(char *file, Info *ginfo) +MiavConfig::MiavConfig(char *file, Info *i) { - info = ginfo; + info = i; configs = NULL; filename = string(file); @@ -57,7 +60,8 @@ MiavConfig::MiavConfig(char *file, Info *ginfo) FILE* fp = fopen(file, "r"); if(!fp) { - info->error("Error reading configuration file %s\n", file); + if(info) info->error("Error reading configuration file %s\n", file); + else fprintf(stderr, "Error reading configuration file %s\n", file); return; } fseek(fp, 0, SEEK_END); @@ -91,7 +95,8 @@ MiavConfig::~MiavConfig() */ _cfg *MiavConfig::parseError(char* msg, char* line) { - info->error("Error parsing file %s at line:\n\t%s\n\t%s\n", filename.c_str(), line, msg); + if(info) info->error("Error parsing file %s at line:\n\t%s\n\t%s\n", filename.c_str(), line, msg); + else fprintf(stderr, "Error parsing file %s at line:\n\t%s\n\t%s\n", filename.c_str(), line, msg); return NULL; } @@ -265,6 +270,8 @@ _cfg *MiavConfig::findNode(char* node) if(!strcmp(node, cfg->name->c_str())) return cfg; cfg = cfg->next; } - info->error("Request for nonexisting node \"%s\"!\n", node); + if(info) info->error("Request for nonexisting node \"%s\"!\n", node); + else fprintf(stderr, "Request for nonexisting node \"%s\"!\n", node); + return NULL; } diff --git a/src/miav_config.h b/src/miav_config.h index 5d1fa29..4bbcc59 100644 --- a/src/miav_config.h +++ b/src/miav_config.h @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.7 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.6 2005/05/03 08:31:59 deva * Removed the error object, and replaced it with a more generic info object. * @@ -46,6 +49,8 @@ using namespace std; #include "info.h" +// Cyclic include :( +class Info; typedef struct __cfg { string *name; @@ -58,7 +63,7 @@ typedef struct __cfg { class MiavConfig { public: - MiavConfig(char *file, Info* ginfo); + MiavConfig(char *file, Info *info); ~MiavConfig(); int readInt(char *node); @@ -66,8 +71,6 @@ public: string *readString(char *node); float readFloat(char *node); - Info* getInfoObj(); - private: Info *info; diff --git a/src/miav_daemon.cc b/src/miav_daemon.cc index 633ab7d..2d679c3 100644 --- a/src/miav_daemon.cc +++ b/src/miav_daemon.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.2 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.1 2005/06/09 11:00:03 deva * Added daemon code, and cleaned up using -Wall and -Werror * @@ -45,6 +48,9 @@ #include "server.h" #include "socket.h" +#include +#include + MiavDaemon::MiavDaemon() {} @@ -53,7 +59,8 @@ MiavDaemon::~MiavDaemon() int MiavDaemon::daemon_main() { - InfoConsole info; + MiavConfig cfg(ETC"/miav.conf", NULL); + InfoConsole info(&cfg); config = new MiavConfig(ETC"/miav.conf", &info); int port = config->readInt("server_port"); @@ -62,7 +69,7 @@ int MiavDaemon::daemon_main() signal(SIGCLD, SIG_IGN); // Ved SIGCHILD til IGNORE maa wait/waitpid ikke kaldes // (ellers kommer der kernel-brok) - printf("Listening on port %d\n", port); + info.log("Listening on port %d", port); Socket *socket = new Socket(port, &info); while(1) { @@ -72,11 +79,11 @@ int MiavDaemon::daemon_main() switch(childpid) { case -1: // fork() returns -1 on failure - perror("fork"); + info.log("Fork error: %s", strerror(errno)); exit(1); case 0: // fork() returns 0 to the child process delete socket; // Close listen socket. - newConnection(csocket); + newConnection(csocket, &info); delete csocket; // Close communication socket. exit(0); diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc index fff5600..3945040 100644 --- a/src/mov_encoder.cc +++ b/src/mov_encoder.cc @@ -39,6 +39,9 @@ /* * $Log$ + * Revision 1.28 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.27 2005/06/09 11:00:03 deva * Added daemon code, and cleaned up using -Wall and -Werror * @@ -112,8 +115,11 @@ MovEncoder::MovEncoder(sem_t *r_sem, FrameVectorQueue *in, sem_t *in_sem, pthread_mutex_t *in_mutex, - FramePriorityQueue *out, sem_t *out_sem, pthread_mutex_t *out_mutex) + FramePriorityQueue *out, sem_t *out_sem, pthread_mutex_t *out_mutex, + Info *i) { + info = i; + // FIXME: Hmmm... should this be detected somewhere?! int w = 720; int h = 576; @@ -147,7 +153,7 @@ MovEncoder::MovEncoder(sem_t *r_sem, // can then be used for subsequent library calls.) fame_context = fame_open(); if(!fame_context) { - fprintf(stderr, "Unable to open FAME context, due to the following error: %s", strerror(errno)); + info->error("Unable to open FAME context, due to the following error: %s", strerror(errno)); return; } @@ -217,7 +223,7 @@ MovEncoder::MovEncoder(sem_t *r_sem, if(strcmp(config->readString("encoding_codec")->c_str(), "mpeg4") == 0) { - fprintf(stderr, "Using mpeg4 compression\n"); fflush(stderr); + info->info("Using mpeg4 compression."); fame_object_t *object; object = fame_get_object(fame_context, "profile/mpeg4/simple"); @@ -225,7 +231,7 @@ MovEncoder::MovEncoder(sem_t *r_sem, } else if(strcmp(config->readString("encoding_codec")->c_str(), "mpeg1") == 0) { - fprintf(stderr, "Using mpeg1 compression\n"); fflush(stderr); + info->info("Using mpeg1 compression."); fame_object_t *object; object = fame_get_object(fame_context, "profile/mpeg1"); @@ -233,7 +239,7 @@ MovEncoder::MovEncoder(sem_t *r_sem, } else if(strcmp(config->readString("encoding_codec")->c_str(), "mpeg1") == 0) { } else { - fprintf(stderr, "Using default (mpeg1) compression\n"); fflush(stderr); + info->info("Using default (mpeg1) compression."); } fame_init(fame_context, &fame_par, fame_buffer, FAME_BUFFER_SIZE); @@ -380,7 +386,7 @@ void MovEncoder::run() // Unlock input mutex if(!item) { - fprintf(stderr, "\t\t\t\tEmpty block detected.\n"); fflush(stderr); + info->warn("Empty block detected."); continue; } diff --git a/src/mov_encoder.h b/src/mov_encoder.h index d7e0c17..f006daa 100644 --- a/src/mov_encoder.h +++ b/src/mov_encoder.h @@ -36,6 +36,9 @@ /* * $Log$ + * Revision 1.11 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.10 2005/05/22 15:49:22 deva * Added multithreaded encoding support. * @@ -83,6 +86,8 @@ using namespace std; #include "thread.h" #include +#include "info.h" + // size specifies the length of the buffer. #define FAME_BUFFER_SIZE (2*720*576*4) // FIXME: One size fits all... @@ -90,7 +95,8 @@ class MovEncoder : public Thread { public: MovEncoder(sem_t *r_sem, FrameVectorQueue *in, sem_t *in_sem, pthread_mutex_t *in_mutex, - FramePriorityQueue *out, sem_t *out_sem, pthread_mutex_t *out_mutex); + FramePriorityQueue *out, sem_t *out_sem, pthread_mutex_t *out_mutex, + Info *info); ~MovEncoder(); Frame* encode(Frame *frame); @@ -99,6 +105,8 @@ public: volatile bool running; private: + Info *info; + // Input/Output queues FrameVectorQueue *inputqueue; FramePriorityQueue *outputqueue; diff --git a/src/mov_encoder_thread.cc b/src/mov_encoder_thread.cc index 2febb4f..c1d3e56 100644 --- a/src/mov_encoder_thread.cc +++ b/src/mov_encoder_thread.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.10 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.9 2005/05/26 12:48:36 deva * *** empty log message *** * @@ -65,14 +68,16 @@ #include #include "miav_config.h" -MovEncoderThread::MovEncoderThread(const char *filename) +MovEncoderThread::MovEncoderThread(const char *cpr, Info *i) { + info = i; outputqueue = new FramePriorityQueue(); inputqueue = new FrameVectorQueue(); block = new FrameVector(); num_frames_in_block = config->readString("frame_sequence")->length(); - fprintf(stderr, "Frame sequence length [%d]\n", num_frames_in_block); fflush(stderr); + + info->log("Frame sequence length %d", num_frames_in_block); threads = config->readInt("encoding_threads"); @@ -86,14 +91,15 @@ MovEncoderThread::MovEncoderThread(const char *filename) pthread_mutex_init (&input_mutex, NULL); pthread_mutex_init (&output_mutex, NULL); - writer = new MovEncoderWriter(filename, outputqueue, &out_sem, &output_mutex); + writer = new MovEncoderWriter(cpr, outputqueue, &out_sem, &output_mutex, info); writer_tid = new pthread_t; pthread_create (writer_tid, NULL, thread_run, writer); for(int cnt = 0; cnt < threads; cnt++) { encs.push_back(new MovEncoder(&read_sem, inputqueue, &in_sem, &input_mutex, - outputqueue, &out_sem, &output_mutex)); + outputqueue, &out_sem, &output_mutex, + info)); tids.push_back(new pthread_t); pthread_create (tids[cnt], NULL, thread_run, encs[cnt]); } @@ -148,7 +154,7 @@ MovEncoderThread::~MovEncoderThread() void MovEncoderThread::encode(Frame* frame) { if(frame == NULL) { - fprintf(stderr, "NULL frame detected.\n"); + info->log("NULL frame detected, exiting."); // Terminate return; } diff --git a/src/mov_encoder_thread.h b/src/mov_encoder_thread.h index 87a8f63..330e6e6 100644 --- a/src/mov_encoder_thread.h +++ b/src/mov_encoder_thread.h @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.7 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.6 2005/06/09 11:00:03 deva * Added daemon code, and cleaned up using -Wall and -Werror * @@ -70,14 +73,18 @@ using namespace std; #include "mov_encoder.h" #include "mov_encoder_writer.h" +#include "info.h" + class MovEncoderThread { public: - MovEncoderThread(const char *filename); + MovEncoderThread(const char *cpr, Info *info); ~MovEncoderThread(); void encode(Frame* frame); private: + Info *info; + FrameVectorQueue *inputqueue; FramePriorityQueue *outputqueue; FrameVector *block; diff --git a/src/mov_encoder_writer.cc b/src/mov_encoder_writer.cc index 2ed6879..c3e4207 100644 --- a/src/mov_encoder_writer.cc +++ b/src/mov_encoder_writer.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.4 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.3 2005/05/26 21:32:39 deva * *** empty log message *** * @@ -54,21 +57,19 @@ #include #include "mov_encoder_writer.h" -MovEncoderWriter::MovEncoderWriter(const char* fname, FramePriorityQueue *q, sem_t *s, pthread_mutex_t *m) +MovEncoderWriter::MovEncoderWriter(const char* cpr, + FramePriorityQueue *q, + sem_t *s, + pthread_mutex_t *m, + Info *i) { - // Append suffix - char f[256]; - sprintf(f, "%s.mpg", fname); - - filename = string(fname); - - file = open(f, - O_CREAT | O_WRONLY | O_SYNC, //| O_LARGEFILE - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if(file == -1) { - fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); - return; - } + info = i; + + // TODO: build filename from cpr and date + char fname[256]; + sprintf(fname, "/tmp/somefile"); + + file = new File(fname, "mpg", info); sem = s; queue = q; @@ -76,23 +77,17 @@ MovEncoderWriter::MovEncoderWriter(const char* fname, FramePriorityQueue *q, sem mutex = m; running = true; - - sequence_number = 0; } MovEncoderWriter::~MovEncoderWriter() { - if(file != -1) close(file); + delete file; } void MovEncoderWriter::run() { - // fprintf(stderr, "\t\t\t\t\t\t\t\t\tFile Writer ready!\n"); fflush(stderr); - Frame *frame; - if(file == -1) return; - while(running) { sem_wait(sem); @@ -103,73 +98,13 @@ void MovEncoderWriter::run() if(frame->number == frame_number) queue->pop(); pthread_mutex_unlock(mutex); - /* - if(!frame) { - fprintf(stderr, "\t\t\t\t\t\t\t\t\tNULL frame detected"); - continue; - } - */ - - // fprintf(stderr, "\t\t\t\t\t\t\t\t\tChecking frame [%d] against expected [%d]\n", - // frame->number, frame_number); fflush(stderr); while(frame->number == frame_number) { - int ret; - - ret = write(file, frame->data, frame->size); - if(ret != frame->size) { - fprintf(stderr, "Error in filewriter\n"); fflush(stderr); - switch(errno) { - case EAGAIN: // Non-blocking I/O has been selected using O_NONBLOCK and the write would block. - case EBADF: // fd is not a valid file descriptor or is not open for writing. - case EFAULT: // buf is outside your accessible address space. - case EINTR: // The call was interrupted by a signal before any data was written. - case EINVAL: // fd is attached to an object which is unsuitable for writing. - case EIO: // A low-level I/O error occurred while modifying the inode. - case ENOSPC: // The device containing the file referred to by fd has no room for the data. - case EPIPE: // fd is connected to a pipe or socket whose reading end is closed. When this hap- - // pens the writing process will also receive a SIGPIPE signal. (Thus, the write - // return value is seen only if the program catches, blocks or ignores this sig- - // nal.) - fprintf(stderr, "Could not write to file: %s\n", strerror(errno)); fflush(stderr); - return; - - case EFBIG: // An attempt was made to write a file that exceeds the implementation-defined max- - // imum file size or the process' file size limit, or to write at a position past - // than the maximum allowed offset. - fprintf(stderr, "Attempting to write to a new file\n"); fflush(stderr); - // Close current file - if(file != -1) close(file); - { - sequence_number++; - // Create new filename - char f[256]; - sprintf(f, "%s-%d.mpg", filename.c_str(), sequence_number); - - // Open new file - file = open(f, - O_CREAT | O_WRONLY | O_SYNC, //| O_LARGEFILE - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if(file == -1) { - fprintf(stderr, "Could not open file for writing: %s\n", strerror(errno)); fflush(stderr); - return; - } - } - // Do write again. - ret = write(file, frame->data, frame->size); - if(ret == -1) { - fprintf(stderr, "Could not write to file: %s\n", strerror(errno)); fflush(stderr); - return; - } - fprintf(stderr, "Success\n"); fflush(stderr); - break; - } - } - + int ret = file->Write(frame->data, frame->size); delete frame; - - // fprintf(stderr, "\t\t\t\t\t\t\t\t\tWrite frame [%d]\n", frame->number); fflush(stderr); + if(ret == -1) return; + frame_number++; pthread_mutex_lock(mutex); diff --git a/src/mov_encoder_writer.h b/src/mov_encoder_writer.h index 816abac..4ed144f 100644 --- a/src/mov_encoder_writer.h +++ b/src/mov_encoder_writer.h @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.3 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.2 2005/05/26 12:48:36 deva * *** empty log message *** * @@ -45,13 +48,19 @@ #include "frame.h" #include "thread.h" +#include "file.h" +#include "info.h" #include using namespace std; class MovEncoderWriter : public Thread { public: - MovEncoderWriter(const char* filename, FramePriorityQueue *q, sem_t *s, pthread_mutex_t *m); + MovEncoderWriter(const char* cpr, + FramePriorityQueue *q, + sem_t *s, + pthread_mutex_t *m, + Info *info); ~MovEncoderWriter(); void run(); @@ -59,11 +68,9 @@ public: volatile bool running; private: - // for use when creating multiple files in one movie. - int sequence_number; + Info *info; - string filename; - int file; + File *file; FramePriorityQueue *queue; pthread_mutex_t *mutex; diff --git a/src/mov_file.cc b/src/mov_file.cc deleted file mode 100644 index 5312966..0000000 --- a/src/mov_file.cc +++ /dev/null @@ -1,42 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * mov_file.cc - * - * Thu Jun 9 15:30:19 CEST 2005 - * Copyright 2005 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. - */ - -/* - * $Id$ - */ - -/* - * $Log$ - * Revision 1.1 2005/06/09 17:54:00 deva - * New file object, that takes care of uniqueness and counts up number in - * filename, when grown too big. - * - */ - -#include -#include "mov_file.h" - diff --git a/src/mov_file.h b/src/mov_file.h deleted file mode 100644 index f562fee..0000000 --- a/src/mov_file.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/*************************************************************************** - * mov_file.h - * - * Thu Jun 9 15:30:18 CEST 2005 - * Copyright 2005 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. - */ - -/* - * $Id$ - */ - -/* - * $Log$ - * Revision 1.1 2005/06/09 17:54:00 deva - * New file object, that takes care of uniqueness and counts up number in - * filename, when grown too big. - * - */ - -#include -#ifndef __MIAV_MOV_FILE_H__ -#define __MIAV_MOV_FILE_H__ -#endif/*__MIAV_MOV_FILE_H__*/ diff --git a/src/server.cc b/src/server.cc index cdbe506..5e3126b 100644 --- a/src/server.cc +++ b/src/server.cc @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.22 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.21 2005/05/26 21:32:39 deva * *** empty log message *** * @@ -92,9 +95,12 @@ // For unlink #include +// For errno +#include + + #include "miav_config.h" -//#include "mov_encoder.h" #include "mov_encoder_thread.h" #include "img_encoder.h" @@ -102,8 +108,6 @@ #include "dv.h" -#include "info_console.h" - void saveFrameAsImage(char* cpr, Frame *f) { ImgEncoder imgenc; @@ -208,6 +212,7 @@ struct tm MovEncoderThread *newMovEncoder(char* cpr) { + /* MovEncoderThread *enc; struct tm *ltime; time_t t = time(NULL); @@ -293,14 +298,15 @@ MovEncoderThread *newMovEncoder(char* cpr) fprintf(stderr, "Success - using filename: [%s.mpg]\n", fname); fflush(stderr); enc = new MovEncoderThread(fname); return enc; +*/ + return NULL; } -void newConnection(Socket *socket) +void newConnection(Socket *socket, Info *info) { char cpr[256]; bool hasCpr = false; ServerStatus status; - InfoConsole info; n_savestate savestate = LATER; n_header h; @@ -311,15 +317,13 @@ void newConnection(Socket *socket) frame = new Frame(NULL, DVPACKAGE_SIZE); - fprintf(stderr, "New connection[pid: %d]...\n", getpid()); - fflush(stderr); + info->log("New connection"); - Network network = Network(socket, &info); + Network network = Network(socket, info); while(int ret = network.recvPackage(&h, frame->data, frame->size)) { status.checkPoint(); if(ret == -1) { - fprintf(stderr, "An error occurred...!\n"); - fflush(stderr); + info->error("A network error ocurred, terminating session"); break; } @@ -358,7 +362,8 @@ void newConnection(Socket *socket) // This one must be last! if(h.header.h_data.record) { - if(!enc) enc = newMovEncoder(cpr); + // if(!enc) enc = newMovEncoder(cpr); + if(!enc) enc = new MovEncoderThread(cpr, info); enc->encode(frame); } @@ -367,10 +372,10 @@ void newConnection(Socket *socket) // TODO: Use save state - fprintf(stderr, "Closing connection...\n"); fflush(stderr); + info->log("Closing connection..."); if(enc) delete enc; - fprintf(stderr, "Connection closed [pid: %d]...\n", getpid()); fflush(stderr); + info->log("Connection closed"); } diff --git a/src/server.h b/src/server.h index 200ce68..0f14adf 100644 --- a/src/server.h +++ b/src/server.h @@ -31,6 +31,9 @@ /* * $Log$ + * Revision 1.5 2005/06/14 12:29:40 deva + * Incorporated the use of the Info object everywhere... also using the log functionality. + * * Revision 1.4 2005/05/03 08:31:59 deva * Removed the error object, and replaced it with a more generic info object. * @@ -42,19 +45,11 @@ #ifndef __SERVER_H__ #define __SERVER_H__ -#include // Symbolic Constants -#include // Primitive System Data Types -#include // Errors -#include // Input/Output -#include // Wait for Process Termination -#include // General Utilities - -#include - -#include "frame.h" #include "socket.h" -void newConnection(Socket *s); +#include "info.h" + +void newConnection(Socket *s, Info* info); #endif/*__SERVER_H__*/ diff --git a/tools/MIaVAdd b/tools/MIaVAdd index 7f36037..e066b04 100755 --- a/tools/MIaVAdd +++ b/tools/MIaVAdd @@ -11,21 +11,21 @@ function allfile() { echo " ****************************************************************************/" >> $1; echo "" >> $1; echo "/*" >> $1; - echo " * This file is part of MIaV." >> $1; + echo " * This file is part of MIaV." >> $1; echo " *" >> $1; - echo " * MIaV is free software; you can redistribute it and/or modify" >> $1; - echo " * it under the terms of the GNU General Public License as published by" >> $1; - echo " * the Free Software Foundation; either version 2 of the License, or" >> $1; - echo " * (at your option) any later version." >> $1; + echo " * MIaV is free software; you can redistribute it and/or modify" >> $1; + echo " * it under the terms of the GNU General Public License as published by" >> $1; + echo " * the Free Software Foundation; either version 2 of the License, or" >> $1; + echo " * (at your option) any later version." >> $1; echo " *" >> $1; - echo " * MIaV is distributed in the hope that it will be useful," >> $1; - echo " * but WITHOUT ANY WARRANTY; without even the implied warranty of" >> $1; - echo " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" >> $1; - echo " * GNU General Public License for more details." >> $1; + echo " * MIaV is distributed in the hope that it will be useful," >> $1; + echo " * but WITHOUT ANY WARRANTY; without even the implied warranty of" >> $1; + echo " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" >> $1; + echo " * GNU General Public License for more details." >> $1; echo " *" >> $1; - echo " * You should have received a copy of the GNU General Public License" >> $1; - echo " * along with MIaV; if not, write to the Free Software" >> $1; - echo " * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA." >> $1; + echo " * You should have received a copy of the GNU General Public License" >> $1; + echo " * along with MIaV; if not, write to the Free Software" >> $1; + echo " * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA." >> $1; echo " */" >> $1; echo "" >> $1; echo "/*" >> $1; -- cgit v1.2.3