@vestra-player/sdk 1.6.20 → 1.6.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/dist/docs-tree.json.gz +0 -0
- package/dist/i18n-tools.js +7 -2
- package/dist/plugin/types/base.d.ts +1097 -0
- package/dist/plugin/types/base.js +1 -0
- package/dist/plugin/types/commands.d.ts +1189 -0
- package/dist/plugin/types/commands.js +1 -0
- package/dist/plugin/types/packages.d.ts +661 -0
- package/dist/plugin/types/packages.js +1 -0
- package/dist/plugin/types/playback.d.ts +1654 -0
- package/dist/plugin/types/playback.js +1 -0
- package/dist/plugin/types/processing.d.ts +974 -0
- package/dist/plugin/types/processing.js +1 -0
- package/dist/plugin/types/services.d.ts +1132 -0
- package/dist/plugin/types/services.js +1 -0
- package/dist/plugin/types/snapshots.d.ts +491 -0
- package/dist/plugin/types/snapshots.js +1 -0
- package/dist/plugin/types/sources.d.ts +302 -0
- package/dist/plugin/types/sources.js +1 -0
- package/dist/plugin/types/subtitles.d.ts +327 -0
- package/dist/plugin/types/subtitles.js +1 -0
- package/dist/plugin/types/ui-content.d.ts +692 -0
- package/dist/plugin/types/ui-content.js +1 -0
- package/dist/plugin/types/ui-layout.d.ts +1079 -0
- package/dist/plugin/types/ui-layout.js +1 -0
- package/dist/plugin/types/ui-locale.d.ts +490 -0
- package/dist/plugin/types/ui-locale.js +1 -0
- package/dist/plugin/types/ui-shell.d.ts +1072 -0
- package/dist/plugin/types/ui-shell.js +1 -0
- package/dist/plugin/types.d.ts +18 -11072
- package/llms.txt +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,974 @@
|
|
|
1
|
+
import type { Plugin, Scope, SystemInfo } from "./base.ts";
|
|
2
|
+
import type { Player } from "./playback.ts";
|
|
3
|
+
import type { Rendering, RenderingReason } from "./services.ts";
|
|
4
|
+
import type { AudioNode, VideoNode } from "../../processing.ts";
|
|
5
|
+
import type { Disposable, PluginError } from "./base.ts";
|
|
6
|
+
/**
|
|
7
|
+
* The state of a filter, display layer or render options handle.
|
|
8
|
+
* After `failed` nothing retries automatically until the next `set()`,
|
|
9
|
+
* `retry()` or a new source.
|
|
10
|
+
*
|
|
11
|
+
* @since 1.0.0
|
|
12
|
+
* @category Processing
|
|
13
|
+
*/
|
|
14
|
+
export type FilterStatus =
|
|
15
|
+
/** No ready media; the value is kept and applied when media is ready. */
|
|
16
|
+
{
|
|
17
|
+
/** Waiting for ready media. */
|
|
18
|
+
state: "waiting";
|
|
19
|
+
}
|
|
20
|
+
/** A request is in flight. */
|
|
21
|
+
| {
|
|
22
|
+
/** A request is in flight. */
|
|
23
|
+
state: "applying";
|
|
24
|
+
}
|
|
25
|
+
/** The backend accepted it (not a visible-frame guarantee). */
|
|
26
|
+
| {
|
|
27
|
+
/** Accepted by the backend. */
|
|
28
|
+
state: "applied";
|
|
29
|
+
}
|
|
30
|
+
/** Not applied. `retry()`, the next `set()` or a new source tries again. */
|
|
31
|
+
| {
|
|
32
|
+
/** Not applied. */
|
|
33
|
+
state: "failed";
|
|
34
|
+
/**
|
|
35
|
+
* Why. `backend-uncertain`: the backend blocked the stage.
|
|
36
|
+
* `unsupported`: the source is a generated stream
|
|
37
|
+
* ({@link Player.openStream}), whose frames and samples do not pass
|
|
38
|
+
* through the player's filters; the chain is applied again when the
|
|
39
|
+
* source changes to media the player decodes.
|
|
40
|
+
*/
|
|
41
|
+
error: PluginError;
|
|
42
|
+
};
|
|
43
|
+
interface Filter<T> extends Disposable {
|
|
44
|
+
/**
|
|
45
|
+
* Desired chain; last write wins. An empty chain (video `[]`; audio
|
|
46
|
+
* `nodes: []` with no delay) removes this chain, leaving other chains
|
|
47
|
+
* alone; nothing is sent if it was never applied. Players before 0.3.0
|
|
48
|
+
* refuse an empty video chain with `invalid`.
|
|
49
|
+
*/
|
|
50
|
+
set(value: T): void;
|
|
51
|
+
/** Current status. */
|
|
52
|
+
readonly status: FilterStatus;
|
|
53
|
+
/** The status changed. */
|
|
54
|
+
onStatus(listener: (status: FilterStatus) => void): Disposable;
|
|
55
|
+
/** Re-check the host and apply the current value again. */
|
|
56
|
+
retry(): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* This plugin's own video processing chain, re-applied for every new source.
|
|
60
|
+
* From `plugin.video.filter(id)`; needs `processing.video`,
|
|
61
|
+
* `playback.read` and `events`. Without `events` the SDK does not see the
|
|
62
|
+
* source change: a value set before the media is ready stays `waiting`.
|
|
63
|
+
*
|
|
64
|
+
* Members: `set(nodes)` (desired chain, last write wins, `[]` withdraws
|
|
65
|
+
* this plugin's effect), `status` ({@link FilterStatus}),
|
|
66
|
+
* `onStatus(listener)`, `retry()` (re-check and apply again) and
|
|
67
|
+
* `dispose()` (withdraws the chain if it was applied).
|
|
68
|
+
*
|
|
69
|
+
* Each plugin's chain is joined with the others' in a stable order; at most
|
|
70
|
+
* 64 nodes across all plugins. A generated stream ({@link Player.openStream})
|
|
71
|
+
* bypasses the filters: while one plays, a non-empty chain is `failed` with
|
|
72
|
+
* `unsupported`, and it is applied again once a decoded file or URL plays. Calling `set` on every slider move is fine:
|
|
73
|
+
* one request is in flight at a time and only the newest value is sent.
|
|
74
|
+
* Values out of range fail with `invalid` (see {@link VideoNode}). The
|
|
75
|
+
* same chain applies to processed snapshots and exports.
|
|
76
|
+
*
|
|
77
|
+
* @example Brighten the picture and report when it fails
|
|
78
|
+
* Every video plays a little brighter with more contrast, and the OSD
|
|
79
|
+
* says why when the player cannot apply it. `set` records the desired
|
|
80
|
+
* chain (last write wins, one request in flight); the player reapplies it
|
|
81
|
+
* for each new source, and `onStatus` reports `applied` or `failed`.
|
|
82
|
+
* ```ts
|
|
83
|
+
* const picture = plugin.video.filter("picture");
|
|
84
|
+
* // `unsupported` while a generated stream plays: its frames skip filters.
|
|
85
|
+
* picture.onStatus((s) => s.state === "failed" && plugin.osd.show(s.error.message));
|
|
86
|
+
* picture.set([{ kind: "eq", brightness: 0.1, contrast: 1.1, saturation: 1, gamma: 1 }]);
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @remarks
|
|
90
|
+
* Members: `set(nodes)` records the desired chain (last write wins) and
|
|
91
|
+
* sends it, one request at a time and only the newest; `status` and
|
|
92
|
+
* `onStatus` report `waiting`, `applying`, `applied` or `failed`; `retry`
|
|
93
|
+
* applies the current value again; `dispose` withdraws the chain. `set`
|
|
94
|
+
* never throws: a refused chain shows as `failed` in `status`.
|
|
95
|
+
*
|
|
96
|
+
* @capability processing.video, playback.read and events
|
|
97
|
+
* @see [Video and audio processing](../../../docs/explanation/processing.md)
|
|
98
|
+
* @since 1.0.0
|
|
99
|
+
* @category Processing
|
|
100
|
+
*/
|
|
101
|
+
export type VideoFilter = Filter<VideoNode[]>;
|
|
102
|
+
/**
|
|
103
|
+
* This plugin's own audio chain plus its audio delay in 10 ms steps.
|
|
104
|
+
* From `plugin.audio.filter(id)`; needs `processing.audio`,
|
|
105
|
+
* `playback.read` and `events`. Same members and rules as
|
|
106
|
+
* {@link VideoFilter}.
|
|
107
|
+
*
|
|
108
|
+
* `delayMs` is −10000–10000 in multiples of 10; the positive and the
|
|
109
|
+
* negative delays of all plugins each add up to at most 10000.
|
|
110
|
+
*
|
|
111
|
+
* @example Lower the volume and delay the sound
|
|
112
|
+
* Every file plays 6 dB quieter, with its sound 120 ms later to match a
|
|
113
|
+
* slow display. `set` sends the plugin's whole chain and delay; the
|
|
114
|
+
* player applies it to each source and adds the delays of all plugins.
|
|
115
|
+
* ```ts
|
|
116
|
+
* const audio = plugin.audio.filter("sound");
|
|
117
|
+
* audio.set({ nodes: [{ kind: "volume", gainDb: -6 }], delayMs: 120 }); // 10 ms steps
|
|
118
|
+
* ```
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* The same members and rules as {@link VideoFilter}: `set` records the
|
|
122
|
+
* desired value and never throws, `status` and `onStatus` report the
|
|
123
|
+
* result, `retry` applies it again, `dispose` withdraws it.
|
|
124
|
+
*
|
|
125
|
+
* @capability processing.audio, playback.read and events
|
|
126
|
+
* @see [Video and audio processing](../../../docs/explanation/processing.md)
|
|
127
|
+
* @since 1.0.0
|
|
128
|
+
* @category Processing
|
|
129
|
+
*/
|
|
130
|
+
export type AudioFilter = Filter<{
|
|
131
|
+
/** The audio chain; `[]` for none. */
|
|
132
|
+
nodes: AudioNode[];
|
|
133
|
+
/** Audio delay in ms, −10000–10000 in steps of 10 (default 0). */
|
|
134
|
+
delayMs?: number;
|
|
135
|
+
}>;
|
|
136
|
+
/**
|
|
137
|
+
* How the video sits in the video area; not part of snapshots or exports.
|
|
138
|
+
* Defaults: `{ aspect: null, fit: "keep", zoom: 1, panX: 0, panY: 0 }`.
|
|
139
|
+
*
|
|
140
|
+
* @since 1.0.0
|
|
141
|
+
* @category Processing
|
|
142
|
+
*/
|
|
143
|
+
export interface ViewSettings {
|
|
144
|
+
/** Display aspect override 0.25–4; `null` = as the source. */
|
|
145
|
+
aspect: number | null;
|
|
146
|
+
/** keep: letterbox; stretch: fill, distorted; fill: fill, cropped. */
|
|
147
|
+
fit: "keep" | "stretch" | "fill";
|
|
148
|
+
/** 0.25–4 (1 = fit the area). */
|
|
149
|
+
zoom: number;
|
|
150
|
+
/** −1–1, in units of the shown video's width / height. */
|
|
151
|
+
panX: number;
|
|
152
|
+
/** −1–1, in units of the shown video's height. */
|
|
153
|
+
panY: number;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* The display layer, from `plugin.video.view()` (`processing.video`).
|
|
157
|
+
*
|
|
158
|
+
* Single owner: the first plugin to call `view()` owns it; another plugin's
|
|
159
|
+
* handle reports `failed` (`conflict`) and retries on each `set`. Values
|
|
160
|
+
* persist across sources (reset them yourself on a new `sourceId` if
|
|
161
|
+
* needed); disposing or stopping the owner restores the defaults.
|
|
162
|
+
* Out-of-range values or unknown fields fail with `invalid` without
|
|
163
|
+
* sending anything.
|
|
164
|
+
*
|
|
165
|
+
* @example Fill the window, then zoom in
|
|
166
|
+
* The video fills the video area (cropped instead of letterboxed), then
|
|
167
|
+
* zooms to 150 % shifted a little to the right. The first plugin to call
|
|
168
|
+
* `view()` owns the display layer; each `set` merges into its settings,
|
|
169
|
+
* which stay across sources until the plugin disposes the view or stops.
|
|
170
|
+
* ```ts
|
|
171
|
+
* const view = plugin.video.view();
|
|
172
|
+
* view.set({ fit: "fill" });
|
|
173
|
+
* view.set({ zoom: 1.5, panX: 0.1 }); // merged with the previous write
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @remarks
|
|
177
|
+
* Not part of snapshots or exports: it changes how the picture sits in the
|
|
178
|
+
* video area, not the picture. `set` merges into the current settings and
|
|
179
|
+
* never throws: an out-of-range value or unknown field shows as `failed`
|
|
180
|
+
* (`invalid`) in `status` and is reported to `onError`, without sending
|
|
181
|
+
* anything.
|
|
182
|
+
*
|
|
183
|
+
* @capability processing.video, playback.read and events (like
|
|
184
|
+
* {@link VideoFilter})
|
|
185
|
+
* @see [Video and audio processing](../../../docs/explanation/processing.md)
|
|
186
|
+
* @since 1.0.0
|
|
187
|
+
* @category Processing
|
|
188
|
+
*/
|
|
189
|
+
export interface VideoView extends Disposable {
|
|
190
|
+
/**
|
|
191
|
+
* Merged into the current settings; last write wins.
|
|
192
|
+
*
|
|
193
|
+
* @capability processing.video
|
|
194
|
+
*
|
|
195
|
+
* @example Stretch a 4:3 video to fill the window
|
|
196
|
+
* A 4:3 video fills a 16:9 window, distorted, as the user asked. Each
|
|
197
|
+
* `set` merges the given fields into this plugin's view settings; the
|
|
198
|
+
* newest write wins, and the settings stay for later files until the
|
|
199
|
+
* plugin disposes the view or stops.
|
|
200
|
+
* ```ts
|
|
201
|
+
* plugin.video.view().set({ fit: "stretch" });
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* @since 1.0.0
|
|
205
|
+
*/
|
|
206
|
+
set(value: Partial<ViewSettings>): void;
|
|
207
|
+
/** Current status (the same four states as filters). */
|
|
208
|
+
readonly status: FilterStatus;
|
|
209
|
+
/**
|
|
210
|
+
* The status changed.
|
|
211
|
+
*
|
|
212
|
+
* @capability processing.video
|
|
213
|
+
*
|
|
214
|
+
* @example Tell the user another plugin owns the view
|
|
215
|
+
* When another plugin already controls the display layer, the OSD says
|
|
216
|
+
* so. The first plugin to call `view()` owns it; this plugin's handle
|
|
217
|
+
* then reports `failed` with `conflict`, and tries again on its next `set`.
|
|
218
|
+
* ```ts
|
|
219
|
+
* const view = plugin.video.view();
|
|
220
|
+
* view.onStatus((status) => {
|
|
221
|
+
* if (status.state === "failed" && status.error.code === "conflict")
|
|
222
|
+
* void plugin.osd.show("Another plugin controls the picture size");
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @since 1.0.0
|
|
227
|
+
*/
|
|
228
|
+
onStatus(listener: (status: FilterStatus) => void): Disposable;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* GPU renderer options; not part of snapshots or exports.
|
|
232
|
+
* Defaults: `{ toneMapping: "auto", targetPeak: 203, peakDetect: true, shaders: [], interpolation: false }`.
|
|
233
|
+
*
|
|
234
|
+
* @since 1.0.0
|
|
235
|
+
* @category Processing
|
|
236
|
+
*/
|
|
237
|
+
export interface RenderSettings {
|
|
238
|
+
/** HDR → SDR: "auto" maps HDR sources only; "off" clips without a curve. */
|
|
239
|
+
toneMapping: "auto" | "off" | "bt.2390" | "hable" | "mobius" | "reinhard" | "clip";
|
|
240
|
+
/** SDR display brightness in nits, 100–400. */
|
|
241
|
+
targetPeak: number;
|
|
242
|
+
/** Per-scene peak estimation (where the GPU supports it). */
|
|
243
|
+
peakDetect: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* mpv user shaders (`.glsl`): absolute paths of existing files, at most
|
|
246
|
+
* 16, in order. They run before the shaders of every plugin's
|
|
247
|
+
* {@link VideoShaders} handles.
|
|
248
|
+
*/
|
|
249
|
+
shaders: string[];
|
|
250
|
+
/** Motion interpolation, resampled to the display's refresh rate. */
|
|
251
|
+
interpolation: boolean;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* The GPU renderer's options, from `plugin.video.render()`
|
|
255
|
+
* (`processing.video`). Single owner, like {@link VideoView}; the two are
|
|
256
|
+
* independent handles.
|
|
257
|
+
*
|
|
258
|
+
* Platforms: macOS renders on the GPU by default; Windows does since
|
|
259
|
+
* version 0.5.14 of the player when the user turns on Video ▸ GPU Rendering
|
|
260
|
+
* (Experimental) (off by default, {@link Rendering}). Under software
|
|
261
|
+
* rendering (Windows by default, Linux, headless, fallback) every `set`
|
|
262
|
+
* fails with `unsupported`; {@link SystemInfo.rendering} tells which
|
|
263
|
+
* renderer draws without creating the handle. macOS OpenGL 4.1 has no
|
|
264
|
+
* compute shaders, so `peakDetect` is accepted but has no effect; output
|
|
265
|
+
* is always SDR.
|
|
266
|
+
*
|
|
267
|
+
* @example Tone-map HDR video and hide the menu where it cannot work
|
|
268
|
+
* On a GPU-rendering player HDR video is tone-mapped with BT.2390 for a
|
|
269
|
+
* 250-nit display; under software rendering the plugin hides its HDR menu.
|
|
270
|
+
* `set` merges the values into the plugin's render options and the
|
|
271
|
+
* player reports the result through `onStatus`: `failed` with
|
|
272
|
+
* `unsupported` means the player renders in software (Linux, or Windows
|
|
273
|
+
* while GPU rendering is off).
|
|
274
|
+
* ```ts
|
|
275
|
+
* declare function hideHdrMenu(): void;
|
|
276
|
+
* // ---cut---
|
|
277
|
+
* const render = plugin.video.render();
|
|
278
|
+
* render.onStatus((s) => {
|
|
279
|
+
* if (s.state === "failed" && s.error.code === "unsupported") hideHdrMenu();
|
|
280
|
+
* });
|
|
281
|
+
* render.set({ toneMapping: "bt.2390", targetPeak: 250 }); // nits
|
|
282
|
+
* ```
|
|
283
|
+
*
|
|
284
|
+
* @remarks
|
|
285
|
+
* GPU renderer options (tone mapping, peak detection, shaders,
|
|
286
|
+
* interpolation). Only the GPU renderer has them (macOS; Windows with GPU
|
|
287
|
+
* rendering turned on, version 0.5.14 and later);
|
|
288
|
+
* under software rendering the handle is `failed` with `unsupported` after
|
|
289
|
+
* the player's first answer to `render()` (reported to `onError` too), and so is
|
|
290
|
+
* every `set`. Single owner, like {@link VideoView}. `set` never throws; the
|
|
291
|
+
* result shows in `status`. For shaders that several plugins add at the
|
|
292
|
+
* same time, use {@link VideoShaders} (SDK 1.5.39). After a run of the
|
|
293
|
+
* player that ended abnormally while plugin shaders were drawing, a `set`
|
|
294
|
+
* whose merged values hold a non-empty `shaders` list is refused with
|
|
295
|
+
* `previous-crash` (player 0.6.3; the rules are on {@link VideoShaders}).
|
|
296
|
+
* Every `set` sends all the values set so far, the refused `shaders`
|
|
297
|
+
* included, so include `shaders: []` in the next `set` to go on without
|
|
298
|
+
* them.
|
|
299
|
+
*
|
|
300
|
+
* @capability processing.video, playback.read and events (like
|
|
301
|
+
* {@link VideoFilter})
|
|
302
|
+
* @see [Video and audio processing](../../../docs/explanation/processing.md)
|
|
303
|
+
* @since 1.0.0
|
|
304
|
+
* @category Processing
|
|
305
|
+
*/
|
|
306
|
+
export interface RenderOptions extends Disposable {
|
|
307
|
+
/**
|
|
308
|
+
* Merged into the current settings; last write wins.
|
|
309
|
+
*
|
|
310
|
+
* @capability processing.video
|
|
311
|
+
*
|
|
312
|
+
* @example Turn on motion interpolation
|
|
313
|
+
* Motion becomes smoother on the GPU renderer. `set` merges the field into
|
|
314
|
+
* the plugin's render options; under software rendering the status turns
|
|
315
|
+
* `failed` with `unsupported` instead.
|
|
316
|
+
* ```ts
|
|
317
|
+
* plugin.video.render().set({ interpolation: true });
|
|
318
|
+
* ```
|
|
319
|
+
*
|
|
320
|
+
* @since 1.0.0
|
|
321
|
+
*/
|
|
322
|
+
set(value: Partial<RenderSettings>): void;
|
|
323
|
+
/**
|
|
324
|
+
* `failed` with `unsupported` while the player renders in software;
|
|
325
|
+
* `failed` with `failed` when mpv cannot compile a shader (pushed later;
|
|
326
|
+
* while other plugins' {@link VideoShaders} are on too, the player
|
|
327
|
+
* cannot tell whose shader failed and says so in the message);
|
|
328
|
+
* `failed` with `previous-crash` (player 0.6.3) when a `set` with a
|
|
329
|
+
* non-empty `shaders` list comes after a run of the player that ended
|
|
330
|
+
* abnormally while plugin shaders were drawing (the rules are the same
|
|
331
|
+
* as for {@link VideoShaders}). The handle keeps the refused list among
|
|
332
|
+
* its values and every `set` sends them all, so a later `set` without
|
|
333
|
+
* `shaders` is refused again: include `shaders: []` in it
|
|
334
|
+
* (`set({ shaders: [], toneMapping: "bt.2390" })`); `dispose` always
|
|
335
|
+
* works.
|
|
336
|
+
*/
|
|
337
|
+
readonly status: FilterStatus;
|
|
338
|
+
/**
|
|
339
|
+
* The status changed (including later pushes such as shader compile errors).
|
|
340
|
+
*
|
|
341
|
+
* @capability processing.video
|
|
342
|
+
*
|
|
343
|
+
* @example Report a shader that does not compile
|
|
344
|
+
* The OSD shows mpv's message when a shader the plugin set fails to
|
|
345
|
+
* compile. The player pushes that failure after the `set` was accepted, so
|
|
346
|
+
* it arrives through `onStatus`, not as a rejected call.
|
|
347
|
+
* ```ts
|
|
348
|
+
* const render = plugin.video.render();
|
|
349
|
+
* render.onStatus((status) => {
|
|
350
|
+
* if (status.state === "failed") void plugin.osd.show("Render: {}", [status.error.message]);
|
|
351
|
+
* });
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @since 1.0.0
|
|
355
|
+
*/
|
|
356
|
+
onStatus(listener: (status: FilterStatus) => void): Disposable;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* This plugin's own GPU shaders, from `plugin.video.shaders(id)`
|
|
360
|
+
* (`processing.video`, SDK 1.5.39, player 0.5.20): mpv user shaders
|
|
361
|
+
* (`.glsl`, `//!HOOK` …) that the GPU renderer runs on every frame.
|
|
362
|
+
*
|
|
363
|
+
* @remarks
|
|
364
|
+
* Any number of plugins hold shader handles at the same time (unlike
|
|
365
|
+
* {@link RenderOptions}, which has one owner). The player joins every
|
|
366
|
+
* handle's list in a stable order, after the render options' own
|
|
367
|
+
* `shaders`: built-in plugins first, then installed plugins in the order
|
|
368
|
+
* they were first installed, then development loads (`--plugin`); ties by
|
|
369
|
+
* plugin id, and a plugin's handles by `id`. At most 16 shaders across all
|
|
370
|
+
* handles (`limit` beyond, nothing changes); the render options keep their
|
|
371
|
+
* own 16.
|
|
372
|
+
*
|
|
373
|
+
* Files must be this plugin's own: absolute paths inside its package
|
|
374
|
+
* directory or {@link Plugin.dataDirectory} after following links, each
|
|
375
|
+
* at most 16 MiB. Elsewhere: `invalid`; a file that does not exist:
|
|
376
|
+
* `missing`. The player reads the files when the list is set.
|
|
377
|
+
*
|
|
378
|
+
* GPU rendering only (macOS; Windows with Video ▸ GPU Rendering
|
|
379
|
+
* (Experimental) turned on): under software rendering a non-empty list is
|
|
380
|
+
* `failed` with `unsupported`, and a switch to software during the run
|
|
381
|
+
* pushes `unsupported` to every handle with shaders and removes every
|
|
382
|
+
* list (they no longer count against the 16); set them again once the
|
|
383
|
+
* player draws on the GPU (after a restart). Shaders act when a
|
|
384
|
+
* frame is drawn, so processed snapshots and exports never contain them
|
|
385
|
+
* (use a {@link VideoNode} for that). When mpv cannot compile a shader the
|
|
386
|
+
* handle turns `failed` with `failed` (pushed later); mpv does not say
|
|
387
|
+
* which file failed, so while several plugins' shaders are on, each of
|
|
388
|
+
* them hears it and the message says the player cannot tell whose.
|
|
389
|
+
*
|
|
390
|
+
* `set` sends the whole list (last write wins); `clear` and `dispose`
|
|
391
|
+
* withdraw it; the player removes a stopped plugin's shaders itself.
|
|
392
|
+
* Players before 0.5.20 refuse the request (the handle is `failed`): declare
|
|
393
|
+
* `"minPlayerVersion": "0.5.20"`.
|
|
394
|
+
*
|
|
395
|
+
* **After an abnormal end** (player 0.6.3): when the previous run of the
|
|
396
|
+
* player ended while plugin shaders were drawing (a crash, the process
|
|
397
|
+
* being ended, a lost GPU device), the player refuses every non-empty
|
|
398
|
+
* list of every plugin with `previous-crash`, its message naming the
|
|
399
|
+
* plugins whose shaders were on: one such end keeps them off for the next
|
|
400
|
+
* start only; two within a day keep them off until the GPU, its driver or
|
|
401
|
+
* the player changes, or for 7 days. Clearing (`[]`, `clear`,
|
|
402
|
+
* `dispose`) still works. The player shows one OSD line about it itself;
|
|
403
|
+
* the handle is `failed` with `previous-crash` and the SDK does not
|
|
404
|
+
* retry it. Do not set the list again in a loop while it is refused, and
|
|
405
|
+
* do not show an OSD line of your own for it; a later start of the player
|
|
406
|
+
* applies lists again once the guard lets it. Players before 0.6.3 never
|
|
407
|
+
* refuse with it.
|
|
408
|
+
*
|
|
409
|
+
* @example Add a sharpening shader the plugin ships
|
|
410
|
+
* The video looks sharper on the GPU renderer; under software rendering
|
|
411
|
+
* the OSD says why it is not. The shader file lives in the plugin's
|
|
412
|
+
* package, and the player puts it after other plugins' shaders that come
|
|
413
|
+
* earlier in its order.
|
|
414
|
+
* ```ts
|
|
415
|
+
* import { join } from "node:path";
|
|
416
|
+
* declare const packageDirectory: string;
|
|
417
|
+
* // ---cut---
|
|
418
|
+
* const shaders = plugin.video.shaders("sharpen");
|
|
419
|
+
* shaders.onStatus((s) => {
|
|
420
|
+
* // `unsupported`: software rendering; `failed`: mpv could not compile it.
|
|
421
|
+
* if (s.state === "failed") void plugin.osd.show("Sharpen: {}", [s.error.message]);
|
|
422
|
+
* });
|
|
423
|
+
* shaders.set([join(packageDirectory, "shaders", "sharpen.glsl")]);
|
|
424
|
+
* ```
|
|
425
|
+
*
|
|
426
|
+
* @capability processing.video
|
|
427
|
+
* @player 0.5.20; older players refuse the request.
|
|
428
|
+
* @see [Video and audio processing](../../../docs/explanation/processing.md)
|
|
429
|
+
* @since 1.5.39
|
|
430
|
+
* @category Processing
|
|
431
|
+
*/
|
|
432
|
+
export interface VideoShaders extends Disposable {
|
|
433
|
+
/**
|
|
434
|
+
* Replace this handle's shader list (last write wins); `[]` withdraws
|
|
435
|
+
* it.
|
|
436
|
+
*
|
|
437
|
+
* @remarks
|
|
438
|
+
* Never throws: a refused list shows in `status` (`invalid`, `missing`,
|
|
439
|
+
* `limit`, `unsupported`, and `previous-crash` from player 0.6.3: see
|
|
440
|
+
* the interface's remarks) and goes to {@link Scope.onError}, and what the
|
|
441
|
+
* player held stays.
|
|
442
|
+
*
|
|
443
|
+
* @capability processing.video
|
|
444
|
+
* @param paths - Absolute paths of shader files in this plugin's package
|
|
445
|
+
* or data directory, in the order they run.
|
|
446
|
+
*
|
|
447
|
+
* @example Switch between two shader presets
|
|
448
|
+
* The plugin offers a light and a strong preset; picking one replaces
|
|
449
|
+
* the handle's list in one request. The files were written to the
|
|
450
|
+
* plugin's data directory when the user imported them.
|
|
451
|
+
* ```ts
|
|
452
|
+
* import { join } from "node:path";
|
|
453
|
+
* // ---cut---
|
|
454
|
+
* const presets: Record<string, string[]> = {
|
|
455
|
+
* light: [join(plugin.dataDirectory, "denoise.glsl")],
|
|
456
|
+
* strong: [join(plugin.dataDirectory, "denoise.glsl"), join(plugin.dataDirectory, "sharpen.glsl")],
|
|
457
|
+
* };
|
|
458
|
+
* plugin.video.shaders("presets").set(presets.strong!);
|
|
459
|
+
* ```
|
|
460
|
+
*
|
|
461
|
+
* @since 1.5.39
|
|
462
|
+
*/
|
|
463
|
+
set(paths: readonly string[]): void;
|
|
464
|
+
/**
|
|
465
|
+
* Withdraw this handle's shaders (the same as `set([])`).
|
|
466
|
+
*
|
|
467
|
+
* @capability processing.video
|
|
468
|
+
*
|
|
469
|
+
* @example Turn the plugin's shaders off from a menu item
|
|
470
|
+
* A Video menu item turns the plugin's shader on and off. Clearing
|
|
471
|
+
* keeps the handle, so the next pick sets the list again.
|
|
472
|
+
* ```ts
|
|
473
|
+
* declare const file: string;
|
|
474
|
+
* // ---cut---
|
|
475
|
+
* const shaders = plugin.video.shaders();
|
|
476
|
+
* let on = false;
|
|
477
|
+
* plugin.commands.add({
|
|
478
|
+
* id: "toggle-shader",
|
|
479
|
+
* path: ["@video", "Sharpen (Shader)"],
|
|
480
|
+
* checked: () => on,
|
|
481
|
+
* run: () => {
|
|
482
|
+
* on = !on;
|
|
483
|
+
* // Clearing keeps the handle; the next pick sets the list again.
|
|
484
|
+
* if (on) shaders.set([file]);
|
|
485
|
+
* else shaders.clear();
|
|
486
|
+
* },
|
|
487
|
+
* });
|
|
488
|
+
* ```
|
|
489
|
+
*
|
|
490
|
+
* @since 1.5.39
|
|
491
|
+
*/
|
|
492
|
+
clear(): void;
|
|
493
|
+
/**
|
|
494
|
+
* Current status: `waiting` before ready media, `applying`, `applied`,
|
|
495
|
+
* or `failed` with the reason (see the remarks).
|
|
496
|
+
*/
|
|
497
|
+
readonly status: FilterStatus;
|
|
498
|
+
/**
|
|
499
|
+
* The status changed, including later pushes (a compile failure, a
|
|
500
|
+
* switch to software rendering).
|
|
501
|
+
*
|
|
502
|
+
* @capability processing.video
|
|
503
|
+
*
|
|
504
|
+
* @example Report a shader that does not compile
|
|
505
|
+
* The OSD shows mpv's message when the plugin's shader fails to compile.
|
|
506
|
+
* The player pushes that failure after the list was accepted, so it
|
|
507
|
+
* arrives through `onStatus`, not as a refused `set`.
|
|
508
|
+
* ```ts
|
|
509
|
+
* const shaders = plugin.video.shaders();
|
|
510
|
+
* shaders.onStatus((status) => {
|
|
511
|
+
* if (status.state === "failed") void plugin.osd.show("Shader: {}", [status.error.message]);
|
|
512
|
+
* });
|
|
513
|
+
* ```
|
|
514
|
+
*
|
|
515
|
+
* @since 1.5.39
|
|
516
|
+
*/
|
|
517
|
+
onStatus(listener: (status: FilterStatus) => void): Disposable;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Why the GPU's video upscaler does not work, as a stable kebab-case code.
|
|
521
|
+
* A newer player may add codes: compare with the ones you handle and show
|
|
522
|
+
* {@link UpscalingReason.message} for the rest. The codes of player 0.5.16,
|
|
523
|
+
* in the order the player checks them (the first that holds is reported):
|
|
524
|
+
*
|
|
525
|
+
* | Code | Meaning |
|
|
526
|
+
* | --- | --- |
|
|
527
|
+
* | `platform` | The player has no video upscaler on this system (macOS, Linux). |
|
|
528
|
+
* | `no-gpu` | No GPU that can upscale video (Windows: no NVIDIA GPU). |
|
|
529
|
+
* | `driver` | The graphics driver is too old (Windows: an NVIDIA driver before 530). |
|
|
530
|
+
* | `gpu-unsupported` | The driver does not offer upscaling on this GPU (Windows: not an RTX GPU), or the check failed. |
|
|
531
|
+
* | `rendering` | The player renders in software, or GPU rendering is still starting; upscaling needs GPU rendering ({@link Rendering}). |
|
|
532
|
+
* | `adapter` | GPU rendering runs on another GPU than the one that can upscale (a laptop with two GPUs; Windows: choose the high-performance GPU for Vestra in Settings ▸ System ▸ Display ▸ Graphics). |
|
|
533
|
+
* | `decoding` | The video is not decoded on the GPU that renders it: copy-back or software decoding, for example while a {@link VideoFilter} needs the frames in memory. {@link UpscalingReason.cause} says which, and {@link UpscalingReason.plugins} whose filters (newer players; see there). |
|
|
534
|
+
* | `unchecked` | The player has not checked the GPU yet. Only in the answer to `set(false)`, which never starts the check; `state()` and `set(true)` always check first. |
|
|
535
|
+
*
|
|
536
|
+
* `decoding` and `rendering` while GPU rendering is still starting can pass
|
|
537
|
+
* during the run, so `set(true)` accepts them and keeps the request; every
|
|
538
|
+
* other reason holds until the player restarts, and `set(true)` rejects it.
|
|
539
|
+
* Turning upscaling off is always accepted.
|
|
540
|
+
*
|
|
541
|
+
* @example Advise the user by reason
|
|
542
|
+
* The plugin shows its own advice for the reasons the user can act on and
|
|
543
|
+
* the player's message for the rest. `reason.code` is looked up among the
|
|
544
|
+
* codes the plugin knows; an unknown code from a newer player falls
|
|
545
|
+
* through to the message, which names the GPU and what to do.
|
|
546
|
+
* ```ts
|
|
547
|
+
* const { reason } = await plugin.video.upscaling.state();
|
|
548
|
+
* // Advice for the codes this plugin knows; any other code shows the message.
|
|
549
|
+
* const advice: Partial<Record<UpscalingReasonCode, string>> = {
|
|
550
|
+
* driver: "Update the NVIDIA driver to 530 or newer.",
|
|
551
|
+
* rendering: "Turn on Video ▸ GPU Rendering (Experimental) and restart.",
|
|
552
|
+
* };
|
|
553
|
+
* if (reason) console.log(advice[reason.code] ?? reason.message);
|
|
554
|
+
* ```
|
|
555
|
+
*
|
|
556
|
+
* @player 0.5.16
|
|
557
|
+
* @since 1.5.37
|
|
558
|
+
* @category Processing
|
|
559
|
+
*/
|
|
560
|
+
export type UpscalingReasonCode = "platform" | "no-gpu" | "driver" | "gpu-unsupported" | "rendering" | "adapter" | "decoding" | "unchecked" | (string & {});
|
|
561
|
+
/**
|
|
562
|
+
* Why the GPU's video upscaler does not work: a stable
|
|
563
|
+
* {@link UpscalingReasonCode} to branch on and a sentence to show, the same
|
|
564
|
+
* shape as {@link RenderingReason}.
|
|
565
|
+
*
|
|
566
|
+
* @example Grey out a menu item with the player's reason
|
|
567
|
+
* The plugin disables its upscaling item and shows why. `message` is the
|
|
568
|
+
* player's English text, naming the GPU and what the user can do (turn on
|
|
569
|
+
* GPU rendering, choose the other GPU, update the driver); `code` is for
|
|
570
|
+
* decisions.
|
|
571
|
+
* ```ts
|
|
572
|
+
* const { available, reason } = await plugin.video.upscaling.state();
|
|
573
|
+
* if (!available && reason) console.log(`${reason.code}: ${reason.message}`);
|
|
574
|
+
* ```
|
|
575
|
+
*
|
|
576
|
+
* @player 0.5.16
|
|
577
|
+
* @since 1.5.37
|
|
578
|
+
* @category Processing
|
|
579
|
+
*/
|
|
580
|
+
export interface UpscalingReason {
|
|
581
|
+
/** The reason as a stable kebab-case code; branch on this. */
|
|
582
|
+
readonly code: UpscalingReasonCode;
|
|
583
|
+
/**
|
|
584
|
+
* The reason as English text for people, for example with the GPU's name
|
|
585
|
+
* and what to change; never branch on it.
|
|
586
|
+
*/
|
|
587
|
+
readonly message: string;
|
|
588
|
+
/**
|
|
589
|
+
* With code `decoding` only: why the video is not decoded on the GPU
|
|
590
|
+
* that renders it ({@link UpscalingDecodingCause}). Absent with every
|
|
591
|
+
* other code, and from players before 0.5.25.
|
|
592
|
+
*
|
|
593
|
+
* @player 0.5.25; older players send `decoding` without a cause.
|
|
594
|
+
* @since 1.5.43
|
|
595
|
+
*/
|
|
596
|
+
readonly cause?: UpscalingDecodingCause;
|
|
597
|
+
/**
|
|
598
|
+
* With cause `copy-back` only: the plugins whose video filters need the
|
|
599
|
+
* frames in memory, which is why the player switched to copy-back
|
|
600
|
+
* decoding, in the order the plugins started (each plugin once). Name
|
|
601
|
+
* them to the user, who can turn the filters off there. Empty when
|
|
602
|
+
* the copy-back decoding is not one the player chose for a filter (the
|
|
603
|
+
* user's own `hwdec` setting). Absent with any other cause, and from
|
|
604
|
+
* players before 0.5.25.
|
|
605
|
+
*
|
|
606
|
+
* @player 0.5.25
|
|
607
|
+
* @since 1.5.43
|
|
608
|
+
*/
|
|
609
|
+
readonly plugins?: readonly UpscalingPlugin[];
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Why the video is not decoded on the GPU that renders it: the
|
|
613
|
+
* {@link UpscalingReason.cause} of a `decoding` reason (player 0.5.25). A
|
|
614
|
+
* newer player may add causes: show {@link UpscalingReason.message} for the
|
|
615
|
+
* ones you do not handle.
|
|
616
|
+
*
|
|
617
|
+
* | Cause | Meaning |
|
|
618
|
+
* | --- | --- |
|
|
619
|
+
* | `copy-back` | Decoded on the GPU and copied back to memory, because a plugin's video filter needs the frames there ({@link UpscalingReason.plugins} names it), or because of the user's `hwdec` setting. |
|
|
620
|
+
* | `hwdec-off` | Hardware decoding is turned off (mpv's `hwdec` is `no`). |
|
|
621
|
+
* | `software` | This video is decoded in software: a cover picture, a format the GPU does not decode, or a hardware decoder that failed. It passes with the next video. |
|
|
622
|
+
* | `other-hwdec` | This video is decoded with another hardware decoder than the one the upscaler needs. |
|
|
623
|
+
*
|
|
624
|
+
* @example Name the plugins whose filters block upscaling
|
|
625
|
+
* A plugin's upscaling window explains a `decoding` reason by its cause,
|
|
626
|
+
* and for `copy-back` names the plugins whose filters stand in the way, so
|
|
627
|
+
* the user can turn them off there (a plugin cannot run another plugin's
|
|
628
|
+
* commands).
|
|
629
|
+
* ```ts
|
|
630
|
+
* const { reason } = await plugin.video.upscaling.state();
|
|
631
|
+
* if (reason?.code === "decoding" && reason.cause === "copy-back") {
|
|
632
|
+
* const names = (reason.plugins ?? []).map((p) => p.name).join(", ");
|
|
633
|
+
* // Ask the user to reset those filters; the manifest names are not translated.
|
|
634
|
+
* console.log(names ? `Turn off the video filters of ${names}` : reason.message);
|
|
635
|
+
* } else if (reason) console.log(reason.message);
|
|
636
|
+
* ```
|
|
637
|
+
*
|
|
638
|
+
* @player 0.5.25
|
|
639
|
+
* @since 1.5.43
|
|
640
|
+
* @category Processing
|
|
641
|
+
*/
|
|
642
|
+
export type UpscalingDecodingCause = "copy-back" | "hwdec-off" | "software" | "other-hwdec" | (string & {});
|
|
643
|
+
/**
|
|
644
|
+
* A plugin named in an {@link UpscalingReason}: its manifest id and its
|
|
645
|
+
* name for people, as its manifest gives it (not translated).
|
|
646
|
+
*
|
|
647
|
+
* @player 0.5.25
|
|
648
|
+
* @since 1.5.43
|
|
649
|
+
* @category Processing
|
|
650
|
+
*/
|
|
651
|
+
export interface UpscalingPlugin {
|
|
652
|
+
/** The plugin's manifest id, for example `vestra.video`. */
|
|
653
|
+
readonly id: string;
|
|
654
|
+
/** The manifest's `name` as is (its id without one), for people. */
|
|
655
|
+
readonly name: string;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* The video's size as the upscaler gets it ({@link UpscalingState.video}):
|
|
659
|
+
* the decoder's frame size, width and height swapped for the file's
|
|
660
|
+
* quarter-turn rotation metadata.
|
|
661
|
+
*
|
|
662
|
+
* @player 0.5.25
|
|
663
|
+
* @since 1.5.43
|
|
664
|
+
* @category Processing
|
|
665
|
+
*/
|
|
666
|
+
export interface UpscalingVideoSize {
|
|
667
|
+
/** The frames' stored width in pixels. */
|
|
668
|
+
readonly width: number;
|
|
669
|
+
/** The frames' stored height in pixels. */
|
|
670
|
+
readonly height: number;
|
|
671
|
+
/** The width the video is meant to be shown at (non-square pixels). */
|
|
672
|
+
readonly displayWidth: number;
|
|
673
|
+
/** The height the video is meant to be shown at. */
|
|
674
|
+
readonly displayHeight: number;
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* What {@link VideoUpscaling.state} and {@link VideoUpscaling.set} report:
|
|
678
|
+
* whether the upscaler works now and why not, whether this plugin turned
|
|
679
|
+
* it on, and whether the player asked the GPU to upscale.
|
|
680
|
+
*
|
|
681
|
+
* @remarks
|
|
682
|
+
* `requested` is as far as the player can see. The player puts the
|
|
683
|
+
* upscaler last in the video filter chain, scaling the video to the area it
|
|
684
|
+
* is shown in; the driver gives no sign that it upscales. On Windows the
|
|
685
|
+
* user must also turn on Super Resolution in the NVIDIA app (System ▸ Video
|
|
686
|
+
* ▸ RTX Video Enhancement), which no program can read: say so next to the
|
|
687
|
+
* switch.
|
|
688
|
+
*
|
|
689
|
+
* @example Label the item with what happens now
|
|
690
|
+
* The plugin's menu item says whether upscaling is on and whether the
|
|
691
|
+
* video is being upscaled. `enabled` is this plugin's own request;
|
|
692
|
+
* `requested` is true while the player has the upscaler in the filter
|
|
693
|
+
* chain, which needs a video shown larger than its own size (`factor`
|
|
694
|
+
* above 1).
|
|
695
|
+
* ```ts
|
|
696
|
+
* const state = await plugin.video.upscaling.state();
|
|
697
|
+
* // `enabled`: this plugin's request; `requested`: in the filter chain now.
|
|
698
|
+
* const label = !state.enabled
|
|
699
|
+
* ? "AI Upscaling: Off"
|
|
700
|
+
* : state.requested
|
|
701
|
+
* ? `AI Upscaling: On (×${state.factor?.toFixed(2)})`
|
|
702
|
+
* : "AI Upscaling: On (not needed for this video)";
|
|
703
|
+
* console.log(label);
|
|
704
|
+
* ```
|
|
705
|
+
*
|
|
706
|
+
* @player 0.5.16
|
|
707
|
+
* @since 1.5.37
|
|
708
|
+
* @category Processing
|
|
709
|
+
*/
|
|
710
|
+
export interface UpscalingState {
|
|
711
|
+
/** Whether the upscaler works now; `false` with {@link UpscalingState.reason}. */
|
|
712
|
+
readonly available: boolean;
|
|
713
|
+
/** Why it does not work now; `null` while it does. */
|
|
714
|
+
readonly reason: UpscalingReason | null;
|
|
715
|
+
/** This plugin asked for upscaling ({@link VideoUpscaling.set}) and has not turned it off. */
|
|
716
|
+
readonly enabled: boolean;
|
|
717
|
+
/**
|
|
718
|
+
* The player has the upscaler in the video filter chain now, for this
|
|
719
|
+
* plugin or another one: upscaling is enabled and available and the
|
|
720
|
+
* video is shown larger than its own size. Not a sign that the GPU
|
|
721
|
+
* upscales (see the remarks).
|
|
722
|
+
*/
|
|
723
|
+
readonly requested: boolean;
|
|
724
|
+
/**
|
|
725
|
+
* The scale factor the upscaler was asked for (the area the video is
|
|
726
|
+
* shown in over the video's size, in hundredths, above 1); `null` while
|
|
727
|
+
* nothing is requested.
|
|
728
|
+
*/
|
|
729
|
+
readonly factor: number | null;
|
|
730
|
+
/**
|
|
731
|
+
* The video's size as the upscaler gets it; `null` while no video
|
|
732
|
+
* decodes. With {@link UpscalingState.area} it explains the factor.
|
|
733
|
+
* Absent from players before 0.5.25.
|
|
734
|
+
*
|
|
735
|
+
* @player 0.5.25
|
|
736
|
+
* @since 1.5.43
|
|
737
|
+
*/
|
|
738
|
+
readonly video?: UpscalingVideoSize | null;
|
|
739
|
+
/**
|
|
740
|
+
* The area the video is shown in, in pixels (the upscaler scales the
|
|
741
|
+
* video to fit it); `null` while the player shows no video area. Absent
|
|
742
|
+
* from players before 0.5.25.
|
|
743
|
+
*
|
|
744
|
+
* @player 0.5.25
|
|
745
|
+
* @since 1.5.43
|
|
746
|
+
*/
|
|
747
|
+
readonly area?: {
|
|
748
|
+
/** Width in physical pixels. */
|
|
749
|
+
readonly width: number;
|
|
750
|
+
/** Height in physical pixels. */
|
|
751
|
+
readonly height: number;
|
|
752
|
+
} | null;
|
|
753
|
+
/**
|
|
754
|
+
* The name of the GPU that renders, for example `NVIDIA GeForce RTX 4070
|
|
755
|
+
* Laptop GPU`; `null` in software rendering and where the player does not
|
|
756
|
+
* know it (macOS, Linux). Absent from players before 0.5.25.
|
|
757
|
+
*
|
|
758
|
+
* @player 0.5.25
|
|
759
|
+
* @since 1.5.43
|
|
760
|
+
*/
|
|
761
|
+
readonly gpu?: string | null;
|
|
762
|
+
/**
|
|
763
|
+
* The hardware decoder in use for this video, as mpv names it (`d3d11va`,
|
|
764
|
+
* `d3d11va-copy`; `no` for software decoding); `null` while no video
|
|
765
|
+
* decodes. For people and logs: branch on {@link UpscalingReason.cause}.
|
|
766
|
+
* Absent from players before 0.5.25.
|
|
767
|
+
*
|
|
768
|
+
* @player 0.5.25
|
|
769
|
+
* @since 1.5.43
|
|
770
|
+
*/
|
|
771
|
+
readonly hwdecCurrent?: string | null;
|
|
772
|
+
/**
|
|
773
|
+
* The upscaler is in the player's video filter chain now, read from the
|
|
774
|
+
* chain itself (`requested` is what the player asked for; they differ
|
|
775
|
+
* only for a moment, while the chain changes). Still not a sign that the
|
|
776
|
+
* GPU upscales: the driver gives none (see the remarks). Absent from
|
|
777
|
+
* players before 0.5.25.
|
|
778
|
+
*
|
|
779
|
+
* @player 0.5.25
|
|
780
|
+
* @since 1.5.43
|
|
781
|
+
*/
|
|
782
|
+
readonly inChain?: boolean;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* `plugin.video.upscaling`: the GPU's video upscaler, NVIDIA RTX Video
|
|
786
|
+
* Super Resolution on Windows (`video.upscaling`). Read whether it works
|
|
787
|
+
* here and why not; turn it on or off for this plugin.
|
|
788
|
+
*
|
|
789
|
+
* @remarks
|
|
790
|
+
* The player checks the GPU once, when a plugin first asks, and keeps the
|
|
791
|
+
* answer: the check wakes a sleeping discrete GPU, so call
|
|
792
|
+
* {@link VideoUpscaling.state} when the plugin first needs the answer (the
|
|
793
|
+
* first time the user picks its upscaling item), not while the plugin
|
|
794
|
+
* starts, and do not poll it. `set(false)` never starts the check. It works
|
|
795
|
+
* only with GPU rendering, on the GPU the upscaler runs on, with the video decoded on that GPU; {@link UpscalingReasonCode}
|
|
796
|
+
* lists what can stand in the way.
|
|
797
|
+
*
|
|
798
|
+
* While some plugin has it on and it works, the player puts the upscaler
|
|
799
|
+
* last in the video filter chain and scales the video to the area it is
|
|
800
|
+
* shown in, following window and video size changes (a resize waits until
|
|
801
|
+
* the size holds). A video already shown at its own size or smaller is not
|
|
802
|
+
* upscaled. The upscaler stays while any plugin has it on; it goes when the
|
|
803
|
+
* last one turns it off or stops: the player revokes a stopped plugin's
|
|
804
|
+
* request.
|
|
805
|
+
*
|
|
806
|
+
* **Windows:** the user must turn on Super Resolution in the NVIDIA app
|
|
807
|
+
* (System ▸ Video ▸ RTX Video Enhancement); no program can read that
|
|
808
|
+
* switch, and the driver gives no sign that it upscales
|
|
809
|
+
* ({@link UpscalingState.requested} is as far as the player can see). It
|
|
810
|
+
* uses the NVIDIA GPU, so power use and heat go up, and on a laptop with
|
|
811
|
+
* two GPUs the whole player must run on the NVIDIA one.
|
|
812
|
+
* **macOS, Linux:** `available` is `false` with `platform`.
|
|
813
|
+
*
|
|
814
|
+
* Players before 0.5.16 do not know `video.upscaling` and do not load a
|
|
815
|
+
* plugin that declares it: declare `"minPlayerVersion": "0.5.16"`.
|
|
816
|
+
*
|
|
817
|
+
* @example Offer AI upscaling as a menu item
|
|
818
|
+
* A Video menu item turns upscaling on and off; once the player said it
|
|
819
|
+
* cannot work here, the item is greyed out with the player's reason. The
|
|
820
|
+
* state is read the first time the user picks the item (that runs the
|
|
821
|
+
* player's GPU check, so nothing wakes the GPU while the plugin starts) and
|
|
822
|
+
* again after each pick; `set` resolves with the new state, or rejects with
|
|
823
|
+
* `unsupported` where upscaling cannot work in this run.
|
|
824
|
+
* ```ts
|
|
825
|
+
* let state: UpscalingState | null = null; // unknown until first picked
|
|
826
|
+
* plugin.commands.add({
|
|
827
|
+
* id: "upscaling",
|
|
828
|
+
* path: ["@video", "AI Upscaling"],
|
|
829
|
+
* checked: () => state?.enabled ?? false,
|
|
830
|
+
* // Greyed only once the player said it cannot work (`decoding` can pass).
|
|
831
|
+
* enabled: () => state === null || state.available || state.reason?.code === "decoding",
|
|
832
|
+
* reason: () => state?.reason?.message ?? null, // shown while disabled
|
|
833
|
+
* run: async () => {
|
|
834
|
+
* state ??= await plugin.video.upscaling.state(); // the first pick checks the GPU
|
|
835
|
+
* try {
|
|
836
|
+
* state = await plugin.video.upscaling.set(!(state?.enabled ?? false));
|
|
837
|
+
* } catch (error) {
|
|
838
|
+
* // Cannot work in this run (no RTX GPU, software rendering…).
|
|
839
|
+
* if ((error as PluginError).code !== "unsupported") throw error;
|
|
840
|
+
* state = await plugin.video.upscaling.state();
|
|
841
|
+
* }
|
|
842
|
+
* },
|
|
843
|
+
* });
|
|
844
|
+
* ```
|
|
845
|
+
*
|
|
846
|
+
* @capability video.upscaling
|
|
847
|
+
* @player 0.5.16; older players do not load a plugin that declares
|
|
848
|
+
* `video.upscaling`.
|
|
849
|
+
* @since 1.5.37
|
|
850
|
+
* @category Processing
|
|
851
|
+
*/
|
|
852
|
+
export interface VideoUpscaling {
|
|
853
|
+
/**
|
|
854
|
+
* Read whether the upscaler works now and why not, whether this plugin
|
|
855
|
+
* turned it on and what the player asked the GPU for.
|
|
856
|
+
*
|
|
857
|
+
* @capability video.upscaling
|
|
858
|
+
* @returns The state, once the player's GPU check ran (the first call
|
|
859
|
+
* starts it and may take a moment).
|
|
860
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
861
|
+
* `video.upscaling`.
|
|
862
|
+
*
|
|
863
|
+
* @example Find out whether upscaling can work here
|
|
864
|
+
* The plugin reads the state the first time the user picks its upscaling
|
|
865
|
+
* item and keeps it for the item. The first call makes the player check the GPU (which
|
|
866
|
+
* wakes a sleeping discrete GPU) and later calls reuse the answer; the
|
|
867
|
+
* rest (GPU rendering, the GPU it runs on, the decoding) is read at
|
|
868
|
+
* each call.
|
|
869
|
+
* ```ts
|
|
870
|
+
* const { available, reason } = await plugin.video.upscaling.state();
|
|
871
|
+
* if (!available) console.log(reason?.message);
|
|
872
|
+
* ```
|
|
873
|
+
*
|
|
874
|
+
* @since 1.5.37
|
|
875
|
+
*/
|
|
876
|
+
state(): Promise<UpscalingState>;
|
|
877
|
+
/**
|
|
878
|
+
* Turn upscaling on or off for this plugin.
|
|
879
|
+
*
|
|
880
|
+
* @remarks
|
|
881
|
+
* On stays this plugin's request until it turns it off or stops; the
|
|
882
|
+
* player upscales whenever the request can take effect (a `decoding`
|
|
883
|
+
* reason can pass with the next file). Off takes the upscaler out at
|
|
884
|
+
* once unless another plugin has it on. Upscaling is a request of the
|
|
885
|
+
* whole plugin, not of a {@link Scope}: disposing a scope does not turn
|
|
886
|
+
* it off.
|
|
887
|
+
*
|
|
888
|
+
* @capability video.upscaling
|
|
889
|
+
* @param enabled - `true` to ask for upscaling, `false` to withdraw the
|
|
890
|
+
* request.
|
|
891
|
+
* @returns The new state.
|
|
892
|
+
* @throws `capability` (rejects) The manifest does not declare
|
|
893
|
+
* `video.upscaling`.
|
|
894
|
+
* @throws `invalid` (rejects) `enabled` is not a boolean.
|
|
895
|
+
* @throws `unsupported` (rejects) `true` where upscaling cannot work in
|
|
896
|
+
* this run: every {@link UpscalingReasonCode} except `decoding`, and
|
|
897
|
+
* except `rendering` while GPU rendering is still starting (those two
|
|
898
|
+
* are accepted and the request is kept until they pass); `message` is
|
|
899
|
+
* the reason. Nothing changes. `false` is always accepted and answered
|
|
900
|
+
* at once without the GPU check (before any check, `available` is
|
|
901
|
+
* `false` with `unchecked`).
|
|
902
|
+
*
|
|
903
|
+
* @example Turn upscaling on and explain what is needed
|
|
904
|
+
* The plugin turns upscaling on from its settings and tells the user what
|
|
905
|
+
* else to switch on. `set(true)` records the request and resolves with the
|
|
906
|
+
* new state; where upscaling cannot work in this run it rejects with
|
|
907
|
+
* `unsupported` and the player's reason instead.
|
|
908
|
+
* ```ts
|
|
909
|
+
* try {
|
|
910
|
+
* const state = await plugin.video.upscaling.set(true);
|
|
911
|
+
* // The driver's own switch cannot be read: remind the user once.
|
|
912
|
+
* if (state.enabled) await plugin.osd.show("Turn on Super Resolution in the NVIDIA app");
|
|
913
|
+
* } catch (error) {
|
|
914
|
+
* if ((error as PluginError).code !== "unsupported") throw error;
|
|
915
|
+
* await plugin.osd.show("AI upscaling: {}", [(error as PluginError).message]);
|
|
916
|
+
* }
|
|
917
|
+
* ```
|
|
918
|
+
*
|
|
919
|
+
* @since 1.5.37
|
|
920
|
+
*/
|
|
921
|
+
set(enabled: boolean): Promise<UpscalingState>;
|
|
922
|
+
/**
|
|
923
|
+
* Call `listener` with the new state whenever it changes while some
|
|
924
|
+
* plugin has upscaling on: the factor, whether the upscaler is in the
|
|
925
|
+
* chain, the reason, the video's and the area's size, the decoder. A
|
|
926
|
+
* window that shows how upscaling runs listens instead of polling
|
|
927
|
+
* {@link VideoUpscaling.state}.
|
|
928
|
+
*
|
|
929
|
+
* @remarks
|
|
930
|
+
* The player looks about five times a second while upscaling is on for
|
|
931
|
+
* any plugin (a window resize sends at most that many), and sends a
|
|
932
|
+
* change only when something differs; after the last plugin turns it
|
|
933
|
+
* off one more change says so, then nothing until it is on again: read
|
|
934
|
+
* {@link VideoUpscaling.state} when you need the state then. Nothing is
|
|
935
|
+
* sent before the player's GPU check ran (the first `state()` or
|
|
936
|
+
* `set(true)` of any plugin). `enabled` is this plugin's own request, as
|
|
937
|
+
* in `state()`. The message of a `rendering` reason can be shorter than
|
|
938
|
+
* the one `state()` gives (it may leave out what to do).
|
|
939
|
+
*
|
|
940
|
+
* **A listener keeps the plugin running.** `video.upscaling.changed` is
|
|
941
|
+
* not an event the player wakes a stopped plugin for: while the plugin
|
|
942
|
+
* listens, the player does not stop it while idle (lazy activation), even
|
|
943
|
+
* with upscaling off. Listen only while a window that shows the state is
|
|
944
|
+
* open, and dispose of the listener when it closes. Players before 0.5.25 do not know the event: the listener
|
|
945
|
+
* never fires and the SDK logs that the player refused the subscription.
|
|
946
|
+
*
|
|
947
|
+
* @capability video.upscaling
|
|
948
|
+
* @param listener - Receives the new state.
|
|
949
|
+
* @returns Stops listening; also when the scope that added it is
|
|
950
|
+
* disposed.
|
|
951
|
+
* @throws `capability` (synchronously) The manifest does not declare
|
|
952
|
+
* `video.upscaling`.
|
|
953
|
+
*
|
|
954
|
+
* @example Show how upscaling runs while a window is open
|
|
955
|
+
* The plugin's window shows the factor, the sizes and the GPU while it
|
|
956
|
+
* is open; the listener goes when the window closes, so the plugin can
|
|
957
|
+
* be stopped while idle again.
|
|
958
|
+
* ```ts
|
|
959
|
+
* // When the window opens:
|
|
960
|
+
* const watch = plugin.video.upscaling.onChange((state) => {
|
|
961
|
+
* const video = state.video ? `${state.video.width}×${state.video.height}` : "no video";
|
|
962
|
+
* const area = state.area ? `${state.area.width}×${state.area.height}` : "—";
|
|
963
|
+
* console.log(`${video} → ${area}, ×${state.factor ?? 1}, ${state.gpu ?? "no GPU"}`);
|
|
964
|
+
* });
|
|
965
|
+
* // When it closes: stop listening (it keeps the plugin running).
|
|
966
|
+
* await watch.dispose();
|
|
967
|
+
* ```
|
|
968
|
+
*
|
|
969
|
+
* @player 0.5.25
|
|
970
|
+
* @since 1.5.43
|
|
971
|
+
*/
|
|
972
|
+
onChange(listener: (state: UpscalingState) => void): Disposable;
|
|
973
|
+
}
|
|
974
|
+
export {};
|