@volcengine/veplayer-plugin 2.4.1-rc.0 → 2.5.0-rc.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 (43) hide show
  1. package/esm/index.d.ts +1 -0
  2. package/esm/index.development.css +7 -0
  3. package/esm/index.development.js +31562 -23809
  4. package/esm/index.production.css +1 -1
  5. package/esm/index.production.js +13 -4
  6. package/esm/veplayer.plugin.abr.development.js +59 -3
  7. package/esm/veplayer.plugin.abr.production.js +1 -1
  8. package/esm/veplayer.plugin.ad.development.css +7 -0
  9. package/esm/veplayer.plugin.ad.development.js +9042 -0
  10. package/esm/veplayer.plugin.ad.production.css +1 -0
  11. package/esm/veplayer.plugin.ad.production.js +4 -0
  12. package/esm/veplayer.plugin.drm.development.js +59 -3
  13. package/esm/veplayer.plugin.drm.production.js +1 -1
  14. package/esm/veplayer.plugin.flv.development.js +63 -22
  15. package/esm/veplayer.plugin.flv.production.js +1 -1
  16. package/esm/veplayer.plugin.hls.development.js +398 -55
  17. package/esm/veplayer.plugin.hls.production.js +1 -1
  18. package/esm/veplayer.plugin.mp4.development.js +61 -5
  19. package/esm/veplayer.plugin.mp4.production.js +1 -1
  20. package/esm/veplayer.plugin.rtm.development.js +63 -13
  21. package/esm/veplayer.plugin.rtm.production.js +1 -1
  22. package/esm/veplayer.plugin.shaka.development.js +60 -4
  23. package/esm/veplayer.plugin.shaka.production.js +1 -1
  24. package/package.json +1 -1
  25. package/umd/index.d.ts +1 -0
  26. package/umd/veplayer.plugin.abr.development.js +59 -3
  27. package/umd/veplayer.plugin.abr.production.js +1 -1
  28. package/umd/veplayer.plugin.ad.development.css +7 -0
  29. package/umd/veplayer.plugin.ad.development.js +9045 -0
  30. package/umd/veplayer.plugin.ad.production.css +1 -0
  31. package/umd/veplayer.plugin.ad.production.js +1 -0
  32. package/umd/veplayer.plugin.drm.development.js +59 -3
  33. package/umd/veplayer.plugin.drm.production.js +1 -1
  34. package/umd/veplayer.plugin.flv.development.js +63 -22
  35. package/umd/veplayer.plugin.flv.production.js +1 -1
  36. package/umd/veplayer.plugin.hls.development.js +398 -55
  37. package/umd/veplayer.plugin.hls.production.js +1 -1
  38. package/umd/veplayer.plugin.mp4.development.js +61 -5
  39. package/umd/veplayer.plugin.mp4.production.js +1 -1
  40. package/umd/veplayer.plugin.rtm.development.js +63 -13
  41. package/umd/veplayer.plugin.rtm.production.js +1 -1
  42. package/umd/veplayer.plugin.shaka.development.js +60 -4
  43. package/umd/veplayer.plugin.shaka.production.js +1 -1
@@ -1644,7 +1644,7 @@
1644
1644
  }
1645
1645
  return offsetTime;
1646
1646
  };
1647
- var version = "3.0.19-rc.0";
1647
+ var version = "3.0.20-alpha.4";
1648
1648
  var ERROR_MAP = {
1649
1649
  1: 5101,
1650
1650
  2: 5102,
@@ -1753,8 +1753,7 @@
1753
1753
  }
1754
1754
  if (this.__hooks && this.__hooks[hookName]) {
1755
1755
  try {
1756
- var _this$__hooks$hookNam;
1757
- var preRet = (_this$__hooks$hookNam = this.__hooks[hookName]).call.apply(_this$__hooks$hookNam, [this, this].concat(Array.prototype.slice.call(arguments)));
1756
+ var preRet = runHooks(this, hookName, handler);
1758
1757
  if (preRet) {
1759
1758
  if (preRet.then) {
1760
1759
  preRet.then(function(isContinue) {
@@ -1779,6 +1778,19 @@
1779
1778
  }
1780
1779
  }.bind(this);
1781
1780
  }
1781
+ function findHookIndex(hookName, handler) {
1782
+ var __hooks = this.__hooks;
1783
+ if (!__hooks || !Array.isArray(__hooks[hookName])) {
1784
+ return -1;
1785
+ }
1786
+ var hookHandlers = __hooks[hookName];
1787
+ for (var i = 0; i < hookHandlers.length; i++) {
1788
+ if (hookHandlers[i] === handler) {
1789
+ return i;
1790
+ }
1791
+ }
1792
+ return -1;
1793
+ }
1782
1794
  function useHooks(hookName, handler) {
1783
1795
  var __hooks = this.__hooks;
1784
1796
  if (!__hooks) {
@@ -1788,7 +1800,12 @@
1788
1800
  console.warn("has no supported hook which name [".concat(hookName, "]"));
1789
1801
  return false;
1790
1802
  }
1791
- __hooks && (__hooks[hookName] = handler);
1803
+ if (!Array.isArray(__hooks[hookName])) {
1804
+ __hooks[hookName] = [];
1805
+ }
1806
+ if (findHookIndex.call(this, hookName, handler) === -1) {
1807
+ __hooks[hookName].push(handler);
1808
+ }
1792
1809
  return true;
1793
1810
  }
1794
1811
  function removeHooks(hookName, handler) {
@@ -1796,6 +1813,13 @@
1796
1813
  if (!__hooks) {
1797
1814
  return;
1798
1815
  }
1816
+ if (Array.isArray(__hooks[hookName])) {
1817
+ var hooks = __hooks[hookName];
1818
+ var index = findHookIndex.call(this, hookName, handler);
1819
+ if (index !== -1) {
1820
+ hooks.splice(index, 1);
1821
+ }
1822
+ }
1799
1823
  delete __hooks[hookName];
1800
1824
  }
1801
1825
  function hooksDescriptor(instance) {
@@ -1817,6 +1841,38 @@
1817
1841
  function delHooksDescriptor(instance) {
1818
1842
  instance.__hooks = null;
1819
1843
  }
1844
+ function runHooks(obj, hookName, handler) {
1845
+ for (var _len5 = arguments.length, args = new Array(_len5 > 3 ? _len5 - 3 : 0), _key5 = 3; _key5 < _len5; _key5++) {
1846
+ args[_key5 - 3] = arguments[_key5];
1847
+ }
1848
+ if (obj.__hooks && Array.isArray(obj.__hooks[hookName])) {
1849
+ var hooks = obj.__hooks[hookName];
1850
+ var index = -1;
1851
+ var runHooksRecursive = function runHooksRecursive2(obj2, hookName2, handler2) {
1852
+ for (var _len6 = arguments.length, args2 = new Array(_len6 > 3 ? _len6 - 3 : 0), _key6 = 3; _key6 < _len6; _key6++) {
1853
+ args2[_key6 - 3] = arguments[_key6];
1854
+ }
1855
+ index++;
1856
+ if (hooks.length === 0 || index === hooks.length) {
1857
+ return handler2.call.apply(handler2, [obj2, obj2].concat(args2));
1858
+ }
1859
+ var hook2 = hooks[index];
1860
+ var ret = hook2.call.apply(hook2, [obj2, obj2].concat(args2));
1861
+ if (ret && ret.then) {
1862
+ return ret.then(function(data) {
1863
+ return data === false ? null : runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1864
+ }).catch(function(e) {
1865
+ console.warn("[runHooks]".concat(hookName2, " reject"), e.message);
1866
+ });
1867
+ } else if (ret !== false) {
1868
+ return runHooksRecursive2.apply(void 0, [obj2, hookName2, handler2].concat(args2));
1869
+ }
1870
+ };
1871
+ return runHooksRecursive.apply(void 0, [obj, hookName, handler].concat(args));
1872
+ } else {
1873
+ return handler.call.apply(handler, [obj, obj].concat(args));
1874
+ }
1875
+ }
1820
1876
  function showErrorMsg(pluginName, msg) {
1821
1877
  XG_DEBUG.logError("[".concat(pluginName, "] event or callback cant be undefined or null when call ").concat(msg));
1822
1878
  }
@@ -2866,6 +2922,21 @@
2866
2922
  length: Buffer2.totalLength && Buffer2.totalLength(buffers)
2867
2923
  };
2868
2924
  }
2925
+ }, {
2926
+ key: "isBuffered",
2927
+ value: function isBuffered(media, pos) {
2928
+ if (media) {
2929
+ var buffered = Buffer2.get(media);
2930
+ if (buffered !== null && buffered !== void 0 && buffered.length) {
2931
+ for (var i = 0; i < buffered.length; i++) {
2932
+ if (pos >= buffered.start(i) && pos <= buffered.end(i)) {
2933
+ return true;
2934
+ }
2935
+ }
2936
+ }
2937
+ }
2938
+ return false;
2939
+ }
2869
2940
  }]);
2870
2941
  return Buffer2;
2871
2942
  }();
@@ -5986,7 +6057,7 @@
5986
6057
  continue;
5987
6058
  }
5988
6059
  frameLength = (data[i + 3] & 3) << 11 | data[i + 4] << 3 | (data[i + 5] & 224) >> 5;
5989
- if (len - i < frameLength)
6060
+ if (!frameLength || len - i < frameLength)
5990
6061
  break;
5991
6062
  protectionSkipBytes = (~data[i + 1] & 1) * 2;
5992
6063
  frames.push({
@@ -6180,6 +6251,15 @@
6180
6251
  return parseInt(item, 16);
6181
6252
  });
6182
6253
  }
6254
+ function combineToFloat(integer, decimal) {
6255
+ return Number(integer + "." + decimal);
6256
+ }
6257
+ function toDegree(matrix) {
6258
+ if (matrix.length < 5)
6259
+ return 0;
6260
+ var scaled0 = Math.hypot(matrix[0], matrix[3]), scaled1 = Math.hypot(matrix[1], matrix[4]);
6261
+ return 0 === scaled0 || 0 === scaled1 ? 0 : 180 * Math.atan2(matrix[1] / scaled1, matrix[0] / scaled0) / Math.PI;
6262
+ }
6183
6263
  var NALu = /* @__PURE__ */ function() {
6184
6264
  function NALu2() {
6185
6265
  _classCallCheck(this, NALu2);
@@ -6842,13 +6922,16 @@
6842
6922
  var AUDIO_EXCETION_LOG_EMIT_DURATION = 5 * 9e4;
6843
6923
  var MAX_VIDEO_FRAME_DURATION = 9e4;
6844
6924
  var MAX_DTS_DELTA_WITH_NEXT_CHUNK = 9e4 / 2;
6925
+ var LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD = 9e4 * 5;
6845
6926
  var TsFixer = /* @__PURE__ */ function() {
6846
- function TsFixer2(videoTrack, audioTrack, metadataTrack) {
6927
+ function TsFixer2(videoTrack, audioTrack, metadataTrack, fixerConfig) {
6847
6928
  _classCallCheck(this, TsFixer2);
6848
6929
  this.videoTrack = videoTrack;
6849
6930
  this.audioTrack = audioTrack;
6850
6931
  this.metadataTrack = metadataTrack;
6851
6932
  this._baseDts = -1;
6933
+ this._baseVideoDts = -1;
6934
+ this._baseAudioDts = -1;
6852
6935
  this._baseDtsInited = false;
6853
6936
  this._audioNextPts = void 0;
6854
6937
  this._videoNextDts = void 0;
@@ -6857,6 +6940,8 @@
6857
6940
  this._lastAudioExceptionGapDot = 0;
6858
6941
  this._lastAudioExceptionOverlapDot = 0;
6859
6942
  this._lastAudioExceptionLargeGapDot = 0;
6943
+ this._needForceFixLargeGap = fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.forceFixLargeGap;
6944
+ this._largeGapThreshold = (fixerConfig === null || fixerConfig === void 0 ? void 0 : fixerConfig.largeGapThreshold) || LARGE_AV_FIRST_FRAME_FORCE_FIX_THRESHOLD;
6860
6945
  }
6861
6946
  _createClass(TsFixer2, [{
6862
6947
  key: "fix",
@@ -6884,10 +6969,16 @@
6884
6969
  if (discontinuity) {
6885
6970
  this._calculateBaseDts(this.audioTrack, this.videoTrack);
6886
6971
  this._baseDts -= startTime;
6972
+ this._baseAudioDts -= startTime;
6973
+ this._baseVideoDts -= startTime;
6887
6974
  }
6888
6975
  if (!contiguous) {
6889
6976
  this._videoNextDts = vaDelta > 0 ? startTime + vaDelta : startTime;
6890
6977
  this._audioNextPts = vaDelta > 0 ? startTime : startTime - vaDelta;
6978
+ if (this._needForceFixLargeGap) {
6979
+ this._videoNextDts = 0;
6980
+ this._audioNextPts = 0;
6981
+ }
6891
6982
  var vDeltaToNextDts = firstVideoSample ? firstVideoSample.dts - this._baseDts - this._videoNextDts : 0;
6892
6983
  var aDeltaToNextDts = firstAudioSample ? firstAudioSample.pts - this._baseDts - this._audioNextPts : 0;
6893
6984
  if (Math.abs(vDeltaToNextDts || aDeltaToNextDts) > MAX_VIDEO_FRAME_DURATION) {
@@ -6920,8 +7011,8 @@
6920
7011
  if (!samples.length)
6921
7012
  return;
6922
7013
  samples.forEach(function(x) {
6923
- x.dts -= _this2._baseDts;
6924
- x.pts -= _this2._baseDts;
7014
+ x.dts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
7015
+ x.pts -= _this2._needForceFixLargeGap ? _this2._baseVideoDts : _this2._baseDts;
6925
7016
  });
6926
7017
  if (this._videoNextDts === void 0) {
6927
7018
  var samp0 = samples[0];
@@ -7014,7 +7105,7 @@
7014
7105
  if (!samples.length)
7015
7106
  return;
7016
7107
  samples.forEach(function(x) {
7017
- x.pts -= _this3._baseDts;
7108
+ x.pts -= _this3._needForceFixLargeGap ? _this3._baseAudioDts : _this3._baseDts;
7018
7109
  x.dts = x.pts;
7019
7110
  });
7020
7111
  this._doFixAudioInternal(audioTrack, samples, 9e4);
@@ -7031,12 +7122,15 @@
7031
7122
  var videoBaseDts = Infinity;
7032
7123
  if (audioSamps.length) {
7033
7124
  audioTrack.baseDts = audioBasePts = audioSamps[0].pts;
7125
+ this._baseAudioDts = audioBasePts;
7034
7126
  }
7035
7127
  if (videoSamps.length) {
7036
7128
  videoTrack.baseDts = videoBaseDts = videoSamps[0].dts;
7129
+ this._baseVideoDts = videoBaseDts;
7037
7130
  }
7038
7131
  this._baseDts = Math.min(audioBasePts, videoBaseDts);
7039
7132
  var delta = videoBaseDts - audioBasePts;
7133
+ var largeGap = false;
7040
7134
  if (Number.isFinite(delta) && Math.abs(delta) > LARGE_AV_FIRST_FRAME_GAP) {
7041
7135
  videoTrack.warnings.push({
7042
7136
  type: WarningType.LARGE_AV_SHIFT,
@@ -7046,6 +7140,16 @@
7046
7140
  delta
7047
7141
  });
7048
7142
  }
7143
+ if (Number.isFinite(delta) && Math.abs(delta) > this._largeGapThreshold * MAX_SILENT_FRAME_DURATION) {
7144
+ largeGap = true;
7145
+ }
7146
+ if (!this._baseDtsInited) {
7147
+ if (largeGap && this._needForceFixLargeGap) {
7148
+ this._needForceFixLargeGap = true;
7149
+ } else {
7150
+ this._needForceFixLargeGap = false;
7151
+ }
7152
+ }
7049
7153
  this._baseDtsInited = true;
7050
7154
  return true;
7051
7155
  }
@@ -7139,6 +7243,7 @@
7139
7243
  var logger$4 = new Logger$1("TsDemuxer");
7140
7244
  var TsDemuxer = /* @__PURE__ */ function() {
7141
7245
  function TsDemuxer2(videoTrack, audioTrack, metadataTrack) {
7246
+ var fixerConfig = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
7142
7247
  _classCallCheck(this, TsDemuxer2);
7143
7248
  _defineProperty(this, "_pmtId", -1);
7144
7249
  _defineProperty(this, "_remainingPacketData", null);
@@ -7148,7 +7253,7 @@
7148
7253
  this.videoTrack = videoTrack || new VideoTrack();
7149
7254
  this.audioTrack = audioTrack || new AudioTrack();
7150
7255
  this.metadataTrack = metadataTrack || new MetadataTrack();
7151
- this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack);
7256
+ this._fixer = new TsFixer(this.videoTrack, this.audioTrack, this.metadataTrack, fixerConfig);
7152
7257
  }
7153
7258
  _createClass(TsDemuxer2, [{
7154
7259
  key: "demux",
@@ -7495,6 +7600,166 @@
7495
7600
  }]);
7496
7601
  return TsDemuxer2;
7497
7602
  }();
7603
+ var ByteReader = /* @__PURE__ */ function() {
7604
+ function ByteReader2(buf, offset, len) {
7605
+ _classCallCheck(this, ByteReader2);
7606
+ this.dv = new DataView(buf);
7607
+ this.start = this.offset = offset || this.dv.byteOffset;
7608
+ this.end = len ? this.start + len : this.dv.byteLength;
7609
+ }
7610
+ _createClass(ByteReader2, [{
7611
+ key: "buffer",
7612
+ get: function get() {
7613
+ return this.dv.buffer;
7614
+ }
7615
+ }, {
7616
+ key: "unreadLength",
7617
+ get: function get() {
7618
+ return Math.max(this.end - this.offset, 0);
7619
+ }
7620
+ }, {
7621
+ key: "size",
7622
+ get: function get() {
7623
+ return this.end - this.start;
7624
+ }
7625
+ }, {
7626
+ key: "readFloat",
7627
+ value: function readFloat(byteNum) {
7628
+ var val = 0;
7629
+ switch (byteNum) {
7630
+ case 4:
7631
+ val = this.dv.getFloat32(this.offset);
7632
+ break;
7633
+ case 8:
7634
+ val = this.dv.getFloat64(this.offset);
7635
+ break;
7636
+ default:
7637
+ throw new Error("read ".concat(byteNum, "-byte float is not supported"));
7638
+ }
7639
+ this.offset += byteNum;
7640
+ return val;
7641
+ }
7642
+ }, {
7643
+ key: "back",
7644
+ value: function back(byteNum) {
7645
+ this.offset -= byteNum;
7646
+ }
7647
+ }, {
7648
+ key: "skip",
7649
+ value: function skip(byteNum) {
7650
+ this.offset += byteNum;
7651
+ }
7652
+ }, {
7653
+ key: "readInt",
7654
+ value: function readInt(byteNum) {
7655
+ var offset = this.offset;
7656
+ this.offset += byteNum;
7657
+ switch (byteNum) {
7658
+ case 1:
7659
+ return this.dv.getInt8(offset);
7660
+ case 2:
7661
+ return this.dv.getInt16(offset);
7662
+ case 4:
7663
+ return this.dv.getInt32(offset);
7664
+ default:
7665
+ throw new Error("read ".concat(byteNum, "-byte integers is not supported"));
7666
+ }
7667
+ }
7668
+ }, {
7669
+ key: "read",
7670
+ value: function read(byteNum) {
7671
+ var offset = this.offset;
7672
+ this.offset += byteNum;
7673
+ switch (byteNum) {
7674
+ case 1:
7675
+ return this.dv.getUint8(offset);
7676
+ case 2:
7677
+ return this.dv.getUint16(offset);
7678
+ case 3:
7679
+ return (this.dv.getUint16(offset) << 8) + this.dv.getUint8(offset + 2);
7680
+ case 4:
7681
+ return this.dv.getUint32(offset);
7682
+ default:
7683
+ this.back(byteNum - 4);
7684
+ return this.read(byteNum - 4) + this.dv.getUint32(offset) * Math.pow(256, byteNum - 4);
7685
+ }
7686
+ }
7687
+ }, {
7688
+ key: "write",
7689
+ value: function write(byteNum, val) {
7690
+ var offset = this.offset;
7691
+ this.offset += byteNum;
7692
+ switch (byteNum) {
7693
+ case 1:
7694
+ return this.dv.setUint8(offset, val);
7695
+ case 2:
7696
+ return this.dv.setUint16(offset, val);
7697
+ case 3:
7698
+ return this.dv.setUint8(offset, val >>> 16), this.dv.setUint16(offset + 1, 65535 & val);
7699
+ case 4:
7700
+ return this.dv.setUint32(offset, val);
7701
+ default:
7702
+ throw new Error("write ".concat(byteNum, "-byte integers is not supported"));
7703
+ }
7704
+ }
7705
+ }, {
7706
+ key: "readToBuffer",
7707
+ value: function readToBuffer(len) {
7708
+ var buffer;
7709
+ if (this.offset || len) {
7710
+ buffer = this.dv.buffer.slice(this.offset, len ? this.offset + len : void 0);
7711
+ } else {
7712
+ buffer = this.dv.buffer;
7713
+ }
7714
+ this.offset += buffer.byteLength;
7715
+ return buffer;
7716
+ }
7717
+ }, {
7718
+ key: "readToUint8",
7719
+ value: function readToUint8(len) {
7720
+ var uint8 = new Uint8Array(this.dv.buffer, this.offset, len || this.unreadLength);
7721
+ this.offset += uint8.byteLength;
7722
+ return uint8;
7723
+ }
7724
+ }, {
7725
+ key: "readString",
7726
+ value: function readString(len) {
7727
+ var i = 0, str = "";
7728
+ for (; i < len; i++) {
7729
+ str += String.fromCharCode(this.dv.getUint8(this.offset));
7730
+ this.offset++;
7731
+ }
7732
+ return str;
7733
+ }
7734
+ }], [{
7735
+ key: "fromUint8",
7736
+ value: function fromUint8(uint8) {
7737
+ return new ByteReader2(uint8.buffer, uint8.byteOffset, uint8.byteLength);
7738
+ }
7739
+ }, {
7740
+ key: "concatUint8s",
7741
+ value: function concatUint8s(args) {
7742
+ var uint8 = new Uint8Array(args.reduce(function(ret, v) {
7743
+ return ret + v.byteLength;
7744
+ }, 0));
7745
+ var offset = 0;
7746
+ args.forEach(function(v) {
7747
+ uint8.set(v, offset);
7748
+ offset += v.byteLength;
7749
+ });
7750
+ return uint8;
7751
+ }
7752
+ }, {
7753
+ key: "concatUint8",
7754
+ value: function concatUint8() {
7755
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
7756
+ args[_key] = arguments[_key];
7757
+ }
7758
+ return this.concatUint8s(args);
7759
+ }
7760
+ }]);
7761
+ return ByteReader2;
7762
+ }();
7498
7763
  var MP4Parser = /* @__PURE__ */ function() {
7499
7764
  function MP4Parser2() {
7500
7765
  _classCallCheck(this, MP4Parser2);
@@ -7652,18 +7917,36 @@
7652
7917
  key: "tkhd",
7653
7918
  value: function tkhd(box) {
7654
7919
  return parseBox(box, true, function(ret, data) {
7655
- var start = 0;
7920
+ var byte = ByteReader.fromUint8(data);
7656
7921
  if (ret.version === 1) {
7657
- ret.trackId = readBig32(data, 16);
7658
- ret.duration = readBig64(data, 24);
7659
- start += 32;
7922
+ byte.read(8);
7923
+ byte.read(8);
7924
+ ret.trackId = byte.read(4);
7925
+ byte.read(4);
7926
+ ret.duration = byte.read(8);
7660
7927
  } else {
7661
- ret.trackId = readBig32(data, 8);
7662
- ret.duration = readBig32(data, 16);
7663
- start += 20;
7928
+ byte.read(4);
7929
+ byte.read(4);
7930
+ ret.trackId = byte.read(4);
7931
+ byte.read(4);
7932
+ ret.duration = byte.read(4);
7933
+ }
7934
+ byte.skip(16);
7935
+ ret.matrix = [];
7936
+ for (var i = 0; i < 36; i++) {
7937
+ ret.matrix.push(byte.read(1));
7938
+ }
7939
+ byte.back(36);
7940
+ var caculatedMatrix = [];
7941
+ for (var _i = 0, int32; _i < 3; _i++) {
7942
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
7943
+ caculatedMatrix.push(combineToFloat(byte.readInt(2), byte.readInt(2)));
7944
+ int32 = byte.readInt(4);
7945
+ caculatedMatrix.push(combineToFloat(int32 >> 30, int32 & 1073741823));
7664
7946
  }
7665
- ret.width = readBig32(data, start + 52);
7666
- ret.height = readBig32(data, start + 56);
7947
+ ret.rotation = toDegree(caculatedMatrix);
7948
+ ret.width = byte.read(4);
7949
+ ret.height = byte.read(4);
7667
7950
  });
7668
7951
  }
7669
7952
  }, {
@@ -7793,7 +8076,7 @@
7793
8076
  if (ret.version > 0) {
7794
8077
  var numKeyIds = readBig32(data, start);
7795
8078
  start += 4;
7796
- for (var _i = 0; _i < ("" + numKeyIds).length; _i++) {
8079
+ for (var _i2 = 0; _i2 < ("" + numKeyIds).length; _i2++) {
7797
8080
  for (var j = 0; j < 16; j++) {
7798
8081
  var keyId = data[start];
7799
8082
  start += 1;
@@ -7929,7 +8212,7 @@
7929
8212
  ret.ppsLength = data[start];
7930
8213
  start += 1;
7931
8214
  ret.pps = [];
7932
- for (var _i2 = 0; _i2 < ret.ppsLength; _i2++) {
8215
+ for (var _i3 = 0; _i3 < ret.ppsLength; _i3++) {
7933
8216
  var _size = readBig16(data, start);
7934
8217
  start += 2;
7935
8218
  ret.pps.push(data.subarray(start, start += _size));
@@ -8098,7 +8381,7 @@
8098
8381
  start += 8;
8099
8382
  }
8100
8383
  } else {
8101
- for (var _i3 = 0; _i3 < entryCount; _i3++) {
8384
+ for (var _i4 = 0; _i4 < entryCount; _i4++) {
8102
8385
  entries.push({
8103
8386
  count: readBig32(data, start),
8104
8387
  offset: -(~readBig32(data, start + 4) + 1)
@@ -8320,6 +8603,8 @@
8320
8603
  v.mvhdTimecale = moov.mvhd.timescale;
8321
8604
  v.timescale = v.formatTimescale = vTrack.mdia.mdhd.timescale;
8322
8605
  v.duration = vTrack.mdia.mdhd.duration || v.mvhdDurtion / v.mvhdTimecale * v.timescale;
8606
+ v.rotation = vTrack.tkhd.rotation;
8607
+ v.matrix = vTrack.tkhd.matrix;
8323
8608
  var e1 = vTrack.mdia.minf.stbl.stsd.entries[0];
8324
8609
  v.width = e1.width;
8325
8610
  v.height = e1.height;
@@ -10886,11 +11171,11 @@
10886
11171
  });
10887
11172
  var logger$3 = new Logger$2("Transmuxer");
10888
11173
  var Transmuxer = /* @__PURE__ */ function() {
10889
- function Transmuxer2(hls, isMP4, needRemux) {
11174
+ function Transmuxer2(hls, isMP4, needRemux, fixerConfig) {
10890
11175
  _classCallCheck$3(this, Transmuxer2);
10891
11176
  _defineProperty$3(this, "_initSegmentId", "");
10892
11177
  this.hls = hls;
10893
- this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer();
11178
+ this._demuxer = isMP4 ? new FMP4Demuxer() : new TsDemuxer(null, null, null, fixerConfig);
10894
11179
  this._isMP4 = isMP4;
10895
11180
  if (needRemux)
10896
11181
  this._remuxer = new FMP4Remuxer(this._demuxer.videoTrack, this._demuxer.audioTrack);
@@ -11157,11 +11442,11 @@
11157
11442
  return;
11158
11443
  if (TsDemuxer.probe(chunk)) {
11159
11444
  if (!this._transmuxer)
11160
- this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo);
11445
+ this._transmuxer = new Transmuxer(this.hls, false, !this._softVideo, this.hls.config.fixerConfig);
11161
11446
  } else if (MP4Parser.probe(chunk)) {
11162
11447
  if (this._softVideo) {
11163
11448
  if (!this._transmuxer)
11164
- this._transmuxer = new Transmuxer(this.hls, true);
11449
+ this._transmuxer = new Transmuxer(this.hls, true, null, this.hls.config.fixerConfig);
11165
11450
  } else {
11166
11451
  this._directAppend = true;
11167
11452
  var mix = false;
@@ -11604,7 +11889,11 @@
11604
11889
  minSegmentsStartPlay: 3,
11605
11890
  preferMMS: false,
11606
11891
  preferMMSStreaming: false,
11607
- mseLowLatency: true
11892
+ mseLowLatency: true,
11893
+ fixerConfig: {
11894
+ forceFixLargeGap: false,
11895
+ largeGapThreshold: 5
11896
+ }
11608
11897
  }, cfg), {}, {
11609
11898
  media
11610
11899
  });
@@ -11719,6 +12008,8 @@
11719
12008
  _defineProperty$3(this, "lowLatency", false);
11720
12009
  _defineProperty$3(this, "endPartIndex", 0);
11721
12010
  _defineProperty$3(this, "segments", []);
12011
+ _defineProperty$3(this, "dateRanges", {});
12012
+ _defineProperty$3(this, "skippedSegments", 0);
11722
12013
  });
11723
12014
  var MediaSegment = /* @__PURE__ */ function() {
11724
12015
  function MediaSegment2(parentUrl) {
@@ -11890,6 +12181,38 @@
11890
12181
  }
11891
12182
  }
11892
12183
  }
12184
+ function isValidDaterange(attr, dateRangeWithSameId) {
12185
+ var _badValueForSameId;
12186
+ if (dateRangeWithSameId) {
12187
+ for (var key in dateRangeWithSameId) {
12188
+ if (Object.prototype.hasOwnProperty.call(dateRangeWithSameId, key) && attr[key] !== dateRangeWithSameId[key]) {
12189
+ _badValueForSameId = key;
12190
+ break;
12191
+ }
12192
+ }
12193
+ }
12194
+ var duration = null;
12195
+ if (attr.DURATION) {
12196
+ duration = parseFloat(attr.DURATION);
12197
+ if (!Number.isFinite(duration)) {
12198
+ duration = null;
12199
+ } else if (attr._endDate) {
12200
+ duration = (attr._endDate.getTime() - attr._startDate.getTime()) / 1e3;
12201
+ }
12202
+ }
12203
+ var cue = enumeratedStringList(attr.CUE || attr["X-CUE"], {
12204
+ pre: false,
12205
+ post: false,
12206
+ once: false
12207
+ });
12208
+ return !!attr.ID && !_badValueForSameId && Number.isFinite(attr._startDate.getTime()) && (duration === null || duration >= 0) && (!(attr.END_ON_NEXT === "YES") || !!attr.CLASS) && (!attr.CUE || !cue.pre && !cue.post || cue.pre !== cue.post) && (!(attr.CLASS === "com.apple.hls.interstitial") || "X-ASSET-URI" in attr || "X-ASSET-LIST" in attr);
12209
+ }
12210
+ function enumeratedStringList(attrValue, dict) {
12211
+ return (attrValue ? attrValue.split(/[ ,]+/) : []).reduce(function(result, identifier) {
12212
+ result[identifier.toLowerCase()] = true;
12213
+ return result;
12214
+ }, dict);
12215
+ }
11893
12216
  function parseMasterPlaylist(lines, parentUrl) {
11894
12217
  var master = new MasterPlaylist();
11895
12218
  var index = 0;
@@ -11998,9 +12321,6 @@
11998
12321
  var endOfList = false;
11999
12322
  var partSegmentIndex = 0;
12000
12323
  while (line = lines[index++]) {
12001
- if (endOfList) {
12002
- break;
12003
- }
12004
12324
  if (line[0] !== "#") {
12005
12325
  if (media.lowLatency) {
12006
12326
  curSN++;
@@ -12054,11 +12374,6 @@
12054
12374
  break;
12055
12375
  case "ENDLIST":
12056
12376
  {
12057
- var _lastSegment = media.segments[media.segments.length - 1];
12058
- if (_lastSegment) {
12059
- _lastSegment.isLast = true;
12060
- }
12061
- media.live = false;
12062
12377
  endOfList = true;
12063
12378
  }
12064
12379
  break;
@@ -12155,6 +12470,29 @@
12155
12470
  curSegment = new MediaSegment(parentUrl);
12156
12471
  }
12157
12472
  break;
12473
+ case "SKIP":
12474
+ {
12475
+ var _attr5 = parseAttr(data);
12476
+ var skippedSegments = parseInt(_attr5["SKIPPED-SEGMENTS"], 10);
12477
+ if (skippedSegments <= Number.MAX_SAFE_INTEGER) {
12478
+ media.skippedSegments += skippedSegments;
12479
+ }
12480
+ }
12481
+ break;
12482
+ case "DATERANGE":
12483
+ {
12484
+ var _attr6 = parseAttr(data);
12485
+ var dateRangeWithSameId = media.dateRanges[_attr6.ID];
12486
+ _attr6._startDate = dateRangeWithSameId ? dateRangeWithSameId._startDate : new Date(_attr6["START-DATE"]);
12487
+ var endDate = (dateRangeWithSameId === null || dateRangeWithSameId === void 0 ? void 0 : dateRangeWithSameId._endDate) || new Date(_attr6.END_DATE);
12488
+ if (Number.isFinite(endDate)) {
12489
+ _attr6._endDate = endDate;
12490
+ }
12491
+ if (isValidDaterange(_attr6, dateRangeWithSameId) || media.skippedSegments) {
12492
+ media.dateRanges[_attr6.ID] = _attr6;
12493
+ }
12494
+ }
12495
+ break;
12158
12496
  }
12159
12497
  }
12160
12498
  media.segments = media.segments.filter(function(x) {
@@ -12162,11 +12500,14 @@
12162
12500
  });
12163
12501
  var lastSegment = media.segments[media.segments.length - 1];
12164
12502
  if (lastSegment) {
12165
- media.endSN = lastSegment.sn;
12166
- media.endPartIndex = lastSegment.partIndex;
12167
- if (endOfList && !lastSegment.isLast) {
12503
+ if (endOfList) {
12168
12504
  lastSegment.isLast = true;
12169
12505
  }
12506
+ media.endSN = lastSegment.sn;
12507
+ media.endPartIndex = lastSegment.partIndex;
12508
+ }
12509
+ if (endOfList) {
12510
+ media.live = false;
12170
12511
  }
12171
12512
  media.totalDuration = totalDuration;
12172
12513
  media.endCC = curCC;
@@ -13263,7 +13604,7 @@
13263
13604
  _defineProperty$3(_assertThisInitialized$2(_this), "_switchUrlOpts", null);
13264
13605
  _defineProperty$3(_assertThisInitialized$2(_this), "_isProcessQuotaExceeded", false);
13265
13606
  _defineProperty$3(_assertThisInitialized$2(_this), "_loadSegment", /* @__PURE__ */ _asyncToGenerator$1(/* @__PURE__ */ _regeneratorRuntime$1().mark(function _callee() {
13266
- var nextSeg, _assertThisInitialize, config, bInfo, bufferThroughout;
13607
+ var _this$_playlist, nextSegment, lastSegment, _assertThisInitialize, config, minFrameDuration, maxBufferThroughout, bInfo, bufferThroughout;
13267
13608
  return _regeneratorRuntime$1().wrap(function _callee$(_context) {
13268
13609
  while (1)
13269
13610
  switch (_context.prev = _context.next) {
@@ -13274,42 +13615,44 @@
13274
13615
  }
13275
13616
  return _context.abrupt("return");
13276
13617
  case 2:
13277
- nextSeg = _this._playlist.nextSegment;
13618
+ _this$_playlist = _this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
13278
13619
  _assertThisInitialize = _assertThisInitialized$2(_this), config = _assertThisInitialize.config;
13279
- if (nextSeg) {
13280
- _context.next = 6;
13620
+ minFrameDuration = 0.016;
13621
+ maxBufferThroughout = Math.min(Math.max((lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.duration) - minFrameDuration / 2 || 0, minFrameDuration), 0.1);
13622
+ if (nextSegment) {
13623
+ _context.next = 8;
13281
13624
  break;
13282
13625
  }
13283
13626
  return _context.abrupt("return");
13284
- case 6:
13627
+ case 8:
13285
13628
  if (_this.isLive) {
13286
- _context.next = 16;
13629
+ _context.next = 18;
13287
13630
  break;
13288
13631
  }
13289
13632
  bInfo = _this.bufferInfo();
13290
13633
  if (_this.media.paused && !_this.media.currentTime) {
13291
13634
  bInfo = _this.bufferInfo(bInfo.nextStart || 0.5);
13292
13635
  }
13293
- bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < 0.1;
13636
+ bufferThroughout = Math.abs(bInfo.end - _this.media.duration) < maxBufferThroughout;
13294
13637
  if (!(bInfo.remaining >= config.preloadTime || bufferThroughout)) {
13295
- _context.next = 13;
13638
+ _context.next = 15;
13296
13639
  break;
13297
13640
  }
13298
13641
  _this._tryEos();
13299
13642
  return _context.abrupt("return");
13300
- case 13:
13643
+ case 15:
13301
13644
  if (!(config.preferMMSStreaming && !_this._bufferService.msStreaming)) {
13302
- _context.next = 15;
13645
+ _context.next = 17;
13303
13646
  break;
13304
13647
  }
13305
13648
  return _context.abrupt("return");
13306
- case 15:
13307
- if (!_this._urlSwitching && _this._prevSegSn !== nextSeg.sn - 1 && bInfo.end && Math.abs(nextSeg.start - bInfo.end) > 1) {
13649
+ case 17:
13650
+ if (!_this._urlSwitching && _this._prevSegSn !== nextSegment.sn - 1 && bInfo.end && Math.abs(nextSegment.start - bInfo.end) > 1) {
13308
13651
  _this._playlist.setNextSegmentByIndex(_this._playlist.findSegmentIndexByTime(bInfo.end + 0.1));
13309
13652
  }
13310
- case 16:
13653
+ case 18:
13311
13654
  return _context.abrupt("return", _this._loadSegmentDirect());
13312
- case 17:
13655
+ case 19:
13313
13656
  case "end":
13314
13657
  return _context.stop();
13315
13658
  }
@@ -14562,8 +14905,8 @@
14562
14905
  value: function _tryEos() {
14563
14906
  var _this$_bufferService3, _this$_bufferService4;
14564
14907
  var media = this.media;
14565
- var _this$_playlist = this._playlist, nextSegment = _this$_playlist.nextSegment, lastSegment = _this$_playlist.lastSegment;
14566
- var eosAllowed = !nextSegment && media.readyState && media.duration > 0 && ((_this$_bufferService3 = this._bufferService) === null || _this$_bufferService3 === void 0 ? void 0 : _this$_bufferService3.msIsOpened) && !((_this$_bufferService4 = this._bufferService) !== null && _this$_bufferService4 !== void 0 && _this$_bufferService4.msHasOpTasks);
14908
+ var _this$_playlist2 = this._playlist, nextSegment = _this$_playlist2.nextSegment, lastSegment = _this$_playlist2.lastSegment;
14909
+ var eosAllowed = (!nextSegment || lastSegment && Buffer$1.isBuffered(media, lastSegment.start + lastSegment.duration / 2)) && media.readyState && media.duration > 0 && ((_this$_bufferService3 = this._bufferService) === null || _this$_bufferService3 === void 0 ? void 0 : _this$_bufferService3.msIsOpened) && !((_this$_bufferService4 = this._bufferService) !== null && _this$_bufferService4 !== void 0 && _this$_bufferService4.msHasOpTasks);
14567
14910
  if (!eosAllowed) {
14568
14911
  return;
14569
14912
  }
@@ -14599,7 +14942,7 @@
14599
14942
  }]);
14600
14943
  return Hls2;
14601
14944
  }(EventEmitter);
14602
- _defineProperty$3(Hls, "version", "3.0.19-rc.0");
14945
+ _defineProperty$3(Hls, "version", "3.0.20-alpha.2");
14603
14946
  try {
14604
14947
  if (localStorage.getItem("xgd")) {
14605
14948
  Hls.enableLogger();