各位高手,给我看看下面一段V4L的摄像头程序,编译没错误,在板子上运行就出现Segmentation fault错误,我郁闷好久,没看的出来!!
#include "spcav4l.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <errno.h>
/*#define CIF_WIDTH 352
#define CIF_HEIGHT 288
#define QCIF_WIDTH 176
#define QCIF_HEIGHT 144*/
#define QVGA_WIDTH 320
#define QVGA_HEIGHT 240
#define VIDEO_PALETTE_YUV420P 15
#define DEPTH_YUV420P 12
typedef struct _v4l_struct
{
int fd;
struct video_capability capability;
struct video_window window;
struct video_channel channel;
struct video_picture picture;
struct video_mmap vmmap;
struct video_mbuf mbuf;
unsigned char *pFramebuffer;
unsigned int mmapsize;
unsigned char *pCapturebuf;
unsigned char *ptframe;
unsigned int hdrheight;
unsigned int hdrwidth;
unsigned int formatIn;
unsigned int bppIn;
unsigned int framesize;
}v4l_device;
int v4l_open(char *,v4l_device *);
int v4l_get_capability(v4l_device *);
int v4l_get_picture(v4l_device *);
int v4l_get_channels(v4l_device *);
int v4l_set_palette(v4l_device *);
int v4l_grab(v4l_device *);
/*int v4l_mmap_init(v4l_device *,int );
int v4l_grab_frame(v4l_device *);*/
int v4l_close(v4l_device *);
v4l_device *vd;
#define DEFAULT_DEVICE "/dev/v4l/video0"
int main(void)
{
v4l_open(DEFAULT_DEVICE,vd);
v4l_get_channels(vd);
v4l_set_palette(vd);
v4l_grab(vd);
v4l_close(vd);
}
/******************open zx301**********************/
int v4l_open(char *dev,v4l_device *vd)
{
if((vd->fd=open(DEFAULT_DEVICE,O_RDWR))<0)
{ perror("v4l_open:");
return -1;
}
if(v4l_get_capability(vd)) return -1;
if(v4l_get_picture(vd)) return -1;
return 0;
}
/*******************鑾峰彇璁惧?淇℃伅***********************/
int v4l_get_capability(v4l_device *vd)
{
if(ioctl(vd->fd,VIDIOCGCAP,&(vd->capability))<0)
{ perror("v4l_get_capability:");
return -1;
}
printf("zx301 found:%s\n",vd->capability.name);
return 0;
}
/**************鑾峰彇褰撳墠鐨勫浘鍍忓睘鎬ц?缃?********************/
int v4l_get_picture(v4l_device *vd)
{
if(ioctl(vd->fd,VIDIOCGPICT,&(vd->picture))<0)
{ perror("v4l_get_picture:");
return -1;
}
return 0;
}
/**************鑾峰彇瑙嗛?閫氶亾淇℃伅***************************/
int v4l_get_channels(v4l_device *vd)
{
if(ioctl(vd->fd,VIDIOCGCHAN,&(vd->channel))<0)
{ perror("v4l_get_channel:");
return -1;
}
printf("Brideg found:%s\n",vd->channel.name);
return 0;
}
/*************璁剧疆鍥惧儚灞炴