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.
This commit is contained in:
commit
2fa8f2435f
121 changed files with 17802 additions and 0 deletions
59
apps/pkg/mpd/registry.go
Normal file
59
apps/pkg/mpd/registry.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue