Skip to content

feat(config): add useRgbData config to control RGB preview mode#488

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
add-uos:release/eagle
Jun 24, 2026
Merged

feat(config): add useRgbData config to control RGB preview mode#488
deepin-bot[bot] merged 1 commit into
linuxdeepin:release/eaglefrom
add-uos:release/eagle

Conversation

@add-uos

@add-uos add-uos commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Add DConfig option "useRgbData" to control whether YUV frames are converted to RGB for preview rendering. Supports three modes: -1: auto (default, let system decide)
0: force disable
1: force enable

添加DConfig配置项"useRgbData",控制预览时是否将YUV帧数据转换为RGB格式。
支持三态:-1自动判断(默认)、0强制关闭、1强制开启。

Log: 添加RGB预览模式配置项
PMS: BUG-366739
Influence: 通过DConfig配置可强制控制预览RGB数据的使用,便于排查特定机型显示异常问题。

Summary by Sourcery

Add a configurable RGB preview mode controlled by a new DConfig option.

New Features:

  • Introduce a DataManager setting to control whether RGB data is used for preview rendering with three modes: auto, force off, and force on.

Enhancements:

  • Wire the new RGB preview mode into the image processing thread so the DConfig setting can override the default RGB usage behavior.
  • Initialize the RGB preview mode from the DConfig "useRgbData" key during application startup to support per-device configuration.

@sourcery-ai

sourcery-ai Bot commented Jun 24, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a new DConfig-driven switch to control whether RGB data is used for preview rendering, wiring it through DataManager, main startup configuration, and the major image processing thread’s RGB path selection logic.

Sequence diagram for DConfig-driven RGB preview mode selection

sequenceDiagram
    participant Main
    participant DConfig
    participant DataManager
    participant MajorImageProcessingThread

    Main->>DConfig: value(useRgbData)
    DConfig-->>Main: int useRgbData
    Main->>DataManager: setUseRgbData(useRgbData)
    Main-->>MajorImageProcessingThread: start()

    MajorImageProcessingThread->>DataManager: getUseRgbData()
    DataManager-->>MajorImageProcessingThread: useRgbData
    alt [useRgbData == 1]
        MajorImageProcessingThread->>MajorImageProcessingThread: bUseRgb = true
    else [useRgbData == 0]
        MajorImageProcessingThread->>MajorImageProcessingThread: bUseRgb = false
    else [useRgbData == -1]
        MajorImageProcessingThread->>MajorImageProcessingThread: [system auto decides bUseRgb]
    end
Loading

File-Level Changes

Change Details Files
Introduce a configurable RGB preview mode flag in DataManager, with default auto behavior.
  • Add m_useRgbData member with default -1 to represent auto mode, plus inline setter and getter methods.
  • Document the semantics of the RGB preview mode (-1 auto, 0 force off, 1 force on) in DataManager’s interface comments.
src/src/basepub/datamanager.h
Apply the RGB preview mode setting to the runtime decision of whether to use RGB frames during image processing.
  • Read useRgbData from DataManager in MajorImageProcessingThread::run and override the existing bUseRgb decision accordingly.
  • Ensure that mode 1 forces RGB usage, mode 0 disables it, and mode -1 leaves the prior logic (e.g., GStreamer environment and photo display conditions) unchanged.
src/src/majorimageprocessingthread.cpp
Plumb the DConfig value for useRgbData into DataManager at application startup.
  • On startup, check DConfig for a useRgbData key and, if present, parse it as int and log the selected mode.
  • Store the parsed mode in DataManager so it can later drive preview RGB usage decisions.
src/main.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've found 2 issues, and left some high level feedback:

  • Consider replacing the raw int values -1/0/1 for useRgbData with a strongly typed enum to make the meaning of each mode clearer at the call site and reduce the risk of invalid values.
  • It may be worth validating/clamping the useRgbData value read from DConfig in main.cpp (e.g., restricting to -1, 0, 1) before storing it in DataManager to avoid unexpected behavior from malformed configuration.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider replacing the raw `int` values `-1/0/1` for `useRgbData` with a strongly typed enum to make the meaning of each mode clearer at the call site and reduce the risk of invalid values.
- It may be worth validating/clamping the `useRgbData` value read from DConfig in `main.cpp` (e.g., restricting to -1, 0, 1) before storing it in `DataManager` to avoid unexpected behavior from malformed configuration.

## Individual Comments

### Comment 1
<location path="src/main.cpp" line_range="220-224" />
<code_context>
         }
     }

+    if (dconfig && dconfig->isValid() && dconfig->keyList().contains("useRgbData")) {
+        int useRgbData = dconfig->value("useRgbData").toInt();
+        qInfo() << "use RGB data for preview:" << useRgbData;
+        DataManager::instance()->setUseRgbData(useRgbData);
+    }
+
</code_context>
<issue_to_address>
**suggestion:** Validate or clamp the configuration value for `useRgbData` before storing it.

`useRgbData` is documented as `-1/0/1`, but any value from the config is forwarded directly. If an invalid or legacy value is present, it will be treated as "auto" in `MajorImageProcessingThread`, which can be misleading when debugging. Please validate and either clamp or map unknown values to a default (e.g. `-1`) before calling `setUseRgbData`.

```suggestion
    if (dconfig && dconfig->isValid() && dconfig->keyList().contains("useRgbData")) {
        int useRgbData = dconfig->value("useRgbData").toInt();

        // Normalize to supported values -1 (auto), 0 (disabled), 1 (enabled)
        if (useRgbData != -1 && useRgbData != 0 && useRgbData != 1) {
            qWarning() << "Invalid useRgbData value in config:" << useRgbData
                       << "- mapping to default value -1 (auto)";
            useRgbData = -1;
        }

        qInfo() << "use RGB data for preview:" << useRgbData;
        DataManager::instance()->setUseRgbData(useRgbData);
    }
```
</issue_to_address>

### Comment 2
<location path="src/src/majorimageprocessingthread.cpp" line_range="286-289" />
<code_context>
                 bUseRgb = true;

+            // DConfig配置控制RGB数据使用模式,-1表示不设置(由系统自动判断),0表示强制关闭,1表示强制开启
+            int useRgbData = DataManager::instance()->getUseRgbData();
+            if (useRgbData == 1) {
+                bUseRgb = true;
+            } else if (useRgbData == 0) {
+                bUseRgb = false;
+            }
</code_context>
<issue_to_address>
**suggestion:** Clarify handling of unexpected `useRgbData` values to make the auto behavior explicit.

Right now only `0`/`1` change `bUseRgb`; any other value (including the documented `-1` auto) just falls back to the old behavior. If the intent is “non-0/1 = auto”, consider encoding that explicitly (e.g. switch or explicit `-1` case), and/or logging/asserting on unexpected values to surface config mistakes early.

Suggested implementation:

```cpp
            // DConfig配置控制RGB数据使用模式,-1表示不设置(由系统自动判断),0表示强制关闭,1表示强制开启
            int useRgbData = DataManager::instance()->getUseRgbData();
            switch (useRgbData) {
            case 1:
                // 强制开启 RGB
                bUseRgb = true;
                break;
            case 0:
                // 强制关闭 RGB
                bUseRgb = false;
                break;
            case -1:
                // 自动模式:保持当前 bUseRgb 由系统逻辑决定
                break;
            default:
                // 非法配置值:保持当前 bUseRgb,同时在开发期暴露问题
                assert(false && "Invalid useRgbData configuration value (expected -1/0/1)");
                break;
            }

```

1. Ensure `<cassert>` (or your project’s standard assert/logging header) is included in `majorimageprocessingthread.cpp` or a common header; e.g. add `#include <cassert>` if not already present.
2. If your codebase uses a specific logging/assert macro (e.g. `LOG_WARNING`, `Q_ASSERT`, etc.), replace the `assert(false && "...")` call with that preferred mechanism to align with existing conventions.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/main.cpp
Comment on lines +286 to +289
int useRgbData = DataManager::instance()->getUseRgbData();
if (useRgbData == 1) {
bUseRgb = true;
} else if (useRgbData == 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: Clarify handling of unexpected useRgbData values to make the auto behavior explicit.

Right now only 0/1 change bUseRgb; any other value (including the documented -1 auto) just falls back to the old behavior. If the intent is “non-0/1 = auto”, consider encoding that explicitly (e.g. switch or explicit -1 case), and/or logging/asserting on unexpected values to surface config mistakes early.

Suggested implementation:

            // DConfig配置控制RGB数据使用模式,-1表示不设置(由系统自动判断),0表示强制关闭,1表示强制开启
            int useRgbData = DataManager::instance()->getUseRgbData();
            switch (useRgbData) {
            case 1:
                // 强制开启 RGB
                bUseRgb = true;
                break;
            case 0:
                // 强制关闭 RGB
                bUseRgb = false;
                break;
            case -1:
                // 自动模式:保持当前 bUseRgb 由系统逻辑决定
                break;
            default:
                // 非法配置值:保持当前 bUseRgb,同时在开发期暴露问题
                assert(false && "Invalid useRgbData configuration value (expected -1/0/1)");
                break;
            }
  1. Ensure <cassert> (or your project’s standard assert/logging header) is included in majorimageprocessingthread.cpp or a common header; e.g. add #include <cassert> if not already present.
  2. If your codebase uses a specific logging/assert macro (e.g. LOG_WARNING, Q_ASSERT, etc.), replace the assert(false && "...") call with that preferred mechanism to align with existing conventions.

Add DConfig option "useRgbData" to control whether YUV frames are
converted to RGB for preview rendering. Supports three modes:
-1: auto (default, let system decide)
0: force disable
1: force enable

添加DConfig配置项"useRgbData",控制预览时是否将YUV帧数据转换为RGB格式。
支持三态:-1自动判断(默认)、0强制关闭、1强制开启。

Log: 添加RGB预览模式配置项
PMS: BUG-366739
Influence: 通过DConfig配置可强制控制预览RGB数据的使用,便于排查特定机型显示异常问题。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了DConfig配置强制控制YUV/RGB预览数据格式,逻辑严谨且无安全风险
评分理由:四个维度均表现优异,实现了预期的功能增强且无任何缺陷

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

majorimageprocessingthread.cpprun() 函数中,新增的 DConfig 逻辑精准插入在系统自动判断之后、实际使用 bUseRgb 之前。main.cpp 中对配置值进行了严格的白名单校验,非 -101 的值会被安全重置为 -1,确保传入 DataManager 的值绝对合法,覆盖逻辑严密无漏洞。
建议:无

  • 2.代码质量(良好)✓

代码命名规范清晰,useRgbDatasetUseRgbData 等命名见名知意。datamanager.h 中为新增方法提供了完整的 Doxygen 注释,明确说明了 -101 三种模式的含义。JSON 配置文件中同时提供了中英文描述,符合国际化规范。
建议:无

  • 3.代码性能(高效)✓

getUseRgbData() 被实现为内联函数,直接返回成员变量,开销极低。main.cpp 中的配置读取仅在程序启动时执行一次,不会对运行时的视频预览处理造成任何性能损耗。
建议:虽然当前 getUseRgbData()run() 循环内被调用,但由于其极小的开销且与原有 bUseRgb 计算逻辑处于同一层级,保持现状是合理的;若追求极致,可考虑将其移至循环外,但非必要。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
DConfig 配置项的 visibility 设置为 privatepermissionsreadwrite,限制了仅应用自身可读写,有效防止了恶意第三方应用篡改预览模式配置。main.cpp 中的防御性编程确保了即使配置文件被意外损坏或手动篡改为非法数值,也不会导致后续逻辑出现越界或不可预期的行为,整体安全性极高。

  • 建议:无

■ 【改进建议代码示例】

// 以下为可选的性能微优化示例,将配置读取移出 run() 循环体外部(仅在初始化时读取一次)
// 文件:src/src/majorimageprocessingthread.cpp
void MajorImageProcessingThread::run()
{
    // 在线程启动时读取一次配置,避免在每帧处理的循环中重复调用
    const int useRgbData = DataManager::instance()->getUseRgbData();

    while (m_bRunning) {
        // ...
        // 判断是否使用rgb数据
        bool bUseRgb = false;
#if defined(_loongarch) || defined(__loongarch__) || defined(__loongarch64) || defined (__mips__)
            bUseRgb = true;
#endif

        if(DSysInfo::majorVersion().toInt() >= 23) {
            bUseRgb = true;
        }

        if (GStreamer_Env == m_eEncodeEnv)
            bUseRgb = true;

        // DConfig配置控制RGB数据使用模式,-1表示不设置(由系统自动判断),0表示强制关闭,1表示强制开启
        if (useRgbData == 1) {
            bUseRgb = true;
        } else if (useRgbData == 0) {
            bUseRgb = false;
        }
        // ...
    }
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, lzwind

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@add-uos

add-uos commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot deepin-bot Bot merged commit ced1680 into linuxdeepin:release/eagle Jun 24, 2026
20 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.

3 participants