Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85fea48159 | ||
|
|
986d30dfb4 | ||
|
|
ab36d2f25c | ||
|
|
bfcd102ed0 | ||
|
|
131e0349b8 | ||
|
|
d0fe04bf25 | ||
|
|
51ab1a4b48 | ||
|
|
5279f3929a | ||
|
|
ac85de2cb8 | ||
|
|
7e25861498 |
+1
-1
@@ -9,7 +9,7 @@ secrets*.md
|
||||
# deploy.py --legacy actually uses), so only the legacy one is tracked.
|
||||
/jfvr-mvp.js
|
||||
# Temporary offline test page (fake <video> + libass canvas + XR stubs).
|
||||
_harness.html
|
||||
_harness*.html
|
||||
|
||||
# --- build / tooling noise --------------------------------------------
|
||||
__pycache__/
|
||||
|
||||
+127
-1
@@ -122,7 +122,7 @@ Style: RightEye, Alignment=8, MarginL=1920, MarginR=50 , MarginV=700
|
||||
| `XRWebGLBinding.createQuadLayer` | **true** |
|
||||
| `XRWebGLBinding.getSubImage` | **需要 2 个参数** `(layer, frame)` |
|
||||
| `MAX_TEXTURE_SIZE` / `MAX_RENDERBUFFER_SIZE` | **8192 / 16384** |
|
||||
| 8K HEVC `decodingInfo` | `supported:true, powerEfficient:true` |
|
||||
| 8K HEVC `decodingInfo` | `supported:true, powerEfficient:true`(仅 8-bit Main,见 ADDENDUM 12) |
|
||||
| `supportedFrameRates` | **[72, 80, 90, 120]** |
|
||||
| `enabledFeatures` | `[local, viewer, bounded-floor, layers, hand-tracking, webxr, local-floor]` |
|
||||
| 手部追踪 | ✅ 25 关节齐全,profiles `["oculus-hand","generic-hand","generic-hand-select","generic-trigger"]` |
|
||||
@@ -789,3 +789,129 @@ handPref=left(持久化后重开会话) pointer hand:left HIT 0.22,0
|
||||
右手按住画面拖动条,左手松开 viewDrag 仍 "armed"(拖动存活)
|
||||
右手按住画面拖动条,右手松开 viewDrag "reset (tap)"(拖动结束)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 18. ADDENDUM 12 — 「这台机器放不出来」:8K Main 10 与客户端自报能力(插件 0.2.0.0 / bundle `edca47`)
|
||||
|
||||
### 18.1 现象
|
||||
|
||||
同一个文件 `masex.tv@kiwvr00896_1_8k.mp4`:
|
||||
|
||||
- **Quest 3 上正常播放**
|
||||
- **PC 浏览器上黑屏 / 一直转圈,进度条不走**,而且**播放器界面(含码率菜单)根本不出现**
|
||||
|
||||
### 18.2 根因
|
||||
|
||||
**文件是 10-bit,而库里其它文件都是 8-bit。** 实测:
|
||||
|
||||
```
|
||||
FAILS : kiwvr00896_1_8k profile=Main 10 pix_fmt=yuv420p10le 8192x4096 level 183 (6.1) 30 Mbps
|
||||
kiwvr00896_2_8k profile=Main 10 pix_fmt=yuv420p10le
|
||||
WORKS : 13dsvr01786_1_8k profile=Main pix_fmt=yuv420p 8192x4096 level 183
|
||||
13dsvr01794_1_8k profile=Main pix_fmt=yuv420p
|
||||
13dsvr01797_1_8k profile=Main pix_fmt=yuv420p
|
||||
```
|
||||
|
||||
**关键:Jellyfin 的直连/转码决策 100% 看客户端上报的 DeviceProfile。** Jellyfin Web 是这么生成它的(`src/scripts/browserDeviceProfile.js`):
|
||||
|
||||
```js
|
||||
let maxHevcLevel = 120;
|
||||
let hevcProfiles = 'main';
|
||||
// hevc main10 level 6.1
|
||||
if (videoTestElement.canPlayType('video/mp4; codecs="hvc1.2.4.L183"')...) {
|
||||
maxHevcLevel = 183; // 8K
|
||||
hevcProfiles = 'main|main 10'; // 10-bit
|
||||
}
|
||||
```
|
||||
|
||||
PC 浏览器对 `hvc1.2.4.L183` 返回 **"probably"**(系统里有*某个* HEVC 解码器,`canPlayType` 判断很粗),于是声明「支持 Main 10 到 level 6.1(8K)」→ 服务器选了 **Direct Play** → 实际硬件解不动 → 黑屏。Quest 声明同样的话但它真做得到。
|
||||
|
||||
**服务器侧没有「强制转码」开关。** `UserPolicy` 只有:`EnableVideoPlaybackTranscoding`(已开)、`EnablePlaybackRemuxing`(已开)、`RemoteClientBitrateLimit`(只对远程连接)、`ForceRemoteSourceTranscoding`(只对远程片源)。没有任何按条目/按设备的强制转码。
|
||||
|
||||
**顺带发现:本项目的能力探测有盲区。** `src/00-core.js:326` 只测了
|
||||
|
||||
```js
|
||||
['video/mp4; codecs="hev1.1.6.L183.B0"', // profile_idc 1 = Main(8-bit)
|
||||
'video/mp4; codecs="hvc1.1.6.L183.B0"',
|
||||
'video/mp4; codecs="hev1"', 'video/mp4; codecs="hvc1"']
|
||||
```
|
||||
|
||||
`hev1.**1.6**.L183.B0` 里的 `1.6` 是 **Main**;**Main 10 是 `hev1.2.4.L183.B0`,从来没测过**。所以 README §2.0 那句「8K HEVC decodingInfo supported:true」**只对 8-bit 成立** —— 之前碰巧全是 8-bit 文件才没暴露。
|
||||
|
||||
### 18.3 为什么卡住之后连码率都调不了(重要)
|
||||
|
||||
Jellyfin Web 的播放器 UI **只在 `playbackstart` 之后才被创建**:
|
||||
|
||||
```
|
||||
HtmlVideoPlayer.play() htmlVideoPlayer/plugin.js:502
|
||||
createMediaElement() :1802 loading.show() 转圈
|
||||
<div.videoPlayerContainer><video>
|
||||
document.body.insertBefore(...) ← 还没有 src
|
||||
updateVideoUrl() / setCurrentSrc() :593 elem.src = url
|
||||
→ loadedmetadata → canplay → play
|
||||
→ 'playbackstart'
|
||||
→ OSD 控制器(apps/legacy/controllers/playback/video/index.js:591)
|
||||
```
|
||||
|
||||
媒体起不来 → 事件不触发 → **OSD(含码率菜单)从未被创建**。所以「卡住后调不了码率」不是菜单藏起来了,是**它还不存在**。
|
||||
|
||||
推论:看门狗不能用 `90-main.js` 的 `findVideo()`(它要求 `videoWidth`,卡死时返回 null),必须直接看 `.videoPlayerContainer video`。
|
||||
|
||||
### 18.4 对策:`src/40-watchdog.js`
|
||||
|
||||
检测「OSD 之前就卡住」这个状态并给出唯一的解 —— 让服务器转码。见 README §1.2。
|
||||
|
||||
阈值:媒体报错立即弹;直连 15 秒;转码(src 已是 hls)45 秒;有画面立即退出;VR 会话中不跑。
|
||||
|
||||
选码率后写入 Jellyfin 自己那套键再重载:
|
||||
|
||||
```
|
||||
maxbitrate-Video-<true|false> = 20000000
|
||||
enableautobitratebitrate-Video-<true|false> = false ← 上游拼写,bitrate 出现两次
|
||||
```
|
||||
|
||||
> 不能用 `playbackManager.setMaxStreamingBitrate()`:那个模块**没有暴露到 window**
|
||||
> (实测 `window.playbackManager === undefined`,`window.Emby` 只剩 `Page`)。
|
||||
|
||||
### 18.5 转码在这台 NAS 上的实测能力
|
||||
|
||||
2026-10-05 那次播放走的就是转码:
|
||||
|
||||
```
|
||||
-codec:v h264_vaapi -b:v 2744000 -vf "scale_vaapi=w=1280:h=640"
|
||||
→ 1280x640 @ 2.7 Mbps,ffmpeg 每次 exit 0,无失败
|
||||
```
|
||||
|
||||
8K 10-bit 硬解 + h264 硬编在 UHD 上跑得动,但**输出只有 1280×640**(当时目标码率 2.7 Mbps;UHD 编码上限约 4K)。
|
||||
|
||||
### 18.6 附带查清的两件事
|
||||
|
||||
1. **续播点 33:22.759 的来历**:就是 2026-10-05 那次转码会话留下的(`stopped ... at 2002759ms`)。所以 10-17 两次播放都从 33:22 续播,画面出不来进度自然不动,于是「停在 33:22」重复了两次。
|
||||
2. **文件本身没问题**:完全分配无空洞(`du` 实际用量 == 表观大小)、`moov` 在文件头(faststart 正常)、33:22 处 ffmpeg 解码无报错、Jellyfin 数据库里时长正确(50:58)。同目录还有 3 个垃圾广告文件(`.url` × 3 + 一个 20 MB 的 `三 上 悠 亚…mp4`),是盗版站打包进来的。
|
||||
|
||||
### 18.7 已做(插件 0.3.0.0 / bundle `4e9a8f`)
|
||||
|
||||
- [x] `src/00-core.js` 的能力探测补上 Main 10 和 8K/4K 分档;新增 `NS.caps.codec`(`decodingInfo` 逐档结果)与 `NS.capsDiag()` 里的 `HEVC real` 段
|
||||
- [x] **彻底自动化**:用 `MediaCapabilities.decodingInfo` 真机探测后覆盖 `HTMLVideoElement.prototype.canPlayType`,让 Jellyfin Web 自己那套 `maxHevcLevel` 逻辑算出准确 profile
|
||||
|
||||
覆盖逻辑的关键点:
|
||||
|
||||
- 每档在**它对应的分辨率**上探测(level 字符串不带尺寸):`L120→1920x1080@30`、`L123→1080p60`、`L153→3840x2160@60`、`L183/L186→8192x4096@60`
|
||||
- codec string → `'<profile_idc>:<level>'`(`hvc1.2.4.L183` → `2:183`);`hvc1`/`hev1` 同键,因为差的只是 sample entry
|
||||
- **只有 `supported === false` 才降级**;`supported:true, smooth:false` 只记录不行动(太贴边,而且看门狗已经兜底)
|
||||
- 钩子在 bundle 执行时**同步**装上(此时还没有 verdict,一律交给原生),探测结果落地后才生效
|
||||
- 逃生开关:`localStorage['jfvr-cpt'] = 'off'` → 完全不装钩子
|
||||
|
||||
三种模式本地实测(`_harness-codec.html`,全过):
|
||||
|
||||
| 模式 | 结果 |
|
||||
|---|---|
|
||||
| `pc` | 8K Main10 被拦 → Jellyfin 封顶 level 153 → 8K 文件超出声明 → **转码** |
|
||||
| `quest` | 无一被拦 → 声明保持 ≥183 → **Direct Play 不变** |
|
||||
| `off` | 钩子未安装,`canPlayType` 完全未动 → 恢复旧行为 |
|
||||
|
||||
### 18.8 待办
|
||||
|
||||
- [ ] 探测目前只覆盖 HEVC。AV1 / VP9 走同一套机制,但库里没有这类片源,先不做。
|
||||
- [ ] `decodingInfo` 的 `smooth` 现在是只记录不行动。如果哪天出现「supported:true 但实际掉帧」的案例,可以考虑把 `smooth === false` 也纳入降级条件(风险:可能误伤 Quest)。
|
||||
|
||||
@@ -54,6 +54,80 @@ python3 pack.py --bump --publish # 构建 → 打包 → 建 Release → 推 m
|
||||
> 老路子仍然可用,作为插件的兜底:`JF_PW=... python3 deploy.py`。
|
||||
> 但**两者不要同时开** —— 装了插件就别再跑 `deploy.py`(跑完插件也会把那个标签清掉)。
|
||||
|
||||
### 1.2 播放看门狗(卡住检测)
|
||||
|
||||
`src/40-watchdog.js`。针对一种很坑的失败:**某些设备/浏览器放不出来时,Jellyfin 的播放器界面根本不会被创建**。
|
||||
|
||||
原因(已从 Jellyfin Web 源码确认):播放器 UI 只在 `playbackstart` 事件之后构建,而 `playbackstart` 要等媒体真的起来了才会触发。加载顺序是:
|
||||
|
||||
```
|
||||
HtmlVideoPlayer.play() htmlVideoPlayer/plugin.js:502
|
||||
createMediaElement() :1802 转圈 + <div.videoPlayerContainer> + <video>
|
||||
(此时还没 src)
|
||||
setCurrentSrc() :593 elem.src = url
|
||||
→ loadedmetadata → canplay → play → 'playbackstart'
|
||||
→ OSD 控制器(apps/legacy/controllers/playback/video/index.js:591)
|
||||
```
|
||||
|
||||
媒体起不来 → `playbackstart` 不触发 → **码率菜单根本不存在**,页面上只剩一个转圈和一个 `videoWidth === 0` 的 `<video>`。所以「卡住之后调不了码率」不是菜单藏起来了,是菜单还没被创建。
|
||||
|
||||
看门狗就盯这个状态(`.videoPlayerContainer` 里的 `<video>` 仍然是 `videoWidth === 0`):
|
||||
|
||||
| | 阈值 |
|
||||
|---|---|
|
||||
| 媒体报错(`video.error`) | 立即弹 |
|
||||
| 直连没画面 | 15 秒 |
|
||||
| 转码(src 已经是 hls) | 45 秒(服务器要先出片) |
|
||||
| 已经有画面 | 立即退出,不打扰 |
|
||||
| VR 会话中 | 完全不跑 |
|
||||
|
||||
弹窗会写明**具体格式**(走 Jellyfin API 查 MediaStreams),并给 20/8/3 Mbps 三档 + 「继续等待」。选一档后写入 Jellyfin 自己那套 localStorage 键然后重载:
|
||||
|
||||
```
|
||||
maxbitrate-Video-<true|false> = 20000000
|
||||
enableautobitratebitrate-Video-<true|false> = false
|
||||
```
|
||||
|
||||
> 注意 `enableautobitratebitrate` 里 `bitrate` 确实出现了两次 —— 这是 Jellyfin 上游的拼写,照抄的。
|
||||
> 之所以不用 `playbackManager.setMaxStreamingBitrate()`:那个模块没暴露到 window(已实测 `window.playbackManager === undefined`,`window.Emby` 只剩 `Page`),所以只能写设置 + 重载。
|
||||
|
||||
选过之后 120 秒内不再打扰(记在 sessionStorage)。
|
||||
|
||||
### 1.3 让客户端如实上报解码能力(`canPlayType` 覆盖)
|
||||
|
||||
`src/00-core.js`。解决的问题:**Jellyfin 的直连/转码决策 100% 看客户端上报的设备档案**,而 Jellyfin Web 是从 `canPlayType` 推出整个 HEVC 声明的(`browserDeviceProfile.js`):
|
||||
|
||||
```js
|
||||
if (canPlayType('video/mp4; codecs="hvc1.2.4.L183"')) {
|
||||
maxHevcLevel = 183; // level 6.1 = 8K
|
||||
hevcProfiles = 'main|main 10';
|
||||
}
|
||||
```
|
||||
|
||||
`canPlayType` 回答的是「这台机器*有没有* HEVC 解码器」,不是「能不能解 8192×4096 的 Main 10 @60fps」。所以一个只是「系统里有 HEVC 解码器」的桌面浏览器会声称支持 8K Main 10 → 服务器选 DirectPlay → 黑屏(而 OSD 压根不会创建,见 §1.2)。
|
||||
|
||||
插件的做法:
|
||||
|
||||
1. 页面加载时用 **`MediaCapabilities.decodingInfo`** 对 HEVC 各档做真机探测(每档在它对应的分辨率上测:L120→1080p30、L153→4K60、L183/L186→8K60,因为 level 字符串本身不带尺寸);
|
||||
2. 把结果回灌给 `HTMLVideoElement.prototype.canPlayType`:只有 `supported === false` 才返回 `''`,其余全部交给原生实现。
|
||||
|
||||
这样 Jellyfin Web 自己那套 `maxHevcLevel` 逻辑就会得出**准确**档案:
|
||||
|
||||
| 设备 | 结果 |
|
||||
|---|---|
|
||||
| 桌面(声称支持但实际解不动 8K Main 10) | 降到 level 153 → 8K 文件超出声明 → **服务器转码** |
|
||||
| Quest 3(真能解 8K Main 10) | 保持 ≥183 → **继续 Direct Play** |
|
||||
|
||||
**故意保守**:只有 `supported === false` 才降级。`supported:true, smooth:false` 会记录但不影响行为 —— 太贴边了,而且「声称能播结果没播出来」已经有 §1.2 的看门狗兜底。
|
||||
|
||||
出问题的逃生开关(某台设备报得离谱时用):
|
||||
|
||||
```js
|
||||
localStorage['jfvr-cpt'] = 'off'; // 然后刷新,覆盖完全不安装
|
||||
```
|
||||
|
||||
当前状态可以在诊断面板里看到(`canPlayType hook` 和 `HEVC real (decodingInfo)` 两段)。这也是 Meta 官方文档推荐的做法 —— 他们明确说「用 Media Capabilities API 探测,不要靠 UA 嗅探」。
|
||||
|
||||
---
|
||||
|
||||
## 2. Quest 3 实测数据(已用 ADB + CDP 在真机验证)
|
||||
@@ -75,10 +149,14 @@ UA Mozilla/5.0 (X11; Linux x86_64; Quest 3) ... Chrome/152 ... VR Safari/537.36
|
||||
| `XRWebGLBinding` | — | true ← 回退路径可用 |
|
||||
| `MAX_TEXTURE_SIZE` | 8192 | 8192 |
|
||||
| `MAX_RENDERBUFFER_SIZE` | 16384 | 16384 |
|
||||
| 8K HEVC `decodingInfo` | supported / powerEfficient | **supported:true, powerEfficient:true** |
|
||||
| 8K HEVC `decodingInfo` | supported / powerEfficient | **supported:true, powerEfficient:true**(仅 8-bit Main) |
|
||||
|
||||
结论:**HTTPS 下 Quest 浏览器提供全部所需 WebXR 能力,8K HEVC 走硬件解码。**
|
||||
|
||||
> ⚠️ 上面那行 `decodingInfo` 当年只测了 **8-bit Main** 的 codec string(`hev1.1.6.L183.B0`),
|
||||
> **10-bit Main 10(`hev1.2.4.L183.B0`)从来没测过**。插件现在会分档探测(见 §1.3),
|
||||
> 诊断面板里会列出 Main/Main10 × 4K/8K 的真实结果。
|
||||
|
||||
### 2.1 网络实测:HTTPS 域名在 Quest 上就是内网直连
|
||||
|
||||
```
|
||||
|
||||
@@ -21,7 +21,7 @@ SRC = os.path.join(HERE, "src")
|
||||
DIST = os.path.join(HERE, "dist")
|
||||
OUT = os.path.join(DIST, "jfvr.js")
|
||||
|
||||
ORDER = ["00-core.js", "10-subtitles.js", "20-controls.js", "30-hands.js", "90-main.js"]
|
||||
ORDER = ["00-core.js", "10-subtitles.js", "20-controls.js", "30-hands.js", "40-watchdog.js", "90-main.js"]
|
||||
|
||||
|
||||
def sources():
|
||||
|
||||
Vendored
+528
-5
@@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* JFVR (Jellyfin Web VR) — built bundle. DO NOT EDIT.
|
||||
* Edit src/*.js and run: python3 build.py
|
||||
* Modules: 00-core.js, 10-subtitles.js, 20-controls.js, 30-hands.js, 90-main.js
|
||||
* Modules: 00-core.js, 10-subtitles.js, 20-controls.js, 30-hands.js, 40-watchdog.js, 90-main.js
|
||||
*/
|
||||
|
||||
/* ===== 00-core.js ===== */
|
||||
@@ -315,9 +315,81 @@
|
||||
hasGetJointPose: typeof window.XRFrame !== 'undefined' && typeof XRFrame.prototype.getJointPose === 'function',
|
||||
maxTextureSize: null,
|
||||
hevc: {},
|
||||
decoding8k: null
|
||||
decoding8k: null,
|
||||
|
||||
/* MediaCapabilities verdicts, keyed '<profile_idc>:<level>'. See below. */
|
||||
codec: {},
|
||||
codecBlocked: [],
|
||||
cptPatched: false,
|
||||
cptMode: null
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* codec capability: what this browser will ACTUALLY decode
|
||||
* ------------------------------------------------------------------
|
||||
* Two layers.
|
||||
*
|
||||
* 1. NS.caps.hevc -- raw canPlayType() answers, for the diagnostics panel.
|
||||
* This used to only ask about Main profile (8-bit), which is why the
|
||||
* project's notes said "8K HEVC: supported" right up until a Main 10
|
||||
* (10-bit) file showed up and could not be decoded at all. The Main 10
|
||||
* strings are the ones that actually matter for 8K VR here.
|
||||
*
|
||||
* 2. NS.caps.codec + the canPlayType override -- makes Jellyfin Web build
|
||||
* an ACCURATE device profile.
|
||||
*
|
||||
* Why the override: Jellyfin Web derives its entire HEVC claim from
|
||||
* canPlayType (src/scripts/browserDeviceProfile.js):
|
||||
*
|
||||
* let maxHevcLevel = 120, hevcProfiles = 'main';
|
||||
* ...
|
||||
* if (canPlayType('video/mp4; codecs="hvc1.2.4.L183"')) {
|
||||
* maxHevcLevel = 183; // level 6.1 = 8K
|
||||
* hevcProfiles = 'main|main 10';
|
||||
* }
|
||||
*
|
||||
* canPlayType answers "does this system have an HEVC decoder", not "can it
|
||||
* do 8192x4096 Main 10 at 60 fps". So a desktop browser that merely ships an
|
||||
* HEVC decoder claims 8K Main 10, the server picks DirectPlay, and playback
|
||||
* dies on a black screen with no player UI (the OSD is only built after
|
||||
* 'playbackstart'). decodingInfo asks the actual decoder, so feeding its
|
||||
* verdict back through canPlayType lets Jellyfin's own logic land on the
|
||||
* right profile: the desktop drops to whatever it can really do and the
|
||||
* server transcodes, while a Quest that genuinely decodes 8K Main 10 keeps
|
||||
* DirectPlay. Meta's browser-video docs recommend exactly this API over UA
|
||||
* sniffing.
|
||||
*
|
||||
* Only `supported === false` downgrades. `supported:true, smooth:false` is
|
||||
* recorded but does not change behaviour: it is too close to the edge to act
|
||||
* on, and 40-watchdog.js already covers "it claimed to work and did not".
|
||||
*
|
||||
* Kill switch if a device reports nonsense:
|
||||
* localStorage['jfvr-cpt'] = 'off' then reload
|
||||
*/
|
||||
|
||||
// decodingInfo needs real dimensions; a level string does not carry them, so
|
||||
// each level is probed at the resolution it exists for.
|
||||
var CODEC_PROBES = [
|
||||
{ key: '1:120', name: 'Main L4.0', w: 1920, h: 1080, fps: 30, codec: 'hvc1.1.L120' },
|
||||
{ key: '1:123', name: 'Main L4.1', w: 1920, h: 1080, fps: 60, codec: 'hvc1.1.4.L123' },
|
||||
{ key: '1:183', name: 'Main L6.1 (8K)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.1.6.L183.B0' },
|
||||
{ key: '2:123', name: 'Main10 L4.1', w: 1920, h: 1080, fps: 60, codec: 'hvc1.2.4.L123' },
|
||||
{ key: '2:153', name: 'Main10 L5.1 (4K)', w: 3840, h: 2160, fps: 60, codec: 'hvc1.2.4.L153' },
|
||||
{ key: '2:183', name: 'Main10 L6.1 (8K)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.2.4.L183' },
|
||||
{ key: '2:186', name: 'Main10 L6.2 (8K60)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.2.4.L186' }
|
||||
];
|
||||
|
||||
/**
|
||||
* 'video/mp4; codecs="hvc1.2.4.L183.B0"' -> '2:183' (profile_idc : level).
|
||||
* Both the hvc1 and hev1 spellings map to the same key: they differ in the
|
||||
* sample entry, not in what has to be decoded.
|
||||
*/
|
||||
function hevcKey(type) {
|
||||
var m = /(?:hvc1|hev1)\.([0-9]+)(?:\.[0-9]+)?\.l([0-9]+)/i.exec(String(type || ''));
|
||||
return m ? m[1] + ':' + m[2] : null;
|
||||
}
|
||||
NS.caps.hevcKey = hevcKey;
|
||||
|
||||
(function probe() {
|
||||
try {
|
||||
var mb = window.XRMediaBinding;
|
||||
@@ -331,12 +403,17 @@
|
||||
if (gl) NS.caps.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
||||
} catch (e) {}
|
||||
try {
|
||||
['video/mp4; codecs="hev1.1.6.L183.B0"',
|
||||
var ve = document.createElement('video');
|
||||
['video/mp4; codecs="hev1.1.6.L183.B0"', // Main 8-bit 8K (the files that work)
|
||||
'video/mp4; codecs="hvc1.1.6.L183.B0"',
|
||||
'video/mp4; codecs="hev1.2.4.L183.B0"', // Main 10 8K (the files that do not)
|
||||
'video/mp4; codecs="hvc1.2.4.L183.B0"',
|
||||
'video/mp4; codecs="hev1.2.4.L153.B0"', // Main 10 4K
|
||||
'video/mp4; codecs="hvc1.2.4.L153.B0"',
|
||||
'video/mp4; codecs="hev1"',
|
||||
'video/mp4; codecs="hvc1"'].forEach(function (cs) {
|
||||
NS.caps.hevc[cs] = (typeof MediaSource !== 'undefined' && MediaSource.isTypeSupported(cs)) ||
|
||||
document.createElement('video').canPlayType(cs) || 'no';
|
||||
ve.canPlayType(cs) || 'no';
|
||||
});
|
||||
} catch (e) {}
|
||||
if (navigator.xr && navigator.xr.isSessionSupported) {
|
||||
@@ -346,8 +423,85 @@
|
||||
}
|
||||
})();
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* MediaCapabilities probe + canPlayType override
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
function applyVerdicts() {
|
||||
NS.caps.codecBlocked = CODEC_PROBES.filter(function (p) {
|
||||
var v = NS.caps.codec[p.key];
|
||||
return v && v.supported === false;
|
||||
}).map(function (p) { return p.name; });
|
||||
}
|
||||
|
||||
function installCanPlayTypeOverride() {
|
||||
if (NS.caps.cptMode === 'off') return;
|
||||
var proto = window.HTMLVideoElement && window.HTMLVideoElement.prototype;
|
||||
if (!proto || typeof proto.canPlayType !== 'function') return;
|
||||
|
||||
var orig = proto.canPlayType;
|
||||
proto.canPlayType = function (type) {
|
||||
try {
|
||||
var key = hevcKey(type);
|
||||
var v = key && NS.caps.codec[key];
|
||||
// Only a definite "no" is acted on. Anything else is the browser's call.
|
||||
if (v && v.supported === false) return '';
|
||||
} catch (e) { /* never break the native answer */ }
|
||||
return orig.apply(this, arguments);
|
||||
};
|
||||
NS.caps.cptPatched = true;
|
||||
NS.caps.cptMode = 'on';
|
||||
}
|
||||
|
||||
(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) {}
|
||||
var mc = navigator.mediaCapabilities;
|
||||
if (!mc || typeof mc.decodingInfo !== 'function') { NS.caps.cptMode = 'no-api'; return; }
|
||||
|
||||
// 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();
|
||||
|
||||
var pending = CODEC_PROBES.length;
|
||||
CODEC_PROBES.forEach(function (p) {
|
||||
var cfg = {
|
||||
type: 'file',
|
||||
video: {
|
||||
contentType: 'video/mp4; codecs="' + p.codec + '"',
|
||||
width: p.w, height: p.h, bitrate: 20000000, framerate: p.fps
|
||||
}
|
||||
};
|
||||
mc.decodingInfo(cfg).then(function (info) {
|
||||
NS.caps.codec[p.key] = {
|
||||
name: p.name, workload: p.w + 'x' + p.h + '@' + p.fps,
|
||||
supported: info.supported, smooth: info.smooth, powerEfficient: info.powerEfficient
|
||||
};
|
||||
}).catch(function (e) {
|
||||
NS.caps.codec[p.key] = { name: p.name, error: String(e && e.message || e) };
|
||||
}).then(function () {
|
||||
if (--pending === 0) {
|
||||
applyVerdicts();
|
||||
NS.log('codec probe done; blocked = ' + (NS.caps.codecBlocked.join(', ') || 'none'));
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
NS.capsDiag = function () {
|
||||
var c = NS.caps;
|
||||
var real = CODEC_PROBES.map(function (p) {
|
||||
var v = c.codec[p.key];
|
||||
if (!v) return ' ' + p.name.padEnd(20) + ' (pending)';
|
||||
if (v.error) return ' ' + p.name.padEnd(20) + ' error: ' + v.error;
|
||||
return ' ' + p.name.padEnd(20) + ' supported=' + v.supported +
|
||||
' smooth=' + v.smooth + ' powerEfficient=' + v.powerEfficient +
|
||||
' [' + v.workload + ']' + (v.supported === false ? ' <-- BLOCKED' : '');
|
||||
}).join('\n');
|
||||
|
||||
return [
|
||||
'origin : ' + location.origin,
|
||||
'secureContext : ' + c.secureContext,
|
||||
@@ -357,7 +511,11 @@
|
||||
'createQuadLayer : ' + c.hasQuadLayer,
|
||||
'hand tracking API : ' + c.hasHandTracking + ' / jointSpace=' + c.hasXRJointSpace + ' / getJointPose=' + c.hasGetJointPose,
|
||||
'MAX_TEXTURE_SIZE : ' + c.maxTextureSize,
|
||||
'HEVC : ' + JSON.stringify(c.hevc)
|
||||
'HEVC canPlayType : ' + JSON.stringify(c.hevc),
|
||||
'canPlayType hook : ' + (c.cptMode || 'pending') +
|
||||
(c.cptMode === 'on' ? ' (downgraded: ' + (c.codecBlocked.join(', ') || 'nothing yet') + ')' : ''),
|
||||
'HEVC real (decodingInfo):',
|
||||
real
|
||||
].join('\n');
|
||||
};
|
||||
})();
|
||||
@@ -4396,6 +4554,368 @@
|
||||
|
||||
|
||||
|
||||
/* ===== 40-watchdog.js ===== */
|
||||
|
||||
/*!
|
||||
* JFVR watchdog — "this video never started" detection.
|
||||
*
|
||||
* WHY THIS EXISTS
|
||||
* ---------------
|
||||
* Jellyfin Web builds the whole player UI (including the quality menu) only
|
||||
* after the 'playbackstart' event, which the media element fires once it has
|
||||
* actually started. The load order is:
|
||||
*
|
||||
* HtmlVideoPlayer.play() htmlVideoPlayer/plugin.js:502
|
||||
* createMediaElement() :1802 -> loading.show() spinner
|
||||
* -> <div.videoPlayerContainer><video>
|
||||
* -> inserted into document.body
|
||||
* (no src yet!)
|
||||
* setCurrentSrc() :593 -> elem.src = url, only now
|
||||
* -> loadedmetadata -> canplay -> play
|
||||
* -> 'playbackstart'
|
||||
* -> OSD controller (apps/legacy/controllers/playback/video/index.js:591)
|
||||
*
|
||||
* So when the browser cannot use the stream, the OSD never appears at all: the
|
||||
* page is a spinner over an empty container with a <video> whose videoWidth is
|
||||
* still 0. There is no quality menu to click, because it was never created.
|
||||
*
|
||||
* That is the case this module covers. It watches for exactly that state and
|
||||
* offers the only thing that can help: tell Jellyfin to transcode.
|
||||
*
|
||||
* WHY localStorage AND NOT THE PLAYBACK MANAGER
|
||||
* --------------------------------------------
|
||||
* The bitrate is normally set through playbackManager.setMaxStreamingBitrate(),
|
||||
* which does a live changeStream(). That manager is an ES module export and is
|
||||
* NOT on window (verified: window.playbackManager is undefined; window.Emby only
|
||||
* has Page). So the watchdog writes the same keys appSettings would have written
|
||||
* (src/scripts/settings/appSettings.js) and reloads, which makes Jellyfin request
|
||||
* PlaybackInfo again with the new cap and pick Transcode.
|
||||
*
|
||||
* NOTE the key name really does say "bitrate" twice — that is upstream's typo,
|
||||
* reproduced here deliberately.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var NS = window.__JFVR;
|
||||
if (!NS) { console.error('[JFVR] core missing'); return; }
|
||||
if (NS.__watchdog) return;
|
||||
NS.__watchdog = true;
|
||||
|
||||
var S = NS.state;
|
||||
var log = NS.log;
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* tunables
|
||||
* ------------------------------------------------------------------ */
|
||||
var POLL_MS = 500;
|
||||
|
||||
// Direct play on a LAN should have metadata almost immediately; the file is
|
||||
// 11 GB but its moov atom is at the front, so there is nothing to wait for.
|
||||
// A transcode is different: the server has to decode the first GOP and produce
|
||||
// segments before the browser sees any metadata, and this NAS is doing 8K.
|
||||
var DEAD_MS = 15000;
|
||||
var DEAD_TRANSCODE_MS = 45000;
|
||||
|
||||
// After the user answers (either way) stay quiet, so a slow-but-working
|
||||
// playback does not get nagged at.
|
||||
var QUIET_MS = 120000;
|
||||
|
||||
var QUIET_KEY = 'jfvr-watchdog-quiet-until';
|
||||
|
||||
// Values from Jellyfin's own menu (src/components/qualityOptions.js).
|
||||
var CHOICES = [
|
||||
{ label: '20 Mbps', bitrate: 20000000, note: '≈4K,最接近原始画质' },
|
||||
{ label: '8 Mbps', bitrate: 8000000, note: '1080p 档,稳' },
|
||||
{ label: '3 Mbps', bitrate: 3000000, note: '720p 档,最省算力' }
|
||||
];
|
||||
|
||||
var W = {
|
||||
seenAt: 0, // when the current stalled <video> first showed up
|
||||
shown: false,
|
||||
quietUntil: 0,
|
||||
lastReason: '',
|
||||
applied: null,
|
||||
codec: null, // filled in best-effort from the Jellyfin API
|
||||
panel: null
|
||||
};
|
||||
NS.Watchdog = W;
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* helpers
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
function now() { return Date.now(); }
|
||||
|
||||
/**
|
||||
* The element Jellyfin creates in createMediaElement(). It exists from the
|
||||
* very start of playback — including the failure case, which is the whole
|
||||
* point: findVideo() in 90-main.js requires videoWidth and would return null.
|
||||
*/
|
||||
function playerVideo() {
|
||||
var c = document.querySelector('.videoPlayerContainer');
|
||||
if (!c) return null;
|
||||
return c.querySelector('video') || null;
|
||||
}
|
||||
|
||||
function isTranscode(v) {
|
||||
var src = v.currentSrc || v.src || '';
|
||||
return src.indexOf('/hls') >= 0 || src.indexOf('.m3u8') >= 0;
|
||||
}
|
||||
|
||||
/** Metadata parsed AND a frame available. False means "no picture". */
|
||||
function hasPicture(v) {
|
||||
return v.videoWidth > 0 && v.readyState >= 2;
|
||||
}
|
||||
|
||||
function readQuiet() {
|
||||
try {
|
||||
var raw = window.sessionStorage && sessionStorage.getItem(QUIET_KEY);
|
||||
return raw ? parseInt(raw, 10) || 0 : 0;
|
||||
} catch (e) { return 0; }
|
||||
}
|
||||
|
||||
function setQuiet(ms) {
|
||||
W.quietUntil = now() + ms;
|
||||
try { sessionStorage.setItem(QUIET_KEY, String(W.quietUntil)); } catch (e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the same keys Jellyfin's own quality menu writes, for BOTH in-network
|
||||
* and out-of-network, because the client is the only side that knows which one
|
||||
* applies and we cannot ask it (appSettings is not on window).
|
||||
*/
|
||||
function applyBitrate(bitrate) {
|
||||
var media = 'Video';
|
||||
['true', 'false'].forEach(function (inNet) {
|
||||
try {
|
||||
localStorage.setItem('enableautobitratebitrate-' + media + '-' + inNet, 'false');
|
||||
localStorage.setItem('maxbitrate-' + media + '-' + inNet, String(bitrate));
|
||||
} catch (e) {
|
||||
log('watchdog: could not persist bitrate', e && e.message);
|
||||
}
|
||||
});
|
||||
W.applied = bitrate;
|
||||
log('watchdog: capped bitrate at', bitrate, 'and reloading');
|
||||
setQuiet(QUIET_MS);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* best-effort: name the actual format so the message is actionable
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
function itemIdFrom(v) {
|
||||
var s = (v && (v.currentSrc || v.src)) || '';
|
||||
var m = s.match(/\/Videos\/([0-9a-f]{32})\//i);
|
||||
if (m) return m[1];
|
||||
m = (window.location.hash || '').match(/[?&]id=([0-9a-f]{32})/i);
|
||||
return m ? m[1] : null;
|
||||
}
|
||||
|
||||
function describeCodec(v) {
|
||||
if (W.codec) return;
|
||||
var id = itemIdFrom(v);
|
||||
if (!id || !window.ApiClient) return;
|
||||
var url;
|
||||
try { url = window.ApiClient.getUrl('Items/' + id); } catch (e) { return; }
|
||||
window.ApiClient.ajax({ type: 'GET', url: url, dataType: 'json' }).then(function (item) {
|
||||
var ms = (item && item.MediaSources && item.MediaSources[0] && item.MediaSources[0].MediaStreams) || [];
|
||||
for (var i = 0; i < ms.length; i++) {
|
||||
var st = ms[i];
|
||||
if (st.Type !== 'Video') continue;
|
||||
W.codec = [
|
||||
st.Width + '×' + st.Height,
|
||||
(st.Codec || '').toUpperCase(),
|
||||
st.Profile || '',
|
||||
st.BitDepth ? st.BitDepth + '-bit' : ''
|
||||
].filter(Boolean).join(' ');
|
||||
break;
|
||||
}
|
||||
if (W.shown) render(); // update the message in place
|
||||
}).catch(function () { /* the prompt works fine without this */ });
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* the prompt
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
var WD_CSS = [
|
||||
'.jfvr-wd{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);z-index:2147483002;width:420px;max-width:calc(100vw - 32px);',
|
||||
'background:rgba(18,18,22,.97);color:#eaeaea;border:1px solid rgba(255,255,255,.16);border-radius:14px;',
|
||||
'box-shadow:0 18px 60px rgba(0,0,0,.7);font-family:inherit;font-size:14px;padding:18px 18px 14px;backdrop-filter:blur(10px)}',
|
||||
'.jfvr-wd h3{margin:0 0 6px;font-size:16px;font-weight:600}',
|
||||
'.jfvr-wd p{margin:0 0 10px;font-size:13px;line-height:1.6;color:#c3c9d4}',
|
||||
'.jfvr-wd .jfvr-wd-fmt{color:#ffd479;font-weight:600}',
|
||||
'.jfvr-wd .jfvr-wd-sub{font-size:12px;color:#8b93a1;line-height:1.55;margin-bottom:12px}',
|
||||
'.jfvr-wd-btns{display:flex;flex-direction:column;gap:8px;margin-bottom:10px}',
|
||||
'.jfvr-wd-btns button{display:flex;justify-content:space-between;align-items:baseline;gap:10px;width:100%;padding:10px 12px;',
|
||||
'border:1px solid rgba(255,255,255,.16);border-radius:9px;background:rgba(255,255,255,.05);color:#eaeaea;',
|
||||
'font-size:14px;font-weight:600;cursor:pointer;font-family:inherit;text-align:left}',
|
||||
'.jfvr-wd-btns button:hover{background:rgba(78,161,255,.18);border-color:#4ea1ff}',
|
||||
'.jfvr-wd-btns button span.note{font-size:11px;font-weight:400;color:#8b93a1}',
|
||||
'.jfvr-wd-quiet{width:100%;padding:9px;border:0;border-radius:9px;background:transparent;color:#8b93a1;',
|
||||
'font-size:13px;cursor:pointer;font-family:inherit}',
|
||||
'.jfvr-wd-quiet:hover{color:#eaeaea}',
|
||||
'.jfvr-wd-diag{margin-top:10px;font-size:11px;color:#8b93a1}',
|
||||
'.jfvr-wd-diag summary{cursor:pointer;user-select:none}',
|
||||
'.jfvr-wd-diag pre{white-space:pre-wrap;word-break:break-all;margin:8px 0 0;font-size:10px;line-height:1.5;',
|
||||
'max-height:150px;overflow:auto;color:#9fb0c4;background:rgba(0,0,0,.35);padding:8px;border-radius:7px}'
|
||||
].join('');
|
||||
|
||||
function injectWdCss() {
|
||||
if (document.getElementById('jfvr-wd-css')) return;
|
||||
var s = NS.makeEl('style');
|
||||
s.id = 'jfvr-wd-css';
|
||||
s.textContent = WD_CSS;
|
||||
document.head.appendChild(s);
|
||||
}
|
||||
|
||||
function diagText(v) {
|
||||
var e = v.error;
|
||||
return [
|
||||
'readyState : ' + v.readyState + ' (0=HAVE_NOTHING, 1=HAVE_METADATA, 2=HAVE_CURRENT_DATA)',
|
||||
'networkState: ' + v.networkState,
|
||||
'videoWidth : ' + v.videoWidth + '×' + v.videoHeight,
|
||||
'paused : ' + v.paused,
|
||||
'currentTime : ' + v.currentTime,
|
||||
'error : ' + (e ? e.code + ' ' + (e.message || '') : 'none'),
|
||||
'src : ' + String(v.currentSrc || v.src || '').slice(0, 160),
|
||||
'格式 : ' + (W.codec || '(未知)')
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (!W.panel) return;
|
||||
var body = W.panel.querySelector('.jfvr-wd-body');
|
||||
var v = playerVideo();
|
||||
if (body && v) {
|
||||
var fmt = body.querySelector('.jfvr-wd-fmt');
|
||||
if (fmt) fmt.textContent = W.codec || '这个格式';
|
||||
var pre = body.querySelector('pre');
|
||||
if (pre) pre.textContent = diagText(v);
|
||||
}
|
||||
}
|
||||
|
||||
function show(v, reason) {
|
||||
if (W.shown) { render(); return; }
|
||||
W.shown = true;
|
||||
W.lastReason = reason;
|
||||
injectWdCss();
|
||||
|
||||
var p = NS.makeEl('div', 'jfvr-wd');
|
||||
p.id = 'jfvr-wd';
|
||||
p.appendChild(NS.makeEl('h3', null, '视频没能开始播放'));
|
||||
|
||||
var body = NS.makeEl('div', 'jfvr-wd-body');
|
||||
|
||||
var msg = NS.makeEl('p');
|
||||
var waited = Math.round(timeoutMs(v) / 1000);
|
||||
msg.innerHTML =
|
||||
(reason === 'error'
|
||||
? '播放器报错了,一个画面都没解出来。'
|
||||
: '等了 ' + waited + ' 秒都没拿到任何画面(<code>videoWidth = 0</code>),' +
|
||||
'所以播放器界面也没有被创建出来。') +
|
||||
'最常见的原因是<strong>这台设备解不动这个格式</strong>:' +
|
||||
'<span class="jfvr-wd-fmt">' + (W.codec || '该格式') + '</span>。<br>' +
|
||||
'让服务器转码成 H.264 再播就能看到画面,代价是画质下降(这台 NAS 的转码上限约 4K)。';
|
||||
body.appendChild(msg);
|
||||
|
||||
body.appendChild(NS.makeEl('div', 'jfvr-wd-sub',
|
||||
'选一档码率后会写入播放设置并重新加载页面。'));
|
||||
|
||||
var btns = NS.makeEl('div', 'jfvr-wd-btns');
|
||||
CHOICES.forEach(function (c) {
|
||||
var b = NS.makeEl('button');
|
||||
b.type = 'button';
|
||||
b.appendChild(NS.makeEl('span', null, c.label));
|
||||
b.appendChild(NS.makeEl('span', 'note', c.note));
|
||||
b.addEventListener('click', function (ev) {
|
||||
ev.stopPropagation();
|
||||
applyBitrate(c.bitrate);
|
||||
});
|
||||
btns.appendChild(b);
|
||||
});
|
||||
body.appendChild(btns);
|
||||
|
||||
var quiet = NS.makeEl('button', 'jfvr-wd-quiet', '继续等待,先别管我');
|
||||
quiet.type = 'button';
|
||||
quiet.addEventListener('click', function (ev) {
|
||||
ev.stopPropagation();
|
||||
setQuiet(QUIET_MS);
|
||||
hide();
|
||||
});
|
||||
body.appendChild(quiet);
|
||||
|
||||
var diag = NS.makeEl('details', 'jfvr-wd-diag');
|
||||
diag.appendChild(NS.makeEl('summary', null, '诊断信息'));
|
||||
diag.appendChild(NS.makeEl('pre', null, diagText(v)));
|
||||
body.appendChild(diag);
|
||||
|
||||
p.appendChild(body);
|
||||
document.body.appendChild(p);
|
||||
W.panel = p;
|
||||
|
||||
NS.recordError('watchdog', new Error('playback never started: ' + reason));
|
||||
log('watchdog: playback never started, reason =', reason, 'codec =', W.codec);
|
||||
}
|
||||
|
||||
function hide() {
|
||||
W.shown = false;
|
||||
if (W.panel) { W.panel.remove(); W.panel = null; }
|
||||
}
|
||||
|
||||
function reset() {
|
||||
W.seenAt = 0;
|
||||
W.codec = null;
|
||||
if (W.shown) hide();
|
||||
}
|
||||
|
||||
function timeoutMs(v) {
|
||||
return isTranscode(v) ? DEAD_TRANSCODE_MS : DEAD_MS;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* poll
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
function poll() {
|
||||
// Never interfere with an active VR session: the session owns the flow and
|
||||
// a modal in the middle of it would be a disaster.
|
||||
if (S.session) { if (W.shown) hide(); return; }
|
||||
|
||||
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);
|
||||
if (W.quietUntil && now() < W.quietUntil) return;
|
||||
show(v, 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!W.seenAt) W.seenAt = now();
|
||||
if (now() - W.seenAt < timeoutMs(v)) return;
|
||||
|
||||
if (W.quietUntil && now() < W.quietUntil) return;
|
||||
|
||||
describeCodec(v);
|
||||
show(v, 'timeout');
|
||||
}
|
||||
|
||||
NS.Watchdog.init = function () {
|
||||
W.quietUntil = readQuiet();
|
||||
setInterval(poll, POLL_MS);
|
||||
log('watchdog armed (dead=' + DEAD_MS + 'ms, transcode=' + DEAD_TRANSCODE_MS + 'ms)');
|
||||
};
|
||||
})();
|
||||
|
||||
|
||||
|
||||
/* ===== 90-main.js ===== */
|
||||
|
||||
/*!
|
||||
@@ -6343,6 +6863,9 @@
|
||||
try { if (NS.Subtitles && NS.Subtitles.init) NS.Subtitles.init(); } catch (e) { NS.recordError('Subtitles.init', e); }
|
||||
try { if (NS.Controls && NS.Controls.init) NS.Controls.init(); } catch (e) { NS.recordError('Controls.init', e); }
|
||||
try { if (NS.Hands && NS.Hands.init) NS.Hands.init(); } catch (e) { NS.recordError('Hands.init', e); }
|
||||
// Watches for "the player never produced a picture" and offers the only fix
|
||||
// that helps (let the server transcode). See 40-watchdog.js.
|
||||
try { if (NS.Watchdog && NS.Watchdog.init) NS.Watchdog.init(); } catch (e) { NS.recordError('Watchdog.init', e); }
|
||||
|
||||
scan();
|
||||
new MutationObserver(scan).observe(document.documentElement, { childList: true, subtree: true });
|
||||
|
||||
+26
-2
@@ -7,13 +7,37 @@
|
||||
"owner": "cat-shark",
|
||||
"category": "General",
|
||||
"versions": [
|
||||
{
|
||||
"version": "0.3.0.0",
|
||||
"targetAbi": "12.0.0.0",
|
||||
"changelog": "Bundle version: `4e9a8f`\n\nFirst plugin build. The web bundle is embedded in the DLL and served from /JFVR/jfvr.js; index.html is rewritten at request time, so nothing is written to the jellyfin-web folder on disk.",
|
||||
"sourceUrl": "https://git.cat-shark.xyz/cat-shark/jellyfin_vr_web_plugin/releases/download/v0.3.0.0/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||
"checksum": "1BFAF246451C090E351F9DDD516BD4DC",
|
||||
"timestamp": "2026-10-17T17:08:08"
|
||||
},
|
||||
{
|
||||
"version": "0.2.0.0",
|
||||
"targetAbi": "12.0.0.0",
|
||||
"changelog": "Bundle version: `edca47`\n\nFirst plugin build. The web bundle is embedded in the DLL and served from /JFVR/jfvr.js; index.html is rewritten at request time, so nothing is written to the jellyfin-web folder on disk.",
|
||||
"sourceUrl": "https://git.cat-shark.xyz/cat-shark/jellyfin_vr_web_plugin/releases/download/v0.2.0.0/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||
"checksum": "355DD18DC228A6586334431518C4B60D",
|
||||
"timestamp": "2026-10-17T16:28:23"
|
||||
},
|
||||
{
|
||||
"version": "0.1.0.1",
|
||||
"targetAbi": "12.0.0.0",
|
||||
"changelog": "Bundle version: `917fde`\n\nFirst plugin build. The web bundle is embedded in the DLL and served from /JFVR/jfvr.js; index.html is rewritten at request time, so nothing is written to the jellyfin-web folder on disk.",
|
||||
"sourceUrl": "https://git.cat-shark.xyz/cat-shark/jellyfin_vr_web_plugin/releases/download/v0.1.0.1/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||
"checksum": "5BB9DA51A50C5449E7C1D0D6602E8813",
|
||||
"timestamp": "2026-10-17T15:33:14"
|
||||
},
|
||||
{
|
||||
"version": "0.1.0.0",
|
||||
"targetAbi": "12.0.0.0",
|
||||
"changelog": "Bundle version: `917fde`\n\nFirst plugin build. The web bundle is embedded in the DLL and served from /JFVR/jfvr.js; index.html is rewritten at request time, so nothing is written to the jellyfin-web folder on disk.",
|
||||
"sourceUrl": "https://git.cat-shark.xyz/cat-shark/jellyfin_vr_web_plugin/releases/download/v0.1.0.0/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||
"checksum": "66B0A065AF32A07C7D71DD1B9073EE76",
|
||||
"timestamp": "2026-10-16T00:05:11"
|
||||
"checksum": "F9CC1843F0B9386A9E990669112FF533",
|
||||
"timestamp": "2026-10-17T15:25:41"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -240,6 +240,24 @@ def head_ok(url):
|
||||
return e.code, None
|
||||
|
||||
|
||||
def fetch_md5(url):
|
||||
"""Download the published asset and hash it -- exactly what Jellyfin does.
|
||||
|
||||
This is the check that catches a manifest whose checksum no longer matches the
|
||||
uploaded zip (a real failure mode: the install then dies with
|
||||
"The checksum of the received data doesn't match.").
|
||||
"""
|
||||
h = hashlib.md5()
|
||||
req = urllib.request.Request(url, method="GET")
|
||||
with urllib.request.urlopen(req, timeout=300) as resp:
|
||||
while True:
|
||||
chunk = resp.read(1 << 20)
|
||||
if not chunk:
|
||||
break
|
||||
h.update(chunk)
|
||||
return h.hexdigest().upper()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- steps
|
||||
|
||||
|
||||
@@ -275,11 +293,25 @@ def verify_embedded(dll):
|
||||
|
||||
|
||||
def make_zip(dll, target_abi):
|
||||
"""Package the DLL the way Jellyfin expects: one file, named after the assembly.
|
||||
|
||||
The entry gets a fixed timestamp on purpose. zip stores mtimes, so packaging
|
||||
the same DLL twice would otherwise produce different bytes, a different MD5,
|
||||
and a manifest checksum that no longer matches the already-uploaded asset.
|
||||
"""
|
||||
os.makedirs(OUT_DIR, exist_ok=True)
|
||||
asset = "%s_%s.zip" % (ASSEMBLY, target_abi)
|
||||
path = os.path.join(OUT_DIR, asset)
|
||||
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
zf.write(dll, ASSEMBLY + ".dll")
|
||||
|
||||
info = zipfile.ZipInfo(ASSEMBLY + ".dll", date_time=(1980, 1, 1, 0, 0, 0))
|
||||
info.compress_type = zipfile.ZIP_DEFLATED
|
||||
info.external_attr = 0o644 << 16
|
||||
|
||||
with open(dll, "rb") as fh:
|
||||
payload = fh.read()
|
||||
with zipfile.ZipFile(path, "w") as zf:
|
||||
zf.writestr(info, payload)
|
||||
|
||||
print("packaged %s (%d bytes)" % (path, os.path.getsize(path)))
|
||||
return path, asset
|
||||
|
||||
@@ -383,6 +415,13 @@ def main():
|
||||
if status != 200:
|
||||
sys.exit("the asset is not downloadable -- is the release a draft?")
|
||||
|
||||
# What Jellyfin will do at install time: download it and compare MD5.
|
||||
live = fetch_md5(entry["sourceUrl"])
|
||||
if live != checksum:
|
||||
sys.exit("published asset md5 %s != manifest checksum %s -- install would fail"
|
||||
% (live, checksum))
|
||||
print("asset md5 matches the manifest checksum (%s)" % live)
|
||||
|
||||
if not args.no_push:
|
||||
run(["git", "add", "manifest.json", "plugin/build.yaml"], cwd=HERE)
|
||||
dirty = subprocess.run(
|
||||
|
||||
@@ -38,6 +38,7 @@ public sealed class ScriptInjectionStartupFilter : IStartupFilter
|
||||
private readonly BundleProvider _bundle;
|
||||
private readonly ILogger<ScriptInjectionStartupFilter> _logger;
|
||||
private int _loggedOnce;
|
||||
private int _legacyLoggedOnce;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScriptInjectionStartupFilter"/> class.
|
||||
@@ -158,9 +159,15 @@ public sealed class ScriptInjectionStartupFilter : IStartupFilter
|
||||
|
||||
var rewritten = IndexHtmlRewriter.Rewrite(html, scriptUrl, out var removedLegacy);
|
||||
|
||||
if (removedLegacy)
|
||||
if (removedLegacy && Interlocked.Exchange(ref _legacyLoggedOnce, 1) == 0)
|
||||
{
|
||||
_logger.LogInformation("JFVR: removed the legacy deploy.py <script> tag from index.html.");
|
||||
// Logged once, not per request: the legacy tag lives in the on-disk
|
||||
// index.html, so it is stripped from every single response until the
|
||||
// file itself is cleaned up (deploy.py rollback) or deploy.py is run
|
||||
// again. Per-request logging would just fill the log with the same line.
|
||||
_logger.LogInformation(
|
||||
"JFVR: stripping the legacy deploy.py <script> tag from index.html. "
|
||||
+ "It is still present on disk; run 'python3 deploy.py rollback' to clean it up.");
|
||||
}
|
||||
|
||||
if (IndexHtmlRewriter.IsInjected(html) || rewritten == html)
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@
|
||||
# (InstallationManager.GetAvailablePackages), so one package covers all of 12.x.
|
||||
name: "Jellyfin Web VR"
|
||||
guid: "7d33ef59-f9b0-412b-93bd-5cd5353018de"
|
||||
version: "0.1.0.0"
|
||||
version: "0.3.0.0"
|
||||
targetAbi: "12.0.0.0"
|
||||
framework: "net10.0"
|
||||
overview: "VR180/VR360 playback inside Jellyfin Web for Meta Quest 3."
|
||||
|
||||
+162
-4
@@ -307,9 +307,81 @@
|
||||
hasGetJointPose: typeof window.XRFrame !== 'undefined' && typeof XRFrame.prototype.getJointPose === 'function',
|
||||
maxTextureSize: null,
|
||||
hevc: {},
|
||||
decoding8k: null
|
||||
decoding8k: null,
|
||||
|
||||
/* MediaCapabilities verdicts, keyed '<profile_idc>:<level>'. See below. */
|
||||
codec: {},
|
||||
codecBlocked: [],
|
||||
cptPatched: false,
|
||||
cptMode: null
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* codec capability: what this browser will ACTUALLY decode
|
||||
* ------------------------------------------------------------------
|
||||
* Two layers.
|
||||
*
|
||||
* 1. NS.caps.hevc -- raw canPlayType() answers, for the diagnostics panel.
|
||||
* This used to only ask about Main profile (8-bit), which is why the
|
||||
* project's notes said "8K HEVC: supported" right up until a Main 10
|
||||
* (10-bit) file showed up and could not be decoded at all. The Main 10
|
||||
* strings are the ones that actually matter for 8K VR here.
|
||||
*
|
||||
* 2. NS.caps.codec + the canPlayType override -- makes Jellyfin Web build
|
||||
* an ACCURATE device profile.
|
||||
*
|
||||
* Why the override: Jellyfin Web derives its entire HEVC claim from
|
||||
* canPlayType (src/scripts/browserDeviceProfile.js):
|
||||
*
|
||||
* let maxHevcLevel = 120, hevcProfiles = 'main';
|
||||
* ...
|
||||
* if (canPlayType('video/mp4; codecs="hvc1.2.4.L183"')) {
|
||||
* maxHevcLevel = 183; // level 6.1 = 8K
|
||||
* hevcProfiles = 'main|main 10';
|
||||
* }
|
||||
*
|
||||
* canPlayType answers "does this system have an HEVC decoder", not "can it
|
||||
* do 8192x4096 Main 10 at 60 fps". So a desktop browser that merely ships an
|
||||
* HEVC decoder claims 8K Main 10, the server picks DirectPlay, and playback
|
||||
* dies on a black screen with no player UI (the OSD is only built after
|
||||
* 'playbackstart'). decodingInfo asks the actual decoder, so feeding its
|
||||
* verdict back through canPlayType lets Jellyfin's own logic land on the
|
||||
* right profile: the desktop drops to whatever it can really do and the
|
||||
* server transcodes, while a Quest that genuinely decodes 8K Main 10 keeps
|
||||
* DirectPlay. Meta's browser-video docs recommend exactly this API over UA
|
||||
* sniffing.
|
||||
*
|
||||
* Only `supported === false` downgrades. `supported:true, smooth:false` is
|
||||
* recorded but does not change behaviour: it is too close to the edge to act
|
||||
* on, and 40-watchdog.js already covers "it claimed to work and did not".
|
||||
*
|
||||
* Kill switch if a device reports nonsense:
|
||||
* localStorage['jfvr-cpt'] = 'off' then reload
|
||||
*/
|
||||
|
||||
// decodingInfo needs real dimensions; a level string does not carry them, so
|
||||
// each level is probed at the resolution it exists for.
|
||||
var CODEC_PROBES = [
|
||||
{ key: '1:120', name: 'Main L4.0', w: 1920, h: 1080, fps: 30, codec: 'hvc1.1.L120' },
|
||||
{ key: '1:123', name: 'Main L4.1', w: 1920, h: 1080, fps: 60, codec: 'hvc1.1.4.L123' },
|
||||
{ key: '1:183', name: 'Main L6.1 (8K)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.1.6.L183.B0' },
|
||||
{ key: '2:123', name: 'Main10 L4.1', w: 1920, h: 1080, fps: 60, codec: 'hvc1.2.4.L123' },
|
||||
{ key: '2:153', name: 'Main10 L5.1 (4K)', w: 3840, h: 2160, fps: 60, codec: 'hvc1.2.4.L153' },
|
||||
{ key: '2:183', name: 'Main10 L6.1 (8K)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.2.4.L183' },
|
||||
{ key: '2:186', name: 'Main10 L6.2 (8K60)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.2.4.L186' }
|
||||
];
|
||||
|
||||
/**
|
||||
* 'video/mp4; codecs="hvc1.2.4.L183.B0"' -> '2:183' (profile_idc : level).
|
||||
* Both the hvc1 and hev1 spellings map to the same key: they differ in the
|
||||
* sample entry, not in what has to be decoded.
|
||||
*/
|
||||
function hevcKey(type) {
|
||||
var m = /(?:hvc1|hev1)\.([0-9]+)(?:\.[0-9]+)?\.l([0-9]+)/i.exec(String(type || ''));
|
||||
return m ? m[1] + ':' + m[2] : null;
|
||||
}
|
||||
NS.caps.hevcKey = hevcKey;
|
||||
|
||||
(function probe() {
|
||||
try {
|
||||
var mb = window.XRMediaBinding;
|
||||
@@ -323,12 +395,17 @@
|
||||
if (gl) NS.caps.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
|
||||
} catch (e) {}
|
||||
try {
|
||||
['video/mp4; codecs="hev1.1.6.L183.B0"',
|
||||
var ve = document.createElement('video');
|
||||
['video/mp4; codecs="hev1.1.6.L183.B0"', // Main 8-bit 8K (the files that work)
|
||||
'video/mp4; codecs="hvc1.1.6.L183.B0"',
|
||||
'video/mp4; codecs="hev1.2.4.L183.B0"', // Main 10 8K (the files that do not)
|
||||
'video/mp4; codecs="hvc1.2.4.L183.B0"',
|
||||
'video/mp4; codecs="hev1.2.4.L153.B0"', // Main 10 4K
|
||||
'video/mp4; codecs="hvc1.2.4.L153.B0"',
|
||||
'video/mp4; codecs="hev1"',
|
||||
'video/mp4; codecs="hvc1"'].forEach(function (cs) {
|
||||
NS.caps.hevc[cs] = (typeof MediaSource !== 'undefined' && MediaSource.isTypeSupported(cs)) ||
|
||||
document.createElement('video').canPlayType(cs) || 'no';
|
||||
ve.canPlayType(cs) || 'no';
|
||||
});
|
||||
} catch (e) {}
|
||||
if (navigator.xr && navigator.xr.isSessionSupported) {
|
||||
@@ -338,8 +415,85 @@
|
||||
}
|
||||
})();
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* MediaCapabilities probe + canPlayType override
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
function applyVerdicts() {
|
||||
NS.caps.codecBlocked = CODEC_PROBES.filter(function (p) {
|
||||
var v = NS.caps.codec[p.key];
|
||||
return v && v.supported === false;
|
||||
}).map(function (p) { return p.name; });
|
||||
}
|
||||
|
||||
function installCanPlayTypeOverride() {
|
||||
if (NS.caps.cptMode === 'off') return;
|
||||
var proto = window.HTMLVideoElement && window.HTMLVideoElement.prototype;
|
||||
if (!proto || typeof proto.canPlayType !== 'function') return;
|
||||
|
||||
var orig = proto.canPlayType;
|
||||
proto.canPlayType = function (type) {
|
||||
try {
|
||||
var key = hevcKey(type);
|
||||
var v = key && NS.caps.codec[key];
|
||||
// Only a definite "no" is acted on. Anything else is the browser's call.
|
||||
if (v && v.supported === false) return '';
|
||||
} catch (e) { /* never break the native answer */ }
|
||||
return orig.apply(this, arguments);
|
||||
};
|
||||
NS.caps.cptPatched = true;
|
||||
NS.caps.cptMode = 'on';
|
||||
}
|
||||
|
||||
(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) {}
|
||||
var mc = navigator.mediaCapabilities;
|
||||
if (!mc || typeof mc.decodingInfo !== 'function') { NS.caps.cptMode = 'no-api'; return; }
|
||||
|
||||
// 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();
|
||||
|
||||
var pending = CODEC_PROBES.length;
|
||||
CODEC_PROBES.forEach(function (p) {
|
||||
var cfg = {
|
||||
type: 'file',
|
||||
video: {
|
||||
contentType: 'video/mp4; codecs="' + p.codec + '"',
|
||||
width: p.w, height: p.h, bitrate: 20000000, framerate: p.fps
|
||||
}
|
||||
};
|
||||
mc.decodingInfo(cfg).then(function (info) {
|
||||
NS.caps.codec[p.key] = {
|
||||
name: p.name, workload: p.w + 'x' + p.h + '@' + p.fps,
|
||||
supported: info.supported, smooth: info.smooth, powerEfficient: info.powerEfficient
|
||||
};
|
||||
}).catch(function (e) {
|
||||
NS.caps.codec[p.key] = { name: p.name, error: String(e && e.message || e) };
|
||||
}).then(function () {
|
||||
if (--pending === 0) {
|
||||
applyVerdicts();
|
||||
NS.log('codec probe done; blocked = ' + (NS.caps.codecBlocked.join(', ') || 'none'));
|
||||
}
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
NS.capsDiag = function () {
|
||||
var c = NS.caps;
|
||||
var real = CODEC_PROBES.map(function (p) {
|
||||
var v = c.codec[p.key];
|
||||
if (!v) return ' ' + p.name.padEnd(20) + ' (pending)';
|
||||
if (v.error) return ' ' + p.name.padEnd(20) + ' error: ' + v.error;
|
||||
return ' ' + p.name.padEnd(20) + ' supported=' + v.supported +
|
||||
' smooth=' + v.smooth + ' powerEfficient=' + v.powerEfficient +
|
||||
' [' + v.workload + ']' + (v.supported === false ? ' <-- BLOCKED' : '');
|
||||
}).join('\n');
|
||||
|
||||
return [
|
||||
'origin : ' + location.origin,
|
||||
'secureContext : ' + c.secureContext,
|
||||
@@ -349,7 +503,11 @@
|
||||
'createQuadLayer : ' + c.hasQuadLayer,
|
||||
'hand tracking API : ' + c.hasHandTracking + ' / jointSpace=' + c.hasXRJointSpace + ' / getJointPose=' + c.hasGetJointPose,
|
||||
'MAX_TEXTURE_SIZE : ' + c.maxTextureSize,
|
||||
'HEVC : ' + JSON.stringify(c.hevc)
|
||||
'HEVC canPlayType : ' + JSON.stringify(c.hevc),
|
||||
'canPlayType hook : ' + (c.cptMode || 'pending') +
|
||||
(c.cptMode === 'on' ? ' (downgraded: ' + (c.codecBlocked.join(', ') || 'nothing yet') + ')' : ''),
|
||||
'HEVC real (decodingInfo):',
|
||||
real
|
||||
].join('\n');
|
||||
};
|
||||
})();
|
||||
|
||||
@@ -0,0 +1,357 @@
|
||||
/*!
|
||||
* JFVR watchdog — "this video never started" detection.
|
||||
*
|
||||
* WHY THIS EXISTS
|
||||
* ---------------
|
||||
* Jellyfin Web builds the whole player UI (including the quality menu) only
|
||||
* after the 'playbackstart' event, which the media element fires once it has
|
||||
* actually started. The load order is:
|
||||
*
|
||||
* HtmlVideoPlayer.play() htmlVideoPlayer/plugin.js:502
|
||||
* createMediaElement() :1802 -> loading.show() spinner
|
||||
* -> <div.videoPlayerContainer><video>
|
||||
* -> inserted into document.body
|
||||
* (no src yet!)
|
||||
* setCurrentSrc() :593 -> elem.src = url, only now
|
||||
* -> loadedmetadata -> canplay -> play
|
||||
* -> 'playbackstart'
|
||||
* -> OSD controller (apps/legacy/controllers/playback/video/index.js:591)
|
||||
*
|
||||
* So when the browser cannot use the stream, the OSD never appears at all: the
|
||||
* page is a spinner over an empty container with a <video> whose videoWidth is
|
||||
* still 0. There is no quality menu to click, because it was never created.
|
||||
*
|
||||
* That is the case this module covers. It watches for exactly that state and
|
||||
* offers the only thing that can help: tell Jellyfin to transcode.
|
||||
*
|
||||
* WHY localStorage AND NOT THE PLAYBACK MANAGER
|
||||
* --------------------------------------------
|
||||
* The bitrate is normally set through playbackManager.setMaxStreamingBitrate(),
|
||||
* which does a live changeStream(). That manager is an ES module export and is
|
||||
* NOT on window (verified: window.playbackManager is undefined; window.Emby only
|
||||
* has Page). So the watchdog writes the same keys appSettings would have written
|
||||
* (src/scripts/settings/appSettings.js) and reloads, which makes Jellyfin request
|
||||
* PlaybackInfo again with the new cap and pick Transcode.
|
||||
*
|
||||
* NOTE the key name really does say "bitrate" twice — that is upstream's typo,
|
||||
* reproduced here deliberately.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var NS = window.__JFVR;
|
||||
if (!NS) { console.error('[JFVR] core missing'); return; }
|
||||
if (NS.__watchdog) return;
|
||||
NS.__watchdog = true;
|
||||
|
||||
var S = NS.state;
|
||||
var log = NS.log;
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* tunables
|
||||
* ------------------------------------------------------------------ */
|
||||
var POLL_MS = 500;
|
||||
|
||||
// Direct play on a LAN should have metadata almost immediately; the file is
|
||||
// 11 GB but its moov atom is at the front, so there is nothing to wait for.
|
||||
// A transcode is different: the server has to decode the first GOP and produce
|
||||
// segments before the browser sees any metadata, and this NAS is doing 8K.
|
||||
var DEAD_MS = 15000;
|
||||
var DEAD_TRANSCODE_MS = 45000;
|
||||
|
||||
// After the user answers (either way) stay quiet, so a slow-but-working
|
||||
// playback does not get nagged at.
|
||||
var QUIET_MS = 120000;
|
||||
|
||||
var QUIET_KEY = 'jfvr-watchdog-quiet-until';
|
||||
|
||||
// Values from Jellyfin's own menu (src/components/qualityOptions.js).
|
||||
var CHOICES = [
|
||||
{ label: '20 Mbps', bitrate: 20000000, note: '≈4K,最接近原始画质' },
|
||||
{ label: '8 Mbps', bitrate: 8000000, note: '1080p 档,稳' },
|
||||
{ label: '3 Mbps', bitrate: 3000000, note: '720p 档,最省算力' }
|
||||
];
|
||||
|
||||
var W = {
|
||||
seenAt: 0, // when the current stalled <video> first showed up
|
||||
shown: false,
|
||||
quietUntil: 0,
|
||||
lastReason: '',
|
||||
applied: null,
|
||||
codec: null, // filled in best-effort from the Jellyfin API
|
||||
panel: null
|
||||
};
|
||||
NS.Watchdog = W;
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* helpers
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
function now() { return Date.now(); }
|
||||
|
||||
/**
|
||||
* The element Jellyfin creates in createMediaElement(). It exists from the
|
||||
* very start of playback — including the failure case, which is the whole
|
||||
* point: findVideo() in 90-main.js requires videoWidth and would return null.
|
||||
*/
|
||||
function playerVideo() {
|
||||
var c = document.querySelector('.videoPlayerContainer');
|
||||
if (!c) return null;
|
||||
return c.querySelector('video') || null;
|
||||
}
|
||||
|
||||
function isTranscode(v) {
|
||||
var src = v.currentSrc || v.src || '';
|
||||
return src.indexOf('/hls') >= 0 || src.indexOf('.m3u8') >= 0;
|
||||
}
|
||||
|
||||
/** Metadata parsed AND a frame available. False means "no picture". */
|
||||
function hasPicture(v) {
|
||||
return v.videoWidth > 0 && v.readyState >= 2;
|
||||
}
|
||||
|
||||
function readQuiet() {
|
||||
try {
|
||||
var raw = window.sessionStorage && sessionStorage.getItem(QUIET_KEY);
|
||||
return raw ? parseInt(raw, 10) || 0 : 0;
|
||||
} catch (e) { return 0; }
|
||||
}
|
||||
|
||||
function setQuiet(ms) {
|
||||
W.quietUntil = now() + ms;
|
||||
try { sessionStorage.setItem(QUIET_KEY, String(W.quietUntil)); } catch (e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the same keys Jellyfin's own quality menu writes, for BOTH in-network
|
||||
* and out-of-network, because the client is the only side that knows which one
|
||||
* applies and we cannot ask it (appSettings is not on window).
|
||||
*/
|
||||
function applyBitrate(bitrate) {
|
||||
var media = 'Video';
|
||||
['true', 'false'].forEach(function (inNet) {
|
||||
try {
|
||||
localStorage.setItem('enableautobitratebitrate-' + media + '-' + inNet, 'false');
|
||||
localStorage.setItem('maxbitrate-' + media + '-' + inNet, String(bitrate));
|
||||
} catch (e) {
|
||||
log('watchdog: could not persist bitrate', e && e.message);
|
||||
}
|
||||
});
|
||||
W.applied = bitrate;
|
||||
log('watchdog: capped bitrate at', bitrate, 'and reloading');
|
||||
setQuiet(QUIET_MS);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* best-effort: name the actual format so the message is actionable
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
function itemIdFrom(v) {
|
||||
var s = (v && (v.currentSrc || v.src)) || '';
|
||||
var m = s.match(/\/Videos\/([0-9a-f]{32})\//i);
|
||||
if (m) return m[1];
|
||||
m = (window.location.hash || '').match(/[?&]id=([0-9a-f]{32})/i);
|
||||
return m ? m[1] : null;
|
||||
}
|
||||
|
||||
function describeCodec(v) {
|
||||
if (W.codec) return;
|
||||
var id = itemIdFrom(v);
|
||||
if (!id || !window.ApiClient) return;
|
||||
var url;
|
||||
try { url = window.ApiClient.getUrl('Items/' + id); } catch (e) { return; }
|
||||
window.ApiClient.ajax({ type: 'GET', url: url, dataType: 'json' }).then(function (item) {
|
||||
var ms = (item && item.MediaSources && item.MediaSources[0] && item.MediaSources[0].MediaStreams) || [];
|
||||
for (var i = 0; i < ms.length; i++) {
|
||||
var st = ms[i];
|
||||
if (st.Type !== 'Video') continue;
|
||||
W.codec = [
|
||||
st.Width + '×' + st.Height,
|
||||
(st.Codec || '').toUpperCase(),
|
||||
st.Profile || '',
|
||||
st.BitDepth ? st.BitDepth + '-bit' : ''
|
||||
].filter(Boolean).join(' ');
|
||||
break;
|
||||
}
|
||||
if (W.shown) render(); // update the message in place
|
||||
}).catch(function () { /* the prompt works fine without this */ });
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* the prompt
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
var WD_CSS = [
|
||||
'.jfvr-wd{position:fixed;left:50%;top:50%;transform:translate(-50%,-50%);z-index:2147483002;width:420px;max-width:calc(100vw - 32px);',
|
||||
'background:rgba(18,18,22,.97);color:#eaeaea;border:1px solid rgba(255,255,255,.16);border-radius:14px;',
|
||||
'box-shadow:0 18px 60px rgba(0,0,0,.7);font-family:inherit;font-size:14px;padding:18px 18px 14px;backdrop-filter:blur(10px)}',
|
||||
'.jfvr-wd h3{margin:0 0 6px;font-size:16px;font-weight:600}',
|
||||
'.jfvr-wd p{margin:0 0 10px;font-size:13px;line-height:1.6;color:#c3c9d4}',
|
||||
'.jfvr-wd .jfvr-wd-fmt{color:#ffd479;font-weight:600}',
|
||||
'.jfvr-wd .jfvr-wd-sub{font-size:12px;color:#8b93a1;line-height:1.55;margin-bottom:12px}',
|
||||
'.jfvr-wd-btns{display:flex;flex-direction:column;gap:8px;margin-bottom:10px}',
|
||||
'.jfvr-wd-btns button{display:flex;justify-content:space-between;align-items:baseline;gap:10px;width:100%;padding:10px 12px;',
|
||||
'border:1px solid rgba(255,255,255,.16);border-radius:9px;background:rgba(255,255,255,.05);color:#eaeaea;',
|
||||
'font-size:14px;font-weight:600;cursor:pointer;font-family:inherit;text-align:left}',
|
||||
'.jfvr-wd-btns button:hover{background:rgba(78,161,255,.18);border-color:#4ea1ff}',
|
||||
'.jfvr-wd-btns button span.note{font-size:11px;font-weight:400;color:#8b93a1}',
|
||||
'.jfvr-wd-quiet{width:100%;padding:9px;border:0;border-radius:9px;background:transparent;color:#8b93a1;',
|
||||
'font-size:13px;cursor:pointer;font-family:inherit}',
|
||||
'.jfvr-wd-quiet:hover{color:#eaeaea}',
|
||||
'.jfvr-wd-diag{margin-top:10px;font-size:11px;color:#8b93a1}',
|
||||
'.jfvr-wd-diag summary{cursor:pointer;user-select:none}',
|
||||
'.jfvr-wd-diag pre{white-space:pre-wrap;word-break:break-all;margin:8px 0 0;font-size:10px;line-height:1.5;',
|
||||
'max-height:150px;overflow:auto;color:#9fb0c4;background:rgba(0,0,0,.35);padding:8px;border-radius:7px}'
|
||||
].join('');
|
||||
|
||||
function injectWdCss() {
|
||||
if (document.getElementById('jfvr-wd-css')) return;
|
||||
var s = NS.makeEl('style');
|
||||
s.id = 'jfvr-wd-css';
|
||||
s.textContent = WD_CSS;
|
||||
document.head.appendChild(s);
|
||||
}
|
||||
|
||||
function diagText(v) {
|
||||
var e = v.error;
|
||||
return [
|
||||
'readyState : ' + v.readyState + ' (0=HAVE_NOTHING, 1=HAVE_METADATA, 2=HAVE_CURRENT_DATA)',
|
||||
'networkState: ' + v.networkState,
|
||||
'videoWidth : ' + v.videoWidth + '×' + v.videoHeight,
|
||||
'paused : ' + v.paused,
|
||||
'currentTime : ' + v.currentTime,
|
||||
'error : ' + (e ? e.code + ' ' + (e.message || '') : 'none'),
|
||||
'src : ' + String(v.currentSrc || v.src || '').slice(0, 160),
|
||||
'格式 : ' + (W.codec || '(未知)')
|
||||
].join('\n');
|
||||
}
|
||||
|
||||
function render() {
|
||||
if (!W.panel) return;
|
||||
var body = W.panel.querySelector('.jfvr-wd-body');
|
||||
var v = playerVideo();
|
||||
if (body && v) {
|
||||
var fmt = body.querySelector('.jfvr-wd-fmt');
|
||||
if (fmt) fmt.textContent = W.codec || '这个格式';
|
||||
var pre = body.querySelector('pre');
|
||||
if (pre) pre.textContent = diagText(v);
|
||||
}
|
||||
}
|
||||
|
||||
function show(v, reason) {
|
||||
if (W.shown) { render(); return; }
|
||||
W.shown = true;
|
||||
W.lastReason = reason;
|
||||
injectWdCss();
|
||||
|
||||
var p = NS.makeEl('div', 'jfvr-wd');
|
||||
p.id = 'jfvr-wd';
|
||||
p.appendChild(NS.makeEl('h3', null, '视频没能开始播放'));
|
||||
|
||||
var body = NS.makeEl('div', 'jfvr-wd-body');
|
||||
|
||||
var msg = NS.makeEl('p');
|
||||
var waited = Math.round(timeoutMs(v) / 1000);
|
||||
msg.innerHTML =
|
||||
(reason === 'error'
|
||||
? '播放器报错了,一个画面都没解出来。'
|
||||
: '等了 ' + waited + ' 秒都没拿到任何画面(<code>videoWidth = 0</code>),' +
|
||||
'所以播放器界面也没有被创建出来。') +
|
||||
'最常见的原因是<strong>这台设备解不动这个格式</strong>:' +
|
||||
'<span class="jfvr-wd-fmt">' + (W.codec || '该格式') + '</span>。<br>' +
|
||||
'让服务器转码成 H.264 再播就能看到画面,代价是画质下降(这台 NAS 的转码上限约 4K)。';
|
||||
body.appendChild(msg);
|
||||
|
||||
body.appendChild(NS.makeEl('div', 'jfvr-wd-sub',
|
||||
'选一档码率后会写入播放设置并重新加载页面。'));
|
||||
|
||||
var btns = NS.makeEl('div', 'jfvr-wd-btns');
|
||||
CHOICES.forEach(function (c) {
|
||||
var b = NS.makeEl('button');
|
||||
b.type = 'button';
|
||||
b.appendChild(NS.makeEl('span', null, c.label));
|
||||
b.appendChild(NS.makeEl('span', 'note', c.note));
|
||||
b.addEventListener('click', function (ev) {
|
||||
ev.stopPropagation();
|
||||
applyBitrate(c.bitrate);
|
||||
});
|
||||
btns.appendChild(b);
|
||||
});
|
||||
body.appendChild(btns);
|
||||
|
||||
var quiet = NS.makeEl('button', 'jfvr-wd-quiet', '继续等待,先别管我');
|
||||
quiet.type = 'button';
|
||||
quiet.addEventListener('click', function (ev) {
|
||||
ev.stopPropagation();
|
||||
setQuiet(QUIET_MS);
|
||||
hide();
|
||||
});
|
||||
body.appendChild(quiet);
|
||||
|
||||
var diag = NS.makeEl('details', 'jfvr-wd-diag');
|
||||
diag.appendChild(NS.makeEl('summary', null, '诊断信息'));
|
||||
diag.appendChild(NS.makeEl('pre', null, diagText(v)));
|
||||
body.appendChild(diag);
|
||||
|
||||
p.appendChild(body);
|
||||
document.body.appendChild(p);
|
||||
W.panel = p;
|
||||
|
||||
NS.recordError('watchdog', new Error('playback never started: ' + reason));
|
||||
log('watchdog: playback never started, reason =', reason, 'codec =', W.codec);
|
||||
}
|
||||
|
||||
function hide() {
|
||||
W.shown = false;
|
||||
if (W.panel) { W.panel.remove(); W.panel = null; }
|
||||
}
|
||||
|
||||
function reset() {
|
||||
W.seenAt = 0;
|
||||
W.codec = null;
|
||||
if (W.shown) hide();
|
||||
}
|
||||
|
||||
function timeoutMs(v) {
|
||||
return isTranscode(v) ? DEAD_TRANSCODE_MS : DEAD_MS;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ *
|
||||
* poll
|
||||
* ------------------------------------------------------------------ */
|
||||
|
||||
function poll() {
|
||||
// Never interfere with an active VR session: the session owns the flow and
|
||||
// a modal in the middle of it would be a disaster.
|
||||
if (S.session) { if (W.shown) hide(); return; }
|
||||
|
||||
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);
|
||||
if (W.quietUntil && now() < W.quietUntil) return;
|
||||
show(v, 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!W.seenAt) W.seenAt = now();
|
||||
if (now() - W.seenAt < timeoutMs(v)) return;
|
||||
|
||||
if (W.quietUntil && now() < W.quietUntil) return;
|
||||
|
||||
describeCodec(v);
|
||||
show(v, 'timeout');
|
||||
}
|
||||
|
||||
NS.Watchdog.init = function () {
|
||||
W.quietUntil = readQuiet();
|
||||
setInterval(poll, POLL_MS);
|
||||
log('watchdog armed (dead=' + DEAD_MS + 'ms, transcode=' + DEAD_TRANSCODE_MS + 'ms)');
|
||||
};
|
||||
})();
|
||||
@@ -1943,6 +1943,9 @@
|
||||
try { if (NS.Subtitles && NS.Subtitles.init) NS.Subtitles.init(); } catch (e) { NS.recordError('Subtitles.init', e); }
|
||||
try { if (NS.Controls && NS.Controls.init) NS.Controls.init(); } catch (e) { NS.recordError('Controls.init', e); }
|
||||
try { if (NS.Hands && NS.Hands.init) NS.Hands.init(); } catch (e) { NS.recordError('Hands.init', e); }
|
||||
// Watches for "the player never produced a picture" and offers the only fix
|
||||
// that helps (let the server transcode). See 40-watchdog.js.
|
||||
try { if (NS.Watchdog && NS.Watchdog.init) NS.Watchdog.init(); } catch (e) { NS.recordError('Watchdog.init', e); }
|
||||
|
||||
scan();
|
||||
new MutationObserver(scan).observe(document.documentElement, { childList: true, subtree: true });
|
||||
|
||||
Reference in New Issue
Block a user