Skip to content

Commit 3e466ca

Browse files
committed
fix(audio): 设置端口时, 调整端口的优先级
之前做音频端口优先级优化时, 忽略了产品需要, 要求将设置的端口放到端口类型优先级队首. Log: 音频端口优先级策略调整 PMS: BUG-351629 Influence: audio priority
1 parent 251c73e commit 3e466ca

7 files changed

Lines changed: 511 additions & 181 deletions

File tree

audio1/audio.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ func (a *Audio) init() error {
806806

807807
// priorities.Load(globalPrioritiesFilePath, a.cards) // TODO: 删除
808808
GetPriorityManager().Init(a.cards)
809-
GetPriorityManager().Print()
810809

811810
go a.handleEvent()
812811
go a.handleStateChanged()

audio1/card.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -126,9 +126,6 @@ func (c *Card) update(card *pulse.Card) {
126126
}
127127
c.Ports = append(c.Ports, port)
128128
}
129-
130-
// 根据端口优先级排序,顺序由低到高
131-
c.sortPortsByPriority(card)
132129
}
133130

134131
func portBluezMode(port *pulse.CardPortInfo) string {

audio1/config_keeper.go

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"sync"
1313

14+
"github.com/linuxdeepin/go-lib/pulse"
1415
"github.com/linuxdeepin/go-lib/xdg/basedir"
1516
)
1617

@@ -25,8 +26,10 @@ type PortConfig struct {
2526
}
2627

2728
type CardConfig struct {
28-
Name string
29-
Ports map[string]*PortConfig // Name => PortConfig
29+
Name string
30+
Ports map[string]*PortConfig // Name => PortConfig
31+
DefaultOutputPort string // 默认输出端口名称,手动设置时记录
32+
DefaultInputPort string // 默认输入端口名称,手动设置时记录
3033
}
3134

3235
type MuteConfig struct {
@@ -77,8 +80,10 @@ func NewMuteConfig() *MuteConfig {
7780

7881
func NewCardConfig(name string) *CardConfig {
7982
return &CardConfig{
80-
Name: name,
81-
Ports: make(map[string]*PortConfig),
83+
Name: name,
84+
Ports: make(map[string]*PortConfig),
85+
DefaultOutputPort: "",
86+
DefaultInputPort: "",
8287
}
8388
}
8489

@@ -286,6 +291,47 @@ func (ck *ConfigKeeper) SetMuteAll(mute bool) {
286291
ck.Save()
287292
}
288293

294+
// SetDefaultPort 设置声卡的默认端口
295+
func (ck *ConfigKeeper) SetDefaultPort(cardName string, portName string, direction int) {
296+
ck.mu.Lock()
297+
defer ck.mu.Unlock()
298+
299+
cardConfig, ok := ck.Cards[cardName]
300+
if !ok {
301+
logger.Warningf("card %s not found in config", cardName)
302+
return
303+
}
304+
305+
if direction == pulse.DirectionSink {
306+
cardConfig.DefaultOutputPort = portName
307+
} else if direction == pulse.DirectionSource {
308+
cardConfig.DefaultInputPort = portName
309+
} else {
310+
logger.Warningf("unexpected direction %d of port <%s:%s>",
311+
direction, cardName, portName)
312+
return
313+
}
314+
ck.Save()
315+
}
316+
317+
// GetDefaultPort 获取声卡的默认端口
318+
func (ck *ConfigKeeper) GetDefaultPort(cardName string, direction int) string {
319+
ck.mu.Lock()
320+
defer ck.mu.Unlock()
321+
322+
cardConfig, ok := ck.Cards[cardName]
323+
if !ok {
324+
return ""
325+
}
326+
327+
if direction == pulse.DirectionSink {
328+
return cardConfig.DefaultOutputPort
329+
} else if direction == pulse.DirectionSource {
330+
return cardConfig.DefaultInputPort
331+
}
332+
return ""
333+
}
334+
289335
func (card *CardConfig) UpdatePortConfig(portConfig *PortConfig) {
290336
card.Ports[portConfig.Name] = portConfig
291337
}

audio1/config_keeper_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2018 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2018 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: GPL-3.0-or-later
44
package audio
@@ -49,7 +49,9 @@ func TestConfigKeeper_Save(t *testing.T) {
4949
fileContent: `{
5050
"one": {
5151
"Name": "xxx",
52-
"Ports": {}
52+
"Ports": {},
53+
"DefaultOutputPort": "",
54+
"DefaultInputPort": ""
5355
}
5456
}`,
5557
},

0 commit comments

Comments
 (0)