Skip to content

feat(web): add direct Canvas rendering and fix HEVC NAL framing - #30

Merged
fython merged 5 commits into
fython:mainfrom
seasonyuu:codex/direct-canvas-hevc-fix
Oct 21, 2026
Merged

fython merged 5 commits into
fython:mainfrom
seasonyuu:codex/direct-canvas-hevc-fix

Conversation

@seasonyuu

Copy link
Copy Markdown
Contributor

新增不创建 <video> 元素的实验性直接 Canvas 模式,并修复真机 HEVC 间歇性 decode-stalled 的 NAL 格式转换缺陷。默认仍使用原生 Video;缺少主线程 Processor 或发生媒体错误时保留所选模式,沿用上游图像回退与重试机制。

改动

  • 将接收器与媒体渲染解耦,提供原生 Video、兼容 Canvas 和直接 Canvas 三种方式;旧模式按需创建 Video,直接 Canvas 串行读取并释放 VideoFrame。
  • 新增单选卡片、旧偏好迁移、三语文案和独立绘制诊断;保留上游媒体版本隔离、触控就绪状态、缩放补偿、JPEG / WebP 流水线及有界退避重试。
  • 修复 Native 转换器将 00 00 01 xx 长度前缀误认成 Annex B 起始码的问题:256–511 字节的 NAL 原先会携带多余长度字节进入 RTP。两个 AirPlay 入口现在显式声明输入格式,并新增边界、多 NAL、畸形输入、关键帧分类及 RTP 往返测试。
  • 修复 Android CSP 阻止 data: WebP 探测而导致始终协商 JPEG 的问题,改用及时释放的 Blob URL;真实浏览器测试使用 Android 服务端的同一 CSP,无需放宽策略。
  • 更新两份 README、架构、恢复说明与验证记录。真实码流和私人画面仅保存在本地忽略目录,未提交。

验证

  • npm test:136 项通过;npm run check、git diff --check 通过。
  • :common:testDebugUnitTest:57 个套件、324 项通过,无失败或跳过。
  • Native 长度前缀测试通过 ASan / UBSan,已有 packetizer 测试通过。
  • npm run test:browser:media:真实 Chromium 覆盖 CSP 下的 WebP 探测、缩放触控、损坏图片回退、精确 ACK、旧帧拒绝、恢复期限、旋转及 WebSocket 重连。
  • Android Debug 构建并安装成功,设备安装包哈希与本地产物一致。
  • Pixel 3 / Android 15 + 无线 iPhone XS Max → Mac Chromium,2544×1576、协商上限 60 fps:三种渲染方式均正常;直接 Canvas 静置约 80 秒后恢复滑动,没有非预期 decode-stalled。
  • Rebase 后捕获的 3495 个 HEVC 访问单元全部通过 FFmpeg / FFprobe 独立解码,含旧缺陷范围内的 NAL,无语法或参考链警告。
  • 最终 APK 注入一次临时绘制异常后成功显示 WebP,约 5.8 秒自动恢复 HEVC / 直接 Canvas;全过程 Video 元素、创建次数及视频 play 调用均为 0。完成后恢复 30 fps、H.264 及原设备设置。

范围与限制

直接 Canvas 保持实验性且默认关闭,首版仅支持主线程 MediaStreamTrackProcessor。本轮动态成功绘制约 51 fps,不承诺持续 60 fps 或物理屏幕刷新率;目标车机型号及长时间运行仍需单独验证。

详细过程及各轮数据见 docs/VALIDATION.md。

Introduce renderer adapters, accessible mode selection and preference migration. Add no-Video rendering, JPEG fallback diagnostics, session isolation and regression coverage with localized documentation.
Declare the input framing at AirPlay decode entry points instead of guessing from start-code bytes. Cover AVC and HEVC length boundaries, keyframe detection, malformed records and byte-exact RTP roundtrips.
Document frame-rate measurements, bottleneck investigation, the NAL framing diagnosis and fixed-APK verification across all three renderers. Record restored device settings and remaining validation limits.
Use a temporary Blob URL for the WebP capability image and revoke it on completion. Run the real browser media regression against the Android CSP so blocked data URLs cannot silently disable WebP negotiation.
…dation

Describe JPEG and WebP image fallback with upstream retry and presentation state. Record merged checks, real HEVC playback and recovery, the CSP probe regression, final APK verification and restored device settings.
@fython
fython merged commit 3f5c462 into fython:main Oct 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants