avbridge 2.10.0 → 2.12.0

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/{avi-B5CQYB7L.cjs → avi-EQE6AR75.cjs} +4 -4
  3. package/dist/{avi-2ILLBNPQ.cjs.map → avi-EQE6AR75.cjs.map} +1 -1
  4. package/dist/{avi-RWWPN2PR.js → avi-NNHH4AAA.js} +3 -3
  5. package/dist/{avi-JXU4GQL2.js.map → avi-NNHH4AAA.js.map} +1 -1
  6. package/dist/{avi-JXU4GQL2.js → avi-S7EY54YA.js} +3 -3
  7. package/dist/{avi-RWWPN2PR.js.map → avi-S7EY54YA.js.map} +1 -1
  8. package/dist/{avi-2ILLBNPQ.cjs → avi-Y3N325WZ.cjs} +4 -4
  9. package/dist/{avi-B5CQYB7L.cjs.map → avi-Y3N325WZ.cjs.map} +1 -1
  10. package/dist/{chunk-GYIJU44C.js → chunk-2LNXMGT6.js} +5 -5
  11. package/dist/{chunk-GYIJU44C.js.map → chunk-2LNXMGT6.js.map} +1 -1
  12. package/dist/{chunk-DCSOQH2N.js → chunk-3AI5WFFN.js} +40 -16
  13. package/dist/chunk-3AI5WFFN.js.map +1 -0
  14. package/dist/{chunk-2NSOOMXW.js → chunk-3YKWU4FM.js} +3 -3
  15. package/dist/{chunk-2NSOOMXW.js.map → chunk-3YKWU4FM.js.map} +1 -1
  16. package/dist/{chunk-CL6UEUQF.js → chunk-5Y5BTB5D.js} +5 -5
  17. package/dist/{chunk-CL6UEUQF.js.map → chunk-5Y5BTB5D.js.map} +1 -1
  18. package/dist/{chunk-NQULEIA3.cjs → chunk-7EF4VTUS.cjs} +36 -28
  19. package/dist/chunk-7EF4VTUS.cjs.map +1 -0
  20. package/dist/{chunk-5KVLE6YI.js → chunk-EDDWAN2L.js} +3 -2
  21. package/dist/chunk-EDDWAN2L.js.map +1 -0
  22. package/dist/{chunk-OTFS7DC4.cjs → chunk-GJBNLPGI.cjs} +14 -14
  23. package/dist/{chunk-OTFS7DC4.cjs.map → chunk-GJBNLPGI.cjs.map} +1 -1
  24. package/dist/{chunk-BYGZN4Z5.cjs → chunk-HBHSUGNI.cjs} +5 -5
  25. package/dist/{chunk-BYGZN4Z5.cjs.map → chunk-HBHSUGNI.cjs.map} +1 -1
  26. package/dist/{chunk-L7A3ECI2.cjs → chunk-HZUVMXBN.cjs} +4 -4
  27. package/dist/{chunk-L7A3ECI2.cjs.map → chunk-HZUVMXBN.cjs.map} +1 -1
  28. package/dist/{chunk-S4WAZC2T.cjs → chunk-WRKO6Q42.cjs} +3 -2
  29. package/dist/chunk-WRKO6Q42.cjs.map +1 -0
  30. package/dist/{chunk-Z33SBWL5.cjs → chunk-YPZFGJV3.cjs} +40 -16
  31. package/dist/chunk-YPZFGJV3.cjs.map +1 -0
  32. package/dist/{chunk-3GKM5DFM.js → chunk-Z26PXRUY.js} +18 -10
  33. package/dist/chunk-Z26PXRUY.js.map +1 -0
  34. package/dist/element-browser.js +65 -19
  35. package/dist/element-browser.js.map +1 -1
  36. package/dist/element.cjs +21 -8
  37. package/dist/element.cjs.map +1 -1
  38. package/dist/element.d.cts +1 -1
  39. package/dist/element.d.ts +1 -1
  40. package/dist/element.js +20 -7
  41. package/dist/element.js.map +1 -1
  42. package/dist/index.cjs +23 -23
  43. package/dist/index.d.cts +2 -2
  44. package/dist/index.d.ts +2 -2
  45. package/dist/index.js +10 -10
  46. package/dist/{libav-demux-3N5Y3VQA.cjs → libav-demux-575OYCT2.cjs} +9 -9
  47. package/dist/{libav-demux-3N5Y3VQA.cjs.map → libav-demux-575OYCT2.cjs.map} +1 -1
  48. package/dist/{libav-demux-JXD4OTLM.js → libav-demux-SXZDLC7W.js} +4 -4
  49. package/dist/{libav-demux-JXD4OTLM.js.map → libav-demux-SXZDLC7W.js.map} +1 -1
  50. package/dist/libav-http-reader-2S5HAHW4.js +3 -0
  51. package/dist/{libav-http-reader-WXG3Z7AI.js.map → libav-http-reader-2S5HAHW4.js.map} +1 -1
  52. package/dist/libav-http-reader-Q356EO2K.cjs +16 -0
  53. package/dist/{libav-http-reader-AZLE7YFS.cjs.map → libav-http-reader-Q356EO2K.cjs.map} +1 -1
  54. package/dist/{player-DDdNVFDv.d.cts → player-bQ6n4hVp.d.cts} +15 -0
  55. package/dist/{player-DDdNVFDv.d.ts → player-bQ6n4hVp.d.ts} +15 -0
  56. package/dist/player.cjs +166 -33
  57. package/dist/player.cjs.map +1 -1
  58. package/dist/player.d.cts +36 -0
  59. package/dist/player.d.ts +36 -0
  60. package/dist/player.js +162 -29
  61. package/dist/player.js.map +1 -1
  62. package/dist/remux-7TA4FKTY.js +10 -0
  63. package/dist/{remux-56V7LDAD.js.map → remux-7TA4FKTY.js.map} +1 -1
  64. package/dist/remux-VPKCLHHM.cjs +35 -0
  65. package/dist/{remux-KUS5GIL6.cjs.map → remux-VPKCLHHM.cjs.map} +1 -1
  66. package/dist/subtitles-5H24MEBJ.js +4 -0
  67. package/dist/{subtitles-4T74JRGT.js.map → subtitles-5H24MEBJ.js.map} +1 -1
  68. package/dist/subtitles-HMVGWTU2.cjs +29 -0
  69. package/dist/{subtitles-QUH4LPI4.cjs.map → subtitles-HMVGWTU2.cjs.map} +1 -1
  70. package/package.json +1 -1
  71. package/src/element/avbridge-player.ts +128 -18
  72. package/src/element/avbridge-subtitles.ts +273 -0
  73. package/src/element/avbridge-video.ts +21 -1
  74. package/src/element/player-styles.ts +13 -1
  75. package/src/player.ts +3 -3
  76. package/src/strategies/fallback/audio-output.ts +10 -0
  77. package/src/subtitles/index.ts +2 -0
  78. package/src/types.ts +15 -0
  79. package/src/util/libav-http-reader.ts +58 -19
  80. package/dist/chunk-3GKM5DFM.js.map +0 -1
  81. package/dist/chunk-5KVLE6YI.js.map +0 -1
  82. package/dist/chunk-DCSOQH2N.js.map +0 -1
  83. package/dist/chunk-NQULEIA3.cjs.map +0 -1
  84. package/dist/chunk-S4WAZC2T.cjs.map +0 -1
  85. package/dist/chunk-Z33SBWL5.cjs.map +0 -1
  86. package/dist/libav-http-reader-AZLE7YFS.cjs +0 -16
  87. package/dist/libav-http-reader-WXG3Z7AI.js +0 -3
  88. package/dist/remux-56V7LDAD.js +0 -10
  89. package/dist/remux-KUS5GIL6.cjs +0 -35
  90. package/dist/subtitles-4T74JRGT.js +0 -4
  91. package/dist/subtitles-QUH4LPI4.cjs +0 -29
@@ -29513,7 +29513,8 @@ async function prepareLibavInput(libav, filename, source, transport) {
29513
29513
  if (source.kind === "url") {
29514
29514
  const handle = await attachLibavHttpReader(libav, filename, source.url, {
29515
29515
  requestInit: transport?.requestInit,
29516
- fetchFn: transport?.fetchFn
29516
+ fetchFn: transport?.fetchFn,
29517
+ cacheBytes: transport?.cacheBytes
29517
29518
  });
29518
29519
  return {
29519
29520
  filename,
@@ -29575,7 +29576,9 @@ async function attachLibavHttpReader(libav, filename, url2, options = {}) {
29575
29576
  }
29576
29577
  await libav.mkblockreaderdev(filename, size);
29577
29578
  let detached = false;
29578
- let cached = null;
29579
+ const cache2 = /* @__PURE__ */ new Map();
29580
+ let cacheBytes = 0;
29581
+ const cacheBudget = Math.max(0, options.cacheBytes ?? DEFAULT_CACHE_BYTES);
29579
29582
  let inflight = null;
29580
29583
  function clampReadLength(requested) {
29581
29584
  const doubled = requested * 2;
@@ -29583,14 +29586,33 @@ async function attachLibavHttpReader(libav, filename, url2, options = {}) {
29583
29586
  if (doubled > MAX_READ) return MAX_READ;
29584
29587
  return doubled;
29585
29588
  }
29586
- function cacheCovers(pos, length) {
29587
- if (!cached) return false;
29588
- return pos >= cached.pos && pos + length <= cached.pos + cached.bytes.byteLength;
29589
+ function cacheLookup(pos, length) {
29590
+ for (const [blockPos, bytes2] of cache2) {
29591
+ if (pos >= blockPos && pos + length <= blockPos + bytes2.byteLength) {
29592
+ cache2.delete(blockPos);
29593
+ cache2.set(blockPos, bytes2);
29594
+ const offset = pos - blockPos;
29595
+ return bytes2.subarray(offset, offset + length);
29596
+ }
29597
+ }
29598
+ return null;
29589
29599
  }
29590
- function sliceFromCache(pos, length) {
29591
- if (!cached) throw new Error("sliceFromCache called with no cache");
29592
- const offset = pos - cached.pos;
29593
- return cached.bytes.subarray(offset, offset + length);
29600
+ function cacheInsert(pos, bytes2) {
29601
+ const existing = cache2.get(pos);
29602
+ if (existing) {
29603
+ cacheBytes -= existing.byteLength;
29604
+ cache2.delete(pos);
29605
+ }
29606
+ cache2.set(pos, bytes2);
29607
+ cacheBytes += bytes2.byteLength;
29608
+ while (cacheBytes > cacheBudget && cache2.size > 0) {
29609
+ const oldestKey = cache2.keys().next().value;
29610
+ if (oldestKey === void 0) break;
29611
+ const oldest = cache2.get(oldestKey);
29612
+ if (!oldest) break;
29613
+ cache2.delete(oldestKey);
29614
+ cacheBytes -= oldest.byteLength;
29615
+ }
29594
29616
  }
29595
29617
  async function fetchRange(pos, length) {
29596
29618
  const end = Math.min(pos + length - 1, size - 1);
@@ -29607,7 +29629,7 @@ async function attachLibavHttpReader(libav, filename, url2, options = {}) {
29607
29629
  );
29608
29630
  }
29609
29631
  const buf = new Uint8Array(await res.arrayBuffer());
29610
- cached = { pos, bytes: buf };
29632
+ cacheInsert(pos, buf);
29611
29633
  return buf;
29612
29634
  }
29613
29635
  async function handleRead(name, pos, length) {
@@ -29618,10 +29640,10 @@ async function attachLibavHttpReader(libav, filename, url2, options = {}) {
29618
29640
  }
29619
29641
  }
29620
29642
  if (detached) return;
29621
- if (cacheCovers(pos, length)) {
29622
- const data = sliceFromCache(pos, length);
29643
+ const hit = cacheLookup(pos, length);
29644
+ if (hit) {
29623
29645
  try {
29624
- await libav.ff_block_reader_dev_send(name, pos, data);
29646
+ await libav.ff_block_reader_dev_send(name, pos, hit);
29625
29647
  } catch {
29626
29648
  }
29627
29649
  return;
@@ -29674,7 +29696,8 @@ async function attachLibavHttpReader(libav, filename, url2, options = {}) {
29674
29696
  } catch {
29675
29697
  }
29676
29698
  }
29677
- cached = null;
29699
+ cache2.clear();
29700
+ cacheBytes = 0;
29678
29701
  try {
29679
29702
  await libav.unlinkreadaheadfile(filename);
29680
29703
  } catch {
@@ -29682,11 +29705,12 @@ async function attachLibavHttpReader(libav, filename, url2, options = {}) {
29682
29705
  }
29683
29706
  };
29684
29707
  }
29685
- var MIN_READ, MAX_READ;
29708
+ var MIN_READ, MAX_READ, DEFAULT_CACHE_BYTES;
29686
29709
  var init_libav_http_reader = __esm({
29687
29710
  "src/util/libav-http-reader.ts"() {
29688
29711
  MIN_READ = 256 * 1024;
29689
29712
  MAX_READ = 1 * 1024 * 1024;
29713
+ DEFAULT_CACHE_BYTES = 8 * 1024 * 1024;
29690
29714
  }
29691
29715
  });
29692
29716
 
@@ -31144,6 +31168,7 @@ async function attachSubtitleTracks(video, tracks, bag, onError, transport) {
31144
31168
  }
31145
31169
  for (const t of tracks) {
31146
31170
  if (!t.sidecarUrl) continue;
31171
+ console.log(`[avbridge:subs] attaching track id=${t.id} format=${t.format} url=${t.sidecarUrl.slice(0, 60)}`);
31147
31172
  try {
31148
31173
  let url2 = t.sidecarUrl;
31149
31174
  if (t.format === "srt") {
@@ -32952,6 +32977,10 @@ var AudioOutput = class {
32952
32977
  if (this.ctx.state === "suspended") {
32953
32978
  await this.ctx.resume();
32954
32979
  }
32980
+ try {
32981
+ this.gain.connect(this.ctx.destination);
32982
+ } catch {
32983
+ }
32955
32984
  if (this.state === "paused") {
32956
32985
  this.ctxTimeAtAnchor = this.ctx.currentTime;
32957
32986
  this.state = "playing";
@@ -32978,6 +33007,10 @@ var AudioOutput = class {
32978
33007
  this.mediaTimeOfAnchor = this.now();
32979
33008
  this.state = "paused";
32980
33009
  if (this.noAudio) return;
33010
+ try {
33011
+ this.gain.disconnect();
33012
+ } catch {
33013
+ }
32981
33014
  if (this.ctx.state === "running") {
32982
33015
  await this.ctx.suspend();
32983
33016
  }
@@ -34625,9 +34658,9 @@ var UnifiedPlayer = class _UnifiedPlayer {
34625
34658
  constructor(options, registry) {
34626
34659
  this.options = options;
34627
34660
  this.registry = registry;
34628
- const { requestInit, fetchFn } = options;
34629
- if (requestInit || fetchFn) {
34630
- this.transport = { requestInit, fetchFn };
34661
+ const { requestInit, fetchFn, cacheBytes } = options;
34662
+ if (requestInit || fetchFn || cacheBytes !== void 0) {
34663
+ this.transport = { requestInit, fetchFn, cacheBytes };
34631
34664
  }
34632
34665
  }
34633
34666
  options;
@@ -35787,14 +35820,27 @@ var AvbridgeVideoElement = class extends HTMLElementCtor {
35787
35820
  sidecarUrl: subtitle.url
35788
35821
  };
35789
35822
  this._subtitleTracks.push(track);
35823
+ console.log(`[avbridge:subs] addSubtitle id=${track.id} format=${format} lang=${subtitle.language ?? "?"}`);
35790
35824
  await attachSubtitleTracks2(
35791
35825
  this._videoEl,
35792
35826
  this._subtitleTracks,
35793
35827
  void 0,
35794
35828
  (err, t) => {
35795
- console.warn(`[avbridge] subtitle ${t.id} failed: ${err.message}`);
35829
+ console.warn(`[avbridge:subs] subtitle ${t.id} failed: ${err.message}`);
35796
35830
  }
35797
35831
  );
35832
+ const textTracks = this._videoEl.textTracks;
35833
+ for (let i = 0; i < textTracks.length; i++) {
35834
+ if (textTracks[i].label === (subtitle.language ?? `Subtitle ${track.id}`)) {
35835
+ textTracks[i].mode = "showing";
35836
+ console.log(`[avbridge:subs] enabled textTrack[${i}] mode=showing`);
35837
+ break;
35838
+ }
35839
+ }
35840
+ this._dispatch("trackschange", {
35841
+ audioTracks: this._audioTracks,
35842
+ subtitleTracks: this.subtitleTracks
35843
+ });
35798
35844
  }
35799
35845
  /**
35800
35846
  * Disable the automatic `screen.orientation.lock()` that runs on