summaryrefslogtreecommitdiff
path: root/src/server.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.cc')
-rw-r--r--src/server.cc129
1 files changed, 129 insertions, 0 deletions
diff --git a/src/server.cc b/src/server.cc
new file mode 100644
index 0000000..22b691f
--- /dev/null
+++ b/src/server.cc
@@ -0,0 +1,129 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * miav-rec.cc
+ *
+ * Mon Nov 8 11:35:01 CET 2004
+ * Copyright 2004 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.
+ */
+
+#include "server.h"
+#include "miav.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mov_encoder.h"
+#include "img_encoder.h"
+
+void saveFrameAsImage(char* cpr, DVFrame *f)
+{
+ char fname[256];
+ ImgEncoder imgenc;
+
+ sprintf(fname, "image-%s-%d.jpeg", cpr, rand());
+
+ imgenc.encode(f, fname, 100); // Quality is between 0...100, where 100 is best.
+}
+/*
+struct tm
+{
+ int tm_sec; // Seconds. [0-60] (1 leap second)
+ int tm_min; // Minutes. [0-59]
+ int tm_hour; // Hours. [0-23]
+ int tm_mday; // Day. [1-31]
+ int tm_mon; // Month. [0-11]
+ int tm_year; // Year - 1900.
+ int tm_wday; // Day of week. [0-6]
+ int tm_yday; // Days in year.[0-365]
+ int tm_isdst; // DST. [-1/0/1]
+};
+*/
+
+MovEncoder *newMovEncoder(char* cpr)
+{
+ MovEncoder *enc;
+ struct tm *ltime;
+ char fname[256];
+ time_t t = time(NULL);
+ ltime = localtime(&t);
+ sprintf(fname, "%.2d%.2d%.2d%.2d%.2d%.2d-%s.mpg", ltime->tm_year + 1900, ltime->tm_mon,
+ ltime->tm_mday, ltime->tm_hour, ltime->tm_min, ltime->tm_sec, cpr);
+ enc = new MovEncoder(fname);
+ return enc;
+}
+
+void newConnection(Socket *s)
+{
+ n_header h;
+ DVFrame *f;
+ DVFrame *freeze_frame = NULL;
+ MovEncoder *enc = NULL;
+
+ f = new DVFrame();
+
+ printf("New connection[pid: %d]...\n", getpid());
+
+ Network n = Network(s);
+ while(int ret = n.recvPackage(&h, (void*)f->frame, DVPACKAGE_SIZE)) {
+ if(ret == -1) {
+ fprintf(stderr, "An error occurred...!\n");
+ break;
+ }
+ printf("Read: %d bytes\t", ret);
+ printf("\ttyp: %d\t", h.header_type);
+ printf("\tcpr: %s\t", h.header.h_data.cpr);
+ printf("\tfrz: %d\t", h.header.h_data.freeze);
+ printf("\tsht: %d\n", h.header.h_data.snapshot);
+
+ if(h.header.h_data.snapshot) {
+ if(freeze_frame) {
+ saveFrameAsImage(h.header.h_data.cpr, freeze_frame);
+ delete freeze_frame;
+ freeze_frame = NULL;
+ } else {
+ saveFrameAsImage(h.header.h_data.cpr, f);
+ }
+ }
+
+ if(h.header.h_data.record) {
+ if(!enc) enc = newMovEncoder(h.header.h_data.cpr);
+ enc->encode(f);
+ }
+
+ if(h.header.h_data.freeze) {
+ if(freeze_frame) delete freeze_frame;
+ freeze_frame = f;
+ } else {
+ delete f;
+ }
+
+ f = new DVFrame();
+ }
+ delete f;
+ if(enc) delete enc;
+
+ printf("Connection end[pid: %d]...\n", getpid());
+
+}
+/*
+int main(int argc, char *argv[])
+{
+}
+*/