streamd: serve start/stop/update, streamd.yaml, egress, module panel fixes

- Add streamd serve start|stop|restart|status|update with auto-written streamd.yaml
- Panel modules: STREAMD_MODULES_DIR for describe, YAML channel fallback, textarea value fix
- Per-stream WireGuard/SOCKS egress profiles + Settings UI
- Drop drm-* from release builds; track streamd-bg.sh / streamd-update.sh wrappers
- Docs: streamd-server-setup lifecycle and update flow
This commit is contained in:
404errordeveloper 2026-10-10 18:05:51 +02:00
parent da8e1123ec
commit 8fc7e4c0b8
57 changed files with 4031 additions and 257 deletions

View file

@ -37,12 +37,19 @@ type Media struct {
// ViewersFn reports the live client count for a stream, for the metrics
// series. Optional.
ViewersFn func(streamName string) int
// ProxyResolver resolves stream.Proxy / stream.Egress to a SOCKS/HTTP URL.
ProxyResolver ProxyResolver
mu sync.Mutex
procs map[int64]*streamProc
stopMon chan struct{}
}
// ProxyResolver turns a stream row into an origin-fetch proxy URL.
type ProxyResolver interface {
ResolveProxy(st db.Stream) (string, error)
}
// Notifier is the subset of the websocket hub the supervisor needs.
type Notifier interface {
NotifyRuntime(name, health string)
@ -82,15 +89,16 @@ type streamProc struct {
// Options for constructing the media supervisor.
type Options struct {
Store *db.Store
DataDir string
NRE string
FFmpeg string
MP4Decrypt string
Log *slog.Logger
Fanout *tsfanout.Set
Notifier Notifier
ViewersFn func(streamName string) int
Store *db.Store
DataDir string
NRE string
FFmpeg string
MP4Decrypt string
Log *slog.Logger
Fanout *tsfanout.Set
Notifier Notifier
ViewersFn func(streamName string) int
ProxyResolver ProxyResolver
}
func NewMedia(opt Options) *Media {
@ -103,17 +111,18 @@ func NewMedia(opt Options) *Media {
fan = tsfanout.NewSet(tsfanout.DefaultBufferBytes)
}
m := &Media{
Store: opt.Store,
DataDir: opt.DataDir,
NRE: opt.NRE,
FFmpeg: opt.FFmpeg,
MP4Decrypt: opt.MP4Decrypt,
Log: lg,
Fanout: fan,
Notifier: opt.Notifier,
ViewersFn: opt.ViewersFn,
procs: map[int64]*streamProc{},
stopMon: make(chan struct{}),
Store: opt.Store,
DataDir: opt.DataDir,
NRE: opt.NRE,
FFmpeg: opt.FFmpeg,
MP4Decrypt: opt.MP4Decrypt,
Log: lg,
Fanout: fan,
Notifier: opt.Notifier,
ViewersFn: opt.ViewersFn,
ProxyResolver: opt.ProxyResolver,
procs: map[int64]*streamProc{},
stopMon: make(chan struct{}),
}
go m.monitorLoop()
return m
@ -143,6 +152,13 @@ func (m *Media) Running(id int64) bool {
func (m *Media) logsDir() string { return filepath.Join(m.DataDir, "logs") }
func (m *Media) effectiveProxy(st db.Stream) (string, error) {
if m.ProxyResolver != nil {
return m.ProxyResolver.ResolveProxy(st)
}
return strings.TrimSpace(st.Proxy), nil
}
func (m *Media) Start(id int64) error {
st, err := m.Store.GetStream(id)
if err != nil {
@ -203,12 +219,17 @@ func (m *Media) Start(id int64) error {
saveName := st.Name
headers := headerMap(st.HeadersJSON)
cfg := settingsFor(st, m.Store.GlobalPackagerSettings())
originProxy, err := m.effectiveProxy(st)
if err != nil {
m.fail(id, st.Name, "egress: "+err.Error())
return err
}
manifestURL := st.MPD
var mpdProxy *mpd.LocalServer
// The rewriter is named by the stream row or its app module and looked up in
// the mpd registry, so streamd needs no knowledge of any provider.
if rw, needed := mpd.Lookup(cfg.Rewriter); needed && strings.TrimSpace(st.MPD) != "" && !cfg.IsHLS {
srv, err := mpd.StartLocal(st.MPD, st.Key, headers, rw, st.Proxy)
srv, err := mpd.StartLocal(st.MPD, st.Key, headers, rw, originProxy)
if err != nil {
m.fail(id, st.Name, "mpd rewrite server: "+err.Error())
return err
@ -246,7 +267,7 @@ func (m *Media) Start(id int64) error {
"--mp4-real-time-decryption",
)
}
if proxy := strings.TrimSpace(st.Proxy); proxy != "" {
if proxy := strings.TrimSpace(originProxy); proxy != "" {
// NRE prefers --custom-proxy over the system proxy when both are set.
// The proxy may carry credentials, so it is not logged.
nreArgs = append(nreArgs, "--custom-proxy", proxy)