Skip to content

fix: Optimize audio initialization timing and DBus interface timeout#757

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:audio-adjust
Nov 17, 2025
Merged

fix: Optimize audio initialization timing and DBus interface timeout#757
deepin-bot[bot] merged 1 commit into
linuxdeepin:develop/snipefrom
dengzhongyuan365-dev:audio-adjust

Conversation

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member
  • Delay audio and camera watcher initialization to recording mode only, avoiding unnecessary resource usage in screenshot mode
  • Add initAudioAndCameraWatchers() method to handle audio/camera initialization separately
  • Set DBus interface timeout to 3 seconds instead of default 25 seconds using AudioDBusTimeout constant
  • Fix memory leaks in RecordProcess audio device name retrieval methods
  • Add null pointer checks for audio watchers in recording stop and mode switching scenarios
  • Stop audio/camera watchers when switching from recording to screenshot mode to save resources

This optimization improves performance by reducing unnecessary audio service initialization in screenshot mode and provides faster DBus response times through reduced timeout values.

修复: 优化音频初始化时机和DBus接口超时配置

  • 将音频和摄像头监视器初始化延迟到录屏模式,避免截图模式下的不必要资源占用
  • 添加initAudioAndCameraWatchers()方法单独处理音频/摄像头初始化逻辑
  • 使用AudioDBusTimeout常量将DBus接口超时时间设置为3秒,替代默认的25秒
  • 修复RecordProcess中音频设备名称获取方法的内存泄漏问题
  • 为录屏停止和模式切换场景添加音频监视器空指针检查

此优化通过减少截图模式下不必要的音频服务初始化提升了性能,并通过缩短超时时间提供了更快的DBus响应速度。

- Delay audio and camera watcher initialization to recording mode only, avoiding unnecessary resource usage in screenshot mode
- Add initAudioAndCameraWatchers() method to handle audio/camera initialization separately
- Set DBus interface timeout to 3 seconds instead of default 25 seconds using AudioDBusTimeout constant
- Fix memory leaks in RecordProcess audio device name retrieval methods
- Add null pointer checks for audio watchers in recording stop and mode switching scenarios
- Stop audio/camera watchers when switching from recording to screenshot mode to save resources

This optimization improves performance by reducing unnecessary audio service initialization in screenshot mode and provides faster DBus response times through reduced timeout values.

修复: 优化音频初始化时机和DBus接口超时配置

- 将音频和摄像头监视器初始化延迟到录屏模式,避免截图模式下的不必要资源占用
- 添加initAudioAndCameraWatchers()方法单独处理音频/摄像头初始化逻辑
- 使用AudioDBusTimeout常量将DBus接口超时时间设置为3秒,替代默认的25秒
- 修复RecordProcess中音频设备名称获取方法的内存泄漏问题
- 为录屏停止和模式切换场景添加音频监视器空指针检查
- 从录屏模式切换到截图模式时停止音频/摄像头监视器以节省资源

此优化通过减少截图模式下不必要的音频服务初始化提升了性能,并通过缩短超时时间提供了更快的DBus响应速度。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

我来对这个diff进行代码审查:

  1. 代码结构和逻辑改进:
  • 将音频和摄像头监视器的初始化逻辑抽取为单独的函数 initAudioAndCameraWatchers() 是很好的重构,提高了代码的可维护性。
  • 在多个地方调用这个初始化函数,但逻辑判断不够统一,建议统一在一个地方判断是否需要初始化。
  1. 代码质量改进:
  • initAudioAndCameraWatchers() 中添加了空指针检查,这是很好的实践。
  • 建议在函数开头添加更多的注释说明,特别是关于初始化时机的说明。
  1. 性能优化:
  • AudioUtils 中添加了 DBus 超时设置是好的改进,可以避免长时间等待。
  • 建议将 AudioDBusTimeout 定义为可配置项,而不是硬编码。
  1. 安全性改进:
  • startCountdown() 中添加了对监视器指针的空检查,提高了代码的健壮性。
  • 建议在 initAudioAndCameraWatchers() 中也添加对 m_toolBarInit 的检查,保持一致性。
  1. 具体建议:
void MainWindow::initAudioAndCameraWatchers()
{
    // 添加更详细的注释
    if (!m_toolBarInit) {  // 添加工具栏初始化检查
        qCWarning(dsrApp) << "工具栏未初始化,跳过音频和摄像头监视器初始化";
        return;
    }

    qCDebug(dsrApp) << "初始化音频和摄像头监视器...";
    
    // 初始化音频监视器
    if (!m_pVoiceVolumeWatcher) {
        m_pVoiceVolumeWatcher = new voiceVolumeWatcher(this);
        m_pVoiceVolumeWatcher->setWatch(true);
        connect(m_pVoiceVolumeWatcher, &voiceVolumeWatcher::sigRecodeState, 
                this, &MainWindow::microPhoneEnable);  // 使用新式连接语法
        emit microPhoneEnable(false);
        qCDebug(dsrApp) << "音频监视器初始化完成";
    }
    
    // 初始化摄像头监视器
    if (!m_pCameraWatcher) {
        m_pCameraWatcher = new CameraWatcher(this);
        m_pCameraWatcher->setWatch(true);
        qCDebug(dsrApp) << "摄像头监视器初始化完成";
    }
}
  1. 其他建议:
  • 考虑将音频和摄像头监视器的初始化时机统一管理,避免在多个地方重复调用。
  • 建议添加错误处理机制,当初始化失败时能够有适当的错误提示。
  • 可以考虑添加监视器的清理函数,在不需要时释放资源。

总的来说,这个改动主要是代码重构,提高了代码的可维护性和健壮性,但还可以进一步优化错误处理和资源管理。

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dengzhongyuan365-dev, 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

@dengzhongyuan365-dev

Copy link
Copy Markdown
Member Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 17, 2025

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot deepin-bot Bot merged commit 79043bb into linuxdeepin:develop/snipe Nov 17, 2025
8 of 9 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