Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7b097a344 | ||
|
|
4f82de9ffa | ||
|
|
d6734e505c | ||
|
|
d20482d5dd | ||
|
|
cf731c16c2 | ||
|
|
03919dab98 | ||
|
|
beba1e66f0 | ||
|
|
0270cd1bc1 | ||
|
|
08cbef83a3 | ||
|
|
c25e40070a | ||
|
|
0bf0a1f1da | ||
|
|
1176c2009c | ||
|
|
30f97808ae |
+129
-11
@@ -890,28 +890,146 @@ enableautobitratebitrate-Video-<true|false> = false ← 上游拼写,bitra
|
|||||||
1. **续播点 33:22.759 的来历**:就是 2026-10-05 那次转码会话留下的(`stopped ... at 2002759ms`)。所以 10-17 两次播放都从 33:22 续播,画面出不来进度自然不动,于是「停在 33:22」重复了两次。
|
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`),是盗版站打包进来的。
|
2. **文件本身没问题**:完全分配无空洞(`du` 实际用量 == 表观大小)、`moov` 在文件头(faststart 正常)、33:22 处 ffmpeg 解码无报错、Jellyfin 数据库里时长正确(50:58)。同目录还有 3 个垃圾广告文件(`.url` × 3 + 一个 20 MB 的 `三 上 悠 亚…mp4`),是盗版站打包进来的。
|
||||||
|
|
||||||
### 18.7 已做(插件 0.3.0.0 / bundle `4e9a8f`)
|
### 18.7 已做(插件 0.5.0.0 / bundle `72681d`)
|
||||||
|
|
||||||
- [x] `src/00-core.js` 的能力探测补上 Main 10 和 8K/4K 分档;新增 `NS.caps.codec`(`decodingInfo` 逐档结果)与 `NS.capsDiag()` 里的 `HEVC real` 段
|
- [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
|
- [x] **彻底自动化**:用 `MediaCapabilities.decodingInfo` 真机探测后覆盖 `HTMLVideoElement.prototype.canPlayType`,让 Jellyfin Web 自己那套 `maxHevcLevel` 逻辑算出准确 profile
|
||||||
|
- [x] **补上「实时吞吐」这一维**(`smooth`)—— 见下
|
||||||
|
|
||||||
覆盖逻辑的关键点:
|
覆盖逻辑的关键点:
|
||||||
|
|
||||||
- 每档在**它对应的分辨率**上探测(level 字符串不带尺寸):`L120→1920x1080@30`、`L123→1080p60`、`L153→3840x2160@60`、`L183/L186→8192x4096@60`
|
- 每档在**它对应的分辨率和码率**上探测(level 字符串不带尺寸):`L120→1920x1080@30/8Mbps`、`L123→1080p60/8Mbps`、`L153→3840x2160@60/20Mbps`、`L183/L186→8192x4096@60/30Mbps`
|
||||||
- codec string → `'<profile_idc>:<level>'`(`hvc1.2.4.L183` → `2:183`);`hvc1`/`hev1` 同键,因为差的只是 sample entry
|
- codec string → `'<profile_idc>:<level>'`(`hvc1.2.4.L183` → `2:183`);`hvc1`/`hev1` 同键,因为差的只是 sample entry
|
||||||
- **只有 `supported === false` 才降级**;`supported:true, smooth:false` 只记录不行动(太贴边,而且看门狗已经兜底)
|
- **拦掉一档的两个条件**:`supported === false`(完全解不了)或 **`smooth === false`**(能解但跟不上)。只有 `powerEfficient:false`(纯软解)本身不拦
|
||||||
- 钩子在 bundle 执行时**同步**装上(此时还没有 verdict,一律交给原生),探测结果落地后才生效
|
- 钩子在 bundle 执行时**同步**装上(此时还没有 verdict,一律交给原生),探测结果落地后才生效
|
||||||
- 逃生开关:`localStorage['jfvr-cpt'] = 'off'` → 完全不装钩子
|
- 逃生开关:`localStorage['jfvr-cpt'] = 'off'` 完全关掉;`localStorage['jfvr-cpt-keep'] = '2:183'` 只保留某一档(单台设备误报时用)
|
||||||
|
|
||||||
三种模式本地实测(`_harness-codec.html`,全过):
|
### 18.7.1 为什么最后把 `smooth` 加上了(重要)
|
||||||
|
|
||||||
| 模式 | 结果 |
|
0.3.0.0 只看了 `supported`,当时故意不动 `smooth`,理由是怕误伤 Quest。但那样会漏掉**最现实的那种桌面场景**:
|
||||||
|---|---|
|
|
||||||
| `pc` | 8K Main10 被拦 → Jellyfin 封顶 level 153 → 8K 文件超出声明 → **转码** |
|
> 显卡**有** HEVC 解码器(所以 `canPlayType` 报 "probably"、`supported:true`),但**在 8K60 下跑不动**(`smooth:false`)
|
||||||
| `quest` | 无一被拦 → 声明保持 ≥183 → **Direct Play 不变** |
|
|
||||||
| `off` | 钩子未安装,`canPlayType` 完全未动 → 恢复旧行为 |
|
结果就是:声称支持 level 6.1 → 服务器 DirectPlay → 黑屏。而这恰好就是本机上那个文件的真实情况。所以 0.5.0.0 把它纳入判定。
|
||||||
|
|
||||||
|
**定位真机问题时看这个**:在出问题的浏览器控制台跑
|
||||||
|
|
||||||
|
```js
|
||||||
|
window.__JFVR.capsDiag()
|
||||||
|
```
|
||||||
|
|
||||||
|
会列出每一档的 `supported / smooth / powerEfficient`、探测用的负载、以及**为什么被拦**(`unsupported` 还是 `not-smooth`)。一次就能看出是哪一维的问题。
|
||||||
|
|
||||||
|
五种模式本地实测(`_harness-codec.html`,全过):
|
||||||
|
|
||||||
|
| 模式 | 模拟 | 结果 |
|
||||||
|
|---|---|---|
|
||||||
|
| `pc` | `supported=false` | 封顶 level 153 → **转码** |
|
||||||
|
| `slow` | `supported=true, smooth=false`(**真实桌面场景**) | 封顶 level 153 → **转码** |
|
||||||
|
| `quest` | 全部 `smooth` | 保持 ≥183 → **Direct Play** |
|
||||||
|
| `pin` | `slow` + `jfvr-cpt-keep=2:183` | 恢复 183 → **Direct Play** |
|
||||||
|
| `off` | 开关关闭 | `canPlayType` 完全未动 |
|
||||||
|
|
||||||
### 18.8 待办
|
### 18.8 待办
|
||||||
|
|
||||||
- [ ] 探测目前只覆盖 HEVC。AV1 / VP9 走同一套机制,但库里没有这类片源,先不做。
|
- [ ] 探测目前只覆盖 HEVC。AV1 / VP9 走同一套机制,但库里没有这类片源,先不做。
|
||||||
- [ ] `decodingInfo` 的 `smooth` 现在是只记录不行动。如果哪天出现「supported:true 但实际掉帧」的案例,可以考虑把 `smooth === false` 也纳入降级条件(风险:可能误伤 Quest)。
|
- [ ] 网络带宽那一维不在设备档案范围内(档案是在播放开始时判一次的)。Jellyfin 自带的 Auto 码率探测管这个。
|
||||||
|
- [ ] 看门狗(§1.2)现在退居为纯兜底:如果检测结果准了,它就不应该再触发。它仍然保留,作为「声称能播结果没播出来」的最后一道。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 19. ADDENDUM 13 — 真机根因:`nvidia-vaapi-driver` 0.0.14 的自引用初始化器
|
||||||
|
|
||||||
|
### 19.1 结论(先看这个)
|
||||||
|
|
||||||
|
本机(Kubuntu / NVIDIA TU116M GTX 1660 Ti Mobile / Chrome 152)播不了 8K Main 10,
|
||||||
|
**根因不在 Jellyfin、不在插件、也不在显卡硬件**,而在 `nvidia-vaapi-driver` 的版本:
|
||||||
|
|
||||||
|
```
|
||||||
|
已安装: nvidia-vaapi-driver 0.0.14-1 (2025-06-08,Ubuntu 26.04 仓库里只有这个)
|
||||||
|
已修复: 0.0.18 (2026-08-31)
|
||||||
|
```
|
||||||
|
|
||||||
|
**升级到 0.0.18 即可,不需要转码、不需要插件做任何补偿。**
|
||||||
|
|
||||||
|
### 19.2 证据链
|
||||||
|
|
||||||
|
**1) 硬件能做,中间层不行** —— 同一文件、同一台机器:
|
||||||
|
|
||||||
|
| 路径 | 结果 |
|
||||||
|
|---|---|
|
||||||
|
| `ffmpeg -hwaccel vaapi`(走 nvidia-vaapi-driver) | ❌ `Failed to create decode context: 2 (resource allocation failed)` |
|
||||||
|
| `ffmpeg -hwaccel cuda`(直连 NVDEC) | ✅ 正常 |
|
||||||
|
| VAAPI 解 8K **Main(8-bit)** | ✅ 正常 |
|
||||||
|
| VAAPI 解 1080p **Main 10** | ✅ 正常 |
|
||||||
|
|
||||||
|
→ 只有 **8K + 10-bit** 这个组合失败;硬件本身没问题。
|
||||||
|
|
||||||
|
**2) Chrome 侧的配置是对的** —— `chrome://gpu` 实测:
|
||||||
|
|
||||||
|
```
|
||||||
|
Graphics Feature Status
|
||||||
|
* Video Decode: Hardware accelerated ← VAAPI 生效中
|
||||||
|
Video Acceleration Information
|
||||||
|
Decode hevc main : 144x144 to 8192x8192 pixels
|
||||||
|
Decode hevc main 10 : 144x144 to 8192x8192 pixels ← 驱动"声称"支持
|
||||||
|
```
|
||||||
|
|
||||||
|
**驱动声称支持 8K Main 10,实际建不出解码器。** 于是:
|
||||||
|
|
||||||
|
```
|
||||||
|
canPlayType('hvc1.2.4.L183') → truthy
|
||||||
|
→ Jellyfin Web 声明 maxHevcLevel=183 / main|main 10
|
||||||
|
→ 服务器选 DirectPlay(日志里没有任何 ffmpeg)
|
||||||
|
→ Chrome 真正解码时 cuvidCreateDecoder 失败
|
||||||
|
→ 黑屏 / 一直转圈(而 OSD 只在 playbackstart 之后创建,所以连码率菜单都没有)
|
||||||
|
```
|
||||||
|
|
||||||
|
**3) 上游 bug** —— 0.0.14 的 `src/vabackend.c`:
|
||||||
|
|
||||||
|
```c
|
||||||
|
CUVIDDECODECREATEINFO vdci = {
|
||||||
|
.ulWidth = vdci.ulMaxWidth = vdci.ulTargetWidth = picture_width, // ← 在自身初始化器里引用自己
|
||||||
|
.ulHeight = vdci.ulMaxHeight = vdci.ulTargetHeight = picture_height, // C 里这是未定义行为
|
||||||
|
```
|
||||||
|
|
||||||
|
修复提交 `a565237`(2026-07-09)标题即 **"fix: drop self-referential CUVIDDECODECREATEINFO initializer"**,
|
||||||
|
把赋值移出初始化器;`#449`(2026-07-17 合入)把同样的修复镜像到另一个函数。**0.0.17 仍有问题,0.0.18 已修复。**
|
||||||
|
|
||||||
|
### 19.3 Kubuntu 上正确让 Chrome 用显卡
|
||||||
|
|
||||||
|
用户现有的启动参数**是对的**(`chrome://gpu` 已确认 `Video Decode: Hardware accelerated`):
|
||||||
|
|
||||||
|
```
|
||||||
|
--enable-features=VaapiOnNvidiaGPUs,VaapiVideoDecodeLinuxGL,VaapiVideoDecoder
|
||||||
|
--disable-features=UseChromeOSDirectVideoDecoder
|
||||||
|
```
|
||||||
|
|
||||||
|
配套条件:
|
||||||
|
|
||||||
|
- `nvidia-vaapi-driver` **≥ 0.0.18**(当前 0.0.14 → 这是要补的一环)
|
||||||
|
- 驱动 README 要求内核参数 `nvidia-drm.modeset=1`(**本机当前未设置**,`/proc/cmdline` 里没有)
|
||||||
|
- `LIBVA_DRIVER_NAME=nvidia`
|
||||||
|
- 注意:驱动 README 明说 *"specifically designed to be used by Firefox … may not operate correctly in other applications"*、*"Chrome is currently unsupported"*。Chrome 能用但不受官方支持。
|
||||||
|
|
||||||
|
升级(Ubuntu 仓库只有 0.0.14,需从源码构建):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt install meson ninja-build libva-dev libegl-dev gstreamer1.0-plugins-bad libffmpeg-nvenc-dev
|
||||||
|
git clone --branch v0.0.18 https://github.com/elFarto/nvidia-vaapi-driver
|
||||||
|
cd nvidia-vaapi-driver && meson setup build && sudo meson install -C build
|
||||||
|
```
|
||||||
|
|
||||||
|
### 19.4 这对插件意味着什么
|
||||||
|
|
||||||
|
升级驱动后:Chrome 能真正解 8K Main 10 → `decodingInfo` 报 `smooth:true` → 插件不拦任何档
|
||||||
|
→ 直连 8K → 看门狗也不会触发。**插件侧不需要做任何补偿。**
|
||||||
|
|
||||||
|
但 **0.5.0.0 的判定逻辑本身有个缺陷,已在 0.5.1.0 修掉**:它在 `smooth === false` 时就压低
|
||||||
|
level 上限,而 Jellyfin 的档案**无法表达「Main 支持到 8K,Main 10 只到 4K」**(level 上限和
|
||||||
|
profile 列表来自同一条 Main 10 判断链)。所以在那台「8-bit 8K 正常、10-bit 8K 失败」的机器上,
|
||||||
|
拦掉 `2:183` 会把**整库 61 个 8-bit 8K 文件**一起拖进转码 —— 而 NAS 转 8K 只能出 1280×640。
|
||||||
|
|
||||||
|
0.5.1.0 改成:**只有当同位深的 Main(8-bit)档也不可用时,才压低 level 上限**(为此补测了
|
||||||
|
Main L5.1 / L6.1 / L6.2 作为对照)。代价是「8-bit 能解、10-bit 不能」的设备仍会声称 10-bit 并在
|
||||||
|
那种文件上黑屏 —— 那正是 `40-watchdog.js` 存在的意义。
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ JFVR 同时也是一个标准的 **Jellyfin 插件**,通过自建 Gitea 仓库
|
|||||||
| 脚本端点 | `/JFVR/jfvr.js`(bundle 内嵌在 DLL 里,URL 带内容哈希做缓存键) |
|
| 脚本端点 | `/JFVR/jfvr.js`(bundle 内嵌在 DLL 里,URL 带内容哈希做缓存键) |
|
||||||
| 状态查询 | `/JFVR/status` |
|
| 状态查询 | `/JFVR/status` |
|
||||||
| 设置页 | Dashboard → 插件 → Jellyfin Web VR(开关注入 / 覆盖脚本 URL) |
|
| 设置页 | Dashboard → 插件 → Jellyfin Web VR(开关注入 / 覆盖脚本 URL) |
|
||||||
|
| 页面按钮 | 「VR 播放」按钮**可拖动**(位置记住;双击回到默认右下角) |
|
||||||
|
|
||||||
**安装**:Dashboard → 插件 → 目录 → ⚙️ → ➕ → 粘贴上面的仓库地址 → 保存 →
|
**安装**:Dashboard → 插件 → 目录 → ⚙️ → ➕ → 粘贴上面的仓库地址 → 保存 →
|
||||||
在 Catalog 里找到 **Jellyfin Web VR** → 安装 → **重启 Jellyfin**。
|
在 Catalog 里找到 **Jellyfin Web VR** → 安装 → **重启 Jellyfin**。
|
||||||
@@ -108,25 +109,56 @@ if (canPlayType('video/mp4; codecs="hvc1.2.4.L183"')) {
|
|||||||
|
|
||||||
插件的做法:
|
插件的做法:
|
||||||
|
|
||||||
1. 页面加载时用 **`MediaCapabilities.decodingInfo`** 对 HEVC 各档做真机探测(每档在它对应的分辨率上测:L120→1080p30、L153→4K60、L183/L186→8K60,因为 level 字符串本身不带尺寸);
|
1. 页面加载时用 **`MediaCapabilities.decodingInfo`** 对 HEVC 各档做真机探测(每档在它对应的分辨率和码率上测:L120→1080p30/8Mbps、L153→4K60/20Mbps、L183/L186→8K60/30Mbps,因为 level 字符串本身不带尺寸);
|
||||||
2. 把结果回灌给 `HTMLVideoElement.prototype.canPlayType`:只有 `supported === false` 才返回 `''`,其余全部交给原生实现。
|
2. 把结果回灌给 `HTMLVideoElement.prototype.canPlayType`。
|
||||||
|
|
||||||
|
**拦掉一档的条件有两个,都是「确定的不能」**:
|
||||||
|
|
||||||
|
| 条件 | 含义 |
|
||||||
|
|---|---|
|
||||||
|
| `supported === false` | 完全解不了这个格式 |
|
||||||
|
| `smooth === false` | 能解,但**在那种分辨率和帧率下跟不上** —— 就是「有 HEVC 解码器,但 8K 跑不动」这种桌面场景 |
|
||||||
|
|
||||||
|
只有 `powerEfficient:false`(纯软解)**本身不拦**。
|
||||||
|
|
||||||
这样 Jellyfin Web 自己那套 `maxHevcLevel` 逻辑就会得出**准确**档案:
|
这样 Jellyfin Web 自己那套 `maxHevcLevel` 逻辑就会得出**准确**档案:
|
||||||
|
|
||||||
| 设备 | 结果 |
|
| 设备 | 结果 |
|
||||||
|---|---|
|
|---|---|
|
||||||
| 桌面(声称支持但实际解不动 8K Main 10) | 降到 level 153 → 8K 文件超出声明 → **服务器转码** |
|
| 桌面(声称支持但实际解不动 8K Main 10) | 降到 level 153 → 8K 文件超出声明 → **服务器自动转码** |
|
||||||
| Quest 3(真能解 8K Main 10) | 保持 ≥183 → **继续 Direct Play** |
|
| Quest 3(真能解 8K Main 10) | 保持 ≥183 → **继续 Direct Play** |
|
||||||
|
|
||||||
**故意保守**:只有 `supported === false` 才降级。`supported:true, smooth:false` 会记录但不影响行为 —— 太贴边了,而且「声称能播结果没播出来」已经有 §1.2 的看门狗兜底。
|
注意:这里**不问用户任何东西**。客户端如实上报,Jellyfin 在 `PlaybackInfo` 那一步自己选 Transcode —— 这正是「提示用户切码率」想要达到的目的,只是做在了正确的层。
|
||||||
|
|
||||||
出问题的逃生开关(某台设备报得离谱时用):
|
逃生开关:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
localStorage['jfvr-cpt'] = 'off'; // 然后刷新,覆盖完全不安装
|
localStorage['jfvr-cpt'] = 'off'; // 完全关掉钩子
|
||||||
|
localStorage['jfvr-cpt-keep'] = '2:183'; // 只保留某一档(单台设备误报时用,不用整个关掉)
|
||||||
```
|
```
|
||||||
|
|
||||||
当前状态可以在诊断面板里看到(`canPlayType hook` 和 `HEVC real (decodingInfo)` 两段)。这也是 Meta 官方文档推荐的做法 —— 他们明确说「用 Media Capabilities API 探测,不要靠 UA 嗅探」。
|
当前状态可以在诊断面板里看到,每档会写明**为什么**被拦(`unsupported` / `not-smooth`)或是否被 pin:
|
||||||
|
|
||||||
|
```
|
||||||
|
canPlayType hook : on (blocked: Main10 L6.1 (8K) (not-smooth), ...)
|
||||||
|
HEVC real (decodingInfo):
|
||||||
|
Main10 L6.1 (8K) supported=true smooth=false powerEfficient=true [8192x4096@60 30Mbps] <-- BLOCKED (not-smooth)
|
||||||
|
```
|
||||||
|
|
||||||
|
这也是 Meta 官方文档推荐的做法 —— 他们明确说「用 Media Capabilities API 探测,不要靠 UA 嗅探」。
|
||||||
|
|
||||||
|
### 1.4 「VR 播放」按钮可以拖了
|
||||||
|
|
||||||
|
原来钉死在右下角(`right:16px; bottom:120px`),窗口矮的时候正好压在播放看门狗弹窗的码率按钮上,没地方躲。
|
||||||
|
|
||||||
|
现在:
|
||||||
|
|
||||||
|
- 用 `left/top` 定位(不再用 `right/bottom`),用 pointer 事件拖动,位置记在 `localStorage['jfvr-btn-pos']`
|
||||||
|
- `touch-action:none` —— 不加这个,触屏上拖动会变成滚动页面
|
||||||
|
- **拖动结束仍然会触发一次 click**,代码会把那一次吃掉,所以拖完不会意外弹出面板
|
||||||
|
- 限制在视窗内,窗口缩放时会重新夹紧
|
||||||
|
- **双击回到默认右下角**(拖到尴尬位置时的逃生口)
|
||||||
|
- 设置面板跟着按钮走(不再是钉在视窗角落),优先放在按钮上方,上方放不下就放下方,再放不下就夹在屏幕内
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
Vendored
+380
-46
@@ -320,6 +320,7 @@
|
|||||||
/* MediaCapabilities verdicts, keyed '<profile_idc>:<level>'. See below. */
|
/* MediaCapabilities verdicts, keyed '<profile_idc>:<level>'. See below. */
|
||||||
codec: {},
|
codec: {},
|
||||||
codecBlocked: [],
|
codecBlocked: [],
|
||||||
|
codecKept: [],
|
||||||
cptPatched: false,
|
cptPatched: false,
|
||||||
cptMode: null
|
cptMode: null
|
||||||
};
|
};
|
||||||
@@ -359,24 +360,77 @@
|
|||||||
* DirectPlay. Meta's browser-video docs recommend exactly this API over UA
|
* DirectPlay. Meta's browser-video docs recommend exactly this API over UA
|
||||||
* sniffing.
|
* sniffing.
|
||||||
*
|
*
|
||||||
* Only `supported === false` downgrades. `supported:true, smooth:false` is
|
* A tier is blocked when:
|
||||||
* 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:
|
* supported === false the decoder cannot handle the format at all
|
||||||
* localStorage['jfvr-cpt'] = 'off' then reload
|
* smooth === false it can, but not in real time at that resolution and
|
||||||
|
* frame rate -- the "decoder exists, 8K does not work"
|
||||||
|
* case
|
||||||
|
*
|
||||||
|
* AND, for a Main 10 tier, only when the SAME LEVEL IS ALSO UNUSABLE IN MAIN
|
||||||
|
* (8-bit). That second condition is not cosmetic; it is forced by a real
|
||||||
|
* limitation in Jellyfin's device profile.
|
||||||
|
*
|
||||||
|
* browserDeviceProfile.js derives the level ceiling and the profile list from
|
||||||
|
* ONE chain of Main 10 probes -- the only Main (8-bit) probes are L4.0 and
|
||||||
|
* L4.1. So the reachable states are only:
|
||||||
|
*
|
||||||
|
* (120, main) (123, main) (123, main|main 10) (153, main|main 10)
|
||||||
|
* (183, main|main 10) (186, main|main 10)
|
||||||
|
*
|
||||||
|
* "Main up to 8K, Main 10 only up to 4K" is NOT expressible. So blocking
|
||||||
|
* 2:183 on a device that decodes 8-bit 8K but not 10-bit 8K does not just
|
||||||
|
* spare the 10-bit file -- it drags every 8-bit 8K file down to level 153 and
|
||||||
|
* transcodes them too. On a server that cannot transcode 8K in real time
|
||||||
|
* (measured: 8192x4096 -> 1280x640), that trades one broken file for sixty.
|
||||||
|
*
|
||||||
|
* Verified on the machine this was written for: NVIDIA VAAPI decodes
|
||||||
|
* 8192x4096 Main 8-bit fine and fails to create a decoder for 8192x4096
|
||||||
|
* Main 10 (nvidia-vaapi-driver passes the surface bit depth straight to
|
||||||
|
* cuvidCreateDecoder). Its whole library is 8-bit 8K, so lowering the ceiling
|
||||||
|
* would have broken all of it.
|
||||||
|
*
|
||||||
|
* The cost of this rule: a device that decodes 8-bit at a level but not
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// decodingInfo needs real dimensions; a level string does not carry them, so
|
// decodingInfo needs real dimensions; a level string does not carry them, so
|
||||||
// each level is probed at the resolution it exists for.
|
// each level is probed at the resolution and bitrate it exists for. Main
|
||||||
|
// (8-bit) is probed at the same levels as Main 10 because it is the control
|
||||||
|
// that decides whether a level is really out of reach.
|
||||||
|
//
|
||||||
|
// NOTE on the codec strings: they MUST carry a constraint byte. Chrome's
|
||||||
|
// MediaCapabilities.decodingInfo does not recognise the bare 'hvc1.1.L120'
|
||||||
|
// spelling and answers supported:false for it even on a machine that decodes
|
||||||
|
// HEVC perfectly, while 'hvc1.1.0.L120' is answered correctly. That one
|
||||||
|
// character used to matter far more than it looks: browserDeviceProfile.js
|
||||||
|
// gates the WHOLE hevc entry on supportsHevc(), which is exactly
|
||||||
|
//
|
||||||
|
// canPlayType('...codecs="hvc1.1.L120"') ||
|
||||||
|
// canPlayType('...codecs="hev1.1.L120"') ||
|
||||||
|
// canPlayType('...codecs="hvc1.1.0.L120"') || ...
|
||||||
|
//
|
||||||
|
// so a spurious block of tier 1:120 (all spellings map to it) removes hevc
|
||||||
|
// from every DirectPlayProfile and transcode every HEVC file in the library.
|
||||||
|
// 1:120 is NOT part of Jellyfin's level chain; it is only that gate.
|
||||||
var CODEC_PROBES = [
|
var CODEC_PROBES = [
|
||||||
{ key: '1:120', name: 'Main L4.0', w: 1920, h: 1080, fps: 30, codec: 'hvc1.1.L120' },
|
{ key: '1:120', name: 'Main L4.0', w: 1920, h: 1080, fps: 30, mbps: 8, codec: 'hvc1.1.0.L120' },
|
||||||
{ key: '1:123', name: 'Main L4.1', w: 1920, h: 1080, fps: 60, codec: 'hvc1.1.4.L123' },
|
{ key: '1:123', name: 'Main L4.1', w: 1920, h: 1080, fps: 60, mbps: 8, 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: '1:153', name: 'Main L5.1 (4K)', w: 3840, h: 2160, fps: 60, mbps: 20, codec: 'hvc1.1.5.L153.B0' },
|
||||||
{ key: '2:123', name: 'Main10 L4.1', w: 1920, h: 1080, fps: 60, codec: 'hvc1.2.4.L123' },
|
{ key: '1:183', name: 'Main L6.1 (8K)', w: 8192, h: 4096, fps: 60, mbps: 30, codec: 'hvc1.1.6.L183.B0' },
|
||||||
{ key: '2:153', name: 'Main10 L5.1 (4K)', w: 3840, h: 2160, fps: 60, codec: 'hvc1.2.4.L153' },
|
{ key: '1:186', name: 'Main L6.2 (8K60)', w: 8192, h: 4096, fps: 60, mbps: 30, codec: 'hvc1.1.6.L186.B0' },
|
||||||
{ key: '2:183', name: 'Main10 L6.1 (8K)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.2.4.L183' },
|
{ key: '2:123', name: 'Main10 L4.1', w: 1920, h: 1080, fps: 60, mbps: 8, codec: 'hvc1.2.4.L123' },
|
||||||
{ key: '2:186', name: 'Main10 L6.2 (8K60)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.2.4.L186' }
|
{ key: '2:153', name: 'Main10 L5.1 (4K)', w: 3840, h: 2160, fps: 60, mbps: 20, codec: 'hvc1.2.4.L153' },
|
||||||
|
{ key: '2:183', name: 'Main10 L6.1 (8K)', w: 8192, h: 4096, fps: 60, mbps: 30, codec: 'hvc1.2.4.L183' },
|
||||||
|
{ key: '2:186', name: 'Main10 L6.2 (8K60)', w: 8192, h: 4096, fps: 60, mbps: 30, codec: 'hvc1.2.4.L186' }
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -427,11 +481,78 @@
|
|||||||
* MediaCapabilities probe + canPlayType override
|
* MediaCapabilities probe + canPlayType override
|
||||||
* ------------------------------------------------------------------ */
|
* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/** Tiers the user has pinned as "keep claiming this", '<key>,<key>' in localStorage. */
|
||||||
|
function readKeepList() {
|
||||||
|
try {
|
||||||
|
var raw = localStorage.getItem('jfvr-cpt-keep') || '';
|
||||||
|
return raw.split(',').map(function (s) { return s.trim(); }).filter(Boolean);
|
||||||
|
} catch (e) { return []; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Why a verdict means "do not claim this tier", or null if it is fine. */
|
||||||
|
function blockReason(v, keep) {
|
||||||
|
if (!v || v.error) return null; // unknown -> leave it to the browser
|
||||||
|
if (keep.indexOf(v.key) >= 0) return null; // user pinned it
|
||||||
|
if (v.supported === false) return 'unsupported';
|
||||||
|
if (v.smooth === false) return 'not-smooth';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** True when this tier is not usable on its own terms. */
|
||||||
|
function tierUnusable(key) {
|
||||||
|
var v = NS.caps.codec[key];
|
||||||
|
return !!v && !v.error && (v.supported === false || v.smooth === false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The decision the canPlayType hook uses.
|
||||||
|
*
|
||||||
|
* A Main 10 tier is only blocked when the SAME LEVEL is also unusable in Main
|
||||||
|
* (8-bit). See the long comment above CODEC_PROBES: Jellyfin's profile cannot
|
||||||
|
* express "Main up to 8K, Main 10 up to 4K", so blocking 2:183 on a device
|
||||||
|
* that handles 8-bit 8K would drag all of its 8-bit 8K files into transcoding.
|
||||||
|
*/
|
||||||
|
function shouldBlock(key, keep) {
|
||||||
|
var v = NS.caps.codec[key];
|
||||||
|
if (!v || v.error) return null;
|
||||||
|
if (keep.indexOf(key) >= 0) return null;
|
||||||
|
var own = blockReason(v, keep);
|
||||||
|
if (!own) return null;
|
||||||
|
var parts = key.split(':');
|
||||||
|
|
||||||
|
// Base tier. 1:120 is not in Jellyfin's level chain -- it is only the
|
||||||
|
// coarse "does this client have HEVC at all" gate (supportsHevc() in
|
||||||
|
// browserDeviceProfile.js, which probes exactly this level). Blocking it
|
||||||
|
// drops hevc from every DirectPlayProfile, i.e. transcodes the entire
|
||||||
|
// HEVC library. Never act on it unless the device is unusable at EVERY
|
||||||
|
// Main tier, so one flaky/early probe cannot do that.
|
||||||
|
if (key === '1:120') {
|
||||||
|
var anyMainUsable = CODEC_PROBES.some(function (p) {
|
||||||
|
if (p.key === '1:120' || p.key.charAt(0) !== '1') return false;
|
||||||
|
var m = NS.caps.codec[p.key];
|
||||||
|
return !!m && !m.error && m.supported !== false && m.smooth !== false;
|
||||||
|
});
|
||||||
|
if (anyMainUsable) return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts[0] === '2') {
|
||||||
|
// Control: the same level in Main (8-bit).
|
||||||
|
if (!tierUnusable('1:' + parts[1])) return null;
|
||||||
|
}
|
||||||
|
return own;
|
||||||
|
}
|
||||||
|
|
||||||
function applyVerdicts() {
|
function applyVerdicts() {
|
||||||
NS.caps.codecBlocked = CODEC_PROBES.filter(function (p) {
|
var keep = NS.caps.__keep || [];
|
||||||
|
NS.caps.codecKept = [];
|
||||||
|
NS.caps.codecBlocked = [];
|
||||||
|
CODEC_PROBES.forEach(function (p) {
|
||||||
var v = NS.caps.codec[p.key];
|
var v = NS.caps.codec[p.key];
|
||||||
return v && v.supported === false;
|
if (!v) return;
|
||||||
}).map(function (p) { return p.name; });
|
var why = shouldBlock(p.key, keep);
|
||||||
|
if (why) NS.caps.codecBlocked.push(p.name + ' (' + why + ')');
|
||||||
|
else if (keep.indexOf(p.key) >= 0) NS.caps.codecKept.push(p.name);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function installCanPlayTypeOverride() {
|
function installCanPlayTypeOverride() {
|
||||||
@@ -443,9 +564,8 @@
|
|||||||
proto.canPlayType = function (type) {
|
proto.canPlayType = function (type) {
|
||||||
try {
|
try {
|
||||||
var key = hevcKey(type);
|
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.
|
// Only a definite "no" is acted on. Anything else is the browser's call.
|
||||||
if (v && v.supported === false) return '';
|
if (key && shouldBlock(key, NS.caps.__keep || [])) return '';
|
||||||
} catch (e) { /* never break the native answer */ }
|
} catch (e) { /* never break the native answer */ }
|
||||||
return orig.apply(this, arguments);
|
return orig.apply(this, arguments);
|
||||||
};
|
};
|
||||||
@@ -454,17 +574,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
(function probeCodecs() {
|
(function probeCodecs() {
|
||||||
// Kill switch, and the escape hatch if this ever misbehaves on a device.
|
// Native behavior is the default: do NOT install the canPlayType override,
|
||||||
try {
|
// so Jellyfin builds its own device profile exactly as it would without this
|
||||||
if (localStorage.getItem('jfvr-cpt') === 'off') { NS.caps.cptMode = 'off'; return; }
|
// plugin. Opt back in with localStorage['jfvr-cpt'] = 'on' when diagnosing.
|
||||||
} catch (e) {}
|
// 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;
|
var mc = navigator.mediaCapabilities;
|
||||||
if (!mc || typeof mc.decodingInfo !== 'function') { NS.caps.cptMode = 'no-api'; return; }
|
if (!mc || typeof mc.decodingInfo !== 'function') { NS.caps.cptMode = 'no-api'; return; }
|
||||||
|
|
||||||
|
// Read the pin list once, up front: canPlayType is synchronous and must not
|
||||||
|
// touch localStorage on every call.
|
||||||
|
NS.caps.__keep = readKeepList();
|
||||||
|
|
||||||
// Install FIRST, synchronously, so the hook is in place before anything can
|
// Install FIRST, synchronously, so the hook is in place before anything can
|
||||||
// read canPlayType. Until a verdict lands the hook just defers to native,
|
// read canPlayType. Until a verdict lands the hook just defers to native,
|
||||||
// which is the safe default.
|
// which is the safe default.
|
||||||
installCanPlayTypeOverride();
|
if (hookOn) installCanPlayTypeOverride();
|
||||||
|
|
||||||
var pending = CODEC_PROBES.length;
|
var pending = CODEC_PROBES.length;
|
||||||
CODEC_PROBES.forEach(function (p) {
|
CODEC_PROBES.forEach(function (p) {
|
||||||
@@ -472,20 +601,22 @@
|
|||||||
type: 'file',
|
type: 'file',
|
||||||
video: {
|
video: {
|
||||||
contentType: 'video/mp4; codecs="' + p.codec + '"',
|
contentType: 'video/mp4; codecs="' + p.codec + '"',
|
||||||
width: p.w, height: p.h, bitrate: 20000000, framerate: p.fps
|
width: p.w, height: p.h, bitrate: p.mbps * 1000000, framerate: p.fps
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mc.decodingInfo(cfg).then(function (info) {
|
mc.decodingInfo(cfg).then(function (info) {
|
||||||
NS.caps.codec[p.key] = {
|
NS.caps.codec[p.key] = {
|
||||||
name: p.name, workload: p.w + 'x' + p.h + '@' + p.fps,
|
key: p.key, name: p.name, workload: p.w + 'x' + p.h + '@' + p.fps + ' ' + p.mbps + 'Mbps',
|
||||||
supported: info.supported, smooth: info.smooth, powerEfficient: info.powerEfficient
|
supported: info.supported, smooth: info.smooth, powerEfficient: info.powerEfficient
|
||||||
};
|
};
|
||||||
}).catch(function (e) {
|
}).catch(function (e) {
|
||||||
NS.caps.codec[p.key] = { name: p.name, error: String(e && e.message || e) };
|
NS.caps.codec[p.key] = { key: p.key, name: p.name, error: String(e && e.message || e) };
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
if (--pending === 0) {
|
if (--pending === 0) {
|
||||||
applyVerdicts();
|
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(', ') : ''));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -493,13 +624,19 @@
|
|||||||
|
|
||||||
NS.capsDiag = function () {
|
NS.capsDiag = function () {
|
||||||
var c = NS.caps;
|
var c = NS.caps;
|
||||||
|
var keep = readKeepList();
|
||||||
var real = CODEC_PROBES.map(function (p) {
|
var real = CODEC_PROBES.map(function (p) {
|
||||||
var v = c.codec[p.key];
|
var v = c.codec[p.key];
|
||||||
if (!v) return ' ' + p.name.padEnd(20) + ' (pending)';
|
if (!v) return ' ' + p.name.padEnd(20) + ' (pending)';
|
||||||
if (v.error) return ' ' + p.name.padEnd(20) + ' error: ' + v.error;
|
if (v.error) return ' ' + p.name.padEnd(20) + ' error: ' + v.error;
|
||||||
|
var why = shouldBlock(p.key, keep);
|
||||||
|
var own = blockReason(v, keep);
|
||||||
|
var note = why ? ' <-- BLOCKED (' + why + ')' :
|
||||||
|
(own ? ' (unusable, but kept: 8-bit at this level works)' :
|
||||||
|
(keep.indexOf(p.key) >= 0 ? ' <-- pinned' : ''));
|
||||||
return ' ' + p.name.padEnd(20) + ' supported=' + v.supported +
|
return ' ' + p.name.padEnd(20) + ' supported=' + v.supported +
|
||||||
' smooth=' + v.smooth + ' powerEfficient=' + v.powerEfficient +
|
' smooth=' + v.smooth + ' powerEfficient=' + v.powerEfficient +
|
||||||
' [' + v.workload + ']' + (v.supported === false ? ' <-- BLOCKED' : '');
|
' [' + v.workload + ']' + note;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -513,7 +650,7 @@
|
|||||||
'MAX_TEXTURE_SIZE : ' + c.maxTextureSize,
|
'MAX_TEXTURE_SIZE : ' + c.maxTextureSize,
|
||||||
'HEVC canPlayType : ' + JSON.stringify(c.hevc),
|
'HEVC canPlayType : ' + JSON.stringify(c.hevc),
|
||||||
'canPlayType hook : ' + (c.cptMode || 'pending') +
|
'canPlayType hook : ' + (c.cptMode || 'pending') +
|
||||||
(c.cptMode === 'on' ? ' (downgraded: ' + (c.codecBlocked.join(', ') || 'nothing yet') + ')' : ''),
|
(c.cptMode === 'on' ? ' (blocked: ' + (c.codecBlocked.join(', ') || 'nothing yet') + ')' : ''),
|
||||||
'HEVC real (decodingInfo):',
|
'HEVC real (decodingInfo):',
|
||||||
real
|
real
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@@ -4617,6 +4754,15 @@
|
|||||||
var DEAD_MS = 15000;
|
var DEAD_MS = 15000;
|
||||||
var DEAD_TRANSCODE_MS = 45000;
|
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
|
// After the user answers (either way) stay quiet, so a slow-but-working
|
||||||
// playback does not get nagged at.
|
// playback does not get nagged at.
|
||||||
var QUIET_MS = 120000;
|
var QUIET_MS = 120000;
|
||||||
@@ -4637,7 +4783,9 @@
|
|||||||
lastReason: '',
|
lastReason: '',
|
||||||
applied: null,
|
applied: null,
|
||||||
codec: null, // filled in best-effort from the Jellyfin API
|
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;
|
NS.Watchdog = W;
|
||||||
|
|
||||||
@@ -4663,7 +4811,7 @@
|
|||||||
return src.indexOf('/hls') >= 0 || src.indexOf('.m3u8') >= 0;
|
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) {
|
function hasPicture(v) {
|
||||||
return v.videoWidth > 0 && v.readyState >= 2;
|
return v.videoWidth > 0 && v.readyState >= 2;
|
||||||
}
|
}
|
||||||
@@ -4805,17 +4953,25 @@
|
|||||||
|
|
||||||
var p = NS.makeEl('div', 'jfvr-wd');
|
var p = NS.makeEl('div', 'jfvr-wd');
|
||||||
p.id = '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 body = NS.makeEl('div', 'jfvr-wd-body');
|
||||||
|
|
||||||
var msg = NS.makeEl('p');
|
var msg = NS.makeEl('p');
|
||||||
var waited = Math.round(timeoutMs(v) / 1000);
|
var waited = Math.round(timeoutMs(v) / 1000);
|
||||||
|
var intro;
|
||||||
|
if (reason === 'error') {
|
||||||
|
intro = '播放器报错了,一个画面都没解出来。';
|
||||||
|
} else if (reason === 'stalled') {
|
||||||
|
intro = '画面已经出来了,但播放进度停住不动了(<code>currentTime</code> 不再前进)—— ' +
|
||||||
|
'解码器跟不上这个文件。';
|
||||||
|
} else {
|
||||||
|
intro = '等了 ' + waited + ' 秒都没拿到任何画面(<code>videoWidth = 0</code>),' +
|
||||||
|
'所以播放器界面也没有被创建出来。';
|
||||||
|
}
|
||||||
msg.innerHTML =
|
msg.innerHTML =
|
||||||
(reason === 'error'
|
intro +
|
||||||
? '播放器报错了,一个画面都没解出来。'
|
|
||||||
: '等了 ' + waited + ' 秒都没拿到任何画面(<code>videoWidth = 0</code>),' +
|
|
||||||
'所以播放器界面也没有被创建出来。') +
|
|
||||||
'最常见的原因是<strong>这台设备解不动这个格式</strong>:' +
|
'最常见的原因是<strong>这台设备解不动这个格式</strong>:' +
|
||||||
'<span class="jfvr-wd-fmt">' + (W.codec || '该格式') + '</span>。<br>' +
|
'<span class="jfvr-wd-fmt">' + (W.codec || '该格式') + '</span>。<br>' +
|
||||||
'让服务器转码成 H.264 再播就能看到画面,代价是画质下降(这台 NAS 的转码上限约 4K)。';
|
'让服务器转码成 H.264 再播就能看到画面,代价是画质下降(这台 NAS 的转码上限约 4K)。';
|
||||||
@@ -4857,7 +5013,7 @@
|
|||||||
W.panel = p;
|
W.panel = p;
|
||||||
|
|
||||||
NS.recordError('watchdog', new Error('playback never started: ' + reason));
|
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() {
|
function hide() {
|
||||||
@@ -4867,6 +5023,8 @@
|
|||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
W.seenAt = 0;
|
W.seenAt = 0;
|
||||||
|
W.lastTime = -1;
|
||||||
|
W.progressAt = 0;
|
||||||
W.codec = null;
|
W.codec = null;
|
||||||
if (W.shown) hide();
|
if (W.shown) hide();
|
||||||
}
|
}
|
||||||
@@ -4887,9 +5045,6 @@
|
|||||||
var v = playerVideo();
|
var v = playerVideo();
|
||||||
if (!v) { reset(); return; }
|
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.
|
// A media error is unambiguous — no need to wait out the timer.
|
||||||
if (v.error) {
|
if (v.error) {
|
||||||
describeCodec(v);
|
describeCodec(v);
|
||||||
@@ -4898,6 +5053,31 @@
|
|||||||
return;
|
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 (!W.seenAt) W.seenAt = now();
|
||||||
if (now() - W.seenAt < timeoutMs(v)) return;
|
if (now() - W.seenAt < timeoutMs(v)) return;
|
||||||
|
|
||||||
@@ -4910,7 +5090,8 @@
|
|||||||
NS.Watchdog.init = function () {
|
NS.Watchdog.init = function () {
|
||||||
W.quietUntil = readQuiet();
|
W.quietUntil = readQuiet();
|
||||||
setInterval(poll, POLL_MS);
|
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)');
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
@@ -5219,16 +5400,23 @@
|
|||||||
// Sits ABOVE Jellyfin's own OSD bar: at the viewport's bottom-right it
|
// Sits ABOVE Jellyfin's own OSD bar: at the viewport's bottom-right it
|
||||||
// covered the player's fullscreen button (owner report). 120 px clears the
|
// covered the player's fullscreen button (owner report). 120 px clears the
|
||||||
// OSD bottom bar; the settings panel stacks above it.
|
// OSD bottom bar; the settings panel stacks above it.
|
||||||
'.jfvr-btn{position:fixed;right:16px;bottom:120px;z-index:2147483000;display:flex;align-items:center;gap:8px;',
|
// left/top are set from JS (see placeButton) so the button can be dragged
|
||||||
|
// anywhere. touch-action:none is what makes a drag work on a touch screen
|
||||||
|
// instead of scrolling the page underneath.
|
||||||
|
'.jfvr-btn{position:fixed;z-index:2147483000;display:flex;align-items:center;gap:8px;',
|
||||||
'padding:10px 16px;border:0;border-radius:24px;background:linear-gradient(135deg,#4ea1ff,#7b5cff);color:#fff;',
|
'padding:10px 16px;border:0;border-radius:24px;background:linear-gradient(135deg,#4ea1ff,#7b5cff);color:#fff;',
|
||||||
'font-size:15px;font-weight:600;cursor:pointer;box-shadow:0 6px 22px rgba(0,0,0,.45);font-family:inherit}',
|
'font-size:15px;font-weight:600;cursor:grab;box-shadow:0 6px 22px rgba(0,0,0,.45);font-family:inherit;',
|
||||||
|
'touch-action:none;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}',
|
||||||
'.jfvr-btn:active{transform:scale(.96)}',
|
'.jfvr-btn:active{transform:scale(.96)}',
|
||||||
|
'.jfvr-btn.jfvr-drag{cursor:grabbing;transform:none;box-shadow:0 10px 32px rgba(0,0,0,.65)}',
|
||||||
// the panel must always fit the viewport AND keep the CTA reachable, so the
|
// the panel must always fit the viewport AND keep the CTA reachable, so the
|
||||||
// body scrolls and the button lives in a sticky footer
|
// body scrolls and the button lives in a sticky footer
|
||||||
'.jfvr-panel{position:fixed;right:16px;bottom:180px;z-index:2147483001;width:290px;background:rgba(20,20,24,.96);',
|
// Positioned from JS (positionPanel) so it follows the button once the
|
||||||
|
// button has been dragged; it no longer lives in the viewport corner.
|
||||||
|
'.jfvr-panel{position:fixed;z-index:2147483001;width:290px;background:rgba(20,20,24,.96);',
|
||||||
'color:#eaeaea;border:1px solid rgba(255,255,255,.14);border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.6);',
|
'color:#eaeaea;border:1px solid rgba(255,255,255,.14);border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.6);',
|
||||||
'font-family:inherit;font-size:14px;backdrop-filter:blur(10px);display:flex;flex-direction:column;',
|
'font-family:inherit;font-size:14px;backdrop-filter:blur(10px);display:flex;flex-direction:column;',
|
||||||
'max-height:calc(100vh - 200px);overflow:hidden}',
|
'max-height:calc(100vh - 32px);overflow:hidden}',
|
||||||
'.jfvr-head{display:flex;justify-content:space-between;align-items:center;padding:10px 12px;background:rgba(255,255,255,.06);font-weight:600;flex:0 0 auto}',
|
'.jfvr-head{display:flex;justify-content:space-between;align-items:center;padding:10px 12px;background:rgba(255,255,255,.06);font-weight:600;flex:0 0 auto}',
|
||||||
'.jfvr-x{background:none;border:0;color:#aaa;font-size:20px;line-height:1;cursor:pointer;padding:0 4px}',
|
'.jfvr-x{background:none;border:0;color:#aaa;font-size:20px;line-height:1;cursor:pointer;padding:0 4px}',
|
||||||
'.jfvr-body{padding:12px;overflow-y:auto;flex:1 1 auto;min-height:0}',
|
'.jfvr-body{padding:12px;overflow-y:auto;flex:1 1 auto;min-height:0}',
|
||||||
@@ -5276,9 +5464,151 @@
|
|||||||
var b = NS.makeEl('button', 'jfvr-btn');
|
var b = NS.makeEl('button', 'jfvr-btn');
|
||||||
b.type = 'button';
|
b.type = 'button';
|
||||||
b.innerHTML = '<span>🎥</span><span>VR 播放</span>';
|
b.innerHTML = '<span>🎥</span><span>VR 播放</span>';
|
||||||
b.addEventListener('click', function (ev) { ev.stopPropagation(); togglePanel(); });
|
b.title = '点击打开设置;按住拖动可以换位置;双击回到默认位置';
|
||||||
|
b.addEventListener('click', function (ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
// A drag still produces a click on most browsers. Swallow that one so
|
||||||
|
// dragging the button never opens the panel by accident.
|
||||||
|
if (dragMoved) { dragMoved = false; return; }
|
||||||
|
togglePanel();
|
||||||
|
});
|
||||||
|
// Escape hatch: a button dragged half off a small window is annoying to
|
||||||
|
// recover by hand.
|
||||||
|
b.addEventListener('dblclick', function (ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
resetButtonPos();
|
||||||
|
});
|
||||||
|
installDrag(b);
|
||||||
document.body.appendChild(b);
|
document.body.appendChild(b);
|
||||||
btn = b;
|
btn = b;
|
||||||
|
btnPos = readBtnPos();
|
||||||
|
placeButton(b, btnPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ *
|
||||||
|
* button placement / dragging
|
||||||
|
* ------------------------------------------------------------------
|
||||||
|
* The button used to be pinned to the bottom-right corner. On a short window
|
||||||
|
* that put it right on top of the bitrate choices the playback watchdog
|
||||||
|
* shows (that panel is centred), and there was no way to move it. It is
|
||||||
|
* draggable now and the spot is remembered per browser.
|
||||||
|
*
|
||||||
|
* The settings panel follows the button rather than the viewport corner, so
|
||||||
|
* the two cannot drift apart.
|
||||||
|
* ------------------------------------------------------------------ */
|
||||||
|
var BTN_POS_KEY = 'jfvr-btn-pos';
|
||||||
|
var BTN_MARGIN = 8;
|
||||||
|
var DRAG_SLOP = 4; // px of travel before it counts as a drag, not a tap
|
||||||
|
|
||||||
|
var btnPos = null; // {left, top} once placed; persisted on drop
|
||||||
|
var dragging = false;
|
||||||
|
var dragMoved = false;
|
||||||
|
var dragStart = null;
|
||||||
|
|
||||||
|
function readBtnPos() {
|
||||||
|
try {
|
||||||
|
var o = JSON.parse(localStorage.getItem(BTN_POS_KEY) || 'null');
|
||||||
|
if (o && typeof o.left === 'number' && typeof o.top === 'number') return o;
|
||||||
|
} catch (e) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeBtnPos(pos) {
|
||||||
|
try { localStorage.setItem(BTN_POS_KEY, JSON.stringify(pos)); } catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clampPos(left, top, w, h) {
|
||||||
|
var maxLeft = Math.max(BTN_MARGIN, window.innerWidth - w - BTN_MARGIN);
|
||||||
|
var maxTop = Math.max(BTN_MARGIN, window.innerHeight - h - BTN_MARGIN);
|
||||||
|
return {
|
||||||
|
left: Math.round(Math.min(Math.max(left, BTN_MARGIN), maxLeft)),
|
||||||
|
top: Math.round(Math.min(Math.max(top, BTN_MARGIN), maxTop))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The default spot: the old fixed corner, expressed in left/top. */
|
||||||
|
function defaultPos(b) {
|
||||||
|
return { left: window.innerWidth - b.offsetWidth - 16,
|
||||||
|
top: window.innerHeight - b.offsetHeight - 120 };
|
||||||
|
}
|
||||||
|
|
||||||
|
function placeButton(b, pos) {
|
||||||
|
var p = pos || defaultPos(b);
|
||||||
|
var c = clampPos(p.left, p.top, b.offsetWidth, b.offsetHeight);
|
||||||
|
b.style.left = c.left + 'px';
|
||||||
|
b.style.top = c.top + 'px';
|
||||||
|
b.style.right = 'auto';
|
||||||
|
b.style.bottom = 'auto';
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetButtonPos() {
|
||||||
|
if (!btn) return;
|
||||||
|
try { localStorage.removeItem(BTN_POS_KEY); } catch (e) {}
|
||||||
|
btnPos = placeButton(btn, null);
|
||||||
|
positionPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
function installDrag(b) {
|
||||||
|
b.addEventListener('pointerdown', function (ev) {
|
||||||
|
if (ev.button != null && ev.button !== 0) return; // primary button / touch only
|
||||||
|
var r = b.getBoundingClientRect();
|
||||||
|
dragging = true;
|
||||||
|
dragMoved = false;
|
||||||
|
dragStart = { x: ev.clientX, y: ev.clientY, left: r.left, top: r.top };
|
||||||
|
b.classList.add('jfvr-drag');
|
||||||
|
try { b.setPointerCapture(ev.pointerId); } catch (e) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
b.addEventListener('pointermove', function (ev) {
|
||||||
|
if (!dragging || !dragStart) return;
|
||||||
|
var dx = ev.clientX - dragStart.x;
|
||||||
|
var dy = ev.clientY - dragStart.y;
|
||||||
|
if (!dragMoved) {
|
||||||
|
if (Math.abs(dx) < DRAG_SLOP && Math.abs(dy) < DRAG_SLOP) return;
|
||||||
|
dragMoved = true;
|
||||||
|
if (panel) hidePanel(); // do not drag the panel around with it
|
||||||
|
}
|
||||||
|
btnPos = clampPos(dragStart.left + dx, dragStart.top + dy, b.offsetWidth, b.offsetHeight);
|
||||||
|
b.style.left = btnPos.left + 'px';
|
||||||
|
b.style.top = btnPos.top + 'px';
|
||||||
|
});
|
||||||
|
|
||||||
|
function endDrag(ev) {
|
||||||
|
if (!dragging) return;
|
||||||
|
dragging = false;
|
||||||
|
dragStart = null;
|
||||||
|
b.classList.remove('jfvr-drag');
|
||||||
|
try { b.releasePointerCapture(ev.pointerId); } catch (e) {}
|
||||||
|
if (dragMoved) writeBtnPos(btnPos);
|
||||||
|
}
|
||||||
|
b.addEventListener('pointerup', endDrag);
|
||||||
|
b.addEventListener('pointercancel', endDrag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Put the panel next to the button: above it, or below when there is no room. */
|
||||||
|
function positionPanel() {
|
||||||
|
if (!panel || !btn) return;
|
||||||
|
var b = btn.getBoundingClientRect();
|
||||||
|
var w = panel.offsetWidth;
|
||||||
|
var h = panel.offsetHeight;
|
||||||
|
var gap = 8;
|
||||||
|
|
||||||
|
var left = b.right - w; // right edges aligned
|
||||||
|
var top = b.top - h - gap;
|
||||||
|
if (top < BTN_MARGIN) top = b.bottom + gap; // no room above -> below
|
||||||
|
|
||||||
|
var maxLeft = Math.max(BTN_MARGIN, window.innerWidth - w - BTN_MARGIN);
|
||||||
|
var maxTop = Math.max(BTN_MARGIN, window.innerHeight - h - BTN_MARGIN);
|
||||||
|
panel.style.left = Math.round(Math.min(Math.max(left, BTN_MARGIN), maxLeft)) + 'px';
|
||||||
|
panel.style.top = Math.round(Math.min(Math.max(top, BTN_MARGIN), maxTop)) + 'px';
|
||||||
|
panel.style.right = 'auto';
|
||||||
|
panel.style.bottom = 'auto';
|
||||||
|
}
|
||||||
|
|
||||||
|
function onViewportResize() {
|
||||||
|
if (btn && document.body.contains(btn)) btnPos = placeButton(btn, btnPos);
|
||||||
|
positionPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeButton() {
|
function removeButton() {
|
||||||
@@ -5462,6 +5792,7 @@
|
|||||||
panel.appendChild(foot);
|
panel.appendChild(foot);
|
||||||
|
|
||||||
document.body.appendChild(panel);
|
document.body.appendChild(panel);
|
||||||
|
positionPanel();
|
||||||
|
|
||||||
panelSync = function () {
|
panelSync = function () {
|
||||||
for (var i = 0; i < panelSyncs.length; i++) {
|
for (var i = 0; i < panelSyncs.length; i++) {
|
||||||
@@ -6873,6 +7204,9 @@
|
|||||||
window.addEventListener('beforeunload', function () {
|
window.addEventListener('beforeunload', function () {
|
||||||
if (S.session) { try { S.session.end(); } catch (e) {} }
|
if (S.session) { try { S.session.end(); } catch (e) {} }
|
||||||
});
|
});
|
||||||
|
// Keep the draggable button (and the panel that follows it) on screen when
|
||||||
|
// the window changes size.
|
||||||
|
window.addEventListener('resize', onViewportResize);
|
||||||
installFrameTracker();
|
installFrameTracker();
|
||||||
|
|
||||||
window.__JFVR_STATE__ = S;
|
window.__JFVR_STATE__ = S;
|
||||||
|
|||||||
@@ -7,6 +7,46 @@
|
|||||||
"owner": "cat-shark",
|
"owner": "cat-shark",
|
||||||
"category": "General",
|
"category": "General",
|
||||||
"versions": [
|
"versions": [
|
||||||
|
{
|
||||||
|
"version": "0.5.3.0",
|
||||||
|
"targetAbi": "12.0.0.0",
|
||||||
|
"changelog": "Bundle version: `99e506`\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.5.3.0/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||||
|
"checksum": "657AA20A07471AAE96AD5B36E5875A18",
|
||||||
|
"timestamp": "2026-10-19T15:51:07"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.5.2.0",
|
||||||
|
"targetAbi": "12.0.0.0",
|
||||||
|
"changelog": "Bundle version: `16ae94`\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.5.2.0/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||||
|
"checksum": "C5BD8E8C384642D4502BE1A0F80B8E68",
|
||||||
|
"timestamp": "2026-10-19T15:01:57"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.5.1.0",
|
||||||
|
"targetAbi": "12.0.0.0",
|
||||||
|
"changelog": "Bundle version: `3e611e`\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.5.1.0/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||||
|
"checksum": "54AB6541A1BFD7A62636A435350821E0",
|
||||||
|
"timestamp": "2026-10-18T03:57:47"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.5.0.0",
|
||||||
|
"targetAbi": "12.0.0.0",
|
||||||
|
"changelog": "Bundle version: `72681d`\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.5.0.0/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||||
|
"checksum": "F9773C70C9CC4858AF042E40D5CFBAA9",
|
||||||
|
"timestamp": "2026-10-17T17:34:28"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"version": "0.4.0.0",
|
||||||
|
"targetAbi": "12.0.0.0",
|
||||||
|
"changelog": "Bundle version: `ae28bd`\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.4.0.0/Jellyfin.Plugin.JFVR_12.0.0.0.zip",
|
||||||
|
"checksum": "30A0E388FFD6A3D88C73DAB5928C6388",
|
||||||
|
"timestamp": "2026-10-17T17:20:34"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"version": "0.3.0.0",
|
"version": "0.3.0.0",
|
||||||
"targetAbi": "12.0.0.0",
|
"targetAbi": "12.0.0.0",
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@
|
|||||||
# (InstallationManager.GetAvailablePackages), so one package covers all of 12.x.
|
# (InstallationManager.GetAvailablePackages), so one package covers all of 12.x.
|
||||||
name: "Jellyfin Web VR"
|
name: "Jellyfin Web VR"
|
||||||
guid: "7d33ef59-f9b0-412b-93bd-5cd5353018de"
|
guid: "7d33ef59-f9b0-412b-93bd-5cd5353018de"
|
||||||
version: "0.3.0.0"
|
version: "0.5.3.0"
|
||||||
targetAbi: "12.0.0.0"
|
targetAbi: "12.0.0.0"
|
||||||
framework: "net10.0"
|
framework: "net10.0"
|
||||||
overview: "VR180/VR360 playback inside Jellyfin Web for Meta Quest 3."
|
overview: "VR180/VR360 playback inside Jellyfin Web for Meta Quest 3."
|
||||||
|
|||||||
+166
-29
@@ -312,6 +312,7 @@
|
|||||||
/* MediaCapabilities verdicts, keyed '<profile_idc>:<level>'. See below. */
|
/* MediaCapabilities verdicts, keyed '<profile_idc>:<level>'. See below. */
|
||||||
codec: {},
|
codec: {},
|
||||||
codecBlocked: [],
|
codecBlocked: [],
|
||||||
|
codecKept: [],
|
||||||
cptPatched: false,
|
cptPatched: false,
|
||||||
cptMode: null
|
cptMode: null
|
||||||
};
|
};
|
||||||
@@ -351,24 +352,77 @@
|
|||||||
* DirectPlay. Meta's browser-video docs recommend exactly this API over UA
|
* DirectPlay. Meta's browser-video docs recommend exactly this API over UA
|
||||||
* sniffing.
|
* sniffing.
|
||||||
*
|
*
|
||||||
* Only `supported === false` downgrades. `supported:true, smooth:false` is
|
* A tier is blocked when:
|
||||||
* 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:
|
* supported === false the decoder cannot handle the format at all
|
||||||
* localStorage['jfvr-cpt'] = 'off' then reload
|
* smooth === false it can, but not in real time at that resolution and
|
||||||
|
* frame rate -- the "decoder exists, 8K does not work"
|
||||||
|
* case
|
||||||
|
*
|
||||||
|
* AND, for a Main 10 tier, only when the SAME LEVEL IS ALSO UNUSABLE IN MAIN
|
||||||
|
* (8-bit). That second condition is not cosmetic; it is forced by a real
|
||||||
|
* limitation in Jellyfin's device profile.
|
||||||
|
*
|
||||||
|
* browserDeviceProfile.js derives the level ceiling and the profile list from
|
||||||
|
* ONE chain of Main 10 probes -- the only Main (8-bit) probes are L4.0 and
|
||||||
|
* L4.1. So the reachable states are only:
|
||||||
|
*
|
||||||
|
* (120, main) (123, main) (123, main|main 10) (153, main|main 10)
|
||||||
|
* (183, main|main 10) (186, main|main 10)
|
||||||
|
*
|
||||||
|
* "Main up to 8K, Main 10 only up to 4K" is NOT expressible. So blocking
|
||||||
|
* 2:183 on a device that decodes 8-bit 8K but not 10-bit 8K does not just
|
||||||
|
* spare the 10-bit file -- it drags every 8-bit 8K file down to level 153 and
|
||||||
|
* transcodes them too. On a server that cannot transcode 8K in real time
|
||||||
|
* (measured: 8192x4096 -> 1280x640), that trades one broken file for sixty.
|
||||||
|
*
|
||||||
|
* Verified on the machine this was written for: NVIDIA VAAPI decodes
|
||||||
|
* 8192x4096 Main 8-bit fine and fails to create a decoder for 8192x4096
|
||||||
|
* Main 10 (nvidia-vaapi-driver passes the surface bit depth straight to
|
||||||
|
* cuvidCreateDecoder). Its whole library is 8-bit 8K, so lowering the ceiling
|
||||||
|
* would have broken all of it.
|
||||||
|
*
|
||||||
|
* The cost of this rule: a device that decodes 8-bit at a level but not
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// decodingInfo needs real dimensions; a level string does not carry them, so
|
// decodingInfo needs real dimensions; a level string does not carry them, so
|
||||||
// each level is probed at the resolution it exists for.
|
// each level is probed at the resolution and bitrate it exists for. Main
|
||||||
|
// (8-bit) is probed at the same levels as Main 10 because it is the control
|
||||||
|
// that decides whether a level is really out of reach.
|
||||||
|
//
|
||||||
|
// NOTE on the codec strings: they MUST carry a constraint byte. Chrome's
|
||||||
|
// MediaCapabilities.decodingInfo does not recognise the bare 'hvc1.1.L120'
|
||||||
|
// spelling and answers supported:false for it even on a machine that decodes
|
||||||
|
// HEVC perfectly, while 'hvc1.1.0.L120' is answered correctly. That one
|
||||||
|
// character used to matter far more than it looks: browserDeviceProfile.js
|
||||||
|
// gates the WHOLE hevc entry on supportsHevc(), which is exactly
|
||||||
|
//
|
||||||
|
// canPlayType('...codecs="hvc1.1.L120"') ||
|
||||||
|
// canPlayType('...codecs="hev1.1.L120"') ||
|
||||||
|
// canPlayType('...codecs="hvc1.1.0.L120"') || ...
|
||||||
|
//
|
||||||
|
// so a spurious block of tier 1:120 (all spellings map to it) removes hevc
|
||||||
|
// from every DirectPlayProfile and transcode every HEVC file in the library.
|
||||||
|
// 1:120 is NOT part of Jellyfin's level chain; it is only that gate.
|
||||||
var CODEC_PROBES = [
|
var CODEC_PROBES = [
|
||||||
{ key: '1:120', name: 'Main L4.0', w: 1920, h: 1080, fps: 30, codec: 'hvc1.1.L120' },
|
{ key: '1:120', name: 'Main L4.0', w: 1920, h: 1080, fps: 30, mbps: 8, codec: 'hvc1.1.0.L120' },
|
||||||
{ key: '1:123', name: 'Main L4.1', w: 1920, h: 1080, fps: 60, codec: 'hvc1.1.4.L123' },
|
{ key: '1:123', name: 'Main L4.1', w: 1920, h: 1080, fps: 60, mbps: 8, 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: '1:153', name: 'Main L5.1 (4K)', w: 3840, h: 2160, fps: 60, mbps: 20, codec: 'hvc1.1.5.L153.B0' },
|
||||||
{ key: '2:123', name: 'Main10 L4.1', w: 1920, h: 1080, fps: 60, codec: 'hvc1.2.4.L123' },
|
{ key: '1:183', name: 'Main L6.1 (8K)', w: 8192, h: 4096, fps: 60, mbps: 30, codec: 'hvc1.1.6.L183.B0' },
|
||||||
{ key: '2:153', name: 'Main10 L5.1 (4K)', w: 3840, h: 2160, fps: 60, codec: 'hvc1.2.4.L153' },
|
{ key: '1:186', name: 'Main L6.2 (8K60)', w: 8192, h: 4096, fps: 60, mbps: 30, codec: 'hvc1.1.6.L186.B0' },
|
||||||
{ key: '2:183', name: 'Main10 L6.1 (8K)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.2.4.L183' },
|
{ key: '2:123', name: 'Main10 L4.1', w: 1920, h: 1080, fps: 60, mbps: 8, codec: 'hvc1.2.4.L123' },
|
||||||
{ key: '2:186', name: 'Main10 L6.2 (8K60)', w: 8192, h: 4096, fps: 60, codec: 'hvc1.2.4.L186' }
|
{ key: '2:153', name: 'Main10 L5.1 (4K)', w: 3840, h: 2160, fps: 60, mbps: 20, codec: 'hvc1.2.4.L153' },
|
||||||
|
{ key: '2:183', name: 'Main10 L6.1 (8K)', w: 8192, h: 4096, fps: 60, mbps: 30, codec: 'hvc1.2.4.L183' },
|
||||||
|
{ key: '2:186', name: 'Main10 L6.2 (8K60)', w: 8192, h: 4096, fps: 60, mbps: 30, codec: 'hvc1.2.4.L186' }
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -419,11 +473,78 @@
|
|||||||
* MediaCapabilities probe + canPlayType override
|
* MediaCapabilities probe + canPlayType override
|
||||||
* ------------------------------------------------------------------ */
|
* ------------------------------------------------------------------ */
|
||||||
|
|
||||||
|
/** Tiers the user has pinned as "keep claiming this", '<key>,<key>' in localStorage. */
|
||||||
|
function readKeepList() {
|
||||||
|
try {
|
||||||
|
var raw = localStorage.getItem('jfvr-cpt-keep') || '';
|
||||||
|
return raw.split(',').map(function (s) { return s.trim(); }).filter(Boolean);
|
||||||
|
} catch (e) { return []; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Why a verdict means "do not claim this tier", or null if it is fine. */
|
||||||
|
function blockReason(v, keep) {
|
||||||
|
if (!v || v.error) return null; // unknown -> leave it to the browser
|
||||||
|
if (keep.indexOf(v.key) >= 0) return null; // user pinned it
|
||||||
|
if (v.supported === false) return 'unsupported';
|
||||||
|
if (v.smooth === false) return 'not-smooth';
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** True when this tier is not usable on its own terms. */
|
||||||
|
function tierUnusable(key) {
|
||||||
|
var v = NS.caps.codec[key];
|
||||||
|
return !!v && !v.error && (v.supported === false || v.smooth === false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The decision the canPlayType hook uses.
|
||||||
|
*
|
||||||
|
* A Main 10 tier is only blocked when the SAME LEVEL is also unusable in Main
|
||||||
|
* (8-bit). See the long comment above CODEC_PROBES: Jellyfin's profile cannot
|
||||||
|
* express "Main up to 8K, Main 10 up to 4K", so blocking 2:183 on a device
|
||||||
|
* that handles 8-bit 8K would drag all of its 8-bit 8K files into transcoding.
|
||||||
|
*/
|
||||||
|
function shouldBlock(key, keep) {
|
||||||
|
var v = NS.caps.codec[key];
|
||||||
|
if (!v || v.error) return null;
|
||||||
|
if (keep.indexOf(key) >= 0) return null;
|
||||||
|
var own = blockReason(v, keep);
|
||||||
|
if (!own) return null;
|
||||||
|
var parts = key.split(':');
|
||||||
|
|
||||||
|
// Base tier. 1:120 is not in Jellyfin's level chain -- it is only the
|
||||||
|
// coarse "does this client have HEVC at all" gate (supportsHevc() in
|
||||||
|
// browserDeviceProfile.js, which probes exactly this level). Blocking it
|
||||||
|
// drops hevc from every DirectPlayProfile, i.e. transcodes the entire
|
||||||
|
// HEVC library. Never act on it unless the device is unusable at EVERY
|
||||||
|
// Main tier, so one flaky/early probe cannot do that.
|
||||||
|
if (key === '1:120') {
|
||||||
|
var anyMainUsable = CODEC_PROBES.some(function (p) {
|
||||||
|
if (p.key === '1:120' || p.key.charAt(0) !== '1') return false;
|
||||||
|
var m = NS.caps.codec[p.key];
|
||||||
|
return !!m && !m.error && m.supported !== false && m.smooth !== false;
|
||||||
|
});
|
||||||
|
if (anyMainUsable) return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts[0] === '2') {
|
||||||
|
// Control: the same level in Main (8-bit).
|
||||||
|
if (!tierUnusable('1:' + parts[1])) return null;
|
||||||
|
}
|
||||||
|
return own;
|
||||||
|
}
|
||||||
|
|
||||||
function applyVerdicts() {
|
function applyVerdicts() {
|
||||||
NS.caps.codecBlocked = CODEC_PROBES.filter(function (p) {
|
var keep = NS.caps.__keep || [];
|
||||||
|
NS.caps.codecKept = [];
|
||||||
|
NS.caps.codecBlocked = [];
|
||||||
|
CODEC_PROBES.forEach(function (p) {
|
||||||
var v = NS.caps.codec[p.key];
|
var v = NS.caps.codec[p.key];
|
||||||
return v && v.supported === false;
|
if (!v) return;
|
||||||
}).map(function (p) { return p.name; });
|
var why = shouldBlock(p.key, keep);
|
||||||
|
if (why) NS.caps.codecBlocked.push(p.name + ' (' + why + ')');
|
||||||
|
else if (keep.indexOf(p.key) >= 0) NS.caps.codecKept.push(p.name);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function installCanPlayTypeOverride() {
|
function installCanPlayTypeOverride() {
|
||||||
@@ -435,9 +556,8 @@
|
|||||||
proto.canPlayType = function (type) {
|
proto.canPlayType = function (type) {
|
||||||
try {
|
try {
|
||||||
var key = hevcKey(type);
|
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.
|
// Only a definite "no" is acted on. Anything else is the browser's call.
|
||||||
if (v && v.supported === false) return '';
|
if (key && shouldBlock(key, NS.caps.__keep || [])) return '';
|
||||||
} catch (e) { /* never break the native answer */ }
|
} catch (e) { /* never break the native answer */ }
|
||||||
return orig.apply(this, arguments);
|
return orig.apply(this, arguments);
|
||||||
};
|
};
|
||||||
@@ -446,17 +566,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
(function probeCodecs() {
|
(function probeCodecs() {
|
||||||
// Kill switch, and the escape hatch if this ever misbehaves on a device.
|
// Native behavior is the default: do NOT install the canPlayType override,
|
||||||
try {
|
// so Jellyfin builds its own device profile exactly as it would without this
|
||||||
if (localStorage.getItem('jfvr-cpt') === 'off') { NS.caps.cptMode = 'off'; return; }
|
// plugin. Opt back in with localStorage['jfvr-cpt'] = 'on' when diagnosing.
|
||||||
} catch (e) {}
|
// 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;
|
var mc = navigator.mediaCapabilities;
|
||||||
if (!mc || typeof mc.decodingInfo !== 'function') { NS.caps.cptMode = 'no-api'; return; }
|
if (!mc || typeof mc.decodingInfo !== 'function') { NS.caps.cptMode = 'no-api'; return; }
|
||||||
|
|
||||||
|
// Read the pin list once, up front: canPlayType is synchronous and must not
|
||||||
|
// touch localStorage on every call.
|
||||||
|
NS.caps.__keep = readKeepList();
|
||||||
|
|
||||||
// Install FIRST, synchronously, so the hook is in place before anything can
|
// Install FIRST, synchronously, so the hook is in place before anything can
|
||||||
// read canPlayType. Until a verdict lands the hook just defers to native,
|
// read canPlayType. Until a verdict lands the hook just defers to native,
|
||||||
// which is the safe default.
|
// which is the safe default.
|
||||||
installCanPlayTypeOverride();
|
if (hookOn) installCanPlayTypeOverride();
|
||||||
|
|
||||||
var pending = CODEC_PROBES.length;
|
var pending = CODEC_PROBES.length;
|
||||||
CODEC_PROBES.forEach(function (p) {
|
CODEC_PROBES.forEach(function (p) {
|
||||||
@@ -464,20 +593,22 @@
|
|||||||
type: 'file',
|
type: 'file',
|
||||||
video: {
|
video: {
|
||||||
contentType: 'video/mp4; codecs="' + p.codec + '"',
|
contentType: 'video/mp4; codecs="' + p.codec + '"',
|
||||||
width: p.w, height: p.h, bitrate: 20000000, framerate: p.fps
|
width: p.w, height: p.h, bitrate: p.mbps * 1000000, framerate: p.fps
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mc.decodingInfo(cfg).then(function (info) {
|
mc.decodingInfo(cfg).then(function (info) {
|
||||||
NS.caps.codec[p.key] = {
|
NS.caps.codec[p.key] = {
|
||||||
name: p.name, workload: p.w + 'x' + p.h + '@' + p.fps,
|
key: p.key, name: p.name, workload: p.w + 'x' + p.h + '@' + p.fps + ' ' + p.mbps + 'Mbps',
|
||||||
supported: info.supported, smooth: info.smooth, powerEfficient: info.powerEfficient
|
supported: info.supported, smooth: info.smooth, powerEfficient: info.powerEfficient
|
||||||
};
|
};
|
||||||
}).catch(function (e) {
|
}).catch(function (e) {
|
||||||
NS.caps.codec[p.key] = { name: p.name, error: String(e && e.message || e) };
|
NS.caps.codec[p.key] = { key: p.key, name: p.name, error: String(e && e.message || e) };
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
if (--pending === 0) {
|
if (--pending === 0) {
|
||||||
applyVerdicts();
|
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(', ') : ''));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -485,13 +616,19 @@
|
|||||||
|
|
||||||
NS.capsDiag = function () {
|
NS.capsDiag = function () {
|
||||||
var c = NS.caps;
|
var c = NS.caps;
|
||||||
|
var keep = readKeepList();
|
||||||
var real = CODEC_PROBES.map(function (p) {
|
var real = CODEC_PROBES.map(function (p) {
|
||||||
var v = c.codec[p.key];
|
var v = c.codec[p.key];
|
||||||
if (!v) return ' ' + p.name.padEnd(20) + ' (pending)';
|
if (!v) return ' ' + p.name.padEnd(20) + ' (pending)';
|
||||||
if (v.error) return ' ' + p.name.padEnd(20) + ' error: ' + v.error;
|
if (v.error) return ' ' + p.name.padEnd(20) + ' error: ' + v.error;
|
||||||
|
var why = shouldBlock(p.key, keep);
|
||||||
|
var own = blockReason(v, keep);
|
||||||
|
var note = why ? ' <-- BLOCKED (' + why + ')' :
|
||||||
|
(own ? ' (unusable, but kept: 8-bit at this level works)' :
|
||||||
|
(keep.indexOf(p.key) >= 0 ? ' <-- pinned' : ''));
|
||||||
return ' ' + p.name.padEnd(20) + ' supported=' + v.supported +
|
return ' ' + p.name.padEnd(20) + ' supported=' + v.supported +
|
||||||
' smooth=' + v.smooth + ' powerEfficient=' + v.powerEfficient +
|
' smooth=' + v.smooth + ' powerEfficient=' + v.powerEfficient +
|
||||||
' [' + v.workload + ']' + (v.supported === false ? ' <-- BLOCKED' : '');
|
' [' + v.workload + ']' + note;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
@@ -505,7 +642,7 @@
|
|||||||
'MAX_TEXTURE_SIZE : ' + c.maxTextureSize,
|
'MAX_TEXTURE_SIZE : ' + c.maxTextureSize,
|
||||||
'HEVC canPlayType : ' + JSON.stringify(c.hevc),
|
'HEVC canPlayType : ' + JSON.stringify(c.hevc),
|
||||||
'canPlayType hook : ' + (c.cptMode || 'pending') +
|
'canPlayType hook : ' + (c.cptMode || 'pending') +
|
||||||
(c.cptMode === 'on' ? ' (downgraded: ' + (c.codecBlocked.join(', ') || 'nothing yet') + ')' : ''),
|
(c.cptMode === 'on' ? ' (blocked: ' + (c.codecBlocked.join(', ') || 'nothing yet') + ')' : ''),
|
||||||
'HEVC real (decodingInfo):',
|
'HEVC real (decodingInfo):',
|
||||||
real
|
real
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|||||||
+56
-12
@@ -59,6 +59,15 @@
|
|||||||
var DEAD_MS = 15000;
|
var DEAD_MS = 15000;
|
||||||
var DEAD_TRANSCODE_MS = 45000;
|
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
|
// After the user answers (either way) stay quiet, so a slow-but-working
|
||||||
// playback does not get nagged at.
|
// playback does not get nagged at.
|
||||||
var QUIET_MS = 120000;
|
var QUIET_MS = 120000;
|
||||||
@@ -79,7 +88,9 @@
|
|||||||
lastReason: '',
|
lastReason: '',
|
||||||
applied: null,
|
applied: null,
|
||||||
codec: null, // filled in best-effort from the Jellyfin API
|
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;
|
NS.Watchdog = W;
|
||||||
|
|
||||||
@@ -105,7 +116,7 @@
|
|||||||
return src.indexOf('/hls') >= 0 || src.indexOf('.m3u8') >= 0;
|
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) {
|
function hasPicture(v) {
|
||||||
return v.videoWidth > 0 && v.readyState >= 2;
|
return v.videoWidth > 0 && v.readyState >= 2;
|
||||||
}
|
}
|
||||||
@@ -247,17 +258,25 @@
|
|||||||
|
|
||||||
var p = NS.makeEl('div', 'jfvr-wd');
|
var p = NS.makeEl('div', 'jfvr-wd');
|
||||||
p.id = '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 body = NS.makeEl('div', 'jfvr-wd-body');
|
||||||
|
|
||||||
var msg = NS.makeEl('p');
|
var msg = NS.makeEl('p');
|
||||||
var waited = Math.round(timeoutMs(v) / 1000);
|
var waited = Math.round(timeoutMs(v) / 1000);
|
||||||
|
var intro;
|
||||||
|
if (reason === 'error') {
|
||||||
|
intro = '播放器报错了,一个画面都没解出来。';
|
||||||
|
} else if (reason === 'stalled') {
|
||||||
|
intro = '画面已经出来了,但播放进度停住不动了(<code>currentTime</code> 不再前进)—— ' +
|
||||||
|
'解码器跟不上这个文件。';
|
||||||
|
} else {
|
||||||
|
intro = '等了 ' + waited + ' 秒都没拿到任何画面(<code>videoWidth = 0</code>),' +
|
||||||
|
'所以播放器界面也没有被创建出来。';
|
||||||
|
}
|
||||||
msg.innerHTML =
|
msg.innerHTML =
|
||||||
(reason === 'error'
|
intro +
|
||||||
? '播放器报错了,一个画面都没解出来。'
|
|
||||||
: '等了 ' + waited + ' 秒都没拿到任何画面(<code>videoWidth = 0</code>),' +
|
|
||||||
'所以播放器界面也没有被创建出来。') +
|
|
||||||
'最常见的原因是<strong>这台设备解不动这个格式</strong>:' +
|
'最常见的原因是<strong>这台设备解不动这个格式</strong>:' +
|
||||||
'<span class="jfvr-wd-fmt">' + (W.codec || '该格式') + '</span>。<br>' +
|
'<span class="jfvr-wd-fmt">' + (W.codec || '该格式') + '</span>。<br>' +
|
||||||
'让服务器转码成 H.264 再播就能看到画面,代价是画质下降(这台 NAS 的转码上限约 4K)。';
|
'让服务器转码成 H.264 再播就能看到画面,代价是画质下降(这台 NAS 的转码上限约 4K)。';
|
||||||
@@ -299,7 +318,7 @@
|
|||||||
W.panel = p;
|
W.panel = p;
|
||||||
|
|
||||||
NS.recordError('watchdog', new Error('playback never started: ' + reason));
|
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() {
|
function hide() {
|
||||||
@@ -309,6 +328,8 @@
|
|||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
W.seenAt = 0;
|
W.seenAt = 0;
|
||||||
|
W.lastTime = -1;
|
||||||
|
W.progressAt = 0;
|
||||||
W.codec = null;
|
W.codec = null;
|
||||||
if (W.shown) hide();
|
if (W.shown) hide();
|
||||||
}
|
}
|
||||||
@@ -329,9 +350,6 @@
|
|||||||
var v = playerVideo();
|
var v = playerVideo();
|
||||||
if (!v) { reset(); return; }
|
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.
|
// A media error is unambiguous — no need to wait out the timer.
|
||||||
if (v.error) {
|
if (v.error) {
|
||||||
describeCodec(v);
|
describeCodec(v);
|
||||||
@@ -340,6 +358,31 @@
|
|||||||
return;
|
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 (!W.seenAt) W.seenAt = now();
|
||||||
if (now() - W.seenAt < timeoutMs(v)) return;
|
if (now() - W.seenAt < timeoutMs(v)) return;
|
||||||
|
|
||||||
@@ -352,6 +395,7 @@
|
|||||||
NS.Watchdog.init = function () {
|
NS.Watchdog.init = function () {
|
||||||
W.quietUntil = readQuiet();
|
W.quietUntil = readQuiet();
|
||||||
setInterval(poll, POLL_MS);
|
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)');
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
+158
-5
@@ -299,16 +299,23 @@
|
|||||||
// Sits ABOVE Jellyfin's own OSD bar: at the viewport's bottom-right it
|
// Sits ABOVE Jellyfin's own OSD bar: at the viewport's bottom-right it
|
||||||
// covered the player's fullscreen button (owner report). 120 px clears the
|
// covered the player's fullscreen button (owner report). 120 px clears the
|
||||||
// OSD bottom bar; the settings panel stacks above it.
|
// OSD bottom bar; the settings panel stacks above it.
|
||||||
'.jfvr-btn{position:fixed;right:16px;bottom:120px;z-index:2147483000;display:flex;align-items:center;gap:8px;',
|
// left/top are set from JS (see placeButton) so the button can be dragged
|
||||||
|
// anywhere. touch-action:none is what makes a drag work on a touch screen
|
||||||
|
// instead of scrolling the page underneath.
|
||||||
|
'.jfvr-btn{position:fixed;z-index:2147483000;display:flex;align-items:center;gap:8px;',
|
||||||
'padding:10px 16px;border:0;border-radius:24px;background:linear-gradient(135deg,#4ea1ff,#7b5cff);color:#fff;',
|
'padding:10px 16px;border:0;border-radius:24px;background:linear-gradient(135deg,#4ea1ff,#7b5cff);color:#fff;',
|
||||||
'font-size:15px;font-weight:600;cursor:pointer;box-shadow:0 6px 22px rgba(0,0,0,.45);font-family:inherit}',
|
'font-size:15px;font-weight:600;cursor:grab;box-shadow:0 6px 22px rgba(0,0,0,.45);font-family:inherit;',
|
||||||
|
'touch-action:none;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}',
|
||||||
'.jfvr-btn:active{transform:scale(.96)}',
|
'.jfvr-btn:active{transform:scale(.96)}',
|
||||||
|
'.jfvr-btn.jfvr-drag{cursor:grabbing;transform:none;box-shadow:0 10px 32px rgba(0,0,0,.65)}',
|
||||||
// the panel must always fit the viewport AND keep the CTA reachable, so the
|
// the panel must always fit the viewport AND keep the CTA reachable, so the
|
||||||
// body scrolls and the button lives in a sticky footer
|
// body scrolls and the button lives in a sticky footer
|
||||||
'.jfvr-panel{position:fixed;right:16px;bottom:180px;z-index:2147483001;width:290px;background:rgba(20,20,24,.96);',
|
// Positioned from JS (positionPanel) so it follows the button once the
|
||||||
|
// button has been dragged; it no longer lives in the viewport corner.
|
||||||
|
'.jfvr-panel{position:fixed;z-index:2147483001;width:290px;background:rgba(20,20,24,.96);',
|
||||||
'color:#eaeaea;border:1px solid rgba(255,255,255,.14);border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.6);',
|
'color:#eaeaea;border:1px solid rgba(255,255,255,.14);border-radius:14px;box-shadow:0 12px 40px rgba(0,0,0,.6);',
|
||||||
'font-family:inherit;font-size:14px;backdrop-filter:blur(10px);display:flex;flex-direction:column;',
|
'font-family:inherit;font-size:14px;backdrop-filter:blur(10px);display:flex;flex-direction:column;',
|
||||||
'max-height:calc(100vh - 200px);overflow:hidden}',
|
'max-height:calc(100vh - 32px);overflow:hidden}',
|
||||||
'.jfvr-head{display:flex;justify-content:space-between;align-items:center;padding:10px 12px;background:rgba(255,255,255,.06);font-weight:600;flex:0 0 auto}',
|
'.jfvr-head{display:flex;justify-content:space-between;align-items:center;padding:10px 12px;background:rgba(255,255,255,.06);font-weight:600;flex:0 0 auto}',
|
||||||
'.jfvr-x{background:none;border:0;color:#aaa;font-size:20px;line-height:1;cursor:pointer;padding:0 4px}',
|
'.jfvr-x{background:none;border:0;color:#aaa;font-size:20px;line-height:1;cursor:pointer;padding:0 4px}',
|
||||||
'.jfvr-body{padding:12px;overflow-y:auto;flex:1 1 auto;min-height:0}',
|
'.jfvr-body{padding:12px;overflow-y:auto;flex:1 1 auto;min-height:0}',
|
||||||
@@ -356,9 +363,151 @@
|
|||||||
var b = NS.makeEl('button', 'jfvr-btn');
|
var b = NS.makeEl('button', 'jfvr-btn');
|
||||||
b.type = 'button';
|
b.type = 'button';
|
||||||
b.innerHTML = '<span>🎥</span><span>VR 播放</span>';
|
b.innerHTML = '<span>🎥</span><span>VR 播放</span>';
|
||||||
b.addEventListener('click', function (ev) { ev.stopPropagation(); togglePanel(); });
|
b.title = '点击打开设置;按住拖动可以换位置;双击回到默认位置';
|
||||||
|
b.addEventListener('click', function (ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
// A drag still produces a click on most browsers. Swallow that one so
|
||||||
|
// dragging the button never opens the panel by accident.
|
||||||
|
if (dragMoved) { dragMoved = false; return; }
|
||||||
|
togglePanel();
|
||||||
|
});
|
||||||
|
// Escape hatch: a button dragged half off a small window is annoying to
|
||||||
|
// recover by hand.
|
||||||
|
b.addEventListener('dblclick', function (ev) {
|
||||||
|
ev.stopPropagation();
|
||||||
|
resetButtonPos();
|
||||||
|
});
|
||||||
|
installDrag(b);
|
||||||
document.body.appendChild(b);
|
document.body.appendChild(b);
|
||||||
btn = b;
|
btn = b;
|
||||||
|
btnPos = readBtnPos();
|
||||||
|
placeButton(b, btnPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ------------------------------------------------------------------ *
|
||||||
|
* button placement / dragging
|
||||||
|
* ------------------------------------------------------------------
|
||||||
|
* The button used to be pinned to the bottom-right corner. On a short window
|
||||||
|
* that put it right on top of the bitrate choices the playback watchdog
|
||||||
|
* shows (that panel is centred), and there was no way to move it. It is
|
||||||
|
* draggable now and the spot is remembered per browser.
|
||||||
|
*
|
||||||
|
* The settings panel follows the button rather than the viewport corner, so
|
||||||
|
* the two cannot drift apart.
|
||||||
|
* ------------------------------------------------------------------ */
|
||||||
|
var BTN_POS_KEY = 'jfvr-btn-pos';
|
||||||
|
var BTN_MARGIN = 8;
|
||||||
|
var DRAG_SLOP = 4; // px of travel before it counts as a drag, not a tap
|
||||||
|
|
||||||
|
var btnPos = null; // {left, top} once placed; persisted on drop
|
||||||
|
var dragging = false;
|
||||||
|
var dragMoved = false;
|
||||||
|
var dragStart = null;
|
||||||
|
|
||||||
|
function readBtnPos() {
|
||||||
|
try {
|
||||||
|
var o = JSON.parse(localStorage.getItem(BTN_POS_KEY) || 'null');
|
||||||
|
if (o && typeof o.left === 'number' && typeof o.top === 'number') return o;
|
||||||
|
} catch (e) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeBtnPos(pos) {
|
||||||
|
try { localStorage.setItem(BTN_POS_KEY, JSON.stringify(pos)); } catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
function clampPos(left, top, w, h) {
|
||||||
|
var maxLeft = Math.max(BTN_MARGIN, window.innerWidth - w - BTN_MARGIN);
|
||||||
|
var maxTop = Math.max(BTN_MARGIN, window.innerHeight - h - BTN_MARGIN);
|
||||||
|
return {
|
||||||
|
left: Math.round(Math.min(Math.max(left, BTN_MARGIN), maxLeft)),
|
||||||
|
top: Math.round(Math.min(Math.max(top, BTN_MARGIN), maxTop))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** The default spot: the old fixed corner, expressed in left/top. */
|
||||||
|
function defaultPos(b) {
|
||||||
|
return { left: window.innerWidth - b.offsetWidth - 16,
|
||||||
|
top: window.innerHeight - b.offsetHeight - 120 };
|
||||||
|
}
|
||||||
|
|
||||||
|
function placeButton(b, pos) {
|
||||||
|
var p = pos || defaultPos(b);
|
||||||
|
var c = clampPos(p.left, p.top, b.offsetWidth, b.offsetHeight);
|
||||||
|
b.style.left = c.left + 'px';
|
||||||
|
b.style.top = c.top + 'px';
|
||||||
|
b.style.right = 'auto';
|
||||||
|
b.style.bottom = 'auto';
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetButtonPos() {
|
||||||
|
if (!btn) return;
|
||||||
|
try { localStorage.removeItem(BTN_POS_KEY); } catch (e) {}
|
||||||
|
btnPos = placeButton(btn, null);
|
||||||
|
positionPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
function installDrag(b) {
|
||||||
|
b.addEventListener('pointerdown', function (ev) {
|
||||||
|
if (ev.button != null && ev.button !== 0) return; // primary button / touch only
|
||||||
|
var r = b.getBoundingClientRect();
|
||||||
|
dragging = true;
|
||||||
|
dragMoved = false;
|
||||||
|
dragStart = { x: ev.clientX, y: ev.clientY, left: r.left, top: r.top };
|
||||||
|
b.classList.add('jfvr-drag');
|
||||||
|
try { b.setPointerCapture(ev.pointerId); } catch (e) {}
|
||||||
|
});
|
||||||
|
|
||||||
|
b.addEventListener('pointermove', function (ev) {
|
||||||
|
if (!dragging || !dragStart) return;
|
||||||
|
var dx = ev.clientX - dragStart.x;
|
||||||
|
var dy = ev.clientY - dragStart.y;
|
||||||
|
if (!dragMoved) {
|
||||||
|
if (Math.abs(dx) < DRAG_SLOP && Math.abs(dy) < DRAG_SLOP) return;
|
||||||
|
dragMoved = true;
|
||||||
|
if (panel) hidePanel(); // do not drag the panel around with it
|
||||||
|
}
|
||||||
|
btnPos = clampPos(dragStart.left + dx, dragStart.top + dy, b.offsetWidth, b.offsetHeight);
|
||||||
|
b.style.left = btnPos.left + 'px';
|
||||||
|
b.style.top = btnPos.top + 'px';
|
||||||
|
});
|
||||||
|
|
||||||
|
function endDrag(ev) {
|
||||||
|
if (!dragging) return;
|
||||||
|
dragging = false;
|
||||||
|
dragStart = null;
|
||||||
|
b.classList.remove('jfvr-drag');
|
||||||
|
try { b.releasePointerCapture(ev.pointerId); } catch (e) {}
|
||||||
|
if (dragMoved) writeBtnPos(btnPos);
|
||||||
|
}
|
||||||
|
b.addEventListener('pointerup', endDrag);
|
||||||
|
b.addEventListener('pointercancel', endDrag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Put the panel next to the button: above it, or below when there is no room. */
|
||||||
|
function positionPanel() {
|
||||||
|
if (!panel || !btn) return;
|
||||||
|
var b = btn.getBoundingClientRect();
|
||||||
|
var w = panel.offsetWidth;
|
||||||
|
var h = panel.offsetHeight;
|
||||||
|
var gap = 8;
|
||||||
|
|
||||||
|
var left = b.right - w; // right edges aligned
|
||||||
|
var top = b.top - h - gap;
|
||||||
|
if (top < BTN_MARGIN) top = b.bottom + gap; // no room above -> below
|
||||||
|
|
||||||
|
var maxLeft = Math.max(BTN_MARGIN, window.innerWidth - w - BTN_MARGIN);
|
||||||
|
var maxTop = Math.max(BTN_MARGIN, window.innerHeight - h - BTN_MARGIN);
|
||||||
|
panel.style.left = Math.round(Math.min(Math.max(left, BTN_MARGIN), maxLeft)) + 'px';
|
||||||
|
panel.style.top = Math.round(Math.min(Math.max(top, BTN_MARGIN), maxTop)) + 'px';
|
||||||
|
panel.style.right = 'auto';
|
||||||
|
panel.style.bottom = 'auto';
|
||||||
|
}
|
||||||
|
|
||||||
|
function onViewportResize() {
|
||||||
|
if (btn && document.body.contains(btn)) btnPos = placeButton(btn, btnPos);
|
||||||
|
positionPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeButton() {
|
function removeButton() {
|
||||||
@@ -542,6 +691,7 @@
|
|||||||
panel.appendChild(foot);
|
panel.appendChild(foot);
|
||||||
|
|
||||||
document.body.appendChild(panel);
|
document.body.appendChild(panel);
|
||||||
|
positionPanel();
|
||||||
|
|
||||||
panelSync = function () {
|
panelSync = function () {
|
||||||
for (var i = 0; i < panelSyncs.length; i++) {
|
for (var i = 0; i < panelSyncs.length; i++) {
|
||||||
@@ -1953,6 +2103,9 @@
|
|||||||
window.addEventListener('beforeunload', function () {
|
window.addEventListener('beforeunload', function () {
|
||||||
if (S.session) { try { S.session.end(); } catch (e) {} }
|
if (S.session) { try { S.session.end(); } catch (e) {} }
|
||||||
});
|
});
|
||||||
|
// Keep the draggable button (and the panel that follows it) on screen when
|
||||||
|
// the window changes size.
|
||||||
|
window.addEventListener('resize', onViewportResize);
|
||||||
installFrameTracker();
|
installFrameTracker();
|
||||||
|
|
||||||
window.__JFVR_STATE__ = S;
|
window.__JFVR_STATE__ = S;
|
||||||
|
|||||||
Reference in New Issue
Block a user