aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/outcome/sppipewire.go
blob: b9359f7ebadd64d9c1d0fd2073437e2e75cf0413 (plain)
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
package outcome

import (
	"encoding/gob"

	"hakurei.app/hst"
	"hakurei.app/internal/pipewire"
)

func init() { gob.Register(spPipeWireOp{}) }

// spPipeWireOp exports the PipeWire server to the container via SecurityContext.
// Runs after spRuntimeOp.
type spPipeWireOp struct{}

func (s spPipeWireOp) toSystem(state *outcomeStateSys) error {
	if state.et&hst.EPipeWire == 0 {
		return errNotEnabled
	}

	appId := state.appId
	if appId == "" {
		// use instance ID in case app id is not set
		appId = "app.hakurei." + state.id.String()
	}
	state.sys.PipeWire(state.instance().Append("pipewire"), appId, state.id.String())
	return nil
}

func (s spPipeWireOp) toContainer(state *outcomeStateParams) error {
	innerPath := state.runtimeDir.Append(pipewire.PW_DEFAULT_REMOTE)
	state.env[pipewire.Remote] = innerPath.String()
	state.params.Bind(state.instancePath().Append("pipewire"), innerPath, 0)

	return nil
}