mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 08:01:20 -08:00
解析amf成功
This commit is contained in:
1 parent
94aaf29da8
commit
3afe2e1640
4 files changed
+204
-102
No files matched your search
@@ -667,56 +667,131 @@
|
|||||||
var slicedToArray = _slicedToArray;
|
var slicedToArray = _slicedToArray;
|
||||||
|
|
||||||
function getMetaData(scripTag) {
|
function getMetaData(scripTag) {
|
||||||
var readMetaData = readUint8(scripTag.body);
|
var readScripTag = readUint8(scripTag.body);
|
||||||
var metadata = Object.create(null);
|
var metadata = Object.create(null);
|
||||||
var amf1 = Object.create(null);
|
var amf1 = Object.create(null);
|
||||||
var amf2 = Object.create(null);
|
var amf2 = Object.create(null);
|
||||||
|
|
||||||
var _readMetaData = readMetaData(1);
|
var _readScripTag = readScripTag(1);
|
||||||
|
|
||||||
var _readMetaData2 = slicedToArray(_readMetaData, 1);
|
var _readScripTag2 = slicedToArray(_readScripTag, 1);
|
||||||
|
|
||||||
amf1.type = _readMetaData2[0];
|
amf1.type = _readScripTag2[0];
|
||||||
amf1.size = getUint8Sum(readMetaData(2));
|
amf1.size = getUint8Sum(readScripTag(2));
|
||||||
amf1.string = bin2String(readMetaData(amf1.size));
|
amf1.string = bin2String(readScripTag(amf1.size));
|
||||||
|
|
||||||
var _readMetaData3 = readMetaData(1);
|
var _readScripTag3 = readScripTag(1);
|
||||||
|
|
||||||
var _readMetaData4 = slicedToArray(_readMetaData3, 1);
|
var _readScripTag4 = slicedToArray(_readScripTag3, 1);
|
||||||
|
|
||||||
amf2.type = _readMetaData4[0];
|
amf2.type = _readScripTag4[0];
|
||||||
amf2.size = getUint8Sum(readMetaData(4));
|
amf2.size = getUint8Sum(readScripTag(4));
|
||||||
amf2.metaData = Object.create(null);
|
amf2.metaData = Object.create(null);
|
||||||
|
|
||||||
while (readMetaData.index < scripTag.body.length) {
|
function getValue(type) {
|
||||||
var nameLength = getUint8Sum(readMetaData(2));
|
var value = null;
|
||||||
var name = bin2String(readMetaData(nameLength));
|
|
||||||
var type = readMetaData(1)[0];
|
|
||||||
|
|
||||||
switch (type) {
|
if (type !== undefined) {
|
||||||
case 0:
|
switch (type) {
|
||||||
amf2.metaData[name] = bin2Float(readMetaData(8));
|
case 0:
|
||||||
break;
|
value = bin2Float(readScripTag(8));
|
||||||
|
|
||||||
case 1:
|
|
||||||
amf2.metaData[name] = bin2Boolean(readMetaData(1)[0]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
{
|
|
||||||
var valueLength = getUint8Sum(readMetaData(2));
|
|
||||||
amf2.metaData[name] = bin2String(readMetaData(valueLength));
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case 3:
|
case 1:
|
||||||
amf2.metaData[name] = Object.create(null);
|
value = bin2Boolean(readScripTag(1)[0]);
|
||||||
readMetaData(scripTag.body.length - readMetaData.index);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
case 2:
|
||||||
errorHandle(false, "AMF: Unknown metaData type: ".concat(type));
|
{
|
||||||
break;
|
var valueLength = getUint8Sum(readScripTag(2));
|
||||||
|
value = bin2String(readScripTag(valueLength));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
value = Object.create(null);
|
||||||
|
var endObject = false;
|
||||||
|
|
||||||
|
while (!endObject && readScripTag.index < scripTag.body.length) {
|
||||||
|
var nameLength = getUint8Sum(readScripTag(2));
|
||||||
|
var name = bin2String(readScripTag(nameLength));
|
||||||
|
var _type = readScripTag(1)[0];
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
value[name] = getValue(_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_type === 9) {
|
||||||
|
endObject = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 8:
|
||||||
|
{
|
||||||
|
value = Object.create(null);
|
||||||
|
var _endObject = false;
|
||||||
|
|
||||||
|
while (!_endObject && readScripTag.index < scripTag.body.length) {
|
||||||
|
var _nameLength = getUint8Sum(readScripTag(2));
|
||||||
|
|
||||||
|
var _name = bin2String(readScripTag(_nameLength));
|
||||||
|
|
||||||
|
var _type2 = readScripTag(1)[0];
|
||||||
|
|
||||||
|
if (_name) {
|
||||||
|
value[_name] = getValue(_type2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_type2 === 9) {
|
||||||
|
_endObject = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 10:
|
||||||
|
{
|
||||||
|
var _valueLength = getUint8Sum(readScripTag(4));
|
||||||
|
|
||||||
|
value = [];
|
||||||
|
|
||||||
|
for (var index = 0; index < _valueLength; index += 1) {
|
||||||
|
var itemType = readScripTag(1)[0];
|
||||||
|
value.push(getValue(itemType));
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 12:
|
||||||
|
{
|
||||||
|
var _valueLength2 = getUint8Sum(readScripTag(4));
|
||||||
|
|
||||||
|
value = bin2String(readScripTag(_valueLength2));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
console.warn("AMF: Unknown metaData type: ".concat(type, " in ").concat(readScripTag.index - 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (readScripTag.index < scripTag.body.length) {
|
||||||
|
var nameLength = getUint8Sum(readScripTag(2));
|
||||||
|
var name = bin2String(readScripTag(nameLength));
|
||||||
|
var type = readScripTag(1)[0];
|
||||||
|
|
||||||
|
if (name) {
|
||||||
|
amf2.metaData[name] = getValue(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -733,6 +808,7 @@
|
|||||||
|
|
||||||
classCallCheck(this, FlvParse);
|
classCallCheck(this, FlvParse);
|
||||||
|
|
||||||
|
this.flv = flv;
|
||||||
var url = flv.options.url;
|
var url = flv.options.url;
|
||||||
this.uint8 = new Uint8Array(0);
|
this.uint8 = new Uint8Array(0);
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
@@ -769,8 +845,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
flv.emit('parseDone');
|
flv.emit('parseDone');
|
||||||
|
|
||||||
_this.verify();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof url === 'string') {
|
if (typeof url === 'string') {
|
||||||
@@ -791,6 +865,8 @@
|
|||||||
header.headersize = this.read(4);
|
header.headersize = this.read(4);
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.read(4);
|
this.read(4);
|
||||||
|
this.flv.emit('parseHeader', this.header);
|
||||||
|
console.log(this.header);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (this.index < this.uint8.length) {
|
while (this.index < this.uint8.length) {
|
||||||
@@ -802,10 +878,13 @@
|
|||||||
tag.body = this.read(getUint8Sum(tag.dataSize));
|
tag.body = this.read(getUint8Sum(tag.dataSize));
|
||||||
this.tags.push(tag);
|
this.tags.push(tag);
|
||||||
this.read(4);
|
this.read(4);
|
||||||
|
this.flv.emit('parseTag', tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tags.length > 1 && this.tags[0].tagType[0] === 18 && !this.metadata) {
|
if (this.tags.length > 1 && this.tags[0].tagType[0] === 18 && !this.metadata) {
|
||||||
this.metadata = getMetaData(this.tags[0]);
|
this.metadata = getMetaData(this.tags[0]);
|
||||||
|
this.flv.emit('parseMetadata', this.metadata);
|
||||||
|
console.log(this.metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
@@ -820,24 +899,6 @@
|
|||||||
|
|
||||||
return tempUint8;
|
return tempUint8;
|
||||||
}
|
}
|
||||||
}, {
|
|
||||||
key: "verify",
|
|
||||||
value: function verify() {
|
|
||||||
var types = Object.create(null);
|
|
||||||
this.tags.forEach(function (item) {
|
|
||||||
var tagType = item.tagType[0];
|
|
||||||
|
|
||||||
if (types[tagType]) {
|
|
||||||
types[tagType] += 1;
|
|
||||||
} else {
|
|
||||||
types[tagType] = 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(this.header);
|
|
||||||
console.log(this.metadata);
|
|
||||||
console.log(this.tags);
|
|
||||||
console.log(types);
|
|
||||||
}
|
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
return FlvParse;
|
return FlvParse;
|
||||||
|
|||||||
@@ -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/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","../../packages/artplayer-plugin-flv/src/flvParse/fetchStream.js","../../packages/artplayer-plugin-flv/src/flvParse/readFile.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/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\" && superClass !== null) {\n throw new TypeError(\"Super expLine 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/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","../../packages/artplayer-plugin-flv/src/flvParse/fetchStream.js","../../packages/artplayer-plugin-flv/src/flvParse/readFile.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/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\" && superClass !== null) {\n throw new TypeError(\"Super expLine truncated
|
||||||
@@ -1,40 +1,92 @@
|
|||||||
import { getUint8Sum, readUint8, bin2String, bin2Boolean, bin2Float, errorHandle } from '../utils';
|
import { getUint8Sum, readUint8, bin2String, bin2Boolean, bin2Float } from '../utils';
|
||||||
|
|
||||||
export default function getMetaData(scripTag) {
|
export default function getMetaData(scripTag) {
|
||||||
const readMetaData = readUint8(scripTag.body);
|
const readScripTag = readUint8(scripTag.body);
|
||||||
const metadata = Object.create(null);
|
const metadata = Object.create(null);
|
||||||
const amf1 = Object.create(null);
|
const amf1 = Object.create(null);
|
||||||
const amf2 = Object.create(null);
|
const amf2 = Object.create(null);
|
||||||
[amf1.type] = readMetaData(1);
|
[amf1.type] = readScripTag(1);
|
||||||
amf1.size = getUint8Sum(readMetaData(2));
|
amf1.size = getUint8Sum(readScripTag(2));
|
||||||
amf1.string = bin2String(readMetaData(amf1.size));
|
amf1.string = bin2String(readScripTag(amf1.size));
|
||||||
[amf2.type] = readMetaData(1);
|
[amf2.type] = readScripTag(1);
|
||||||
amf2.size = getUint8Sum(readMetaData(4));
|
amf2.size = getUint8Sum(readScripTag(4));
|
||||||
amf2.metaData = Object.create(null);
|
amf2.metaData = Object.create(null);
|
||||||
|
|
||||||
while (readMetaData.index < scripTag.body.length) {
|
function getValue(type) {
|
||||||
const nameLength = getUint8Sum(readMetaData(2));
|
let value = null;
|
||||||
const name = bin2String(readMetaData(nameLength));
|
if (type !== undefined) {
|
||||||
const type = readMetaData(1)[0];
|
switch (type) {
|
||||||
switch (type) {
|
case 0:
|
||||||
case 0:
|
value = bin2Float(readScripTag(8));
|
||||||
amf2.metaData[name] = bin2Float(readMetaData(8));
|
break;
|
||||||
break;
|
case 1:
|
||||||
case 1:
|
value = bin2Boolean(readScripTag(1)[0]);
|
||||||
amf2.metaData[name] = bin2Boolean(readMetaData(1)[0]);
|
break;
|
||||||
break;
|
case 2: {
|
||||||
case 2: {
|
const valueLength = getUint8Sum(readScripTag(2));
|
||||||
const valueLength = getUint8Sum(readMetaData(2));
|
value = bin2String(readScripTag(valueLength));
|
||||||
amf2.metaData[name] = bin2String(readMetaData(valueLength));
|
break;
|
||||||
break;
|
}
|
||||||
|
case 3: {
|
||||||
|
value = Object.create(null);
|
||||||
|
let endObject = false;
|
||||||
|
while (!endObject && readScripTag.index < scripTag.body.length) {
|
||||||
|
const nameLength = getUint8Sum(readScripTag(2));
|
||||||
|
const name = bin2String(readScripTag(nameLength));
|
||||||
|
const type = readScripTag(1)[0];
|
||||||
|
if (name) {
|
||||||
|
value[name] = getValue(type);
|
||||||
|
}
|
||||||
|
if (type === 9) {
|
||||||
|
endObject = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 8: {
|
||||||
|
value = Object.create(null);
|
||||||
|
let endObject = false;
|
||||||
|
while (!endObject && readScripTag.index < scripTag.body.length) {
|
||||||
|
const nameLength = getUint8Sum(readScripTag(2));
|
||||||
|
const name = bin2String(readScripTag(nameLength));
|
||||||
|
const type = readScripTag(1)[0];
|
||||||
|
if (name) {
|
||||||
|
value[name] = getValue(type);
|
||||||
|
}
|
||||||
|
if (type === 9) {
|
||||||
|
endObject = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 10: {
|
||||||
|
const valueLength = getUint8Sum(readScripTag(4));
|
||||||
|
value = [];
|
||||||
|
for (let index = 0; index < valueLength; index += 1) {
|
||||||
|
const itemType = readScripTag(1)[0];
|
||||||
|
value.push(getValue(itemType));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 12: {
|
||||||
|
const valueLength = getUint8Sum(readScripTag(4));
|
||||||
|
value = bin2String(readScripTag(valueLength));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
console.warn(`AMF: Unknown metaData type: ${type} in ${readScripTag.index - 1}`);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
case 3:
|
}
|
||||||
amf2.metaData[name] = Object.create(null);
|
return value;
|
||||||
readMetaData(scripTag.body.length - readMetaData.index);
|
}
|
||||||
break;
|
|
||||||
default:
|
while (readScripTag.index < scripTag.body.length) {
|
||||||
errorHandle(false, `AMF: Unknown metaData type: ${type}`);
|
const nameLength = getUint8Sum(readScripTag(2));
|
||||||
break;
|
const name = bin2String(readScripTag(nameLength));
|
||||||
|
const type = readScripTag(1)[0];
|
||||||
|
if (name) {
|
||||||
|
amf2.metaData[name] = getValue(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { mergeTypedArrays, getUint8Sum } from '../utils';
|
|||||||
|
|
||||||
export default class FlvParse {
|
export default class FlvParse {
|
||||||
constructor(flv) {
|
constructor(flv) {
|
||||||
|
this.flv = flv;
|
||||||
const { url } = flv.options;
|
const { url } = flv.options;
|
||||||
this.uint8 = new Uint8Array(0);
|
this.uint8 = new Uint8Array(0);
|
||||||
this.index = 0;
|
this.index = 0;
|
||||||
@@ -42,7 +43,6 @@ export default class FlvParse {
|
|||||||
this.parse();
|
this.parse();
|
||||||
}
|
}
|
||||||
flv.emit('parseDone');
|
flv.emit('parseDone');
|
||||||
this.verify();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (typeof url === 'string') {
|
if (typeof url === 'string') {
|
||||||
@@ -61,6 +61,8 @@ export default class FlvParse {
|
|||||||
header.headersize = this.read(4);
|
header.headersize = this.read(4);
|
||||||
this.header = header;
|
this.header = header;
|
||||||
this.read(4);
|
this.read(4);
|
||||||
|
this.flv.emit('parseHeader', this.header);
|
||||||
|
console.log(this.header);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (this.index < this.uint8.length) {
|
while (this.index < this.uint8.length) {
|
||||||
@@ -72,10 +74,13 @@ export default class FlvParse {
|
|||||||
tag.body = this.read(getUint8Sum(tag.dataSize));
|
tag.body = this.read(getUint8Sum(tag.dataSize));
|
||||||
this.tags.push(tag);
|
this.tags.push(tag);
|
||||||
this.read(4);
|
this.read(4);
|
||||||
|
this.flv.emit('parseTag', tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.tags.length > 1 && this.tags[0].tagType[0] === 18 && !this.metadata) {
|
if (this.tags.length > 1 && this.tags[0].tagType[0] === 18 && !this.metadata) {
|
||||||
this.metadata = getMetaData(this.tags[0]);
|
this.metadata = getMetaData(this.tags[0]);
|
||||||
|
this.flv.emit('parseMetadata', this.metadata);
|
||||||
|
console.log(this.metadata);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,20 +92,4 @@ export default class FlvParse {
|
|||||||
}
|
}
|
||||||
return tempUint8;
|
return tempUint8;
|
||||||
}
|
}
|
||||||
|
|
||||||
verify() {
|
|
||||||
const types = Object.create(null);
|
|
||||||
this.tags.forEach(item => {
|
|
||||||
const tagType = item.tagType[0];
|
|
||||||
if (types[tagType]) {
|
|
||||||
types[tagType] += 1;
|
|
||||||
} else {
|
|
||||||
types[tagType] = 1;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
console.log(this.header);
|
|
||||||
console.log(this.metadata);
|
|
||||||
console.log(this.tags);
|
|
||||||
console.log(types);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user