-
Notifications
You must be signed in to change notification settings - Fork 251
/
loopback_audio_linux.go
51 lines (40 loc) · 1.83 KB
/
loopback_audio_linux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//go:build linux
package main
import (
"fmt"
"github.com/taskcluster/taskcluster/v60/workers/generic-worker/host"
)
func (lat *LoopbackAudioTask) setupAudioDevice() *CommandExecutionError {
opts := fmt.Sprintf("options snd-aloop enable=1 index=%d", config.LoopbackAudioDeviceNumber)
out, err := host.CombinedOutput("/usr/bin/env", "bash", "-c", fmt.Sprintf("/usr/bin/echo %s > /etc/modprobe.d/snd-aloop.conf", opts))
if err != nil {
return executionError(internalError, errored, fmt.Errorf("could not set snd-aloop kernel module options. Output: %s. Error: %v", out, err))
}
out, err = host.CombinedOutput("/usr/sbin/modprobe", "snd-aloop")
if err != nil {
return executionError(internalError, errored, fmt.Errorf("could not load the snd-aloop kernel module. Output: %s. Error: %v", out, err))
}
for _, devicePath := range lat.devicePaths {
out, err = host.CombinedOutput("/bin/chmod", "660", devicePath)
if err != nil {
return executionError(internalError, errored, fmt.Errorf("could not chmod 660 the %s device. Output: %s. Error: %v", devicePath, out, err))
}
}
for _, devicePath := range lat.devicePaths {
err = makeFileOrDirReadWritableForUser(false, devicePath, taskContext.User)
if err != nil {
return executionError(internalError, errored, fmt.Errorf("could make the %s device readwritable for task user: %v", devicePath, err))
}
}
lat.task.Infof("Loopback audio devices are available at %v", lat.devicePaths)
return nil
}
func (lat *LoopbackAudioTask) resetAudioDevice() *CommandExecutionError {
for _, devicePath := range lat.devicePaths {
chownErr := makeDirUnreadableForUser(devicePath, taskContext.User)
if chownErr != nil {
return executionError(internalError, errored, fmt.Errorf("could not remove %s's access from the %s device: %v", taskContext.User.Name, devicePath, chownErr))
}
}
return nil
}