Skip to content

fix: sync resolution config after prepare_new_resolution (#372317) - #518

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-372317-sync-resolution-config-after-prepare
Aug 18, 2026
Merged

fix: sync resolution config after prepare_new_resolution (#372317)#518
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:fix-372317-sync-resolution-config-after-prepare

Conversation

@add-uos

@add-uos add-uos commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Sync my_config width/height with actual values after v4l2core_prepare_new_resolution to avoid config mismatch.

在 v4l2core_prepare_new_resolution 调用后同步 my_config 的 宽高配置,避免配置值与实际分辨率不一致。

Log: 同步分辨率配置
PMS: BUG-372317
Influence: 修复相机分辨率配置与实际设置不同步的问题,确保配置文件记录的分辨率与实际使用的分辨率一致。

Summary by Sourcery

Bug Fixes:

  • Synchronize the configured camera width and height with the actual resolution after preparing a new V4L2 resolution, preventing configuration mismatches.

Sync my_config width/height with actual values after
v4l2core_prepare_new_resolution to avoid config mismatch.

在 v4l2core_prepare_new_resolution 调用后同步 my_config 的
宽高配置,避免配置值与实际分辨率不一致。

Log: 同步分辨率配置
PMS: BUG-372317
Influence: 修复相机分辨率配置与实际设置不同步的问题,确保配置文件记录的分辨率与实际使用的分辨率一致。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码修复了摄像头初始化阶段分辨率设置不匹配的逻辑缺陷,确保配置数据同步
逻辑正确且修复方案简洁有效,无安全漏洞,仅因上下文信息有限保留少量扣分

■ 【详细分析】

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

camInit 函数中,调用 v4l2core_prepare_new_resolution 后,原代码未重新获取实际的宽高配置,导致后续 v4l2core_update_old_format 可能使用了过时的分辨率数据。新增的两行代码通过调用 get_my_width()get_my_height() 正确同步了 my_config 结构体。
潜在问题:若 v4l2core_prepare_new_resolution 失败,get_my_width() 等函数可能返回无效值,但当前上下文未显示错误处理逻辑
建议:在调用 v4l2core_prepare_new_resolution 后增加返回值检查,确保分辨率准备成功后再同步配置

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

修复代码风格与上下文保持一致,变量命名清晰,直接解决了配置不同步的问题,没有引入冗余代码。
潜在问题:无
建议:无

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

新增的仅为两个 getter 函数调用和结构体成员赋值,开销极小,不会对摄像头初始化性能产生任何负面影响。
潜在问题:无
建议:无

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改仅涉及配置数据的同步读取与赋值,未引入外部输入处理、内存操作或权限变更,不存在安全风险。

  • 建议:无需针对安全进行额外修复

■ 【改进建议代码示例】

diff --git a/src/src/LPF_V4L2.c b/src/src/LPF_V4L2.c
index 7a79ecdf..a6a180b4 100644
--- a/src/src/LPF_V4L2.c
+++ b/src/src/LPF_V4L2.c
@@ -220,6 +220,11 @@ int camInit(const char *devicename)
                 my_config->height = get_my_height();
             } else {
-                v4l2core_prepare_new_resolution(my_vd, my_config->width, my_config->height);
+                int prepare_ret = v4l2core_prepare_new_resolution(my_vd, my_config->width, my_config->height);
+                if (prepare_ret >= 0) {
+                    my_config->width  = get_my_width();
+                    my_config->height = get_my_height();
+                } else {
+                    // 处理分辨率准备失败的情况,记录日志或返回错误
+                    return prepare_ret;
+                }
             }
             ret = v4l2core_update_old_format(my_vd, my_config->width, my_config->height, v4l2core_get_requested_frame_format(my_vd));
         } else {

@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

@sourcery-ai

sourcery-ai Bot commented Aug 18, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

This PR ensures the internal camera configuration (my_config) width/height are synchronized with the actual device resolution after v4l2core_prepare_new_resolution, preventing mismatches between configuration and real capture settings.

Sequence diagram for camInit resolution config synchronization

sequenceDiagram
    participant camInit
    participant v4l2core
    participant device
    participant my_config

    camInit->>v4l2core: v4l2core_prepare_new_resolution(my_vd, my_config.width, my_config.height)
    v4l2core->>device: apply_new_resolution()
    device-->>v4l2core: actual_resolution
    camInit->>device: get_my_width()
    device-->>camInit: width
    camInit->>my_config: width = get_my_width()
    camInit->>device: get_my_height()
    device-->>camInit: height
    camInit->>my_config: height = get_my_height()
    camInit->>v4l2core: v4l2core_update_old_format(my_vd, my_config.width, my_config.height, v4l2core_get_requested_frame_format(my_vd))
Loading

File-Level Changes

Change Details Files
Synchronize my_config resolution with the actual device resolution after preparing a new resolution.
  • After calling v4l2core_prepare_new_resolution, update my_config->width from the current device width via get_my_width().
  • After calling v4l2core_prepare_new_resolution, update my_config->height from the current device height via get_my_height().
  • Ensure subsequent v4l2core_update_old_format uses the synced my_config width/height values.
src/src/LPF_V4L2.c

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

@add-uos

add-uos commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

This pr cannot be merged! (status: unstable)

@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 left some high level feedback:

  • If v4l2core_prepare_new_resolution can fail or fall back to a different resolution, consider checking its return value before overwriting my_config->width/height with get_my_width/height so the config only reflects a successfully applied mode.
  • To keep behavior consistent, you might want to explicitly document or assert that get_my_width/height return the final negotiated resolution (not just the requested one), since the config is now fully driven by those accessors after v4l2core_prepare_new_resolution.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- If `v4l2core_prepare_new_resolution` can fail or fall back to a different resolution, consider checking its return value before overwriting `my_config->width/height` with `get_my_width/height` so the config only reflects a successfully applied mode.
- To keep behavior consistent, you might want to explicitly document or assert that `get_my_width/height` return the final negotiated resolution (not just the requested one), since the config is now fully driven by those accessors after `v4l2core_prepare_new_resolution`.

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.

@add-uos

add-uos commented Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 6691fb6 into linuxdeepin:master Aug 18, 2026
18 of 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