[Sumover-dev] [svn commit] r3887 - in vic/branches/mpeg4: . codec codec/ffmpeg tcl video

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Thu Oct 5 09:47:59 BST 2006


Author: barz
Date: Thu Oct  5 09:45:33 2006
New Revision: 3887

Modified:
   vic/branches/mpeg4/Makefile.in
   vic/branches/mpeg4/codec/decoder-h264.cpp
   vic/branches/mpeg4/codec/decoder-mpeg4.cpp
   vic/branches/mpeg4/codec/ffmpeg/config.mak
   vic/branches/mpeg4/codec/x264encoder.cpp
   vic/branches/mpeg4/main.cpp
   vic/branches/mpeg4/module.cpp
   vic/branches/mpeg4/module.h
   vic/branches/mpeg4/render/color-x11.cpp
   vic/branches/mpeg4/render/color.cpp
   vic/branches/mpeg4/render/renderer-window.cpp
   vic/branches/mpeg4/render/renderer.cpp
   vic/branches/mpeg4/render/renderer.h
   vic/branches/mpeg4/render/vw.cpp
   vic/branches/mpeg4/render/vw.h
   vic/branches/mpeg4/render/xvideo.cpp
   vic/branches/mpeg4/render/xvideo.h
   vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl
   vic/branches/mpeg4/tcl/ui-main.tcl
   vic/branches/mpeg4/tcl/ui-windows.tcl
   vic/branches/mpeg4/video/grabber-video4linux.cpp
   vic/branches/mpeg4/video/grabber.cpp
   vic/branches/mpeg4/video/grabber.h

Log:
software scaling and xvido extension support

Modified: vic/branches/mpeg4/Makefile.in
==============================================================================
--- vic/branches/mpeg4/Makefile.in	(original)
+++ vic/branches/mpeg4/Makefile.in	Thu Oct  5 09:45:33 2006
@@ -151,10 +151,13 @@
 	codec/decoder-h263.o codec/decoder-h263v2.o codec/decoder-cellb.o \
 	codec/decoder-h261.o codec/decoder-h261v1.o codec/decoder-raw.o \
 	render/renderer.o render/renderer-window.o render/color.o \
-	render/color-true.o render/color-pseudo.o render/color-dither.o \
-	render/color-ed.o render/color-quant.o render/color-hi.o\
+	render/color-x11.o\
+	render/color-pseudo.o render/color-dither.o \
+	render/color-ed.o render/color-quant.o \
 	render/color-gray.o render/color-mono.o render/color-hist.o \
-	render/rgb-converter.o render/vw.o render/ppm.o @V_OBJ@
+	render/rgb-converter.o render/vw.o render/ppm.o render/xvideo.o @V_OBJ@
+        #render/color-true.o render/color-hi.o
+
 
 OBJ3 =	cm0.o cm1.o huffcode.o version.o bv.o codec/pvh-huff.o \
 	$(TCL_VIC:.tcl=.o) tk.o
@@ -167,27 +170,33 @@
 OBJ_VDD = vdd.o p64/p64.o p64/p64dump.o \
 	module.o renderer.o renderer-window.o color.o \
 	color-dither.o color-gray.o color-pseudo.o color-ed.o \
-	color-quant.o color-true.o color-hi.o color-mono.o color-hist.o \
+	color-quant.o color-mono.o color-hist.o \
+	color-x11.o \
 	Tcl.o Tcl2.o vw.o cm0.o cm1.o \
 	dct.o huffcode.o bv.o iohandler.o timer.o \
 	ui-vdd.o tk.o random.o
+	# color-true.o color-hi.o
 
 OBJ_H261PLAY = h261_play.o p64/p64.o p64/p64dump.o \
 	module.o renderer.o renderer-window.o color.o \
 	color-dither.o color-gray.o color-pseudo.o color-ed.o \
-	color-quant.o color-true.o color-hi.o color-mono.o color-hist.o \
+	color-quant.o color-mono.o color-hist.o \
+	color-x11.o \
 	Tcl.o Tcl2.o vw.o cm0.o cm1.o \
 	dct.o huffcode.o bv.o iohandler.o timer.o \
 	ui-h261_play.o tk.o random.o
+	# color-true.o color-hi.o
 
 OBJ_JPEGPLAY = jpeg_play.o jpeg/jpeg.o \
 	renderer.o renderer-window.o color.o \
 	color-dither.o color-gray.o color-pseudo.o color-ed.o \
-	color-quant.o color-true.o color-hi.o color-mono.o \
+	color-quant.o color-mono.o \
+	color-x11.o \
 	Tcl.o Tcl2.o vw.o cm0.o cm1.o \
 	dct.o huffcode.o jpeg_play_tcl.o bv.o iohandler.o timer.o \
 	ui-jpeg_play.o tk.o random.o
-
+	# color-true.o color-hi.o
+	
 LIB_CB = @V_LIB_TK@ @V_LIB_TCL@ @V_LIB_X11@ @V_LIB@ -lm
 OBJ_CB = net/cbAppInit.o net/cb.o net/confbus.o net/group-ipc.o iohandler.o \
 	render/ppm.o \

Modified: vic/branches/mpeg4/codec/decoder-h264.cpp
==============================================================================
--- vic/branches/mpeg4/codec/decoder-h264.cpp	(original)
+++ vic/branches/mpeg4/codec/decoder-h264.cpp	Thu Oct  5 09:45:33 2006
@@ -107,7 +107,7 @@
     //fclose(fptr);
 }
 
-int H264Decoder::colorhist(u_int * hist) const 
+int H264Decoder::colorhist(u_int * hist)  const
 {
     return (1);
 }

Modified: vic/branches/mpeg4/codec/decoder-mpeg4.cpp
==============================================================================
--- vic/branches/mpeg4/codec/decoder-mpeg4.cpp	(original)
+++ vic/branches/mpeg4/codec/decoder-mpeg4.cpp	Thu Oct  5 09:45:33 2006
@@ -97,12 +97,12 @@
     delete stream;
 }
 
-     int MPEG4Decoder::colorhist(u_int * hist) const
-     {
-	 return (1);
-     }
+int MPEG4Decoder::colorhist(u_int * hist) const
+{
+    return (1);
+}
 
-     void MPEG4Decoder::recv(pktbuf * pb)
+void MPEG4Decoder::recv(pktbuf * pb)
 {
     rtphdr *rh = (rtphdr *) pb->dp;
     int hdrsize = sizeof(rtphdr);	// sizeof(rtphdr) is 12 bytes

Modified: vic/branches/mpeg4/codec/ffmpeg/config.mak
==============================================================================
--- vic/branches/mpeg4/codec/ffmpeg/config.mak	(original)
+++ vic/branches/mpeg4/codec/ffmpeg/config.mak	Thu Oct  5 09:45:33 2006
@@ -9,8 +9,8 @@
 RANLIB=ranlib
 STRIP=strip
 INSTALLSTRIP=-s
-OPTFLAGS=-O3 -g -Wall -Wno-switch 
-SHCFLAGS=-O3 -g -Wall -Wno-switch 
+OPTFLAGS=-O3 -g 
+SHCFLAGS=-O3 -g 
 LDFLAGS=-Wl,--warn-common -rdynamic
 LDCONFIG=ldconfig
 FFSLDFLAGS=-Wl,-E

Modified: vic/branches/mpeg4/codec/x264encoder.cpp
==============================================================================
--- vic/branches/mpeg4/codec/x264encoder.cpp	(original)
+++ vic/branches/mpeg4/codec/x264encoder.cpp	Thu Oct  5 09:45:33 2006
@@ -106,9 +106,8 @@
     memcpy(pic->img.plane[1], (f + frame_size), frame_size / 4);
     memcpy(pic->img.plane[2], (f + frame_size * 5 / 4), frame_size / 4);
 
-    int result =
-	x264_encoder_encode(enc->h, &(enc->nal), &(enc->i_nal), pic,
-			    &(enc->pic_out));
+    int result = x264_encoder_encode(enc->h, &(enc->nal), &(enc->i_nal), pic,
+				     &(enc->pic_out));
 
     if (result < 0) {
 	isFrameEncoded = false;

Modified: vic/branches/mpeg4/main.cpp
==============================================================================
--- vic/branches/mpeg4/main.cpp	(original)
+++ vic/branches/mpeg4/main.cpp	Thu Oct  5 09:45:33 2006
@@ -134,7 +134,7 @@
 http://www-mice.cs.ucl.ac.uk/multimedia/software/vic/faq.html\n\
 Options: vic [-HPs] [-A nv|ivs|rtp] [-B maxbps] [-C conf]\n\
 \t[-c ed|gray|od|quantize] [-D device] [-d display]\n\
-\t[-f bvc|cellb|h261|jpeg|nv] [-F maxfps] [-i ifAddr ] [-I channel]\n\
+\t[-f bvc|cellb|h261|jpeg|nv|mpeg4|h264] [-F maxfps] [-i ifAddr ] [-I channel]\n\
 \t[-K key ] [-L flowLabel (ip6 only)] [-l (creates log file)]\n\
 \t[-M colormap] [-m mtu] [-N session] [-n atm|ip|ip6|rtip]\n\
 \t[-o clipfile] [-t ttl] [-U interval] [-u script] [-v version] [-V visual]\n\

Modified: vic/branches/mpeg4/module.cpp
==============================================================================
--- vic/branches/mpeg4/module.cpp	(original)
+++ vic/branches/mpeg4/module.cpp	Thu Oct  5 09:45:33 2006
@@ -36,6 +36,7 @@
     "@(#) $Header$ (LBL)";
 #endif
 #include "module.h"
+#include "deinterlace.h"
 
 char* Module::fttoa(int ft)
 {
@@ -128,3 +129,8 @@
 	}
 	return (Module::command(argc, argv));
 }
+
+void VideoFrame::deinterlace() {
+   Deinterlace::Render(bp_, width_, height_);
+}
+

Modified: vic/branches/mpeg4/module.h
==============================================================================
--- vic/branches/mpeg4/module.h	(original)
+++ vic/branches/mpeg4/module.h	Thu Oct  5 09:45:33 2006
@@ -52,6 +52,8 @@
 	inline VideoFrame(u_int32_t ts, u_int8_t* bp, int w, int h,
 			  int layer) :
 		ts_(ts), bp_(bp), width_(w), height_(h), layer_(layer) { }
+	void deinterlace();
+
 	u_int32_t ts_;
 	u_int8_t* bp_;
 	int width_;

Modified: vic/branches/mpeg4/render/color-x11.cpp
==============================================================================
--- vic/branches/mpeg4/render/color-x11.cpp	(original)
+++ vic/branches/mpeg4/render/color-x11.cpp	Thu Oct  5 09:45:33 2006
@@ -1,3 +1,41 @@
+/*
+ * Copyright (c) 2004 Regents of National Center of High Performance Computing.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *      This product includes software developed by the University of
+ *      California, Berkeley and the Network Research Group at
+ *      Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory may be used
+ *    to endorse or promote products derived from this software without
+ *    specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+static char rcsid[] =
+    "@(#) $Header: /forge/cvsroot/nchc-vic/vic/render/color-x11.cpp,v 1.1.1.1 2005/08/11 15:28:33 barz Exp $ (LBL)";
+#endif
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -5,144 +43,131 @@
 #include "renderer-window.h"
 #include "vw.h"
 #include "renderer.h"
-extern "C"
-{
 #include "postproc/swscale.h"
-}
 
-class X11WindowRenderer:public WindowDitherer
-{
-  public:
-    X11WindowRenderer(VideoWindow * vw, int decimation,
-		      int depth_):WindowDitherer(vw, decimation)
-    {
-	i_width = i_height = o_width = o_height = -1;
-	sws_context = NULL;
-
-	// 15, 16, 24, or 32 bits
-	switch (depth_) {
-	case 15:
-	case 16:
-	    out_format = IMGFMT_BGR16;
-	    bytes_per_pixel = 2;
-	    break;
-	    case 24:case 32:out_format = IMGFMT_BGR32;
-	    bytes_per_pixel = 4;
-	}
-    }
-         ~X11WindowRenderer()
-    {
-	if (sws_context)
-	    sws_freeContext(sws_context);
-    }
-    inline bool resized()
-    {
-	return (i_width != width_ || i_height != height_ || o_width != outw_
-		|| o_height != outh_);
-    }
-    void render(const u_char * frm, int off, int x, int w, int h)
-    {
-	if (enable_xv) {
-	    memcpy(pixbuf_, frm, framesize_ * 3 / 2);
-	}
-	else {
-	    if (resized()) {
-		if (sws_context)
-		    sws_freeContext(sws_context);
-		sws_context =
-		    sws_getContext(width_, height_, IMGFMT_I420, outw_,
-				   outh_, out_format, SWS_FAST_BILINEAR, NULL,
-				   NULL);
-		sws_src_stride[0] = width_;
-		sws_src_stride[1] = sws_src_stride[2] = width_ / 2;
-		sws_tar[0] = pixbuf_;
-		sws_tar[1] = sws_tar[2] = NULL;
-		sws_tar_stride[0] = outw_ * bytes_per_pixel;
-		sws_tar_stride[1] = sws_tar_stride[2] = 0;
-	    }
-	    i_width = width_;
-	    i_height = height_;
-	    o_width = outw_;
-	    o_height = outh_;
-	    sws_src[0] = (uint8_t *) frm;
+class X11WindowRenderer : public WindowDitherer {
+public:
+	X11WindowRenderer(VideoWindow* vw, int decimation, int depth_) :
+		WindowDitherer(vw, decimation) { 
+	  i_width = i_height = o_width = o_height = -1;
+	  sws_context = NULL;
+	  
+	  // 15, 16, 24, or 32 bits
+	  switch (depth_) {
+	    case 15:
+	    case 16:
+	        out_format = IMGFMT_BGR16;
+	        bytes_per_pixel	= 2;
+	    	break;
+	    	
+	    case 24:
+	    case 32:
+	        out_format = IMGFMT_BGR32;
+	        bytes_per_pixel	= 4;
+  	  }
+	}
+
+	~X11WindowRenderer() { 
+	  if(sws_context) sws_freeContext(sws_context);
+	}
+	
+	inline bool resized(){
+	  return (i_width != width_ || i_height != height_ || o_width != outw_ || o_height != outh_);
+	}
+	
+	void render(const u_char* frm, int off, int x, int w, int h) {
+				
+	  if(enable_xv){
+	    memcpy(pixbuf_, frm, framesize_*3/2);	  
+	  }else{ 	
+	    if(resized()){
+	      if(sws_context)
+	        sws_freeContext(sws_context);	
+	      sws_context = sws_getContext(width_, height_, IMGFMT_I420,
+	                 outw_, outh_, out_format, SWS_FAST_BILINEAR, NULL, NULL, NULL); 	   
+	      sws_src_stride[0] = width_;
+	      sws_src_stride[1] = sws_src_stride[2] = width_/2;
+	    
+  	      sws_tar[0] = pixbuf_;
+  	      sws_tar[1] = sws_tar[2] = NULL;
+  	      sws_tar_stride[0] = outw_*bytes_per_pixel;
+  	      sws_tar_stride[1] = sws_tar_stride[2] = 0;	  	      
+            }
+
+	    i_width = width_; i_height = height_; o_width = outw_; o_height = outh_;	  		 	
+	    sws_src[0] = (uint8_t*)frm;
 	    sws_src[1] = sws_src[0] + framesize_;
-	    sws_src[2] = sws_src[1] + framesize_ / 4;
+	    sws_src[2] = sws_src[1] + framesize_/4;
 
-	    sws_scale_ordered(sws_context, sws_src, sws_src_stride, 0,
-			      height_, sws_tar, sws_tar_stride);
+     	    sws_scale_ordered(sws_context, sws_src, sws_src_stride, 0, height_, sws_tar, sws_tar_stride);
+	  }	
 	}
-    }
-  protected:
-    virtual void update()
-    {
-    }
-    virtual void disable()
-    {
-    }
-    // libswscale: color conversion and interpolation
-    int i_width, i_height, o_width, o_height;
-    SwsContext *sws_context;
-    uint8_t *sws_src[3];
-    uint8_t *sws_tar[3];
-    int sws_src_stride[3];
-    int sws_tar_stride[3];
-    int out_format;
-    int bytes_per_pixel;
+protected:
+	virtual void update() { }
+	virtual void disable() { }
+
+	// libswscale: color conversion and interpolation
+	int i_width, i_height, o_width, o_height;
+	SwsContext *sws_context;
+	uint8_t *sws_src[3];
+  	uint8_t *sws_tar[3];
+  	int sws_src_stride[3];
+  	int sws_tar_stride[3];	
+  	int out_format;
+  	int bytes_per_pixel;
 };
 
 
-class X11ColorModel:public TclObject
-{
-  public:
-    virtual int command(int argc, const char *const *argv)
-    {
-	Tcl & tcl = Tcl::instance();
-	if (argc == 4 && strcmp(argv[1], "renderer") == 0) {
-
-	    VideoWindow *vw = VideoWindow::lookup(argv[2]);
-	    int decimation = atoi(argv[3]);
-	    Renderer *r = new X11WindowRenderer(vw, decimation, vw->bpp());
-	             tcl.result(r->name());
-	             return (TCL_OK);
-	}
-	if    (argc == 2) {
-	    if (strcmp(argv[1], "alloc-colors") == 0) {
-		tcl.result("1");
-		return (TCL_OK);
-	    }
-	    if (strcmp(argv[1], "free-colors") == 0) {
-		return (TCL_OK);
-	    }
-	}
-	else if (argc == 3) {
-	    if (strcmp(argv[1], "visual") == 0) {
-		return (TCL_OK);
-	    }
-	    if (strcmp(argv[1], "gamma") == 0) {
-		tcl.result("1");
+class X11ColorModel : public TclObject {
+public:
+	virtual int command(int argc, const char*const* argv){
+	  Tcl& tcl = Tcl::instance();	
+	  
+	  if (argc == 4 && strcmp(argv[1], "renderer") == 0) {
+
+		VideoWindow* vw = VideoWindow::lookup(argv[2]);
+		int decimation = atoi(argv[3]);
+		
+		Renderer* r = new X11WindowRenderer(vw, decimation, vw->bpp());
+		tcl.result(r->name());
 		return (TCL_OK);
-	    }
+	  }
+	  if (argc == 2) {
+		if (strcmp(argv[1], "alloc-colors") == 0) {
+			tcl.result("1");
+			return (TCL_OK);
+		}
+		if (strcmp(argv[1], "free-colors") == 0) {
+			return (TCL_OK);
+		}
+	} else if (argc == 3) {
+		if (strcmp(argv[1], "visual") == 0) {
+			return (TCL_OK);
+		}
+		if (strcmp(argv[1], "gamma") == 0) {
+			tcl.result("1");
+			return (TCL_OK);
+		}
+	}	  
+	  return (TclObject::command(argc, argv));
 	}
-	return (TclObject::command(argc, argv));
-    }
 };
 
-class X11ColorMatcher:public Matcher
-{
-  public:
-    X11ColorMatcher():Matcher("colormodel")
-    {
-    }
-    virtual TclObject *match(const char *id)
-    {
-	if (strcasecmp(id, "truecolor/15") == 0 ||
-	    strcasecmp(id, "truecolor/16") == 0
-	    || strcasecmp(id, "truecolor/24") == 0
-	    || strcasecmp(id, "truecolor/32") == 0) {
-	    return (new X11ColorModel());
-	}
-	return (0);
-    }
-}
 
-matcher_x11;
+class X11ColorMatcher : public Matcher {
+public:
+	X11ColorMatcher() : Matcher("colormodel") {}
+	virtual TclObject* match(const char* id) {
+		if ( strcasecmp(id, "truecolor/15") == 0 ||
+		     strcasecmp(id, "truecolor/16") == 0 ||
+		     strcasecmp(id, "truecolor/24") == 0 ||
+		     strcasecmp(id, "truecolor/32") == 0 ){
+			return (new X11ColorModel());
+		}		
+		return (0);
+	}
+} matcher_x11;
+
+					       
+
+

Modified: vic/branches/mpeg4/render/color.cpp
==============================================================================
--- vic/branches/mpeg4/render/color.cpp	(original)
+++ vic/branches/mpeg4/render/color.cpp	Thu Oct  5 09:45:33 2006
@@ -49,7 +49,12 @@
 #include <fcntl.h>
 #endif
 #include <string.h>
-
+#include "../config_arch.h"
+#ifdef USE_FASTMEMCPY
+extern "C" {
+#include "postproc/fastmemcpy.h"
+}
+#endif
 #ifdef WIN32
 #include <tk.h>
 

Modified: vic/branches/mpeg4/render/renderer-window.cpp
==============================================================================
--- vic/branches/mpeg4/render/renderer-window.cpp	(original)
+++ vic/branches/mpeg4/render/renderer-window.cpp	Thu Oct  5 09:45:33 2006
@@ -83,6 +83,9 @@
 	 * On a mismatch, the image will be centered in the window.
 	 */
 	scale_ = 0;
+//	outw_ = (ww_ >> 2) << 2;
+//	outh_ = (wh_ >> 2) << 2;
+
 	int d = distance(ww_, width_);
 	int t = distance(ww_, width_ << 1);
 	if (t < d) {
@@ -90,7 +93,7 @@
 		outh_ = height_ << 1;
 		scale_ = -1;
 	} else {
-		/*XXX this should be a loop */
+		// XXX this should be a loop 
 		t = distance(ww_, width_ >> 1);
 		if (t < d) {
 			d = t;
@@ -108,6 +111,7 @@
 		outw_ = width_ >> scale_;
 		outh_ = height_ >> scale_;
 	}
+    
 }
 
 void WindowRenderer::sync() const
@@ -117,6 +121,13 @@
 
 void WindowRenderer::push(const u_char*, int miny, int maxy, int minx, int maxx) const
 {
+        if(enable_xv){
+            window_->render(image_, 0, outh_, 0, outw_ );
+        }else{
+            window_->render(image_, 0, 0 , 0, 0);
+	}
+	
+/*
 	if (scale_ >= 0) {
 		miny >>= scale_;
 		maxy >>= scale_;
@@ -129,6 +140,7 @@
 		maxx <<= -scale_;
 	}
 	window_->render(image_, miny, maxy, minx, maxx);
+*/	
 }
 
 /*
@@ -190,6 +202,17 @@
 void WindowDitherer::alloc_image()
 {
 	StandardVideoImage* p;
+	if(enable_xv){
+	  XVideoImage *p;		
+	  p = XVideoImage::allocate(window_->tkwin(), width_, height_);	
+	  if(p){
+	    pixbuf_ = p->pixbuf();
+	    image_ = p;
+	    return;
+	  }	  
+	  enable_xv = false;
+	  printf("disable xvideo\n");
+	}
 	p = StandardVideoImage::allocate(window_->tkwin(), outw_, outh_);
 	pixbuf_ = p->pixbuf();
 	image_ = p;

Modified: vic/branches/mpeg4/render/renderer.cpp
==============================================================================
--- vic/branches/mpeg4/render/renderer.cpp	(original)
+++ vic/branches/mpeg4/render/renderer.cpp	Thu Oct  5 09:45:33 2006
@@ -56,7 +56,8 @@
 	next_(0),
 	now_(0),
 	update_interval_(0),
-	need_update_(1)
+	need_update_(1),
+	enable_xv(false)
 {
 }
 
@@ -70,7 +71,12 @@
 		if (strcmp(argv[1], "color") == 0) {
 			setcolor(atoi(argv[2]));
 			return (TCL_OK);
-		}
+		}else if (strcmp(argv[1], "enable_xv") == 0) {
+#ifdef HAVE_XVIDEO
+			enable_xv = !strcmp(argv[2], "true");
+#endif
+			return (TCL_OK);
+		}	
 	}
 	return (Module::command(argc, argv));
 }
@@ -117,60 +123,72 @@
 			return (0);
 		need_update_ = 0;
 	}
-	/*
-	 * check how many blocks we need to update.  If more than
-	 * 12%, do a single image push call for them.  Otherwise,
-	 * only push the ones that change.
-	 */
-	u_int now = now_;
-	const u_int8_t* ts = p->crvec_;
-	u_int bcnt = 0;
-	int w = width_ >> 3;
-	int y;
-	for (y = height_ >> 3; --y >= 0; ) {
-		for (int x = 0; x < w; ++x)
-			if (!RV_PAST(now, ts[x]))
-				++bcnt;
-		ts += w;
-	}
-	int immed = bcnt < irthresh_;
 
-#ifdef WIN32
-	immed = 0;
-#endif
-
-	int ymin = height_;
-	int ymax = 0;
-	ts = p->crvec_;
-	for (y = 0; y < height_; y += 8) {
-		for (int x = 0; x < width_; ) {
-			if (RV_PAST(now, ts[x >> 3])) {
-				x += 8;
-				continue;
+	render(vf->bp_, 0, 0, 0, 0);
+	
+	// put the image to display
+	// in WindowRenderer::push
+	push(NULL, 0, 0, 0, 0);
+	sync();
+	
+	/*
+		//
+		//  check how many blocks we need to update.  If more than
+		//  12%, do a single image push call for them.  Otherwise,
+		// only push the ones that change.
+		//
+		u_int now = now_;
+		const u_int8_t* ts = p->crvec_;
+		u_int bcnt = 0;
+		int w = width_ >> 3;
+		int y;
+		for (y = height_ >> 3; --y >= 0; ) {
+			for (int x = 0; x < w; ++x)
+				if (!RV_PAST(now, ts[x]))
+					++bcnt;
+			ts += w;
+		}
+		int immed = bcnt < irthresh_;
+	
+	
+	#ifdef WIN32
+		immed = 0;
+	#endif
+	
+		int ymin = height_;
+		int ymax = 0;
+		ts = p->crvec_;
+		for (y = 0; y < height_; y += 8) {
+			for (int x = 0; x < width_; ) {
+				if (RV_PAST(now, ts[x >> 3])) {
+					x += 8;
+					continue;
+				}
+				int sx = x;
+				do {
+					x += 8;
+				} while (x < width_ && !RV_PAST(now, ts[x >> 3]));
+	
+				if (y < ymin)
+					ymin = y;
+				if (y > ymax)
+					ymax = y;
+				// XXX
+				int off = y * width_ + sx;
+				render(p->bp_, off, sx, x - sx, 8);
+				if (immed)
+					push(p->bp_, y, y + 8, sx, x);
 			}
-			int sx = x;
-			do {
-				x += 8;
-			} while (x < width_ && !RV_PAST(now, ts[x >> 3]));
-
-			if (y < ymin)
-				ymin = y;
-			if (y > ymax)
-				ymax = y;
-			/*XXX*/
-			int off = y * width_ + sx;
-			render(p->bp_, off, sx, x - sx, 8);
-			if (immed)
-				push(p->bp_, y, y + 8, sx, x);
+			ts += width_ >> 3;
+		}
+		// XXX
+		now_ = p->ts_;
+		if (ymin <= ymax) {
+			if (!immed)
+				push(p->bp_, ymin, ymax + 8, 0, 0);
+			sync();
 		}
-		ts += width_ >> 3;
-	}
-	/*XXX*/
-	now_ = p->ts_;
-	if (ymin <= ymax) {
-		if (!immed)
-			push(p->bp_, ymin, ymax + 8, 0, 0);
-		sync();
 	}
+	*/
 	return (0);
 }

Modified: vic/branches/mpeg4/render/renderer.h
==============================================================================
--- vic/branches/mpeg4/render/renderer.h	(original)
+++ vic/branches/mpeg4/render/renderer.h	Thu Oct  5 09:45:33 2006
@@ -65,6 +65,7 @@
 	u_int now_;
 	u_int update_interval_;	/* update interval */
 	int need_update_;	/* true to update on next frame */
+	bool enable_xv;
 };
 
 class BlockRenderer : public Renderer {

Modified: vic/branches/mpeg4/render/vw.cpp
==============================================================================
--- vic/branches/mpeg4/render/vw.cpp	(original)
+++ vic/branches/mpeg4/render/vw.cpp	Thu Oct  5 09:45:33 2006
@@ -41,7 +41,7 @@
 #include "vw.h"
 #include "color.h"
 #include "rgb-converter.h"
-
+#include "xvideo.h"
 extern "C" {
 #include <tk.h>
 
@@ -158,6 +158,41 @@
 	XDestroyImage(image_);
 }
 
+
+// FIXME: need to detect xvdieo capability
+bool XVideoImage::enable_xv = true;
+
+XVideoImage::XVideoImage(Tk_Window tk, int width, int height)
+  : VideoImage(tk, width, height), image_(NULL)
+{			     
+	if(render.init(dpy_, FOURCC_I420, Tk_Visual(tk), Tk_Depth(tk), 3) >= 0){
+	  image_ = render.createImage(width, height);	  
+	}else{
+	  printf("cannot initialize xvideo extension");
+	  enable_xv = false;
+    }
+}
+
+XVideoImage* XVideoImage::allocate(Tk_Window tk, int width, int height){
+	
+	if(enable_xv){
+	  XVideoImage* p = new XVideoImage(tk, width, height);
+	  if(enable_xv){
+	    printf("using Xvideo extension\n");
+	    return (p);	
+	  }else{
+	    delete p;
+	    return NULL;
+	  }
+	}
+	return NULL;
+}
+
+void XVideoImage::putimage(Display* dpy, Window window, GC gc,
+		      int sx, int sy, int x, int y,int w, int h) const{
+	render.displayImage(window, gc, w, h);
+}
+
 SlowVideoImage::SlowVideoImage(Tk_Window tk, int w, int h)
 	: StandardVideoImage(tk, w, h)
 {
@@ -450,15 +485,16 @@
 	int h = y1 - y0;
 	if (h == 0)
 		h = vi_->height();
-	else if (h > vi_->height())
-		h = vi_->height();
+// for fullscreen rendering, video frame is larger than render window size
+//	else if (h > vi_->height())
+//		h = vi_->height();
 	else if (h < 0)
 		return;
 	int w = x1 - x0;
 	if (w == 0)
 		w = vi_->width();
-	else if (w > vi_->width())
-		w = vi_->width();
+//	else if (w > vi_->width())
+//		w = vi_->width();
 	else if (w < 0)
 		return;
 

Modified: vic/branches/mpeg4/render/vw.h
==============================================================================
--- vic/branches/mpeg4/render/vw.h	(original)
+++ vic/branches/mpeg4/render/vw.h	Thu Oct  5 09:45:33 2006
@@ -39,6 +39,7 @@
 
 #include "vic_tcl.h"
 
+
 extern "C" {
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
@@ -46,6 +47,7 @@
 #include <X11/extensions/XShm.h>
 #endif
 #include <tk.h>
+#include "xvideo.h"
 }
 
 class VideoWindow;
@@ -83,6 +85,27 @@
 	XImage* image_;
 };
 
+/* 
+ * XVideoImage supports shared memory, 
+ * Xvideo extension, and basic X11 rendering
+ */
+
+class XVideoImage : public VideoImage {
+    protected:
+	XVideoImage(Tk_Window, int width, int height);
+    public:
+	static XVideoImage* allocate(Tk_Window, int width, int height);
+	inline u_char* pixbuf() { return ((u_char*)image_->data); }
+	inline IMAGE_TYPE* ximage() { return (image_); }
+	void putimage(Display* dpy, Window window, GC gc,
+		      int sx, int sy, int x, int y,int w, int h) const;
+        static inline bool is_supported() { return enable_xv; }        		      
+        
+    protected:
+	IMAGE_TYPE* image_;
+	XRender render;
+	static bool enable_xv;
+};
 #ifdef USE_SHM
 /*
  * A class for ximages, which will be allocate in shared memory

Modified: vic/branches/mpeg4/render/xvideo.cpp
==============================================================================
--- vic/branches/mpeg4/render/xvideo.cpp	(original)
+++ vic/branches/mpeg4/render/xvideo.cpp	Thu Oct  5 09:45:33 2006
@@ -1,6 +1,8 @@
 #include <stdio.h>
 #include <stdlib.h>
+
 #include "../config_arch.h"
+
 #ifdef HAVE_SHM
 #include <sys/ipc.h>
 #include <sys/shm.h>
@@ -9,28 +11,27 @@
 
 #include "color.h"
 #include "rgb-converter.h"
-extern "C"
-{
 
+extern "C"{
 #include <tk.h>
 }
 
-IMAGE_TYPE *CreateImage(Display *, EXTRA_ARGS, int, int);
+IMAGE_TYPE *CreateImage    ( Display *, EXTRA_ARGS, int, int );
 #ifdef HAVE_SHM
-IMAGE_TYPE *CreateShmImage(Display *, EXTRA_ARGS_SHM, int, int);
+IMAGE_TYPE *CreateShmImage ( Display *, EXTRA_ARGS_SHM, int, int );
 #endif
 
 /* Function Definition */
 #ifdef HAVE_XVIDEO
-int XVideoGetPort(Display *, vlc_fourcc_t, vlc_fourcc_t *);
-static void XVideoReleasePort(Display *, int);
+int  XVideoGetPort    ( Display *, vlc_fourcc_t , vlc_fourcc_t *);
+static void XVideoReleasePort( Display *, int );
 #endif
 
-int vout_ChromaCmp(vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc);
+int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc );
 
-void DisplayVideo(Display * p_display, int i_xvport, Window video_window,
-		  GC gc, IMAGE_TYPE * p_image, int width, int height,
-		  int o_width, int o_height, bool shared_memory);
+void DisplayVideo( Display *p_display, int i_xvport, Window video_window,
+	GC gc, IMAGE_TYPE *p_image, int width, int height, int o_width, int o_height,
+	bool shared_memory );
 
 static int xv_port = -1;
 // how many clients that use xv_port
@@ -40,249 +41,275 @@
 /*****************************************************************************
  * XVideoGetPort: get YUV12 port
  *****************************************************************************/
-int XVideoGetPort(Display * p_display,
-		  vlc_fourcc_t i_chroma, vlc_fourcc_t * pi_newchroma)
+int XVideoGetPort( Display *p_display,
+                          vlc_fourcc_t i_chroma, vlc_fourcc_t *pi_newchroma )
 {
     XvAdaptorInfo *p_adaptor;
     unsigned int i;
     unsigned int i_num_adaptors;
-    int i_adaptor, i_requested_adaptor;
+    int i_adaptor,  i_requested_adaptor;
     int i_selected_port;
 
-    switch (XvQueryExtension(p_display, &i, &i, &i, &i, &i)) {
-    case Success:
-	break;
-
-    case XvBadExtension:
-	printf("XvBadExtension\n");
-	return -1;
-
-    case XvBadAlloc:
-	printf("XvBadAlloc\n");
-	return -1;
-
-    default:
-	printf("XvQueryExtension failed\n");
-	return -1;
-    }
-
-    switch (XvQueryAdaptors(p_display,
-			    DefaultRootWindow(p_display),
-			    &i_num_adaptors, &p_adaptor)) {
-    case Success:
-	break;
-
-    case XvBadExtension:
-	printf("XvBadExtension for XvQueryAdaptors\n");
-	return -1;
-
-    case XvBadAlloc:
-	printf("XvBadAlloc for XvQueryAdaptors\n");
-	return -1;
-
-    default:
-	printf("XvQueryAdaptors failed\n");
-	return -1;
+    switch( XvQueryExtension( p_display, &i, &i, &i, &i, &i ) )
+    {
+        case Success:
+            break;
+
+        case XvBadExtension:
+            printf("XvBadExtension\n");
+            return -1;
+
+        case XvBadAlloc:
+            printf("XvBadAlloc\n");
+            return -1;
+
+        default:
+            printf( "XvQueryExtension failed\n" );
+            return -1;
+    }
+
+    switch( XvQueryAdaptors( p_display,
+                             DefaultRootWindow( p_display ),
+                             &i_num_adaptors, &p_adaptor ) )
+    {
+        case Success:
+            break;
+
+        case XvBadExtension:
+            printf( "XvBadExtension for XvQueryAdaptors\n" );
+            return -1;
+
+        case XvBadAlloc:
+            printf( "XvBadAlloc for XvQueryAdaptors\n" );
+            return -1;
+
+        default:
+            printf( "XvQueryAdaptors failed\n" );
+            return -1;
     }
 
     i_selected_port = -1;
     i_requested_adaptor = -1;
 
-    for (i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor) {
-	XvImageFormatValues *p_formats;
-	int i_format, i_num_formats;
-	int i_port;
-
-	/* If we requested an adaptor and it's not this one, we aren't
-	 * interested */
-	if (i_requested_adaptor != -1 && i_adaptor != i_requested_adaptor) {
-	    continue;
-	}
-
-	/* If the adaptor doesn't have the required properties, skip it */
-	if (!(p_adaptor[i_adaptor].type & XvInputMask) ||
-	    !(p_adaptor[i_adaptor].type & XvImageMask)) {
-	    continue;
-	}
-
-	/* Check that adaptor supports our requested format... */
-	p_formats = XvListImageFormats(p_display,
-				       p_adaptor[i_adaptor].base_id,
-				       &i_num_formats);
-
-	for (i_format = 0;
-	     i_format < i_num_formats && (i_selected_port == -1);
-	     i_format++) {
+    for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
+    {
+        XvImageFormatValues *p_formats;
+        int i_format, i_num_formats;
+        int i_port;
+
+        /* If we requested an adaptor and it's not this one, we aren't
+         * interested */
+        if( i_requested_adaptor != -1 && i_adaptor != i_requested_adaptor )
+        {
+            continue;
+        }
+
+        /* If the adaptor doesn't have the required properties, skip it */
+        if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
+            !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
+        {
+            continue;
+        }
+
+        /* Check that adaptor supports our requested format... */
+        p_formats = XvListImageFormats( p_display,
+                                        p_adaptor[i_adaptor].base_id,
+                                        &i_num_formats );
+
+        for( i_format = 0;
+             i_format < i_num_formats && ( i_selected_port == -1 );
+             i_format++ )
+        {
 
 /*
 	    printf("  0x%x (%4.4s) %s\n",
 	       p_formats[i_format].id,
 	       (char *)&p_formats[i_format].id,
 	       (p_formats[i_format].format == XvPacked) ? "packed" : "planar");
-  */
-
-	    /* If this is not the format we want, or at least a
-	     * similar one, forget it */
-	    if (!vout_ChromaCmp(p_formats[i_format].id, i_chroma)) {
-		continue;
-	    }
-
-	    /* Look for the first available port supporting this format */
-	    for (i_port = p_adaptor[i_adaptor].base_id;
-		 (i_port < (int) (p_adaptor[i_adaptor].base_id
-				  + p_adaptor[i_adaptor].num_ports))
-		 && (i_selected_port == -1); i_port++) {
-		if (XvGrabPort(p_display, i_port, CurrentTime) == Success) {
-		    i_selected_port = i_port;
-		    *pi_newchroma = p_formats[i_format].id;
-		}
-	    }
-
-	    /* If no free port was found, forget it */
-	    if (i_selected_port == -1) {
-		continue;
-	    }
+  */    
 
+            /* If this is not the format we want, or at least a
+             * similar one, forget it */
+            if( !vout_ChromaCmp( p_formats[ i_format ].id, i_chroma ) )
+            {
+                continue;
+            }
+
+            /* Look for the first available port supporting this format */
+            for( i_port = p_adaptor[i_adaptor].base_id;
+                 ( i_port < (int)(p_adaptor[i_adaptor].base_id
+                                   + p_adaptor[i_adaptor].num_ports) )
+                   && ( i_selected_port == -1 );
+                 i_port++ )
+            {
+                if( XvGrabPort( p_display, i_port, CurrentTime ) == Success )
+                {
+                    i_selected_port = i_port;
+                    *pi_newchroma = p_formats[ i_format ].id;
+                }
+            }
+
+            /* If no free port was found, forget it */
+            if( i_selected_port == -1 )
+            {
+                continue;
+            }
+            
 #if 0
-	    // If we found a port, print information about it 
-	    printf("adaptor %i, port %i, format 0x%x (%4.4s) %s\n",
-		   i_adaptor, i_selected_port, p_formats[i_format].id,
-		   (char *) &p_formats[i_format].id,
-		   (p_formats[i_format].format == XvPacked) ?
-		   "packed" : "planar");
-
-
-	    XvEncodingInfo *p_enc;
-	    unsigned int i_enc, i_num_encodings;
-	    XvAttribute *p_attr;
-	    int i_attr, i_num_attributes;
-
-	    printf(" encoding list:\n");
-
-	    if (XvQueryEncodings(p_display, i_selected_port,
-				 &i_num_encodings, &p_enc)
-		!= Success) {
-		printf("  XvQueryEncodings failed\n");
-		continue;
-	    }
-
-	    for (i_enc = 0; i_enc < i_num_encodings; i_enc++) {
-		printf("  id=%ld, name=%s, size=%ldx%ld,"
-		       " numerator=%d, denominator=%d\n",
-		       p_enc[i_enc].encoding_id, p_enc[i_enc].name,
-		       p_enc[i_enc].width, p_enc[i_enc].height,
-		       p_enc[i_enc].rate.numerator,
-		       p_enc[i_enc].rate.denominator);
-	    }
-
-	    if (p_enc != NULL) {
-		XvFreeEncodingInfo(p_enc);
-	    }
-
-	    printf(" attribute list:\n");
-	    p_attr = XvQueryPortAttributes(p_display,
-					   i_selected_port,
-					   &i_num_attributes);
-	    for (i_attr = 0; i_attr < i_num_attributes; i_attr++) {
-		printf("  name=%s, flags=[%s%s ], min=%i, max=%i\n",
-		       p_attr[i_attr].name,
-		       (p_attr[i_attr].flags & XvGettable) ? " get" : "",
-		       (p_attr[i_attr].flags & XvSettable) ? " set" : "",
-		       p_attr[i_attr].min_value, p_attr[i_attr].max_value);
-	    }
-
-	    if (p_attr != NULL) {
-		XFree(p_attr);
-	    }
-#endif
-	}
-
-	if (p_formats != NULL) {
-	    XFree(p_formats);
-	}
-
-    }
-
-    if (i_num_adaptors > 0) {
-	XvFreeAdaptorInfo(p_adaptor);
-    }
-
-    if (i_selected_port == -1) {
-	int i_chroma_tmp = X112VLC_FOURCC(i_chroma);
-	if (i_requested_adaptor == -1) {
-	    printf("no free XVideo port found for format \n"
-		   "0x%.8x (%4.4s)", i_chroma_tmp, (char *) &i_chroma_tmp);
-	}
-	else {
-	    printf("XVideo adaptor %i does not have a free \n"
-		   "XVideo port for format 0x%.8x (%4.4s)",
-		   i_requested_adaptor, i_chroma_tmp, (char *) &i_chroma_tmp);
-	}
+            // If we found a port, print information about it 
+            printf( "adaptor %i, port %i, format 0x%x (%4.4s) %s\n",
+                     i_adaptor, i_selected_port, p_formats[ i_format ].id,
+                     (char *)&p_formats[ i_format ].id,
+                     ( p_formats[ i_format ].format == XvPacked ) ?
+                         "packed" : "planar" );
+
+
+            XvEncodingInfo  *p_enc;
+            unsigned int             i_enc, i_num_encodings;
+            XvAttribute     *p_attr;
+            int             i_attr, i_num_attributes;
+
+            printf(  " encoding list:\n" );
+	    
+            if( XvQueryEncodings( p_display, i_selected_port,
+                                  &i_num_encodings, &p_enc )
+                 != Success )
+            {
+                printf(  "  XvQueryEncodings failed\n" );
+                continue;
+            }
+
+            for( i_enc = 0; i_enc < i_num_encodings; i_enc++ )
+            {
+                printf( "  id=%ld, name=%s, size=%ldx%ld,"
+                                      " numerator=%d, denominator=%d\n",
+                             p_enc[i_enc].encoding_id, p_enc[i_enc].name,
+                             p_enc[i_enc].width, p_enc[i_enc].height,
+                             p_enc[i_enc].rate.numerator,
+                             p_enc[i_enc].rate.denominator );
+            }
+
+            if( p_enc != NULL )
+            {
+                XvFreeEncodingInfo( p_enc );
+            }
+
+            printf(  " attribute list:\n" );
+            p_attr = XvQueryPortAttributes( p_display,
+                                            i_selected_port,
+                                            &i_num_attributes );
+            for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
+            {
+                printf( "  name=%s, flags=[%s%s ], min=%i, max=%i\n",
+                      p_attr[i_attr].name,
+                      (p_attr[i_attr].flags & XvGettable) ? " get" : "",
+                      (p_attr[i_attr].flags & XvSettable) ? " set" : "",
+                      p_attr[i_attr].min_value, p_attr[i_attr].max_value );
+            }
+
+            if( p_attr != NULL )
+            {
+                XFree( p_attr );
+            }
+#endif
+        }
+
+        if( p_formats != NULL )
+        {
+            XFree( p_formats );
+        }
+
+    }
+
+    if( i_num_adaptors > 0 )
+    {
+        XvFreeAdaptorInfo( p_adaptor );
+    }
+
+    if( i_selected_port == -1 )
+    {
+        int i_chroma_tmp = X112VLC_FOURCC( i_chroma );
+        if( i_requested_adaptor == -1 )
+        {
+            printf( "no free XVideo port found for format \n"
+                      "0x%.8x (%4.4s)", i_chroma_tmp, (char*)&i_chroma_tmp );
+        }
+        else
+        {
+            printf( "XVideo adaptor %i does not have a free \n"
+                      "XVideo port for format 0x%.8x (%4.4s)",
+                      i_requested_adaptor, i_chroma_tmp, (char*)&i_chroma_tmp );
+        }
     }
 
     return i_selected_port;
 }
-#endif
+#endif 
 
-// =========================================================================
-int vout_ChromaCmp(vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc)
+// ======================================================================================
+int vout_ChromaCmp( vlc_fourcc_t i_chroma, vlc_fourcc_t i_amorhc )
 {
-    /* If they are the same, they are the same ! */
-    if (i_chroma == i_amorhc) {
-	return 1;
-    }
-
-    /* Check for equivalence classes */
-    switch (i_chroma) {
-    case FOURCC_I420:
-    case FOURCC_IYUV:
-    case FOURCC_YV12:
-	switch (i_amorhc) {
-	case FOURCC_I420:
-	case FOURCC_IYUV:
-	case FOURCC_YV12:
-	    return 1;
-
-	default:
-	    return 0;
-	}
-
-    case FOURCC_UYVY:
-    case FOURCC_UYNV:
-    case FOURCC_Y422:
-	switch (i_amorhc) {
-	case FOURCC_UYVY:
-	case FOURCC_UYNV:
-	case FOURCC_Y422:
-	    return 1;
-
-	default:
-	    return 0;
-	}
-
-    case FOURCC_YUY2:
-    case FOURCC_YUNV:
-	switch (i_amorhc) {
-	case FOURCC_YUY2:
-	case FOURCC_YUNV:
-	    return 1;
-
-	default:
-	    return 0;
-	}
-
-    default:
-	return 0;
-    }
+     /* If they are the same, they are the same ! */
+     if( i_chroma == i_amorhc )
+     {
+         return 1;
+     }
+ 
+     /* Check for equivalence classes */
+     switch( i_chroma )
+     {
+         case FOURCC_I420:
+         case FOURCC_IYUV:
+         case FOURCC_YV12:
+             switch( i_amorhc )
+             {
+                 case FOURCC_I420:
+                 case FOURCC_IYUV:
+                 case FOURCC_YV12:
+                     return 1;
+ 
+                 default:
+                     return 0;
+             }
+ 
+         case FOURCC_UYVY:
+         case FOURCC_UYNV:
+         case FOURCC_Y422:
+             switch( i_amorhc )
+             {
+                 case FOURCC_UYVY:
+                 case FOURCC_UYNV:
+                 case FOURCC_Y422:
+                     return 1;
+ 
+                 default:
+                     return 0;
+             }
+ 
+         case FOURCC_YUY2:
+         case FOURCC_YUNV:
+             switch( i_amorhc )
+             {
+                 case FOURCC_YUY2:
+                 case FOURCC_YUNV:
+                     return 1;
+ 
+                 default:
+                     return 0;
+             }
+ 
+         default:
+             return 0;
+     }
 }
 
 #ifdef HAVE_XVIDEO
 /*****************************************************************************
  * XVideoReleasePort: release YUV12 port
  *****************************************************************************/
-static void XVideoReleasePort(Display * p_display, int i_port)
+static void XVideoReleasePort( Display *p_display, int i_port )
 {
-    XvUngrabPort(p_display, i_port, CurrentTime);
+    XvUngrabPort( p_display, i_port, CurrentTime );
 }
 #endif
 
@@ -297,64 +324,67 @@
  * document by J.Corbet and K.Packard. Most of the parameters were copied from
  * there. See http://ftp.xfree86.org/pub/XFree86/4.0/doc/mit-shm.TXT
  *****************************************************************************/
-IMAGE_TYPE *CreateShmImage(Display * p_display, EXTRA_ARGS_SHM,
-			   int i_width, int i_height)
+IMAGE_TYPE * CreateShmImage( Display* p_display, EXTRA_ARGS_SHM,
+                                    int i_width, int i_height )
 {
     IMAGE_TYPE *p_image;
 
     /* Create XImage / XvImage */
 #ifdef HAVE_XVIDEO
-    p_image =
-	XvShmCreateImage(p_display, i_xvport, VLC2X11_FOURCC(i_chroma), 0,
-			 i_width, i_height, p_shm);
+    p_image = XvShmCreateImage( p_display, i_xvport, VLC2X11_FOURCC(i_chroma), 0,
+                                i_width, i_height, p_shm );
 #else
-    p_image = XShmCreateImage(p_display, p_visual, i_depth, ZPixmap, 0,
-			      p_shm, i_width, i_height);
+    p_image = XShmCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
+                               p_shm, i_width, i_height );
 #endif
-    if (p_image == NULL) {
-	printf("image creation failed\n");
-	return NULL;
+    if( p_image == NULL )
+    {
+        printf("image creation failed\n");
+        return NULL;
     }
 
     /* Allocate shared memory segment - 0776 set the access permission
      * rights (like umask), they are not yet supported by all X servers */
-    p_shm->shmid = shmget(IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0776);
-    if (p_shm->shmid < 0) {
-	printf("cannot allocate shared image data\n");
-	IMAGE_FREE(p_image);
-	return NULL;
+    p_shm->shmid = shmget( IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0776 );
+    if( p_shm->shmid < 0 )
+    {
+        printf("cannot allocate shared image data\n");
+        IMAGE_FREE( p_image );
+        return NULL;
     }
 
     /* Attach shared memory segment to process (read/write) */
-    p_shm->shmaddr = p_image->data = (char *) shmat(p_shm->shmid, 0, 0);
-    if (!p_shm->shmaddr) {
-	printf("cannot attach shared memory\n");
-	IMAGE_FREE(p_image);
-	shmctl(p_shm->shmid, IPC_RMID, 0);
-	return NULL;
+    p_shm->shmaddr = p_image->data = (char*)shmat( p_shm->shmid, 0, 0 );
+    if( !p_shm->shmaddr )
+    {
+        printf("cannot attach shared memory\n");
+        IMAGE_FREE( p_image );
+        shmctl( p_shm->shmid, IPC_RMID, 0 );
+        return NULL;
     }
 
     /* Read-only data. We won't be using XShmGetImage */
     p_shm->readOnly = True;
 
     /* Attach shared memory segment to X server */
-    if (XShmAttach(p_display, p_shm) == False) {
-	printf("cannot attach shared memory to X server\n");
-	IMAGE_FREE(p_image);
-	shmctl(p_shm->shmid, IPC_RMID, 0);
-	shmdt(p_shm->shmaddr);
-	return NULL;
+    if( XShmAttach( p_display, p_shm ) == False )
+    {
+        printf("cannot attach shared memory to X server\n" );
+        IMAGE_FREE( p_image );
+        shmctl( p_shm->shmid, IPC_RMID, 0 );
+        shmdt( p_shm->shmaddr );
+        return NULL;
     }
 
     /* Send image to X server. This instruction is required, since having
      * built a Shm XImage and not using it causes an error on XCloseDisplay,
      * and remember NOT to use XFlush ! */
-    XSync(p_display, False);
+    XSync( p_display, False );
 
 #if 0
     /* Mark the shm segment to be removed when there are no more
      * attachements, so it is automatic on process exit or after shmdt */
-    shmctl(p_shm->shmid, IPC_RMID, 0);
+    shmctl( p_shm->shmid, IPC_RMID, 0 );
 #endif
 
     return p_image;
@@ -366,26 +396,27 @@
  *****************************************************************************
  * Create a simple image used as a buffer.
  *****************************************************************************/
-IMAGE_TYPE *CreateImage(Display * p_display, EXTRA_ARGS,
-			int i_width, int i_height)
+IMAGE_TYPE * CreateImage( Display *p_display, EXTRA_ARGS,
+                                 int i_width, int i_height )
 {
-    uint8_t *p_data;		/* image data storage zone */
+    uint8_t *    p_data;                           /* image data storage zone */
     IMAGE_TYPE *p_image;
 #ifndef HAVE_XVIDEO
-    int i_quantum;		/* XImage quantum (see below) */
-    int i_bytes_per_line;
+    int         i_quantum;                     /* XImage quantum (see below) */
+    int         i_bytes_per_line;
 #endif
 
     /* Allocate memory for image */
 #ifdef HAVE_XVIDEO
-    p_data = (uint8_t *) malloc(i_width * i_height * i_bits_per_pixel / 8);
+    p_data = (uint8_t *) malloc( i_width * i_height * i_bits_per_pixel / 8 );
 #else
     i_bytes_per_line = i_width * i_bytes_per_pixel;
-    p_data = (uint8_t *) malloc(i_bytes_per_line * i_height);
+    p_data = (uint8_t *) malloc( i_bytes_per_line * i_height );
 #endif
-    if (!p_data) {
-	printf("out of memory\n");
-	return NULL;
+    if( !p_data )
+    {
+        printf("out of memory\n" );
+        return NULL;
     }
 
 #ifndef HAVE_XVIDEO
@@ -394,88 +425,91 @@
     /* Specifies the quantum of a scanline (8, 16, or 32). In other words, 
        the start of one scanline is separated in client memory from the start 
        of the next scanline by an integer multiple of this many bits.      */
-
-    if (i_bytes_per_line & 0xf)	// 8
+       
+    if( i_bytes_per_line & 0xf )  // 8
     {
-	i_quantum = 0x8;
+        i_quantum = 0x8;
     }
-    else if (i_bytes_per_line & 0x10)	// 16
+    else if( i_bytes_per_line & 0x10 ) // 16
     {
-	i_quantum = 0x10;
+        i_quantum = 0x10;
     }
-    else			// 32
+    else  // 32
     {
-	i_quantum = 0x20;
+        i_quantum = 0x20;
     }
 #endif
 
     /* Create XImage. p_data will be automatically freed */
 #ifdef HAVE_XVIDEO
-    p_image = XvCreateImage(p_display, i_xvport, VLC2X11_FOURCC(i_chroma),
-			    (char *) p_data, i_width, i_height);
+    p_image = XvCreateImage( p_display, i_xvport, VLC2X11_FOURCC(i_chroma),
+                             (char*)p_data, i_width, i_height );
 #else
-    p_image = XCreateImage(p_display, p_visual, i_depth, ZPixmap, 0,
-			   (char *) p_data, i_width, i_height, i_quantum, 0);
+    p_image = XCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
+                            (char*)p_data, i_width, i_height, i_quantum, 0 );
 #endif
-    if (p_image == NULL) {
-	printf("XCreateImage() failed\n");
-	free(p_data);
-	return NULL;
+    if( p_image == NULL )
+    {
+        printf("XCreateImage() failed\n");
+        free( p_data );
+        return NULL;
     }
 
     return p_image;
-}
+ }
 
-void DisplayVideo(Display * p_display, int i_xvport, Window video_window,
-		  GC gc, IMAGE_TYPE * p_image, int width, int height,
-		  int o_width, int o_height, bool shared_memory)
+void DisplayVideo( Display *p_display, int i_xvport, Window video_window,
+	GC gc, IMAGE_TYPE *p_image, int width, int height, int o_width, int o_height,
+	bool shared_memory )
 {
 
 
 #ifdef HAVE_SHM
-    if (shared_memory) {
-	/* Display rendered image using shared memory extension */
+    if( shared_memory )
+    {
+        /* Display rendered image using shared memory extension */
 #   ifdef HAVE_XVIDEO
-	XvShmPutImage(p_display, i_xvport,
-		      video_window, gc, p_image, 0 /*src_x */ , 0 /*src_y */ ,
-		      width, height,
-		      0 /*dest_x */ , 0 /*dest_y */ , o_width, o_height,
-		      False	/* Don't put True here or you'll waste your CPU */
-	    );
+        XvShmPutImage( p_display, i_xvport,
+                       video_window,
+                       gc, p_image,
+                       0 /*src_x*/, 0 /*src_y*/,
+                       width, height,
+                       0 /*dest_x*/, 0 /*dest_y*/, o_width, o_height,
+                       False /* Don't put True here or you'll waste your CPU */ );
 #   else
-	XShmPutImage(p_display,
-		     video_window,
-		     gc, p_image,
-		     0 /*src_x */ , 0 /*src_y */ , 0 /*dest_x */ ,
-		     0 /*dest_y */ ,
-		     width, height, False /* Don't put True here ! */ );
+        XShmPutImage( p_display,
+                      video_window,
+                      gc, p_image,
+                      0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
+                      width, height,
+                      False /* Don't put True here ! */ );
 #   endif
     }
     else
 #endif /* HAVE_SHM */
     {
-	/* Use standard XPutImage -- this is gonna be slow ! */
+        /* Use standard XPutImage -- this is gonna be slow ! */
 #ifdef HAVE_XVIDEO
-	XvPutImage(p_display, i_xvport,
-		   video_window, gc, p_image, 0 /*src_x */ , 0 /*src_y */ ,
-		   width, height,
-		   0 /*dest_x */ , 0 /*dest_y */ , o_width, o_height);
+        XvPutImage( p_display, i_xvport,
+                    video_window,
+                    gc, p_image,
+                    0 /*src_x*/, 0 /*src_y*/,
+                    width, height,
+                    0 /*dest_x*/, 0 /*dest_y*/, o_width, o_height );
 #else
-	XPutImage(p_display,
-		  video_window,
-		  gc, p_image, 0 /*src_x */ , 0 /*src_y */ , 0 /*dest_x */ ,
-		  0 /*dest_y */ ,
-		  width, height);
+        XPutImage( p_display,
+                   video_window,
+                   gc, p_image,
+                   0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
+                   width, height );
 #endif
     }
 
-    /* Make sure the command is sent now - do NOT use XFlush ! */
+    /* Make sure the command is sent now - do NOT use XFlush !*/
 #ifndef WINDOWS
-    XSync(p_display, False);
-
-#else /*  */
-    p_display->request++;
-
+    XSync( p_display, False );
+#else
+	p_display->request++;
 #endif
 }
 
@@ -483,8 +517,7 @@
 
 
 XRender::XRender()
-:  yuv_image(NULL), display(NULL), enable_shm(false)
-{
+  :yuv_image(NULL), display(NULL), enable_shm(false){
 
 }
 
@@ -493,106 +526,95 @@
 // -1: indicate the X server doesn't support xvideo extension
 //  0: successfult allocate xv_port
 //  1: exist xv_port allocated 
-int XRender::init(Display * _dpy, vlc_fourcc_t _chroma, Visual * _p_visual,
-		  int _depth, int _bytes_per_rgb)
-{
-    display = _dpy;
-    i_chroma = _chroma;
-    p_visual = _p_visual;
-    depth = _depth;
-    bytes_per_rgb = _bytes_per_rgb;
-
-
-#ifdef HAVE_SHM
-    if (XShmQueryExtension(display)) {
-	enable_shm = true;
-	// printf("==> using shared memory.\n");
-    }
-    else {
-	enable_shm = false;
-	// printf("==> no shmem available.\n");    
-    }
-#endif
-
-#ifdef HAVE_XVIDEO
-    if (xv_port != -1) {
-	num_xv_port++;
-	return 1;
-    }
-
-    xv_port = XVideoGetPort(display, i_chroma, &o_chroma);
-    if (xv_port != -1) {
-	num_xv_port = 1;
-	return 0;
-    }
-    else {			// doesn't supoort Xvideo extension
-	enable_shm = false;
-	return -1;
-    }
-#endif
-    return -1;
+int XRender::init(Display *_dpy, vlc_fourcc_t _chroma, Visual *_p_visual, int _depth, int _bytes_per_rgb){
+  display = _dpy;
+  i_chroma = _chroma;
+  p_visual = _p_visual;
+  depth = _depth;
+  bytes_per_rgb = _bytes_per_rgb;
+  
+  
+#ifdef HAVE_SHM 
+  if (XShmQueryExtension(display)){
+    enable_shm = true;  	
+    // printf("==> using shared memory.\n");
+  }else{
+    enable_shm = false;
+    // printf("==> no shmem available.\n");    
+  }
+#endif
+  
+#ifdef HAVE_XVIDEO  
+  if(xv_port != -1){
+    num_xv_port++;
+    return 1;
+  }
+  
+  xv_port = XVideoGetPort( display, i_chroma, &o_chroma );
+  if(xv_port != -1){
+    num_xv_port = 1; 
+    return 0;
+  }else{ // doesn't supoort Xvideo extension
+    enable_shm = false;
+    return -1;	
+  }
+#endif
+  return -1;
+}
+
+IMAGE_TYPE* XRender::createImage(int _width, int _height){
+  i_width  = _width;
+  i_height = _height;
+  
+  if(yuv_image) IMAGE_FREE(yuv_image);
+  
+#ifdef HAVE_SHM    
+  if(enable_shm){
+    yuv_image = CreateShmImage(display, 
+    #ifdef HAVE_XVIDEO   
+      xv_port, i_chroma, &yuv_shminfo,
+    #else
+      p_visual, depth, &yuv_shminfo, 
+    #endif
+      i_width, i_height );  
+  }else
+#endif  // HAVE_SHM
+  {
+    yuv_image = CreateImage(display,
+    #ifdef HAVE_XVIDEO  
+      xv_port, i_chroma, 12,
+    #else
+      p_visual, depth, bytes_per_rgb,
+    #endif
+      i_width, i_height );
+  }
+  return yuv_image; 
+}
+
+void XRender::displayImage(Window video_window, GC gc, int o_width, int o_height) const{
+  DisplayVideo( display, xv_port, video_window, gc, yuv_image, i_width, i_height, 
+    o_width, o_height, enable_shm );	
+	
+}
+
+void XRender::release(){
+  if(yuv_image) IMAGE_FREE(yuv_image);
+  
+  #ifdef HAVE_XVIDEO
+  if(--num_xv_port == 0)
+    XVideoReleasePort(display, xv_port);
+  #endif  
+  
+  #ifdef HAVE_SHM
+  if(enable_shm){
+    XShmDetach(display, &yuv_shminfo);
+    if(shmdt( yuv_shminfo.shmaddr) <0 )
+      printf("vic: shmdt\n");
+  }
+  #endif
 }
 
-IMAGE_TYPE *XRender::createImage(int _width, int _height)
-{
-    i_width = _width;
-    i_height = _height;
-
-    if (yuv_image)
-	IMAGE_FREE(yuv_image);
-
-#ifdef HAVE_SHM
-    if (enable_shm) {
-	yuv_image = CreateShmImage(display,
-#ifdef HAVE_XVIDEO
-				   xv_port, i_chroma, &yuv_shminfo,
-#else
-				   p_visual, depth, &yuv_shminfo,
-#endif
-				   i_width, i_height);
-    }
-    else
-#endif // HAVE_SHM
-    {
-	yuv_image = CreateImage(display,
-#ifdef HAVE_XVIDEO
-				xv_port, i_chroma, 12,
-#else
-				p_visual, depth, bytes_per_rgb,
-#endif
-				i_width, i_height);
-    }
-    return yuv_image;
-}
-
-     void XRender::displayImage(Window video_window, GC gc, int o_width,
-			   int o_height) const const const
-     {
-	 DisplayVideo(display, xv_port, video_window, gc, yuv_image, i_width,
-		      i_height, o_width, o_height, enable_shm);
-
-     }
-
-     void XRender::release()
-{
-    if (yuv_image)
-	IMAGE_FREE(yuv_image);
-
-#ifdef HAVE_XVIDEO
-    if (--num_xv_port == 0)
-	XVideoReleasePort(display, xv_port);
-#endif
-
-#ifdef HAVE_SHM
-    if (enable_shm) {
-	XShmDetach(display, &yuv_shminfo);
-	if (shmdt(yuv_shminfo.shmaddr) < 0)
-	    printf("vic: shmdt\n");
-    }
-#endif
+XRender::~XRender(){
+  release();	
 }
 
-XRender::~XRender()
-{
-    release();
-}

Modified: vic/branches/mpeg4/render/xvideo.h
==============================================================================
--- vic/branches/mpeg4/render/xvideo.h	(original)
+++ vic/branches/mpeg4/render/xvideo.h	Thu Oct  5 09:45:33 2006
@@ -4,8 +4,7 @@
 #include "../config_arch.h"
 
 #include "vic_tcl.h"
-extern "C"
-{
+extern "C"{
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <tk.h>
@@ -30,7 +29,7 @@
 #   define EXTRA_ARGS     int i_xvport, vlc_fourcc_t i_chroma, int i_bits_per_pixel
 #   define EXTRA_ARGS_SHM int i_xvport, vlc_fourcc_t i_chroma, XShmSegmentInfo *p_shm
 #   define DATA_SIZE(p)   (p)->data_size
-#   define IMAGE_FREE     XFree	/* There is nothing like XvDestroyImage */
+#   define IMAGE_FREE     XFree      /* There is nothing like XvDestroyImage */
 #else
 #   define IMAGE_TYPE     XImage
 #   define EXTRA_ARGS     Visual *p_visual, int i_depth, int i_bytes_per_pixel
@@ -39,35 +38,32 @@
 #   define IMAGE_FREE     XDestroyImage
 #endif
 
-class XRender
-{
+class XRender{
   public:
     XRender();
     ~XRender();
-    int init(Display * _dpy, vlc_fourcc_t _chroma, Visual * _p_visual =
-	     NULL, int _depth = 0, int _bytes_per_rgb = 3);
-    IMAGE_TYPE *createImage(int _width, int _height);
-    void displayImage(Window video_window, GC gc, int _o_width,
-		      int _o_height) const;
+    int init(Display *_dpy, vlc_fourcc_t _chroma, Visual *_p_visual=NULL, int _depth=0, int _bytes_per_rgb=3);
+    IMAGE_TYPE* createImage(int _width, int _height);
+    void displayImage(Window video_window, GC gc, int _o_width, int _o_height) const;    
     void release();
     bool enable_shm;
 
-
+        
   protected:
-         IMAGE_TYPE * yuv_image;
+    IMAGE_TYPE *yuv_image;  
     Display *display;
     int i_width, i_height;
     Visual *p_visual;
     int depth, bytes_per_rgb;
-
+        
     // for Xvideo extension
     vlc_fourcc_t i_chroma;
     vlc_fourcc_t o_chroma;
-
+    
     // for shared memory
-#ifdef HAVE_SHM
-    XShmSegmentInfo yuv_shminfo;
-#endif
+    #ifdef HAVE_SHM
+    XShmSegmentInfo  yuv_shminfo;
+    #endif 
 
 };
 
@@ -75,9 +71,9 @@
 /*****************************************************************************
  * Fourcc definitions that we can handle internally
  *****************************************************************************/
-#define VLC_FOURCC( a, b, c, d ) \
+ #define VLC_FOURCC( a, b, c, d ) \
         ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
-           | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
+           | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )     
 #define X11_FOURCC( a, b, c, d ) \
         ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
            | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
@@ -86,8 +82,8 @@
                     ((char *)&i)[3] )
 #define X112VLC_FOURCC( i ) \
         VLC_FOURCC( i & 0xff, (i >> 8) & 0xff, (i >> 16) & 0xff, \
-                    (i >> 24) & 0xff )
-
+                    (i >> 24) & 0xff )  	
+                   
 /* Packed RGB 15bpp, usually 0x7c00, 0x03e0, 0x001f */
 #define FOURCC_RV15         VLC_FOURCC('R','V','1','5')
 

Modified: vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl
==============================================================================
--- vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl	(original)
+++ vic/branches/mpeg4/tcl/ui-ctrlmenu.tcl	Thu Oct  5 09:45:33 2006
@@ -930,6 +930,7 @@
 
 	global inputType typeButton
 	set inputType auto
+    	#set inputType [string tolower [option get . inputType Vic]]
 	set typeButton $w
 }
 

Modified: vic/branches/mpeg4/tcl/ui-main.tcl
==============================================================================
--- vic/branches/mpeg4/tcl/ui-main.tcl	(original)
+++ vic/branches/mpeg4/tcl/ui-main.tcl	Thu Oct  5 09:45:33 2006
@@ -399,7 +399,7 @@
 #
 # create a renderer for window $w and attach it to $src
 #
-proc attach_renderer { src w } {
+proc attach_renderer { src w {enable_xv false}} {
 	global win_target win_is_slow win_use_hw V
 	set d [$src handler]
 	set target ""
@@ -436,6 +436,7 @@
 	if $win_is_slow($w) {
 		$target update-interval [option get . stampInterval Vic]
 	}
+	$target enable_xv $enable_xv
 	adjust_voff $w $d
 	$d attach $target
 	set win_target($w) $target
@@ -453,8 +454,8 @@
 # bind a source to a window so that the video stream from
 # source $src appears in window $w
 #
-proc attach_window { src w } {
-	attach_renderer $src $w
+proc attach_window { src w {enable_xv false}} {
+	attach_renderer $src $w $enable_xv
 	global win_src win_list
 	set win_src($w) $src
 	lappend win_list($src) $w

Modified: vic/branches/mpeg4/tcl/ui-windows.tcl
==============================================================================
--- vic/branches/mpeg4/tcl/ui-windows.tcl	(original)
+++ vic/branches/mpeg4/tcl/ui-windows.tcl	Thu Oct  5 09:45:33 2006
@@ -77,6 +77,30 @@
 }
 
 #
+# fit video window size as soure resolution
+#
+proc fit_window { vw } {
+
+	global win_src
+	set src $win_src($vw)
+		
+	set d [$src handler]
+	set iw [$d width]
+	set ih [$d height]	
+
+	resize $vw $iw $ih	
+	resize_window $vw $iw $ih	
+}
+
+proc resize_window {vw width height} {
+
+	set w [winfo parent [winfo parent $vw]]	
+	set old_g [split [wm geometry $w] "x+"]
+	set geo [format "%sx%s+%s+%s" $width $height [lindex $old_g 2] [lindex $old_g 3]]	
+	wm geometry $w $geo
+	global size$w		
+	set size$w [format "%sx%s" $width $height]
+}
 # true if w is a top-level viewing window
 #
 proc viewing_window w {
@@ -150,11 +174,22 @@
 proc open_window src {
 	set f [smallfont]	
 	set uid [uniqueID]
+	set d [$src handler]
+	set iw [$d width]
+	set ih [$d height]
+	if { $iw == 0 || $ih == 0} {
+	   puts "window width or height is zero"
+	   return 
+	}
 	set w .vw$uid
 	toplevel $w -class Vic \
 		-visual "[winfo visual .top] [winfo depth .top]" \
 		-colormap .top
 	catch "wm resizable $w false false"
+	#
+	# make windows become x-y resizeable
+	#
+	#catch "wm resizable $w true false"
 	frame $w.frame
 
 
@@ -165,13 +200,18 @@
 		set size$w $userwin_size($src)
 		set d [split $userwin_size($src) x]
 		create_video_widget $w.frame.video [lindex $d 0] [lindex $d 1]
-	} elseif [isCIF [rtp_format $src]] {
-		create_video_widget $w.frame.video 352 288
-		set size$w 352x288
 	} else {
-		create_video_widget $w.frame.video 320 240
-		set size$w 320x240
-	}
+	   # show the video frame accroding to it's resolution
+	   create_video_widget $w.frame.video $iw $ih
+	   set size$w [format "%sx%s" $iw $ih]
+	}
+	#elseif [isCIF [rtp_format $src]] {
+	#	create_video_widget $w.frame.video 352 288
+	#	set size$w 352x288
+	#} else {
+	#	create_video_widget $w.frame.video 320 240
+	#	set size$w 320x240
+	#}
 	set v $w.frame.video
 
 	frame $w.bar
@@ -287,7 +327,38 @@
 	bind $w <greater> "switcher_next $v"
 	bind $w <less> "switcher_prev $v"
 	bind $w <comma> "switcher_prev $v"
+	# double clicking to toggle fullscreen mode
+	#bind $w <Double-1> {
+	#  destroy_userwin %W
+	#  open_full_window $src	  
+	#}
+	
+	# Resize
+	bind $w <Configure> {	  
+	  global win_src win_target
+
+	  if { [info exists win_src(%W)] & [info exists win_target(%W)]} {
+	    # %W is vw.frame.video
+	    set src $win_src(%W)
+	    
+	    # return Decoder "d" as a PacketHandler
+	    set d [$src handler]
+	    
+	    set iw [$d width]
+	    set ih [$d height]
+
+	    set aspect_r [expr 1.0*$ih / $iw]
+	    
+	    set ow [expr %w + 2*%x]
+	    set oh [expr int($aspect_r * $ow)]
+	
 
+	    if { $iw != $ow || $ih != $oh} {	
+	      # resize_window %W $ow $oh     
+	      # resize %W $ow $oh		       
+	    }    
+	  }	 
+	}		
 	switcher_register $v $src window_switch
 
 	#
@@ -297,6 +368,257 @@
 	windowname $w [getid $src]
 }
 
+
+#
+# create a new window for viewing video
+#
+
+proc open_full_window src {
+	set f [minifont]	
+	set uid [uniqueID]
+	set d [$src handler]
+	set iw [$d width]
+	set ih [$d height]
+
+	if { $iw == 0 || $ih == 0} {
+	   puts "window width or height is zero"
+	   return 
+	}
+
+	set w .vw$uid
+	toplevel $w -class Vic \
+		-visual "[winfo visual .top] [winfo depth .top]" \
+		-colormap .top
+	catch "wm resizable $w true false"	
+	# for bordless window	
+	set sw [winfo screenwidth .]
+	set sh [winfo screenheight .]
+	wm overrideredirect $w true	
+	#wm aspect . 4 3 4 3		
+	
+	frame $w.frame
+
+	#debug_show "open_window $src"
+	global size$w userwin_x userwin_y userwin_size
+	
+	
+	create_video_widget $w.frame.video $sw $sh
+	set size$w [format "%sx%s" $sw $sh]
+	
+	set v $w.frame.video
+
+	#frame $w.bar -height 1
+	frame $w.bar
+	button $w.bar.dismiss -text Dismiss -font $f -width 8 \
+		-highlightthickness 0
+
+	set m $w.bar.mode.menu
+	menubutton $w.bar.mode -text Modes... -menu $m -relief raised \
+		-width 8 -font $f
+	menu $m
+
+	$m add checkbutton -label Voice-switched \
+		-command "window_set_switched $v" \
+		-font $f -variable win_is_switched($v)
+	$m add checkbutton -label Timer-switched \
+		-command "window_set_timed $v" \
+		-font $f -variable win_is_timed($v)
+	$m add checkbutton -label Save-CPU \
+		-command "window_set_slow $v" \
+		-font $f -variable win_is_slow($v)
+
+	if ![have cb] {
+		$m entryconfigure Voice-switched -state disabled
+	}
+
+	set m $w.bar.size.menu
+	#menubutton $w.bar.size -text Size... -menu $m -relief raised -width 8 \
+	#	-font $f -height 0
+	menubutton $w.bar.size -text Size... -menu $m -relief raised -width 8 \
+		-font $f
+
+	menu $m
+	$m add radiobutton -label QCIF -command "resize $v 176 144" \
+		-font $f -value 176x144 -variable size$w
+	$m add radiobutton -label CIF -command "resize $v 352 288" \
+		-font $f -value 352x288 -variable size$w
+	$m add radiobutton -label SCIF -command "resize $v 704 576" \
+		-font $f -value 704x576 -variable size$w
+
+	$m add separator
+	$m add radiobutton -label "1/16 NTSC" \
+		-command "resize $v 160 120" \
+		-font $f -value 160x120 -variable size$w
+	$m add radiobutton -label "1/4 NTSC" \
+		-command "resize $v 320 240" \
+		-font $f -value 320x240 -variable size$w
+	$m add radiobutton -label NTSC \
+		-command "resize $v 640 480" \
+		-font $f -value 640x480 -variable size$w
+
+	$m add separator
+	$m add radiobutton -label "1/16 PAL" \
+		-command "resize $v 192 144" \
+		-font $f -value 192x144 -variable size$w
+	$m add radiobutton -label "1/4 PAL" \
+		-command "resize $v 384 288" \
+		-font $f -value 384x288 -variable size$w
+	$m add radiobutton -label PAL \
+		-command "resize $v 768 576" \
+		-font $f -value 768x576 -variable size$w
+
+
+# Marcus ... 
+	set m $w.bar.decoder.menu
+	menubutton $w.bar.decoder -text Decoder... -menu $m -relief raised -width 8 -font $f
+	menu $m
+	$m add radiobutton -label Use-Magic \
+		-command "reallocate_renderer $v" \
+		-font $f -variable win_use_hw($v) -value magic
+	
+	global assistorlist
+
+	if ![info exists assistorlist]  {
+		set assistorlist [new assistorlist xx]
+	}
+	set d [$src handler]
+	set fmt [rtp_format $src]
+	if { $fmt == "jpeg" } {
+		set fmt $fmt/[$d decimation]
+	}
+	set targets [$assistorlist assistors $fmt]
+	foreach xname $targets {
+		if { $xname != "" } {
+			$m add radiobutton -label "Use-$xname-Assistor" \
+				-command "reallocate_renderer $v" \
+				-font $f -variable win_use_hw($v) -value $xname
+		}
+	}
+
+	$m add radiobutton -label "Use-VIC Software" \
+		-command "reallocate_renderer $v" \
+		-font $f -variable win_use_hw($v) -value software
+
+# ... Marcus
+
+	label $w.bar.label -text "" -anchor w -relief raised
+	# pack $w.bar.label -expand 1 -side left -fill both
+	# comment next line to remove buttons
+	# pack $w.bar.decoder $w.bar.size $w.bar.mode $w.bar.dismiss -side left -fill y
+
+	pack $w.frame.video -anchor c
+	pack $w.frame -expand 1 -fill both
+	# comment next line to remove buttons
+	# pack $w.bar -fill x
+
+	bind $w <Enter> { focus %W }
+	#wm focusmodel $w active
+
+	bind $w <d> "destroy_userwin $v"
+	bind $w <q> "destroy_userwin $v"
+#	bind $w <Destroy> "destroy_from_wm $v"
+	wm protocol $w WM_DELETE_WINDOW "destroy_userwin $v"
+	$w.bar.dismiss configure -command "destroy_userwin $v"
+
+	bind $w <Return> "switcher_next $v"
+	bind $w <space> "switcher_next $v"
+	bind $w <greater> "switcher_next $v"
+	bind $w <less> "switcher_prev $v"
+	bind $w <comma> "switcher_prev $v"
+
+	#bind $w <g> "set_window_glue $v 1"
+	#bind $w <G> "set_window_glue $v 0"
+	bind $w <h> "set_hardware_render $v 1"
+	bind $w <H> "set_hardware_render $v 0"
+	bind $w <H> "set_hardware_render $v 0"
+	bind $w <Double-1> {	  	
+	  destroy_userwin %W true
+	  open_window $src	  
+	}
+		
+	
+	switcher_register $v $src window_switch
+
+	global window_glue
+	set window_glue($v) 0
+	global button_active vtk_client
+
+	bind $v <Button-3> {
+	    tk_popup $m %x %y
+	}
+
+#	puts "w is $v"
+
+	bind $v <Control-KeyPress> {
+#	    puts "got ctl keypress %K %x %y"
+	    if { [string length %K] == 1 } {
+		binary scan %K c keyval
+		send_to_vtk K 0 $keyval %x %y %W
+		break
+	    }
+	}
+	bind $v <Button> {
+	    global notifier_id ag_last_x ag_last_y
+
+	    send_to_vtk D 0 %b %x %y %W
+
+	    set button_active %b
+	    set modifier 0
+
+	    set ag_last_x %x
+	    set ag_last_y %y
+
+	    set notifier_id [after 100 ag_update_motion]
+	}
+	bind $v <Control-Button> {
+	    global notifier_id
+	    send_to_vtk D 0 [expr %b | 8] %x %y %W
+
+	    set button_active %b
+	    set notifier_id [after 100 ag_update_motion]
+	}
+	bind $v <Shift-Button> {
+	    global notifier_id
+	    send_to_vtk D 0 [expr %b | 16] %x %y %W
+
+	    set button_active %b
+	    set notifier_id [after 100 ag_update_motion]
+	}
+	bind $v <Shift-Control-Button> {
+	    global notifier_id
+	    send_to_vtk D 0 [expr %b | 8 | 16] %x %y %W
+
+	    set button_active %b
+	    set notifier_id [after 100 ag_update_motion]
+	}
+
+	bind $v <ButtonRelease> {
+	    if $button_active {
+		global notifier_id
+		set button_active 0
+		after cancel $notifier_id
+		send_to_vtk U 0 %b %x %y %W
+	    }
+	}
+	bind $v <Motion> {
+	    if $button_active {
+		global ag_motion_x ag_motion_y ag_motion_W
+#		send_to_vtk M 0 $button_active %x %y %W
+		set ag_motion_x %x
+		set ag_motion_y %y
+		set ag_motion_W %W
+	    }
+	}
+	
+	#
+	# Finally, bind the source to the window.
+	#	
+	# the last parameter indicates whether using Xvideo or not
+	attach_window $src $v true
+	windowname $w [getid $src]
+
+}
+
 proc windowname { w name } {
 	if ![yesno suppressUserName] {
 		$w.bar.label configure -text $name

Modified: vic/branches/mpeg4/video/grabber-video4linux.cpp
==============================================================================
--- vic/branches/mpeg4/video/grabber-video4linux.cpp	(original)
+++ vic/branches/mpeg4/video/grabber-video4linux.cpp	Thu Oct  5 09:45:33 2006
@@ -945,8 +945,13 @@
     struct video_channel channel;
     debug_msg("V4l: format\n");
 
-    width_ = CIF_WIDTH * 2 / decimate_;
-    height_ = CIF_HEIGHT * 2 / decimate_;
+    if(decimate_!=1){
+   		width_ = CIF_WIDTH * 2 / decimate_;
+    	height_ = CIF_HEIGHT * 2 / decimate_;
+	}else{
+		width_  = capability.maxwidth;
+		height_ = capability.maxheight;
+	}
 
     // FIXED by barz 2006/9/19:  YUV422 is default
     if (have_420P)

Modified: vic/branches/mpeg4/video/grabber.cpp
==============================================================================
--- vic/branches/mpeg4/video/grabber.cpp	(original)
+++ vic/branches/mpeg4/video/grabber.cpp	Thu Oct  5 09:45:33 2006
@@ -455,6 +455,12 @@
 
 	int ispal;
 	switch (w) {
+	case 640:
+		/* for qcam */
+		ispal = 0;
+		outw_ = 640;
+		outh_ = 480;
+		break;
 	case 320:
 		/* 1/2 NTSC */
 		ispal = 0;

Modified: vic/branches/mpeg4/video/grabber.h
==============================================================================
--- vic/branches/mpeg4/video/grabber.h	(original)
+++ vic/branches/mpeg4/video/grabber.h	Thu Oct  5 09:45:33 2006
@@ -40,6 +40,12 @@
 #include "media-timer.h"
 #include "vic_tcl.h"
 
+#ifdef USE_FASTMEMCPY
+extern "C" {
+#include "postproc/fastmemcpy.h"
+}
+#endif
+
 class Module;
 class Transmitter;
 



More information about the Sumover-dev mailing list