summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--etc/miav.conf2
-rw-r--r--src/daemon.cc3
-rw-r--r--src/file.cc41
-rw-r--r--src/info_console.cc4
-rw-r--r--src/mov_encoder.cc20
-rw-r--r--src/mov_encoder_thread.cc12
-rw-r--r--src/mov_encoder_writer.cc78
-rw-r--r--src/server.cc17
8 files changed, 118 insertions, 59 deletions
diff --git a/etc/miav.conf b/etc/miav.conf
index 51fda2f..39bf4f6 100644
--- a/etc/miav.conf
+++ b/etc/miav.conf
@@ -45,7 +45,7 @@ frame_quality = 85
# The number of threads started for parallel encoding on the server
# (for multiprocessor systems)
-encoding_threads = 2
+encoding_threads = 1
# Codec is one of the following:
# "mpeg1" For use with mpeg1 encoding.
diff --git a/src/daemon.cc b/src/daemon.cc
index fc42ee7..678a8c9 100644
--- a/src/daemon.cc
+++ b/src/daemon.cc
@@ -48,9 +48,8 @@ int Daemon::run(uid_t uid, gid_t gid)
f = fork();
switch(f) {
case -1: // Fork error
- fprintf(stderr, "fork() error!\n");
+ perror("Fork in daemon.cc");
return 1;
- break;
case 0: // Forked child
if(setgid(gid) != 0) {
diff --git a/src/file.cc b/src/file.cc
index 813a041..2224178 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.4 2005/06/14 18:58:35 deva
+ * *** empty log message ***
+ *
* Revision 1.3 2005/06/14 12:29:40 deva
* Incorporated the use of the Info object everywhere... also using the log functionality.
*
@@ -111,11 +114,11 @@ int File::Open()
}
fd = open(fname, O_CREAT | O_WRONLY | O_SYNC | O_EXCL, //| O_LARGEFILE
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- num ++;
+ if(fd == -1) num ++;
// If more than 1000 files are created in one day, something is terribly wrong!
if(num > 1000) {
- info->error("Something is wrong with the path [%s]!\n", fname);
+ info->error("Something is wrong with the path [%s]!", fname);
exit(1);
}
@@ -123,7 +126,7 @@ int File::Open()
seqnum ++;
- info->log("Opened the file %s for output.", fname);
+ info->info("Outout file: %s", fname);
return 0;
}
@@ -135,11 +138,11 @@ int File::Write(void* data, int size)
w = write(fd, data, size);
if(w != size) {
- info->log("Wrapping file.\n");
+ info->info("Wrapping file.");
Open();
w = write(fd, data, size);
if(w != size) {
- info->error("Out of diskspace!\n");
+ info->error("Out of diskspace!");
return -1;
}
}
@@ -158,10 +161,10 @@ int File::createPath(char* path)
subpath[strrchr(subpath, '/') - subpath] = '\0';
- info->info("Checking and/or generating directory: %s", path);
-
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);
@@ -172,27 +175,3 @@ int File::createPath(char* path)
return 0;
}
-
-#ifdef FILE_TEST // Test
-#define BLOCK_SIZE 1024*1024
-#define TIMES 4000
-int main()
-{
- void *buf = malloc(BLOCK_SIZE);
-
- double b = BLOCK_SIZE;
- double t = TIMES;
-
- double gb = b / (1024 * 1024 * 1024);
- gb *= t;
-
- printf("Writing %f GB.\n", gb);
-
- File file("/tmp/filetest/folder1/folder2/file", "ext");
- for(int cnt = 0; cnt < TIMES; cnt++) {
- file.Write(buf, BLOCK_SIZE);
- }
-
- printf("Done.\n");
-}
-#endif // Test
diff --git a/src/info_console.cc b/src/info_console.cc
index fc82de4..a860dd8 100644
--- a/src/info_console.cc
+++ b/src/info_console.cc
@@ -26,11 +26,11 @@
*/
/*
- * $Id:$
+ * $Id$
*/
/*
- * $Log:$
+ * $Log$
*/
#include <config.h>
diff --git a/src/mov_encoder.cc b/src/mov_encoder.cc
index 3945040..d422f87 100644
--- a/src/mov_encoder.cc
+++ b/src/mov_encoder.cc
@@ -39,6 +39,9 @@
/*
* $Log$
+ * Revision 1.29 2005/06/14 18:58:35 deva
+ * *** empty log message ***
+ *
* Revision 1.28 2005/06/14 12:29:40 deva
* Incorporated the use of the Info object everywhere... also using the log functionality.
*
@@ -119,6 +122,7 @@ MovEncoder::MovEncoder(sem_t *r_sem,
Info *i)
{
info = i;
+ info->info("MovEncoder");
// FIXME: Hmmm... should this be detected somewhere?!
int w = 720;
@@ -260,6 +264,7 @@ MovEncoder::MovEncoder(sem_t *r_sem,
MovEncoder::~MovEncoder()
{
+ info->info("~MovEncoder");
/*
if(f) { // The file was opened.
int written = fame_close(fame_context);
@@ -367,19 +372,22 @@ void MovEncoder::encode_audio(Frame *dvframe)
// this runs in a thread
void MovEncoder::run()
{
+ info->info("MovEncoder::run");
+
FrameVector *item;
Frame *in_frame;
Frame *out_frame;
- // fprintf(stderr, "\t\t\t\tEncoder Ready\n"); fflush(stderr);
-
while(running) {
sem_wait(input_sem);
- // fprintf(stderr, "\t\t\t\tReading block\n"); fflush(stderr);
-
// Lock inout mutex
pthread_mutex_lock(input_mutex);
+ if(inputqueue->size() == 0) {
+ info->error("Dammit... Empty queue in MovEncoder.");
+ pthread_mutex_unlock(input_mutex);
+ continue;
+ }
item = inputqueue->front();
inputqueue->pop();
pthread_mutex_unlock(input_mutex);
@@ -402,8 +410,6 @@ void MovEncoder::run()
outputqueue->push(out_frame);
pthread_mutex_unlock(output_mutex);
// Unlock output mutex
-
- // fprintf(stderr, "\t\t\t\tEncoded [%d] - pushed it for writing\n", in_frame->number); fflush(stderr);
}
delete item;
@@ -411,4 +417,6 @@ void MovEncoder::run()
sem_post(read_sem);
sem_post(output_sem);
}
+
+ info->info("MovEncoder::stop");
}
diff --git a/src/mov_encoder_thread.cc b/src/mov_encoder_thread.cc
index c1d3e56..600a351 100644
--- a/src/mov_encoder_thread.cc
+++ b/src/mov_encoder_thread.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.11 2005/06/14 18:58:35 deva
+ * *** empty log message ***
+ *
* Revision 1.10 2005/06/14 12:29:40 deva
* Incorporated the use of the Info object everywhere... also using the log functionality.
*
@@ -44,7 +47,6 @@
* Added multithreaded encoding support.
*
* Revision 1.6 2005/05/19 14:10:22 deva
- *
* Multithreading rulez?
*
* Revision 1.5 2005/05/19 10:55:49 deva
@@ -71,13 +73,15 @@
MovEncoderThread::MovEncoderThread(const char *cpr, Info *i)
{
info = i;
+ info->info("MovEncoderThread");
+
outputqueue = new FramePriorityQueue();
inputqueue = new FrameVectorQueue();
block = new FrameVector();
num_frames_in_block = config->readString("frame_sequence")->length();
- info->log("Frame sequence length %d", num_frames_in_block);
+ info->info("Frame sequence length %d", num_frames_in_block);
threads = config->readInt("encoding_threads");
@@ -110,6 +114,8 @@ MovEncoderThread::MovEncoderThread(const char *cpr, Info *i)
MovEncoderThread::~MovEncoderThread()
{
+ info->info("~MovEncoderThread");
+
// These should not be deleted here... its done elsewhere.
// inputqueue = NULL;
@@ -154,7 +160,7 @@ MovEncoderThread::~MovEncoderThread()
void MovEncoderThread::encode(Frame* frame)
{
if(frame == NULL) {
- info->log("NULL frame detected, exiting.");
+ info->info("MovEncoderThread::encode - NULL frame detected.");
// Terminate
return;
}
diff --git a/src/mov_encoder_writer.cc b/src/mov_encoder_writer.cc
index c3e4207..bd4fb56 100644
--- a/src/mov_encoder_writer.cc
+++ b/src/mov_encoder_writer.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.5 2005/06/14 18:58:35 deva
+ * *** empty log message ***
+ *
* Revision 1.4 2005/06/14 12:29:40 deva
* Incorporated the use of the Info object everywhere... also using the log functionality.
*
@@ -44,6 +47,9 @@
* Added multithreaded encoding support.
*
*/
+#include <config.h>
+#include "mov_encoder_writer.h"
+
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@@ -54,8 +60,12 @@
#include <errno.h>
-#include <config.h>
-#include "mov_encoder_writer.h"
+#include <string>
+using namespace std;
+
+#include "miav_config.h"
+
+#include <time.h>
MovEncoderWriter::MovEncoderWriter(const char* cpr,
FramePriorityQueue *q,
@@ -64,10 +74,32 @@ MovEncoderWriter::MovEncoderWriter(const char* cpr,
Info *i)
{
info = i;
+ info->info("MovEncoderWriter");
- // TODO: build filename from cpr and date
+ // Create path and filename
char fname[256];
- sprintf(fname, "/tmp/somefile");
+ string *server_root;
+ char birthmonth[3];
+ char date[32];
+
+ // Get server root
+ server_root = config->readString("server_root");
+
+ // Copy the bytes representing the birth month from the cpr
+ // [dd][mm][yy]-[nn][nn]
+ strncpy(birthmonth, &cpr[2], 2);
+ birthmonth[2] = 0;
+
+ // Create date (today) in [yyyy][mm][dd]
+ struct tm *ltime;
+ time_t t = time(NULL);
+ ltime = localtime(&t);
+ sprintf(date, "%.4d%.2d%.2d",
+ ltime->tm_year + 1900,
+ ltime->tm_mon,
+ ltime->tm_mday);
+
+ sprintf(fname, "%s/%s/%s/%s-%s-", server_root->c_str(), birthmonth, cpr, cpr, date);
file = new File(fname, "mpg", info);
@@ -81,37 +113,69 @@ MovEncoderWriter::MovEncoderWriter(const char* cpr,
MovEncoderWriter::~MovEncoderWriter()
{
+ info->info("~MovEncoderWriter");
delete file;
}
+//#define TEST_SIZE
+#ifdef TEST_SIZE
+ #define BLOCK_SIZE 1024*1024
+ #define TIMES 10
+ static void *buf = NULL;
+#endif
+
void MovEncoderWriter::run()
{
+ info->info("MovEncoderWriter::run");
+
+#ifdef TEST_SIZE
+ if(!buf) buf = malloc(BLOCK_SIZE);
+#endif
+
Frame *frame;
while(running) {
sem_wait(sem);
- if(queue->size() == 0) continue;
pthread_mutex_lock(mutex);
+ if(queue->size() == 0) {
+ // info->warn("MovEncoderWriter::run() encountered an empty queue.");
+ pthread_mutex_unlock(mutex);
+ continue;
+ }
frame = queue->top();
if(frame->number == frame_number) queue->pop();
pthread_mutex_unlock(mutex);
while(frame->number == frame_number) {
+ int ret;
+
+#ifdef TEST_SIZE
+ for(int cnt = 0; cnt < TIMES; cnt++) ret = file->Write(buf, BLOCK_SIZE);
+#else
+ ret = file->Write(frame->data, frame->size);
+#endif
- int ret = file->Write(frame->data, frame->size);
delete frame;
if(ret == -1) return;
frame_number++;
+ // Lock output mutex
pthread_mutex_lock(mutex);
+ if(queue->size() == 0) {
+ //info->warn("MovEncoderWriter::run() encountered an empty queue.");
+ pthread_mutex_unlock(mutex);
+ break;
+ }
frame = queue->top();
if(frame->number == frame_number) queue->pop();
pthread_mutex_unlock(mutex);
-
+ // Unlock output mutex
}
}
+
+ info->info("MovEncoderWriter::stop");
}
diff --git a/src/server.cc b/src/server.cc
index 5e3126b..fad79ae 100644
--- a/src/server.cc
+++ b/src/server.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.23 2005/06/14 18:58:35 deva
+ * *** empty log message ***
+ *
* Revision 1.22 2005/06/14 12:29:40 deva
* Incorporated the use of the Info object everywhere... also using the log functionality.
*
@@ -41,14 +44,12 @@
* *** empty log message ***
*
* Revision 1.19 2005/05/22 16:34:44 deva
- *
* Fix: Connection is now taken down when taking a sanpshot without recording.
*
* Revision 1.18 2005/05/22 15:49:22 deva
* Added multithreaded encoding support.
*
* Revision 1.17 2005/05/17 19:16:26 deva
- *
* Made new mpeg writer work, with proper file permissions.
*
* Revision 1.16 2005/05/17 15:12:51 deva
@@ -58,11 +59,9 @@
* Added code, preparing threaded encoding.
*
* Revision 1.14 2005/05/16 16:00:57 deva
- *
* Lots of stuff!
*
* Revision 1.13 2005/05/09 16:40:20 deva
- *
* Added optimize yuv conversion code
*
* Revision 1.12 2005/05/07 10:56:18 deva
@@ -98,6 +97,10 @@
// For errno
#include <errno.h>
+// For inet_ntoa
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include "miav_config.h"
@@ -317,7 +320,7 @@ void newConnection(Socket *socket, Info *info)
frame = new Frame(NULL, DVPACKAGE_SIZE);
- info->log("New connection");
+ info->info("New connection (%s)", inet_ntoa(socket->socketaddr.sin_addr));
Network network = Network(socket, info);
while(int ret = network.recvPackage(&h, frame->data, frame->size)) {
@@ -372,10 +375,10 @@ void newConnection(Socket *socket, Info *info)
// TODO: Use save state
- info->log("Closing connection...");
+ info->info("Closing connection...");
if(enc) delete enc;
- info->log("Connection closed");
+ info->info("Connection closed");
}