Skip to content

fix(hdr): 按码流自动识别 HDR Vivid - #98

Merged
qiin2333 merged 3 commits into
masterfrom
codex/fix-hdr-vivid-autodetect
Aug 3, 2026
Merged

fix(hdr): 按码流自动识别 HDR Vivid#98
qiin2333 merged 3 commits into
masterfrom
codex/fix-hdr-vivid-autodetect

Conversation

@qiin2333

@qiin2333 qiin2333 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • PQ 和 HLG 会话都扫描 CUVA T.35 元数据,覆盖 HEVC SEI 与 AV1 Metadata OBU
  • 每个 HDR 会话先写入 OH_VIDEO_HDR_HDR10OH_VIDEO_HDR_HLG,把上一会话残留的 Vivid 状态赶走
  • 解码器输出格式只用于同步 PQ/HLG 传递函数,不再读取 OH_MD_KEY_VIDEO_IS_HDR_VIVID
  • CUVA 命中后写入 OH_VIDEO_HDR_VIVID,并在当前会话内保持 Vivid,避免后到的输出格式回调把它降级
  • NativeWindow HDR 类型更新通过互斥锁串行化,避免并发写入这个非线程安全接口

为啥要改

PQ/HLG 是基础传递函数,Vivid 只由 CUVA 动态元数据决定。把普通 HLG 固定标记成 Vivid 会误判,依赖解码器输出的 OH_MD_KEY_VIDEO_IS_HDR_VIVID 也不可靠,因为该字段面向媒体轨道而不是原始码流解码输出。

现在新会话先明确覆盖基础 HDR 类型,检测到 CUVA 才升级到 Vivid;这个升级在会话内保持粘滞,下一次会话 reset 后仍能正常覆盖,残留状态这只杂鱼就钻不过来了。

验证

  • git diff --check
  • clang++ -std=c++17 -I nativelib/src/main/cpp nativelib/src/test/cpp/hdr_vivid_metadata_scanner_test.cpp nativelib/src/main/cpp/hdr_vivid_metadata_scanner.cpp -o /tmp/moonlight-hdr-vivid-scanner-test
  • /tmp/moonlight-hdr-vivid-scanner-test,输出 HDR Vivid metadata scanner tests passed
  • npm run check
  • JAVA_HOME=/Applications/DevEco-Studio.app/Contents/jbr/Contents/Home DEVECO_SDK_HOME=/Applications/DevEco-Studio.app/Contents/sdk node hvigorw.js assembleApp --mode project -p product=default -p buildMode=debug --no-daemon
  • 完整构建结果:BUILD SUCCESSFUL

Summary by CodeRabbit

  • 新功能

    • 扩展 HDR Vivid 内容识别范围,支持启用 HDR 的 HEVC 和 AV1 视频。
    • 根据视频码流及输出格式自动判定并应用 HDR 类型。
  • 改进

    • 优化 HDR 元数据处理,保留必要的色彩空间、亮度及静态 HDR 信息。
    • 改进解码过程中的 HDR 状态同步与动态切换,提升不同 HDR 内容的播放兼容性与稳定性。

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: eb02f6c5-1621-4436-a176-aba26cc0e534

📥 Commits

Reviewing files that changed from the base of the PR and between cf01f9d and 5986dd4.

📒 Files selected for processing (1)
  • nativelib/src/main/cpp/video_decoder.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • nativelib/src/main/cpp/video_decoder.cpp

📝 Walkthrough

Walkthrough

本次变更扩展 HDR Vivid 检测范围,并根据码流或输出格式动态设置 NativeWindow HDR 类型。解码器继续设置颜色空间、白点亮度和静态 HDR 元数据。

Changes

HDR 元数据处理

Layer / File(s) Summary
HDR Vivid 检测与会话基线
nativelib/src/main/cpp/video_decoder.cpp, nativelib/src/main/cpp/video_decoder.h
启用 HDR 的 HEVC 和 AV1 配置执行 HDR Vivid 探测。初始化阶段设置会话基线 HDR 类型。NativeWindow 继续接收颜色空间、白点亮度和静态 HDR 元数据。
输出 HDR 类型应用
nativelib/src/main/cpp/video_decoder.cpp
新增线程安全的 HDR 类型设置方法。输出格式解析根据 HDR Vivid 标志和传输特性选择 HDR Vivid、HLG 或 HDR10。输出格式变化和同步模式变化会应用该类型。
窗口状态同步与清理
nativelib/src/main/cpp/video_decoder.cpp, nativelib/src/main/cpp/video_decoder.h
窗口元数据状态使用互斥锁保护。重复类型写入受到限制。清理时释放窗口引用并重置已应用的 HDR 类型状态。

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了按码流自动识别 HDR Vivid 的主要变更。
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.
✨ 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 codex/fix-hdr-vivid-autodetect

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.

@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/video_decoder.cpp`:
- Around line 806-822: Update the video decoder’s output callback to read the
output OH_AVFormat and set the corresponding NativeWindow/Buffer metadata via
OH_NativeWindow_SetMetadataValue for OH_VIDEO_HDR_VIVID, OH_HDR_HLG, or
OH_HDR_HDR10 based on the detected HDR type, rather than only recording
hdrVividDetected_. Ensure each new session resets or overwrites stale Vivid
metadata when no CUVA is detected, so HLG/PQ content cannot inherit the previous
session’s Vivid setting.
🪄 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: 2e694c96-7ef7-4575-a2fa-31f6e1b50266

📥 Commits

Reviewing files that changed from the base of the PR and between ffb7f08 and 7182a22.

📒 Files selected for processing (2)
  • nativelib/src/main/cpp/video_decoder.cpp
  • nativelib/src/main/cpp/video_decoder.h

Comment thread nativelib/src/main/cpp/video_decoder.cpp Outdated

@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: 2

🤖 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/video_decoder.cpp`:
- Around line 1590-1594: Remove the OH_MD_KEY_VIDEO_IS_HDR_VIVID lookup and
related vividFlag handling from ApplyOutputHdrMetadata(), including the
hdrVividDetected_ update based on the decoder output format. Preserve the
remaining output HDR metadata processing unchanged.
- Around line 1585-1609: Update SetNativeWindowHdrMetadataType to reject
non-OH_VIDEO_HDR_VIVID metadata when hasAppliedHdrMetadataType_ is already true
and the current applied type is OH_VIDEO_HDR_VIVID, while allowing the update
when the session has been reset and hasAppliedHdrMetadataType_ is false. Keep
normal metadata transitions unchanged and ensure the check occurs under the
existing synchronization used for the write.
🪄 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: 5cc73e0e-cf68-4a5c-956a-68740c20e2a3

📥 Commits

Reviewing files that changed from the base of the PR and between 7182a22 and cf01f9d.

📒 Files selected for processing (2)
  • nativelib/src/main/cpp/video_decoder.cpp
  • nativelib/src/main/cpp/video_decoder.h

Comment thread nativelib/src/main/cpp/video_decoder.cpp
Comment thread nativelib/src/main/cpp/video_decoder.cpp Outdated
@qiin2333
qiin2333 merged commit e091bb7 into master Aug 3, 2026
2 of 3 checks passed
@qiin2333
qiin2333 deleted the codex/fix-hdr-vivid-autodetect branch August 3, 2026 09:38
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