hls.js 1.5.14-0.canary.10429 → 1.5.14-0.canary.10431

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.
@@ -17,14 +17,13 @@ export function findFirstFragWithCC(
17
17
  }
18
18
 
19
19
  export function shouldAlignOnDiscontinuities(
20
- lastFrag: Fragment | null,
21
- switchDetails: LevelDetails | undefined,
20
+ refDetails: LevelDetails | undefined,
22
21
  details: LevelDetails,
23
- ): switchDetails is LevelDetails & boolean {
24
- if (switchDetails) {
22
+ ): refDetails is LevelDetails & boolean {
23
+ if (refDetails) {
25
24
  if (
26
- details.endCC > details.startCC ||
27
- (lastFrag && lastFrag.cc < details.startCC)
25
+ details.startCC < refDetails.endCC &&
26
+ details.endCC > refDetails.startCC
28
27
  ) {
29
28
  return true;
30
29
  }
@@ -32,29 +31,6 @@ export function shouldAlignOnDiscontinuities(
32
31
  return false;
33
32
  }
34
33
 
35
- // Find the first frag in the previous level which matches the CC of the first frag of the new level
36
- export function findDiscontinuousReferenceFrag(
37
- prevDetails: LevelDetails,
38
- curDetails: LevelDetails,
39
- ) {
40
- const prevFrags = prevDetails.fragments;
41
- const curFrags = curDetails.fragments;
42
-
43
- if (!curFrags.length || !prevFrags.length) {
44
- logger.log('No fragments to align');
45
- return;
46
- }
47
-
48
- const prevStartFrag = findFirstFragWithCC(prevFrags, curFrags[0].cc);
49
-
50
- if (!prevStartFrag || (prevStartFrag && !prevStartFrag.startPTS)) {
51
- logger.log('No frag in previous level to align on');
52
- return;
53
- }
54
-
55
- return prevStartFrag;
56
- }
57
-
58
34
  function adjustFragmentStart(frag: Fragment, sliding: number) {
59
35
  if (frag) {
60
36
  const start = frag.start + sliding;
@@ -94,7 +70,7 @@ export function alignStream(
94
70
  if (!switchDetails) {
95
71
  return;
96
72
  }
97
- alignDiscontinuities(lastFrag, details, switchDetails);
73
+ alignDiscontinuities(details, switchDetails);
98
74
  if (!details.alignedSliding && switchDetails) {
99
75
  // If the PTS wasn't figured out via discontinuity sequence that means there was no CC increase within the level.
100
76
  // Aligning via Program Date Time should therefore be reliable, since PDT should be the same within the same
@@ -110,29 +86,27 @@ export function alignStream(
110
86
  }
111
87
 
112
88
  /**
113
- * Computes the PTS if a new level's fragments using the PTS of a fragment in the last level which shares the same
114
- * discontinuity sequence.
115
- * @param lastFrag - The last Fragment which shares the same discontinuity sequence
89
+ * Ajust the start of fragments in `details` by the difference in time between fragments of the latest
90
+ * shared discontinuity sequence change.
116
91
  * @param lastLevel - The details of the last loaded level
117
92
  * @param details - The details of the new level
118
93
  */
119
- function alignDiscontinuities(
120
- lastFrag: Fragment | null,
94
+ export function alignDiscontinuities(
121
95
  details: LevelDetails,
122
- switchDetails: LevelDetails | undefined,
96
+ refDetails: LevelDetails | undefined,
123
97
  ) {
124
- if (shouldAlignOnDiscontinuities(lastFrag, switchDetails, details)) {
125
- const referenceFrag = findDiscontinuousReferenceFrag(
126
- switchDetails,
127
- details,
128
- );
129
- if (referenceFrag && Number.isFinite(referenceFrag.start)) {
130
- logger.log(
131
- `Adjusting PTS using last level due to CC increase within current level ${details.url}`,
132
- );
133
- adjustSlidingStart(referenceFrag.start, details);
134
- }
98
+ if (!shouldAlignOnDiscontinuities(refDetails, details)) {
99
+ return;
135
100
  }
101
+ const targetCC = Math.min(refDetails.endCC, details.endCC);
102
+ const refFrag = findFirstFragWithCC(refDetails.fragments, targetCC);
103
+ const frag = findFirstFragWithCC(details.fragments, targetCC);
104
+ if (!refFrag || !frag) {
105
+ return;
106
+ }
107
+ logger.log(`Aligning playlist at start of dicontinuity sequence ${targetCC}`);
108
+ const delta = refFrag.start - frag.start;
109
+ adjustSlidingStart(delta, details);
136
110
  }
137
111
 
138
112
  /**