|
int main(int argc,char** argv)
{
img=(unsigned char *)malloc(IMGSIZE*sizeof(char));
printf("opne v4l\n");
if((vd.fd=open("/dev/video0",O_RDWR))<0)
{
printf("open v4l error\n");
exit(1);
}
ioctl(vd.fd,VIDIOCGCAP,&(vd.capability));
printf("capability.name: %s\n",vd.capability.name);
///////get picture//////////////
ioctl(vd.fd,VIDIOCGPICT,&(vd.picture));
///////////set picture////////////////
vd.picture.depth=12;
vd.picture.palette=15;
if(ioctl(vd.fd,VIDIOCSPICT,&(vd.picture))<0)
{
printf("vidiocspic error\n");
exit(1);
}
////////mmap_init///////
vd.mmap.width=IMGWIDTH;
vd.mmap.height=IMGHEIGHT;
vd.mmap.format=VIDEO_PALETTE_RGB24;
vd.frame=0;
vd.framestat[0]=vd.framestat[1]=0;
//////////get buffer////////////////////////
if((ioctl(vd.fd,VIDIOCGFBUF,&(vd.buffer)))==-1)
{
printf("get mbuf error\n");
exit(1);
}
//////////////////mmap_init//////////////////
if((ioctl(vd.fd,VIDIOCGMBUF,&(vd.mbuf)))==-1)
{
printf("get mbuf error\n");
exit(1);
}
vd.map=(unsigned char*)mmap(0,vd.mbuf.size,PROT_READ|PROT_WRITE,MAP_SHARED,vd.fd,0);
if(MAP_FAILED==vd.map)
{
perror("");
printf("mmap error\n");
}
printf("vd.map=%d\n",(int)vd.map);
////////////grab frame//////////////////////////////
vd.mmap.frame=0;
ioctl(vd.fd,VIDIOCMCAPTURE,&(vd.mmap));
vd.framestat[0]=1;
vd.frame=0;
////////////////grab sync/////////////////////////////
ioctl(vd.fd,VIDIOCSYNC,&(vd.frame));
vd.framestat[vd.frame]=0;
/////////////get address///////////////////////////
img=vd.map+vd.mbuf.offsets[vd.frame];
printf("vd.map=%d\n",(int)vd.map);
printf("vd.mbuf.offsets[vd.frame]=%d\n",(int)vd.mbuf.offsets[vd.frame]);
printf("img1=%d\n",(int)img);
。。。。。。
运行后显示
vd.map=-1211031552
vd.mbuf.offsets[vd.frame]=0
img1=-1211031552
就不明白为什么mmap()返回给的值是个负的 不知道哪里出问题了
请各位帮忙看看 谢谢了 |
|