redroid-doc icon indicating copy to clipboard operation
redroid-doc copied to clipboard

为redroid添加虚拟摄像头

Open wulliwui opened this issue 1 year ago • 19 comments

我在宿主机上使用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识别并使用这两个摄像头

wulliwui avatar Jan 12 '24 07:01 wulliwui

Take a look at hardware/libhardware/modules/camera/3_4 (https://android.googlesource.com/platform/hardware/libhardware/+/master/modules/camera/3_4/README.md).

zhouziyang avatar Jan 14 '24 09:01 zhouziyang

mark

hongyang51 avatar Jan 17 '24 06:01 hongyang51

我在/redroid/device/redroid/redroid_x86_64/device.mk中添加了 USE_CAMERA_V4L2_HAL := true PRODUCT_PACKAGES += camera.v4l2 PRODUCT_PROPERTY_OVERRIDES += ro.hardware.camera=v4l2 如下图所示 image 当我编译成功并成功运行这个镜像后仍然无法找到摄像头设备 image 这个是我的启动命令 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识别并使用这两个摄像头设备

wulliwui avatar Jan 25 '24 10:01 wulliwui

Did you ever forget to add camera provider (hardware/interfaces/camera/provider/2.4/default)?

zhouziyang avatar Jan 26 '24 03:01 zhouziyang

下面是我修改的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

wulliwui avatar Jan 27 '24 02:01 wulliwui

我向manifest内添加了 image 我只修改了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) )" 我如何才能让我的相机工作?

wulliwui avatar Jan 27 '24 02:01 wulliwui

Yeah, this manifest entry is required. How about changing to <instance>legacy/0</instance>?

zhouziyang avatar Jan 28 '24 09:01 zhouziyang

我修改成legacy/0后能成功编译,但是仍然无法识别我的虚拟摄像头,我还需要修改哪些地方? 并且我添加了PRODUCT_PACKAGES += Camera2 希望预装系统原生相机,但是同样失败了。 以下是我查看logcat | grep -i camera得到的日志,似乎是驱动没有成功安装,我对这方面不是很熟悉,我应该修改哪些地方? redroid_x86_64:/ # logcat | grep -i camera grep: (standard input): Invalid argument grep: (standard input): Invalid argument 01-26 06:10:48.722 0 0 I init : Parsing file /system/etc/init/cameraserver.rc... 01-30 01:13:37.040 130 130 I cameraserver: Waiting for sensor privacy service 01-30 01:13:37.094 130 130 I HidlServiceManagement: Registered [email protected]::ICameraService/default 01-30 01:13:37.094 130 130 I CameraService: CameraService pinged cameraservice proxy 01-30 01:13:37.095 130 130 I cameraserver: ServiceManager: 0xf2580870 done instantiate 01-30 01:13:37.586 260 260 I SystemServerTiming: OnBootPhase_500_com.android.server.camera.CameraServiceProxy 01-30 01:13:37.586 260 260 D SystemServerTiming: OnBootPhase_500_com.android.server.camera.CameraServiceProxy took to complete: 0ms 01-30 01:13:37.640 260 260 I SystemServerTiming: OnBootPhase_520_com.android.server.camera.CameraServiceProxy 01-30 01:13:37.640 260 260 D SystemServerTiming: OnBootPhase_520_com.android.server.camera.CameraServiceProxy took to complete: 0ms 01-30 01:13:37.674 260 260 I SystemServerTiming: OnBootPhase_550_com.android.server.camera.CameraServiceProxy 01-30 01:13:37.674 260 260 D SystemServerTiming: OnBootPhase_550_com.android.server.camera.CameraServiceProxy took to complete: 0ms 01-30 01:13:37.897 260 260 I SystemServerTiming: OnBootPhase_600_com.android.server.camera.CameraServiceProxy 01-30 01:13:37.897 260 260 D SystemServerTiming: OnBootPhase_600_com.android.server.camera.CameraServiceProxy took to complete: 0ms 01-30 01:13:37.916 260 260 V StorageManagerService: Package com.android.camera2 has legacy storage 01-30 01:13:37.935 260 260 I SystemServerTiming: ssm.onStartUser-0_com.android.server.camera.CameraServiceProxy 01-30 01:13:37.936 260 260 D SystemServerTiming: ssm.onStartUser-0_com.android.server.camera.CameraServiceProxy took to complete: 1ms 01-30 01:13:38.306 260 630 I ActivityManager: ntv ?? 10749: cameraserver (pid 130) native 01-30 01:13:38.411 405 405 I CameraManagerGlobal: Connecting to camera service grep: (standard input): Invalid argument 01-30 01:13:38.981 260 280 I ActivityManagerTiming: OnBootPhase_1000_com.android.server.camera.CameraServiceProxy 01-30 01:13:38.981 260 280 D ActivityManagerTiming: OnBootPhase_1000_com.android.server.camera.CameraServiceProxy took to complete: 0ms 01-30 01:13:39.120 260 286 I SystemServerTimingAsync: ssm.onUnlockingUser-0_com.android.server.camera.CameraServiceProxy 01-30 01:13:39.120 260 286 D SystemServerTimingAsync: ssm.onUnlockingUser-0_com.android.server.camera.CameraServiceProxy took to complete: 0ms 01-30 01:13:39.549 260 286 I SystemServerTimingAsync: ssm.onUnlockedUser-0_com.android.server.camera.CameraServiceProxy 01-30 01:13:39.549 260 286 D SystemServerTimingAsync: ssm.onUnlockedUser-0_com.android.server.camera.CameraServiceProxy took to complete: 0ms 01-30 01:13:40.506 1494 1494 I [email protected]: [email protected] legacy service is starting. 01-30 01:13:40.514 1494 1494 E [email protected]: Could not load camera HAL module: -2 (No such file or directory) 01-30 01:13:40.514 1494 1494 E [email protected]: getProviderImpl: camera provider init failed! 01-30 01:13:40.517 1494 1494 E LegacySupport: Could not get passthrough implementation for [email protected]::ICameraProvider/legacy/0. 01-30 01:13:45.512 1539 1539 I [email protected]: [email protected] legacy service is starting. 01-30 01:13:45.521 1539 1539 E [email protected]: Could not load camera HAL module: -2 (No such file or directory) 01-30 01:13:45.521 1539 1539 E [email protected]: getProviderImpl: camera provider init failed! 01-30 01:13:45.524 1539 1539 E LegacySupport: Could not get passthrough implementation for [email protected]::ICameraProvider/legacy/0. 01-30 01:13:50.517 1542 1542 I [email protected]: [email protected] legacy service is starting. 01-30 01:13:50.525 1542 1542 E [email protected]: Could not load camera HAL module: -2 (No such file or directory) 01-30 01:13:50.525 1542 1542 E [email protected]: getProviderImpl: camera provider init failed! 01-30 01:13:50.528 1542 1542 E LegacySupport: Could not get passthrough implementation for [email protected]::ICameraProvider/legacy/0. 01-30 01:13:55.523 1545 1545 I [email protected]: [email protected] legacy service is starting. 01-30 01:13:55.530 1545 1545 E [email protected]: Could not load camera HAL module: -2 (No such file or directory) 01-30 01:13:55.530 1545 1545 E [email protected]: getProviderImpl: camera provider init failed!

wulliwui avatar Jan 29 '24 03:01 wulliwui

我看了下 在 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,这个跟我遇到的问题是否有关系

wulliwui avatar Jan 30 '24 02:01 wulliwui

我增加了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

wulliwui avatar Jan 31 '24 02:01 wulliwui

或者让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/ 下的方法 但是目前还没找到

wulliwui avatar Jan 31 '24 06:01 wulliwui

Try add LOCAL_PROPRIETARY_MODULE := true in Android.mk

zhouziyang avatar Jan 31 '24 10:01 zhouziyang

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)

wulliwui avatar Feb 01 '24 02:02 wulliwui

我尝试在mk里添加LOCAL_VENDOR_MODULE := true也报同样的错libjpeg_static_ndk与libcamera_client似乎由于Project Treble的原因供应商模块不能直接链接到系统命名空间中的库,我不清楚这要如何解决

wulliwui avatar Feb 02 '24 08:02 wulliwui

@zhouziyang 还没找到解决方法,是否有人解决了这个问题? 希望得到您的帮助

wulliwui avatar Feb 18 '24 06:02 wulliwui

我更换版本到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.

wulliwui avatar Feb 29 '24 07:02 wulliwui

Sorry, I cannot walk you through this camera emulation. Try debugging yourself, have fun~~

zhouziyang avatar Feb 29 '24 10:02 zhouziyang

楼主这是在做模拟器还是云手机之类的业务进行虚拟仿真呢?亚矩阵云手机平台的虚拟摄像头能力做的非常好,是圈内目前大家公认仿真能力最全面和最好的,建议可以去参考他们的API文档找下灵感呢。

apex-cmyk avatar Feb 12 '25 09:02 apex-cmyk

@wulliwui 楼主解决了吗?解决了的话可以分享一下思路吗

CNTcnt avatar Apr 08 '25 03:04 CNTcnt