xgplayer-mp4 2.0.2 → 2.0.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xgplayer-mp4",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "description": "xgplayer plugin for mp4 transform to fmp4",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -8,6 +8,7 @@
8
8
  "build": "node ./src/version.js && webpack --progress --display-chunks -p",
9
9
  "watch": "webpack --progress --display-chunks -p --watch",
10
10
  "test": "karma start --single-run",
11
+ "release": "npm publish --registry=https://registry.npmjs.org",
11
12
  "test:watch": "karma start"
12
13
  },
13
14
  "repository": {
package/src/mp4.js CHANGED
@@ -254,13 +254,7 @@ class MP4 {
254
254
  if (nextBox) {
255
255
  if (nextBox.type === 'moov') {
256
256
  self.getData(moovStart, moovStart + nextBox.size + 28).then(res => {
257
- let parsed
258
- // try {
259
- parsed = new Parser(res)
260
- // }catch(e) {
261
-
262
- // }
263
-
257
+ let parsed = new Parser(res)
264
258
  self._boxes = self._boxes.concat(parsed.boxes)
265
259
  moov = parsed.boxes.filter(box => box.type === 'moov')
266
260
  if (moov.length) {
@@ -307,6 +301,7 @@ class MP4 {
307
301
  let stsz = util.findBox(trak, 'stsz') // sample-size
308
302
  let stts = util.findBox(trak, 'stts') // sample-time
309
303
  let stco = util.findBox(trak, 'stco') // chunk-offset
304
+
310
305
  let cttsObj = type === 'video' ? this._cttsObj : null;
311
306
  let stscObj = type === 'video' ? this._stscVideoObj : this._stscAudioObj;
312
307
  let mdatStart = this.mdatStart
@@ -333,12 +328,11 @@ class MP4 {
333
328
  })
334
329
  }
335
330
  } else {
336
- let offset = util.seekSampleOffset(stsc, stco, stsz, start, mdatStart, stscObj)
337
331
  samples = {
338
332
  idx: start,
339
333
  size: stsz.entries[start],
340
334
  time: util.seekSampleTime(stts, cttsObj, start),
341
- offset: offset
335
+ offset: util.seekSampleOffset(stsc, stco, stsz, start, mdatStart, stscObj)
342
336
  }
343
337
  }
344
338
  return samples
@@ -481,7 +475,7 @@ class MP4 {
481
475
  end = videoNextFrame.offset
482
476
  if (this.audioTrak) {
483
477
  let audioNextFrame = this.getSamplesByOrders('audio', this.audioKeyFrames[fragIndex + 1].order, 0)
484
- end = Math.max(end, audioNextFrame.offset || 0)
478
+ end = Math.max(end, audioNextFrame.offset)
485
479
  }
486
480
  }
487
481
  if (window.isNaN(start) || (end !== undefined && window.isNaN(end))) {
@@ -493,10 +487,7 @@ class MP4 {
493
487
  loadFragment (fragIndex) {
494
488
  let self = this
495
489
  let range = this.getFragRange(fragIndex)
496
- if(range === [0, 0]) {
497
- debugger
498
- return false;
499
- }
490
+ if(range === [0, 0]) return false;
500
491
  return this.getData(range[0], range[1]).then((dat) => {
501
492
  return self.createFragment(new Uint8Array(dat), range[0] - this.mdatStart, fragIndex)
502
493
  })
@@ -5,9 +5,6 @@ Box.MP4DecConfigDescrTag = function (stream) {
5
5
  let box = new Box()
6
6
  let size
7
7
  box.type = stream.readUint8()
8
- if (box.type !== 4) {
9
- return box
10
- }
11
8
  size = stream.readUint8()
12
9
  if (size === 0x80) {
13
10
  box.extend = true
@@ -4,10 +4,6 @@ Box.MP4DecSpecificDescrTag = function (stream) {
4
4
  let box = new Box()
5
5
  let size, dataSize
6
6
  box.type = stream.readUint8()
7
- if (box.type !== 5) {
8
- stream.position = stream.position - 1
9
- return box
10
- }
11
7
  size = stream.readUint8()
12
8
  if (size === 0x80) {
13
9
  box.extend = true
@@ -5,13 +5,8 @@ Box.esds = function () {
5
5
  let stream = new Stream(this.data)
6
6
  this.version = stream.readUint8()
7
7
  this.flag = Stream.readByte(stream.dataview, 3)
8
- try {
9
- let box = Box.MP4ESDescrTag(stream)
10
- this.subBox.push(box)
11
- delete this.data
12
- stream = null
13
- }catch(e) {
14
- console.error(e)
15
- }
16
-
8
+ let box = Box.MP4ESDescrTag(stream)
9
+ this.subBox.push(box)
10
+ delete this.data
11
+ stream = null
17
12
  }
package/src/util/index.js CHANGED
@@ -69,11 +69,12 @@ util.stscOffset = function (stsc, sample_order, stscObj) {
69
69
  // let chunk_start = stsc.entries.filter((item) => {
70
70
  // return item.first_sample <= sample_order && sample_order < item.first_sample + item.chunk_count * item.samples_per_chunk
71
71
  // })[0]
72
- let chunk_start = stscObj[sample_order];
72
+ let chunk_start = stscObj[sample_order]
73
73
  if (!chunk_start) {
74
74
  let last_chunk = stsc.entries.pop()
75
75
  stsc.entries.push(last_chunk)
76
76
  let chunk_offset = Math.floor((sample_order - last_chunk.first_sample) / last_chunk.samples_per_chunk)
77
+ chunk_offset = Math.min(chunk_offset, last_chunk.chunk_count)
77
78
  let last_chunk_index = last_chunk.first_chunk + chunk_offset
78
79
  let last_chunk_first_sample = last_chunk.first_sample + last_chunk.samples_per_chunk * chunk_offset
79
80
  return {
@@ -94,9 +95,7 @@ util.stscOffset = function (stsc, sample_order, stscObj) {
94
95
 
95
96
  util.seekSampleOffset = function (stsc, stco, stsz, order, mdatStart, stscObj) {
96
97
  let chunkOffset = util.stscOffset(stsc, order + 1, stscObj)
97
- let sum = util.sum.apply(null, stsz.entries.slice(chunkOffset.samples_offset[0] - 1, chunkOffset.samples_offset[1] - 1))
98
- let ss = stco.entries[chunkOffset.chunk_index - 1]
99
- let result = ss + sum - mdatStart
98
+ let result = stco.entries[chunkOffset.chunk_index - 1] + util.sum.apply(null, stsz.entries.slice(chunkOffset.samples_offset[0] - 1, chunkOffset.samples_offset[1] - 1)) - mdatStart
100
99
  if (result === undefined) {
101
100
  throw `result=${result},stco.length=${stco.entries.length},sum=${util.sum.apply(null, stsz.entries.slice(0, order))}`
102
101
  } else if (result < 0) {
@@ -119,7 +118,7 @@ util.seekSampleTime = function (stts, cttsObj, order) {
119
118
  }
120
119
  })
121
120
  if (cttsObj) {
122
- if(cttsObj[order]){
121
+ if (cttsObj[order]) {
123
122
  offset = cttsObj[order]
124
123
  }
125
124
  }
@@ -241,11 +240,11 @@ util.toUTF8 = function (str) {
241
240
  }
242
241
 
243
242
  util.bufferToString = function (value) {
244
- return ("0"+(Number(value).toString(16))).slice(-2).toUpperCase()
243
+ return ('0' + (Number(value).toString(16))).slice(-2).toUpperCase()
245
244
  }
246
245
  util.strToBuf = function (str) {
247
246
  let buffer = []
248
- for(let i = 0; i < str.length; i = i + 2) {
247
+ for (let i = 0; i < str.length; i = i + 2) {
249
248
  buffer.push(
250
249
  parseInt(str[i] + str[i + 1], 16)
251
250
  )
@@ -253,20 +252,20 @@ util.strToBuf = function (str) {
253
252
  return new Uint8Array(buffer)
254
253
  }
255
254
  util.str2hex = function (str) {
256
- if(str === "") {
257
- return ""
255
+ if (str === '') {
256
+ return ''
258
257
  }
259
- let arr = [];
260
- for(let i = 0; i < str.length; i++) {
258
+ let arr = []
259
+ for (let i = 0; i < str.length; i++) {
261
260
  arr.push(str.charCodeAt(i))
262
261
  }
263
262
  return arr
264
263
  }
265
264
  util.parse = function (a) {
266
265
  if (!Array.isArray(a)) {
267
- let arr = [];
268
- let value = '';
269
- for(let i = 0; i < a.length; i++) {
266
+ let arr = []
267
+ let value = ''
268
+ for (let i = 0; i < a.length; i++) {
270
269
  if (i % 2) {
271
270
  value = a[i - 1] + a[ i ]
272
271
  arr.push(parseInt(value, 16))
@@ -275,6 +274,6 @@ util.parse = function (a) {
275
274
  }
276
275
  return arr
277
276
  }
278
- return a.map(item => {return parseInt(item, 16)})
277
+ return a.map(item => { return parseInt(item, 16) })
279
278
  }
280
279
  export default util
package/version.json CHANGED
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "2.0.2"
2
+ "version": "2.0.4"
3
3
  }
package/webpack.config.js CHANGED
@@ -41,7 +41,7 @@ const client = {
41
41
  library: 'Mp4Player',
42
42
  libraryTarget: 'window'
43
43
  },
44
- // devtool: argv.watch ? 'source-map' : 'none',
44
+ devtool: argv.watch ? 'source-map' : 'none',
45
45
  module: {
46
46
  rules: [
47
47
  {