Null-DRM-Official/apps/streamd/internal/supervisor/appdefaults.go
404errordeveloper 2fa8f2435f Initial commit: Null DRM Official
Capture, decrypt, and restream toolkit with compiled-in app modules
(RTE, TG4, BBC), on-device MITM proxy, streamd control plane, and www.
BBC module.yaml is published (clear streams); other module values stay local.
2026-10-06 00:25:35 +02:00

87 lines
2.2 KiB
Go

package supervisor
import (
"strings"
"drmdecryption/app"
"drmdecryption/apps/streamd/internal/db"
)
// 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 a, err := app.Get(st.App); err == nil {
if sd, ok := a.(app.StreamDefaults); ok {
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
}
// 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")
}