Null-DRM-Official/apps/pkg/mpd/registry.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

59 lines
1.4 KiB
Go

package mpd
import (
"sort"
"strings"
"sync"
)
var (
regMu sync.RWMutex
registry = map[string]func() Rewriter{}
)
func init() {
Register("none", func() Rewriter { return Passthrough{} })
}
// Register makes a rewriter resolvable by name, so consumers (streamd) can pick
// one from stored config without importing the provider that implements it. A
// factory is registered rather than an instance because a rewriter may carry
// per-stream fallback state.
func Register(name string, newRewriter func() Rewriter) {
regMu.Lock()
defer regMu.Unlock()
registry[strings.ToLower(name)] = newRewriter
}
// Lookup builds a fresh rewriter for a name. An empty name, "none" or an unknown
// name yields Passthrough with ok=false, so callers can tell "no rewrite needed"
// from "rewrite with X".
func Lookup(name string) (Rewriter, bool) {
key := strings.ToLower(strings.TrimSpace(name))
if key == "" || key == "none" {
return Passthrough{}, false
}
regMu.RLock()
newRewriter, ok := registry[key]
regMu.RUnlock()
if !ok {
return Passthrough{}, false
}
rw := newRewriter()
if _, isPass := rw.(Passthrough); isPass {
return rw, false
}
return rw, true
}
// Names lists registered rewriter names.
func Names() []string {
regMu.RLock()
defer regMu.RUnlock()
out := make([]string, 0, len(registry))
for k := range registry {
out = append(out, k)
}
sort.Strings(out)
return out
}