fix(hls): los prewarms ya no desalojan la sesión del espectador + trickplay 12x

- StreamSession.Prewarm → HLSSessionConfig.Prewarm: el daemon difiere el
  encode de un prewarm hasta que no haya encode vivo (poll 10s, tope
  30min) y lo registra vía RegisterKeep (side-by-side, sin desalojar).
  Antes todo pasaba por Register(), que cierra las demás sesiones — un
  prewarm de next-episode reclamado en mitad de la reproducción mataba
  el stream del usuario ("closed (cache discarded)" → master 404,
  verificado 2026-06-10). Una sesión REAL nueva primero reapea los
  prewarms en vuelo (CloseWhere(IsPrewarm)) para liberar el writer-lock
  de la caché — un prewarm SELLADO sobrevive como cache HIT — y luego
  desaloja normal vía Register.
- Trickplay: -skip_frame nokey + fps=...:eof_action=pass — solo
  decodifica keyframes (12x menos CPU medido: 233s→19s en un episodio
  de 24min 1080p; importa porque corre junto al streaming en vivo).
  Los ticks siguen siendo uniformes (fps repite el último keyframe),
  así que manifest y clientes cacheados no cambian. eof_action=pass
  cubre clips con un único keyframe (el filtro fps no emite nada de un
  stream de 1 frame con el eof por defecto).
This commit is contained in:
Deivid Soto 2026-06-10 00:54:50 +02:00
parent 9b97aedfe4
commit f9ecd5ed82
5 changed files with 228 additions and 5 deletions

View file

@ -485,6 +485,13 @@ type StreamSession struct {
// slow resume). 0/omitted = start at the beginning. Older daemons simply
// don't decode the field and keep the old start-at-0 behaviour.
StartSec float64 `json:"startSec,omitempty"`
// Prewarm marks a background cache-fill session (next-episode prewarm,
// hover prewarm): the daemon must encode it WITHOUT displacing the
// viewer's live session — it waits until the active encode finishes and
// registers alongside instead of evicting (Register kills every other
// session; a prewarm claimed mid-playback used to kill the stream the
// user was watching). False/omitted = a real viewer session.
Prewarm bool `json:"prewarm,omitempty"`
// PlayMethod is how the daemon should serve this session:
// "" — default (HLS transcode); also what legacy servers send.
// "direct" — the source is already browser-native (the web decided this