@banou/media-player 0.10.37 → 0.10.39

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/README.md CHANGED
@@ -23,7 +23,9 @@ import MediaPlayer from '@banou/media-player'
23
23
  libavWorkerUrl="/libav-worker.js"
24
24
  jassubWorkerUrl={jassubWorkerUrl}
25
25
  jassubWasmUrl={jassubWasmUrl}
26
+ jassubWasmWorkerUrl={jassubWasmWorkerUrl}
26
27
  jassubLegacyWasmUrl={jassubLegacyWasmUrl}
28
+ jassubLegacyWasmWorkerUrl={jassubLegacyWasmWorkerUrl}
27
29
  defaultFontUrl={defaultFontUrl}
28
30
  cjkFontUrl={cjkFontUrl}
29
31
  title="episode.mkv"
@@ -116,28 +118,18 @@ vite that is one query each, in your own source:
116
118
  ```ts
117
119
  import jassubWorkerUrl from 'jassub/dist/worker/worker.js?worker&url'
118
120
  import jassubWasmUrl from 'jassub/dist/wasm/jassub-worker-modern.wasm?no-inline&url'
121
+ import jassubWasmWorkerUrl from 'jassub/dist/wasm/jassub-worker-modern.js?no-inline&url'
119
122
  import jassubLegacyWasmUrl from 'jassub/dist/wasm/jassub-worker.wasm?no-inline&url'
123
+ import jassubLegacyWasmWorkerUrl from 'jassub/dist/wasm/jassub-worker.js?no-inline&url'
120
124
  import defaultFontUrl from 'jassub/dist/default.woff2?no-inline&url'
121
125
  ```
122
126
 
123
127
  `?no-inline` is load bearing for anything built with `build.lib` set: vite inlines every asset as a
124
128
  base64 data url in library mode and ignores `assetsInlineLimit` while doing it, so without it the two
125
- wasm builds and the font land in your entry chunk as about 5.9 MB of base64. `src/asset-urls.ts` in
126
- this repo is the same four lines and is meant to be copied.
127
-
128
- **If you build with `build.lib` set, build these four in a separate pass with it UNSET.** `?no-inline`
129
- covers the assets you name, and it cannot cover the ones jassub names for itself: its emscripten glue
130
- resolves the wasm with `new URL('./wasm/...', import.meta.url)` inside the worker, and lib mode inlines
131
- those too. Measured on this version, one entry importing exactly the four lines above:
132
-
133
- | build | worker chunk | base64 wasm blobs |
134
- | --- | --- | --- |
135
- | `build.lib` set | 2,922,207 bytes | 2 |
136
- | no `build.lib` | 110,525 bytes | 0 |
137
-
138
- `assetsInlineLimit: 0` and the function form both make no difference, because lib mode decides to
139
- inline before it consults either. A second vite config with a single JS entry, no `lib`, and the same
140
- `outDir` produces the 110 KB worker, the 30 KB pthread glue and both wasm files as real files.
129
+ wasm builds, their scripts and the font land in your entry chunk as about 6 MB of base64.
130
+ `src/asset-urls.ts` in this repo is the same six lines and is meant to be copied. With them, one pass
131
+ is enough even in library mode: from jassub 2.5.35 the worker loads its wasm script by url instead of
132
+ bundling it, so the worker chunk comes out at 90,949 bytes with no base64 in it, with `build.lib` set or not.
141
133
 
142
134
  `?no-inline&url` needs a type declaration, because vite's own ambient `*?url` only matches a specifier
143
135
  ENDING in `?url`. See `src/vite-env.d.ts`.
@@ -146,12 +138,17 @@ The two wasm builds are picked at runtime:
146
138
 
147
139
  | option | file | when it is used |
148
140
  | --- | --- | --- |
149
- | `jassubWasmUrl` | `jassub/dist/wasm/jassub-worker-modern.wasm` | wherever RELAXED SIMD exists |
141
+ | `jassubWasmUrl` | `jassub/dist/wasm/jassub-worker-modern.wasm` | wherever RELAXED SIMD exists and the device reports more than 2 GB of memory |
150
142
  | `jassubLegacyWasmUrl` | `jassub/dist/wasm/jassub-worker.wasm` | everywhere else |
151
143
 
144
+ Each build runs from its own script, `jassubWasmWorkerUrl` and `jassubLegacyWasmWorkerUrl`, which jassub's worker
145
+ imports and starts its threads from, so they are served from your origin as JavaScript and come from the same jassub
146
+ version as the wasm beside them.
147
+
152
148
  The test is RELAXED simd, not baseline simd: jassub validates a module using `i8x16.relaxed_swizzle`.
153
149
  That is a much later feature than plain SIMD, so the second file is not a museum piece for ancient
154
- Safari the way it was under jassub 1. Serve both.
150
+ Safari the way it was under jassub 1. The memory rule is jassub's own (`navigator.deviceMemory`): its SIMD
151
+ build allocates with mimalloc, which grows the heap two to three times as far. Serve both.
155
152
 
156
153
  Serve the wasm as `application/wasm`: jassub instantiates it with `instantiateStreaming`, which
157
154
  refuses any other content type.
@@ -234,6 +231,15 @@ reflect the real element froze the window: seeking while paused left the old sce
234
231
  transport state is carried by the Media Session instead, which is what the window reads for its
235
232
  play/pause button.
236
233
 
234
+ Frames are painted on the page's frame callbacks, which follow the browser window, not the picture
235
+ in picture one: they stop with the browser window minimized or off screen, while the window is still
236
+ on screen. A timer then paints at 60 a second instead. The page's own video is hidden while the
237
+ window is open, as Chrome's own picture in picture does, because a video shown in the page moves its
238
+ picture only on the page's rendering, so every paint would read the same frame for 250 ms. The
239
+ subtitles are rendered on the page's rendering too, so once they fall two seconds behind the video
240
+ they are left out of the window rather than shown wrong. `scripts/measure-picture-in-picture.mjs`
241
+ measures each state.
242
+
237
243
  The window outlives the player. A player unmounted while its window is open leaves it open for a
238
244
  second, and the next player mounted in the same document in that time plays in it, at the shape of
239
245
  its own video. So an app that mounts a new player for the next episode keeps the window without a
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "../engine-x5oIkHAN.js";
1
+ import { a as e, c as t, d as n, f as r, i, l as a, n as o, o as s, r as c, s as l, t as u, u as d } from "../engine-DFqSQyNb.js";
2
2
  export { i as DEFAULT_BUFFER_SIZE, e as MediaElementError, a as SUBTITLES_OFF, u as createPictureInPicture, d as createSubtitleRenderer, c as createThumbnailGenerator, n as getTimeRanges, s as isMediaElementError, o as pictureInPictureMode, l as startPlayback, t as terminateRemuxer, r as updateSourceBuffer };
@@ -59,8 +59,12 @@ export type PlaybackOptions = {
59
59
  libavWorkerUrl: string;
60
60
  jassubWorkerUrl: string;
61
61
  jassubWasmUrl: string;
62
- /** jassub's non-SIMD build; without it subtitles fail rather than degrade on Safari before 16.4 */
62
+ /** `jassub/dist/wasm/jassub-worker-modern.js`, the script that runs `jassubWasmUrl` */
63
+ jassubWasmWorkerUrl: string;
64
+ /** jassub's non-SIMD build, for browsers without relaxed SIMD and devices with 2 GB of memory or less */
63
65
  jassubLegacyWasmUrl?: string;
66
+ /** `jassub/dist/wasm/jassub-worker.js`, the script that runs `jassubLegacyWasmUrl` */
67
+ jassubLegacyWasmWorkerUrl?: string;
64
68
  defaultFontUrl?: string;
65
69
  cjkFontUrl?: string;
66
70
  bufferSize?: number;
@@ -4,7 +4,7 @@ export type SubtitleStream = {
4
4
  title: string;
5
5
  language: string;
6
6
  };
7
- /** -1 turns subtitles off. It frees the track and matches no header, so nothing is set. */
7
+ /** -1 turns subtitles off. It empties the track and matches no header, so nothing is set. */
8
8
  export declare const SUBTITLES_OFF = -1;
9
9
  export type SubtitleRendererOptions = {
10
10
  video: HTMLVideoElement;
@@ -21,16 +21,26 @@ export type SubtitleRendererOptions = {
21
21
  */
22
22
  container: HTMLElement;
23
23
  workerUrl: string;
24
- /** The SIMD build, `jassub-worker-modern.wasm`. Used wherever WebAssembly SIMD is available. */
24
+ /**
25
+ * The SIMD build, `jassub-worker-modern.wasm`. Used wherever relaxed SIMD is available and the device
26
+ * reports more than 2 GB of memory.
27
+ */
25
28
  wasmUrl: string;
26
29
  /**
27
- * The non-SIMD build, `jassub-worker.wasm`, for anything without WebAssembly SIMD.
30
+ * The script that runs `wasmUrl`, `jassub-worker-modern.js` from the same jassub version, since each wasm
31
+ * build has its own. The worker imports it and starts its threads from it, so it is a same-origin url.
32
+ */
33
+ wasmWorkerUrl: string;
34
+ /**
35
+ * The non-SIMD build, `jassub-worker.wasm`, for anything without relaxed SIMD or with 2 GB of memory or less.
28
36
  *
29
37
  * Optional in practice as well as in the type, unlike under jassub 1: v2 defaults both wasm urls to
30
38
  * its own files resolved against `import.meta.url`, so leaving this unset degrades to whatever the
31
39
  * bundler emitted rather than failing outright.
32
40
  */
33
41
  legacyWasmUrl?: string;
42
+ /** The script that runs `legacyWasmUrl`, `jassub-worker.js`. Pass both or neither. */
43
+ legacyWasmWorkerUrl?: string;
34
44
  /**
35
45
  * Fallback face for `liberation sans`. Without it jassub falls back to whatever the wasm build embeds.
36
46
  *