feat(hdr): improve metadata, AV1 hard decode, and brightness calibration - #53
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
nativelib/src/main/cpp/callbacks.cppnativelib/src/main/cpp/video_decoder.cppnativelib/src/main/cpp/video_decoder.h
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
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.
| namespace { | ||
| Smpte2086Metadata g_hdrStaticMetadata = {}; | ||
| bool g_hasHdrStaticMetadata = false; | ||
| } |
| // 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"); | ||
| } |
| void SetHdrStaticMetadata(const Smpte2086Metadata* metadata) { | ||
| std::lock_guard<std::mutex> lock(g_videoDecoderMutex); | ||
|
|
| g_hasHdrStaticMetadata = false; | ||
| g_hdrStaticMetadata = {}; |
改了啥呀
OH_NativeBuffer_StaticMetadata,合法元数据优先写入 NativeWindow。setHdrMode回调签名不匹配,让 common-c 能把 Sunshine metadata 指针正确传给 Harmony native 层。1.0.0.780,并更新应用内 changelog。为啥要改
验证
git diff --checkvideo_decoder.cpp使用现有compile_commands.json执行-fsyntax-only通过,仅有既有LOG_TAGmacro redefined warning。moonlight-common-c的ControlStream.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
新功能
问题修复