-
Notifications
You must be signed in to change notification settings - Fork 106
fix: 解决接入有限耳机, 输入输出还是null的问题 #993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
处理一些特殊场景,当声卡的端口可用性发生变化时,没有自动切换端口,因为此时sink/source还没有更新,导致切换失败. 当sink/source收到事件时,也只是change的事件,不会触发端口切换逻辑,导致端口一直没有变化. 一些warning日志不太重要,应该为debug或者info级别的调试辅助信息. Log: 解决接入优先耳机,输入和输出为null的问题 PMS: BUG-346985 Influence: audio
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts audio port auto-switching logic to correctly react when physical sink/source port availability changes, especially for preferred wired headsets, and downgrades several noisy warning logs to debug/info levels. Sequence diagram for updated sink change auto-switch behaviorsequenceDiagram
participant PulseServer
participant Audio
participant Sink
PulseServer->>Audio: handleSinkChanged(idx)
Audio->>PulseServer: GetSinkInfo(idx)
PulseServer-->>Audio: sink
Audio->>Sink: update(sink)
Audio->>Audio: isPhysicalDevice(sink.Name)?
alt sink is physical device
Audio->>Audio: checkCardIsReady(sink.Card)
alt card is ready
Audio->>Audio: autoSwitchPort()
Audio->>Audio: autoSwitchOutputPort()
Audio->>Audio: autoSwitchInputPort()
else card not ready
Audio-->>PulseServer: return (no auto switch)
end
else sink is virtual device
Audio-->>PulseServer: return (no auto switch)
end
Sequence diagram for updated source events auto-switch behaviorsequenceDiagram
participant PulseServer
participant Audio
participant Source
rect rgb(230,230,230)
PulseServer->>Audio: handleSourceAdded(idx)
Audio->>PulseServer: GetSourceInfo(idx)
PulseServer-->>Audio: source
Audio->>Audio: isPhysicalDevice(source.Name)?
alt source is physical device
Audio->>Audio: checkCardIsReady(source.Card)
alt card is ready
Audio->>Audio: autoSwitchInputPort()
else card not ready
Audio-->>PulseServer: return (no auto switch)
end
else source is virtual device
Audio-->>PulseServer: return (no auto switch)
end
end
rect rgb(230,230,230)
PulseServer->>Audio: handleSourceChanged(idx)
Audio->>PulseServer: GetSourceInfo(idx)
PulseServer-->>Audio: source
Audio->>Source: update(source)
Audio->>Audio: isPhysicalDevice(source.Name)?
alt source is physical device
Audio->>Audio: checkCardIsReady(source.Card)
alt card is ready
Audio->>Audio: autoSwitchInputPort()
else card not ready
Audio-->>PulseServer: return (no auto switch)
end
else source is virtual device
Audio-->>PulseServer: return (no auto switch)
end
end
rect rgb(230,230,230)
PulseServer->>Audio: handleSourceRemoved(idx)
Audio->>Audio: isPhysicalDevice(removedSource.Name)?
alt removed source is physical device
Audio->>Audio: checkCardIsReady(cardId)
alt card is ready
Audio->>Audio: autoSwitchInputPort()
else card not ready
Audio-->>PulseServer: return (no auto switch)
end
else removed source is virtual device
Audio-->>PulseServer: return (no auto switch)
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review这份代码修改主要涉及音频服务的日志级别调整和音频端口自动切换逻辑的优化。以下是对代码的详细审查意见: 1. 语法逻辑优点:
建议:
2. 代码质量优点:
建议:
3. 代码性能优点:
建议:
4. 代码安全优点:
建议:
5. 具体修改建议对于 func (a *Audio) handleSinkChanged(idx uint32) {
sink, err := a.getSink(idx)
if err != nil {
logger.Warningf("failed to get sink %d: %v", idx, err)
return
}
if _, ok := a.sinks[idx]; ok {
a.sinks[idx].update(sink)
}
// 处理场景:当sink的端口可用性发生变化时,切换端口
// cardchange事件也会触发,但是处理不了,因为这时sink可能还没更新,无可用端口
if a.shouldAutoSwitchPort(sink) {
a.autoSwitchPort()
}
}
// 新增辅助函数
func (a *Audio) shouldAutoSwitchPort(device interface{}) bool {
var name string
var cardId uint32
switch d := device.(type) {
case *Sink:
name = d.Name
cardId = d.Card
case *Source:
name = d.Name
cardId = d.Card
default:
return false
}
return isPhysicalDevice(name) && a.checkCardIsReady(cardId)
}类似地,可以优化 总结整体来看,这次代码修改主要是为了优化音频端口自动切换的逻辑,使其更加健壮。主要改进点包括:
建议在后续版本中考虑上述提到的优化点,特别是错误处理和防抖机制,以提高代码的健壮性和用户体验。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey - I've left some high level feedback:
- In
handleSinkChangedandhandleSourceChanged, you now use thesink/sourcevariables (forisPhysicalDevice(...)andcheckCardIsReady(...)) even when theGetSink/GetSourcelookup may have failed; consider returning early whenokis false to avoid relying on zero-valued structs and make the intent clearer. - In
handleSinkChanged, callingautoSwitchPort()will also trigger input-port switching; if the intent is to react only to output device changes here, consider usingautoSwitchOutputPort()for symmetry with the source-handling code which calls onlyautoSwitchInputPort().
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `handleSinkChanged` and `handleSourceChanged`, you now use the `sink`/`source` variables (for `isPhysicalDevice(...)` and `checkCardIsReady(...)`) even when the `GetSink`/`GetSource` lookup may have failed; consider returning early when `ok` is false to avoid relying on zero-valued structs and make the intent clearer.
- In `handleSinkChanged`, calling `autoSwitchPort()` will also trigger input-port switching; if the intent is to react only to output device changes here, consider using `autoSwitchOutputPort()` for symmetry with the source-handling code which calls only `autoSwitchInputPort()`.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: fly602, mhduiy 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 |
处理一些特殊场景,当声卡的端口可用性发生变化时,没有自动切换端口,因为此时sink/source还没有更新,导致切换失败. 当sink/source收到事件时,也只是change的事件,不会触发端口切换逻辑,导致端口一直没有变化. 一些warning日志不太重要,应该为debug或者info级别的调试辅助信息.
Log: 解决接入优先耳机,输入和输出为null的问题
PMS: BUG-346985
Influence: audio
Summary by Sourcery
Improve automatic audio port switching behavior when wired devices change availability to avoid null input/output, and adjust log levels for routine operations.
Bug Fixes:
Enhancements: