Skip to content

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

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
lichaofan2008:release/eagle
Mar 16, 2026
Merged

feat: enable the configuration for 8K preview.#462
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
lichaofan2008:release/eagle

Conversation

@lichaofan2008
Copy link
Contributor

@lichaofan2008 lichaofan2008 commented Mar 16, 2026

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

Summary by Sourcery

Enable configurable 8K camera preview support while disabling recording at 8K resolutions.

New Features:

  • Add DConfig-controlled switch to enable 8K camera preview for supported vendors.
  • Expose APIs in the V4L2 format layer and data manager to control 8K preview enablement.

Enhancements:

  • Relax resolution validation limits when 8K preview is enabled to allow higher resolutions like 8192x2772.
  • Hide or reset the recording mode UI when the current resolution exceeds the maximum supported recording width.
  • Add a reset capability to the rolling selector widget used for mode switching.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 16, 2026

Reviewer's Guide

Enables configurable 8K preview via DConfig, loosens resolution validation when 8K preview is enabled, and disables recording UI/behavior at 8K while wiring configuration through DataManager and the V4L2 layer.

Sequence diagram for 8K preview configuration on startup

sequenceDiagram
    participant Main
    participant DConfig
    participant DataManager
    participant V4L2Formats

    Main->>DConfig: isValid()
    alt DConfig valid
        Main->>DConfig: keyList()
        DConfig-->>Main: list
        Main->>DConfig: value(enable8kPreview)
        DConfig-->>Main: bool enable
        Main->>DataManager: setEnable8kPreview(enable)
        Main->>V4L2Formats: set_enable_8k_preview(enable ? 1 : 0)
    else DConfig invalid or key missing
        Main-->>Main: use default 8K preview disabled
    end

    note over V4L2Formats: enable_8k_preview affects is_valid_resolution
Loading

Updated class diagram for 8K preview configuration and UI control

classDiagram
    class DataManager {
        -DataManager *m_dataManager
        -bool m_isInstallFilter
        -bool m_bSupportSnapshot
        -bool m_isSupportCameraSwitch
        -bool m_isPreviewNoDelay
        -bool m_enableUsbGroup
        -bool m_enable8kPreview
        +static DataManager *instance()
        +bool isInstallFilter()
        +bool isSupportSnapshot()
        +bool isSupportCameraSwitch()
        +bool isPreviewNoDelay()
        +bool isEnableUsbGroup()
        +void setEnableUsbGroup(bool enable)
        +void setEnable8kPreview(bool enable)
        +bool isEnable8kPreview()
    }

    class CMainWindow {
        +~CMainWindow()
        +void onSwitchCameraSuccess(QString cameraName)
        +void onSettingsDlgClose()
        +void showChildWidget()
        +void showWidget(DWidget *widget, bool bShow)
        +bool checkResolutionTooHigh()
        -DWidget *m_snapshotLabel
        -DWidget *m_cameraSwitchBtn
        -RollingBox *m_modeSwitchBox
        -DWidget *m_photoRecordBtn
        -DWidget *m_takePhotoSettingArea
        -DWidget *m_filterName
        -bool m_bSwitchCameraShowEnable
    }

    class RollingBox {
        -int m_currentIndex
        -int m_rangeMin
        -int m_rangeMax
        -int m_deviation
        +int getCurrentValue()
        +void reset()
        +void setDeviation(int n)
        +void wheelEvent(QWheelEvent *event)
        +void mousePressEvent(QMouseEvent *event)
        +void mouseMoveEvent(QMouseEvent *event)
        +void mouseReleaseEvent(QMouseEvent *event)
    }

    class V4L2Formats {
        -int enable_8k_preview
        +int is_valid_resolution(int width, int height)
        +void set_enable_8k_preview(int enable)
        +int is_enable_8k_preview()
    }

    class V4L2DeviceHandler {
        +v4l2_dev_t *get_v4l2_device_handler()
        +int v4l2core_get_frame_width(v4l2_dev_t *fd)
    }

    CMainWindow --> RollingBox : uses
    CMainWindow --> V4L2DeviceHandler : queries_width
    CMainWindow ..> V4L2Formats : affected_by_is_valid_resolution
    DataManager ..> V4L2Formats : configures_8K_preview
Loading

Flow diagram for resolution validation and UI behavior with 8K preview

flowchart TD
    A[Start_resolution_validation] --> B{enable_8k_preview?}
    B -->|Yes| C{width > 0 and height > 0?}
    C -->|No| Z[Resolution_invalid]
    C -->|Yes| D{width % 16 == 0 and height % 4 == 0?}
    D -->|Yes| Y[Resolution_valid]
    D -->|No| Z

    B -->|No| E{width > 0 and height > 0?}
    E -->|No| Z
    E -->|Yes| F{width <= MAX_WIDTH_LIMIT and height <= MAX_HEIGHT_LIMIT?}
    F -->|No| Z
    F -->|Yes| G{width % 16 == 0 and height % 8 == 0?}
    G -->|Yes| Y
    G -->|No| Z

    subgraph UI_behavior_in_CMainWindow
        H[Check_resolution_too_high] --> I[get_v4l2_device_handler]
        I --> J{handler_exists?}
        J -->|No| K[Assume_width_0]
        J -->|Yes| L[v4l2core_get_frame_width]
        L --> M[Compare_width_to_MAX_WIDTH_LIMIT]
        K --> M
        M --> N{currentWidth > MAX_WIDTH_LIMIT?}
        N -->|Yes| O[isResolutionTooHigh = true]
        N -->|No| P[isResolutionTooHigh = false]
        O --> Q[showChildWidget_hides_modeSwitchBox]
        P --> R[showChildWidget_shows_modeSwitchBox]
    end
Loading

File-Level Changes

Change Details Files
Add global 8K preview switch in v4l2 formats and relax resolution validation when enabled.
  • Introduce global flag enable_8k_preview with default 0
  • Alter is_valid_resolution to bypass 4K max limit and use looser alignment constraints when 8K preview is enabled
  • Expose setters/getters set_enable_8k_preview and is_enable_8k_preview in v4l2_formats.c and v4l2_formats.h
libcam/libcam_v4l2core/v4l2_formats.c
libcam/libcam_v4l2core/v4l2_formats.h
Wire 8K preview enablement from DConfig through DataManager into the V4L2 core.
  • Extend DataManager to store an m_enable8kPreview flag with simple setter/getter
  • In main(), read DConfig key enable8kPreview, log its value, store it in DataManager, and forward it to the V4L2 layer via set_enable_8k_preview
src/src/basepub/datamanager.h
src/main.cpp
Hide/disable recording UI when current resolution exceeds the 4K width limit (8K case).
  • On camera switch success and settings dialog close, call showChildWidget to refresh visible controls
  • Add CMainWindow::checkResolutionTooHigh() to query current frame width via v4l2core_get_frame_width and compare with MAX_WIDTH_LIMIT
  • Update showChildWidget() to hide m_modeSwitchBox when resolution is too high and reset it when closing settings at high resolution
src/src/mainwindow.cpp
src/src/mainwindow.h
Allow resetting the RollingBox selector to its initial state, used when disabling recording at 8K.
  • Add RollingBox::reset() that restores m_currentIndex to m_rangeMin, clears deviation, emits currentValueChanged, and repaints
src/src/rollingbox.cpp
src/src/rollingbox.h

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

  • The enable_8k_preview flag and its accessors in v4l2_formats.c/.h are modeled as int; consider using bool in the C++-facing API and a more explicit name (e.g. g_enable_8k_preview) to better convey semantics and global scope, and keep naming consistent with DataManager::setEnable8kPreview.
  • checkResolutionTooHigh() only checks width against MAX_WIDTH_LIMIT and ignores height; if the intent is to mirror the resolution constraints used in is_valid_resolution, consider checking height and alignment constraints as well so UI behavior matches backend capability checks.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `enable_8k_preview` flag and its accessors in `v4l2_formats.c/.h` are modeled as `int`; consider using `bool` in the C++-facing API and a more explicit name (e.g. `g_enable_8k_preview`) to better convey semantics and global scope, and keep naming consistent with `DataManager::setEnable8kPreview`.
- `checkResolutionTooHigh()` only checks width against `MAX_WIDTH_LIMIT` and ignores height; if the intent is to mirror the resolution constraints used in `is_valid_resolution`, consider checking height and alignment constraints as well so UI behavior matches backend capability checks.

## Individual Comments

### Comment 1
<location path="libcam/libcam_v4l2core/v4l2_formats.c" line_range="122-123" />
<code_context>
 	0
 };

+// 是否开启8K预览
+int enable_8k_preview = 0;
+
 /* FIXME: doesn't support bigendian formats=> fourcc | (1 << 31)
</code_context>
<issue_to_address>
**suggestion:** Limit the 8K preview flag’s linkage scope to this translation unit

Given `set_enable_8k_preview`/`is_enable_8k_preview` already provide access, this variable doesn’t need external linkage. Please make `enable_8k_preview` `static` (or move it into an internal struct) to avoid exporting a global symbol and reduce risk of name collisions or unintended external modification.

```suggestion
/* 是否开启8K预览
 * Restrict linkage to this translation unit; external access should go
 * through set_enable_8k_preview()/is_enable_8k_preview().
 */
static int enable_8k_preview = 0;
```
</issue_to_address>

### Comment 2
<location path="src/src/mainwindow.cpp" line_range="2362-2373" />
<code_context>
+    if (fd) {
+        currentWidth = v4l2core_get_frame_width(fd);
+    }
+    bool isTrue = currentWidth > MAX_WIDTH_LIMIT;
+    qInfo() << __func__ << isTrue << currentWidth;
+
+    return isTrue;
</code_context>
<issue_to_address>
**suggestion (performance):** Avoid noisy logging in a frequently called helper

If `checkResolutionTooHigh()` is invoked on every UI update (e.g. via `showChildWidget()`), this `qInfo()` will produce excessive log output in normal use. Consider logging only on state changes (when the result flips), lowering this to a debug-level log, or removing it once initial debugging is done.

```suggestion
bool CMainWindow::checkResolutionTooHigh()
{
    int currentWidth = 0;
    v4l2_dev_t *fd = get_v4l2_device_handler();
    if (fd) {
        currentWidth = v4l2core_get_frame_width(fd);
    }

    bool isTrue = currentWidth > MAX_WIDTH_LIMIT;

    // Log only when the result changes to avoid noisy logging in frequent calls.
    static bool lastIsTrue = false;
    if (isTrue != lastIsTrue) {
        qInfo() << __func__ << "resolutionTooHigh changed:" << isTrue << "width:" << currentWidth;
        lastIsTrue = isTrue;
    }

    return isTrue;
}
```
</issue_to_address>

### Comment 3
<location path="src/src/mainwindow.h" line_range="207" />
<code_context>
+    /**
+    * @brief 检测分辨率是否太高,8K分辨率不显示录像功能
+    */
+    bool checkResolutionTooHigh();
+
 private slots:
</code_context>
<issue_to_address>
**suggestion:** Mark `checkResolutionTooHigh` as `const` since it doesn’t modify state

`checkResolutionTooHigh()` only queries the V4L2 device and doesn’t modify any members, so it can be declared `const`. This improves clarity and allows calls on `const` instances of the class.

Suggested implementation:

```c
    /**
    * @brief 检测分辨率是否太高,8K分辨率不显示录像功能
    */
    bool checkResolutionTooHigh() const;

```

You will also need to update the corresponding definition in the `.cpp` file (likely `mainwindow.cpp`) to match the new signature by adding `const`:

- Change `bool MainWindow::checkResolutionTooHigh()` to `bool MainWindow::checkResolutionTooHigh() const`.

Ensure any overrides or interface declarations are updated similarly if this method is virtual or declared in a base class.
</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 +2362 to +2373
bool CMainWindow::checkResolutionTooHigh()
{
int currentWidth = 0;
v4l2_dev_t *fd = get_v4l2_device_handler();
if (fd) {
currentWidth = v4l2core_get_frame_width(fd);
}
bool isTrue = currentWidth > MAX_WIDTH_LIMIT;
qInfo() << __func__ << isTrue << currentWidth;

return isTrue;
}
Copy link

Choose a reason for hiding this comment

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

suggestion (performance): Avoid noisy logging in a frequently called helper

If checkResolutionTooHigh() is invoked on every UI update (e.g. via showChildWidget()), this qInfo() will produce excessive log output in normal use. Consider logging only on state changes (when the result flips), lowering this to a debug-level log, or removing it once initial debugging is done.

Suggested change
bool CMainWindow::checkResolutionTooHigh()
{
int currentWidth = 0;
v4l2_dev_t *fd = get_v4l2_device_handler();
if (fd) {
currentWidth = v4l2core_get_frame_width(fd);
}
bool isTrue = currentWidth > MAX_WIDTH_LIMIT;
qInfo() << __func__ << isTrue << currentWidth;
return isTrue;
}
bool CMainWindow::checkResolutionTooHigh()
{
int currentWidth = 0;
v4l2_dev_t *fd = get_v4l2_device_handler();
if (fd) {
currentWidth = v4l2core_get_frame_width(fd);
}
bool isTrue = currentWidth > MAX_WIDTH_LIMIT;
// Log only when the result changes to avoid noisy logging in frequent calls.
static bool lastIsTrue = false;
if (isTrue != lastIsTrue) {
qInfo() << __func__ << "resolutionTooHigh changed:" << isTrue << "width:" << currentWidth;
lastIsTrue = isTrue;
}
return isTrue;
}

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

Bug: https://pms.uniontech.com/bug-view-349401.html
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要实现了针对8K分辨率(特别是希沃品牌的8192x2772分辨率)的预览支持,并通过配置开关控制是否启用该功能。同时,为了防止在高分辨率下录像出现问题,代码增加了在8K分辨率下禁用录像功能的逻辑。

以下是对该代码的审查意见,分为语法逻辑、代码质量、代码性能和代码安全四个方面:

1. 语法逻辑

  • 逻辑一致性
    • v4l2_formats.c 中,enable_8k_preview 被初始化为 0 (False),这与 JSON 配置文件中的默认值 false 保持一致,逻辑正确。
    • is_valid_resolution 函数的修改逻辑清晰:当开启8K预览时,放宽宽高限制(仅要求正整数和对齐),否则保持原有的 MAX_WIDTH_LIMITMAX_HEIGHT_LIMIT 限制。
  • 边界条件
    • is_valid_resolution 中对 8K 模式的判断条件是 width > 0 && height > 0。虽然代码注释提到希沃的分辨率是 8192x2772,但逻辑上允许任意正分辨率通过。如果目的是专门针对希沃,建议确认是否需要更精确的范围限制,或者当前的通用放宽策略是符合预期的(看起来是为了通用性而放宽)。
  • 函数命名
    • is_enable_8k_preview() 函数名使用了 is_ 前缀,通常返回布尔值,但代码中返回的是 int。虽然在 C 语言中 int 常被用作布尔值,但在 C++ 上下文中(main.cpp 包含了该头文件),这种命名习惯可能会引起轻微的混淆。不过考虑到它是 C 接口,可以接受。

2. 代码质量

  • 注释与文档
    • 代码中的注释非常详尽,特别是在 main.cpp 中解释了为什么要引入这个功能(希沃的需求、录像异常、默认关闭的原因),这对于后续维护非常有帮助。
    • v4l2_formats.c 中的注释指出了具体的分辨率数值,便于理解上下文。
  • 代码复用与封装
    • CMainWindow::checkResolutionTooHigh() 方法被提取出来,用于判断当前分辨率是否超过限制,避免了在多处重复判断宽高逻辑,提高了代码的可维护性。
    • RollingBox::reset() 方法被添加,用于将模式切换框重置到初始状态(拍照模式),逻辑清晰。
  • 魔数
    • is_valid_resolution 中,8K 模式下宽的对齐要求是 16,高是 4;非 8K 模式下宽的对齐要求是 16,高是 8。建议将这些对齐值定义为宏或常量(例如 ALIGN_WIDTH_8K, ALIGN_HEIGHT_8K 等),以提高代码可读性。

3. 代码性能

  • 频繁调用
    • checkResolutionTooHigh() 函数在 onSettingsDlgCloseshowChildWidget 中被调用。showChildWidget 可能会被频繁调用(如窗口大小改变、状态更新等)。该函数内部调用了 v4l2core_get_frame_widthv4l2core_get_frame_height。如果这些函数涉及硬件访问或复杂的计算,频繁调用可能会影响性能。
    • 建议:考虑在分辨率改变时(例如切换摄像头或格式时)缓存当前的分辨率状态,或者确保 v4l2core_get_frame_width/height 只是简单的内存读取操作。

4. 代码安全

  • 类型安全
    • main.cpp 中,set_enable_8k_preview(enable ? 1 : 0) 将 C++ 的 bool 显式转换为 C 的 int,这是良好的实践,避免了隐式转换可能带来的警告或问题。
  • 线程安全
    • enable_8k_preview 是一个静态全局变量。set_enable_8k_preview 会在 main 函数初始化阶段被调用。如果后续程序运行过程中有其他线程可能修改或读取该变量(虽然目前看起来只在初始化时设置),则需要考虑加锁保护。目前的实现假设是单线程初始化或后续只读,风险较小。
  • 空指针检查
    • checkResolutionTooHigh 中对 fd 进行了判空检查,这是安全的。
  • 配置读取
    • main.cpp 中读取 enable8kPreview 配置时,检查了 dconfig 的有效性以及 key 是否存在,处理得比较稳妥。

总结与改进建议

  1. 消除魔数:建议将 v4l2_formats.c 中的对齐参数(16, 4, 8)定义为宏常量,增加可读性。
    #define WIDTH_ALIGNMENT 16
    #define HEIGHT_ALIGNMENT_STD 8
    #define HEIGHT_ALIGNMENT_8K 4
  2. 性能优化:建议确认 v4l2core_get_frame_width/height 的开销。如果开销较大,建议在 CMainWindow 中增加成员变量缓存当前分辨率,仅在分辨率变化事件发生时更新,从而减少 checkResolutionTooHigh 的调用开销。
  3. 逻辑微调is_valid_resolution 在 8K 模式下仅检查 > 0 和对齐。如果未来有其他超高清分辨率(如 10K)且硬件不支持,此逻辑会允许通过。建议确认是否需要设置一个更高的上限(例如 16384)或者保持现状(依赖硬件能力)。
  4. 代码风格is_enable_8k_preview 命名略显生硬,若不涉及 ABI 兼容性问题,可考虑改为 is_8k_preview_enabled,但这属于次要问题。

总体而言,这段代码逻辑清晰,注释完善,能够较好地解决特定硬件(希沃8K)的兼容性问题,同时通过配置开关控制风险,实现方式是合理的。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lichaofan2008, max-lvs

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

@lichaofan2008
Copy link
Contributor Author

/merge

@deepin-bot deepin-bot bot merged commit b5c2d8e into linuxdeepin:release/eagle Mar 16, 2026
22 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