/******************************林启俊_V4L_采集************************************************
**** *
***作者: 林启俊 * *
***日期: 2006-11-30 * *
*** * *
*** * ALL RIGHTS Reserved *
***
***版本: 1.0 * *
***环境: Linux * *
*** *
***目的: 为3G手机的现场直播而准备
***申明: 一切解释权本人作解释;不得修改(除非经本人同意),不得发表!
***
*** e_mail: linqijun211@163.com
*******************************************************************************************
***人生格言: 为人生理想而战斗,不怕辛苦!! 为报答父母而奋斗,不怕劳累!! ********************
********************************************************************************************
**说明: 此程序尽力让V4L简单而写,采用调用函数来实现;希望对学习V4L的朋友有所帮助 **********
** 我的摄像头只支持两贞采集,我的想法是,每采集一贞就保存了一个图像;所以我设了两个图像文件 *********
**** /home/linzi.jpeg和/home/linzicheng.jpeg;用的时候可以随便保存到任何地方的 *******************
***
*** Please email to me if you have some problems or advices to me to modify! than you !! ***********/
#include "v4l_linqijun.h"
int main(int argc,char **argv)
{ char *address="";
int frame =0;
int fd;
/***********=== Save the image to the two file =========*************/
FILE * fp;
FILE * FP;
fp=fopen("/home/linzi.jpeg","w");
FP=fopen("/home/linzicheng.jpeg","w");
/*******============从这开始====================*************/
fd=open(DEFAULT,O_RDWR);
if(fd==0)
printf("open success\n");
else
{ printf("open failure and open again\n");
sleep(3); //稍等,也许设备没有准备好!
if((fd=open(DEFAULT1,O_RDWR))<0)
{ perror(" open devicen");
}
else printf("open sucess at second time\n");
}
printf("\t\n-------- Go to get capability-----------\n");
if(lin_get_capability(fd,&capability)==0)
printf(" \tGET video_capability SUCCESS!\n");
printf("\t\n --------Go to get picture---------------\n");
if(lin_get_picture(fd,&picture)==0)
printf("\tGET video_picture SUCCESS !\n");
else
perror(" get video_picture!\n");
printf("\t\n--------GO to set picture-----------------\n");
if(lin_set_picture(fd,&picture)==0)
printf("SET video_picture SUCCESS !\n");
else
perror(" set video_picture!\n");
printf("\t\n----------GO to set window---------------\n");
if(lin_set_window(fd,&window)==0)
printf("SET video_window SUCCESS!\n");
else
printf(" SET video_window error!\n");
printf("\t\n----------------GO to get mbuf-----------------\n");
if(lin_get_mbuf(fd,&mbuf)==0)
printf("SET video_mbuf SUCCESS!\n");
else
printf("SET videio_mbuf error\n");
printf("\t\n-----------------GO to set mmap----------------\n");
if(lin_set_mmap(&mmap1)==0)
printf(" SET video_mmap SUCCESS !\n");
else
printf(" SET video_mmap errro\n");
printf("\t\n----------------GO to memory map----------------\n");
if(lin_memory_map(fd,mbuf.size)<0)
printf("memory map failed \n");
else
printf(" memory map SUCCESS \n");
printf("\t\n-------------GO TO start capture image----------------\n");
if(lin_start_capture(fd,&mmap1)==0)
printf("\t\t grabcapture SUCCESS\n");
else
printf("\t\n startcapture FAIL\n");
fprintf(fp,"P6\n%d %d\n255\n",NTSC_WIDTH,NTSC_HEIGHT); //jpeg文件的头;
fprintf(FP,"P6\n%d %d\n255\n",NTSC_WIDTH,NTSC_HEIGHT);
while(frame<mbuf.frames)
{
address=lin_get_mapaddress(frame);
if( address==(char *)NULL)
printf(" get mapaddress Failed!\n");
else
printf(" get mapaddress SUCCESS!\n");
if(frame)
{ printf("\t\n #hehe ! this is the first frame captured here,and saved as /home/lin.jpeg...###\n");
fwrite(address,NTSC_WIDTH,3*NTSC_HEIGHT,fp);
}
else {
printf("\t\n #hehe ! this is the sencond frame captured here,and saved as /home/linqijun.jpeg...###\n");
fwrite(address,NTSC_WIDTH,3*NTSC_HEIGHT,FP);
}
frame++;
}
return 0;
}