Skip to content

Commit

Permalink
chore: audio card信息添加portTpye (#642)
Browse files Browse the repository at this point in the history
audio card信息添加portTpye, 适配任务栏插件

Issue: linuxdeepin/developer-center#9844

Co-authored-by: fuleyi <[email protected]>
  • Loading branch information
fly602 and fly602 authored Jul 23, 2024
1 parent ff1521a commit 80cfbfe
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
3 changes: 3 additions & 0 deletions audio1/card.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type CardPortExport struct {
Bluetooth bool
Description string
Direction int
PortType int
}

func newCard(card *pulse.Card) *Card {
Expand Down Expand Up @@ -161,6 +162,7 @@ func (cards CardList) string() string {
Bluetooth: isBluetoothCard(cardInfo.core),
Description: portInfo.Description,
Direction: portInfo.Direction,
PortType: DetectPortType(cardInfo.core, &portInfo),
})
}

Expand Down Expand Up @@ -189,6 +191,7 @@ func (cards CardList) stringWithoutUnavailable() string {
Bluetooth: isBluetoothCard(cardInfo.core),
Description: portInfo.Description,
Direction: portInfo.Direction,
PortType: DetectPortType(cardInfo.core, &portInfo),
})
}

Expand Down
18 changes: 8 additions & 10 deletions audio1/priority_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ func GetPortType(cardName string, portName string) int {
if contains(cardName, portName, "multichannel") {
return PortTypeMultiChannel
}
if contains(cardName, portName, "speaker") ||
contains(cardName, portName, "input-mic") {
return PortTypeBuiltin
}

if contains(cardName, portName, "linein") ||
contains(cardName, portName, "lineout") {
return PortTypeLineIO
}

if contains(cardName, portName, "bluez") ||
contains(cardName, portName, "bluetooth") {
return PortTypeBluetooth
}

if contains(cardName, portName, "usb") ||
contains(cardName, portName, "rear-mic") ||
contains(cardName, portName, "front-mic") ||
contains(cardName, portName, "headset") ||
contains(cardName, portName, "headphone") {
return PortTypeHeadset
}
Expand All @@ -83,12 +83,10 @@ func GetPortType(cardName string, portName string) int {
return PortTypeHdmi
}

if contains(cardName, portName, "speaker") ||
contains(cardName, portName, "input-mic") {
return PortTypeBuiltin

if contains(cardName, portName, "bluez") ||
contains(cardName, portName, "bluetooth") {
return PortTypeBluetooth
}

return PortTypeUnknown
}

Expand Down
16 changes: 7 additions & 9 deletions audio1/priority_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ func DetectPortType(card *pulse.Card, port *pulse.CardPortInfo) int {
if hasKeyword(stringList, "multichannel") {
return PortTypeMultiChannel
}
if hasKeyword(stringList, "speaker") ||
hasKeyword(stringList, "input-mic") {
return PortTypeBuiltin
}

if hasKeyword(stringList, "linein") ||
hasKeyword(stringList, "lineout") {
return PortTypeLineIO
}

if hasKeyword(stringList, "bluez") ||
hasKeyword(stringList, "bluetooth") {
return PortTypeBluetooth
}

if hasKeyword(stringList, "rear-mic") ||
hasKeyword(stringList, "front-mic") ||
hasKeyword(stringList, "headphone") ||
Expand All @@ -74,10 +73,9 @@ func DetectPortType(card *pulse.Card, port *pulse.CardPortInfo) int {
return PortTypeHdmi
}

if hasKeyword(stringList, "speaker") ||
hasKeyword(stringList, "input-mic") {
return PortTypeBuiltin

if hasKeyword(stringList, "bluez") ||
hasKeyword(stringList, "bluetooth") {
return PortTypeBluetooth
}

return PortTypeUnknown
Expand Down
2 changes: 1 addition & 1 deletion audio1/priority_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func Test_GetPortType(t *testing.T) {
assert.Equal(t, GetPortType("usb.abcd.1234", "world.abcd.1234"), PortTypeHeadset)
assert.Equal(t, GetPortType("hbc.abcd.1234", "usb.abcd.1234"), PortTypeHeadset)
assert.Equal(t, GetPortType("hello.abcd.speaker", "world.abcd.1234"), PortTypeBuiltin)
assert.Equal(t, GetPortType("hdmi.abcd.speaker", "world.abcd.1234"), PortTypeHdmi)
assert.Equal(t, GetPortType("hdmi.abcd.speaker", "world.abcd.1234"), PortTypeBuiltin)
}

func Test_IsInputTypeAfter(t *testing.T) {
Expand Down

0 comments on commit 80cfbfe

Please sign in to comment.