summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordeva <deva>2005-04-29 13:53:47 +0000
committerdeva <deva>2005-04-29 13:53:47 +0000
commit0791ce8426fe56246afa4123c37388c2f506f8ce (patch)
tree3bf583d2ce5b998e789c0002dff23ba3b52083a5 /src
parentedb7f06d81d94178aace1a9c29888e4bb800fb6a (diff)
Testing mpeg4 (divx) codec
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am6
-rw-r--r--src/frame.cc2
-rw-r--r--src/mov_encoder.cc12
-rw-r--r--src/player.cc2
-rw-r--r--src/server.cc15
-rw-r--r--src/server_status.cc69
-rw-r--r--src/server_status.h50
7 files changed, 144 insertions, 12 deletions
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 <libdv/dv.h>
#include <libdv/dv_types.h>
+#include <time.h>
+
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 <config.h>
+#include "server_status.h"
+
+#include <stdio.h>
+
+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 <config.h>
+#ifndef __MIAV_SERVER_STATUS_H__
+#define __MIAV_SERVER_STATUS_H__
+
+#include <sys/time.h>
+
+#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__*/