vid_mmap等变量是全局的,
int v4lstart(int fd)
{
if (ioctl (fd, VIDIOCMCAPTURE, &vid_mmap) == -1) {
perror ("ioctl VIDIOCMCAPTURE");
munmap (map, vid_buf.size);
return -1;
}
vid_mmap.frame = 1;
if (ioctl (fd, VIDIOCMCAPTURE, &vid_mmap) == -1) {
perror ("ioctl VIDIOCMCAPTURE");
munmap (map, vid_buf.size);
return -1;
}
return 0;
}
char *v4lsyn(int fd,int i)
{int bytes = 3;
vid_mmap.frame = (i +1)%2;
i++;
if (ioctl (fd, VIDIOCSYNC, &vid_mmap.frame) == -1) {
perror ("ioctl VIDIOCSYNC");
munmap (map, vid_buf.size);
return (NULL);
}
map=map +vid_buf.offsets[vid_mmap.frame];
/*if (palette == VIDEO_PALETTE_YUV420P) {
if (verbose)
fprintf (stderr, "converting from YUV to RGB\n");
convmap = malloc ( width * height * bytes );
v4l_yuv420p2rgb (convmap, map, width, height, bytes * 8);
memcpy (map, convmap, (size_t) width * height * bytes);
free (convmap);
}*/
convmap =(unsigned char *) malloc ( width * height * bytes );
v4l_yuv420p2rgb (convmap, map, width, height, bytes * 8);
memcpy (map, convmap, (size_t) width * height * bytes);
free (convmap);
return ((char *)map);
}
int v4lcapture(int fd)
{
if (ioctl (fd, VIDIOCMCAPTURE, &vid_mmap) == -1)
{
perror ("ioctl VIDIOCMCAPTURE");
munmap (map, vid_buf.size);
return -1;
}
sleep(50);
//munmap (map, vid_buf.size);
return 0;
}
然后再程序中作了个循环
v4lbuf(dev1);
v4lmap(dev1);
v4lstart(dev1);
while(1)
{
buffer=v4lsyn(dev1,i);
v4lcapture(dev1);
}
结果出现的错误是New Thread 1084981632 (LWP 4936),请各位代谢阿帮忙分析一下,谢谢
[ 此贴被XChinux在2007-01-12 14:38重新编辑 ]