OpenMoko Webcam - guvcview bug fix

Rask Ingemann Lambertsen rask at
Sun Jan 25 19:43:43 CET 2009

On Wed, Jan 14, 2009 at 12:27:03AM +0100, Rask Ingemann Lambertsen wrote:
> 1) Guvcview on Debian/armel has problems. It saves a corrupt config file,
> preventing it from starting again unless you delete the config file. It also
> saves a corrupt AVI capture file. It works fine on Fedora/x86. I haven't yet
> tried other video programs.

   (For the impatient, see patch at the bottom.)

   The config file corruption was in these two lines:

# video resolution 
# control window size: default 575x610

   Instead of the proper values, there was junk for 288, 480 and 588. My
first thought was an endianess problem, but the Neo runs the ARM in little
endian mode, which is the same endianess as the x86. But still, it looked
very much as if something was writing to the wrong address, clobbering
adjecent fields in the configuration. In src/globals.h:

        int width;
        int height;
        int winwidth;
        int winheight;

   A bit further up, it says:

        DWORD framecount;
        unsigned char frmrate;
        short Sound_enable; /*Enable Sound by Default*/
        int Sound_SampRate;

   There's supposed to be a hidden, one byte pad field after the 'frmrate'
field so 'Sound_enable' is naturally aligned. However, the structure has
'__attribute__ ((packed))' which prevents such pad fields from being
inserted by the compiler. The following fields will then be misaligned.
Misaligned fields are handled, with a performance penalty, by either the
compiler or the CPU. On x86, the CPU handles it while on ARM, the compiler
handles it. The latter fails for guvcview because of this line in

	gtk_window_get_size(GTK_WINDOW(gwidget->mainwin),&(global->winwidth),&(global->winheight));//mainwin or widget

   gtk_window_get_size() will of course assume that it is passed properly
aligned pointers. And sure enough, this patch (against guvcview 0.9.5) makes
the problem go away:

--- src/globals.h~	2008-11-08 00:43:18.000000000 +0100
+++ src/globals.h	2009-01-25 17:29:59.000000000 +0100
@@ -103,7 +103,7 @@ struct GLOBAL {
 	unsigned int   jpeg_bufsize; /* width*height/2 */
 	int autofocus;/*some autofocus flags*/
 	int AFcontrol;
-}   __attribute__ ((packed));
+} /*  __attribute__ ((packed)) */ ;
 /*----------------------------- prototypes ------------------------------------*/
 int initGlobals(struct GLOBAL *global);

   Guvcview then saves a working config file on exit and the AVI files it
saves can be played back (tested with mplayer).

Rask Ingemann Lambertsen
Danish law requires addresses in e-mail to be logged and stored for a year

More information about the support mailing list