我买了款usb摄像头,在mini2440的usb摄像头测试程序里使用正常,但是自己想用v4l来测试下他问题就出来了。
内核用的是友善的最新内核2.6.32
状况如下:
1.首先将摄像头插入USB时 显示的是如下mesg:
usb 1-1: new full speed USB device using s3c2410-ohci and address 4
usb 1-1: device not accepting address 4, error -62
usb 1-1: new full speed USB device using s3c2410-ohci and address 5
usb 1-1: New USB device found, idVendor=04fc, idProduct=2700
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1: Product: USB2.0 WebCam
usb 1-1: Manufacturer: WebCam Co Ltd
usb 1-1: configuration #1 chosen from 1 choice
uvcvideo: Found UVC 1.00 device USB2.0 WebCam (04fc:2700)
uvcvideo: Non-zero status (-62) in status completion handler.
2.然后在/dev/下出现了video0这个设备,执行cat /dev/video0 > picture出现错误:cat: read error: No such device
3.在程序中用v4l方法操作read的时候读出来的数据总为-1
4.用mmap时,在if(ioctl(vd.fd,VIDIOCGMBUF,&vd.mbuf)<0) 即取得mbuf的时候出错,错误为: Invalid argument,而其他的属性例如capability和picture都可以正常取得。
程序代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/videodev.h>
struct v4l_struct
{
int fd;
struct video_capability capability;
struct video_buffer buffer;
struct video_window window;
struct video_channel channel[8];
struct video_picture picture;
struct video_mmap mmap;
struct video_mbuf mbuf;
unsigned char *map;
};
typedef struct v4l_struct v4l_device;
int main()
{
v4l_device vd;
int n;
int len ;
unsigned char *map;
vd.fd=open("/dev/video0",O_RDWR);
if(vd.fd<0)
perror("open");
if(ioctl(vd.fd,VIDIOCGCAP,&vd.capability)<0)
perror("get capability");
if(ioctl(vd.fd,VIDIOCGPICT,&vd.picture)<0)
perror("get picture");
if(ioctl(vd.fd,VIDIOCGMBUF,&vd.mbuf)<0)
perror("get mbuf"); //问题就出在这里
/*map=(unsigned char *)malloc(vd.capability.maxwidth*vd.capability.maxheight);
len = read(vd.fd,map,
vd.capability.maxwidth*vd.capability.maxheight*3 );*/ //如果使用read,则读出来总为-1,。
//n=read(fd,buf,500);
printf("name:%s,maxwidth:%d,maxheight:%d,maxwidth:%d,maxheight:%d\n",vd.capability.name,vd.capability.maxwidth,vd.capability.maxheight,vd.capability.minwidth,vd.capability.minheight); //这些能正常打印
printf("mbuf.size:%d,\n",vd.mbuf.size); //打印为0
close(vd.fd);
exit(0);
}
请版主和各位高人帮忙看看,不胜感激!