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
|
|
@ -2,6 +2,7 @@ package queue
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
|
@ -100,24 +101,56 @@ func parseTime(s string) time.Time {
|
|||
return t
|
||||
}
|
||||
|
||||
// EnqueueIfIdle inserts a job unless one is already queued/running for the stream.
|
||||
// Job priorities. ClaimNext orders by priority ascending, so a lower number
|
||||
// runs sooner.
|
||||
const (
|
||||
// PriorityInteractive is for a capture a viewer or a schedule is actively
|
||||
// waiting on, pushed by streamd over the agent websocket.
|
||||
PriorityInteractive = 10
|
||||
// PriorityRoutine is a background refresh found by polling.
|
||||
PriorityRoutine = 100
|
||||
)
|
||||
|
||||
// EnqueueIfIdle inserts a routine job unless one is already queued/running
|
||||
// for the stream.
|
||||
func (s *Store) EnqueueIfIdle(streamID int64, name, app, channel, reason string, maxAttempts int) (Job, bool, error) {
|
||||
var existing int
|
||||
return s.EnqueueIfIdlePriority(streamID, name, app, channel, reason, maxAttempts, PriorityRoutine)
|
||||
}
|
||||
|
||||
// EnqueueIfIdlePriority is EnqueueIfIdle with an explicit priority. A job that
|
||||
// someone is waiting on is enqueued ahead of routine refreshes; if a routine
|
||||
// job for the same stream is already queued, its priority is raised instead of
|
||||
// adding a duplicate.
|
||||
func (s *Store) EnqueueIfIdlePriority(streamID int64, name, app, channel, reason string, maxAttempts, priority int) (Job, bool, error) {
|
||||
var existingID int64
|
||||
var existingPriority int
|
||||
err := s.DB.QueryRow(`
|
||||
SELECT COUNT(1) FROM jobs WHERE stream_id=? AND status IN ('queued','running')`, streamID).Scan(&existing)
|
||||
if err != nil {
|
||||
return Job{}, false, err
|
||||
}
|
||||
if existing > 0 {
|
||||
SELECT id, priority FROM jobs
|
||||
WHERE stream_id=? AND status IN ('queued','running')
|
||||
ORDER BY id LIMIT 1`, streamID).Scan(&existingID, &existingPriority)
|
||||
switch {
|
||||
case err == nil:
|
||||
// Already pending. Promote it when this request is more urgent, and
|
||||
// clear any backoff so it runs now rather than after the delay.
|
||||
if priority < existingPriority {
|
||||
_, _ = s.DB.Exec(
|
||||
`UPDATE jobs SET priority=?, reason=?, not_before='' WHERE id=? AND status='queued'`,
|
||||
priority, reason, existingID)
|
||||
}
|
||||
return Job{}, false, nil
|
||||
case !errors.Is(err, sql.ErrNoRows):
|
||||
return Job{}, false, err
|
||||
}
|
||||
if maxAttempts <= 0 {
|
||||
maxAttempts = 5
|
||||
}
|
||||
if priority <= 0 {
|
||||
priority = PriorityRoutine
|
||||
}
|
||||
res, err := s.DB.Exec(`
|
||||
INSERT INTO jobs(stream_id,stream_name,app,channel,reason,status,priority,attempts,max_attempts,created_at,not_before)
|
||||
VALUES(?,?,?,?,?,'queued',100,0,?,?,?)`,
|
||||
streamID, name, app, channel, reason, maxAttempts, now(), now())
|
||||
VALUES(?,?,?,?,?,'queued',?,0,?,?,?)`,
|
||||
streamID, name, app, channel, reason, priority, maxAttempts, now(), now())
|
||||
if err != nil {
|
||||
return Job{}, false, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue