主题 : Segmentation fault 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 2654
精华: 0
发帖: 5
金钱: 50 两
威望: 50 点
综合积分: 10 分
注册时间: 2008-11-30
最后登录: 2010-07-25
楼主  发表于: 2009-03-15 20:12

 Segmentation fault

各位高手,给我看看下面一段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;
}
/*************璁剧疆鍥惧儚灞炴
*無鈳取玳
级别: 论坛版主
UID: 27
精华: 12
发帖: 5398
金钱: 40120 两
威望: 17929 点
综合积分: 11036 分
注册时间: 2008-01-16
最后登录: 2014-11-22
1楼  发表于: 2009-03-15 21:42
复制代码
  1. v4l_device *vd;
  2. ...
  3. v4l_open(DEFAULT_DEVICE,vd);


你认为传给v4l_open()的vd指针指向的是什么地址?
"If you have an apple and I have an apple and we exchange apples, then you and I will
still each have one apple. But if you have an idea and I have an idea and we exchange
these ideas, then each of us will have two ideas."