Add a Quality upscaling tier and make enhancement verifiable
Quality runs ArtCNN C4F32 (its denoising model when Denoising is on), KrigBilateral, debanding and CAS. Its network runs at any enlargement, so 1080p in a maximized 1440p window is doubled and scaled down; Balanced keeps FSRCNNX's 1.3x threshold. The enhancement pipeline moves to player/enhance.ts. Mode changes are serialized (latest wins). Shader errors in mpv's log, or network passes missing from vo-passes, drop to the tier below with a notice, and the chosen and running tiers are shown separately. HDR is judged from the decoded video. Debanding, sharpening and denoising have their own toggles, B compares with enhancement off, and the panel shows the renderer's actual stages, GPU time and dropped frames. Compiled shaders persist in the app cache (gpu-shader-cache-dir): ArtCNN's first Direct3D compile takes about a minute, which the player now announces, and later launches start immediately. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
5efcf2c5a5
commit
9fd2b0603e
11 changed files with 8400 additions and 68 deletions
|
|
@ -4,9 +4,10 @@ import { directUrl, previewUrl, reportTimeline, stopTranscode, transcodeUrl, typ
|
|||
import type { Item, Stream } from '../plex/types';
|
||||
import { useSession } from '../app/session';
|
||||
import { useSettings, SUBTITLE_MARGIN, type Preferences, type Quality, type Upscaling } from '../app/settings';
|
||||
import { noteMpvLog, requestEnhancement, watchPerformance } from './enhance';
|
||||
import { channelLabel } from '../app/format';
|
||||
import { invalidateLibrary } from '../app/queries';
|
||||
import { keepAwake, isNative, resourcePath, win } from '../platform/native';
|
||||
import { keepAwake, isNative, win } from '../platform/native';
|
||||
import { mpv, type MpvEvent, type MpvTrack } from './engine';
|
||||
import { toast } from '../ui/overlays';
|
||||
import { stopThemeMusic } from './theme';
|
||||
|
|
@ -64,6 +65,10 @@ interface PlayerState {
|
|||
/** Playing in the corner while browsing. */
|
||||
mini: boolean;
|
||||
audioDelay: number;
|
||||
/** The upscaling tier actually running (may be below the chosen one), and the before/after bypass. */
|
||||
enhance: { active: Upscaling; bypass: boolean; preparing: boolean };
|
||||
/** Transfer function of the decoded video ('pq', 'hlg', 'bt.1886'…), once known. */
|
||||
videoGamma: string;
|
||||
|
||||
play(item: Item, opts?: PlayOptions): Promise<void>;
|
||||
close(): Promise<void>;
|
||||
|
|
@ -203,43 +208,6 @@ async function applySubtitleStyle(prefs: Preferences = useSettings.getState()) {
|
|||
}
|
||||
}
|
||||
|
||||
/** mpv's own scaler settings, read once so Off can put them back. */
|
||||
const SCALER_PROPS = ['scale', 'cscale', 'dscale', 'sigmoid-upscaling', 'deband', 'deband-iterations', 'deband-grain'] as const;
|
||||
let scalerDefaults: Partial<Record<(typeof SCALER_PROPS)[number], unknown>> | null = null;
|
||||
let shaderDir: Promise<string> | null = null;
|
||||
|
||||
/**
|
||||
* Video enhancement tiers. The bundled shaders decide for themselves when to
|
||||
* run (their WHEN conditions), so one list covers every video and window size:
|
||||
* FSRCNNX doubles luma only when upscaling by more than 1.3×, KrigBilateral
|
||||
* rebuilds subsampled colour, CAS sharpens at native size (CAS-prescale also
|
||||
* before upscaling). CAS assumes SDR gamma, so HDR titles skip it.
|
||||
*/
|
||||
async function applyUpscaling(mode: Upscaling = useSettings.getState().upscaling) {
|
||||
if (!scalerDefaults) {
|
||||
scalerDefaults = {};
|
||||
for (const p of SCALER_PROPS) scalerDefaults[p] = await mpv.get(p).catch(() => undefined);
|
||||
}
|
||||
const st = usePlayer.getState();
|
||||
const hdr = !!st.item?.media[st.mediaIndex]?.dynamicRange;
|
||||
const dir = await (shaderDir ??= resourcePath('shaders').catch(() => ''));
|
||||
// mpv takes a path list: ';'-separated on Windows, ':' elsewhere.
|
||||
const windows = dir.includes('\\');
|
||||
const shaders = (names: string[]) => names.map((n) => `${dir}${windows ? '\\' : '/'}${n}`).join(windows ? ';' : ':');
|
||||
let props: Record<string, unknown>;
|
||||
let list: string[] = [];
|
||||
if (mode === 'performance') {
|
||||
props = { scale: 'spline36', cscale: 'spline36', dscale: 'mitchell', 'sigmoid-upscaling': true, deband: true, 'deband-iterations': 1, 'deband-grain': 24 };
|
||||
if (!hdr) list = ['CAS-prescale.glsl'];
|
||||
} else if (mode === 'balanced') {
|
||||
props = { scale: 'ewa_lanczossharp', cscale: 'ewa_lanczossharp', dscale: 'mitchell', 'sigmoid-upscaling': true, deband: true, 'deband-iterations': 2, 'deband-grain': 16 };
|
||||
list = ['FSRCNNX_x2_8-0-4-1.glsl', 'KrigBilateral.glsl', ...(hdr ? [] : ['CAS.glsl'])];
|
||||
} else props = { ...scalerDefaults };
|
||||
for (const [k, v] of Object.entries(props)) if (v !== undefined) await mpv.set(k, v).catch(() => {});
|
||||
if (dir && list.length) await mpv.set('glsl-shaders', shaders(list)).catch((e) => console.warn('[upscaling]', e));
|
||||
else await mpv.command('change-list', 'glsl-shaders', 'clr', '').catch(() => {});
|
||||
}
|
||||
|
||||
function report(state: 'playing' | 'paused' | 'buffering' | 'stopped') {
|
||||
const s = server();
|
||||
const { item, position, delivery } = usePlayer.getState();
|
||||
|
|
@ -426,6 +394,11 @@ function onEvent(e: MpvEvent) {
|
|||
break;
|
||||
case 'video-params':
|
||||
if (v?.w) usePlayer.setState({ video: { ...(st.video ?? { hwdec: '', codec: '' }), width: v.w, height: v.h } });
|
||||
// Enhancement follows the decoded video's transfer (HDR skips SDR-tuned stages).
|
||||
if (v?.gamma && v.gamma !== st.videoGamma) {
|
||||
usePlayer.setState({ videoGamma: v.gamma });
|
||||
requestEnhancement();
|
||||
}
|
||||
break;
|
||||
case 'hwdec-current':
|
||||
usePlayer.setState({ video: { ...(st.video ?? { width: 0, height: 0, codec: '' }), hwdec: v ?? '' } });
|
||||
|
|
@ -467,6 +440,7 @@ function onEvent(e: MpvEvent) {
|
|||
} else if (e.reason === 'eof') onEnded();
|
||||
break;
|
||||
case 'log':
|
||||
noteMpvLog(e.level, e.prefix, e.text);
|
||||
if (e.level === 'error' && /http|stream|open/i.test(e.prefix + e.text) && !st.firstFrame) console.warn('[mpv]', e.prefix, e.text);
|
||||
break;
|
||||
}
|
||||
|
|
@ -530,6 +504,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
fullscreen: false,
|
||||
mini: false,
|
||||
audioDelay: 0,
|
||||
enhance: { active: 'off', bypass: false, preparing: false },
|
||||
videoGamma: '',
|
||||
|
||||
async play(input, opts = {}) {
|
||||
const token = ++loadToken;
|
||||
|
|
@ -572,6 +548,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
video: null,
|
||||
fullscreen: wasFullscreenBeforePlay,
|
||||
mini: false,
|
||||
videoGamma: '',
|
||||
enhance: { ...previous.enhance, bypass: false, preparing: false },
|
||||
});
|
||||
|
||||
try {
|
||||
|
|
@ -627,7 +605,8 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
await mpv.set('speed', 1);
|
||||
await mpv.set('audio-delay', 0);
|
||||
await applySubtitleStyle(prefs);
|
||||
await applyUpscaling(prefs.upscaling);
|
||||
await requestEnhancement();
|
||||
watchPerformance(true);
|
||||
await mpv.set('force-media-title', item.type === 'episode' ? `${item.grandparentTitle} — ${item.title}` : item.title);
|
||||
await mpv.show(true);
|
||||
const fileOpts = [
|
||||
|
|
@ -659,6 +638,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
|
|||
const s = server();
|
||||
if (st.delivery?.session && s) stopTranscode(s, st.delivery.session);
|
||||
keepAwake(false);
|
||||
watchPerformance(false);
|
||||
if (isNative) {
|
||||
await mpv.command('stop').catch(() => {});
|
||||
await mpv.show(false).catch(() => {});
|
||||
|
|
@ -822,8 +802,3 @@ const SUBTITLE_PREFS = ['subtitleScale', 'subtitleColor', 'subtitleEdge', 'subti
|
|||
useSettings.subscribe((prefs, prev) => {
|
||||
if (isNative && usePlayer.getState().open && SUBTITLE_PREFS.some((k) => prefs[k] !== prev[k])) applySubtitleStyle(prefs);
|
||||
});
|
||||
|
||||
/** The enhancement tier, chosen in the player, applies straight away. */
|
||||
useSettings.subscribe((prefs, prev) => {
|
||||
if (isNative && usePlayer.getState().open && prefs.upscaling !== prev.upscaling) applyUpscaling(prefs.upscaling);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue