Skip to content

fick from v20#504

Merged
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
add-uos:master
Jul 21, 2026
Merged

fick from v20#504
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
add-uos:master

Conversation

@add-uos

@add-uos add-uos commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Integrate configurable preferred camera resolution and low-performance device detection into the camera pipeline and configuration handling.

New Features:

  • Add support for setting a preferred camera resolution via configuration and propagating it into the V4L2 core resolution selection.
  • Introduce a configuration-driven flag to mark devices as low-performance and reuse it in low-performance board detection.

Enhancements:

  • Update V4L2 resolution selection to prioritize a validated preferred resolution and fall back to the maximum valid resolution with improved logging.
  • Initialize and store preferred resolution inside DataManager for centralized access.
  • Refresh copyright year ranges for GlobalUtils to cover up to 2026.

Use the DConfig mechanism to enable the configuration for the preferred resolution.
使用DConfig机制,开放首选分辨率的配置功能。

pick form: 2cdcb53

Task: https://pms.uniontech.com/task-view-387315.html
@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Introduce a configurable preferred resolution flow from config -> DataManager -> v4l2 core, replace the previous "largest valid resolution" selection logic, and add a DConfig-based low-performance-device override to the existing board-based detection.

Sequence diagram for preferred resolution config to v4l2 core selection

sequenceDiagram
    actor User
    participant Main as main
    participant DConfig as DConfig
    participant DataManager as DataManager
    participant V4L2Formats as v4l2_formats
    participant V4L2Core as v4l2core_prepare_valid_resolution

    User->>Main: start application
    Main->>DConfig: DConfig::create("org.deepin.camera", "org.deepin.camera.encode")
    Main->>DConfig: value("preferredResolution")
    DConfig-->>Main: QString preferredResolution
    Main->>DataManager: setPreferredResolution(preferredResolution)
    Main->>DataManager: getPreferredResolution()
    DataManager-->>Main: QSize size
    Main->>V4L2Formats: set_preferred_resolution(size.width(), size.height())

    User->>V4L2Core: v4l2core_prepare_valid_resolution(vd)
    V4L2Core->>V4L2Formats: get_preferred_resolution_width()
    V4L2Formats-->>V4L2Core: pref_w
    V4L2Core->>V4L2Formats: get_preferred_resolution_height()
    V4L2Formats-->>V4L2Core: pref_h
    V4L2Core->>V4L2Core: scan resolutions, find preferred or max
    V4L2Core-->>User: selected resolution my_width x my_height
Loading

Sequence diagram for low performance device detection with DConfig override

sequenceDiagram
    participant GlobalUtils as GlobalUtils
    participant DConfig as DConfig
    participant SystemInfo as com.deepin.system.SystemInfo

    GlobalUtils->>GlobalUtils: loadCameraConf()
    GlobalUtils->>DConfig: DConfig::create("org.deepin.camera", "org.deepin.camera.encode")
    DConfig-->>GlobalUtils: DConfig instance
    GlobalUtils->>DConfig: keyList()
    GlobalUtils->>DConfig: value("isLowPerformanceDevice")
    DConfig-->>GlobalUtils: QVariant bool
    GlobalUtils->>GlobalUtils: m_IsLowPerformanceDevice = toBool()

    GlobalUtils->>GlobalUtils: isLowPerformanceBoard()
    alt m_IsLowPerformanceDevice == true
        GlobalUtils-->>GlobalUtils: return true
    else m_IsLowPerformanceDevice == false
        GlobalUtils->>SystemInfo: query DMI via DBus
        SystemInfo-->>GlobalUtils: DMIInfo
        GlobalUtils->>GlobalUtils: check m_LowPerformanceBoards
        GlobalUtils-->>GlobalUtils: return result
    end
Loading

File-Level Changes

Change Details Files
Add global preferred resolution state and accessors to the v4l2 formats/core layer and use it when selecting capture resolution.
  • Introduce static globals for preferred width/height and simple setter/getter functions in the v4l2 formats module with validation and logging.
  • Change v4l2core_prepare_valid_resolution to scan available resolutions once, track whether a preferred resolution exists, compute the maximum valid resolution, and choose preferred or max resolution accordingly, including debug logging and an error path when no valid resolution is found.
libcam/libcam_v4l2core/v4l2_formats.c
libcam/libcam_v4l2core/v4l2_core.c
libcam/libcam_v4l2core/v4l2_formats.h
Plumb a preferred resolution from application configuration into the v4l2 core and validate it at the DataManager level.
  • Expose set/get preferred resolution APIs on DataManager using a QString "WIDTHxHEIGHT" interface backed by a QSize member with initialization to 0x0.
  • Parse, range-check (including an upper bound), and call is_valid_resolution for the configured resolution and store it only if valid.
  • Wire main.cpp to read "preferredResolution" from DConfig, set it on DataManager, and call the new C-level set_preferred_resolution with the resulting QSize if non-null.
  • Include the v4l2_formats header in datamanager.cpp via extern "C" for cross-language linkage.
src/src/basepub/datamanager.cpp
src/src/basepub/datamanager.h
src/main.cpp
Extend low-performance device detection to consult a DConfig flag in addition to the existing board list and track it in GlobalUtils.
  • Add a static boolean flag on GlobalUtils to represent a low-performance device, with header/implementation updates.
  • Modify isLowPerformanceBoard to short-circuit based on the flag when DConfig support is compiled in, retaining the original D-Bus based board detection.
  • In loadCameraConf, initialize the new flag and, when DConfig is available, read the "isLowPerformanceDevice" key from org.deepin.camera.encode config and set the flag accordingly.
  • Update copyright/SPDX year ranges in globalutils headers and sources.
src/src/globalutils.cpp
src/src/globalutils.h
src/assets/org.deepin.camera.encode.json

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

lzwind
lzwind previously approved these changes Jul 21, 2026

@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 1 issue, and left some high level feedback:

  • The new resolution selection path in v4l2core_prepare_valid_resolution now ignores the previous my_width/my_height-based logic and always chooses either the preferred or the max resolution; consider preserving the old behavior (e.g. respecting an initial target resolution and the 3840x2160 limit) or explicitly documenting/handling the changed semantics to avoid regressions.
  • In v4l2core_prepare_valid_resolution, when no valid resolution is found you log an error but still leave my_width/my_height at 0; it would be safer to either retain the previous valid values, fall back to a known safe default, or propagate an explicit failure rather than continuing with a 0x0 resolution.
  • The new preferred resolution helpers in v4l2_formats.c use printf for logging, which is inconsistent with the rest of the codebase’s logging style; consider switching to the existing logging mechanism (e.g. qInfo/qWarning or project-specific macros) for uniform output and better integration with log handling.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new resolution selection path in v4l2core_prepare_valid_resolution now ignores the previous my_width/my_height-based logic and always chooses either the preferred or the max resolution; consider preserving the old behavior (e.g. respecting an initial target resolution and the 3840x2160 limit) or explicitly documenting/handling the changed semantics to avoid regressions.
- In v4l2core_prepare_valid_resolution, when no valid resolution is found you log an error but still leave my_width/my_height at 0; it would be safer to either retain the previous valid values, fall back to a known safe default, or propagate an explicit failure rather than continuing with a 0x0 resolution.
- The new preferred resolution helpers in v4l2_formats.c use printf for logging, which is inconsistent with the rest of the codebase’s logging style; consider switching to the existing logging mechanism (e.g. qInfo/qWarning or project-specific macros) for uniform output and better integration with log handling.

## Individual Comments

### Comment 1
<location path="libcam/libcam_v4l2core/v4l2_core.c" line_range="1706-1715" />
<code_context>
+	for (int i = 0; i < vd->list_stream_formats[format_index].numb_res; i++)
</code_context>
<issue_to_address>
**issue:** Handle the case where no valid resolution is found more robustly.

Currently, if no valid resolution is found, `max_width`/`max_height` stay at 0, causing `my_width`/`my_height` to be set to 0 and only logging an error. If callers treat these as valid, this can result in invalid downstream configuration. Please either fall back to the previous `my_width`/`my_height`, return/propagate an error from this function, or ensure that a `(0, 0)` resolution is never used later in the pipeline.
</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 on lines +1706 to +1715
for (int i = 0; i < vd->list_stream_formats[format_index].numb_res; i++)
{
int w = vd->list_stream_formats[format_index].list_stream_cap[i].width;
int h = vd->list_stream_formats[format_index].list_stream_cap[i].height;
printf("V4L2_CORE: - valid resolution(%dx%d)\n", w, h);
if (my_width <= w && my_height <= h && is_valid_resolution(w, h)) {
my_width = w;
my_height = h;
if (is_valid_resolution(w, h))
{
// 找出首选分辨率
printf("V4L2_CORE: check valid resolution, width: %d, height: %d, preferred width: %d, preferred height: %d\n",
w, h, pref_w, pref_h);
if (!found_preferred && pref_w != 0 && pref_h != 0 && w == pref_w && h == pref_h) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue: Handle the case where no valid resolution is found more robustly.

Currently, if no valid resolution is found, max_width/max_height stay at 0, causing my_width/my_height to be set to 0 and only logging an error. If callers treat these as valid, this can result in invalid downstream configuration. Please either fall back to the previous my_width/my_height, return/propagate an error from this function, or ensure that a (0, 0) resolution is never used later in the pipeline.

Log: 支持通过配置标记低性能设备
Bug: https://pms.uniontech.com/bug-view-358869.html
Influence: 可通过配置直接识别低性能设备,优化低性能设备判断逻辑。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:100分

■ 【总体评价】

代码实现了首选分辨率和最大分辨率的有效选择,并增加了配置项管理和低性能设备判断逻辑,整体结构清晰且安全。
逻辑正确,输入校验严格,无安全漏洞,性能良好,故给予满分。

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

v4l2_core.c 中的 v4l2core_prepare_valid_resolution 函数通过单次遍历同时查找首选分辨率和最大分辨率,逻辑严密,避免了原有算法的瑕疵。datamanager.cpp 中对字符串的解析和转换处理得当,包含完整的错误检查。globalutils.cpp 中使用 std::unique_ptr 管理 DConfig 对象,避免了内存泄漏。
潜在问题:v4l2_core.c 中在未找到任何有效分辨率时仅打印错误日志,未进行返回值或状态标识的修改,可能导致后续流程使用 0x0 的分辨率。
建议:在极端情况下,考虑增加错误状态返回或设置一个默认的兜底分辨率,以防后续流程异常。

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

代码注释详尽,命名规范统一。datamanager.cpp 中通过 extern "C" 正确引入了 C 语言接口 is_valid_resolution,处理了 C/C++ 混合编程的符号问题。配置项的添加和读取逻辑清晰,具有良好的可读性和可维护性。
潜在问题:v4l2_formats.c 中 set_preferred_resolution 函数使用了 printf 输出错误信息,而在其他模块中多使用 qWarning 或 fprintf(stderr, ...)。
建议:统一日志输出方式,建议在 v4l2_formats.c 中也使用 fprintf(stderr, ...) 以保持底层库日志风格的一致性。

  • 3.代码性能(无性能问题)✓

分辨率查找算法从可能存在的多次或低效遍历优化为单次 O(N) 遍历,同时完成首选和最大分辨率的筛选,性能表现优异。DConfig 的读取在初始化阶段完成,不会影响运行时的核心循环性能。
潜在问题:无
建议:无需特别优化,保持当前实现即可。

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
总体风险描述:代码在处理外部输入(如配置文件中的分辨率字符串)时,进行了严格的格式、数值范围和有效性校验,未发现缓冲区溢出、注入或异常崩溃等安全风险。

  • 建议:继续保持严格的输入校验机制,对于外部配置项的解析维持当前的防御性编程风格。

■ 【改进建议代码示例】

// v4l2_core.c 中的改进建议
	if (found_preferred) {
		// 有首选分辨率,使用首选分辨率
		my_width  = pref_w;
		my_height = pref_h;
	} else {
		// 没有首选分辨率,使用最大分辨率
		my_width  = max_width;
		my_height = max_height;
		// 极端情况,没有可用分辨率,发出错误提示并设置默认值
		if (max_width == 0 || max_height == 0) {
			fprintf(stderr, "V4L2_CORE: ERROR: no valid resolution found!\n");
			// 设置一个安全的默认分辨率,防止后续流程崩溃
			my_width = 640;
			my_height = 480;
		}
	}

@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 Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 00aa273 into linuxdeepin:master Jul 21, 2026
23 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.

4 participants