Skip to content

Commit 93a628f

Browse files
committed
fix: temporarily handle audio loss after sleep on some devices
Added a temporary compatibility script to handle audio loss issues after system sleep/wakeup on certain devices. The change introduces a fallback mechanism that runs a PipeWire suspend script if it exists, otherwise falls back to the original PulseAudio suspend/resume functions. The main changes include: 1. Added a new function `runPipewireSuspendScriptIfExists()` that checks for and executes `/usr/lib/deepin-daemon/pipewire-suspend.sh` with an action parameter 2. Modified the sleep inhibitor to call this script before and after sleep (with "1" for suspend and "0" for resume) 3. The script execution takes precedence - if the script exists and runs successfully, the original PulseAudio suspend/resume functions are skipped 4. This provides a temporary workaround for devices experiencing audio loss after wakeup from sleep This is a temporary compatibility measure until a more permanent solution can be implemented for the audio subsystem. fix: 临时处理部分设备睡眠后音频丢失问题 添加了临时兼容性脚本来处理部分设备在系统睡眠/唤醒后音频丢失的问题。该更 改引入了一个回退机制,如果存在 PipeWire 挂起脚本则运行该脚本,否则回退到 原始的 PulseAudio 挂起/恢复函数。 主要更改包括: 1. 添加了新函数 `runPipewireSuspendScriptIfExists()`,用于检查并执行 `/ usr/lib/deepin-daemon/pipewire-suspend.sh` 脚本并传入操作参数 2. 修改了睡眠抑制器,在睡眠前后调用此脚本("1" 表示挂起,"0" 表示恢复) 3. 脚本执行具有优先权 - 如果脚本存在并成功运行,则跳过原始的 PulseAudio 挂起/恢复函数 4. 这为在睡眠唤醒后遇到音频丢失问题的设备提供了一个临时解决方案 这是一个临时兼容性措施,直到音频子系统能够实现更永久的解决方案。 PMS: BUG-352093
1 parent c1f483c commit 93a628f

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

session/power1/sleep_inhibit.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
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

55
package power
66

77
import (
8+
"os"
9+
"os/exec"
810
"syscall"
911

1012
"github.com/godbus/dbus/v5"
@@ -14,6 +16,21 @@ import (
1416
"github.com/linuxdeepin/go-lib/dbusutil"
1517
)
1618

19+
const pipewireSuspendScript = "/usr/libexec/deepin/os-config/pipewire-suspend.sh"
20+
21+
func runPipewireSuspendScriptIfExists(action string) bool {
22+
if _, err := os.Stat(pipewireSuspendScript); err != nil {
23+
return false
24+
}
25+
26+
err := exec.Command(pipewireSuspendScript, action).Run()
27+
if err != nil {
28+
logger.Warning("failed to run pipewire suspend script:", err)
29+
return false
30+
}
31+
return true
32+
}
33+
1734
type sleepInhibitor struct {
1835
loginManager login1.Manager
1936
fd int
@@ -59,8 +76,10 @@ func newSleepInhibitor(login1Manager login1.Manager, daemon daemon.Daemon) *slee
5976
if inhibitor.OnBeforeSuspend != nil {
6077
inhibitor.OnBeforeSuspend()
6178
}
62-
suspendPulseSinks(1)
63-
suspendPulseSources(1)
79+
if !runPipewireSuspendScriptIfExists("1") {
80+
suspendPulseSinks(1)
81+
suspendPulseSources(1)
82+
}
6483
err := inhibitor.unblock()
6584
if err != nil {
6685
logger.Warning(err)
@@ -70,8 +89,10 @@ func newSleepInhibitor(login1Manager login1.Manager, daemon daemon.Daemon) *slee
7089
logger.Debug("not run before sleep,don't need run after sleep")
7190
return
7291
}
73-
suspendPulseSources(0)
74-
suspendPulseSinks(0)
92+
if !runPipewireSuspendScriptIfExists("0") {
93+
suspendPulseSources(0)
94+
suspendPulseSinks(0)
95+
}
7596
if inhibitor.OnWakeup != nil {
7697
inhibitor.OnWakeup()
7798
}

0 commit comments

Comments
 (0)