[Sumover-dev] [svn commit] r4376 - in vic/branches/mpeg4: tcl video

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Wed Feb 4 19:24:35 GMT 2009


Author: soohyunc
Date: Wed Feb  4 19:24:31 2009
New Revision: 4376

Added:
   vic/branches/mpeg4/video/grabber-yuv.cpp
Modified:
   vic/branches/mpeg4/Makefile.in
   vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl
   vic/branches/mpeg4/tcl/ui-grabber.tcl

Log:
o  Added StillYuvGrabber and StillYuvDevice
   
   This can be used to test a pre-recorded video sequences (e.g., YUV 4:2:0
   format). In order to enable StillYuvGrabber, one should run vic as belows:

   ./vic -XstillGrabber <IP address>/<port number>

   Then, select "yuv" device, 
   and click "Options" to select "Use Hardware Encode".

   Then, type filename that you want to test (e.g., foreman.yuv)
   Then, click "Options" and select "User Hardware Encode".

   Finally, click on "Transmit" button.

Note: StillYuvGrabber and StillYuvDevice is an extension of StillGrabber and
StillDevice, respectively.



Modified: vic/branches/mpeg4/Makefile.in
==============================================================================
--- vic/branches/mpeg4/Makefile.in	(original)
+++ vic/branches/mpeg4/Makefile.in	Wed Feb  4 19:24:31 2009
@@ -137,7 +137,7 @@
 	net/net.o net/net-ip.o net/net-addr.o net/net-ipv6.o \
 	net/mbus_handler.o net/mbus_engine.o net/group-ipc.o net/confbus.o \
 	rtp/session.o rtp/source.o rtp/transmitter.o rtp/pktbuf-rtp.o \
-	video/device.o video/grabber.o video/grabber-still.o \
+	video/device.o video/grabber.o video/grabber-still.o video/grabber-yuv.o \
 	codec/encoder-h261.o codec/encoder-jpeg.o codec/encoder-raw.o \
 	codec/encoder-h263.o codec/encoder-h263v2.o codec/encoder-nv.o \
 	codec/encoder-cellb.o codec/encoder-pvh.o codec/compositor.o \

Modified: vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl
==============================================================================
--- vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl	(original)
+++ vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl	Wed Feb  4 19:24:31 2009
@@ -789,6 +789,10 @@
 			set defaultFormat($d) $videoFormat
 			continue
 		}
+		if { [$d nickname] == "yuv" && ![yesno stillGrabber] } {
+			set defaultFormat($d) $videoFormat
+			continue
+		}
 		# this is fragile
 		$m add radiobutton -label [$d nickname] \
 			-command "select_device $d" \

Modified: vic/branches/mpeg4/tcl/ui-grabber.tcl
==============================================================================
--- vic/branches/mpeg4/tcl/ui-grabber.tcl	(original)
+++ vic/branches/mpeg4/tcl/ui-grabber.tcl	Wed Feb  4 19:24:31 2009
@@ -645,6 +645,21 @@
     pack $w.f.entry -side left -fill x -expand 1
 }
 
+proc build.yuv w {
+	set f [smallfont]
+	label $w.title -text "StillYuvGrabber"
+
+    frame $w.f -relief sunken -borderwidth 2
+    label $w.f.label  -font $f -anchor e -text "File"
+    
+    mk.entry $w.f set.still.frame "frame"
+
+    pack $w.title $w.f -fill x -expand 1
+    
+    pack $w.f.label -side left 
+    pack $w.f.entry -side left -fill x -expand 1
+}
+
 proc set.still.frame {w s } {
     global lastDevice
     $lastDevice file $s

Added: vic/branches/mpeg4/video/grabber-yuv.cpp
==============================================================================
--- (empty file)
+++ vic/branches/mpeg4/video/grabber-yuv.cpp	Wed Feb  4 19:24:31 2009
@@ -0,0 +1,283 @@
+/*
+ * FILE:	grabber-yuv.cpp
+ * AUTHOR:	Soo-Hyun Choi <s.choi at cs.ucl.ac.uk>
+ *
+ * Copyright (c) 2009 University College London
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the University of
+ *      California, Berkeley and the Network Research Group at
+ *      Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory may be used
+ *    to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ */
+
+#ifndef lint
+static const char rcsid[] =
+    "@(#) $Header$ (LBL)";
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#ifndef WIN32
+#include <sys/file.h>
+#endif
+#include <sys/stat.h>
+
+#include "inet.h"
+#include "vic_tcl.h"
+#include "rtp.h"
+#include "grabber.h"
+#include "crdef.h"
+#include "device-input.h"
+#include "transmitter.h"
+#include "module.h"
+
+//#define DEBUG 1
+#undef DEBUG
+
+class StillYuvGrabber : public Grabber {
+public:
+	StillYuvGrabber();
+	virtual ~StillYuvGrabber();
+	virtual int command(int argc, const char* const* argv);
+protected:
+	void start();
+	void stop();
+	int grab();
+	void setsize();
+
+	int decimate_;
+	int width_;			// width in pixel
+	int height_;		// height in pixel
+	int num_frame_;		// current frame number
+};
+
+class StillYuvDevice : public InputDevice {
+public:
+    StillYuvDevice(const char* s);
+    virtual int command(int argc, const char * const * argv);
+    virtual Grabber* still_yuv_grabber();
+
+    void load_file(const char * const file);
+    char *frame_;
+    int len_;
+	int devstat_;		// device status
+private:
+};
+
+static StillYuvDevice yuv_device("yuv");
+
+StillYuvDevice::StillYuvDevice(const char* s) : InputDevice(s),
+		frame_(NULL), len_(0), devstat_(-1)
+{
+    attributes_ = "format { 420 422 jpeg cif } size { small large cif }";
+
+#ifdef DEBUG
+    debug_msg("StillYuvDevice::StillYuvDevice name=%s\n", s);
+#endif /* DEBUG */
+}
+
+/*
+ * StillYuvDevice
+ */
+int StillYuvDevice::command(int argc, const char*const* argv) {
+#ifdef DEBUG
+	for (int i = 0; i < argc; i++)
+		debug_msg("StillYuvDevice\t%s\n", argv[i]);
+#endif
+    if (argc == 3)
+    {
+		if (strcmp(argv[1], "open") == 0)
+		{
+		    const char* fmt = argv[2];
+			TclObject* o = 0;
+			if (strcmp(fmt, "cif") == 0) 
+				o = still_yuv_grabber();
+		    if (o != 0)
+				Tcl::instance().result(o->name());
+		    return (TCL_OK);
+		}
+		else if (strcmp(argv[1], "file") == 0)
+		{
+		    debug_msg("Loading %s\n", argv[2]);
+		    load_file(argv[2]);
+		}
+    }
+    return (InputDevice::command(argc, argv));
+}
+
+Grabber* StillYuvDevice::still_yuv_grabber() {
+	return (new StillYuvGrabber());
+}
+
+/*
+ * File loading
+ */
+void StillYuvDevice::load_file(const char * const f) {
+    FILE *fp;
+    struct stat s;
+    
+    fp = fopen(f, "r");
+    if (fp == (FILE *) NULL)
+    {
+		perror("cannot load file");
+		return;
+    }
+    if (fstat(fileno(fp), &s) < 0)
+    {
+		perror("cannot stat frame");
+		fclose(fp);
+		return;
+    }
+    
+    len_ = s.st_size;	// file length
+	if (len_ == 0) return;
+
+    if (frame_)
+		delete[] frame_; 
+    
+    frame_ = new char[len_ + 1];
+	fread(frame_, len_, 1, fp);
+
+	devstat_ = 0;	// device is now ready
+    fclose(fp);
+}
+
+/*
+ * StillYuvGraber
+ */
+int StillYuvGrabber::command(int argc, const char* const* argv) {
+#ifdef DEBUG
+	debug_msg("StillYuvGrabber::command argc=%d\n", argc);
+	for (int i = 0; i < argc; i++)
+		debug_msg("\"%s\"\n", argv[i]);
+#endif
+	Tcl& tcl = Tcl::instance();
+
+    if (argc == 2)
+    {
+        if (strcmp(argv[1], "status") == 0)
+        {
+            sprintf(tcl.buffer(), "%d", status_);
+            tcl.result(tcl.buffer());
+            return (TCL_OK);
+        }
+        if (strcmp(argv[1], "need-capwin") == 0)
+        {
+            tcl.result("0");
+            return (TCL_OK);
+        }
+    }
+
+    if (argc == 3)
+    {
+        if (strcmp(argv[1], "q") == 0)
+        {
+            return (TCL_OK);
+        }
+        if (strcmp(argv[1], "decimate") == 0)
+        {
+            decimate_ = atoi(argv[2]);
+            setsize();
+            if (running_)
+                start();
+        }
+    }
+    return (Grabber::command(argc, argv));
+}
+
+StillYuvGrabber::StillYuvGrabber() :
+	width_(0), height_(0), num_frame_(0)
+{
+	// set device status 
+	status_ = yuv_device.devstat_;
+}
+
+StillYuvGrabber::~StillYuvGrabber() {
+#ifdef DEBUG
+    debug_msg("Destroy StillYuvGrabber\n");
+#endif
+}
+
+void StillYuvGrabber::start() {
+	Grabber::start();
+}
+
+void StillYuvGrabber::stop() {
+    cancel();
+}
+
+void StillYuvGrabber::setsize() {
+#ifdef DEBUG
+	debug_msg("StillYuvGrabber::setsize()\n");
+#endif
+
+	if(running_)
+		stop();
+
+	// CIF frame size in pixel
+	width_ = 352;
+	height_ = 288;
+
+	set_size_420(width_, height_);
+	//crinit(width_, height_);
+	allocref();
+}
+
+int StillYuvGrabber::grab() {
+#ifdef DEBUG
+	debug_msg("StillYuvGrabber::grab() called\n");
+#endif
+
+    int frc = 0; 
+
+	// "framesize_" is just the number of pixels, 
+	// so the number of bytes becomes "3 * framesize_ / 2"
+	memcpy (frame_, yuv_device.frame_ + num_frame_, 
+			framesize_ + (framesize_ >> 1));
+
+	if ((num_frame_ += framesize_ + (framesize_ >> 1)) 
+			< yuv_device.len_) {
+		// we are good here
+	} else {
+		num_frame_=0;
+	}
+ 	
+#ifdef DEBUG
+	debug_msg(" number of frames: %d\n", num_frame_);
+#endif
+
+	suppress(frame_);
+	saveblks(frame_);
+	YuvFrame f(media_ts(), (u_int8_t *) frame_, crvec_, outw_, outh_);
+
+	frc = target_->consume(&f);
+    return frc;
+}



More information about the Sumover-dev mailing list