Null-DRM-Official/apps/streamd/internal/supervisor/appdefaults.go
404errordeveloper f9c28be3f1
All checks were successful
release / build-and-upload (push) Successful in 6m8s
modules-release / build-and-upload (push) Successful in 4m47s
v0.1.1: external modules, publish YAML, proxy reset, binary-first README
- Host discovers/builds modules under modules/ (bbc, rte, tg4)
- module-publish.yaml tracked; local module.yaml gitignored
- drm --modules-dir / DRM_MODULES_DIR
- drm proxy reset; Magisk reinject reliability
- modules-v* Forgejo release workflow + build scripts
- BBC full Explore channel map including S4C
- README quickstart based on release binaries
2026-10-08 23:16:14 +02:00

104 lines
2.6 KiB
Go

package supervisor
import (
"strings"
"drmdecryption/app"
"drmdecryption/apps/streamd/internal/db"
"drmdecryption/modhost"
"drmdecryption/repo"
)
// streamSettings are the downloader knobs for one stream. They come from the
// stream's app module when it declares them, so the supervisor never has to
// guess from an app name or a stream name.
type streamSettings struct {
VideoSelect string
AudioSelect string
Rewriter string
LiveWait int
TSReadyBytes int64
// IsHLS drives packaging choices that depend on the manifest format.
IsHLS bool
}
const (
defaultLiveWait = 2
defaultTSReadyBytes = 256 * 1024
// hlsTSReadyBytes buffers more before probing: an HLS pipe-mux often starts
// with incomplete audio config.
hlsTSReadyBytes = 2 * 1024 * 1024
hlsLiveWait = 6
)
// settingsFor resolves a stream's downloader settings: the app module's
// declarations first, then the stream row, then neutral defaults.
func settingsFor(st db.Stream) streamSettings {
s := streamSettings{
VideoSelect: strings.TrimSpace(st.VideoSelect),
AudioSelect: strings.TrimSpace(st.AudioSelect),
Rewriter: strings.TrimSpace(st.Rewriter),
LiveWait: defaultLiveWait,
TSReadyBytes: defaultTSReadyBytes,
IsHLS: isHLS(st),
}
if sd := streamDefaultsFor(st.App); sd != nil {
if s.VideoSelect == "" {
s.VideoSelect = sd.VideoSelect()
}
if s.AudioSelect == "" {
s.AudioSelect = sd.AudioSelect()
}
if s.Rewriter == "" {
s.Rewriter = sd.RewriterName()
}
if n := sd.LiveWaitSeconds(); n > 0 {
s.LiveWait = n
}
if n := sd.TSReadyBytes(); n > 0 {
s.TSReadyBytes = n
}
}
if s.IsHLS {
if s.LiveWait == defaultLiveWait {
s.LiveWait = hlsLiveWait
}
if s.TSReadyBytes == defaultTSReadyBytes {
s.TSReadyBytes = hlsTSReadyBytes
}
}
if s.VideoSelect == "" {
s.VideoSelect = "for=best"
}
if s.AudioSelect == "" {
s.AudioSelect = "for=best"
}
if s.Rewriter == "" {
s.Rewriter = "none"
}
return s
}
// streamDefaultsFor prefers an external modules/<name>/ provider; falls back to
// any in-process app.Register (used by unit tests).
func streamDefaultsFor(name string) app.StreamDefaults {
if name == "" {
return nil
}
if a, err := modhost.Open(repo.Root(), name); err == nil {
return a
}
if a, err := app.Get(name); err == nil {
if sd, ok := a.(app.StreamDefaults); ok {
return sd
}
}
return nil
}
// isHLS reports whether a stream's manifest is an HLS playlist, by URL shape.
// No provider host is consulted: a module declares its own needs through
// app.StreamDefaults.
func isHLS(st db.Stream) bool {
return strings.Contains(strings.ToLower(strings.TrimSpace(st.MPD)), ".m3u8")
}