@banou/media-player 0.10.48 → 0.10.49

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.
@@ -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-wP5Udzzj.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-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
- h.setVideo(t).catch(E), h.ready.catch(T);
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-wP5Udzzj.js";
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";
@@ -896,7 +896,10 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
896
896
  this.ring.fill(0)
897
897
  this.ringSum = 0
898
898
  this.ringFill = 0
899
- if (this.offset !== null) this.doubt = true
899
+ if (this.offset !== null) {
900
+ this.doubt = true
901
+ if (data.reset === 'seek') this.jumped = true
902
+ }
900
903
  }
901
904
  if (data?.reset === 'source') {
902
905
  this.hist.fill(0)
@@ -930,6 +933,7 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
930
933
  this.candidate = null
931
934
  this.search = null
932
935
  this.doubt = false
936
+ this.jumped = false
933
937
  this.model = null
934
938
  this.settling = []
935
939
  this.liveCount = 0
@@ -945,16 +949,18 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
945
949
  pair({ media, ctx, rate, paused }) {
946
950
  const frame = ctx * sampleRate
947
951
  const model = this.model
952
+ const previous = model ? this.mediaAt(frame) : media
953
+ if (this.offset !== null && !(Math.abs(media - previous) <= 0.025)) this.jumped = true
948
954
  if (paused) {
949
955
  // More than 25 ms from where the clock had it, the media is where the pair says: a seek moved it, its audio
950
956
  // already playing (10 to 27 ms after the move in Chrome 155, where the main thread once took 52 ms to say so,
951
957
  // 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 ? this.mediaAt(frame) : media
958
+ const held = model && !model.paused ? previous : media
953
959
  this.model = { paused: true, media: Math.abs(media - held) <= 0.025 ? held : media }
954
960
  this.liveCount = 0
955
961
  return
956
962
  }
957
- const predicted = model && !model.paused && model.rate === rate ? model.media + (frame - model.frame) * rate / sampleRate : NaN
963
+ const predicted = model && !model.paused && model.rate === rate ? previous : NaN
958
964
  if (!(Math.abs(media - predicted) <= 0.025)) {
959
965
  this.model = { frame, media, rate }
960
966
  this.settling = []
@@ -1281,16 +1287,21 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
1281
1287
  this.gainLine[at] = gain
1282
1288
 
1283
1289
  if (ahead) {
1284
- // at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower
1290
+ // at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower.
1291
+ // 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
1292
  let wantedDb = exact ? this.cutAt(this.mediaAt(start + i - delay) + this.offset) : held
1286
1293
  if (!(wantedDb <= 0)) wantedDb = this.aheadDb
1287
1294
  if (wantedDb > this.aheadDb + 0.2) wantedDb = this.aheadDb + 0.2
1288
- else if (wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
1295
+ else if (!this.jumped && wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
1289
1296
  this.aheadDb = wantedDb
1297
+ this.jumped = false
1290
1298
  this.handover = Math.min(1, this.handover + handoverStep)
1291
1299
  } else {
1292
1300
  this.handover = Math.max(0, this.handover - handoverStep)
1293
- if (this.handover === 0) this.aheadDb = liveDb
1301
+ if (this.handover === 0) {
1302
+ this.aheadDb = liveDb
1303
+ this.jumped = false
1304
+ }
1294
1305
  }
1295
1306
  this.mix += Math.max(-crossfadeStep, Math.min(crossfadeStep, target - this.mix))
1296
1307
  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.48",
3
+ "version": "0.10.49",
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.14",
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"
@@ -896,7 +896,10 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
896
896
  this.ring.fill(0)
897
897
  this.ringSum = 0
898
898
  this.ringFill = 0
899
- if (this.offset !== null) this.doubt = true
899
+ if (this.offset !== null) {
900
+ this.doubt = true
901
+ if (data.reset === 'seek') this.jumped = true
902
+ }
900
903
  }
901
904
  if (data?.reset === 'source') {
902
905
  this.hist.fill(0)
@@ -930,6 +933,7 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
930
933
  this.candidate = null
931
934
  this.search = null
932
935
  this.doubt = false
936
+ this.jumped = false
933
937
  this.model = null
934
938
  this.settling = []
935
939
  this.liveCount = 0
@@ -945,16 +949,18 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
945
949
  pair({ media, ctx, rate, paused }) {
946
950
  const frame = ctx * sampleRate
947
951
  const model = this.model
952
+ const previous = model ? this.mediaAt(frame) : media
953
+ if (this.offset !== null && !(Math.abs(media - previous) <= 0.025)) this.jumped = true
948
954
  if (paused) {
949
955
  // More than 25 ms from where the clock had it, the media is where the pair says: a seek moved it, its audio
950
956
  // already playing (10 to 27 ms after the move in Chrome 155, where the main thread once took 52 ms to say so,
951
957
  // 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 ? this.mediaAt(frame) : media
958
+ const held = model && !model.paused ? previous : media
953
959
  this.model = { paused: true, media: Math.abs(media - held) <= 0.025 ? held : media }
954
960
  this.liveCount = 0
955
961
  return
956
962
  }
957
- const predicted = model && !model.paused && model.rate === rate ? model.media + (frame - model.frame) * rate / sampleRate : NaN
963
+ const predicted = model && !model.paused && model.rate === rate ? previous : NaN
958
964
  if (!(Math.abs(media - predicted) <= 0.025)) {
959
965
  this.model = { frame, media, rate }
960
966
  this.settling = []
@@ -1281,16 +1287,21 @@ const defineProcessor = () => class VolumeNormalizer extends AudioWorkletProcess
1281
1287
  this.gainLine[at] = gain
1282
1288
 
1283
1289
  if (ahead) {
1284
- // at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower
1290
+ // at most 0.2 dB a sample, so a change of mode cannot click; the cut itself moves slower.
1291
+ // 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
1292
  let wantedDb = exact ? this.cutAt(this.mediaAt(start + i - delay) + this.offset) : held
1286
1293
  if (!(wantedDb <= 0)) wantedDb = this.aheadDb
1287
1294
  if (wantedDb > this.aheadDb + 0.2) wantedDb = this.aheadDb + 0.2
1288
- else if (wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
1295
+ else if (!this.jumped && wantedDb < this.aheadDb - 0.2) wantedDb = this.aheadDb - 0.2
1289
1296
  this.aheadDb = wantedDb
1297
+ this.jumped = false
1290
1298
  this.handover = Math.min(1, this.handover + handoverStep)
1291
1299
  } else {
1292
1300
  this.handover = Math.max(0, this.handover - handoverStep)
1293
- if (this.handover === 0) this.aheadDb = liveDb
1301
+ if (this.handover === 0) {
1302
+ this.aheadDb = liveDb
1303
+ this.jumped = false
1304
+ }
1294
1305
  }
1295
1306
  this.mix += Math.max(-crossfadeStep, Math.min(crossfadeStep, target - this.mix))
1296
1307
  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 canvas
181
- // jassub has transferred reports the size of the last frame its worker committed, so the zero
182
- // check still keeps drawImage off a source with no dimensions to read.
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 (surface && surface.width > 0 && surface.height > 0 && Math.abs(video.currentTime - frameTime) <= STALE_SUBTITLES_S) {
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
- void jassub.setVideo(video).catch(startFailed)
332
- void jassub.ready.catch(rendererFailed)
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