[Sumover-dev] [svn commit] r3942 - in vic/branches/mpeg4: codec cpu render

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Tue Nov 21 10:03:44 GMT 2006


Author: barz
Date: Tue Nov 21 10:04:07 2006
New Revision: 3942

Modified:
   vic/branches/mpeg4/codec/decoder-h264.cpp
   vic/branches/mpeg4/codec/decoder-mpeg4.cpp
   vic/branches/mpeg4/codec/ffmpeg_codec.cpp
   vic/branches/mpeg4/codec/packetbuffer.cpp
   vic/branches/mpeg4/codec/x264encoder.cpp
   vic/branches/mpeg4/cpu/cpuid.cpp
   vic/branches/mpeg4/render/color-swscale.cpp
   vic/branches/mpeg4/vic.vcproj

Log:
* h264/mpeg4 robust decoding 
* fix 16bits colorspace for win32

Modified: vic/branches/mpeg4/codec/decoder-h264.cpp
==============================================================================
--- vic/branches/mpeg4/codec/decoder-h264.cpp	(original)
+++ vic/branches/mpeg4/codec/decoder-h264.cpp	Tue Nov 21 10:04:07 2006
@@ -89,9 +89,9 @@
     last_iframe = 0;
     last_seq = 0;
 
-    //256 packets, each 1024 byte (default will not exceed 1000 byte)
+    //256 packets, each 1600 byte (default will not exceed 1600 byte)
     //cout << "new PacketBuffer..\n";
-    stream = new PacketBuffer(1024, 1024);
+    stream = new PacketBuffer(1024, 1600);
     startPkt = false;
 
     //fptr = fopen("out.m4v", "w");
@@ -124,6 +124,7 @@
        stream->clear();
        startPkt = true;
        idx = seq;
+	   last_seq = seq - 1;
     }
 	  
     int pktIdx = seq - idx;
@@ -131,22 +132,19 @@
         pktIdx = (0xFFFF - idx) + seq;
     }
 
-    if (pktIdx - last_seq > 5) {
-       debug_msg("mp4dec: sequece interrupt!\n");
-       idx = seq;
-       pktIdx = 0;
-       stream->clear();
+    if (abs(seq - last_seq) > 5) {
+	    debug_msg("h264dec: sequece interrupt!\n");
+	    idx = seq;
+	    pktIdx = 0;
+	    stream->clear();
+    }else if (last_seq + 1 != seq) {
+	    /* oops - missing packet */
+	    debug_msg("h264dec: missing packet\n");
     }
-    
+
     //copy packet
     stream->write(pktIdx, cc, (char *) bp);
-    // printf("pktIdx=%d, cc=%d, seq=%d\n", pktIdx, cc, seq);
     
-    if (last_seq + 1 != seq) {
-       /* oops - missing packet */
-       debug_msg("h264dec: missing packet\n");
-    }
-	
     last_seq = seq;
     int len=0;
 	
@@ -155,30 +153,23 @@
 
 	    DataBuffer *f;	    
 	    if (stream->isComplete()) {
-		f = stream->getStream();
-		len =  h264.decode((UCHAR *) f->getData(), f->getDataSize(),
-				xxx_frame);
+			f = stream->getStream();
+		    len =  h264.decode((UCHAR *) f->getData(), f->getDataSize(), xxx_frame);
 	    }
 	    
-            if(len == -2){
-               debug_msg("h264dec: resize\n");
-    	       h264.release();
-               h264.init_decoder();
-	       len = h264.decode((UCHAR *) f->getData(), f->getDataSize(), xxx_frame);
-	    }
-	   if (len <= 0) {
+	    if (len < 0) {
 	       debug_msg("h264dec: frame error\n");
 	    }
 	   
 	    if (inw_ != h264.width || inh_ != h264.height) {
-		inw_ = h264.width;
-		inh_ = h264.height;
-		resize(inw_, inh_);
+			inw_ = h264.width;
+			inh_ = h264.height;
+			resize(inw_, inh_);
 	    }
 	    else {
-		Decoder::redraw(xxx_frame);
+			Decoder::redraw(xxx_frame);
 	    }
-            stream->clear();
+        stream->clear();
 	    idx = seq+1;
 		     
     }

Modified: vic/branches/mpeg4/codec/decoder-mpeg4.cpp
==============================================================================
--- vic/branches/mpeg4/codec/decoder-mpeg4.cpp	(original)
+++ vic/branches/mpeg4/codec/decoder-mpeg4.cpp	Tue Nov 21 10:04:07 2006
@@ -30,14 +30,10 @@
 
     /* packet statistics */
     u_int16_t last_seq;		/* sequence number */
-    bool first_packet;
     bool startPkt, startFrame;
     PacketBuffer *stream;
 
     /* collecting data for a frame */
-    int b_off;			/* how much bitstream data we have */
-    int b_all;			/* got all packets for so far? */
-    int last_mbit;
     int last_iframe;
     int idx;
 
@@ -83,20 +79,16 @@
     mpeg4.init_decoder();
     startPkt = false;
     startFrame = false;
-    stream = new PacketBuffer(1024, 1280);
+    stream = new PacketBuffer(1024, 1600);
 
-    b_all = 1;
-    b_off = 0;
-    last_mbit = 0;
     last_iframe = 0;
     last_seq = 0;
-    first_packet = true;
-    debug_msg("mp4dec: initialized");
+    debug_msg("mp4dec: initialized\n");
 }
 
 MPEG4Decoder::~MPEG4Decoder()
 {
-    debug_msg("mp4dec: released");
+    debug_msg("mp4dec: released\n");
     delete stream;
 }
 
@@ -112,102 +104,83 @@
     u_char *bp = pb->dp + hdrsize;
     int cc = pb->len - hdrsize;
 
-    //(sizeof(*rh) + 4);
-    /* RTP header  */
-    /* Basic RTP header 
-       struct rtphdr {
-       u_int16_t rh_flags;      // T:2 P:1 X:1 CC:4 M:1 PT:7 
-       u_int16_t rh_seqno;      // sequence number 
-       u_int32_t rh_ts; // media-specific time stamp 
-       u_int32_t rh_ssrc;       // synchronization src id 
-       // data sources follow per cc 
-       }; */
-
     int mbit = ntohs(rh->rh_flags) >> 7 & 1;
     int seq = ntohs(rh->rh_seqno);
     int ts = ntohl(rh->rh_ts);
 
+	// debug_msg("seq=%d, idx=%d, size=%d\n", seq, idx, cc);
+
     if (!startPkt) {
-	startPkt = true;
-	idx = seq;
+		stream->clear();
+	    startPkt = true;
+	    idx = seq;
+		last_seq = seq - 1;
     }
 
     int pktIdx = seq - idx;
     if (pktIdx < 0) {
-	pktIdx = (0xFFFF - idx) + seq;
+	    pktIdx = (0xFFFF - idx) + seq;
     }
  
-    if (pktIdx - last_seq > 5) {
-	debug_msg("mp4dec: sequece interrupt!\n");
-	idx = seq;
-	pktIdx = 0;
-	stream->clear();
+    if (abs(seq - last_seq) > 5) {
+	    debug_msg("mp4dec: sequece interrupt!\n");
+	    idx = seq;
+	    pktIdx = 0;
+	    stream->clear();
+    }else if (last_seq + 1 != seq) {
+	    /* oops - missing packet */
+	    debug_msg("mp4dec: missing packet\n");
     }
     
     stream->write(pktIdx, cc, (char *) bp);
 
-    if (!first_packet && last_seq + 1 != seq) {
-	first_packet = false;
-	
-	/* oops - missing packet */
-	debug_msg("mpeg4dec: missing packet\n");
-    }
-
     last_seq = seq;
     int len = 0;
+
     if (mbit) {
-	DataBuffer *f;
-	UCHAR *encData;
+	    DataBuffer *f;
+	    UCHAR *encData;
 
-	stream->setTotalPkts(pktIdx + 1);
+	    stream->setTotalPkts(pktIdx + 1);
 
-	if (stream->isComplete()) {
-	    int ti;
-	    f = stream->getStream();
-	    encData = (UCHAR *) f->getData();
-	    /*
-	       for(ti = 0; ti < 12; ti++)
-	       printf("%2d ", encData[ti]);
-	       printf("\n");
-	     */
-	    if (encData[0] == 0x00 && encData[1] == 0x00 && encData[2] == 0x01
-		&& encData[3] == 0xb0) {
-		startFrame = true;
+	    if (stream->isComplete()) {
+	        f = stream->getStream();
+	        encData = (UCHAR *) f->getData();
+
+	        if (encData[0] == 0x00 && encData[1] == 0x00 && encData[2] == 0x01
+		       && encData[3] == 0xb0) {
+		       startFrame = true;
+	        }
+
+	        if (!startFrame) {
+				debug_msg("mp4dec: waiting for the first key frame...\n");
+			    pb->release();
+			    stream->clear();
+			    idx = seq + 1;
+			    return;
+	        }
+
+	        len = mpeg4.decode(encData, f->getDataSize(), xxx_frame);
 	    }
-	    if (!startFrame) {
-		pb->release();
+
+		if (len < 0) {
+			pb->release();
+			debug_msg("mp4dec: frame error\n");
+			stream->clear();
+			idx = seq + 1;
+			return;
+		}
+	    
+		if (inw_ != mpeg4.width || inh_ != mpeg4.height) {
+			inw_ = mpeg4.width;
+			inh_ = mpeg4.height;
+			resize(inw_, inh_);
+		}
+  		else {
+			Decoder::redraw(xxx_frame);
+		}
 		stream->clear();
 		idx = seq + 1;
-		return;
-	    }
-	    len = mpeg4.decode(encData, f->getDataSize(), xxx_frame);
-	}
-
-        if(len == -2){
-            debug_msg("mpeg4dec: resize\n");
-            mpeg4.release();
-            mpeg4.init_decoder();
-            len = mpeg4.decode(encData, f->getDataSize(), xxx_frame);
-	}
-	if (len < 0) {
-	     pb->release();
-	     debug_msg("mpeg4dec: frame error\n");
-	     stream->clear();
-	     idx = seq + 1;
-	     return;
-         }
-    
-	 if (inw_ != mpeg4.width || inh_ != mpeg4.height) {
-	    inw_ = mpeg4.width;
-	    inh_ = mpeg4.height;
-	    resize(inw_, inh_);
-	 }
-  	 else {
-	    Decoder::redraw(xxx_frame);
-	 }
-	 b_off = 0;
-	 stream->clear();
-	 idx = seq + 1;
     }
     pb->release();
 }

Modified: vic/branches/mpeg4/codec/ffmpeg_codec.cpp
==============================================================================
--- vic/branches/mpeg4/codec/ffmpeg_codec.cpp	(original)
+++ vic/branches/mpeg4/codec/ffmpeg_codec.cpp	Tue Nov 21 10:04:07 2006
@@ -222,9 +222,8 @@
 #endif
 }
 
-// return: the decoding length
+// return:  videoframe size
 //         -1 indicates decoding failure
-//         -2  indicates resizing
 int FFMpegCodec::decode(UCHAR * codedstream, int size, UCHAR * vf)
 {
     int got_picture;
@@ -233,15 +232,15 @@
     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);
-	resize(c->width, c->height);
-	return -2;
+		debug_msg("ffmpegcodec: resize to %dx%d\n", c->width, c->height);
+		resize(c->width, c->height);
+		// return len;
     }
 
     if (!got_picture || len < 0) {
-	return -1;
-
+		return -1;
     }
+
 /*
     if(avpicture_deinterlace((AVPicture *)picture, (AVPicture *)picture,
                                     c->pix_fmt, c->width, c->height) < 0) {

Modified: vic/branches/mpeg4/codec/packetbuffer.cpp
==============================================================================
--- vic/branches/mpeg4/codec/packetbuffer.cpp	(original)
+++ vic/branches/mpeg4/codec/packetbuffer.cpp	Tue Nov 21 10:04:07 2006
@@ -1,3 +1,4 @@
+#include "config.h"
 #include "packetbuffer.h"
 #include "databuffer.h"
 
@@ -40,8 +41,8 @@
 	return false;
     for (int i = 0; i < totalPkts; i++){	
 	if (!isDataRecv[i]){
-	    printf("lost packet %d\n", i);	
-	    //return false;
+	    debug_msg("lost packet %d\n", i);	
+	    return false;
 	}
     }
     return true;

Modified: vic/branches/mpeg4/codec/x264encoder.cpp
==============================================================================
--- vic/branches/mpeg4/codec/x264encoder.cpp	(original)
+++ vic/branches/mpeg4/codec/x264encoder.cpp	Tue Nov 21 10:04:07 2006
@@ -60,8 +60,8 @@
     //DONOT ENABLE PSNR ANALYSE
     param->analyse.b_psnr = 1;
     
-    param->i_keyint_max = 100;
-    param->i_keyint_min = 60;
+    param->i_keyint_max = 50;
+    param->i_keyint_min = 20;
     param->i_bframe = 0;
     
     // deblocking filter

Modified: vic/branches/mpeg4/cpu/cpuid.cpp
==============================================================================
--- vic/branches/mpeg4/cpu/cpuid.cpp	(original)
+++ vic/branches/mpeg4/cpu/cpuid.cpp	Tue Nov 21 10:04:07 2006
@@ -1,3 +1,5 @@
+#include "config.h"
+
 #if defined(WIN32) || defined(WIN64)
 #include <windows.h>
 #endif
@@ -95,7 +97,7 @@
    aCpuCaps.has3DNow	= (available_cpu_flags & FF_CPU_3DNOW ? 1:0);
    aCpuCaps.has3DNowExt	= (available_cpu_flags & FF_CPU_3DNOWEXT ? 1:0);
 
-   printf("cpudetect: MMX=%d MMX2=%d SSE=%d SSE2=%d 3DNow=%d 3DNowExt=%d\n",  \
+   debug_msg("cpudetect: MMX=%d MMX2=%d SSE=%d SSE2=%d 3DNow=%d 3DNowExt=%d\n",  \
 	        aCpuCaps.hasMMX, aCpuCaps.hasMMX2, aCpuCaps.hasSSE, aCpuCaps.hasSSE2, \
 	       	aCpuCaps.has3DNow, aCpuCaps.has3DNowExt );
    return available_cpu_flags;

Modified: vic/branches/mpeg4/render/color-swscale.cpp
==============================================================================
--- vic/branches/mpeg4/render/color-swscale.cpp	(original)
+++ vic/branches/mpeg4/render/color-swscale.cpp	Tue Nov 21 10:04:07 2006
@@ -31,7 +31,8 @@
 	    case 15:
 	    case 16:
 			// printf("16\n");
-	        out_format = PIX_FMT_RGB565;
+	        //out_format = PIX_FMT_RGB565;
+			out_format = PIX_FMT_BGR555;
 	        bytes_per_pixel	= 2;
 	    	break;
 	    	

Modified: vic/branches/mpeg4/vic.vcproj
==============================================================================
--- vic/branches/mpeg4/vic.vcproj	(original)
+++ vic/branches/mpeg4/vic.vcproj	Tue Nov 21 10:04:07 2006
@@ -14609,7 +14609,7 @@
 					<Tool
 						Name="VCCustomBuildTool"
 						Description="Assembling $(InputPath)"
-						CommandLine="nasmw -f win32 -DPREFIX -o &quot;$(IntDir)\$(InputName).obj&quot; $(InputPath)"
+						CommandLine="nasmw -f win32 -DPREFIX -o &quot;$(IntDir)\$(InputName).obj&quot; &quot;$(InputPath)&quot;"
 						Outputs="&quot;$(IntDir)\$(InputName).obj&quot;"/>
 				</FileConfiguration>
 			</File>



More information about the Sumover-dev mailing list