Skip to content

fix: solve audio silent issue after upgrade#1132

Open
fly602 wants to merge 1 commit into
linuxdeepin:masterfrom
fly602:master
Open

fix: solve audio silent issue after upgrade#1132
fly602 wants to merge 1 commit into
linuxdeepin:masterfrom
fly602:master

Conversation

@fly602
Copy link
Copy Markdown
Contributor

@fly602 fly602 commented May 28, 2026

Added a method to check profile existence in ProfileList and modified audio setup to handle missing profiles by selecting an existing one when the stored profile is not found. This addresses compatibility issues after pipewire upgrades where configuration files change or audio ports are not reported simultaneously during initialization, preventing audio from being silent.

Log: Fixed audio issue where sound was lost after system upgrade, ensuring proper profile selection.

Influence:

  1. Test audio playback after a system upgrade to ensure no sound loss.
  2. Verify that audio profiles are correctly selected when stored profiles are missing.
  3. Check audio initialization scenarios where ports might not be reported simultaneously.
  4. Test compatibility with different pipewire versions or upgrade paths.

fix: 解决升级后音频无声的问题

添加了一个方法来检查 ProfileList 中是否存在配置文件,并在音频设置中,
当存储的配置文件未找到时,选择一个已存在的配置文件而非失败。这解决了
pipewire 升级后配置文件变化或音频端口在初始化时未同时上报导致的兼容性问
题,从而防止音频无声。

Log: 修复了系统升级后音频丢失的问题,确保正确的配置文件选择。

Influence:

  1. 测试系统升级后的音频播放,确保无声音丢失。
  2. 验证当存储的配置文件缺失时,音频配置文件是否被正确选择。
  3. 检查音频初始化场景,其中端口可能未同时上报。
  4. 测试与不同 pipewire 版本或升级路径的兼容性。

PMS: BUG-358827
Change-Id: Iee93871193e5ca05edbde091d362c71a0c12a801

Summary by Sourcery

Ensure audio continues working after configuration changes by validating stored audio profiles and falling back to an available profile when necessary.

Bug Fixes:

  • Prevent audio from becoming silent after upgrades by selecting an existing audio profile when the stored profile no longer exists.

Enhancements:

  • Add a helper on ProfileList to check for the existence of a given audio profile.
  • Update the audio module copyright header years.

Added a method to check profile existence in ProfileList and modified
audio setup to handle missing profiles by selecting an existing one when
the stored profile is not found. This addresses compatibility issues
after pipewire upgrades where configuration files change or audio ports
are not reported simultaneously during initialization, preventing audio
from being silent.

Log: Fixed audio issue where sound was lost after system upgrade,
ensuring proper profile selection.

Influence:
1. Test audio playback after a system upgrade to ensure no sound loss.
2. Verify that audio profiles are correctly selected when stored
profiles are missing.
3. Check audio initialization scenarios where ports might not be
reported simultaneously.
4. Test compatibility with different pipewire versions or upgrade paths.

fix: 解决升级后音频无声的问题

添加了一个方法来检查 ProfileList 中是否存在配置文件,并在音频设置中,
当存储的配置文件未找到时,选择一个已存在的配置文件而非失败。这解决了
pipewire 升级后配置文件变化或音频端口在初始化时未同时上报导致的兼容性问
题,从而防止音频无声。

Log: 修复了系统升级后音频丢失的问题,确保正确的配置文件选择。

Influence:
1. 测试系统升级后的音频播放,确保无声音丢失。
2. 验证当存储的配置文件缺失时,音频配置文件是否被正确选择。
3. 检查音频初始化场景,其中端口可能未同时上报。
4. 测试与不同 pipewire 版本或升级路径的兼容性。

PMS: BUG-358827
Change-Id: Iee93871193e5ca05edbde091d362c71a0c12a801
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602

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

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 28, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a profile-existence helper on ProfileList and updates audio port/profile selection logic so that when a previously stored profile is missing (e.g., after pipewire upgrades or staggered port reporting), the code falls back to a valid existing profile instead of failing, preventing silent audio after upgrades.

Sequence diagram for updated audio profile selection in setPort

sequenceDiagram
    participant Audio
    participant ConfigKeeper
    participant Card
    participant Port
    participant ProfileList

    Audio->>ConfigKeeper: GetConfigKeeper
    Audio->>ConfigKeeper: Mode(card, portName)
    ConfigKeeper-->>Audio: profile

    alt [profile is empty]
        Audio->>Port: Profiles.SelectProfile
        Port-->>Audio: profile
        Audio->>ConfigKeeper: SetMode(card, portName, profile)
    else [profile is not empty]
        Audio->>ProfileList: card.Profiles.Exists(profile)
        alt [profile exists]
            Audio->>Card: use existing profile
        else [profile missing]
            Audio->>Port: Profiles.SelectProfile
            Port-->>Audio: profile
        end
    end
Loading

File-Level Changes

Change Details Files
Introduce a helper on the profile collection to check whether a given profile name exists.
  • Define an Exists(name string) bool method on ProfileList that linearly scans for a matching Profile.Name and returns true if found, false otherwise.
  • Keep existing profile construction and blacklist logic unchanged aside from extending the copyright year range.
audio1/profile.go
Harden audio profile selection during port setup to gracefully handle missing or outdated profiles.
  • When a stored profile is present for a card/port, verify that it exists in the card's profile list before using it.
  • If the stored profile does not exist (e.g., due to pipewire upgrade or non-simultaneous port reporting), fall back to selecting a valid profile via port.Profiles.SelectProfile() instead of keeping the invalid one.
  • Retain existing behavior of persisting the selected profile only when none was stored initially, to avoid overriding configurations in transient initialization states.
audio1/audio.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是CodeGeeX,你的智能编程助手。我已经仔细审查了你提供的Git Diff代码。这段代码主要处理了音频配置文件在特定场景下找不到的兼容性问题,并新增了一个辅助判断方法。

以下是我从语法逻辑、代码质量、代码性能和代码安全四个维度提出的详细审查意见和改进建议:

1. 语法与逻辑

  • 逻辑合理性:新增的 if !card.Profiles.Exists(profile) 分支逻辑是合理的。当配置文件中记录的 profile 在当前声卡的可用列表中不存在时(由于pipewire升级或异步初始化),回退到 port.Profiles.SelectProfile() 是一种有效的容错机制。注释中也清晰说明了为什么不直接修改配置文件,逻辑闭环良好。
  • 潜在的类型不一致风险:在 Exists 方法中,入参是 name string,对比的是 p.Name。请确保 card.Profiles 的类型也是 ProfileList(或者其元素包含 Name string 字段)。从 Diff 上下文来看,card.Profiles 可能是另一个类型(比如 CardProfileList),如果它没有实现 Exists 方法,编译会报错。如果类型不同,建议为对应类型也实现 Exists 方法,或者提取一个通用的判断逻辑。

2. 代码质量

  • 注释规范
    • audio.go 中的中文注释清晰表达了业务场景,这很好。但建议在注释中明确“不能修改配置文件”指的是不能调用 GetConfigKeeper().SetMode,以免后续维护者误解。
    • profile.go 中修改了版权声明年份至 2026。通常版权声明的结束年份应该是文件最后一次实质性修改的年份(如2023或2024),除非你们项目组有特定的版权规范要求写至某个未来年份,否则建议遵循常规实践,写当前修改年份即可。
  • 代码可读性Exists 方法实现很简洁,符合 Go 语言的惯用写法。

3. 代码性能

  • 时间复杂度:新增的 Exists 方法使用了线性遍历 O(N)。考虑到音频声卡的 Profiles 数量通常极少(一般不超过10个),这里的 O(N) 遍历在性能上完全没有问题,不需要为了追求 O(1) 而引入额外的 map 结构增加内存开销和代码复杂度。

4. 代码安全

  • 空指针解引用风险
    • Exists 方法中:for _, p := range l,如果 lnil,在 Go 中对 nil slice 进行 range 遍历是安全的,不会引发 panic。
    • 但是,如果 l 中的某个元素 pnil(即 ProfileList 中包含未初始化的指针),那么 p.Name 将会导致 panic(空指针解引用)
    • 同样,在 audio.go 的上下文中,调用 card.Profiles.Exists(profile) 时,如果 card.Profilesnil,也会引发 panic。
  • 改进建议:在 Exists 方法中增加防御性编程,检查元素是否为 nil

改进后的代码建议

针对上述审查意见,主要是为了增强代码的健壮性(防止空指针 Panic),建议对 profile.go 中的 Exists 方法做如下改进:

func (l ProfileList) Exists(name string) bool {
	for _, p := range l {
		// 防御性编程:防止 ProfileList 中存在未初始化的 nil 指针导致 panic
		if p != nil && p.Name == name {
			return true
		}
	}
	return false
}

对于 audio.go 的逻辑,如果 card.Profiles 有可能为 nil,建议在调用前加一层判断(视你整体的业务逻辑和初始化流程而定,如果确保不为 nil 则无需修改):

		} else {
			// 情况一:兼容pipewire升级导致的声卡的配置文件的发生变化,导致配置找不到
			// 情况二:另一种情况是pipewire初始化时,音频端口不是同时上报上来的,导致配置文件找不到,暂时先切换到已存在的profile
			// 由于情况二的场景存在,不能在这里调用 SetMode 修改配置文件
			if card.Profiles != nil && !card.Profiles.Exists(profile) {
				profile = port.Profiles.SelectProfile()
			}
		}

总体而言,这段代码的修改目标明确,容错设计合理,只需稍微注意一下空指针的边界情况即可。希望这些意见对你有所帮助!如果有其他代码需要审查,随时告诉我。

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

2 participants