jmuxer 2.1.2 → 2.1.4
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/dist/jmuxer.js +64 -27
- package/dist/jmuxer.min.js +1 -1
- package/package.json +3 -4
- package/src/remuxer/h264.js +16 -11
- package/src/remuxer/h265.js +20 -15
- package/src/util/mp4-generator.js +5 -3
- package/src/util/utils.js +8 -0
- package/.idea/codeStyles/Project.xml +0 -13
- package/.idea/codeStyles/codeStyleConfig.xml +0 -5
- package/.idea/copilot.data.migration.agent.xml +0 -6
- package/.idea/inspectionProfiles/Project_Default.xml +0 -6
- package/.idea/jmuxer.iml +0 -9
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- /package/{rollup.config.js → rollup.config.mjs} +0 -0
package/dist/jmuxer.js
CHANGED
|
@@ -723,13 +723,15 @@
|
|
|
723
723
|
0x03,
|
|
724
724
|
// numOfArrays
|
|
725
725
|
|
|
726
|
+
// A stream may carry more than one PPS, so each array declares its real
|
|
727
|
+
// count: an under-reported numNalus leaves the extra sets unreadable.
|
|
726
728
|
0x20,
|
|
727
729
|
// array_completeness + NAL_unit_type (32 = VPS)
|
|
728
|
-
|
|
730
|
+
track.vps.length >>> 8 & 0xFF, track.vps.length & 0xFF], _toConsumableArray(vps), [0x21,
|
|
729
731
|
// NAL_unit_type (33 = SPS)
|
|
730
|
-
|
|
732
|
+
track.sps.length >>> 8 & 0xFF, track.sps.length & 0xFF], _toConsumableArray(sps), [0x22,
|
|
731
733
|
// NAL_unit_type (34 = PPS)
|
|
732
|
-
|
|
734
|
+
track.pps.length >>> 8 & 0xFF, track.pps.length & 0xFF], _toConsumableArray(pps))));
|
|
733
735
|
var width = track.width;
|
|
734
736
|
var height = track.height;
|
|
735
737
|
return MP4.box(MP4.types.hev1, new Uint8Array([0x00, 0x00, 0x00,
|
|
@@ -1823,6 +1825,13 @@
|
|
|
1823
1825
|
// Use regex to strip all trailing ".0" sequences
|
|
1824
1826
|
return input.replace(/(?:\.0)+$/, '');
|
|
1825
1827
|
}
|
|
1828
|
+
function sameBytes(a, b) {
|
|
1829
|
+
if (a.length !== b.length) return false;
|
|
1830
|
+
for (var i = 0; i < a.length; i++) {
|
|
1831
|
+
if (a[i] !== b[i]) return false;
|
|
1832
|
+
}
|
|
1833
|
+
return true;
|
|
1834
|
+
}
|
|
1826
1835
|
|
|
1827
1836
|
var H264Remuxer = /*#__PURE__*/function (_BaseRemuxer) {
|
|
1828
1837
|
function H264Remuxer(timescale, duration, frameDuration) {
|
|
@@ -1838,8 +1847,8 @@
|
|
|
1838
1847
|
type: 'video',
|
|
1839
1848
|
len: 0,
|
|
1840
1849
|
fragmented: true,
|
|
1841
|
-
sps:
|
|
1842
|
-
pps:
|
|
1850
|
+
sps: [],
|
|
1851
|
+
pps: [],
|
|
1843
1852
|
fps: 30,
|
|
1844
1853
|
width: 0,
|
|
1845
1854
|
height: 0,
|
|
@@ -1858,8 +1867,8 @@
|
|
|
1858
1867
|
key: "resetTrack",
|
|
1859
1868
|
value: function resetTrack() {
|
|
1860
1869
|
this.readyToDecode = false;
|
|
1861
|
-
this.mp4track.sps =
|
|
1862
|
-
this.mp4track.pps =
|
|
1870
|
+
this.mp4track.sps = [];
|
|
1871
|
+
this.mp4track.pps = [];
|
|
1863
1872
|
this.nextDts = 0;
|
|
1864
1873
|
this.dts = 0;
|
|
1865
1874
|
this.remainingData = new Uint8Array();
|
|
@@ -2079,7 +2088,23 @@
|
|
|
2079
2088
|
}, {
|
|
2080
2089
|
key: "parsePPS",
|
|
2081
2090
|
value: function parsePPS(pps) {
|
|
2082
|
-
|
|
2091
|
+
// A stream may define more than one PPS (e.g. the encoder uses different
|
|
2092
|
+
// entropy-coding modes for I- vs P-slices, thus referencing different
|
|
2093
|
+
// pps_ids). Keep every distinct PPS so any slice can find the one it
|
|
2094
|
+
// references.
|
|
2095
|
+
var _iterator4 = _createForOfIteratorHelper(this.mp4track.pps),
|
|
2096
|
+
_step4;
|
|
2097
|
+
try {
|
|
2098
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
2099
|
+
var existing = _step4.value;
|
|
2100
|
+
if (sameBytes(existing, pps)) return;
|
|
2101
|
+
}
|
|
2102
|
+
} catch (err) {
|
|
2103
|
+
_iterator4.e(err);
|
|
2104
|
+
} finally {
|
|
2105
|
+
_iterator4.f();
|
|
2106
|
+
}
|
|
2107
|
+
this.mp4track.pps.push(new Uint8Array(pps));
|
|
2083
2108
|
}
|
|
2084
2109
|
}, {
|
|
2085
2110
|
key: "parseNAL",
|
|
@@ -2091,13 +2116,11 @@
|
|
|
2091
2116
|
var push = false;
|
|
2092
2117
|
switch (unit.type()) {
|
|
2093
2118
|
case NALU264.PPS:
|
|
2094
|
-
|
|
2095
|
-
this.parsePPS(unit.getPayload());
|
|
2096
|
-
}
|
|
2119
|
+
this.parsePPS(unit.getPayload());
|
|
2097
2120
|
push = true;
|
|
2098
2121
|
break;
|
|
2099
2122
|
case NALU264.SPS:
|
|
2100
|
-
if (!this.mp4track.sps) {
|
|
2123
|
+
if (!this.mp4track.sps.length) {
|
|
2101
2124
|
this.parseSPS(unit.getPayload());
|
|
2102
2125
|
}
|
|
2103
2126
|
push = true;
|
|
@@ -2109,7 +2132,7 @@
|
|
|
2109
2132
|
log('SEI - ignoing');
|
|
2110
2133
|
break;
|
|
2111
2134
|
}
|
|
2112
|
-
if (!this.readyToDecode && this.mp4track.pps && this.mp4track.sps) {
|
|
2135
|
+
if (!this.readyToDecode && this.mp4track.pps.length && this.mp4track.sps.length) {
|
|
2113
2136
|
this.readyToDecode = true;
|
|
2114
2137
|
}
|
|
2115
2138
|
return push;
|
|
@@ -2637,9 +2660,9 @@
|
|
|
2637
2660
|
type: 'video',
|
|
2638
2661
|
len: 0,
|
|
2639
2662
|
fragmented: true,
|
|
2640
|
-
vps:
|
|
2641
|
-
sps:
|
|
2642
|
-
pps:
|
|
2663
|
+
vps: [],
|
|
2664
|
+
sps: [],
|
|
2665
|
+
pps: [],
|
|
2643
2666
|
hvcC: {},
|
|
2644
2667
|
fps: 30,
|
|
2645
2668
|
width: 0,
|
|
@@ -2659,9 +2682,9 @@
|
|
|
2659
2682
|
key: "resetTrack",
|
|
2660
2683
|
value: function resetTrack() {
|
|
2661
2684
|
this.readyToDecode = false;
|
|
2662
|
-
this.mp4track.vps =
|
|
2663
|
-
this.mp4track.sps =
|
|
2664
|
-
this.mp4track.pps =
|
|
2685
|
+
this.mp4track.vps = [];
|
|
2686
|
+
this.mp4track.sps = [];
|
|
2687
|
+
this.mp4track.pps = [];
|
|
2665
2688
|
this.mp4track.hvcC = {};
|
|
2666
2689
|
this.nextDts = 0;
|
|
2667
2690
|
this.dts = 0;
|
|
@@ -2884,12 +2907,28 @@
|
|
|
2884
2907
|
}, {
|
|
2885
2908
|
key: "parsePPS",
|
|
2886
2909
|
value: function parsePPS(pps) {
|
|
2887
|
-
|
|
2910
|
+
// A stream may define more than one PPS (e.g. the encoder uses different
|
|
2911
|
+
// entropy-coding modes for I- vs P-slices, thus referencing different
|
|
2912
|
+
// pps_ids). Keep every distinct PPS so any slice can find the one it
|
|
2913
|
+
// references.
|
|
2914
|
+
var _iterator4 = _createForOfIteratorHelper(this.mp4track.pps),
|
|
2915
|
+
_step4;
|
|
2916
|
+
try {
|
|
2917
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
2918
|
+
var existing = _step4.value;
|
|
2919
|
+
if (sameBytes(existing, pps)) return;
|
|
2920
|
+
}
|
|
2921
|
+
} catch (err) {
|
|
2922
|
+
_iterator4.e(err);
|
|
2923
|
+
} finally {
|
|
2924
|
+
_iterator4.f();
|
|
2925
|
+
}
|
|
2926
|
+
this.mp4track.pps.push(new Uint8Array(pps));
|
|
2888
2927
|
}
|
|
2889
2928
|
}, {
|
|
2890
2929
|
key: "parseVPS",
|
|
2891
2930
|
value: function parseVPS(vps) {
|
|
2892
|
-
this.mp4track.vps = [vps];
|
|
2931
|
+
this.mp4track.vps = [new Uint8Array(vps)];
|
|
2893
2932
|
}
|
|
2894
2933
|
}, {
|
|
2895
2934
|
key: "parseNAL",
|
|
@@ -2901,21 +2940,19 @@
|
|
|
2901
2940
|
var push = false;
|
|
2902
2941
|
switch (unit.type()) {
|
|
2903
2942
|
case NALU265.VPS:
|
|
2904
|
-
if (!this.mp4track.vps) {
|
|
2943
|
+
if (!this.mp4track.vps.length) {
|
|
2905
2944
|
this.parseVPS(unit.getPayload());
|
|
2906
2945
|
}
|
|
2907
2946
|
push = true;
|
|
2908
2947
|
break;
|
|
2909
2948
|
case NALU265.SPS:
|
|
2910
|
-
if (!this.mp4track.sps) {
|
|
2949
|
+
if (!this.mp4track.sps.length) {
|
|
2911
2950
|
this.parseSPS(unit.getPayload());
|
|
2912
2951
|
}
|
|
2913
2952
|
push = true;
|
|
2914
2953
|
break;
|
|
2915
2954
|
case NALU265.PPS:
|
|
2916
|
-
|
|
2917
|
-
this.parsePPS(unit.getPayload());
|
|
2918
|
-
}
|
|
2955
|
+
this.parsePPS(unit.getPayload());
|
|
2919
2956
|
push = true;
|
|
2920
2957
|
break;
|
|
2921
2958
|
case NALU265.AUD:
|
|
@@ -2926,7 +2963,7 @@
|
|
|
2926
2963
|
log('SEI - ignoing');
|
|
2927
2964
|
break;
|
|
2928
2965
|
}
|
|
2929
|
-
if (!this.readyToDecode && this.mp4track.vps && this.mp4track.sps && this.mp4track.pps) {
|
|
2966
|
+
if (!this.readyToDecode && this.mp4track.vps.length && this.mp4track.sps.length && this.mp4track.pps.length) {
|
|
2930
2967
|
this.readyToDecode = true;
|
|
2931
2968
|
}
|
|
2932
2969
|
return push;
|
package/dist/jmuxer.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("stream")):"function"==typeof define&&define.amd?define(["stream"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).JMuxer=t(e.stream)}(this,function(e){"use strict";function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function r(e,t,r){return t=u(t),function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,d()?Reflect.construct(t,r||[],u(e).constructor):t.apply(e,r))}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,p(n.key),n)}}function a(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=v(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==r.return||r.return()}finally{if(o)throw a}}}}function o(e,t,r){return(t=p(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&l(e,t)}function d(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(d=function(){return!!e})()}function l(e,t){return l=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},l(e,t)}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,a,s,o=[],u=!0,c=!1;try{if(a=(r=r.call(e)).next,0===t);else for(;!(u=(n=a.call(r)).done)&&(o.push(n.value),o.length!==t);u=!0);}catch(e){c=!0,i=e}finally{try{if(!u&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw i}}return o}}(e,t)||v(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||v(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:t+""}function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function v(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}var m,g;function k(e){if(m){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];m.apply(void 0,[e].concat(r))}}function b(e){if(g){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];g.apply(void 0,[e].concat(r))}}var U=function(){return a(function e(t){n(this,e),this.listener={},this.type=""|t},[{key:"on",value:function(e,t){return this.listener[e]||(this.listener[e]=[]),this.listener[e].push(t),!0}},{key:"off",value:function(e,t){if(this.listener[e]){var r=this.listener[e].indexOf(t);return r>-1&&this.listener[e].splice(r,1),!0}return!1}},{key:"offAll",value:function(){this.listener={}}},{key:"dispatch",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return!!this.listener[e]&&(this.listener[e].map(function(e){e.apply(null,r)}),!0)}}])}(),S=function(){function e(){n(this,e)}return a(e,null,[{key:"init",value:function(){var t;for(t in e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],hev1:[],hvcC:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]},e.types)e.types.hasOwnProperty(t)&&(e.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);var r=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),n=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]);e.HDLR_TYPES={video:r,audio:n};var i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),a=new Uint8Array([0,0,0,0,0,0,0,0]);e.STTS=e.STSC=e.STCO=a,e.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),e.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),e.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);var s=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),u=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,s,u,s,o),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,i))}},{key:"box",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];for(var i,a=8,s=r.length,o=s;s--;)a+=r[s].byteLength;for((i=new Uint8Array(a))[0]=a>>24&255,i[1]=a>>16&255,i[2]=a>>8&255,i[3]=255&a,i.set(e,4),s=0,a=8;s<o;++s)i.set(r[s],a),a+=r[s].byteLength;return i}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}},{key:"mdhd",value:function(t,r){return e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,r>>>24&255,r>>>16&255,r>>>8&255,255&r,85,196,0,0]))}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"minf",value:function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))}},{key:"moof",value:function(t,r,n){return e.box(e.types.moof,e.mfhd(t),e.traf(n,r))}},{key:"moov",value:function(t,r,n){for(var i=t.length,a=[];i--;)a[i]=e.trak(t[i]);return e.box.apply(null,[e.types.moov,e.mvhd(n,r)].concat(a).concat(e.mvex(t)))}},{key:"mvex",value:function(t){for(var r=t.length,n=[];r--;)n[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(n))}},{key:"mvhd",value:function(t,r){var n=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,t>>24&255,t>>16&255,t>>8&255,255&t,r>>>24&255,r>>>16&255,r>>>8&255,255&r,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return e.box(e.types.mvhd,n)}},{key:"sdtp",value:function(t){var r,n,i=t.samples||[],a=new Uint8Array(4+i.length);for(n=0;n<i.length;n++)r=i[n].flags,a[n+4]=r.dependsOn<<4|r.isDependedOn<<2|r.hasRedundancy;return e.box(e.types.sdtp,a)}},{key:"stbl",value:function(t){return e.box(e.types.stbl,e.stsd(t),e.box(e.types.stts,e.STTS),e.box(e.types.stsc,e.STSC),e.box(e.types.stsz,e.STSZ),e.box(e.types.stco,e.STCO))}},{key:"avc1",value:function(t){var r,n,i,a=[],s=[];for(r=0;r<t.sps.length;r++)i=(n=t.sps[r]).byteLength,a.push(i>>>8&255),a.push(255&i),a=a.concat(Array.prototype.slice.call(n));for(r=0;r<t.pps.length;r++)i=(n=t.pps[r]).byteLength,s.push(i>>>8&255),s.push(255&i),s=s.concat(Array.prototype.slice.call(n));var o=e.box(e.types.avcC,new Uint8Array([1,a[3],a[4],a[5],255,224|t.sps.length].concat(a).concat([t.pps.length]).concat(s))),u=t.width,c=t.height;return e.box(e.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,u>>8&255,255&u,c>>8&255,255&c,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,98,105,110,101,108,112,114,111,46,114,117,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"hev1",value:function(t){for(var r,n,i=[],a=[],s=[],o=0;o<((null===(u=t.vps)||void 0===u?void 0:u.length)||0);o++){var u;n=(r=t.vps[o]).byteLength,i.push(n>>>8&255,255&n),i=i.concat(Array.prototype.slice.call(r))}for(var c=0;c<((null===(d=t.sps)||void 0===d?void 0:d.length)||0);c++){var d;n=(r=t.sps[c]).byteLength,a.push(n>>>8&255,255&n),a=a.concat(Array.prototype.slice.call(r))}for(var l=0;l<((null===(f=t.pps)||void 0===f?void 0:f.length)||0);l++){var f;n=(r=t.pps[l]).byteLength,s.push(n>>>8&255,255&n),s=s.concat(Array.prototype.slice.call(r))}var p=t.hvcC,y=p.profile_space,v=p.tier_flag,m=p.profile_idc,g=p.profile_compatibility_flags,k=p.constraint_indicator_flags,b=p.level_idc,U=p.chroma_format_idc,S=e.box(e.types.hvcC,new Uint8Array([1,y<<6|v<<5|m,g>>24&255,g>>16&255,g>>8&255,255&g].concat(h(k),[b,240,0,252,252|U,248,248,0,0,3,3,32,0,1],h(i),[33,0,1],h(a),[34,0,1],h(s)))),B=t.width,w=t.height;return e.box(e.types.hev1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,B>>8&255,255&B,w>>8&255,255&w,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,98,105,110,101,108,112,114,111,46,114,117,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),S,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"esds",value:function(e){var t=e.config.byteLength,r=new Uint8Array(26+t+3);return r.set([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5,t]),r.set(e.config,26),r.set([6,1,2],26+t),r}},{key:"mp4a",value:function(t){var r=t.audiosamplerate;return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]),e.box(e.types.esds,e.esds(t)))}},{key:"stsd",value:function(t){return"audio"===t.type?e.box(e.types.stsd,e.STSD,e.mp4a(t)):t.codec.startsWith("hvc1")?e.box(e.types.stsd,e.STSD,e.hev1(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))}},{key:"tkhd",value:function(t){var r=t.id,n=t.duration,i=t.width,a=t.height,s=t.volume;return e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,n>>>24&255,n>>>16&255,n>>>8&255,255&n,0,0,0,0,0,0,0,0,0,0,0,0,255&s,s%1*10&255,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,i>>8&255,255&i,0,0,a>>8&255,255&a,0,0]))}},{key:"traf",value:function(t,r){var n=e.sdtp(t),i=t.id;return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i])),e.box(e.types.tfdt,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r])),e.trun(t,n.length+16+16+8+16+8+8),n)}},{key:"trak",value:function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))}},{key:"trex",value:function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(t,r){var n,i,a,s,o,u,c=t.samples||[],d=c.length,l=12+16*d,f=new Uint8Array(l);for(r+=8+l,f.set([0,0,15,1,d>>>24&255,d>>>16&255,d>>>8&255,255&d,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),n=0;n<d;n++)a=(i=c[n]).duration,s=i.size,o=i.flags,u=i.cts,f.set([a>>>24&255,a>>>16&255,a>>>8&255,255&a,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,u>>>24&255,u>>>16&255,u>>>8&255,255&u],12+16*n);return e.box(e.types.trun,f)}},{key:"initSegment",value:function(t,r,n){e.types||e.init();var i,a=e.moov(t,r,n);return(i=new Uint8Array(e.FTYP.byteLength+a.byteLength)).set(e.FTYP),i.set(a,e.FTYP.byteLength),i}}])}(),B=function(){function e(){n(this,e)}return a(e,null,[{key:"samplingRateMap",get:function(){return[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350]}},{key:"getHeaderLength",value:function(e){return 1&e[1]?7:9}},{key:"getFrameLength",value:function(e){return(3&e[3])<<11|e[4]<<3|(224&e[5])>>>5}},{key:"isAACPattern",value:function(e){return!(255!==e[0]||240&~e[1]||6&e[1])}},{key:"extractAAC",value:function(t){var r,n,i=0,a=t.byteLength,s=[];if(!e.isAACPattern(t))return b("Invalid ADTS audio format"),{valid:!1};r=e.getHeaderLength(t);for(var o=t.subarray(0,r);i<a;)n=e.getFrameLength(t),s.push(t.subarray(r,n)),t=t.slice(n),i+=n;return{valid:!0,header:o,slices:s}}}])}(),w=1,E=function(e){function t(){return n(this,t),r(this,t,arguments)}return c(t,e),a(t,[{key:"flush",value:function(){this.mp4track.len=0,this.mp4track.samples=[]}},{key:"isReady",value:function(){return!(!this.readyToDecode||!this.samples.length)||null}}],[{key:"getTrackID",value:function(){return w++}}])}(U),A=function(e){function t(e,i,a){var s;return n(this,t),(s=r(this,t,["AACRemuxer"])).frameDuration=a,s.readyToDecode=!1,s.header=null,s.nextDts=0,s.dts=0,s.mp4track={id:E.getTrackID(),type:"audio",channelCount:0,len:0,fragmented:!0,timescale:e,duration:i,samples:[],config:"",codec:""},s.samples=[],s}return c(t,e),a(t,[{key:"resetTrack",value:function(){this.readyToDecode=!1,this.header=null,this.mp4track.codec="",this.mp4track.channelCount="",this.mp4track.config="",this.mp4track.timescale=this.timescale,this.nextDts=0,this.dts=0}},{key:"feed",value:function(e,t){var r=B.extractAAC(e),n=r.valid,i=r.header,a=r.slices;return this.header||(this.header=i),n&&a.length>0?(this.remux(this.getAudioFrames(a,t)),!0):(b("Failed to extract audio data from:",e),this.dispatch("outOfData"),!1)}},{key:"getAudioFrames",value:function(e,t){var r,n,i=[],a=0,o=s(e);try{for(o.s();!(n=o.n()).done;){var u=n.value;i.push({units:u})}}catch(e){o.e(e)}finally{o.f()}return r=t?t/i.length|0:this.frameDuration,a=t?t-r*i.length:0,i.map(function(e){e.duration=r,a>0&&(e.duration++,a--)}),i}},{key:"remux",value:function(e){if(e.length>0)for(var t=0;t<e.length;t++){var r=e[t],n=r.units,i=n.byteLength;this.samples.push({units:n,size:i,duration:r.duration}),this.mp4track.len+=i,this.readyToDecode||this.setAACConfig()}}},{key:"getPayload",value:function(){if(!this.isReady())return null;var e,t,r=new Uint8Array(this.mp4track.len),n=0,i=this.mp4track.samples;for(this.dts=this.nextDts;this.samples.length;){var a=this.samples.shift();a.units,(t=a.duration)<=0?(k("remuxer: invalid sample duration at DTS: ".concat(this.nextDts," :").concat(t)),this.mp4track.len-=a.size):(this.nextDts+=t,e={size:a.size,duration:t,cts:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},r.set(a.units,n),n+=a.size,i.push(e))}return i.length?new Uint8Array(r.buffer,0,this.mp4track.len):null}},{key:"setAACConfig",value:function(){var e,t,r,n=new Uint8Array(2);this.header&&(e=((192&this.header[2])>>>6)+1,t=(60&this.header[2])>>>2,r=(1&this.header[2])<<2,r|=(192&this.header[3])>>>6,n[0]=e<<3,n[0]|=(14&t)>>1,n[1]|=(1&t)<<7,n[1]|=r<<3,this.mp4track.codec="mp4a.40."+e,this.mp4track.channelCount=r,this.mp4track.config=n,this.readyToDecode=!0)}}])}(E),D=function(){return a(function e(t){n(this,e),this.data=t,this.index=0,this.bitLength=8*t.byteLength},[{key:"setData",value:function(e){this.data=e,this.index=0,this.bitLength=8*e.byteLength}},{key:"bitsAvailable",get:function(){return this.bitLength-this.index}},{key:"skipBits",value:function(e){if(this.bitsAvailable<e)return!1;this.index+=e}},{key:"readBits",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.getBits(e,this.index,t)}},{key:"getBits",value:function(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(this.bitsAvailable<e)return 0;var n=t%8,i=this.data[t/8|0]&255>>>n,a=8-n;if(a>=e)return r&&(this.index+=e),i>>a-e;r&&(this.index+=a);var s=e-a;return i<<s|this.getBits(s,t+a,r)}},{key:"skipLZ",value:function(){var e;for(e=0;e<this.bitLength-this.index;++e)if(0!==this.getBits(1,this.index+e,!1))return this.index+=e,e;return e}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBoolean",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.readBits(8*e)}},{key:"readUShort",value:function(){return this.readBits(16)}},{key:"readUInt",value:function(){return this.readBits(32)}}])}(),x=function(){function e(){n(this,e)}return a(e,null,[{key:"extractNALu",value:function(e){for(var t=0,r=e.byteLength,n=[],i=0,a=0;t<r;){var s=e[t++];if(0===s)a++;else if(1===s&&a>=2){var o=a+1;i!==t-o&&n.push(e.subarray(i,t-o)),i=t,a=0}else a=0}var u=null;return i<r&&(u=e.subarray(i,r)),[n,u]}},{key:"skipScalingList",value:function(e,t){for(var r=8,n=8,i=0;i<t;i++)0!==n&&(n=(r+e.readEG()+256)%256),r=0===n?r:n}},{key:"readSPS",value:function(t){var r,n,i,a,s,o,u=new D(t),c=0,d=0,l=0,f=0,h=1,p=0;u.readUByte();for(var y=[],v=t.byteLength,m=1;m<v;m++)m+2<v&&3===u.readBits(24,!1)?(y.push(u.readBits(8)),y.push(u.readBits(8)),m+=2,u.readBits(8)):y.push(u.readBits(8));if(u.setData(new Uint8Array(y)),r=u.readUByte(),u.readBits(5),u.skipBits(3),u.readUByte(),u.skipUEG(),100===r||110===r||122===r||244===r||44===r||83===r||86===r||118===r||128===r){var g=u.readUEG();if(3===g&&u.skipBits(1),u.skipUEG(),u.skipUEG(),u.skipBits(1),u.readBoolean()){o=3!==g?8:12;for(var k=0;k<o;++k)u.readBoolean()&&(k<6?e.skipScalingList(u,16):e.skipScalingList(u,64))}}u.skipUEG();var b=u.readUEG();if(0===b)u.readUEG();else if(1===b){u.skipBits(1),u.skipEG(),u.skipEG(),n=u.readUEG();for(var U=0;U<n;++U)u.skipEG()}if(u.skipUEG(),u.skipBits(1),i=u.readUEG(),a=u.readUEG(),0===(s=u.readBits(1))&&u.skipBits(1),u.skipBits(1),u.readBoolean()&&(c=u.readUEG(),d=u.readUEG(),l=u.readUEG(),f=u.readUEG()),u.readBoolean()){if(u.readBoolean()){var S;switch(u.readUByte()){case 1:S=[1,1];break;case 2:S=[12,11];break;case 3:S=[10,11];break;case 4:S=[16,11];break;case 5:S=[40,33];break;case 6:S=[24,11];break;case 7:S=[20,11];break;case 8:S=[32,11];break;case 9:S=[80,33];break;case 10:S=[18,11];break;case 11:S=[15,11];break;case 12:S=[64,33];break;case 13:S=[160,99];break;case 14:S=[4,3];break;case 15:S=[3,2];break;case 16:S=[2,1];break;case 255:S=[u.readUByte()<<8|u.readUByte(),u.readUByte()<<8|u.readUByte()]}S&&S[0]>0&&S[1]>0&&(h=S[0]/S[1])}if(u.readBoolean()&&u.skipBits(1),u.readBoolean()&&(u.skipBits(4),u.readBoolean()&&u.skipBits(24)),u.readBoolean()&&(u.skipUEG(),u.skipUEG()),u.readBoolean()){var B=u.readUInt(),w=u.readUInt();u.readBoolean(),p=w/(2*B)}}return{fps:p>0?p:void 0,width:Math.ceil((16*(i+1)-2*c-2*d)*h),height:(2-s)*(a+1)*16-(s?2:4)*(l+f)}}}])}(),C=function(){function e(t){n(this,e),this.payload=t,this.nri=(96&this.payload[0])>>5,this.nalUnitType=31&this.payload[0],this._sliceType=null,this._isFirstSlice=!1}return a(e,[{key:"toString",value:function(){return"".concat(e.TYPES[this.type()]||"UNKNOWN",": NRI: ").concat(this.getNri())}},{key:"getNri",value:function(){return this.nri}},{key:"type",value:function(){return this.nalUnitType}},{key:"isKeyframe",get:function(){return this.nalUnitType===e.IDR}},{key:"isVCL",get:function(){return this.nalUnitType==e.IDR||this.nalUnitType==e.NDR}},{key:"parseHeader",value:function(){var e=new D(this.getPayload());e.readUByte(),this._isFirstSlice=0===e.readUEG(),this._sliceType=e.readUEG()}},{key:"isFirstSlice",get:function(){return this._isFirstSlice||this.parseHeader(),this._isFirstSlice}},{key:"sliceType",get:function(){return this._sliceType||this.parseHeader(),this._sliceType}},{key:"getPayload",value:function(){return this.payload}},{key:"getPayloadSize",value:function(){return this.payload.byteLength}},{key:"getSize",value:function(){return 4+this.getPayloadSize()}},{key:"getData",value:function(){var e=new Uint8Array(this.getSize());return new DataView(e.buffer).setUint32(0,this.getSize()-4),e.set(this.getPayload(),4),e}}],[{key:"NDR",get:function(){return 1}},{key:"IDR",get:function(){return 5}},{key:"SEI",get:function(){return 6}},{key:"SPS",get:function(){return 7}},{key:"PPS",get:function(){return 8}},{key:"AUD",get:function(){return 9}},{key:"TYPES",get:function(){return o(o(o(o(o(o({},e.IDR,"IDR"),e.SEI,"SEI"),e.SPS,"SPS"),e.PPS,"PPS"),e.NDR,"NDR"),e.AUD,"AUD")}}])}();function P(e,t){var r=new Uint8Array((0|e.byteLength)+(0|t.byteLength));return r.set(e,0),r.set(t,0|e.byteLength),r}function T(e){var t,r,n,i="";return t=Math.floor(e),(r=parseInt(t/3600,10)%24)>0&&(i+=(r<10?"0"+r:r)+":"),i+=((n=parseInt(t/60,10)%60)<10?"0"+n:n)+":"+((t=t<0?0:t%60)<10?"0"+t:t)}var L=function(e){function t(e,i,a){var s;return n(this,t),(s=r(this,t,["H264Remuxer"])).frameDuration=a,s.readyToDecode=!1,s.nextDts=0,s.dts=0,s.mp4track={id:E.getTrackID(),type:"video",len:0,fragmented:!0,sps:"",pps:"",fps:30,width:0,height:0,timescale:e,duration:i,samples:[]},s.samples=[],s.remainingData=new Uint8Array,s.kfCounter=0,s.pendingUnits={},s}return c(t,e),a(t,[{key:"resetTrack",value:function(){this.readyToDecode=!1,this.mp4track.sps="",this.mp4track.pps="",this.nextDts=0,this.dts=0,this.remainingData=new Uint8Array,this.kfCounter=0,this.pendingUnits={}}},{key:"feed",value:function(e,t,r){var n,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=[];e=P(this.remainingData,e);var s=f(x.extractNALu(e),2);return a=s[0],(n=s[1])?i?(a.push(n),this.remainingData=new Uint8Array):this.remainingData=n:this.remainingData=new Uint8Array,a.length>0?(this.remux(this.getVideoFrames(a,t,r)),!0):(k("Failed to extract any NAL units from video data:",n),this.dispatch("outOfData"),!1)}},{key:"getVideoFrames",value:function(e,t,r){var n,i=this,a=[],o=[],u=0,c=!1,d=!1;this.pendingUnits.units&&(a=this.pendingUnits.units,d=this.pendingUnits.vcl,c=this.pendingUnits.keyFrame,this.pendingUnits={});var l,f=s(e);try{for(f.s();!(l=f.n()).done;){var h=l.value,p=new C(h);this.parseNAL(p)&&(a.length&&d&&(p.isFirstSlice||!p.isVCL)&&(o.push({units:a,keyFrame:c}),a=[],c=!1,d=!1),a.push(p),c=c||p.isKeyframe,d=d||p.isVCL)}}catch(e){f.e(e)}finally{f.f()}if(a.length)if(t)if(d)o.push({units:a,keyFrame:c});else{var y=o.length-1;y>=0&&(o[y].units=o[y].units.concat(a))}else this.pendingUnits={units:a,keyFrame:c,vcl:d};return n=t?t/o.length|0:this.frameDuration,u=t?t-n*o.length:0,o.map(function(e){e.duration=n,e.compositionTimeOffset=r,u>0&&(e.duration++,u--),i.kfCounter++,e.keyFrame&&i.dispatch("keyframePosition",i.kfCounter*n/1e3)}),k("jmuxer: No. of H264 frames of the last chunk: ".concat(o.length)),o}},{key:"remux",value:function(e){var t,r=s(e);try{for(r.s();!(t=r.n()).done;){var n=t.value,i=n.units.reduce(function(e,t){return e+t.getSize()},0);n.units.length>0&&this.readyToDecode&&(this.mp4track.len+=i,this.samples.push({units:n.units,size:i,keyFrame:n.keyFrame,duration:n.duration,compositionTimeOffset:n.compositionTimeOffset}))}}catch(e){r.e(e)}finally{r.f()}}},{key:"getPayload",value:function(){if(!this.isReady())return null;var e,t,r=new Uint8Array(this.mp4track.len),n=0,i=this.mp4track.samples;for(this.dts=this.nextDts;this.samples.length;){var a=this.samples.shift(),o=a.units;if((t=a.duration)<=0)k("remuxer: invalid sample duration at DTS: ".concat(this.nextDts," :").concat(t)),this.mp4track.len-=a.size;else{this.nextDts+=t,e={size:a.size,duration:t,cts:a.compositionTimeOffset||0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,isNonSync:a.keyFrame?0:1,dependsOn:a.keyFrame?2:1}};var u,c=s(o);try{for(c.s();!(u=c.n()).done;){var d=u.value;r.set(d.getData(),n),n+=d.getSize()}}catch(e){c.e(e)}finally{c.f()}i.push(e)}}return i.length?new Uint8Array(r.buffer,0,this.mp4track.len):null}},{key:"parseSPS",value:function(e){var t=x.readSPS(new Uint8Array(e));this.mp4track.fps=t.fps||this.mp4track.fps,this.mp4track.width=t.width,this.mp4track.height=t.height,this.mp4track.sps=[new Uint8Array(e)],this.mp4track.codec="avc1.";for(var r=new DataView(e.buffer,e.byteOffset+1,4),n=0;n<3;++n){var i=r.getUint8(n).toString(16);i.length<2&&(i="0"+i),this.mp4track.codec+=i}}},{key:"parsePPS",value:function(e){this.mp4track.pps=[new Uint8Array(e)]}},{key:"parseNAL",value:function(e){if(!e)return!1;if(e.isVCL)return!0;var t=!1;switch(e.type()){case C.PPS:this.mp4track.pps||this.parsePPS(e.getPayload()),t=!0;break;case C.SPS:this.mp4track.sps||this.parseSPS(e.getPayload()),t=!0;break;case C.AUD:k("AUD - ignoing");break;case C.SEI:k("SEI - ignoing")}return!this.readyToDecode&&this.mp4track.pps&&this.mp4track.sps&&(this.readyToDecode=!0),t}}])}(E),_=function(){return a(function e(){n(this,e)},null,[{key:"extractNALu",value:function(e){for(var t=0,r=e.byteLength,n=[],i=0,a=0;t<r;){var s=e[t++];if(0===s)a++;else if(1===s&&a>=2){var o=a+1;i!==t-o&&n.push(e.subarray(i,t-o)),i=t,a=0}else a=0}var u=null;return i<r&&(u=e.subarray(i,r)),[n,u]}},{key:"removeEmulationPreventionBytes",value:function(e){for(var t=[],r=0,n=0;n<e.length;n++){var i=e[n];2!==r||3!==i?(t.push(i),0===i?r++:r=0):r=0}return new Uint8Array(t)}},{key:"readSPS",value:function(e){var t=new D(e);t.readUByte(),t.readUByte(),t.readBits(4);var r=t.readBits(3);t.readBits(1);for(var n=t.readBits(2),i=t.readBits(1),a=t.readBits(5),s=t.readUInt(),o=new Uint8Array(6),u=0;u<6;u++)o[u]=t.readUByte();var c=t.readUByte();t.readUEG();var d=t.readUEG();3===d&&t.readBits(1);var l=t.readUEG(),f=t.readUEG(),h=0,p=0,y=0,v=0;t.readBoolean()&&(h=t.readUEG(),p=t.readUEG(),y=t.readUEG(),v=t.readUEG()),t.readUEG(),t.readUEG(),t.readUEG();for(var m=t.readBits(1)?0:r;m<=r;m++)t.readUEG(),t.readUEG(),t.readUEG();if((t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG(),t.readBits(1))&&t.readBits(1))for(var g=0;g<4;g++)for(var k=0;k<(3===g?2:6);k++){if(t.readBits(1)){var b=Math.min(64,1<<4+(g<<1));g>1&&t.readEG();for(var U=0;U<b;U++)t.readEG()}else t.readUEG()}t.readBits(1),t.readBits(1),t.readBits(1)&&(t.readBits(4),t.readBits(4),t.readUEG(),t.readUEG(),t.readBits(1));for(var S=t.readUEG(),B=0;B<S;B++){var w=!1;if(0!==B&&(w=t.readBoolean()),w)t.readUEG(),t.readBits(1),t.readUEG();else{for(var E=t.readUEG(),A=t.readUEG(),x=0;x<E;x++)t.readUEG(),t.readBits(1);for(var C=0;C<A;C++)t.readUEG(),t.readBits(1)}}if(t.readBits(1))for(var P=t.readUEG(),T=0;T<P;T++)t.readUEG(),t.readBits(1);t.readBits(1),t.readBits(1);var L=null;if(t.readBoolean()){if(t.readBoolean())255===t.readUByte()&&(t.readUShort(),t.readUShort());if(t.readBoolean()&&t.readBoolean(),t.readBoolean())t.readBits(3),t.readBoolean(),t.readBoolean()&&(t.readUByte(),t.readUByte(),t.readUByte());if(t.readBoolean()&&(t.readUEG(),t.readUEG()),t.readBoolean(),t.readBoolean(),t.readBoolean(),t.readBoolean()&&(t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG()),t.readBoolean()){var _=t.readUInt(),G=t.readUInt();if(t.readBoolean()&&t.readUEG(),t.readBoolean()){var I=!1,R=!1,O=!1;I=t.readBoolean(),R=t.readBoolean(),(I||R)&&((O=t.readBoolean())&&(t.readBits(8),t.readBits(5),t.readBits(1),t.readBits(5)),t.readBits(4),t.readBits(4),O&&t.readBits(4),t.readBits(5),t.readBits(5),t.readBits(5));for(var F=0;F<=r;F++){var M=!1,N=0;if(!!t.readBoolean()||t.readBoolean()?t.readUEG():M=t.readBoolean(),M||(N=t.readUEG()),I)for(var z=0;z<=N;z++)t.readUEG(),t.readUEG(),O&&(t.readUEG(),t.readUEG()),t.readBits(1);if(R)for(var j=0;j<=N;j++)t.readUEG(),t.readUEG(),O&&(t.readUEG(),t.readUEG()),t.readBits(1)}}_>0&&G>0&&(L=G/_)}t.readBoolean()&&(t.readBoolean(),t.readBoolean(),t.readBoolean(),t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG())}return{width:l-(1===d||2===d?2:1)*(p+h),height:f-(1===d?2:1)*(y+v),profile_space:n,tier_flag:i,profile_idc:a,profile_compatibility_flags:s,constraint_indicator_flags:o,level_idc:c,chroma_format_idc:d,fps:L}}}])}(),G=function(){function e(t){n(this,e),this.payload=t,this.nalUnitType=(126&t[0])>>1,this.nuhLayerId=(1&t[0])<<5|(248&t[1])>>3,this.nuhTemporalIdPlus1=7&t[1],this._isFirstSlice=null,this._sliceType=null}return a(e,[{key:"toString",value:function(){return"".concat(e.TYPES[this.type()]||"UNKNOWN ("+this.type()+")",": Layer: ").concat(this.nuhLayerId,", Temporal Id: ").concat(this.nuhTemporalIdPlus1)}},{key:"type",value:function(){return this.nalUnitType}},{key:"isKeyframe",get:function(){return[e.IDR_W_RADL,e.IDR_N_LP,e.CRA].includes(this.nalUnitType)}},{key:"isVCL",get:function(){return this.nalUnitType<=31}},{key:"parseHeader",value:function(){var e=new D(this.getPayload());e.readUByte(),e.readUByte(),this._isFirstSlice=e.readBoolean(),this.isKeyframe&&e.readBits(1),e.readUEG(),this._sliceType=e.readUEG()}},{key:"isFirstSlice",get:function(){return this._isFirstSlice||this.parseHeader(),this._isFirstSlice}},{key:"sliceType",get:function(){return this._sliceType||this.parseHeader(),this._sliceType}},{key:"getPayload",value:function(){return this.payload}},{key:"getPayloadSize",value:function(){return this.payload.byteLength}},{key:"getSize",value:function(){return 4+this.getPayloadSize()}},{key:"getData",value:function(){var e=new Uint8Array(this.getSize());return new DataView(e.buffer).setUint32(0,this.getSize()-4),e.set(this.getPayload(),4),e}}],[{key:"TRAIL_N",get:function(){return 0}},{key:"TRAIL_R",get:function(){return 1}},{key:"IDR_W_RADL",get:function(){return 19}},{key:"IDR_N_LP",get:function(){return 20}},{key:"CRA",get:function(){return 21}},{key:"VPS",get:function(){return 32}},{key:"SPS",get:function(){return 33}},{key:"PPS",get:function(){return 34}},{key:"AUD",get:function(){return 35}},{key:"SEI",get:function(){return 39}},{key:"SEI2",get:function(){return 40}},{key:"TYPES",get:function(){var t;return o(o(o(o(o(o(o(o(o(o(t={},e.TRAIL_N,"TRAIL_N"),e.TRAIL_R,"TRAIL_R"),e.IDR_W_RADL,"IDR"),e.IDR_N_LP,"IDR2"),e.CRA,"CRA"),e.VPS,"VPS"),e.SPS,"SPS"),e.PPS,"PPS"),e.AUD,"AUD"),e.SEI,"SEI"),o(t,e.SEI2,"SEI2")}}])}(),I=function(e){function t(e,i,a){var s;return n(this,t),(s=r(this,t,["H264Remuxer"])).frameDuration=a,s.readyToDecode=!1,s.nextDts=0,s.dts=0,s.mp4track={id:E.getTrackID(),type:"video",len:0,fragmented:!0,vps:"",sps:"",pps:"",hvcC:{},fps:30,width:0,height:0,timescale:e,duration:i,samples:[]},s.samples=[],s.remainingData=new Uint8Array,s.kfCounter=0,s.pendingUnits={},s}return c(t,e),a(t,[{key:"resetTrack",value:function(){this.readyToDecode=!1,this.mp4track.vps="",this.mp4track.sps="",this.mp4track.pps="",this.mp4track.hvcC={},this.nextDts=0,this.dts=0,this.remainingData=new Uint8Array,this.kfCounter=0,this.pendingUnits={}}},{key:"feed",value:function(e,t,r){var n,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=[];e=P(this.remainingData,e);var s=f(_.extractNALu(e),2);return a=s[0],(n=s[1])?i?(a.push(n),this.remainingData=new Uint8Array):this.remainingData=n:this.remainingData=new Uint8Array,a.length>0?(this.remux(this.getVideoFrames(a,t,r)),!0):(k("Failed to extract any NAL units from video data:",n),this.dispatch("outOfData"),!1)}},{key:"getVideoFrames",value:function(e,t,r){var n,i=this,a=[],o=[],u=0,c=!1,d=!1;this.pendingUnits.units&&(a=this.pendingUnits.units,d=this.pendingUnits.vcl,c=this.pendingUnits.keyFrame,this.pendingUnits={});var l,f=s(e);try{for(f.s();!(l=f.n()).done;){var h=l.value,p=new G(h);this.parseNAL(p)&&(a.length&&d&&(p.isFirstSlice||!p.isVCL)&&(o.push({units:a,keyFrame:c}),a=[],c=!1,d=!1),a.push(p),c=c||p.isKeyframe,d=d||p.isVCL)}}catch(e){f.e(e)}finally{f.f()}if(a.length)if(t)if(d)o.push({units:a,keyFrame:c});else{var y=o.length-1;y>=0&&(o[y].units=o[y].units.concat(a))}else this.pendingUnits={units:a,keyFrame:c,vcl:d};return n=t?t/o.length|0:this.frameDuration,u=t?t-n*o.length:0,o.map(function(e){e.duration=n,e.compositionTimeOffset=r,u>0&&(e.duration++,u--),i.kfCounter++,e.keyFrame&&i.dispatch("keyframePosition",i.kfCounter*n/1e3)}),k("jmuxer: No. of H265 frames of the last chunk: ".concat(o.length)),o}},{key:"remux",value:function(e){var t,r=s(e);try{for(r.s();!(t=r.n()).done;){var n=t.value,i=n.units.reduce(function(e,t){return e+t.getSize()},0);n.units.length>0&&this.readyToDecode&&(this.mp4track.len+=i,this.samples.push({units:n.units,size:i,keyFrame:n.keyFrame,duration:n.duration,compositionTimeOffset:n.compositionTimeOffset}))}}catch(e){r.e(e)}finally{r.f()}}},{key:"getPayload",value:function(){if(!this.isReady())return null;var e,t,r=new Uint8Array(this.mp4track.len),n=0,i=this.mp4track.samples;for(this.dts=this.nextDts;this.samples.length;){var a=this.samples.shift(),o=a.units;if((t=a.duration)<=0)k("remuxer: invalid sample duration at DTS: ".concat(this.nextDts," :").concat(t)),this.mp4track.len-=a.size;else{this.nextDts+=t,e={size:a.size,duration:t,cts:a.compositionTimeOffset||0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,isNonSync:a.keyFrame?0:1,dependsOn:a.keyFrame?2:1}};var u,c=s(o);try{for(c.s();!(u=c.n()).done;){var d=u.value;r.set(d.getData(),n),n+=d.getSize()}}catch(e){c.e(e)}finally{c.f()}i.push(e)}}return i.length?new Uint8Array(r.buffer,0,this.mp4track.len):null}},{key:"parseSPS",value:function(e){this.mp4track.sps=[new Uint8Array(e)],e=_.removeEmulationPreventionBytes(e);var t=_.readSPS(new Uint8Array(e));this.mp4track.fps=t.fps||this.mp4track.fps,this.mp4track.width=t.width,this.mp4track.height=t.height,this.mp4track.codec="hvc1."+(t.profile_space?String.fromCharCode(64+t.profile_space):"")+t.profile_idc+"."+function(e){for(var t=0,r=0;r<32;r++)t<<=1,t|=1&e,e>>>=1;return t>>>0}(t.profile_compatibility_flags).toString(16)+"."+(t.tier_flag?"H":"L")+t.level_idc+"."+t.constraint_indicator_flags.map(function(e){return e.toString(16)}).join(".").toUpperCase().replace(/(?:\.0)+$/,""),this.mp4track.hvcC={profile_space:t.profile_space,tier_flag:t.tier_flag,profile_idc:t.profile_idc,profile_compatibility_flags:t.profile_compatibility_flags,constraint_indicator_flags:t.constraint_indicator_flags,level_idc:t.level_idc,chroma_format_idc:t.chroma_format_idc}}},{key:"parsePPS",value:function(e){this.mp4track.pps=[e]}},{key:"parseVPS",value:function(e){this.mp4track.vps=[e]}},{key:"parseNAL",value:function(e){if(!e)return!1;if(e.isVCL)return!0;var t=!1;switch(e.type()){case G.VPS:this.mp4track.vps||this.parseVPS(e.getPayload()),t=!0;break;case G.SPS:this.mp4track.sps||this.parseSPS(e.getPayload()),t=!0;break;case G.PPS:this.mp4track.pps||this.parsePPS(e.getPayload()),t=!0;break;case G.AUD:k("AUD - ignoing");break;case G.SEI:case G.SEI2:k("SEI - ignoing")}return!this.readyToDecode&&this.mp4track.vps&&this.mp4track.sps&&this.mp4track.pps&&(this.readyToDecode=!0),t}}])}(E),R=function(e){function t(e,i,a,s){var o;return n(this,t),(o=r(this,t,["remuxer"])).videoCodec=a,o.frameDuration=s,o.initialized=!1,o.tracks={},o.seq=1,o.env=e,o.timescale=1e3,o.mediaDuration=i?4294967295:0,o}return c(t,e),a(t,[{key:"addTrack",value:function(e){var t=this;if("video"!==e&&"both"!==e||("H265"==this.videoCodec?this.tracks.video=new I(this.timescale,this.mediaDuration,this.frameDuration):this.tracks.video=new L(this.timescale,this.mediaDuration,this.frameDuration),this.tracks.video.on("outOfData",function(){t.dispatch("missingVideoFrames")}),this.tracks.video.on("keyframePosition",function(e){t.dispatch("keyframePosition",e)})),"audio"===e||"both"===e){var r=new A(this.timescale,this.mediaDuration,this.frameDuration);this.tracks.audio=r,this.tracks.audio.on("outOfData",function(){t.dispatch("missingAudioFrames")})}}},{key:"reset",value:function(){for(var e in this.tracks)this.tracks[e].resetTrack();this.initialized=!1}},{key:"destroy",value:function(){this.tracks={},this.offAll()}},{key:"flush",value:function(){if(!this.initialized){if(!this.isReady())return;this.dispatch("ready"),this.initSegment(),this.initialized=!0}for(var e in this.tracks){var t=this.tracks[e],r=t.getPayload();if(r&&r.byteLength){var n={type:e,payload:P(S.moof(this.seq,t.dts,t.mp4track),S.mdat(r)),dts:t.dts};"video"===e&&(n.fps=t.mp4track.fps),this.dispatch("buffer",n);var i=T(t.dts/this.timescale);k("put segment (".concat(e,"): dts: ").concat(t.dts," frames: ").concat(t.mp4track.samples.length," second: ").concat(i)),t.flush(),this.seq++}}}},{key:"initSegment",value:function(){var e=[];for(var t in this.tracks){var r=this.tracks[t];if("browser"==this.env){var n={type:t,payload:S.initSegment([r.mp4track],this.mediaDuration,this.timescale)};this.dispatch("buffer",n)}else e.push(r.mp4track)}if("node"==this.env){var i={type:"all",payload:S.initSegment(e,this.mediaDuration,this.timescale)};this.dispatch("buffer",i)}k("Initial segment generated.")}},{key:"isReady",value:function(){for(var e in this.tracks)if(!this.tracks[e].readyToDecode||!this.tracks[e].samples.length)return!1;return!0}},{key:"feed",value:function(e){var t=!1;e.video&&this.tracks.video&&(t|=this.tracks.video.feed(e.video,e.duration,e.compositionTimeOffset,e.isLastVideoFrameComplete)),e.audio&&this.tracks.audio&&(t|=this.tracks.audio.feed(e.audio,e.duration)),t?this.flush():b("Input object must have video and/or audio property. Make sure it is a valid typed array")}}])}(U),O=function(e){function t(e,i){var a;return n(this,t),(a=r(this,t,["buffer"])).type=i,a.queue=new Uint8Array,a.cleaning=!1,a.pendingCleaning=0,a.cleanOffset=30,a.cleanRanges=[],a.sourceBuffer=e,a.sourceBuffer.addEventListener("updateend",function(){a.pendingCleaning>0&&(a.initCleanup(a.pendingCleaning),a.pendingCleaning=0),a.cleaning=!1,a.cleanRanges.length&&a.doCleanup()}),a.sourceBuffer.addEventListener("error",function(){a.dispatch("error",{type:a.type,name:"buffer",error:"buffer error"})}),a}return c(t,e),a(t,[{key:"destroy",value:function(){this.queue=null,this.sourceBuffer=null,this.offAll()}},{key:"doCleanup",value:function(){if(this.cleanRanges.length){var e=this.cleanRanges.shift();k("".concat(this.type," remove range [").concat(e[0]," - ").concat(e[1],")")),this.cleaning=!0,this.sourceBuffer.remove(e[0],e[1])}else this.cleaning=!1}},{key:"initCleanup",value:function(e){try{if(this.sourceBuffer.updating)return void(this.pendingCleaning=e);if(this.sourceBuffer.buffered&&this.sourceBuffer.buffered.length&&!this.cleaning){for(var t=0;t<this.sourceBuffer.buffered.length;++t){var r=this.sourceBuffer.buffered.start(t),n=this.sourceBuffer.buffered.end(t);e-r>this.cleanOffset&&r<(n=e-this.cleanOffset)&&this.cleanRanges.push([r,n])}this.doCleanup()}}catch(e){b("Error occured while cleaning ".concat(this.type," buffer - ").concat(e.name,": ").concat(e.message))}}},{key:"doAppend",value:function(){if(this.queue.length&&this.sourceBuffer&&!this.sourceBuffer.updating)try{this.sourceBuffer.appendBuffer(this.queue),this.queue=new Uint8Array}catch(t){var e="unexpectedError";"QuotaExceededError"===t.name?(k("".concat(this.type," buffer quota full")),e="QuotaExceeded"):(b("Error occured while appending ".concat(this.type," buffer - ").concat(t.name,": ").concat(t.message)),e="InvalidStateError"),this.dispatch("error",{type:this.type,name:e,error:"buffer error"})}}},{key:"feed",value:function(e){this.queue=P(this.queue,e)}}])}(U);return function(t){function i(e){var t;n(this,i),(t=r(this,i,["jmuxer"])).isReset=!1;var a={node:"",mode:"both",videoCodec:"H264",flushingTime:500,maxDelay:500,clearBuffer:!0,fps:30,readFpsFromTrack:!1,debug:!1,onReady:function(){},onData:function(){},onError:function(){},onUnsupportedCodec:function(){},onMissingVideoFrames:function(){},onMissingAudioFrames:function(){},onKeyframePosition:function(){},onLoggerLog:console.log,onLoggerErr:console.error};return t.options=Object.assign({},a,e),t.env="object"===("undefined"==typeof process?"undefined":y(process))&&"undefined"==typeof window?"node":"browser",t.options.debug&&function(e,t){m=e,g=t}(t.options.onLoggerLog,t.options.onLoggerErr),t.options.fps||(t.options.fps=30),t.frameDuration=1e3/t.options.fps|0,t.remuxController=new R(t.env,e.live,t.options.videoCodec,t.frameDuration),t.remuxController.addTrack(t.options.mode),t.initData(),t.remuxController.on("buffer",t.onBuffer.bind(t)),"browser"==t.env&&(t.remuxController.on("ready",t.createBuffer.bind(t)),t.initBrowser()),t.remuxController.on("missingVideoFrames",function(){"function"==typeof t.options.onMissingVideoFrames&&t.options.onMissingVideoFrames.call(null)}),t.remuxController.on("missingAudioFrames",function(){"function"==typeof t.options.onMissingAudioFrames&&t.options.onMissingAudioFrames.call(null)}),t.clearBuffer&&t.remuxController.on("keyframePosition",function(e){t.kfPosition.push(e)}),"function"==typeof t.options.onKeyframePosition&&t.remuxController.on("keyframePosition",function(e){t.options.onKeyframePosition.call(null,e)}),t}return c(i,t),a(i,[{key:"initData",value:function(){this.lastCleaningTime=Date.now(),this.kfPosition=[],this.pendingUnits={},this.remainingData=new Uint8Array,this.startInterval()}},{key:"initBrowser",value:function(){"string"==typeof this.options.node&&""==this.options.node&&b("no video element were found to render, provide a valid video element"),this.node="string"==typeof this.options.node?document.getElementById(this.options.node):this.options.node,this.mseReady=!1,this.setupMSE()}},{key:"createStream",value:function(){var t=this.feed.bind(this),r=this.destroy.bind(this);return this.stream=new e.Duplex({writableObjectMode:!0,read:function(e){},write:function(e,r,n){t(e),n()},final:function(e){r(),e()}}),this.stream}},{key:"setupMSE",value:function(){if(window.MediaSource=window.MediaSource||window.WebKitMediaSource||window.ManagedMediaSource,!window.MediaSource)throw"Oops! Browser does not support Media Source Extension or Managed Media Source (IOS 17+).";if(this.isMSESupported=!!window.MediaSource,this.mediaSource=new window.MediaSource,this.url=URL.createObjectURL(this.mediaSource),window.MediaSource===window.ManagedMediaSource)try{this.node.removeAttribute("src"),this.node.disableRemotePlayback=!0;var e=document.createElement("source");e.type="video/mp4",e.src=this.url,this.node.appendChild(e),this.node.load()}catch(e){this.node.src=this.url}else this.node.src=this.url;this.mseEnded=!1,this.mediaSource.addEventListener("sourceopen",this.onMSEOpen.bind(this)),this.mediaSource.addEventListener("sourceclose",this.onMSEClose.bind(this)),this.mediaSource.addEventListener("webkitsourceopen",this.onMSEOpen.bind(this)),this.mediaSource.addEventListener("webkitsourceclose",this.onMSEClose.bind(this))}},{key:"endMSE",value:function(){if(!this.mseEnded)try{this.mseEnded=!0,this.mediaSource.endOfStream()}catch(e){b("mediasource is not available to end")}}},{key:"feed",value:function(e){e&&this.remuxController&&(e.duration=e.duration?parseInt(e.duration):0,this.remuxController.feed(e))}},{key:"destroy",value:function(){if(this.stopInterval(),this.stream&&(this.remuxController.flush(),this.stream.push(null),this.stream=null),this.remuxController&&(this.remuxController.destroy(),this.remuxController=null),this.bufferControllers){for(var e in this.bufferControllers)this.bufferControllers[e].destroy();this.bufferControllers=null,this.endMSE()}this.node=!1,this.mseReady=!1,this.videoStarted=!1,this.mediaSource=null}},{key:"reset",value:function(){if(this.stopInterval(),this.isReset=!0,this.node.pause(),this.remuxController&&this.remuxController.reset(),this.bufferControllers){for(var e in this.bufferControllers)this.bufferControllers[e].destroy();this.bufferControllers=null,this.endMSE()}this.initData(),"browser"==this.env&&this.initBrowser(),k("JMuxer was reset")}},{key:"createBuffer",value:function(){if(this.mseReady&&this.remuxController&&this.remuxController.isReady()&&!this.bufferControllers)for(var e in this.bufferControllers={},this.remuxController.tracks){var t=this.remuxController.tracks[e];if(!i.isSupported("".concat(e,'/mp4; codecs="').concat(t.mp4track.codec,'"')))return b("Browser does not support codec: ".concat(e,'/mp4; codecs="').concat(t.mp4track.codec,'"')),"function"==typeof this.options.onUnsupportedCodec&&this.options.onUnsupportedCodec.call(null,t.mp4track.codec),!1;var r=this.mediaSource.addSourceBuffer("".concat(e,'/mp4; codecs="').concat(t.mp4track.codec,'"'));this.bufferControllers[e]=new O(r,e),this.bufferControllers[e].on("error",this.onBufferError.bind(this))}}},{key:"startInterval",value:function(){var e=this;this.interval=setInterval(function(){e.options.flushingTime?e.applyAndClearBuffer():e.bufferControllers&&e.cancelDelay()},this.options.flushingTime||1e3)}},{key:"stopInterval",value:function(){this.interval&&clearInterval(this.interval)}},{key:"cancelDelay",value:function(){if(this.node.buffered&&this.node.buffered.length>0&&!this.node.seeking){var e=this.node.buffered.end(0);e-this.node.currentTime>this.options.maxDelay/1e3&&(k("delay"),this.node.paused&&this.node.play().catch(b),this.node.currentTime=e-.001)}}},{key:"releaseBuffer",value:function(){for(var e in this.bufferControllers)this.bufferControllers[e].doAppend()}},{key:"applyAndClearBuffer",value:function(){this.bufferControllers&&(this.releaseBuffer(),this.clearBuffer())}},{key:"getSafeClearOffsetOfBuffer",value:function(e){for(var t,r="audio"===this.options.mode&&e||0,n=0;n<this.kfPosition.length&&!(this.kfPosition[n]>=e);n++)t=this.kfPosition[n];return t&&(this.kfPosition=this.kfPosition.filter(function(e){return e<t&&(r=e),e>=t})),r}},{key:"clearBuffer",value:function(){if(this.options.clearBuffer&&Date.now()-this.lastCleaningTime>1e4){for(var e in this.bufferControllers){var t=this.getSafeClearOffsetOfBuffer(this.node.currentTime);this.bufferControllers[e].initCleanup(t)}this.lastCleaningTime=Date.now()}}},{key:"onBuffer",value:function(e){this.options.readFpsFromTrack&&void 0!==e.fps&&this.options.fps!=e.fps&&(this.options.fps=e.fps,this.frameDuration=Math.ceil(1e3/e.fps),k("JMuxer changed FPS to ".concat(e.fps," from track data"))),"browser"==this.env?this.bufferControllers&&this.bufferControllers[e.type]&&this.bufferControllers[e.type].feed(e.payload):this.stream&&this.stream.push(e.payload),this.options.onData&&this.options.onData(e.payload),0===this.options.flushingTime&&this.applyAndClearBuffer()}},{key:"onMSEOpen",value:function(){this.mseReady=!0,URL.revokeObjectURL(this.url),"function"==typeof this.options.onReady&&this.options.onReady.call(null,this.isReset,this.mediaSource)}},{key:"onMSEClose",value:function(){this.mseReady=!1,this.videoStarted=!1}},{key:"onBufferError",value:function(e){if("QuotaExceeded"==e.name)return k("JMuxer cleaning ".concat(e.type," buffer due to QuotaExceeded error")),void this.bufferControllers[e.type].initCleanup(this.node.currentTime);"InvalidStateError"==e.name?(k("JMuxer is reseting due to InvalidStateError"),this.reset()):this.endMSE(),"function"==typeof this.options.onError&&this.options.onError.call(null,e)}}],[{key:"isSupported",value:function(e){return window.MediaSource&&window.MediaSource.isTypeSupported(e)}}])}(U)});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("stream")):"function"==typeof define&&define.amd?define(["stream"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).JMuxer=t(e.stream)}(this,function(e){"use strict";function t(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function r(e,t,r){return t=u(t),function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,c()?Reflect.construct(t,r||[],u(e).constructor):t.apply(e,r))}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,p(n.key),n)}}function a(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function s(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=v(e))||t){r&&(e=r);var n=0,i=function(){};return{s:i,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){o=!0,a=e},f:function(){try{s||null==r.return||r.return()}finally{if(o)throw a}}}}function o(e,t,r){return(t=p(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(e){return u=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},u(e)}function l(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}function c(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(c=function(){return!!e})()}function d(e,t){return d=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},d(e,t)}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,a,s,o=[],u=!0,l=!1;try{if(a=(r=r.call(e)).next,0===t);else for(;!(u=(n=a.call(r)).done)&&(o.push(n.value),o.length!==t);u=!0);}catch(e){l=!0,i=e}finally{try{if(!u&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(l)throw i}}return o}}(e,t)||v(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||v(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e,"string");return"symbol"==typeof t?t:t+""}function y(e){return y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},y(e)}function v(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}var m,g;function k(e){if(m){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];m.apply(void 0,[e].concat(r))}}function b(e){if(g){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];g.apply(void 0,[e].concat(r))}}var U=function(){return a(function e(t){n(this,e),this.listener={},this.type=""|t},[{key:"on",value:function(e,t){return this.listener[e]||(this.listener[e]=[]),this.listener[e].push(t),!0}},{key:"off",value:function(e,t){if(this.listener[e]){var r=this.listener[e].indexOf(t);return r>-1&&this.listener[e].splice(r,1),!0}return!1}},{key:"offAll",value:function(){this.listener={}}},{key:"dispatch",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return!!this.listener[e]&&(this.listener[e].map(function(e){e.apply(null,r)}),!0)}}])}(),S=function(){function e(){n(this,e)}return a(e,null,[{key:"init",value:function(){var t;for(t in e.types={avc1:[],avcC:[],btrt:[],dinf:[],dref:[],esds:[],ftyp:[],hdlr:[],hev1:[],hvcC:[],mdat:[],mdhd:[],mdia:[],mfhd:[],minf:[],moof:[],moov:[],mp4a:[],mvex:[],mvhd:[],sdtp:[],stbl:[],stco:[],stsc:[],stsd:[],stsz:[],stts:[],tfdt:[],tfhd:[],traf:[],trak:[],trun:[],trex:[],tkhd:[],vmhd:[],smhd:[]},e.types)e.types.hasOwnProperty(t)&&(e.types[t]=[t.charCodeAt(0),t.charCodeAt(1),t.charCodeAt(2),t.charCodeAt(3)]);var r=new Uint8Array([0,0,0,0,0,0,0,0,118,105,100,101,0,0,0,0,0,0,0,0,0,0,0,0,86,105,100,101,111,72,97,110,100,108,101,114,0]),n=new Uint8Array([0,0,0,0,0,0,0,0,115,111,117,110,0,0,0,0,0,0,0,0,0,0,0,0,83,111,117,110,100,72,97,110,100,108,101,114,0]);e.HDLR_TYPES={video:r,audio:n};var i=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,12,117,114,108,32,0,0,0,1]),a=new Uint8Array([0,0,0,0,0,0,0,0]);e.STTS=e.STSC=e.STCO=a,e.STSZ=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0]),e.VMHD=new Uint8Array([0,0,0,1,0,0,0,0,0,0,0,0]),e.SMHD=new Uint8Array([0,0,0,0,0,0,0,0]),e.STSD=new Uint8Array([0,0,0,0,0,0,0,1]);var s=new Uint8Array([105,115,111,109]),o=new Uint8Array([97,118,99,49]),u=new Uint8Array([0,0,0,1]);e.FTYP=e.box(e.types.ftyp,s,u,s,o),e.DINF=e.box(e.types.dinf,e.box(e.types.dref,i))}},{key:"box",value:function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];for(var i,a=8,s=r.length,o=s;s--;)a+=r[s].byteLength;for((i=new Uint8Array(a))[0]=a>>24&255,i[1]=a>>16&255,i[2]=a>>8&255,i[3]=255&a,i.set(e,4),s=0,a=8;s<o;++s)i.set(r[s],a),a+=r[s].byteLength;return i}},{key:"hdlr",value:function(t){return e.box(e.types.hdlr,e.HDLR_TYPES[t])}},{key:"mdat",value:function(t){return e.box(e.types.mdat,t)}},{key:"mdhd",value:function(t,r){return e.box(e.types.mdhd,new Uint8Array([0,0,0,0,0,0,0,2,0,0,0,3,t>>24&255,t>>16&255,t>>8&255,255&t,r>>>24&255,r>>>16&255,r>>>8&255,255&r,85,196,0,0]))}},{key:"mdia",value:function(t){return e.box(e.types.mdia,e.mdhd(t.timescale,t.duration),e.hdlr(t.type),e.minf(t))}},{key:"mfhd",value:function(t){return e.box(e.types.mfhd,new Uint8Array([0,0,0,0,t>>24,t>>16&255,t>>8&255,255&t]))}},{key:"minf",value:function(t){return"audio"===t.type?e.box(e.types.minf,e.box(e.types.smhd,e.SMHD),e.DINF,e.stbl(t)):e.box(e.types.minf,e.box(e.types.vmhd,e.VMHD),e.DINF,e.stbl(t))}},{key:"moof",value:function(t,r,n){return e.box(e.types.moof,e.mfhd(t),e.traf(n,r))}},{key:"moov",value:function(t,r,n){for(var i=t.length,a=[];i--;)a[i]=e.trak(t[i]);return e.box.apply(null,[e.types.moov,e.mvhd(n,r)].concat(a).concat(e.mvex(t)))}},{key:"mvex",value:function(t){for(var r=t.length,n=[];r--;)n[r]=e.trex(t[r]);return e.box.apply(null,[e.types.mvex].concat(n))}},{key:"mvhd",value:function(t,r){var n=new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,2,t>>24&255,t>>16&255,t>>8&255,255&t,r>>>24&255,r>>>16&255,r>>>8&255,255&r,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255]);return e.box(e.types.mvhd,n)}},{key:"sdtp",value:function(t){var r,n,i=t.samples||[],a=new Uint8Array(4+i.length);for(n=0;n<i.length;n++)r=i[n].flags,a[n+4]=r.dependsOn<<4|r.isDependedOn<<2|r.hasRedundancy;return e.box(e.types.sdtp,a)}},{key:"stbl",value:function(t){return e.box(e.types.stbl,e.stsd(t),e.box(e.types.stts,e.STTS),e.box(e.types.stsc,e.STSC),e.box(e.types.stsz,e.STSZ),e.box(e.types.stco,e.STCO))}},{key:"avc1",value:function(t){var r,n,i,a=[],s=[];for(r=0;r<t.sps.length;r++)i=(n=t.sps[r]).byteLength,a.push(i>>>8&255),a.push(255&i),a=a.concat(Array.prototype.slice.call(n));for(r=0;r<t.pps.length;r++)i=(n=t.pps[r]).byteLength,s.push(i>>>8&255),s.push(255&i),s=s.concat(Array.prototype.slice.call(n));var o=e.box(e.types.avcC,new Uint8Array([1,a[3],a[4],a[5],255,224|t.sps.length].concat(a).concat([t.pps.length]).concat(s))),u=t.width,l=t.height;return e.box(e.types.avc1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,u>>8&255,255&u,l>>8&255,255&l,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,98,105,110,101,108,112,114,111,46,114,117,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),o,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"hev1",value:function(t){for(var r,n,i=[],a=[],s=[],o=0;o<((null===(u=t.vps)||void 0===u?void 0:u.length)||0);o++){var u;n=(r=t.vps[o]).byteLength,i.push(n>>>8&255,255&n),i=i.concat(Array.prototype.slice.call(r))}for(var l=0;l<((null===(c=t.sps)||void 0===c?void 0:c.length)||0);l++){var c;n=(r=t.sps[l]).byteLength,a.push(n>>>8&255,255&n),a=a.concat(Array.prototype.slice.call(r))}for(var d=0;d<((null===(f=t.pps)||void 0===f?void 0:f.length)||0);d++){var f;n=(r=t.pps[d]).byteLength,s.push(n>>>8&255,255&n),s=s.concat(Array.prototype.slice.call(r))}var p=t.hvcC,y=p.profile_space,v=p.tier_flag,m=p.profile_idc,g=p.profile_compatibility_flags,k=p.constraint_indicator_flags,b=p.level_idc,U=p.chroma_format_idc,S=e.box(e.types.hvcC,new Uint8Array([1,y<<6|v<<5|m,g>>24&255,g>>16&255,g>>8&255,255&g].concat(h(k),[b,240,0,252,252|U,248,248,0,0,3,3,32,t.vps.length>>>8&255,255&t.vps.length],h(i),[33,t.sps.length>>>8&255,255&t.sps.length],h(a),[34,t.pps.length>>>8&255,255&t.pps.length],h(s)))),B=t.width,w=t.height;return e.box(e.types.hev1,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,B>>8&255,255&B,w>>8&255,255&w,0,72,0,0,0,72,0,0,0,0,0,0,0,1,18,98,105,110,101,108,112,114,111,46,114,117,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,17,17]),S,e.box(e.types.btrt,new Uint8Array([0,28,156,128,0,45,198,192,0,45,198,192])))}},{key:"esds",value:function(e){var t=e.config.byteLength,r=new Uint8Array(26+t+3);return r.set([0,0,0,0,3,23+t,0,1,0,4,15+t,64,21,0,0,0,0,0,0,0,0,0,0,0,5,t]),r.set(e.config,26),r.set([6,1,2],26+t),r}},{key:"mp4a",value:function(t){var r=t.audiosamplerate;return e.box(e.types.mp4a,new Uint8Array([0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,t.channelCount,0,16,0,0,0,0,r>>8&255,255&r,0,0]),e.box(e.types.esds,e.esds(t)))}},{key:"stsd",value:function(t){return"audio"===t.type?e.box(e.types.stsd,e.STSD,e.mp4a(t)):t.codec.startsWith("hvc1")?e.box(e.types.stsd,e.STSD,e.hev1(t)):e.box(e.types.stsd,e.STSD,e.avc1(t))}},{key:"tkhd",value:function(t){var r=t.id,n=t.duration,i=t.width,a=t.height,s=t.volume;return e.box(e.types.tkhd,new Uint8Array([0,0,0,7,0,0,0,0,0,0,0,0,r>>24&255,r>>16&255,r>>8&255,255&r,0,0,0,0,n>>>24&255,n>>>16&255,n>>>8&255,255&n,0,0,0,0,0,0,0,0,0,0,0,0,255&s,s%1*10&255,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0,i>>8&255,255&i,0,0,a>>8&255,255&a,0,0]))}},{key:"traf",value:function(t,r){var n=e.sdtp(t),i=t.id;return e.box(e.types.traf,e.box(e.types.tfhd,new Uint8Array([0,0,0,0,i>>24,i>>16&255,i>>8&255,255&i])),e.box(e.types.tfdt,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r])),e.trun(t,n.length+16+16+8+16+8+8),n)}},{key:"trak",value:function(t){return t.duration=t.duration||4294967295,e.box(e.types.trak,e.tkhd(t),e.mdia(t))}},{key:"trex",value:function(t){var r=t.id;return e.box(e.types.trex,new Uint8Array([0,0,0,0,r>>24,r>>16&255,r>>8&255,255&r,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,1]))}},{key:"trun",value:function(t,r){var n,i,a,s,o,u,l=t.samples||[],c=l.length,d=12+16*c,f=new Uint8Array(d);for(r+=8+d,f.set([0,0,15,1,c>>>24&255,c>>>16&255,c>>>8&255,255&c,r>>>24&255,r>>>16&255,r>>>8&255,255&r],0),n=0;n<c;n++)a=(i=l[n]).duration,s=i.size,o=i.flags,u=i.cts,f.set([a>>>24&255,a>>>16&255,a>>>8&255,255&a,s>>>24&255,s>>>16&255,s>>>8&255,255&s,o.isLeading<<2|o.dependsOn,o.isDependedOn<<6|o.hasRedundancy<<4|o.paddingValue<<1|o.isNonSync,61440&o.degradPrio,15&o.degradPrio,u>>>24&255,u>>>16&255,u>>>8&255,255&u],12+16*n);return e.box(e.types.trun,f)}},{key:"initSegment",value:function(t,r,n){e.types||e.init();var i,a=e.moov(t,r,n);return(i=new Uint8Array(e.FTYP.byteLength+a.byteLength)).set(e.FTYP),i.set(a,e.FTYP.byteLength),i}}])}(),B=function(){function e(){n(this,e)}return a(e,null,[{key:"samplingRateMap",get:function(){return[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350]}},{key:"getHeaderLength",value:function(e){return 1&e[1]?7:9}},{key:"getFrameLength",value:function(e){return(3&e[3])<<11|e[4]<<3|(224&e[5])>>>5}},{key:"isAACPattern",value:function(e){return!(255!==e[0]||240&~e[1]||6&e[1])}},{key:"extractAAC",value:function(t){var r,n,i=0,a=t.byteLength,s=[];if(!e.isAACPattern(t))return b("Invalid ADTS audio format"),{valid:!1};r=e.getHeaderLength(t);for(var o=t.subarray(0,r);i<a;)n=e.getFrameLength(t),s.push(t.subarray(r,n)),t=t.slice(n),i+=n;return{valid:!0,header:o,slices:s}}}])}(),w=1,E=function(e){function t(){return n(this,t),r(this,t,arguments)}return l(t,e),a(t,[{key:"flush",value:function(){this.mp4track.len=0,this.mp4track.samples=[]}},{key:"isReady",value:function(){return!(!this.readyToDecode||!this.samples.length)||null}}],[{key:"getTrackID",value:function(){return w++}}])}(U),A=function(e){function t(e,i,a){var s;return n(this,t),(s=r(this,t,["AACRemuxer"])).frameDuration=a,s.readyToDecode=!1,s.header=null,s.nextDts=0,s.dts=0,s.mp4track={id:E.getTrackID(),type:"audio",channelCount:0,len:0,fragmented:!0,timescale:e,duration:i,samples:[],config:"",codec:""},s.samples=[],s}return l(t,e),a(t,[{key:"resetTrack",value:function(){this.readyToDecode=!1,this.header=null,this.mp4track.codec="",this.mp4track.channelCount="",this.mp4track.config="",this.mp4track.timescale=this.timescale,this.nextDts=0,this.dts=0}},{key:"feed",value:function(e,t){var r=B.extractAAC(e),n=r.valid,i=r.header,a=r.slices;return this.header||(this.header=i),n&&a.length>0?(this.remux(this.getAudioFrames(a,t)),!0):(b("Failed to extract audio data from:",e),this.dispatch("outOfData"),!1)}},{key:"getAudioFrames",value:function(e,t){var r,n,i=[],a=0,o=s(e);try{for(o.s();!(n=o.n()).done;){var u=n.value;i.push({units:u})}}catch(e){o.e(e)}finally{o.f()}return r=t?t/i.length|0:this.frameDuration,a=t?t-r*i.length:0,i.map(function(e){e.duration=r,a>0&&(e.duration++,a--)}),i}},{key:"remux",value:function(e){if(e.length>0)for(var t=0;t<e.length;t++){var r=e[t],n=r.units,i=n.byteLength;this.samples.push({units:n,size:i,duration:r.duration}),this.mp4track.len+=i,this.readyToDecode||this.setAACConfig()}}},{key:"getPayload",value:function(){if(!this.isReady())return null;var e,t,r=new Uint8Array(this.mp4track.len),n=0,i=this.mp4track.samples;for(this.dts=this.nextDts;this.samples.length;){var a=this.samples.shift();a.units,(t=a.duration)<=0?(k("remuxer: invalid sample duration at DTS: ".concat(this.nextDts," :").concat(t)),this.mp4track.len-=a.size):(this.nextDts+=t,e={size:a.size,duration:t,cts:0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,dependsOn:1}},r.set(a.units,n),n+=a.size,i.push(e))}return i.length?new Uint8Array(r.buffer,0,this.mp4track.len):null}},{key:"setAACConfig",value:function(){var e,t,r,n=new Uint8Array(2);this.header&&(e=((192&this.header[2])>>>6)+1,t=(60&this.header[2])>>>2,r=(1&this.header[2])<<2,r|=(192&this.header[3])>>>6,n[0]=e<<3,n[0]|=(14&t)>>1,n[1]|=(1&t)<<7,n[1]|=r<<3,this.mp4track.codec="mp4a.40."+e,this.mp4track.channelCount=r,this.mp4track.config=n,this.readyToDecode=!0)}}])}(E),D=function(){return a(function e(t){n(this,e),this.data=t,this.index=0,this.bitLength=8*t.byteLength},[{key:"setData",value:function(e){this.data=e,this.index=0,this.bitLength=8*e.byteLength}},{key:"bitsAvailable",get:function(){return this.bitLength-this.index}},{key:"skipBits",value:function(e){if(this.bitsAvailable<e)return!1;this.index+=e}},{key:"readBits",value:function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];return this.getBits(e,this.index,t)}},{key:"getBits",value:function(e,t){var r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2];if(this.bitsAvailable<e)return 0;var n=t%8,i=this.data[t/8|0]&255>>>n,a=8-n;if(a>=e)return r&&(this.index+=e),i>>a-e;r&&(this.index+=a);var s=e-a;return i<<s|this.getBits(s,t+a,r)}},{key:"skipLZ",value:function(){var e;for(e=0;e<this.bitLength-this.index;++e)if(0!==this.getBits(1,this.index+e,!1))return this.index+=e,e;return e}},{key:"skipUEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"skipEG",value:function(){this.skipBits(1+this.skipLZ())}},{key:"readUEG",value:function(){var e=this.skipLZ();return this.readBits(e+1)-1}},{key:"readEG",value:function(){var e=this.readUEG();return 1&e?1+e>>>1:-1*(e>>>1)}},{key:"readBoolean",value:function(){return 1===this.readBits(1)}},{key:"readUByte",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1;return this.readBits(8*e)}},{key:"readUShort",value:function(){return this.readBits(16)}},{key:"readUInt",value:function(){return this.readBits(32)}}])}(),x=function(){function e(){n(this,e)}return a(e,null,[{key:"extractNALu",value:function(e){for(var t=0,r=e.byteLength,n=[],i=0,a=0;t<r;){var s=e[t++];if(0===s)a++;else if(1===s&&a>=2){var o=a+1;i!==t-o&&n.push(e.subarray(i,t-o)),i=t,a=0}else a=0}var u=null;return i<r&&(u=e.subarray(i,r)),[n,u]}},{key:"skipScalingList",value:function(e,t){for(var r=8,n=8,i=0;i<t;i++)0!==n&&(n=(r+e.readEG()+256)%256),r=0===n?r:n}},{key:"readSPS",value:function(t){var r,n,i,a,s,o,u=new D(t),l=0,c=0,d=0,f=0,h=1,p=0;u.readUByte();for(var y=[],v=t.byteLength,m=1;m<v;m++)m+2<v&&3===u.readBits(24,!1)?(y.push(u.readBits(8)),y.push(u.readBits(8)),m+=2,u.readBits(8)):y.push(u.readBits(8));if(u.setData(new Uint8Array(y)),r=u.readUByte(),u.readBits(5),u.skipBits(3),u.readUByte(),u.skipUEG(),100===r||110===r||122===r||244===r||44===r||83===r||86===r||118===r||128===r){var g=u.readUEG();if(3===g&&u.skipBits(1),u.skipUEG(),u.skipUEG(),u.skipBits(1),u.readBoolean()){o=3!==g?8:12;for(var k=0;k<o;++k)u.readBoolean()&&(k<6?e.skipScalingList(u,16):e.skipScalingList(u,64))}}u.skipUEG();var b=u.readUEG();if(0===b)u.readUEG();else if(1===b){u.skipBits(1),u.skipEG(),u.skipEG(),n=u.readUEG();for(var U=0;U<n;++U)u.skipEG()}if(u.skipUEG(),u.skipBits(1),i=u.readUEG(),a=u.readUEG(),0===(s=u.readBits(1))&&u.skipBits(1),u.skipBits(1),u.readBoolean()&&(l=u.readUEG(),c=u.readUEG(),d=u.readUEG(),f=u.readUEG()),u.readBoolean()){if(u.readBoolean()){var S;switch(u.readUByte()){case 1:S=[1,1];break;case 2:S=[12,11];break;case 3:S=[10,11];break;case 4:S=[16,11];break;case 5:S=[40,33];break;case 6:S=[24,11];break;case 7:S=[20,11];break;case 8:S=[32,11];break;case 9:S=[80,33];break;case 10:S=[18,11];break;case 11:S=[15,11];break;case 12:S=[64,33];break;case 13:S=[160,99];break;case 14:S=[4,3];break;case 15:S=[3,2];break;case 16:S=[2,1];break;case 255:S=[u.readUByte()<<8|u.readUByte(),u.readUByte()<<8|u.readUByte()]}S&&S[0]>0&&S[1]>0&&(h=S[0]/S[1])}if(u.readBoolean()&&u.skipBits(1),u.readBoolean()&&(u.skipBits(4),u.readBoolean()&&u.skipBits(24)),u.readBoolean()&&(u.skipUEG(),u.skipUEG()),u.readBoolean()){var B=u.readUInt(),w=u.readUInt();u.readBoolean(),p=w/(2*B)}}return{fps:p>0?p:void 0,width:Math.ceil((16*(i+1)-2*l-2*c)*h),height:(2-s)*(a+1)*16-(s?2:4)*(d+f)}}}])}(),C=function(){function e(t){n(this,e),this.payload=t,this.nri=(96&this.payload[0])>>5,this.nalUnitType=31&this.payload[0],this._sliceType=null,this._isFirstSlice=!1}return a(e,[{key:"toString",value:function(){return"".concat(e.TYPES[this.type()]||"UNKNOWN",": NRI: ").concat(this.getNri())}},{key:"getNri",value:function(){return this.nri}},{key:"type",value:function(){return this.nalUnitType}},{key:"isKeyframe",get:function(){return this.nalUnitType===e.IDR}},{key:"isVCL",get:function(){return this.nalUnitType==e.IDR||this.nalUnitType==e.NDR}},{key:"parseHeader",value:function(){var e=new D(this.getPayload());e.readUByte(),this._isFirstSlice=0===e.readUEG(),this._sliceType=e.readUEG()}},{key:"isFirstSlice",get:function(){return this._isFirstSlice||this.parseHeader(),this._isFirstSlice}},{key:"sliceType",get:function(){return this._sliceType||this.parseHeader(),this._sliceType}},{key:"getPayload",value:function(){return this.payload}},{key:"getPayloadSize",value:function(){return this.payload.byteLength}},{key:"getSize",value:function(){return 4+this.getPayloadSize()}},{key:"getData",value:function(){var e=new Uint8Array(this.getSize());return new DataView(e.buffer).setUint32(0,this.getSize()-4),e.set(this.getPayload(),4),e}}],[{key:"NDR",get:function(){return 1}},{key:"IDR",get:function(){return 5}},{key:"SEI",get:function(){return 6}},{key:"SPS",get:function(){return 7}},{key:"PPS",get:function(){return 8}},{key:"AUD",get:function(){return 9}},{key:"TYPES",get:function(){return o(o(o(o(o(o({},e.IDR,"IDR"),e.SEI,"SEI"),e.SPS,"SPS"),e.PPS,"PPS"),e.NDR,"NDR"),e.AUD,"AUD")}}])}();function P(e,t){var r=new Uint8Array((0|e.byteLength)+(0|t.byteLength));return r.set(e,0),r.set(t,0|e.byteLength),r}function T(e){var t,r,n,i="";return t=Math.floor(e),(r=parseInt(t/3600,10)%24)>0&&(i+=(r<10?"0"+r:r)+":"),i+=((n=parseInt(t/60,10)%60)<10?"0"+n:n)+":"+((t=t<0?0:t%60)<10?"0"+t:t)}function L(e,t){if(e.length!==t.length)return!1;for(var r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}var _=function(e){function t(e,i,a){var s;return n(this,t),(s=r(this,t,["H264Remuxer"])).frameDuration=a,s.readyToDecode=!1,s.nextDts=0,s.dts=0,s.mp4track={id:E.getTrackID(),type:"video",len:0,fragmented:!0,sps:[],pps:[],fps:30,width:0,height:0,timescale:e,duration:i,samples:[]},s.samples=[],s.remainingData=new Uint8Array,s.kfCounter=0,s.pendingUnits={},s}return l(t,e),a(t,[{key:"resetTrack",value:function(){this.readyToDecode=!1,this.mp4track.sps=[],this.mp4track.pps=[],this.nextDts=0,this.dts=0,this.remainingData=new Uint8Array,this.kfCounter=0,this.pendingUnits={}}},{key:"feed",value:function(e,t,r){var n,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=[];e=P(this.remainingData,e);var s=f(x.extractNALu(e),2);return a=s[0],(n=s[1])?i?(a.push(n),this.remainingData=new Uint8Array):this.remainingData=n:this.remainingData=new Uint8Array,a.length>0?(this.remux(this.getVideoFrames(a,t,r)),!0):(k("Failed to extract any NAL units from video data:",n),this.dispatch("outOfData"),!1)}},{key:"getVideoFrames",value:function(e,t,r){var n,i=this,a=[],o=[],u=0,l=!1,c=!1;this.pendingUnits.units&&(a=this.pendingUnits.units,c=this.pendingUnits.vcl,l=this.pendingUnits.keyFrame,this.pendingUnits={});var d,f=s(e);try{for(f.s();!(d=f.n()).done;){var h=d.value,p=new C(h);this.parseNAL(p)&&(a.length&&c&&(p.isFirstSlice||!p.isVCL)&&(o.push({units:a,keyFrame:l}),a=[],l=!1,c=!1),a.push(p),l=l||p.isKeyframe,c=c||p.isVCL)}}catch(e){f.e(e)}finally{f.f()}if(a.length)if(t)if(c)o.push({units:a,keyFrame:l});else{var y=o.length-1;y>=0&&(o[y].units=o[y].units.concat(a))}else this.pendingUnits={units:a,keyFrame:l,vcl:c};return n=t?t/o.length|0:this.frameDuration,u=t?t-n*o.length:0,o.map(function(e){e.duration=n,e.compositionTimeOffset=r,u>0&&(e.duration++,u--),i.kfCounter++,e.keyFrame&&i.dispatch("keyframePosition",i.kfCounter*n/1e3)}),k("jmuxer: No. of H264 frames of the last chunk: ".concat(o.length)),o}},{key:"remux",value:function(e){var t,r=s(e);try{for(r.s();!(t=r.n()).done;){var n=t.value,i=n.units.reduce(function(e,t){return e+t.getSize()},0);n.units.length>0&&this.readyToDecode&&(this.mp4track.len+=i,this.samples.push({units:n.units,size:i,keyFrame:n.keyFrame,duration:n.duration,compositionTimeOffset:n.compositionTimeOffset}))}}catch(e){r.e(e)}finally{r.f()}}},{key:"getPayload",value:function(){if(!this.isReady())return null;var e,t,r=new Uint8Array(this.mp4track.len),n=0,i=this.mp4track.samples;for(this.dts=this.nextDts;this.samples.length;){var a=this.samples.shift(),o=a.units;if((t=a.duration)<=0)k("remuxer: invalid sample duration at DTS: ".concat(this.nextDts," :").concat(t)),this.mp4track.len-=a.size;else{this.nextDts+=t,e={size:a.size,duration:t,cts:a.compositionTimeOffset||0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,isNonSync:a.keyFrame?0:1,dependsOn:a.keyFrame?2:1}};var u,l=s(o);try{for(l.s();!(u=l.n()).done;){var c=u.value;r.set(c.getData(),n),n+=c.getSize()}}catch(e){l.e(e)}finally{l.f()}i.push(e)}}return i.length?new Uint8Array(r.buffer,0,this.mp4track.len):null}},{key:"parseSPS",value:function(e){var t=x.readSPS(new Uint8Array(e));this.mp4track.fps=t.fps||this.mp4track.fps,this.mp4track.width=t.width,this.mp4track.height=t.height,this.mp4track.sps=[new Uint8Array(e)],this.mp4track.codec="avc1.";for(var r=new DataView(e.buffer,e.byteOffset+1,4),n=0;n<3;++n){var i=r.getUint8(n).toString(16);i.length<2&&(i="0"+i),this.mp4track.codec+=i}}},{key:"parsePPS",value:function(e){var t,r=s(this.mp4track.pps);try{for(r.s();!(t=r.n()).done;){if(L(t.value,e))return}}catch(e){r.e(e)}finally{r.f()}this.mp4track.pps.push(new Uint8Array(e))}},{key:"parseNAL",value:function(e){if(!e)return!1;if(e.isVCL)return!0;var t=!1;switch(e.type()){case C.PPS:this.parsePPS(e.getPayload()),t=!0;break;case C.SPS:this.mp4track.sps.length||this.parseSPS(e.getPayload()),t=!0;break;case C.AUD:k("AUD - ignoing");break;case C.SEI:k("SEI - ignoing")}return!this.readyToDecode&&this.mp4track.pps.length&&this.mp4track.sps.length&&(this.readyToDecode=!0),t}}])}(E),G=function(){return a(function e(){n(this,e)},null,[{key:"extractNALu",value:function(e){for(var t=0,r=e.byteLength,n=[],i=0,a=0;t<r;){var s=e[t++];if(0===s)a++;else if(1===s&&a>=2){var o=a+1;i!==t-o&&n.push(e.subarray(i,t-o)),i=t,a=0}else a=0}var u=null;return i<r&&(u=e.subarray(i,r)),[n,u]}},{key:"removeEmulationPreventionBytes",value:function(e){for(var t=[],r=0,n=0;n<e.length;n++){var i=e[n];2!==r||3!==i?(t.push(i),0===i?r++:r=0):r=0}return new Uint8Array(t)}},{key:"readSPS",value:function(e){var t=new D(e);t.readUByte(),t.readUByte(),t.readBits(4);var r=t.readBits(3);t.readBits(1);for(var n=t.readBits(2),i=t.readBits(1),a=t.readBits(5),s=t.readUInt(),o=new Uint8Array(6),u=0;u<6;u++)o[u]=t.readUByte();var l=t.readUByte();t.readUEG();var c=t.readUEG();3===c&&t.readBits(1);var d=t.readUEG(),f=t.readUEG(),h=0,p=0,y=0,v=0;t.readBoolean()&&(h=t.readUEG(),p=t.readUEG(),y=t.readUEG(),v=t.readUEG()),t.readUEG(),t.readUEG(),t.readUEG();for(var m=t.readBits(1)?0:r;m<=r;m++)t.readUEG(),t.readUEG(),t.readUEG();if((t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG(),t.readBits(1))&&t.readBits(1))for(var g=0;g<4;g++)for(var k=0;k<(3===g?2:6);k++){if(t.readBits(1)){var b=Math.min(64,1<<4+(g<<1));g>1&&t.readEG();for(var U=0;U<b;U++)t.readEG()}else t.readUEG()}t.readBits(1),t.readBits(1),t.readBits(1)&&(t.readBits(4),t.readBits(4),t.readUEG(),t.readUEG(),t.readBits(1));for(var S=t.readUEG(),B=0;B<S;B++){var w=!1;if(0!==B&&(w=t.readBoolean()),w)t.readUEG(),t.readBits(1),t.readUEG();else{for(var E=t.readUEG(),A=t.readUEG(),x=0;x<E;x++)t.readUEG(),t.readBits(1);for(var C=0;C<A;C++)t.readUEG(),t.readBits(1)}}if(t.readBits(1))for(var P=t.readUEG(),T=0;T<P;T++)t.readUEG(),t.readBits(1);t.readBits(1),t.readBits(1);var L=null;if(t.readBoolean()){if(t.readBoolean())255===t.readUByte()&&(t.readUShort(),t.readUShort());if(t.readBoolean()&&t.readBoolean(),t.readBoolean())t.readBits(3),t.readBoolean(),t.readBoolean()&&(t.readUByte(),t.readUByte(),t.readUByte());if(t.readBoolean()&&(t.readUEG(),t.readUEG()),t.readBoolean(),t.readBoolean(),t.readBoolean(),t.readBoolean()&&(t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG()),t.readBoolean()){var _=t.readUInt(),G=t.readUInt();if(t.readBoolean()&&t.readUEG(),t.readBoolean()){var I=!1,R=!1,O=!1;I=t.readBoolean(),R=t.readBoolean(),(I||R)&&((O=t.readBoolean())&&(t.readBits(8),t.readBits(5),t.readBits(1),t.readBits(5)),t.readBits(4),t.readBits(4),O&&t.readBits(4),t.readBits(5),t.readBits(5),t.readBits(5));for(var F=0;F<=r;F++){var M=!1,N=0;if(!!t.readBoolean()||t.readBoolean()?t.readUEG():M=t.readBoolean(),M||(N=t.readUEG()),I)for(var z=0;z<=N;z++)t.readUEG(),t.readUEG(),O&&(t.readUEG(),t.readUEG()),t.readBits(1);if(R)for(var j=0;j<=N;j++)t.readUEG(),t.readUEG(),O&&(t.readUEG(),t.readUEG()),t.readBits(1)}}_>0&&G>0&&(L=G/_)}t.readBoolean()&&(t.readBoolean(),t.readBoolean(),t.readBoolean(),t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG(),t.readUEG())}return{width:d-(1===c||2===c?2:1)*(p+h),height:f-(1===c?2:1)*(y+v),profile_space:n,tier_flag:i,profile_idc:a,profile_compatibility_flags:s,constraint_indicator_flags:o,level_idc:l,chroma_format_idc:c,fps:L}}}])}(),I=function(){function e(t){n(this,e),this.payload=t,this.nalUnitType=(126&t[0])>>1,this.nuhLayerId=(1&t[0])<<5|(248&t[1])>>3,this.nuhTemporalIdPlus1=7&t[1],this._isFirstSlice=null,this._sliceType=null}return a(e,[{key:"toString",value:function(){return"".concat(e.TYPES[this.type()]||"UNKNOWN ("+this.type()+")",": Layer: ").concat(this.nuhLayerId,", Temporal Id: ").concat(this.nuhTemporalIdPlus1)}},{key:"type",value:function(){return this.nalUnitType}},{key:"isKeyframe",get:function(){return[e.IDR_W_RADL,e.IDR_N_LP,e.CRA].includes(this.nalUnitType)}},{key:"isVCL",get:function(){return this.nalUnitType<=31}},{key:"parseHeader",value:function(){var e=new D(this.getPayload());e.readUByte(),e.readUByte(),this._isFirstSlice=e.readBoolean(),this.isKeyframe&&e.readBits(1),e.readUEG(),this._sliceType=e.readUEG()}},{key:"isFirstSlice",get:function(){return this._isFirstSlice||this.parseHeader(),this._isFirstSlice}},{key:"sliceType",get:function(){return this._sliceType||this.parseHeader(),this._sliceType}},{key:"getPayload",value:function(){return this.payload}},{key:"getPayloadSize",value:function(){return this.payload.byteLength}},{key:"getSize",value:function(){return 4+this.getPayloadSize()}},{key:"getData",value:function(){var e=new Uint8Array(this.getSize());return new DataView(e.buffer).setUint32(0,this.getSize()-4),e.set(this.getPayload(),4),e}}],[{key:"TRAIL_N",get:function(){return 0}},{key:"TRAIL_R",get:function(){return 1}},{key:"IDR_W_RADL",get:function(){return 19}},{key:"IDR_N_LP",get:function(){return 20}},{key:"CRA",get:function(){return 21}},{key:"VPS",get:function(){return 32}},{key:"SPS",get:function(){return 33}},{key:"PPS",get:function(){return 34}},{key:"AUD",get:function(){return 35}},{key:"SEI",get:function(){return 39}},{key:"SEI2",get:function(){return 40}},{key:"TYPES",get:function(){var t;return o(o(o(o(o(o(o(o(o(o(t={},e.TRAIL_N,"TRAIL_N"),e.TRAIL_R,"TRAIL_R"),e.IDR_W_RADL,"IDR"),e.IDR_N_LP,"IDR2"),e.CRA,"CRA"),e.VPS,"VPS"),e.SPS,"SPS"),e.PPS,"PPS"),e.AUD,"AUD"),e.SEI,"SEI"),o(t,e.SEI2,"SEI2")}}])}(),R=function(e){function t(e,i,a){var s;return n(this,t),(s=r(this,t,["H264Remuxer"])).frameDuration=a,s.readyToDecode=!1,s.nextDts=0,s.dts=0,s.mp4track={id:E.getTrackID(),type:"video",len:0,fragmented:!0,vps:[],sps:[],pps:[],hvcC:{},fps:30,width:0,height:0,timescale:e,duration:i,samples:[]},s.samples=[],s.remainingData=new Uint8Array,s.kfCounter=0,s.pendingUnits={},s}return l(t,e),a(t,[{key:"resetTrack",value:function(){this.readyToDecode=!1,this.mp4track.vps=[],this.mp4track.sps=[],this.mp4track.pps=[],this.mp4track.hvcC={},this.nextDts=0,this.dts=0,this.remainingData=new Uint8Array,this.kfCounter=0,this.pendingUnits={}}},{key:"feed",value:function(e,t,r){var n,i=arguments.length>3&&void 0!==arguments[3]&&arguments[3],a=[];e=P(this.remainingData,e);var s=f(G.extractNALu(e),2);return a=s[0],(n=s[1])?i?(a.push(n),this.remainingData=new Uint8Array):this.remainingData=n:this.remainingData=new Uint8Array,a.length>0?(this.remux(this.getVideoFrames(a,t,r)),!0):(k("Failed to extract any NAL units from video data:",n),this.dispatch("outOfData"),!1)}},{key:"getVideoFrames",value:function(e,t,r){var n,i=this,a=[],o=[],u=0,l=!1,c=!1;this.pendingUnits.units&&(a=this.pendingUnits.units,c=this.pendingUnits.vcl,l=this.pendingUnits.keyFrame,this.pendingUnits={});var d,f=s(e);try{for(f.s();!(d=f.n()).done;){var h=d.value,p=new I(h);this.parseNAL(p)&&(a.length&&c&&(p.isFirstSlice||!p.isVCL)&&(o.push({units:a,keyFrame:l}),a=[],l=!1,c=!1),a.push(p),l=l||p.isKeyframe,c=c||p.isVCL)}}catch(e){f.e(e)}finally{f.f()}if(a.length)if(t)if(c)o.push({units:a,keyFrame:l});else{var y=o.length-1;y>=0&&(o[y].units=o[y].units.concat(a))}else this.pendingUnits={units:a,keyFrame:l,vcl:c};return n=t?t/o.length|0:this.frameDuration,u=t?t-n*o.length:0,o.map(function(e){e.duration=n,e.compositionTimeOffset=r,u>0&&(e.duration++,u--),i.kfCounter++,e.keyFrame&&i.dispatch("keyframePosition",i.kfCounter*n/1e3)}),k("jmuxer: No. of H265 frames of the last chunk: ".concat(o.length)),o}},{key:"remux",value:function(e){var t,r=s(e);try{for(r.s();!(t=r.n()).done;){var n=t.value,i=n.units.reduce(function(e,t){return e+t.getSize()},0);n.units.length>0&&this.readyToDecode&&(this.mp4track.len+=i,this.samples.push({units:n.units,size:i,keyFrame:n.keyFrame,duration:n.duration,compositionTimeOffset:n.compositionTimeOffset}))}}catch(e){r.e(e)}finally{r.f()}}},{key:"getPayload",value:function(){if(!this.isReady())return null;var e,t,r=new Uint8Array(this.mp4track.len),n=0,i=this.mp4track.samples;for(this.dts=this.nextDts;this.samples.length;){var a=this.samples.shift(),o=a.units;if((t=a.duration)<=0)k("remuxer: invalid sample duration at DTS: ".concat(this.nextDts," :").concat(t)),this.mp4track.len-=a.size;else{this.nextDts+=t,e={size:a.size,duration:t,cts:a.compositionTimeOffset||0,flags:{isLeading:0,isDependedOn:0,hasRedundancy:0,degradPrio:0,isNonSync:a.keyFrame?0:1,dependsOn:a.keyFrame?2:1}};var u,l=s(o);try{for(l.s();!(u=l.n()).done;){var c=u.value;r.set(c.getData(),n),n+=c.getSize()}}catch(e){l.e(e)}finally{l.f()}i.push(e)}}return i.length?new Uint8Array(r.buffer,0,this.mp4track.len):null}},{key:"parseSPS",value:function(e){this.mp4track.sps=[new Uint8Array(e)],e=G.removeEmulationPreventionBytes(e);var t=G.readSPS(new Uint8Array(e));this.mp4track.fps=t.fps||this.mp4track.fps,this.mp4track.width=t.width,this.mp4track.height=t.height,this.mp4track.codec="hvc1."+(t.profile_space?String.fromCharCode(64+t.profile_space):"")+t.profile_idc+"."+function(e){for(var t=0,r=0;r<32;r++)t<<=1,t|=1&e,e>>>=1;return t>>>0}(t.profile_compatibility_flags).toString(16)+"."+(t.tier_flag?"H":"L")+t.level_idc+"."+t.constraint_indicator_flags.map(function(e){return e.toString(16)}).join(".").toUpperCase().replace(/(?:\.0)+$/,""),this.mp4track.hvcC={profile_space:t.profile_space,tier_flag:t.tier_flag,profile_idc:t.profile_idc,profile_compatibility_flags:t.profile_compatibility_flags,constraint_indicator_flags:t.constraint_indicator_flags,level_idc:t.level_idc,chroma_format_idc:t.chroma_format_idc}}},{key:"parsePPS",value:function(e){var t,r=s(this.mp4track.pps);try{for(r.s();!(t=r.n()).done;){if(L(t.value,e))return}}catch(e){r.e(e)}finally{r.f()}this.mp4track.pps.push(new Uint8Array(e))}},{key:"parseVPS",value:function(e){this.mp4track.vps=[new Uint8Array(e)]}},{key:"parseNAL",value:function(e){if(!e)return!1;if(e.isVCL)return!0;var t=!1;switch(e.type()){case I.VPS:this.mp4track.vps.length||this.parseVPS(e.getPayload()),t=!0;break;case I.SPS:this.mp4track.sps.length||this.parseSPS(e.getPayload()),t=!0;break;case I.PPS:this.parsePPS(e.getPayload()),t=!0;break;case I.AUD:k("AUD - ignoing");break;case I.SEI:case I.SEI2:k("SEI - ignoing")}return!this.readyToDecode&&this.mp4track.vps.length&&this.mp4track.sps.length&&this.mp4track.pps.length&&(this.readyToDecode=!0),t}}])}(E),O=function(e){function t(e,i,a,s){var o;return n(this,t),(o=r(this,t,["remuxer"])).videoCodec=a,o.frameDuration=s,o.initialized=!1,o.tracks={},o.seq=1,o.env=e,o.timescale=1e3,o.mediaDuration=i?4294967295:0,o}return l(t,e),a(t,[{key:"addTrack",value:function(e){var t=this;if("video"!==e&&"both"!==e||("H265"==this.videoCodec?this.tracks.video=new R(this.timescale,this.mediaDuration,this.frameDuration):this.tracks.video=new _(this.timescale,this.mediaDuration,this.frameDuration),this.tracks.video.on("outOfData",function(){t.dispatch("missingVideoFrames")}),this.tracks.video.on("keyframePosition",function(e){t.dispatch("keyframePosition",e)})),"audio"===e||"both"===e){var r=new A(this.timescale,this.mediaDuration,this.frameDuration);this.tracks.audio=r,this.tracks.audio.on("outOfData",function(){t.dispatch("missingAudioFrames")})}}},{key:"reset",value:function(){for(var e in this.tracks)this.tracks[e].resetTrack();this.initialized=!1}},{key:"destroy",value:function(){this.tracks={},this.offAll()}},{key:"flush",value:function(){if(!this.initialized){if(!this.isReady())return;this.dispatch("ready"),this.initSegment(),this.initialized=!0}for(var e in this.tracks){var t=this.tracks[e],r=t.getPayload();if(r&&r.byteLength){var n={type:e,payload:P(S.moof(this.seq,t.dts,t.mp4track),S.mdat(r)),dts:t.dts};"video"===e&&(n.fps=t.mp4track.fps),this.dispatch("buffer",n);var i=T(t.dts/this.timescale);k("put segment (".concat(e,"): dts: ").concat(t.dts," frames: ").concat(t.mp4track.samples.length," second: ").concat(i)),t.flush(),this.seq++}}}},{key:"initSegment",value:function(){var e=[];for(var t in this.tracks){var r=this.tracks[t];if("browser"==this.env){var n={type:t,payload:S.initSegment([r.mp4track],this.mediaDuration,this.timescale)};this.dispatch("buffer",n)}else e.push(r.mp4track)}if("node"==this.env){var i={type:"all",payload:S.initSegment(e,this.mediaDuration,this.timescale)};this.dispatch("buffer",i)}k("Initial segment generated.")}},{key:"isReady",value:function(){for(var e in this.tracks)if(!this.tracks[e].readyToDecode||!this.tracks[e].samples.length)return!1;return!0}},{key:"feed",value:function(e){var t=!1;e.video&&this.tracks.video&&(t|=this.tracks.video.feed(e.video,e.duration,e.compositionTimeOffset,e.isLastVideoFrameComplete)),e.audio&&this.tracks.audio&&(t|=this.tracks.audio.feed(e.audio,e.duration)),t?this.flush():b("Input object must have video and/or audio property. Make sure it is a valid typed array")}}])}(U),F=function(e){function t(e,i){var a;return n(this,t),(a=r(this,t,["buffer"])).type=i,a.queue=new Uint8Array,a.cleaning=!1,a.pendingCleaning=0,a.cleanOffset=30,a.cleanRanges=[],a.sourceBuffer=e,a.sourceBuffer.addEventListener("updateend",function(){a.pendingCleaning>0&&(a.initCleanup(a.pendingCleaning),a.pendingCleaning=0),a.cleaning=!1,a.cleanRanges.length&&a.doCleanup()}),a.sourceBuffer.addEventListener("error",function(){a.dispatch("error",{type:a.type,name:"buffer",error:"buffer error"})}),a}return l(t,e),a(t,[{key:"destroy",value:function(){this.queue=null,this.sourceBuffer=null,this.offAll()}},{key:"doCleanup",value:function(){if(this.cleanRanges.length){var e=this.cleanRanges.shift();k("".concat(this.type," remove range [").concat(e[0]," - ").concat(e[1],")")),this.cleaning=!0,this.sourceBuffer.remove(e[0],e[1])}else this.cleaning=!1}},{key:"initCleanup",value:function(e){try{if(this.sourceBuffer.updating)return void(this.pendingCleaning=e);if(this.sourceBuffer.buffered&&this.sourceBuffer.buffered.length&&!this.cleaning){for(var t=0;t<this.sourceBuffer.buffered.length;++t){var r=this.sourceBuffer.buffered.start(t),n=this.sourceBuffer.buffered.end(t);e-r>this.cleanOffset&&r<(n=e-this.cleanOffset)&&this.cleanRanges.push([r,n])}this.doCleanup()}}catch(e){b("Error occured while cleaning ".concat(this.type," buffer - ").concat(e.name,": ").concat(e.message))}}},{key:"doAppend",value:function(){if(this.queue.length&&this.sourceBuffer&&!this.sourceBuffer.updating)try{this.sourceBuffer.appendBuffer(this.queue),this.queue=new Uint8Array}catch(t){var e="unexpectedError";"QuotaExceededError"===t.name?(k("".concat(this.type," buffer quota full")),e="QuotaExceeded"):(b("Error occured while appending ".concat(this.type," buffer - ").concat(t.name,": ").concat(t.message)),e="InvalidStateError"),this.dispatch("error",{type:this.type,name:e,error:"buffer error"})}}},{key:"feed",value:function(e){this.queue=P(this.queue,e)}}])}(U);return function(t){function i(e){var t;n(this,i),(t=r(this,i,["jmuxer"])).isReset=!1;var a={node:"",mode:"both",videoCodec:"H264",flushingTime:500,maxDelay:500,clearBuffer:!0,fps:30,readFpsFromTrack:!1,debug:!1,onReady:function(){},onData:function(){},onError:function(){},onUnsupportedCodec:function(){},onMissingVideoFrames:function(){},onMissingAudioFrames:function(){},onKeyframePosition:function(){},onLoggerLog:console.log,onLoggerErr:console.error};return t.options=Object.assign({},a,e),t.env="object"===("undefined"==typeof process?"undefined":y(process))&&"undefined"==typeof window?"node":"browser",t.options.debug&&function(e,t){m=e,g=t}(t.options.onLoggerLog,t.options.onLoggerErr),t.options.fps||(t.options.fps=30),t.frameDuration=1e3/t.options.fps|0,t.remuxController=new O(t.env,e.live,t.options.videoCodec,t.frameDuration),t.remuxController.addTrack(t.options.mode),t.initData(),t.remuxController.on("buffer",t.onBuffer.bind(t)),"browser"==t.env&&(t.remuxController.on("ready",t.createBuffer.bind(t)),t.initBrowser()),t.remuxController.on("missingVideoFrames",function(){"function"==typeof t.options.onMissingVideoFrames&&t.options.onMissingVideoFrames.call(null)}),t.remuxController.on("missingAudioFrames",function(){"function"==typeof t.options.onMissingAudioFrames&&t.options.onMissingAudioFrames.call(null)}),t.clearBuffer&&t.remuxController.on("keyframePosition",function(e){t.kfPosition.push(e)}),"function"==typeof t.options.onKeyframePosition&&t.remuxController.on("keyframePosition",function(e){t.options.onKeyframePosition.call(null,e)}),t}return l(i,t),a(i,[{key:"initData",value:function(){this.lastCleaningTime=Date.now(),this.kfPosition=[],this.pendingUnits={},this.remainingData=new Uint8Array,this.startInterval()}},{key:"initBrowser",value:function(){"string"==typeof this.options.node&&""==this.options.node&&b("no video element were found to render, provide a valid video element"),this.node="string"==typeof this.options.node?document.getElementById(this.options.node):this.options.node,this.mseReady=!1,this.setupMSE()}},{key:"createStream",value:function(){var t=this.feed.bind(this),r=this.destroy.bind(this);return this.stream=new e.Duplex({writableObjectMode:!0,read:function(e){},write:function(e,r,n){t(e),n()},final:function(e){r(),e()}}),this.stream}},{key:"setupMSE",value:function(){if(window.MediaSource=window.MediaSource||window.WebKitMediaSource||window.ManagedMediaSource,!window.MediaSource)throw"Oops! Browser does not support Media Source Extension or Managed Media Source (IOS 17+).";if(this.isMSESupported=!!window.MediaSource,this.mediaSource=new window.MediaSource,this.url=URL.createObjectURL(this.mediaSource),window.MediaSource===window.ManagedMediaSource)try{this.node.removeAttribute("src"),this.node.disableRemotePlayback=!0;var e=document.createElement("source");e.type="video/mp4",e.src=this.url,this.node.appendChild(e),this.node.load()}catch(e){this.node.src=this.url}else this.node.src=this.url;this.mseEnded=!1,this.mediaSource.addEventListener("sourceopen",this.onMSEOpen.bind(this)),this.mediaSource.addEventListener("sourceclose",this.onMSEClose.bind(this)),this.mediaSource.addEventListener("webkitsourceopen",this.onMSEOpen.bind(this)),this.mediaSource.addEventListener("webkitsourceclose",this.onMSEClose.bind(this))}},{key:"endMSE",value:function(){if(!this.mseEnded)try{this.mseEnded=!0,this.mediaSource.endOfStream()}catch(e){b("mediasource is not available to end")}}},{key:"feed",value:function(e){e&&this.remuxController&&(e.duration=e.duration?parseInt(e.duration):0,this.remuxController.feed(e))}},{key:"destroy",value:function(){if(this.stopInterval(),this.stream&&(this.remuxController.flush(),this.stream.push(null),this.stream=null),this.remuxController&&(this.remuxController.destroy(),this.remuxController=null),this.bufferControllers){for(var e in this.bufferControllers)this.bufferControllers[e].destroy();this.bufferControllers=null,this.endMSE()}this.node=!1,this.mseReady=!1,this.videoStarted=!1,this.mediaSource=null}},{key:"reset",value:function(){if(this.stopInterval(),this.isReset=!0,this.node.pause(),this.remuxController&&this.remuxController.reset(),this.bufferControllers){for(var e in this.bufferControllers)this.bufferControllers[e].destroy();this.bufferControllers=null,this.endMSE()}this.initData(),"browser"==this.env&&this.initBrowser(),k("JMuxer was reset")}},{key:"createBuffer",value:function(){if(this.mseReady&&this.remuxController&&this.remuxController.isReady()&&!this.bufferControllers)for(var e in this.bufferControllers={},this.remuxController.tracks){var t=this.remuxController.tracks[e];if(!i.isSupported("".concat(e,'/mp4; codecs="').concat(t.mp4track.codec,'"')))return b("Browser does not support codec: ".concat(e,'/mp4; codecs="').concat(t.mp4track.codec,'"')),"function"==typeof this.options.onUnsupportedCodec&&this.options.onUnsupportedCodec.call(null,t.mp4track.codec),!1;var r=this.mediaSource.addSourceBuffer("".concat(e,'/mp4; codecs="').concat(t.mp4track.codec,'"'));this.bufferControllers[e]=new F(r,e),this.bufferControllers[e].on("error",this.onBufferError.bind(this))}}},{key:"startInterval",value:function(){var e=this;this.interval=setInterval(function(){e.options.flushingTime?e.applyAndClearBuffer():e.bufferControllers&&e.cancelDelay()},this.options.flushingTime||1e3)}},{key:"stopInterval",value:function(){this.interval&&clearInterval(this.interval)}},{key:"cancelDelay",value:function(){if(this.node.buffered&&this.node.buffered.length>0&&!this.node.seeking){var e=this.node.buffered.end(0);e-this.node.currentTime>this.options.maxDelay/1e3&&(k("delay"),this.node.paused&&this.node.play().catch(b),this.node.currentTime=e-.001)}}},{key:"releaseBuffer",value:function(){for(var e in this.bufferControllers)this.bufferControllers[e].doAppend()}},{key:"applyAndClearBuffer",value:function(){this.bufferControllers&&(this.releaseBuffer(),this.clearBuffer())}},{key:"getSafeClearOffsetOfBuffer",value:function(e){for(var t,r="audio"===this.options.mode&&e||0,n=0;n<this.kfPosition.length&&!(this.kfPosition[n]>=e);n++)t=this.kfPosition[n];return t&&(this.kfPosition=this.kfPosition.filter(function(e){return e<t&&(r=e),e>=t})),r}},{key:"clearBuffer",value:function(){if(this.options.clearBuffer&&Date.now()-this.lastCleaningTime>1e4){for(var e in this.bufferControllers){var t=this.getSafeClearOffsetOfBuffer(this.node.currentTime);this.bufferControllers[e].initCleanup(t)}this.lastCleaningTime=Date.now()}}},{key:"onBuffer",value:function(e){this.options.readFpsFromTrack&&void 0!==e.fps&&this.options.fps!=e.fps&&(this.options.fps=e.fps,this.frameDuration=Math.ceil(1e3/e.fps),k("JMuxer changed FPS to ".concat(e.fps," from track data"))),"browser"==this.env?this.bufferControllers&&this.bufferControllers[e.type]&&this.bufferControllers[e.type].feed(e.payload):this.stream&&this.stream.push(e.payload),this.options.onData&&this.options.onData(e.payload),0===this.options.flushingTime&&this.applyAndClearBuffer()}},{key:"onMSEOpen",value:function(){this.mseReady=!0,URL.revokeObjectURL(this.url),"function"==typeof this.options.onReady&&this.options.onReady.call(null,this.isReset,this.mediaSource)}},{key:"onMSEClose",value:function(){this.mseReady=!1,this.videoStarted=!1}},{key:"onBufferError",value:function(e){if("QuotaExceeded"==e.name)return k("JMuxer cleaning ".concat(e.type," buffer due to QuotaExceeded error")),void this.bufferControllers[e.type].initCleanup(this.node.currentTime);"InvalidStateError"==e.name?(k("JMuxer is reseting due to InvalidStateError"),this.reset()):this.endMSE(),"function"==typeof this.options.onError&&this.options.onError.call(null,e)}}],[{key:"isSupported",value:function(e){return window.MediaSource&&window.MediaSource.isTypeSupported(e)}}])}(U)});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jmuxer",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"description": "jMuxer - a simple javascript mp4 muxer for non-standard streaming communications protocol",
|
|
5
5
|
"main": "dist/jmuxer.min.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "
|
|
30
|
+
"url": "https://github.com/samirkumardas/jmuxer.git"
|
|
31
31
|
},
|
|
32
32
|
"author": "Samir Das",
|
|
33
33
|
"devDependencies": {
|
|
@@ -45,6 +45,5 @@
|
|
|
45
45
|
"msgpack-lite": "^0.1.26",
|
|
46
46
|
"nodemon": "^3.1.10",
|
|
47
47
|
"rollup": "^4.59.0"
|
|
48
|
-
}
|
|
49
|
-
"type": "module"
|
|
48
|
+
}
|
|
50
49
|
}
|
package/src/remuxer/h264.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as debug from '../util/debug';
|
|
2
2
|
import { H264Parser, NALU264 } from '../parsers/h264.js';
|
|
3
3
|
import { BaseRemuxer } from './base.js';
|
|
4
|
-
import { appendByteArray } from '../util/utils.js';
|
|
4
|
+
import { appendByteArray, sameBytes } from '../util/utils.js';
|
|
5
5
|
|
|
6
6
|
export class H264Remuxer extends BaseRemuxer {
|
|
7
7
|
|
|
@@ -16,8 +16,8 @@ export class H264Remuxer extends BaseRemuxer {
|
|
|
16
16
|
type: 'video',
|
|
17
17
|
len: 0,
|
|
18
18
|
fragmented: true,
|
|
19
|
-
sps:
|
|
20
|
-
pps:
|
|
19
|
+
sps: [],
|
|
20
|
+
pps: [],
|
|
21
21
|
fps: 30,
|
|
22
22
|
width: 0,
|
|
23
23
|
height: 0,
|
|
@@ -33,8 +33,8 @@ export class H264Remuxer extends BaseRemuxer {
|
|
|
33
33
|
|
|
34
34
|
resetTrack() {
|
|
35
35
|
this.readyToDecode = false;
|
|
36
|
-
this.mp4track.sps =
|
|
37
|
-
this.mp4track.pps =
|
|
36
|
+
this.mp4track.sps = [];
|
|
37
|
+
this.mp4track.pps = [];
|
|
38
38
|
this.nextDts = 0;
|
|
39
39
|
this.dts = 0;
|
|
40
40
|
this.remainingData = new Uint8Array();
|
|
@@ -226,7 +226,14 @@ export class H264Remuxer extends BaseRemuxer {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
parsePPS(pps) {
|
|
229
|
-
|
|
229
|
+
// A stream may define more than one PPS (e.g. the encoder uses different
|
|
230
|
+
// entropy-coding modes for I- vs P-slices, thus referencing different
|
|
231
|
+
// pps_ids). Keep every distinct PPS so any slice can find the one it
|
|
232
|
+
// references.
|
|
233
|
+
for (const existing of this.mp4track.pps) {
|
|
234
|
+
if (sameBytes(existing, pps)) return;
|
|
235
|
+
}
|
|
236
|
+
this.mp4track.pps.push(new Uint8Array(pps));
|
|
230
237
|
}
|
|
231
238
|
|
|
232
239
|
parseNAL(unit) {
|
|
@@ -239,13 +246,11 @@ export class H264Remuxer extends BaseRemuxer {
|
|
|
239
246
|
let push = false;
|
|
240
247
|
switch (unit.type()) {
|
|
241
248
|
case NALU264.PPS:
|
|
242
|
-
|
|
243
|
-
this.parsePPS(unit.getPayload());
|
|
244
|
-
}
|
|
249
|
+
this.parsePPS(unit.getPayload());
|
|
245
250
|
push = true;
|
|
246
251
|
break;
|
|
247
252
|
case NALU264.SPS:
|
|
248
|
-
if (!this.mp4track.sps) {
|
|
253
|
+
if (!this.mp4track.sps.length) {
|
|
249
254
|
this.parseSPS(unit.getPayload());
|
|
250
255
|
}
|
|
251
256
|
push = true;
|
|
@@ -259,7 +264,7 @@ export class H264Remuxer extends BaseRemuxer {
|
|
|
259
264
|
default:
|
|
260
265
|
}
|
|
261
266
|
|
|
262
|
-
if (!this.readyToDecode && this.mp4track.pps && this.mp4track.sps) {
|
|
267
|
+
if (!this.readyToDecode && this.mp4track.pps.length && this.mp4track.sps.length) {
|
|
263
268
|
this.readyToDecode = true;
|
|
264
269
|
}
|
|
265
270
|
|
package/src/remuxer/h265.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as debug from '../util/debug';
|
|
2
2
|
import { H265Parser, NALU265 } from '../parsers/h265.js';
|
|
3
3
|
import { BaseRemuxer } from './base.js';
|
|
4
|
-
import { appendByteArray, reverseBits, removeTrailingDotZero } from '../util/utils.js';
|
|
4
|
+
import { appendByteArray, reverseBits, removeTrailingDotZero, sameBytes } from '../util/utils.js';
|
|
5
5
|
|
|
6
6
|
export class H265Remuxer extends BaseRemuxer {
|
|
7
7
|
|
|
@@ -16,9 +16,9 @@ export class H265Remuxer extends BaseRemuxer {
|
|
|
16
16
|
type: 'video',
|
|
17
17
|
len: 0,
|
|
18
18
|
fragmented: true,
|
|
19
|
-
vps:
|
|
20
|
-
sps:
|
|
21
|
-
pps:
|
|
19
|
+
vps: [],
|
|
20
|
+
sps: [],
|
|
21
|
+
pps: [],
|
|
22
22
|
hvcC: {},
|
|
23
23
|
fps: 30,
|
|
24
24
|
width: 0,
|
|
@@ -35,9 +35,9 @@ export class H265Remuxer extends BaseRemuxer {
|
|
|
35
35
|
|
|
36
36
|
resetTrack() {
|
|
37
37
|
this.readyToDecode = false;
|
|
38
|
-
this.mp4track.vps =
|
|
39
|
-
this.mp4track.sps =
|
|
40
|
-
this.mp4track.pps =
|
|
38
|
+
this.mp4track.vps = [];
|
|
39
|
+
this.mp4track.sps = [];
|
|
40
|
+
this.mp4track.pps = [];
|
|
41
41
|
this.mp4track.hvcC = {};
|
|
42
42
|
this.nextDts = 0;
|
|
43
43
|
this.dts = 0;
|
|
@@ -240,11 +240,18 @@ export class H265Remuxer extends BaseRemuxer {
|
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
parsePPS(pps) {
|
|
243
|
-
|
|
243
|
+
// A stream may define more than one PPS (e.g. the encoder uses different
|
|
244
|
+
// entropy-coding modes for I- vs P-slices, thus referencing different
|
|
245
|
+
// pps_ids). Keep every distinct PPS so any slice can find the one it
|
|
246
|
+
// references.
|
|
247
|
+
for (const existing of this.mp4track.pps) {
|
|
248
|
+
if (sameBytes(existing, pps)) return;
|
|
249
|
+
}
|
|
250
|
+
this.mp4track.pps.push(new Uint8Array(pps));
|
|
244
251
|
}
|
|
245
252
|
|
|
246
253
|
parseVPS(vps) {
|
|
247
|
-
this.mp4track.vps = [vps];
|
|
254
|
+
this.mp4track.vps = [new Uint8Array(vps)];
|
|
248
255
|
}
|
|
249
256
|
|
|
250
257
|
parseNAL(unit) {
|
|
@@ -257,23 +264,21 @@ export class H265Remuxer extends BaseRemuxer {
|
|
|
257
264
|
let push = false;
|
|
258
265
|
switch (unit.type()) {
|
|
259
266
|
case NALU265.VPS:
|
|
260
|
-
if (!this.mp4track.vps) {
|
|
267
|
+
if (!this.mp4track.vps.length) {
|
|
261
268
|
this.parseVPS(unit.getPayload());
|
|
262
269
|
}
|
|
263
270
|
push = true;
|
|
264
271
|
break;
|
|
265
272
|
|
|
266
273
|
case NALU265.SPS:
|
|
267
|
-
if (!this.mp4track.sps) {
|
|
274
|
+
if (!this.mp4track.sps.length) {
|
|
268
275
|
this.parseSPS(unit.getPayload());
|
|
269
276
|
}
|
|
270
277
|
push = true;
|
|
271
278
|
break;
|
|
272
279
|
|
|
273
280
|
case NALU265.PPS:
|
|
274
|
-
|
|
275
|
-
this.parsePPS(unit.getPayload());
|
|
276
|
-
}
|
|
281
|
+
this.parsePPS(unit.getPayload());
|
|
277
282
|
push = true;
|
|
278
283
|
break;
|
|
279
284
|
case NALU265.AUD:
|
|
@@ -286,7 +291,7 @@ export class H265Remuxer extends BaseRemuxer {
|
|
|
286
291
|
default:
|
|
287
292
|
}
|
|
288
293
|
|
|
289
|
-
if (!this.readyToDecode && this.mp4track.vps && this.mp4track.sps && this.mp4track.pps) {
|
|
294
|
+
if (!this.readyToDecode && this.mp4track.vps.length && this.mp4track.sps.length && this.mp4track.pps.length) {
|
|
290
295
|
this.readyToDecode = true;
|
|
291
296
|
}
|
|
292
297
|
|
|
@@ -437,16 +437,18 @@ export class MP4 {
|
|
|
437
437
|
0x03, // constantFrameRate = 0, numTemporalLayers = 0, lengthSizeMinusOne = 3 (AKA 4)
|
|
438
438
|
0x03, // numOfArrays
|
|
439
439
|
|
|
440
|
+
// A stream may carry more than one PPS, so each array declares its real
|
|
441
|
+
// count: an under-reported numNalus leaves the extra sets unreadable.
|
|
440
442
|
0x20, // array_completeness + NAL_unit_type (32 = VPS)
|
|
441
|
-
|
|
443
|
+
(track.vps.length >>> 8) & 0xFF, track.vps.length & 0xFF, // numNalus
|
|
442
444
|
...vps,
|
|
443
445
|
|
|
444
446
|
0x21, // NAL_unit_type (33 = SPS)
|
|
445
|
-
|
|
447
|
+
(track.sps.length >>> 8) & 0xFF, track.sps.length & 0xFF,
|
|
446
448
|
...sps,
|
|
447
449
|
|
|
448
450
|
0x22, // NAL_unit_type (34 = PPS)
|
|
449
|
-
|
|
451
|
+
(track.pps.length >>> 8) & 0xFF, track.pps.length & 0xFF,
|
|
450
452
|
...pps
|
|
451
453
|
]));
|
|
452
454
|
|
package/src/util/utils.js
CHANGED
|
@@ -42,3 +42,11 @@ export function removeTrailingDotZero(input) {
|
|
|
42
42
|
// Use regex to strip all trailing ".0" sequences
|
|
43
43
|
return input.replace(/(?:\.0)+$/, '');
|
|
44
44
|
}
|
|
45
|
+
|
|
46
|
+
export function sameBytes(a, b) {
|
|
47
|
+
if (a.length !== b.length) return false;
|
|
48
|
+
for (let i = 0; i < a.length; i++) {
|
|
49
|
+
if (a[i] !== b[i]) return false;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<component name="ProjectCodeStyleConfiguration">
|
|
2
|
-
<code_scheme name="Project" version="173">
|
|
3
|
-
<JSCodeStyleSettings version="0">
|
|
4
|
-
<option name="FORCE_SEMICOLON_STYLE" value="true" />
|
|
5
|
-
<option name="USE_DOUBLE_QUOTES" value="false" />
|
|
6
|
-
<option name="FORCE_QUOTE_STYlE" value="true" />
|
|
7
|
-
</JSCodeStyleSettings>
|
|
8
|
-
<codeStyleSettings language="JavaScript">
|
|
9
|
-
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
|
|
10
|
-
<option name="ALIGN_MULTILINE_FOR" value="false" />
|
|
11
|
-
</codeStyleSettings>
|
|
12
|
-
</code_scheme>
|
|
13
|
-
</component>
|
package/.idea/jmuxer.iml
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<module type="JAVA_MODULE" version="4">
|
|
3
|
-
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
|
4
|
-
<exclude-output />
|
|
5
|
-
<content url="file://$MODULE_DIR$" />
|
|
6
|
-
<orderEntry type="inheritedJdk" />
|
|
7
|
-
<orderEntry type="sourceFolder" forTests="false" />
|
|
8
|
-
</component>
|
|
9
|
-
</module>
|
package/.idea/misc.xml
DELETED
package/.idea/modules.xml
DELETED
package/.idea/vcs.xml
DELETED
|
File without changes
|