Proposal: webcam redirection via MS-RDPECAM (video capture virtual channel)
Summary
I'd like to add server-side support for MS-RDPECAM (Video Capture Virtual Channel Extension) to xrdp, so that a camera attached to the RDP client shows up as a camera inside the xrdp session (Zoom/Teams/Jitsi/browser etc.). Before writing the real implementation I'd like to agree on the design with you.
Earlier requests (#1786, #2324) were closed with the note that this would need USB redirection. MS-RDPECAM avoids that: it runs over two kinds of dynamic virtual channels, and the client sends already-encoded frames, so no USB is involved.
Feasibility test (done)
I wrote a small throw-away probe that uses the existing xrdpapi (WTSVirtualChannelOpenEx with WTS_CHANNEL_OPTION_DYNAMIC) from inside a session. No changes to xrdp were needed.
Setup: xrdp devel (0.10.80), Debian 13; client mstsc on Windows 11 24H2 (build 26200) with a built-in laptop camera.
Trace of what the probe saw:
open RDCamera_Device_Enumerator -> ok
enumerator: 2 bytes: 02 03 (SelectVersionRequest, client version 2)
SelectVersionResponse (version 2) sent
camera: "ACER QHD User Facing" channel: "RDCamera_Device_0" (DeviceAddedNotification)
open RDCamera_Device_0 -> ok
ActivateDevice -> SuccessResponse
StreamList -> 1 stream, FrameSourceTypes Color, Category Capture
MediaTypeList(0):
H264 2560x1440 30/1 fps
H264 1920x1080 30/1 fps
H264 1280x720 30/1 fps
H264 640x480 30/1 fps
H264 640x360 30/1 fps
StartStreams (H264 640x480) -> SuccessResponse
60 x SampleRequest/SampleResponse -> 150 KB Annex-B H.264
StopStreams / DeactivateDevice -> SuccessResponseffprobe shows a valid H.264 Main stream at 640x480 with 60 decodable frames.
Two things worth knowing for anyone testing:
- mstsc on current Windows 11 always opens the enumerator channel and sends
SelectVersionRequest, but it only sendsDeviceAddedNotificationif the camera is enabled for this connection. For unsigned .rdp files the security prompt now has a checkbox "Cameras and other video capture devices", and it is off by default.camerastoredirect:s:*in the .rdp file alone is not enough. - The server core data version xrdp announces (
0x00080004) is fine; I checked with a patched0x0008000Dfirst, and it made no difference.
Proposed design
New chansrv module
rdpecam.c(modelled onaudin.c). It uses the existingchansrv_drdynvc_open()API:- opens
RDCamera_Device_Enumeratoronce drdynvc is up and negotiates the version (1 or 2) - on
DeviceAddedNotificationopens the per-device channel named by the client and tracks devices (add/remove) - runs the device state machine: Activate → StreamList → MediaTypeList → StartStreams → SampleRequest loop (credit based, one or a few outstanding requests) → Stop/Deactivate
- activates the device only while a local application actually has the virtual camera open, so the client camera LED is off otherwise
- opens
Local camera inside the session. Two options, and I'd welcome your preference:
- v4l2loopback: chansrv (or a small helper) writes decoded frames into a
/dev/videoNloopback device. Works with everything that speaks V4L2 (browsers, Zoom, Teams-in-browser, OBS), but needs the out-of-tree kernel module and some per-session device allocation or permission handling on multi-user servers. - PipeWire: publish a camera node in the user's PipeWire session. No kernel module and naturally per-user, but only apps that use PipeWire/portal camera access see it (Firefox and Chromium do; many others don't yet).
My suggestion: v4l2loopback first (widest app support), with the sink behind a small interface so a PipeWire sink can be added later.
- v4l2loopback: chansrv (or a small helper) writes decoded frames into a
Formats. mstsc offered only H.264 here, so the server has to decode. I'd use the H.264 decoding already available at build time: libavcodec, or VA-API when it is enabled (
--enable-vaapialready exists for encoding). The sink gets YUY2/NV12/I420. If the client also offers MJPG or raw YUY2/NV12, the server can pick those instead.Configuration: a
[Channels]switch inxrdp.ini/sesman.ini(e.g.rdpecam=true), off by default at first. The build dependency is optional (--enable-rdpecam).
Questions
- Is a contribution along these lines welcome, and is chansrv the right place for it (rather than a separate daemon talking to chansrv)?
- Do you prefer v4l2loopback or PipeWire as the first sink, or should it be a runtime choice?
- Is a new optional dependency on libavcodec acceptable for decoding, or should it be VA-API/openh264 only?
- Any conventions for the config key name and default?
I'm happy to do the implementation and testing, including with FreeRDP's rdpecam client in addition to mstsc.
Source: neutrinolabs/xrdp