usb到camera本来是支持热插拔的,但是由于正在preview时拔出camera,再插入时,camera注册到设备节点会由/dev/video0变为/dev/video1,或者插入多个video设备时,会变为/dev/video1、/dev/video2.。。。。。。而HAL层的代码是固定打开/dev/video0,所以就会打开失败。
方法1
对video0到video63循环打开。
int i;
char* devname="/dev/video";
char s[16];
char index[10];
for( i=0; i<=63; i++)
{
sprintf(index,"%d",i); //将int格式化为char
sprintf(s,"%s%s",devname,index);
LOGW("devname=%s",s);
if ((mCameraHandle = open(s, O_RDWR)) != -1)
break;
}
if(i==64)
{
LOGINFO("Error while opening handle to V4L2 Camera: %s", strerror(errno));
return -EINVAL;
}
方法2 使用popen调用shell命令
FILE * fp;
char name[12]; //只能video0到video9
fp=popen("ls /dev/v*","r");
fgets(name,sizeof(name),fp);
pclose(fp);
if ((mCameraHandle = open(name, O_RDWR)) == -1)
{
LOGINFO("Error while opening handle to V4L2 Camera: %s", strerror(errno));
return -EINVAL;
}
FILE *popen(const char *command, const char *type);调用fork产生一个子进程,建立管道连接到子进程的标准输出或输入设备,然后在子进程中调用shell命令,shell的输出可以采用读取文件的方式获得。
参数type可使用“r”表示读取,“w”表示写入
pclose则用于使用结束后关闭这个指针。
调用shell命令也可以用system函数,但是不能返回shell命令到结果。
有两个地方都进行来打开设备操作
vendor/marvell/generic/libcamera/V4LCameraAdapter.cpp V4LCameraAdapter::initialize()
vendor/marvell/generic/libcamera/CameraProperties.cpp CameraProperties::loadProperties()
vendor/marvell/berlin_bg2_freud/88DE3100_FILES/prebuild/ics/rootdir/ueventd.rc 中
/dev/video0 0666 root root/dev/video1 0666 root root
。。。。。