summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordeva <deva>2006-08-12 15:00:40 +0000
committerdeva <deva>2006-08-12 15:00:40 +0000
commit49265541974282f3346c9dc7de2365858f9fcb4d (patch)
tree0861c3b9bdb9d64a7c68674c4f864171a26eed18 /lib
parenta145483e4f59ae76b28657cefd1b1e72fe5e4e2c (diff)
Added timecode and fixed the sending and receiving of frames through the network.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/frame.cc17
-rw-r--r--lib/frame.h16
-rw-r--r--lib/libdv_wrapper.cc24
-rw-r--r--lib/libdv_wrapper.h4
-rw-r--r--lib/network.cc138
-rw-r--r--lib/network.h21
-rw-r--r--lib/package.h16
-rw-r--r--lib/timecode.h37
9 files changed, 258 insertions, 16 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 038161a..a2b9b37 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -46,6 +46,7 @@ EXTRA_DIST = \
threadsafe_queue.h \
threadsafe_queue_fifo.h \
threadsafe_queue_priority.h \
+ timecode.h \
transcoder.h \
util.h
diff --git a/lib/frame.cc b/lib/frame.cc
index 3a6c1eb..fb7f6f3 100644
--- a/lib/frame.cc
+++ b/lib/frame.cc
@@ -3,7 +3,7 @@
* frame.cc
*
* Mon Nov 15 19:45:07 CET 2004
- * Copyright 2004 Bent Bisballe
+ * Copyright 2004 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -24,9 +24,10 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <config.h>
#include "frame.h"
+#include "info.h"
+
#include <memory.h>
#include <stdlib.h>
@@ -43,6 +44,14 @@ Frame::Frame(char *vframe, int vframesize, video_format_t vformat,
this->aframesize = aframesize;
this->aformat = aformat;
+ timecode.hour = 0;
+ timecode.min = 0;
+ timecode.sec = 0;
+ timecode.frame = 0;
+
+ freeze = false;
+ snapshot = false;
+
// FIX... remove when old code is removed
data = NULL;
}
@@ -59,12 +68,14 @@ Frame::Frame(char *vframe, int vframesize, video_format_t vformat,
*/
Frame::Frame(unsigned char *d, int sz)
{
+ MIaV::info->error("Allocated a frame in the old way!");
+
if(sz) data = new unsigned char[sz];
if(sz && d) memcpy(data, d, sz);
if(sz == 0 && d) data = d;
size = sz;
number = 0;
- memset(timecode, 0, sizeof(timecode));
+ memset(timestamp, 0, sizeof(timestamp));
endOfFrameStream = false;
diff --git a/lib/frame.h b/lib/frame.h
index 8c8fe34..9ddb8e7 100644
--- a/lib/frame.h
+++ b/lib/frame.h
@@ -3,7 +3,7 @@
* frame.h
*
* Mon Nov 15 19:45:07 CET 2004
- * Copyright 2004 Bent Bisballe
+ * Copyright 2004 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -24,25 +24,23 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "config.h"
#ifndef __FRAME_H__
#define __FRAME_H__
#include "format.h"
-//#define START_USE_FRAME(x) x->usage++
-//#define STOP_USE_FRAME(x) if(--x->usage == 0) delete x; x = NULL
-
// Definition of vector
#include <vector>
+#include "timecode.h"
+
class Frame {
public:
Frame(char *vframe, int vframesize, video_format_t vformat,
char *aframe = NULL, int aframesize = 0, audio_format_t aformat = AF_NONE);
// Video
- char* vframe;
+ char *vframe;
int vframesize;
video_format_t vformat;
@@ -51,6 +49,10 @@ public:
int aframesize;
audio_format_t aformat;
+ TimeCode timecode;
+
+ bool snapshot;
+
/**
* Old frame code... to be removed shortly
*/
@@ -70,7 +72,7 @@ public:
bool shoot;
int freeze; // 1 is freeze, -1 is unfreeze
bool record;
- char timecode[12];
+ char timestamp[12];
bool endOfFrameStream;
diff --git a/lib/libdv_wrapper.cc b/lib/libdv_wrapper.cc
index a056419..e178ee3 100644
--- a/lib/libdv_wrapper.cc
+++ b/lib/libdv_wrapper.cc
@@ -142,7 +142,6 @@ Frame *LibDVWrapper::decode(Frame *input, DV::ColorSpace c)
break;
}
-
dv_decode_full_frame(decoder,
(const uint8_t*)input->vframe,
(dv_color_space_t)colorspace,
@@ -150,6 +149,29 @@ Frame *LibDVWrapper::decode(Frame *input, DV::ColorSpace c)
pitches);
Frame *frame = new Frame(buf, size, type, NULL, 0, AF_NONE);
+
+ frame->timecode = getTimeCode();
+
return frame;
}
+TimeCode LibDVWrapper::getTimeCode()
+{
+ TimeCode timecode;
+ int timestamp[4];
+
+ dv_get_timestamp_int(decoder, timestamp);
+
+ timecode.hour = timestamp[0];
+ timecode.min = timestamp[1];
+ timecode.sec = timestamp[2];
+ timecode.frame = timestamp[3];
+ /*
+ fprintf(stderr, "%d %d %d %d\n",
+ timecode.hour,
+ timecode.min,
+ timecode.sec,
+ timecode.frame);
+ */
+ return timecode;
+}
diff --git a/lib/libdv_wrapper.h b/lib/libdv_wrapper.h
index bde5620..77089c7 100644
--- a/lib/libdv_wrapper.h
+++ b/lib/libdv_wrapper.h
@@ -33,6 +33,8 @@
#include "frame.h"
+#include "timecode.h"
+
namespace DV {
/*
#define DV_QUALITY_COLOR 1 // Clear this bit to make monochrome
@@ -106,6 +108,8 @@ public:
void setSystem(DV::System system);
void setSampling(DV::Sampling sampling);
+ TimeCode getTimeCode();
+
Frame *decode(Frame *input, DV::ColorSpace colorspace = DV::YUV);
private:
diff --git a/lib/network.cc b/lib/network.cc
index f00d358..cb3f94e 100644
--- a/lib/network.cc
+++ b/lib/network.cc
@@ -3,7 +3,7 @@
* network.cc
*
* Wed Nov 3 21:23:14 CET 2004
- * Copyright 2004 Bent Bisballe
+ * Copyright 2004 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -24,9 +24,12 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <config.h>
#include "network.h"
+//#ifdef USE_DEBUG
+//#include "efencepp.h"
+//#endif /*USE_DEBUG*/
+
#include "info.h"
#include <stdlib.h>
@@ -34,6 +37,8 @@
#include <string.h>
#include <sys/socket.h>
+#include <arpa/inet.h>
+
Network::Network(Socket *gs)
{
s = gs;
@@ -150,3 +155,132 @@ int Network::recvPackage(n_header *h, void* buf, int bufsz)
return n;
}
+int Network::sendFrame(Frame *frame)
+{
+ frameheader_t header;
+ struct msghdr msg;
+ struct iovec iovecs[2];
+
+ if(!s->isConnected()) {
+ // MIaV::info->error("Write attempted to a socket not connected!");
+ return -1;
+ }
+
+ header.timecode.hour = htonl(frame->timecode.hour);
+ header.timecode.min = htonl(frame->timecode.min);
+ header.timecode.sec = htonl(frame->timecode.sec);
+ header.timecode.frame = htonl(frame->timecode.frame);
+ header.snapshot = htonl(frame->snapshot);
+ header.freeze = htonl(frame->freeze);
+ header.vformat = (video_format_t)htons((short unsigned int)frame->vformat);
+ header.aformat = (audio_format_t)htons((short unsigned int)frame->aformat);
+ header.vframesize = htonl(frame->vframesize);
+ header.aframesize = htonl(frame->aframesize);
+
+ write(&header, sizeof(header));
+
+ char *vframe = frame->vframe;
+ char *aframe = frame->aframe;
+
+ int vframesize = frame->vframesize;
+ int aframesize = frame->aframesize;
+
+ memset(&msg, 0, sizeof(msg));
+
+ msg.msg_iov = iovecs;
+ msg.msg_iovlen = 2;
+
+ msg.msg_iov[0].iov_base = vframe;
+ msg.msg_iov[0].iov_len = vframesize;
+
+ msg.msg_iov[1].iov_base = aframe;
+ msg.msg_iov[1].iov_len = aframesize;
+
+ int n = sendmsg(s->ssocket, &msg, 0);
+
+ if(n < 0) {
+ MIaV::info->error("A network error ocurred during sendPackage!");
+ return -1;
+ }
+
+ return n;
+}
+
+
+Frame *Network::recvFrame()
+{
+ Frame *frame = NULL;
+
+ frameheader_t header;
+ struct msghdr msg;
+ struct iovec iovecs[2];
+
+ if(!s->isConnected()) {
+ // MIaV::info->error("Read attempted to a socket not connected!");
+ return NULL;
+ }
+
+ read(&header, sizeof(header));
+
+ int vframesize = ntohl(header.vframesize);
+ int aframesize = ntohl(header.aframesize);
+
+ char *vframe = new char[vframesize];
+ char *aframe = new char[aframesize];
+
+ memset(&msg, 0, sizeof(msg));
+
+ iovecs[0].iov_base = vframe;
+ iovecs[0].iov_len = vframesize;
+
+ iovecs[1].iov_base = aframe;
+ iovecs[1].iov_len = aframesize;
+
+ msg.msg_iov = iovecs;
+ msg.msg_iovlen = 2;
+
+ int n = recvmsg(s->ssocket, &msg, MSG_WAITALL);
+
+ if(n < 0) {
+ MIaV::info->error("A network error ocurred during recvPackage!");
+ return NULL;
+ }
+
+ if(n == 0) {
+ // No more frames to receive.
+ return NULL;
+ }
+
+ if(msg.msg_iovlen != 2) {
+ MIaV::info->error("Wrong package format!");
+ return NULL;
+ }
+
+ frame = new Frame(vframe, vframesize, (video_format_t)ntohs((short unsigned int)header.vformat),
+ aframe, aframesize, (audio_format_t)ntohs((short unsigned int)header.aformat));
+
+ frame->timecode.hour = ntohl(header.timecode.hour);
+ frame->timecode.min = ntohl(header.timecode.min);
+ frame->timecode.sec = ntohl(header.timecode.sec);
+ frame->timecode.frame = ntohl(header.timecode.frame);
+ frame->snapshot = ntohl(header.snapshot);
+ frame->freeze = ntohl(header.freeze);
+
+ return frame;
+}
+
+int Network::sendStatus(Status *status)
+{
+ return 0;
+}
+
+int Network::recvStatus(Status *status)
+{
+ /*
+ status.diskspace = 10;
+ status.diskspace_max = 100;
+ status.load = 80;
+ status.load_max = 100;
+ */
+ return 0;
+}
diff --git a/lib/network.h b/lib/network.h
index e00dac7..dc7d614 100644
--- a/lib/network.h
+++ b/lib/network.h
@@ -3,7 +3,7 @@
* network.h
*
* Wed Nov 3 21:23:14 CET 2004
- * Copyright 2004 Bent Bisballe
+ * Copyright 2004 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -30,6 +30,13 @@
#include "socket.h"
#include "package.h"
+#include "frame.h"
+#include "status.h"
+
+// Frame recv buffer sizes.
+// These should be big enough for every type of frame.
+#define VFRAMESZ 720*576*4
+#define AFRAMESZ 48000*2
class Network {
public:
@@ -43,9 +50,21 @@ public:
// Package communication
int sendPackage(n_header *h, void* buf, int bufsz);
int recvPackage(n_header *h, void* buf, int bufsz);
+
+ // Frame communication
+ int sendFrame(Frame *frame);
+ Frame *recvFrame();
+
+ // Status message communication
+ int sendStatus(Status *status);
+ int recvStatus(Status *status);
private:
Socket *s;
+
+ // Frame recv buffer
+ char vframe_buf[VFRAMESZ];
+ char aframe_buf[AFRAMESZ];
};
#endif/*__NETWORK_H__*/
diff --git a/lib/package.h b/lib/package.h
index a16557a..c9d18b2 100644
--- a/lib/package.h
+++ b/lib/package.h
@@ -3,7 +3,7 @@
* package.h
*
* Tue Nov 9 10:57:20 CET 2004
- * Copyright 2004 Bent Bisballe
+ * Copyright 2004 Bent Bisballe Nyeng
* deva@aasimon.org
****************************************************************************/
@@ -24,10 +24,12 @@
* along with MIaV; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include "config.h"
#ifndef __MIAVLIB_PACKAGE_H__
#define __MIAVLIB_PACKAGE_H__
+#include "format.h"
+#include "timecode.h"
+
typedef enum {
NO_CHANGE = 0,
SAVE,
@@ -58,6 +60,16 @@ typedef struct {
} n_header;
+typedef struct {
+ video_format_t vformat;
+ audio_format_t aformat;
+ int vframesize;
+ int aframesize;
+ TimeCode timecode;
+ bool snapshot;
+ bool freeze;
+} frameheader_t;
+
#endif/*__PACKAGE_H__*/
diff --git a/lib/timecode.h b/lib/timecode.h
new file mode 100644
index 0000000..ae28912
--- /dev/null
+++ b/lib/timecode.h
@@ -0,0 +1,37 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * timecode.h
+ *
+ * Tue Jul 25 20:20:13 CEST 2006
+ * Copyright 2006 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of MIaV.
+ *
+ * MIaV 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.
+ *
+ * MIaV 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MIaV; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __MIAV_TIMECODE_H__
+#define __MIAV_TIMECODE_H__
+
+typedef struct TimeCode {
+ int hour;
+ int min;
+ int sec;
+ int frame;
+} TimeCode;
+
+#endif/*__MIAV_TIMECODE_H__*/