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

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Wed Dec 13 12:30:56 GMT 2006


Author: barz
Date: Wed Dec 13 12:29:55 2006
New Revision: 3954

Modified:
   vic/branches/mpeg4/Makefile.in
   vic/branches/mpeg4/codec/encoder-h264.cpp
   vic/branches/mpeg4/codec/encoder-mpeg4.cpp
   vic/branches/mpeg4/codec/x264encoder.cpp
   vic/branches/mpeg4/configure
   vic/branches/mpeg4/configure.in
   vic/branches/mpeg4/video/deinterlace.cpp
   vic/branches/mpeg4/video/deinterlace.h
   vic/branches/mpeg4/video/grabber-video4linux.cpp

Log:
improve deinterlacer, remove grabber-v4l2 (wrong implementaion)

Modified: vic/branches/mpeg4/Makefile.in
==============================================================================
--- vic/branches/mpeg4/Makefile.in	(original)
+++ vic/branches/mpeg4/Makefile.in	Wed Dec 13 12:29:55 2006
@@ -137,6 +137,7 @@
 	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/deinterlace.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 \
@@ -438,6 +439,9 @@
 ffmpeg/lib/libswscale.a:
 	(cd ffmpeg/libswscale; make; make install )
 
+ffmpeg/lib/libpostproc.a:
+	(cd ffmpeg/libpostproc; make; make install )
+
 x264/lib/libx264.a:
 	(cd x264; make; make install )
 

Modified: vic/branches/mpeg4/codec/encoder-h264.cpp
==============================================================================
--- vic/branches/mpeg4/codec/encoder-h264.cpp	(original)
+++ vic/branches/mpeg4/codec/encoder-h264.cpp	Wed Dec 13 12:29:55 2006
@@ -43,7 +43,7 @@
 
     x264Encoder *enc;
     DataBuffer *fOut;
-	Deinterlace deinterlacer;
+    Deinterlace deinterlacer;
 
     FILE *fptr;
 };
@@ -85,7 +85,7 @@
 {
     debug_msg("H264: WxH %dx%d\n", w, h);
     Module::size(w, h);
-    fOut = new DataBuffer(w * h * 3 >> 1);
+    fOut = new DataBuffer(w * h * 3 >> 2);
 }
 
 int H264Encoder::command(int argc, const char *const *argv)
@@ -149,10 +149,8 @@
     }
 
     frame_size = vf->width_ * vf->height_;
-    // char *data = fIn->getData();
-    // memcpy(data, vf->bp_, frame_size * 3 >> 1);
 
-	deinterlacer.render(vf->bp_, vf->width_, vf->height_);
+    deinterlacer.render(vf->bp_, vf->width_, vf->height_);
 	
     enc->encodeFrame(vf->bp_);
 

Modified: vic/branches/mpeg4/codec/encoder-mpeg4.cpp
==============================================================================
--- vic/branches/mpeg4/codec/encoder-mpeg4.cpp	(original)
+++ vic/branches/mpeg4/codec/encoder-mpeg4.cpp	Wed Dec 13 12:29:55 2006
@@ -12,7 +12,7 @@
 #include "pktbuf-rtp.h"
 #include "module.h"
 #include "ffmpeg_codec.h"
-
+#include "deinterlace.h"
 
 static Transmitter *tx;
 static RTP_BufferPool *pool;
@@ -42,7 +42,7 @@
 
     FFMpegCodec mpeg4;
     UCHAR *bitstream;
-
+    Deinterlace deinterlacer;
 };
 
 static class MPEG4EncoderMatcher:public Matcher
@@ -163,6 +163,8 @@
 	// std::cout << "kbps:" << kbps << " fps:" << fps << "\n";
 	mpeg4.init_encoder(vf->width_, vf->height_, kbps * 1024, fps, gop);
     }
+    
+    deinterlacer.render(vf->bp_, vf->width_, vf->height_);    
     bitstream = mpeg4.encode(vf->bp_, len);
     //    std::cout << "MPEG4 ENC: packet length " << len << endl;
     

Modified: vic/branches/mpeg4/codec/x264encoder.cpp
==============================================================================
--- vic/branches/mpeg4/codec/x264encoder.cpp	(original)
+++ vic/branches/mpeg4/codec/x264encoder.cpp	Wed Dec 13 12:29:55 2006
@@ -3,6 +3,8 @@
 #include <string.h>
 #include <inttypes.h>
 
+#include "config.h"
+
 #include "x264encoder.h"
 #include "ffmpeg/avcodec.h"
 #include "databuffer.h"
@@ -104,20 +106,17 @@
     //refresh 
     enc->i_nal = 0;
 
-    enc->pic.img.i_csp = X264_CSP_I420;
-	enc->pic.img.i_plane = 3;
+    enc->pic.img.i_csp = X264_CSP_I420;
+    enc->pic.img.i_plane = 3;
     enc->pic.i_type = X264_TYPE_AUTO;
-	enc->pic.img.i_stride[0] = param->i_width;
-	enc->pic.img.i_stride[1] = param->i_width/2;
-	enc->pic.img.i_stride[2] = param->i_width/2;
-
-
+    enc->pic.img.i_stride[0] = param->i_width;
+    enc->pic.img.i_stride[1] = param->i_width/2;
+    enc->pic.img.i_stride[2] = param->i_width/2;
     enc->pic.img.plane[0] = buf;
     enc->pic.img.plane[1] = buf + frame_size;
     enc->pic.img.plane[2] = buf + frame_size*5/4;
 
-    int result = x264_encoder_encode(enc->h, &(enc->nal), &(enc->i_nal), &(enc->pic),
-				     &(enc->pic_out));
+    int result = x264_encoder_encode(enc->h, &(enc->nal), &(enc->i_nal), &(enc->pic), &(enc->pic_out));
 
     if (result < 0) {
 	  isFrameEncoded = false;
@@ -150,9 +149,10 @@
     int packetSize;
 
     packetSize = x264_nal_encode(pkt, &data, 1, &(enc->nal[idx]));
-
+   
     f->setSize(packetSize);
-
+    // debug_msg("i_nal=%d, idx=%d, size=%d\n", enc->i_nal, idx, packetSize);
+    
     return isFrameEncoded;
 }
 

Modified: vic/branches/mpeg4/configure
==============================================================================
--- vic/branches/mpeg4/configure	(original)
+++ vic/branches/mpeg4/configure	Wed Dec 13 12:29:55 2006
@@ -4559,10 +4559,10 @@
      echo "checking out ffmpeg from  svn://svn.mplayerhq.hu/ffmpeg/trunk..."
      svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
      echo "Configuring ffmpeg..."
-     cd ffmpeg; ./configure --prefix=$V_PATH/ffmpeg --enable-gpl --enable-swscaler; cd ..
+     cd ffmpeg; ./configure --prefix=$V_PATH/ffmpeg --enable-gpl --enable-swscaler --enable-pp; cd ..
    fi
    V_INCLUDE="$V_INCLUDE -Iffmpeg/include"
-   V_CODEC_LIB="$V_CODEC_LIB ffmpeg/lib/libavcodec.a ffmpeg/lib/libavutil.a ffmpeg/lib/libswscale.a"
+   V_CODEC_LIB="$V_CODEC_LIB ffmpeg/lib/libavcodec.a ffmpeg/lib/libavutil.a ffmpeg/lib/libswscale.a ffmpeg/lib/libpostproc.a"
 fi
 
 # Check whether --enable-x264-co or --disable-x264-co was given.
@@ -5065,8 +5065,11 @@
 	        echo "Error! you need to have $ffmpeglib/libavutil.a around"
 	   elif test ! -r $ffmpeglib/libswscale.a ; then
 	        echo "Error! you need to have $ffmpeglib/libswscale.a around"
-	   fi
-	   V_LIB_FFMPEG="-L$ffmpeglib -lavcodec -lavutil -lswscale"
+           elif test ! -r $ffmpeglib/libpostproc.a ; then
+                echo "Error! you need to have $ffmpeglib/libpostproc.a around"
+           fi
+
+	   V_LIB_FFMPEG="-L$ffmpeglib -lavcodec -lavutil -lswscale -lpostproc"
 	else
 
 echo "$as_me:$LINENO: checking for main in -lavcodec" >&5
@@ -5284,7 +5287,81 @@
 
 fi
 
-	   V_LIB_FFMPEG="-lavcodec -lavutil -lswscale"
+
+
+echo "$as_me:$LINENO: checking for main in -lpostproc" >&5
+echo $ECHO_N "checking for main in -lpostproc... $ECHO_C" >&6
+if test "${ac_cv_lib_postproc_main+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lpostproc  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+
+int
+main ()
+{
+main ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+	 { ac_try='test -z "$ac_c_werror_flag"			 || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+	 { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_postproc_main=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_postproc_main=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_postproc_main" >&5
+echo "${ECHO_T}$ac_cv_lib_postproc_main" >&6
+if test $ac_cv_lib_postproc_main = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBPOSTPROC 1
+_ACEOF
+
+  LIBS="-lpostproc $LIBS"
+
+else
+
+                echo "Error! you need to have libpostproc around."
+                exit -1
+
+fi
+
+
+	   V_LIB_FFMPEG="-lavcodec -lavutil -lswscale -lpostproc"
 	fi
 fi
 
@@ -6002,7 +6079,8 @@
 		echo "Using old Linux grabber-v4l2"
 elif test -r /usr/include/linux/videodev.h ; then
         if grep V4L2 /usr/include/linux/videodev.h >/dev/null 2>&1  ; then
-                V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2.o video/grabber-video4linux.o"
+                #V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2.o video/grabber-video4linux.o"
+ 		V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-video4linux.o"
 		echo "Using Linux (new)video4linux2(2.6.x compatible) and V4L v1"
         else
                 V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-video4linux.o"

Modified: vic/branches/mpeg4/configure.in
==============================================================================
--- vic/branches/mpeg4/configure.in	(original)
+++ vic/branches/mpeg4/configure.in	Wed Dec 13 12:29:55 2006
@@ -70,10 +70,10 @@
      echo "checking out ffmpeg from  svn://svn.mplayerhq.hu/ffmpeg/trunk..."
      svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
      echo "Configuring ffmpeg..."
-     cd ffmpeg; ./configure --prefix=$V_PATH/ffmpeg --enable-gpl --enable-swscaler; cd ..
+     cd ffmpeg; ./configure --prefix=$V_PATH/ffmpeg --enable-gpl --enable-swscaler --enable-pp; cd ..
    fi
    V_INCLUDE="$V_INCLUDE -Iffmpeg/include"
-   V_CODEC_LIB="$V_CODEC_LIB ffmpeg/lib/libavcodec.a ffmpeg/lib/libavutil.a ffmpeg/lib/libswscale.a"
+   V_CODEC_LIB="$V_CODEC_LIB ffmpeg/lib/libavcodec.a ffmpeg/lib/libavutil.a ffmpeg/lib/libswscale.a ffmpeg/lib/libpostproc.a"
 fi
 
 AC_ARG_ENABLE(x264-co,        --disable-x264-co      Enable or disable x264 svn checkout, x264co="no", x264co="yes")
@@ -130,8 +130,11 @@
 	        echo "Error! you need to have $ffmpeglib/libavutil.a around"
 	   elif test ! -r $ffmpeglib/libswscale.a ; then
 	        echo "Error! you need to have $ffmpeglib/libswscale.a around"
-	   fi
-	   V_LIB_FFMPEG="-L$ffmpeglib -lavcodec -lavutil -lswscale"
+           elif test ! -r $ffmpeglib/libpostproc.a ; then
+                echo "Error! you need to have $ffmpeglib/libpostproc.a around"
+           fi
+	   
+	   V_LIB_FFMPEG="-L$ffmpeglib -lavcodec -lavutil -lswscale -lpostproc"
 	else
 	   AC_CHECK_LIB(avcodec, main, [], [
 	        echo "Error! you need to have libavcodec around."
@@ -145,7 +148,13 @@
 	        echo "Error! you need to have libswscale around."
 	        exit -1
 	   ])
-	   V_LIB_FFMPEG="-lavcodec -lavutil -lswscale"
+
+           AC_CHECK_LIB(postproc, main, [], [
+                echo "Error! you need to have libpostproc around."
+                exit -1
+           ])
+
+	   V_LIB_FFMPEG="-lavcodec -lavutil -lswscale -lpostproc"
 	fi
 fi 
 
@@ -256,7 +265,8 @@
 		echo "Using old Linux grabber-v4l2"
 elif test -r /usr/include/linux/videodev.h ; then
         if grep V4L2 /usr/include/linux/videodev.h >/dev/null 2>&1  ; then
-                V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2.o video/grabber-video4linux.o"
+                #V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-v4l2.o video/grabber-video4linux.o"
+ 		V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-video4linux.o"
 		echo "Using Linux (new)video4linux2(2.6.x compatible) and V4L v1"
         else
                 V_OBJ_GRABBER="$V_OBJ_GRABBER video/grabber-video4linux.o"

Modified: vic/branches/mpeg4/video/deinterlace.cpp
==============================================================================
--- vic/branches/mpeg4/video/deinterlace.cpp	(original)
+++ vic/branches/mpeg4/video/deinterlace.cpp	Wed Dec 13 12:29:55 2006
@@ -9,34 +9,35 @@
 
 Deinterlace::Deinterlace()
 {
-	context = NULL;
-	width_ = height_ = 0;
+    context = NULL;
+    width_ = height_ = 0;
+    mode = 0;
 }
 
 Deinterlace::~Deinterlace()
 {
-	if(context){
-		pp_free_context(context);
-		context = NULL;
-	}
+    if(context){
+ 	pp_free_context(context);
+	context = NULL;
+    }
 }
 
 
 void Deinterlace::init(int width, int height)
 {
-	if(context){
-		pp_free_context(context);
-		context = NULL;
-	}
+    if(context){
+	pp_free_context(context);
+	context = NULL;
+    }
 
     int flags = 0;
-	flags |= (cpu_flags & FF_CPU_MMX ? PP_CPU_CAPS_MMX : 0);
-	flags |= (cpu_flags & FF_CPU_MMXEXT ? PP_CPU_CAPS_MMX2 : 0);
-	flags |= (cpu_flags & FF_CPU_3DNOW ? PP_CPU_CAPS_3DNOW : 0);
-	flags |= (cpu_flags & FF_CPU_ALTIVEC ? PP_CPU_CAPS_ALTIVEC : 0);
+    flags |= (cpu_flags & FF_CPU_MMX ? PP_CPU_CAPS_MMX : 0);
+    flags |= (cpu_flags & FF_CPU_MMXEXT ? PP_CPU_CAPS_MMX2 : 0);
+    flags |= (cpu_flags & FF_CPU_3DNOW ? PP_CPU_CAPS_3DNOW : 0);
+    flags |= (cpu_flags & FF_CPU_ALTIVEC ? PP_CPU_CAPS_ALTIVEC : 0);
 
-	context = pp_get_context(width, height, PP_FORMAT_420 | flags);
-	mode = pp_get_mode_by_name_and_quality("de", 6);
+    context = pp_get_context(width, height, PP_FORMAT_420 | flags);
+    mode = pp_get_mode_by_name_and_quality("lb", 4);
 }
 
 
@@ -56,9 +57,9 @@
 	src[2] = src[1] + framesize/4;
 
 
-    pp_postprocess(src, srcStride,
-                   src, srcStride,
-                   width, height,
-                   NULL,  0,
+        pp_postprocess(src, srcStride,
+                   src, srcStride,
+                   width, height,
+                   NULL,  0,
                    mode, context, 1);
 }

Modified: vic/branches/mpeg4/video/deinterlace.h
==============================================================================
--- vic/branches/mpeg4/video/deinterlace.h	(original)
+++ vic/branches/mpeg4/video/deinterlace.h	Wed Dec 13 12:29:55 2006
@@ -4,7 +4,7 @@
 #include <string.h>
 
 typedef unsigned char uint8_t;
-typedef  char int8_t;
+typedef signed char int8_t;
 
 #include "cpu/cpudetect.h"
 #include <postproc/postprocess.h>
@@ -14,17 +14,16 @@
 {
   public:
     Deinterlace();
-	~Deinterlace();
+    ~Deinterlace();
     void init(int width, int height);
-	void render(void *buf, int width, int height);
+    void render(void *buf, int width, int height);
 
   private:
-    int width_, height_;
-	pp_mode_t	*mode;
-	pp_context_t	*context;
-	int srcStride[3];
-	uint8_t *src[3];
-
+    int width_, height_;
+    pp_mode_t	 *mode;
+    pp_context_t *context;
+    int srcStride[3];
+    uint8_t *src[3];
 };			
 
 #endif

Modified: vic/branches/mpeg4/video/grabber-video4linux.cpp
==============================================================================
--- vic/branches/mpeg4/video/grabber-video4linux.cpp	(original)
+++ vic/branches/mpeg4/video/grabber-video4linux.cpp	Wed Dec 13 12:29:55 2006
@@ -3,9 +3,6 @@
      Copyright (c) 1997 Regents of Koji OKAMURA, oka at kobe-u.ac.jp
      All rights reserved.
 
-     Sloved BTTV palette problems 
-     by Barz Hsu <barz at nchc.org.tw>
-     
      largely rewritten for new bttv/video4linux interface
      by Gerd Knorr <kraxel at cs.tu-berlin.de>
 
@@ -58,6 +55,8 @@
 
 //#define DEBUG(x)
 
+#define D1_WIDTH    720
+#define D1_HEIGHT   480
 #define NTSC_WIDTH  640
 #define NTSC_HEIGHT 480
 #define PAL_WIDTH   768
@@ -135,6 +134,8 @@
     int height_;
     int max_width_;
     int max_height_;
+    int base_width_;
+    int base_height_;
     int decimate_;
 };
 
@@ -338,6 +339,18 @@
 	status_ = -1;
 	return;
     }
+
+    max_width_ = capability.maxwidth;
+    max_height_ = capability.maxheight;
+    
+    if(max_width_ >= D1_WIDTH || max_height_ >= D1_HEIGHT){
+	base_width_ = D1_WIDTH;
+	base_height_ = D1_HEIGHT;	
+    }else{
+	base_width_ = max_width_;
+	base_height_ = max_height_;
+    }
+    
     channels = (struct video_channel *)
 	calloc(capability.channels, sizeof(struct video_channel));
     for (i = 0; i < capability.channels; i++) {
@@ -958,12 +971,12 @@
     debug_msg("V4l: format\n");
 
     if(decimate_!=1){
-   		width_ = CIF_WIDTH * 2 / decimate_;
+   	width_ = CIF_WIDTH * 2 / decimate_;
     	height_ = CIF_HEIGHT * 2 / decimate_;
-	}else{
-		width_  = capability.maxwidth;
-		height_ = capability.maxheight;
-	}
+    }else{
+	width_  = base_width_;
+	height_ = base_height_;
+    }
 
     // FIXED by barz 2006/9/19:  YUV422 is default
     if (have_420P)



More information about the Sumover-dev mailing list