Skip to content

fix: prevent auto-switch to unavailable audio ports - #1269

Draft
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/bot/57b9d7213dcf
Draft

MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/bot/57b9d7213dcf

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

修复禁用有线耳机和USB扬声器端口时输出设置错误切换为HDMI的问题

问题描述

禁用有线耳机和USB扬声器端口后,输出设置错误切换为HDMI,且音频仍从有线耳机输出。

修改内容

  1. audio1/priority_manager.go:refreshPorts 移除对 AvailableTypeNo 端口的过滤,仅按 !pc.Enabled 跳过,临时不可用但已启用的端口保留在优先级队列中
  2. audio1/audio_events.go:checkAutoSwitchOutputPort / checkAutoSwitchInputPort 新增端口可用性检查,Available == AvailableTypeNo 时跳过,避免自动切换到不可用端口

Multica Issue

DDE-400

PMS

https://pms.uniontech.com/bug-view-378321.html

Summary by Sourcery

Prevent automatic audio routing from selecting unavailable ports while preserving enabled ports across transient availability changes.

Bug Fixes:

  • Prevent automatic audio input and output switching to ports that are currently unavailable.
  • Preserve enabled but temporarily unavailable ports in the priority queue to avoid incorrect fallback switching during profile transitions.

1. Remove AvailableTypeNo filter in refreshPorts to keep temporarily
   unavailable but enabled ports in priority queue
2. Add port availability check in checkAutoSwitchOutputPort to skip
   unavailable ports during auto-switch
3. Add symmetric availability check in checkAutoSwitchInputPort
4. Prevent incorrect auto-switch to HDMI when wired/USB ports disabled

Log: Fixed audio output incorrectly switching to HDMI when wired
headphone and USB speaker ports are disabled

Influence:
1. Test disabling wired headphone and USB speaker ports, verify output
   does not switch to HDMI
2. Test audio auto-switch with Bluetooth devices and HDMI hot-plug
3. Test PulseAudio and PipeWire backends
4. Test input port auto-switch behavior

fix: 修复禁用有线耳机和USB扬声器时音频端口错误切换

1. 移除 refreshPorts 中 AvailableTypeNo 过滤条件,临时不可用但已启用的端口保留在优先级队列中
2. 在 checkAutoSwitchOutputPort 中新增端口可用性检查,跳过不可用端口
3. 在 checkAutoSwitchInputPort 中新增对称的可用性检查
4. 防止禁用有线耳机和USB扬声器时输出错误切换到HDMI

Log: 修复禁用有线耳机和USB扬声器端口时输出设置自动切换为HDMI的问题

Influence:
1. 测试禁用有线耳机和USB扬声器端口后,输出不会切换到HDMI
2. 测试蓝牙设备和HDMI热插拔场景下的音频自动切换
3. 测试 PulseAudio 和 PipeWire 后端兼容性
4. 测试输入端口自动切换行为

PMS: BUG-378321
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: MyLeeJiEun

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

sourcery-ai Bot commented Sep 28, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The fix separates priority-list membership from current port availability: enabled ports remain prioritized through transient profile states, while auto-switch logic checks availability at selection time and skips unavailable input or output candidates.

Flow diagram for availability-aware audio auto-switching

flowchart TD
    A[refreshPorts] --> B{Port enabled?}
    B -->|No| C[Exclude from priority queue]
    B -->|Yes| D[Keep in priority queue]
    D --> E[checkAutoSwitchOutputPort or checkAutoSwitchInputPort]
    E --> F{Available == AvailableTypeNo?}
    F -->|Yes| G[Skip candidate]
    F -->|No| H[Select candidate for auto-switch]
Loading

File-Level Changes

Change Details Files
Preserve enabled but temporarily unavailable ports in the priority queue instead of removing them during port refresh.
  • Filter refreshed ports only by the user-enabled setting.
  • Retain unavailable ports so transient profile changes do not delete their priority entries.
audio1/priority_manager.go
Prevent automatic input and output switching from selecting currently unavailable ports.
  • Retrieve output port metadata and skip candidates marked unavailable.
  • Skip unavailable input candidates while evaluating the priority list.
  • Continue evaluating lower-priority candidates when a port is unavailable.
audio1/audio_events.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

Hi @MyLeeJiEun. Thanks for your PR.

I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants