Files
piik/docs/research/camera-and-microphone.md
T
AAA 066e218d84 fix(media): improve connection recovery and capture compatibility (#498)
## Problem and outcome

Stale ICE and transport callbacks, interrupted media ownership, and optional encoder capabilities could break otherwise recoverable sharing sessions. This maintenance phase corrects those owners across Web, Native and embedded SFU, improves current-state diagnostics, and finishes the affected UI and documentation animation paths.

Android, QR invitations and App/Server headline presentation stay on their feature branch. This PR contains the accepted maintenance scope only.

## Release notes

**Play together. Your turn!**

Approved friends can play together with shared keyboard and mouse controls or optional gamepads.

**远程同乐,轮到你啦!**

获准的朋友可以共用键鼠,或使用可选手柄,一起玩本地多人游戏。

### English

This maintenance update improves connection recovery, capture compatibility and troubleshooting for existing Piik rooms.

- Keep ICE candidates and gathering completion tied to their current connection. Preserve Viewer route preferences through reconnection and retry newly available Peer opportunities after SFU fallback.
- Correct picture and voice ownership during restart, source replacement and connection retirement. Report failed picture dependencies while keeping room voice available.
- Separate capture and forwarding statistics and isolate pooled sender attachment failures.
- Improve Windows H.264 compatibility with optional encoder properties, retain safe capture failure codes, and keep shared sound volume usable without microphone support.
- Improve remote input continuity and mouse responsiveness after idle.
- Fix fullscreen handling in some mobile browsers, source-picker refresh, delayed chat confirmations, starred-site startup and local App requests. Refine control motion and reduced-motion behavior.
- Restore the mascot's face and shared animation lifecycle in the documentation header.
- Include current connection and playback state in diagnostic exports, update Zod to 4.6.6 and simplify shared lifecycle code.

Existing 2.x protocols, configuration and default quality settings are preserved.

### 中文

本次维护更新改善现有房间的连接恢复、采集兼容性和故障诊断。

- ICE 候选和收集结束事件跟随当前连接;重连保留观众线路偏好,SFU 兜底后出现新的可用 P2P 机会仍可尝试。
- 修正重启、换源和连接结束时的画面与语音生命周期;语音继续时,画面失败会明确反馈。
- 区分采集与转发统计,隔离编码池中单个输出连接的失败。
- 改善 Windows H.264 可选属性兼容性,保留有效的采集失败原因;没有麦克风能力时也能调整共享声音音量。
- 修复部分移动浏览器全屏、选源刷新、迟到聊天确认、收藏站点启动和本机 App 请求问题,打磨控件动效及减少动态效果行为。
- 修复文档导航 mascot 面部一直隐藏的问题,接回共用动画生命周期。
- 诊断导出补取当前连接与播放状态,升级 Zod 至 4.6.6,精简共用生命周期代码。

沿用现有 2.x 协议、配置和画质默认值。Android、二维码邀请及 App/Server 新增的 HEADLINE 展示留待后续版本。

## Verification

- `npm run check`: type-check, 98 test files / 1,765 tests, production Web build passed.
- `npm run check:go-core`: Go formatting, tests, vet, Windows/Linux builds passed; Darwin builds require the native CI runners.
- `npm run check:native`: current Windows capture compilation, fixtures and capability probe passed.
- `npm run build:website`, TypeScript and repository hygiene checks passed after the documentation-brand fix.
- Existing controlled media lifecycle and P2P/SFU voice acceptance covered the retained route/transport changes. Final local browser acceptance covered actual sharing and pause/resume, fullscreen, source refresh, voice/keyboard/settings, 320px to desktop layouts, both themes and all presentation modes. Documentation brand was reproduced broken, then verified on load, replay and reduced motion.
- Independent scoped reviews found no integration blocker.

## Impact

Patch release v2.4.1. Existing 2.x wire, configuration, authority, capacity and default quality contracts remain intact; no data migration. Source volume no longer depends on microphone availability. Zod 4.6.6 fixes GHSA-mrhx-c7xc-m3w5.

The device-specific Windows reports #495 and #452 remain under investigation; this PR improves compatibility and diagnostics without claiming those reports fully resolved. Physical macOS acceptance remains with its native runner/device checks.
2026-10-24 12:30:39 -04:00

12 KiB
Raw Blame History

Camera And Host Microphone

Status: integrated into the ordinary Host UI and accepted for release. Platform evidence is summarized in verification status.

Scope And Ownership

The current source restores optional commentary under Sharing settings → Sound → Include my microphone, independently of room voice. The stable Browser output and Native mixer described below have a current UI consumer. Commentary starts off for each new share; enabling room voice does not change it. Both may remain enabled under the current microphone contract. The normal-page room-voice gate verified simultaneous room microphone and source commentary delivery, commentary retirement on share stop, and the next share's default-off state with synthetic devices. This does not establish physical echo or device acceptance.

The existing source picker offers Browser, Camera, Window and Screen in that order, defaulting to Window when an App is detected. Without an App, it shows only Browser and Camera, defaulting to Browser. Mobile browsers can choose Camera when screen capture is unavailable. There is one active picture; capture, replacement, pause and stop retain their existing Host session and route owners. Camera permission never includes an implicit microphone request. HTTPS or localhost is required for device capture.

The Host microphone mixes commentary with Browser source audio into one outgoing audio track through Web Audio. The existing P2P, relay and SFU senders borrow that stream. Microphone mute preserves the mixed track and source replacement preserves microphone intent. Denial or unplugging leaves healthy video alone; retiring the share closes audio resources and discards late permission results. The Host preview stays muted. Viewers receive the combined sound with their existing volume control and never request microphone permission.

App native screen/window capture mixes selected-device microphone PCM with source audio before the existing Opus encoder. Windows uses WASAPI, macOS uses AVAudioEngine and Linux uses PulseAudio/PipeWire through GStreamer. Platform converters supply 48 kHz stereo PCM; one 20 ms output clock consumes each input once, with a bounded queue and silence for missing samples. This bounds backlog; it does not replace platform resampling or establish long-term clock-drift and echo-cancellation performance.

New App/page pairs opt into a stable mixed audio track from share startup, even with source sound disabled. Opening or muting the microphone and replacing the source preserve that track, encoder, preview and route owners. Source sound and microphone availability remain separate reported facts. Old Apps/pages retain the existing capture contract through capability negotiation; microphone capture starts only after an explicit action. Permission waiting is cancellable and does not hold the control reader. Device loss retires only that audio input.

Windows native capture and the App-to-Viewer path have local acceptance evidence. macOS/Linux microphone compilation is checked by native-platform packaging. Real audio-level/echo checks, macOS/Linux device acceptance and actual phone capture remain physical evidence limits; synthetic tests do not establish those results. The owner authorized release with those limits retained. The Host preview remains muted on every path.

This scope adds no room messages, ports, chat, Viewer microphone or emoji interactions. Microphone, pause, source replacement and stop share one action row below the picture, outside the playback controls and television status. Their order and meaning stay the same in Chinese, English and pure-visual modes. Source-sound details describe the raw capture input; microphone intent and Viewer playback volume are separate facts. Pausing the share silences the mixed output and temporarily disables microphone toggling without clearing its intent. Sharing settings open from the action dock. Picture presets/parameters and sound form separate groups, with microphone device/input gain under sound and a further disclosure for connection/codec options. The panel expands in page flow, pushing the couch down; video presets remain available before capture starts. The dock keeps only its frequent mute action; camera selection stays with source selection. The default follows the system; an explicit selection never silently falls back to another device. Browser capture and native capture keep separate device IDs for the page lifetime. Enumeration does not request permission. Browser labels may appear only after the first grant; refresh and device-change events update the list. A missing selected device stays visible as unavailable. Switching an active microphone prepares the new input before retiring the old one; failure leaves the old input running. The mixed output stays unchanged. Browser voice-processing selection follows that same input-replacement operation. It lasts for the Host page lifetime and defaults on. When off, capture requests no echo cancellation, noise suppression, automatic gain or voice isolation, and prefers stereo; actual support remains Browser/device-owned. Muted changes do not request capture, and source replacement retains the selected processing. Native capture does not run Browser processing or expose its switch; platform audio effects remain system/device-owned.

Camera and audio inputs are separate devices, even when a webcam includes a microphone. Camera capture never guesses an audio pairing. OBS Virtual Camera supplies video; its audio may be routed through a separately selected virtual audio input using the ordinary microphone control. This uses the existing mixer and routes. End-to-end OBS sound quality and A/V synchronization remain unverified device coverage.

OBS's Windows virtual-camera output uses raw_video and writes raw NV12 frames, not an encoded H.264 stream. Virtual camera alone therefore does not require an OBS encode/decode round trip before Piik's encoder. Source decoding, composition, pixel conversion and copies may still cost resources. Do not promise a zero-copy path or describe every virtual camera setup as double encoding.

Direct OBS ingestion is not currently implemented. OBS's WHIP output would be the relevant standard to evaluate if a measured virtual-camera bottleneck justified another input. It would still need an explicit publication/admission lifecycle and integration with Piik's existing media owner; an RTMP listener alone would not provide that. Keep this outside the current microphone/camera change.

Camera selection belongs in the existing Camera tab and uses the same named thumbnail cards as window/display selection. Entering the Camera tab may request camera permission for local previews; it never requests microphone access or starts a room. Preview inputs open serially and stop after one bounded thumbnail. Leaving the tab or cancelling the picker stops owned inputs and discards late permission results. Images last only for that picker. While already sharing a camera, preview borrows the current video frame and lists other devices without opening them, because some phones retire an active camera when another opens. Missing thumbnails do not disable a known device. The Host's existing source-replacement operation owns the old camera's automatic end event until the pending capture settles; failure with an already-ended old camera retires sharing normally. This does not suppress a user's screen-share Stop action. Some phones require releasing the old camera before opening another; seamless switching is not established.

The input-volume control adjusts microphone input from 0–200% through smoothed input gain. It does not change source audio or Viewer playback volume, reopen permission, or replace the outgoing track. Its value lasts for the Host page lifetime; new page loads use 100%. Mute remains a separate direct action. Volume settings use the existing settings disclosure without covering the picture or participants. The microphone-volume comic describes outgoing commentary, separately from the Viewer's local listening volume.

Local Review

Use the ordinary development or embedded Server entry described in the contributor guide. Start a share from the normal Host page, select a source, then join through its ordinary invitation in another browser tab. Use headphones for same-device microphone tests. Browser-emulated mobile layout and synthetic devices do not establish actual iOS/Android permission, orientation, background or audio behavior.

Phone Microphone Assessment

The proposed phone link would supply one Host audio input, not give Viewers a room-voice permission. Web Audio can mix a received MediaStream into the Browser Host's existing output. The native mixer instead consumes fixed PCM from local capture processes; it has no authenticated remote-input boundary. Room signaling authorizes assigned parent/child connections, so an ordinary Viewer invitation must not become permission to publish audio into the Host.

A coherent implementation therefore needs a Host-scoped, revocable pairing grant, one incoming audio connection and a decoded/resampled input for native mixing. The existing Host share must own that input's mute, replacement and retirement; input loss must leave healthy picture/source audio running. Phone capture still requires a secure origin and explicit microphone permission. The transport adds latency, and physical phone echo/background/lock behavior is not established by Browser emulation or a loopback audio test.

This is a source/API assessment, not an implemented or device-verified feature. Keep it outside the current candidate until a concrete use case justifies that pairing and input ownership. An audio device already exposed by the operating system can use Piik's existing microphone selector without this extension.

Primary Technical References