Files
orbisubs/web/player.html
T
guy a6668f1601 OrbiSubs: master advertises the real resolution and bitrate; players jump to live by hand
The master playlist had BANDWIDTH and RESOLUTION hard-coded to T13's values
(2.6 Mb/s, 1280x720), so ecuadortv (1080p60, ~8 Mb/s) was announced as 720p.
They are now measured from the ingest's own segments in a side thread and the
master is rewritten when they change; --bandwidth/--resolution still pin them.

4f7a685 passed liveMaxLatencyDurationCount alone, which hls.js rejects
("Illegal hls.js config"), so no channel played in player.html or in the
panel's preview. The jump back to live is now done on LEVEL_UPDATED, which
keeps the HOLD-BACK published by the channel as the target.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 22:28:08 -05:00

63 lines
4.1 KiB
HTML

<!doctype html>
<html lang="es"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title>OrbiSubs prueba</title>
<style>body{background:#111;color:#ddd;font-family:sans-serif;margin:16px}video{width:100%;max-width:960px}
#info{font-size:13px;color:#999;margin-top:8px}select,input{font-size:14px}</style></head>
<body>
<h3>OrbiSubs — subtítulos en vivo (prueba)</h3>
<input id="u" size="50" value="/hls/t13/master.m3u8"> <button onclick="cargar()">Cargar</button>
<label> Subtítulos <select id="s"><option value="-1">Apagados</option></select></label>
<div><video id="v" controls muted autoplay playsinline></video></div>
<div id="info"></div>
<div id="diag" style="font-size:12px;color:#777"></div>
<script src="https://cdn.jsdelivr.net/npm/hls.js@1.5.20/dist/hls.min.js"></script>
<script>
let hls;
// ?u=/hls/<canal>/master.m3u8 elige el canal (lo usan los enlaces del panel, tarea 079).
const qu=new URLSearchParams(location.search).get('u'); if(qu&&/^\/hls\/[a-z0-9-]+\/master\.m3u8$/.test(qu)) document.getElementById('u').value=qu;
// Si quedó más de 6 segmentos detrás del colchón (corte largo de la fuente), al vivo.
function saltarAlVivo(h,v){
h.on(Hls.Events.LEVEL_UPDATED,(e,d)=>{
const td=d.details.targetduration, obj=h.targetLatency, pos=h.liveSyncPosition;
if(td&&obj&&pos&&h.latency>obj+6*td) v.currentTime=pos;
});
}
function cargar(){
const v=document.getElementById('v'), s=document.getElementById('s');
if(hls) hls.destroy();
// Colchón al borde: el HOLD-BACK que publica OrbiSubs en video.m3u8 (panel, tarea 081);
// sin él, los 3 segmentos de hls.js. ?sync=S lo fija a mano (pruebas).
const sync=+new URLSearchParams(location.search).get('sync');
// hls.js toma el HOLD-BACK como objetivo pero arranca más atrás y no se acerca solo
// (medido en la 081: objetivo 12 s, quedaba en 18): con hasta 1,1x de velocidad converge.
// Tras un corte largo de la fuente (CDN de T13, 65 s el 2026-11-17 17:37) el player quedaba
// un minuto atrás y a 1,1x tardaba ~10 min en volver: con más de 6 segmentos de atraso salta al vivo.
// El salto va a mano (saltarAlVivo): liveMaxLatencyDurationCount solo hace que hls.js tire
// "Illegal hls.js config" si no va con liveSyncDurationCount, y ese pisa el HOLD-BACK
// (pasó con 4f7a685: ningún canal reproducía, 2026-11-19).
hls=new Hls(sync>0?{liveSyncDuration:sync,liveMaxLatencyDuration:sync+12,maxLiveSyncPlaybackRate:1.1}:{maxLiveSyncPlaybackRate:1.1});
if(!(sync>0)) saltarAlVivo(hls,v);
// Recuperación estándar de hls.js: el CDN de origen mete cortes de PTS en las tandas
// y el decoder del navegador a veces se cae ahí (visto con Chromium, 2026-11-16).
hls.on(Hls.Events.ERROR,(e,d)=>{ if(!d.fatal) return;
if(d.type===Hls.ErrorTypes.MEDIA_ERROR) hls.recoverMediaError(); else hls.startLoad(); });
hls.loadSource(document.getElementById('u').value); hls.attachMedia(v);
hls.on(Hls.Events.SUBTITLE_TRACKS_UPDATED,()=>{
s.innerHTML='<option value="-1">Apagados</option>'+hls.subtitleTracks.map((t,i)=>`<option value="${i}">${t.name}</option>`).join('');
// Arranca en la pista pedida por ?lang=en (o en español).
const q=new URLSearchParams(location.search).get('lang')||'es';
const i=Math.max(0,hls.subtitleTracks.findIndex(t=>t.lang===q));
s.value=i; hls.subtitleTrack=i; hls.subtitleDisplay=true;
});
s.onchange=()=>{hls.subtitleTrack=+s.value; hls.subtitleDisplay=+s.value>=0;};
// Diagnóstico: cuántos cues cargó la pista y cuál está en pantalla (sirve para
// probar con un navegador headless que el texto llega y en qué tiempo del video).
setInterval(()=>{const t=[...v.textTracks].find(x=>x.mode==='showing');
const act=t&&t.activeCues&&t.activeCues.length?[...t.activeCues].map(c=>c.text.replace(/\n/g,' ')).join(' / '):'';
document.getElementById('diag').textContent=`t=${v.currentTime.toFixed(1)} pistas=${v.textTracks.length} cues=${t&&t.cues?t.cues.length:0} activo=[${act}]`;},500);
setInterval(()=>{const l=hls.latency; document.getElementById('info').textContent=
'Retraso al borde de la lista publicada: '+(l?l.toFixed(1):'?')+' s';},1000);
}
cargar();
</script></body></html>