redroid-doc
redroid-doc copied to clipboard
为redroid添加虚拟摄像头
我在宿主机上使用v4l2loopback虚拟了2个摄像头 并在宿主机中验证过他们能正常使用 我在docker run的时候添加了这两个命令--device=/dev/video0 --device=/dev/video1 但是在redroid启动后,系统无法识别并使用这两个摄像头 redroid_x86_64:/ $ su redroid_x86_64:/ # ls /dev/video* /dev/video0 /dev/video1 redroid_x86_64:/ # camera2 list /system/bin/sh: camera2: inaccessible or not found 我应该怎么做,可以让redroid识别并使用这两个摄像头
Take a look at hardware/libhardware/modules/camera/3_4 (https://android.googlesource.com/platform/hardware/libhardware/+/master/modules/camera/3_4/README.md).
mark
我在/redroid/device/redroid/redroid_x86_64/device.mk中添加了
USE_CAMERA_V4L2_HAL := true
PRODUCT_PACKAGES += camera.v4l2
PRODUCT_PROPERTY_OVERRIDES += ro.hardware.camera=v4l2
如下图所示
当我编译成功并成功运行这个镜像后仍然无法找到摄像头设备
这个是我的启动命令
sudo docker run -itd --rm --privileged \
-v ~/data:/data \ -p 5555:5555 \ --device /dev/video0:/dev/video0 \ --device /dev/video1:/dev/video1 \ redroid \ androidboot.redroid_width=1080 \ androidboot.redroid_height=1920 \ androidboot.redroid_dpi=480 \
其中> --device /dev/video0:/dev/video0 \
--device /dev/video1:/dev/video1 \这两个摄像头是我使用v4l2loopback虚拟出来的虚拟摄像头设备,并且我测试过他们正常工作, 我应该怎么做才能让redroid识别并使用这两个摄像头设备
Did you ever forget to add camera provider (hardware/interfaces/camera/provider/2.4/default)?
下面是我修改的redroid_x86_64/device.mk 这样仍然无法识别我的虚拟相机
PRODUCT_COPY_FILES +=
device/redroid/mediacodec.policy.x86:$(TARGET_COPY_OUT_VENDOR)/etc/seccomp_policy/mediacodec.policy \
PRODUCT_PROPERTY_OVERRIDES +=
ro.enable.native.bridge.exec=1
ro.dalvik.vm.isa.arm64=x86_64
ro.dalvik.vm.isa.arm=x86
ro.dalvik.vm.native.bridge=libnb.so \
$(call inherit-product, device/redroid-prebuilts/prebuilts_x86.mk) USE_CAMERA_V4L2_HAL := true
PRODUCT_PROPERTY_OVERRIDES += ro.hardware.camera=v4l2
PRODUCT_PACKAGES +=
[email protected]
[email protected]
[email protected]
[email protected]
camera.v4l2
我向manifest内添加了
我只修改了device.mk与manifest,编译报错
[ 74% 79186/106451] build out/target/product/redroid_x86_64/obj/PACKAGING/check_vintf_all_intermediates/check_vintf_compatible_log
FAILED: out/target/product/redroid_x86_64/obj/PACKAGING/check_vintf_all_intermediates/check_vintf_compatible_log
/bin/bash -c "(echo -n -e 'Deps: \n ' > out/target/product/redroid_x86_64/obj/PACKAGING/check_vintf_all_intermediates/check_vintf_compatible_log ) && (sed 's/ /\n /g' <<< "out/target/product/redroid_x86_64/system/etc/vintf/compatibility_matrix.1.xml out/target/product/
redroid_x86_64/system/etc/vintf/compatibility_matrix.2.xml out/target/product/redroid_x86_64/system/etc/vintf/compatibility_matrix.3.xml out/target/product/redroid_x86_64/system/etc/vintf/compatibility_matrix.4.xml out/target/product/redroid_x86_64/system/etc/vintf/compatib
ility_matrix.5.xml out/target/product/redroid_x86_64/system/etc/vintf/compatibility_matrix.device.xml out/target/product/redroid_x86_64/system/etc/vintf/compatibility_matrix.legacy.xml out/target/product/redroid_x86_64/system/etc/vintf/manifest.xml out/target/product/redroi
d_x86_64/system/etc/vintf/manifest/[email protected] out/target/product/redroid_x86_64/system/etc/vintf/manifest/[email protected] out/target/product/redroid_x86_64/system/etc/vintf/manifest/[email protected]
out/target/product/redroid_x86_64/system/etc/vintf/manifest/[email protected] out/target/product/redroid_x86_64/system/etc/vintf/manifest/manifest_media_c2_software.xml out/target/product/redroid_x86_64/system/system_ext/etc/vintf/man
ifest.xml out/target/product/redroid_x86_64/vendor/etc/vintf/compatibility_matrix.xml out/target/product/redroid_x86_64/vendor/etc/vintf/manifest.xml out/target/product/redroid_x86_64/vendor/etc/vintf/manifest/[email protected] out/target/product/redroid_
x86_64/vendor/etc/vintf/manifest/[email protected] out/target/product/redroid_x86_64/vendor/etc/vintf/manifest/[email protected] out/target/product/redroid_x86_64/vendor/etc/vintf/manifest/[email protected]
l out/target/product/redroid_x86_64/vendor/etc/vintf/manifest/[email protected] out/target/product/redroid_x86_64/vendor/etc/vintf/manifest/[email protected] out/target/product/redroid_x86_64/vendor/etc/vintf/manifest/android.h
[email protected] out/target/product/redroid_x86_64/vendor/etc/vintf/manifest/[email protected] out/target/product/redroid_x86_64/vendor/etc/vintf/manifest/power-default.xml" >> out/target/product/redroid_x86_64/obj/PACKAGING
/check_vintf_all_intermediates/check_vintf_compatible_log ) && (echo -n -e 'Args: \n ' >> out/target/product/redroid_x86_64/obj/PACKAGING/check_vintf_all_intermediates/check_vintf_compatible_log ) && (cat <<< " --dirmap /system:out/target/product/redroid_x86_64/system --
dirmap /vendor:out/target/product/redroid_x86_64/vendor --dirmap /odm:out/target/product/redroid_x86_64/vendor/odm --dirmap /product:out/target/product/redroid_x86_64/system/product --dirmap /system_ext:out/target/product/redroid_x86_64/system/system_ext --property ro.prod
uct.first_api_level=30" >> out/target/product/redroid_x86_64/obj/PACKAGING/check_vintf_all_intermediates/check_vintf_compatible_log ) && (echo "For ODM SKU = EMPTY_ODM_SKU_PLACEHOLDER, vendor SKU = EMPTY_VENDOR_SKU_PLACEHOLDER" >> out/target/product/redroid_x86_64/obj/PA
CKAGING/check_vintf_all_intermediates/check_vintf_compatible_log; ( out/host/linux-x86/bin/checkvintf --check-compat --dirmap /system:out/target/product/redroid_x86_64/system --dirmap /vendor:out/target/product/redroid_x86_64/vendor --dirmap /odm:out/target/product/redroid
_x86_64/vendor/odm --dirmap /product:out/target/product/redroid_x86_64/system/product --dirmap /system_ext:out/target/product/redroid_x86_64/system/system_ext --property ro.product.first_api_level=30 --property ro.boot.product.hardware.sku= --property ro.boot.product.vendo
r.sku= >> out/target/product/redroid_x86_64/obj/PACKAGING/check_vintf_all_intermediates/check_vintf_compatible_log 2>&1 ) || (cat out/target/product/redroid_x86_64/obj/PACKAGING/check_vintf_all_intermediates/check_vintf_compatible_log && exit 1) )"
我如何才能让我的相机工作?
Yeah, this manifest entry is required.
How about changing to <instance>legacy/0</instance>?
我修改成
我看了下 在 130|redroid_x86_64:/ # ls /system/lib/hw [email protected] audio.a2dp.default.so camera.v4l2.so 这里确实存在了camera.v4l2.so,那就是[[email protected]]没有找到这个hal,一般来说相机的hal是在device.mk里指定,我在~/redroid/device/redroid/redroid_x86_64下的device.mk中确实添加了USE_CAMERA_V4L2_HAL := true PRODUCT_PACKAGES += camera.v4l2 PRODUCT_PROPERTY_OVERRIDES += ro.hardware.camera=v4l2 我查看了dmesg [72781.514992] init: starting service 'vendor.camera-provider-2-4'... [72781.535743] init: Service 'vendor.camera-provider-2-4' (pid 1956) exited with status 1 [72781.535753] init: Sending signal 9 to service 'vendor.camera-provider-2-4' (pid 1956) process group... [72786.521465] init: starting service 'vendor.camera-provider-2-4'... [72786.542310] init: Service 'vendor.camera-provider-2-4' (pid 1957) exited with status 1 [72786.542320] init: Sending signal 9 to service 'vendor.camera-provider-2-4' (pid 1957) process group... 也一直在报错 我是哪个步骤出错了么? 并且我没有看到有预装原相机app,这个跟我遇到的问题是否有关系
我增加了log发现[email protected]在初始化的时候在/vendor/lib/hw/camera.v4l2.so找so 但是我的camera.v4l2.so在/system/lib/hw下 这个是哪里配置有问题? 根据他的加载代码,他将会在这几个路径下查找驱动 static int hw_module_exists(char *path, size_t path_len, const char *name, const char *subname) { snprintf(path, path_len, "%s/%s.%s.so", HAL_LIBRARY_PATH3, name, subname); if (path_in_path(path, HAL_LIBRARY_PATH3) && access(path, R_OK) == 0) return 0;
snprintf(path, path_len, "%s/%s.%s.so",
HAL_LIBRARY_PATH2, name, subname);
if (path_in_path(path, HAL_LIBRARY_PATH2) && access(path, R_OK) == 0)
return 0;
#ifndef ANDROID_VNDK snprintf(path, path_len, "%s/%s.%s.so", HAL_LIBRARY_PATH1, name, subname); if (path_in_path(path, HAL_LIBRARY_PATH1) && access(path, R_OK) == 0) return 0; #endif
return -ENOENT;
} 这里的HAL_LIBRARY_PATH3 2 分别对应/odm/lib/hw/ 和/vendor/lib/hw/ 如何修改mk才能让camera.v4l2.so安装到/vendor/lib/hw/ 下, 或者让HAL_LIBRARY_PATH3 2 其中一个指向/system/lib/hw 下面是我加的日志 01-31 02:24:22.296 1555 1555 E HAL : hw_get_module_by_class: name camera 01-31 02:24:22.296 1555 1555 E HAL : hw_get_module_by_class: prop_name ro.hardware.camera 01-31 02:24:22.296 1555 1555 E HAL : hw_module_exists path: /odm/lib/hw/camera.v4l2.so 01-31 02:24:22.296 1555 1555 E HAL : hw_module_exists path: /vendor/lib/hw/camera.v4l2.so 01-31 02:24:22.296 1555 1555 E HAL : hw_module_exists path: /odm/lib/hw/camera.redroid.so 01-31 02:24:22.296 1555 1555 E HAL : hw_module_exists path: /vendor/lib/hw/camera.redroid.so 01-31 02:24:22.296 1555 1555 E HAL : hw_module_exists path: /odm/lib/hw/camera.default.so 01-31 02:24:22.296 1555 1555 E HAL : hw_module_exists path: /vendor/lib/hw/camera.default.so
或者让HAL_LIBRARY_PATH3 2 其中一个指向/system/lib/hw这个方式无法使用 01-31 06:12:39.959 1559 1559 E linker : library "/system/lib/hw/camera.v4l2.so" ("/system/lib/hw/camera.v4l2.so") needed or dlopened by "/system/lib/libvndksupport.so" is not accessible for the namespace: [name="(default)", ld_library_paths="", default_library_paths="/vendor/lib:/vendor/lib/hw:/vendor/lib/egl", permitted_paths="/odm:/vendor:/system/vendor"] 我现在正在寻找将驱动安装到/vendor/lib/hw/ 下的方法 但是目前还没找到
Try add LOCAL_PROPRIETARY_MODULE := true in Android.mk
hardware/libhardware/modules/camera/3_4/Android.mk 内添加了LOCAL_PROPRIETARY_MODULE := true报错 FAILED: hardware/libhardware/modules/camera/3_4/Android.mk: error: "camera.v4l2 (native:vendor) can not link against libjpeg_static_ndk (native:platform)" hardware/libhardware/modules/camera/3_4/Android.mk: error: "camera.v4l2 (native:vendor) can not link against libcamera_client (native:platform)" hardware/libhardware/modules/camera/3_4/Android.mk: error: "camera.v4l2 (native:vendor) can not link against libjpeg_static_ndk (native:platform)" hardware/libhardware/modules/camera/3_4/Android.mk: error: "camera.v4l2 (native:vendor) can not link against libcamera_client (native:platform)" build/make/core/main.mk:946: error: exiting from previous errors. 02:18:02 ckati failed with: exit status 1
failed to build some targets (35 seconds)
我尝试在mk里添加LOCAL_VENDOR_MODULE := true也报同样的错libjpeg_static_ndk与libcamera_client似乎由于Project Treble的原因供应商模块不能直接链接到系统命名空间中的库,我不清楚这要如何解决
@zhouziyang 还没找到解决方法,是否有人解决了这个问题? 希望得到您的帮助
我更换版本到android8.1.0 现在驱动已经能正常加载,看日志报错是没有权限打开/dev/video0 这个要如何解决? 下面是详细日志 mac@ubuntu:~$ adb shell redroid_x86_64:/ $ logcat | grep -i camera 02-29 06:58:23.524 43 43 I [email protected]: Camera provider Service is starting. 02-29 06:58:23.567 43 43 D vndksupport: Loading /vendor/lib/hw/[email protected] from current namespace instead of sphal namespace. 02-29 06:58:23.683 43 43 E V4L2CameraHAL: V4L2CameraHAL:84: failed to open /dev/video1 (Permission denied). 02-29 06:58:23.683 43 43 E V4L2CameraHAL: V4L2CameraHAL:84: failed to open /dev/video0 (Permission denied). 02-29 06:58:23.683 43 43 I [email protected]: Loaded "V4L2 Camera HAL v3" camera module 02-29 06:58:23.697 43 43 I ServiceManagement: Removing namespace from process name [email protected] to [email protected]. 02-29 06:58:23.697 43 43 I [email protected]: Registration complete for [email protected]::ICameraProvider/legacy/0. 02-29 06:58:23.758 60 60 I cameraserver: ServiceManager: 0xe9b37340 02-29 06:58:23.758 60 60 I CameraService: CameraService started (pid=60) 02-29 06:58:23.758 60 60 I CameraService: CameraService process starting 02-29 06:58:23.758 60 60 I CameraProviderManager: Connecting to new camera provider: legacy/0, isRemote? 1 02-29 06:58:23.759 60 60 I CameraProviderManager: Camera provider legacy/0 ready with 0 camera devices 02-29 06:58:23.759 60 146 W CameraProviderManager: addProviderLocked: Camera provider HAL with name 'legacy/0' already registered 02-29 06:58:25.010 161 161 I SystemServer: StartCameraServiceProxy 02-29 06:58:25.010 161 161 I SystemServiceManager: Starting com.android.server.camera.CameraServiceProxy 02-29 06:58:25.011 161 274 I ServiceThread: Enabled StrictMode logging for CameraService_proxy looper. 02-29 06:58:25.011 161 161 D SystemServerTiming: StartCameraServiceProxy took to complete: 1ms 02-29 06:58:25.511 322 322 I CameraManagerGlobal: Connecting to camera service 02-29 06:58:25.518 322 322 W StatusBar: at com.android.systemui.statusbar.phone.StatusBar.isCameraAllowedByAdmin(StatusBar.java:5484) 02-29 06:58:25.518 322 322 W StatusBar: at com.android.systemui.statusbar.phone.KeyguardBottomAreaView.updateCameraVisibility(KeyguardBottomAreaView.java:382) 02-29 06:58:25.574 322 322 W StatusBar: at com.android.systemui.statusbar.phone.StatusBar.isCameraAllowedByAdmin(StatusBar.java:5484) 02-29 06:58:25.574 322 322 W StatusBar: at com.android.systemui.statusbar.phone.KeyguardBottomAreaView.updateCameraVisibility(KeyguardBottomAreaView.java:382) 02-29 06:58:25.609 322 322 W StatusBar: at com.android.systemui.statusbar.phone.StatusBar.isCameraAllowedByAdmin(StatusBar.java:5484) 02-29 06:58:25.609 322 322 W StatusBar: at com.android.systemui.statusbar.phone.KeyguardBottomAreaView.updateCameraVisibility(KeyguardBottomAreaView.java:382) ^C 130|redroid_x86_64:/ $ dumpsys media.camera
== Service global info: ==
Number of camera devices: 0 Number of normal camera devices: 0 Active Camera Clients: [] Allowed user IDs: 0
== Camera service events log (most recent at top): == 02-29 06:58:25 : USER_SWITCH previous allowed user IDs: <None>, current allowed user IDs: 0
== Camera Provider HAL legacy/0 (v2.4, remote) static info: 0 devices: ==
== Vendor tags: ==
Dumping vendor tag descriptors for vendor with id 3854507339 Dumping configured vendor tag descriptors: None set
== Camera error traces (0): == No camera traces collected.
Sorry, I cannot walk you through this camera emulation. Try debugging yourself, have fun~~
楼主这是在做模拟器还是云手机之类的业务进行虚拟仿真呢?亚矩阵云手机平台的虚拟摄像头能力做的非常好,是圈内目前大家公认仿真能力最全面和最好的,建议可以去参考他们的API文档找下灵感呢。
@wulliwui 楼主解决了吗?解决了的话可以分享一下思路吗