@videojs/hlsjs-video 10.0.0-rc.1

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 (56) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +36 -0
  3. package/dist/default/adapter.js +289 -0
  4. package/dist/default/adapter.js.map +1 -0
  5. package/dist/default/airplay-bridge.js +76 -0
  6. package/dist/default/airplay-bridge.js.map +1 -0
  7. package/dist/default/cap-level.js +191 -0
  8. package/dist/default/cap-level.js.map +1 -0
  9. package/dist/default/drm.js +46 -0
  10. package/dist/default/drm.js.map +1 -0
  11. package/dist/default/errors.js +58 -0
  12. package/dist/default/errors.js.map +1 -0
  13. package/dist/default/hls-js-only.js +99 -0
  14. package/dist/default/hls-js-only.js.map +1 -0
  15. package/dist/default/index.js +3 -0
  16. package/dist/default/live.js +124 -0
  17. package/dist/default/live.js.map +1 -0
  18. package/dist/default/media-tracks.js +123 -0
  19. package/dist/default/media-tracks.js.map +1 -0
  20. package/dist/default/metadata-tracks.js +40 -0
  21. package/dist/default/metadata-tracks.js.map +1 -0
  22. package/dist/default/preload.js +91 -0
  23. package/dist/default/preload.js.map +1 -0
  24. package/dist/default/stream-type.js +43 -0
  25. package/dist/default/stream-type.js.map +1 -0
  26. package/dist/default/text-tracks.js +162 -0
  27. package/dist/default/text-tracks.js.map +1 -0
  28. package/dist/dev/adapter.d.ts +188 -0
  29. package/dist/dev/adapter.d.ts.map +1 -0
  30. package/dist/dev/adapter.js +305 -0
  31. package/dist/dev/adapter.js.map +1 -0
  32. package/dist/dev/airplay-bridge.js +76 -0
  33. package/dist/dev/airplay-bridge.js.map +1 -0
  34. package/dist/dev/cap-level.js +191 -0
  35. package/dist/dev/cap-level.js.map +1 -0
  36. package/dist/dev/drm.js +50 -0
  37. package/dist/dev/drm.js.map +1 -0
  38. package/dist/dev/errors.js +58 -0
  39. package/dist/dev/errors.js.map +1 -0
  40. package/dist/dev/hls-js-only.js +99 -0
  41. package/dist/dev/hls-js-only.js.map +1 -0
  42. package/dist/dev/index.d.ts +3 -0
  43. package/dist/dev/index.js +3 -0
  44. package/dist/dev/live.js +124 -0
  45. package/dist/dev/live.js.map +1 -0
  46. package/dist/dev/media-tracks.js +123 -0
  47. package/dist/dev/media-tracks.js.map +1 -0
  48. package/dist/dev/metadata-tracks.js +40 -0
  49. package/dist/dev/metadata-tracks.js.map +1 -0
  50. package/dist/dev/preload.js +91 -0
  51. package/dist/dev/preload.js.map +1 -0
  52. package/dist/dev/stream-type.js +43 -0
  53. package/dist/dev/stream-type.js.map +1 -0
  54. package/dist/dev/text-tracks.js +162 -0
  55. package/dist/dev/text-tracks.js.map +1 -0
  56. package/package.json +54 -0
@@ -0,0 +1,191 @@
1
+ import Hls from "hls.js";
2
+ //#region src/cap-level.ts
3
+ /**
4
+ * Floor applied to the player-size cap unless a source names another.
5
+ *
6
+ * The low rungs of a ladder are there for bad network conditions, and at that end the relationship between resolution
7
+ * and perceived quality stops holding: a small player capped to 360p looks worse than its size alone suggests. No
8
+ * reliable signal exists to key that on, so a fixed floor stands in for one.
9
+ */
10
+ const DEFAULT_MIN_AUTO_RESOLUTION = "720p";
11
+ /**
12
+ * Pixel area of a resolution shorthand, assuming 16:9 — `'720p'` is `1280 × 720`, or `921_600`.
13
+ *
14
+ * Renditions are matched on area rather than literal height so anamorphic variants are judged by how many pixels they
15
+ * actually carry: a 2560×1080 ultrawide rendition costs more than 16:9 1080p and is capped accordingly.
16
+ *
17
+ * Mirrors `maxResolutionToPixelArea` in `@videojs/spf`, and agrees with it on every rung whose 16:9 width is a whole
18
+ * number. It parts company at `'480p'` on purpose: 16:9 at 480 tall is 853.33 wide, ladders ship the rounded-up
19
+ * 854×480, and the exact area would put the standard 480p rendition over its own cap. Rounding the width up admits it
20
+ * while still excluding anything genuinely wider.
21
+ */
22
+ function resolutionToPixelArea(resolution) {
23
+ if (resolution === void 0) return Number.POSITIVE_INFINITY;
24
+ const height = Number.parseInt(resolution, 10);
25
+ if (!(Number.isFinite(height) && height > 0)) return Number.POSITIVE_INFINITY;
26
+ return Math.ceil(height * 16 / 9) * height;
27
+ }
28
+ /**
29
+ * Highest level index that keeps automatic selection at or below `resolution`.
30
+ *
31
+ * `autoLevelCapping` is a ceiling on the _index_, so every level at or below it stays eligible. That makes the answer
32
+ * the end of the leading run that fits the budget, not the single best match: hls.js orders levels by height, so a
33
+ * wider rendition can exceed the pixel budget from a lower index, and capping at the best match would leave it
34
+ * selectable.
35
+ *
36
+ * Falls back to index `0` when even the lowest rung is over budget — playing something over-spec beats refusing to
37
+ * adapt.
38
+ *
39
+ * Returns `undefined` when there is nothing to cap: no resolution requested, or no levels to choose from.
40
+ */
41
+ function levelIndexAtOrBelow(levels, resolution) {
42
+ const maxPixelArea = resolutionToPixelArea(resolution);
43
+ if (maxPixelArea === Number.POSITIVE_INFINITY || levels.length === 0) return void 0;
44
+ const overBudget = levels.findIndex((level) => (level.width ?? 0) * (level.height ?? 0) > maxPixelArea);
45
+ return overBudget === -1 ? levels.length - 1 : Math.max(0, overBudget - 1);
46
+ }
47
+ /**
48
+ * Lowest level index that keeps a rendition at or above `resolution` eligible.
49
+ *
50
+ * The complement of {@link levelIndexAtOrBelow}, for raising a ceiling rather than lowering one, and reasoned the same
51
+ * way: `autoLevelCapping` is a ceiling on the _index_, so the cheapest ceiling that still admits the floor is the first
52
+ * index that reaches it. Every rung below stays eligible either way, which is what keeps this a bound on capping rather
53
+ * than a quality minimum.
54
+ *
55
+ * Falls back to the top of the ladder when no rendition reaches the floor — a floor nothing can satisfy has no cap to
56
+ * raise.
57
+ *
58
+ * Returns `undefined` when there is no floor to apply: no resolution requested, or no levels to choose from.
59
+ */
60
+ function levelIndexAtOrAbove(levels, resolution) {
61
+ const minPixelArea = resolutionToPixelArea(resolution);
62
+ if (minPixelArea === Number.POSITIVE_INFINITY || levels.length === 0) return void 0;
63
+ const atFloor = levels.findIndex((level) => (level.width ?? 0) * (level.height ?? 0) >= minPixelArea);
64
+ return atFloor === -1 ? levels.length - 1 : atFloor;
65
+ }
66
+ /**
67
+ * Build the `capLevelController` class to hand to the hls.js constructor.
68
+ *
69
+ * `hls.autoLevelCapping` has exactly one writer: hls.js's own `CapLevelController`, which rewrites it on a one-second
70
+ * interval for as long as `capLevelToPlayerSize` is on — and it is on by default here. Assigning the property from
71
+ * outside is undone within a second, so a cap has to be applied from inside the controller rather than in competition
72
+ * with it.
73
+ *
74
+ * The only seam hls.js offers is `getMaxLevel()`, which every value the capping loop writes passes through. Overriding
75
+ * it makes the requested ceiling part of the same single-writer computation.
76
+ *
77
+ * @param policy - Live cap inputs, re-read on every evaluation.
78
+ * @param BaseController - Controller to layer on top of, so a controller passed through
79
+ * `source.engine.capLevelController` keeps its behavior.
80
+ */
81
+ function createCapLevelController(policy, BaseController = Hls.DefaultConfig.capLevelController) {
82
+ return class RenditionCapLevelController extends BaseController {
83
+ #hls;
84
+ #capping = false;
85
+ #measuringWithoutSize = false;
86
+ constructor(hls) {
87
+ super(hls);
88
+ this.#hls = hls;
89
+ policy.controller = this;
90
+ hls.on(Hls.Events.MANIFEST_PARSED, this.#onLevelsChanged);
91
+ hls.on(Hls.Events.LEVELS_UPDATED, this.#onLevelsChanged);
92
+ }
93
+ destroy() {
94
+ this.#hls.off(Hls.Events.MANIFEST_PARSED, this.#onLevelsChanged);
95
+ this.#hls.off(Hls.Events.LEVELS_UPDATED, this.#onLevelsChanged);
96
+ if (policy.controller === this) policy.controller = void 0;
97
+ super.destroy();
98
+ }
99
+ startCapping() {
100
+ this.#capping = true;
101
+ super.startCapping();
102
+ }
103
+ stopCapping() {
104
+ this.#capping = false;
105
+ super.stopCapping();
106
+ }
107
+ /**
108
+ * Hls.js derives its player-size ceiling from these two, so reporting an unbounded measurement is how
109
+ * `capToPlayerSize: false` switches that ceiling off while leaving the rest of the base controller intact.
110
+ *
111
+ * Returning early from `getMaxLevel()` instead would be the obvious way to skip the size cap, and it would also
112
+ * skip the levels `capLevelOnFPSDrop` has restricted: those are filtered inside the same `super.getMaxLevel()`
113
+ * call, and `restrictedLevels` is private, so there is no way to reapply them afterwards. Neutralizing the input
114
+ * keeps one path for both.
115
+ */
116
+ get mediaWidth() {
117
+ return this.#sizeApplies ? super.mediaWidth : Number.POSITIVE_INFINITY;
118
+ }
119
+ get mediaHeight() {
120
+ return this.#sizeApplies ? super.mediaHeight : Number.POSITIVE_INFINITY;
121
+ }
122
+ get #sizeApplies() {
123
+ return policy.capToPlayerSize && !this.#measuringWithoutSize;
124
+ }
125
+ /**
126
+ * What `super` allows with player size out of the picture — the ladder minus whatever `capLevelOnFPSDrop` has
127
+ * restricted. Reached through the same unbounded-measurement seam the toggle uses, since `restrictedLevels` is
128
+ * private and not readable any other way.
129
+ */
130
+ #topAllowedLevel(capLevelIndex) {
131
+ this.#measuringWithoutSize = true;
132
+ try {
133
+ return super.getMaxLevel(capLevelIndex);
134
+ } finally {
135
+ this.#measuringWithoutSize = false;
136
+ }
137
+ }
138
+ /**
139
+ * Intersect hls.js's player-size ceiling with the requested one. Deferring to `super` first keeps the behavior it
140
+ * owns — notably the level restrictions `capLevelOnFPSDrop` accumulates.
141
+ *
142
+ * The translation from resolution to level index happens here, not when the policy is set, because levels arrive
143
+ * after the option does and shift whenever hls.js drops one.
144
+ */
145
+ getMaxLevel(capLevelIndex) {
146
+ const { levels } = this.#hls;
147
+ let ceiling = super.getMaxLevel(capLevelIndex);
148
+ if (policy.capToPlayerSize && ceiling >= 0) {
149
+ const floor = levelIndexAtOrAbove(levels, policy.minAutoResolution);
150
+ if (floor !== void 0) ceiling = Math.min(Math.max(ceiling, floor), this.#topAllowedLevel(capLevelIndex));
151
+ }
152
+ const byResolution = levelIndexAtOrBelow(levels, policy.maxAutoResolution);
153
+ if (byResolution !== void 0) ceiling = Math.min(ceiling, byResolution);
154
+ return Math.min(ceiling, capLevelIndex);
155
+ }
156
+ /**
157
+ * Hls.js measures the element here and writes the ceiling it derives. It backs out entirely when the element has no
158
+ * measurable size — sensible for a cap that _is_ the element's size, but a requested resolution ceiling does not
159
+ * depend on layout. A player that is hidden, detached, or not laid out yet still has to honor it.
160
+ */
161
+ detectPlayerSize() {
162
+ super.detectPlayerSize();
163
+ if (super.mediaWidth > 0 && super.mediaHeight > 0) return;
164
+ this.#applyResolutionCap();
165
+ }
166
+ apply() {
167
+ if (this.#capping) {
168
+ this.detectPlayerSize();
169
+ return;
170
+ }
171
+ this.#applyResolutionCap();
172
+ }
173
+ /**
174
+ * The ceiling on its own, for when the size measurement is unavailable.
175
+ *
176
+ * Neither `capToPlayerSize` nor `minAutoResolution` reaches this path, and neither has anything to do here: both
177
+ * describe a cap derived from the element's size, and this is precisely the case where no such cap exists — there
178
+ * is none to switch off, and none for a floor to lift.
179
+ */
180
+ #applyResolutionCap() {
181
+ const { levels } = this.#hls;
182
+ if (!levels?.length) return;
183
+ this.#hls.autoLevelCapping = levelIndexAtOrBelow(levels, policy.maxAutoResolution) ?? -1;
184
+ }
185
+ #onLevelsChanged = () => this.apply();
186
+ };
187
+ }
188
+ //#endregion
189
+ export { DEFAULT_MIN_AUTO_RESOLUTION, createCapLevelController, levelIndexAtOrAbove, levelIndexAtOrBelow, resolutionToPixelArea };
190
+
191
+ //# sourceMappingURL=cap-level.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cap-level.js","names":["#hls","#onLevelsChanged","#capping","#sizeApplies","#measuringWithoutSize","#topAllowedLevel","#applyResolutionCap"],"sources":["../../src/cap-level.ts"],"sourcesContent":["import type { MediaResolution } from '@videojs/media';\nimport Hls, { type Level } from 'hls.js';\n\n/**\n * Live cap inputs the installed cap-level controller reads on every evaluation.\n *\n * Hls.js fixes `capLevelController` when the engine is constructed, so the class cannot carry values that change during\n * playback. The media element owns this object and mutates it in place instead, which is what lets a cap change skip\n * rebuilding the engine.\n */\nexport interface RenditionCapPolicy {\n /** Highest resolution ABR may auto-select, or `undefined` for no cap. */\n maxAutoResolution: MediaResolution | undefined;\n /** Whether the element's rendered size caps automatic selection. */\n capToPlayerSize: boolean;\n /** Lowest resolution {@link capToPlayerSize} may cap down to, or `undefined` for no floor. */\n minAutoResolution: MediaResolution | undefined;\n /** Registered by the controller's own constructor. */\n controller?: RenditionCapController | undefined;\n}\n\n/**\n * Floor applied to the player-size cap unless a source names another.\n *\n * The low rungs of a ladder are there for bad network conditions, and at that end the relationship between resolution\n * and perceived quality stops holding: a small player capped to 360p looks worse than its size alone suggests. No\n * reliable signal exists to key that on, so a fixed floor stands in for one.\n */\nexport const DEFAULT_MIN_AUTO_RESOLUTION: MediaResolution = '720p';\n\nexport interface RenditionCapController {\n /** Re-evaluate the policy now rather than on hls.js's next tick. */\n apply(): void;\n}\n\n/**\n * Pixel area of a resolution shorthand, assuming 16:9 — `'720p'` is `1280 × 720`, or `921_600`.\n *\n * Renditions are matched on area rather than literal height so anamorphic variants are judged by how many pixels they\n * actually carry: a 2560×1080 ultrawide rendition costs more than 16:9 1080p and is capped accordingly.\n *\n * Mirrors `maxResolutionToPixelArea` in `@videojs/spf`, and agrees with it on every rung whose 16:9 width is a whole\n * number. It parts company at `'480p'` on purpose: 16:9 at 480 tall is 853.33 wide, ladders ship the rounded-up\n * 854×480, and the exact area would put the standard 480p rendition over its own cap. Rounding the width up admits it\n * while still excluding anything genuinely wider.\n */\nexport function resolutionToPixelArea(resolution: MediaResolution | undefined): number {\n if (resolution === undefined) return Number.POSITIVE_INFINITY;\n\n const height = Number.parseInt(resolution, 10);\n if (!(Number.isFinite(height) && height > 0)) return Number.POSITIVE_INFINITY;\n\n return Math.ceil((height * 16) / 9) * height;\n}\n\n/**\n * Highest level index that keeps automatic selection at or below `resolution`.\n *\n * `autoLevelCapping` is a ceiling on the _index_, so every level at or below it stays eligible. That makes the answer\n * the end of the leading run that fits the budget, not the single best match: hls.js orders levels by height, so a\n * wider rendition can exceed the pixel budget from a lower index, and capping at the best match would leave it\n * selectable.\n *\n * Falls back to index `0` when even the lowest rung is over budget — playing something over-spec beats refusing to\n * adapt.\n *\n * Returns `undefined` when there is nothing to cap: no resolution requested, or no levels to choose from.\n */\nexport function levelIndexAtOrBelow(\n levels: readonly Level[],\n resolution: MediaResolution | undefined\n): number | undefined {\n const maxPixelArea = resolutionToPixelArea(resolution);\n if (maxPixelArea === Number.POSITIVE_INFINITY || levels.length === 0) return undefined;\n\n const overBudget = levels.findIndex((level) => (level.width ?? 0) * (level.height ?? 0) > maxPixelArea);\n\n // Everything fits: the whole ladder is eligible. Otherwise stop one short of\n // the first level that does not, and never below index 0.\n return overBudget === -1 ? levels.length - 1 : Math.max(0, overBudget - 1);\n}\n\n/**\n * Lowest level index that keeps a rendition at or above `resolution` eligible.\n *\n * The complement of {@link levelIndexAtOrBelow}, for raising a ceiling rather than lowering one, and reasoned the same\n * way: `autoLevelCapping` is a ceiling on the _index_, so the cheapest ceiling that still admits the floor is the first\n * index that reaches it. Every rung below stays eligible either way, which is what keeps this a bound on capping rather\n * than a quality minimum.\n *\n * Falls back to the top of the ladder when no rendition reaches the floor — a floor nothing can satisfy has no cap to\n * raise.\n *\n * Returns `undefined` when there is no floor to apply: no resolution requested, or no levels to choose from.\n */\nexport function levelIndexAtOrAbove(\n levels: readonly Level[],\n resolution: MediaResolution | undefined\n): number | undefined {\n const minPixelArea = resolutionToPixelArea(resolution);\n if (minPixelArea === Number.POSITIVE_INFINITY || levels.length === 0) return undefined;\n\n const atFloor = levels.findIndex((level) => (level.width ?? 0) * (level.height ?? 0) >= minPixelArea);\n\n return atFloor === -1 ? levels.length - 1 : atFloor;\n}\n\ntype CapLevelControllerClass = typeof Hls.DefaultConfig.capLevelController;\n\n/**\n * Build the `capLevelController` class to hand to the hls.js constructor.\n *\n * `hls.autoLevelCapping` has exactly one writer: hls.js's own `CapLevelController`, which rewrites it on a one-second\n * interval for as long as `capLevelToPlayerSize` is on — and it is on by default here. Assigning the property from\n * outside is undone within a second, so a cap has to be applied from inside the controller rather than in competition\n * with it.\n *\n * The only seam hls.js offers is `getMaxLevel()`, which every value the capping loop writes passes through. Overriding\n * it makes the requested ceiling part of the same single-writer computation.\n *\n * @param policy - Live cap inputs, re-read on every evaluation.\n * @param BaseController - Controller to layer on top of, so a controller passed through\n * `source.engine.capLevelController` keeps its behavior.\n */\nexport function createCapLevelController(\n policy: RenditionCapPolicy,\n BaseController: CapLevelControllerClass = Hls.DefaultConfig.capLevelController\n): CapLevelControllerClass {\n return class RenditionCapLevelController extends BaseController {\n #hls: Hls;\n #capping = false;\n #measuringWithoutSize = false;\n\n constructor(hls: Hls) {\n super(hls);\n this.#hls = hls;\n policy.controller = this;\n\n // hls.js re-evaluates on both of these itself, but only while its capping\n // loop runs. These cover the case where it never starts.\n hls.on(Hls.Events.MANIFEST_PARSED, this.#onLevelsChanged);\n hls.on(Hls.Events.LEVELS_UPDATED, this.#onLevelsChanged);\n }\n\n destroy() {\n this.#hls.off(Hls.Events.MANIFEST_PARSED, this.#onLevelsChanged);\n this.#hls.off(Hls.Events.LEVELS_UPDATED, this.#onLevelsChanged);\n\n if (policy.controller === this) policy.controller = undefined;\n\n super.destroy();\n }\n\n // hls.js keeps the interval handle private, so the loop is tracked through\n // the public start/stop pair instead of reaching into it.\n startCapping() {\n this.#capping = true;\n super.startCapping();\n }\n\n stopCapping() {\n this.#capping = false;\n super.stopCapping();\n }\n\n /**\n * Hls.js derives its player-size ceiling from these two, so reporting an unbounded measurement is how\n * `capToPlayerSize: false` switches that ceiling off while leaving the rest of the base controller intact.\n *\n * Returning early from `getMaxLevel()` instead would be the obvious way to skip the size cap, and it would also\n * skip the levels `capLevelOnFPSDrop` has restricted: those are filtered inside the same `super.getMaxLevel()`\n * call, and `restrictedLevels` is private, so there is no way to reapply them afterwards. Neutralizing the input\n * keeps one path for both.\n */\n get mediaWidth(): number {\n return this.#sizeApplies ? super.mediaWidth : Number.POSITIVE_INFINITY;\n }\n\n get mediaHeight(): number {\n return this.#sizeApplies ? super.mediaHeight : Number.POSITIVE_INFINITY;\n }\n\n get #sizeApplies(): boolean {\n return policy.capToPlayerSize && !this.#measuringWithoutSize;\n }\n\n /**\n * What `super` allows with player size out of the picture — the ladder minus whatever `capLevelOnFPSDrop` has\n * restricted. Reached through the same unbounded-measurement seam the toggle uses, since `restrictedLevels` is\n * private and not readable any other way.\n */\n #topAllowedLevel(capLevelIndex: number): number {\n this.#measuringWithoutSize = true;\n\n try {\n return super.getMaxLevel(capLevelIndex);\n } finally {\n this.#measuringWithoutSize = false;\n }\n }\n\n /**\n * Intersect hls.js's player-size ceiling with the requested one. Deferring to `super` first keeps the behavior it\n * owns — notably the level restrictions `capLevelOnFPSDrop` accumulates.\n *\n * The translation from resolution to level index happens here, not when the policy is set, because levels arrive\n * after the option does and shift whenever hls.js drops one.\n */\n getMaxLevel(capLevelIndex: number): number {\n const { levels } = this.#hls;\n let ceiling = super.getMaxLevel(capLevelIndex);\n\n // Only where there is a size ceiling to lift: `super` reports `-1` when no\n // level is available at all, and player size is no reason to overrule that.\n if (policy.capToPlayerSize && ceiling >= 0) {\n const floor = levelIndexAtOrAbove(levels, policy.minAutoResolution);\n\n // A floor says \"do not cap this small player that far down\", not \"decode\n // what this device can't\", so it stops at the top allowed level.\n if (floor !== undefined) ceiling = Math.min(Math.max(ceiling, floor), this.#topAllowedLevel(capLevelIndex));\n }\n\n // Narrowing after the floor is what subordinates it: a caller asking for\n // at most 360p gets 360p, however high the floor sits.\n const byResolution = levelIndexAtOrBelow(levels, policy.maxAutoResolution);\n\n if (byResolution !== undefined) ceiling = Math.min(ceiling, byResolution);\n\n // A floor can push past the top of the ladder; `capLevelIndex` is the real bound.\n return Math.min(ceiling, capLevelIndex);\n }\n\n /**\n * Hls.js measures the element here and writes the ceiling it derives. It backs out entirely when the element has no\n * measurable size — sensible for a cap that _is_ the element's size, but a requested resolution ceiling does not\n * depend on layout. A player that is hidden, detached, or not laid out yet still has to honor it.\n */\n detectPlayerSize() {\n super.detectPlayerSize();\n\n // Through the base getters: the overrides above report an unbounded size\n // while the cap is off, which would pass for a measurable element.\n if (super.mediaWidth > 0 && super.mediaHeight > 0) return;\n\n this.#applyResolutionCap();\n }\n\n apply() {\n // While the loop runs it owns the slot, so go through its own path;\n // everything it writes already passes through `getMaxLevel()`.\n if (this.#capping) {\n this.detectPlayerSize();\n return;\n }\n\n this.#applyResolutionCap();\n }\n\n /**\n * The ceiling on its own, for when the size measurement is unavailable.\n *\n * Neither `capToPlayerSize` nor `minAutoResolution` reaches this path, and neither has anything to do here: both\n * describe a cap derived from the element's size, and this is precisely the case where no such cap exists — there\n * is none to switch off, and none for a floor to lift.\n */\n #applyResolutionCap() {\n const { levels } = this.#hls;\n if (!levels?.length) return;\n\n // `-1` is how hls.js spells \"uncapped\".\n this.#hls.autoLevelCapping = levelIndexAtOrBelow(levels, policy.maxAutoResolution) ?? -1;\n }\n\n #onLevelsChanged = () => this.apply();\n };\n}\n"],"mappings":";;;;;;;;;AA4BA,MAAa,8BAA+C;;;;;;;;;;;;AAkB5D,SAAgB,sBAAsB,YAAiD;CACrF,IAAI,eAAe,KAAA,GAAW,OAAO,OAAO;CAE5C,MAAM,SAAS,OAAO,SAAS,YAAY,EAAE;CAC7C,IAAI,EAAE,OAAO,SAAS,MAAM,KAAK,SAAS,IAAI,OAAO,OAAO;CAE5D,OAAO,KAAK,KAAM,SAAS,KAAM,CAAC,IAAI;AACxC;;;;;;;;;;;;;;AAeA,SAAgB,oBACd,QACA,YACoB;CACpB,MAAM,eAAe,sBAAsB,UAAU;CACrD,IAAI,iBAAiB,OAAO,qBAAqB,OAAO,WAAW,GAAG,OAAO,KAAA;CAE7E,MAAM,aAAa,OAAO,WAAW,WAAW,MAAM,SAAS,MAAM,MAAM,UAAU,KAAK,YAAY;CAItG,OAAO,eAAe,KAAK,OAAO,SAAS,IAAI,KAAK,IAAI,GAAG,aAAa,CAAC;AAC3E;;;;;;;;;;;;;;AAeA,SAAgB,oBACd,QACA,YACoB;CACpB,MAAM,eAAe,sBAAsB,UAAU;CACrD,IAAI,iBAAiB,OAAO,qBAAqB,OAAO,WAAW,GAAG,OAAO,KAAA;CAE7E,MAAM,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B,WAAW,GAAG;IAC1C,MAAM,QAAQ,oBAAoB,QAAQ,OAAO,iBAAiB;IAIlE,IAAI,UAAU,KAAA,GAAW,UAAU,KAAK,IAAI,KAAK,IAAI,SAAS,KAAK,GAAG,KAAKK,iBAAiB,aAAa,CAAC;GAC5G;GAIA,MAAM,eAAe,oBAAoB,QAAQ,OAAO,iBAAiB;GAEzE,IAAI,iBAAiB,KAAA,GAAW,UAAU,KAAK,IAAI,SAAS,YAAY;GAGxE,OAAO,KAAK,IAAI,SAAS,aAAa;EACxC;;;;;;EAOA,mBAAmB;GACjB,MAAM,iBAAiB;GAIvB,IAAI,MAAM,aAAa,KAAK,MAAM,cAAc,GAAG;GAEnD,KAAKC,oBAAoB;EAC3B;EAEA,QAAQ;GAGN,IAAI,KAAKJ,UAAU;IACjB,KAAK,iBAAiB;IACtB;GACF;GAEA,KAAKI,oBAAoB;EAC3B;;;;;;;;EASA,sBAAsB;GACpB,MAAM,EAAE,WAAW,KAAKN;GACxB,IAAI,CAAC,QAAQ,QAAQ;GAGrB,KAAKA,KAAK,mBAAmB,oBAAoB,QAAQ,OAAO,iBAAiB,KAAK;EACxF;EAEA,yBAAyB,KAAK,MAAM;CACtC;AACF"}
@@ -0,0 +1,50 @@
1
+ import Hls from "hls.js";
2
+ //#region src/drm.ts
3
+ /**
4
+ * Hardware-backed Widevine security level. Preferred (but not required) so content restricted to L1 devices plays where
5
+ * the CDM supports it.
6
+ */
7
+ const HARDWARE_ROBUSTNESS = "HW_SECURE_ALL";
8
+ /**
9
+ * Round off EME playback on a fresh engine. What to play and where to license it is hls.js's own configuration, reached
10
+ * through `source.engine` (`emeEnabled`, `drmSystems`); this only fills in what hls.js leaves to the caller:
11
+ *
12
+ * - Prefers a hardware-backed Widevine CDM, falling back to whatever robustness the browser offers.
13
+ * - Surfaces non-fatal key system errors in development, which are otherwise silent.
14
+ *
15
+ * A `requestMediaKeySystemAccessFunc` of your own takes precedence over both.
16
+ */
17
+ function setupDrm(engine) {
18
+ if (!engine.config.emeEnabled) return;
19
+ engine.config.requestMediaKeySystemAccessFunc = engine.userConfig.requestMediaKeySystemAccessFunc ?? requestKeySystemAccess;
20
+ engine.on(Hls.Events.ERROR, (_event, data) => {
21
+ if (data.fatal || data.type !== Hls.ErrorTypes.KEY_SYSTEM_ERROR) return;
22
+ console.warn(`[vjs-drm] ${data.details}`, data.error);
23
+ });
24
+ }
25
+ const requestKeySystemAccess = (keySystem, supportedConfigurations) => {
26
+ const configurations = keySystem.includes("widevine") ? withHardwareRobustness(supportedConfigurations) : supportedConfigurations;
27
+ return navigator.requestMediaKeySystemAccess(keySystem, configurations);
28
+ };
29
+ /**
30
+ * Duplicate the requested key system configurations with hardware-level video robustness ahead of the originals.
31
+ * `requestMediaKeySystemAccess()` resolves with the first supported entry, so this prefers a hardware CDM without
32
+ * failing when only software security is available.
33
+ */
34
+ function withHardwareRobustness(configurations) {
35
+ return [...configurations.map((configuration) => {
36
+ const { videoCapabilities } = configuration;
37
+ if (!videoCapabilities) return configuration;
38
+ return {
39
+ ...configuration,
40
+ videoCapabilities: videoCapabilities.map((capability) => ({
41
+ ...capability,
42
+ robustness: HARDWARE_ROBUSTNESS
43
+ }))
44
+ };
45
+ }), ...configurations];
46
+ }
47
+ //#endregion
48
+ export { setupDrm };
49
+
50
+ //# sourceMappingURL=drm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drm.js","names":[],"sources":["../../src/drm.ts"],"sourcesContent":["import Hls, { type MediaKeyFunc } from 'hls.js';\n\n/**\n * Hardware-backed Widevine security level. Preferred (but not required) so content restricted to L1 devices plays where\n * the CDM supports it.\n */\nconst HARDWARE_ROBUSTNESS = 'HW_SECURE_ALL';\n\n/**\n * Round off EME playback on a fresh engine. What to play and where to license it is hls.js's own configuration, reached\n * through `source.engine` (`emeEnabled`, `drmSystems`); this only fills in what hls.js leaves to the caller:\n *\n * - Prefers a hardware-backed Widevine CDM, falling back to whatever robustness the browser offers.\n * - Surfaces non-fatal key system errors in development, which are otherwise silent.\n *\n * A `requestMediaKeySystemAccessFunc` of your own takes precedence over both.\n */\nexport function setupDrm(engine: Hls): void {\n // hls.js only runs EME while `emeEnabled` is set, so unprotected playback is\n // left exactly as hls.js configured it.\n if (!engine.config.emeEnabled) return;\n\n engine.config.requestMediaKeySystemAccessFunc =\n engine.userConfig.requestMediaKeySystemAccessFunc ?? requestKeySystemAccess;\n\n if (__DEV__) {\n engine.on(Hls.Events.ERROR, (_event, data) => {\n // Fatal key system failures surface as media errors; non-fatal ones\n // (e.g. output restricted → black frames) are otherwise silent.\n if (data.fatal || data.type !== Hls.ErrorTypes.KEY_SYSTEM_ERROR) return;\n\n console.warn(`[vjs-drm] ${data.details}`, data.error);\n });\n }\n}\n\nconst requestKeySystemAccess: MediaKeyFunc = (keySystem, supportedConfigurations) => {\n // Matched loosely: key systems are versioned (`com.apple.fps.1_0`) and\n // vendor-prefixed (`com.widevine.alpha.experiment`) in the wild.\n const configurations = keySystem.includes('widevine')\n ? withHardwareRobustness(supportedConfigurations)\n : supportedConfigurations;\n\n return navigator.requestMediaKeySystemAccess(keySystem, configurations);\n};\n\n/**\n * Duplicate the requested key system configurations with hardware-level video robustness ahead of the originals.\n * `requestMediaKeySystemAccess()` resolves with the first supported entry, so this prefers a hardware CDM without\n * failing when only software security is available.\n */\nfunction withHardwareRobustness(configurations: MediaKeySystemConfiguration[]): MediaKeySystemConfiguration[] {\n const hardware = configurations.map((configuration): MediaKeySystemConfiguration => {\n const { videoCapabilities } = configuration;\n if (!videoCapabilities) return configuration;\n\n return {\n ...configuration,\n videoCapabilities: videoCapabilities.map((capability) => ({ ...capability, robustness: HARDWARE_ROBUSTNESS })),\n };\n });\n\n return [...hardware, ...configurations];\n}\n"],"mappings":";;;;;;AAMA,MAAM,sBAAsB;;;;;;;;;;AAW5B,SAAgB,SAAS,QAAmB;CAG1C,IAAI,CAAC,OAAO,OAAO,YAAY;CAE/B,OAAO,OAAO,kCACZ,OAAO,WAAW,mCAAmC;CAGrD,OAAO,GAAG,IAAI,OAAO,QAAQ,QAAQ,SAAS;EAG5C,IAAI,KAAK,SAAS,KAAK,SAAS,IAAI,WAAW,kBAAkB;EAEjE,QAAQ,KAAK,aAAa,KAAK,WAAW,KAAK,KAAK;CACtD,CAAC;AAEL;AAEA,MAAM,0BAAwC,WAAW,4BAA4B;CAGnF,MAAM,iBAAiB,UAAU,SAAS,UAAU,IAChD,uBAAuB,uBAAuB,IAC9C;CAEJ,OAAO,UAAU,4BAA4B,WAAW,cAAc;AACxE;;;;;;AAOA,SAAS,uBAAuB,gBAA8E;CAW5G,OAAO,CAAC,GAVS,eAAe,KAAK,kBAA+C;EAClF,MAAM,EAAE,sBAAsB;EAC9B,IAAI,CAAC,mBAAmB,OAAO;EAE/B,OAAO;GACL,GAAG;GACH,mBAAmB,kBAAkB,KAAK,gBAAgB;IAAE,GAAG;IAAY,YAAY;GAAoB,EAAE;EAC/G;CACF,CAEkB,GAAG,GAAG,cAAc;AACxC"}
@@ -0,0 +1,58 @@
1
+ import { MediaError } from "@videojs/media";
2
+ import Hls from "hls.js";
3
+ //#region src/errors.ts
4
+ const hlsErrorTypeToCode = {
5
+ [Hls.ErrorTypes.NETWORK_ERROR]: MediaError.MEDIA_ERR_NETWORK,
6
+ [Hls.ErrorTypes.MEDIA_ERROR]: MediaError.MEDIA_ERR_DECODE,
7
+ [Hls.ErrorTypes.KEY_SYSTEM_ERROR]: MediaError.MEDIA_ERR_ENCRYPTED,
8
+ [Hls.ErrorTypes.MUX_ERROR]: MediaError.MEDIA_ERR_DECODE,
9
+ [Hls.ErrorTypes.OTHER_ERROR]: MediaError.MEDIA_ERR_CUSTOM
10
+ };
11
+ function HlsJsErrorsMixin(BaseClass) {
12
+ class HlsJsErrors extends BaseClass {
13
+ #disconnect = null;
14
+ #error = null;
15
+ constructor(...args) {
16
+ super(...args);
17
+ this.engine?.on(Hls.Events.MANIFEST_LOADING, () => this.#init());
18
+ this.engine?.on(Hls.Events.MEDIA_ATTACHED, () => this.#init());
19
+ this.engine?.on(Hls.Events.MEDIA_DETACHED, () => this.#destroy());
20
+ this.engine?.on(Hls.Events.DESTROYING, () => this.#destroy());
21
+ }
22
+ get error() {
23
+ return this.#error;
24
+ }
25
+ #destroy() {
26
+ this.#disconnect?.abort();
27
+ this.#disconnect = null;
28
+ }
29
+ #init() {
30
+ this.#disconnect?.abort();
31
+ this.#disconnect = new AbortController();
32
+ const { engine, target } = this;
33
+ if (!engine || !target) return;
34
+ const onError = (_event, data) => {
35
+ if (!data.fatal) return;
36
+ const code = hlsErrorTypeToCode[data.type] ?? MediaError.MEDIA_ERR_CUSTOM;
37
+ const error = new MediaError(data.error?.message, code, true, data.details);
38
+ error.data = data;
39
+ this.#error = error;
40
+ const event = new ErrorEvent("error", {
41
+ error,
42
+ message: error.message
43
+ });
44
+ this.dispatchEvent(event);
45
+ };
46
+ engine.on(Hls.Events.ERROR, onError);
47
+ this.#disconnect.signal.addEventListener("abort", () => {
48
+ engine.off(Hls.Events.ERROR, onError);
49
+ this.#error = null;
50
+ }, { once: true });
51
+ }
52
+ }
53
+ return HlsJsErrors;
54
+ }
55
+ //#endregion
56
+ export { HlsJsErrorsMixin };
57
+
58
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":["#init","#destroy","#error","#disconnect"],"sources":["../../src/errors.ts"],"sourcesContent":["import { MediaError } from '@videojs/media';\nimport type { Constructor, MixinReturn } from '@videojs/utils/types';\nimport type { ErrorData } from 'hls.js';\nimport Hls from 'hls.js';\n\nimport type { HlsEngineHost } from './types';\n\nconst hlsErrorTypeToCode: Record<string, number> = {\n [Hls.ErrorTypes.NETWORK_ERROR]: MediaError.MEDIA_ERR_NETWORK,\n [Hls.ErrorTypes.MEDIA_ERROR]: MediaError.MEDIA_ERR_DECODE,\n [Hls.ErrorTypes.KEY_SYSTEM_ERROR]: MediaError.MEDIA_ERR_ENCRYPTED,\n [Hls.ErrorTypes.MUX_ERROR]: MediaError.MEDIA_ERR_DECODE,\n [Hls.ErrorTypes.OTHER_ERROR]: MediaError.MEDIA_ERR_CUSTOM,\n};\n\nexport function HlsJsErrorsMixin<Base extends Constructor<HlsEngineHost>>(BaseClass: Base) {\n class HlsJsErrors extends BaseClass {\n #disconnect: AbortController | null = null;\n #error: MediaError | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n\n this.engine?.on(Hls.Events.MANIFEST_LOADING, () => this.#init());\n this.engine?.on(Hls.Events.MEDIA_ATTACHED, () => this.#init());\n this.engine?.on(Hls.Events.MEDIA_DETACHED, () => this.#destroy());\n this.engine?.on(Hls.Events.DESTROYING, () => this.#destroy());\n }\n\n get error(): MediaError | null {\n return this.#error;\n }\n\n #destroy(): void {\n this.#disconnect?.abort();\n this.#disconnect = null;\n }\n\n #init(): void {\n this.#disconnect?.abort();\n this.#disconnect = new AbortController();\n\n const { engine, target } = this;\n if (!engine || !target) return;\n\n const onError = (_event: string, data: ErrorData) => {\n if (!data.fatal) return;\n\n const code = hlsErrorTypeToCode[data.type] ?? MediaError.MEDIA_ERR_CUSTOM;\n const error = new MediaError(data.error?.message, code, true, data.details);\n\n error.data = data;\n\n this.#error = error;\n\n const event = new ErrorEvent('error', { error, message: error.message });\n\n this.dispatchEvent(event);\n };\n\n engine.on(Hls.Events.ERROR, onError);\n\n this.#disconnect.signal.addEventListener(\n 'abort',\n () => {\n engine.off(Hls.Events.ERROR, onError);\n this.#error = null;\n },\n { once: true }\n );\n }\n }\n\n return HlsJsErrors as unknown as MixinReturn<Base, { readonly error: MediaError | null }>;\n}\n"],"mappings":";;;AAOA,MAAM,qBAA6C;EAChD,IAAI,WAAW,gBAAgB,WAAW;EAC1C,IAAI,WAAW,cAAc,WAAW;EACxC,IAAI,WAAW,mBAAmB,WAAW;EAC7C,IAAI,WAAW,YAAY,WAAW;EACtC,IAAI,WAAW,cAAc,WAAW;AAC3C;AAEA,SAAgB,iBAA0D,WAAiB;CACzF,MAAM,oBAAoB,UAAU;EAClC,cAAsC;EACt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+ import { setupDrm } from "./drm.js";
4
+ import { HlsJsErrorsMixin } from "./errors.js";
5
+ import { HlsJsLiveMixin } from "./live.js";
6
+ import { HlsJsMediaTracksMixin } from "./media-tracks.js";
7
+ import { HlsJsMetadataTracksMixin } from "./metadata-tracks.js";
8
+ import { HlsJsPreloadMixin } from "./preload.js";
9
+ import { HlsJsStreamTypeMixin } from "./stream-type.js";
10
+ import { HlsJsTextTracksMixin, withPreservedTextTracks } from "./text-tracks.js";
11
+ import { HTMLVideoAdapter } from "@videojs/media/dom";
12
+ import Hls from "hls.js";
13
+ import { MediaTracksMixin } from "@videojs/media/media-tracks";
14
+ //#region src/hls-js-only.ts
15
+ const defaultHlsConfig = {
16
+ backBufferLength: 30,
17
+ renderTextTracksNatively: false,
18
+ liveDurationInfinity: true,
19
+ capLevelToPlayerSize: true,
20
+ capLevelOnFPSDrop: true,
21
+ autoStartLoad: false
22
+ };
23
+ var HlsJsOnlyAdapterCore = class extends HTMLVideoAdapter {
24
+ #engine = null;
25
+ #capPolicy = {
26
+ maxAutoResolution: void 0,
27
+ capToPlayerSize: true,
28
+ minAutoResolution: DEFAULT_MIN_AUTO_RESOLUTION
29
+ };
30
+ constructor(params) {
31
+ super();
32
+ const config = {
33
+ ...defaultHlsConfig,
34
+ ...params.config
35
+ };
36
+ this.#engine = new Hls({
37
+ ...config,
38
+ capLevelController: createCapLevelController(this.#capPolicy, config.capLevelController)
39
+ });
40
+ setupDrm(this.#engine);
41
+ }
42
+ get engine() {
43
+ return this.#engine;
44
+ }
45
+ /** Ceiling on automatic rendition selection. See `HlsSource.maxAutoResolution`. */
46
+ get maxAutoResolution() {
47
+ return this.#capPolicy.maxAutoResolution;
48
+ }
49
+ set maxAutoResolution(value) {
50
+ if (this.#capPolicy.maxAutoResolution === value) return;
51
+ this.#capPolicy.maxAutoResolution = value;
52
+ this.#capPolicy.controller?.apply();
53
+ }
54
+ /** Whether the rendered size caps selection. See `HlsSource.capRenditionToPlayerSize`. */
55
+ get capRenditionToPlayerSize() {
56
+ return this.#capPolicy.capToPlayerSize;
57
+ }
58
+ set capRenditionToPlayerSize(value) {
59
+ const next = value ?? true;
60
+ if (this.#capPolicy.capToPlayerSize === next) return;
61
+ this.#capPolicy.capToPlayerSize = next;
62
+ this.#capPolicy.controller?.apply();
63
+ }
64
+ /** Floor on the player-size cap. See `HlsSource.minAutoResolution`. */
65
+ get minAutoResolution() {
66
+ return this.#capPolicy.minAutoResolution ?? "720p";
67
+ }
68
+ set minAutoResolution(value) {
69
+ const next = value ?? "720p";
70
+ if (this.#capPolicy.minAutoResolution === next) return;
71
+ this.#capPolicy.minAutoResolution = next;
72
+ this.#capPolicy.controller?.apply();
73
+ }
74
+ get src() {
75
+ return this.#engine?.url ?? "";
76
+ }
77
+ set src(src) {
78
+ withPreservedTextTracks(this.target, () => this.#engine?.loadSource(src));
79
+ }
80
+ attach(target) {
81
+ super.attach(target);
82
+ withPreservedTextTracks(target, () => this.#engine?.attachMedia(target));
83
+ }
84
+ detach() {
85
+ withPreservedTextTracks(this.target, () => this.#engine?.detachMedia());
86
+ super.detach();
87
+ }
88
+ destroy() {
89
+ this.detach();
90
+ this.#engine?.destroy();
91
+ this.#engine = null;
92
+ }
93
+ };
94
+ const HlsJsOnlyAdapterComposed = HlsJsAirPlayMixin(HlsJsPreloadMixin(HlsJsLiveMixin(HlsJsStreamTypeMixin(HlsJsMediaTracksMixin(HlsJsMetadataTracksMixin(HlsJsTextTracksMixin(HlsJsErrorsMixin(MediaTracksMixin(HlsJsOnlyAdapterCore)))))))));
95
+ var HlsJsOnlyAdapter = class extends HlsJsOnlyAdapterComposed {};
96
+ //#endregion
97
+ export { HlsJsOnlyAdapter, defaultHlsConfig };
98
+
99
+ //# sourceMappingURL=hls-js-only.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hls-js-only.js","names":["#engine","#capPolicy"],"sources":["../../src/hls-js-only.ts"],"sourcesContent":["import type {\n EngineAdapter,\n MediaError,\n MediaLiveCapability,\n MediaResolution,\n MediaSourceCapability,\n MediaStreamTypeCapability,\n} from '@videojs/media';\nimport { HTMLVideoAdapter } from '@videojs/media/dom';\nimport { MediaTracksMixin, type WithMediaTracks } from '@videojs/media/media-tracks';\nimport type { MixinReturn } from '@videojs/utils/types';\nimport Hls, { type HlsConfig } from 'hls.js';\n\nimport { HlsJsAirPlayMixin } from './airplay-bridge';\nimport { createCapLevelController, DEFAULT_MIN_AUTO_RESOLUTION, type RenditionCapPolicy } from './cap-level';\nimport { setupDrm } from './drm';\nimport { HlsJsErrorsMixin } from './errors';\nimport { HlsJsLiveMixin } from './live';\nimport { HlsJsMediaTracksMixin } from './media-tracks';\nimport { HlsJsMetadataTracksMixin } from './metadata-tracks';\nimport { HlsJsPreloadMixin } from './preload';\nimport { HlsJsStreamTypeMixin } from './stream-type';\nimport { HlsJsTextTracksMixin, withPreservedTextTracks } from './text-tracks';\n\nexport const defaultHlsConfig: Partial<HlsConfig> = {\n backBufferLength: 30,\n renderTextTracksNatively: false,\n liveDurationInfinity: true,\n // Runs hls.js's capping loop, which every rendition cap is evaluated on, not\n // only the one named after it. `capRenditionToPlayerSize` is the live switch.\n capLevelToPlayerSize: true,\n capLevelOnFPSDrop: true,\n autoStartLoad: false,\n};\n\nexport interface HlsJsOnlyMediaParams {\n /** Options forwarded to the hls.js constructor, merged over {@link defaultHlsConfig}. */\n config: Partial<HlsConfig>;\n}\n\nclass HlsJsOnlyAdapterCore extends HTMLVideoAdapter implements EngineAdapter<Hls, HTMLVideoElement> {\n #engine: Hls | null = null;\n #capPolicy: RenditionCapPolicy = {\n maxAutoResolution: undefined,\n capToPlayerSize: true,\n minAutoResolution: DEFAULT_MIN_AUTO_RESOLUTION,\n };\n\n constructor(params: HlsJsOnlyMediaParams) {\n super();\n const config = { ...defaultHlsConfig, ...params.config };\n\n this.#engine = new Hls({\n ...config,\n // Layered over whatever controller the config already names, so a\n // `capLevelController` passed through `source.engine` keeps working.\n capLevelController: createCapLevelController(this.#capPolicy, config.capLevelController),\n });\n\n setupDrm(this.#engine);\n }\n\n get engine() {\n return this.#engine;\n }\n\n /** Ceiling on automatic rendition selection. See `HlsSource.maxAutoResolution`. */\n get maxAutoResolution(): MediaResolution | undefined {\n return this.#capPolicy.maxAutoResolution;\n }\n\n set maxAutoResolution(value: MediaResolution | undefined) {\n if (this.#capPolicy.maxAutoResolution === value) return;\n\n this.#capPolicy.maxAutoResolution = value;\n this.#capPolicy.controller?.apply();\n }\n\n /** Whether the rendered size caps selection. See `HlsSource.capRenditionToPlayerSize`. */\n get capRenditionToPlayerSize(): boolean {\n return this.#capPolicy.capToPlayerSize;\n }\n\n set capRenditionToPlayerSize(value: boolean | undefined) {\n // Defaults resolve here rather than in the caller, so the getters report the\n // cap that is actually in force instead of what a source happened to name.\n const next = value ?? true;\n if (this.#capPolicy.capToPlayerSize === next) return;\n\n this.#capPolicy.capToPlayerSize = next;\n this.#capPolicy.controller?.apply();\n }\n\n /** Floor on the player-size cap. See `HlsSource.minAutoResolution`. */\n get minAutoResolution(): MediaResolution {\n return this.#capPolicy.minAutoResolution ?? DEFAULT_MIN_AUTO_RESOLUTION;\n }\n\n set minAutoResolution(value: MediaResolution | undefined) {\n const next = value ?? DEFAULT_MIN_AUTO_RESOLUTION;\n if (this.#capPolicy.minAutoResolution === next) return;\n\n this.#capPolicy.minAutoResolution = next;\n this.#capPolicy.controller?.apply();\n }\n\n get src() {\n return this.#engine?.url ?? '';\n }\n\n set src(src: string) {\n // Attaching, detaching, and loading a source each reset every text track on\n // the element, sideloaded ones included. See `withPreservedTextTracks`.\n withPreservedTextTracks(this.target as HTMLVideoElement | null, () => this.#engine?.loadSource(src));\n }\n\n attach(target: HTMLVideoElement) {\n super.attach(target);\n withPreservedTextTracks(target, () => this.#engine?.attachMedia(target));\n }\n\n detach() {\n withPreservedTextTracks(this.target as HTMLVideoElement | null, () => this.#engine?.detachMedia());\n super.detach();\n }\n\n destroy() {\n this.detach();\n this.#engine?.destroy();\n this.#engine = null;\n }\n}\n\ninterface HlsJsMediaCapabilities\n extends MediaStreamTypeCapability, MediaLiveCapability, Pick<MediaSourceCapability, 'preload'> {\n readonly error: MediaError | null;\n}\n\nconst HlsJsOnlyAdapterComposed = HlsJsAirPlayMixin(\n HlsJsPreloadMixin(\n HlsJsLiveMixin(\n HlsJsStreamTypeMixin(\n HlsJsMediaTracksMixin(\n HlsJsMetadataTracksMixin(HlsJsTextTracksMixin(HlsJsErrorsMixin(MediaTracksMixin(HlsJsOnlyAdapterCore))))\n )\n )\n )\n )\n) as unknown as MixinReturn<WithMediaTracks<typeof HlsJsOnlyAdapterCore>, HlsJsMediaCapabilities>;\n\nexport class HlsJsOnlyAdapter extends HlsJsOnlyAdapterComposed {}\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAa,mBAAuC;CAClD,kBAAkB;CAClB,0BAA0B;CAC1B,sBAAsB;CAGtB,sBAAsB;CACtB,mBAAmB;CACnB,eAAe;AACjB;AAOA,IAAM,uBAAN,cAAmC,iBAAiE;CAClG,UAAsB;CACtB,aAAiC;EAC/B,mBAAmB,KAAA;EACnB,iBAAiB;EACjB,mBAAmB;CACrB;CAEA,YAAY,QAA8B;EACxC,MAAM;EACN,MAAM,SAAS;GAAE,GAAG;GAAkB,GAAG,OAAO;EAAO;EAEvD,KAAKA,UAAU,IAAI,IAAI;GACrB,GAAG;GAGH,oBAAoB,yBAAyB,KAAKC,YAAY,OAAO,kBAAkB;EACzF,CAAC;EAED,SAAS,KAAKD,OAAO;CACvB;CAEA,IAAI,SAAS;EACX,OAAO,KAAKA;CACd;;CAGA,IAAI,oBAAiD;EACnD,OAAO,KAAKC,WAAW;CACzB;CAEA,IAAI,kBAAkB,OAAoC;EACxD,IAAI,KAAKA,WAAW,sBAAsB,OAAO;EAEjD,KAAKA,WAAW,oBAAoB;EACpC,KAAKA,WAAW,YAAY,MAAM;CACpC;;CAGA,IAAI,2BAAoC;EACtC,OAAO,KAAKA,WAAW;CACzB;CAEA,IAAI,yBAAyB,OAA4B;EAGvD,MAAM,OAAO,SAAS;EACtB,IAAI,KAAKA,WAAW,oBAAoB,MAAM;EAE9C,KAAKA,WAAW,kBAAkB;EAClC,KAAKA,WAAW,YAAY,MAAM;CACpC;;CAGA,IAAI,oBAAqC;EACvC,OAAO,KAAKA,WAAW,qBAAA;CACzB;CAEA,IAAI,kBAAkB,OAAoC;EACxD,MAAM,OAAO,SAAA;EACb,IAAI,KAAKA,WAAW,sBAAsB,MAAM;EAEhD,KAAKA,WAAW,oBAAoB;EACpC,KAAKA,WAAW,YAAY,MAAM;CACpC;CAEA,IAAI,MAAM;EACR,OAAO,KAAKD,SAAS,OAAO;CAC9B;CAEA,IAAI,IAAI,KAAa;EAGnB,wBAAwB,KAAK,cAAyC,KAAKA,SAAS,WAAW,GAAG,CAAC;CACrG;CAEA,OAAO,QAA0B;EAC/B,MAAM,OAAO,MAAM;EACnB,wBAAwB,cAAc,KAAKA,SAAS,YAAY,MAAM,CAAC;CACzE;CAEA,SAAS;EACP,wBAAwB,KAAK,cAAyC,KAAKA,SAAS,YAAY,CAAC;EACjG,MAAM,OAAO;CACf;CAEA,UAAU;EACR,KAAK,OAAO;EACZ,KAAKA,SAAS,QAAQ;EACtB,KAAKA,UAAU;CACjB;AACF;AAOA,MAAM,2BAA2B,kBAC/B,kBACE,eACE,qBACE,sBACE,yBAAyB,qBAAqB,iBAAiB,iBAAiB,oBAAoB,CAAC,CAAC,CAAC,CACzG,CACF,CACF,CACF,CACF;AAEA,IAAa,mBAAb,cAAsC,yBAAyB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ContentTypes, Hls, HlsEngineConfig, HlsJsAdapter, HlsJsAdapterProps, HlsSource, MediaResolution, PlaybackType, PlaybackTypes, PreloadType, SourceType, StreamType, StreamTypes } from "./adapter.js";
2
+ import { DrmSystemConfig, DrmSystemsConfig, KeySystem, KeySystems } from "@videojs/media";
3
+ export { ContentTypes, type DrmSystemConfig, type DrmSystemsConfig, Hls, HlsEngineConfig, HlsJsAdapter, HlsJsAdapterProps, HlsSource, type KeySystem, KeySystems, type MediaResolution, PlaybackType, PlaybackTypes, PreloadType, SourceType, StreamType, StreamTypes };
@@ -0,0 +1,3 @@
1
+ import { ContentTypes, Hls, HlsJsAdapter, PlaybackTypes, StreamTypes } from "./adapter.js";
2
+ import { KeySystems } from "@videojs/media";
3
+ export { ContentTypes, Hls, HlsJsAdapter, KeySystems, PlaybackTypes, StreamTypes };
@@ -0,0 +1,124 @@
1
+ import { MediaStreamTypes } from "@videojs/media";
2
+ import Hls from "hls.js";
3
+ //#region src/live.ts
4
+ function HlsJsLiveMixin(BaseClass) {
5
+ class HlsJsLive extends BaseClass {
6
+ #targetLiveWindow = NaN;
7
+ #liveEdgeStartOffset;
8
+ #seekToLiveAbort = null;
9
+ #seekToLivePending = false;
10
+ constructor(...args) {
11
+ super(...args);
12
+ const { engine } = this;
13
+ engine?.on(Hls.Events.MANIFEST_LOADING, () => {
14
+ this.#reset();
15
+ this.#armSeekToLive();
16
+ });
17
+ engine?.on(Hls.Events.MEDIA_ATTACHED, () => this.#armSeekToLive());
18
+ engine?.on(Hls.Events.MEDIA_DETACHED, () => this.#disarmSeekToLive());
19
+ engine?.on(Hls.Events.DESTROYING, () => {
20
+ this.#reset();
21
+ this.#disarmSeekToLive();
22
+ });
23
+ engine?.on(Hls.Events.LEVEL_LOADED, (_event, data) => {
24
+ this.#derive(data.details);
25
+ if (this.#seekToLivePending) this.#trySeekToLive();
26
+ });
27
+ }
28
+ get targetLiveWindow() {
29
+ return this.#targetLiveWindow;
30
+ }
31
+ get liveEdgeStart() {
32
+ if (this.#liveEdgeStartOffset === void 0) return NaN;
33
+ const { target } = this;
34
+ if (!target) return NaN;
35
+ const { seekable } = target;
36
+ if (!seekable.length) return NaN;
37
+ return seekable.end(seekable.length - 1) - this.#liveEdgeStartOffset;
38
+ }
39
+ #derive(details) {
40
+ if (!details.live) return this.#reset();
41
+ const info = getStreamInfoFromHlsjsLevelDetails(details);
42
+ this.#liveEdgeStartOffset = info.liveEdgeStartOffset;
43
+ this.#updateConfig(info);
44
+ this.#setTargetLiveWindow(info.targetLiveWindow);
45
+ }
46
+ #reset() {
47
+ this.#liveEdgeStartOffset = void 0;
48
+ this.#setTargetLiveWindow(NaN);
49
+ }
50
+ #updateConfig({ streamType, lowLatency }) {
51
+ if (streamType === MediaStreamTypes.LIVE) {
52
+ const hls = this.engine;
53
+ if (!hls) return;
54
+ if (lowLatency) {
55
+ hls.config.backBufferLength = hls.userConfig.backBufferLength ?? 4;
56
+ hls.config.maxFragLookUpTolerance = hls.userConfig.maxFragLookUpTolerance ?? .001;
57
+ hls.config.abrBandWidthUpFactor = hls.userConfig.abrBandWidthUpFactor ?? hls.config.abrBandWidthFactor;
58
+ } else hls.config.backBufferLength = hls.userConfig.backBufferLength ?? 8;
59
+ }
60
+ }
61
+ #setTargetLiveWindow(value) {
62
+ if (Object.is(this.#targetLiveWindow, value)) return;
63
+ this.#targetLiveWindow = value;
64
+ this.dispatchEvent(new Event("targetlivewindowchange"));
65
+ }
66
+ /**
67
+ * Arm a one-shot seek-to-live on the first user-initiated `play`. Skipped when `autoplay` is set, since hls.js
68
+ * positions at the live edge during its own startup sequence and a programmatic seek would race that.
69
+ */
70
+ #armSeekToLive() {
71
+ this.#disarmSeekToLive();
72
+ const target = this.target;
73
+ if (!target || target.autoplay) return;
74
+ this.#seekToLiveAbort = new AbortController();
75
+ target.addEventListener("play", () => {
76
+ this.#seekToLivePending = true;
77
+ this.#trySeekToLive();
78
+ }, {
79
+ signal: this.#seekToLiveAbort.signal,
80
+ once: true
81
+ });
82
+ }
83
+ #disarmSeekToLive() {
84
+ this.#seekToLiveAbort?.abort();
85
+ this.#seekToLiveAbort = null;
86
+ this.#seekToLivePending = false;
87
+ }
88
+ #trySeekToLive() {
89
+ const target = this.target;
90
+ if (!target) return;
91
+ const { liveEdgeStart } = this;
92
+ if (!Number.isFinite(liveEdgeStart)) return;
93
+ if (target.currentTime < liveEdgeStart) target.currentTime = liveEdgeStart;
94
+ this.#seekToLivePending = false;
95
+ }
96
+ }
97
+ return HlsJsLive;
98
+ }
99
+ const getStreamInfoFromHlsjsLevelDetails = (levelDetails) => {
100
+ const playlistType = levelDetails.type;
101
+ const streamType = toStreamTypeFromPlaylistType(playlistType);
102
+ const targetLiveWindow = toTargetLiveWindowFromPlaylistType(playlistType);
103
+ const lowLatency = !!levelDetails.partList?.length;
104
+ let liveEdgeStartOffset;
105
+ if (streamType === MediaStreamTypes.LIVE) liveEdgeStartOffset = lowLatency ? levelDetails.partHoldBack || levelDetails.partTarget * 2 : levelDetails.holdBack || levelDetails.targetduration * 3;
106
+ return {
107
+ streamType,
108
+ targetLiveWindow,
109
+ liveEdgeStartOffset,
110
+ lowLatency
111
+ };
112
+ };
113
+ const toStreamTypeFromPlaylistType = (playlistType) => {
114
+ return playlistType === "VOD" ? MediaStreamTypes.ON_DEMAND : MediaStreamTypes.LIVE;
115
+ };
116
+ const toTargetLiveWindowFromPlaylistType = (playlistType) => {
117
+ if (playlistType === "EVENT") return Number.POSITIVE_INFINITY;
118
+ if (playlistType === "VOD") return NaN;
119
+ return 0;
120
+ };
121
+ //#endregion
122
+ export { HlsJsLiveMixin };
123
+
124
+ //# sourceMappingURL=live.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"live.js","names":["#reset","#armSeekToLive","#disarmSeekToLive","#derive","#seekToLivePending","#trySeekToLive","#targetLiveWindow","#liveEdgeStartOffset","#updateConfig","#setTargetLiveWindow","#seekToLiveAbort"],"sources":["../../src/live.ts"],"sourcesContent":["import { MediaStreamTypes } from '@videojs/media';\nimport type { Constructor } from '@videojs/utils/types';\nimport type { LevelLoadedData } from 'hls.js';\nimport Hls from 'hls.js';\n\nimport type { HlsEngineHost, HlsPlaylistTypes } from './types';\n\nexport function HlsJsLiveMixin<Base extends Constructor<HlsEngineHost>>(BaseClass: Base) {\n class HlsJsLive extends (BaseClass as Constructor<HlsEngineHost>) {\n #targetLiveWindow = Number.NaN;\n #liveEdgeStartOffset: number | undefined;\n #seekToLiveAbort: AbortController | null = null;\n #seekToLivePending = false;\n\n constructor(...args: any[]) {\n super(...args);\n\n const { engine } = this;\n\n engine?.on(Hls.Events.MANIFEST_LOADING, () => {\n this.#reset();\n this.#armSeekToLive();\n });\n engine?.on(Hls.Events.MEDIA_ATTACHED, () => this.#armSeekToLive());\n engine?.on(Hls.Events.MEDIA_DETACHED, () => this.#disarmSeekToLive());\n engine?.on(Hls.Events.DESTROYING, () => {\n this.#reset();\n this.#disarmSeekToLive();\n });\n engine?.on(Hls.Events.LEVEL_LOADED, (_event: string, data: LevelLoadedData) => {\n this.#derive(data.details);\n\n // For `preload=\"none\"`/`\"metadata\"` the manifest only loads after the\n // first play, so retry the seek once `liveEdgeStart` becomes finite.\n if (this.#seekToLivePending) this.#trySeekToLive();\n });\n }\n\n get targetLiveWindow() {\n return this.#targetLiveWindow;\n }\n\n // Derived from seekable + offset at read time. No cached state, no event.\n get liveEdgeStart() {\n if (this.#liveEdgeStartOffset === undefined) return Number.NaN;\n\n const { target } = this;\n if (!target) return Number.NaN;\n\n const { seekable } = target;\n if (!seekable.length) return Number.NaN;\n\n return seekable.end(seekable.length - 1) - this.#liveEdgeStartOffset;\n }\n\n #derive(details: LevelLoadedData['details']) {\n if (!details.live) return this.#reset();\n\n const info = getStreamInfoFromHlsjsLevelDetails(details);\n\n this.#liveEdgeStartOffset = info.liveEdgeStartOffset;\n this.#updateConfig(info);\n this.#setTargetLiveWindow(info.targetLiveWindow);\n }\n\n #reset() {\n this.#liveEdgeStartOffset = undefined;\n this.#setTargetLiveWindow(Number.NaN);\n }\n\n #updateConfig({ streamType, lowLatency }: StreamInfo) {\n if (streamType === MediaStreamTypes.LIVE) {\n // Update hls.js config for live/ll-live\n const hls = this.engine;\n if (!hls) return;\n\n if (lowLatency) {\n hls.config.backBufferLength = hls.userConfig.backBufferLength ?? 4;\n hls.config.maxFragLookUpTolerance = hls.userConfig.maxFragLookUpTolerance ?? 0.001;\n // For ll-hls, ensure that up switches are weighted the same as down switches to mitigate\n // cases of getting stuck at lower bitrates.\n hls.config.abrBandWidthUpFactor = hls.userConfig.abrBandWidthUpFactor ?? hls.config.abrBandWidthFactor;\n } else {\n hls.config.backBufferLength = hls.userConfig.backBufferLength ?? 8;\n }\n }\n }\n\n #setTargetLiveWindow(value: number) {\n if (Object.is(this.#targetLiveWindow, value)) return;\n\n this.#targetLiveWindow = value;\n this.dispatchEvent(new Event('targetlivewindowchange'));\n }\n\n /**\n * Arm a one-shot seek-to-live on the first user-initiated `play`. Skipped when `autoplay` is set, since hls.js\n * positions at the live edge during its own startup sequence and a programmatic seek would race that.\n */\n #armSeekToLive() {\n this.#disarmSeekToLive();\n\n const target = this.target as HTMLVideoElement | null;\n if (!target || target.autoplay) return;\n\n this.#seekToLiveAbort = new AbortController();\n target.addEventListener(\n 'play',\n () => {\n this.#seekToLivePending = true;\n this.#trySeekToLive();\n },\n { signal: this.#seekToLiveAbort.signal, once: true }\n );\n }\n\n #disarmSeekToLive() {\n this.#seekToLiveAbort?.abort();\n this.#seekToLiveAbort = null;\n this.#seekToLivePending = false;\n }\n\n #trySeekToLive() {\n const target = this.target as HTMLVideoElement | null;\n if (!target) return;\n\n const { liveEdgeStart } = this;\n if (!Number.isFinite(liveEdgeStart)) return;\n\n if (target.currentTime < liveEdgeStart) {\n target.currentTime = liveEdgeStart;\n }\n\n this.#seekToLivePending = false;\n }\n }\n\n return HlsJsLive as unknown as Base &\n Constructor<{ readonly liveEdgeStart: number; readonly targetLiveWindow: number }>;\n}\n\ntype StreamInfo = ReturnType<typeof getStreamInfoFromHlsjsLevelDetails>;\n\nconst getStreamInfoFromHlsjsLevelDetails = (levelDetails: LevelLoadedData['details']) => {\n const playlistType: HlsPlaylistTypes = levelDetails.type as HlsPlaylistTypes;\n const streamType = toStreamTypeFromPlaylistType(playlistType);\n const targetLiveWindow = toTargetLiveWindowFromPlaylistType(playlistType);\n const lowLatency = !!levelDetails.partList?.length;\n let liveEdgeStartOffset: number | undefined;\n\n if (streamType === MediaStreamTypes.LIVE) {\n // Prefer manifest-declared HOLD-BACK / PART-HOLD-BACK when present;\n // otherwise fall back to the per-spec multiples of the target durations.\n // See https://datatracker.ietf.org/doc/html/draft-pantos-hls-rfc8216bis-12\n liveEdgeStartOffset = lowLatency\n ? levelDetails.partHoldBack || levelDetails.partTarget * 2\n : levelDetails.holdBack || levelDetails.targetduration * 3;\n }\n\n return {\n streamType,\n targetLiveWindow,\n liveEdgeStartOffset,\n lowLatency,\n };\n};\n\nconst toStreamTypeFromPlaylistType = (playlistType: HlsPlaylistTypes) => {\n return playlistType === 'VOD' ? MediaStreamTypes.ON_DEMAND : MediaStreamTypes.LIVE;\n};\n\nconst toTargetLiveWindowFromPlaylistType = (playlistType: HlsPlaylistTypes) => {\n if (playlistType === 'EVENT') return Number.POSITIVE_INFINITY;\n\n if (playlistType === 'VOD') return Number.NaN;\n\n return 0;\n};\n"],"mappings":";;;AAOA,SAAgB,eAAwD,WAAiB;CACvF,MAAM,kBAAmB,UAAyC;EAChE,oBAAoB;EACpB;EACA,mBAA2C;EAC3C,qBAAqB;EAErB,YAAY,GAAG,MAAa;GAC1B,MAAM,GAAG,IAAI;GAEb,MAAM,EAAE,WAAW;GAEnB,QAAQ,GAAG,IAAI,OAAO,wBAAwB;IAC5C,KAAKA,OAAO;IACZ,KAAKC,eAAe;GACtB,CAAC;GACD,QAAQ,GAAG,IAAI,OAAO,sBAAsB,KAAKA,eAAe,CAAC;GACjE,QAAQ,GAAG,IAAI,OAAO,sBAAsB,KAAKC,kBAAkB,CAAC;GACpE,QAAQ,GAAG,IAAI,OAAO,kBAAkB;IACtC,KAAKF,OAAO;IACZ,KAAKE,kBAAkB;GACzB,CAAC;GACD,QAAQ,GAAG,IAAI,OAAO,eAAe,QAAgB,SAA0B;IAC7E,KAAKC,QAAQ,KAAK,OAAO;IAIzB,IAAI,KAAKC,oBAAoB,KAAKC,eAAe;GACnD,CAAC;EACH;EAEA,IAAI,mBAAmB;GACrB,OAAO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