mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
audio: add 'index' prop for Sink/Source/SinkInput
Change-Id: I7c7b7093c02babf549c399144801670a0a55e349
This commit is contained in:
parent
4e6bd145c0
commit
7df0cf019c
@ -55,16 +55,19 @@ func (s *Audio) GetDefaultSource() *Source {
|
||||
|
||||
func NewSink(core *pulse.Sink) *Sink {
|
||||
s := &Sink{core: core}
|
||||
s.index = s.core.Index
|
||||
s.update()
|
||||
return s
|
||||
}
|
||||
func NewSource(core *pulse.Source) *Source {
|
||||
s := &Source{core: core}
|
||||
s.index = s.core.Index
|
||||
s.update()
|
||||
return s
|
||||
}
|
||||
func NewSinkInput(core *pulse.SinkInput) *SinkInput {
|
||||
s := &SinkInput{core: core}
|
||||
s.index = s.core.Index
|
||||
s.update()
|
||||
return s
|
||||
}
|
||||
@ -102,7 +105,8 @@ type Port struct {
|
||||
Available byte // Unknow:0, No:1, Yes:2
|
||||
}
|
||||
type Sink struct {
|
||||
core *pulse.Sink
|
||||
core *pulse.Sink
|
||||
index uint32
|
||||
|
||||
Name string
|
||||
Description string
|
||||
@ -151,7 +155,9 @@ func (s *Sink) SetPort(name string) {
|
||||
}
|
||||
|
||||
type SinkInput struct {
|
||||
core *pulse.SinkInput
|
||||
core *pulse.SinkInput
|
||||
index uint32
|
||||
|
||||
Name string
|
||||
Icon string
|
||||
Mute bool
|
||||
@ -190,7 +196,9 @@ func (s *SinkInput) SetMute(v bool) {
|
||||
}
|
||||
|
||||
type Source struct {
|
||||
core *pulse.Source
|
||||
core *pulse.Source
|
||||
index uint32
|
||||
|
||||
Name string
|
||||
Description string
|
||||
|
||||
|
@ -41,7 +41,7 @@ func (m *Meter) setPropVolume(v float64) {
|
||||
func (s *Sink) GetDBusInfo() dbus.DBusInfo {
|
||||
return dbus.DBusInfo{
|
||||
Dest: baseBusName,
|
||||
ObjectPath: fmt.Sprintf("%s/Sink%d", baseBusPath, s.core.Index),
|
||||
ObjectPath: fmt.Sprintf("%s/Sink%d", baseBusPath, s.index),
|
||||
Interface: baseBusIfc + ".Sink",
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,7 @@ func (s *Sink) GetDBusInfo() dbus.DBusInfo {
|
||||
func (s *Source) GetDBusInfo() dbus.DBusInfo {
|
||||
return dbus.DBusInfo{
|
||||
Dest: baseBusName,
|
||||
ObjectPath: fmt.Sprintf("%s/Source%d", baseBusPath, s.core.Index),
|
||||
ObjectPath: fmt.Sprintf("%s/Source%d", baseBusPath, s.index),
|
||||
Interface: baseBusIfc + ".Source",
|
||||
}
|
||||
}
|
||||
@ -57,7 +57,7 @@ func (s *Source) GetDBusInfo() dbus.DBusInfo {
|
||||
func (s *SinkInput) GetDBusInfo() dbus.DBusInfo {
|
||||
return dbus.DBusInfo{
|
||||
Dest: baseBusName,
|
||||
ObjectPath: fmt.Sprintf("%s/SinkInput%d", baseBusPath, s.core.Index),
|
||||
ObjectPath: fmt.Sprintf("%s/SinkInput%d", baseBusPath, s.index),
|
||||
Interface: baseBusIfc + ".SinkInput",
|
||||
}
|
||||
}
|
||||
@ -92,13 +92,14 @@ func (a *Audio) rebuildSinkInputList() {
|
||||
|
||||
func (a *Audio) addSinkInput(idx uint32) {
|
||||
for _, si := range a.SinkInputs {
|
||||
if si.core.Index == idx {
|
||||
if si.index == idx {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
core := a.core.GetSinkInput(idx)
|
||||
if core == nil {
|
||||
core, err := a.core.GetSinkInput(idx)
|
||||
if err != nil {
|
||||
logger.Warning(err)
|
||||
return
|
||||
}
|
||||
if filterSinkInput(core) {
|
||||
@ -106,7 +107,12 @@ func (a *Audio) addSinkInput(idx uint32) {
|
||||
}
|
||||
|
||||
si := NewSinkInput(core)
|
||||
dbus.InstallOnSession(si)
|
||||
err = dbus.InstallOnSession(si)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
a.SinkInputs = append(a.SinkInputs, si)
|
||||
dbus.NotifyChange(a, "SinkInputs")
|
||||
}
|
||||
@ -114,7 +120,7 @@ func (a *Audio) removeSinkInput(idx uint32) {
|
||||
var tryRemoveSinkInput *SinkInput
|
||||
var newSinkInputList []*SinkInput
|
||||
for _, si := range a.SinkInputs {
|
||||
if si.core.Index == idx {
|
||||
if si.index == idx {
|
||||
tryRemoveSinkInput = si
|
||||
} else {
|
||||
newSinkInputList = append(newSinkInputList, si)
|
||||
@ -153,7 +159,7 @@ func (a *Audio) rebuildSourceList() {
|
||||
a.setPropSources(sources)
|
||||
}
|
||||
func (a *Audio) update() {
|
||||
sinfo := a.core.GetServer()
|
||||
sinfo, _ := a.core.GetServer()
|
||||
if sinfo != nil {
|
||||
a.setPropDefaultSink(sinfo.DefaultSinkName)
|
||||
a.setPropDefaultSource(sinfo.DefaultSourceName)
|
||||
|
@ -27,11 +27,15 @@ func (a *Audio) handleSinkEvent(eType int, idx uint32) {
|
||||
|
||||
case pulse.EventTypeChange:
|
||||
for _, s := range a.Sinks {
|
||||
if s.core.Index == idx {
|
||||
s.core = a.core.GetSink(idx)
|
||||
if s.core != nil {
|
||||
s.update()
|
||||
if s.index == idx {
|
||||
info, err := a.core.GetSink(idx)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
s.core = info
|
||||
s.update()
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -66,13 +70,19 @@ func (a *Audio) handleSinkInputEvent(eType int, idx uint32) {
|
||||
}
|
||||
|
||||
case pulse.EventTypeChange:
|
||||
for _, s := range a.SinkInputs {
|
||||
if s.core.Index == idx {
|
||||
s.core = a.core.GetSinkInput(idx)
|
||||
if s.core != nil {
|
||||
a.siEventChan <- func() {
|
||||
for _, s := range a.SinkInputs {
|
||||
if s.index == idx {
|
||||
info, err := a.core.GetSinkInput(idx)
|
||||
if err != nil {
|
||||
logger.Warning(err)
|
||||
break
|
||||
}
|
||||
|
||||
s.core = info
|
||||
s.update()
|
||||
break
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,11 +94,15 @@ func (a *Audio) handleSourceEvent(eType int, idx uint32) {
|
||||
|
||||
case pulse.EventTypeChange:
|
||||
for _, s := range a.Sources {
|
||||
if s.core.Index == idx {
|
||||
s.core = a.core.GetSource(idx)
|
||||
if s.core != nil {
|
||||
s.update()
|
||||
if s.index == idx {
|
||||
info, err := a.core.GetSource(idx)
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
break
|
||||
}
|
||||
|
||||
s.core = info
|
||||
s.update()
|
||||
break
|
||||
}
|
||||
}
|
||||
@ -96,9 +110,12 @@ func (a *Audio) handleSourceEvent(eType int, idx uint32) {
|
||||
}
|
||||
|
||||
func (a *Audio) handleServerEvent() {
|
||||
sinfo := a.core.GetServer()
|
||||
if sinfo != nil {
|
||||
a.setPropDefaultSink(sinfo.DefaultSinkName)
|
||||
a.setPropDefaultSource(sinfo.DefaultSourceName)
|
||||
sinfo, err := a.core.GetServer()
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
a.setPropDefaultSink(sinfo.DefaultSinkName)
|
||||
a.setPropDefaultSource(sinfo.DefaultSourceName)
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ func (s *SinkInput) correctAppName() {
|
||||
filePath := path.Join("/proc", pid, "cmdline")
|
||||
contents, err := ioutil.ReadFile(filePath)
|
||||
if err != nil {
|
||||
logger.Debugf("ReadFile '%s' failed: %v", filePath, err)
|
||||
logger.Warningf("ReadFile '%s' failed: %v", filePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user