From 2f10a73cbbe4333e2a41e87a94eda7fb3d442dc5 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 17 Mar 2008 09:10:42 +0000 Subject: Major code changes... FFMPEG introduced. Project splitup into subfolders. --- libmiav/Makefile.am | 47 + libmiav/aa_socket.cc | 254 +++ libmiav/aa_socket.h | 42 + libmiav/config.h | 33 + libmiav/debug.h | 103 ++ libmiav/dv.h | 33 + libmiav/dv1394.cc | 202 +++ libmiav/dv1394.h | 55 + libmiav/file.cc | 246 +++ libmiav/file.h | 72 + libmiav/font.h | 3152 ++++++++++++++++++++++++++++++++++ libmiav/frame.cc | 52 + libmiav/frame.h | 58 + libmiav/frame_stream.h | 41 + libmiav/info.cc | 76 + libmiav/info.h | 66 + libmiav/info_simple.cc | 94 + libmiav/info_simple.h | 45 + libmiav/jpeg_mem_dest.cc | 137 ++ libmiav/jpeg_mem_dest.h | 39 + libmiav/miav.h | 37 + libmiav/miav_config.cc | 492 ++++++ libmiav/miav_config.h | 98 ++ libmiav/mutex.cc | 48 + libmiav/mutex.h | 45 + libmiav/network.cc | 172 ++ libmiav/network.h | 55 + libmiav/package.h | 63 + libmiav/queue.h | 248 +++ libmiav/semaphore.cc | 48 + libmiav/semaphore.h | 45 + libmiav/server_status.cc | 77 + libmiav/server_status.h | 56 + libmiav/socket.cc | 150 ++ libmiav/socket.h | 61 + libmiav/thread.cc | 56 + libmiav/thread.h | 49 + libmiav/threadsafe_queue.cc | 44 + libmiav/threadsafe_queue.h | 58 + libmiav/threadsafe_queue_fifo.cc | 70 + libmiav/threadsafe_queue_fifo.h | 50 + libmiav/threadsafe_queue_priority.cc | 101 ++ libmiav/threadsafe_queue_priority.h | 64 + libmiav/util.cc | 95 + libmiav/util.h | 54 + 45 files changed, 7183 insertions(+) create mode 100644 libmiav/Makefile.am create mode 100644 libmiav/aa_socket.cc create mode 100644 libmiav/aa_socket.h create mode 100644 libmiav/config.h create mode 100644 libmiav/debug.h create mode 100644 libmiav/dv.h create mode 100644 libmiav/dv1394.cc create mode 100644 libmiav/dv1394.h create mode 100644 libmiav/file.cc create mode 100644 libmiav/file.h create mode 100644 libmiav/font.h create mode 100644 libmiav/frame.cc create mode 100644 libmiav/frame.h create mode 100644 libmiav/frame_stream.h create mode 100644 libmiav/info.cc create mode 100644 libmiav/info.h create mode 100644 libmiav/info_simple.cc create mode 100644 libmiav/info_simple.h create mode 100644 libmiav/jpeg_mem_dest.cc create mode 100644 libmiav/jpeg_mem_dest.h create mode 100644 libmiav/miav.h create mode 100644 libmiav/miav_config.cc create mode 100644 libmiav/miav_config.h create mode 100644 libmiav/mutex.cc create mode 100644 libmiav/mutex.h create mode 100644 libmiav/network.cc create mode 100644 libmiav/network.h create mode 100644 libmiav/package.h create mode 100644 libmiav/queue.h create mode 100644 libmiav/semaphore.cc create mode 100644 libmiav/semaphore.h create mode 100644 libmiav/server_status.cc create mode 100644 libmiav/server_status.h create mode 100644 libmiav/socket.cc create mode 100644 libmiav/socket.h create mode 100644 libmiav/thread.cc create mode 100644 libmiav/thread.h create mode 100644 libmiav/threadsafe_queue.cc create mode 100644 libmiav/threadsafe_queue.h create mode 100644 libmiav/threadsafe_queue_fifo.cc create mode 100644 libmiav/threadsafe_queue_fifo.h create mode 100644 libmiav/threadsafe_queue_priority.cc create mode 100644 libmiav/threadsafe_queue_priority.h create mode 100644 libmiav/util.cc create mode 100644 libmiav/util.h (limited to 'libmiav') diff --git a/libmiav/Makefile.am b/libmiav/Makefile.am new file mode 100644 index 0000000..bda45b9 --- /dev/null +++ b/libmiav/Makefile.am @@ -0,0 +1,47 @@ +lib_LTLIBRARIES = libmiav.la + +libmiav_la_SOURCES = \ + aa_socket.cc \ + dv1394.cc \ + file.cc \ + frame.cc \ + info.cc \ + info_simple.cc \ + jpeg_mem_dest.cc \ + miav_config.cc \ + mutex.cc \ + network.cc \ + semaphore.cc \ + server_status.cc \ + socket.cc \ + thread.cc \ + threadsafe_queue.cc \ + threadsafe_queue_fifo.cc \ + threadsafe_queue_priority.cc \ + util.cc + +EXTRA_DIST = \ + aa_socket.h \ + dv.h \ + dv1394.h \ + file.h \ + frame.h \ + frame_stream.h \ + info.h \ + info_simple.h \ + jpeg_mem_dest.h \ + miav_config.h \ + mutex.h \ + network.h \ + package.h \ + queue.h \ + semaphore.h \ + server_status.h \ + socket.h \ + thread.h \ + threadsafe_queue.h \ + threadsafe_queue_fifo.h \ + threadsafe_queue_priority.h \ + timecode.h \ + util.h + diff --git a/libmiav/aa_socket.cc b/libmiav/aa_socket.cc new file mode 100644 index 0000000..28ecead --- /dev/null +++ b/libmiav/aa_socket.cc @@ -0,0 +1,254 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ + +#include "aa_socket.h" + +//#include + +#include +using namespace std; + +#include +//#include +#include +#include +#include + +#include + +#include +#if defined(linux) +#include +#else +#include +#endif /*defined(linux)*/ + +// for gethostbyname +#include + +// These functions are wrappers, to preserve my nice method naming! +inline int _socket(int a,int b,int c){return socket(a,b,c);} +inline int _connect(int a,const struct sockaddr *b,socklen_t c){return connect(a,b,c);} +inline int _listen(int a,int b){return listen(a,b);} +inline int _send(int a,char *b,unsigned int c, int d){return send(a,b,c,d);} + + +AASocket::AASocket() +{ +} + +AASocket::~AASocket() +{ + int err = close(socket); // close server + if(err == -1) throw Network_error("close", strerror(errno)); +} + +void AASocket::connect(char *host, unsigned short port) +{ + // create socket + socket = _socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + // PF_INET: ipv4, PF_INET6: ipv6 + // tcp: IPPROTO_TCP + // upd: IPPROTO_UDP + + if (socket == -1) throw Network_error("socket", strerror(errno)); + + socketaddr.sin_family = AF_INET; // Use "internet protocol" IP + socketaddr.sin_port = htons(port); // connect to that port + socketaddr.sin_addr.s_addr = INADDR_ANY; + // INADDR_ANY puts your IP address automatically + + + + struct hostent *hp = gethostbyname(host); + // memcpy(&socketaddr.sin_addr.s_addr, *(hp->h_addr_list),sizeof(struct in_addr)); + memcpy(&(socketaddr.sin_addr),*(hp->h_addr_list),sizeof(struct in_addr)); + + // FIXME: gethostbyname() + // socketaddr.sin_addr.s_addr = inet_addr(host); + //inet_aton (ip, &socketaddr.sin_addr); + + int err = _connect(socket, (struct sockaddr*)&socketaddr, sizeof(socketaddr)); + if(err == -1) throw Network_error("connect", strerror(errno)); +} + +void AASocket::listen(unsigned short port) +{ + int err; + + bind_socket = _socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + if(bind_socket == -1) throw Network_error("tmp socket", strerror(errno)); + + int optval = 1; + err = setsockopt(bind_socket, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)); + if(err == -1) throw Network_error("setsockopt", strerror(errno)); + + socketaddr.sin_family = AF_INET; // Use "internet protocol" IP + socketaddr.sin_port = htons(port); // connect to that port + socketaddr.sin_addr.s_addr = INADDR_ANY; + // INADDR_ANY puts your IP address automatically + + // bind socket to address specified by "sa" parameter + err = bind(bind_socket, (struct sockaddr*)&socketaddr, sizeof(socketaddr)); + if(err == -1) throw Network_error("bind", strerror(errno)); + + err = _listen(bind_socket, 5); + if(err == -1) throw Network_error("listen", strerror(errno)); + + int csalen = sizeof(socketaddr); + socket = accept(bind_socket, + (struct sockaddr*)&socketaddr, + (socklen_t*)&csalen); + if(socket == -1) throw Network_error("accept", strerror(errno)); + + err = close(bind_socket); // We don't need this anymore + bind_socket = -1; + if(err == -1) throw Network_error("tmp close", strerror(errno)); +} + + +void AASocket::force_close() +{ + if(bind_socket != -1) close(bind_socket); // This should break the accept call +} + + +void AASocket::send(char* buf, unsigned int size) +{ + //unsigned int newsize = size + sizeof(unsigned int); + // char *newbuf = new char[newsize]; + + unsigned int nsize = htonl(size); + int n = _send(socket, (char*)&nsize, sizeof(unsigned int), MSG_WAITALL); + if(n == -1) throw Network_error("send", strerror(errno)); + + n = _send(socket, buf, size, MSG_WAITALL); + if(n == -1) throw Network_error("send", strerror(errno)); +} + + +int AASocket::receive(char* buf, unsigned int size) +{ + unsigned int insize; + + int n = recv(socket, &insize, sizeof(unsigned int), MSG_WAITALL); + if(n == -1) throw Network_error("recv", strerror(errno)); + + insize = ntohl(insize); + if(insize > size) { + char err_buf[256]; + sprintf(err_buf, "Buffer is too small. Should be %d is %d." , insize, size); + throw Network_error("receive", err_buf); + } + + n = recv(socket, buf, insize, MSG_WAITALL); + if(n == -1) throw Network_error("recv", strerror(errno)); + + return n; +} + + +void AASocket::send_string(string str) +{ + this->send((char*)str.c_str(), str.length()); +} + + +string AASocket::receive_string() +{ + char buf[1024]; + memset(buf, 0, sizeof(buf)); + + receive(buf, sizeof(buf)); + + return string(buf); +} + + + +#ifdef TEST_SOCKET + +/** + * Test application for AASocket + * It should print the following to stdout: + * A: Hello, how are you? + * B: Fine thanks. + * A: What about you? + * B: I'm fine too. + */ + +#include +#include + +#include +#include + +int main() +{ + char buf[1024]; + memset(buf, 0, sizeof(buf)); + int f = fork(); + switch(f) { + case -1: // Fork error + perror("Fork failed!"); + return 1; + + case 0: // Forked child + { + try { + AASocket out; + + sleep(1); // Make sure the other end is listening + + // Test connect + out.connect("127.0.0.1", 6666); + + // Test raw communication send + sprintf(buf, "Hello how are you?"); + out.send(buf, sizeof(buf)); + + // Test raw communication receive + out.receive(buf, sizeof(buf)); + std::cout << "B: " << buf << std::endl; + + // Test string receive + std::string q = out.receive_string(); + std::cout << "B: " << q << std::endl; + + // Test string send + out.send_string(std::string("I'm fine too.")); + return 0; + } catch(Network_error e) { + std::cerr << "Out: " << e.error << std::endl; + } + } + default: // Parent + { + try { + AASocket in; + + // Test listen + in.listen(6666); + + // Test raw communication receive + in.receive(buf, sizeof(buf)); + std::cout << "A: " << buf << std::endl; + + // Test raw communication send + sprintf(buf, "Fine thanks."); + in.send(buf, sizeof(buf)); + + // Test string send + in.send_string(std::string("What about you?")); + + // Test string receive + std::string a = in.receive_string(); + std::cout << "A: " << a << std::endl; + return 0; + } catch(Network_error e) { + std::cerr << "In: " << e.error << std::endl; + } + } + } + return 0; +} +#endif/*TEST_SOCKET*/ diff --git a/libmiav/aa_socket.h b/libmiav/aa_socket.h new file mode 100644 index 0000000..0d02723 --- /dev/null +++ b/libmiav/aa_socket.h @@ -0,0 +1,42 @@ +#ifndef __SOCKET_H__ +#define __SOCKET_H__ + +#include + +#include +//#include + + +/** + * Exceptions + */ +struct Network_error { + Network_error(char *event, char *err) { + error = std::string(err) + " - in " + std::string(event); + } + std::string error; +}; + +class AASocket { +public: + AASocket(); + ~AASocket(); + + void listen(unsigned short port); + void connect(char *ip, unsigned short port); + + void send(char* buf, unsigned int buf_size); + int receive(char* buf, unsigned int buf_size); + + void send_string(std::string buf); + std::string receive_string(); + + void force_close(); + +private: + struct sockaddr_in socketaddr; + int socket; + int bind_socket; // Tmp socket for listen. +}; + +#endif/*__SOCKET_H__*/ diff --git a/libmiav/config.h b/libmiav/config.h new file mode 100644 index 0000000..e7101c9 --- /dev/null +++ b/libmiav/config.h @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * config.h + * + * Thu Jul 28 12:46:38 CEST 2005 + * 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. + */ + +#ifndef __CONFIG_IS_LOADED__ +#define __CONFIG_IS_LOADED__ + +#include "../config.h" + +#endif/*__CONFIG_IS_LOADED__*/ diff --git a/libmiav/debug.h b/libmiav/debug.h new file mode 100644 index 0000000..48c0830 --- /dev/null +++ b/libmiav/debug.h @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * debug.h + * + * Tue Apr 12 14:34:20 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. + */ +#include "config.h" +#ifndef __MIAV_DEBUG_H__ +#define __MIAV_DEBUG_H__ + +//#define DEBUG_ALLOC + +#ifdef DEBUG_ALLOC +typedef struct _A_{ + struct _A_* prev; + struct _A_* next; + char name[32]; + void *addr; +} __debug__; + +__debug__ *debug_first = NULL; + +inline void debugAlloc(void *p, char* name) +{ + __debug__ *d = debug_first; + + fprintf(stderr, "Adding %d - %s\n", p, name); + + debug_first = (__debug__*)malloc(sizeof(__debug__)); + debug_first->prev = NULL; + debug_first->next = d; + if(d) d->prev = debug_first; + debug_first->addr = p; + strcpy(debug_first->name, name); +} + +inline void debugFree(void *p) +{ + __debug__ *d = debug_first; + + while(d && d->addr != p) { + d = d->next; + } + + if(!d) { + fprintf(stderr, "ERROR: memory address not found %d - perhaps already freed!\n", p); + exit(1); + } + + fprintf(stderr, "Removing %d - %s\n", p, d->name); + __debug__ *next = d->next; + __debug__ *prev = d->prev; + if(prev) prev->next = d->next; + if(next) next->prev = d->prev; + if(debug_first == d) debug_first = next; + free(d); +} + +inline void debugPrint() +{ + __debug__ *d = debug_first; + + fprintf(stderr, "Alloc List:\n"); + + while(d) { + fprintf(stderr, "\t[%d] %s\n", d->addr, d->name); + d = d->next; + } +} + +#define FREE(x) debugFree(x) +#define ALLOC(x, y) debugAlloc(x, y) +#define PRINT() debugPrint() + +#else/*DEBUG_ALLOC*/ + +#define FREE(x) {} +#define ALLOC(x, y) {} +#define PRINT() {} + +#endif/*DEBUG_ALLOC*/ + +#endif/*__MIAV_DEBUG_H__*/ diff --git a/libmiav/dv.h b/libmiav/dv.h new file mode 100644 index 0000000..e346d03 --- /dev/null +++ b/libmiav/dv.h @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * dv.h + * + * Thu Apr 14 19:29:55 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. + */ +#include "config.h" +#ifndef __MIAV_DV_H__ +#define __MIAV_DV_H__ + +#define DVPACKAGE_SIZE 144000 + +#endif/*__MIAV_DV_H__*/ diff --git a/libmiav/dv1394.cc b/libmiav/dv1394.cc new file mode 100644 index 0000000..26953d9 --- /dev/null +++ b/libmiav/dv1394.cc @@ -0,0 +1,202 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * dv1394.cc + * + * Tue Apr 19 12:10:34 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. + */ +#include +#include "dv1394.h" + +#ifdef USE_GUI + +#include "dv.h" + + +#include +#include +#include +#include +#include +#include +#include + +/** + * Callback function for the firewire interface. + */ +static raw1394_iso_disposition raw_reader(raw1394handle_t handle, + unsigned char *data, + unsigned int length, + unsigned char channel, + unsigned char tag, + unsigned char sy, + unsigned int cycle, + unsigned int dropped) +{ + static char *framedata = NULL; + + // Only process packets with reasonable length. + if ( length > 16 ) + { + unsigned char * p = ( unsigned char* ) & data[ 8 ]; + int section_type = p[ 0 ] >> 5; // section type is in bits 5 - 7 + int dif_sequence = p[ 1 ] >> 4; // dif sequence number is in bits 4 - 7 + int dif_block = p[ 2 ]; + + if ( section_type == 0 && dif_sequence == 0 ) + { + if ( framedata != NULL ) + { + raw1394_set_userdata(handle, (void *)framedata); + framedata = NULL; + } + } + + if(!framedata) + { + framedata = (char *)malloc(DVPACKAGE_SIZE); // dvframe.h + if(!framedata) + { + // We're fucked + fprintf(stderr, "Framedata allocation error: %s.\n", strerror( errno ) ); fflush(stderr); + exit(1); + } + } + + switch ( section_type ) + { + case 0: // 1 Header block + // p[3] |= 0x80; // hack to force PAL data + memcpy( framedata + dif_sequence * 150 * 80, p, 480 ); + break; + + case 1: // 2 Subcode blocks + memcpy( framedata + dif_sequence * 150 * 80 + ( 1 + dif_block ) * 80, p, 480 ); + break; + + case 2: // 3 VAUX blocks + memcpy( framedata + dif_sequence * 150 * 80 + ( 3 + dif_block ) * 80, p, 480 ); + break; + + case 3: // 9 Audio blocks interleaved with video + memcpy( framedata + dif_sequence * 150 * 80 + ( 6 + dif_block * 16 ) * 80, p, 480 ); + break; + + case 4: // 135 Video blocks interleaved with audio + memcpy( framedata + dif_sequence * 150 * 80 + ( 7 + ( dif_block / 15 ) + dif_block ) * 80, p, 480 ); + break; + + default: // we can't handle any other data + break; + } + } + + return RAW1394_ISO_OK; +} + +dv1394::dv1394(Info *i, int p, int c) +{ + info = i; + port = p; + channel = c; +} + +dv1394::~dv1394() +{ + // Close firewire connection. + if(handle) { + raw1394_iso_shutdown(handle); + raw1394_destroy_handle(handle); + } +} + +bool dv1394::connect() +{ + int n_ports; + struct raw1394_portinfo pinf[ 16 ]; + + // Get handle to firewire channels + handle = raw1394_new_handle(); + if(!handle) { + info->error("raw1394 - failed to get handle: %s.", strerror( errno ) ); + return false; + } + + // how many adapters are hooked in? + if((n_ports = raw1394_get_port_info(handle, pinf, 16)) < 0 ) { + info->error("raw1394 - failed to get port info: %s.", strerror( errno ) ); + raw1394_destroy_handle(handle); + handle = NULL; + return false; + } + + // Tell raw1394 which host adapter to use + if(raw1394_set_port(handle, port) < 0 ) { + info->error("raw1394 - failed to set port: %s.", strerror( errno ) ); + raw1394_destroy_handle(handle); + handle = NULL; + return false; + } + + int res = raw1394_iso_recv_init(handle, + raw_reader, + 488, + 512, // Wonder what this size should actually be!? + channel, + RAW1394_DMA_PACKET_PER_BUFFER,//RAW1394_DMA_DEFAULT, + -1); + if(res == -1) { + fprintf(stderr, "Error in raw1394_iso_recv_init: %s\n", strerror(errno)); + // exit(1); + } + + raw1394_set_userdata( handle, ( void* ) NULL); + + res = raw1394_iso_recv_start(handle, -1, -1, 0); + + if(res == -1) { + fprintf(stderr, "Error in raw1394_iso_recv_start: %s\n", strerror(errno)); + // exit(1); + } + + return true; +} + +unsigned char *dv1394::readFrame() +{ + // Firewire port not correctly opened. + if(!handle) return NULL; + + unsigned char *ptr; + while(1) { + raw1394_loop_iterate(handle); + ptr = (unsigned char *)raw1394_get_userdata(handle); + if(ptr) { + raw1394_set_userdata(handle, NULL); + break; + } + } + + return ptr; +} + +#endif/*USE_GUI*/ diff --git a/libmiav/dv1394.h b/libmiav/dv1394.h new file mode 100644 index 0000000..7cea9d0 --- /dev/null +++ b/libmiav/dv1394.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * dv1394.h + * + * Tue Apr 19 12:10:34 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. + */ +#include "config.h" +#ifndef __MIAV_DV1394_H__ +#define __MIAV_DV1394_H__ + +#ifdef USE_GUI + +#include "frame_stream.h" +#include + +#include "info.h" + +class dv1394 : public frame_stream { +public: + dv1394(Info* info, int port = 0, int channel = 63); // 63 is default channel... sucks. + ~dv1394(); + + bool connect(); + + unsigned char *readFrame(); + +private: + raw1394handle_t handle; + Info *info; + int port; + int channel; +}; + +#endif/*__MIAV_DV1394_H__*/ +#endif/*USE_GUI*/ diff --git a/libmiav/file.cc b/libmiav/file.cc new file mode 100644 index 0000000..fc02072 --- /dev/null +++ b/libmiav/file.cc @@ -0,0 +1,246 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * file.cc + * + * Thu Jun 9 15:31:38 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. + */ +#include +#include "file.h" + +#include "miav_config.h" + +#include +#include +#include +#include +#include + +#include + +// For ntoh* +#include + +#include + +File::File(char *fn, char* ext, Info *i) +{ + char path[256]; + + info = i; + + savestate = SAVE; + + filename = new char[strlen(fn) + 1]; + extension = new char[strlen(ext) + 1]; + + strcpy(filename, fn); + strcpy(extension, ext); + + num = 0; + seqnum = 0; + fd = -1; + + int pos = (int)strrchr(filename, '/'); + memset(path, 0, sizeof(path)); + + if(pos) { // pos is NULL, a file will be created in the current dir (Which is bad) + pos -= (int)filename; // Make pos relative to the beginning of the string + strncpy(path, filename, pos); + createPath(path); + } + + // Open(); +} + +File::~File() +{ + info->info("~File..."); + + info->info("This session contains the following files..."); + for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) { + info->info("[%s]", filelist[cnt].c_str()); + } + + std::string *trash = config->readString("server_trash"); + std::string *later = config->readString("server_later"); + + switch(savestate) { + case NO_CHANGE: + info->warn("File had no savestate!"); + break; + + case SAVE: + info->info("Files in this session is to be saved."); + break; + + case DELETE: + info->info("Files in this session is to be deleted (moved to trash)."); + Move((char*)trash->c_str()); + break; + + case LATER: + info->info("Files in this session is stored for later decisson."); + Move((char*)later->c_str()); + break; + } + + delete filename; + delete extension; + + info->info("~File...done"); +} + +int File::Move(char *destination) +{ + char newfile[256]; + char filename[256]; + + createPath(destination); + for(unsigned int cnt = 0; cnt < filelist.size(); cnt ++) { + // TODO: Check is the file exists... if not make som noise! + + + // TODO: Move file filelist[cnt] to the destination folder. + strcpy(filename, (char*)filelist[cnt].c_str()); + sprintf(newfile, "%s%s", destination, strrchr(filename, '/')); + if(rename((char*)filelist[cnt].c_str(), newfile) == -1) + info->error("Error moving file %s to %s:", + (char*)filelist[cnt].c_str(), + newfile, + strerror(errno)); + } + return 0; +} + +std::string File::Open() +{ + char fname[256]; + + if(fd != -1) { + close(fd); + fd = -1; + } + + while(fd == -1) { + if(seqnum) { + // A sequence number > 0 + sprintf(fname, "%s%.3d-%d.%s", filename, num, seqnum, extension); + } else { + // A sequence number of 0 + sprintf(fname, "%s%.3d.%s", filename, num, extension); + } + fd = open(fname, O_CREAT | O_WRONLY | O_ASYNC | O_EXCL, //| O_LARGEFILE + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if(fd == -1) num ++; + + // If more than 100 files are created in one day, something is terribly wrong! + if(num > 100) { + info->error("Something is wrong with the path [%s]!", fname); + exit(1); + } + + } + + std::string filename_string(fname); + filelist.push_back(filename_string); + + seqnum ++; + + info->info("Output file: %s", fname); + + close(fd); + return fname; +} + +int File::Write(void* data, int size) +{ + /* + int w; + + w = write(fd, data, size); + + if(w != size) { + info->info("Wrapping file."); + Open(); + w = write(fd, data, size); + if(w != size) { + info->error("Out of diskspace!"); + return -1; + } + } + + return w; + */ + return 0; +} + +int File::createPath(char* path) +{ + // struct stat stats; + char *subpath; + + subpath = (char*)calloc(strlen(path) + 1, 1); + + strcpy(subpath, path); + + subpath[strrchr(subpath, '/') - subpath] = '\0'; + + if(strlen(subpath) > 0) createPath(subpath); + + info->info("Checking and/or generating directory: %s", path); + + // 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); + + return 0; +} + +void File::setSaveState(n_savestate s) +{ + savestate = s; + info->info("SETTING SAVESTATE TO: %d", savestate); +} + +#ifdef __TEST_FILE +#include "info_simple.h" + +int main(int argc, char *argv[]) { + if(argc < 3) { + fprintf(stderr, "usage:\n\ttest_file [filename] [extension]\n"); + return 1; + } + + + InfoSimple info; + File file(argv[1], argv[2], &info); + + unsigned int val = 0x01234567; + file.Write(val); + +} + +#endif/* __TEST_FILE*/ diff --git a/libmiav/file.h b/libmiav/file.h new file mode 100644 index 0000000..7ab6731 --- /dev/null +++ b/libmiav/file.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * file.h + * + * Thu Jun 9 15:31:38 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. + */ +#include "config.h" +#ifndef __MIAV_FILE_H__ +#define __MIAV_FILE_H__ + +#include "info.h" +#include + +#include +#include + +#include + +// For savestate_n +#include "package.h" + +class File { +public: + File(char *filename, char* ext, Info* info); + ~File(); + + int Write(void* data, int size); + std::string Open(); + + void setSaveState(n_savestate savestate); + + +private: + volatile n_savestate savestate; + Info* info; + + std::vector filelist; + + int Move(char *destination); + + int fd; + + int num; + int seqnum; + + char* filename; + char* extension; + + int createPath(char* path); +}; + +#endif/*__MIAV_FILE_H__*/ diff --git a/libmiav/font.h b/libmiav/font.h new file mode 100644 index 0000000..64b5723 --- /dev/null +++ b/libmiav/font.h @@ -0,0 +1,3152 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * font.h + * + * Thu Sep 22 15:40:39 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#ifndef __MIAV_FONT_H__ +#define __MIAV_FONT_H__ + +#define FONT_HEIGHT 10 +#define FONT_WIDTH 8 + +const char palette[] = { + "\0\0\0\0\0\0\0\0\0\0" // 0 - 9 + "\0\0\0\0\0\0\0\0\0\0" // 10 - 19 + "\0\0\0\0\0\0\0\0\0\0" // 20 - 29 + "\0\0\0\0\0\0\0\0\0\0" // 30 - 39 + "\0\0\0\0\0\0\0\0\0\0" // 40 - 49 + "\0\0\0\0\0\0\0\0\0\0" // 50 - 59 + "\0\0\0\0\0\0\0\0\0\0" // 60 - 69 + "\0\0\0\0\0\0\0\0\0\0" // 70 - 79 + "\0\0\0\0\0\0\0\0\0\0" // 80 - 89 + "\0\0\0\0\0\0\0\0\0\0" // 90 - 99 + "\0\0\0\0\0\0\0\0\0\0" //100 -109 + "\0\0\0\0\0\0\0\0\0\0" //110 -119 + "\255\0\0\0\0\0\0\0\0\0" //120 -129 + "\0\0\0\0\0\0\0\0\0\0" //130 -139 + "\0\0\0\0\0\0\0\0\0\0" //140 -149 + "\0\0\0\0\0\0\0\0\0\0" //150 -159 + "\0\0\0\0\0\0\0\0\0\0" //160 -169 + "\0\0\0\0\0\0\0\0\0\0" //170 -179 + "\0\0\0\0\0\0\0\0\0\0" //180 -189 + "\0\0\0\0\0\0\0\0\0\0" //190 -199 + "\0\0\0\0\0\0\0\0\0\0" //200 -209 + "\0\0\0\0\0\0\0\0\0\0" //210 -219 + "\0\0\0\0\0\0\0\0\0\0" //220 -229 + "\0\0\0\0\0\0\0\0\0\0" //230 -239 + "\0\0\0\0\0\0\0\0\0\0" //240 -249 + "\0\0\0\0\0\0" //250 -255 +}; + +const unsigned char letter[FONT_WIDTH + 1][FONT_HEIGHT][255] = { + { // 0 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 1 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 2 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 3 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 4 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 5 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 6 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 7 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 8 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 9 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // 10 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 11 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 12 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 13 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 14 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 15 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 16 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 17 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 18 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 19 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // 20 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 21 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 22 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 23 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 24 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 25 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 26 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 27 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 28 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 29 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // 30 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 31 + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 32 space + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 33 ! + " x ", + " x ", + " x ", + " x ", + " x ", + " x ", + " x ", + " ", + " x ", + " x ", + }, + { // 34 " + " ", + " x x ", + " x x ", + " x x ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // 35 # + " x x ", + " x x ", + "xxxxxxx ", + " x x ", + " x x ", + " x x ", + " x x ", + "xxxxxxx ", + " x x ", + " x x ", + }, + { // 36 $ + " x ", + " xxxxx ", + " x x x ", + "x x x ", + " x x ", + " xxxxx ", + "x x x ", + " x x x ", + " xxxxx ", + " x ", + }, + { // 37 % + " xx x ", + "x x x ", + " xx x ", + " x ", + " x ", + " x ", + " x ", + " x xx ", + "x x x ", + "x xx ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + }, + { // + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + " ", + } +}; + + +#endif/*__MIAV_FONT_H__*/ diff --git a/libmiav/frame.cc b/libmiav/frame.cc new file mode 100644 index 0000000..a274d89 --- /dev/null +++ b/libmiav/frame.cc @@ -0,0 +1,52 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * frame.cc + * + * Mon Nov 15 19:45:07 CET 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 +#include "frame.h" + +#include "debug.h" + +#include +#include + +Frame::Frame(unsigned char *d, int sz) +{ + if(sz) data = new unsigned char[sz]; + if(sz && d) memcpy(data, d, sz); + size = sz; + number = 0; + memset(timecode, 0, sizeof(timecode)); + + endOfFrameStream = false; +} + +Frame::~Frame() +{ + delete data; + data = NULL; + size = 0; +} + diff --git a/libmiav/frame.h b/libmiav/frame.h new file mode 100644 index 0000000..988f460 --- /dev/null +++ b/libmiav/frame.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * frame.h + * + * Mon Nov 15 19:45:07 CET 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" +#ifndef __FRAME_H__ +#define __FRAME_H__ + +// Definition of vector +#include + +class Frame { +public: + Frame(unsigned char *d, int sz); + ~Frame(); + + unsigned char *data; + unsigned int size; + + unsigned int number; + + unsigned int bitrate; + + bool mute; + + bool shoot; + int freeze; // 1 is freeze, -1 is unfreeze + bool record; + char timecode[12]; + + bool endOfFrameStream; +}; + +typedef std::vector< Frame* > FrameVector; + +#endif/*__FRAME_H__*/ diff --git a/libmiav/frame_stream.h b/libmiav/frame_stream.h new file mode 100644 index 0000000..bc0b9a2 --- /dev/null +++ b/libmiav/frame_stream.h @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * frame_stream.h + * + * Thu Jul 28 17:15:27 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. + */ +#include "config.h" +#ifndef __MIAV_FRAME_STREAM_H__ +#define __MIAV_FRAME_STREAM_H__ + +class frame_stream { +public: + frame_stream() {} + virtual ~frame_stream() {} + + virtual unsigned char *readFrame() = 0; +}; + + +#endif/*__MIAV_FRAME_STREAM_H__*/ + diff --git a/libmiav/info.cc b/libmiav/info.cc new file mode 100644 index 0000000..01d69ba --- /dev/null +++ b/libmiav/info.cc @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * info.cc + * + * Mon Jun 13 22:16: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. + */ +#include +#include "info.h" + +#include + +Info::Info() { + pthread_mutex_init (&mutex, NULL); +} + +void Info::log(char *fmt, ...) +{ + // const time_t t; + FILE *fp; + char buf[1024]; + + pthread_mutex_lock(&mutex); + // Beginning of safezone + + fp = fopen(log_filename.c_str(), "a"); + if(!fp) { + fprintf(stderr, "Log file %s could not be opened in writemode.\n", log_filename.c_str()); + return; + } + + va_list argp; + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + + time_t t = time(NULL); + 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); + + // End of safezone + pthread_mutex_unlock(&mutex); +} + + +Info *MIaV::info = NULL; + +void MIaV::setInfo(Info *info) +{ + MIaV::info = info; +} diff --git a/libmiav/info.h b/libmiav/info.h new file mode 100644 index 0000000..776338a --- /dev/null +++ b/libmiav/info.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * info.h + * + * Tue May 3 09:04:04 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. + */ +#include "config.h" +#ifndef __MIAV_INFO_H__ +#define __MIAV_INFO_H__ + +#include "miav_config.h" +// Cyclic include :( +class MiavConfig; + +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +class Info { +public: + Info(); + virtual ~Info() {} + + virtual void error(char* fmt, ...) = 0; + virtual void warn(char* fmt, ...) = 0; + virtual void info(char* fmt, ...) = 0; + void log(char* fmt, ...); + +protected: + MiavConfig *config; + + pthread_mutex_t mutex; + string log_filename; +}; + +namespace MIaV { + extern Info *info; + void setInfo(Info *info); +}; + +#endif/*__MIAV_INFO_H__*/ diff --git a/libmiav/info_simple.cc b/libmiav/info_simple.cc new file mode 100644 index 0000000..a3db393 --- /dev/null +++ b/libmiav/info_simple.cc @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * info_simple.cc + * + * Tue Sep 20 17:00:25 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#include "info_simple.h" + +#include +#include + +InfoSimple::InfoSimple(): Info() +{ +} + +InfoSimple::~InfoSimple() +{ + pthread_mutex_destroy(&mutex); +} + +void InfoSimple::error(char *fmt, ...) +{ + char buf[1024]; + + pthread_mutex_lock(&mutex); + // Beginning of safezone + + va_list argp; + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + + // End of safezone + pthread_mutex_unlock(&mutex); + + fprintf(stderr, "Error: %s\n", buf); +} + +void InfoSimple::warn(char *fmt, ...) +{ + char buf[1024]; + + pthread_mutex_lock(&mutex); + // Beginning of safezone + + va_list argp; + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + + // End of safezone + pthread_mutex_unlock(&mutex); + + fprintf(stderr, "Warning: %s\n", buf); +} + +void InfoSimple::info(char *fmt, ...) +{ + char buf[1024]; + + pthread_mutex_lock(&mutex); + // Beginning of safezone + + va_list argp; + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + + // End of safezone + pthread_mutex_unlock(&mutex); + + fprintf(stderr, "Info: %s\n", buf); +} diff --git a/libmiav/info_simple.h b/libmiav/info_simple.h new file mode 100644 index 0000000..302a371 --- /dev/null +++ b/libmiav/info_simple.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * info_simple.h + * + * Tue Sep 20 17:00:25 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#ifndef __MIAV_INFO_SIMPLE_H__ +#define __MIAV_INFO_SIMPLE_H__ + +#include "info.h" + +class InfoSimple: public Info { +public: + InfoSimple(); + ~InfoSimple(); + + void error(char* fmt, ...); + void warn(char* fmt, ...); + void info(char* fmt, ...); + +private: +}; + +#endif/*__MIAV_INFO_SIMPLE_H__*/ diff --git a/libmiav/jpeg_mem_dest.cc b/libmiav/jpeg_mem_dest.cc new file mode 100644 index 0000000..439c9a8 --- /dev/null +++ b/libmiav/jpeg_mem_dest.cc @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * jpeg_mem_dest.cc + * + * Thu Jul 28 16:40:08 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. + */ +#include +#include "jpeg_mem_dest.h" + +#define OUTPUT_BUF_SIZE 4096 /* choose an efficiently ?? size */ + +/* Expanded data destination object for stdio output */ +typedef struct { + struct jpeg_destination_mgr pub; /* public fields */ + + JOCTET * outbuff; /* target buffer */ + size_t * size; +} mem_destination_mgr; + +typedef mem_destination_mgr * mem_dest_ptr; + +/* + * Initialize destination --- called by jpeg_start_compress + * before any data is actually written. + */ +void init_destination (j_compress_ptr cinfo) +{ + mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; + + *dest->size = 0; + dest->pub.next_output_byte = dest->outbuff; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; +} + +/* + * Terminate destination --- called by jpeg_finish_compress + * after all data has been written. Usually needs to flush buffer. + * + * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding + * application must deal with any cleanup that should happen even + * for error exit. + */ +void term_destination (j_compress_ptr cinfo) +{ + mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; + size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer; + + /* Write any data remaining in the buffer */ + if (datacount > 0) { + dest->outbuff+=datacount; + *dest->size+=datacount; + } +} + +/* + * Empty the output buffer --- called whenever buffer fills up. + * + * In typical applications, this should write the entire output buffer + * (ignoring the current state of next_output_byte & free_in_buffer), + * reset the pointer & count to the start of the buffer, and return TRUE + * indicating that the buffer has been dumped. + * + * In applications that need to be able to suspend compression due to output + * overrun, a FALSE return indicates that the buffer cannot be emptied now. + * In this situation, the compressor will return to its caller (possibly with + * an indication that it has not accepted all the supplied scanlines). The + * application should resume compression after it has made more room in the + * output buffer. Note that there are substantial restrictions on the use of + * suspension --- see the documentation. + * + * When suspending, the compressor will back up to a convenient restart point + * (typically the start of the current MCU). next_output_byte & free_in_buffer + * indicate where the restart point will be if the current call returns FALSE. + * Data beyond this point will be regenerated after resumption, so do not + * write it out when emptying the buffer externally. + */ +boolean empty_output_buffer (j_compress_ptr cinfo) +{ + mem_dest_ptr dest = (mem_dest_ptr) cinfo->dest; + + dest->outbuff+=OUTPUT_BUF_SIZE; + *dest->size+=OUTPUT_BUF_SIZE; + + dest->pub.next_output_byte = dest->outbuff; + dest->pub.free_in_buffer = OUTPUT_BUF_SIZE; + + return TRUE; +} + +/* + * Prepare for output to a memory buffer. + . The caller must have already allocated the buffer, and is responsible + * for closing it after finishing compression. + */ +void jpeg_mem_dest (j_compress_ptr cinfo, char * outbuff, size_t * size) +{ + mem_dest_ptr dest; + + /* The destination object is made permanent so that multiple JPEG images + * can be written to the same file without re-executing jpeg_stdio_dest. + * This makes it dangerous to use this manager and a different destination + * manager serially with the same JPEG object, because their private object + * sizes may be different. Caveat programmer. + */ + if (cinfo->dest == NULL) { /* first time for this JPEG object? */ + cinfo->dest = (struct jpeg_destination_mgr *) + (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, + sizeof(mem_destination_mgr)); + } + + dest = (mem_dest_ptr) cinfo->dest; + dest->pub.init_destination = init_destination; + dest->pub.empty_output_buffer = empty_output_buffer; + dest->pub.term_destination = term_destination; + dest->outbuff = (JOCTET *)outbuff; + dest->size = (size_t *)size; +} diff --git a/libmiav/jpeg_mem_dest.h b/libmiav/jpeg_mem_dest.h new file mode 100644 index 0000000..b1ff103 --- /dev/null +++ b/libmiav/jpeg_mem_dest.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * jpeg_mem_dest.h + * + * Thu Jul 28 16:40:08 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. + */ +//#include "config.h" +#ifndef __MIAV_JPEG_MEM_DEST_H__ +#define __MIAV_JPEG_MEM_DEST_H__ + +#include + +extern "C" { +#include +} + +void jpeg_mem_dest (j_compress_ptr cinfo, char * outbuff, size_t * size); + +#endif/*__MIAV_JPEG_MEM_DEST_H__*/ diff --git a/libmiav/miav.h b/libmiav/miav.h new file mode 100644 index 0000000..6d5068a --- /dev/null +++ b/libmiav/miav.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * miav.h + * + * Mon Nov 8 09:59:24 CET 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" +#ifndef __LIBMIAV_H__ +#define __LIBMIAV_H__ + +#include "util.h" + +#include "network.h" +#include "socket.h" +#include "queue.h" + +#endif/*__LIBMIAV_H__*/ diff --git a/libmiav/miav_config.cc b/libmiav/miav_config.cc new file mode 100644 index 0000000..adfa5c5 --- /dev/null +++ b/libmiav/miav_config.cc @@ -0,0 +1,492 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * miav_config.cc + * + * Sat Feb 19 14:13:19 CET 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. + */ +#include +#include "miav_config.h" + +MiavConfig *config; + +MiavConfig::MiavConfig(char *file, Info *i) +{ + info = i; + configs = NULL; + + filename = string(file); + + // Read config file + FILE* fp = fopen(file, "r"); + + if(!fp) { + 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); + int fsz = ftell(fp) + 1; + fseek(fp, 0, SEEK_SET); + + char *raw = (char*)calloc(fsz, 1); + fread(raw, 1, fsz, fp); + + fclose(fp); + + configs = parse(raw); + + free(raw); +} + +MiavConfig::~MiavConfig() +{ + _cfg *die = NULL; + _cfg *cfg = configs; + + while(cfg) { + if(die) free(die); + die = cfg; + cfg = cfg->next; + } + if(die) free(die); +} + +/** + * Prints a reasonable error message when a parse error occurres. + */ +void MiavConfig::parseError(char* msg, _cfg* cfg) +{ + if(info) info->error("Error parsing file %s at line %d:\n\t%s\n\t%s\n", + filename.c_str(), + cfg->line, + cfg->orig, + msg); + else fprintf(stderr, "Error parsing file %s at line %d:\n\t%s\n\t%s\n", + filename.c_str(), + cfg->line, + cfg->orig, + msg); +} + +_cfg* MiavConfig::readLines(char* raw) +{ + int line = 1; + + _cfg *first = (_cfg*)calloc(1, sizeof(_cfg)); + _cfg *current = first; + _cfg *next = NULL; + + char *nl = strchr(raw, '\n'); + + while(nl != NULL) { + int len = nl - raw; + + current->line = line; + + current->orig = (char*) calloc(len + 1, 1); + strncpy(current->orig, raw, len); + + // Find next newline + raw = nl+1; + nl = strchr(raw, '\n'); + + line++; + + // Add _cfg + if(nl != NULL) { + next = (_cfg*)calloc(1, sizeof(_cfg)); + current->next = next; + current = next; + } else { + current->next = NULL; + } + } + + return first; +} + +_cfg* MiavConfig::parseLines(_cfg *cfg) +{ + if(cfg == NULL) return NULL; + + char *l = cfg->left = (char*)calloc(1, strlen(cfg->orig)); + char *r = cfg->right = (char*)calloc(1, strlen(cfg->orig)); + + char *p = cfg->orig; + + // Skip leftmost whitespace + while(p < cfg->orig + strlen(cfg->orig) && strchr("\t ", *p)) { + p++; + } + + // Empty line, with whitespaces + if(p == cfg->orig + strlen(cfg->orig)) { + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + // Parse left side + while(p < cfg->orig + strlen(cfg->orig) && !strchr("\t ", *p)) { + if(strchr("#", *p)) { + if(l != cfg->left) parseError("Incomplete line.", cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + if(strchr("=", *p)) break; + + if(strchr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_", *p)) { + *l = *p; + l++; + } else { + char buf[256]; + sprintf(buf, "Invalid left hand side character at [%s].", p); + parseError(buf, cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + p++; + } + + // Skip whitespace + while(p < cfg->orig + strlen(cfg->orig) && strchr("\t ", *p)) { + p++; + } + + if(*p != '=') { + parseError("Expected '='.", cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + p++; // Get past the '=' + + // Skip whitespace + while(p < cfg->orig + strlen(cfg->orig) && strchr("\t ", *p)) { + p++; + } + + // Parse right hand side + int instring = 0; + while(p < cfg->orig + strlen(cfg->orig) && !(strchr("\t ", *p) && instring != 1)) { + if(*p == '\"') instring++; + if(instring > 2) { + parseError("Too many '\"'.", cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + if(instring == 1) { + // Accept all chars + *r= *p; + r++; + } else { + // Accept only those chars valid for the data types. + if(strchr("truefalseyesnoTRUEFALSEYESNO1234567890\",.-", *p)) { + if(*p == ',') *r= '.'; + *r = *p; + r++; + } else if(!strchr("\n", *p)) { + char buf[256]; + sprintf(buf, "Invalid right hand side character at [%s].", p); + parseError(buf, cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + if(*p == '#') break; + } + + p++; + } + + // Skip whitespace + while(p < cfg->orig + strlen(cfg->orig) && strchr("\t ", *p)) { + p++; + } + + // Detect if whitespace ocurred inside righthand value. + if(p != cfg->orig + strlen(cfg->orig)) { + parseError("Invalid use of whitespace.", cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + // Check for instring (string not ended) + if(instring == 1) { + parseError("String not closed.", cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + // Check for empty line + if(l == cfg->left && r == cfg->right) { + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + // Check for empty left side. + if(l == cfg->left) { + parseError("Empty left side.", cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + // Check for empty right side. + if(r == cfg->right) { + parseError("Empty right side.", cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return parseLines(next); + } + + cfg->next = parseLines(cfg->next); + return cfg; +} + + +_cfg *MiavConfig::createSemantics(_cfg *cfg) { + if(cfg == NULL) return NULL; + + cfg->type = CONFIG_UNKNOWN; + + // Boolean - true + if(strcasecmp(cfg->right, "yes") == 0 || + strcasecmp(cfg->right, "true") == 0) { + cfg->type = CONFIG_BOOL; + cfg->boolval = true; + } + + // Boolean - false + if(strcasecmp(cfg->right, "no") == 0 || + strcasecmp(cfg->right, "false") == 0) { + cfg->type = CONFIG_BOOL; + cfg->boolval = false; + } + + // String + if(cfg->right[0] == '\"') { + cfg->type = CONFIG_STRING; + cfg->right[strlen(cfg->right) - 1] = '\0'; + cfg->stringval = new string(cfg->right + 1); + + } + + // Number + bool number = true; + char *p = cfg->right; + while(p < cfg->right + strlen(cfg->right)) { + if(!strchr("01234567890.-", *p)) number = false; + p++; + } + + // Integer + if(number && strstr(cfg->right, ".") == NULL ) { + cfg->type = CONFIG_INT; + cfg->intval = atoi(cfg->right); + } + + // Float + if(number && strstr(cfg->right, ".") != NULL) { + cfg->type = CONFIG_FLOAT; + cfg->floatval = atof(cfg->right); + } + + if(cfg->type == CONFIG_UNKNOWN) { + parseError("Unknown type (see 'man miav.conf' for valid right hand sides).", cfg); + _cfg* next = cfg->next; + free(cfg->orig); + free(cfg->left); + free(cfg->right); + free(cfg); + return createSemantics(next); + } + + // Create name + cfg->name = new string(cfg->left); + + cfg->next = createSemantics(cfg->next); + return cfg; +} + + +_cfg* MiavConfig::parse(char* raw) +{ + _cfg *first = readLines(raw); + first = parseLines(first); + + first = createSemantics(first); + + /* + _cfg* cfg = first; + while(cfg) { + printf("Node:\n"); + printf("\tLine: [%d]\n", cfg->line); + printf("\tOrig: [%s]\n", cfg->orig); + printf("\tLeft: [%s]\n", cfg->left); + printf("\tRight: [%s]\n", cfg->right); + + switch(cfg->type) { + case CONFIG_INT: + printf("\tInt value: %d\n", cfg->intval); + break; + case CONFIG_BOOL: + printf("\tBool value: %d\n", cfg->boolval); + break; + case CONFIG_FLOAT: + printf("\tFloat value: %f\n", cfg->floatval); + break; + case CONFIG_STRING: + printf("\tString value: %s\n", cfg->stringval->c_str()); + break; + case CONFIG_UNKNOWN: + printf("\tUnknown type: %s\n", cfg->right); + break; + } + + cfg= cfg->next; + } + */ + return first; +} + +int MiavConfig::readInt(char *node) +{ + _cfg* n = findNode(node); + if(n) { + if(n->type == CONFIG_INT) return n->intval; + parseError("Expected integer.", n); + } + return 0; +} + +bool MiavConfig::readBool(char *node) +{ + _cfg* n = findNode(node); + if(n) { + if(n->type == CONFIG_BOOL) return n->boolval; + if(n->type == CONFIG_INT) return (n->intval != 0); + parseError("Expected boolean.", n); + } + return false; +} + +string *MiavConfig::readString(char *node) +{ + _cfg* n = findNode(node); + if(n) { + if(n->type == CONFIG_STRING) return n->stringval; + parseError("Expected string.", n); + } + return &emptyString; +} + +float MiavConfig::readFloat(char *node) +{ + _cfg* n = findNode(node); + if(n) { + if(n->type == CONFIG_FLOAT) return n->floatval; + if(n->type == CONFIG_INT) return (float)n->intval; + parseError("Expected float.", n); + } + return 0.0f; +} + +_cfg *MiavConfig::findNode(char* node) +{ + _cfg *cfg = configs; + + while(cfg) { + if(!strcmp(node, cfg->name->c_str())) return cfg; + cfg = cfg->next; + } + if(info) info->error("Missing line in configuration file: \"%s\"!\n", node); + else fprintf(stderr, "Missing line in configuration file: \"%s\"!\n", node); + + return NULL; +} + +#ifdef __TEST_MIAV_CONFIG + +int main(int argc, char *argv[]) { + if(argc < 2) { + fprintf(stderr, "usage:\n\tmiav_config [filename]\n"); + return 1; + } + + MiavConfig cfg(argv[1]); + printf("Server user: [%s]\n", cfg.readString("server_user")->c_str()); + printf("Resolution: [%f]\n", cfg.readFloat("screensize")); + printf("Resolution (as int): [%d]\n", cfg.readInt("screensize")); + printf("Width: [%d]\n", cfg.readInt("pixel_width")); + printf("Width (as float): [%f]\n", cfg.readFloat("pixel_width")); + printf("Frame quality: [%d]\n", cfg.readInt("frame_quality")); + printf("Skip frames: [%d]\n", cfg.readBool("player_skip_frames")); + printf("Skip frames (as int): [%d]\n", cfg.readInt("player_skip_frames")); + printf("Frame quality (as bool): [%d]\n", cfg.readBool("frame_quality")); + +} + +#endif/* __TEST_MIAV_CONFIG*/ diff --git a/libmiav/miav_config.h b/libmiav/miav_config.h new file mode 100644 index 0000000..a8658f1 --- /dev/null +++ b/libmiav/miav_config.h @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * miav_config.h + * + * Sat Feb 19 14:13:19 CET 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. + */ +#include "config.h" +#ifndef __MIAV_MIAV_CONFIG_H__ +#define __MIAV_MIAV_CONFIG_H__ + +#include +using namespace std; + +#include "info.h" +// Cyclic include :( +class Info; + +typedef enum { + CONFIG_UNKNOWN, + CONFIG_INT, + CONFIG_BOOL, + CONFIG_FLOAT, + CONFIG_STRING +} ConfigType; + + +typedef struct __cfg { + // For parsing + char* orig; + int line; + char* left; + char* right; + + // For traversal + string *name; + ConfigType type; + int intval; + bool boolval; + float floatval; + string *stringval; + + struct __cfg* next; +} _cfg; + +class MiavConfig { +public: + MiavConfig(char *file, Info *info = NULL); + ~MiavConfig(); + + int readInt(char *node); + bool readBool(char *node); + string *readString(char *node); + float readFloat(char *node); + +protected: + Info *info; + string filename; + + _cfg *createSemantics(_cfg *cfg); + _cfg* readLines(char* raw); + _cfg* parseLines(_cfg *cfg); + _cfg *parse(char* raw); + string emptyString; + + +#if 0 + _cfg *addConfig(_cfg *parent, char* conf); + char *strip(char* conf); +#endif + + void parseError(char* msg, _cfg *cfg); + _cfg *findNode(char* node); + _cfg *configs; +}; + +extern MiavConfig *config; + +#endif/*__MIAV_MIAV_CONFIG_H__*/ diff --git a/libmiav/mutex.cc b/libmiav/mutex.cc new file mode 100644 index 0000000..483d71a --- /dev/null +++ b/libmiav/mutex.cc @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mutex.cc + * + * Sat Oct 8 17:44:09 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#include "mutex.h" + +Mutex::Mutex() +{ + pthread_mutex_init (&mutex, NULL); +} + +Mutex::~Mutex() +{ + pthread_mutex_destroy(&mutex); +} + +void Mutex::lock() +{ + pthread_mutex_lock( &mutex ); +} + +void Mutex::unlock() +{ + pthread_mutex_unlock( &mutex ); +} diff --git a/libmiav/mutex.h b/libmiav/mutex.h new file mode 100644 index 0000000..0b1f4e7 --- /dev/null +++ b/libmiav/mutex.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * mutex.h + * + * Sat Oct 8 17:44:09 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#ifndef __MIAV_MUTEX_H__ +#define __MIAV_MUTEX_H__ + +#include + +class Mutex { +public: + Mutex(); + ~Mutex(); + + void lock(); + void unlock(); + +private: + pthread_mutex_t mutex; +}; + +#endif/*__MIAV_MUTEX_H__*/ diff --git a/libmiav/network.cc b/libmiav/network.cc new file mode 100644 index 0000000..6917d86 --- /dev/null +++ b/libmiav/network.cc @@ -0,0 +1,172 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * network.cc + * + * Wed Nov 3 21:23:14 CET 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 +#include "network.h" + +#include +#include +#include +#include +#include +#include + +#include "util.h" + +Network::Network(Socket *gs, Info *ginfo) +{ + info = ginfo; + s = gs; +} + +Network::~Network() +{ +} + +int Network::write(void *buf, int size) +{ + if(!s->isConnected()) { + // info->error("Write attempted to a socket not connected!"); + return -1; + } + int n = send(s->ssocket, buf, size, MSG_WAITALL); + + if(n == -1) { + info->error("An error occurred!"); + } + + return n; +} + +int Network::read(void *buf, int size) +{ + if(!s->isConnected()) { + // info->error("Read attempted from a socket not connected!"); + return -1; + } + int n = recv(s->ssocket, buf, size, MSG_WAITALL); + + if(n == -1) { + info->error("An error occurred!"); + } + + return n; +} + +/* +struct msghdr { + void *msg_name // Optional address. + socklen_t msg_namelen // Size of address. + struct iovec *msg_iov // Scatter/gather array. + int msg_iovlen // Members in msg_iov. + void *msg_control // Ancillary data; see below. + socklen_t msg_controllen // Ancillary data buffer len. + int msg_flags // Flags on received message. +}; +*/ + +int Network::sendPackage(n_header *h, void* buf, int bufsz) +{ + struct msghdr msg; + struct iovec iovecs[2]; + + if(!s->isConnected()) { + // info->error("Write attempted to a socket not connected!"); + return -1; + } + + memset(&msg, 0, sizeof(msg)); + + msg.msg_iov = iovecs; + msg.msg_iovlen = 2; + + msg.msg_iov[0].iov_base = h; + msg.msg_iov[0].iov_len = sizeof(*h); + + msg.msg_iov[1].iov_base = buf; + msg.msg_iov[1].iov_len = bufsz; + + msg.msg_flags = MSG_DONTWAIT; + + int n; + /* + int cnt = 0; + while((n = sendmsg(s->ssocket, &msg, 0)) == -1 && errno == EAGAIN) { + // printf("(timeout)!"); + sleep_1_frame(); + if(cnt > 250) { + // printf("A network error ocurred during sendPackage (timeout)!"); + info->error("A network error ocurred during sendPackage (timeout)!"); + return -1; + } + cnt++; + } + */ + n = sendmsg(s->ssocket, &msg, 0); + + if(n < 0) { + info->error("A network error ocurred during sendPackage!"); + return -1; + } + + return n; +} + +int Network::recvPackage(n_header *h, void* buf, int bufsz) +{ + struct msghdr msg; + struct iovec iovecs[2]; + + if(!s->isConnected()) { + // info->error("Read attempted to a socket not connected!"); + return -1; + } + + memset(&msg, 0, sizeof(msg)); + + iovecs[0].iov_base = h; + iovecs[0].iov_len = sizeof(*h); + + iovecs[1].iov_base = buf; + iovecs[1].iov_len = bufsz; + + msg.msg_iov = iovecs; + msg.msg_iovlen = 2; + + int n = recvmsg(s->ssocket, &msg, MSG_WAITALL); + + if(n < 0) { + info->error("A network error ocurred during recvPackage!"); + return -1; + } + + if(msg.msg_iovlen != 2) { + info->error("Wrong package format!"); + return -1; + } + return n; +} + diff --git a/libmiav/network.h b/libmiav/network.h new file mode 100644 index 0000000..f64310e --- /dev/null +++ b/libmiav/network.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * network.h + * + * Wed Nov 3 21:23:14 CET 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" +#ifndef __MIAVLIB_NETWORK_H__ +#define __MIAVLIB_NETWORK_H__ + +#include "socket.h" +#include "package.h" +#include "info.h" + +class Network { +public: + Network(Socket *gs, Info* ginfo); + ~Network(); + + // Raw communication + int write(void *buf, int size); + int read(void *buf, int size); + + // Package communication + int sendPackage(n_header *h, void* buf, int bufsz); + int recvPackage(n_header *h, void* buf, int bufsz); + +private: + Info *info; + Socket *s; +}; + +#endif/*__NETWORK_H__*/ + + diff --git a/libmiav/package.h b/libmiav/package.h new file mode 100644 index 0000000..a16557a --- /dev/null +++ b/libmiav/package.h @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * package.h + * + * Tue Nov 9 10:57:20 CET 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" +#ifndef __MIAVLIB_PACKAGE_H__ +#define __MIAVLIB_PACKAGE_H__ + +typedef enum { + NO_CHANGE = 0, + SAVE, + DELETE, + LATER +} n_savestate; + +typedef enum { + DATA_HEADER = 0x0001, + INFO_HEADER = 0x0002 +} n_header_type; + +typedef struct { + n_header_type header_type; + union { + struct { + char cpr[32]; // Can hold wierd cpr numbers as well (not only danish) + bool record; + bool freeze; + bool snapshot; + n_savestate savestate; + bool mute; + } h_data; + struct { + int fisk; + } h_info; + } header; +} n_header; + + +#endif/*__PACKAGE_H__*/ + + diff --git a/libmiav/queue.h b/libmiav/queue.h new file mode 100644 index 0000000..3cb6fbc --- /dev/null +++ b/libmiav/queue.h @@ -0,0 +1,248 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * queue.h + * + * Tue Nov 9 10:57:20 CET 2004 + * Copyright 2004 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" +#ifndef __RTVIDEOREC_QUEUE_H +#define __RTVIDEOREC_QUEUE_H + +#include +#include +#include +#include +//#include +//#include + +#include "thread.h" +#include "util.h" + +typedef struct __buf_t { + struct __buf_t *next; + struct __buf_t *prev; + void *data; +} buf_t; + + +template +class Queue { +public: + Queue(int glimit = 0); + ~Queue(); + + void push(T *t); + T *pop(); + T *peek(); + + void lock(); + void unlock(); + + int length(); + +private: + volatile bool locked; + int limit; + buf_t *head; + buf_t *tail; + int count; + pthread_mutex_t mutex; + T *_pop(); +}; + +/** + * Initialize queue + */ +template +Queue::Queue(int glimit) +{ + locked = false; + pthread_mutex_init (&mutex, NULL); + limit = glimit; + count = 0; + head = NULL; + tail = NULL; +} + +/** + * Clean up queue. + */ +template +Queue::~Queue() +{ + if(count != 0) { + fprintf(stderr, "Queue not empty (%d)\n", count); + while(T *t = _pop()) delete t; + } + pthread_mutex_destroy(&mutex); +} + +/** + * Push element on queue. + */ +template +void Queue::push(T *t) +{ + if(locked) { + delete t; + return; + } + + pthread_mutex_lock(&mutex); + + buf_t *b = (buf_t*)xmalloc(sizeof(*b)); + b->data = (void*)t; + + assert(b != NULL); + + if(limit && count > 0) { + T* tmp = (T*)_pop(); + delete tmp; + } + + if(!head) { + head = tail = b; + b->next = b->prev = NULL; + count = 1; + pthread_mutex_unlock(&mutex); + return; + } + + b->next = tail; + b->prev = NULL; + if(tail) + tail->prev = b; + tail = b; + count++; + + pthread_mutex_unlock(&mutex); +} + +/** + * Pop element from queue. + * If queue is empty, NULL is returned. + */ +template +T *Queue::pop() +{ + pthread_mutex_lock(&mutex); + T *d = _pop(); + pthread_mutex_unlock(&mutex); + return d; +} + +/** + * Pop helper method + * If queue is empty, NULL is returned. + */ +template +T *Queue::_pop() +{ + T *d; + buf_t *b; + + assert(count >= 0); + + if(count == 0) { + return NULL; + } + + b = head; + if(b->prev) + b->prev->next = NULL; + head = b->prev; + if(b == tail) + tail = NULL; + count--; + + d = (T*)b->data; + free(b); + + return d; +} + +/** + * Peek foremost element in queue + * If queue is empty, NULL is returned. + */ +template +T *Queue::peek() +{ + // pthread_mutex_lock(&mutex); + T *d; + + // assert(count >= 0); + + if(count == 0) { + return NULL; + } + + d = (T*)head->data; + // pthread_mutex_unlock(&mutex); + return d; +} + +/** + * Print current length of queue + */ +template +int Queue::length() +{ + int length; + pthread_mutex_lock(&mutex); + length = count; + pthread_mutex_unlock(&mutex); + return length; +} + +/** + * Lock the queue (all elements pushed from this point will be deleted.) + */ +template +void Queue::lock() +{ + fprintf(stderr, "Lock this motherfucker..."); fflush(stderr); + locked = true; + fprintf(stderr, "done\n"); fflush(stderr); +} + +/** + * Unlock the queue. + */ +template +void Queue::unlock() +{ + fprintf(stderr, "Unlock this motherfucker..."); fflush(stderr); + locked = false; + fprintf(stderr, "done\n"); fflush(stderr); +} + +#endif + diff --git a/libmiav/semaphore.cc b/libmiav/semaphore.cc new file mode 100644 index 0000000..147bd24 --- /dev/null +++ b/libmiav/semaphore.cc @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * semaphore.cc + * + * Sat Oct 8 17:44:13 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#include "semaphore.h" + +Semaphore::Semaphore() +{ + sem_init(&semaphore, 0, 0); +} + +Semaphore::~Semaphore() +{ + sem_destroy(&semaphore); +} + +void Semaphore::post() +{ + sem_post(&semaphore); +} + +void Semaphore::wait() +{ + sem_wait(&semaphore); +} diff --git a/libmiav/semaphore.h b/libmiav/semaphore.h new file mode 100644 index 0000000..85f4c09 --- /dev/null +++ b/libmiav/semaphore.h @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * semaphore.h + * + * Sat Oct 8 17:44:13 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#ifndef __MIAV_SEMAPHORE_H__ +#define __MIAV_SEMAPHORE_H__ + +#include + +class Semaphore { +public: + Semaphore(); + ~Semaphore(); + + void post(); + void wait(); + +private: + sem_t semaphore; +}; + +#endif/*__MIAV_SEMAPHORE_H__*/ diff --git a/libmiav/server_status.cc b/libmiav/server_status.cc new file mode 100644 index 0000000..7f4714e --- /dev/null +++ b/libmiav/server_status.cc @@ -0,0 +1,77 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * server_status.cc + * + * Fri Apr 29 13:58:26 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. + */ +#include +#include "server_status.h" + +#include + +ServerStatus::ServerStatus(Info *i) +{ + info = i; + + gettimeofday(&oldtime, NULL); + + for(int cnt = 0; cnt < BUFFERSIZE; cnt++) { + frametime[cnt] = 41660; + } + + gettimeofday(&time, NULL); + + interval = 0; +} + +ServerStatus::~ServerStatus() +{ +} + +void ServerStatus::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); + + interval += frametime[0]; + if(interval > UPD) { + interval = 0; + double total = 0.0; + for(int cnt = 0; cnt < BUFFERSIZE; cnt++) { + total += (double)frametime[cnt]; + } + info->info("Status - fps: %f", 1000000.0 / (total / (double)BUFFERSIZE)); + } + +} + +/* +date(1), gettimeofday(2), ctime(3), ftime(3) +*/ diff --git a/libmiav/server_status.h b/libmiav/server_status.h new file mode 100644 index 0000000..5a7cb6c --- /dev/null +++ b/libmiav/server_status.h @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * server_status.h + * + * Fri Apr 29 13:58:26 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. + */ +#include "config.h" +#ifndef __MIAV_SERVER_STATUS_H__ +#define __MIAV_SERVER_STATUS_H__ + +#include "info.h" + +#include + +// How many steps to do avarage calculation over. +#define BUFFERSIZE 100 + +// Interval in us (microseconds) +#define UPD 60 * 1000 * 1000 // 1 minute + +class ServerStatus { +public: + ServerStatus(Info *info); + ~ServerStatus(); + + void checkPoint(); + +private: + long long interval; + Info *info; + unsigned int frametime[BUFFERSIZE]; + struct timeval time; + struct timeval oldtime; +}; + +#endif/*__MIAV_SERVER_STATUS_H__*/ diff --git a/libmiav/socket.cc b/libmiav/socket.cc new file mode 100644 index 0000000..2ae88dc --- /dev/null +++ b/libmiav/socket.cc @@ -0,0 +1,150 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * socket.cc + * + * Mon Nov 8 10:49:33 CET 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 + +#include "socket.h" + +#include + +Socket::Socket(Info *ginfo) +{ + info = ginfo; + connected = false; + err = 0; +} + +Socket::Socket(u_short port, Info *ginfo) +{ + info = ginfo; + connected = false; + err = 0; + + // create socket + ssocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); + // PF_INET: ipv4, PF_INET6: ipv6 + // tcp: IPPROTO_TCP + // upd: IPPROTO_UDP + + if (ssocket < 0) { + err = 1; + info->error("Socket: socket() failed!"); + } + + socketaddr.sin_family = AF_INET; // Use "internet protocol" IP + socketaddr.sin_port = htons(port); // connect to that port + socketaddr.sin_addr.s_addr = INADDR_ANY; + // INADDR_ANY puts your IP address automatically +} + + +Socket::~Socket() +{ + // if(err) perror("Socket: No socket to kill"); + // printf("Socket: I'm melting...[%d]\n", ssocket); + if(ssocket >= 0) close(ssocket); // close server socket +} + + +Socket Socket::slisten() +{ + Socket s = Socket(info); + + if(err) { + //info->error("Socket: No socket present!"); + return s; + } + if(!connected) { + // bind socket to address specified by "sa" parameter + err = bind(ssocket, (struct sockaddr*)&socketaddr, sizeof(socketaddr)); + + if (err) { + info->error("Socket: bind() failed! %s", strerror(errno)); + return s; + } + + // start listen for connection - kernel will accept connection + // requests (max 5 in queue) + err = listen(ssocket, 5); + if(err) { + info->error("Socket: listen() failed! %s", strerror(errno)); + return s; + } + } + + // accept new connection and get its connection descriptor + int csalen = sizeof(s.socketaddr); + + s.ssocket = accept(ssocket, + (struct sockaddr*)&s.socketaddr, + (socklen_t*)&csalen); + + if (s.ssocket < 0) { + s.connected = false; + err = 1; + info->error("Socket: accept() failed! %s", strerror(errno)); + return s; + } + + connected = true; + s.connected = true; + return s; +} + + +int Socket::sconnect(char *ip) +{ + if(err) { + connected = false; + info->error("Socket: No socket present!"); + return err; + } + + // FIXME: gethostbyname() + socketaddr.sin_addr.s_addr = inet_addr(ip); + //inet_aton (ip, &socketaddr.sin_addr); + + err = connect(ssocket, (struct sockaddr*)&socketaddr, sizeof(socketaddr)); + if (err) { + connected = false; + info->error("Socket: connect() failed! %s", strerror(errno)); + return err; + } + // fprintf(stderr, "Socket connected\n"); + connected = true; + return 0; +} + + +bool Socket::isConnected() +{ + return connected; +} + +bool Socket::hasError() +{ + return err != 0; +} diff --git a/libmiav/socket.h b/libmiav/socket.h new file mode 100644 index 0000000..df2a133 --- /dev/null +++ b/libmiav/socket.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * socket.h + * + * Mon Nov 8 10:49:33 CET 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" +#ifndef __MIAVLIB_SOCKET_H__ +#define __MIAVLIB_SOCKET_H__ + +#include +#include + +#include +#include +#include +#include +#include + +#include "info.h" + +class Socket { +public: + Socket(Info *ginfo); + Socket(u_short port, Info *ginfo); + ~Socket(); + Socket slisten(); + int sconnect(char *ip); + bool isConnected(); + bool hasError(); + + struct sockaddr_in socketaddr; + int ssocket; + bool connected; + +private: + Info *info; + int err; +}; + +#endif/*__SOCKET_H__*/ diff --git a/libmiav/thread.cc b/libmiav/thread.cc new file mode 100644 index 0000000..147cf00 --- /dev/null +++ b/libmiav/thread.cc @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * thread.cc + * + * Sun Oct 31 12:12:20 CET 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 + +#include "thread.h" +#include + +static void* thread_run(void *data) { + Thread *t = (Thread*)data; + t->thread_main(); + return NULL; +} + +Thread::Thread() +{ +} + +Thread::~Thread() +{ +} + +void Thread::run() +{ + pthread_attr_init(&attr); + + pthread_create(&tid, &attr, thread_run, this); +} + +void Thread::wait_stop() +{ + pthread_join(tid, NULL); +} diff --git a/libmiav/thread.h b/libmiav/thread.h new file mode 100644 index 0000000..3d58d74 --- /dev/null +++ b/libmiav/thread.h @@ -0,0 +1,49 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * thread.h + * + * Sun Oct 31 12:12:20 CET 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" +#ifndef __THREAD_H__ +#define __THREAD_H__ + +#include +#include + +class Thread { +public: + Thread(); + virtual ~Thread(); + + void run(); + void wait_stop(); + + virtual void thread_main() = 0; + +private: + pthread_attr_t attr; + pthread_t tid; +}; + +#endif/*__THREAD_H__*/ diff --git a/libmiav/threadsafe_queue.cc b/libmiav/threadsafe_queue.cc new file mode 100644 index 0000000..89f2d6a --- /dev/null +++ b/libmiav/threadsafe_queue.cc @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * threadsafe_queue.cc + * + * Tue Sep 27 14:43:45 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#include "threadsafe_queue.h" +/* +template +ThreadSafeQueue::ThreadSafeQueue() +{ + pthread_mutex_init (&mutex, NULL); + sem_init(&semaphore, 0, 0); +} + +template +ThreadSafeQueue::~ThreadSafeQueue() +{ + pthread_mutex_destroy(&mutex); + sem_destroy(&semaphore); +} + +*/ diff --git a/libmiav/threadsafe_queue.h b/libmiav/threadsafe_queue.h new file mode 100644 index 0000000..b6d5725 --- /dev/null +++ b/libmiav/threadsafe_queue.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * threadsafe_queue.h + * + * Tue Sep 27 14:01:01 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#ifndef __MIAV_THREADSAFE_QUEUE_H__ +#define __MIAV_THREADSAFE_QUEUE_H__ + +#include "mutex.h" +#include "semaphore.h" + +template +class ThreadSafeQueue { +public: + ThreadSafeQueue() { + // pthread_mutex_init (&mutex, NULL); + // sem_init(&semaphore, 0, 0); + } + + virtual ~ThreadSafeQueue() { + // pthread_mutex_destroy(&mutex); + //sem_destroy(&semaphore); + } + + virtual void push(T t) = 0; + virtual T pop() = 0; + virtual int size() = 0; + +protected: + // pthread_mutex_t mutex; + Mutex mutex; + //sem_t semaphore; + Semaphore semaphore; +}; + +#endif/*__MIAV_THREADSAFE_QUEUE_H__*/ diff --git a/libmiav/threadsafe_queue_fifo.cc b/libmiav/threadsafe_queue_fifo.cc new file mode 100644 index 0000000..6dbcb67 --- /dev/null +++ b/libmiav/threadsafe_queue_fifo.cc @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * threadsafe_queue_fifo.cc + * + * Tue Sep 27 14:01:10 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#include "threadsafe_queue_fifo.h" + +ThreadSafeQueueFIFO::ThreadSafeQueueFIFO() +{ +} + +ThreadSafeQueueFIFO::~ThreadSafeQueueFIFO() +{ +} + +void ThreadSafeQueueFIFO::push(FrameVector *framevector) +{ + mutex.lock(); + queue.push(framevector); + mutex.unlock(); + + semaphore.post(); +} + +FrameVector *ThreadSafeQueueFIFO::pop() +{ + semaphore.wait(); + + FrameVector *framevector; + + mutex.lock(); + framevector = queue.front(); + queue.pop(); + mutex.unlock(); + + return framevector; +} + +int ThreadSafeQueueFIFO::size() +{ + int sz; + + mutex.lock(); + sz = queue.size(); + mutex.unlock(); + + return sz; +} diff --git a/libmiav/threadsafe_queue_fifo.h b/libmiav/threadsafe_queue_fifo.h new file mode 100644 index 0000000..ee3ac3b --- /dev/null +++ b/libmiav/threadsafe_queue_fifo.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * threadsafe_queue_fifo.h + * + * Tue Sep 27 14:01:10 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#ifndef __MIAV_THREADSAFE_QUEUE_FIFO_H__ +#define __MIAV_THREADSAFE_QUEUE_FIFO_H__ + +#include "threadsafe_queue.h" + +#include "frame.h" + +#include + +class ThreadSafeQueueFIFO: public ThreadSafeQueue { +public: + ThreadSafeQueueFIFO(); + ~ThreadSafeQueueFIFO(); + + void push(FrameVector* framevector); + FrameVector* pop(); + int size(); + +private: + std::queue queue; +}; + +#endif/*__MIAV_THREADSAFE_QUEUE_FIFO_H__*/ diff --git a/libmiav/threadsafe_queue_priority.cc b/libmiav/threadsafe_queue_priority.cc new file mode 100644 index 0000000..df7ae8c --- /dev/null +++ b/libmiav/threadsafe_queue_priority.cc @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * threadsafe_queue_priority.cc + * + * Tue Sep 27 14:01:24 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#include "threadsafe_queue_priority.h" + +#include "util.h" + +ThreadSafeQueuePriority::ThreadSafeQueuePriority(Info* i, unsigned int number) + // : ThreadSafeQueue< Frame* >() +{ + info = i; + framenumber = number; +} + +ThreadSafeQueuePriority::~ThreadSafeQueuePriority() +{ +} + +void ThreadSafeQueuePriority::push(Frame *frame) +{ + // Lock mutex + // pthread_mutex_lock( &mutex ); + mutex.lock(); + queue.push(frame); + // pthread_mutex_unlock( &mutex ); + mutex.unlock(); + // Unlock mutex + + // sem_post(&semaphore); + semaphore.post(); +} + +Frame *ThreadSafeQueuePriority::pop() +{ + semaphore.wait(); + // sem_wait(&semaphore); + + Frame *tmpframe = NULL; + Frame *frame = NULL; + + while( frame == NULL ) { + // Lock mutex + // pthread_mutex_lock( &mutex ); + mutex.lock(); + + tmpframe = queue.top(); + + if(tmpframe && tmpframe->number == framenumber ) { + queue.pop(); + frame = tmpframe; + framenumber++; + } + + // pthread_mutex_unlock( &mutex ); + mutex.unlock(); + // Unlock mutex + + if(frame == NULL) sleep_0_2_frame(); + } + + return frame; +} + +int ThreadSafeQueuePriority::size() +{ + int sz; + + // Lock mutex + // pthread_mutex_lock( &mutex ); + mutex.lock(); + sz = queue.size(); + // pthread_mutex_unlock( &mutex ); + mutex.unlock(); + // Unlock mutex + + return sz; +} diff --git a/libmiav/threadsafe_queue_priority.h b/libmiav/threadsafe_queue_priority.h new file mode 100644 index 0000000..8d3cdf1 --- /dev/null +++ b/libmiav/threadsafe_queue_priority.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * threadsafe_queue_priority.h + * + * Tue Sep 27 14:01:24 CEST 2005 + * Copyright 2005 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. + */ +#include "config.h" +#ifndef __MIAV_THREADSAFE_QUEUE_PRIORITY_H__ +#define __MIAV_THREADSAFE_QUEUE_PRIORITY_H__ + +#include "threadsafe_queue.h" + +#include "frame.h" + +#include +#include + +#include "info.h" + +// Method for use, when comparing Frames in priority queue. +template +struct priority : std::binary_function { + bool operator() (const T& a, const T& b) const { + return ((Frame*)a)->number > ((Frame*)b)->number; + } +}; + +class ThreadSafeQueuePriority: public ThreadSafeQueue< Frame* > { +public: + ThreadSafeQueuePriority(Info *info, unsigned int framenumber = 0); + ~ThreadSafeQueuePriority(); + + void push(Frame *frame); + Frame *pop(); + int size(); + +private: + Info* info; + + unsigned int framenumber; + std::priority_queue< Frame*, std::vector, priority > queue; +}; + +#endif/*__MIAV_THREADSAFE_QUEUE_PRIORITY_H__*/ diff --git a/libmiav/util.cc b/libmiav/util.cc new file mode 100644 index 0000000..11f1402 --- /dev/null +++ b/libmiav/util.cc @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * util.cc + * + * Sun Oct 31 12:12:20 CET 2004 + * Copyright 2004 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 + +#include +#include +#include +#include + +// For nanosleep +#include + +#include "util.h" + +void *xmalloc(size_t s) +{ + void *p; + assert(s > 0); + + p = malloc(s); + if(!p) { + fprintf(stderr, "Out of memory in xmalloc\n"); + exit(1); + } + memset(p, 0, s); + return p; +} + +void *xrealloc(void *b, size_t s) +{ + void *p; + assert(s > 0); + + if(!b) return xmalloc(s); + + p = realloc(b, s); + if(!p) { + fprintf(stderr, "Out of memory in xrealloc\n"); + exit(1); + } + return p; +} + +void sleep_1_frame() +{ + // Sleep 1/25th of a second + + struct timespec ts; + + ts.tv_sec = 0; + ts.tv_nsec = 1000000000L / 25L; // 1000ms / 25 + nanosleep(&ts, NULL); +} + +void sleep_0_2_frame() +{ + // Sleep 1/25th of a second + + struct timespec ts; + + ts.tv_sec = 0; + ts.tv_nsec = 8000000L;//1000000000L / 25L * 0.2; // 1000ms / 25 + nanosleep(&ts, NULL); +} diff --git a/libmiav/util.h b/libmiav/util.h new file mode 100644 index 0000000..ef21e06 --- /dev/null +++ b/libmiav/util.h @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * util.h + * + * Mon Nov 8 10:49:33 CET 2004 + * Copyright 2004 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" +#ifndef __RTVIDEOREC_UTIL_H +#define __RTVIDEOREC_UTIL_H + +#include +//#include + +//#ifdef __cplusplus +//extern "C" { +//#endif + +void *xmalloc(size_t s); +void *xrealloc(void *b, size_t s); + +void sleep_1_frame(); +void sleep_0_2_frame(); +//#ifdef __cplusplus +//} +//#endif + +#endif -- cgit v1.2.3