fix: fix audio resume logic for default sink/source#1026
fix: fix audio resume logic for default sink/source#1026robertkill merged 1 commit intolinuxdeepin:masterfrom
Conversation
The previous logic had a bug where resumeSinkConfig and resumeSourceConfig would only be called if autoSwitchOutputPort or autoSwitchInputPort returned false. This could cause issues when a default sink or source already exists (non-nil) but auto-switching succeeded. The fix ensures that resume config is also called when a default sink or source is already present, regardless of the auto- switch result. This prevents potential audio configuration issues after initialization. Influence: 1. Test audio initialization with existing default sink and source 2. Verify audio output resumes correctly after system startup 3. Test audio input configuration persistence 4. Verify behavior when auto-switching succeeds but default devices exist 5. Test audio functionality after suspend/resume cycles fix: 修复默认音频输入输出设备的恢复逻辑 之前的逻辑存在一个缺陷,只有当自动切换输出端口或输入端口返回 false 时, 才会调用 resumeSinkConfig 和 resumeSourceConfig。这可能导致当默认音频输 出或输入设备已经存在(非空)但自动切换成功时出现问题。修复确保当默认音频 输出或输入设备已经存在时,无论自动切换结果如何,都会调用恢复配置。这可以 防止初始化后可能出现的音频配置问题。 Influence: 1. 测试存在默认音频输出和输入设备时的音频初始化 2. 验证系统启动后音频输出是否正确恢复 3. 测试音频输入配置的持久性 4. 验证当自动切换成功但默认设备存在时的行为 5. 测试系统休眠唤醒后的音频功能 PMS: BUG-349719
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts audio initialization so that sink/source resume configuration is applied whenever a default device exists, even if auto-switching to ports succeeds, preventing missed resume of audio settings. Sequence diagram for updated audio init resume logicsequenceDiagram
participant Audio
participant OutputPort
participant SinkConfig
participant InputPort
participant SourceConfig
Audio->>Audio: init()
activate Audio
Audio->>OutputPort: autoSwitchOutputPort()
OutputPort-->>Audio: successOrFailure
alt autoSwitchOutputPort_failed OR defaultSink_not_nil
Audio->>SinkConfig: resumeSinkConfig(defaultSink)
end
Audio->>InputPort: autoSwitchInputPort()
InputPort-->>Audio: successOrFailure
alt autoSwitchInputPort_failed OR defaultSource_not_nil
Audio->>SourceConfig: resumeSourceConfig(defaultSource)
end
deactivate Audio
Class diagram for Audio init and resume behaviorclassDiagram
class Audio {
+defaultSink
+defaultSource
+init() error
+autoSwitchOutputPort() bool
+autoSwitchInputPort() bool
+resumeSinkConfig(sink)
+resumeSourceConfig(source)
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这段代码修改涉及音频设备初始化逻辑中关于默认设备配置恢复的判断条件。以下是对该代码修改的审查意见,包括语法逻辑、代码质量、代码性能和代码安全四个方面: 1. 语法逻辑问题:布尔逻辑存在潜在缺陷 这里存在逻辑反转的风险。
改进意见:
2. 代码质量问题:可读性与意图表达 改进意见: // 只有在非自动切换模式下,且存在默认设备时,才恢复配置
if !a.autoSwitchOutputPort() {
if a.defaultSink != nil {
a.resumeSinkConfig(a.defaultSink)
}
}或者如果是为了在自动切换模式下也强制恢复(如果这是业务需求): // 如果存在默认设备,总是尝试恢复配置(无论是否自动切换)
if a.defaultSink != nil {
a.resumeSinkConfig(a.defaultSink)
}同时,建议为 3. 代码性能分析:
结论: 4. 代码安全问题:潜在的空指针引用风险
改进意见:
总结建议这段代码修改在语法逻辑和代码安全上存在较大风险。目前的 建议修改方案: // 对于 Sink
if !a.autoSwitchOutputPort() && a.defaultSink != nil {
a.resumeSinkConfig(a.defaultSink)
}
// 对于 Source
if !a.autoSwitchInputPort() && a.defaultSource != nil {
a.resumeSourceConfig(a.defaultSource)
}请务必结合 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, robertkill 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 |
The previous logic had a bug where resumeSinkConfig and resumeSourceConfig would only be called if autoSwitchOutputPort or autoSwitchInputPort returned false. This could cause issues when a default sink or source already exists (non-nil) but auto-switching succeeded. The fix ensures that resume config is also called when a default sink or source is already present, regardless of the auto- switch result. This prevents potential audio configuration issues after initialization.
Influence:
fix: 修复默认音频输入输出设备的恢复逻辑
之前的逻辑存在一个缺陷,只有当自动切换输出端口或输入端口返回 false 时,
才会调用 resumeSinkConfig 和 resumeSourceConfig。这可能导致当默认音频输 出或输入设备已经存在(非空)但自动切换成功时出现问题。修复确保当默认音频
输出或输入设备已经存在时,无论自动切换结果如何,都会调用恢复配置。这可以
防止初始化后可能出现的音频配置问题。
Influence:
PMS: BUG-349719
Summary by Sourcery
Bug Fixes: