[Sumover-dev] [svn commit] r3894 - in vic/branches/mpeg4: codec

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Fri Oct 13 06:13:02 BST 2006


Author: barz
Date: Fri Oct 13 06:12:30 2006
New Revision: 3894

Modified:
   vic/branches/mpeg4/codec/decoder-mpeg4.cpp
   vic/branches/mpeg4/codec/encoder-h264.cpp
   vic/branches/mpeg4/codec/encoder-mpeg4.cpp
   vic/branches/mpeg4/codec/mpeg4.cpp
   vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl

Log:
slove the issues, mpeg4 freezed while switching format

Modified: vic/branches/mpeg4/codec/decoder-mpeg4.cpp
==============================================================================
--- vic/branches/mpeg4/codec/decoder-mpeg4.cpp	(original)
+++ vic/branches/mpeg4/codec/decoder-mpeg4.cpp	Fri Oct 13 06:12:30 2006
@@ -153,7 +153,7 @@
     }
 
     last_seq = seq;
-    int len;
+    int len = 0;
     if (mbit) {
 	stream->setTotalPkts(pktIdx + 1);
 	debug_msg("receive %d\n", b_off);
@@ -183,7 +183,6 @@
 
 	if (len < 0) {
 	    pb->release();
-	    //printf("mpeg4dec: frame error\n");
 	    debug_msg("mpeg4dec: frame error\n");
 	    stream->clear();
 	    idx = seq + 1;

Modified: vic/branches/mpeg4/codec/encoder-h264.cpp
==============================================================================
--- vic/branches/mpeg4/codec/encoder-h264.cpp	(original)
+++ vic/branches/mpeg4/codec/encoder-h264.cpp	Fri Oct 13 06:12:30 2006
@@ -37,7 +37,7 @@
     static void rtp_callback(void *data, int size, int packet_number);
 
   protected:
-    int fps, bps, gop;
+    int fps, kbps, gop;
     bool state;
     //UCHAR* bitstream;
 
@@ -74,7 +74,7 @@
     fptr = NULL;
     frame_seq = 0;
     fps = 20;
-    bps = 512;
+    kbps = 512;
     gop = 20;
 }
 
@@ -111,22 +111,16 @@
 	    std::cout << "H264: fps " << fps << "\n";
 	    return (TCL_OK);
 	}
-	else if (strcmp(argv[1], "bps") == 0) {
-	    bps = atoi(argv[2]);
-	    if (bps < 64)
-		bps = 64;
-	    std::cout << "H264: bps " << bps << "\n";
-	    /*
-	       if(enc->isInitialized()){
-	       printf("set bitrate to %d kbps.\n", bps);
-	       enc->setBitRate(bps);
-	       }
-	     */
+	else if (strcmp(argv[1], "kbps") == 0) {
+	    kbps = atoi(argv[2]);
+	    if (kbps < 64)
+		kbps = 64;
+	    std::cout << "H264: kbps " << kbps << "\n";
 	    return (TCL_OK);
 	}
 	else if (strcmp(argv[1], "hq") == 0) {
 	    int enable_hq = atoi(argv[2]);
-	    printf("enable h264 high quality encoding\n", enable_hq);
+	    // printf("enable h264 high quality encoding\n");
 	    //h264.enable_hq_encoding = bool(enable_hq);
 	    return (TCL_OK);
 	}
@@ -157,9 +151,9 @@
 	state = true;
 	size(vf->width_, vf->height_);
 	std::
-	    cout << "init x264 encoder with bps:" << bps << " fps:" << fps <<
+	    cout << "init x264 encoder with kbps:" << kbps << " fps:" << fps <<
 	    "\n";
-	enc->init(vf->width_, vf->height_, bps, fps);
+	enc->init(vf->width_, vf->height_, kbps, fps);
 	enc->setGOP(gop);
 	frame_size = vf->width_ * vf->height_;
 	//fptr = fopen("out.m4v", "w");
@@ -251,5 +245,5 @@
      * VIC will grab a frame with a time interval according to this return value.
      * Since this module adopts ratecontrol by bps value, it returns a constant value for a reason of smoonthness.
      */
-    return (bps * 100) / fps;
+    return (kbps*1024) / (fps*8);
 }

Modified: vic/branches/mpeg4/codec/encoder-mpeg4.cpp
==============================================================================
--- vic/branches/mpeg4/codec/encoder-mpeg4.cpp	(original)
+++ vic/branches/mpeg4/codec/encoder-mpeg4.cpp	Fri Oct 13 06:12:30 2006
@@ -20,6 +20,8 @@
 static int vicEncodedMB;
 static int vicNumMB;
 
+using namespace std;
+
 class MPEG4Encoder:public TransmitterModule
 {
   public:
@@ -35,7 +37,7 @@
 			     int num_mb);
 
   protected:
-    int fps, bps, gop;
+    int fps, kbps, gop;
     bool state;
 
     FFMpegCodec mpeg4;
@@ -64,7 +66,7 @@
     state = false;
     mpeg4.init(true, CODEC_ID_MPEG4, PIX_FMT_YUV420P);
     mpeg4.rtp_callback = rtp_callback;
-    bps = 1000 * 1024;
+    kbps = 1000;
     fps = 20;
     gop = 20;
     vicNumMB = 0;
@@ -97,8 +99,8 @@
 	    fps = atoi(argv[2]);
 	    return (TCL_OK);
 	}
-	else if (strcmp(argv[1], "bps") == 0) {
-	    bps = atoi(argv[2]);
+	else if (strcmp(argv[1], "kbps") == 0) {
+	    kbps = atoi(argv[2]);
 	    return (TCL_OK);
 	}
 	else if (strcmp(argv[1], "hq") == 0) {
@@ -114,7 +116,7 @@
 void MPEG4Encoder::rtp_callback(AVCodecContext * c, void *data, int size,
 				int num_mb)
 {
-    //printf("packet size = %d, packet num= %d \n", size, packet_number);
+    // cout << "packet size = " << size << "  MB num = "<< num_mb << endl;
 
     pktbuf *pb;
     rtphdr *rh;
@@ -124,7 +126,6 @@
 
     vicEncodedMB += num_mb;
     if (vicEncodedMB == vicNumMB) {
-	//std::cout << "mpeg4enc: set RTP_M\n";
 	rh->rh_flags |= htons(RTP_M);
 	vicEncodedMB = 0;
     }
@@ -136,6 +137,7 @@
 
     pb->len = size + 12;
     tx->send(pb);
+    tx->flush();
 }
 
 
@@ -155,30 +157,20 @@
     if (!state) {
 	state = true;
 	size(vf->width_, vf->height_);
-	std::cout << "MPEG4 ENC: WxH:" << vf->width_ << "x" << vf->height_;
-	std::cout << "BPS:" << bps * 1024 << " FPS:" << fps << "\n";
-	mpeg4.init_encoder(vf->width_, vf->height_, bps * 1024, fps, gop);
+	std::cout << "mpeg4enc: WxH:" << vf->width_ << "x" << vf->height_;
+	std::cout << "kbps:" << kbps << " fps:" << fps << "\n";
+	mpeg4.init_encoder(vf->width_, vf->height_, kbps * 1024, fps, gop);
     }
-    tx_->flush();
     bitstream = mpeg4.encode(vf->bp_, len);
-
-    psnr = mpeg4.get_PSNR();
-    char buf[20];
-    //sprintf(buf,"%.1f dB", psnr);    
-    Tcl tcl = Tcl::instance();
-    Tcl_SetVar(tcl.interp(), "psnr", buf, TCL_GLOBAL_ONLY);
-
-    /*
-       if(mpeg4.pict_type == FF_I_TYPE){ 
-       pframe_no=0;
-       return len/2;  // for lag reduction
-       }
-       else 
-       return len; */
+    //    std::cout << "MPEG4 ENC: packet length " << len << endl;
+    
     /*
      * champ:
      * VIC will grab a frame with a time interval according to this return value.
      * Since this module adopts rate-control by bps value, it returns a constant value for a reason of smoothness.
      */
-    return (bps * 100) / fps;
+    // cout << kbps*1024/(fps*8) << " to " << len << endl;
+    return kbps*1024 /(fps*8);
+    //return len;
+    
 }

Modified: vic/branches/mpeg4/codec/mpeg4.cpp
==============================================================================
--- vic/branches/mpeg4/codec/mpeg4.cpp	(original)
+++ vic/branches/mpeg4/codec/mpeg4.cpp	Fri Oct 13 06:12:30 2006
@@ -73,7 +73,7 @@
     std::cout << "mpeg4: set framerate: " << frame_rate << "\n";
     c->time_base.den = frame_rate;
     c->time_base.num = 1;
-    // emit one intra frame every ten frames 
+    // emit one intra frame every gop_size frames 
     c->gop_size = iframe_gap;
     c->flags |= CODEC_FLAG_EMU_EDGE;
     c->flags |= CODEC_FLAG_LOW_DELAY;
@@ -102,7 +102,7 @@
 
     /* open it */
     if (avcodec_open(c, codec) < 0) {
-	//fprintf(stderr, "could not open codec\n");
+	fprintf(stderr, "could not open codec\n");
 	exit(1);
     }
 
@@ -136,12 +136,12 @@
 
     codec = avcodec_find_decoder(codecid);
     if (!codec) {
-	//fprintf(stderr, "codec not found\n");
+	fprintf(stderr, "codec not found\n");
 	exit(1);
     }
     /* open it */
     if (avcodec_open(c, codec) < 0) {
-	//fprintf(stderr, "could not open codec\n");
+	fprintf(stderr, "could not open codec\n");
 	exit(1);
     }
 
@@ -210,13 +210,12 @@
     len = avcodec_decode_video(c, picture, &got_picture, codedstream, size);
 
     if (c->width != width || c->height != height) {
-	debug_msg("mpeg4enc: resize to %dx%d\n", c->width, c->height);
+	debug_msg("mpeg4dec: resize to %dx%d\n", c->width, c->height);
 	resize(c->width, c->height);
 	return -2;
 
     }
 
-
     if (!got_picture || len < 0) {
 	return -1;
 

Modified: vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl
==============================================================================
--- vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl	(original)
+++ vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl	Fri Oct 13 06:12:30 2006
@@ -284,7 +284,7 @@
 set logoButtonState 0
 
 proc transmit { } {
-	global logoButton logoButtonState transmitButtonState videoFormat videoDevice V useJPEGforH261 useHardwareComp numEncoderLayers  fps_slider bps_slider
+	global logoButton logoButtonState transmitButtonState videoFormat videoDevice V useJPEGforH261 useHardwareComp numEncoderLayers  fps_slider kbps_slider
 	if ![have grabber] {
 		set DA [$videoDevice attributes]
 		set DF [attribute_class $DA format]
@@ -382,7 +382,7 @@
 	}
 	if {$videoFormat == "mpeg4"} {
 		encoder fps [$fps_slider get]
-		encoder bps [$bps_slider get]			
+		encoder kbps [$kbps_slider get]			
 		if [yesno enable_hq] {
 		  encoder hq 1
 		}
@@ -390,7 +390,7 @@
 
 	if {$videoFormat == "h264"} {
 		encoder fps [$fps_slider get]
-		encoder bps [$bps_slider get]
+		encoder kbps [$kbps_slider get]
 	}
 	$V(grabber) send $transmitButtonState
 }
@@ -524,9 +524,9 @@
 	$w.bps.scale set [option get . bandwidth Vic]
 	$w.fps.scale set [option get . framerate Vic]
 
-	global fps_slider bps_slider
+	global fps_slider kbps_slider
 	set fps_slider $w.fps.scale
-	set bps_slider $w.bps.scale
+	set kbps_slider $w.bps.scale
 }
 
 proc attribute_class { attr class } {
@@ -1378,7 +1378,7 @@
 set lastFmt ""
 
 proc select_format fmt {
-	global qscale qlabel videoDevice videoFormat qscale_val lastFmt
+	global qscale qlabel videoDevice videoFormat qscale_val lastFmt fps_slider kbps_slider
 
 	if { $fmt == "h261" || $fmt == "pvh"} {
 		# H.261 supports only QCIF/CIF
@@ -1440,6 +1440,20 @@
 			# SV, title-maker fix: see marked code below
 			delete $V(encoder)
 			set V(encoder) $encoder
+
+		        if {$videoFormat == "mpeg4"} {
+                	    encoder fps [$fps_slider get]
+ 		            encoder kbps [$kbps_slider get]
+                	    if [yesno enable_hq] {
+                  		encoder hq 1
+                	    }
+        		}
+
+		        if {$videoFormat == "h264"} {
+                	    encoder fps [$fps_slider get]
+	                    encoder kbps [$kbps_slider get]
+		        }
+
 			$encoder transmitter $V(session)
 			
 			# SV ######################
@@ -1492,9 +1506,9 @@
 	}
 
 	$grabber transmitter $V(session)
-	global qscale inputSize fps_slider bps_slider videoDevice
+	global qscale inputSize fps_slider kbps_slider videoDevice
 	$grabber fps [$fps_slider get]
-	$grabber bps [$bps_slider get]
+	$grabber bps [$kbps_slider get]
 	$grabber decimate $inputSize
 	if { [lindex [$qscale configure -state] 4] == "normal" } {
 		set cmd [lindex [$qscale configure -command] 4]



More information about the Sumover-dev mailing list