From 0791ce8426fe56246afa4123c37388c2f506f8ce Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 29 Apr 2005 13:53:47 +0000 Subject: Testing mpeg4 (divx) codec --- src/Makefile.am | 6 +++-- src/frame.cc | 2 +- src/mov_encoder.cc | 12 ++++++--- src/player.cc | 2 ++ src/server.cc | 15 ++++++++---- src/server_status.cc | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/server_status.h | 50 +++++++++++++++++++++++++++++++++++++ tools/MIaVAdd | 3 +++ 8 files changed, 147 insertions(+), 12 deletions(-) create mode 100644 src/server_status.cc create mode 100644 src/server_status.h diff --git a/src/Makefile.am b/src/Makefile.am index b23a966..6edcd73 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -29,7 +29,8 @@ miav_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; fi ) \ img_encoder.cc \ server.cc \ error.cc \ - dv1394.cc + dv1394.cc \ + server_status.cc EXTRA_DIST = \ miav.conf \ @@ -58,7 +59,8 @@ EXTRA_DIST = \ videowidget.h \ debug.h \ dv.h \ - dv1394.cc + dv1394.cc \ + server_status.h miav_LDADD := $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList o; fi ) \ -lavcodec -lavformat diff --git a/src/frame.cc b/src/frame.cc index 4b94fcb..23d98ce 100644 --- a/src/frame.cc +++ b/src/frame.cc @@ -34,7 +34,7 @@ Frame::Frame(unsigned char *d, int sz) { data = (unsigned char *)malloc(sz); - memcpy(data, d, sz); + if(d) memcpy(data, d, sz); size = sz; } diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc index 52702a5..01a5c5a 100644 --- a/src/mov_encoder.cc +++ b/src/mov_encoder.cc @@ -41,7 +41,8 @@ MovEncoder::MovEncoder(const char *filename) exit(1); } - efc->oformat = guess_format("mpeg", NULL, NULL); + efc->oformat = guess_format("avi", NULL, NULL); + // efc->oformat = guess_format("mpeg", NULL, NULL); //efc->oformat = guess_format(NULL, filename, NULL); if(!(st = av_new_stream(efc, 0))) { @@ -65,15 +66,18 @@ MovEncoder::MovEncoder(const char *filename) exit(1); } - enc_codec = avcodec_find_encoder(CODEC_ID_MPEG2VIDEO); + enc_codec = avcodec_find_encoder(CODEC_ID_MPEG4); + // enc_codec = avcodec_find_encoder(CODEC_ID_MPEG2VIDEO); if(!enc_codec) { fprintf(stderr, "Unsupported codec for output stream\n"); fflush(stderr); exit(1); } avcodec_get_context_defaults(&st->codec); ecc = &st->codec; - ecc->codec_id = CODEC_ID_MPEG2VIDEO; - ecc->bit_rate = 8192*1000; + ecc->codec_id = CODEC_ID_MPEG4; + // ecc->codec_id = CODEC_ID_MPEG2VIDEO; + // ecc->bit_rate = 8192*1000; + ecc->bit_rate = 4096*1000; ecc->bit_rate_tolerance = 8000*1000; ecc->frame_rate = 25; ecc->frame_rate_base = 1; diff --git a/src/player.cc b/src/player.cc index 963f6e7..bc17f0a 100644 --- a/src/player.cc +++ b/src/player.cc @@ -29,6 +29,8 @@ #include #include +#include + Player::Player(Error *err, volatile int *grunning, sem_t *gsem, diff --git a/src/server.cc b/src/server.cc index 3bfd1a2..d603b41 100644 --- a/src/server.cc +++ b/src/server.cc @@ -32,6 +32,8 @@ #include "mov_encoder.h" #include "img_encoder.h" +#include "server_status.h" + #include "dv.h" void saveFrameAsImage(char* cpr, Frame *f) @@ -78,26 +80,27 @@ MovEncoder *newMovEncoder(char* cpr) void newConnection(Socket *socket) { + ServerStatus status; + n_savestate savestate = LATER; n_header h; Frame *frame; Frame *freeze_frame = NULL; MovEncoder *enc = NULL; - unsigned char dvbuf[DVPACKAGE_SIZE]; + // unsigned char dvbuf[DVPACKAGE_SIZE]; - // frame = new Frame((unsigned char *)malloc(DVPACKAGE_SIZE), DVPACKAGE_SIZE); + frame = new Frame(NULL, DVPACKAGE_SIZE); printf("New connection[pid: %d]...\n", getpid()); Network network = Network(socket); - while(int ret = network.recvPackage(&h, dvbuf, DVPACKAGE_SIZE)) { + while(int ret = network.recvPackage(&h, frame->data, frame->size)) { + status.checkPoint(); if(ret == -1) { fprintf(stderr, "An error occurred...!\n"); break; } - frame = new Frame(dvbuf, DVPACKAGE_SIZE); - printf("Read: %d bytes ", ret); printf("\ttyp: %d ", h.header_type); printf("\tcpr: %s ", h.header.h_data.cpr); @@ -130,6 +133,8 @@ void newConnection(Socket *socket) } else { delete frame; } + + frame = new Frame(NULL, DVPACKAGE_SIZE); } // TODO: Use save state diff --git a/src/server_status.cc b/src/server_status.cc new file mode 100644 index 0000000..a26ddd6 --- /dev/null +++ b/src/server_status.cc @@ -0,0 +1,69 @@ +/* -*- 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 program 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. + * + * This program 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 Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +/* + * $Id$ + */ + +#include +#include "server_status.h" + +#include + +ServerStatus::ServerStatus() +{ + for(int cnt = 0; cnt < BUFFERSIZE; cnt++) { + frametime[cnt] = 0; + } + gettimeofday(&oldtime, NULL); + gettimeofday(&time, NULL); +} + +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); + + double total = 0.0; + for(int cnt = 0; cnt < BUFFERSIZE; cnt++) { + total += (double)frametime[cnt]; + } + fprintf(stderr, "[ms: %d, fps: %f]\t", frametime[0], 1000000.0 / (total / (double)BUFFERSIZE) ); + +} + +/* +date(1), gettimeofday(2), ctime(3), ftime(3) +*/ diff --git a/src/server_status.h b/src/server_status.h new file mode 100644 index 0000000..cbc2a0d --- /dev/null +++ b/src/server_status.h @@ -0,0 +1,50 @@ +/* -*- 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 program 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. + * + * This program 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 Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +/* + * $Id$ + */ + +#include +#ifndef __MIAV_SERVER_STATUS_H__ +#define __MIAV_SERVER_STATUS_H__ + +#include + +#define BUFFERSIZE 25 + +class ServerStatus { +public: + ServerStatus(); + ~ServerStatus(); + + void checkPoint(); + +private: + unsigned int frametime[BUFFERSIZE]; + struct timeval time; + struct timeval oldtime; +}; + +#endif/*__MIAV_SERVER_STATUS_H__*/ diff --git a/tools/MIaVAdd b/tools/MIaVAdd index 8a62377..3d30d63 100755 --- a/tools/MIaVAdd +++ b/tools/MIaVAdd @@ -25,6 +25,9 @@ function allfile() { echo " * along with this program; if not, write to the Free Software" >> $1; echo " * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA." >> $1; echo " */" >> $1; + echo "/*" >> $1; + echo " * \$Id$" >> $1; + echo " */" >> $1; echo "" >> $1; echo "#include " >> $1; } -- cgit v1.2.3