Skip to content

Commit

Permalink
feat: add pause player interface
Browse files Browse the repository at this point in the history
Log:

(cherry picked from commit 52a7dcc)
  • Loading branch information
Decodetalkers authored and fly602 committed Sep 4, 2024
1 parent 375d165 commit 31a1c27
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 5 deletions.
43 changes: 38 additions & 5 deletions audio1/audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
gsKeyHeadphoneOutputVolume = "headphone-output-volume"
gsKeyHeadphoneUnplugAutoPause = "headphone-unplug-auto-pause"
gsKeyVolumeIncrease = "volume-increase"

gsKeyReduceNoise = "reduce-input-noise"
gsKeyOutputAutoSwitchCountMax = "output-auto-switch-count-max"

Expand All @@ -50,6 +51,7 @@ const (
increaseMaxVolume = 1.5
normalMaxVolume = 1.0

dsgkeyPausePlayer = "pausePlayer"
dsgKeyAutoSwitchPort = "autoSwitchPort"
dsgKeyBluezModeFilterList = "bluezModeFilterList"
dsgKeyPortFilterList = "portFilterList"
Expand Down Expand Up @@ -105,6 +107,7 @@ type Audio struct {
// dbusutil-gen: equal=objectPathSliceEqual
Sinks []dbus.ObjectPath
// dbusutil-gen: equal=objectPathSliceEqual
configManagerPath dbus.ObjectPath
Sources []dbus.ObjectPath
DefaultSink dbus.ObjectPath
DefaultSource dbus.ObjectPath
Expand All @@ -117,7 +120,10 @@ type Audio struct {
// dbusutil-gen: ignore
IncreaseVolume gsprop.Bool `prop:"access:rw"`

ReduceNoise bool `prop:"access:rw"`
PausePlayer bool `prop:"access:rw"`

ReduceNoise bool `prop:"access:rw"`

defaultPaCfg defaultPaConfig

// 最大音量
Expand Down Expand Up @@ -210,6 +216,7 @@ func newAudio(service *dbusutil.Service) *Audio {
a.settings.Reset(gsKeyOutputVolume)
a.settings.Reset(gsKeyHeadphoneOutputVolume)
a.IncreaseVolume.Bind(a.settings, gsKeyVolumeIncrease)
a.PausePlayer = false
a.ReduceNoise = false
a.emitPropChangedReduceNoise(a.ReduceNoise)
a.headphoneUnplugAutoPause = a.settings.GetBoolean(gsKeyHeadphoneUnplugAutoPause)
Expand Down Expand Up @@ -506,6 +513,9 @@ func (a *Audio) refershSinkInputs() {
}

func (a *Audio) shouldAutoPause() bool {
if !a.PausePlayer {
return false
}
if a.defaultSink == nil {
logger.Warning("default sink is nil")
return false
Expand Down Expand Up @@ -1668,16 +1678,15 @@ func (a *Audio) initDsgProp() error {

a.systemSigLoop = dbusutil.NewSignalLoop(systemBus, 10)

var configManagerPath dbus.ObjectPath
systemConnObj := systemBus.Object("org.desktopspec.ConfigManager", "/")
err = systemConnObj.Call("org.desktopspec.ConfigManager.acquireManager", 0, "org.deepin.dde.daemon", "org.deepin.dde.daemon.audio", "").Store(&configManagerPath)
err = systemConnObj.Call("org.desktopspec.ConfigManager.acquireManager", 0, "org.deepin.dde.daemon", "org.deepin.dde.daemon.audio", "").Store(&a.configManagerPath)
if err != nil {
logger.Warning(err)
return nil
}

err = dbusutil.NewMatchRuleBuilder().Type("signal").
PathNamespace(string(configManagerPath)).
PathNamespace(string(a.configManagerPath)).
Interface("org.desktopspec.ConfigManager.Manager").
Member("valueChanged").Build().AddTo(systemBus)
if err != nil {
Expand All @@ -1686,7 +1695,7 @@ func (a *Audio) initDsgProp() error {
}

var val bool
systemConnObj = systemBus.Object("org.desktopspec.ConfigManager", configManagerPath)
systemConnObj = systemBus.Object("org.desktopspec.ConfigManager", a.configManagerPath)
err = systemConnObj.Call("org.desktopspec.ConfigManager.Manager.value", 0, dsgKeyAutoSwitchPort).Store(&val)
if err != nil {
logger.Warning(err)
Expand All @@ -1695,6 +1704,17 @@ func (a *Audio) initDsgProp() error {
a.setEnableAutoSwitchPort(val)
}

var keyPausePlayer bool
err = systemConnObj.Call("org.desktopspec.ConfigManager.Manager.value", 0, dsgkeyPausePlayer).Store(&keyPausePlayer)
if err != nil {
logger.Warning(err)
} else {
logger.Info("auto switch port:", keyPausePlayer)
a.PropsMu.Lock()
a.PausePlayer = keyPausePlayer
a.PropsMu.Unlock()
}

var ret []dbus.Variant
err = systemConnObj.Call("org.desktopspec.ConfigManager.Manager.value", 0, dsgKeyBluezModeFilterList).Store(&ret)
if err != nil {
Expand Down Expand Up @@ -1792,6 +1812,19 @@ func (a *Audio) initDsgProp() error {
}
}

if ok && key == dsgkeyPausePlayer {
var pausePlayer bool
err = systemConnObj.Call("org.desktopspec.ConfigManager.Manager.value", 0, key).Store(&pausePlayer)
if err != nil {
logger.Warning(err)
} else {
logger.Info("pausePlayer config:", pausePlayer)
a.PropsMu.Lock()
a.PausePlayer = pausePlayer
a.emitPropChangedPausePlayer(pausePlayer)
a.PropsMu.Unlock()
}
}
}
})

Expand Down
13 changes: 13 additions & 0 deletions audio1/audio_dbusutil.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions audio1/audio_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,25 @@ func (a *Audio) writeReduceNoise(write *dbusutil.PropertyWrite) *dbus.Error {
return nil
}

func (a *Audio) writeKeyPausePlayer(write *dbusutil.PropertyWrite) *dbus.Error {
pausePlayer, ok := write.Value.(bool)
if !ok {
return dbusutil.ToError(errors.New("type is not bool"))
}
systemBus, err := dbus.SystemBus()
if err != nil {
return dbus.MakeFailedError(err)
}

systemConnObj := systemBus.Object("org.desktopspec.ConfigManager", a.configManagerPath)
err = systemConnObj.Call("org.desktopspec.ConfigManager.Manager.setValue", 0, dsgkeyPausePlayer, dbus.MakeVariant(pausePlayer)).Err
if err != nil {
return dbusutil.ToError(errors.New("dconfig Cannot set value " + dsgkeyPausePlayer))
}
a.setPropPausePlayer(pausePlayer)
return nil
}

func (a *Audio) notifyBluezCardPortInsert(card *Card) {
logger.Debugf("notify bluez card %d:%s", card.Id, card.core.Name)
oldCard, err := a.oldCards.getByName(card.core.Name)
Expand Down
10 changes: 10 additions & 0 deletions audio1/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ func (m *Module) start() error {
so := service.GetServerObject(m.audio)
err = so.SetWriteCallback(m.audio, "ReduceNoise", m.audio.writeReduceNoise)

if err != nil {
logger.Warning("failed to bind callback for ReduceNoise:", err)
}

err = so.SetWriteCallback(m.audio, "PausePlayer", m.audio.writeKeyPausePlayer)

if err != nil {
logger.Warning("failed to bind callback for PausePlayer:", err)
}

err = m.audio.syncConfig.Register()
if err != nil {
logger.Warning("failed to register for deepin sync:", err)
Expand Down
10 changes: 10 additions & 0 deletions misc/dsg-configs/org.deepin.dde.daemon.audio.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"pausePlayer": {
"value": false,
"serial":0,
"flags" : [],
"name": "PlayerPause",
"name[zh_CN]": "插拔声音设备暂停输出",
"description": "auto pause player",
"permissions": "readwrite",
"visibility": "private"
},
"autoSwitchPort": {
"value": true,
"serial": 0,
Expand Down

0 comments on commit 31a1c27

Please sign in to comment.