Add player upscaling and fix miniplayer and scrub bar issues

Upscaling is chosen in the player (Playback options, or U): Performance
uses spline36 scaling, debanding and AMD CAS sharpening; Balanced adds
FSRCNNX neural luma upscaling and KrigBilateral chroma reconstruction.
The shaders ship in src-tauri/shaders and their WHEN conditions decide
whether they run for the current video and window size; HDR titles skip
CAS, which assumes SDR gamma.

The title above the scrub bar now opens its show, movie or episode page
with playback moving to the miniplayer. Leaving the miniplayer any way
(including starting another title, which left the app invisible) puts
the video back over the whole window. The scrub bar separates played
and buffered sections more clearly, and its preview keeps its size at
the end of the bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Elijah 2026-10-30 18:55:52 -07:00
parent 6be6633f64
commit 5dc18ff9e5
13 changed files with 1345 additions and 15 deletions

View file

@ -1,14 +1,16 @@
import { useCallback, useEffect, useRef, useState, type ReactNode } from 'react';
import { usePlayer } from './store';
import { useSession } from '../app/session';
import { useSettings, QUALITY_LABEL, type Quality, type SubtitleBox } from '../app/settings';
import { useSettings, QUALITY_LABEL, UPSCALING, type Quality, type SubtitleBox, type Upscaling } from '../app/settings';
import { bitrate, channelLabel, clock, episodeLabel, resolutionLabel } from '../app/format';
import { Icon } from '../ui/Icon';
import { Facts, TitleArt } from '../ui/media';
import { Button, Spinner } from '../ui/primitives';
import { win, isNative } from '../platform/native';
import { WindowControls } from '../app/TopBar';
import { navigate } from '../app/router';
import { mpv } from './engine';
import { toast } from '../ui/overlays';
import type { Item } from '../plex/types';
const HIDE_AFTER = 3000;
@ -237,7 +239,23 @@ const SUB_BOXES: { value: SubtitleBox; label: string }[] = [
{ value: 'solid', label: 'Solid' },
];
type SettingsView = 'main' | 'audio' | 'subtitles' | 'quality' | 'speed' | 'version' | 'chapters' | 'subSize' | 'subBox';
type SettingsView = 'main' | 'audio' | 'subtitles' | 'quality' | 'upscaling' | 'speed' | 'version' | 'chapters' | 'subSize' | 'subBox';
const UPSCALING_ORDER: Upscaling[] = ['off', 'performance', 'balanced'];
/** What the current tier is doing for this video at this size, for the details list. */
function upscalingDetail(mode: Upscaling, video: { width: number; height: number } | null, hdr: boolean) {
if (mode === 'off') return 'Off';
const dpr = window.devicePixelRatio || 1;
const factor = video && video.width ? Math.min((window.innerWidth * dpr) / video.width, (window.innerHeight * dpr) / video.height) : 1;
const parts = [UPSCALING[mode].label];
if (factor > 1.01) parts.push(`${factor.toFixed(1)}× ${mode === 'balanced' && factor > 1.3 ? 'neural upscale' : 'upscale'}`);
else parts.push('native size');
if (mode === 'balanced') parts.push('colour reconstruction');
parts.push('debanding');
if (!hdr) parts.push('sharpening');
return parts.join(' · ');
}
function SettingsPanel({ onClose }: { onClose: () => void }) {
const st = usePlayer();
@ -286,6 +304,14 @@ function SettingsPanel({ onClose }: { onClose: () => void }) {
))}
</Panel>
);
if (view === 'upscaling')
return (
<Panel title="Upscaling" onClose={onClose} onBack={back}>
{UPSCALING_ORDER.map((m) => (
<Option key={m} selected={prefs.upscaling === m} label={UPSCALING[m].label} detail={UPSCALING[m].detail} onClick={() => (prefs.set('upscaling', m), back())} />
))}
</Panel>
);
if (view === 'speed')
return (
<Panel title="Playback speed" onClose={onClose} onBack={back}>
@ -353,6 +379,7 @@ function SettingsPanel({ onClose }: { onClose: () => void }) {
if (v && v.width > 0)
stats.push(['Video', [`${v.width}×${v.height}`, v.codec.toUpperCase(), source?.dynamicRange, v.hwdec && v.hwdec !== 'no' ? 'Hardware decoding' : 'Software decoding'].filter(Boolean).join(' · ')]);
if (audio) stats.push(['Audio', [audio.label, audio.detail].filter(Boolean).join(' · ')]);
stats.push(['Upscaling', upscalingDetail(prefs.upscaling, v, !!source?.dynamicRange)]);
if (source?.bitrate && !local) stats.push(['Bitrate', st.delivery?.mode === 'transcode' ? `${bitrate(source.bitrate)} source` : bitrate(source.bitrate)]);
if (source?.container) stats.push(['Container', source.container.toUpperCase()]);
@ -361,6 +388,7 @@ function SettingsPanel({ onClose }: { onClose: () => void }) {
{row('Audio', audio ? audio.label : st.audioTracks.length ? 'Choose' : 'None', () => setView('audio'), !st.audioTracks.length)}
{row('Subtitles', sub ? sub.label : 'Off', () => setView('subtitles'))}
{!local && row('Quality', qualityLabel(st.quality), () => setView('quality'))}
{row('Upscaling', UPSCALING[prefs.upscaling].label, () => setView('upscaling'))}
{row('Speed', st.speed === 1 ? 'Normal' : `${st.speed}×`, () => setView('speed'))}
{media.length > 1 && !local && row('Version', `${st.mediaIndex + 1} of ${media.length}`, () => setView('version'))}
{st.chapters.length > 1 && row('Chapters', `${st.chapters.length}`, () => setView('chapters'))}
@ -465,14 +493,29 @@ function PostPlay() {
);
}
/** The title opens its show or movie page, with playback moving to the miniplayer. */
function openFromPlayer(id: string | undefined) {
if (!id) return;
usePlayer.getState().minimize();
navigate({ name: 'item', id });
}
function TitleBlock({ item }: { item: Item }) {
const linkable = item.type === 'movie' || item.type === 'episode';
const art = <TitleArt item={item.type === 'episode' ? { ...item, logo: item.raw?.Image?.find?.((i: any) => i.type === 'clearLogo')?.url ?? '' } : item} maxWidth={240} maxHeight={60} as="h2" />;
return (
<div className="player-title">
<TitleArt item={item.type === 'episode' ? { ...item, logo: item.raw?.Image?.find?.((i: any) => i.type === 'clearLogo')?.url ?? '' } : item} maxWidth={240} maxHeight={60} as="h2" />
{linkable ? (
<button className="player-title-link" title={`Go to ${item.type === 'episode' ? item.grandparentTitle : item.title}`} onClick={() => openFromPlayer(item.type === 'episode' ? item.grandparentId : item.id)}>
{art}
</button>
) : (
art
)}
{item.type === 'episode' && (
<div className="player-episode">
<button className="player-episode" title="Go to this episode" onClick={() => openFromPlayer(item.id)}>
{episodeLabel(item)} · {item.title}
</div>
</button>
)}
{item.type !== 'clip' && <Facts item={item} withFormats={false} episode={false} />}
</div>
@ -627,6 +670,14 @@ export function PlayerOverlay() {
if (e.shiftKey && p.nextUp) p.playNext();
else handled = false;
break;
case 'u':
case 'U': {
const prefs = useSettings.getState();
const next = UPSCALING_ORDER[(UPSCALING_ORDER.indexOf(prefs.upscaling) + 1) % UPSCALING_ORDER.length];
prefs.set('upscaling', next);
toast(`Upscaling: ${UPSCALING[next].label}`);
break;
}
case 'c':
case 'C': {
const subs = p.subTracks;

View file

@ -3,10 +3,10 @@ import * as api from '../plex/api';
import { directUrl, previewUrl, reportTimeline, stopTranscode, transcodeUrl, type Delivery } from '../plex/playback';
import type { Item, Stream } from '../plex/types';
import { useSession } from '../app/session';
import { useSettings, SUBTITLE_MARGIN, type Preferences, type Quality } from '../app/settings';
import { useSettings, SUBTITLE_MARGIN, type Preferences, type Quality, type Upscaling } from '../app/settings';
import { channelLabel } from '../app/format';
import { invalidateLibrary } from '../app/queries';
import { keepAwake, isNative, win } from '../platform/native';
import { keepAwake, isNative, resourcePath, win } from '../platform/native';
import { mpv, type MpvEvent, type MpvTrack } from './engine';
import { toast } from '../ui/overlays';
import { stopThemeMusic } from './theme';
@ -203,6 +203,43 @@ 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();
@ -590,6 +627,7 @@ 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 mpv.set('force-media-title', item.type === 'episode' ? `${item.grandparentTitle} — ${item.title}` : item.title);
await mpv.show(true);
const fileOpts = [
@ -692,9 +730,7 @@ export const usePlayer = create<PlayerState>((set, get) => ({
},
expand() {
if (!get().mini) return;
set({ mini: false });
if (isNative) mpv.rect(null).catch(() => {});
if (get().mini) set({ mini: false });
},
async selectAudio(key) {
@ -776,6 +812,9 @@ usePlayer.subscribe((st, prev) => {
html.toggle('player-open', st.open && !st.mini);
html.toggle('player-mini', st.open && st.mini);
}
// However the miniplayer is left (expanding, playing another title, closing),
// the video returns to the whole window.
if (prev.mini && !st.mini && isNative) mpv.rect(null).catch(() => {});
});
/** Subtitle look changes apply to the playing video straight away. */
@ -783,3 +822,8 @@ 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);
});