[Sumover-dev] [svn commit] r4691 - in vic/branches/cc: . codec

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Sun Mar 14 19:45:07 GMT 2010


Author: soohyunc
Date: Sun Mar 14 19:45:07 2010
New Revision: 4691

Modified:
   vic/branches/cc/codec/encoder-h261.cpp
   vic/branches/cc/module.h
   vic/branches/cc/video/grabber-still.cpp

Log:
-- added mechanisms to suspend grabbing
   
when the transmitter's queue is growing forever, the grabber should entirely
stop grabbing more frames 
(e.g., if the network RTT is large, then the grabbing rate will be faster than
the send rate, which in turn can cause Tx queue length to be very high.)

currently, if the Tx queue length is larger than a certain number of packets
(currently, 5 frames), then we suspend grabbing the new frames.



Modified: vic/branches/cc/codec/encoder-h261.cpp
==============================================================================
--- vic/branches/cc/codec/encoder-h261.cpp	(original)
+++ vic/branches/cc/codec/encoder-h261.cpp	Sun Mar 14 19:45:07 2010
@@ -138,6 +138,9 @@
 	// video frame number
 	int vfno_;
 
+	// should we suspend grabbing?
+	virtual bool suspend_grabbing();
+
     protected:
 	H261Encoder(int ft);
 	~H261Encoder();
@@ -990,3 +993,33 @@
 
 	return (cc);
 }
+
+/*
+ * if Tx queue is building up more than 5 frames, roughly,
+ * then we should suspend grabbing to prevent it from growing up forever.
+ */
+bool H261Encoder::suspend_grabbing() {
+	// Tx queue len (in packets) at the time of calling this method
+	int txq = tx_->tx_buf_size();
+	// highest watermark
+	int highmark = 0;
+
+	if (vfno_ < FHSIZE) 
+	return false;
+
+	for (int i = 0; i < FHSIZE; i++)
+		highmark += ppframe_[vfno_%FHSIZE];
+
+	// highmark is the average number of packets per frame
+	// (average window size is equal to FHSIZE)
+	highmark /= FHSIZE;
+
+	// now, highmark is set to "5 * (num packets per frame)",
+	// which roughly represents 5 frames.
+	highmark = 5 * highmark;
+
+	if (txq > highmark)
+		return true;
+
+	return false;
+}

Modified: vic/branches/cc/module.h
==============================================================================
--- vic/branches/cc/module.h	(original)
+++ vic/branches/cc/module.h	Sun Mar 14 19:45:07 2010
@@ -125,6 +125,7 @@
 
 	double offset_;
 	inline double offset() { return offset_; }
+	virtual bool suspend_grabbing() = 0;
 
     protected:
 	Module(int ft);

Modified: vic/branches/cc/video/grabber-still.cpp
==============================================================================
--- vic/branches/cc/video/grabber-still.cpp	(original)
+++ vic/branches/cc/video/grabber-still.cpp	Sun Mar 14 19:45:07 2010
@@ -100,6 +100,9 @@
 	int width_;			// width in pixel
 	int height_;		// height in pixel
 	int nbytes_;		// current bytes
+private:
+	void fps(int v);
+	double ini_ftime_;	// initial frametime
 };
 
 class StillDevice : public InputDevice {
@@ -174,6 +177,7 @@
 {
     FILE *fp;
     struct stat s;
+	size_t r;
     
     fp = fopen(f, "r");
     if (fp == (FILE *) NULL)
@@ -193,7 +197,7 @@
 		delete[] frame_; //SV-XXX: Debian
     
     frame_ = new char[len_ + 1];
-	fread(frame_, len_, 1, fp);
+	r = fread(frame_, len_, 1, fp);
 	debug_msg("Successfully loaded %s\n", f);
 
 	devstat_ = 0;	// device is now ready
@@ -290,20 +294,33 @@
     }
 
     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));
+	{
+		if (strcmp(argv[1], "send") == 0) {
+			if (atoi(argv[2])) {
+				if (!running_) {
+				start();
+				running_ = 1;
+				}
+			} else {
+				if (running_) {
+				stop();
+				running_ = 0;
+				}
+			}
+			return (TCL_OK);
+		}
+		if (strcmp(argv[1], "fps") == 0)
+		{
+			fps(atoi(argv[2]));
+			return (TCL_OK);
+		}
+		if (strcmp(argv[1], "decimate") == 0)
+		{
+			decimate_ = atoi(argv[2]);
+			setsize();
+		}
+	}
+	return (Grabber::command(argc, argv));
 }
 
 StillYuvGrabber::StillYuvGrabber() :
@@ -322,8 +339,14 @@
 #endif
 }
 
+void StillYuvGrabber::fps(int v) {
+	Grabber::fps(v);
+	ini_ftime_ = 1e6 / double(v);
+}
+
 void StillYuvGrabber::start()
 {
+	target_->offset_ = stillYuv_ts_off_;
 	Grabber::start();
 }
 
@@ -357,12 +380,16 @@
 #endif
 
 	// time measurement
-	target_->offset_ = stillYuv_ts_off_;
 	start_grab_ = stillYuv_now() - stillYuv_ts_off_;
 	fprintf(stderr, "start_grab\tnow: %f\n", start_grab_);
 
     int frc=0; //SV-XXX: gcc4 warns for initialisation
 
+	// check if Tx queue is growing too much.
+	// if so, we should suspend grabbing more frames.
+	if (target_->suspend_grabbing())
+	return (frc);
+
 	// "framesize_" is just the number of pixels, 
 	// so the number of bytes becomes "3 * framesize_ / 2"
 	memcpy (frame_, still_device.frame_ + nbytes_, 



More information about the Sumover-dev mailing list