fix: 将摄像头卡片过滤关键字改为 DConfig 配置#481
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Resurgamz The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's GuideThis PR moves camera card filter keywords from being hardcoded in the V4L2 device enumeration to a DConfig-driven configuration (CardKeywords), adding a libcam API to receive keywords from the Qt main process and using them to skip matching V4L2 devices. Sequence diagram for DConfig-driven camera card keyword filteringsequenceDiagram
participant MainProcess
participant DConfig
participant libcam_camview
participant V4L2Devices
MainProcess->>DConfig: value(CardKeywords)
DConfig-->>MainProcess: QStringList
MainProcess->>libcam_camview: set_card_keywords(keywords, count)
MainProcess->>V4L2Devices: enum_v4l2_devices()
V4L2Devices->>libcam_camview: get_card_keywords(count)
libcam_camview-->>V4L2Devices: const char** card_keywords
loop each V4L2 device
V4L2Devices->>V4L2Devices: [card matches card_keywords]
alt match
V4L2Devices->>V4L2Devices: m_v4l2_close(fd)
V4L2Devices->>V4L2Devices: continue
else no match
V4L2Devices->>V4L2Devices: keep device
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In enum_v4l2_devices(), get_card_keywords() is called on every directory entry; consider moving the call (and associated keyword lookup setup) outside the loop so the keyword array is fetched once per enumeration instead of once per device.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In enum_v4l2_devices(), get_card_keywords() is called on every directory entry; consider moving the call (and associated keyword lookup setup) outside the loop so the keyword array is fetched once per enumeration instead of once per device.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
将原先在 enum_v4l2_devices 中硬编码的摄像头卡片关键字迁移到 org.deepin.camera.encode.json 的 CardKeywords 配置项中,并在启动时 从 DConfig 读取后动态传递给 libcam 使用,支持后续通过配置增删过滤关键字。 Log: 将摄像头卡片过滤关键字设置为DConfig配置
deepin pr auto review你好!我是CodeGeeX,我已经仔细审查了你提供的Git Diff。本次代码变更的主要目的是通过DConfig配置一组关键字(CardKeywords),在枚举V4L2设备时,如果设备的 整体来看,代码逻辑清晰,C和C++的边界处理得当,内存管理也考虑了空指针和释放问题。但是,在代码性能、代码质量和代码安全方面,还有一些可以改进和优化的空间。以下是详细的审查意见: 1. 代码性能问题:
2. 代码质量问题一:C++侧的悬垂指针风险
问题二:C与C++侧对空格字符串的重复过滤
问题三:C++侧的废弃API使用
3. 代码安全问题一:
问题二:
4. 修改建议代码示例针对上述主要问题,提供以下修改后的代码片段供参考: v4l2_devices.c (引入大小写不敏感匹配): // 如果平台支持 GNU extension,可以直接使用 strcasestr
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <string.h>
// ... 在 enum_v4l2_devices 函数中 ...
int is_card_keyword_device = 0;
for (int i = 0; i < num_card_keywords; i++) {
if(card_keywords[i] != NULL && strcasestr((const char *)v4l2_cap.card, card_keywords[i]) != NULL) {
is_card_keyword_device = 1;
break;
}
}globalutils.cpp (修复废弃API): QStringList GlobalUtils::parseStringListConfig(const QVariant &value)
{
QStringList rawList;
// 使用 userType 替代废弃的 type()
if (value.userType() == QMetaType::QStringList) {
rawList = value.toStringList();
} else if (value.userType() == QMetaType::QVariantList) {
const QVariantList variantList = value.toList();
for (const QVariant &item : variantList) {
if (item.userType() == QMetaType::QString) {
rawList.append(item.toString());
}
}
} else {
return QStringList();
}
QStringList result;
for (const QString &keyword : rawList) {
if (!keyword.trimmed().isEmpty()) {
result.append(keyword);
}
}
return result;
}camview.c (补充错误日志): card_keywords[card_keyword_count] = strdup(keywords[i]);
if (card_keywords[card_keyword_count] != NULL) {
card_keyword_count++;
} else {
fprintf(stderr, "deepin-camera: failed to duplicate card keyword: %s\n", keywords[i]);
}main.cpp (添加安全注释): if (dconfig && dconfig->isValid() && dconfig->keyList().contains("CardKeywords")) {
QStringList cardKeywords = GlobalUtils::parseStringListConfig(dconfig->value("CardKeywords"));
QVector<QByteArray> keywordBytes;
QVector<const char *> keywordData;
keywordBytes.reserve(cardKeywords.size());
keywordData.reserve(cardKeywords.size());
for (const QString &keyword : cardKeywords) {
keywordBytes.append(keyword.toUtf8());
keywordData.append(keywordBytes.last().constData());
}
qInfo() << "card keywords:" << cardKeywords;
// 注意: set_card_keywords 内部对传入的字符串使用了 strdup 进行深拷贝,
// 因此虽然 keywordData 是临时指针,在此处生命周期结束后不会导致悬垂指针问题。
set_card_keywords(keywordData.data(), keywordData.size());
}希望这些审查意见对你有所帮助!如果有任何疑问,欢迎继续探讨。 |
将原先在 enum_v4l2_devices 中硬编码的摄像头卡片关键字迁移到
org.deepin.camera.encode.json 的 CardKeywords 配置项中,并在启动时
从 DConfig 读取后动态传递给 libcam 使用,支持后续通过配置增删过滤关键字。
Log: 将摄像头卡片过滤关键字设置为DConfig配置
Summary by Sourcery
Move camera card filter keywords from hardcoded v4l2 enumeration logic to a dynamic, DConfig-driven configuration and propagate them into libcam for runtime filtering.
Enhancements: