streamd: preview quality picker, dashboard polish, C4 wrap keys
- Preview player can select FHD/HD/SD (or ABR master) from publish links - Embed dashboard screenshots in README; Linux streamd+agent setup guide - C4 Widevine wrap license mode + require --wvd; prefer Widevine PSSH - Channel 4 and My5 modules; streamd auth, variants, schedules, HLS gate
This commit is contained in:
parent
b3955bd81e
commit
066e018749
113 changed files with 19002 additions and 1541 deletions
|
|
@ -9,6 +9,10 @@ import (
|
|||
"drmdecryption/apps/streamd/internal/db"
|
||||
)
|
||||
|
||||
// stalePlaylistS is how old a playlist may get before the output counts as
|
||||
// down. It matches the supervisor's own staleness threshold.
|
||||
const stalePlaylistS = 45
|
||||
|
||||
// enrichVariantHealth updates each variant's health from on-disk HLS playlists.
|
||||
func (h *Handler) enrichVariantHealth(st *db.Stream) {
|
||||
if st == nil {
|
||||
|
|
@ -27,28 +31,90 @@ func (h *Handler) enrichVariantHealth(st *db.Stream) {
|
|||
v.Health = "off"
|
||||
continue
|
||||
}
|
||||
if v.Height <= 0 {
|
||||
if v.IsSource() {
|
||||
v.Health = st.Health
|
||||
v.PlaylistAgeS = st.PlaylistAgeS
|
||||
continue
|
||||
}
|
||||
dirName := st.Name + "-" + v.ID
|
||||
index := filepath.Join(www, dirName, "index.m3u8")
|
||||
fi, err := os.Stat(index)
|
||||
if err != nil {
|
||||
if st.Health == "ok" || st.Health == "starting" {
|
||||
v.Health = "starting"
|
||||
dirName := db.VariantDir(st.Name, v.ID, v.Height, v.AudioOnly)
|
||||
health, age := h.playlistHealth(filepath.Join(www, dirName, "index.m3u8"), st.Health)
|
||||
v.Health = health
|
||||
v.PlaylistAgeS = age
|
||||
}
|
||||
}
|
||||
|
||||
// enrichLinks resolves every variant x output endpoint and stats each one, so
|
||||
// the dashboard can show that (say) HLS is fine while DASH has died.
|
||||
func (h *Handler) enrichLinks(st *db.Stream) {
|
||||
if st == nil {
|
||||
return
|
||||
}
|
||||
links := db.BuildPublishLinks(st.Name, st.VariantsJSON, st.OutputsJSON)
|
||||
www := strings.TrimSpace(h.WWWRoot)
|
||||
// Variant health computed above, to fall back on for outputs with no file
|
||||
// of their own (progressive TS is a live pipe, not a playlist).
|
||||
variantHealth := map[string]string{}
|
||||
for _, v := range st.Variants {
|
||||
variantHealth[v.ID] = v.Health
|
||||
}
|
||||
for i := range links {
|
||||
l := &links[i]
|
||||
if www == "" {
|
||||
continue
|
||||
}
|
||||
if l.Format == db.FormatTS {
|
||||
// No file to stat: the pipe is live exactly when its variant is.
|
||||
if hv, ok := variantHealth[l.VariantID]; ok {
|
||||
l.Health = hv
|
||||
} else {
|
||||
v.Health = st.Health
|
||||
l.Health = st.Health
|
||||
}
|
||||
continue
|
||||
}
|
||||
age := time.Since(fi.ModTime()).Seconds()
|
||||
v.PlaylistAgeS = age
|
||||
if age > 45 {
|
||||
v.Health = "down"
|
||||
} else {
|
||||
v.Health = "ok"
|
||||
rel := relFromPlayPath(l.PlayPath)
|
||||
if rel == "" {
|
||||
continue
|
||||
}
|
||||
l.Health, l.PlaylistAgeS = h.playlistHealth(filepath.Join(www, rel), st.Health)
|
||||
}
|
||||
st.Links = links
|
||||
}
|
||||
|
||||
// playlistHealth reports a playlist's health from its mtime. A missing file
|
||||
// while the stream is coming up is "starting", not "down".
|
||||
func (h *Handler) playlistHealth(path, streamHealth string) (string, float64) {
|
||||
fi, err := os.Stat(path)
|
||||
if err != nil {
|
||||
if streamHealth == "ok" || streamHealth == "starting" {
|
||||
return "starting", 0
|
||||
}
|
||||
return streamHealth, 0
|
||||
}
|
||||
age := time.Since(fi.ModTime()).Seconds()
|
||||
if age > stalePlaylistS {
|
||||
return "down", age
|
||||
}
|
||||
return "ok", age
|
||||
}
|
||||
|
||||
// relFromPlayPath turns a /hls/... URL path back into a path relative to the
|
||||
// www root. It returns "" for anything that escapes that root.
|
||||
func relFromPlayPath(p string) string {
|
||||
const prefix = "/hls/"
|
||||
if !strings.HasPrefix(p, prefix) {
|
||||
return ""
|
||||
}
|
||||
rel := strings.TrimPrefix(p, prefix)
|
||||
// These paths are built by us, but treat them as untrusted anyway: a
|
||||
// stream name is user input and must never climb out of www.
|
||||
clean := filepath.Clean(filepath.FromSlash(rel))
|
||||
if clean == "." || strings.HasPrefix(clean, "..") || filepath.IsAbs(clean) {
|
||||
return ""
|
||||
}
|
||||
for _, seg := range strings.Split(filepath.ToSlash(clean), "/") {
|
||||
if seg == ".." {
|
||||
return ""
|
||||
}
|
||||
}
|
||||
return clean
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue