xgplayer-mp4-loader 3.0.9-alpha.2 → 3.0.9-alpha.21

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/es/utils.js CHANGED
@@ -1,5 +1,17 @@
1
1
  import { toConsumableArray as _toConsumableArray } from "./_virtual/_rollupPluginBabelHelpers.js";
2
- function moovToSegments(moov, duration) {
2
+ function isEdtsApplicable() {
3
+ var flag = true;
4
+ var userAgent = navigator.userAgent || "";
5
+ var isChrome = /Chrome/gi.test(userAgent) && !/Edge\//gi.test(userAgent);
6
+ if (isChrome) {
7
+ var result = userAgent.match(/Chrome\/(\d+)/i);
8
+ var chromeVersion = result ? parseInt(result[1], 10) : 0;
9
+ flag = !!chromeVersion && chromeVersion >= 75;
10
+ }
11
+ return flag;
12
+ }
13
+ function moovToSegments(moov, config) {
14
+ var segmentDuration = config.segmentDuration;
3
15
  var tracks = moov.trak;
4
16
  if (!tracks || !tracks.length)
5
17
  return;
@@ -17,54 +29,52 @@ function moovToSegments(moov, duration) {
17
29
  var audioSegments = [];
18
30
  var segmentDurations;
19
31
  if (videoTrack) {
20
- var _videoTrack$mdia, _videoTrack$mdia$minf, _videoTrack$mdia$mdhd;
21
- var videoStbl = (_videoTrack$mdia = videoTrack.mdia) === null || _videoTrack$mdia === void 0 ? void 0 : (_videoTrack$mdia$minf = _videoTrack$mdia.minf) === null || _videoTrack$mdia$minf === void 0 ? void 0 : _videoTrack$mdia$minf.stbl;
22
- if (!videoStbl)
23
- return;
24
- var timescale = (_videoTrack$mdia$mdhd = videoTrack.mdia.mdhd) === null || _videoTrack$mdia$mdhd === void 0 ? void 0 : _videoTrack$mdia$mdhd.timescale;
25
- var stts = videoStbl.stts, stsc = videoStbl.stsc, stsz = videoStbl.stsz, stco = videoStbl.stco, stss = videoStbl.stss, ctts = videoStbl.ctts;
26
- if (!timescale || !stts || !stsc || !stsz || !stco || !stss)
27
- return;
28
- videoSegments = getSegments(duration, timescale, stts, stsc, stsz, stco, stss, ctts);
32
+ videoSegments = getSegments("video", videoTrack, segmentDuration, config);
29
33
  segmentDurations = videoSegments.map(function(x) {
30
34
  return x.duration;
31
35
  });
32
36
  }
33
37
  if (audioTrack) {
34
- var _audioTrack$mdia, _audioTrack$mdia$minf, _audioTrack$mdia$mdhd;
35
- var audioStbl = (_audioTrack$mdia = audioTrack.mdia) === null || _audioTrack$mdia === void 0 ? void 0 : (_audioTrack$mdia$minf = _audioTrack$mdia.minf) === null || _audioTrack$mdia$minf === void 0 ? void 0 : _audioTrack$mdia$minf.stbl;
36
- if (!audioStbl)
37
- return;
38
- var _timescale = (_audioTrack$mdia$mdhd = audioTrack.mdia.mdhd) === null || _audioTrack$mdia$mdhd === void 0 ? void 0 : _audioTrack$mdia$mdhd.timescale;
39
- var _stts = audioStbl.stts, _stsc = audioStbl.stsc, _stsz = audioStbl.stsz, _stco = audioStbl.stco;
40
- if (!_timescale || !_stts || !_stsc || !_stsz || !_stco)
41
- return;
42
- audioSegments = getSegments(duration, _timescale, _stts, _stsc, _stsz, _stco, null, null, segmentDurations);
38
+ audioSegments = getSegments("audio", audioTrack, segmentDuration, config, segmentDurations, videoSegments);
43
39
  }
44
40
  return {
45
41
  videoSegments,
46
42
  audioSegments
47
43
  };
48
44
  }
49
- function getSegments(segDuration, timescale, stts, stsc, stsz, stco, stss, ctts, segmentDurations) {
45
+ function getSegments(type, track, segDuration, config) {
46
+ var _track$mdia, _track$mdia$minf, _track$mdia$mdhd, _track$edts, _track$edts$elst;
47
+ var segmentDurations = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : [];
48
+ var videoSegments = arguments.length > 5 ? arguments[5] : void 0;
49
+ var fixEditListOffset = config.fixEditListOffset, fixEditListOffsetThreshold = config.fixEditListOffsetThreshold, audioGroupingStrategy = config.audioGroupingStrategy;
50
+ var stbl = (_track$mdia = track.mdia) === null || _track$mdia === void 0 ? void 0 : (_track$mdia$minf = _track$mdia.minf) === null || _track$mdia$minf === void 0 ? void 0 : _track$mdia$minf.stbl;
51
+ if (!stbl) {
52
+ return [];
53
+ }
54
+ var timescale = (_track$mdia$mdhd = track.mdia.mdhd) === null || _track$mdia$mdhd === void 0 ? void 0 : _track$mdia$mdhd.timescale;
55
+ var stts = stbl.stts, stsc = stbl.stsc, stsz = stbl.stsz, stco = stbl.stco, stss = stbl.stss, ctts = stbl.ctts;
56
+ if (!timescale || !stts || !stsc || !stsz || !stco || type === "video" && !stss) {
57
+ return [];
58
+ }
59
+ var editListOffset = 0;
60
+ var editList = (_track$edts = track.edts) === null || _track$edts === void 0 ? void 0 : (_track$edts$elst = _track$edts.elst) === null || _track$edts$elst === void 0 ? void 0 : _track$edts$elst.entries;
61
+ if (fixEditListOffset && isEdtsApplicable() && Array.isArray(editList) && editList.length > 0) {
62
+ var media_time = editList[0].media_time;
63
+ var maxAllowedTime = fixEditListOffsetThreshold ? fixEditListOffsetThreshold * timescale : 5 * timescale;
64
+ if (media_time > 0 && media_time < maxAllowedTime) {
65
+ editListOffset = media_time;
66
+ }
67
+ }
50
68
  var frames = [];
51
69
  var gop = [];
52
70
  var gopDuration = [];
71
+ var gopMinPtsArr = [];
72
+ var gopMaxPtsFrameIdxArr = [];
53
73
  var stscEntries = stsc.entries;
54
74
  var stcoEntries = stco.entries;
55
75
  var stszEntrySizes = stsz.entrySizes;
56
76
  var stssEntries = stss === null || stss === void 0 ? void 0 : stss.entries;
57
77
  var cttsEntries = ctts === null || ctts === void 0 ? void 0 : ctts.entries;
58
- var cttsArr;
59
- if (cttsEntries) {
60
- cttsArr = [];
61
- cttsEntries.forEach(function(_ref) {
62
- var count = _ref.count, offset = _ref.offset;
63
- for (var i2 = 0; i2 < count; i2++) {
64
- cttsArr.push(offset);
65
- }
66
- });
67
- }
68
78
  var keyframeMap;
69
79
  if (stssEntries) {
70
80
  keyframeMap = {};
@@ -74,22 +84,27 @@ function getSegments(segDuration, timescale, stts, stsc, stsz, stco, stss, ctts,
74
84
  }
75
85
  var frame;
76
86
  var duration;
77
- var startTime = 0;
78
87
  var pos = 0;
79
88
  var chunkIndex = 0;
80
89
  var chunkRunIndex = 0;
81
90
  var offsetInChunk = 0;
82
- var lastSampleInChunk = stscEntries[0].samplesPerChunk;
83
- var lastChunkInRun = stscEntries[1] ? stscEntries[1].firstChunk - 1 : Infinity;
91
+ var lastSampleInChunk = stscEntries.length > 0 ? stscEntries[0].samplesPerChunk : 0;
92
+ var lastChunkInRun = stscEntries.length > 1 && stscEntries[1] ? stscEntries[1].firstChunk - 1 : Infinity;
84
93
  var dts = 0;
85
94
  var gopId = -1;
86
- stts.entries.forEach(function(_ref2) {
87
- var count = _ref2.count, delta = _ref2.delta;
95
+ var editListApplied = false;
96
+ var beforeCttsInfo = null;
97
+ if ((cttsEntries === null || cttsEntries === void 0 ? void 0 : cttsEntries.length) > 0 && editListOffset > 0) {
98
+ dts -= editListOffset;
99
+ editListApplied = true;
100
+ }
101
+ track.editListApplied = editListApplied;
102
+ stts.entries.forEach(function(_ref) {
103
+ var count = _ref.count, delta = _ref.delta;
88
104
  duration = delta;
89
105
  for (var i2 = 0; i2 < count; i2++) {
90
106
  frame = {
91
107
  dts,
92
- startTime,
93
108
  duration,
94
109
  size: stszEntrySizes[pos] || stsz.sampleSize,
95
110
  offset: stcoEntries[chunkIndex] + offsetInChunk,
@@ -107,14 +122,33 @@ function getSegments(segDuration, timescale, stts, stsc, stsz, stco, stss, ctts,
107
122
  }
108
123
  frame.gopId = gopId;
109
124
  }
110
- if (cttsArr && pos < cttsArr.length) {
111
- frame.pts = dts + cttsArr[pos];
125
+ if (cttsEntries) {
126
+ beforeCttsInfo = getCTTSOffset(cttsEntries, pos, beforeCttsInfo);
127
+ frame.pts = dts + beforeCttsInfo.offset;
112
128
  }
113
- if (pos === 0) {
129
+ if (editListOffset === 0 && pos === 0) {
114
130
  frame.pts = 0;
115
131
  }
116
- frames.push(frame);
117
- startTime += duration;
132
+ if (frame.pts === void 0) {
133
+ frame.pts = frame.dts;
134
+ }
135
+ if (frame.keyframe) {
136
+ gopMinPtsArr[gopMinPtsArr.length] = frame.pts;
137
+ } else {
138
+ if (frame.pts < gopMinPtsArr[gop.length - 1]) {
139
+ gopMinPtsArr[gop.length - 1] = frame.pts;
140
+ }
141
+ }
142
+ if (frame.keyframe) {
143
+ gopMaxPtsFrameIdxArr[gopMaxPtsFrameIdxArr.length] = frame.index;
144
+ } else if (gop.length > 0 && gopMaxPtsFrameIdxArr[gop.length - 1] !== void 0) {
145
+ var _frames$gopMaxPtsFram;
146
+ var curMaxPts = (_frames$gopMaxPtsFram = frames[gopMaxPtsFrameIdxArr[gop.length - 1]]) === null || _frames$gopMaxPtsFram === void 0 ? void 0 : _frames$gopMaxPtsFram.pts;
147
+ if (curMaxPts !== void 0 && frame.pts > curMaxPts) {
148
+ gopMaxPtsFrameIdxArr[gop.length - 1] = frame.index;
149
+ }
150
+ }
151
+ frames[frames.length] = frame;
118
152
  dts += delta;
119
153
  pos++;
120
154
  if (pos < lastSampleInChunk) {
@@ -131,27 +165,38 @@ function getSegments(segDuration, timescale, stts, stsc, stsz, stco, stss, ctts,
131
165
  }
132
166
  });
133
167
  var l = frames.length;
134
- if (!l || stss && !frames[0].keyframe)
135
- return;
168
+ if (!l || stss && !frames[0].keyframe) {
169
+ return [];
170
+ }
136
171
  var segments = [];
137
172
  var segFrames = [];
138
173
  var time = 0;
139
174
  var lastFrame;
140
175
  var adjust = 0;
141
- var pushSegment = function pushSegment2(duration2) {
142
- var _segments;
176
+ var segMinPts = 0;
177
+ var segMaxPtsFrame = 0;
178
+ var pushSegment = function pushSegment2(duration2, startGopIdx, endGopIdx) {
143
179
  lastFrame = segFrames[segFrames.length - 1];
180
+ segMinPts = gopMinPtsArr[startGopIdx];
181
+ segMaxPtsFrame = frames[gopMaxPtsFrameIdxArr[endGopIdx]];
182
+ if (segments.length === 0) {
183
+ var diff = segMaxPtsFrame.pts + segMaxPtsFrame.duration - segMinPts;
184
+ duration2 = diff / timescale;
185
+ }
144
186
  segments.push({
145
187
  index: segments.length,
146
- startTime: ((_segments = segments[segments.length - 1]) === null || _segments === void 0 ? void 0 : _segments.endTime) || segFrames[0].startTime / timescale,
147
- endTime: (lastFrame.startTime + lastFrame.duration) / timescale,
188
+ startTime: segMinPts / timescale,
189
+ endTime: (segMaxPtsFrame.pts + segMaxPtsFrame.duration) / timescale,
148
190
  duration: duration2,
149
- range: [segFrames[0].offset, lastFrame.offset + lastFrame.size],
191
+ range: [segFrames[0].offset, lastFrame.offset + lastFrame.size - 1],
150
192
  frames: segFrames
151
193
  });
152
- time = 0;
194
+ if (audioGroupingStrategy !== 1) {
195
+ time = 0;
196
+ }
153
197
  segFrames = [];
154
198
  };
199
+ var segGopStartIdx = 0;
155
200
  if (stss) {
156
201
  var _duration = segDuration * timescale;
157
202
  for (var i = 0, _l = gop.length; i < _l; i++) {
@@ -160,28 +205,84 @@ function getSegments(segDuration, timescale, stts, stsc, stsz, stco, stss, ctts,
160
205
  (_segFrames = segFrames).push.apply(_segFrames, _toConsumableArray(gop[i]));
161
206
  if (i + 1 < _l) {
162
207
  if (i === 0 || time > _duration) {
163
- pushSegment(time / timescale);
208
+ pushSegment(time / timescale, segGopStartIdx, i);
209
+ segGopStartIdx = i + 1;
164
210
  }
165
211
  } else {
166
- pushSegment(time / timescale);
212
+ pushSegment(time / timescale, segGopStartIdx, i);
213
+ segGopStartIdx = i + 1;
167
214
  }
168
215
  }
169
216
  } else {
170
- segmentDurations = segmentDurations || [];
217
+ gopMinPtsArr = [];
218
+ gopMaxPtsFrameIdxArr = [];
171
219
  var _duration2 = segmentDurations[0] || segDuration;
172
- for (var _i = 0; _i < l; _i++) {
173
- segFrames.push(frames[_i]);
174
- time += frames[_i].duration;
175
- var curTime = time / timescale;
176
- if (_i + 1 >= l || curTime + adjust >= _duration2) {
177
- adjust += curTime - _duration2;
178
- pushSegment(curTime);
179
- _duration2 = segmentDurations[segments.length] || segDuration;
220
+ if (audioGroupingStrategy === 1) {
221
+ for (var _i = 0, nextEndTime; _i < l; _i++) {
222
+ var curFrame = frames[_i];
223
+ var nextFrame = frames[_i + 1];
224
+ var isFinalFrame = _i === l - 1;
225
+ segFrames.push(curFrame);
226
+ time += curFrame.duration;
227
+ var curEndTime = nextEndTime || time / timescale;
228
+ nextEndTime = (nextFrame ? time + nextFrame.duration : 0) / timescale;
229
+ if (isFinalFrame || (videoSegments[segments.length] ? nextEndTime > videoSegments[segments.length].endTime : nextEndTime - segFrames[0].pts / timescale >= _duration2)) {
230
+ gopMinPtsArr.push(segFrames[0].pts);
231
+ gopMaxPtsFrameIdxArr.push(segFrames[segFrames.length - 1].index);
232
+ pushSegment(curEndTime, segments.length, segments.length);
233
+ _duration2 = segmentDurations[segments.length] || segDuration;
234
+ }
235
+ }
236
+ } else {
237
+ for (var _i2 = 0, _nextEndTime; _i2 < l; _i2++) {
238
+ var _curFrame = frames[_i2];
239
+ var _nextFrame = frames[_i2 + 1];
240
+ var _isFinalFrame = _i2 === l - 1;
241
+ segFrames.push(_curFrame);
242
+ time += _curFrame.duration;
243
+ var _curEndTime = _nextEndTime || time / timescale;
244
+ _nextEndTime = (_nextFrame ? time + _nextFrame.duration : 0) / timescale;
245
+ if (_isFinalFrame || _nextEndTime + adjust >= _duration2) {
246
+ if (audioGroupingStrategy === 2) {
247
+ adjust += time / timescale - _duration2;
248
+ } else {
249
+ adjust += _nextEndTime - _duration2;
250
+ }
251
+ gopMinPtsArr.push(segFrames[0].pts);
252
+ gopMaxPtsFrameIdxArr.push(segFrames[segFrames.length - 1].index);
253
+ pushSegment(_curEndTime, segments.length, segments.length);
254
+ _duration2 = segmentDurations[segments.length] || segDuration;
255
+ }
180
256
  }
181
257
  }
182
258
  }
183
259
  return segments;
184
260
  }
261
+ function getCTTSOffset(cttsEntries, frameIndex, beforeCttsInfo) {
262
+ var ret = {};
263
+ if (!cttsEntries || (cttsEntries === null || cttsEntries === void 0 ? void 0 : cttsEntries.length) <= 0 || (beforeCttsInfo === null || beforeCttsInfo === void 0 ? void 0 : beforeCttsInfo.usedCttsIdx) >= cttsEntries.length) {
264
+ ret.offset = 0;
265
+ ret.usedCttsIdx = (beforeCttsInfo === null || beforeCttsInfo === void 0 ? void 0 : beforeCttsInfo.usedCttsIdx) || 0;
266
+ ret.beforeFrameNum = (beforeCttsInfo === null || beforeCttsInfo === void 0 ? void 0 : beforeCttsInfo.beforeFrameNum) || 0;
267
+ }
268
+ var curerentCTTS = cttsEntries[(beforeCttsInfo === null || beforeCttsInfo === void 0 ? void 0 : beforeCttsInfo.usedCttsIdx) || 0];
269
+ var count = (curerentCTTS === null || curerentCTTS === void 0 ? void 0 : curerentCTTS.count) || 1;
270
+ if (frameIndex < ((beforeCttsInfo === null || beforeCttsInfo === void 0 ? void 0 : beforeCttsInfo.beforeFrameNum) || 0) + count) {
271
+ ret.offset = (curerentCTTS === null || curerentCTTS === void 0 ? void 0 : curerentCTTS.offset) || 0;
272
+ ret.usedCttsIdx = (beforeCttsInfo === null || beforeCttsInfo === void 0 ? void 0 : beforeCttsInfo.usedCttsIdx) || 0;
273
+ ret.beforeFrameNum = (beforeCttsInfo === null || beforeCttsInfo === void 0 ? void 0 : beforeCttsInfo.beforeFrameNum) || 0;
274
+ } else {
275
+ var newCTTS = cttsEntries[beforeCttsInfo.usedCttsIdx + 1];
276
+ if (!newCTTS) {
277
+ ret.offset = 0;
278
+ } else {
279
+ ret.offset = (newCTTS === null || newCTTS === void 0 ? void 0 : newCTTS.offset) || 0;
280
+ }
281
+ ret.usedCttsIdx = beforeCttsInfo.usedCttsIdx + 1;
282
+ ret.beforeFrameNum = ((beforeCttsInfo === null || beforeCttsInfo === void 0 ? void 0 : beforeCttsInfo.beforeFrameNum) || 0) + ((curerentCTTS === null || curerentCTTS === void 0 ? void 0 : curerentCTTS.count) || 1);
283
+ }
284
+ return ret;
285
+ }
185
286
  function moovToMeta(moov) {
186
287
  var videoCodec = "";
187
288
  var audioCodec = "";
@@ -208,14 +309,14 @@ function moovToMeta(moov) {
208
309
  var e1 = null;
209
310
  var defaultKID;
210
311
  if (videoTrack) {
211
- var _videoTrack$mdia2, _videoTrack$mdia2$min, _videoTrack$mdia2$min2;
212
- e1 = (_videoTrack$mdia2 = videoTrack.mdia) === null || _videoTrack$mdia2 === void 0 ? void 0 : (_videoTrack$mdia2$min = _videoTrack$mdia2.minf) === null || _videoTrack$mdia2$min === void 0 ? void 0 : (_videoTrack$mdia2$min2 = _videoTrack$mdia2$min.stbl) === null || _videoTrack$mdia2$min2 === void 0 ? void 0 : _videoTrack$mdia2$min2.stsd.entries[0];
312
+ var _videoTrack$mdia, _videoTrack$mdia$minf, _videoTrack$mdia$minf2;
313
+ e1 = (_videoTrack$mdia = videoTrack.mdia) === null || _videoTrack$mdia === void 0 ? void 0 : (_videoTrack$mdia$minf = _videoTrack$mdia.minf) === null || _videoTrack$mdia$minf === void 0 ? void 0 : (_videoTrack$mdia$minf2 = _videoTrack$mdia$minf.stbl) === null || _videoTrack$mdia$minf2 === void 0 ? void 0 : _videoTrack$mdia$minf2.stsd.entries[0];
213
314
  if (e1) {
214
- var _videoTrack$mdia3, _videoTrack$mdia3$mdh, _ref3;
315
+ var _videoTrack$mdia2, _videoTrack$mdia2$mdh, _ref2;
215
316
  width = e1.width;
216
317
  height = e1.height;
217
- videoTimescale = (_videoTrack$mdia3 = videoTrack.mdia) === null || _videoTrack$mdia3 === void 0 ? void 0 : (_videoTrack$mdia3$mdh = _videoTrack$mdia3.mdhd) === null || _videoTrack$mdia3$mdh === void 0 ? void 0 : _videoTrack$mdia3$mdh.timescale;
218
- videoCodec = (_ref3 = e1.avcC || e1.hvcC || e1.vvcC) === null || _ref3 === void 0 ? void 0 : _ref3.codec;
318
+ videoTimescale = (_videoTrack$mdia2 = videoTrack.mdia) === null || _videoTrack$mdia2 === void 0 ? void 0 : (_videoTrack$mdia2$mdh = _videoTrack$mdia2.mdhd) === null || _videoTrack$mdia2$mdh === void 0 ? void 0 : _videoTrack$mdia2$mdh.timescale;
319
+ videoCodec = (_ref2 = e1.avcC || e1.hvcC || e1.vvcC) === null || _ref2 === void 0 ? void 0 : _ref2.codec;
219
320
  if (e1.type === "encv") {
220
321
  var _e1$sinf, _e1$sinf$schi;
221
322
  defaultKID = (_e1$sinf = e1.sinf) === null || _e1$sinf === void 0 ? void 0 : (_e1$sinf$schi = _e1$sinf.schi) === null || _e1$sinf$schi === void 0 ? void 0 : _e1$sinf$schi.tenc.default_KID;
@@ -223,14 +324,14 @@ function moovToMeta(moov) {
223
324
  }
224
325
  }
225
326
  if (audioTrack) {
226
- var _audioTrack$mdia2, _audioTrack$mdia2$min, _audioTrack$mdia2$min2;
227
- e1 = (_audioTrack$mdia2 = audioTrack.mdia) === null || _audioTrack$mdia2 === void 0 ? void 0 : (_audioTrack$mdia2$min = _audioTrack$mdia2.minf) === null || _audioTrack$mdia2$min === void 0 ? void 0 : (_audioTrack$mdia2$min2 = _audioTrack$mdia2$min.stbl) === null || _audioTrack$mdia2$min2 === void 0 ? void 0 : _audioTrack$mdia2$min2.stsd.entries[0];
327
+ var _audioTrack$mdia, _audioTrack$mdia$minf, _audioTrack$mdia$minf2;
328
+ e1 = (_audioTrack$mdia = audioTrack.mdia) === null || _audioTrack$mdia === void 0 ? void 0 : (_audioTrack$mdia$minf = _audioTrack$mdia.minf) === null || _audioTrack$mdia$minf === void 0 ? void 0 : (_audioTrack$mdia$minf2 = _audioTrack$mdia$minf.stbl) === null || _audioTrack$mdia$minf2 === void 0 ? void 0 : _audioTrack$mdia$minf2.stsd.entries[0];
228
329
  if (e1) {
229
- var _e1$esds, _audioTrack$mdia3, _audioTrack$mdia3$mdh;
330
+ var _e1$esds, _audioTrack$mdia2, _audioTrack$mdia2$mdh;
230
331
  audioChannelCount = e1.channelCount;
231
332
  audioSampleRate = e1.sampleRate;
232
333
  audioCodec = (_e1$esds = e1.esds) === null || _e1$esds === void 0 ? void 0 : _e1$esds.codec;
233
- audioTimescale = (_audioTrack$mdia3 = audioTrack.mdia) === null || _audioTrack$mdia3 === void 0 ? void 0 : (_audioTrack$mdia3$mdh = _audioTrack$mdia3.mdhd) === null || _audioTrack$mdia3$mdh === void 0 ? void 0 : _audioTrack$mdia3$mdh.timescale;
334
+ audioTimescale = (_audioTrack$mdia2 = audioTrack.mdia) === null || _audioTrack$mdia2 === void 0 ? void 0 : (_audioTrack$mdia2$mdh = _audioTrack$mdia2.mdhd) === null || _audioTrack$mdia2$mdh === void 0 ? void 0 : _audioTrack$mdia2$mdh.timescale;
234
335
  if (e1.type === "enca") {
235
336
  var _e1$sinf2, _e1$sinf2$schi;
236
337
  defaultKID = defaultKID || ((_e1$sinf2 = e1.sinf) === null || _e1$sinf2 === void 0 ? void 0 : (_e1$sinf2$schi = _e1$sinf2.schi) === null || _e1$sinf2$schi === void 0 ? void 0 : _e1$sinf2$schi.tenc.default_KID);
@@ -255,4 +356,16 @@ function moovToMeta(moov) {
255
356
  function isNumber(n) {
256
357
  return typeof n === "number" && !Number.isNaN(n);
257
358
  }
258
- export { isNumber, moovToMeta, moovToSegments };
359
+ function isSegmentsOk(segments) {
360
+ if (!segments) {
361
+ return false;
362
+ }
363
+ var audioSegments = segments.audioSegments, videoSegments = segments.videoSegments;
364
+ var v = !videoSegments || videoSegments.length === 0;
365
+ var a = !audioSegments || audioSegments.length === 0;
366
+ if (v && a) {
367
+ return false;
368
+ }
369
+ return true;
370
+ }
371
+ export { isNumber, isSegmentsOk, moovToMeta, moovToSegments };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xgplayer-mp4-loader",
3
- "version": "3.0.9-alpha.2",
3
+ "version": "3.0.9-alpha.21",
4
4
  "main": "dist/index.min.js",
5
5
  "module": "es/index.js",
6
6
  "typings": "es/index.d.ts",
@@ -22,8 +22,8 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "xgplayer-transmuxer": "3.0.9-alpha.1",
26
- "xgplayer-streaming-shared": "3.0.9",
25
+ "xgplayer-transmuxer": "3.0.9-alpha.10",
26
+ "xgplayer-streaming-shared": "3.0.11-alpha.10",
27
27
  "eventemitter3": "^4.0.7"
28
28
  },
29
29
  "peerDependencies": {