camera热插拔

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

。。。。。




  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值