Skip to content

fix(hdr): 打通 HEVC/AV1 CUVA HDR Vivid 链路 - #92

Merged
qiin2333 merged 2 commits into
masterfrom
agent/preserve-hdr-vivid-sei
Jul 28, 2026
Merged

fix(hdr): 打通 HEVC/AV1 CUVA HDR Vivid 链路#92
qiin2333 merged 2 commits into
masterfrom
agent/preserve-hdr-vivid-sei

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • 更新 moonlight-common-c 到配套 HEVC 修复: fix(video): preserve HEVC SEI for opted-in renderers qiin2333/moonlight-common-c#15
  • HarmonyOS 渲染器显式启用 CAPABILITY_PRESERVE_HEVC_SEI,让 CUVA SEI 同时到达硬件解码器和状态扫描器。
  • 将 HDR Vivid 扫描器扩展为 HEVC Annex-B SEI + AV1 low-overhead Metadata OBU 两种输入。
  • AV1 解析支持跨 scatter 分段、可选 extension header、LEB128 OBU size、多字节 size 和末尾无 size OBU。
  • HEVC/AV1 在 HDR+HLG 会话中共用同一个探测状态,识别后性能覆盖层显示 HDR Vivid
  • 保留 HDR10+ 排除逻辑,避免只看到 ITU-T T.35 就误报 Vivid。

为啥要改

Foundation Sunshine 已经在两条编码路径注入同一份 CUVA T.35 动态元数据:HEVC 使用 seiPayloadArray,AV1 使用 obuPayloadArray。客户端原来有两只杂鱼断点:HEVC SEI 在解包层提前被删掉,AV1 虽然完整透传给硬解,但探测器被硬编码成只扫描 HEVC,因此覆盖层永远无法确认 AV1 Vivid。

现在链路变为:

Sunshine CUVA SEI/OBU → common-c 完整 decode unit → HarmonyOS AVCodec → HEVC/AV1 元数据扫描 → HDR Vivid 覆盖层状态

AV1 解码输入没有被改写,只增加只读扫描;是否实际呈现动态效果仍由设备的 HarmonyOS AV1 HDR Vivid 硬解能力决定。

用户影响

  • HEVC + HLG + CUVA:动态元数据不再丢失,硬解与覆盖层都能收到。
  • AV1 + HLG + CUVA:原有 OBU 继续原样进入硬解,覆盖层现在也能识别。
  • HEVC/AV1 + HLG 但无 CUVA:保持 HDR HLG,不会把 HDR10+ 误判为 Vivid。
  • H.264、AV1 RTP 重组、网络协商和码流字节均未改变。

验证

  • g++ -std=c++17 -Wall -Wextra -Werror nativelib/src/main/cpp/hdr_vivid_metadata_scanner.cpp nativelib/src/test/cpp/hdr_vivid_metadata_scanner_test.cpp -I nativelib/src/main/cpp -o .codex-build/hdr_vivid_metadata_scanner_test.exe
  • .codex-build/hdr_vivid_metadata_scanner_test.exeHDR Vivid metadata scanner tests passed
  • ninja -C C:\Users\mohaha\StudioProjects\moonlight-harmonyos\nativelib\.cxx\default\default\debug\arm64-v8a moonlight_nativelib:arm64 原生库编译并链接成功。
  • git diff --check:通过,仅有工作区 CRLF 转换提示。

覆盖用例包括:HEVC prefix/suffix SEI、同一 SEI 中 HDR10+ 后跟 CUVA、AV1 OBU 跨分段、extension header、多字节 LEB128 size、末尾无 size OBU,以及 HEVC/AV1 HDR10+ 排除。

补充:Hvigor 顶层任务仍被现有的 The root node is not yet available for build 配置错误阻断,因此使用已有 HarmonyOS arm64 Ninja 构建树完成原生链路验证。设备端 AV1 Vivid 实际渲染仍需在支持 AV1 HDR Vivid 的 HarmonyOS 设备上验收。

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

HDR SEI 处理

Layer / File(s) Summary
HEVC SEI 能力传播
nativelib/src/main/cpp/moonlight-common-cnativelib/src/main/cpp/moonlight_bridge.cpp
更新子模块提交,并在视频回调初始化及连接启动时始终保留 HEVC SEI 能力。
同一 SEI NAL 的 CUVA 检测测试
nativelib/src/test/cpp/hdr_vivid_metadata_scanner_test.cpp
新增 HDR10+ 后检测同一 prefix SEI NAL 中 CUVA 的测试,并加入测试入口。

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次对 CUVA HDR Vivid 链路和 HEVC SEI 透传支持的核心改动。
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/preserve-hdr-vivid-sei

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qiin2333
qiin2333 marked this pull request as ready for review July 28, 2026 14:10

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nativelib/src/main/cpp/moonlight-common-c`:
- Line 1: 将子模块引用 nativelib/src/main/cpp/moonlight-common-c
更新为可公开访问远端中的对应提交;先把所需提交推送到公开仓库,再更新 gitlink,确保 CI 和干净检出环境能够正常拉取。
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b4b11305-e120-43c5-8750-4e23347a6104

📥 Commits

Reviewing files that changed from the base of the PR and between ac6a038 and d22e246.

📒 Files selected for processing (3)
  • nativelib/src/main/cpp/moonlight-common-c
  • nativelib/src/main/cpp/moonlight_bridge.cpp
  • nativelib/src/test/cpp/hdr_vivid_metadata_scanner_test.cpp

@@ -1 +1 @@
Subproject commit e9319eec44f6c866b7c5a2b1fc342f34d3d42612
Subproject commit 2b913d47a4d29b0825c3fe748493fd336d80a241

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

submodule="nativelib/src/main/cpp/moonlight-common-c"
expected="2b913d47a4d29b0825c3fe748493fd336d80a241"

actual="$(git ls-tree HEAD -- "$submodule" | awk '{print $3}')"
test "$actual" = "$expected"

git -C "$submodule" cat-file -e "$expected^{commit}"
git -C "$submodule" grep -n 'CAPABILITY_PRESERVE_HEVC_SEI' "$expected" -- .
git -C "$submodule" show --stat --oneline "$expected"

Repository: AlkaidLab/moonlight-harmony

Length of output: 341


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== repo submodule entry =="
git ls-tree -l HEAD -- nativelib/src/main/cpp/moonlight-common-c || true

echo "== submodule config =="
if [ -f .gitmodules ]; then
  sed -n '/\[submodule "nativelib\/src\/main\/cpp\/moonlight-common-c"\]/,/^\[/p' .gitmodules
else
  sed -n '/\[submodule "moonlight-common-c"\]/,/^\[/p' .gitmodules 2>/dev/null || true
fi

echo "== .git/config relevant refs/remotes =="
git config --get-regexp 'submodule\.nativelib/src/main/cpp/moonlight-common-c|core\.worktree|branch' | sed -n '1,120p' || true

echo "== local presence =="
if [ -e nativelib/src/main/cpp/moonlight-common-c ]; then
  echo "exists"
  git -C nativelib/src/main/cpp/moonlight-common-c rev-parse --is-inside-work-tree || true
  git -C nativelib/src/main/cpp/moonlight-common-c config --get-regexp 'remote|fetch|url' || true
  git -C nativelib/src/main/cpp/moonlight-common-c branch --show-current || true
else
  echo "missing"
fi

echo "== tracked references to commit in local submodule repo (if present) =="
if [ -e nativelib/src/main/cpp/moonlight-common-c/.git ]; then
  cd nativelib/src/main/cpp/moonlight-common-c
  git cat-file -e2> /dev/null 2b913d47a4d29b0825c3fe748493fd336d80a241^{commit} || true
  git rev-parse --is-inside-work-tree
  git status -s
  git branch -a --contains 2b913d47a4d29b0825c3fe748493fd336d80a241 2>/dev/null | sed -n '1,20p' || true
  for r in $(git remote -v | awk '{print $1}' | sort -u); do
    echo "--- remote $r ---"
    git ls-remote "$r" 2>/dev/null | grep -E '2b913d47a4d29b0825c3fe748493fd336d80a241' | sed -n '1,20p' || true
  done
fi

Repository: AlkaidLab/moonlight-harmony

Length of output: 1054


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
import subprocess, pathlib, textwrap, hashlib, urllib.request, urllib.error

sha = "2b913d47a4d29b0825c3fe748493fd336d80a241"
print("SHA length:", len(sha), "valid_hex:", all(c in "0123456789abcdef" for c in sha))
print("submodule path:", "nativelib/src/main/cpp/moonlight-common-c")

def fetch(url):
    req = urllib.request.Request(url, headers={"User-Agent": "CodeRabbit/verify-submodule-sha"})
    try:
        resp = urllib.request.urlopen(req, timeout=10)
    except urllib.error.HTTPError as e:
        raise
    return resp.read()

for fmt in ["text", "json"]:
    base = "https://api.github.com/repos/LizardByte/moonlight-common-c/git/ref" if fmt == "text" else "https://api.github.com/repos/LizardByte/moonlight-common-c/git/refs"
    url = f"{base}/heads/{sha}" if fmt == "text" else f"{base}/{sha[0:2]}/{sha[2:]}"
    print(f"\n== trying {fmt}: {url} ==")
    try:
        data = fetch(url)
        text = data.decode("utf-8", "replace")
        print(text[:2000])
        print("status found")
    except urllib.error.HTTPError as e:
        print(e.code, e.reason)
        print(e.read().decode("utf-8", "replace")[:800])

# Check GitHub raw object without fetching the full commit content too aggressively.
for url in [
    f"https://api.github.com/repos/LizardByte/moonlight-common-c/commits/{sha}",
    f"https://raw.githubusercontent.com/LizardByte/moonlight-common-c/{sha}/.github/workflows/ci.yml",
    f"https://raw.githubusercontent.com/LizardByte/moonlight-common-c/{sha}/platform/android/src/main/cpp/.../CUVA"
]:
    print(f"\n== raw probe: {url} ==")
    try:
        data = urllib.request.urlopen(url, timeout=15)
        print("exists", data.status)
    except urllib.error.HTTPError as e:
        print(e.code, e.reason)
PY

Repository: AlkaidLab/moonlight-harmony

Length of output: 2711


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sha="2b913d47a4d29b0825c3fe748493fd336d80a241"
remote="https://github.com/qiin2333/moonlight-common-c.git"
remote_private="$(git config --get submodule.nativelib/src/main/cpp/moonlight-common-c.url || true)"

echo "== configured submodule URL =="
echo "$remote_private"

echo "== git ls-remote from configured submodule remote =="
git ls-remote "$remote_private" "$sha" "$sha^{commit}" 2>&1 | sed -n '1,20p' || true

echo "== git ls-remote from configured ref names containing sha (if any branch/tag) =="
git ls-remote "$remote_private" | grep -E "^[0-9a-f]+[[:space:]]+.*(refs/heads/(mic|master|main)|refs/tags/).*${sha#2b9}" | sed -n '1,20p' || true

echo "== local gitmodules entry =="
sed -n '/\[submodule "nativelib\/src\/main\/cpp\/moonlight-common-c"\]/,/^\[[^]]*]/p' .gitmodules | sed -n '1,24p'

Repository: AlkaidLab/moonlight-harmony

Length of output: 638


请提供可公开获取的子模块提交。

nativelib/src/main/cpp/moonlight-common-c 指向 qiin2333/moonlight-common-c 非公开仓库中的 private 提交;CI 或其他干净检出环境无法拉取该 gitlink,合并前需将所需提交推送到可公开访问的子模块仓库远端并更新引用。

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@nativelib/src/main/cpp/moonlight-common-c` at line 1, 将子模块引用
nativelib/src/main/cpp/moonlight-common-c 更新为可公开访问远端中的对应提交;先把所需提交推送到公开仓库,再更新
gitlink,确保 CI 和干净检出环境能够正常拉取。

Source: Path instructions

@qiin2333 qiin2333 changed the title fix(hdr): 打通 CUVA HDR Vivid 元数据链路 fix(hdr): 打通 HEVC/AV1 CUVA HDR Vivid 链路 Jul 28, 2026
@qiin2333
qiin2333 merged commit 4c208fb into master Jul 28, 2026
2 checks passed
@qiin2333
qiin2333 deleted the agent/preserve-hdr-vivid-sei branch July 28, 2026 14:35
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.

1 participant