hls.js 1.5.2-0.canary.9970 → 1.5.2-0.canary.9971

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/hls.js CHANGED
@@ -556,7 +556,7 @@
556
556
  // Some browsers don't allow to use bind on console object anyway
557
557
  // fallback to default if needed
558
558
  try {
559
- newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.2-0.canary.9970");
559
+ newLogger.log("Debug logs enabled for \"" + context + "\" in hls.js version " + "1.5.2-0.canary.9971");
560
560
  } catch (e) {
561
561
  /* log fn threw an exception. All logger methods are no-ops. */
562
562
  return createLogger();
@@ -11770,6 +11770,110 @@
11770
11770
  logger.log(VideoSample.pts + '/' + VideoSample.dts + ':' + VideoSample.debug);
11771
11771
  }
11772
11772
  };
11773
+ _proto.parseNALu = function parseNALu(track, array) {
11774
+ var len = array.byteLength;
11775
+ var state = track.naluState || 0;
11776
+ var lastState = state;
11777
+ var units = [];
11778
+ var i = 0;
11779
+ var value;
11780
+ var overflow;
11781
+ var unitType;
11782
+ var lastUnitStart = -1;
11783
+ var lastUnitType = 0;
11784
+ // logger.log('PES:' + Hex.hexDump(array));
11785
+
11786
+ if (state === -1) {
11787
+ // special use case where we found 3 or 4-byte start codes exactly at the end of previous PES packet
11788
+ lastUnitStart = 0;
11789
+ // NALu type is value read from offset 0
11790
+ lastUnitType = this.getNALuType(array, 0);
11791
+ state = 0;
11792
+ i = 1;
11793
+ }
11794
+ while (i < len) {
11795
+ value = array[i++];
11796
+ // optimization. state 0 and 1 are the predominant case. let's handle them outside of the switch/case
11797
+ if (!state) {
11798
+ state = value ? 0 : 1;
11799
+ continue;
11800
+ }
11801
+ if (state === 1) {
11802
+ state = value ? 0 : 2;
11803
+ continue;
11804
+ }
11805
+ // here we have state either equal to 2 or 3
11806
+ if (!value) {
11807
+ state = 3;
11808
+ } else if (value === 1) {
11809
+ overflow = i - state - 1;
11810
+ if (lastUnitStart >= 0) {
11811
+ var unit = {
11812
+ data: array.subarray(lastUnitStart, overflow),
11813
+ type: lastUnitType
11814
+ };
11815
+ // logger.log('pushing NALU, type/size:' + unit.type + '/' + unit.data.byteLength);
11816
+ units.push(unit);
11817
+ } else {
11818
+ // lastUnitStart is undefined => this is the first start code found in this PES packet
11819
+ // first check if start code delimiter is overlapping between 2 PES packets,
11820
+ // ie it started in last packet (lastState not zero)
11821
+ // and ended at the beginning of this PES packet (i <= 4 - lastState)
11822
+ var lastUnit = this.getLastNalUnit(track.samples);
11823
+ if (lastUnit) {
11824
+ if (lastState && i <= 4 - lastState) {
11825
+ // start delimiter overlapping between PES packets
11826
+ // strip start delimiter bytes from the end of last NAL unit
11827
+ // check if lastUnit had a state different from zero
11828
+ if (lastUnit.state) {
11829
+ // strip last bytes
11830
+ lastUnit.data = lastUnit.data.subarray(0, lastUnit.data.byteLength - lastState);
11831
+ }
11832
+ }
11833
+ // If NAL units are not starting right at the beginning of the PES packet, push preceding data into previous NAL unit.
11834
+
11835
+ if (overflow > 0) {
11836
+ // logger.log('first NALU found with overflow:' + overflow);
11837
+ lastUnit.data = appendUint8Array(lastUnit.data, array.subarray(0, overflow));
11838
+ lastUnit.state = 0;
11839
+ }
11840
+ }
11841
+ }
11842
+ // check if we can read unit type
11843
+ if (i < len) {
11844
+ unitType = this.getNALuType(array, i);
11845
+ // logger.log('find NALU @ offset:' + i + ',type:' + unitType);
11846
+ lastUnitStart = i;
11847
+ lastUnitType = unitType;
11848
+ state = 0;
11849
+ } else {
11850
+ // not enough byte to read unit type. let's read it on next PES parsing
11851
+ state = -1;
11852
+ }
11853
+ } else {
11854
+ state = 0;
11855
+ }
11856
+ }
11857
+ if (lastUnitStart >= 0 && state >= 0) {
11858
+ var _unit = {
11859
+ data: array.subarray(lastUnitStart, len),
11860
+ type: lastUnitType,
11861
+ state: state
11862
+ };
11863
+ units.push(_unit);
11864
+ // logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state);
11865
+ }
11866
+ // no NALu found
11867
+ if (units.length === 0) {
11868
+ // append pes.data to previous NAL unit
11869
+ var _lastUnit = this.getLastNalUnit(track.samples);
11870
+ if (_lastUnit) {
11871
+ _lastUnit.data = appendUint8Array(_lastUnit.data, array);
11872
+ }
11873
+ }
11874
+ track.naluState = state;
11875
+ return units;
11876
+ };
11773
11877
  return BaseVideoParser;
11774
11878
  }();
11775
11879
 
@@ -11924,22 +12028,179 @@
11924
12028
  ;
11925
12029
  _proto.readUInt = function readUInt() {
11926
12030
  return this.readBits(32);
12031
+ };
12032
+ return ExpGolomb;
12033
+ }();
12034
+
12035
+ var AvcVideoParser = /*#__PURE__*/function (_BaseVideoParser) {
12036
+ _inheritsLoose(AvcVideoParser, _BaseVideoParser);
12037
+ function AvcVideoParser() {
12038
+ return _BaseVideoParser.apply(this, arguments) || this;
12039
+ }
12040
+ var _proto = AvcVideoParser.prototype;
12041
+ _proto.parsePES = function parsePES(track, textTrack, pes, last, duration) {
12042
+ var _this = this;
12043
+ var units = this.parseNALu(track, pes.data);
12044
+ var VideoSample = this.VideoSample;
12045
+ var push;
12046
+ var spsfound = false;
12047
+ // free pes.data to save up some memory
12048
+ pes.data = null;
12049
+
12050
+ // if new NAL units found and last sample still there, let's push ...
12051
+ // this helps parsing streams with missing AUD (only do this if AUD never found)
12052
+ if (VideoSample && units.length && !track.audFound) {
12053
+ this.pushAccessUnit(VideoSample, track);
12054
+ VideoSample = this.VideoSample = this.createVideoSample(false, pes.pts, pes.dts, '');
12055
+ }
12056
+ units.forEach(function (unit) {
12057
+ var _VideoSample2;
12058
+ switch (unit.type) {
12059
+ // NDR
12060
+ case 1:
12061
+ {
12062
+ var iskey = false;
12063
+ push = true;
12064
+ var data = unit.data;
12065
+ // only check slice type to detect KF in case SPS found in same packet (any keyframe is preceded by SPS ...)
12066
+ if (spsfound && data.length > 4) {
12067
+ // retrieve slice type by parsing beginning of NAL unit (follow H264 spec, slice_header definition) to detect keyframe embedded in NDR
12068
+ var sliceType = _this.readSliceType(data);
12069
+ // 2 : I slice, 4 : SI slice, 7 : I slice, 9: SI slice
12070
+ // SI slice : A slice that is coded using intra prediction only and using quantisation of the prediction samples.
12071
+ // An SI slice can be coded such that its decoded samples can be constructed identically to an SP slice.
12072
+ // I slice: A slice that is not an SI slice that is decoded using intra prediction only.
12073
+ // if (sliceType === 2 || sliceType === 7) {
12074
+ if (sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9) {
12075
+ iskey = true;
12076
+ }
12077
+ }
12078
+ if (iskey) {
12079
+ var _VideoSample;
12080
+ // if we have non-keyframe data already, that cannot belong to the same frame as a keyframe, so force a push
12081
+ if ((_VideoSample = VideoSample) != null && _VideoSample.frame && !VideoSample.key) {
12082
+ _this.pushAccessUnit(VideoSample, track);
12083
+ VideoSample = _this.VideoSample = null;
12084
+ }
12085
+ }
12086
+ if (!VideoSample) {
12087
+ VideoSample = _this.VideoSample = _this.createVideoSample(true, pes.pts, pes.dts, '');
12088
+ }
12089
+ VideoSample.frame = true;
12090
+ VideoSample.key = iskey;
12091
+ break;
12092
+ // IDR
12093
+ }
12094
+ case 5:
12095
+ push = true;
12096
+ // handle PES not starting with AUD
12097
+ // if we have frame data already, that cannot belong to the same frame, so force a push
12098
+ if ((_VideoSample2 = VideoSample) != null && _VideoSample2.frame && !VideoSample.key) {
12099
+ _this.pushAccessUnit(VideoSample, track);
12100
+ VideoSample = _this.VideoSample = null;
12101
+ }
12102
+ if (!VideoSample) {
12103
+ VideoSample = _this.VideoSample = _this.createVideoSample(true, pes.pts, pes.dts, '');
12104
+ }
12105
+ VideoSample.key = true;
12106
+ VideoSample.frame = true;
12107
+ break;
12108
+ // SEI
12109
+ case 6:
12110
+ {
12111
+ push = true;
12112
+ parseSEIMessageFromNALu(unit.data, 1, pes.pts, textTrack.samples);
12113
+ break;
12114
+ // SPS
12115
+ }
12116
+ case 7:
12117
+ {
12118
+ var _track$pixelRatio, _track$pixelRatio2;
12119
+ push = true;
12120
+ spsfound = true;
12121
+ var sps = unit.data;
12122
+ var config = _this.readSPS(sps);
12123
+ if (!track.sps || track.width !== config.width || track.height !== config.height || ((_track$pixelRatio = track.pixelRatio) == null ? void 0 : _track$pixelRatio[0]) !== config.pixelRatio[0] || ((_track$pixelRatio2 = track.pixelRatio) == null ? void 0 : _track$pixelRatio2[1]) !== config.pixelRatio[1]) {
12124
+ track.width = config.width;
12125
+ track.height = config.height;
12126
+ track.pixelRatio = config.pixelRatio;
12127
+ track.sps = [sps];
12128
+ track.duration = duration;
12129
+ var codecarray = sps.subarray(1, 4);
12130
+ var codecstring = 'avc1.';
12131
+ for (var i = 0; i < 3; i++) {
12132
+ var h = codecarray[i].toString(16);
12133
+ if (h.length < 2) {
12134
+ h = '0' + h;
12135
+ }
12136
+ codecstring += h;
12137
+ }
12138
+ track.codec = codecstring;
12139
+ }
12140
+ break;
12141
+ }
12142
+ // PPS
12143
+ case 8:
12144
+ push = true;
12145
+ track.pps = [unit.data];
12146
+ break;
12147
+ // AUD
12148
+ case 9:
12149
+ push = true;
12150
+ track.audFound = true;
12151
+ if (VideoSample) {
12152
+ _this.pushAccessUnit(VideoSample, track);
12153
+ }
12154
+ VideoSample = _this.VideoSample = _this.createVideoSample(false, pes.pts, pes.dts, '');
12155
+ break;
12156
+ // Filler Data
12157
+ case 12:
12158
+ push = true;
12159
+ break;
12160
+ default:
12161
+ push = false;
12162
+ if (VideoSample) {
12163
+ VideoSample.debug += 'unknown NAL ' + unit.type + ' ';
12164
+ }
12165
+ break;
12166
+ }
12167
+ if (VideoSample && push) {
12168
+ var _units = VideoSample.units;
12169
+ _units.push(unit);
12170
+ }
12171
+ });
12172
+ // if last PES packet, push samples
12173
+ if (last && VideoSample) {
12174
+ this.pushAccessUnit(VideoSample, track);
12175
+ this.VideoSample = null;
12176
+ }
12177
+ };
12178
+ _proto.getNALuType = function getNALuType(data, offset) {
12179
+ return data[offset] & 0x1f;
12180
+ };
12181
+ _proto.readSliceType = function readSliceType(data) {
12182
+ var eg = new ExpGolomb(data);
12183
+ // skip NALu type
12184
+ eg.readUByte();
12185
+ // discard first_mb_in_slice
12186
+ eg.readUEG();
12187
+ // return slice_type
12188
+ return eg.readUEG();
11927
12189
  }
11928
12190
 
11929
12191
  /**
11930
- * Advance the ExpGolomb decoder past a scaling list. The scaling
11931
- * list is optionally transmitted as part of a sequence parameter
12192
+ * The scaling list is optionally transmitted as part of a sequence parameter
11932
12193
  * set and is not relevant to transmuxing.
11933
12194
  * @param count the number of entries in this scaling list
11934
12195
  * @see Recommendation ITU-T H.264, Section 7.3.2.1.1.1
11935
12196
  */;
11936
- _proto.skipScalingList = function skipScalingList(count) {
12197
+ _proto.skipScalingList = function skipScalingList(count, reader) {
11937
12198
  var lastScale = 8;
11938
12199
  var nextScale = 8;
11939
12200
  var deltaScale;
11940
12201
  for (var j = 0; j < count; j++) {
11941
12202
  if (nextScale !== 0) {
11942
- deltaScale = this.readEG();
12203
+ deltaScale = reader.readEG();
11943
12204
  nextScale = (lastScale + deltaScale + 256) % 256;
11944
12205
  }
11945
12206
  lastScale = nextScale === 0 ? lastScale : nextScale;
@@ -11954,7 +12215,8 @@
11954
12215
  * sequence parameter set, including the dimensions of the
11955
12216
  * associated video frames.
11956
12217
  */;
11957
- _proto.readSPS = function readSPS() {
12218
+ _proto.readSPS = function readSPS(sps) {
12219
+ var eg = new ExpGolomb(sps);
11958
12220
  var frameCropLeftOffset = 0;
11959
12221
  var frameCropRightOffset = 0;
11960
12222
  var frameCropTopOffset = 0;
@@ -11962,13 +12224,13 @@
11962
12224
  var numRefFramesInPicOrderCntCycle;
11963
12225
  var scalingListCount;
11964
12226
  var i;
11965
- var readUByte = this.readUByte.bind(this);
11966
- var readBits = this.readBits.bind(this);
11967
- var readUEG = this.readUEG.bind(this);
11968
- var readBoolean = this.readBoolean.bind(this);
11969
- var skipBits = this.skipBits.bind(this);
11970
- var skipEG = this.skipEG.bind(this);
11971
- var skipUEG = this.skipUEG.bind(this);
12227
+ var readUByte = eg.readUByte.bind(eg);
12228
+ var readBits = eg.readBits.bind(eg);
12229
+ var readUEG = eg.readUEG.bind(eg);
12230
+ var readBoolean = eg.readBoolean.bind(eg);
12231
+ var skipBits = eg.skipBits.bind(eg);
12232
+ var skipEG = eg.skipEG.bind(eg);
12233
+ var skipUEG = eg.skipUEG.bind(eg);
11972
12234
  var skipScalingList = this.skipScalingList.bind(this);
11973
12235
  readUByte();
11974
12236
  var profileIdc = readUByte(); // profile_idc
@@ -11993,9 +12255,9 @@
11993
12255
  if (readBoolean()) {
11994
12256
  // seq_scaling_list_present_flag[ i ]
11995
12257
  if (i < 6) {
11996
- skipScalingList(16);
12258
+ skipScalingList(16, eg);
11997
12259
  } else {
11998
- skipScalingList(64);
12260
+ skipScalingList(64, eg);
11999
12261
  }
12000
12262
  }
12001
12263
  }
@@ -12100,26 +12362,24 @@
12100
12362
  pixelRatio: pixelRatio
12101
12363
  };
12102
12364
  };
12103
- _proto.readSliceType = function readSliceType() {
12104
- // skip NALu type
12105
- this.readUByte();
12106
- // discard first_mb_in_slice
12107
- this.readUEG();
12108
- // return slice_type
12109
- return this.readUEG();
12110
- };
12111
- return ExpGolomb;
12112
- }();
12365
+ return AvcVideoParser;
12366
+ }(BaseVideoParser);
12113
12367
 
12114
- var AvcVideoParser = /*#__PURE__*/function (_BaseVideoParser) {
12115
- _inheritsLoose(AvcVideoParser, _BaseVideoParser);
12116
- function AvcVideoParser() {
12117
- return _BaseVideoParser.apply(this, arguments) || this;
12368
+ var HevcVideoParser = /*#__PURE__*/function (_BaseVideoParser) {
12369
+ _inheritsLoose(HevcVideoParser, _BaseVideoParser);
12370
+ function HevcVideoParser() {
12371
+ var _this;
12372
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12373
+ args[_key] = arguments[_key];
12374
+ }
12375
+ _this = _BaseVideoParser.call.apply(_BaseVideoParser, [this].concat(args)) || this;
12376
+ _this.initVPS = null;
12377
+ return _this;
12118
12378
  }
12119
- var _proto = AvcVideoParser.prototype;
12120
- _proto.parseAVCPES = function parseAVCPES(track, textTrack, pes, last, duration) {
12121
- var _this = this;
12122
- var units = this.parseAVCNALu(track, pes.data);
12379
+ var _proto = HevcVideoParser.prototype;
12380
+ _proto.parsePES = function parsePES(track, textTrack, pes, last, duration) {
12381
+ var _this2 = this;
12382
+ var units = this.parseNALu(track, pes.data);
12123
12383
  var VideoSample = this.VideoSample;
12124
12384
  var push;
12125
12385
  var spsfound = false;
@@ -12135,112 +12395,143 @@
12135
12395
  units.forEach(function (unit) {
12136
12396
  var _VideoSample2;
12137
12397
  switch (unit.type) {
12138
- // NDR
12398
+ // NON-IDR, NON RANDOM ACCESS SLICE
12399
+ case 0:
12139
12400
  case 1:
12140
- {
12141
- var iskey = false;
12142
- push = true;
12143
- var data = unit.data;
12144
- // only check slice type to detect KF in case SPS found in same packet (any keyframe is preceded by SPS ...)
12145
- if (spsfound && data.length > 4) {
12146
- // retrieve slice type by parsing beginning of NAL unit (follow H264 spec, slice_header definition) to detect keyframe embedded in NDR
12147
- var sliceType = new ExpGolomb(data).readSliceType();
12148
- // 2 : I slice, 4 : SI slice, 7 : I slice, 9: SI slice
12149
- // SI slice : A slice that is coded using intra prediction only and using quantisation of the prediction samples.
12150
- // An SI slice can be coded such that its decoded samples can be constructed identically to an SP slice.
12151
- // I slice: A slice that is not an SI slice that is decoded using intra prediction only.
12152
- // if (sliceType === 2 || sliceType === 7) {
12153
- if (sliceType === 2 || sliceType === 4 || sliceType === 7 || sliceType === 9) {
12154
- iskey = true;
12155
- }
12156
- }
12157
- if (iskey) {
12158
- var _VideoSample;
12159
- // if we have non-keyframe data already, that cannot belong to the same frame as a keyframe, so force a push
12160
- if ((_VideoSample = VideoSample) != null && _VideoSample.frame && !VideoSample.key) {
12161
- _this.pushAccessUnit(VideoSample, track);
12162
- VideoSample = _this.VideoSample = null;
12163
- }
12164
- }
12165
- if (!VideoSample) {
12166
- VideoSample = _this.VideoSample = _this.createVideoSample(true, pes.pts, pes.dts, '');
12167
- }
12168
- VideoSample.frame = true;
12169
- VideoSample.key = iskey;
12170
- break;
12171
- // IDR
12401
+ case 2:
12402
+ case 3:
12403
+ case 4:
12404
+ case 5:
12405
+ case 6:
12406
+ case 7:
12407
+ case 8:
12408
+ case 9:
12409
+ if (!VideoSample) {
12410
+ VideoSample = _this2.VideoSample = _this2.createVideoSample(false, pes.pts, pes.dts, '');
12411
+ }
12412
+ VideoSample.frame = true;
12413
+ push = true;
12414
+ break;
12415
+
12416
+ // CRA, BLA (random access picture)
12417
+ case 16:
12418
+ case 17:
12419
+ case 18:
12420
+ case 21:
12421
+ push = true;
12422
+ if (spsfound) {
12423
+ var _VideoSample;
12424
+ // handle PES not starting with AUD
12425
+ // if we have frame data already, that cannot belong to the same frame, so force a push
12426
+ if ((_VideoSample = VideoSample) != null && _VideoSample.frame && !VideoSample.key) {
12427
+ _this2.pushAccessUnit(VideoSample, track);
12428
+ VideoSample = _this2.VideoSample = null;
12429
+ }
12172
12430
  }
12173
- case 5:
12431
+ if (!VideoSample) {
12432
+ VideoSample = _this2.VideoSample = _this2.createVideoSample(true, pes.pts, pes.dts, '');
12433
+ }
12434
+ VideoSample.key = true;
12435
+ VideoSample.frame = true;
12436
+ break;
12437
+
12438
+ // IDR
12439
+ case 19:
12440
+ case 20:
12174
12441
  push = true;
12175
12442
  // handle PES not starting with AUD
12176
12443
  // if we have frame data already, that cannot belong to the same frame, so force a push
12177
12444
  if ((_VideoSample2 = VideoSample) != null && _VideoSample2.frame && !VideoSample.key) {
12178
- _this.pushAccessUnit(VideoSample, track);
12179
- VideoSample = _this.VideoSample = null;
12445
+ _this2.pushAccessUnit(VideoSample, track);
12446
+ VideoSample = _this2.VideoSample = null;
12180
12447
  }
12181
12448
  if (!VideoSample) {
12182
- VideoSample = _this.VideoSample = _this.createVideoSample(true, pes.pts, pes.dts, '');
12449
+ VideoSample = _this2.VideoSample = _this2.createVideoSample(true, pes.pts, pes.dts, '');
12183
12450
  }
12184
12451
  VideoSample.key = true;
12185
12452
  VideoSample.frame = true;
12186
12453
  break;
12454
+
12187
12455
  // SEI
12188
- case 6:
12189
- {
12190
- push = true;
12191
- parseSEIMessageFromNALu(unit.data, 1, pes.pts, textTrack.samples);
12192
- break;
12193
- // SPS
12456
+ case 39:
12457
+ push = true;
12458
+ parseSEIMessageFromNALu(unit.data, 2,
12459
+ // NALu header size
12460
+ pes.pts, textTrack.samples);
12461
+ break;
12462
+
12463
+ // VPS
12464
+ case 32:
12465
+ push = true;
12466
+ if (!track.vps) {
12467
+ var config = _this2.readVPS(unit.data);
12468
+ track.params = _objectSpread2({}, config);
12469
+ _this2.initVPS = unit.data;
12194
12470
  }
12195
- case 7:
12196
- {
12197
- var _track$pixelRatio, _track$pixelRatio2;
12198
- push = true;
12199
- spsfound = true;
12200
- var sps = unit.data;
12201
- var expGolombDecoder = new ExpGolomb(sps);
12202
- var config = expGolombDecoder.readSPS();
12203
- if (!track.sps || track.width !== config.width || track.height !== config.height || ((_track$pixelRatio = track.pixelRatio) == null ? void 0 : _track$pixelRatio[0]) !== config.pixelRatio[0] || ((_track$pixelRatio2 = track.pixelRatio) == null ? void 0 : _track$pixelRatio2[1]) !== config.pixelRatio[1]) {
12204
- track.width = config.width;
12205
- track.height = config.height;
12206
- track.pixelRatio = config.pixelRatio;
12207
- track.sps = [sps];
12471
+ track.vps = [unit.data];
12472
+ break;
12473
+
12474
+ // SPS
12475
+ case 33:
12476
+ push = true;
12477
+ spsfound = true;
12478
+ if (typeof track.params === 'object') {
12479
+ if (track.vps !== undefined && track.vps[0] !== _this2.initVPS && track.sps !== undefined && !_this2.matchSPS(track.sps[0], unit.data)) {
12480
+ _this2.initVPS = track.vps[0];
12481
+ track.sps = track.pps = undefined;
12482
+ }
12483
+ if (!track.sps) {
12484
+ var _config = _this2.readSPS(unit.data);
12485
+ track.width = _config.width;
12486
+ track.height = _config.height;
12487
+ track.pixelRatio = _config.pixelRatio;
12208
12488
  track.duration = duration;
12209
- var codecarray = sps.subarray(1, 4);
12210
- var codecstring = 'avc1.';
12211
- for (var i = 0; i < 3; i++) {
12212
- var h = codecarray[i].toString(16);
12213
- if (h.length < 2) {
12214
- h = '0' + h;
12215
- }
12216
- codecstring += h;
12489
+ track.codec = _config.codecString;
12490
+ track.sps = [];
12491
+ for (var prop in _config.params) {
12492
+ track.params[prop] = _config.params[prop];
12217
12493
  }
12218
- track.codec = codecstring;
12219
12494
  }
12220
- break;
12495
+ if (track.vps !== undefined && track.vps[0] === _this2.initVPS) {
12496
+ track.sps.push(unit.data);
12497
+ }
12221
12498
  }
12499
+ if (!VideoSample) {
12500
+ VideoSample = _this2.VideoSample = _this2.createVideoSample(true, pes.pts, pes.dts, '');
12501
+ }
12502
+ VideoSample.key = true;
12503
+ break;
12504
+
12222
12505
  // PPS
12223
- case 8:
12506
+ case 34:
12224
12507
  push = true;
12225
- track.pps = [unit.data];
12508
+ if (typeof track.params === 'object') {
12509
+ if (!track.pps) {
12510
+ track.pps = [];
12511
+ var _config2 = _this2.readPPS(unit.data);
12512
+ for (var _prop in _config2) {
12513
+ track.params[_prop] = _config2[_prop];
12514
+ }
12515
+ }
12516
+ if (_this2.initVPS !== null || track.pps.length === 0) {
12517
+ track.pps.push(unit.data);
12518
+ }
12519
+ }
12226
12520
  break;
12227
- // AUD
12228
- case 9:
12521
+
12522
+ // ACCESS UNIT DELIMITER
12523
+ case 35:
12229
12524
  push = true;
12230
12525
  track.audFound = true;
12231
12526
  if (VideoSample) {
12232
- _this.pushAccessUnit(VideoSample, track);
12527
+ _this2.pushAccessUnit(VideoSample, track);
12233
12528
  }
12234
- VideoSample = _this.VideoSample = _this.createVideoSample(false, pes.pts, pes.dts, '');
12235
- break;
12236
- // Filler Data
12237
- case 12:
12238
- push = true;
12529
+ VideoSample = _this2.VideoSample = _this2.createVideoSample(false, pes.pts, pes.dts, '');
12239
12530
  break;
12240
12531
  default:
12241
12532
  push = false;
12242
12533
  if (VideoSample) {
12243
- VideoSample.debug += 'unknown NAL ' + unit.type + ' ';
12534
+ VideoSample.debug += 'unknown or irrelevant NAL ' + unit.type + ' ';
12244
12535
  }
12245
12536
  break;
12246
12537
  }
@@ -12255,111 +12546,425 @@
12255
12546
  this.VideoSample = null;
12256
12547
  }
12257
12548
  };
12258
- _proto.parseAVCNALu = function parseAVCNALu(track, array) {
12259
- var len = array.byteLength;
12260
- var state = track.naluState || 0;
12261
- var lastState = state;
12262
- var units = [];
12263
- var i = 0;
12264
- var value;
12265
- var overflow;
12266
- var unitType;
12267
- var lastUnitStart = -1;
12268
- var lastUnitType = 0;
12269
- // logger.log('PES:' + Hex.hexDump(array));
12270
-
12271
- if (state === -1) {
12272
- // special use case where we found 3 or 4-byte start codes exactly at the end of previous PES packet
12273
- lastUnitStart = 0;
12274
- // NALu type is value read from offset 0
12275
- lastUnitType = array[0] & 0x1f;
12276
- state = 0;
12277
- i = 1;
12278
- }
12279
- while (i < len) {
12280
- value = array[i++];
12281
- // optimization. state 0 and 1 are the predominant case. let's handle them outside of the switch/case
12282
- if (!state) {
12283
- state = value ? 0 : 1;
12284
- continue;
12285
- }
12286
- if (state === 1) {
12287
- state = value ? 0 : 2;
12288
- continue;
12549
+ _proto.getNALuType = function getNALuType(data, offset) {
12550
+ return (data[offset] & 0x7e) >>> 1;
12551
+ };
12552
+ _proto.ebsp2rbsp = function ebsp2rbsp(arr) {
12553
+ var dst = new Uint8Array(arr.byteLength);
12554
+ var dstIdx = 0;
12555
+ for (var i = 0; i < arr.byteLength; i++) {
12556
+ if (i >= 2) {
12557
+ // Unescape: Skip 0x03 after 00 00
12558
+ if (arr[i] === 0x03 && arr[i - 1] === 0x00 && arr[i - 2] === 0x00) {
12559
+ continue;
12560
+ }
12289
12561
  }
12290
- // here we have state either equal to 2 or 3
12291
- if (!value) {
12292
- state = 3;
12293
- } else if (value === 1) {
12294
- overflow = i - state - 1;
12295
- if (lastUnitStart >= 0) {
12296
- var unit = {
12297
- data: array.subarray(lastUnitStart, overflow),
12298
- type: lastUnitType
12299
- };
12300
- // logger.log('pushing NALU, type/size:' + unit.type + '/' + unit.data.byteLength);
12301
- units.push(unit);
12302
- } else {
12303
- // lastUnitStart is undefined => this is the first start code found in this PES packet
12304
- // first check if start code delimiter is overlapping between 2 PES packets,
12305
- // ie it started in last packet (lastState not zero)
12306
- // and ended at the beginning of this PES packet (i <= 4 - lastState)
12307
- var lastUnit = this.getLastNalUnit(track.samples);
12308
- if (lastUnit) {
12309
- if (lastState && i <= 4 - lastState) {
12310
- // start delimiter overlapping between PES packets
12311
- // strip start delimiter bytes from the end of last NAL unit
12312
- // check if lastUnit had a state different from zero
12313
- if (lastUnit.state) {
12314
- // strip last bytes
12315
- lastUnit.data = lastUnit.data.subarray(0, lastUnit.data.byteLength - lastState);
12316
- }
12317
- }
12318
- // If NAL units are not starting right at the beginning of the PES packet, push preceding data into previous NAL unit.
12562
+ dst[dstIdx] = arr[i];
12563
+ dstIdx++;
12564
+ }
12565
+ return new Uint8Array(dst.buffer, 0, dstIdx);
12566
+ };
12567
+ _proto.readVPS = function readVPS(vps) {
12568
+ var eg = new ExpGolomb(vps);
12569
+ // remove header
12570
+ eg.readUByte();
12571
+ eg.readUByte();
12572
+ eg.readBits(4); // video_parameter_set_id
12573
+ eg.skipBits(2);
12574
+ eg.readBits(6); // max_layers_minus1
12575
+ var max_sub_layers_minus1 = eg.readBits(3);
12576
+ var temporal_id_nesting_flag = eg.readBoolean();
12577
+ // ...vui fps can be here, but empty fps value is not critical for metadata
12319
12578
 
12320
- if (overflow > 0) {
12321
- // logger.log('first NALU found with overflow:' + overflow);
12322
- lastUnit.data = appendUint8Array(lastUnit.data, array.subarray(0, overflow));
12323
- lastUnit.state = 0;
12579
+ return {
12580
+ numTemporalLayers: max_sub_layers_minus1 + 1,
12581
+ temporalIdNested: temporal_id_nesting_flag
12582
+ };
12583
+ };
12584
+ _proto.readSPS = function readSPS(sps) {
12585
+ var eg = new ExpGolomb(this.ebsp2rbsp(sps));
12586
+ eg.readUByte();
12587
+ eg.readUByte();
12588
+ eg.readBits(4); //video_parameter_set_id
12589
+ var max_sub_layers_minus1 = eg.readBits(3);
12590
+ eg.readBoolean(); // temporal_id_nesting_flag
12591
+
12592
+ // profile_tier_level
12593
+ var general_profile_space = eg.readBits(2);
12594
+ var general_tier_flag = eg.readBoolean();
12595
+ var general_profile_idc = eg.readBits(5);
12596
+ var general_profile_compatibility_flags_1 = eg.readUByte();
12597
+ var general_profile_compatibility_flags_2 = eg.readUByte();
12598
+ var general_profile_compatibility_flags_3 = eg.readUByte();
12599
+ var general_profile_compatibility_flags_4 = eg.readUByte();
12600
+ var general_constraint_indicator_flags_1 = eg.readUByte();
12601
+ var general_constraint_indicator_flags_2 = eg.readUByte();
12602
+ var general_constraint_indicator_flags_3 = eg.readUByte();
12603
+ var general_constraint_indicator_flags_4 = eg.readUByte();
12604
+ var general_constraint_indicator_flags_5 = eg.readUByte();
12605
+ var general_constraint_indicator_flags_6 = eg.readUByte();
12606
+ var general_level_idc = eg.readUByte();
12607
+ var sub_layer_profile_present_flags = [];
12608
+ var sub_layer_level_present_flags = [];
12609
+ for (var i = 0; i < max_sub_layers_minus1; i++) {
12610
+ sub_layer_profile_present_flags.push(eg.readBoolean());
12611
+ sub_layer_level_present_flags.push(eg.readBoolean());
12612
+ }
12613
+ if (max_sub_layers_minus1 > 0) {
12614
+ for (var _i = max_sub_layers_minus1; _i < 8; _i++) {
12615
+ eg.readBits(2);
12616
+ }
12617
+ }
12618
+ for (var _i2 = 0; _i2 < max_sub_layers_minus1; _i2++) {
12619
+ if (sub_layer_profile_present_flags[_i2]) {
12620
+ eg.readUByte(); // sub_layer_profile_space, sub_layer_tier_flag, sub_layer_profile_idc
12621
+ eg.readUByte();
12622
+ eg.readUByte();
12623
+ eg.readUByte();
12624
+ eg.readUByte(); // sub_layer_profile_compatibility_flag
12625
+ eg.readUByte();
12626
+ eg.readUByte();
12627
+ eg.readUByte();
12628
+ eg.readUByte();
12629
+ eg.readUByte();
12630
+ eg.readUByte();
12631
+ }
12632
+ if (sub_layer_level_present_flags[_i2]) {
12633
+ eg.readUByte();
12634
+ }
12635
+ }
12636
+ eg.readUEG(); // seq_parameter_set_id
12637
+ var chroma_format_idc = eg.readUEG();
12638
+ if (chroma_format_idc == 3) {
12639
+ eg.skipBits(1); //separate_colour_plane_flag
12640
+ }
12641
+ var pic_width_in_luma_samples = eg.readUEG();
12642
+ var pic_height_in_luma_samples = eg.readUEG();
12643
+ var conformance_window_flag = eg.readBoolean();
12644
+ var pic_left_offset = 0,
12645
+ pic_right_offset = 0,
12646
+ pic_top_offset = 0,
12647
+ pic_bottom_offset = 0;
12648
+ if (conformance_window_flag) {
12649
+ pic_left_offset += eg.readUEG();
12650
+ pic_right_offset += eg.readUEG();
12651
+ pic_top_offset += eg.readUEG();
12652
+ pic_bottom_offset += eg.readUEG();
12653
+ }
12654
+ var bit_depth_luma_minus8 = eg.readUEG();
12655
+ var bit_depth_chroma_minus8 = eg.readUEG();
12656
+ var log2_max_pic_order_cnt_lsb_minus4 = eg.readUEG();
12657
+ var sub_layer_ordering_info_present_flag = eg.readBoolean();
12658
+ for (var _i3 = sub_layer_ordering_info_present_flag ? 0 : max_sub_layers_minus1; _i3 <= max_sub_layers_minus1; _i3++) {
12659
+ eg.skipUEG(); // max_dec_pic_buffering_minus1[i]
12660
+ eg.skipUEG(); // max_num_reorder_pics[i]
12661
+ eg.skipUEG(); // max_latency_increase_plus1[i]
12662
+ }
12663
+ eg.skipUEG(); // log2_min_luma_coding_block_size_minus3
12664
+ eg.skipUEG(); // log2_diff_max_min_luma_coding_block_size
12665
+ eg.skipUEG(); // log2_min_transform_block_size_minus2
12666
+ eg.skipUEG(); // log2_diff_max_min_transform_block_size
12667
+ eg.skipUEG(); // max_transform_hierarchy_depth_inter
12668
+ eg.skipUEG(); // max_transform_hierarchy_depth_intra
12669
+ var scaling_list_enabled_flag = eg.readBoolean();
12670
+ if (scaling_list_enabled_flag) {
12671
+ var sps_scaling_list_data_present_flag = eg.readBoolean();
12672
+ if (sps_scaling_list_data_present_flag) {
12673
+ for (var sizeId = 0; sizeId < 4; sizeId++) {
12674
+ for (var matrixId = 0; matrixId < (sizeId === 3 ? 2 : 6); matrixId++) {
12675
+ var scaling_list_pred_mode_flag = eg.readBoolean();
12676
+ if (!scaling_list_pred_mode_flag) {
12677
+ eg.readUEG(); // scaling_list_pred_matrix_id_delta
12678
+ } else {
12679
+ var coefNum = Math.min(64, 1 << 4 + (sizeId << 1));
12680
+ if (sizeId > 1) {
12681
+ eg.readEG();
12682
+ }
12683
+ for (var _i4 = 0; _i4 < coefNum; _i4++) {
12684
+ eg.readEG();
12685
+ }
12324
12686
  }
12325
12687
  }
12326
12688
  }
12327
- // check if we can read unit type
12328
- if (i < len) {
12329
- unitType = array[i] & 0x1f;
12330
- // logger.log('find NALU @ offset:' + i + ',type:' + unitType);
12331
- lastUnitStart = i;
12332
- lastUnitType = unitType;
12333
- state = 0;
12334
- } else {
12335
- // not enough byte to read unit type. let's read it on next PES parsing
12336
- state = -1;
12337
- }
12338
- } else {
12339
- state = 0;
12340
12689
  }
12341
12690
  }
12342
- if (lastUnitStart >= 0 && state >= 0) {
12343
- var _unit = {
12344
- data: array.subarray(lastUnitStart, len),
12345
- type: lastUnitType,
12346
- state: state
12347
- };
12348
- units.push(_unit);
12349
- // logger.log('pushing NALU, type/size/state:' + unit.type + '/' + unit.data.byteLength + '/' + state);
12350
- }
12351
- // no NALu found
12352
- if (units.length === 0) {
12353
- // append pes.data to previous NAL unit
12354
- var _lastUnit = this.getLastNalUnit(track.samples);
12355
- if (_lastUnit) {
12356
- _lastUnit.data = appendUint8Array(_lastUnit.data, array);
12691
+ eg.readBoolean(); // amp_enabled_flag
12692
+ eg.readBoolean(); // sample_adaptive_offset_enabled_flag
12693
+ var pcm_enabled_flag = eg.readBoolean();
12694
+ if (pcm_enabled_flag) {
12695
+ eg.readUByte();
12696
+ eg.skipUEG();
12697
+ eg.skipUEG();
12698
+ eg.readBoolean();
12699
+ }
12700
+ var num_short_term_ref_pic_sets = eg.readUEG();
12701
+ var num_delta_pocs = 0;
12702
+ for (var _i5 = 0; _i5 < num_short_term_ref_pic_sets; _i5++) {
12703
+ var inter_ref_pic_set_prediction_flag = false;
12704
+ if (_i5 !== 0) {
12705
+ inter_ref_pic_set_prediction_flag = eg.readBoolean();
12706
+ }
12707
+ if (inter_ref_pic_set_prediction_flag) {
12708
+ if (_i5 === num_short_term_ref_pic_sets) {
12709
+ eg.readUEG();
12710
+ }
12711
+ eg.readBoolean();
12712
+ eg.readUEG();
12713
+ var next_num_delta_pocs = 0;
12714
+ for (var j = 0; j <= num_delta_pocs; j++) {
12715
+ var used_by_curr_pic_flag = eg.readBoolean();
12716
+ var use_delta_flag = false;
12717
+ if (!used_by_curr_pic_flag) {
12718
+ use_delta_flag = eg.readBoolean();
12719
+ }
12720
+ if (used_by_curr_pic_flag || use_delta_flag) {
12721
+ next_num_delta_pocs++;
12722
+ }
12723
+ }
12724
+ num_delta_pocs = next_num_delta_pocs;
12725
+ } else {
12726
+ var num_negative_pics = eg.readUEG();
12727
+ var num_positive_pics = eg.readUEG();
12728
+ num_delta_pocs = num_negative_pics + num_positive_pics;
12729
+ for (var _j = 0; _j < num_negative_pics; _j++) {
12730
+ eg.readUEG();
12731
+ eg.readBoolean();
12732
+ }
12733
+ for (var _j2 = 0; _j2 < num_positive_pics; _j2++) {
12734
+ eg.readUEG();
12735
+ eg.readBoolean();
12736
+ }
12737
+ }
12738
+ }
12739
+ var long_term_ref_pics_present_flag = eg.readBoolean();
12740
+ if (long_term_ref_pics_present_flag) {
12741
+ var num_long_term_ref_pics_sps = eg.readUEG();
12742
+ for (var _i6 = 0; _i6 < num_long_term_ref_pics_sps; _i6++) {
12743
+ for (var _j3 = 0; _j3 < log2_max_pic_order_cnt_lsb_minus4 + 4; _j3++) {
12744
+ eg.readBits(1);
12745
+ }
12746
+ eg.readBits(1);
12747
+ }
12748
+ }
12749
+ var min_spatial_segmentation_idc = 0;
12750
+ var sar_width = 1,
12751
+ sar_height = 1;
12752
+ var fps_fixed = true,
12753
+ fps_den = 1,
12754
+ fps_num = 0;
12755
+ eg.readBoolean(); // sps_temporal_mvp_enabled_flag
12756
+ eg.readBoolean(); // strong_intra_smoothing_enabled_flag
12757
+ var default_display_window_flag = false;
12758
+ var vui_parameters_present_flag = eg.readBoolean();
12759
+ if (vui_parameters_present_flag) {
12760
+ var aspect_ratio_info_present_flag = eg.readBoolean();
12761
+ if (aspect_ratio_info_present_flag) {
12762
+ var aspect_ratio_idc = eg.readUByte();
12763
+ var sar_width_table = [1, 12, 10, 16, 40, 24, 20, 32, 80, 18, 15, 64, 160, 4, 3, 2];
12764
+ var sar_height_table = [1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99, 3, 2, 1];
12765
+ if (aspect_ratio_idc > 0 && aspect_ratio_idc < 16) {
12766
+ sar_width = sar_width_table[aspect_ratio_idc - 1];
12767
+ sar_height = sar_height_table[aspect_ratio_idc - 1];
12768
+ } else if (aspect_ratio_idc === 255) {
12769
+ sar_width = eg.readBits(16);
12770
+ sar_height = eg.readBits(16);
12771
+ }
12772
+ }
12773
+ var overscan_info_present_flag = eg.readBoolean();
12774
+ if (overscan_info_present_flag) {
12775
+ eg.readBoolean();
12776
+ }
12777
+ var video_signal_type_present_flag = eg.readBoolean();
12778
+ if (video_signal_type_present_flag) {
12779
+ eg.readBits(3);
12780
+ eg.readBoolean();
12781
+ var colour_description_present_flag = eg.readBoolean();
12782
+ if (colour_description_present_flag) {
12783
+ eg.readUByte();
12784
+ eg.readUByte();
12785
+ eg.readUByte();
12786
+ }
12787
+ }
12788
+ var chroma_loc_info_present_flag = eg.readBoolean();
12789
+ if (chroma_loc_info_present_flag) {
12790
+ eg.readUEG();
12791
+ eg.readUEG();
12792
+ }
12793
+ eg.readBoolean(); // neutral_chroma_indication_flag
12794
+ eg.readBoolean(); // field_seq_flag
12795
+ eg.readBoolean(); // frame_field_info_present_flag
12796
+ default_display_window_flag = eg.readBoolean();
12797
+ if (default_display_window_flag) {
12798
+ pic_left_offset += eg.readUEG();
12799
+ pic_right_offset += eg.readUEG();
12800
+ pic_top_offset += eg.readUEG();
12801
+ pic_bottom_offset += eg.readUEG();
12802
+ }
12803
+ var vui_timing_info_present_flag = eg.readBoolean();
12804
+ if (vui_timing_info_present_flag) {
12805
+ fps_den = eg.readBits(32);
12806
+ fps_num = eg.readBits(32);
12807
+ var vui_poc_proportional_to_timing_flag = eg.readBoolean();
12808
+ if (vui_poc_proportional_to_timing_flag) {
12809
+ eg.readUEG();
12810
+ }
12811
+ var vui_hrd_parameters_present_flag = eg.readBoolean();
12812
+ if (vui_hrd_parameters_present_flag) {
12813
+ //const commonInfPresentFlag = true;
12814
+ //if (commonInfPresentFlag) {
12815
+ var nal_hrd_parameters_present_flag = eg.readBoolean();
12816
+ var vcl_hrd_parameters_present_flag = eg.readBoolean();
12817
+ var sub_pic_hrd_params_present_flag = false;
12818
+ if (nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag) {
12819
+ sub_pic_hrd_params_present_flag = eg.readBoolean();
12820
+ if (sub_pic_hrd_params_present_flag) {
12821
+ eg.readUByte();
12822
+ eg.readBits(5);
12823
+ eg.readBoolean();
12824
+ eg.readBits(5);
12825
+ }
12826
+ eg.readBits(4); // bit_rate_scale
12827
+ eg.readBits(4); // cpb_size_scale
12828
+ if (sub_pic_hrd_params_present_flag) {
12829
+ eg.readBits(4);
12830
+ }
12831
+ eg.readBits(5);
12832
+ eg.readBits(5);
12833
+ eg.readBits(5);
12834
+ }
12835
+ //}
12836
+ for (var _i7 = 0; _i7 <= max_sub_layers_minus1; _i7++) {
12837
+ fps_fixed = eg.readBoolean(); // fixed_pic_rate_general_flag
12838
+ var fixed_pic_rate_within_cvs_flag = fps_fixed || eg.readBoolean();
12839
+ var low_delay_hrd_flag = false;
12840
+ if (fixed_pic_rate_within_cvs_flag) {
12841
+ eg.readEG();
12842
+ } else {
12843
+ low_delay_hrd_flag = eg.readBoolean();
12844
+ }
12845
+ var cpb_cnt = low_delay_hrd_flag ? 1 : eg.readUEG() + 1;
12846
+ if (nal_hrd_parameters_present_flag) {
12847
+ for (var _j4 = 0; _j4 < cpb_cnt; _j4++) {
12848
+ eg.readUEG();
12849
+ eg.readUEG();
12850
+ if (sub_pic_hrd_params_present_flag) {
12851
+ eg.readUEG();
12852
+ eg.readUEG();
12853
+ }
12854
+ eg.skipBits(1);
12855
+ }
12856
+ }
12857
+ if (vcl_hrd_parameters_present_flag) {
12858
+ for (var _j5 = 0; _j5 < cpb_cnt; _j5++) {
12859
+ eg.readUEG();
12860
+ eg.readUEG();
12861
+ if (sub_pic_hrd_params_present_flag) {
12862
+ eg.readUEG();
12863
+ eg.readUEG();
12864
+ }
12865
+ eg.skipBits(1);
12866
+ }
12867
+ }
12868
+ }
12869
+ }
12357
12870
  }
12871
+ var bitstream_restriction_flag = eg.readBoolean();
12872
+ if (bitstream_restriction_flag) {
12873
+ eg.readBoolean(); // tiles_fixed_structure_flag
12874
+ eg.readBoolean(); // motion_vectors_over_pic_boundaries_flag
12875
+ eg.readBoolean(); // restricted_ref_pic_lists_flag
12876
+ min_spatial_segmentation_idc = eg.readUEG();
12877
+ }
12878
+ }
12879
+ var width = pic_width_in_luma_samples,
12880
+ height = pic_height_in_luma_samples;
12881
+ if (conformance_window_flag || default_display_window_flag) {
12882
+ var chroma_scale_w = 1,
12883
+ chroma_scale_h = 1;
12884
+ if (chroma_format_idc === 1) {
12885
+ // YUV 420
12886
+ chroma_scale_w = chroma_scale_h = 2;
12887
+ } else if (chroma_format_idc == 2) {
12888
+ // YUV 422
12889
+ chroma_scale_w = 2;
12890
+ }
12891
+ width = pic_width_in_luma_samples - chroma_scale_w * pic_right_offset - chroma_scale_w * pic_left_offset;
12892
+ height = pic_height_in_luma_samples - chroma_scale_h * pic_bottom_offset - chroma_scale_h * pic_top_offset;
12893
+ }
12894
+ var profile_space_string = general_profile_space ? ['A', 'B', 'C'][general_profile_space] : '';
12895
+ var profile_compatibility_buf = general_profile_compatibility_flags_1 << 24 | general_profile_compatibility_flags_2 << 16 | general_profile_compatibility_flags_3 << 8 | general_profile_compatibility_flags_4;
12896
+ var profile_compatibility_rev = 0;
12897
+ for (var _i8 = 0; _i8 < 32; _i8++) {
12898
+ profile_compatibility_rev = (profile_compatibility_rev | (profile_compatibility_buf >> _i8 & 1) << 31 - _i8) >>> 0; // reverse bit position (and cast as UInt32)
12899
+ }
12900
+ var profile_compatibility_flags_string = profile_compatibility_rev.toString(16);
12901
+ if (general_profile_idc === 1 && profile_compatibility_flags_string === '2') {
12902
+ profile_compatibility_flags_string = '6';
12903
+ }
12904
+ var tier_flag_string = general_tier_flag ? 'H' : 'L';
12905
+ return {
12906
+ codecString: "hvc1." + profile_space_string + general_profile_idc + "." + profile_compatibility_flags_string + "." + tier_flag_string + general_level_idc + ".B0",
12907
+ params: {
12908
+ general_tier_flag: general_tier_flag,
12909
+ general_profile_idc: general_profile_idc,
12910
+ general_profile_space: general_profile_space,
12911
+ general_profile_compatibility_flags: [general_profile_compatibility_flags_1, general_profile_compatibility_flags_2, general_profile_compatibility_flags_3, general_profile_compatibility_flags_4],
12912
+ general_constraint_indicator_flags: [general_constraint_indicator_flags_1, general_constraint_indicator_flags_2, general_constraint_indicator_flags_3, general_constraint_indicator_flags_4, general_constraint_indicator_flags_5, general_constraint_indicator_flags_6],
12913
+ general_level_idc: general_level_idc,
12914
+ bit_depth: bit_depth_luma_minus8 + 8,
12915
+ bit_depth_luma_minus8: bit_depth_luma_minus8,
12916
+ bit_depth_chroma_minus8: bit_depth_chroma_minus8,
12917
+ min_spatial_segmentation_idc: min_spatial_segmentation_idc,
12918
+ chroma_format_idc: chroma_format_idc,
12919
+ frame_rate: {
12920
+ fixed: fps_fixed,
12921
+ fps: fps_num / fps_den
12922
+ }
12923
+ },
12924
+ width: width,
12925
+ height: height,
12926
+ pixelRatio: [sar_width, sar_height]
12927
+ };
12928
+ };
12929
+ _proto.readPPS = function readPPS(pps) {
12930
+ var eg = new ExpGolomb(this.ebsp2rbsp(pps));
12931
+ eg.readUByte();
12932
+ eg.readUByte();
12933
+ eg.skipUEG(); // pic_parameter_set_id
12934
+ eg.skipUEG(); // seq_parameter_set_id
12935
+ eg.skipBits(2); // dependent_slice_segments_enabled_flag, output_flag_present_flag
12936
+ eg.skipBits(3); // num_extra_slice_header_bits
12937
+ eg.skipBits(2); // sign_data_hiding_enabled_flag, cabac_init_present_flag
12938
+ eg.skipUEG();
12939
+ eg.skipUEG();
12940
+ eg.skipEG(); // init_qp_minus26
12941
+ eg.skipBits(2); // constrained_intra_pred_flag, transform_skip_enabled_flag
12942
+ var cu_qp_delta_enabled_flag = eg.readBoolean();
12943
+ if (cu_qp_delta_enabled_flag) {
12944
+ eg.skipUEG();
12945
+ }
12946
+ eg.skipEG(); // cb_qp_offset
12947
+ eg.skipEG(); // cr_qp_offset
12948
+ eg.skipBits(4); // pps_slice_chroma_qp_offsets_present_flag, weighted_pred_flag, weighted_bipred_flag, transquant_bypass_enabled_flag
12949
+ var tiles_enabled_flag = eg.readBoolean();
12950
+ var entropy_coding_sync_enabled_flag = eg.readBoolean();
12951
+ var parallelismType = 1; // slice-based parallel decoding
12952
+ if (entropy_coding_sync_enabled_flag && tiles_enabled_flag) {
12953
+ parallelismType = 0; // mixed-type parallel decoding
12954
+ } else if (entropy_coding_sync_enabled_flag) {
12955
+ parallelismType = 3; // wavefront-based parallel decoding
12956
+ } else if (tiles_enabled_flag) {
12957
+ parallelismType = 2; // tile-based parallel decoding
12358
12958
  }
12359
- track.naluState = state;
12360
- return units;
12959
+ return {
12960
+ parallelismType: parallelismType
12961
+ };
12361
12962
  };
12362
- return AvcVideoParser;
12963
+ _proto.matchSPS = function matchSPS(sps1, sps2) {
12964
+ // compare without headers and VPS related params
12965
+ return String.fromCharCode.apply(null, sps1).substr(3) === String.fromCharCode.apply(null, sps2).substr(3);
12966
+ };
12967
+ return HevcVideoParser;
12363
12968
  }(BaseVideoParser);
12364
12969
 
12365
12970
  /**
@@ -12496,7 +13101,7 @@
12496
13101
  this.observer = observer;
12497
13102
  this.config = config;
12498
13103
  this.typeSupported = typeSupported;
12499
- this.videoParser = new AvcVideoParser();
13104
+ this.videoParser = null;
12500
13105
  }
12501
13106
  TSDemuxer.probe = function probe(data) {
12502
13107
  var syncOffset = TSDemuxer.syncOffset(data);
@@ -12666,7 +13271,19 @@
12666
13271
  case videoPid:
12667
13272
  if (stt) {
12668
13273
  if (videoData && (pes = parsePES(videoData))) {
12669
- this.videoParser.parseAVCPES(videoTrack, textTrack, pes, false, this._duration);
13274
+ if (this.videoParser === null) {
13275
+ switch (videoTrack.segmentCodec) {
13276
+ case 'avc':
13277
+ this.videoParser = new AvcVideoParser();
13278
+ break;
13279
+ case 'hevc':
13280
+ this.videoParser = new HevcVideoParser();
13281
+ break;
13282
+ }
13283
+ }
13284
+ if (this.videoParser !== null) {
13285
+ this.videoParser.parsePES(videoTrack, textTrack, pes, false, this._duration);
13286
+ }
12670
13287
  }
12671
13288
  videoData = {
12672
13289
  data: [],
@@ -12829,8 +13446,20 @@
12829
13446
  // try to parse last PES packets
12830
13447
  var pes;
12831
13448
  if (videoData && (pes = parsePES(videoData))) {
12832
- this.videoParser.parseAVCPES(videoTrack, textTrack, pes, true, this._duration);
12833
- videoTrack.pesData = null;
13449
+ if (this.videoParser === null) {
13450
+ switch (videoTrack.segmentCodec) {
13451
+ case 'avc':
13452
+ this.videoParser = new AvcVideoParser();
13453
+ break;
13454
+ case 'hevc':
13455
+ this.videoParser = new HevcVideoParser();
13456
+ break;
13457
+ }
13458
+ }
13459
+ if (this.videoParser !== null) {
13460
+ this.videoParser.parsePES(videoTrack, textTrack, pes, true, this._duration);
13461
+ videoTrack.pesData = null;
13462
+ }
12834
13463
  } else {
12835
13464
  // either avcData null or PES truncated, keep it for next frag parsing
12836
13465
  videoTrack.pesData = videoData;
@@ -13162,7 +13791,12 @@
13162
13791
  logger.warn('Unsupported EC-3 in M2TS found');
13163
13792
  break;
13164
13793
  case 0x24:
13165
- logger.warn('Unsupported HEVC in M2TS found');
13794
+ // ITU-T Rec. H.265 and ISO/IEC 23008-2 (HEVC)
13795
+ if (result.videoPid === -1) {
13796
+ result.videoPid = pid;
13797
+ result.segmentVideoCodec = 'hevc';
13798
+ logger.log('HEVC in M2TS found');
13799
+ }
13166
13800
  break;
13167
13801
  }
13168
13802
  // move to the next table entry
@@ -13390,6 +14024,8 @@
13390
14024
  avc1: [],
13391
14025
  // codingname
13392
14026
  avcC: [],
14027
+ hvc1: [],
14028
+ hvcC: [],
13393
14029
  btrt: [],
13394
14030
  dinf: [],
13395
14031
  dref: [],
@@ -13817,8 +14453,10 @@
13817
14453
  return MP4.box(MP4.types.stsd, MP4.STSD, MP4.ac3(track));
13818
14454
  }
13819
14455
  return MP4.box(MP4.types.stsd, MP4.STSD, MP4.mp4a(track));
13820
- } else {
14456
+ } else if (track.segmentCodec === 'avc') {
13821
14457
  return MP4.box(MP4.types.stsd, MP4.STSD, MP4.avc1(track));
14458
+ } else {
14459
+ return MP4.box(MP4.types.stsd, MP4.STSD, MP4.hvc1(track));
13822
14460
  }
13823
14461
  };
13824
14462
  MP4.tkhd = function tkhd(track) {
@@ -13956,6 +14594,84 @@
13956
14594
  var result = appendUint8Array(MP4.FTYP, movie);
13957
14595
  return result;
13958
14596
  };
14597
+ MP4.hvc1 = function hvc1(track) {
14598
+ var ps = track.params;
14599
+ var units = [track.vps, track.sps, track.pps];
14600
+ var NALuLengthSize = 4;
14601
+ var config = new Uint8Array([0x01, ps.general_profile_space << 6 | (ps.general_tier_flag ? 32 : 0) | ps.general_profile_idc, ps.general_profile_compatibility_flags[0], ps.general_profile_compatibility_flags[1], ps.general_profile_compatibility_flags[2], ps.general_profile_compatibility_flags[3], ps.general_constraint_indicator_flags[0], ps.general_constraint_indicator_flags[1], ps.general_constraint_indicator_flags[2], ps.general_constraint_indicator_flags[3], ps.general_constraint_indicator_flags[4], ps.general_constraint_indicator_flags[5], ps.general_level_idc, 240 | ps.min_spatial_segmentation_idc >> 8, 255 & ps.min_spatial_segmentation_idc, 252 | ps.parallelismType, 252 | ps.chroma_format_idc, 248 | ps.bit_depth_luma_minus8, 248 | ps.bit_depth_chroma_minus8, 0x00, parseInt(ps.frame_rate.fps), NALuLengthSize - 1 | ps.temporal_id_nested << 2 | ps.num_temporal_layers << 3 | (ps.frame_rate.fixed ? 64 : 0), units.length]);
14602
+
14603
+ // compute hvcC size in bytes
14604
+ var length = config.length;
14605
+ for (var i = 0; i < units.length; i += 1) {
14606
+ length += 3;
14607
+ for (var j = 0; j < units[i].length; j += 1) {
14608
+ length += 2 + units[i][j].length;
14609
+ }
14610
+ }
14611
+ var hvcC = new Uint8Array(length);
14612
+ hvcC.set(config, 0);
14613
+ length = config.length;
14614
+ // append parameter set units: one vps, one or more sps and pps
14615
+ var iMax = units.length - 1;
14616
+ for (var _i = 0; _i < units.length; _i += 1) {
14617
+ hvcC.set(new Uint8Array([32 + _i | (_i === iMax ? 128 : 0), 0x00, units[_i].length]), length);
14618
+ length += 3;
14619
+ for (var _j = 0; _j < units[_i].length; _j += 1) {
14620
+ hvcC.set(new Uint8Array([units[_i][_j].length >> 8, units[_i][_j].length & 255]), length);
14621
+ length += 2;
14622
+ hvcC.set(units[_i][_j], length);
14623
+ length += units[_i][_j].length;
14624
+ }
14625
+ }
14626
+ var hvcc = MP4.box(MP4.types.hvcC, hvcC);
14627
+ var width = track.width;
14628
+ var height = track.height;
14629
+ var hSpacing = track.pixelRatio[0];
14630
+ var vSpacing = track.pixelRatio[1];
14631
+ return MP4.box(MP4.types.hvc1, new Uint8Array([0x00, 0x00, 0x00,
14632
+ // reserved
14633
+ 0x00, 0x00, 0x00,
14634
+ // reserved
14635
+ 0x00, 0x01,
14636
+ // data_reference_index
14637
+ 0x00, 0x00,
14638
+ // pre_defined
14639
+ 0x00, 0x00,
14640
+ // reserved
14641
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
14642
+ // pre_defined
14643
+ width >> 8 & 0xff, width & 0xff,
14644
+ // width
14645
+ height >> 8 & 0xff, height & 0xff,
14646
+ // height
14647
+ 0x00, 0x48, 0x00, 0x00,
14648
+ // horizresolution
14649
+ 0x00, 0x48, 0x00, 0x00,
14650
+ // vertresolution
14651
+ 0x00, 0x00, 0x00, 0x00,
14652
+ // reserved
14653
+ 0x00, 0x01,
14654
+ // frame_count
14655
+ 0x12, 0x64, 0x61, 0x69, 0x6c,
14656
+ // dailymotion/hls.js
14657
+ 0x79, 0x6d, 0x6f, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x68, 0x6c, 0x73, 0x2e, 0x6a, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
14658
+ // compressorname
14659
+ 0x00, 0x18,
14660
+ // depth = 24
14661
+ 0x11, 0x11]),
14662
+ // pre_defined = -1
14663
+ hvcc, MP4.box(MP4.types.btrt, new Uint8Array([0x00, 0x1c, 0x9c, 0x80,
14664
+ // bufferSizeDB
14665
+ 0x00, 0x2d, 0xc6, 0xc0,
14666
+ // maxBitrate
14667
+ 0x00, 0x2d, 0xc6, 0xc0])),
14668
+ // avgBitrate
14669
+ MP4.box(MP4.types.pasp, new Uint8Array([hSpacing >> 24,
14670
+ // hSpacing
14671
+ hSpacing >> 16 & 0xff, hSpacing >> 8 & 0xff, hSpacing & 0xff, vSpacing >> 24,
14672
+ // vSpacing
14673
+ vSpacing >> 16 & 0xff, vSpacing >> 8 & 0xff, vSpacing & 0xff])));
14674
+ };
13959
14675
  return MP4;
13960
14676
  }();
13961
14677
  MP4.types = void 0;
@@ -14357,9 +15073,9 @@
14357
15073
  var foundOverlap = delta < -1;
14358
15074
  if (foundHole || foundOverlap) {
14359
15075
  if (foundHole) {
14360
- logger.warn("AVC: " + toMsFromMpegTsClock(delta, true) + " ms (" + delta + "dts) hole between fragments detected at " + timeOffset.toFixed(3));
15076
+ logger.warn((track.segmentCodec || '').toUpperCase() + ": " + toMsFromMpegTsClock(delta, true) + " ms (" + delta + "dts) hole between fragments detected at " + timeOffset.toFixed(3));
14361
15077
  } else {
14362
- logger.warn("AVC: " + toMsFromMpegTsClock(-delta, true) + " ms (" + delta + "dts) overlapping between fragments detected at " + timeOffset.toFixed(3));
15078
+ logger.warn((track.segmentCodec || '').toUpperCase() + ": " + toMsFromMpegTsClock(-delta, true) + " ms (" + delta + "dts) overlapping between fragments detected at " + timeOffset.toFixed(3));
14363
15079
  }
14364
15080
  if (!foundOverlap || nextAvcDts >= inputSamples[0].pts || chromeVersion) {
14365
15081
  firstDTS = nextAvcDts;
@@ -14533,7 +15249,7 @@
14533
15249
  }
14534
15250
  }
14535
15251
  }
14536
- // next AVC sample DTS should be equal to last sample DTS + last sample duration (in PES timescale)
15252
+ // next AVC/HEVC sample DTS should be equal to last sample DTS + last sample duration (in PES timescale)
14537
15253
  mp4SampleDuration = stretchedLastFrame || !mp4SampleDuration ? averageSampleDuration : mp4SampleDuration;
14538
15254
  this.nextAvcDts = nextAvcDts = lastDTS + mp4SampleDuration;
14539
15255
  this.videoSampleDuration = mp4SampleDuration;
@@ -29301,7 +30017,7 @@
29301
30017
  * Get the video-dev/hls.js package version.
29302
30018
  */
29303
30019
  function get() {
29304
- return "1.5.2-0.canary.9970";
30020
+ return "1.5.2-0.canary.9971";
29305
30021
  }
29306
30022
  }, {
29307
30023
  key: "Events",