-
Notifications
You must be signed in to change notification settings - Fork 250
/
loopback_video_linux.go
44 lines (33 loc) · 1.52 KB
/
loopback_video_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
//go:build linux
package main
import (
"fmt"
"github.com/taskcluster/taskcluster/v64/workers/generic-worker/host"
)
func (lvt *LoopbackVideoTask) setupVideoDevice() *CommandExecutionError {
err := host.Run("/usr/sbin/modprobe", "v4l2loopback", fmt.Sprintf("video_nr=%d", config.LoopbackVideoDeviceNumber))
if err != nil {
return executionError(internalError, errored, fmt.Errorf("could not load the v4l2loopback kernel module: %v", err))
}
err = host.Run("/bin/chmod", "660", lvt.devicePath)
if err != nil {
return executionError(internalError, errored, fmt.Errorf("could not chmod 660 the %s device: %v", lvt.devicePath, err))
}
err = makeFileOrDirReadWritableForUser(false, lvt.devicePath, taskContext.User)
if err != nil {
return executionError(internalError, errored, fmt.Errorf("could make the %s device readwritable for task user: %v", lvt.devicePath, err))
}
err = lvt.task.setVariable("TASKCLUSTER_VIDEO_DEVICE", lvt.devicePath)
if err != nil {
return executionError(internalError, errored, fmt.Errorf("could not set TASKCLUSTER_VIDEO_DEVICE environment variable: %v", err))
}
lvt.task.Infof("Loopback video device is available at %s", lvt.devicePath)
return nil
}
func (lvt *LoopbackVideoTask) resetVideoDevice() *CommandExecutionError {
chownErr := makeDirUnreadableForUser(lvt.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, lvt.devicePath, chownErr))
}
return nil
}