Skip to content

feat(hdr): improve metadata, AV1 hard decode, and brightness calibration - #53

Merged
qiin2333 merged 7 commits into
masterfrom
codex/hdr-metadata-av1-hard-decode
Jun 26, 2026
Merged

feat(hdr): improve metadata, AV1 hard decode, and brightness calibration#53
qiin2333 merged 7 commits into
masterfrom
codex/hdr-metadata-av1-hard-decode

Conversation

@qiin2333

@qiin2333 qiin2333 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

改了啥呀

  • AV1 MIME 改为运行期加载,能力探测只认硬件解码器,创建解码器时按 capability name 绑定硬解实现,软解这种杂鱼退路先按住不让它跑。
  • Sunshine HDR 静态元数据从控制流回调一路传到 HarmonyOS OH_NativeBuffer_StaticMetadata,合法元数据优先写入 NativeWindow。
  • HDR metadata 补了范围校验;缺失、越界或老服务端没传时继续 fallback 到默认 BT.2020/1000nits,避免空数据把显示链路绊倒。
  • 修复 setHdrMode 回调签名不匹配,让 common-c 能把 Sunshine metadata 指针正确传给 Harmony native 层。
  • 设置里新增手动 HDR 亮度校准:可覆盖上报给 Sunshine 的 HDR 峰值亮度,范围 300-4000 nits,重新连接串流后生效。
  • 版本递增到 1.0.0.780,并更新应用内 changelog。

为啥要改

  • 最新 SDK 有 AV1 MIME,但我们只考虑 AV1 硬解;如果设备没有硬件能力,就不应该暴露或初始化 AV1。
  • 服务端已经传 HDR 静态元数据,客户端应该优先使用真实元数据,而不是一直写死默认值。
  • 部分设备上报 HDR 亮度偏保守时,Sunshine 会按偏暗屏幕处理,手动校准给用户一个不改服务端也能自救的入口。

验证

  • git diff --check
  • video_decoder.cpp 使用现有 compile_commands.json 执行 -fsyntax-only 通过,仅有既有 LOG_TAG macro redefined warning。
  • moonlight-common-cControlStream.c / FakeCallbacks.c 使用现有 compile_commands.json 执行 -fsyntax-only 通过。
  • callbacks.cpp / moonlight_bridge.cpp 单文件语法检查被既有 aubio_onset_wrapper.h:18:10: fatal error: types.h file not found 阻塞。
  • node hvigorw.js assembleHap --mode module -p module=entry@default 被本机 SDK 环境阻塞:00303168 SDK component missing

Summary by CodeRabbit

  • 新功能

    • 提升 AV1 解码 MIME 的动态加载与能力探测稳定性,降低低版本加载失败风险。
    • 支持会话级 HDR10 静态元数据注入(SMPTE 2086 / CTA-861.3),并在可用时优先应用更准确的色度/亮度信息。
  • 问题修复

    • HDR 元数据校验失败或开关异常时,将自动清空并回退到默认静态元数据,提升兼容性。
    • 解码器初始化前增加校验,避免在不具备条件时继续配置导致失败。

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/hdr-metadata-av1-hard-decode

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: 4

🤖 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/callbacks.cpp`:
- Around line 104-123: The HDR metadata validation in the callback that
populates the NativeWindow color metadata is incomplete, because it only rejects
zero values and can still accept out-of-range values. Update the validation
logic in the function that maps `source` into `target` so it also rejects
chromaticity coordinates above the allowed SMPTE 2086 range and enforces the
luminance constraint where `minDisplayLuminance` must not exceed
`maxDisplayLuminance` by an invalid ratio. Keep the existing early-return false
behavior, and ensure the `target->redX`, `target->whiteY`,
`target->maxLuminance`, and related assignments only happen after all range
checks pass.
- Around line 1046-1048: 在 BridgeClSetHdrMode / setHdrMode 的回调绑定上存在 ABI
不匹配:当前把一个实际需要两个参数的函数错误地按单参数 bool 回调强转,导致 callbacks.cpp 中的处理逻辑拿不到正确的 hdrMetadata
指针并可能崩溃。请移除 moonlight_bridge.cpp 中对 setHdrMode 的 (void (*)(bool)) 强制转换,并将
CONNECTION_LISTENER_CALLBACKS 里的 setHdrMode 成员签名改为与 BridgeClSetHdrMode
真实定义一致的双参数形式,确保调用链上的参数类型和数量完全匹配。

In `@nativelib/src/main/cpp/video_decoder.cpp`:
- Around line 496-502: The decoder initialization in video_decoder.cpp only
checks hardware capability via GetHWDecoderCapability(mimeType) but then creates
the decoder with OH_VideoDecoder_CreateByMime(mimeType), which can silently fall
back to software. Update the Init flow to use the specific capability name from
OH_AVCapability_GetName(cap) (or an equivalent name-based creation API such as
OH_VideoDecoder_CreateByName if available) so the hardware decoder is explicitly
bound; keep the existing mimeType validation and logs, but ensure the created
decoder is the intended hardware implementation.
- Around line 186-208: Make the AV1 MIME lazy initialization in
TryLoadAv1MimeType thread-safe and guaranteed to run only once, because
g_codecMimeKeysLoaded and key_mime_video_av1 can be read and written
concurrently from IsCodecSupported() and GetCapabilities(). Replace the current
naked boolean/string cache with a one-time initialization mechanism and
synchronized access so the dlsym/dlopen lookup and the OH_LOG_INFO path cannot
race across ArkTS/N-API threads.
🪄 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

Run ID: 01228125-046d-46ab-954f-f8952c277ce6

📥 Commits

Reviewing files that changed from the base of the PR and between 9958633 and 07281d4.

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

Comment thread nativelib/src/main/cpp/callbacks.cpp
Comment thread nativelib/src/main/cpp/callbacks.cpp
Comment thread nativelib/src/main/cpp/video_decoder.cpp
Comment thread nativelib/src/main/cpp/video_decoder.cpp Outdated
@qiin2333 qiin2333 changed the title fix(stream): use host HDR metadata and gate AV1 hardware decode feat(hdr): improve metadata, AV1 hard decode, and brightness calibration Jun 26, 2026
@qiin2333

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

该 PR 聚焦于 HarmonyOS 端的 HDR/AV1 解码链路可靠性:将 Sunshine 下发的 HDR10 静态元数据贯穿到 NativeWindow,并把 AV1 入口收紧到“仅硬解 + 按 capability name 绑定创建”,同时新增可由用户手动覆盖上报给 Sunshine 的 HDR 峰值亮度校准选项,并完成版本与 changelog 更新。

Changes:

  • AV1 MIME 通过运行期 dlsym/dlopen 动态加载,并基于硬件 capability 选择具体硬解 decoder name 创建实例
  • Sunshine HDR10 静态元数据(SMPTE 2086 + CTA-861.3)转换/校验后注入 OH_NativeWindow 元数据;缺失或非法时回退默认 BT.2020/1000nits
  • 新增“手动 HDR 亮度校准”(300–4000 nits)配置项,影响后续连接时上报给 Sunshine 的亮度范围;同步版本号与 changelog

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
nativelib/src/main/cpp/video_decoder.h 新增 Smpte2086Metadata 结构与 SetHdrStaticMetadata() 接口声明
nativelib/src/main/cpp/video_decoder.cpp AV1 MIME 动态加载 + 仅硬解能力探测/按 name 创建;HDR 静态元数据写入 NativeWindow;新增静态元数据缓存接口
nativelib/src/main/cpp/moonlight_bridge.cpp 修正 .setHdrMode 回调函数指针赋值方式
nativelib/src/main/cpp/callbacks.h 修正 BridgeClSetHdrMode 签名为 bool enabled 以匹配调用侧
nativelib/src/main/cpp/callbacks.cpp Sunshine HDR 元数据转换与范围校验,并注入到 video decoder 静态元数据缓存
entry/src/main/resources/rawfile/CHANGELOG.md 增加 1.0.0.781 版本变更说明
entry/src/main/ets/service/streaming/StreamingSession.ets HDR 连接参数中支持可选的亮度覆盖逻辑,并输出日志
entry/src/main/ets/service/SettingsService.ets 新增 HDR 亮度覆盖与峰值亮度设置项读取/钳制(300–4000)
entry/src/main/ets/pages/SettingsPageV2.ets 设置页新增 HDR 亮度校准开关与峰值亮度滑条
entry/src/main/ets/model/StreamConfig.ets StreamConfig 增加 HDR 亮度覆盖相关字段与默认值
AppScope/app.json5 版本号提升到 1.0.0.781

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +212 to +215
namespace {
Smpte2086Metadata g_hdrStaticMetadata = {};
bool g_hasHdrStaticMetadata = false;
}
Comment on lines +831 to +843
// Sunshine 会通过控制流传递主机显示器/内容元数据;缺失时才使用 BT.2020 默认值。
OH_NativeBuffer_StaticMetadata staticMetadata;
if (g_hasHdrStaticMetadata) {
staticMetadata = ToNativeHdrStaticMetadata(g_hdrStaticMetadata);
OH_LOG_INFO(LOG_APP, "{Init} Using host HDR static metadata: maxLum=%.3f, minLum=%.4f, maxCLL=%.3f, maxFALL=%.3f",
staticMetadata.smpte2086.maxLuminance,
staticMetadata.smpte2086.minLuminance,
staticMetadata.cta861.maxContentLightLevel,
staticMetadata.cta861.maxFrameAverageLightLevel);
} else {
staticMetadata = BuildDefaultHdrStaticMetadata();
OH_LOG_INFO(LOG_APP, "{Init} Host HDR metadata unavailable, using BT.2020 fallback static metadata");
}
Comment on lines +2510 to +2512
void SetHdrStaticMetadata(const Smpte2086Metadata* metadata) {
std::lock_guard<std::mutex> lock(g_videoDecoderMutex);

Comment on lines +2534 to +2535
g_hasHdrStaticMetadata = false;
g_hdrStaticMetadata = {};
@qiin2333
qiin2333 merged commit 21f403a into master Jun 26, 2026
2 checks passed
@qiin2333
qiin2333 deleted the codex/hdr-metadata-av1-hard-decode branch June 26, 2026 11:14
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