[Sumover-dev] [svn commit] r3879 - vic/trunk/video

sumover-dev at cs.ucl.ac.uk sumover-dev at cs.ucl.ac.uk
Wed Sep 20 13:52:16 BST 2006


Author: barz
Date: Wed Sep 20 13:51:29 2006
New Revision: 3879

Modified:
   vic/trunk/video/grabber-video4linux.cpp

Log:
Fix BTTV and Qcam palette problem
Put palette detection code later after initializing video channel in case there are multiple channels.
In V4lGrabber::V4lGrabber, local "capability" variable should not hide V4lGrabber memeber variable "capability."
Reformat the code by indent with option "-i4 -npsl -di0 -br -nce -d0 -cli0 -npcs -nfc1"

Barz



Modified: vic/trunk/video/grabber-video4linux.cpp
==============================================================================
--- vic/trunk/video/grabber-video4linux.cpp	(original)
+++ vic/trunk/video/grabber-video4linux.cpp	Wed Sep 20 13:51:29 2006
@@ -3,6 +3,9 @@
      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>
 
@@ -25,7 +28,7 @@
 #include <errno.h>
 
 #include <sys/types.h>
-#include <sys/fcntl.h>  
+#include <sys/fcntl.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
 #include <sys/mman.h>
@@ -35,7 +38,8 @@
 #include <X11/keysym.h>
 
 
-extern "C" {
+extern "C"
+{
 #include <asm/types.h>
 //#include <linux/videodev.h>
 }
@@ -62,7 +66,7 @@
 #define CIF_HEIGHT  288
 
 /* pass 0/1 by reference */
-static const int  one = 1, zero = 0;
+static const int one = 1, zero = 0;
 
 #define CF_422 0
 #define CF_411 1
@@ -78,40 +82,42 @@
 /* VIDEO NORMS */
 #define MAX_NORMS 4
 
-class V4lGrabber : public Grabber {
-public:
-    V4lGrabber(const char * cformat, const char *dev);
-    virtual ~V4lGrabber();
+class V4lGrabber:public Grabber
+{
+  public:
+    V4lGrabber(const char *cformat, const char *dev);
+         virtual ~ V4lGrabber();
 
-    virtual int  command(int argc, const char*const* argv);
+    virtual int command(int argc, const char *const *argv);
     virtual void start();
     virtual void stop();
-    virtual int  grab();
+    virtual int grab();
 
 
-protected:
+  protected:
     void format();
     void setsize();
 
-    void packed422_to_planar422(char *, char*);
-    void packed422_to_planar411(char *, char*);
+    void packed422_to_planar422(char *, char *);
+    void packed422_to_planar411(char *, char *);
     void vcvt_420p_422p(int width, int height, void *src, void *dst);
     void vcvt_420p_411p(int width, int height, void *src, void *dst);
-    void vcvt_420i_yuyv(int width, int height, int plus, void *src, void *dst);
+    void vcvt_420i_yuyv(int width, int height, int plus, void *src,
+			void *dst);
 
-    struct video_capability  capability;
-    struct video_channel     *channels;
-    struct video_picture     pict;
-    struct video_window      win;
+    struct video_capability capability;
+    struct video_channel *channels;
+    struct video_picture pict;
+    struct video_window win;
 
     /* mmap */
-    int                      have_mmap;
-    int                      grab_count;
-    int                      sync_count;
-    struct video_mmap        gb_even;
-    struct video_mmap        gb_odd;
-    struct video_mbuf        gb_buffers;
-    char                     *mem;
+    int have_mmap;
+    int grab_count;
+    int sync_count;
+    struct video_mmap gb_even;
+    struct video_mmap gb_odd;
+    struct video_mbuf gb_buffers;
+    char *mem;
 
     int fd_;
     int format_;
@@ -123,7 +129,7 @@
     int cformat_;
     int port_;
     int norm_;
-    
+
     unsigned char *tm_;
     int width_;
     int height_;
@@ -134,46 +140,47 @@
 
 /* ----------------------------------------------------------------- */
 
-class V4lDevice : public InputDevice {
-public:
-    V4lDevice(const char *dev, const char*, char *attr);
-    virtual int command(int argc, const char*const* argv);
+class V4lDevice:public InputDevice
+{
+  public:
+    V4lDevice(const char *dev, const char *, char *attr);
+    virtual int command(int argc, const char *const *argv);
 
-private:
+  private:
     const char *dev_;
 };
 
 
-V4lDevice::V4lDevice(const char *dev, const char *name, char *attr) : InputDevice(name)
+V4lDevice::V4lDevice(const char *dev, const char *name,
+		     char *attr):InputDevice(name)
 {
     dev_ = dev;
     attributes_ = attr;
-    debug_msg("V4l:  ==> %s\n",attr);
+    debug_msg("V4l:  ==> %s\n", attr);
 }
 
-int V4lDevice::command(int argc, const char*const* argv)
+int V4lDevice::command(int argc, const char *const *argv)
 {
-    Tcl& tcl = Tcl::instance();
+    Tcl & tcl = Tcl::instance();
 
 
     if (argc == 3) {
 	if (strcmp(argv[1], "open") == 0) {
-	    TclObject* o = 0;
-	    o = new V4lGrabber(argv[2],dev_);
+	    TclObject *o = 0;
+	    o = new V4lGrabber(argv[2], dev_);
 	    if (o != 0)
 		tcl.result(o->name());
 	    return (TCL_OK);
 	}
-
-
     }
     return (InputDevice::command(argc, argv));
 }
 
 /* ----------------------------------------------------------------- */
 
-class V4lScanner {
-public:
+class V4lScanner
+{
+  public:
     V4lScanner(const char **dev);
 };
 
@@ -182,23 +189,25 @@
 V4lScanner::V4lScanner(const char **dev)
 {
     static const char *palette_name[] = {
-	"", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15", 
-	"yuv422", "yuyv422", "uyvy422", "yuv420", "yuv411", "RAW", "yuv422P", "yuv411P", "yuv420P", "yuv410P" };
-    
-    struct video_capability  capability;
-    struct video_channel     channel;
-    struct video_picture     pict;
-    unsigned int  	j;
-    int			i,fd;
-    char		*nick, *attr;
+	"", "grey", "hi240", "rgb16", "rgb24", "rgb32", "rgb15",
+	"yuv422", "yuyv422", "uyvy422", "yuv420", "yuv411", "RAW", "yuv422P",
+	    "yuv411P", "yuv420P", "yuv410P"
+    };
+
+    struct video_capability capability;
+    struct video_channel channel;
+    struct video_picture pict;
+    unsigned int j;
+    int i, fd;
+    char *nick, *attr;
 
     for (i = 0; dev[i] != NULL; i++) {
-	debug_msg("V4l: trying %s... ",dev[i]);
-	if (-1 == (fd = open(dev[i],O_RDONLY))) {
-	    debug_msg("Error opening: %s : %s",dev[i], strerror(errno)); //SV-XXX: sys_errlist deprecated, use strerror()
+	debug_msg("V4l: trying %s... ", dev[i]);
+	if (-1 == (fd = open(dev[i], O_RDONLY))) {
+	    debug_msg("Error opening: %s : %s", dev[i], strerror(errno));	//SV-XXX: sys_errlist deprecated, use strerror()
 	    continue;
 	}
-	if (-1 == ioctl(fd,VIDIOCGCAP,&capability)) {
+	if (-1 == ioctl(fd, VIDIOCGCAP, &capability)) {
 	    perror("ioctl VIDIOCGCAP");
 	    close(fd);
 	    continue;
@@ -211,50 +220,52 @@
 	}
 
 	debug_msg("ok, %s\nV4l:   %s; size: %dx%d => %dx%d%s\n",
-		capability.name,
-		capability.type & VID_TYPE_MONOCHROME ? "mono" : "color",
-		capability.minwidth,capability.minheight,
-		capability.maxwidth,capability.maxheight,
-		capability.type & VID_TYPE_SCALES ? " (scales)" : "");
+		  capability.name,
+		  capability.type & VID_TYPE_MONOCHROME ? "mono" : "color",
+		  capability.minwidth, capability.minheight,
+		  capability.maxwidth, capability.maxheight,
+		  capability.type & VID_TYPE_SCALES ? " (scales)" : "");
 
 	attr = new char[512];
-	strcpy(attr,"format { 411 422 cif } ");
+	strcpy(attr, "format { 411 422 cif } ");
 
-        if (capability.maxwidth  > PAL_WIDTH/2 &&
-	    capability.maxheight > PAL_HEIGHT/2) {
-	    strcat(attr,"size { small large cif } ");
-	} else {
-	    strcat(attr,"size { small cif } ");
+	if (capability.maxwidth > PAL_WIDTH / 2 &&
+	    capability.maxheight > PAL_HEIGHT / 2) {
+	    strcat(attr, "size { small large cif } ");
+	}
+	else {
+	    strcat(attr, "size { small cif } ");
 	}
-	
+
 	debug_msg("V4l:   ports:");
-	strcat(attr,"port { ");
+	strcat(attr, "port { ");
 	for (j = 0; j < capability.channels; j++) {
 	    channel.channel = j;
-	    if (-1 == ioctl(fd,VIDIOCGCHAN,&channel)) {
+	    if (-1 == ioctl(fd, VIDIOCGCHAN, &channel)) {
 		perror("ioctl VIDIOCGCHAN");
-	    } else {
-		debug_msg(" %s",channel.name);
-		strcat(attr,channel.name);
-		strcat(attr," ");
+	    }
+	    else {
+		debug_msg(" %s", channel.name);
+		strcat(attr, channel.name);
+		strcat(attr, " ");
 	    }
 	}
 	debug_msg("\n");
-	strcat(attr,"} ");
+	strcat(attr, "} ");
 
-	if (-1 == ioctl(fd,VIDIOCGPICT,&pict)) {
+	if (-1 == ioctl(fd, VIDIOCGPICT, &pict)) {
 	    perror("ioctl VIDIOCGPICT");
 	}
-	debug_msg("V4l:   depth=%d, palette=%s\n",
-		pict.depth,(pict.palette<sizeof(palette_name)/sizeof(char*))?
-		palette_name[pict.palette]:"??");
-
-	strcat(attr,"type {auto pal ntsc secam}");
-
-	nick = new char[strlen(capability.name)+7];
-	sprintf(nick,"V4L1:%s",capability.name);
-	new V4lDevice(dev[i],nick,attr);
-        fprintf(stderr,"Attached to V4l device: %s\n",nick);
+	debug_msg("V4l:   depth=%d, palette=%s\n",  pict.depth,
+		  (pict.palette < sizeof(palette_name) / sizeof(char *))? 
+		  palette_name[pict.palette] : "??");
+
+	strcat(attr, "type {auto pal ntsc secam}");
+
+	nick = new char[strlen(capability.name) + 7];
+	sprintf(nick, "V4L1:%s", capability.name);
+	new V4lDevice(dev[i], nick, attr);
+	fprintf(stderr, "Attached to V4l device: %s\n", nick);
 
 	close(fd);
     }
@@ -264,151 +275,127 @@
 
 V4lGrabber::V4lGrabber(const char *cformat, const char *dev)
 {
-    unsigned int i=0;
-    struct video_mmap 	     vid_mmap;
+    unsigned int i = 0;
+    struct video_mmap vid_mmap;
+
+    // COMMENTED by barz 2006/9/19: should not overwrite protected member variable capability
+    // struct video_capability  capability;
 
-    struct video_capability  capability;
     /* Taken from MASH - need to update code using this approach
      * which checks for palettes with multiple resolutions
-     * Helps various Webcams...
+     * Helps various Webcams... */
+    /*
     int palettes[] = {
-        VIDEO_PALETTE_YUV422,   // BT878 (OS driver broken, so listed first)
-        VIDEO_PALETTE_YUV422P,  // BT878 (untested)
-        VIDEO_PALETTE_YUV420P,  // (untested)
-        VIDEO_PALETTE_UYVY,     // LML33
-        VIDEO_PALETTE_YUYV      // others listed in order of preference
-    };*/
-
+	VIDEO_PALETTE_YUV422,	// BT878 (OS driver broken, so listed first)
+	VIDEO_PALETTE_YUV422P,	// BT878 (untested)
+	VIDEO_PALETTE_YUV420P,	// (untested)
+	VIDEO_PALETTE_UYVY,	// LML33
+	VIDEO_PALETTE_YUYV	// others listed in order of preference
+    };
+    */
+    
     have_mmap = 0;
     have_422P = 0;
-    have_422  = 0;
+    have_422 = 0;
     have_420P = 0;
-
+    
+    port_ = 0;
+    norm_ = 0;
+    decimate_ = 2;
+    
     debug_msg("Videodev: %s\n", dev);
     debug_msg("Cformat: %s\n", cformat);
     fd_ = open(dev, O_RDWR);
+
     if (fd_ < 0) {
 	printf("on: %d\n", fd_);
 	perror("open");
-        status_=-1;
-	return;
-    }
-    if (-1 == ioctl (fd_, VIDIOCGCAP, &capability)) {
-            perror ("ioctl VIDIOCGCAP");
-            close (fd_);
-        status_=-1;
+	status_ = -1;
 	return;
     }
-      printf("dssssddDevice capture VIDEO_PALETTE_YUV420P\n");
-
-    vid_mmap.format = VIDEO_PALETTE_YUV420P;
-    vid_mmap.frame = 0;
-    vid_mmap.width = PAL_WIDTH;
-    vid_mmap.height = PAL_HEIGHT;
-    
-    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
-      have_422P = 0;
-      have_422 = 0;
-      have_420P = 1;
-      printf("Device capture VIDEO_PALETTE_YUV420P\n");
-    } else {
-	vid_mmap.width = capability.maxwidth;
-        vid_mmap.height = capability.maxheight;
-	if (-1 != ioctl (fd_, VIDIOCMCAPTURE, &vid_mmap)) {
-                    have_422P = 1;
-                    //v4lformat_ = palettes[i];
-                    width_ = capability.maxwidth;
-                    height_ = capability.maxheight;
-                    debug_msg("V4l: format index #%d of size %d x %d\n", 
-					      i, width_, height_);
-                } else {
-                    debug_msg("V4l: 2nd mmap failed\n");
-    		}
-    }
-
-    vid_mmap.format = VIDEO_PALETTE_YUV422;
-    vid_mmap.frame = 0;
-    vid_mmap.width = PAL_WIDTH;
-    vid_mmap.height = PAL_HEIGHT;
-    
-    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
-      have_422P = 0;
-      have_422 = 1;
-      printf("Device capture VIDEO_PALETTE_YUV422\n");
-    }
-
-    vid_mmap.format = VIDEO_PALETTE_YUV422P;
-    vid_mmap.frame = 0;
-    vid_mmap.width = PAL_WIDTH;
-    vid_mmap.height = PAL_HEIGHT;
-
-    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
-           have_422P = 1;
-	   printf("Device capture VIDEO_PALETTE_YUV422P\n");
-    }
 
-    if( !( have_422P || have_422 || have_420P))   {
-      debug_msg("No suituable palette found\n");
-      close(fd_);
-      status_=-1;
-      return;
-    }
-
-    /* Release device *
-    close(fd_);
-
-    fd_ = open(dev, O_RDWR);
-    if (fd_ < 0) {
-	perror("open");
-	exit(1);
+    if (-1 == ioctl(fd_, VIDIOCGCAP, &capability)) {
+	perror("ioctl VIDIOCGCAP");
+	close(fd_);
+	status_ = -1;
+	return;
     }
-    * ask for capabilities */
-    if (-1 == ioctl(fd_,VIDIOCGCAP,&capability)) {
+       
+    /* ask for capabilities */
+    if (-1 == ioctl(fd_, VIDIOCGCAP, &capability)) {
 	perror("ioctl VIDIOCGCAP");
-        status_=-1;
-      return;
+	status_ = -1;
+	return;
     }
-    channels = (struct video_channel*)
-    calloc(capability.channels,sizeof(struct video_channel));
+    channels = (struct video_channel *)
+	calloc(capability.channels, sizeof(struct video_channel));
     for (i = 0; i < capability.channels; i++) {
 	channels[i].channel = i;
-	if (-1 == ioctl(fd_,VIDIOCGCHAN,&channels[i])) {
+	if (-1 == ioctl(fd_, VIDIOCGCHAN, &channels[i])) {
 	    perror("ioctl VIDIOCGCHAN");
 	}
     }
-    if (-1 == ioctl(fd_,VIDIOCGPICT,&pict)) {
+    if (-1 == ioctl(fd_, VIDIOCGPICT, &pict)) {
 	perror("ioctl VIDIOCGPICT");
     }
 
     /* map grab buffer */
-    gb_buffers.size = 2*0x151000;
+    gb_buffers.size = 2 * 0x151000;
     gb_buffers.offsets[0] = 0;
     gb_buffers.offsets[1] = 0x151000;
-    if (-1 == ioctl(fd_,VIDIOCGMBUF,&gb_buffers)) {
+    if (-1 == ioctl(fd_, VIDIOCGMBUF, &gb_buffers)) {
 	perror("ioctl VIDIOCGMBUF");
     }
-    mem = (char *)mmap(0,gb_buffers.size,PROT_READ|PROT_WRITE,MAP_SHARED,fd_,0);
+    mem =
+	(char *) mmap(0, gb_buffers.size, PROT_READ | PROT_WRITE, MAP_SHARED,
+		      fd_, 0);
 
-    if ((char*)-1 == mem) {
+    if ((char *) -1 == mem) {
 	perror("mmap");
 	debug_msg("V4l: device has no mmap support\n");
-    } else {
-	debug_msg("v4l: mmap()'ed buffer size = 0x%x\n",
-		gb_buffers.size);
+    }
+    else {
+	debug_msg("v4l: mmap()'ed buffer size = 0x%x\n", gb_buffers.size);
 	have_mmap = 1;
     }
- 
+
+    vid_mmap.frame = 0;
+    vid_mmap.width = CIF_WIDTH;
+    vid_mmap.height = CIF_HEIGHT;
+    
+    vid_mmap.format = VIDEO_PALETTE_YUV422P;    
+    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
+	have_422P = 1;
+	debug_msg("Device capture VIDEO_PALETTE_YUV422P\n");
+    }
+
+    vid_mmap.format = VIDEO_PALETTE_YUV420P;
+    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
+	have_420P = 1;
+	debug_msg("Device capture VIDEO_PALETTE_YUV420P\n");
+    }
+
+
+    vid_mmap.format = VIDEO_PALETTE_YUV422;
+    if (-1 != ioctl(fd_, VIDIOCMCAPTURE, &vid_mmap)) {
+	have_422 = 1;
+	debug_msg("Device capture VIDEO_PALETTE_YUV422\n");
+    }
+
+    if( !( have_422P || have_422 || have_420P)){
+      debug_msg("No suituable palette found\n");
+      close(fd_);
+      status_=-1;
+      return;
+    }
+
     /* fill in defaults */
-    if(!strcmp(cformat, "411"))
+    if (!strcmp(cformat, "411"))
 	cformat_ = CF_411;
-    if(!strcmp(cformat, "422"))
+    if (!strcmp(cformat, "422"))
 	cformat_ = CF_422;
-    if(!strcmp(cformat, "cif"))
+    if (!strcmp(cformat, "cif"))
 	cformat_ = CF_CIF;
-    
-    port_      = 0;
-    norm_      = 0;
-    decimate_  = 2;
 }
 
 V4lGrabber::~V4lGrabber()
@@ -416,24 +403,25 @@
     debug_msg("V4l: destructor\n");
 
     if (have_mmap)
-	munmap(mem,gb_buffers.size);
+	munmap(mem, gb_buffers.size);
     close(fd_);
 }
 
-int V4lGrabber::command(int argc, const char*const* argv)
+int V4lGrabber::command(int argc, const char *const *argv)
 {
     unsigned int i;
     //struct video_channel     channel;
     //static const char *norms[] = {"pal", "ntsc", "secam", "auto"};
 
-    Tcl &tcl = Tcl::instance();
+    Tcl & tcl = Tcl::instance();
 
     byteorder_ = 0;
 
-    if ( tcl.attr("yuv_byteOrder") != NULL ) 
-	byteorder_ = atoi( tcl.attr("yuv_byteOrder") );
+    if (tcl.attr("yuv_byteOrder") != NULL)
+	byteorder_ = atoi(tcl.attr("yuv_byteOrder"));
 
-    if ( ! ((byteorder_ >= 0) && (byteorder_ <= 3)) ) byteorder_=0;
+    if (!((byteorder_ >= 0) && (byteorder_ <= 3)))
+	byteorder_ = 0;
 
     if (argc == 3) {
 	if (strcmp(argv[1], "decimate") == 0) {
@@ -444,105 +432,105 @@
 
 	if (strcmp(argv[1], "port") == 0) {
 	    for (i = 0; i < capability.channels; i++)
-		if(!strcmp(argv[2], channels[i].name)) {
+		if (!strcmp(argv[2], channels[i].name)) {
 		    port_ = i;
-	    }
+		    break;
+		}
 	    if (running_)
 		format();
-    	    return (TCL_OK);
+	    return (TCL_OK);
 	}
 
+	if (strcmp(argv[1], "brightness") == 0) {
+	    u_char val = atoi(argv[2]);
 
-        if (strcmp(argv[1], "brightness") == 0) {
-                        u_char val = atoi(argv[2]);
-		
-			pict.brightness=val*256;
-			
-    			if (-1 == ioctl(fd_,VIDIOCSPICT,&pict))
-        		perror("ioctl VIDIOCSPICT");
+	    pict.brightness = val * 256;
 
-                        debug_msg( "V4l: Brightness = %d\n", val);
-                        return (TCL_OK);
-        }
+	    if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+		perror("ioctl VIDIOCSPICT");
 
-        if (strcmp(argv[1], "contrast") == 0) {
-                        u_char val = atoi(argv[2]);
-			
-			pict.contrast=val*256;
+	    debug_msg("V4l: Brightness = %d\n", val);
+	    return (TCL_OK);
+	}
+
+	if (strcmp(argv[1], "contrast") == 0) {
+	    u_char val = atoi(argv[2]);
+
+	    pict.contrast = val * 256;
+
+	    if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+		perror("ioctl VIDIOCSPICT");
 
-    			if (-1 == ioctl(fd_,VIDIOCSPICT,&pict))
-        		perror("ioctl VIDIOCSPICT");
+	    debug_msg("V4l: Contrast = %d\n", val);
+	    return (TCL_OK);
+	}
 
-                        debug_msg( "V4l: Contrast = %d\n", val);
-                        return (TCL_OK);
-        }
+	if (strcmp(argv[1], "hue") == 0) {
+	    u_char val = atoi(argv[2]);
 
-        if (strcmp(argv[1], "hue") == 0) {
-                        u_char val = atoi(argv[2]);
-			
-			pict.hue=val*256;
+	    pict.hue = val * 256;
 
-    			if (-1 == ioctl(fd_,VIDIOCSPICT,&pict))
-        		perror("ioctl VIDIOCSPICT");
+	    if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+		perror("ioctl VIDIOCSPICT");
 
-                        debug_msg( "V4l: Hue = %d\n", val);
-                        return (TCL_OK);
-        }
+	    debug_msg("V4l: Hue = %d\n", val);
+	    return (TCL_OK);
+	}
 
-        if (strcmp(argv[1], "saturation") == 0) {
-                        u_char val = atoi(argv[2]);
+	if (strcmp(argv[1], "saturation") == 0) {
+	    u_char val = atoi(argv[2]);
 
-                        pict.colour=val*256;
+	    pict.colour = val * 256;
 
-    			if (-1 == ioctl(fd_,VIDIOCSPICT,&pict))
-        		perror("ioctl VIDIOCSPICT");
+	    if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+		perror("ioctl VIDIOCSPICT");
 
-                        debug_msg( "V4l: Saturation = %d\n", val);
-                        return (TCL_OK);
-        }
+	    debug_msg("V4l: Saturation = %d\n", val);
+	    return (TCL_OK);
+	}
 
 	if (strcmp(argv[1], "controls") == 0) {
-		if (strcmp(argv[2], "reset") == 0) {
+	    if (strcmp(argv[2], "reset") == 0) {
 
-			pict.brightness=32768;
-			pict.contrast=32768;
-			pict.colour=32768;
-			pict.hue=32768;
+		pict.brightness = 32768;
+		pict.contrast = 32768;
+		pict.colour = 32768;
+		pict.hue = 32768;
 
-                        if (-1 == ioctl(fd_,VIDIOCSPICT,&pict))
-                        perror("ioctl VIDIOCSPICT");
+		if (-1 == ioctl(fd_, VIDIOCSPICT, &pict))
+		    perror("ioctl VIDIOCSPICT");
 
-                        debug_msg( "V4l: Resetting controls\n");
-                        return (TCL_OK);
-		}
-        }
+		debug_msg("V4l: Resetting controls\n");
+		return (TCL_OK);
+	    }
+	}
 
-        if (strcmp(argv[1], "yuv_byteorder") == 0) {
-                        byteorder_ = atoi(argv[2]);
-                        return (TCL_OK);
-        }
+	if (strcmp(argv[1], "yuv_byteorder") == 0) {
+	    byteorder_ = atoi(argv[2]);
+	    return (TCL_OK);
+	}
 
 
 	if (strcmp(argv[1], "fps") == 0) {
-	    debug_msg("V4l: fps %s\n",argv[2]);
+	    debug_msg("V4l: fps %s\n", argv[2]);
 	}
 
 
-        if (strcmp(argv[1], "type") == 0) {
-                        if (strcmp(argv[2], "auto") == 0)
-                                norm_ = VIDEO_MODE_AUTO;
-                        else if (strcmp(argv[2], "pal") == 0)
-                                norm_ = VIDEO_MODE_PAL;
-                        else if (strcmp(argv[2], "secam") == 0)
-                                norm_ = VIDEO_MODE_SECAM;
-                        else
-                                norm_ = VIDEO_MODE_NTSC;
-                        if (running_)
-                                format();
-                        return (TCL_OK);
-                }
-    
-    } 
+	if (strcmp(argv[1], "type") == 0) {
+	    if (strcmp(argv[2], "auto") == 0)
+		norm_ = VIDEO_MODE_AUTO;
+	    else if (strcmp(argv[2], "pal") == 0)
+		norm_ = VIDEO_MODE_PAL;
+	    else if (strcmp(argv[2], "secam") == 0)
+		norm_ = VIDEO_MODE_SECAM;
+	    else
+		norm_ = VIDEO_MODE_NTSC;
+	    if (running_)
+		format();
+	    return (TCL_OK);
+	}
+
+    }
 
     return (Grabber::command(argc, argv));
 }
@@ -557,17 +545,20 @@
 	grab_count = 0;
 	sync_count = 0;
 
-	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_even))
-	    perror("ioctl VIDIOCMCAPTURE even");
+	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_odd))
+	    perror("ioctl VIDIOCMCAPTURE odd");
 	else
 	    grab_count++;
 
-	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_odd))
-	    perror("ioctl VIDIOCMCAPTURE odd");
+
+	// COMMENTED by barz 2006/9/19: not grab immediately after grabing         
+/*
+	if (-1 == ioctl(fd_, VIDIOCMCAPTURE, &gb_even))
+	    perror("ioctl VIDIOCMCAPTURE even");
 	else
 	    grab_count++;
+*/
     }
-    
     Grabber::start();
 }
 
@@ -577,68 +568,87 @@
 
     if (have_mmap) {
 	while (grab_count > sync_count) {
-	    if (-1 == ioctl(fd_, VIDIOCSYNC, (sync_count%2) ? &one:&zero)) {
+	    if (-1 == ioctl(fd_, VIDIOCSYNC, (sync_count % 2) ? &one : &zero)) {
 		perror("ioctl VIDIOCSYNC");
 		break;
-	    } else
+	    }
+	    else
 		sync_count++;
 	}
     }
-    
+
     Grabber::stop();
 }
 
 int V4lGrabber::grab()
 {
-    char  *fr=NULL;
+    char *fr = NULL;
 
-    debug_msg((sync_count % 2) ? "o" : "e");
+    // debug_msg((sync_count % 2) ? "o" : "e");
 
     if (have_mmap) {
-	fr = mem + (gb_buffers.offsets[ (sync_count % 2) ? 1: 0]);
-	if (-1 == ioctl(fd_, VIDIOCSYNC, (sync_count%2) ? &one:&zero)){
+	fr = mem + (gb_buffers.offsets[(sync_count % 2) ? 1 : 0]);
+
+	if (-1 == ioctl(fd_, VIDIOCSYNC, (sync_count % 2) ? &one : &zero) < 0) {
 	    perror("ioctl VIDIOCSYNC");
-	    printf("Syncerror SyncCount %d\n",sync_count);
+	    printf("Syncerror SyncCount %d\n", sync_count);
 	}
-	else
+	else {
 	    sync_count++;
-    } else {
+	}
+    }
+    else {
 	/* FIXME: read() */
     }
 
-
     switch (cformat_) {
     case CF_411:
-
     case CF_CIF:
-      if (have_422)         
-	packed422_to_planar411((char*)frame_,fr);
-      else {
-	//  have_420P 
-	// vcvt_420p_411p(width_, height_, (char *)fr, frame_);  
-	// erwartet wird scheinbar 420P und nicht 411P  *wunder* 
-	memcpy((void *)frame_, (const void *)fr, (size_t)height_*width_*3/2);
-      }
-      break;
+/*		    
+	if (have_422)         
+	    packed422_to_planar411((char*)frame_,fr);
+	else {
+	   //  have_420P 
+	   // vcvt_420p_411p(width_, height_, (char *)fr, frame_);  
+	   // erwartet wird scheinbar 420P und nicht 411P  *wunder* 
+	   memcpy((void *)frame_, (const void *)fr, (size_t)height_*width_*3/2);
+	}
+	break;						
+	*/
+
+	//  barz: bttv using packed422_to_planar411
+	if (have_420P)
+	    memcpy((void *) frame_, (const void *) fr,
+		   (size_t) height_ * width_ * 3 / 2);
+	else
+	    packed422_to_planar411((char *) frame_, fr);
+	break;
 
     case CF_422:
-      if (have_422P) 
-	memcpy((void *)frame_, (const void *)fr, (size_t)height_*width_*2);
-      else if ( have_422 ) {
-	packed422_to_planar422((char*)frame_,fr);
-      }  else {
-	//  have_420P 
-	vcvt_420p_422p(width_, height_, (char *)fr, frame_);  
-      }
-      break;
-    }
-
-    if (have_mmap) {
-	if (-1 == ioctl(fd_, VIDIOCMCAPTURE,
-			(grab_count % 2) ? &gb_odd : &gb_even))
-	    perror("ioctl VIDIOMCAPTURE");
-	else
-	    grab_count++;
+	if (have_422P)
+	    memcpy((void *) frame_, (const void *) fr,
+		   (size_t) height_ * width_ * 2);
+	else if (have_422) {
+	    packed422_to_planar422((char *) frame_, fr);
+	}
+	else {
+	    //  have_420P 
+	    vcvt_420p_422p(width_, height_, (char *) fr, frame_);
+	}
+	break;
+    }
+
+    // FIXED by barz 2006/9/19: not grab immediately after start
+    if (sync_count > 1) {
+
+	if (have_mmap) {
+	    if (-1 ==
+		ioctl(fd_, VIDIOCMCAPTURE,
+		      (grab_count % 2) ? &gb_odd : &gb_even))
+		perror("ioctl VIDIOMCAPTURE");
+	    else
+		grab_count++;
+	}
     }
 
     suppress(frame_);
@@ -650,12 +660,12 @@
 void V4lGrabber::packed422_to_planar422(char *dest, char *src)
 {
     int i;
-    char *s, *y,*u,*v;
+    char *s, *y, *u, *v;
     unsigned int a, *srca;
 
-    srca = (unsigned int *)src;
+    srca = (unsigned int *) src;
 
-    i = (width_ * height_)/2;
+    i = (width_ * height_) / 2;
     s = src;
     y = dest;
     u = y + width_ * height_;
@@ -665,66 +675,66 @@
     switch (byteorder_) {
     case BYTE_ORDER_YUYV:
 	while (--i) {
-        	a = *(srca++);
-        	*(y++) = a & 0xff;
-        	a >>= 8;
-        	*(u++) = a & 0xff;
-        	a >>= 8;
-        	*(y++) = a & 0xff;
-        	a >>= 8;
-        	*(v++) = a & 0xff;
-    	}
-        break;
+	    a = *(srca++);
+	    *(y++) = a & 0xff;
+	    a >>= 8;
+	    *(u++) = a & 0xff;
+	    a >>= 8;
+	    *(y++) = a & 0xff;
+	    a >>= 8;
+	    *(v++) = a & 0xff;
+	}
+	break;
 
     case BYTE_ORDER_YVYU:
 	while (--i) {
-        	a = *(srca++);
-        	*(y++) = a & 0xff;
-        	a >>= 8;
-        	*(v++) = a & 0xff;
-        	a >>= 8;
-        	*(y++) = a & 0xff;
-        	a >>= 8;
-        	*(u++) = a & 0xff;
-    	}
-        break;
+	    a = *(srca++);
+	    *(y++) = a & 0xff;
+	    a >>= 8;
+	    *(v++) = a & 0xff;
+	    a >>= 8;
+	    *(y++) = a & 0xff;
+	    a >>= 8;
+	    *(u++) = a & 0xff;
+	}
+	break;
 
     case BYTE_ORDER_UYVY:
 	while (--i) {
-        	a = *(srca++);
-        	*(u++) = a & 0xff;
-        	a >>= 8;
-        	*(y++) = a & 0xff;
-        	a >>= 8;
-        	*(v++) = a & 0xff;
-        	a >>= 8;
-        	*(y++) = a & 0xff;
-    	}
-        break;
+	    a = *(srca++);
+	    *(u++) = a & 0xff;
+	    a >>= 8;
+	    *(y++) = a & 0xff;
+	    a >>= 8;
+	    *(v++) = a & 0xff;
+	    a >>= 8;
+	    *(y++) = a & 0xff;
+	}
+	break;
 
     case BYTE_ORDER_VYUY:
 	while (--i) {
-        	a = *(srca++);
-        	*(v++) = a & 0xff;
-        	a >>= 8;
-        	*(y++) = a & 0xff;
-        	a >>= 8;
-        	*(u++) = a & 0xff;
-        	a >>= 8;
-        	*(y++) = a & 0xff;
-    	}
-        break;
+	    a = *(srca++);
+	    *(v++) = a & 0xff;
+	    a >>= 8;
+	    *(y++) = a & 0xff;
+	    a >>= 8;
+	    *(u++) = a & 0xff;
+	    a >>= 8;
+	    *(y++) = a & 0xff;
+	}
+	break;
     }
 
 }
 
 void V4lGrabber::packed422_to_planar411(char *dest, char *src)
 {
-    int  a1,b;
-    char *s, *y,*u,*v;
+    int a1, b;
+    char *s, *y, *u, *v;
     unsigned int a, *srca;
 
-    srca = (unsigned int *)src;
+    srca = (unsigned int *) src;
 
     s = src;
     y = dest;
@@ -734,71 +744,89 @@
     switch (byteorder_) {
     case BYTE_ORDER_YUYV:
 	for (a1 = height_; a1 > 0; a1 -= 2) {
-        	for (b = width_; b > 0; b -= 2) {
-                	a = *(srca++);
-                	*(y++) = a & 0xff; a >>= 8;
-                	*(u++) = a & 0xff; a >>= 8;
-                	*(y++) = a & 0xff; a >>= 8;
-                	*(v++) = a & 0xff;
-        	}
-        	for (b = width_; b > 0; b -= 2) {
-                	a = *(srca++); 
-                	*(y++) = a & 0xff; a >>= 16;
-                	*(y++) = a & 0xff;
-        	}
-    	}
-        break;
+	    for (b = width_; b > 0; b -= 2) {
+		a = *(srca++);
+		*(y++) = a & 0xff;
+		a >>= 8;
+		*(u++) = a & 0xff;
+		a >>= 8;
+		*(y++) = a & 0xff;
+		a >>= 8;
+		*(v++) = a & 0xff;
+	    }
+	    for (b = width_; b > 0; b -= 2) {
+		a = *(srca++);
+		*(y++) = a & 0xff;
+		a >>= 16;
+		*(y++) = a & 0xff;
+	    }
+	}
+	break;
 
     case BYTE_ORDER_YVYU:
 	for (a1 = height_; a1 > 0; a1 -= 2) {
-        	for (b = width_; b > 0; b -= 2) {
-                	a = *(srca++);
-                	*(y++) = a & 0xff; a >>= 8;
-                	*(v++) = a & 0xff; a >>= 8;
-                	*(y++) = a & 0xff; a >>= 8;
-                	*(u++) = a & 0xff;
-        	}
-        	for (b = width_; b > 0; b -= 2) {
-                	a = *(srca++); 
-                	*(y++) = a & 0xff; a >>= 16;
-                	*(y++) = a & 0xff;
-        	}
-    	}
-        break;
+	    for (b = width_; b > 0; b -= 2) {
+		a = *(srca++);
+		*(y++) = a & 0xff;
+		a >>= 8;
+		*(v++) = a & 0xff;
+		a >>= 8;
+		*(y++) = a & 0xff;
+		a >>= 8;
+		*(u++) = a & 0xff;
+	    }
+	    for (b = width_; b > 0; b -= 2) {
+		a = *(srca++);
+		*(y++) = a & 0xff;
+		a >>= 16;
+		*(y++) = a & 0xff;
+	    }
+	}
+	break;
 
     case BYTE_ORDER_UYVY:
 	for (a1 = height_; a1 > 0; a1 -= 2) {
-        	for (b = width_; b > 0; b -= 2) {
-                	a = *(srca++);
-                	*(u++) = a & 0xff; a >>= 8;
-                	*(y++) = a & 0xff; a >>= 8;
-                	*(v++) = a & 0xff; a >>= 8;
-                	*(y++) = a & 0xff;
-        	}
-        	for (b = width_; b > 0; b -= 2) {
-                	a = *(srca++); a >>= 8;
-                	*(y++) = a & 0xff; a >>= 16;
-                	*(y++) = a & 0xff;
-        	}
-    	}
-        break;
+	    for (b = width_; b > 0; b -= 2) {
+		a = *(srca++);
+		*(u++) = a & 0xff;
+		a >>= 8;
+		*(y++) = a & 0xff;
+		a >>= 8;
+		*(v++) = a & 0xff;
+		a >>= 8;
+		*(y++) = a & 0xff;
+	    }
+	    for (b = width_; b > 0; b -= 2) {
+		a = *(srca++);
+		a >>= 8;
+		*(y++) = a & 0xff;
+		a >>= 16;
+		*(y++) = a & 0xff;
+	    }
+	}
+	break;
 
     case BYTE_ORDER_VYUY:
 	for (a1 = height_; a1 > 0; a1 -= 2) {
-        	for (b = width_; b > 0; b -= 2) {
-                	a = *(srca++);
-                	*(v++) = a & 0xff; a >>= 8;
-                	*(y++) = a & 0xff; a >>= 8;
-                	*(u++) = a & 0xff; a >>= 8;
-                	*(y++) = a & 0xff;
-        	}
-        	for (b = width_; b > 0; b -= 2) {
-                	a = *(srca++); a >>= 8;
-                	*(y++) = a & 0xff; a >>= 16;
-                	*(y++) = a & 0xff;
-        	}
-    	}
-        break;
+	    for (b = width_; b > 0; b -= 2) {
+		a = *(srca++);
+		*(v++) = a & 0xff;
+		a >>= 8;
+		*(y++) = a & 0xff;
+		a >>= 8;
+		*(u++) = a & 0xff;
+		a >>= 8;
+		*(y++) = a & 0xff;
+	    }
+	    for (b = width_; b > 0; b -= 2) {
+		a = *(srca++);
+		a >>= 8;
+		*(y++) = a & 0xff;
+		a >>= 16;
+		*(y++) = a & 0xff;
+	    }
+	}
+	break;
     }
 }
 
@@ -815,33 +843,33 @@
   \param dst beginning of YUV422P data
   */
 
-  int line, clinewidth;
-  unsigned char *sy, *su, *sv, *ty, *tu, *tv;
-  
-  clinewidth = 2*width;
-  sy = (unsigned char *)src;
-  su = sy + width * height;
-  sv = su + width * height / 4;
-
-  ty = (unsigned char *)dst;
-  tu = ty + width * height;
-  tv = tu + width * height / 2;
-
-  /* Copy planar lumina block */
-  memcpy(ty,sy,width*height);
-
-  /* Copy the chroma under consideration of chroma for two lines in YUV420 */
-  for (line = 0; line < height; line += 2) {
-    memcpy(tu,su,clinewidth);
-    memcpy(tv,sv,clinewidth);
-    // Don't increment sourceline if line = 2,6,10,14,... 
-    if( (line & 3) != 2 ){
-      su += width;
-      sv += width;
-    }
-    tu += width;
-    tv += width;
-  }
+    int line, clinewidth;
+    unsigned char *sy, *su, *sv, *ty, *tu, *tv;
+
+    clinewidth = 2 * width;
+    sy = (unsigned char *) src;
+    su = sy + width * height;
+    sv = su + width * height / 4;
+
+    ty = (unsigned char *) dst;
+    tu = ty + width * height;
+    tv = tu + width * height / 2;
+
+    /* Copy planar lumina block */
+    memcpy(ty, sy, width * height);
+
+    /* Copy the chroma under consideration of chroma for two lines in YUV420 */
+    for (line = 0; line < height; line += 2) {
+	memcpy(tu, su, clinewidth);
+	memcpy(tv, sv, clinewidth);
+	// Don't increment sourceline if line = 2,6,10,14,... 
+	if ((line & 3) != 2) {
+	    su += width;
+	    sv += width;
+	}
+	tu += width;
+	tv += width;
+    }
 }
 
 
@@ -858,54 +886,54 @@
   \param dst beginning of YUV422P data
   */
 
-  int line, col, clinewidth, tr,tb;
-  unsigned char *sy, *su, *sv, *ty, *tu, *tv;
-  
-  clinewidth = width*2;
-  sy = (unsigned char *)src;
-  su = sy + width * height;
-  sv = su + width * height / 4;
-
-  ty = (unsigned char *)dst;
-  tu = ty + width * height;
-  tv = tu + width * height / 4;
-
-  /* Copy planar lumina block */
-  memcpy(ty,sy,width*height);
-
-  /* Copy the chroma under consideration of chroma for two lines in YUV420
-   * Conversation 2lines2columns1chroma => 1line4columns1chroma */
-  for (line = 0; line < height; line += 2) {
-     for (col = 0; col < clinewidth; col += 4){
-       tb = (*su++ + *su++) / 2; //SV-XXX: clarify desired operation using brackets
-       tr = (*sv++ + *sv++) / 2; //SV-XXX: clarify desired operation using brackets
+    int line, col, clinewidth, tr, tb;
+    unsigned char *sy, *su, *sv, *ty, *tu, *tv;
+
+    clinewidth = width * 2;
+    sy = (unsigned char *) src;
+    su = sy + width * height;
+    sv = su + width * height / 4;
+
+    ty = (unsigned char *) dst;
+    tu = ty + width * height;
+    tv = tu + width * height / 4;
+
+    /* Copy planar lumina block */
+    memcpy(ty, sy, width * height);
+
+    /* Copy the chroma under consideration of chroma for two lines in YUV420
+     * Conversation 2lines2columns1chroma => 1line4columns1chroma */
+    for (line = 0; line < height; line += 2) {
+	for (col = 0; col < clinewidth; col += 4) {
+	    tb = (*su++ + *su++) / 2;	//SV-XXX: clarify desired operation using brackets
+	    tr = (*sv++ + *sv++) / 2;	//SV-XXX: clarify desired operation using brackets
+	    *tu++ = tb;
+	    *tv++ = tr;
+	}
+
+	// Decrement sourceline if line = 2,6,10,14,... 
+	if ((line & 3) == 2) {
+	    su -= width;
+	    sv -= width;
+	}
+    }
+
+    /*  for (line = 0; line < height; line += 2) {
+       for (col = 0; col < width; col += 4){
+       tb = (*su++ + *su++) / 2;
+       tr = (*sv++ + *sv++) / 2;
        *tu++ = tb;
        *tv++ = tr;
-     }
-    
-     // Decrement sourceline if line = 2,6,10,14,... 
-     if( (line & 3) == 2 ){
-       su -= width;
-       sv -= width;
-     }
-     }
-
-  /*  for (line = 0; line < height; line += 2) {
-    for (col = 0; col < width; col += 4){
-      tb = (*su++ + *su++) / 2;
-      tr = (*sv++ + *sv++) / 2;
-      *tu++ = tb;
-      *tv++ = tr;
-    }
-    su -= width/2;
-    sv -= width/2;
-    for (col = 0; col < width; col += 4){
-      tb = (*su++ + *su++) / 2;
-      tr = (*sv++ + *sv++) / 2;
-      *tu++ = tb;
-      *tv++ = tr;
-    }
-    }*/
+       }
+       su -= width/2;
+       sv -= width/2;
+       for (col = 0; col < width; col += 4){
+       tb = (*su++ + *su++) / 2;
+       tr = (*sv++ + *sv++) / 2;
+       *tu++ = tb;
+       *tv++ = tr;
+       }
+       } */
 }
 
 
@@ -914,65 +942,68 @@
 
 void V4lGrabber::format()
 {
-    struct video_channel     channel;
+    struct video_channel channel;
     debug_msg("V4l: format\n");
 
-    width_  = CIF_WIDTH  *2  / decimate_;
-    height_ = CIF_HEIGHT *2  / decimate_;
+    width_ = CIF_WIDTH * 2 / decimate_;
+    height_ = CIF_HEIGHT * 2 / decimate_;
 
-    if (have_422)
-      v4lformat_=VIDEO_PALETTE_YUV422;
+    // FIXED by barz 2006/9/19:  YUV422 is default
+    if (have_420P)
+	v4lformat_ = VIDEO_PALETTE_YUV420P;
     else
-      v4lformat_=VIDEO_PALETTE_YUV420P;
+	v4lformat_ = VIDEO_PALETTE_YUV422;
 
     switch (cformat_) {
     case CF_CIF:
-        set_size_411(width_, height_);
-        debug_msg(" cif");
-        break;
+	set_size_411(width_, height_);
+	debug_msg(" cif");
+	break;
     case CF_411:
-        set_size_411(width_, height_);
-        debug_msg(" 411");
-        break;
+	set_size_411(width_, height_);
+	debug_msg(" 411");
+	break;
     case CF_422:
-        set_size_422(width_, height_);
-    	if (have_422P ) {
-		v4lformat_=VIDEO_PALETTE_YUV422P;
-        	debug_msg("Capturing directly in 422 Planar\n");
+	set_size_422(width_, height_);
+	if (have_422P) {
+	    v4lformat_ = VIDEO_PALETTE_YUV422P;
+	    debug_msg("Capturing directly in 422 Planar\n");
 	}
-        debug_msg(" 422");
-        break;
+	debug_msg(" 422");
+	break;
     }
     if (have_mmap) {
-	gb_even.frame  = 0;
+	gb_even.frame = 0;
 	gb_even.format = v4lformat_;
-	gb_even.width  = width_;
+	gb_even.width = width_;
 	gb_even.height = height_;
-	gb_odd.frame   = 1;
-	gb_odd.format  = v4lformat_;
-	gb_odd.width   = width_;
-	gb_odd.height  = height_;
-    } else {
-	memset(&win,0,sizeof(win));
-	win.width  = width_;
+	gb_odd.frame = 1;
+	gb_odd.format = v4lformat_;
+	gb_odd.width = width_;
+	gb_odd.height = height_;
+    }
+    else {
+	memset(&win, 0, sizeof(win));
+	win.width = width_;
 	win.height = height_;
-	if (-1 == ioctl(fd_,VIDIOCSWIN,&win))
+	debug_msg("Setting palette to %d", pict.palette);
+	if (-1 == ioctl(fd_, VIDIOCSWIN, &win))
 	    perror("ioctl VIDIOCSWIN");
-	if (-1 == ioctl(fd_,VIDIOCGWIN,&win))
+	if (-1 == ioctl(fd_, VIDIOCGWIN, &win))
 	    perror("ioctl VIDIOCGWIN");
-	width_  = win.width;
+	width_ = win.width;
 	height_ = win.height;
 	pict.palette = v4lformat_;
-	if (-1 == ioctl(fd_,VIDIOCSPICT,&pict)) {
-	  perror("ioctl VIDIOCSPICT");
+	if (-1 == ioctl(fd_, VIDIOCSPICT, &pict)) {
+	    perror("ioctl VIDIOCSPICT");
 	}
     }
-    if (-1 == ioctl(fd_,VIDIOCGPICT,&pict)) {
+    // barz: get pict to setup the white blance
+    if (-1 == ioctl(fd_, VIDIOCGPICT, &pict)) {
 	perror("ioctl VIDIOCGPICT");
     }
 
-    
-    debug_msg(" size=%dx%d\n",width_,height_);
+    debug_msg(" size=%dx%d\n", width_, height_);
 
     bzero(&channel, sizeof(struct video_channel));
     if (-1 == ioctl(fd_, VIDIOCGCHAN, &channel))
@@ -984,8 +1015,8 @@
     if (-1 == ioctl(fd_, VIDIOCSCHAN, &channel))
 	perror("ioctl VIDIOCSCHAN");
 
-    debug_msg(" port=%d\n",port_);
-    debug_msg(" norm=%d\n",norm_);
-
+    debug_msg(" port=%d\n", port_);
+    debug_msg(" norm=%d\n", norm_);
+    
     allocref();
 }



More information about the Sumover-dev mailing list