Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ADR-0019: Phone as webcam: shell-helper camera into a v4l2loopback device owned by the daemon

  • Status: accepted
  • Date: 2026-11-28
  • Deciders: maintainer, from the M4 research round (docs/notes/m4-research-shell-helper.md section 8, docs/notes/m4-research-desktop.md section C.2)
  • Tags: android, linux, packaging

Context

Milestone 4.3 makes the phone’s camera usable as a webcam in video call apps on the PC. Zoom, Teams, Discord, Slack and the default browser builds on Mint 22 / Ubuntu 24.04 list V4L2 devices only; PipeWire camera nodes are not shown without the user changing browser settings. A V4L2 device that is not backed by hardware needs the out-of-tree kernel module v4l2loopback, and loading a module needs root.

On the phone, the shell user holds android.permission.CAMERA and can open Camera2 from the helper without a visible activity or a foreground service.

Decision

  • Capture in the shell helper (enhanced tier only). CameraManager through its hidden constructor on the fake context, with the Android 16 ActivityManager context patch. The camera renders straight into a MediaCodec input surface at one of the sizes the camera lists for MediaCodec; there is no GL stage and no rotation on the phone. Ability camera is probed at start (a camera list can be read). Messages CameraListRequest/CameraList, CameraStart, CameraConfigure, CameraStop, CameraEnded, and a CAMERA connection with the mirror record framing (shell.proto). One capture at a time.
  • The daemon owns the webcam. It reads the CAMERA connection and runs appsrc ! h264parse ! <decoder> ! videoflip ! videoconvert ! videoscale (borders) ! videorate ! video/x-raw,format=YUY2,<fixed size and rate> ! v4l2sink. The device format is fixed for as long as the daemon holds the device (default 1280 x 720 at 30 fps); rotation, flip and a camera switch change the picture inside that frame, never the format. Cargo feature webcam in tetherd, default on, shares the GStreamer dependency with audio.
  • The webcam is a switch per phone (Webcam), like phone audio: on means the phone’s camera is open and the V4L2 device is fed. One phone at a time feeds the device. There is no start-on-demand when a call app opens the device: v4l2loopback 0.12.7 (Ubuntu 24.04, Mint 22) has no client-usage event.
  • The device stays open across captures. An output stage (appsrc ! v4l2sink) is held while the switch is on and is fed black frames whenever no capture runs; each capture gets its own decode stage. A camera switch, a retry or a helper restart does not close the device. The output caps are taken from the sink pad, because v4l2sink rejects caps without the device’s colorimetry.
  • Orientation is set by the user (rotation 0/90/180/270, flip), stored per phone. The helper reports facing and sensor orientation; it does not track how the phone is held.
  • v4l2loopback set-up is explicit and guided, never implicit. The daemon reports the machine’s state (WebcamSetupState: not_installed, not_loaded, no_device, ready, plus a reason such as a Secure Boot key rejection) and uses the loopback device whose card label is Tether Phone Camera (or the configured webcam_device). SetUpWebcam runs the packaged script /usr/libexec/tether/tether-webcam-setup through pkexec (polkit action org.tether.webcam-setup): load runs modprobe v4l2loopback devices=1 video_nr=<free> card_label="Tether Phone Camera" exclusive_caps=1, or adds a device with v4l2loopback-ctl add when the module is already loaded by someone else (v4l2loopback 0.13 and later only; 0.12.7 has no control device, there the script stops with an instruction to unload the module); persist also writes /etc/modprobe.d/tether-webcam.conf and /etc/modules-load.d/tether-webcam.conf; remove deletes those files. The script takes no free-form arguments.
  • Packaging: Suggests: v4l2loopback-dkms, v4l2loopback-utils. The package is not pulled in by default because it installs DKMS, kernel headers and a compiler. The set-up page shows the install command when the module is missing.

Consequences

Positive

  • Every call app sees the camera, with no visible activity on the phone.
  • No root in the daemon; one polkit prompt, with a fixed script.
  • The device format never changes under a consumer.

Negative / risks

  • DKMS can fail after a kernel update; Secure Boot needs an enrolled machine owner key. Both can only be explained, not fixed, by Tether.
  • With exclusive_caps=1 the device is listed by apps only while the daemon feeds it, so the switch must be on before the call app looks.
  • The camera stays on while the switch is on (privacy indicator on the phone, battery).
  • Camera access from shell depends on hidden API details that changed in Android 16 once already.
  • Behaviour with the phone locked and with the camera privacy switch on is not known before the first device test.

Alternatives considered

  • PipeWire Video/Source node (pipewiresink mode=provide): no root and no module, but not listed by the call apps and default browsers on the target distributions. Kept as a possible second output later (ADR-0018).
  • Camera in the normal app (foreground service type camera): works without adb, but must be started from a visible activity each time and shows an ongoing notification. Left for a later milestone as the fallback for phones without the enhanced tier.
  • Loading the module from the package’s postinst: surprises users who do not use the webcam and fails noisily under Secure Boot.
  • Rotating on the phone with a GL stage: more hidden-API surface in the helper for something the desktop does in one element.