summaryrefslogtreecommitdiff
path: root/src/server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.cc')
-rw-r--r--src/server.cc95
1 files changed, 5 insertions, 90 deletions
diff --git a/src/server.cc b/src/server.cc
index e6a6ff7..35dbb9d 100644
--- a/src/server.cc
+++ b/src/server.cc
@@ -31,6 +31,9 @@
/*
* $Log$
+ * Revision 1.25 2005/06/19 20:04:43 deva
+ * ImgEncoder now uses the file class for output, through jpeg_mem_dest.
+ *
* Revision 1.24 2005/06/19 11:44:14 deva
* Cleaned up a log of logging.
* Fixed server queue (shouldn't happen).
@@ -116,94 +119,6 @@
#include "dv.h"
-void saveFrameAsImage(char* cpr, Frame *f)
-{
- ImgEncoder imgenc;
- struct tm *ltime;
- time_t t = time(NULL);
- FILE *fp;
- int cnt = 0;
- char fname[256];
- char birthmonth[3];
- char date[9];
-
- string *root = config->readString("server_root");
-
- // Test for server root writeability
- sprintf(fname, "%s/miavtemp.tmp%d", (char*)root->c_str(), rand());
- fp = fopen(fname, "w");
- if(!fp) {
- int r = rand();
- fprintf(stderr, "MIaV does not have write access to the server root [%s]\n", root->c_str());
- fprintf(stderr, "Redirecting output to [/tmp/miav-%d.jpg]\n", r);
- sprintf(fname, "/tmp/miav-%d", r);
- imgenc.encode(f, fname, 100); // Quality is between 0...100, where 100 is best.
- return;
- }
- fclose(fp);
- unlink(fname);
-
- // Check for cpr length correctness
- if(strlen(cpr) != 11) {
- int r = rand();
- fprintf(stderr, "Illigal CPR, it must have length 11, it had length %d\n", strlen(cpr));
- fprintf(stderr, "Redirecting output to [/tmp/miav-%d.jpg]\n", r);
- sprintf(fname, "/tmp/miav-%d", r);
- imgenc.encode(f, fname, 100); // Quality is between 0...100, where 100 is best.
- return;
- }
-
- // Copy the bytes representing the birth month from the cpr
- // [dd][mm][yy]-[nn][nn]
- strncpy(birthmonth, &cpr[2], 2);
- birthmonth[2] = 0;
-
- // Create folder named birthmonth in server root
- sprintf(fname, "%s/%s", root->c_str(), birthmonth);
- if(!mkdir(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH | S_IROTH) == -1 && errno != EEXIST) {
- int r = rand();
- fprintf(stderr, "Not possible to create subfolder %s\n", fname);
- fprintf(stderr, "Redirecting output to [/tmp/miav-%d.jpg]\n", r);
- sprintf(fname, "/tmp/miav-%d", r);
- imgenc.encode(f, fname, 100); // Quality is between 0...100, where 100 is best.
- return;
- }
-
- // Create folder named cpr in serverroot/birthmonth
- sprintf(fname, "%s/%s/%s", root->c_str(), birthmonth, cpr);
- if(!mkdir(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IXOTH | S_IROTH) == -1 && errno != EEXIST) {
- int r = rand();
- fprintf(stderr, "Not possible to create subfolder %s\n", fname);
- fprintf(stderr, "Redirecting output to [/tmp/miav-%d.jpg]\n", r);
- sprintf(fname, "/tmp/miav-%d", r);
- imgenc.encode(f, fname, 100); // Quality is between 0...100, where 100 is best.
- return;
- }
-
- // Create date (today) in [yyyy][mm][dd]
- ltime = localtime(&t);
- sprintf(date, "%.4d%.2d%.2d",
- ltime->tm_year + 1900,
- ltime->tm_mon,
- ltime->tm_mday);
-
- // Create filename: [serverroot]/[birthmonth]/[cpr]/[cpr]-[date]-[cnt].mpg
- sprintf(fname, "%s/%s/%s/%s-%s-%.3d.jpg", root->c_str(), birthmonth, cpr, cpr, date, cnt);
-
- // test filename-[cnt] for existamce cnt++ until not existing.
- fp = fopen(fname, "r");
- while(fp) {
- fclose(fp);
- cnt++;
- sprintf(fname, "%s/%s/%s/%s-%s-%.3d.jpg", root->c_str(), birthmonth, cpr, cpr, date, cnt);
- fp = fopen(fname, "r");
- }
- sprintf(fname, "%s/%s/%s/%s-%s-%.3d", root->c_str(), birthmonth, cpr, cpr, date, cnt);
-
- fprintf(stderr, "Success - using filename: [%s.jpg]\n", fname); fflush(stderr);
- imgenc.encode(f, fname, 100); // Quality is between 0...100, where 100 is best.
-}
-
void newConnection(Socket *socket, Info *info)
{
char cpr[256];
@@ -245,11 +160,11 @@ void newConnection(Socket *socket, Info *info)
if(h.header.h_data.snapshot) {
if(freeze_frame) {
- saveFrameAsImage(cpr, freeze_frame);
+ ImgEncoder(cpr, info).encode(freeze_frame, 100);
delete freeze_frame;
freeze_frame = NULL;
} else {
- saveFrameAsImage(cpr, frame);
+ ImgEncoder(cpr, info).encode(frame, 100);
}
}