remote-android / redroid-doc

redroid (Remote-Android) is a multi-arch, GPU enabled, Android in Cloud solution. Track issues / docs here
4.3k stars 309 forks source link

v4l2loopback can't get video #178

Open ArtBreguez opened 2 years ago

ArtBreguez commented 2 years ago

I'm trying to stream into redroid my desktop, I implemented de v4l2 Hal in redroid and got the USB Camera working through and 3-part-apk, now I need to use the default camera (back) as a webcam or streaming from my desktop.

I'm testing streaming my desktop through v4l2loopback into redroid with --device=/dev/video1:/dev/video1 when i run the container, got the video working on my host, when i run ls /dev/video* inside redroid it returns me /dev/video1, but when I try to open the camera it fails and when i plug my Webcam in my host it shows the camera image (not desktop), not sure what's going on here.

here some logs: Captura de Tela 2022-06-21 às 10 05 10

ps: Here's the issue (closed) when I implemented v4l2 Hal https://github.com/remote-android/redroid-doc/issues/174

diggleweb commented 2 years ago

@zhouziyang, I managed to configure the external camera by usb using v4l2, but i have this err:

E CameraService: cameraIdIntToStrLocked: input id 0 invalid: valid range  (0, 0)
E CameraService: shouldRejectSystemCameraConnection: Invalid camera id , 
W CameraService: Attempting to connect to system-only camera id , connection rejected
W CameraBase: An error occurred while connecting to camera 0: Status(-8, EX_SERVICE_SPECIFIC): '4: validateClientPermissionsLocked:1158: No camera device with ID "" isavailable'

How do I create a rule for this file_contexts in redroid? /dev/video([0-9])+ u:object_r:camera_device:s0 it is possible to create it in init.redroid.rc ? how to start the device according to the link https://source.android.com/security/selinux/device-policy

$ ps -Z | grep init | grep cam

system_u:system_r:initrc_t:s0  cameraserver    139      1   57636  22316 binder_thread_read  0 S cameraserver
system_u:system_r:initrc_t:s0  u0_a118        1332    137 13098508 126472 ep_poll            0 S com.shenyaocn.android.usbcamera
system_u:system_r:initrc_t:s0  u0_a116       14504    137 13281192 298020 ep_poll            0 S com.jacksoftw.webcam

$ dumpsys media.camera

== Service global info: ==

Number of camera devices: 0
Number of normal camera devices: 0
Number of public camera devices visible to API1: 0
Active Camera Clients:
[]
Allowed user IDs: 0

== Camera service events log (most recent at top): ==
  06-21 13:08:37 : REJECT device  client for package net.sourceforge.opencamera (PID 4908), reason: (Status(-8, EX_SERVICE_SPECIFIC): '4: validateClientPermissionsLocked:1158: No camera device with ID "" isavailable')
  06-21 12:52:59 : REJECT device  client for package net.sourceforge.opencamera (PID 4908), reason: (Status(-8, EX_SERVICE_SPECIFIC): '4: validateClientPermissionsLocked:1158: No camera device with ID "" isavailable')
  06-21 12:52:41 : REJECT device  client for package net.sourceforge.opencamera (PID 4908), reason: (Status(-8, EX_SERVICE_SPECIFIC): '4: validateClientPermissionsLocked:1158: No camera device with ID "" isavailable')
  06-21 12:49:33 : REJECT device  client for package net.sourceforge.opencamera (PID 1654), reason: (Status(-8, EX_SERVICE_SPECIFIC): '4: validateClientPermissionsLocked:1158: No camera device with ID "" isavailable')
  06-21 12:49:15 : USER_SWITCH previous allowed user IDs: <None>, current allowed user IDs: 0

== Vendor tags: ==

== Camera error traces (0): ==
  No camera traces collected.

$ cat /lib/modules/$(uname -r)/build/.config | grep CONFIG_USB_VIDEO_CLASS

CONFIG_USB_VIDEO_CLASS=m
CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y
...
CONFIG_ANDROID_BINDER_IPC=m
CONFIG_ANDROID_BINDERFS=m
CONFIG_ANDROID_BINDER_DEVICES=""

help me too, how to set into kernell to CONFIG_USB_VIDEO_CLASS=y?

zhouziyang commented 2 years ago

@ArtBreguez for v4l2loopback streaming, possible need V4L2 Camera HAL (https://cs.android.com/android/platform/superproject/+/android-12.0.0_r1:hardware/libhardware/modules/camera/3_4/;bpv=1;bpt=0)

you need claim new HIDLs in manifext.xml; and better to claim camera features to system (frameworks/native/data/etc/android.hardware.camera...)

zhouziyang commented 2 years ago

@diggleweb selinux is ignored (hook in libselinux.so), and should not care about the se rules. CONFIG_USB_VIDEO_CLASS is the config of your Host kernel. since build as a module (CONFIG_USB_VIDEO_CLASS=m), I think you can load via modprobe

ilmaisin commented 1 year ago

Now that many people have created issues about using cameras, could there be a some kind of documentation entry about that. I find all this very, very cryptic. Should I build a modified Docker container in order to use cameras?

dreamflasher commented 1 year ago

@ilmaisin That would be awesome. I am trying to figure this out as well, and there are a bunch of issues, some people seem to have a found a solution, but nobody posted a fully running solution, so everything needs to reinvent the wheel. Most people seem to need only a static image.

dreamflasher commented 1 year ago

@ArtBreguez How did you do the streaming with v4l2loopback into redroid? Did you need to modify redroid? I don't get the I implemented de v4l2 Hal in redroid part.