diff --git a/dist/jfvr.js b/dist/jfvr.js index 21102dd..dda4196 100644 --- a/dist/jfvr.js +++ b/dist/jfvr.js @@ -394,8 +394,11 @@ * 10-bit will still claim 10-bit at that level and can black-screen on such a * file. 40-watchdog.js covers exactly that, which is why it stays. * - * Escape hatches, if a device reports nonsense: - * localStorage['jfvr-cpt'] = 'off' disable the hook entirely + * THE HOOK IS OFF BY DEFAULT. The plugin no longer influences Jellyfin's + * direct-play / transcode decision at all -- Jellyfin uses its native device + * profile, and when playback cannot keep up the 40-watchdog.js prompt lets the + * user pick a bitrate. The override is kept only as an opt-in experiment: + * localStorage['jfvr-cpt'] = 'on' enable the canPlayType hook * localStorage['jfvr-cpt-keep'] = '2:183' never downgrade these tiers */ @@ -571,10 +574,15 @@ } (function probeCodecs() { - // Kill switch, and the escape hatch if this ever misbehaves on a device. - try { - if (localStorage.getItem('jfvr-cpt') === 'off') { NS.caps.cptMode = 'off'; return; } - } catch (e) {} + // Native behavior is the default: do NOT install the canPlayType override, + // so Jellyfin builds its own device profile exactly as it would without this + // plugin. Opt back in with localStorage['jfvr-cpt'] = 'on' when diagnosing. + // The decodingInfo probe still runs so the diagnostics panel can report what + // the device really supports -- it just no longer changes any decision. + var hookOn = false; + try { hookOn = localStorage.getItem('jfvr-cpt') === 'on'; } catch (e) {} + NS.caps.cptMode = hookOn ? null : 'off'; + var mc = navigator.mediaCapabilities; if (!mc || typeof mc.decodingInfo !== 'function') { NS.caps.cptMode = 'no-api'; return; } @@ -585,7 +593,7 @@ // Install FIRST, synchronously, so the hook is in place before anything can // read canPlayType. Until a verdict lands the hook just defers to native, // which is the safe default. - installCanPlayTypeOverride(); + if (hookOn) installCanPlayTypeOverride(); var pending = CODEC_PROBES.length; CODEC_PROBES.forEach(function (p) { @@ -606,7 +614,8 @@ }).then(function () { if (--pending === 0) { applyVerdicts(); - NS.log('codec probe done; blocked = ' + (NS.caps.codecBlocked.join(', ') || 'none') + + NS.log('codec probe done (hook ' + NS.caps.cptMode + '); would block = ' + + (NS.caps.codecBlocked.join(', ') || 'none') + (NS.caps.codecKept.length ? '; pinned = ' + NS.caps.codecKept.join(', ') : '')); } }); @@ -4745,6 +4754,15 @@ var DEAD_MS = 15000; var DEAD_TRANSCODE_MS = 45000; + // Metadata parsed but the playhead is not moving. This is the silent stall: a + // decoder that reads the header and then cannot keep up (8K HEVC Main 10 on a + // broken VAAPI driver is the motivating case). The old "has picture" check + // only looked at videoWidth/readyState, which are both already set here, so + // playback that never advances stood the watchdog down forever and the user + // got a frozen picture with no prompt. Give it a little longer than a clean + // start, since a heavy 8K stream legitimately buffers early. + var STALL_MS = 20000; + // After the user answers (either way) stay quiet, so a slow-but-working // playback does not get nagged at. var QUIET_MS = 120000; @@ -4765,7 +4783,9 @@ lastReason: '', applied: null, codec: null, // filled in best-effort from the Jellyfin API - panel: null + panel: null, + lastTime: -1, // playhead seen on the previous poll + progressAt: 0 // when the playhead last moved }; NS.Watchdog = W; @@ -4791,7 +4811,7 @@ return src.indexOf('/hls') >= 0 || src.indexOf('.m3u8') >= 0; } - /** Metadata parsed AND a frame available. False means "no picture". */ + /** Metadata parsed AND a frame available. False means "no picture at all". */ function hasPicture(v) { return v.videoWidth > 0 && v.readyState >= 2; } @@ -4933,17 +4953,25 @@ var p = NS.makeEl('div', 'jfvr-wd'); p.id = 'jfvr-wd'; - p.appendChild(NS.makeEl('h3', null, '视频没能开始播放')); + p.appendChild(NS.makeEl('h3', null, + reason === 'stalled' ? '视频播放卡住了' : '视频没能开始播放')); var body = NS.makeEl('div', 'jfvr-wd-body'); var msg = NS.makeEl('p'); var waited = Math.round(timeoutMs(v) / 1000); + var intro; + if (reason === 'error') { + intro = '播放器报错了,一个画面都没解出来。'; + } else if (reason === 'stalled') { + intro = '画面已经出来了,但播放进度停住不动了(currentTime 不再前进)—— ' + + '解码器跟不上这个文件。'; + } else { + intro = '等了 ' + waited + ' 秒都没拿到任何画面(videoWidth = 0),' + + '所以播放器界面也没有被创建出来。'; + } msg.innerHTML = - (reason === 'error' - ? '播放器报错了,一个画面都没解出来。' - : '等了 ' + waited + ' 秒都没拿到任何画面(videoWidth = 0),' + - '所以播放器界面也没有被创建出来。') + + intro + '最常见的原因是这台设备解不动这个格式:' + '' + (W.codec || '该格式') + '。
' + '让服务器转码成 H.264 再播就能看到画面,代价是画质下降(这台 NAS 的转码上限约 4K)。'; @@ -4985,7 +5013,7 @@ W.panel = p; NS.recordError('watchdog', new Error('playback never started: ' + reason)); - log('watchdog: playback never started, reason =', reason, 'codec =', W.codec); + log('watchdog: prompt shown, reason =', reason, 'codec =', W.codec); } function hide() { @@ -4995,6 +5023,8 @@ function reset() { W.seenAt = 0; + W.lastTime = -1; + W.progressAt = 0; W.codec = null; if (W.shown) hide(); } @@ -5015,9 +5045,6 @@ var v = playerVideo(); if (!v) { reset(); return; } - // Playback is fine (or at least has a picture): stand down. - if (hasPicture(v)) { reset(); return; } - // A media error is unambiguous — no need to wait out the timer. if (v.error) { describeCodec(v); @@ -5026,6 +5053,31 @@ return; } + // Metadata is parsed and a frame exists. That is NOT enough to call it + // healthy: a decoder that read the header and then cannot keep up leaves + // videoWidth/readyState set while currentTime never moves. Only a moving + // playhead counts as playback. + if (hasPicture(v)) { + if (!W.progressAt) W.progressAt = now(); + + // Paused / seeking is the user's doing, not a stall. + if (v.paused || v.seeking) { W.progressAt = now(); W.lastTime = v.currentTime; return; } + + if (v.currentTime !== W.lastTime) { + W.lastTime = v.currentTime; + W.progressAt = now(); + if (W.shown) hide(); // it recovered (e.g. after a transcode switch) + return; + } + + if (now() - W.progressAt < STALL_MS) return; + if (W.quietUntil && now() < W.quietUntil) return; + describeCodec(v); + show(v, 'stalled'); + return; + } + + // No picture at all yet: the original "never started" case. if (!W.seenAt) W.seenAt = now(); if (now() - W.seenAt < timeoutMs(v)) return; @@ -5038,7 +5090,8 @@ NS.Watchdog.init = function () { W.quietUntil = readQuiet(); setInterval(poll, POLL_MS); - log('watchdog armed (dead=' + DEAD_MS + 'ms, transcode=' + DEAD_TRANSCODE_MS + 'ms)'); + log('watchdog armed (dead=' + DEAD_MS + 'ms, transcode=' + DEAD_TRANSCODE_MS + + 'ms, stall=' + STALL_MS + 'ms)'); }; })(); diff --git a/src/00-core.js b/src/00-core.js index 2981590..ac5573a 100644 --- a/src/00-core.js +++ b/src/00-core.js @@ -386,8 +386,11 @@ * 10-bit will still claim 10-bit at that level and can black-screen on such a * file. 40-watchdog.js covers exactly that, which is why it stays. * - * Escape hatches, if a device reports nonsense: - * localStorage['jfvr-cpt'] = 'off' disable the hook entirely + * THE HOOK IS OFF BY DEFAULT. The plugin no longer influences Jellyfin's + * direct-play / transcode decision at all -- Jellyfin uses its native device + * profile, and when playback cannot keep up the 40-watchdog.js prompt lets the + * user pick a bitrate. The override is kept only as an opt-in experiment: + * localStorage['jfvr-cpt'] = 'on' enable the canPlayType hook * localStorage['jfvr-cpt-keep'] = '2:183' never downgrade these tiers */ @@ -563,10 +566,15 @@ } (function probeCodecs() { - // Kill switch, and the escape hatch if this ever misbehaves on a device. - try { - if (localStorage.getItem('jfvr-cpt') === 'off') { NS.caps.cptMode = 'off'; return; } - } catch (e) {} + // Native behavior is the default: do NOT install the canPlayType override, + // so Jellyfin builds its own device profile exactly as it would without this + // plugin. Opt back in with localStorage['jfvr-cpt'] = 'on' when diagnosing. + // The decodingInfo probe still runs so the diagnostics panel can report what + // the device really supports -- it just no longer changes any decision. + var hookOn = false; + try { hookOn = localStorage.getItem('jfvr-cpt') === 'on'; } catch (e) {} + NS.caps.cptMode = hookOn ? null : 'off'; + var mc = navigator.mediaCapabilities; if (!mc || typeof mc.decodingInfo !== 'function') { NS.caps.cptMode = 'no-api'; return; } @@ -577,7 +585,7 @@ // Install FIRST, synchronously, so the hook is in place before anything can // read canPlayType. Until a verdict lands the hook just defers to native, // which is the safe default. - installCanPlayTypeOverride(); + if (hookOn) installCanPlayTypeOverride(); var pending = CODEC_PROBES.length; CODEC_PROBES.forEach(function (p) { @@ -598,7 +606,8 @@ }).then(function () { if (--pending === 0) { applyVerdicts(); - NS.log('codec probe done; blocked = ' + (NS.caps.codecBlocked.join(', ') || 'none') + + NS.log('codec probe done (hook ' + NS.caps.cptMode + '); would block = ' + + (NS.caps.codecBlocked.join(', ') || 'none') + (NS.caps.codecKept.length ? '; pinned = ' + NS.caps.codecKept.join(', ') : '')); } }); diff --git a/src/40-watchdog.js b/src/40-watchdog.js index 5f4a9a9..dae86c4 100644 --- a/src/40-watchdog.js +++ b/src/40-watchdog.js @@ -59,6 +59,15 @@ var DEAD_MS = 15000; var DEAD_TRANSCODE_MS = 45000; + // Metadata parsed but the playhead is not moving. This is the silent stall: a + // decoder that reads the header and then cannot keep up (8K HEVC Main 10 on a + // broken VAAPI driver is the motivating case). The old "has picture" check + // only looked at videoWidth/readyState, which are both already set here, so + // playback that never advances stood the watchdog down forever and the user + // got a frozen picture with no prompt. Give it a little longer than a clean + // start, since a heavy 8K stream legitimately buffers early. + var STALL_MS = 20000; + // After the user answers (either way) stay quiet, so a slow-but-working // playback does not get nagged at. var QUIET_MS = 120000; @@ -79,7 +88,9 @@ lastReason: '', applied: null, codec: null, // filled in best-effort from the Jellyfin API - panel: null + panel: null, + lastTime: -1, // playhead seen on the previous poll + progressAt: 0 // when the playhead last moved }; NS.Watchdog = W; @@ -105,7 +116,7 @@ return src.indexOf('/hls') >= 0 || src.indexOf('.m3u8') >= 0; } - /** Metadata parsed AND a frame available. False means "no picture". */ + /** Metadata parsed AND a frame available. False means "no picture at all". */ function hasPicture(v) { return v.videoWidth > 0 && v.readyState >= 2; } @@ -247,17 +258,25 @@ var p = NS.makeEl('div', 'jfvr-wd'); p.id = 'jfvr-wd'; - p.appendChild(NS.makeEl('h3', null, '视频没能开始播放')); + p.appendChild(NS.makeEl('h3', null, + reason === 'stalled' ? '视频播放卡住了' : '视频没能开始播放')); var body = NS.makeEl('div', 'jfvr-wd-body'); var msg = NS.makeEl('p'); var waited = Math.round(timeoutMs(v) / 1000); + var intro; + if (reason === 'error') { + intro = '播放器报错了,一个画面都没解出来。'; + } else if (reason === 'stalled') { + intro = '画面已经出来了,但播放进度停住不动了(currentTime 不再前进)—— ' + + '解码器跟不上这个文件。'; + } else { + intro = '等了 ' + waited + ' 秒都没拿到任何画面(videoWidth = 0),' + + '所以播放器界面也没有被创建出来。'; + } msg.innerHTML = - (reason === 'error' - ? '播放器报错了,一个画面都没解出来。' - : '等了 ' + waited + ' 秒都没拿到任何画面(videoWidth = 0),' + - '所以播放器界面也没有被创建出来。') + + intro + '最常见的原因是这台设备解不动这个格式:' + '' + (W.codec || '该格式') + '。
' + '让服务器转码成 H.264 再播就能看到画面,代价是画质下降(这台 NAS 的转码上限约 4K)。'; @@ -299,7 +318,7 @@ W.panel = p; NS.recordError('watchdog', new Error('playback never started: ' + reason)); - log('watchdog: playback never started, reason =', reason, 'codec =', W.codec); + log('watchdog: prompt shown, reason =', reason, 'codec =', W.codec); } function hide() { @@ -309,6 +328,8 @@ function reset() { W.seenAt = 0; + W.lastTime = -1; + W.progressAt = 0; W.codec = null; if (W.shown) hide(); } @@ -329,9 +350,6 @@ var v = playerVideo(); if (!v) { reset(); return; } - // Playback is fine (or at least has a picture): stand down. - if (hasPicture(v)) { reset(); return; } - // A media error is unambiguous — no need to wait out the timer. if (v.error) { describeCodec(v); @@ -340,6 +358,31 @@ return; } + // Metadata is parsed and a frame exists. That is NOT enough to call it + // healthy: a decoder that read the header and then cannot keep up leaves + // videoWidth/readyState set while currentTime never moves. Only a moving + // playhead counts as playback. + if (hasPicture(v)) { + if (!W.progressAt) W.progressAt = now(); + + // Paused / seeking is the user's doing, not a stall. + if (v.paused || v.seeking) { W.progressAt = now(); W.lastTime = v.currentTime; return; } + + if (v.currentTime !== W.lastTime) { + W.lastTime = v.currentTime; + W.progressAt = now(); + if (W.shown) hide(); // it recovered (e.g. after a transcode switch) + return; + } + + if (now() - W.progressAt < STALL_MS) return; + if (W.quietUntil && now() < W.quietUntil) return; + describeCodec(v); + show(v, 'stalled'); + return; + } + + // No picture at all yet: the original "never started" case. if (!W.seenAt) W.seenAt = now(); if (now() - W.seenAt < timeoutMs(v)) return; @@ -352,6 +395,7 @@ NS.Watchdog.init = function () { W.quietUntil = readQuiet(); setInterval(poll, POLL_MS); - log('watchdog armed (dead=' + DEAD_MS + 'ms, transcode=' + DEAD_TRANSCODE_MS + 'ms)'); + log('watchdog armed (dead=' + DEAD_MS + 'ms, transcode=' + DEAD_TRANSCODE_MS + + 'ms, stall=' + STALL_MS + 'ms)'); }; })();