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
|
|
@ -44,8 +44,11 @@ type capture struct {
|
|||
LicenseURL string `json:"license_url,omitempty"`
|
||||
Auth string `json:"auth,omitempty"`
|
||||
PID string `json:"pid,omitempty"`
|
||||
// LicenseBody is the raw JSON POST body from the phone's license request
|
||||
// (RedBee / wrapped Widevine). Used to re-issue with a local CDM challenge.
|
||||
LicenseBody string `json:"license_body,omitempty"`
|
||||
UpdatedAt string `json:"updated_at,omitempty"`
|
||||
PSSH string `json:"pssh,omitempty"` // first short Widevine PSSH seen in an MPD body
|
||||
PSSH string `json:"pssh,omitempty"` // Widevine cenc:pssh from an MPD body
|
||||
}
|
||||
|
||||
type licenseBody struct {
|
||||
|
|
@ -324,6 +327,7 @@ func main() {
|
|||
if json.Unmarshal(body, &lb) == nil {
|
||||
pid = lb.GetWidevineLicense.ReleasePID
|
||||
}
|
||||
bodyStr := string(body)
|
||||
cap.set(func(c *capture) {
|
||||
c.LicenseURL = url
|
||||
if auth != "" {
|
||||
|
|
@ -332,10 +336,19 @@ func main() {
|
|||
if pid != "" {
|
||||
c.PID = pid
|
||||
}
|
||||
// Keep JSON license wrappers (RedBee / wrapped Widevine) so the
|
||||
// host can swap in a local CDM challenge and re-POST.
|
||||
if len(body) > 0 && (strings.HasPrefix(strings.TrimSpace(bodyStr), "{") ||
|
||||
strings.Contains(strings.ToLower(req.Header.Get("Content-Type")), "json")) {
|
||||
c.LicenseBody = bodyStr
|
||||
}
|
||||
})
|
||||
if *verbose {
|
||||
log.Printf("[LIC] pid=%s auth=%s", pid, trim(auth, 40))
|
||||
log.Printf("[LIC] pid=%s auth=%s body=%d", pid, trim(auth, 40), len(body))
|
||||
log.Printf(" %s", trim(url, 120))
|
||||
if len(body) > 0 {
|
||||
log.Printf(" body: %s", trim(bodyStr, 200))
|
||||
}
|
||||
}
|
||||
if *logAll {
|
||||
traffic.write(map[string]any{
|
||||
|
|
@ -348,7 +361,7 @@ func main() {
|
|||
"authorization": trim(auth, 200),
|
||||
"pid": pid,
|
||||
"body_len": len(body),
|
||||
"body_head": trim(string(body), 240),
|
||||
"body_head": trim(bodyStr, 240),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -1205,34 +1218,74 @@ func trim(s string, n int) string {
|
|||
return s[:n] + "…"
|
||||
}
|
||||
|
||||
// Prefer the short Widevine PSSH (AAAASnBzc2g…) over the giant PlayReady blob.
|
||||
// Prefer a Widevine cenc:pssh (system id edef8ba9-…) over PlayReady / Marlin.
|
||||
// Channel 4 MPDs list PlayReady first; taking "any cenc:pssh" yields a useless blob.
|
||||
func firstShortPSSH(mpd string) string {
|
||||
const marker = "AAAASnBzc2g"
|
||||
idx := strings.Index(mpd, marker)
|
||||
if idx < 0 {
|
||||
// any cenc:pssh content
|
||||
const open = "<cenc:pssh"
|
||||
i := strings.Index(mpd, open)
|
||||
const (
|
||||
wvUUID = "edef8ba9-79d6-4ace-a3c8-27dcd51d21ed"
|
||||
wvUUIDBare = "edef8ba979d64acea3c827dcd51d21ed"
|
||||
openTag = "<cenc:pssh"
|
||||
closeTag = "</cenc:pssh>"
|
||||
)
|
||||
lower := strings.ToLower(mpd)
|
||||
searchFrom := 0
|
||||
for {
|
||||
i := strings.Index(lower[searchFrom:], openTag)
|
||||
if i < 0 {
|
||||
return ""
|
||||
break
|
||||
}
|
||||
i += searchFrom
|
||||
j := strings.Index(mpd[i:], ">")
|
||||
k := strings.Index(mpd[i:], "</cenc:pssh>")
|
||||
k := strings.Index(lower[i:], closeTag)
|
||||
if j < 0 || k < 0 || k <= j {
|
||||
return ""
|
||||
break
|
||||
}
|
||||
return strings.TrimSpace(mpd[i+j+1 : i+k])
|
||||
}
|
||||
end := idx
|
||||
for end < len(mpd) {
|
||||
c := mpd[end]
|
||||
if (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '=' {
|
||||
end++
|
||||
continue
|
||||
val := strings.TrimSpace(mpd[i+j+1 : i+k])
|
||||
// Prefer the Widevine ContentProtection block: UUID appears just before
|
||||
// this pssh, or the decoded box itself starts with the Widevine system id.
|
||||
windowStart := i - 400
|
||||
if windowStart < 0 {
|
||||
windowStart = 0
|
||||
}
|
||||
break
|
||||
window := lower[windowStart : i+j]
|
||||
if strings.Contains(window, wvUUID) || strings.Contains(window, wvUUIDBare) || looksLikeWidevinePSSH(val) {
|
||||
return val
|
||||
}
|
||||
searchFrom = i + k + len(closeTag)
|
||||
}
|
||||
return mpd[idx:end]
|
||||
// Fallback: legacy short BBC-style marker, then first cenc:pssh.
|
||||
const marker = "AAAASnBzc2g"
|
||||
if idx := strings.Index(mpd, marker); idx >= 0 {
|
||||
end := idx
|
||||
for end < len(mpd) {
|
||||
c := mpd[end]
|
||||
if (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '=' {
|
||||
end++
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
return mpd[idx:end]
|
||||
}
|
||||
i := strings.Index(lower, openTag)
|
||||
if i < 0 {
|
||||
return ""
|
||||
}
|
||||
j := strings.Index(mpd[i:], ">")
|
||||
k := strings.Index(lower[i:], closeTag)
|
||||
if j < 0 || k < 0 || k <= j {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(mpd[i+j+1 : i+k])
|
||||
}
|
||||
|
||||
// looksLikeWidevinePSSH reports whether a base64 PSSH box uses the Widevine system id.
|
||||
func looksLikeWidevinePSSH(b64 string) bool {
|
||||
// Widevine system id bytes as they appear after base64 of a typical PSSH header.
|
||||
// Full decode is avoided here to keep the on-device binary dependency-free;
|
||||
// the standard Widevine UUID base64 fragment inside PSSH boxes is stable.
|
||||
const wvFrag = "AAAAA7e+LqXnWSs6jyCfc1R0h7Q" // edef8ba9-79d6-4ace-a3c8-27dcd51d21ed
|
||||
return strings.Contains(b64, wvFrag)
|
||||
}
|
||||
|
||||
func loadOrCreateCA(certPath, keyPath string) (*tls.Certificate, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue