优化标签解析

This commit is contained in:
Harvey Zack committed 2018-12-21 15:43:12 +08:00
1 parent a2125a2634
commit 348aabf44c
4 files changed
+46 -34

No files matched your search

+23 -16
View File
@@ -670,8 +670,8 @@
reader.readAsArrayBuffer(file);
}
function getMetaData(scripTag) {
var readScripTag = readUint8(scripTag.body);
function parseScripTag(scripTagBody) {
var readScripTag = readUint8(scripTagBody);
var metadata = Object.create(null);
var amf1 = Object.create(null);
var amf2 = Object.create(null);
@@ -719,7 +719,7 @@
value = Object.create(null);
var endObject = false;
while (!endObject && readScripTag.index < scripTag.body.length) {
while (!endObject && readScripTag.index < scripTagBody.length) {
var nameLength = getUint8Sum(readScripTag(2));
var name = bin2String(readScripTag(nameLength));
var _type = readScripTag(1)[0];
@@ -741,7 +741,7 @@
value = Object.create(null);
var endArray = false;
while (!endArray && readScripTag.index < scripTag.body.length) {
while (!endArray && readScripTag.index < scripTagBody.length) {
var _nameLength = getUint8Sum(readScripTag(2));
var _name = bin2String(readScripTag(_nameLength));
@@ -783,7 +783,7 @@
}
default:
console.log(readScripTag(scripTag.body.length - readScripTag.index - 1));
console.log(readScripTag(scripTagBody.length - readScripTag.index - 1));
errorHandle(false, "AMF: Unknown metaData type: ".concat(type));
break;
}
@@ -792,7 +792,7 @@
return value;
}
while (readScripTag.index < scripTag.body.length) {
while (readScripTag.index < scripTagBody.length) {
var nameLength = getUint8Sum(readScripTag(2));
var name = bin2String(readScripTag(nameLength));
var type = readScripTag(1)[0];
@@ -802,7 +802,7 @@
}
}
errorHandle(readScripTag.index === scripTag.body.length, 'AMF: Seems to be incompletely parsed');
errorHandle(readScripTag.index === scripTagBody.length, 'AMF: Seems to be incompletely parsed');
errorHandle(amf2.size === Object.keys(amf2.metaData).length, 'AMF: [amf2] length does not match');
metadata.amf1 = amf1;
metadata.amf2 = amf2;
@@ -824,7 +824,7 @@
this.uint8 = new Uint8Array(0);
this.index = 0;
this.header = null;
this.metadata = null;
this.scripTag = null;
this.tags = [];
this.done = false;
flv.on('flvFetchStart', function () {
@@ -853,7 +853,7 @@
_this.uint8 = uint8;
_this.index = 0;
_this.header = null;
_this.metadata = null;
_this.scripTag = null;
_this.tags = [];
_this.parse();
@@ -917,16 +917,23 @@
tag.body = this.read(tag.dataSize);
this.tags.push(tag);
this.read(4);
this.flv.emit('flvParseTag', tag);
}
if (this.tags.length > 1 && this.tags[0].tagType === 18 && !this.metadata) {
this.metadata = getMetaData(this.tags[0]);
this.flv.emit('parseMetadata', this.metadata);
switch (tag.tagType) {
case 18:
this.scripTag = parseScripTag(tag.body);
this.flv.emit('parseScripTag', this.scripTag);
if (debug) {
console.log('[flv-parse-metadata]', this.metadata);
if (debug) {
console.log('[flv-parse-scrip-tag]', this.scripTag);
}
break;
default:
break;
}
this.flv.emit('flvParseTag', tag);
}
}
}, {
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"artplayer-plugin-flv.js","sources":["../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../packages/artplayer-plugin-flv/node_modules/tiny-emitter/index.js","../../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArray.js","../../node_modules/@babel/runtime/helpers/nonIterableSpread.js","../../node_modules/@babel/runtime/helpers/toConsumableArray.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../packages/artplayer-plugin-flv/src/utils/flvError.js","../../packages/artplayer-plugin-flv/src/utils/index.js","../../packages/artplayer-plugin-flv/src/utils/checkSupport.js","../../packages/artplayer-plugin-flv/src/eventProxy.js","../../packages/artplayer-plugin-flv/src/creatWorker.js","../../packages/artplayer-plugin-flv/src/config.js","../../packages/artplayer-plugin-flv/src/creatMediaSource.js","../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../packages/artplayer-plugin-flv/src/flvParse/fetchStream.js","../../packages/artplayer-plugin-flv/src/flvParse/readFile.js","../../packages/artplayer-plugin-flv/src/flvParse/getMetaData.js","../../packages/artplayer-plugin-flv/src/flvParse/index.js","../../packages/artplayer-plugin-flv/src/index.js"],"sourcesContent":["function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\nmodule.exports = _createClass;","function _typeof2(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof2(obj); }\n\nfunction _typeof(obj) {\n if (typeof Symbol === \"function\" && _typeof2(Symbol.iterator) === \"symbol\") {\n module.exports = _typeof = function _typeof(obj) {\n return _typeof2(obj);\n };\n } else {\n module.exports = _typeof = function _typeof(obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : _typeof2(obj);\n };\n }\n\n return _typeof(obj);\n}\n\nmodule.exports = _typeof;","function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized;","var _typeof = require(\"../helpers/typeof\");\n\nvar assertThisInitialized = require(\"./assertThisInitialized\");\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn;","function _getPrototypeOf(o) {\n module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf;","function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" &&Line truncated
{"version":3,"file":"artplayer-plugin-flv.js","sources":["../../node_modules/@babel/runtime/helpers/classCallCheck.js","../../node_modules/@babel/runtime/helpers/createClass.js","../../node_modules/@babel/runtime/helpers/typeof.js","../../node_modules/@babel/runtime/helpers/assertThisInitialized.js","../../node_modules/@babel/runtime/helpers/possibleConstructorReturn.js","../../node_modules/@babel/runtime/helpers/getPrototypeOf.js","../../node_modules/@babel/runtime/helpers/setPrototypeOf.js","../../node_modules/@babel/runtime/helpers/inherits.js","../../packages/artplayer-plugin-flv/node_modules/tiny-emitter/index.js","../../node_modules/@babel/runtime/helpers/arrayWithoutHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArray.js","../../node_modules/@babel/runtime/helpers/nonIterableSpread.js","../../node_modules/@babel/runtime/helpers/toConsumableArray.js","../../node_modules/@babel/runtime/helpers/isNativeFunction.js","../../node_modules/@babel/runtime/helpers/construct.js","../../node_modules/@babel/runtime/helpers/wrapNativeSuper.js","../../packages/artplayer-plugin-flv/src/utils/flvError.js","../../packages/artplayer-plugin-flv/src/utils/index.js","../../packages/artplayer-plugin-flv/src/utils/checkSupport.js","../../packages/artplayer-plugin-flv/src/eventProxy.js","../../packages/artplayer-plugin-flv/src/creatWorker.js","../../packages/artplayer-plugin-flv/src/config.js","../../packages/artplayer-plugin-flv/src/creatMediaSource.js","../../node_modules/@babel/runtime/helpers/arrayWithHoles.js","../../node_modules/@babel/runtime/helpers/iterableToArrayLimit.js","../../node_modules/@babel/runtime/helpers/nonIterableRest.js","../../node_modules/@babel/runtime/helpers/slicedToArray.js","../../packages/artplayer-plugin-flv/src/flvParse/fetchStream.js","../../packages/artplayer-plugin-flv/src/flvParse/readFile.js","../../packages/artplayer-plugin-flv/src/flvParse/parseScripTag.js","../../packages/artplayer-plugin-flv/src/flvParse/index.js","../../packages/artplayer-plugin-flv/src/index.js"],"sourcesContent":["function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}\n\nmodule.exports = _classCallCheck;","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nfunction _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n return Constructor;\n}\n\nmodule.exports = _createClass;","function _typeof2(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof2 = function _typeof2(obj) { return typeof obj; }; } else { _typeof2 = function _typeof2(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof2(obj); }\n\nfunction _typeof(obj) {\n if (typeof Symbol === \"function\" && _typeof2(Symbol.iterator) === \"symbol\") {\n module.exports = _typeof = function _typeof(obj) {\n return _typeof2(obj);\n };\n } else {\n module.exports = _typeof = function _typeof(obj) {\n return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : _typeof2(obj);\n };\n }\n\n return _typeof(obj);\n}\n\nmodule.exports = _typeof;","function _assertThisInitialized(self) {\n if (self === void 0) {\n throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");\n }\n\n return self;\n}\n\nmodule.exports = _assertThisInitialized;","var _typeof = require(\"../helpers/typeof\");\n\nvar assertThisInitialized = require(\"./assertThisInitialized\");\n\nfunction _possibleConstructorReturn(self, call) {\n if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) {\n return call;\n }\n\n return assertThisInitialized(self);\n}\n\nmodule.exports = _possibleConstructorReturn;","function _getPrototypeOf(o) {\n module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {\n return o.__proto__ || Object.getPrototypeOf(o);\n };\n return _getPrototypeOf(o);\n}\n\nmodule.exports = _getPrototypeOf;","function _setPrototypeOf(o, p) {\n module.exports = _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {\n o.__proto__ = p;\n return o;\n };\n\n return _setPrototypeOf(o, p);\n}\n\nmodule.exports = _setPrototypeOf;","var setPrototypeOf = require(\"./setPrototypeOf\");\n\nfunction _inherits(subClass, superClass) {\n if (typeof superClass !== \"function\" Line truncated
@@ -1,6 +1,6 @@
import fetchStream from './fetchStream';
import readFile from './readFile';
import getMetaData from './getMetaData';
import parseScripTag from './parseScripTag';
import { mergeTypedArrays, getUint8Sum, bin2String } from '../utils';
export default class FlvParse {
@@ -10,7 +10,7 @@ export default class FlvParse {
this.uint8 = new Uint8Array(0);
this.index = 0;
this.header = null;
this.metadata = null;
this.scripTag = null;
this.tags = [];
this.done = false;
@@ -40,7 +40,7 @@ export default class FlvParse {
this.uint8 = uint8;
this.index = 0;
this.header = null;
this.metadata = null;
this.scripTag = null;
this.tags = [];
this.parse();
}
@@ -82,15 +82,20 @@ export default class FlvParse {
tag.body = this.read(tag.dataSize);
this.tags.push(tag);
this.read(4);
this.flv.emit('flvParseTag', tag);
}
if (this.tags.length > 1 && this.tags[0].tagType === 18 && !this.metadata) {
this.metadata = getMetaData(this.tags[0]);
this.flv.emit('parseMetadata', this.metadata);
if (debug) {
console.log('[flv-parse-metadata]', this.metadata);
switch (tag.tagType) {
case 18:
this.scripTag = parseScripTag(tag.body);
this.flv.emit('parseScripTag', this.scripTag);
if (debug) {
console.log('[flv-parse-scrip-tag]', this.scripTag);
}
break;
default:
break;
}
this.flv.emit('flvParseTag', tag);
}
}
@@ -1,7 +1,7 @@
import { getUint8Sum, readUint8, bin2String, bin2Boolean, bin2Float, errorHandle } from '../utils';
export default function getMetaData(scripTag) {
const readScripTag = readUint8(scripTag.body);
export default function parseScripTag(scripTagBody) {
const readScripTag = readUint8(scripTagBody);
const metadata = Object.create(null);
const amf1 = Object.create(null);
const amf2 = Object.create(null);
@@ -34,7 +34,7 @@ export default function getMetaData(scripTag) {
case 3: {
value = Object.create(null);
let endObject = false;
while (!endObject && readScripTag.index < scripTag.body.length) {
while (!endObject && readScripTag.index < scripTagBody.length) {
const nameLength = getUint8Sum(readScripTag(2));
const name = bin2String(readScripTag(nameLength));
const type = readScripTag(1)[0];
@@ -50,7 +50,7 @@ export default function getMetaData(scripTag) {
case 8: {
value = Object.create(null);
let endArray = false;
while (!endArray && readScripTag.index < scripTag.body.length) {
while (!endArray && readScripTag.index < scripTagBody.length) {
const nameLength = getUint8Sum(readScripTag(2));
const name = bin2String(readScripTag(nameLength));
const type = readScripTag(1)[0];
@@ -78,7 +78,7 @@ export default function getMetaData(scripTag) {
break;
}
default:
console.log(readScripTag(scripTag.body.length - readScripTag.index - 1));
console.log(readScripTag(scripTagBody.length - readScripTag.index - 1));
errorHandle(false, `AMF: Unknown metaData type: ${type}`);
break;
}
@@ -86,7 +86,7 @@ export default function getMetaData(scripTag) {
return value;
}
while (readScripTag.index < scripTag.body.length) {
while (readScripTag.index < scripTagBody.length) {
const nameLength = getUint8Sum(readScripTag(2));
const name = bin2String(readScripTag(nameLength));
const type = readScripTag(1)[0];
@@ -95,7 +95,7 @@ export default function getMetaData(scripTag) {
}
}
errorHandle(readScripTag.index === scripTag.body.length, 'AMF: Seems to be incompletely parsed');
errorHandle(readScripTag.index === scripTagBody.length, 'AMF: Seems to be incompletely parsed');
errorHandle(amf2.size === Object.keys(amf2.metaData).length, 'AMF: [amf2] length does not match');
metadata.amf1 = amf1;