Skip to content

feat: enable the configuration for 8K preview.#502

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

feat: enable the configuration for 8K preview.#502
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
add-uos:master

Conversation

@add-uos

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

Copy link
Copy Markdown
Contributor

Use the DConfig mechanism to enable the configuration for 8K preview. 使用DConfig机制,开放8K预览功能,同时8K不支持录像。
代码来自xiwo分支。

pick form: b5c2d8e

Bug: https://pms.uniontech.com/bug-view-349401.html

Summary by Sourcery

Enable an optional 8K preview mode controlled by configuration, relaxing resolution limits when active while disabling recording at unsupported high resolutions and wiring the setting through the application and camera core.

New Features:

  • Add configurable 8K preview support controlled via DConfig and propagated through DataManager into the V4L2 core.

Enhancements:

  • Adjust resolution validation logic to allow higher resolutions when 8K preview is enabled while preserving existing limits otherwise.
  • Update the main window UI to hide recording controls when the current resolution exceeds the supported limit (e.g. 8K) and improve child widget visibility handling.
  • Add a reset capability to the RollingBox widget to restore its initial position and value.

Use the DConfig mechanism to enable the configuration for 8K preview.
使用DConfig机制,开放8K预览功能,同时8K不支持录像。
代码来自xiwo分支。

pick form: b5c2d8e

Bug: https://pms.uniontech.com/bug-view-349401.html
@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

This PR adds a DConfig-controlled 8K preview capability, relaxes resolution validation when enabled, and conditionally hides recording UI at 8K while wiring the flag through DataManager and v4l2core; it also adds minor UI helper methods.

Sequence diagram for DConfig-controlled 8K preview and UI behavior

sequenceDiagram
    participant AppMain as main
    participant DConfig as DConfig
    participant DataManager as DataManager
    participant V4L2 as v4l2_formats.c
    participant UI as CMainWindow

    AppMain->>DConfig: keyList()
    DConfig-->>AppMain: contains enable8kPreview
    AppMain->>DConfig: value(enable8kPreview)
    DConfig-->>AppMain: bool enable
    AppMain->>DataManager: setEnable8kPreview(enable)
    AppMain->>V4L2: set_enable_8k_preview(enable ? 1 : 0)

    UI->>V4L2: is_valid_resolution(width, height)
    alt enable_8k_preview == 1
        V4L2-->>UI: allow width%16==0 && height%4==0
    else enable_8k_preview == 0
        V4L2-->>UI: enforce MAX_WIDTH_LIMIT, MAX_HEIGHT_LIMIT
    end

    UI->>V4L2: v4l2core_get_frame_width(fd)
    UI->>V4L2: v4l2core_get_frame_height(fd)
    UI->>UI: checkResolutionTooHigh()
    alt resolution too high (e.g. 8K)
        UI->>UI: showChildWidget()
        UI->>UI: showWidget(m_modeSwitchBox, false)
    else resolution normal
        UI->>UI: showChildWidget()
        UI->>UI: showWidget(m_modeSwitchBox, true)
    end
Loading

File-Level Changes

Change Details Files
Introduce a global 8K preview flag in v4l2core and relax resolution validation when 8K preview is enabled.
  • Add static enable_8k_preview flag and accessors set_enable_8k_preview/is_enable_8k_preview.
  • Update is_valid_resolution logic to bypass MAX_WIDTH/HEIGHT limits and use 16x and 4x alignment when 8K preview is enabled.
libcam/libcam_v4l2core/v4l2_formats.c
libcam/libcam_v4l2core/v4l2_formats.h
Wire DConfig-driven 8K preview configuration into the application startup and shared DataManager state.
  • Include v4l2_formats.h in main.cpp to access the new setter.
  • Read enable8kPreview from DConfig, log its value, update DataManager::m_enable8kPreview, and call set_enable_8k_preview with the corresponding int.
  • Extend DataManager with enable8kPreview getter/setter and a backing member variable.
src/main.cpp
src/src/basepub/datamanager.h
Conditionally hide recording controls when current resolution exceeds the 4K limit and ensure child widgets are shown after camera switch.
  • Call showChildWidget() at the end of onSwitchCameraSuccess to refresh the UI for the new camera.
  • Remove a debug log from onSettingsDlgClose.
  • Add CMainWindow::checkResolutionTooHigh() to query current frame size from v4l2core and compare against MAX_WIDTH_LIMIT/MAX_HEIGHT_LIMIT, logging the result.
  • Update showChildWidget() to compute isResolutionTooHigh and hide m_modeSwitchBox when resolution is too high while keeping other widgets visible.
src/src/mainwindow.cpp
src/src/mainwindow.h
Add a reset helper method to RollingBox so it can return to its initial position and notify listeners.
  • Implement RollingBox::reset() to restore m_currentIndex to m_rangeMin, clear deviation, emit currentValueChanged, and trigger repaint.
  • Declare the reset() method and document it in the RollingBox header.
src/src/rollingbox.cpp
src/src/rollingbox.h
Update encoding configuration asset file (details not visible in the diff snippet).
  • Modify org.deepin.camera.encode.json to align with new or existing encoding/preview behavior, likely related to 8K or DConfig integration.
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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:98分

■ 【总体评价】

代码实现了通过DConfig控制8K预览功能并在高分辨率下禁用录像模式,逻辑清晰且注释完善
逻辑正确但因全局变量无锁访问存在轻微竞态风险扣2分

■ 【详细分析】

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

is_valid_resolution 函数中新增了针对8K分辨率的条件分支,放宽了宽高限制并调整了对齐要求,逻辑正确。checkResolutionTooHigh 函数正确获取了当前设备宽高并与限制值比较。RollingBox::reset 函数正确重置了状态并发送信号。
潜在问题:v4l2_formats.c 中的全局变量 enable_8k_preview 在多线程环境下被 set_enable_8k_preview 修改和 is_valid_resolution 读取时存在竞态条件
建议:如果存在多线程访问场景,建议为 enable_8k_preview 添加互斥锁保护或使用原子操作

  • 2.代码质量 良好 ✓

代码注释非常详细,特别是 main.cpp 中解释了希沃8K分辨率的需求及默认关闭的原因,有助于后续维护。命名规范符合项目风格,DataManager 中新增的接口设计合理。
潜在问题:v4l2_formats.c 中使用全局变量控制行为属于轻微的代码异味
建议:可考虑将配置作为参数传递或封装在设备上下文结构体中,减少全局状态依赖

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

checkResolutionTooHighshowChildWidget 中调用,通过 v4l2core_get_frame_width/height 获取宽高,通常为简单的内存读取,开销极小。RollingBox::reset 仅执行简单赋值和界面更新,无性能瓶颈。
建议:无需优化

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
代码未引入外部输入处理、内存操作或权限相关的高风险操作,DConfig读取有有效性校验,设备句柄有空指针检查,整体安全。
建议:保持现有的防御性编程习惯

■ 【改进建议代码示例】

// libcam/libcam_v4l2core/v4l2_formats.c
#include <pthread.h>

static int enable_8k_preview = 0;
static pthread_mutex_t preview_mutex = PTHREAD_MUTEX_INITIALIZER;

int is_valid_resolution(int width, int height)
{
    int current_enable_8k;
    pthread_mutex_lock(&preview_mutex);
    current_enable_8k = enable_8k_preview;
    pthread_mutex_unlock(&preview_mutex);

    if (current_enable_8k) {
        return (width > 0 && height > 0)
                && (width % 16 == 0 && height % 4 == 0);
    }

    return (width > 0 && height > 0) 
            && (width <= MAX_WIDTH_LIMIT && height <= MAX_HEIGHT_LIMIT) 
            && (width % 16 == 0 && height % 8 == 0);
}

void set_enable_8k_preview(int enable)
{
    pthread_mutex_lock(&preview_mutex);
    enable_8k_preview = enable;
    pthread_mutex_unlock(&preview_mutex);
}

int is_enable_8k_preview()
{
    int current_enable_8k;
    pthread_mutex_lock(&preview_mutex);
    current_enable_8k = enable_8k_preview;
    pthread_mutex_unlock(&preview_mutex);
    return current_enable_8k;
}

@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 8K preview enable state is now tracked both in DataManager::m_enable8kPreview and the global enable_8k_preview in v4l2_formats.c; consider centralizing this into a single source of truth (e.g., one getter/setter that updates both layers) to avoid future divergence.
  • checkResolutionTooHigh() hides the mode switch UI based purely on MAX_WIDTH_LIMIT/MAX_HEIGHT_LIMIT, while is_valid_resolution() changes its constraints when 8K is enabled; it may be clearer and safer to base the UI behavior on the 8K-enable flag (or a shared helper) so resolution/feature gating logic stays consistent between core and UI.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The 8K preview enable state is now tracked both in `DataManager::m_enable8kPreview` and the global `enable_8k_preview` in `v4l2_formats.c`; consider centralizing this into a single source of truth (e.g., one getter/setter that updates both layers) to avoid future divergence.
- `checkResolutionTooHigh()` hides the mode switch UI based purely on `MAX_WIDTH_LIMIT`/`MAX_HEIGHT_LIMIT`, while `is_valid_resolution()` changes its constraints when 8K is enabled; it may be clearer and safer to base the UI behavior on the 8K-enable flag (or a shared helper) so resolution/feature gating logic stays consistent between core and UI.

## Individual Comments

### Comment 1
<location path="libcam/libcam_v4l2core/v4l2_formats.h" line_range="136" />
<code_context>
+ * returns: TRUE(1) if enabled
+ *          FALSE(0) if not
+ */
+int is_enable_8k_preview();
+
 #endif
</code_context>
<issue_to_address>
**nitpick:** Use an explicit void parameter list for the C API to avoid old-style function declarations.

Declare this as `int is_enable_8k_preview(void);` and update the definition accordingly. Using `void` avoids the old-style "unspecified parameters" meaning of `()` and lets the compiler catch signature mismatches.
</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.

* returns: TRUE(1) if enabled
* FALSE(0) if not
*/
int is_enable_8k_preview();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nitpick: Use an explicit void parameter list for the C API to avoid old-style function declarations.

Declare this as int is_enable_8k_preview(void); and update the definition accordingly. Using void avoids the old-style "unspecified parameters" meaning of () and lets the compiler catch signature mismatches.

@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 84dd8ec 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