#include "frame.h"
// place your code here
int fd;
bool capture_lock;
int errorBufNum;
bool errorFlag;
FrameBuffer::FrameBuffer()
{
/*init BMP Header information*/
initBMPHeader();
memset (&fmt, 0, sizeof(fmt) );
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
/*set the capturing picture size*/
width=640;
height=480;
fmt.fmt.pix.width = width;
fmt.fmt.pix.height = height;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.field = V4L2_FIELD_INTERLACED;
req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
req.memory = V4L2_MEMORY_MMAP;
req.count=BUFFER_NUM;
nbuffer = req.count;
/* initialize the QPixmap */
myMap=new QPixmap();
printf("BMP_Header:%d\n",sizeof(BMP_Header));
}
FrameBuffer::~FrameBuffer()
{
if(photoBuffers!=NULL)
delete [] photoBuffers;
if(fd>0)
close(fd);
delete myMap;
}
/* init BMP picture header function */
void FrameBuffer::initBMPHeader()
{
int i=0;
for(;i<55;i++)
{
if(i==0)
{
BMP_Header[i]=0x42;
}
else if(i==1)
{
BMP_Header[i]=0x4D;
}
else if(i==2)
{
BMP_Header[i]=0x36;
}
else if(i==3)
{
BMP_Header[i]=0x02;
}
else if(i==4)
{
BMP_Header[i]=0x4D;
}
else if(i==10)
{
BMP_Header[i]=0x36;
}
else if(i==14)
{
BMP_Header[i]=0x28;
}
else if(i==18)
{
BMP_Header[i]=0x40;
}
else if(i==19)
{
BMP_Header[i]=0x01;
}
else if(i==22)
{
BMP_Header[i]=0xF0;
}
else if(i==26)
{
BMP_Header[i]=0x01;
}
else if(i==28)
{
BMP_Header[i]=0x10;
}
else{
BMP_Header[i]=0x00;
}
}
}
void FrameBuffer::frameBufferMnmap()
{
int i=0;
int ret=0;
for(;i<nbuffer;i++)
{
fprintf(stderr,"i=%d\n",i);
ret=munmap(photoBuffers[i].start,photoBuffers[i].length);
if(ret<0)
fprintf(stderr,"munmap failed!\n");
}
}
/* set function*/
void FrameBuffer::setDevicePath(char *path)
{
strcpy(device_path,path);
}
/* set picture size */
void FrameBuffer::setConfig(int w,int h)
{
closeStream();
//closeDevice();
frameBufferMnmap();
if(getStatus())
{
fprintf(stderr,"device file opened\n");
}
width=w;
height=h;
fmt.fmt.pix.width = w;
fmt.fmt.pix.height = h;
/* open video stream */
openStream();
fprintf(stderr,"set setConfig success!\n");
}
/* get the status of the device file ,opened or closed*/
bool FrameBuffer::getStatus()
{
return opened;
}
bool FrameBuffer::getStreamStatus()
{
return streamOn;
}
/* set the capturing frequency */
bool FrameBuffer::setFrequency(int f)
{
/* save current video frequency!*/
frequency=f;
if(ioctl(fd,VIDIOC_S_FREQ,&frequency)<0)
{
fprintf(stderr,"set frequency error!\n");
return false;
}
fprintf(stderr,"set frequency success!\n");
return true;
}
/* set brightness function */
void FrameBuffer::setBrightness(int b)
{
if(opened)
{
if(ioctl(fd,VIDIOCGPICT,&(vpicture))<0)
{
fprintf(stderr,"get brightness error\n");
}
/* brightness 0~65535 */
vpicture.brightness=b;
if(ioctl(fd,VIDIOCSPICT,&(vpicture))<0)
{
fprintf(stderr,"set brightness failed\n");
}
}
}
/*set contrast function */
void FrameBuffer::setContrast(int c)
{
if(opened)
{
if(ioctl(fd,VIDIOCGPICT,&(vpicture))<0)
{
fprintf(stderr,"get contrast erro");
}
/* contrast 0~65535 */
vpicture.contrast=c;
if(ioctl(fd,VIDIOCSPICT,&(vpicture))<0)
{
fprintf(stderr,"set contrast failed");
}
}
}
/* connect the device and set the format of video*/
bool FrameBuffer::deviceConn()
{
if(device_path==NULL)
{
return false;
}
if((fd = open(device_path, O_RDWR))< 0)
{
fprintf(stderr,"Can not open the file!\n");
return false;
}
return true;
}
/*User memory request*/
bool FrameBuffer::memReq()
{
/* buffers */
photoBuffers = new PhotoBuffer[nbuffer];
if(photoBuffers==NULL)
{
printf("Failed to request memory!\n");
return false;
}
for (unsigned int numBufs = 0; numBufs < req.count; numBufs++)
{
memset( &buf, 0, sizeof(buf) );
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
buf.index = numBufs;
/* Gains data buffer address which in VIDIOC_REQBUFS assigns */
if (ioctl(fd, VIDIOC_QUERYBUF, &buf) == -1)
{
fprintf(stderr,"VIDIOC_QUERYBUF error");
return false;
}
/* Will obtain the data buffer address to transform in the application
procedure the available specific address */
photoBuffers[numBufs].length = buf.length;
photoBuffers[numBufs].start = mmap(NULL, buf.length, PROT_READ|PROT_WRITE,MAP_SHARED, fd, buf.m.offset);
if (photoBuffers[numBufs].start == MAP_FAILED)
{
printf("start == MAP_FAILED\n");
return false;
}
/* Puts in the buffer formation this section of buffers*/
if (ioctl(fd, VIDIOC_QBUF, &buf) == -1)
{
perror("VIDIOC_QBUF");
return false;
}
}
/* Opens the video frequency capture*/
type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (-1==ioctl(fd,VIDIOC_STREAMON,&type))
{
perror ("While opening stream");
return false;
}
return true;
}
/*open video stream*/
bool FrameBuffer::openStream()
{
if(ioctl(fd, VIDIOC_S_FMT, &fmt) == -1)
{
fprintf(stderr,"VIDIOC_S_FMT");
return false;
}
/* Request core memory */
if(ioctl(fd, VIDIOC_REQBUFS, &req) == -1)
{
fprintf(stderr,"VIDIOC_REQBUFS");
return false;
}
if(!memReq())
{
return false;
}
没有合适的资源?快使用搜索试试~ 我知道了~
Linux USB鼠标驱动注解及测试
共37个文件
o:10个
h:7个
cpp:6个
3星 · 超过75%的资源 需积分: 10 46 下载量 13 浏览量
2010-10-13
17:46:25
上传
评论
收藏 677KB ZIP 举报
温馨提示
Linux USB鼠标驱动注解及测试Linux USB鼠标驱动注解及测试Linux USB鼠标驱动注解及测试
资源推荐
资源详情
资源评论
收起资源包目录
QT.zip (37个子文件)
QT
bin
capture1.bmp 900KB
Tomato 80KB
.qdevelop 70KB
Tomato.pro 302B
bookmarks-2010-10-11.json 27KB
src
tomato.h~ 888B
frame.cpp~ 12KB
help.cpp 758B
help.h 683B
frame.h 3KB
main.cpp 260B
tomato.cpp~ 5KB
tomato.cpp 13KB
frame.cpp 17KB
tomato.h 2KB
ui
help.ui 1KB
ourinf.ui 2KB
tomato.ui 8KB
howtouse.ui 3KB
Tomato.pro.user 13KB
Makefile 8KB
build
moc_tomato.cpp 4KB
moc_tomato.o 12KB
main-qdeveloptmp.o 4KB
moc_help.o 16KB
ui_ourinf.h 3KB
ui_howtouse.h 6KB
frame.o 11KB
moc_help.cpp 4KB
ui_help.h 2KB
frame-qdeveloptmp.o 11KB
tomato-qdeveloptmp.o 39KB
ui_tomato.h 9KB
help.o 13KB
main.o 4KB
tomato.o 39KB
help-qdeveloptmp.o 13KB
共 37 条
- 1
jiang_dlut
- 粉丝: 113
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页