美文网首页
UVCCamera(usb camera)适配Android9

UVCCamera(usb camera)适配Android9

作者: wasdzy111 | 来源:发表于2019-05-20 16:07 被阅读0次

    usb驱动来源https://github.com/jiangdongguo/AndroidUSBCamera
    android8以下没有问题;华为8x升级到android9之后发现不能连接摄像头,发现主要是协议过滤和获取到的不匹配:
    华为8x为例:
    android8 返回的是class =239 subClass = 2
    android9 返回的是class =14 subClass = 9
    适配:
    1、修改

    image.png
    <usb>
        <usb-device class="239" subclass="2" /> <!-- all device of UVC -->
        <usb-device class="14" subclass="9" /> <!-- 华为8x of UVC -->
        <usb-device class="2" subclass="0" />
    </usb>
    

    2、修改UVCCameraHelper.java

      public List<UsbDevice> getUsbDeviceList() {       
            List<DeviceFilter> deviceFilters = DeviceFilter
                    .getDeviceFilters(context, R.xml.device_filter);
            if (mUSBMonitor == null || deviceFilters == null)
                return null;
            //获取多个设备过滤条件;之前只返回了第一个
            return mUSBMonitor.getDeviceList(deviceFilters);
        }
    

    3、修改USBMonitor.java

        public List<UsbDevice> getDeviceList(final List<DeviceFilter> filters) throws IllegalStateException {
            if (destroyed) throw new IllegalStateException("already destroyed");
            final HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
            final List<UsbDevice> result = new ArrayList<UsbDevice>();
            if (deviceList != null) {
                if ((filters == null) || filters.isEmpty()) {
                    result.addAll(deviceList.values());
                } else {
                    for (final UsbDevice device : deviceList.values()) {
                        for (final DeviceFilter filter : filters) {
                            //增加判断filter.mSubclass == device.getDeviceSubclass()
                            if (((filter != null) && filter.matches(device)) || (filter != null && filter.mSubclass == device.getDeviceSubclass())) {
                                // when filter matches
                                if (!filter.isExclude) {
                                    result.add(device);
                                }
                                break;
                            }
                        }
                    }
                }
            }
            return result;
        }
    

    4、如果还发现有其他的class 和 subClass 直接添加在配置文件中既可
    若有误请联系反馈………………

    相关文章

      网友评论

          本文标题:UVCCamera(usb camera)适配Android9

          本文链接:https://www.haomeiwen.com/subject/egikzqtx.html