@banou/media-player 0.10.48 → 0.10.50
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/dist/engine/index.js +1 -1
- package/dist/{engine-wP5Udzzj.js → engine-Cdwc76gM.js} +6 -3
- package/dist/index.js +83 -76
- package/dist/volume-normalizer-worklet.js +29 -15
- package/package.json +2 -2
- package/src/lib/audio/loudness-analysis.ts +14 -5
- package/src/lib/audio/volume-normalizer-worklet.d.ts +2 -2
- package/src/lib/audio/volume-normalizer-worklet.js +29 -15
- package/src/lib/engine/picture-in-picture.ts +11 -4
- package/src/lib/engine/subtitles.ts +8 -2
package/dist/engine/index.js
CHANGED
|
@@ -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-
|
|
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-Cdwc76gM.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 };
|
|
@@ -138,7 +138,7 @@ var i = {
|
|
|
138
138
|
"pause"
|
|
139
139
|
], j = () => k(), M = (e) => {
|
|
140
140
|
let u = document.createElement("canvas");
|
|
141
|
-
r.append(u);
|
|
141
|
+
u.dataset.pending = "", r.append(u);
|
|
142
142
|
try {
|
|
143
143
|
h = new n({
|
|
144
144
|
canvas: u,
|
|
@@ -159,7 +159,10 @@ var i = {
|
|
|
159
159
|
u.remove(), T(e);
|
|
160
160
|
return;
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
let d = h;
|
|
163
|
+
d.setVideo(t).catch(E), d.ready.then(() => {
|
|
164
|
+
h === d && delete u.dataset.pending;
|
|
165
|
+
}, T);
|
|
163
166
|
for (let e of A) t.addEventListener(e, j);
|
|
164
167
|
l && D((e) => {
|
|
165
168
|
m = Promise.resolve(e.addFonts([l])).then(k, T);
|
|
@@ -605,7 +608,7 @@ var i = {
|
|
|
605
608
|
let { video: t, subtitles: n } = e, r = e.mode ?? K() ?? "window", i = e.maxWidth ?? (r === "burn-in" ? oe : V), a, o, s, c = 0, l = 0, u = 0, d = !1, f = !1, p = !1, m = !1, h, g = () => r === "burn-in" ? !!a : !!a && document.pictureInPictureElement === a.mirror, _ = (e, r) => {
|
|
606
609
|
r.drawImage(t, 0, 0, e.width, e.height);
|
|
607
610
|
let i = n.querySelector("canvas");
|
|
608
|
-
i && i.width > 0 && i.height > 0 && Math.abs(t.currentTime - u) <= le && r.drawImage(i, 0, 0, e.width, e.height);
|
|
611
|
+
i && !("pending" in i.dataset) && i.width > 0 && i.height > 0 && Math.abs(t.currentTime - u) <= le && r.drawImage(i, 0, 0, e.width, e.height);
|
|
609
612
|
}, v = () => {
|
|
610
613
|
let e = Math.min(t.videoWidth || i, i);
|
|
611
614
|
return {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as e, l as t, m as n, n as r, o as i, p as a, r as o, s, t as c, u as l } from "./engine-
|
|
1
|
+
import { c as e, l as t, m as n, n as r, o as i, p as a, r as o, s, t as c, u as l } from "./engine-Cdwc76gM.js";
|
|
2
2
|
import { languageOf as u, playsIn as d, startingTracks as f } from "./language/index.js";
|
|
3
3
|
import { n as p, r as m, t as h } from "./chapters-EBYXcEml.js";
|
|
4
4
|
import { Children as g, Fragment as _, createContext as v, isValidElement as y, useCallback as b, useContext as x, useEffect as S, useMemo as C, useRef as w, useState as T, useSyncExternalStore as E } from "react";
|
|
@@ -8,7 +8,7 @@ import { definePlayerFeature as M, videoFeatures as N } from "@videojs/core/dom"
|
|
|
8
8
|
import { makeRemuxer as P } from "libav-wasm";
|
|
9
9
|
import { Fragment as F, jsx as I, jsxs as L } from "@emotion/react/jsx-runtime";
|
|
10
10
|
import { createMediaElementSource as R } from "@banou/ponyfill/web-audio";
|
|
11
|
-
import { Captions as z, CaptionsOff as B, Check as V, ChevronLeft as H, ChevronRight as ee, Copy as te, Maximize as
|
|
11
|
+
import { Captions as z, CaptionsOff as B, Check as V, ChevronLeft as H, ChevronRight as ee, Copy as te, Maximize as U, Minimize as ne, Pause as re, Play as W, RotateCcw as ie, Settings as G, TriangleAlert as ae, Volume1 as K, Volume2 as q, VolumeX as oe } from "lucide-react";
|
|
12
12
|
import { Tooltip as J } from "react-tooltip";
|
|
13
13
|
//#region src/lib/react/source-feature.ts
|
|
14
14
|
var se = {
|
|
@@ -205,16 +205,16 @@ var se = {
|
|
|
205
205
|
original: n?.originalLanguage,
|
|
206
206
|
subtitles: n?.preferredSubtitleLanguage,
|
|
207
207
|
alwaysSubtitles: n?.alwaysShowSubtitles
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
let
|
|
211
|
-
|
|
212
|
-
let
|
|
213
|
-
|
|
214
|
-
let
|
|
215
|
-
|
|
216
|
-
let
|
|
217
|
-
|
|
208
|
+
}, U = w(te);
|
|
209
|
+
U.current = te;
|
|
210
|
+
let ne = w(n?.onPreferredAudioLanguageChange);
|
|
211
|
+
ne.current = n?.onPreferredAudioLanguageChange;
|
|
212
|
+
let re = w(n?.onPreferredSubtitleLanguageChange);
|
|
213
|
+
re.current = n?.onPreferredSubtitleLanguageChange;
|
|
214
|
+
let W = w(n?.onAlwaysShowSubtitlesChange);
|
|
215
|
+
W.current = n?.onAlwaysShowSubtitlesChange;
|
|
216
|
+
let ie = w(n?.onSeek);
|
|
217
|
+
ie.current = n?.onSeek;
|
|
218
218
|
let G = w(n?.onPlaybackError);
|
|
219
219
|
G.current = n?.onPlaybackError;
|
|
220
220
|
let ae = w(r);
|
|
@@ -228,7 +228,7 @@ var se = {
|
|
|
228
228
|
let t = typeof e == "number" ? e : void 0, n = a.selectedSubtitleTrack === void 0;
|
|
229
229
|
z.current = B.current, a.setSourceState({ selectedSubtitleTrack: t }), L.current?.selectSubtitleStream(t);
|
|
230
230
|
let r = V.current.subtitles.find((e) => e.streamIndex === t), i = t === void 0 ? null : u(r) ?? (n ? r?.title?.trim() || "und" : void 0);
|
|
231
|
-
i !== void 0 &&
|
|
231
|
+
i !== void 0 && re.current?.(i), i && d(H(), i) && W.current?.(!0);
|
|
232
232
|
}, [a, H]), J = w(0), se = b((e, t = !1) => {
|
|
233
233
|
let n = ++J.current, r = L.current;
|
|
234
234
|
if (!r || O <= 0 || t) {
|
|
@@ -262,7 +262,7 @@ var se = {
|
|
|
262
262
|
streamIndex: e
|
|
263
263
|
});
|
|
264
264
|
let t = u(V.current.audio.find((t) => t.streamIndex === e));
|
|
265
|
-
t !== void 0 &&
|
|
265
|
+
t !== void 0 && ne.current?.(t);
|
|
266
266
|
}, [a]), ce = X((e) => e.setSourceState);
|
|
267
267
|
S(() => {
|
|
268
268
|
ce({
|
|
@@ -339,7 +339,7 @@ var se = {
|
|
|
339
339
|
cjkFontUrl: x,
|
|
340
340
|
bufferSize: C,
|
|
341
341
|
audioStreamIndex: M,
|
|
342
|
-
chooseAudioStream: (e) => e[f(e, [],
|
|
342
|
+
chooseAudioStream: (e) => e[f(e, [], U.current).audio]?.streamIndex,
|
|
343
343
|
onReady: () => {
|
|
344
344
|
if (n) return;
|
|
345
345
|
a.setSourceState({ ready: !0 });
|
|
@@ -350,12 +350,12 @@ var se = {
|
|
|
350
350
|
onRecovered: () => {
|
|
351
351
|
n || a.setSourceState({ playbackError: null });
|
|
352
352
|
},
|
|
353
|
-
onSeek: (e) =>
|
|
353
|
+
onSeek: (e) => ie.current?.(e),
|
|
354
354
|
onOutput: (e) => ae.current?.(e),
|
|
355
355
|
onSubtitleStreams: (e) => {
|
|
356
356
|
if (n) return;
|
|
357
357
|
V.current.subtitles = e;
|
|
358
|
-
let t = H(), r = f(t ? [t] : [], e,
|
|
358
|
+
let t = H(), r = f(t ? [t] : [], e, U.current).subtitles;
|
|
359
359
|
a.setSourceState({
|
|
360
360
|
subtitleTracks: Ce(e, q.current),
|
|
361
361
|
...z.current === c ? {} : { selectedSubtitleTrack: r === null ? void 0 : e[Math.max(r, 0)]?.streamIndex }
|
|
@@ -705,6 +705,7 @@ var se = {
|
|
|
705
705
|
}, [m.port1]), t.port.postMessage({ analysis: m.port2 }, [m.port2]);
|
|
706
706
|
let h = {
|
|
707
707
|
spans: [],
|
|
708
|
+
start: null,
|
|
708
709
|
end: null
|
|
709
710
|
}, g = 0, _ = /* @__PURE__ */ new Map(), v = (e, t) => new Promise((n) => _.set(`${e}:${t}`, n)), y = -1;
|
|
710
711
|
p.onmessage = ({ data: e }) => {
|
|
@@ -712,10 +713,15 @@ var se = {
|
|
|
712
713
|
re();
|
|
713
714
|
return;
|
|
714
715
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
716
|
+
if (e.spans) {
|
|
717
|
+
let t = e.start ?? null;
|
|
718
|
+
(JSON.stringify(e.spans) !== JSON.stringify(h.spans) || t !== h.start || e.end !== h.end) && g++, h = {
|
|
719
|
+
spans: e.spans,
|
|
720
|
+
start: t,
|
|
721
|
+
end: e.end
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
e.type === "merged" && (y = e.run), _.get(`${e.type}:${e.run}`)?.(h), _.delete(`${e.type}:${e.run}`), l();
|
|
719
725
|
};
|
|
720
726
|
let b = t.context, x = () => t.port.postMessage({
|
|
721
727
|
media: n.currentTime,
|
|
@@ -737,24 +743,25 @@ var se = {
|
|
|
737
743
|
];
|
|
738
744
|
for (let e of w) n.addEventListener(e, x);
|
|
739
745
|
let T = Infinity, E = !1, D = 0, O = !1, k = 0, A = 0, j = /* @__PURE__ */ new Map(), M = (e) => {
|
|
740
|
-
let t = e;
|
|
746
|
+
let t = Math.max(e, h.start ?? 0);
|
|
741
747
|
for (let [e, n] of h.spans) e <= t && t < n && (t = n);
|
|
742
748
|
return t >= (h.end ?? T) - .05 ? null : t;
|
|
743
|
-
}, N = (e) => j.get(Math.round(e * 10)) === g ? "idle" : e, F = () => {
|
|
749
|
+
}, N = (e) => j.get(Math.round(e * 10)) === g ? "idle" : e, F = () => h.start !== null && h.end !== null && h.spans.length === 1 && h.spans[0][0] <= h.start && h.spans[0][1] >= h.end, I = () => {
|
|
750
|
+
if (F()) return "done";
|
|
744
751
|
let e = n.currentTime, t = M(e), r = O && y !== D;
|
|
745
752
|
if (t !== null && t < e + Ze) return r && k <= t + 1 && t <= A + Qe ? "read" : N(t);
|
|
746
753
|
if (r) return "read";
|
|
747
754
|
let i = t ?? M(0);
|
|
748
755
|
return i === null ? "done" : N(i);
|
|
749
|
-
},
|
|
750
|
-
|
|
751
|
-
})])),
|
|
752
|
-
S(), E && s.size && typeof
|
|
753
|
-
},
|
|
756
|
+
}, L = () => {}, R = (e) => (e.catch(() => {}), Promise.race([e, new Promise((e) => {
|
|
757
|
+
L = () => e(void 0);
|
|
758
|
+
})])), z = () => {
|
|
759
|
+
S(), E && s.size && typeof I() == "number" && L(), l();
|
|
760
|
+
}, B = () => {
|
|
754
761
|
S(), l();
|
|
755
762
|
};
|
|
756
|
-
n.addEventListener("seeking",
|
|
757
|
-
let
|
|
763
|
+
n.addEventListener("seeking", z), n.addEventListener("seeked", B), n.addEventListener("timeupdate", B);
|
|
764
|
+
let V, H = async (e) => {
|
|
758
765
|
if (!O) return;
|
|
759
766
|
O = !1;
|
|
760
767
|
let t = v("ended", D);
|
|
@@ -763,7 +770,7 @@ var se = {
|
|
|
763
770
|
run: D,
|
|
764
771
|
finished: e
|
|
765
772
|
}), await t;
|
|
766
|
-
},
|
|
773
|
+
}, ee = async (e) => {
|
|
767
774
|
if (A = e.pts + e.duration, !e.data.byteLength) return;
|
|
768
775
|
let t = v("ack", D);
|
|
769
776
|
p.postMessage({
|
|
@@ -771,16 +778,16 @@ var se = {
|
|
|
771
778
|
run: D,
|
|
772
779
|
data: e.data
|
|
773
780
|
}, [e.data]), await t;
|
|
774
|
-
},
|
|
775
|
-
if (
|
|
781
|
+
}, te = async (t) => {
|
|
782
|
+
if (V = await P({
|
|
776
783
|
publicPath: t.publicPath,
|
|
777
784
|
workerUrl: t.libavWorkerUrl,
|
|
778
785
|
workerOptions: { type: "module" },
|
|
779
786
|
length: t.length,
|
|
780
787
|
read: (e, n) => d(t, e, n),
|
|
781
788
|
audioStreamIndex: t.audioStreamIndex
|
|
782
|
-
}), a) return e(
|
|
783
|
-
let n = await
|
|
789
|
+
}), a) return e(V);
|
|
790
|
+
let n = await V.init();
|
|
784
791
|
if (!a) {
|
|
785
792
|
for (T = n.info.input.duration || Infinity, p.postMessage({
|
|
786
793
|
type: "init",
|
|
@@ -793,7 +800,7 @@ var se = {
|
|
|
793
800
|
from: 0,
|
|
794
801
|
start: !0
|
|
795
802
|
}); !a;) {
|
|
796
|
-
let e =
|
|
803
|
+
let e = I();
|
|
797
804
|
if (e === "done") break;
|
|
798
805
|
if (e === "idle") {
|
|
799
806
|
await u();
|
|
@@ -801,15 +808,15 @@ var se = {
|
|
|
801
808
|
}
|
|
802
809
|
try {
|
|
803
810
|
if (e === "read") {
|
|
804
|
-
let e = await
|
|
811
|
+
let e = await R(V.read());
|
|
805
812
|
if (a) return;
|
|
806
813
|
if (!e) continue;
|
|
807
|
-
await
|
|
814
|
+
await ee(e), e.finished && await H(!0);
|
|
808
815
|
} else {
|
|
809
|
-
await
|
|
810
|
-
let t =
|
|
816
|
+
await H(!1), j.set(Math.round(e * 10), g);
|
|
817
|
+
let t = V.seek(Math.max(0, e - $e));
|
|
811
818
|
f(!0);
|
|
812
|
-
let r = await
|
|
819
|
+
let r = await R(t);
|
|
813
820
|
if (a) return;
|
|
814
821
|
if (!r) continue;
|
|
815
822
|
D++, O = !0, k = r.pts, p.postMessage({
|
|
@@ -818,16 +825,16 @@ var se = {
|
|
|
818
825
|
pts: n.timestampOffset,
|
|
819
826
|
from: r.pts,
|
|
820
827
|
start: r.pts <= 0
|
|
821
|
-
}), await
|
|
828
|
+
}), await ee(r), r.finished && await H(!0);
|
|
822
829
|
}
|
|
823
830
|
} catch {
|
|
824
831
|
if (a) return;
|
|
825
|
-
await
|
|
832
|
+
await H(!1), typeof I() != "number" && await u();
|
|
826
833
|
}
|
|
827
834
|
}
|
|
828
|
-
e(
|
|
835
|
+
a || await H(!1), !a && (e(V), V = void 0);
|
|
829
836
|
}
|
|
830
|
-
},
|
|
837
|
+
}, U = () => {}, ne = (e, t) => {
|
|
831
838
|
let n = !1, r = (e) => {
|
|
832
839
|
n && p.postMessage({
|
|
833
840
|
type: "end",
|
|
@@ -835,7 +842,7 @@ var se = {
|
|
|
835
842
|
finished: e
|
|
836
843
|
}), n = !1;
|
|
837
844
|
};
|
|
838
|
-
|
|
845
|
+
U = e.attach(t, (e, t) => {
|
|
839
846
|
if (e.type === "init") {
|
|
840
847
|
r(!1);
|
|
841
848
|
let t = e.data.slice(0);
|
|
@@ -866,12 +873,12 @@ var se = {
|
|
|
866
873
|
if (!a) {
|
|
867
874
|
a = !0, f(!0), l(), clearInterval(C);
|
|
868
875
|
for (let e of w) n.removeEventListener(e, x);
|
|
869
|
-
n.removeEventListener("seeking",
|
|
876
|
+
n.removeEventListener("seeking", z), n.removeEventListener("seeked", B), n.removeEventListener("timeupdate", B), U(), V && e(V), p.terminate(), t.port.postMessage({ analysis: null });
|
|
870
877
|
for (let e of _.values()) e(h);
|
|
871
878
|
_.clear();
|
|
872
879
|
}
|
|
873
880
|
};
|
|
874
|
-
return "tap" in i ? ne(i.tap, i.audioStreamIndex) :
|
|
881
|
+
return "tap" in i ? ne(i.tap, i.audioStreamIndex) : te(i).catch((e) => {
|
|
875
882
|
a || (console.warn("[media-player] the volume normalizer cannot analyse ahead:", e), re());
|
|
876
883
|
}), S(), {
|
|
877
884
|
update: (e) => {
|
|
@@ -1462,7 +1469,7 @@ var se = {
|
|
|
1462
1469
|
B.current !== "touch" && E(z(e.clientX));
|
|
1463
1470
|
}, ee = () => {
|
|
1464
1471
|
_.current && E(void 0);
|
|
1465
|
-
}, te = (e) => r ? e / r * 100 : 0,
|
|
1472
|
+
}, te = (e) => r ? e / r * 100 : 0, U = (e, t, n) => {
|
|
1466
1473
|
let r = Number((n - t).toFixed(4)), i = t * 100;
|
|
1467
1474
|
return /* @__PURE__ */ I("div", {
|
|
1468
1475
|
className: "loaded-part",
|
|
@@ -1471,10 +1478,10 @@ var se = {
|
|
|
1471
1478
|
marginLeft: `${i}%`
|
|
1472
1479
|
}
|
|
1473
1480
|
}, e);
|
|
1474
|
-
},
|
|
1481
|
+
}, ne = C(() => i === void 0 ? r ? o.map(([e, t], n) => U(n, e / r, t / r)) : [] : a?.map((e, t) => {
|
|
1475
1482
|
if (!i || !r) return null;
|
|
1476
1483
|
let n = s.filter((t) => e.startByteOffset <= t.pos && t.pos <= e.endByteOffset), a = n.at(0), o = n.at(-1);
|
|
1477
|
-
return !a || !o ? null :
|
|
1484
|
+
return !a || !o ? null : U(t, a.timestamp / r, o.timestamp / r);
|
|
1478
1485
|
}) ?? [], [
|
|
1479
1486
|
r,
|
|
1480
1487
|
i,
|
|
@@ -1491,7 +1498,7 @@ var se = {
|
|
|
1491
1498
|
v,
|
|
1492
1499
|
r
|
|
1493
1500
|
]);
|
|
1494
|
-
let
|
|
1501
|
+
let re = C(() => {
|
|
1495
1502
|
if (!r) return 0;
|
|
1496
1503
|
if (N && v !== void 0) return v;
|
|
1497
1504
|
let e = f ?? t;
|
|
@@ -1502,20 +1509,20 @@ var se = {
|
|
|
1502
1509
|
N,
|
|
1503
1510
|
v,
|
|
1504
1511
|
f
|
|
1505
|
-
]),
|
|
1506
|
-
if (!
|
|
1507
|
-
let e = b / r * 100, t =
|
|
1508
|
-
return t >= 0 ? t :
|
|
1512
|
+
]), W = C(() => p(d, r), [d, r]), ie = W.length > 0, G = C(() => {
|
|
1513
|
+
if (!ie || b === void 0 || !r) return -1;
|
|
1514
|
+
let e = b / r * 100, t = W.findIndex((t, n) => n < W.length - 1 && e >= t && e < W[n + 1]);
|
|
1515
|
+
return t >= 0 ? t : W.length - 2;
|
|
1509
1516
|
}, [
|
|
1517
|
+
ie,
|
|
1510
1518
|
W,
|
|
1511
|
-
U,
|
|
1512
1519
|
b,
|
|
1513
1520
|
r
|
|
1514
|
-
]), ae = C(() =>
|
|
1521
|
+
]), ae = C(() => ie ? m(W, (e) => e !== G) : void 0, [
|
|
1522
|
+
ie,
|
|
1515
1523
|
W,
|
|
1516
|
-
U,
|
|
1517
1524
|
G
|
|
1518
|
-
]), K = C(() => G >= 0 ? m(
|
|
1525
|
+
]), K = C(() => G >= 0 ? m(W, (e) => e === G) : void 0, [W, G]), q = C(() => {
|
|
1519
1526
|
if (b !== void 0) return d.find(({ start: e, end: t }) => e <= b && b < t);
|
|
1520
1527
|
}, [d, b]), oe = C(() => {
|
|
1521
1528
|
if (b) {
|
|
@@ -1533,13 +1540,13 @@ var se = {
|
|
|
1533
1540
|
/* @__PURE__ */ I("div", { className: "background-bar" }),
|
|
1534
1541
|
/* @__PURE__ */ I("div", {
|
|
1535
1542
|
className: "loaded",
|
|
1536
|
-
children:
|
|
1543
|
+
children: ne
|
|
1537
1544
|
}),
|
|
1538
1545
|
/* @__PURE__ */ I("div", {
|
|
1539
1546
|
className: "play-container",
|
|
1540
1547
|
children: /* @__PURE__ */ I("div", {
|
|
1541
1548
|
className: "play",
|
|
1542
|
-
style: { transform: `scaleX(${
|
|
1549
|
+
style: { transform: `scaleX(${re})` }
|
|
1543
1550
|
})
|
|
1544
1551
|
})
|
|
1545
1552
|
]
|
|
@@ -1550,7 +1557,7 @@ var se = {
|
|
|
1550
1557
|
className: [
|
|
1551
1558
|
"progress-bar",
|
|
1552
1559
|
N ? "dragging" : "",
|
|
1553
|
-
|
|
1560
|
+
ie ? "segmented" : ""
|
|
1554
1561
|
].filter(Boolean).join(" "),
|
|
1555
1562
|
onPointerDown: V,
|
|
1556
1563
|
onPointerMove: V,
|
|
@@ -2757,7 +2764,7 @@ ${Nt}
|
|
|
2757
2764
|
type: "button",
|
|
2758
2765
|
onClick: () => r.togglePaused(),
|
|
2759
2766
|
"aria-label": i(j ? a.replay : o ? a.play : a.pause),
|
|
2760
|
-
children: I(j ?
|
|
2767
|
+
children: I(j ? ie : o ? W : re, {})
|
|
2761
2768
|
}),
|
|
2762
2769
|
toolTipText: /* @__PURE__ */ I("span", { children: i(j ? a.replayKey : o ? a.playKey : a.pauseKey) })
|
|
2763
2770
|
}),
|
|
@@ -2817,7 +2824,7 @@ ${Nt}
|
|
|
2817
2824
|
onClick: P,
|
|
2818
2825
|
"aria-label": i(a.fullScreen),
|
|
2819
2826
|
"aria-pressed": d,
|
|
2820
|
-
children: I(d ?
|
|
2827
|
+
children: I(d ? ne : U, {})
|
|
2821
2828
|
}),
|
|
2822
2829
|
toolTipText: /* @__PURE__ */ I("span", { children: i(d ? a.exitFullScreenKey : a.fullScreenKey) })
|
|
2823
2830
|
})
|
|
@@ -3204,19 +3211,19 @@ ${Nt}
|
|
|
3204
3211
|
ee,
|
|
3205
3212
|
te
|
|
3206
3213
|
]);
|
|
3207
|
-
let
|
|
3214
|
+
let U = X((e) => e.chapters), ne = JSON.stringify(U);
|
|
3208
3215
|
S(() => {
|
|
3209
|
-
z.chapters =
|
|
3210
|
-
}, [
|
|
3211
|
-
let
|
|
3216
|
+
z.chapters = U, z.endingOffered = M, z.dispatchEvent(new Event("chapterschange"));
|
|
3217
|
+
}, [ne, M]);
|
|
3218
|
+
let re = e.autoplayNext;
|
|
3212
3219
|
S(() => {
|
|
3213
|
-
P === null && R(
|
|
3214
|
-
}, [
|
|
3215
|
-
let
|
|
3216
|
-
|
|
3220
|
+
P === null && R(re);
|
|
3221
|
+
}, [re, P]);
|
|
3222
|
+
let W = w(e.onAutoplayNextChange);
|
|
3223
|
+
W.current = e.onAutoplayNextChange, S(() => {
|
|
3217
3224
|
z.autoplayNext = L ?? null, z.dispatchEvent(new Event("autoplaynextchange"));
|
|
3218
3225
|
}, [L]);
|
|
3219
|
-
let
|
|
3226
|
+
let ie = e.fullscreen ?? (O === null ? void 0 : {
|
|
3220
3227
|
active: O,
|
|
3221
3228
|
request: () => z.dispatchEvent(new Event("fullscreenrequest"))
|
|
3222
3229
|
}), G = C(() => rt(), [o]);
|
|
@@ -3301,7 +3308,7 @@ ${Nt}
|
|
|
3301
3308
|
Z({ autoplayNext: L === void 0 ? null : {
|
|
3302
3309
|
enabled: L,
|
|
3303
3310
|
setEnabled: (e) => {
|
|
3304
|
-
R(e),
|
|
3311
|
+
R(e), W.current?.(e);
|
|
3305
3312
|
}
|
|
3306
3313
|
} });
|
|
3307
3314
|
}, [Z, L]), S(() => {
|
|
@@ -3359,7 +3366,7 @@ ${Nt}
|
|
|
3359
3366
|
overlay: e.overlay,
|
|
3360
3367
|
controls: e.controls,
|
|
3361
3368
|
shortcuts: e.shortcuts,
|
|
3362
|
-
fullscreen:
|
|
3369
|
+
fullscreen: ie,
|
|
3363
3370
|
endingOffered: M,
|
|
3364
3371
|
children: t
|
|
3365
3372
|
});
|
|
@@ -504,13 +504,13 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
|
|
|
504
504
|
const write = (run, bin, energy, finger) => {
|
|
505
505
|
if (bin < run.from || bin >= endBin) return
|
|
506
506
|
run.last = bin
|
|
507
|
+
if (run.start && firstBin < 0) firstBin = bin
|
|
507
508
|
if (spanAt(bin)) {
|
|
508
509
|
if (run.wrote && ++run.skipped === MERGED_BINS) toPage({ type: 'merged', run: run.id, ...coverage() })
|
|
509
510
|
return
|
|
510
511
|
}
|
|
511
512
|
run.skipped = 0
|
|
512
513
|
run.wrote = true
|
|
513
|
-
if (run.start && firstBin < 0) firstBin = bin
|
|
514
514
|
const chunk = chunkOf(bin)
|
|
515
515
|
chunk.energy[bin % BLOCK_BINS] = energy
|
|
516
516
|
chunk.finger[bin % BLOCK_BINS] = finger
|
|
@@ -589,6 +589,7 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
|
|
|
589
589
|
|
|
590
590
|
const coverage = () => ({
|
|
591
591
|
spans: spans.map(([a, b]) => [a / BINS_PER_SECOND, b / BINS_PER_SECOND]),
|
|
592
|
+
start: firstBin >= 0 ? firstBin / BINS_PER_SECOND : null,
|
|
592
593
|
end: Number.isFinite(endBin) ? endBin / BINS_PER_SECOND : null,
|
|
593
594
|
normal: normal(),
|
|
594
595
|
})
|
|
@@ -651,13 +652,13 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
|
|
|
651
652
|
* SourceBuffer's timestampOffset adds it for playback; `start` for the one
|
|
652
653
|
* from the start, and `join: true` for one whose first fragments went by
|
|
653
654
|
* unseen, which starts at its first sample
|
|
654
|
-
* { type: 'fragment', run, data } answered { type: 'ack', run, spans, end, normal } once its audio is
|
|
655
|
-
* for decoding: the analysed seconds, the
|
|
656
|
-
* level learned so far in LUFS
|
|
657
|
-
* { type: 'end', run, finished } the run is over, answered { type: 'ended', run, spans, end, normal }
|
|
655
|
+
* { type: 'fragment', run, data } answered { type: 'ack', run, spans, start, end, normal } once its audio is
|
|
656
|
+
* queued for decoding: the analysed seconds, the first and last once known,
|
|
657
|
+
* and the level learned so far in LUFS
|
|
658
|
+
* { type: 'end', run, finished } the run is over, answered { type: 'ended', run, spans, start, end, normal }
|
|
658
659
|
* { type: 'playhead', time }
|
|
659
660
|
*
|
|
660
|
-
* and posts { type: 'merged', run, spans, end, normal } when a run has met audio an earlier one analysed, and
|
|
661
|
+
* and posts { type: 'merged', run, spans, start, end, normal } when a run has met audio an earlier one analysed, and
|
|
661
662
|
* { type: 'unsupported' } when this browser's WebCodecs cannot decode the track.
|
|
662
663
|
*/
|
|
663
664
|
const serve = (scope) => {
|
|
@@ -727,7 +728,7 @@ const serve = (scope) => {
|
|
|
727
728
|
joining = !!data.join
|
|
728
729
|
if (!joining) analysis.startRun(runId, data.from, data.start)
|
|
729
730
|
} else if (data.type === 'fragment') {
|
|
730
|
-
if (data.run !== runId || decoder
|
|
731
|
+
if (data.run !== runId || decoder?.state !== 'configured') return
|
|
731
732
|
const samples = audioSamplesOf(data.data, track)
|
|
732
733
|
if (joining && samples.length) {
|
|
733
734
|
joining = false
|
|
@@ -748,9 +749,11 @@ const serve = (scope) => {
|
|
|
748
749
|
} else if (data.type === 'end') {
|
|
749
750
|
if (data.run !== runId) return
|
|
750
751
|
const ending = decoder
|
|
751
|
-
if (ending
|
|
752
|
+
if (ending?.state === 'configured') await ending.flush().catch(() => {})
|
|
752
753
|
if (data.run !== runId) return
|
|
753
|
-
if (ending
|
|
754
|
+
if (ending?.state === 'configured') ending.close()
|
|
755
|
+
if (decoder === ending) decoder = undefined
|
|
756
|
+
stamps = []
|
|
754
757
|
analysis.endRun(data.finished)
|
|
755
758
|
scope.postMessage({ type: 'ended', run: data.run, ...analysis.coverage() })
|
|
756
759
|
}
|
|
@@ -896,7 +899,10 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
|
|
|
896
899
|
this.ring.fill(0)
|
|
897
900
|
this.ringSum = 0
|
|
898
901
|
this.ringFill = 0
|
|
899
|
-
if (this.offset !== null)
|
|
902
|
+
if (this.offset !== null) {
|
|
903
|
+
this.doubt = true
|
|
904
|
+
if (data.reset === 'seek') this.jumped = true
|
|
905
|
+
}
|
|
900
906
|
}
|
|
901
907
|
if (data?.reset === 'source') {
|
|
902
908
|
this.hist.fill(0)
|
|
@@ -930,6 +936,7 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
|
|
|
930
936
|
this.candidate = null
|
|
931
937
|
this.search = null
|
|
932
938
|
this.doubt = false
|
|
939
|
+
this.jumped = false
|
|
933
940
|
this.model = null
|
|
934
941
|
this.settling = []
|
|
935
942
|
this.liveCount = 0
|
|
@@ -945,16 +952,18 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
|
|
|
945
952
|
pair({ media, ctx, rate, paused }) {
|
|
946
953
|
const frame = ctx * sampleRate
|
|
947
954
|
const model = this.model
|
|
955
|
+
const previous = model ? this.mediaAt(frame) : media
|
|
956
|
+
if (this.offset !== null && !(Math.abs(media - previous) <= 0.025)) this.jumped = true
|
|
948
957
|
if (paused) {
|
|
949
958
|
// More than 25 ms from where the clock had it, the media is where the pair says: a seek moved it, its audio
|
|
950
959
|
// already playing (10 to 27 ms after the move in Chrome 155, where the main thread once took 52 ms to say so,
|
|
951
960
|
// 2026-10-30), or a pause was told late. The seek's reset, posted on the same event, is what puts it in doubt.
|
|
952
|
-
const held = model && !model.paused ?
|
|
961
|
+
const held = model && !model.paused ? previous : media
|
|
953
962
|
this.model = { paused: true, media: Math.abs(media - held) <= 0.025 ? held : media }
|
|
954
963
|
this.liveCount = 0
|
|
955
964
|
return
|
|
956
965
|
}
|
|
957
|
-
const predicted = model && !model.paused && model.rate === rate ?
|
|
966
|
+
const predicted = model && !model.paused && model.rate === rate ? previous : NaN
|
|
958
967
|
if (!(Math.abs(media - predicted) <= 0.025)) {
|
|
959
968
|
this.model = { frame, media, rate }
|
|
960
969
|
this.settling = []
|
|
@@ -1281,16 +1290,21 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
|
|
|
1281
1290
|
this.gainLine[at] = gain
|
|
1282
1291
|
|
|
1283
1292
|
if (ahead) {
|
|
1284
|
-
// at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower
|
|
1293
|
+
// at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower.
|
|
1294
|
+
// After a seek jump, a deeper cut takes effect at once so the first 1 to 2 ms of a loud sound are not left uncut.
|
|
1285
1295
|
let wantedDb = exact ? this.cutAt(this.mediaAt(start + i - delay) + this.offset) : held
|
|
1286
1296
|
if (!(wantedDb <= 0)) wantedDb = this.aheadDb
|
|
1287
1297
|
if (wantedDb > this.aheadDb + 0.2) wantedDb = this.aheadDb + 0.2
|
|
1288
|
-
else if (wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
|
|
1298
|
+
else if (!this.jumped && wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
|
|
1289
1299
|
this.aheadDb = wantedDb
|
|
1300
|
+
this.jumped = false
|
|
1290
1301
|
this.handover = Math.min(1, this.handover + handoverStep)
|
|
1291
1302
|
} else {
|
|
1292
1303
|
this.handover = Math.max(0, this.handover - handoverStep)
|
|
1293
|
-
if (this.handover === 0)
|
|
1304
|
+
if (this.handover === 0) {
|
|
1305
|
+
this.aheadDb = liveDb
|
|
1306
|
+
this.jumped = false
|
|
1307
|
+
}
|
|
1294
1308
|
}
|
|
1295
1309
|
this.mix += Math.max(-crossfadeStep, Math.min(crossfadeStep, target - this.mix))
|
|
1296
1310
|
const db = (liveDb + (this.aheadDb - liveDb) * this.handover) * this.mix
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@banou/media-player",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.50",
|
|
4
4
|
"description": "A video player for containers and codecs the browser cannot play natively, remuxed on the fly",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@videojs/react": "10.0.0-beta.26",
|
|
55
55
|
"ass-compiler": "^0.1.16",
|
|
56
56
|
"jassub": "^2.5.37",
|
|
57
|
-
"libav-wasm": "^0.8.
|
|
57
|
+
"libav-wasm": "^0.8.16",
|
|
58
58
|
"lucide-react": "^0.536.0",
|
|
59
59
|
"osra": "^0.6.12",
|
|
60
60
|
"react-tooltip": "^5.28.0"
|
|
@@ -23,7 +23,7 @@ export type LoudnessAnalysis = {
|
|
|
23
23
|
stop: () => void
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
type Coverage = { spans: [number, number][], end: number | null }
|
|
26
|
+
type Coverage = { spans: [number, number][], start: number | null, end: number | null }
|
|
27
27
|
|
|
28
28
|
// a gap this close ahead of the playhead is analysed before anything else
|
|
29
29
|
const LEAD_SECONDS = 20
|
|
@@ -85,7 +85,7 @@ export const startLoudnessAnalysis = ({ node, element, scriptUrl, source }: {
|
|
|
85
85
|
worker.postMessage({ type: 'port', port: channel.port1 }, [channel.port1])
|
|
86
86
|
node.port.postMessage({ analysis: channel.port2 }, [channel.port2])
|
|
87
87
|
|
|
88
|
-
let coverage: Coverage = { spans: [], end: null }
|
|
88
|
+
let coverage: Coverage = { spans: [], start: null, end: null }
|
|
89
89
|
let version = 0
|
|
90
90
|
const replies = new Map<string, (data: Coverage) => void>()
|
|
91
91
|
const reply = (type: string, run: number) => new Promise<Coverage>((resolve) => replies.set(`${type}:${run}`, resolve))
|
|
@@ -96,8 +96,9 @@ export const startLoudnessAnalysis = ({ node, element, scriptUrl, source }: {
|
|
|
96
96
|
return
|
|
97
97
|
}
|
|
98
98
|
if (data.spans) {
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
const start = data.start ?? null
|
|
100
|
+
if (JSON.stringify(data.spans) !== JSON.stringify(coverage.spans) || start !== coverage.start || data.end !== coverage.end) version++
|
|
101
|
+
coverage = { spans: data.spans, start, end: data.end }
|
|
101
102
|
}
|
|
102
103
|
if (data.type === 'merged') mergedRun = data.run
|
|
103
104
|
replies.get(`${data.type}:${data.run}`)?.(coverage)
|
|
@@ -129,12 +130,18 @@ export const startLoudnessAnalysis = ({ node, element, scriptUrl, source }: {
|
|
|
129
130
|
|
|
130
131
|
// the first time at or after `time` nothing analysed covers, or null when it is all analysed from there
|
|
131
132
|
const gapFrom = (time: number) => {
|
|
132
|
-
let at = time
|
|
133
|
+
let at = Math.max(time, coverage.start ?? 0)
|
|
133
134
|
for (const [from, to] of coverage.spans) if (from <= at && at < to) at = to
|
|
134
135
|
return at >= (coverage.end ?? duration) - 0.05 ? null : at
|
|
135
136
|
}
|
|
136
137
|
const attempt = (target: number) => tried.get(Math.round(target * 10)) === version ? 'idle' as const : target
|
|
138
|
+
const whole = () =>
|
|
139
|
+
coverage.start !== null && coverage.end !== null
|
|
140
|
+
&& coverage.spans.length === 1
|
|
141
|
+
&& coverage.spans[0]![0] <= coverage.start
|
|
142
|
+
&& coverage.spans[0]![1] >= coverage.end
|
|
137
143
|
const decide = (): 'read' | 'idle' | 'done' | number => {
|
|
144
|
+
if (whole()) return 'done'
|
|
138
145
|
const time = element.currentTime
|
|
139
146
|
const gap = gapFrom(time)
|
|
140
147
|
const reading = active && mergedRun !== run
|
|
@@ -240,6 +247,8 @@ export const startLoudnessAnalysis = ({ node, element, scriptUrl, source }: {
|
|
|
240
247
|
if (typeof decide() !== 'number') await changed()
|
|
241
248
|
}
|
|
242
249
|
}
|
|
250
|
+
if (!stopped) await endRun(false)
|
|
251
|
+
if (stopped) return
|
|
243
252
|
// everything is analysed: the worker keeps serving the cut, and the remuxer is no longer needed
|
|
244
253
|
terminateRemuxer(remuxer)
|
|
245
254
|
remuxer = undefined
|
|
@@ -37,7 +37,7 @@ export type Analysis = {
|
|
|
37
37
|
startRun: (id: number, time: number, start?: boolean) => void
|
|
38
38
|
push: (planes: Float32Array[], frames: number, rate: number, time: number) => void
|
|
39
39
|
endRun: (finished: boolean) => void
|
|
40
|
-
coverage: () => { spans: [number, number][], end: number | null, normal: number }
|
|
40
|
+
coverage: () => { spans: [number, number][], start: number | null, end: number | null, normal: number }
|
|
41
41
|
setPlayhead: (time: number) => void
|
|
42
42
|
flushBlocks: () => void
|
|
43
43
|
normal: () => number
|
|
@@ -45,5 +45,5 @@ export type Analysis = {
|
|
|
45
45
|
}
|
|
46
46
|
export const createAnalysis: (handlers: {
|
|
47
47
|
toWorklet: (message: BlockMessage, transfer?: Transferable[]) => void
|
|
48
|
-
toPage?: (message: { type: string, run?: number, spans?: [number, number][], end?: number | null, normal?: number }) => void
|
|
48
|
+
toPage?: (message: { type: string, run?: number, spans?: [number, number][], start?: number | null, end?: number | null, normal?: number }) => void
|
|
49
49
|
}) => Analysis
|
|
@@ -504,13 +504,13 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
|
|
|
504
504
|
const write = (run, bin, energy, finger) => {
|
|
505
505
|
if (bin < run.from || bin >= endBin) return
|
|
506
506
|
run.last = bin
|
|
507
|
+
if (run.start && firstBin < 0) firstBin = bin
|
|
507
508
|
if (spanAt(bin)) {
|
|
508
509
|
if (run.wrote && ++run.skipped === MERGED_BINS) toPage({ type: 'merged', run: run.id, ...coverage() })
|
|
509
510
|
return
|
|
510
511
|
}
|
|
511
512
|
run.skipped = 0
|
|
512
513
|
run.wrote = true
|
|
513
|
-
if (run.start && firstBin < 0) firstBin = bin
|
|
514
514
|
const chunk = chunkOf(bin)
|
|
515
515
|
chunk.energy[bin % BLOCK_BINS] = energy
|
|
516
516
|
chunk.finger[bin % BLOCK_BINS] = finger
|
|
@@ -589,6 +589,7 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
|
|
|
589
589
|
|
|
590
590
|
const coverage = () => ({
|
|
591
591
|
spans: spans.map(([a, b]) => [a / BINS_PER_SECOND, b / BINS_PER_SECOND]),
|
|
592
|
+
start: firstBin >= 0 ? firstBin / BINS_PER_SECOND : null,
|
|
592
593
|
end: Number.isFinite(endBin) ? endBin / BINS_PER_SECOND : null,
|
|
593
594
|
normal: normal(),
|
|
594
595
|
})
|
|
@@ -651,13 +652,13 @@ export const createAnalysis = ({ toWorklet, toPage = () => {} }) => {
|
|
|
651
652
|
* SourceBuffer's timestampOffset adds it for playback; `start` for the one
|
|
652
653
|
* from the start, and `join: true` for one whose first fragments went by
|
|
653
654
|
* unseen, which starts at its first sample
|
|
654
|
-
* { type: 'fragment', run, data } answered { type: 'ack', run, spans, end, normal } once its audio is
|
|
655
|
-
* for decoding: the analysed seconds, the
|
|
656
|
-
* level learned so far in LUFS
|
|
657
|
-
* { type: 'end', run, finished } the run is over, answered { type: 'ended', run, spans, end, normal }
|
|
655
|
+
* { type: 'fragment', run, data } answered { type: 'ack', run, spans, start, end, normal } once its audio is
|
|
656
|
+
* queued for decoding: the analysed seconds, the first and last once known,
|
|
657
|
+
* and the level learned so far in LUFS
|
|
658
|
+
* { type: 'end', run, finished } the run is over, answered { type: 'ended', run, spans, start, end, normal }
|
|
658
659
|
* { type: 'playhead', time }
|
|
659
660
|
*
|
|
660
|
-
* and posts { type: 'merged', run, spans, end, normal } when a run has met audio an earlier one analysed, and
|
|
661
|
+
* and posts { type: 'merged', run, spans, start, end, normal } when a run has met audio an earlier one analysed, and
|
|
661
662
|
* { type: 'unsupported' } when this browser's WebCodecs cannot decode the track.
|
|
662
663
|
*/
|
|
663
664
|
const serve = (scope) => {
|
|
@@ -727,7 +728,7 @@ const serve = (scope) => {
|
|
|
727
728
|
joining = !!data.join
|
|
728
729
|
if (!joining) analysis.startRun(runId, data.from, data.start)
|
|
729
730
|
} else if (data.type === 'fragment') {
|
|
730
|
-
if (data.run !== runId || decoder
|
|
731
|
+
if (data.run !== runId || decoder?.state !== 'configured') return
|
|
731
732
|
const samples = audioSamplesOf(data.data, track)
|
|
732
733
|
if (joining && samples.length) {
|
|
733
734
|
joining = false
|
|
@@ -748,9 +749,11 @@ const serve = (scope) => {
|
|
|
748
749
|
} else if (data.type === 'end') {
|
|
749
750
|
if (data.run !== runId) return
|
|
750
751
|
const ending = decoder
|
|
751
|
-
if (ending
|
|
752
|
+
if (ending?.state === 'configured') await ending.flush().catch(() => {})
|
|
752
753
|
if (data.run !== runId) return
|
|
753
|
-
if (ending
|
|
754
|
+
if (ending?.state === 'configured') ending.close()
|
|
755
|
+
if (decoder === ending) decoder = undefined
|
|
756
|
+
stamps = []
|
|
754
757
|
analysis.endRun(data.finished)
|
|
755
758
|
scope.postMessage({ type: 'ended', run: data.run, ...analysis.coverage() })
|
|
756
759
|
}
|
|
@@ -896,7 +899,10 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
|
|
|
896
899
|
this.ring.fill(0)
|
|
897
900
|
this.ringSum = 0
|
|
898
901
|
this.ringFill = 0
|
|
899
|
-
if (this.offset !== null)
|
|
902
|
+
if (this.offset !== null) {
|
|
903
|
+
this.doubt = true
|
|
904
|
+
if (data.reset === 'seek') this.jumped = true
|
|
905
|
+
}
|
|
900
906
|
}
|
|
901
907
|
if (data?.reset === 'source') {
|
|
902
908
|
this.hist.fill(0)
|
|
@@ -930,6 +936,7 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
|
|
|
930
936
|
this.candidate = null
|
|
931
937
|
this.search = null
|
|
932
938
|
this.doubt = false
|
|
939
|
+
this.jumped = false
|
|
933
940
|
this.model = null
|
|
934
941
|
this.settling = []
|
|
935
942
|
this.liveCount = 0
|
|
@@ -945,16 +952,18 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
|
|
|
945
952
|
pair({ media, ctx, rate, paused }) {
|
|
946
953
|
const frame = ctx * sampleRate
|
|
947
954
|
const model = this.model
|
|
955
|
+
const previous = model ? this.mediaAt(frame) : media
|
|
956
|
+
if (this.offset !== null && !(Math.abs(media - previous) <= 0.025)) this.jumped = true
|
|
948
957
|
if (paused) {
|
|
949
958
|
// More than 25 ms from where the clock had it, the media is where the pair says: a seek moved it, its audio
|
|
950
959
|
// already playing (10 to 27 ms after the move in Chrome 155, where the main thread once took 52 ms to say so,
|
|
951
960
|
// 2026-10-30), or a pause was told late. The seek's reset, posted on the same event, is what puts it in doubt.
|
|
952
|
-
const held = model && !model.paused ?
|
|
961
|
+
const held = model && !model.paused ? previous : media
|
|
953
962
|
this.model = { paused: true, media: Math.abs(media - held) <= 0.025 ? held : media }
|
|
954
963
|
this.liveCount = 0
|
|
955
964
|
return
|
|
956
965
|
}
|
|
957
|
-
const predicted = model && !model.paused && model.rate === rate ?
|
|
966
|
+
const predicted = model && !model.paused && model.rate === rate ? previous : NaN
|
|
958
967
|
if (!(Math.abs(media - predicted) <= 0.025)) {
|
|
959
968
|
this.model = { frame, media, rate }
|
|
960
969
|
this.settling = []
|
|
@@ -1281,16 +1290,21 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
|
|
|
1281
1290
|
this.gainLine[at] = gain
|
|
1282
1291
|
|
|
1283
1292
|
if (ahead) {
|
|
1284
|
-
// at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower
|
|
1293
|
+
// at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower.
|
|
1294
|
+
// After a seek jump, a deeper cut takes effect at once so the first 1 to 2 ms of a loud sound are not left uncut.
|
|
1285
1295
|
let wantedDb = exact ? this.cutAt(this.mediaAt(start + i - delay) + this.offset) : held
|
|
1286
1296
|
if (!(wantedDb <= 0)) wantedDb = this.aheadDb
|
|
1287
1297
|
if (wantedDb > this.aheadDb + 0.2) wantedDb = this.aheadDb + 0.2
|
|
1288
|
-
else if (wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
|
|
1298
|
+
else if (!this.jumped && wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
|
|
1289
1299
|
this.aheadDb = wantedDb
|
|
1300
|
+
this.jumped = false
|
|
1290
1301
|
this.handover = Math.min(1, this.handover + handoverStep)
|
|
1291
1302
|
} else {
|
|
1292
1303
|
this.handover = Math.max(0, this.handover - handoverStep)
|
|
1293
|
-
if (this.handover === 0)
|
|
1304
|
+
if (this.handover === 0) {
|
|
1305
|
+
this.aheadDb = liveDb
|
|
1306
|
+
this.jumped = false
|
|
1307
|
+
}
|
|
1294
1308
|
}
|
|
1295
1309
|
this.mix += Math.max(-crossfadeStep, Math.min(crossfadeStep, target - this.mix))
|
|
1296
1310
|
const db = (liveDb + (this.aheadDb - liveDb) * this.handover) * this.mix
|
|
@@ -177,11 +177,18 @@ export const createPictureInPicture = (options: PictureInPictureOptions): Pictur
|
|
|
177
177
|
|
|
178
178
|
const draw = (composite: HTMLCanvasElement, context: CanvasRenderingContext2D) => {
|
|
179
179
|
context.drawImage(video, 0, 0, composite.width, composite.height)
|
|
180
|
-
// Resolved per frame: the renderer replaces this element on every pipeline rebuild. A
|
|
181
|
-
//
|
|
182
|
-
//
|
|
180
|
+
// Resolved per frame: the renderer replaces this element on every pipeline rebuild. A new
|
|
181
|
+
// canvas keeps HTML's 300 by 150 default while jassub's worker boots, and copying it in Firefox
|
|
182
|
+
// then blocks the page for 10 s on OffscreenCanvasDisplayHelper::GetSurfaceSnapshot, so the
|
|
183
|
+
// renderer marks it `data-pending` until `ready` resolves.
|
|
183
184
|
const surface = subtitles.querySelector('canvas')
|
|
184
|
-
if (
|
|
185
|
+
if (
|
|
186
|
+
surface &&
|
|
187
|
+
!('pending' in surface.dataset) &&
|
|
188
|
+
surface.width > 0 &&
|
|
189
|
+
surface.height > 0 &&
|
|
190
|
+
Math.abs(video.currentTime - frameTime) <= STALE_SUBTITLES_S
|
|
191
|
+
) {
|
|
185
192
|
context.drawImage(surface, 0, 0, composite.width, composite.height)
|
|
186
193
|
}
|
|
187
194
|
}
|
|
@@ -301,6 +301,7 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
301
301
|
|
|
302
302
|
const bootJassub = (header: SubtitleHeaderPart) => {
|
|
303
303
|
const canvas = document.createElement('canvas')
|
|
304
|
+
canvas.dataset.pending = ''
|
|
304
305
|
container.append(canvas)
|
|
305
306
|
try {
|
|
306
307
|
jassub = new JASSUB({
|
|
@@ -328,8 +329,13 @@ export const createSubtitleRenderer = (options: SubtitleRendererOptions) => {
|
|
|
328
329
|
}
|
|
329
330
|
// Not handed to the constructor, which attaches it with a `setVideo` nothing catches: that rejects with `ready`, so a
|
|
330
331
|
// renderer that cannot start would leave an unhandled rejection in the host page.
|
|
331
|
-
|
|
332
|
-
void
|
|
332
|
+
const instance = jassub
|
|
333
|
+
void instance.setVideo(video).catch(startFailed)
|
|
334
|
+
// Cleared once the worker has booted: in Firefox, copying a transferred canvas while its worker
|
|
335
|
+
// starts blocks the page for 10 s on OffscreenCanvasDisplayHelper::GetSurfaceSnapshot.
|
|
336
|
+
void instance.ready.then(() => {
|
|
337
|
+
if (jassub === instance) delete canvas.dataset.pending
|
|
338
|
+
}, rendererFailed)
|
|
333
339
|
for (const type of REPAINT_ON) video.addEventListener(type, onRepaintEvent)
|
|
334
340
|
/*
|
|
335
341
|
* The default face is the one font jassub loads LAZILY. Attachments are handed to the constructor
|