Something went wrong. Try again.
An experimental port of NetBSD, FreeBSD, OpenBSD, and XNU to unkernel unkernel.dev
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475// SPDX-License-Identifier: MIT// Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>// Camera: the browser's camera and microphone, shown in mpv windows on the// page's Wayland desktop (Debian). camera.sh takes the camera's H.264// (kwcam's host encoder, .agents/kernel/devices.md) and decodes it on guest// VA-API (.agents/va.md), so no camera pixels go through the guest's CPU:// - --untimed: the v4l2 input's packets carry no timestamps, so mpv would// pace them at a rate it makes up and fall behind a faster camera;// - --profile=low-latency: no demuxer buffering or probing (the input// format with -o-add, which keeps the profile's fflags=+nobuffer);// - --autofit: a 640x480 picture opens in a window that is too small.// `raw` takes YUV 4:2:0 frames instead, drawn through guest GL (slower:// about 14 frames/s at 640x480 on a fake camera, 2026-11-29). mic.sh draws// the microphone (ALSA's default capture) as a waveform with a level meter,// and plays none of it back.import type { TerminalApp } from "../types.ts";
const COMMON = "--no-config --profile=low-latency --untimed --osc=no --load-scripts=no --ytdl=no --autofit=75%x75%";
const CAMERA = String.raw`#!/bin/sh# The camera (/dev/video0) in a window on the page.# ./camera.sh [480|720|1080] [raw] [mpv options]# 480 (640x480) by default; raw: uncompressed frames drawn through guest GL# instead of the host's H.264 decoded on VA-API. q quits, f is full screen.size=640x480 raw=while [ $# -gt 0 ]; do case $1 in 480) size=640x480 ;; 720) size=1280x720 ;; 1080) size=1920x1080 ;; raw) raw=1 ;; *) break ;; esac shiftdone[ -e /dev/video0 ] || { echo "No camera: /dev/video0 is missing (the page's camera is off with ?cam=0)."; exit 1; }echo "The browser asks for the camera the first time; frames are black until it is allowed."echo "q quits, f is full screen."if [ -n "$raw" ]; then exec mpv ${COMMON} --vo=gpu --hwdec=no \ --demuxer-lavf-o-add=input_format=yuv420p --demuxer-lavf-o-add=video_size=$size \ "$@" av://v4l2:/dev/video0fiexec mpv ${COMMON} --hwdec=vaapi --vo=dmabuf-wayland \ --demuxer-lavf-o-add=input_format=h264 --demuxer-lavf-o-add=video_size=$size \ "$@" av://v4l2:/dev/video0`;
// showwaves draws the signal, showvolume the level as a bar over it; mpv// has no audio output to feed (no [ao] in the graph), so nothing echoes.const GRAPH = "[aid1]asplit[a][b];[a]showwaves=s=800x300:mode=cline:rate=30:colors=0x22c55e[w];[b]showvolume=r=30:w=760:h=24:f=0.9:dm=1[v];[w][v]overlay=x=20:y=10:format=auto[vo]";
const MIC = String.raw`#!/bin/sh# The microphone (ALSA's default capture) as a waveform with a level meter,# in a window on the page. Nothing is played back.# ./mic.sh [mpv options]echo "The browser asks for the microphone the first time; it is silent until it is allowed."echo "q quits."exec mpv ${COMMON} --vo=gpu --force-window=yes --title=Microphone \ --lavfi-complex='${GRAPH}' "$@" av://alsa:default`;
export default { id: "camera", title: "Camera", desc: "The browser's camera and microphone in windows on the page: the camera's H.264 decoded on VA-API in mpv, the microphone as a waveform and level meter", // A camera body with its lens. icon: { svg: '<path fill-rule="evenodd" d="M9 4h6l1.6 2.2H20a2 2 0 0 1 2 2V18a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V8.2a2 2 0 0 1 2-2h3.4Zm3 4.3a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9Zm0 2a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5Z"/>' }, colors: ["#14b8a6", "#042f2e"], needs: { camera: true, wayland: true }, packages: { debian: ["mpv"] }, files: { "camera.sh": { content: CAMERA, mode: 0o755 }, "mic.sh": { content: MIC, mode: 0o755 } }, commands: ["./camera.sh"],} satisfies TerminalApp;