VIDEO4LINUX ON AN OLIMEX AT91SAM9260 BOARD.

Hi , I’d like to run on my board this code to take a photo by a webcam plugged on the USB port and save it on a Secure Digital on board:

/*

main.c

Simple V4L1 applet - Capture one frame from /dev/video0 and save

it as a BMP.

2004-04-03 larwe created

*/

#include <sys/types.h>

#include <sys/stat.h>

#include <stdio.h>

#include <stdlib.h>

#include <fcntl.h>

#include <unistd.h>

#include <sys/ioctl.h>

#include <linux/videodev.h>

#include “bmplib.h”

/*

Demonstration main function

*/

int main(int _argc, char *_argv)

{

BMINFO bi;

BLERR status;

unsigned char *capbuffer;

struct video_capability vc;

struct video_picture vp;

struct video_window vw;

int video, rc;

if (_argc < 2) {

printf(“Usage : vidcap filename.bmp\n”

“Captures one frame from /dev/video0 to filename.bmp\n”);

return -1;

}

printf(“Opening /dev/video0… “);

fflush(NULL);

video = open(“/dev/video0”, O_RDWR);

if (video == -1) {

printf(“Cannot open, aborting.\n”);

return -1;

}

printf(“OK.\nGetting device capabilities… “);

// Ascertain and display capture device properties

rc = ioctl(video, VIDIOCGCAP, &vc);

if (rc) {

printf(“VIDIOCGCAP failed, aborting.”);

return -1;

}

printf(“OK.\n”);

printf(“Name : ‘%s’\n”

“Channels : %d\n”

“Audios : %d\n”

“Size : %dx%d to %dx%d\n”, vc.name, vc.channels,

vc.audios, vc.minwidth, vc.minheight,

vc.maxwidth, vc.maxheight);

printf(“Capabilities : “);

if (vc.type & VID_TYPE_CAPTURE)

printf(“VID_TYPE_CAPTURE “);

if (vc.type & VID_TYPE_TUNER)

printf(“VID_TYPE_TUNER “);

if (vc.type & VID_TYPE_TELETEXT)

printf(“VID_TYPE_TELETEXT “);

if (vc.type & VID_TYPE_OVERLAY)

printf(“VID_TYPE_OVERLAY “);

if (vc.type & VID_TYPE_CHROMAKEY)

printf(“VID_TYPE_CHROMAKEY “);

if (vc.type & VID_TYPE_CLIPPING)

printf(“VID_TYPE_CLIPPING “);

if (vc.type & VID_TYPE_FRAMERAM)

printf(“VID_TYPE_FRAMERAM “);

if (vc.type & VID_TYPE_SCALES)

printf(“VID_TYPE_SCALES “);

if (vc.type & VID_TYPE_MONOCHROME)

printf(“VID_TYPE_MONOCHROME “);

if (vc.type & VID_TYPE_SUBCAPTURE)

printf(“VID_TYPE_SUBCAPTURE “);

printf(“\n”);

printf(“Getting image properties… “);

rc = ioctl(video, VIDIOCGPICT, &vp);

if (rc) {

printf(“VIDIOCGPICT failed, aborting.”);

return -1;

}

printf(“OK.\n”);

if (vp.palette != VIDEO_PALETTE_RGB24) {

// Attempt to set RGB24 palette

printf(“Attempting to set RGB24 palette… “);

vp.palette = VIDEO_PALETTE_RGB24;

rc = ioctl(video, VIDIOCSPICT, &vp);

if (rc) {

printf(“VIDIOCSPICT failed, aborting.\n”);

return -1;

}

rc = ioctl(video, VIDIOCGPICT, &vp);

if (rc) {

printf(“VIDIOCGPICT failed, aborting.\n”);

return -1;

}

if (vp.palette != VIDEO_PALETTE_RGB24) {

printf(“Device does not support RGB24 palette, aborting.\

n”);

return -1;

}

printf(“OK.\n”);

}

printf(“Brightness : %d\n”

“Hue : %d\n”

“Color : %d\n”

“Contrast : %d\n”

“Whiteness : %d\n”

“Depth : %d\n”,

vp.brightness, vp.hue, vp.colour, vp.contrast, vp.whiteness,

vp.depth, vp.palette);

printf(“Palette : “);

switch(vp.palette) {

case VIDEO_PALETTE_GREY: printf(“VIDEO_PALETTE_GREY”); break;

case VIDEO_PALETTE_HI240: printf(“VIDEO_PALETTE_HI240”); break;

case VIDEO_PALETTE_RGB565: printf(“VIDEO_PALETTE_RGB565”); break;

case VIDEO_PALETTE_RGB555: printf(“VIDEO_PALETTE_RGB555”); break;

case VIDEO_PALETTE_RGB24: printf(“VIDEO_PALETTE_RGB24”); break;

case VIDEO_PALETTE_RGB32: printf(“VIDEO_PALETTE_RGB32”); break;

case VIDEO_PALETTE_YUV422: printf(“VIDEO_PALETTE_YUV422”); break;

case VIDEO_PALETTE_YUYV: printf(“VIDEO_PALETTE_YUYV”); break;

case VIDEO_PALETTE_UYVY: printf(“VIDEO_PALETTE_UYVY”); break;

case VIDEO_PALETTE_YUV420: printf(“VIDEO_PALETTE_YUV420”); break;

case VIDEO_PALETTE_YUV411: printf(“VIDEO_PALETTE_YUV411”); break;

case VIDEO_PALETTE_RAW: printf(“VIDEO_PALETTE_RAW (BT848)”);

break;

case VIDEO_PALETTE_YUV422P: printf(“VIDEO_PALETTE_YUV422P”);break;

case VIDEO_PALETTE_YUV411P: printf(“VIDEO_PALETTE_YUV411P”);break;

default: printf(“Unrecognized”);

}

printf(“\n”);

if (vp.palette != VIDEO_PALETTE_RGB24 && vp.palette != VIDEO_PAL-

ETTE_RGB32) {

printf(“This program supports ONLY VIDEO_PALETTE_RGB24 and

VIDEO_PALETTE_RGB32.\n”);

return -1;

}

// Set window

vw.x = 0;

vw.y = 0;

vw.width = vc.maxwidth;

vw.height = vc.maxheight;

vw.chromakey = 0;

vw.flags = 0;

vw.clips = NULL;

vw.clipcount = 0;

printf(“Setting video capture window… “);

rc = ioctl(video, VIDIOCSWIN, &vw);

if (rc) {

printf(“Failed, aborting.\n”);

return -1;

}

printf(“OK.\n”);

printf(“Querying video capture window… “);

rc = ioctl(video, VIDIOCGWIN, &vw);

if (rc) {

printf(“Failed, aborting.\n”);

return -1;

}

printf(“OK, window size is %dx%d.\n”, vw.width, vw.height);

// Allocate RAM for capture buffer. At MOST we need 32 bits per

pixel.

capbuffer = malloc(vw.width * vw.height * 4);

if (capbuffer == NULL) {

printf(“Error allocating memory for capture buffer!\n”);

return -1;

}

// Capture an image using the read() interface. This is potential-

ly unsupported.

printf(“Reading buffer… “);

if (vp.palette == VIDEO_PALETTE_RGB24)

read(video, capbuffer, vw.width * vw.height * 3);

else if (vp.palette == VIDEO_PALETTE_RGB32)

read(video, capbuffer, vw.width * vw.height * 4);

printf(“OK.\n”);

printf(“Closing /dev/video0… “);

close(video);

printf(“OK.\n”);

// For RGB32, we need to convert the image down to RGB24.

if (vp.palette == VIDEO_PALETTE_RGB32) {

// BUGBUG - Not implemented yet!

printf(“CONVERSION NOT IMPLEMENTED.\n”);

return -1;

}

// Create overlying bitmap structure

bi.width = vw.width;

bi.height = vw.height;

bi.bitmapdata = capbuffer;

// Open output file

printf(“Saving output file… “);

fflush(NULL);

bi.fd = open(_argv[1], O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU);

if (bi.fd <= 0) {

printf(“Can’t open output file.\n”);

return -1;

}

status = BL_Save_Bitmap(&bi);

close(bi.fd);

printf(“Returncode %d\n”, status);

}

but under the /DEV directory I can’t find any /DEV/VIDEO0 device , so where is the problem?

In the LINUX kernel source code included in the OLIMEX CD there are the source of VIDEO4LINUX . If I recompile from scratch the Kernel can I fix the problem?

I’m a beginner with Linux in general , so could some more experienced user tell me please where I’m wrong ?

Thank you very very much.