feat: Implement hardware acceleration driver configuration support#402
Conversation
- Added set/get functions for LIBVA_DRIVER_NAME and VDPAU_DRIVER environment variables - Integrated driver configuration loading from dconfig settings during application startup - Set environment variables for VAAPI and VDPAU hardware codec acceleration - Enhanced configuration file with corrected parameter names and descriptions - Added debug logging for driver configuration values and environment variables Log: Add hardware acceleration driver configuration support Bug: https://pms.uniontech.com/bug-view-335297.html
deepin pr auto review这段代码主要添加了对libva和libvdpau驱动名称的支持,我来分析一下代码的各个方面: 语法逻辑
代码质量
代码性能
代码安全
具体改进建议
#define MAX_DRIVER_NAME_LENGTH 200
static char libva_driver_name[MAX_DRIVER_NAME_LENGTH];
static char libvdpau_driver_name[MAX_DRIVER_NAME_LENGTH];
static void set_driver_name(char *driver_name, const char *name, size_t max_len) {
if (name != NULL) {
memset(driver_name, 0, max_len);
strncpy(driver_name, name, max_len - 1);
} else {
memset(driver_name, 0, max_len);
}
}
void set_libva_driver_name(const char *name) {
if (name != NULL && strlen(name) < MAX_DRIVER_NAME_LENGTH - 1) {
set_driver_name(libva_driver_name, name, MAX_DRIVER_NAME_LENGTH);
} else {
memset(libva_driver_name, 0, MAX_DRIVER_NAME_LENGTH);
}
}
void set_environment_variables() {
if (!libVaDriverName.isEmpty()) {
qputenv("LIBVA_DRIVER_NAME", libVaDriverName.toLocal8Bit());
}
if (!libVdpauDriverName.isEmpty()) {
qputenv("VDPAU_DRIVER", libVdpauDriverName.toLocal8Bit());
}
}总体来说,这段代码的实现是合理的,但可以通过上述建议进一步提高代码的健壮性和可维护性。 |
There was a problem hiding this comment.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/main.cpp:146` </location>
<code_context>
set_project_id(projectId.toUtf8().constData());
}
+
+ QString libVaDriverName = "";
+ if (dconfig && dconfig->isValid() && dconfig->keyList().contains("libVaDriverName")) {
+ libVaDriverName = dconfig->value("libVaDriverName").toString();
</code_context>
<issue_to_address>
**issue (complexity):** Consider refactoring the repeated driver configuration logic into a single helper function to reduce duplication and centralize future changes.
You can collapse all of the repeated “read‐key → call C-API → setenv → log” logic into a single helper. For example:
```cpp
// place this helper near the top of your function (or in an anonymous/local namespace)
auto configureDriver = [&](const char* configKey,
void (*setter)(const char*),
const char* envVarName)
{
if (dconfig && dconfig->isValid() && dconfig->keyList().contains(configKey)) {
const QString name = dconfig->value(configKey).toString();
setter(name.toUtf8().constData());
if (!name.isEmpty())
qputenv(envVarName, name.toLocal8Bit());
qInfo() << QString("%1 value is:").arg(configKey) << name
<< envVarName << qgetenv(envVarName);
}
};
```
Then replace your two blocks with:
```cpp
configureDriver("libVaDriverName", set_libva_driver_name, "LIBVA_DRIVER_NAME");
configureDriver("libVdpauDriver", set_libvdpau_driver_name, "VDPAU_DRIVER");
```
This keeps all functionality intact, removes duplication, and centralizes any future tweaks to logging, env-setting or config-access.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Reviewer's GuideThis PR adds support for configuring hardware acceleration drivers by introducing new driver name accessors, loading settings from dconfig at startup to set LIBVA_DRIVER_NAME and VDPAU_DRIVER environment variables (with debug logging), and correcting parameter names in the application's configuration file. Sequence diagram for driver configuration loading and environment setup at startupsequenceDiagram
participant App as "Application Startup"
participant DConfig as "dconfig (settings)"
participant CamView as "camview (driver accessors)"
participant Env as "Environment"
App->>DConfig: Load configuration
DConfig-->>App: Return driver names (libVaDriverName, libVdpauDriver)
App->>CamView: set_libva_driver_name(libVaDriverName)
App->>CamView: set_libvdpau_driver_name(libVdpauDriverName)
App->>Env: Set LIBVA_DRIVER_NAME
App->>Env: Set VDPAU_DRIVER
App->>App: Log driver names and env variables
Class diagram for new hardware driver name accessorsclassDiagram
class camview {
+void set_libva_driver_name(const char *name)
+const char* get_libva_driver_name(void)
+void set_libvdpau_driver_name(const char *name)
+const char* get_libvdpau_driver_name(void)
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, max-lvs 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 |
|
/merge |
Log: Add hardware acceleration driver configuration support
Bug: https://pms.uniontech.com/bug-view-335297.html
Summary by Sourcery
Implement hardware acceleration driver configuration support by introducing APIs for driver name management, loading settings from configuration, exporting environment variables, and adding debug logs
New Features:
Enhancements: