[Sumover-dev] [svn commit] r4188 - vic/branches/cc/video

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Wed Jun 25 17:49:48 BST 2008


Author: soohyunc
Date: Wed Jun 25 17:49:48 2008
New Revision: 4188

Modified:
   vic/branches/cc/video/grabber-still.cpp

Log:
still grabber now works for jpeg image and yuv file (partically as Piers
commented in the previous commit log message.)

still grabber has just StillGrabber as it was and also has StillYuvGrabber. we
still need to fix the colour information.


Modified: vic/branches/cc/video/grabber-still.cpp
==============================================================================
--- vic/branches/cc/video/grabber-still.cpp	(original)
+++ vic/branches/cc/video/grabber-still.cpp	Wed Jun 25 17:49:48 2008
@@ -34,6 +34,10 @@
  * Contributed by Bob Olson (olson at mcs.anl.gov) September 1995.
  */
 
+/*
+ * $Id$
+ */
+
 #ifndef lint
 static const char rcsid[] =
     "@(#) $Header$ (LBL)";
@@ -67,13 +71,23 @@
 	void start();
 	void stop();
 	int	grab();
+};
+
+class StillYuvGrabber : public StillGrabber {
+public:
+	StillYuvGrabber();
+	virtual ~StillYuvGrabber();
+	virtual int command(int argc, const char* const* argv);
+protected:
+	void start();
+	void stop();
+	int grab();
 	void setsize();
 
-//	u_char *frame_;	// copied frames from StillDevice
-	int	decimate_;
-	int	width_;		// width in pixel
-	int	height_;	// height in pixel
-	int num_frame_;	// the number of frame
+	int decimate_;
+	int width_;			// width in pixel
+	int height_;		// height in pixel
+	int num_frame_;		// current frame number
 };
 
 class StillDevice : public InputDevice {
@@ -81,6 +95,7 @@
     StillDevice(const char* s);
     virtual int command(int argc, const char * const * argv);
     virtual Grabber* jpeg_grabber();
+    virtual Grabber* yuv_grabber();
 
     void load_file(const char * const file);
     char *frame_;
@@ -100,34 +115,9 @@
 #endif /* DEBUG */
 }
 
-void StillDevice::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;
-    if (frame_)
-	delete[] frame_; //SV-XXX: Debian
-    
-    frame_ = new char[len_ + 1];
-
-    debug_msg("File size: %d, Read: %d\n",len_, fread(frame_, len_, 1, fp));
-    fclose(fp);
-}
-
+/*
+ * StillDevice
+ */
 int StillDevice::command(int argc, const char*const* argv)
 {
 #ifdef DEBUG
@@ -141,11 +131,11 @@
 	    const char* fmt = argv[2];
 	    TclObject* o = 0;
 	    if (strcmp(fmt, "cif") == 0)
-		o = jpeg_grabber();
+			o = yuv_grabber();
 	    if (strcmp(fmt, "jpeg") == 0)
-		o = jpeg_grabber();
+			o = jpeg_grabber();
 	    if (o != 0)
-		Tcl::instance().result(o->name());
+			Tcl::instance().result(o->name());
 	    return (TCL_OK);
 	}
 	else if (strcmp(argv[1], "file") == 0)
@@ -157,26 +147,47 @@
     return (InputDevice::command(argc, argv));
 }
 
-
 Grabber* StillDevice::jpeg_grabber()
 {
     return (new StillGrabber());
 }
 
-StillGrabber::StillGrabber() :
-	width_(0), height_(0), num_frame_(0)
-//	frame_(NULL), width_(0), height_(0), num_frame_(0)
+Grabber* StillDevice::yuv_grabber()
 {
+	return (new StillYuvGrabber());
 }
 
-StillGrabber::~StillGrabber()
+void StillDevice::load_file(const char * const f)
 {
-#ifdef DEBUG
-    debug_msg("Destroy StillGrabber\n");
-#endif
-}
+    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;
+    if (frame_)
+		delete[] frame_; //SV-XXX: Debian
+    
+    frame_ = new char[len_ + 1];
+	fread(frame_, len_, 1, fp);
 
+    fclose(fp);
+}
 
+/*
+ * StillGrabber
+ */
 int StillGrabber::command(int argc, const char * const * argv)
 {
     //SV-XXX: unused: Tcl& tcl = Tcl::instance();
@@ -188,41 +199,26 @@
 	debug_msg("\"%s\"\n", argv[i]);
     debug_msg("\n");
 #endif /* DEBUG */
-	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));
 }
 
+StillGrabber::StillGrabber() 
+{
+}
+
+StillGrabber::~StillGrabber()
+{
+#ifdef DEBUG
+    debug_msg("Destroy StillGrabber\n");
+#endif
+}
+
 void StillGrabber::start()
 {
 	Grabber::start();
@@ -239,34 +235,88 @@
 	debug_msg("StillGrabber::grab() called\n");
 #endif
     int frc=0; //SV-XXX: gcc4 warns for initialisation
-/*
     if (still_device.frame_) {
 	JpegFrame f(media_ts(), (u_int8_t *) still_device.frame_,
 		    still_device.len_,
 		    80, 0, 320, 240);
+	frc = target_->consume(&f);
 	}
-*/
 
-//	num_frame_ = fread(frame_, 1, framesize_, still_device.frame_);
-	memcpy(frame_, still_device.frame_+num_frame_, framesize_); 
-	if ((num_frame_+= framesize_)<still_device.len_)
-	  ;
-       	else num_frame_=0;
- 	
+    return frc;
+}
+
+/*
+ * StillYuvGraber
+ */
+int StillYuvGrabber::command(int argc, const char* const* argv)
+{
 #ifdef DEBUG
-	debug_msg("	number of frames:	%d\n", num_frame_);
+	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();
 
-	suppress(frame_);
-	saveblks(frame_);
-	YuvFrame f(media_ts(), (u_int8_t *) frame_, crvec_, outw_, outh_);
+    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);
+        }
+    }
 
-	frc = target_->consume(&f);
-    return frc;
+    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));
 }
 
-void StillGrabber::setsize()
+StillYuvGrabber::StillYuvGrabber() :
+	width_(0), height_(0), num_frame_(0)
 {
+}
+
+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("StillGrabber::setsize()\n");
+#endif
+
 	if(running_)
 		stop();
 
@@ -274,10 +324,33 @@
 	width_ = 352;
 	height_ = 288;
 
-        set_size_411(width_, height_);
-	debug_msg("StillGrabber::setsize()\n");
-	/*framesize_ = 2 * width_ * height_;	// frame size in pixel
-	frame_ = new u_char[2 * framesize_];
-	crinit(width_, height_);*/
+	set_size_411(width_, height_);
+	//crinit(width_, height_);
 	allocref();
 }
+
+int StillYuvGrabber::grab()
+{
+#ifdef DEBUG
+	debug_msg("StillYuvGrabber::grab() called\n");
+#endif
+    int frc=0; //SV-XXX: gcc4 warns for initialisation
+
+	memcpy(frame_, still_device.frame_ + num_frame_, framesize_);
+
+	if ((num_frame_ += framesize_) < still_device.len_) {
+	} 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