├── .gitignore ├── test ├── support │ ├── testassets │ │ ├── seg-10s.ts │ │ ├── seg2-10s.ts │ │ ├── ysad01.ts │ │ └── 2000-00002.ts │ └── testassets.js ├── test_unit.js ├── hlsts_unit.js ├── util_unit.js ├── browser_unit.js └── lib │ ├── tsparser_unit.js │ └── pes │ └── pes_parser_unit.js ├── docs ├── fonts │ ├── OpenSans-Bold-webfont.eot │ ├── OpenSans-Bold-webfont.woff │ ├── OpenSans-Light-webfont.eot │ ├── OpenSans-Italic-webfont.eot │ ├── OpenSans-Italic-webfont.woff │ ├── OpenSans-Light-webfont.woff │ ├── OpenSans-Regular-webfont.eot │ ├── OpenSans-Regular-webfont.woff │ ├── OpenSans-Semibold-webfont.eot │ ├── OpenSans-Semibold-webfont.ttf │ ├── OpenSans-BoldItalic-webfont.eot │ ├── OpenSans-Semibold-webfont.woff │ ├── OpenSans-BoldItalic-webfont.woff │ ├── OpenSans-LightItalic-webfont.eot │ ├── OpenSans-LightItalic-webfont.woff │ ├── OpenSans-SemiboldItalic-webfont.eot │ ├── OpenSans-SemiboldItalic-webfont.ttf │ └── OpenSans-SemiboldItalic-webfont.woff ├── scripts │ ├── linenumber.js │ └── prettify │ │ ├── lang-css.js │ │ ├── Apache-License-2.0.txt │ │ └── prettify.js ├── styles │ ├── prettify-jsdoc.css │ ├── prettify-tomorrow.css │ └── jsdoc-default.css ├── lib_parse_stream.js.html ├── lib_pes_pes_parser.js.html ├── ParseStream.html ├── index.js.html ├── lib_browser.js.html ├── global_exports.js.html ├── index.html ├── lib_pes_pes_avc_parser.js.html ├── lib_pes_pes_aac_parser.js.html ├── PESParser.html └── PESAACParser.html ├── jsdoc.conf.json ├── LICENSE ├── .travis.yml ├── lib ├── util.js ├── parse_stream.js ├── pes │ ├── pes_parser.js │ ├── exp_golomb.js │ ├── pes_avc_parser.js │ ├── pes_aac_parser.js │ └── nalu_parser.js ├── browser.js └── tsprograms.js ├── karma.conf.js ├── package.json ├── example.js ├── index.js ├── global_exports.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | *.swp 3 | .vscode/ 4 | coverage/ 5 | .coveralls.yml 6 | -------------------------------------------------------------------------------- /test/support/testassets/seg-10s.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/test/support/testassets/seg-10s.ts -------------------------------------------------------------------------------- /test/support/testassets/seg2-10s.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/test/support/testassets/seg2-10s.ts -------------------------------------------------------------------------------- /test/support/testassets/ysad01.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/test/support/testassets/ysad01.ts -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Bold-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Bold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Bold-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Light-webfont.eot -------------------------------------------------------------------------------- /test/support/testassets/2000-00002.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/test/support/testassets/2000-00002.ts -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Italic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Italic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Italic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Light-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Light-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Regular-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Regular-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Regular-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Semibold-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Semibold-webfont.ttf -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-BoldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-Semibold-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-Semibold-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-BoldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-BoldItalic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-LightItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-LightItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-LightItalic-webfont.woff -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-SemiboldItalic-webfont.eot -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-SemiboldItalic-webfont.ttf -------------------------------------------------------------------------------- /docs/fonts/OpenSans-SemiboldItalic-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Eyevinn/hls-ts-js/HEAD/docs/fonts/OpenSans-SemiboldItalic-webfont.woff -------------------------------------------------------------------------------- /jsdoc.conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "source": { 3 | "include": [ 4 | "README.md", 5 | "index.js", 6 | "global_exports.js", 7 | "lib/browser.js", 8 | "lib/parse_stream.js", 9 | "lib/pes/pes_parser.js", 10 | "lib/pes/pes_avc_parser.js", 11 | "lib/pes/pes_aac_parser.js" 12 | ] 13 | }, 14 | "opts": { 15 | "destination": "./docs/", 16 | "template": "node_modules/minami" 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /test/test_unit.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const TestAssetsModule = require("./support/testassets.js"); 7 | 8 | describe("Test Helpers", () => { 9 | it("can load a test asset and store in a byte array", (done) => { 10 | const testAssetsModule = new TestAssetsModule(); 11 | testAssetsModule.init().then(() => { 12 | const asset = testAssetsModule.getAssetByName("seg-10s"); 13 | const data = asset.data; 14 | expect(data.length).toBeGreaterThan(3 * 188); 15 | expect(data[0]).toBe(0x47); 16 | done(); 17 | }).catch(fail).then(done); 18 | }); 19 | }); -------------------------------------------------------------------------------- /docs/scripts/linenumber.js: -------------------------------------------------------------------------------- 1 | /*global document */ 2 | (function() { 3 | var source = document.getElementsByClassName('prettyprint source linenums'); 4 | var i = 0; 5 | var lineNumber = 0; 6 | var lineId; 7 | var lines; 8 | var totalLines; 9 | var anchorHash; 10 | 11 | if (source && source[0]) { 12 | anchorHash = document.location.hash.substring(1); 13 | lines = source[0].getElementsByTagName('li'); 14 | totalLines = lines.length; 15 | 16 | for (; i < totalLines; i++) { 17 | lineNumber++; 18 | lineId = 'line' + lineNumber; 19 | lines[i].id = lineId; 20 | if (lineId === anchorHash) { 21 | lines[i].className += ' selected'; 22 | } 23 | } 24 | } 25 | })(); 26 | -------------------------------------------------------------------------------- /docs/scripts/prettify/lang-css.js: -------------------------------------------------------------------------------- 1 | PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com", 2 | /^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]); 3 | -------------------------------------------------------------------------------- /test/hlsts_unit.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const request = require("request"); 7 | const hlsTs = require("../index.js"); 8 | 9 | jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; 10 | 11 | describe("Hls TS", () => { 12 | it("can parse data through a pipe", (done) => { 13 | const stream = request.get("http://localhost:9876/base/test/support/testassets/seg-10s.ts"); 14 | stream.pipe(hlsTs.parse({ debug: false })).on("finish", () => { 15 | const programs = hlsTs.programs; 16 | const avcProgram = programs.find(p => p.type === "avc"); 17 | const avcPackets = hlsTs.getPacketsByProgramType("avc"); 18 | const avcData = hlsTs.getDataStreamByProgramType("avc"); 19 | expect(programs.length).toBe(3); 20 | expect(avcPackets.length).toBe(avcProgram.packets); 21 | expect(avcData.data.length).toBe(879536); 22 | expect(avcData.size).toBe(avcData.data.length); 23 | done(); 24 | }); 25 | }); 26 | }); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This library is licensed under the MIT License: 2 | 3 | The MIT License 4 | 5 | Copyright (c) 2017 Eyevinn Technology (eyevinn.github.io) 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 8 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation 9 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 10 | to permit persons to whom the Software is furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all copies or substantial portions 13 | of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 16 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 18 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: node_js 4 | node_js: 5 | - '8' 6 | before_script: 7 | - export CHROME_BIN=/usr/bin/google-chrome 8 | - export DISPLAY=:99.0 9 | - sh -e /etc/init.d/xvfb start 10 | - sudo apt-get update 11 | - sudo apt-get install -y libappindicator1 fonts-liberation 12 | - wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb 13 | - sudo dpkg -i google-chrome*.deb 14 | after_success: 15 | - npm run coveralls 16 | deploy: 17 | provider: npm 18 | email: jonas.birme@eyevinn.se 19 | on: 20 | tags: true 21 | repo: Eyevinn/hls-ts-js 22 | api_key: 23 | secure: IMSLC1e/z/ZbWFPcImTyyIgMOAdeEMd8A3LquOYn77/THQFjpHAILl3TCod1BlHR26rNiR8WQR5weoCmTOMJ/C0TG1T6ap+CZXsbrqB0FpBADNZMdAsJN54cAhmkpRUDrxYsMFOL6VdJt6FWUlvmoH73t84BzWbvMpY9DmtH2vsXu8Lzk4U7isQ60+Rn1GOyS7GKm9YOs7ugjUwetIWShPdzwA3LJJ5/XrKqZ4IOZLLumZhaKm6WTBwKkVfnqksroGO8bOvq/RXHAkQ1/0dU1QvilMfI0LB7fZv0EfIrp3q1Zpb5pTpJyLTNvWiHznHMph8jIt8roWqj0mttIvuGflB8f+Exmb8u7vvF6asVrlFr/DRPytiSeHvCT6RTNPASS0KFU5496qTnT/q2D7/QzIxSohI5iumK2y9ACD7dzu3Ek/+MPA+EnGLWdTQ3UYPRKaWgbYa0K45VmfjiUL/EEAUsDQY+HIfLcxBhJZZHNdi961U89rEmwdaCf/y8IY0IAEoxjHWMOWZxPOp8/k/uxwV0qiDGU7OnPVmnqnFrYVKsvKh7IKCZuWnz5T1Kk6u/e8CQ/GW14uKz71n+5CLG0j14VGz0cflhZ44ewBtvrB8945b1QYqHWWL6LD4wIWMxFPjYLkYZ14k8TtX55Rj2aNzWiC+lAfUaQJR3m8RFdIo= 24 | -------------------------------------------------------------------------------- /test/util_unit.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const util = require("../lib/util.js"); 7 | 8 | describe("Utility functions", () => { 9 | it("can get 5 first bits from a byte as an array", () => { 10 | const mockByte = 178; // 10110010 11 | const fiveBits = util.readBits(mockByte, 5); 12 | expect(fiveBits.length).toBe(5); 13 | expect(fiveBits).toEqual([1, 0, 1, 1, 0]); 14 | }); 15 | it("can get 5 first bits from a byte as an array of booleans (flags)", () => { 16 | const mockByte = 178; // 10110010 17 | const fiveBits = util.readFlags(mockByte, 5); 18 | expect(fiveBits.length).toBe(5); 19 | expect(fiveBits).toEqual([true, false, true, true, false]); 20 | }); 21 | it("can return a value for an array of bits", () => { 22 | const bitArray1 = [0, 0, 0, 1]; 23 | const bitArray2 = [1, 1, 1, 1]; 24 | const bitArray3 = [1, 0, 0, 1]; 25 | const val1 = util.bitsToNumber(bitArray1); 26 | const val2 = util.bitsToNumber(bitArray2); 27 | const val3 = util.bitsToNumber(bitArray3); 28 | expect(val1).toBe(1); 29 | expect(val2).toBe(15); 30 | expect(val3).toBe(1 + 8); 31 | }); 32 | }); -------------------------------------------------------------------------------- /lib/util.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | const hexy = require("hexy"); 6 | 7 | const util = { 8 | toHex: function(d) { 9 | return "0x" + d.toString(16); 10 | }, 11 | hexDump: function(array) { 12 | let buf = new Buffer(array.byteLength); 13 | let view = new Uint8Array(array); 14 | for (let i = 0; i < buf.length; i++) { 15 | buf[i] = view[i]; 16 | } 17 | return hexy.hexy(buf); 18 | }, 19 | readBits: function(byte, numBits) { 20 | let array = []; 21 | const bitMask = [ 22 | 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 23 | ]; 24 | const shift = [ 25 | 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 26 | ]; 27 | for(let i = 0; i< numBits; i++) { 28 | array.push((byte & bitMask[i]) / shift[i]); 29 | } 30 | return array; 31 | }, 32 | readFlags: function(byte, numFlags) { 33 | const array = this.readBits(byte, numFlags); 34 | return array.map(f => f === 1); 35 | }, 36 | bitsToNumber: function(bits) { 37 | let val = 0; 38 | for (let i = 0; i < bits.length; i++) { 39 | const shift = bits.length - i - 1; 40 | val += bits[i] << shift; 41 | } 42 | return val; 43 | } 44 | }; 45 | 46 | module.exports = util; -------------------------------------------------------------------------------- /test/browser_unit.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | require("../global_exports.js"); 7 | 8 | describe("Hls TS browser library", function() { 9 | it("can parse data from XHR response", function(done) { 10 | var xhr = new XMLHttpRequest(); 11 | var url = "http://localhost:9876/base/test/support/testassets/seg-10s.ts"; 12 | var parser = new window.HlsTs({ debug: false }); 13 | xhr.responseType = "arraybuffer"; 14 | xhr.onloadend = function() { 15 | var buffer = xhr.response; 16 | var data = new Uint8Array(buffer); 17 | parser.parse(data).then(function() { 18 | var programs = parser.getPrograms(); 19 | var avcProgram = programs.find(p => p.type === "avc"); 20 | var avcPackets = parser.getPacketsByProgramType("avc"); 21 | var avcData = parser.getDataStreamByProgramType("avc"); 22 | var avcParser = parser.createAvcParser(avcData); 23 | expect(programs.length).toBe(3); 24 | expect(avcPackets.length).toBe(avcProgram.packets); 25 | expect(avcData.data.length).toBe(879536); 26 | expect(avcData.size).toBe(avcData.data.length); 27 | expect(avcParser.getNalUnits().length).toBe(1015); 28 | done(); 29 | }).catch(function(err) { console.error(err.message); fail(); }).then(done); 30 | }; 31 | xhr.open("GET", url); 32 | xhr.send(); 33 | }); 34 | }); -------------------------------------------------------------------------------- /lib/parse_stream.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const Writable = require("stream").Writable; 7 | const TSParser = require("./tsparser.js"); 8 | 9 | /** 10 | * Implements the Stream.Writable API to handle 11 | * chunk of HLS TS data to be parsed 12 | * 13 | * @example 14 | * request.get("http://example.com/seg10.ts") 15 | * .pipe(hlsTs.parse()) // parse() creates a ParseStream object 16 | * .on("finish", function() { 17 | * const avcPackets = hlsTs.getPacketsByProgramType("avc"); 18 | * }); 19 | * @class 20 | * @extends Writable 21 | */ 22 | class ParseStream extends Writable { 23 | constructor(opts) { 24 | super(opts); 25 | this.parser = new TSParser(); 26 | this.firstChunk = true; 27 | } 28 | } 29 | 30 | ParseStream.prototype.getPrograms = function getPrograms() { 31 | return this.parser.getPrograms(); 32 | } 33 | 34 | ParseStream.prototype._write = function(chunk, encoding, next) { 35 | // Parse data 36 | //console.log("_write:" + chunk.length); 37 | let err; 38 | this.firstChunk = false; 39 | if (this.firstChunk) { 40 | if (!this.parser.isValidChunk(chunk)) { 41 | err = new Error("Invalid TS chunk"); 42 | } 43 | } 44 | try { 45 | this.parser.push(chunk, false); 46 | } catch (parserError) { 47 | err = new Error(`Failed to parse chunk: ${parserError}`); 48 | } 49 | next(err); 50 | }; 51 | 52 | module.exports = ParseStream; -------------------------------------------------------------------------------- /lib/pes/pes_parser.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | /** 7 | * @class 8 | */ 9 | class PESParser { 10 | /** 11 | * @constructor 12 | * @param {HlsTsDataStream} pes Data stream to parse 13 | */ 14 | constructor(pes) { 15 | this.data = pes.data; 16 | this.pes = pes.pes; 17 | this.id = pes.id; 18 | } 19 | 20 | /** 21 | * Get program ID 22 | * 23 | * @return {number} Program ID 24 | */ 25 | getId() { 26 | return this.id; 27 | } 28 | 29 | /** 30 | * Get data stream as Uint8 byte array 31 | * 32 | * @return {Uint8Array} Data stream 33 | */ 34 | getData() { 35 | return this.data; 36 | } 37 | 38 | /** 39 | * Get PES headers in this data stream 40 | * 41 | * @return {HlsTsPesHeader[]} 42 | */ 43 | getHeaders() { 44 | return this.pes; 45 | } 46 | 47 | /** 48 | * Get a PES header at a specific position in the data stream 49 | * 50 | * @param {number} offset Position in the data stream 51 | * @return {HlsTsPesHeader} 52 | */ 53 | getHeaderForByteOffset(offset) { 54 | let lastPes = undefined; 55 | for (let i = 0; i < this.pes.length; i++) { 56 | const p = this.pes[i]; 57 | if (i > 0 && p.offset > offset) { 58 | const lastPes = this.pes[i - 1]; 59 | return lastPes; 60 | } 61 | } 62 | if (this.pes.length > 0) { 63 | return this.pes[this.pes.length - 1]; 64 | } 65 | return null; 66 | } 67 | } 68 | 69 | module.exports = PESParser; 70 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | var istanbul = require("browserify-istanbul"); 2 | 3 | module.exports = function (config) { 4 | var configuration = { 5 | basePath: '', 6 | frameworks: ['browserify', 'jasmine-jquery', 'jasmine'], 7 | browserify: { 8 | debug: true, 9 | transform: [ 10 | ['babelify', {plugins: ['babel-plugin-espower']}], 11 | istanbul({ 12 | ignore: ["test/**", "**/node_modules/**"], 13 | instrumenterConfig: { 14 | embedSource: true 15 | } 16 | }) 17 | ], 18 | }, 19 | reporters: ['progress', 'coverage'], 20 | preprocessors: { 21 | 'index.js': ['browserify', 'coverage'], 22 | 'lib/**/*.js': ['browserify', 'coverage'], 23 | 'test/**/*.js': ['browserify'], 24 | }, 25 | files: [ 26 | 'node_modules/babel-polyfill/dist/polyfill.js', 27 | 'test/**/*_unit.js', 28 | { pattern: 'test/support/testassets/*.ts', 29 | watched: true, 30 | served: true, 31 | included: false 32 | } 33 | ], 34 | browsers: ['Chrome'], 35 | singleRun: true, 36 | concurrency: Infinity, 37 | logLevel: config.LOG_INFO, 38 | browserNoActivityTimeout: 5 * 60 * 1000, 39 | customLaunchers: { 40 | Chrome_travis_ci: { 41 | base: 'Chrome', 42 | flags: ['--no-sandbox'] 43 | } 44 | }, 45 | coverageReporter: { 46 | dir: "coverage/", 47 | reporters: [ 48 | { type: "text-summary" }, 49 | { type: "html", subdir: "./" }, 50 | { type: "lcovonly", subdir: "./" } 51 | ] 52 | } 53 | }; 54 | if (process.env.TRAVIS) { 55 | configuration.browsers = ['Chrome_travis_ci']; 56 | } 57 | config.set(configuration); 58 | }; 59 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hls-ts", 3 | "version": "0.4.4", 4 | "description": "HLS TS parser library in Javascript", 5 | "repository": "https://github.com/Eyevinn/hls-ts-js", 6 | "main": "index.js", 7 | "scripts": { 8 | "docs": "$(npm bin)/jsdoc -c jsdoc.conf.json", 9 | "test": "$(npm bin)/karma start karma.conf.js", 10 | "coveralls": "cat ./coverage/lcov.info | coveralls", 11 | "clean": "rm -rf dist/* docs/*", 12 | "prebuild": "npm run clean && npm run test && npm run docs", 13 | "build": "browserify index.js global_exports.js node_modules/logplease/src/index.js -o dist/hls-ts.js -t [ babelify --presets es2015 ] && $(npm bin)/uglifyjs dist/hls-ts.js -o dist/hls-ts.min.js", 14 | "version": "npm run build && git add -A dist && git add -A docs", 15 | "postversion": "git push && git push --tags" 16 | }, 17 | "author": "Jonas Birme (http://eyevinn.github.io)", 18 | "license": "MIT", 19 | "devDependencies": { 20 | "babel-plugin-espower": "^2.3.1", 21 | "babel-polyfill": "^6.20.0", 22 | "babel-preset-es2015": "^6.24.1", 23 | "babelify": "^10.0.0", 24 | "browserify": "^13.1.1", 25 | "browserify-istanbul": "^2.0.0", 26 | "coveralls": "^3.0.3", 27 | "jasmine": "^2.5.2", 28 | "jasmine-jquery": "^2.1.1", 29 | "jsdoc": "^3.5.5", 30 | "karma": "^6.4.1", 31 | "karma-browserify": "^6.0.0", 32 | "karma-chrome-launcher": "^2.0.0", 33 | "karma-coverage": "^1.1.2", 34 | "karma-generic-preprocessor": "^1.1.1", 35 | "karma-jasmine": "^1.1.0", 36 | "karma-jasmine-jquery": "^0.1.1", 37 | "minami": "^1.1.1", 38 | "request": "^2.88.0", 39 | "watchify": "^3.11.1" 40 | }, 41 | "dependencies": { 42 | "hexy": "^0.2.8", 43 | "logplease": "^1.2.12" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/support/testassets.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | function loadAsset(file) { 7 | return new Promise((resolve, reject) => { 8 | xhr = new XMLHttpRequest(); 9 | xhr.onreadystatechange = function(event) { 10 | const xhr = event.currentTarget; 11 | if (xhr.readyState === XMLHttpRequest.DONE) { 12 | if (xhr.status == 200) { 13 | data = xhr.response; 14 | const view = new Uint8Array(data); 15 | resolve(view); 16 | } else { 17 | reject("Unable to load fixture: " + file) 18 | } 19 | } 20 | }; 21 | const url = "http://localhost:9876/base/test/support/testassets/" + file; 22 | xhr.open("GET", url, true); 23 | xhr.responseType = "arraybuffer"; 24 | xhr.send(); 25 | }); 26 | } 27 | 28 | const TestAssets = function constructor() { 29 | this.assets = []; 30 | }; 31 | 32 | TestAssets.prototype.init = function() { 33 | return new Promise((resolve, reject) => { 34 | loadAsset("seg-10s.ts").then((data) => { 35 | this.assets.push({ name: "seg-10s", data: data }); 36 | return loadAsset("seg2-10s.ts"); 37 | }).then((data) => { 38 | this.assets.push({ name: "seg2-10s", data: data }); 39 | return loadAsset("ysad01.ts"); 40 | }).then((data) => { 41 | this.assets.push({ name: "ysad01", data: data }); 42 | resolve(); 43 | }).catch((err) => { 44 | console.error(err); 45 | reject(err); 46 | }) 47 | }); 48 | }; 49 | 50 | TestAssets.prototype.getAssetByName = function(name) { 51 | return this.assets.find((n) => { 52 | return n.name === name; 53 | }); 54 | }; 55 | 56 | module.exports = TestAssets; -------------------------------------------------------------------------------- /docs/styles/prettify-jsdoc.css: -------------------------------------------------------------------------------- 1 | /* JSDoc prettify.js theme */ 2 | 3 | /* plain text */ 4 | .pln { 5 | color: #000000; 6 | font-weight: normal; 7 | font-style: normal; 8 | } 9 | 10 | /* string content */ 11 | .str { 12 | color: hsl(104, 100%, 24%); 13 | font-weight: normal; 14 | font-style: normal; 15 | } 16 | 17 | /* a keyword */ 18 | .kwd { 19 | color: #000000; 20 | font-weight: bold; 21 | font-style: normal; 22 | } 23 | 24 | /* a comment */ 25 | .com { 26 | font-weight: normal; 27 | font-style: italic; 28 | } 29 | 30 | /* a type name */ 31 | .typ { 32 | color: #000000; 33 | font-weight: normal; 34 | font-style: normal; 35 | } 36 | 37 | /* a literal value */ 38 | .lit { 39 | color: #006400; 40 | font-weight: normal; 41 | font-style: normal; 42 | } 43 | 44 | /* punctuation */ 45 | .pun { 46 | color: #000000; 47 | font-weight: bold; 48 | font-style: normal; 49 | } 50 | 51 | /* lisp open bracket */ 52 | .opn { 53 | color: #000000; 54 | font-weight: bold; 55 | font-style: normal; 56 | } 57 | 58 | /* lisp close bracket */ 59 | .clo { 60 | color: #000000; 61 | font-weight: bold; 62 | font-style: normal; 63 | } 64 | 65 | /* a markup tag name */ 66 | .tag { 67 | color: #006400; 68 | font-weight: normal; 69 | font-style: normal; 70 | } 71 | 72 | /* a markup attribute name */ 73 | .atn { 74 | color: #006400; 75 | font-weight: normal; 76 | font-style: normal; 77 | } 78 | 79 | /* a markup attribute value */ 80 | .atv { 81 | color: #006400; 82 | font-weight: normal; 83 | font-style: normal; 84 | } 85 | 86 | /* a declaration */ 87 | .dec { 88 | color: #000000; 89 | font-weight: bold; 90 | font-style: normal; 91 | } 92 | 93 | /* a variable name */ 94 | .var { 95 | color: #000000; 96 | font-weight: normal; 97 | font-style: normal; 98 | } 99 | 100 | /* a function name */ 101 | .fun { 102 | color: #000000; 103 | font-weight: bold; 104 | font-style: normal; 105 | } 106 | 107 | /* Specify class=linenums on a pre to get line numbering */ 108 | ol.linenums { 109 | margin-top: 0; 110 | margin-bottom: 0; 111 | } 112 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | const hlsTs = require("./index.js"); 2 | const fs = require("fs"); 3 | 4 | fs.createReadStream("./test/support/testassets/2000-00002.ts") 5 | .pipe(hlsTs.parse({ debug: false })) 6 | .on("error", function(err) { 7 | console.error(err); 8 | }) 9 | .on("finish", function() { 10 | const programs = hlsTs.programs; 11 | 12 | const avcProgram = programs.find(p => p.type === "avc"); 13 | console.log("avc:pts:", avcProgram.pts.slice(0, 10).join(":")); 14 | 15 | const packets = hlsTs.getPacketsByProgramType(programs[0].type); 16 | const pcrs = packets.filter(p => p.pcr.base); 17 | console.log("avc:pcr(base):", pcrs.map(p => p.pcr.base).slice(0, 10).join(":")); 18 | console.log("avc:pcr(value):", pcrs.map(p => p.pcr.value).slice(0, 10).join(":")); 19 | 20 | console.log(programs[0].type + ":" + packets.length + " packets"); 21 | console.log(programs[0].type + ":" + packets.filter(p => p.payloadUnitStartIndicator).length + " packets with payload"); 22 | const dataStream = hlsTs.getDataStreamByProgramType(programs[0].type); 23 | console.log(programs[0].type + ":" + dataStream.data.length + " bytes"); 24 | avcParser = hlsTs.createAvcParser(dataStream); 25 | avcNalUnits = avcParser.getNalUnits(); 26 | console.log(avcNalUnits.length + " AVC NAL units (showing IDR frames)"); 27 | avcNalUnits.filter(nu => nu.type === 5).forEach((nu) => { 28 | console.log(" - " + avcParser.nalUnitType(nu.type) + ":" + nu.offset + ", pes=" + nu.pes.pts); 29 | }) 30 | 31 | const aacProgram = programs.find(p => p.type === "aac"); 32 | const aacPackets = hlsTs.getPacketsByProgramType("aac"); 33 | const aacDataStream = hlsTs.getDataStreamByProgramType("aac"); 34 | console.log(aacProgram.type + ":" + aacPackets.length + " packets"); 35 | console.log(aacProgram.type + ":" + aacDataStream.data.length + " bytes"); 36 | aacParser = hlsTs.createAacParser(aacDataStream); 37 | const aacAdtsFrames = aacParser.getAdtsFrames(); 38 | let frame = aacAdtsFrames[0]; 39 | console.log(" - MPEG" + frame.mpegVersion + " " + aacParser.audioType(frame.audioObjectType) + " " + frame.channels + "ch (" + frame.samplingRate + "): " + aacAdtsFrames.length + " audio frames, pes=" + frame.pes.pts); 40 | }); 41 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Logger = require("logplease"); 2 | const ParseStream = require("./lib/parse_stream.js"); 3 | const AVCParser = require("./lib/pes/pes_avc_parser.js"); 4 | const AACParser = require("./lib/pes/pes_aac_parser.js"); 5 | 6 | 7 | /** 8 | * @module HlsTs 9 | */ 10 | 11 | const HlsTS = { 12 | streamParser: undefined, 13 | /** 14 | * Parse HLS TS when reading from a Stream 15 | * 16 | * @function parse 17 | * @example 18 | * fs.createReadStream("./seg-10s.ts") 19 | * .pipe(hlsTs.parse({ debug: true })) 20 | * .on("finish", function() { 21 | * const avcPayload = hlsTs.getDataStreamByProgramType("avc"); 22 | * }); 23 | * @param {?HlsTsOptions} opts 24 | * @return {ParseStream} 25 | */ 26 | parse: function(opts) { 27 | if (opts && opts.debug) { 28 | Logger.setLogLevel("DEBUG"); 29 | } else { 30 | Logger.setLogLevel("INFO"); 31 | } 32 | this.streamParser = new ParseStream(opts); 33 | return this.streamParser; 34 | }, 35 | /** 36 | * Get the parsed program types 37 | * 38 | * @member {HlsTsProgramType[]} programs 39 | */ 40 | get programs() { 41 | if (!this.streamParser) { 42 | throw new Error("Nothing parsed yet"); 43 | } 44 | return this.streamParser.getPrograms().getTypes(); 45 | }, 46 | /** 47 | * Get all packets for a specific program type 48 | * 49 | * @function getPacketsByProgramType 50 | * @param {string} type 51 | * @return {HlsTsPacket[]} 52 | */ 53 | getPacketsByProgramType(type) { 54 | if (!this.streamParser) { 55 | throw new Error("Nothing parsed yet"); 56 | } 57 | return this.streamParser.getPrograms().getPackets(type); 58 | }, 59 | /** 60 | * Get the data stream for a program type 61 | * 62 | * @function getDataStreamByProgramType 63 | * @param {string} type 64 | * @return {HlsTsDataStream} 65 | */ 66 | getDataStreamByProgramType(type) { 67 | if (!this.streamParser) { 68 | throw new Error("Nothing parsed yet"); 69 | } 70 | return this.streamParser.getPrograms().getDataStream(type); 71 | }, 72 | /** 73 | * Create an AVC Parser that can parse an AVC data stream 74 | * 75 | * @function createAvcParser 76 | * @param {HlsDataStream} dataStream 77 | * @return {AVCParser} 78 | */ 79 | createAvcParser(dataStream) { 80 | return new AVCParser(dataStream); 81 | }, 82 | /** 83 | * Create an AAC Parser that can parse an AAC data stream 84 | * 85 | * @function createAacParser 86 | * @param {HlsDataStream} dataStream 87 | * @return {AACParser} 88 | */ 89 | createAacParser(dataStream) { 90 | return new AACParser(dataStream); 91 | } 92 | }; 93 | 94 | module.exports = HlsTS; -------------------------------------------------------------------------------- /docs/styles/prettify-tomorrow.css: -------------------------------------------------------------------------------- 1 | /* Tomorrow Theme */ 2 | /* Original theme - https://github.com/chriskempson/tomorrow-theme */ 3 | /* Pretty printing styles. Used with prettify.js. */ 4 | /* SPAN elements with the classes below are added by prettyprint. */ 5 | /* plain text */ 6 | .pln { 7 | color: #4d4d4c; } 8 | 9 | @media screen { 10 | /* string content */ 11 | .str { 12 | color: hsl(104, 100%, 24%); } 13 | 14 | /* a keyword */ 15 | .kwd { 16 | color: hsl(240, 100%, 50%); } 17 | 18 | /* a comment */ 19 | .com { 20 | color: hsl(0, 0%, 60%); } 21 | 22 | /* a type name */ 23 | .typ { 24 | color: hsl(240, 100%, 32%); } 25 | 26 | /* a literal value */ 27 | .lit { 28 | color: hsl(240, 100%, 40%); } 29 | 30 | /* punctuation */ 31 | .pun { 32 | color: #000000; } 33 | 34 | /* lisp open bracket */ 35 | .opn { 36 | color: #000000; } 37 | 38 | /* lisp close bracket */ 39 | .clo { 40 | color: #000000; } 41 | 42 | /* a markup tag name */ 43 | .tag { 44 | color: #c82829; } 45 | 46 | /* a markup attribute name */ 47 | .atn { 48 | color: #f5871f; } 49 | 50 | /* a markup attribute value */ 51 | .atv { 52 | color: #3e999f; } 53 | 54 | /* a declaration */ 55 | .dec { 56 | color: #f5871f; } 57 | 58 | /* a variable name */ 59 | .var { 60 | color: #c82829; } 61 | 62 | /* a function name */ 63 | .fun { 64 | color: #4271ae; } } 65 | /* Use higher contrast and text-weight for printable form. */ 66 | @media print, projection { 67 | .str { 68 | color: #060; } 69 | 70 | .kwd { 71 | color: #006; 72 | font-weight: bold; } 73 | 74 | .com { 75 | color: #600; 76 | font-style: italic; } 77 | 78 | .typ { 79 | color: #404; 80 | font-weight: bold; } 81 | 82 | .lit { 83 | color: #044; } 84 | 85 | .pun, .opn, .clo { 86 | color: #440; } 87 | 88 | .tag { 89 | color: #006; 90 | font-weight: bold; } 91 | 92 | .atn { 93 | color: #404; } 94 | 95 | .atv { 96 | color: #060; } } 97 | /* Style */ 98 | /* 99 | pre.prettyprint { 100 | background: white; 101 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 102 | font-size: 12px; 103 | line-height: 1.5; 104 | border: 1px solid #ccc; 105 | padding: 10px; } 106 | */ 107 | 108 | /* Specify class=linenums on a pre to get line numbering */ 109 | ol.linenums { 110 | margin-top: 0; 111 | margin-bottom: 0; } 112 | 113 | /* IE indents via margin-left */ 114 | li.L0, 115 | li.L1, 116 | li.L2, 117 | li.L3, 118 | li.L4, 119 | li.L5, 120 | li.L6, 121 | li.L7, 122 | li.L8, 123 | li.L9 { 124 | /* */ } 125 | 126 | /* Alternate shading for lines */ 127 | li.L1, 128 | li.L3, 129 | li.L5, 130 | li.L7, 131 | li.L9 { 132 | /* */ } 133 | -------------------------------------------------------------------------------- /lib/browser.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const Logger = require("logplease"); 7 | const TSParser = require("./tsparser.js"); 8 | const AVCParser = require("./pes/pes_avc_parser.js"); 9 | 10 | /** 11 | * Create an HLS TS parser 12 | * 13 | * @example 14 | * var parser = new window.HlsTs({ debug: false }); 15 | * parser.parse(data).then(function() { 16 | * var avcPayload = parser.getDataStreamByProgramType("avc"); 17 | * }); 18 | * @constructor 19 | * @alias window.HlsTs 20 | * @param {?HlsTsOptions} opts 21 | */ 22 | const HlsTsBrowser = function constructor(opts) { 23 | if (opts && opts.debug) { 24 | Logger.setLogLevel("DEBUG"); 25 | } else { 26 | Logger.setLogLevel("INFO"); 27 | } 28 | this.parser = new TSParser(); 29 | }; 30 | 31 | /** 32 | * Parse HLS TS data 33 | * 34 | * @param {Uint8Array} data The data to parse 35 | * @return {Promise} Resolves when data is parsed 36 | */ 37 | HlsTsBrowser.prototype.parse = function parse(data) { 38 | return new Promise((resolve, reject) => { 39 | if (this.parser.isValidChunk(data)) { 40 | this.parser.push(data, false); 41 | resolve(); 42 | } else { 43 | reject("Not a valid TS chunk"); 44 | } 45 | }); 46 | }; 47 | 48 | /** 49 | * Get the parsed program types 50 | * 51 | * @return {HlsTsProgramType[]} 52 | */ 53 | HlsTsBrowser.prototype.getPrograms = function() { 54 | return this.parser.getPrograms().getTypes(); 55 | }; 56 | 57 | /** 58 | * Get all packets for a specific program type 59 | * 60 | * @param {string} type Program type e.g: "avc" or "aac" 61 | * @return {HlsTsPacket[]} 62 | */ 63 | HlsTsBrowser.prototype.getPacketsByProgramType = function(type) { 64 | return this.parser.getPrograms().getPackets(type); 65 | }; 66 | 67 | /** 68 | * Get the data stream for a program type 69 | * 70 | * @param {string} type Program type e.g: "avc" or "aac" 71 | * @return {HlsTsDataStream} 72 | */ 73 | HlsTsBrowser.prototype.getDataStreamByProgramType = function(type) { 74 | return this.parser.getPrograms().getDataStream(type); 75 | }; 76 | 77 | /** 78 | * Create an AVC Parser that can parse an AVC data stream 79 | * 80 | * @example 81 | * var parser = new window.HlsTs(); 82 | * parser.parse(data).then(function() { 83 | * var avcParser = parser.createAvcParser(parser.getDataStreamByProgramType("avc")); 84 | * var nalUnits = avcParser.getNalUnits(); 85 | * }); 86 | * @param {HlsTsDataStream} dataStream 87 | * @return {AVCParser} 88 | */ 89 | HlsTsBrowser.prototype.createAvcParser = function(dataStream) { 90 | return new AVCParser(dataStream); 91 | } 92 | 93 | module.exports = HlsTsBrowser; -------------------------------------------------------------------------------- /lib/tsprograms.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const log = require("logplease").create("TSPrograms", { useColors: false }); 7 | 8 | const TSPrograms = function constructor(pmt, packets, streams) { 9 | this.pmt = pmt; 10 | this.packets = packets; 11 | this.streams = streams; 12 | 13 | Object.keys(this.streams).forEach((type) => { 14 | const stream = this.streams[type]; 15 | if (stream.size > 0) { 16 | throw new Error(`Stream of type ${type} has ${stream.size} bytes of unparsed data`); 17 | } 18 | }); 19 | }; 20 | 21 | TSPrograms.prototype.getTypes = function getTypes() { 22 | let programs = []; 23 | 24 | Object.keys(this.pmt).filter(programType => this.pmt[programType] !== -1).forEach((programType) => { 25 | const pid = this.pmt[programType]; 26 | const program = { 27 | id: pid, 28 | type: programType, 29 | packets: 0, 30 | pts: [], 31 | dts: [], 32 | }; 33 | program.pts = this.streams[program.type].peshdr.map(hdr => hdr.pts); 34 | program.dts = this.streams[program.type].peshdr.map(hdr => hdr.dts); 35 | this.packets.forEach((p) => { 36 | if (p.pid === program.id) { 37 | program.packets++; 38 | } 39 | }); 40 | programs.push(program); 41 | }); 42 | 43 | return programs; 44 | }; 45 | 46 | TSPrograms.prototype.getPackets = function getPackets(type) { 47 | if (!this.pmt[type]) { 48 | log.error(`Unsupported type ${type}`); 49 | return null; 50 | } 51 | if (this.pmt[type] === -1) { 52 | log.error(`No program found for ${type}`); 53 | return null; 54 | } 55 | 56 | const pid = this.pmt[type]; 57 | let packets = []; 58 | this.packets.filter(p => p.pid === pid).forEach((p) => { 59 | const packet = { 60 | pid: p.pid, 61 | payloadUnitStartIndicator: p.pusi, 62 | adaptationFieldControl: p.atf, 63 | pcr: { 64 | base: p.pcrBase, 65 | value: p.pcrValue, 66 | } 67 | }; 68 | packets.push(packet); 69 | }); 70 | return packets; 71 | }; 72 | 73 | TSPrograms.prototype.getDataStream = function getDataStream(type) { 74 | if (!this.streams[type]) { 75 | log.error(`No stream available for type ${type}`); 76 | return null; 77 | } 78 | 79 | log.debug(`${type}: len=${this.streams[type].payload.length}`); 80 | const buffer = new ArrayBuffer(this.streams[type].payload.length); 81 | const dataStream = { 82 | data: new Uint8Array(buffer), 83 | size: this.streams[type].payload.length, 84 | id: this.streams[type].id, 85 | pes: this.streams[type].peshdr, 86 | }; 87 | dataStream.data.set(this.streams[type].payload); 88 | 89 | return dataStream; 90 | }; 91 | 92 | module.exports = TSPrograms; -------------------------------------------------------------------------------- /global_exports.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @typedef {Object} HlsTsOptions 3 | * @property {boolean} debug Output debug informatin to logger 4 | */ 5 | 6 | /** 7 | * @typedef {Object} HlsTsProgramType 8 | * @property {number} id Program ID 9 | * @property {string} type Program type, e.g: avc, aac, id3 10 | * @property {number[]} pts List of all PTS values found 11 | * @property {number[]} dts List of all DTS values found 12 | */ 13 | 14 | /** 15 | * @typedef {Object} HlsTsPacket 16 | * @property {number} pid Program ID this packet belongs to 17 | * @property {boolean} payloadUnitStartIndicator Payload Unit Start Indicator (PUSI) 18 | * @property {number} adaptationFieldControl Adaptation Field Control (ATF) 19 | * @property {HlsTsPCR} pcr PCR value 20 | */ 21 | 22 | /** 23 | * @typedef {Object} HlsTsDataStream 24 | * @property {Uint8Array} data The audio and video data bytes 25 | * @property {number} size Amount of data bytes 26 | * @property {number} id Program ID 27 | * @property {HlsTsPesHeader[]} pes PES Headers for this data stream 28 | */ 29 | 30 | /** 31 | * @typedef {Object} HlsTsPCR 32 | * @property {number} base PCR base part 33 | * @property {number} value PCR value part 34 | */ 35 | 36 | /** 37 | * @typedef {Object} HlsTsPesHeader 38 | * @property {number} pts PTS value 39 | * @property {number} dts DTS value 40 | * @property {number} offset Byte offset in data stream where this PES header was found 41 | */ 42 | 43 | /** 44 | * @typedef {Object} HlsTsNalUnit 45 | * @property {Uint8Array} data The Nal payload 46 | * @property {number} type Nal Unit type 47 | * @property {number} offset Byte offset in data stream where this Nal Unit was found 48 | * @property {HlsTsPesHeader} pes PES Header for this chunk of AVC data 49 | */ 50 | 51 | /** 52 | * @typedef {Object} HlsTsNalUnitSPS 53 | * @property {number} profileIdc 54 | * @property {boolean[]} profileConstraintsFlags 55 | * @property {number} levelIdc 56 | * @property {?number} chromaFormatIdc 57 | * @property {?boolean} seperateColourPlaneFlag 58 | * @property {?number} bitDepthLuma 59 | * @property {?number} bitDepthChroma 60 | * @property {?boolean} qpPrimeYZeroTransformBypassFlag 61 | * @property {?boolean} seqScalingMatrixPresentFlag 62 | * @property {?number} log2MaxFrameNum 63 | * @property {?number} picOrderCntType 64 | * @property {?number} log2MaxPicOrderCntLsb 65 | * @property {?boolean} deltaPicOrderAlwaysZeroFlag 66 | * @property {?number} offsetForNonRefPic 67 | * @property {?number} offsetForTopToBottomField 68 | * @property {?number} numRefFrameInPicOrderCntCycle 69 | * @property {?number[]} offsetForRefFrame 70 | * @property {number} maxNumRefFrames 71 | * @property {boolean} gapsInFrameNumValueAllowedFlag 72 | * @property {number} picWidthInMbs 73 | * @property {number} picWidthInSamples 74 | * @property {number} picHeightInMapUnits 75 | * @property {number} picSizeInMapUnits 76 | */ 77 | 78 | window.HlsTs = require("./lib/browser.js"); -------------------------------------------------------------------------------- /test/lib/tsparser_unit.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const TSParser = require("../../lib/tsparser.js"); 7 | const TestAssetsModule = require("../support/testassets.js"); 8 | 9 | describe("TS Parser", () => { 10 | let testAssetsModule; 11 | 12 | beforeEach((done) => { 13 | testAssetsModule = new TestAssetsModule(); 14 | testAssetsModule.init().then(done); 15 | }); 16 | 17 | it("can verify that a correct TS file is correct", () => { 18 | const asset = testAssetsModule.getAssetByName("seg-10s"); 19 | const parser = new TSParser(); 20 | const isValid = parser.isValidChunk(asset.data); 21 | expect(isValid).toBe(true); 22 | }); 23 | 24 | it("can verify that a correct TS file is incorrect", () => { 25 | const asset = testAssetsModule.getAssetByName("seg-10s"); 26 | asset.data[0] = 0x48; 27 | const parser = new TSParser(); 28 | const isValid = parser.isValidChunk(asset.data); 29 | expect(isValid).toBe(false); 30 | }); 31 | 32 | it("can parse a TS file", () => { 33 | const asset = testAssetsModule.getAssetByName("seg-10s"); 34 | const parser = new TSParser(); 35 | parser.push(asset.data); 36 | const programs = parser.getPrograms(); 37 | const avcPackets = programs.getPackets("avc"); 38 | const aacPackets = programs.getPackets("aac"); 39 | const avcData = programs.getDataStream("avc"); 40 | const aacData = programs.getDataStream("aac"); 41 | 42 | // We should have avc, aac and scte35 43 | expect(programs.getTypes().length).toBe(3); 44 | 45 | // 10s and 25fps should be 250 frames 46 | expect(programs.getTypes().find(p => p.type === "avc").pts.length).toBe(250); 47 | 48 | // We shoule have 250 frames with PCR data 49 | expect(avcPackets.filter(p => p.pcr.base).length).toBe(250); 50 | 51 | expect(avcPackets.length).toBe(4931); 52 | expect(aacPackets.length).toBe(714); 53 | expect(avcData.size).toBe(879536); 54 | expect(aacData.size).toBe(119733); 55 | expect(avcData.id).toBe(224); 56 | }); 57 | 58 | it("can parse all test vectors", () => { 59 | const assets = [ 'seg-10s', 'seg2-10s', 'ysad01' ]; 60 | for (let i = 0; i < assets.length; i++) { 61 | let asset = testAssetsModule.getAssetByName(assets[i]); 62 | let parser = new TSParser(); 63 | parser.push(asset.data); 64 | expect(parser.getPrograms()).not.toBe(null); 65 | } 66 | }); 67 | 68 | it("can parse PCR", () => { 69 | const asset = testAssetsModule.getAssetByName("seg2-10s"); 70 | const parser = new TSParser(); 71 | parser.push(asset.data); 72 | const programs = parser.getPrograms(); 73 | const avcPackets = programs.getPackets("avc"); 74 | const avcProgram = programs.getTypes().find(prog => prog.type === "avc"); 75 | 76 | expect(avcPackets.filter(p => p.pcr.base).length).toBe(250); 77 | expect(avcPackets.filter(p => p.pcr.base).map(p => p.pcr.base)[0]).toBe(2683887710); 78 | expect(avcProgram.pts[0]).toBe(2683984615); 79 | }); 80 | }); 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/Eyevinn/hls-ts-js.svg?branch=master)](https://travis-ci.org/Eyevinn/hls-ts-js) 2 | [![Coverage Status](https://coveralls.io/repos/github/Eyevinn/hls-ts-js/badge.svg?branch=master)](https://coveralls.io/github/Eyevinn/hls-ts-js?branch=master) 3 | 4 | A Javascript library to parse Apple HLS MPEG Transport Stream segments 5 | 6 | ## Usage (Node JS) 7 | 8 | ``` 9 | npm install --save hls-ts 10 | ``` 11 | 12 | The library implements the `Writable` stream interface and acts a a "sink". For example to download 13 | and parse an HLS MPEG Transport Stream segment: 14 | 15 | ``` 16 | const request = require("request"); 17 | const hlsTs = require("hls-ts"); 18 | 19 | request.get("http://example.com/seg10.ts") 20 | .pipe(hlsTs.parse()) 21 | .on("finish", function() { 22 | 23 | // Obtain all programs found in the Transport Stream 24 | const programs = hlsTs.programs; 25 | 26 | // Obtain all packets for a specific program stream 27 | const avcPackets = hlsTs.getPacketsByProgramType("avc"); 28 | 29 | // Obtain the payload for a program stream 30 | const avcPayload = hlsTs.getDataStreamByProgramType("avc"); 31 | 32 | // where avcPayload.data is a Uint8Array 33 | const avcParser = hlsTs.createAvcParser(avcPayload); 34 | 35 | // Obtain NAL units 36 | const nalUnits = avcParser.getNalUnits(); 37 | }); 38 | ``` 39 | 40 | ## Usage (Browser version) 41 | 42 | ``` 43 | 44 | 72 | ``` 73 | 74 | ## API Documentation 75 | 76 | Find API documentation here: https://inspect.eyevinn.technology/docs/index.html 77 | 78 | ## Contributing 79 | All contributions are welcome but before you submit a Pull Request make sure you follow the same 80 | code conventions and that you have written unit tests 81 | 82 | ## About Eyevinn Technology 83 | 84 | Eyevinn Technology is an independent consultant firm specialized in video and streaming. Independent in a way that we are not commercially tied to any platform or technology vendor. 85 | 86 | At Eyevinn, every software developer consultant has a dedicated budget reserved for open source development and contribution to the open source community. This give us room for innovation, team building and personal competence development. And also gives us as a company a way to contribute back to the open source community. 87 | 88 | Want to know more about Eyevinn and how it is to work here. Contact us at work@eyevinn.se! 89 | -------------------------------------------------------------------------------- /lib/pes/exp_golomb.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const util = require("../util.js"); 7 | 8 | class ExpGolomb { 9 | constructor(rbspData) { 10 | this.rbspData = rbspData; 11 | this.currentBitPos = 0; 12 | this.currentBytePos = 0; 13 | this.posInByte = 0; 14 | this.lastPulledByte = null; 15 | } 16 | 17 | _pullByte() { 18 | return this.rbspData[this.currentBytePos]; 19 | } 20 | 21 | _pullWord() { 22 | const bytes = new Uint8Array(4); 23 | bytes[0] = this._pullByte(); 24 | bytes[1] = this._pullByte(); 25 | bytes[2] = this._pullByte(); 26 | bytes[3] = this._pullByte(); 27 | return new DataView(bytes).getUint32(0); 28 | } 29 | 30 | _increment(numBits) { 31 | if (numBits > 32) { 32 | throw new Error("Can only increment with max 32 bits at a time"); 33 | } 34 | this.currentBitPos += numBits; 35 | this.currentBytePos = Math.floor(this.currentBitPos / 8); 36 | } 37 | 38 | readByte() { 39 | const byte = this._pullByte(); 40 | this._increment(8); 41 | return byte; 42 | } 43 | 44 | readBits(numBits) { 45 | let remainingBits = numBits; 46 | let bits = []; 47 | 48 | while (remainingBits > 0) { 49 | let consumedBits = 0; 50 | const byte = this._pullByte(); 51 | const bitsArray = util.readBits(byte, 8); 52 | const bitsToAppend = bitsArray.slice(this.posInByte, Math.min(this.posInByte + remainingBits, 8)); 53 | bits = bits.concat(bitsToAppend); 54 | consumedBits = bitsToAppend.length; 55 | this.posInByte += consumedBits; 56 | if (this.posInByte > 7) { 57 | this.posInByte = 0; 58 | } 59 | remainingBits -= consumedBits; 60 | this._increment(consumedBits); 61 | } 62 | return bits; 63 | } 64 | 65 | readFlags(numBits) { 66 | const byte = this._pullByte(); 67 | this._increment(numBits); 68 | return util.readFlags(byte, numBits); 69 | } 70 | 71 | /** 72 | * Get Exp-Golomb coded value 73 | * 74 | * @return {number} 75 | */ 76 | readCodeNum() { 77 | const leadingZeroBits = this.skipLeadingZeros(); 78 | const val = util.bitsToNumber(this.readBits(leadingZeroBits)); 79 | const codeNum = (2 << leadingZeroBits-1) - 1 + val; 80 | return codeNum; 81 | } 82 | 83 | /** 84 | * Get Truncated Exp-Golomb coded value 85 | * 86 | * @return {number} 87 | */ 88 | readTruncatedCodeNum() { 89 | 90 | } 91 | 92 | /** 93 | * Get ue(v) coded syntax element 94 | */ 95 | readUE() { 96 | return this.readCodeNum(); 97 | } 98 | 99 | /** 100 | * Get se(v) coded syntax element 101 | */ 102 | readSE() { 103 | const codeNum = this.readCodeNum(); 104 | return Math.pow(-1, codeNum + 1) * Math.ceil(codeNum / 2); 105 | } 106 | 107 | /** 108 | * Get me(v) coded syntax element 109 | */ 110 | readME() { 111 | 112 | } 113 | 114 | /** 115 | * Get te(v) coded syntax element 116 | */ 117 | readTE() { 118 | 119 | } 120 | 121 | skipByte() { 122 | this._increment(8); 123 | } 124 | 125 | skipBits(numBits) { 126 | this._increment(numBits); 127 | } 128 | 129 | /** 130 | * @return {number} leading zero count 131 | */ 132 | skipLeadingZeros() { 133 | let leadingZeroBits = -1; 134 | let bit = 0; 135 | while (bit != 1) { 136 | const bits = this.readBits(1); 137 | bit = bits[0]; 138 | leadingZeroBits++; 139 | } 140 | return leadingZeroBits; 141 | } 142 | } 143 | 144 | module.exports = ExpGolomb; -------------------------------------------------------------------------------- /lib/pes/pes_avc_parser.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const PESParser = require("./pes_parser.js"); 7 | const NalUParser = require("./nalu_parser.js"); 8 | const log = require("logplease").create("PESAVCParser", { useColors: false }); 9 | const util = require("../util.js"); 10 | 11 | const NAL_START_PREFIX = 0x01; 12 | const BYTE_STATE = { 13 | "0-7": 0, 14 | "8-15": 1, 15 | "16-23": 2, 16 | "24-31": 3, 17 | }; 18 | 19 | const NALUnit = function constructor() { 20 | return { 21 | data: undefined, 22 | type: undefined, 23 | offset: -1, 24 | pes: undefined, 25 | }; 26 | } 27 | 28 | /** 29 | * @class 30 | * @extends PESParser 31 | */ 32 | class PESAVCParser extends PESParser { 33 | /** 34 | * @constructor 35 | * @param {HlsTsDataStream} pes Data stream to parse 36 | */ 37 | constructor(pes) { 38 | super(pes); 39 | } 40 | 41 | /** 42 | * Translates a Nal Unit type value to a readable string 43 | * 44 | * @param {number} type Nal Unit Type 45 | * @return {string} 46 | */ 47 | nalUnitType(type) { 48 | return NalUParser.nalUnitTypeToString(type); 49 | } 50 | 51 | /** 52 | * Translates a Nal Unit type value to a Nal Unit category 53 | * 54 | * @param {number} type Nal Unit Type 55 | * @return {string} 56 | */ 57 | nalUnitCategory(type) { 58 | return NalUParser.nalUnitTypeToCategory(type); 59 | } 60 | 61 | /** 62 | * Get the RBSP (Raw Byte Sequence Payload) from a Nal Unit 63 | * 64 | * @param {HlsTsNalUnit} nalUnit 65 | * @return {Uint8Array} 66 | */ 67 | rbspFromNalUnit(nalUnit) { 68 | return new NalUParser(nalUnit).rbsp(); 69 | } 70 | 71 | /** 72 | * Get the SPS (Sequence Paramater Set) from a Nal Unit. Returns null 73 | * if Nal Unit type is not SPS in 74 | * 75 | * @param {HlsTsNalUnit} nalUnit 76 | * @return {HlsTsNalUnitSPS} 77 | */ 78 | spsFromNalUnit(nalUnit) { 79 | return new NalUParser(nalUnit).sps(); 80 | } 81 | 82 | /** 83 | * Get all Nal Units in this data stream 84 | * 85 | * @return {HlsTsNalUnit[]} 86 | */ 87 | getNalUnits() { 88 | const data = this.getData(); 89 | const len = data.byteLength; 90 | let state = BYTE_STATE["0-7"]; 91 | let pos = 0; 92 | let units = []; 93 | let unitType; 94 | let unitStartPos = -1; 95 | 96 | //log.debug(util.hexDump(data)); 97 | 98 | let byte; 99 | while (pos < len) { 100 | byte = data[pos++]; 101 | //log.debug(`pos=${pos}, byte:`, util.toHex(byte)); 102 | if (state === BYTE_STATE["0-7"]) { 103 | state = byte ? BYTE_STATE["0-7"] : BYTE_STATE["8-15"]; 104 | continue; 105 | } 106 | if (state === BYTE_STATE["8-15"]) { 107 | state = byte ? BYTE_STATE["0-7"] : BYTE_STATE["16-23"]; 108 | continue; 109 | } 110 | if (state === BYTE_STATE["16-23"] || state === BYTE_STATE["24-31"]) { 111 | if (byte === 0) { 112 | state = BYTE_STATE["24-31"]; 113 | } else if (byte === NAL_START_PREFIX) { 114 | //log.debug(`Start Prefix at ${pos} unitStartPos=${unitStartPos}`); 115 | if (unitStartPos >= 0) { 116 | const unit = new NALUnit(); 117 | unit.data = data.subarray(unitStartPos, pos - state - 1); 118 | unit.type = unitType; 119 | unit.offset = unitStartPos - state - 1; 120 | unit.pes = this.getHeaderForByteOffset(unit.offset); 121 | units.push(unit); 122 | log.debug(`NAL Type:${this.nalUnitType(unitType)} (${unitStartPos})`); 123 | } 124 | unitType = data[pos] & 0x1f; 125 | unitStartPos = pos; 126 | } else { 127 | state = BYTE_STATE["0-7"]; 128 | } 129 | } 130 | } 131 | if (unitStartPos >= 0) { 132 | const unit = new NALUnit(); 133 | unit.data = data.subarray(unitStartPos, pos - state); 134 | unit.type = unitType; 135 | unit.offset = unitStartPos - state; 136 | unit.pes = this.getHeaderForByteOffset(unit.offset); 137 | units.push(unit); 138 | } 139 | return units; 140 | } 141 | } 142 | 143 | module.exports = PESAVCParser; 144 | -------------------------------------------------------------------------------- /lib/pes/pes_aac_parser.js: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const PESParser = require("./pes_parser.js"); 7 | const log = require("logplease").create("PESAACParser", { useColors: false }); 8 | const util = require("../util.js"); 9 | 10 | const SAMPLING_RATES = { 11 | 0: 96000, // `0000` - 96000 Hz 12 | 1: 88200, // `0001` - 88200 Hz 13 | 2: 64000, // `0010` - 64000 Hz 14 | 3: 48000, // `0011` - 48000 Hz 15 | 4: 44100, // `0100` - 44100 Hz 16 | 5: 32000, // `0101` - 32000 Hz 17 | 6: 24000, // `0110` - 24000 Hz 18 | 7: 22050, // `0111` - 22050 Hz 19 | 8: 16000, // `1000` - 16000 Hz 20 | 9: 12000, // `1001` - 12000 Hz 21 | 10: 11025, // `1010` - 11025 Hz 22 | 11: 8000, // `1011` - 8000 Hz 23 | 12: 7350, // `1100` - 7350 Hz 24 | 13: 0, // `1101` - Reserved 25 | 14: 0, // `1110` - Reserved 26 | 15: 0, // `1111` - other 27 | }; 28 | 29 | const CHANNELS = { 30 | 0: 0.0, 31 | 1: 1.0, // 1 ch - (Front: center) 32 | 2: 2.0, // 2 ch - (Front: left, right) 33 | 3: 3.0, // 3 ch - (Front: left, center, right) 34 | 4: 4.0, // 4 ch - (Front: left, center, right) (Rear: center) 35 | 5: 5.0, // 5 ch - (Front: left, center, right) (Rear: left, right) 36 | 6: 5.1, // 5.1 ch - (Front: left, center, right) (Rear: left, right, subwoofer) 37 | 7: 7.1, // 7.1 ch - (Front: left, center, right)(Side: left, right)(Rear: left, right, subwoofer) 38 | }; 39 | 40 | /** 41 | * @class 42 | * @extends PESParser 43 | */ 44 | class PESAACParser extends PESParser { 45 | constructor(pes) { 46 | super(pes); 47 | } 48 | 49 | /** 50 | * Get all ADTS Frames in this data stream 51 | * 52 | * @return {AdtsFrame[]} 53 | */ 54 | getAdtsFrames() { 55 | const data = this.getData(); 56 | const len = data.byteLength; 57 | let pos = 0; 58 | let adtsFrames = []; 59 | 60 | //log.debug(util.hexDump(data)); 61 | 62 | let byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8; 63 | while (pos < len) { 64 | let frameStart = pos; 65 | byte0 = data[pos]; 66 | byte1 = data[pos + 1]; 67 | byte2 = data[pos + 2]; 68 | byte3 = data[pos + 3]; 69 | byte4 = data[pos + 4]; 70 | byte5 = data[pos + 5]; 71 | byte6 = data[pos + 6]; 72 | byte7 = data[pos + 7]; 73 | byte8 = data[pos + 8]; 74 | //log.debug(`pos=${pos}, byte:`, util.toHex(byte)); 75 | 76 | let syncword = (byte0 === 0xFF) && ((byte1 & 0xF0) === 0xF0); // 1111 1111 1111 77 | let mpegVersion = (byte1 & 0x08) === 1 ? 2 : 4; // 0 == MPEG4, 1 == MPEG2 78 | let layer = (byte1 & 0x06) === 0 ? true : false; 79 | let crcProtection = (byte1 & 0x01) === 0 ? true : false; // 0 == HAS CRC, 1 == NO CRC 80 | let audioObjectType = ((byte2 & 0xC0) >> 6) + 1; // 2 == AAC-LC, 5 == HE-AAC, 29 == HE-AAC v2 81 | let samplingRate = SAMPLING_RATES[(byte2 & 0x3C) >> 2]; // 0100 == 44100 82 | let channels = CHANNELS[((byte2 & 0x01) << 2 | byte3 & 0xC0) >> 6]; // 2 == LEFT+RIGHT 83 | 84 | let adtsFrameLength = (byte3 & 0x03) << 11 | byte4 << 3 | (byte5 & 0xE0) >> 5; // adtsHeaderLength + crcLength + (rawDataBlockEnd - rawDataBlockStart) 85 | let bufferFullness = (byte5 & 0x1f) << 6 | byte6 >> 2; 86 | let rdbsInFrame = (byte6 & 0x03); 87 | let adtsHeaderLength = 7; 88 | let crcLength = crcProtection ? 2 : 0; 89 | let rawDataBlockStart = pos + adtsHeaderLength; 90 | let rawDataBlockEnd = pos + adtsFrameLength; 91 | let crc1 = crcProtection ? (((byte7 << 8) | byte8) >>> 0) : 0; 92 | let crc2 = crc1; 93 | let error = false; 94 | 95 | if (!syncword || !layer || audioObjectType !== 2) { 96 | error = true; 97 | } 98 | //log.debug(`${pos}: syncword=${syncword}, layer=${layer}, audioObjectType=${audioObjectType}, error=${error}`); 99 | 100 | if (error) { 101 | pos++; // skip unknown byte 102 | } else { 103 | let pes = this.getHeaderForByteOffset(pos); 104 | pos += adtsFrameLength; 105 | 106 | adtsFrames.push({ 107 | pes: pes, 108 | frameStart: frameStart, 109 | frameEnd: rawDataBlockEnd, 110 | mpegVersion: mpegVersion, 111 | crcProtection: crcProtection, 112 | audioObjectType: audioObjectType, 113 | samplingRate: samplingRate, 114 | channels: channels, 115 | adtsFrameLength: adtsFrameLength, 116 | adtsHeaderLength: adtsHeaderLength, 117 | crcLength: crcLength, 118 | rawDataBlockStart: rawDataBlockStart, 119 | rawDataBlockEnd: rawDataBlockEnd, 120 | bufferFullness: bufferFullness, 121 | rdbsInFrame: rdbsInFrame, 122 | error: error, 123 | data: data.subarray(rawDataBlockStart, rawDataBlockEnd) 124 | }); 125 | } 126 | 127 | } 128 | return adtsFrames; 129 | } 130 | 131 | audioType(type) { 132 | const mapping = { 133 | 2: 'AAC-LC', 134 | 5: 'HE-AAC', 135 | 29: 'HE-AACv2' 136 | }; 137 | return mapping[type]; 138 | } 139 | } 140 | 141 | module.exports = PESAACParser; -------------------------------------------------------------------------------- /docs/lib_parse_stream.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | lib/parse_stream.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

lib/parse_stream.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
// Copyright 2017 Eyevinn Technology. All rights reserved
 42 | // Use of this source code is governed by a MIT License
 43 | // license that can be found in the LICENSE file.
 44 | // Author: Jonas Birme (Eyevinn Technology)
 45 | 
 46 | const Writable = require("stream").Writable;
 47 | const TSParser = require("./tsparser.js");
 48 | 
 49 | /**
 50 |  * Implements the Stream.Writable API to handle
 51 |  * chunk of HLS TS data to be parsed
 52 |  * 
 53 |  * @example
 54 |  * request.get("http://example.com/seg10.ts")
 55 |  * .pipe(hlsTs.parse())  // parse() creates a ParseStream object
 56 |  * .on("finish", function() {
 57 |  *   const avcPackets = hlsTs.getPacketsByProgramType("avc");
 58 |  * });
 59 |  * @class
 60 |  * @extends Writable
 61 |  */
 62 | class ParseStream extends Writable {
 63 |   constructor(opts) {
 64 |     super(opts);
 65 |     this.parser = new TSParser();
 66 |     this.firstChunk = true;
 67 |   }
 68 | }
 69 | 
 70 | ParseStream.prototype.getPrograms = function getPrograms() {
 71 |   return this.parser.getPrograms();
 72 | }
 73 | 
 74 | ParseStream.prototype._write = function(chunk, encoding, next) {
 75 |   // Parse data
 76 |   //console.log("_write:" + chunk.length);
 77 |   let err;
 78 |   this.firstChunk = false;
 79 |   if (this.firstChunk) {
 80 |     if (!this.parser.isValidChunk(chunk)) {
 81 |       err = new Error("Invalid TS chunk");
 82 |     }
 83 |   }
 84 |   try {
 85 |     this.parser.push(chunk, false);
 86 |   } catch (parserError) {
 87 |     err = new Error(`Failed to parse chunk: ${parserError}`);
 88 |   }
 89 |   next(err);
 90 | };
 91 | 
 92 | module.exports = ParseStream;
93 |
94 |
95 | 96 | 97 | 98 | 99 |
100 | 101 |
102 | 103 | 106 | 107 | 108 | 109 | 110 | 111 | -------------------------------------------------------------------------------- /docs/lib_pes_pes_parser.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | lib/pes/pes_parser.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

lib/pes/pes_parser.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
// Copyright 2017 Eyevinn Technology. All rights reserved
 42 | // Use of this source code is governed by a MIT License
 43 | // license that can be found in the LICENSE file.
 44 | // Author: Jonas Birme (Eyevinn Technology)
 45 | 
 46 | /**
 47 |  * @class
 48 |  */
 49 | class PESParser {
 50 |   /**
 51 |    * @constructor
 52 |    * @param {HlsTsDataStream} pes Data stream to parse
 53 |    */
 54 |   constructor(pes) {
 55 |     this.data = pes.data;
 56 |     this.pes = pes.pes;
 57 |     this.id = pes.id;
 58 |   }
 59 | 
 60 |   /**
 61 |    * Get program ID
 62 |    * 
 63 |    * @return {number} Program ID
 64 |    */
 65 |   getId() {
 66 |     return this.id;
 67 |   }
 68 | 
 69 |   /**
 70 |    * Get data stream as Uint8 byte array
 71 |    * 
 72 |    * @return {Uint8Array} Data stream
 73 |    */
 74 |   getData() {
 75 |     return this.data;
 76 |   }
 77 | 
 78 |   /**
 79 |    * Get PES headers in this data stream
 80 |    * 
 81 |    * @return {HlsTsPesHeader[]}
 82 |    */
 83 |   getHeaders() {
 84 |     return this.pes;
 85 |   }
 86 | 
 87 |   /**
 88 |    * Get a PES header at a specific position in the data stream
 89 |    * 
 90 |    * @param {number} offset Position in the data stream
 91 |    * @return {HlsTsPesHeader}
 92 |    */
 93 |   getHeaderForByteOffset(offset) {
 94 |     let lastPes = undefined;
 95 |     for (let i = 0; i < this.pes.length; i++) {
 96 |       const p = this.pes[i];
 97 |       if (i > 0 && p.offset > offset) {
 98 |         const lastPes = this.pes[i - 1];
 99 |         return lastPes;
100 |       }
101 |     }
102 |     if (this.pes.length > 0) {
103 |         return this.pes[this.pes.length - 1];
104 |     }
105 |     return null;
106 |   }
107 | }
108 | 
109 | module.exports = PESParser;
110 | 
111 |
112 |
113 | 114 | 115 | 116 | 117 |
118 | 119 |
120 | 121 | 124 | 125 | 126 | 127 | 128 | 129 | -------------------------------------------------------------------------------- /lib/pes/nalu_parser.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const util = require("../util.js"); 7 | const ExpGolomb = require("./exp_golomb.js"); 8 | 9 | const NAL_UNIT_TYPE = { 10 | 0: "Unspecified", 11 | 1: "Coded slice of a non-IDR picture", 12 | 2: "Coded slice data partition A", 13 | 3: "Coded slice data partition B", 14 | 4: "Coded slice data partition C", 15 | 5: "Coded slice of an IDR picture", 16 | 6: "Supplemental enhancement information (SEI)", 17 | 7: "Sequence parameter set", 18 | 8: "Picture parameter set", 19 | 9: "Access unit delimiter", 20 | 10: "End of sequence", 21 | 11: "End of stream", 22 | 12: "Filler data", 23 | 13: "Sequence parameter set extension", 24 | 14: "Prefix NAL unit", 25 | 15: "Subset sequence parameter set", 26 | 16: "Depth parameter set", 27 | 17: "Reserved", 28 | 18: "Reserved", 29 | 19: "Coded slice of an auxiliary coded picture without partitioning", 30 | 20: "Coded slice extension", 31 | 21: "Coded slice extension for depth view components", 32 | 22: "Reserved", 33 | 23: "Reserved", 34 | 24: "Unspecified", 35 | 28: "Unspecified", 36 | 29: "Unspecified", 37 | }; 38 | 39 | const NAL_UNIT_CATEGORY = { 40 | 0: "non-VCL", 41 | 1: "VCL", 42 | 2: "VCL", 43 | 3: "VCL", 44 | 4: "VCL", 45 | 5: "VCL", 46 | 6: "non-VCL", 47 | 7: "non-VCL", 48 | 8: "non-VCL", 49 | 9: "non-VCL", 50 | 10: "non-VCL", 51 | 11: "non-VCL", 52 | 12: "non-VCL", 53 | 13: "non-VCL", 54 | 14: "non-VCL", 55 | 15: "non-VCL", 56 | 16: "non-VCL", 57 | 17: "non-VCL", 58 | 18: "non-VCL", 59 | 19: "non-VCL", 60 | 20: "non-VCL", 61 | 21: "non-VCL", 62 | 22: "non-VCL", 63 | 23: "non-VCL", 64 | 24: "non-VCL", 65 | 25: "non-VCL", 66 | 26: "non-VCL", 67 | 27: "non-VCL", 68 | 28: "non-VCL", 69 | 29: "non-VCL", 70 | }; 71 | 72 | const NalUnitSPS = function constructor() { 73 | return { 74 | 75 | }; 76 | }; 77 | 78 | class NalUParser { 79 | /** 80 | * @constructor 81 | * @param {HlsTsNalUnit} nalUnit NAL Unit to parse 82 | */ 83 | constructor(nalUnit) { 84 | this.nalUnit = nalUnit; 85 | } 86 | 87 | /** 88 | * Get the NALU data as RBSP 89 | * 90 | * @return {Uint8Array} 91 | */ 92 | rbsp() { 93 | const len = this.nalUnit.data.byteLength; 94 | let pos = 0; 95 | let epbs = []; 96 | 97 | while (pos < (len - 2)) { 98 | if (this.nalUnit.data[pos] == 0 && this.nalUnit.data[pos+1] == 0 && this.nalUnit.data[pos+2] == 0x03) { 99 | epbs.push(pos + 2); 100 | pos += 2; 101 | } else { 102 | pos++; 103 | } 104 | } 105 | let rbsp = new Uint8Array(len - epbs.length); 106 | 107 | // Remove the EPBs 108 | pos = 0; 109 | for (let i = 0; i < rbsp.length; i++) { 110 | if (pos === epbs[0]) { 111 | pos++; 112 | epbs.shift(); 113 | } 114 | rbsp[i] = this.nalUnit.data[pos]; 115 | pos++; 116 | } 117 | return rbsp; 118 | } 119 | 120 | /** 121 | * Get SPS data in NALU (if available) 122 | * 123 | * @return {HlsTsNalUnitSPS} 124 | */ 125 | sps() { 126 | if (this.nalUnit.type != 7) { 127 | return null; 128 | } 129 | let nalUnitSPS = new NalUnitSPS(); 130 | 131 | const rbspData = new ExpGolomb(this.rbsp()); 132 | rbspData.skipByte(); // NalU type 133 | const profileIdc = rbspData.readByte(); 134 | nalUnitSPS.profileIdc = profileIdc; 135 | nalUnitSPS.profileConstraintsFlags = rbspData.readFlags(6); 136 | // Skip reserved bits 137 | rbspData.skipBits(2); 138 | nalUnitSPS.levelIdc = rbspData.readByte(); 139 | const spsId = rbspData.readUE(); 140 | if (profileIdc === 100 || profileIdc === 110 || profileIdc === 122 || 141 | profileIdc === 244 || profileIdc === 44 || profileIdc === 83 || 142 | profileIdc === 86 || profileIdc === 118 || profileIdc === 128 || 143 | profileIdc === 138 || profileIdc === 139 || profileIdc === 134 || profileIdc === 135) 144 | { 145 | nalUnitSPS.chromaFormatIdc = rbspData.readUE(); 146 | if (nalUnitSPS.chromaFormatIdc === 3) { 147 | const flags = rbspData.readFlags(1); 148 | nalUnitSPS.seperateColourPlaneFlag = flags[0]; 149 | } 150 | nalUnitSPS.bitDepthLuma = rbspData.readUE() + 8; 151 | nalUnitSPS.bitDepthChroma = rbspData.readUE() + 8; 152 | const flags = rbspData.readFlags(2); 153 | nalUnitSPS.qpPrimeYZeroTransformBypassFlag = flags[0]; 154 | nalUnitSPS.seqScalingMatrixPresentFlag = flags[1]; 155 | if (nalUnitSPS.seqScalingMatrixPresentFlag) { 156 | nalUnitSPS.seqScalingListPresentFlag = rbspData.readFlags(chromaFormatIdc != 3 ? 8 : 12); 157 | } 158 | } 159 | nalUnitSPS.log2MaxFrameNum = rbspData.readUE() + 4; 160 | nalUnitSPS.picOrderCntType = rbspData.readUE(); 161 | if (nalUnitSPS.picOrderCntType === 0) { 162 | nalUnitSPS.log2MaxPicOrderCntLsb = rbspData.readUE() + 4; 163 | } else if (nalUnitSPS.picOrderCntType === 1) { 164 | nalUnitSPS.deltaPicOrderAlwaysZeroFlag = rbspData.readFlags(1)[0]; 165 | nalUnitSPS.offsetForNonRefPic = rbspData.readSE(); 166 | nalUnitSPS.offsetForTopToBottomField = rbspData.readSE(); 167 | nalUnitSPS.numRefFrameInPicOrderCntCycle = rbspData.readUE(); 168 | nalUnitSPS.offsetForRefFrame = []; 169 | for (let i = 0; i < nalUnitSPS.numRefFrameInPicOrderCntCycle; i++) { 170 | nalUnitSPS.offsetForRefFrame.push(rbspData.readSE()); 171 | } 172 | } 173 | nalUnitSPS.maxNumRefFrames = rbspData.readUE(); 174 | nalUnitSPS.gapsInFrameNumValueAllowedFlag = rbspData.readFlags(1)[0]; 175 | nalUnitSPS.picWidthInMbs = rbspData.readUE() + 1; 176 | nalUnitSPS.picWidthInSamples = nalUnitSPS.picWidthInMbs * 16; 177 | nalUnitSPS.picHeightInMapUnits = rbspData.readUE() + 1; 178 | nalUnitSPS.picSizeInMapUnits = nalUnitSPS.picWidthInMbs * nalUnitSPS.picHeightInMapUnits; 179 | 180 | return nalUnitSPS; 181 | } 182 | 183 | static nalUnitTypeToString(nalUnitType) { 184 | return NAL_UNIT_TYPE[nalUnitType]; 185 | } 186 | 187 | static nalUnitTypeToCategory(nalUnitType) { 188 | return NAL_UNIT_CATEGORY[nalUnitType]; 189 | } 190 | 191 | } 192 | 193 | module.exports = NalUParser; -------------------------------------------------------------------------------- /docs/ParseStream.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ParseStream - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

ParseStream

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 |
42 | 43 |

44 | ParseStream 45 |

46 | 47 |
Implements the Stream.Writable API to handle 48 | chunk of HLS TS data to be parsed
49 | 50 | 51 |
52 | 53 |
54 |
55 | 56 | 57 | 58 | 59 |

Constructor

60 | 61 | 62 |

new ParseStream()

63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 |
81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 |
Source:
108 |
111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 |
119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
Example
135 | 136 |
request.get("http://example.com/seg10.ts")
137 | .pipe(hlsTs.parse())  // parse() creates a ParseStream object
138 | .on("finish", function() {
139 |   const avcPackets = hlsTs.getPacketsByProgramType("avc");
140 | });
141 | 142 | 143 | 144 | 145 |
146 | 147 | 148 |

Extends

149 | 150 | 151 | 152 | 153 |
    154 |
  • Writable
  • 155 |
156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 |
176 | 177 |
178 | 179 | 180 | 181 | 182 |
183 | 184 |
185 | 186 | 189 | 190 | 191 | 192 | 193 | -------------------------------------------------------------------------------- /docs/index.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | index.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

index.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
const Logger = require("logplease");
 42 | const ParseStream = require("./lib/parse_stream.js");
 43 | const AVCParser = require("./lib/pes/pes_avc_parser.js");
 44 | const AACParser = require("./lib/pes/pes_aac_parser.js");
 45 | 
 46 | 
 47 | /** 
 48 |  * @module HlsTs
 49 |  */
 50 | 
 51 | const HlsTS = {
 52 |   streamParser: undefined,
 53 |   /**
 54 |    * Parse HLS TS when reading from a Stream
 55 |    *
 56 |    * @function parse
 57 |    * @example
 58 |    * fs.createReadStream("./seg-10s.ts")
 59 |    * .pipe(hlsTs.parse({ debug: true }))
 60 |    * .on("finish", function() {
 61 |    *   const avcPayload = hlsTs.getDataStreamByProgramType("avc");
 62 |    * });   
 63 |    * @param {?HlsTsOptions} opts
 64 |    * @return {ParseStream}
 65 |    */
 66 |   parse: function(opts) {
 67 |     if (opts && opts.debug) {
 68 |       Logger.setLogLevel("DEBUG");            
 69 |     } else {
 70 |       Logger.setLogLevel("INFO");
 71 |     }
 72 |     this.streamParser = new ParseStream(opts);
 73 |     return this.streamParser;
 74 |   },
 75 |   /**
 76 |    * Get the parsed program types
 77 |    * 
 78 |    * @member {HlsTsProgramType[]} programs
 79 |    */
 80 |   get programs() {
 81 |     if (!this.streamParser) {
 82 |       throw new Error("Nothing parsed yet");
 83 |     }
 84 |     return this.streamParser.getPrograms().getTypes();    
 85 |   },
 86 |   /**
 87 |    * Get all packets for a specific program type
 88 |    * 
 89 |    * @function getPacketsByProgramType
 90 |    * @param {string} type
 91 |    * @return {HlsTsPacket[]}
 92 |    */
 93 |   getPacketsByProgramType(type) {
 94 |     if (!this.streamParser) {
 95 |       throw new Error("Nothing parsed yet");
 96 |     }
 97 |     return this.streamParser.getPrograms().getPackets(type);    
 98 |   },
 99 |   /**
100 |    * Get the data stream for a program type
101 |    * 
102 |    * @function getDataStreamByProgramType
103 |    * @param {string} type
104 |    * @return {HlsTsDataStream}
105 |    */
106 |   getDataStreamByProgramType(type) {
107 |     if (!this.streamParser) {
108 |       throw new Error("Nothing parsed yet");
109 |     }
110 |     return this.streamParser.getPrograms().getDataStream(type);    
111 |   },
112 |   /**
113 |    * Create an AVC Parser that can parse an AVC data stream
114 |    * 
115 |    * @function createAvcParser
116 |    * @param {HlsDataStream} dataStream
117 |    * @return {AVCParser}
118 |    */
119 |   createAvcParser(dataStream) {
120 |     return new AVCParser(dataStream);
121 |   },
122 |   /**
123 |    * Create an AAC Parser that can parse an AAC data stream
124 |    * 
125 |    * @function createAacParser
126 |    * @param {HlsDataStream} dataStream
127 |    * @return {AACParser}
128 |    */
129 |   createAacParser(dataStream) {
130 |     return new AACParser(dataStream);
131 |   }
132 | };
133 | 
134 | module.exports = HlsTS;
135 |
136 |
137 | 138 | 139 | 140 | 141 |
142 | 143 |
144 | 145 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /docs/lib_browser.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | lib/browser.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

lib/browser.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
// Copyright 2017 Eyevinn Technology. All rights reserved
 42 | // Use of this source code is governed by a MIT License
 43 | // license that can be found in the LICENSE file.
 44 | // Author: Jonas Birme (Eyevinn Technology)
 45 | 
 46 | const Logger = require("logplease");
 47 | const TSParser = require("./tsparser.js");
 48 | const AVCParser = require("./pes/pes_avc_parser.js");
 49 | 
 50 | /**
 51 |  * Create an HLS TS parser
 52 |  * 
 53 |  * @example
 54 |  * var parser = new window.HlsTs({ debug: false });
 55 |  * parser.parse(data).then(function() {
 56 |  *   var avcPayload = parser.getDataStreamByProgramType("avc");
 57 |  * });
 58 |  * @constructor
 59 |  * @alias window.HlsTs
 60 |  * @param {?HlsTsOptions} opts
 61 |  */
 62 | const HlsTsBrowser = function constructor(opts) {
 63 |   if (opts && opts.debug) {
 64 |     Logger.setLogLevel("DEBUG");            
 65 |   } else {
 66 |     Logger.setLogLevel("INFO");
 67 |   }
 68 |   this.parser = new TSParser();
 69 | };
 70 | 
 71 | /**
 72 |  * Parse HLS TS data
 73 |  * 
 74 |  * @param {Uint8Array} data The data to parse
 75 |  * @return {Promise} Resolves when data is parsed
 76 |  */
 77 | HlsTsBrowser.prototype.parse = function parse(data) {
 78 |   return new Promise((resolve, reject) => {
 79 |     if (this.parser.isValidChunk(data)) {
 80 |       this.parser.push(data, false);
 81 |       resolve();
 82 |     } else {
 83 |       reject("Not a valid TS chunk");
 84 |     }
 85 |   });
 86 | };
 87 | 
 88 | /**
 89 |  * Get the parsed program types
 90 |  * 
 91 |  * @return {HlsTsProgramType[]}
 92 |  */
 93 | HlsTsBrowser.prototype.getPrograms = function() {
 94 |   return this.parser.getPrograms().getTypes();
 95 | };
 96 | 
 97 | /**
 98 |  * Get all packets for a specific program type
 99 |  * 
100 |  * @param {string} type Program type e.g: "avc" or "aac"
101 |  * @return {HlsTsPacket[]}
102 |  */
103 | HlsTsBrowser.prototype.getPacketsByProgramType = function(type) {
104 |   return this.parser.getPrograms().getPackets(type);    
105 | };
106 | 
107 | /**
108 |  * Get the data stream for a program type
109 |  * 
110 |  * @param {string} type Program type e.g: "avc" or "aac"
111 |  * @return {HlsTsDataStream}
112 |  */
113 | HlsTsBrowser.prototype.getDataStreamByProgramType = function(type) {
114 |   return this.parser.getPrograms().getDataStream(type);    
115 | };
116 | 
117 | /**
118 |  * Create an AVC Parser that can parse an AVC data stream
119 |  * 
120 |  * @example
121 |  * var parser = new window.HlsTs();
122 |  * parser.parse(data).then(function() {
123 |  *   var avcParser = parser.createAvcParser(parser.getDataStreamByProgramType("avc"));
124 |  *   var nalUnits = avcParser.getNalUnits();
125 |  * });
126 |  * @param {HlsTsDataStream} dataStream
127 |  * @return {AVCParser}
128 |  */
129 | HlsTsBrowser.prototype.createAvcParser = function(dataStream) {
130 |   return new AVCParser(dataStream);
131 | }
132 | 
133 | module.exports = HlsTsBrowser;
134 |
135 |
136 | 137 | 138 | 139 | 140 |
141 | 142 |
143 | 144 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /docs/global_exports.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | global_exports.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

global_exports.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
/**
 42 |  * @typedef {Object} HlsTsOptions
 43 |  * @property {boolean} debug Output debug informatin to logger
 44 |  */
 45 | 
 46 | /**
 47 |  * @typedef {Object} HlsTsProgramType
 48 |  * @property {number} id Program ID
 49 |  * @property {string} type Program type, e.g: avc, aac, id3
 50 |  * @property {number[]} pts List of all PTS values found
 51 |  * @property {number[]} dts List of all DTS values found
 52 |  */
 53 | 
 54 | /**
 55 |  * @typedef {Object} HlsTsPacket
 56 |  * @property {number} pid Program ID this packet belongs to
 57 |  * @property {boolean} payloadUnitStartIndicator Payload Unit Start Indicator (PUSI)
 58 |  * @property {number} adaptationFieldControl Adaptation Field Control (ATF)
 59 |  * @property {HlsTsPCR} pcr PCR value
 60 |  */
 61 | 
 62 | /**
 63 |  * @typedef {Object} HlsTsDataStream
 64 |  * @property {Uint8Array} data The audio and video data bytes
 65 |  * @property {number} size Amount of data bytes
 66 |  * @property {number} id Program ID
 67 |  * @property {HlsTsPesHeader[]} pes PES Headers for this data stream
 68 |  */
 69 | 
 70 | /**
 71 |  * @typedef {Object} HlsTsPCR
 72 |  * @property {number} base PCR base part
 73 |  * @property {number} value PCR value part
 74 |  */
 75 | 
 76 | /**
 77 |  * @typedef {Object} HlsTsPesHeader
 78 |  * @property {number} pts PTS value
 79 |  * @property {number} dts DTS value
 80 |  * @property {number} offset Byte offset in data stream where this PES header was found
 81 |  */
 82 | 
 83 | /**
 84 |  * @typedef {Object} HlsTsNalUnit
 85 |  * @property {Uint8Array} data The Nal payload
 86 |  * @property {number} type Nal Unit type
 87 |  * @property {number} offset Byte offset in data stream where this Nal Unit was found
 88 |  * @property {HlsTsPesHeader} pes PES Header for this chunk of AVC data 
 89 |  */
 90 | 
 91 | /**
 92 |  * @typedef {Object} HlsTsNalUnitSPS
 93 |  * @property {number} profileIdc
 94 |  * @property {boolean[]} profileConstraintsFlags
 95 |  * @property {number} levelIdc
 96 |  * @property {?number} chromaFormatIdc
 97 |  * @property {?boolean} seperateColourPlaneFlag 
 98 |  * @property {?number} bitDepthLuma
 99 |  * @property {?number} bitDepthChroma
100 |  * @property {?boolean} qpPrimeYZeroTransformBypassFlag
101 |  * @property {?boolean} seqScalingMatrixPresentFlag
102 |  * @property {?number} log2MaxFrameNum
103 |  * @property {?number} picOrderCntType
104 |  * @property {?number} log2MaxPicOrderCntLsb
105 |  * @property {?boolean} deltaPicOrderAlwaysZeroFlag
106 |  * @property {?number} offsetForNonRefPic
107 |  * @property {?number} offsetForTopToBottomField
108 |  * @property {?number} numRefFrameInPicOrderCntCycle
109 |  * @property {?number[]} offsetForRefFrame
110 |  * @property {number} maxNumRefFrames
111 |  * @property {boolean} gapsInFrameNumValueAllowedFlag
112 |  * @property {number} picWidthInMbs
113 |  * @property {number} picWidthInSamples
114 |  * @property {number} picHeightInMapUnits
115 |  * @property {number} picSizeInMapUnits
116 |  */
117 | 
118 | window.HlsTs = require("./lib/browser.js");
119 |
120 |
121 | 122 | 123 | 124 | 125 |
126 | 127 |
128 | 129 | 132 | 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Home - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 |

Build Status 51 | Coverage Status

52 |

A Javascript library to parse Apple HLS MPEG Transport Stream segments

53 |

Usage (Node JS)

npm install --save hls-ts

The library implements the Writable stream interface and acts a a "sink". For example to download 54 | and parse an HLS MPEG Transport Stream segment:

55 |
const request = require("request");
 56 | const hlsTs = require("hls-ts");
 57 | 
 58 | request.get("http://example.com/seg10.ts")
 59 | .pipe(hlsTs.parse())
 60 | .on("finish", function() {
 61 | 
 62 |   // Obtain all programs found in the Transport Stream
 63 |   const programs = hlsTs.programs;
 64 | 
 65 |   // Obtain all packets for a specific program stream
 66 |   const avcPackets = hlsTs.getPacketsByProgramType("avc");
 67 | 
 68 |   // Obtain the payload for a program stream
 69 |   const avcPayload = hlsTs.getDataStreamByProgramType("avc");
 70 | 
 71 |   // where avcPayload.data is a Uint8Array
 72 |   const avcParser = hlsTs.createAvcParser(avcPayload);
 73 | 
 74 |   // Obtain NAL units
 75 |   const nalUnits = avcParser.getNalUnits();
 76 | });

Usage (Browser version)

<script src="dist/hls-ts.min.js"></script>
 77 | <script>
 78 |   var xhr = new XMLHttpRequest();
 79 |   var url = "http://example.com/hls/seg-10s.ts";
 80 |   var parser = new window.HlsTs({ debug: false });
 81 |   xhr.responseType = "arraybuffer";
 82 |   xhr.onloadend = function() {
 83 |     var buffer = xhr.response;
 84 |     var data = new Uint8Array(buffer);
 85 |     parser.parse(data).then(function() {
 86 |       // Obtain all programs found in the Transport Stream
 87 |       var programs = parser.getPrograms();
 88 | 
 89 |       // Obtain all packets for a specific program stream
 90 |       var avcPackets = parser.getPacketsByProgramType("avc");
 91 | 
 92 |       // Obtain the payload for a program stream
 93 |       var avcPayload = parser.getDataStreamByProgramType("avc");
 94 | 
 95 |       // where avcPayload.data is a Uint8Array
 96 |       var avcParser = parser.createAvcParser(avcPayload);
 97 | 
 98 |       // Obtain NAL units
 99 |       var nalUnits = avcParser.getNalUnits();
100 |     }).catch(function(err) { console.error(err.message); }).then(done);
101 |   };
102 |   xhr.open("GET", url);
103 |   xhr.send();
104 | </script>

API Documentation

Find API documentation here: https://inspect.eyevinn.technology/docs/index.html

105 |

Contributing

All contributions are welcome but before you submit a Pull Request make sure you follow the same 106 | code conventions and that you have written unit tests

107 |
108 | 109 | 110 | 111 | 112 | 113 | 114 |
115 | 116 |
117 | 118 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /docs/lib_pes_pes_avc_parser.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | lib/pes/pes_avc_parser.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

lib/pes/pes_avc_parser.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
// Copyright 2017 Eyevinn Technology. All rights reserved
 42 | // Use of this source code is governed by a MIT License
 43 | // license that can be found in the LICENSE file.
 44 | // Author: Jonas Birme (Eyevinn Technology)
 45 | 
 46 | const PESParser = require("./pes_parser.js");
 47 | const NalUParser = require("./nalu_parser.js");
 48 | const log = require("logplease").create("PESAVCParser", { useColors: false });
 49 | const util = require("../util.js");
 50 | 
 51 | const NAL_START_PREFIX = 0x01;
 52 | const BYTE_STATE = {
 53 |   "0-7": 0,
 54 |   "8-15": 1,
 55 |   "16-23": 2,
 56 |   "24-31": 3,
 57 | };
 58 | 
 59 | const NALUnit = function constructor() {
 60 |   return {
 61 |     data: undefined,
 62 |     type: undefined,
 63 |     offset: -1,
 64 |     pes: undefined,
 65 |   };
 66 | }
 67 | 
 68 | /**
 69 |  * @class
 70 |  * @extends PESParser
 71 |  */
 72 | class PESAVCParser extends PESParser {
 73 |   /**
 74 |    * @constructor
 75 |    * @param {HlsTsDataStream} pes Data stream to parse
 76 |    */
 77 |   constructor(pes) {
 78 |     super(pes);
 79 |   }
 80 | 
 81 |   /**
 82 |    * Translates a Nal Unit type value to a readable string
 83 |    * 
 84 |    * @param {number} type Nal Unit Type
 85 |    * @return {string}
 86 |    */
 87 |   nalUnitType(type) {
 88 |     return NalUParser.nalUnitTypeToString(type);
 89 |   }
 90 | 
 91 |   /**
 92 |    * Translates a Nal Unit type value to a Nal Unit category
 93 |    * 
 94 |    * @param {number} type Nal Unit Type
 95 |    * @return {string} 
 96 |    */
 97 |   nalUnitCategory(type) {
 98 |     return NalUParser.nalUnitTypeToCategory(type);
 99 |   }
100 | 
101 |   /**
102 |    * Get the RBSP (Raw Byte Sequence Payload) from a Nal Unit
103 |    * 
104 |    * @param {HlsTsNalUnit} nalUnit
105 |    * @return {Uint8Array}
106 |    */
107 |   rbspFromNalUnit(nalUnit) {
108 |     return new NalUParser(nalUnit).rbsp();
109 |   }
110 | 
111 |   /**
112 |    * Get the SPS (Sequence Paramater Set) from a Nal Unit. Returns null
113 |    * if Nal Unit type is not SPS in
114 |    *  
115 |    * @param {HlsTsNalUnit} nalUnit
116 |    * @return {HlsTsNalUnitSPS}
117 |    */
118 |   spsFromNalUnit(nalUnit) {
119 |     return new NalUParser(nalUnit).sps();
120 |   }
121 | 
122 |   /**
123 |    * Get all Nal Units in this data stream
124 |    * 
125 |    * @return {HlsTsNalUnit[]}
126 |    */
127 |   getNalUnits() {
128 |     const data = this.getData();
129 |     const len = data.byteLength;
130 |     let state = BYTE_STATE["0-7"];
131 |     let pos = 0;
132 |     let units = [];
133 |     let unitType;
134 |     let unitStartPos = -1;
135 | 
136 |     //log.debug(util.hexDump(data));
137 | 
138 |     let byte;
139 |     while (pos < len) {
140 |       byte = data[pos++];
141 |       //log.debug(`pos=${pos}, byte:`, util.toHex(byte));
142 |       if (state === BYTE_STATE["0-7"]) {
143 |         state = byte ? BYTE_STATE["0-7"] : BYTE_STATE["8-15"];
144 |         continue;
145 |       }
146 |       if (state === BYTE_STATE["8-15"]) {
147 |         state = byte ? BYTE_STATE["0-7"] : BYTE_STATE["16-23"];
148 |         continue;
149 |       }
150 |       if (state === BYTE_STATE["16-23"] || state === BYTE_STATE["24-31"]) {
151 |         if (byte === 0) {
152 |           state = BYTE_STATE["24-31"];
153 |         } else if (byte === NAL_START_PREFIX) {
154 |           //log.debug(`Start Prefix at ${pos} unitStartPos=${unitStartPos}`);
155 |           if (unitStartPos >= 0) {
156 |             const unit = new NALUnit();
157 |             unit.data = data.subarray(unitStartPos, pos - state - 1);
158 |             unit.type = unitType;
159 |             unit.offset = unitStartPos - state - 1;
160 |             unit.pes = this.getHeaderForByteOffset(unit.offset);
161 |             units.push(unit);
162 |             log.debug(`NAL Type:${this.nalUnitType(unitType)} (${unitStartPos})`);
163 |           }
164 |           unitType = data[pos] & 0x1f;
165 |           unitStartPos = pos;
166 |         } else {
167 |           state = BYTE_STATE["0-7"];
168 |         }
169 |       }
170 |     }
171 |     if (unitStartPos >= 0) {
172 |       const unit = new NALUnit();
173 |       unit.data = data.subarray(unitStartPos, pos - state);
174 |       unit.type = unitType;
175 |       unit.offset = unitStartPos - state;
176 |       unit.pes = this.getHeaderForByteOffset(unit.offset);
177 |       units.push(unit);
178 |     }
179 |     return units;
180 |   }
181 | }
182 | 
183 | module.exports = PESAVCParser;
184 | 
185 |
186 |
187 | 188 | 189 | 190 | 191 |
192 | 193 |
194 | 195 | 198 | 199 | 200 | 201 | 202 | 203 | -------------------------------------------------------------------------------- /docs/lib_pes_pes_aac_parser.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | lib/pes/pes_aac_parser.js - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

lib/pes/pes_aac_parser.js

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 |
41 |
// Copyright 2018 Eyevinn Technology. All rights reserved
 42 | // Use of this source code is governed by a MIT License
 43 | // license that can be found in the LICENSE file.
 44 | // Author: Jonas Birme (Eyevinn Technology)
 45 | 
 46 | const PESParser = require("./pes_parser.js");
 47 | const log = require("logplease").create("PESAACParser", { useColors: false });
 48 | const util = require("../util.js");
 49 | 
 50 | const SAMPLING_RATES = {
 51 |   0: 96000,  // `0000` - 96000 Hz
 52 |   1: 88200,  // `0001` - 88200 Hz
 53 |   2: 64000,  // `0010` - 64000 Hz
 54 |   3: 48000,  // `0011` - 48000 Hz
 55 |   4: 44100,  // `0100` - 44100 Hz
 56 |   5: 32000,  // `0101` - 32000 Hz
 57 |   6: 24000,  // `0110` - 24000 Hz
 58 |   7: 22050,  // `0111` - 22050 Hz
 59 |   8: 16000,  // `1000` - 16000 Hz
 60 |   9: 12000,  // `1001` - 12000 Hz
 61 |  10: 11025,  // `1010` - 11025 Hz
 62 |  11:  8000,  // `1011` - 8000 Hz
 63 |  12:  7350,  // `1100` - 7350 Hz
 64 |  13:     0,  // `1101` - Reserved
 65 |  14:     0,  // `1110` - Reserved
 66 |  15:     0,  // `1111` - other
 67 | };
 68 | 
 69 | const CHANNELS = {
 70 |   0: 0.0,
 71 |   1: 1.0,    //   1 ch - (Front:       center)
 72 |   2: 2.0,    //   2 ch - (Front: left,         right)
 73 |   3: 3.0,    //   3 ch - (Front: left, center, right)
 74 |   4: 4.0,    //   4 ch - (Front: left, center, right)                   (Rear:       center)
 75 |   5: 5.0,    //   5 ch - (Front: left, center, right)                   (Rear: left,        right)
 76 |   6: 5.1,    // 5.1 ch - (Front: left, center, right)                   (Rear: left,        right, subwoofer)
 77 |   7: 7.1,    // 7.1 ch - (Front: left, center, right)(Side: left, right)(Rear: left,        right, subwoofer)
 78 | };
 79 | 
 80 | /**
 81 |  * @class
 82 |  * @extends PESParser
 83 |  */
 84 | class PESAACParser extends PESParser {
 85 |   constructor(pes) {
 86 |     super(pes);
 87 |   }
 88 | 
 89 |   /**
 90 |    * Get all ADTS Frames in this data stream
 91 |    * 
 92 |    * @return {AdtsFrame[]}
 93 |    */
 94 |   getAdtsFrames() {
 95 |     const data = this.getData();
 96 |     const len = data.byteLength;
 97 |     let pos = 0;
 98 |     let adtsFrames = [];
 99 | 
100 |     //log.debug(util.hexDump(data));
101 | 
102 |     let byte0, byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8;
103 |     while (pos < len) {
104 |       let frameStart = pos;
105 |       byte0 = data[pos];
106 |       byte1 = data[pos + 1];      
107 |       byte2 = data[pos + 2];      
108 |       byte3 = data[pos + 3];      
109 |       byte4 = data[pos + 4];      
110 |       byte5 = data[pos + 5];      
111 |       byte6 = data[pos + 6];      
112 |       byte7 = data[pos + 7];      
113 |       byte8 = data[pos + 8];      
114 |       //log.debug(`pos=${pos}, byte:`, util.toHex(byte));
115 | 
116 |       let syncword = (byte0 === 0xFF) && ((byte1 & 0xF0) === 0xF0);   // 1111 1111 1111
117 |       let mpegVersion = (byte1 & 0x08) === 1 ? 2 : 4;                 // 0 == MPEG4, 1 == MPEG2
118 |       let layer = (byte1 & 0x06) === 0 ? true : false;
119 |       let crcProtection = (byte1 & 0x01) === 0 ? true : false;        // 0 == HAS CRC, 1 == NO CRC
120 |       let audioObjectType = ((byte2 & 0xC0) >> 6) + 1;                // 2 == AAC-LC, 5 == HE-AAC, 29 == HE-AAC v2
121 |       let samplingRate = SAMPLING_RATES[(byte2 & 0x3C) >> 2];         // 0100 == 44100
122 |       let channels = CHANNELS[((byte2 & 0x01) << 2 | byte3 & 0xC0) >> 6];  // 2 == LEFT+RIGHT
123 | 
124 |       let adtsFrameLength = (byte3 & 0x03) << 11 | byte4 << 3 | (byte5 & 0xE0) >> 5; // adtsHeaderLength + crcLength + (rawDataBlockEnd - rawDataBlockStart)
125 |       let bufferFullness  = (byte5 & 0x1f) << 6  | byte6 >> 2;
126 |       let rdbsInFrame = (byte6 & 0x03);
127 |       let adtsHeaderLength = 7;
128 |       let crcLength  = crcProtection ? 2 : 0;
129 |       let rawDataBlockStart = pos + adtsHeaderLength;
130 |       let rawDataBlockEnd = pos + adtsFrameLength;
131 |       let crc1 = crcProtection ? (((byte7 << 8) | byte8) >>> 0) : 0;
132 |       let crc2 = crc1;
133 |       let error = false;
134 | 
135 |       if (!syncword || !layer || audioObjectType !== 2) {
136 |         error = true;
137 |       }
138 |       //log.debug(`${pos}: syncword=${syncword}, layer=${layer}, audioObjectType=${audioObjectType}, error=${error}`);
139 | 
140 |       if (error) {
141 |         pos++; // skip unknown byte
142 |       } else {
143 |         let pes = this.getHeaderForByteOffset(pos);
144 |         pos += adtsFrameLength;
145 | 
146 |         adtsFrames.push({
147 |           pes: pes,
148 |           frameStart: frameStart,
149 |           frameEnd: rawDataBlockEnd,
150 |           mpegVersion: mpegVersion,
151 |           crcProtection: crcProtection,
152 |           audioObjectType: audioObjectType,
153 |           samplingRate: samplingRate,
154 |           channels: channels,
155 |           adtsFrameLength: adtsFrameLength,
156 |           adtsHeaderLength: adtsHeaderLength,
157 |           crcLength: crcLength,
158 |           rawDataBlockStart: rawDataBlockStart,
159 |           rawDataBlockEnd: rawDataBlockEnd,
160 |           bufferFullness: bufferFullness,
161 |           rdbsInFrame: rdbsInFrame,
162 |           error: error,
163 |           data: data.subarray(rawDataBlockStart, rawDataBlockEnd)
164 |         });
165 |       }
166 | 
167 |     }
168 |     return adtsFrames;
169 |   }
170 | 
171 |   audioType(type) {
172 |     const mapping = {
173 |       2: 'AAC-LC',
174 |       5: 'HE-AAC',
175 |       29: 'HE-AACv2'
176 |     };
177 |     return mapping[type];
178 |   }
179 | }
180 | 
181 | module.exports = PESAACParser;
182 |
183 |
184 | 185 | 186 | 187 | 188 |
189 | 190 |
191 | 192 | 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /test/lib/pes/pes_parser_unit.js: -------------------------------------------------------------------------------- 1 | // Copyright 2017 Eyevinn Technology. All rights reserved 2 | // Use of this source code is governed by a MIT License 3 | // license that can be found in the LICENSE file. 4 | // Author: Jonas Birme (Eyevinn Technology) 5 | 6 | const request = require("request"); 7 | const Logger = require("logplease"); 8 | const hlsTs = require("../../../index.js"); 9 | const PESParser = require("../../../lib/pes/pes_parser.js"); 10 | const PESAVCParser = require("../../../lib/pes/pes_avc_parser.js"); 11 | const PESAACParser = require("../../../lib/pes/pes_aac_parser.js"); 12 | const ExpGolomb = require("../../../lib/pes/exp_golomb.js"); 13 | const util = require("../../../lib/util.js"); 14 | 15 | jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000; 16 | 17 | const mockNalU = "" + 18 | "00 00 00 01 67 64 00 0A AC 72 84 44 26 84 00 00" + 19 | "03 00 04 00 00 03 00 CA 3C 48 96 11 80 00 00 00" + 20 | "01 68 E8 43 8F 13 21 30 00 00 01 65 88 81 00 05" + 21 | "4E 7F 87 DF 61 A5 8B 95 EE A4 E9 38 B7 6A 30 6A" + 22 | "71 B9 55 60 0B 76 2E B5 0E E4 80 59 27 B8 67 A9" + 23 | "63 37 5E 82 20 55 FB E4 6A E9 37 35 72 E2 22 91" + 24 | "9E 4D FF 60 86 CE 7E 42 B7 95 CE 2A E1 26 BE 87" + 25 | "73 84 26 BA 16 36 F4 E6 9F 17 DA D8 64 75 54 B1" + 26 | "F3 45 0C 0B 3C 74 B3 9D BC EB 53 73 87 C3 0E 62" + 27 | "47 48 62 CA 59 EB 86 3F 3A FA 86 B5 BF A8 6D 06" + 28 | "16 50 82 C4 CE 62 9E 4E E6 4C C7 30 3E DE A1 0B" + 29 | "D8 83 0B B6 B8 28 BC A9 EB 77 43 FC 7A 17 94 85" + 30 | "21 CA 37 6B 30 95 B5 46 77 30 60 B7 12 D6 8C C5" + 31 | "54 85 29 D8 69 A9 6F 12 4E 71 DF E3 E2 B1 6B 6B" + 32 | "BF 9F FB 2E 57 30 A9 69 76 C4 46 A2 DF FA 91 D9" + 33 | "50 74 55 1D 49 04 5A 1C D6 86 68 7C B6 61 48 6C" + 34 | "96 E6 12 4C 27 AD BA C7 51 99 8E D0 F0 ED 8E F6" + 35 | "65 79 79 A6 12 A1 95 DB C8 AE E3 B6 35 E6 8D BC" + 36 | "48 A3 7F AF 4A 28 8A 53 E2 7E 68 08 9F 67 77 98" + 37 | "52 DB 50 84 D6 5E 25 E1 4A 99 58 34 C7 11 D6 43" + 38 | "FF C4 FD 9A 44 16 D1 B2 FB 02 DB A1 89 69 34 C2" + 39 | "32 55 98 F9 9B B2 31 3F 49 59 0C 06 8C DB A5 B2" + 40 | "9D 7E 12 2F D0 87 94 44 E4 0A 76 EF 99 2D 91 18" + 41 | "39 50 3B 29 3B F5 2C 97 73 48 91 83 B0 A6 F3 4B" + 42 | "70 2F 1C 8F 3B 78 23 C6 AA 86 46 43 1D D7 2A 23" + 43 | "5E 2C D9 48 0A F5 F5 2C D1 FB 3F F0 4B 78 37 E9" + 44 | "45 DD 72 CF 80 35 C3 95 07 F3 D9 06 E5 4A 58 76" + 45 | "03 6C 81 20 62 45 65 44 73 BC FE C1 9F 31 E5 DB" + 46 | "89 5C 6B 79 D8 68 90 D7 26 A8 A1 88 86 81 DC 9A" + 47 | "4F 40 A5 23 C7 DE BE 6F 76 AB 79 16 51 21 67 83" + 48 | "2E F3 D6 27 1A 42 C2 94 D1 5D 6C DB 4A 7A E2 CB" + 49 | "0B B0 68 0B BE 19 59 00 50 FC C0 BD 9D F5 F5 F8" + 50 | "A8 17 19 D6 B3 E9 74 BA 50 E5 2C 45 7B F9 93 EA" + 51 | "5A F9 A9 30 B1 6F 5B 36 24 1E 8D 55 57 F4 CC 67" + 52 | "B2 65 6A A9 36 26 D0 06 B8 E2 E3 73 8B D1 C0 1C" + 53 | "52 15 CA B5 AC 60 3E 36 42 F1 2C BD 99 77 AB A8" + 54 | "A9 A4 8E 9C 8B 84 DE 73 F0 91 29 97 AE DB AF D6" + 55 | "F8 5E 9B 86 B3 B3 03 B3 AC 75 6F A6 11 69 2F 3D" + 56 | "3A CE FA 53 86 60 95 6C BB C5 4E F3"; 57 | 58 | describe("PES Parser", () => { 59 | describe("AVC", () => { 60 | it("can correctly translate NALU types", () => { 61 | const pesAvcParser = new PESAVCParser({}); 62 | expect(pesAvcParser.nalUnitType(5)).toBe("Coded slice of an IDR picture"); 63 | expect(pesAvcParser.nalUnitCategory(5)).toBe("VCL"); 64 | expect(pesAvcParser.nalUnitCategory(6)).toBe("non-VCL"); 65 | }); 66 | it("can parse NAL units", () => { 67 | const mockPayload = hexToBytes(mockNalU); 68 | const pesAvcParser = new PESAVCParser({ data: mockPayload, pes: [] }); 69 | const nalUnits = pesAvcParser.getNalUnits(); 70 | expect(nalUnits.length).toBe(3); 71 | expect(nalUnits[0].type).toBe(7); 72 | expect(nalUnits[1].type).toBe(8); 73 | expect(nalUnits[2].type).toBe(5); 74 | }); 75 | it("can get the rbsp from a NAL unit", () => { 76 | const mockPayload = hexToBytes(mockNalU); 77 | const pesAvcParser = new PESAVCParser({ data: mockPayload, pes: [] }); 78 | const nalUnits = pesAvcParser.getNalUnits(); 79 | const rbsp = pesAvcParser.rbspFromNalUnit(nalUnits[0]); 80 | expect(rbsp[12]).toBe(0); 81 | expect(rbsp[13]).toBe(4); 82 | }); 83 | it("can parse SPS in a NAL unit", () => { 84 | const mockPayload = hexToBytes(mockNalU); 85 | const pesAvcParser = new PESAVCParser({ data: mockPayload, pes: [] }); 86 | const nalUnits = pesAvcParser.getNalUnits(); 87 | const sps = pesAvcParser.spsFromNalUnit(nalUnits[0]); 88 | expect(sps).toBeDefined(); 89 | expect(sps).toEqual({ 90 | profileIdc: 100, 91 | profileConstraintsFlags: [false, false, false, false, false, false], 92 | levelIdc: 10, 93 | chromaFormatIdc: 1, 94 | bitDepthLuma: 7, 95 | bitDepthChroma: 7, 96 | qpPrimeYZeroTransformBypassFlag: true, 97 | seqScalingMatrixPresentFlag: false, 98 | log2MaxFrameNum: 3, 99 | picOrderCntType: 6, 100 | maxNumRefFrames: 15, 101 | gapsInFrameNumValueAllowedFlag: true, 102 | picWidthInMbs: 0, 103 | picWidthInSamples: 0, 104 | picHeightInMapUnits: 8, 105 | picSizeInMapUnits: 0 106 | }); 107 | }); 108 | it("can parse payload", (done) => { 109 | const stream = request.get("http://localhost:9876/base/test/support/testassets/seg-10s.ts"); 110 | stream.pipe(hlsTs.parse({ debug: false })).on("finish", () => { 111 | const avcData = hlsTs.getDataStreamByProgramType("avc"); 112 | const pesAvcParser = new PESAVCParser(avcData); 113 | expect(pesAvcParser.getId()).toBe(224); 114 | const nalUnits = pesAvcParser.getNalUnits(); 115 | expect(nalUnits.length).toBe(1015); 116 | const nalUnitsCodedPictures = nalUnits.filter(nu => nu.type === 1 || nu.type === 5); 117 | const nalUnitsCodedPicturesWithPES = nalUnitsCodedPictures.filter(nu => nu.pes !== null); 118 | expect(nalUnitsCodedPicturesWithPES.length).toBe(nalUnitsCodedPictures.length); 119 | done(); 120 | }); 121 | }); 122 | it("can parse SPS data in a NAL Unit", (done) => { 123 | const stream = request.get("http://localhost:9876/base/test/support/testassets/seg-10s.ts"); 124 | stream.pipe(hlsTs.parse({ debug: false })).on("finish", () => { 125 | const avcData = hlsTs.getDataStreamByProgramType("avc"); 126 | const pesAvcParser = new PESAVCParser(avcData); 127 | const nalUnits = pesAvcParser.getNalUnits(); 128 | const nalSPS = nalUnits.filter(nu => nu.type === 7).map(nu => pesAvcParser.spsFromNalUnit(nu)); 129 | expect(nalSPS[0]).toEqual({ 130 | profileIdc: 66, 131 | profileConstraintsFlags: [ true, true, false, false, false, false ], 132 | levelIdc: 21, 133 | log2MaxFrameNum: 6, 134 | picOrderCntType: 2, 135 | maxNumRefFrames: 1, 136 | gapsInFrameNumValueAllowedFlag: true, 137 | picWidthInMbs: 64, 138 | picWidthInSamples: 1024, 139 | picHeightInMapUnits: 0, 140 | picSizeInMapUnits: 0 141 | }); 142 | done(); 143 | }); 144 | }); 145 | }); 146 | describe("AAC parser", () => { 147 | it("can parse payload", done => { 148 | const stream = request.get("http://localhost:9876/base/test/support/testassets/2000-00002.ts"); 149 | stream.pipe(hlsTs.parse({ debug: false })).on("finish", () => { 150 | const aacData = hlsTs.getDataStreamByProgramType("aac"); 151 | const pesAacParser = new PESAACParser(aacData); 152 | const adtsFrames = pesAacParser.getAdtsFrames(); 153 | const refFrame = { 154 | frameStart: adtsFrames[0].frameStart, 155 | frameEnd: adtsFrames[0].frameEnd, 156 | mpegVersion: adtsFrames[0].mpegVersion, 157 | crcProtection: adtsFrames[0].crcProtection, 158 | audioObjectType: adtsFrames[0].audioObjectType, 159 | samplingRate: adtsFrames[0].samplingRate, 160 | channels: adtsFrames[0].channels, 161 | adtsFrameLength: adtsFrames[0].adtsFrameLength, 162 | adtsHeaderLength: adtsFrames[0].adtsHeaderLength, 163 | crcLength: adtsFrames[0].crcLength, 164 | rawDataBlockStart: adtsFrames[0].rawDataBlockStart, 165 | rawDataBlockEnd: adtsFrames[0].rawDataBlockEnd, 166 | bufferFullness: adtsFrames[0].bufferFullness, 167 | rdbsInFrame: adtsFrames[0].rdbsInFrame, 168 | error: adtsFrames[0].error 169 | }; 170 | expect(refFrame).toEqual({ 171 | frameStart: 0, 172 | frameEnd: 297, 173 | mpegVersion: 4, 174 | crcProtection: false, 175 | audioObjectType: 2, 176 | samplingRate: 44100, 177 | channels: 2, 178 | adtsFrameLength: 297, 179 | adtsHeaderLength: 7, 180 | crcLength: 0, 181 | rawDataBlockStart: 7, 182 | rawDataBlockEnd: 297, 183 | bufferFullness: 118, 184 | rdbsInFrame: 0, 185 | error: false 186 | }); 187 | }); 188 | done(); 189 | }); 190 | }); 191 | describe("Exp-Golomb decoder", () => { 192 | it("can read 6 bits from a two bytes array", () => { 193 | const mockData = new Uint8Array(2); 194 | mockData[0] = 0x88; // 1000 1000 195 | mockData[1] = 0x44; // 0100 0100 196 | 197 | // Expect to have 1,0,0,0,1,0 198 | const egData = new ExpGolomb(mockData); 199 | const bits = egData.readBits(6); 200 | expect(bits).toEqual([1,0,0,0,1,0]); 201 | }); 202 | it("can read 4 bits from a two bytes array and then read 8 more", () => { 203 | const mockData = new Uint8Array(2); 204 | mockData[0] = 0x88; // 1000 1000 205 | mockData[1] = 0x44; // 0100 0100 206 | const egData = new ExpGolomb(mockData); 207 | const firstBits = egData.readBits(4); 208 | const secondBits = egData.readBits(8); 209 | expect(firstBits).toEqual([1,0,0,0]); 210 | expect(secondBits).toEqual([1,0,0,0,0,1,0,0]); 211 | }); 212 | it("can read 3 bits from a two bytes array and then read 7 more", () => { 213 | const mockData = new Uint8Array(2); 214 | mockData[0] = 0x88; // 1000 1000 215 | mockData[1] = 0x44; // 0100 0100 216 | const egData = new ExpGolomb(mockData); 217 | const firstBits = egData.readBits(3); 218 | const secondBits = egData.readBits(7); 219 | expect(firstBits).toEqual([1,0,0]); 220 | expect(secondBits).toEqual([0,1,0,0,0,0,1]); 221 | }); 222 | it("can skip leading zero bits and return the number of zeroes", () => { 223 | const mockData = new Uint8Array(2); 224 | mockData[0] = 0x00; // 0000 0000 225 | mockData[1] = 0x40; // 0100 0000 226 | const egData = new ExpGolomb(mockData); 227 | const numZeros = egData.skipLeadingZeros(); 228 | expect(numZeros).toBe(9); 229 | }); 230 | it("can return ue(v) value", () => { 231 | const mockData = new Uint8Array(1); 232 | mockData[0] = 0x14; // 0001 0100 233 | const egData = new ExpGolomb(mockData); 234 | const codeNum = egData.readUE(); 235 | expect(codeNum).toBe(9); 236 | }); 237 | it("can return se(v) value", () => { 238 | const mockData = new Uint8Array(1); 239 | mockData[0] = 0x38; // 0011 1000 240 | const egData = new ExpGolomb(mockData); 241 | const codeNumSE = egData.readSE(); 242 | expect(codeNumSE).toBe(-3); 243 | }); 244 | }); 245 | }); 246 | 247 | function hexToBytes(hex) { 248 | const hexString = hex.replace(/\s+/g, ""); 249 | let array = []; 250 | let i = 0; 251 | for (let c = 0; c < hexString.length; c += 2) { 252 | const b = parseInt(hexString.substr(c, 2), 16); 253 | array[i++] = b; 254 | } 255 | let bytes = new Uint8Array(array); 256 | return bytes; 257 | } 258 | 259 | function bytesToHex(bytes) { 260 | let hex = []; 261 | for (i = 0; i < bytes.length; i++) { 262 | hex.push((bytes[i] >>> 4).toString(16)); 263 | hex.push((bytes[i] & 0xF).toString(16)); 264 | } 265 | return hex.join(""); 266 | } 267 | -------------------------------------------------------------------------------- /docs/scripts/prettify/Apache-License-2.0.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /docs/styles/jsdoc-default.css: -------------------------------------------------------------------------------- 1 | @import url(http://fonts.googleapis.com/css?family=Montserrat:400,700); 2 | 3 | * { 4 | box-sizing: border-box 5 | } 6 | 7 | html, body { 8 | height: 100%; 9 | width: 100%; 10 | } 11 | 12 | body { 13 | color: #4d4e53; 14 | background-color: white; 15 | margin: 0 auto; 16 | padding: 0 20px; 17 | 18 | font-family: 'Helvetica Neue', Helvetica, sans-serif; 19 | font-size: 16px; 20 | line-height: 160%; 21 | } 22 | 23 | a, 24 | a:active { 25 | color: #0095dd; 26 | text-decoration: none; 27 | } 28 | 29 | a:hover { 30 | text-decoration: underline 31 | } 32 | 33 | p, ul, ol, blockquote { 34 | margin-bottom: 1em; 35 | } 36 | 37 | h1, h2, h3, h4, h5, h6 { 38 | font-family: 'Montserrat', sans-serif; 39 | } 40 | 41 | h1, h2, h3, h4, h5, h6 { 42 | color: #000; 43 | font-weight: 400; 44 | margin: 0; 45 | } 46 | 47 | h1 { 48 | font-weight: 300; 49 | font-size: 48px; 50 | margin: 1em 0 .5em; 51 | } 52 | 53 | h1.page-title { 54 | font-size: 48px; 55 | margin: 1em 30px; 56 | } 57 | 58 | h2 { 59 | font-size: 24px; 60 | margin: 1.5em 0 .3em; 61 | } 62 | 63 | h3 { 64 | font-size: 24px; 65 | margin: 1.2em 0 .3em; 66 | } 67 | 68 | h4 { 69 | font-size: 18px; 70 | margin: 1em 0 .2em; 71 | color: #4d4e53; 72 | } 73 | 74 | h5, .container-overview .subsection-title { 75 | font-size: 120%; 76 | letter-spacing: -0.01em; 77 | margin: 8px 0 3px 0; 78 | } 79 | 80 | h6 { 81 | font-size: 100%; 82 | letter-spacing: -0.01em; 83 | margin: 6px 0 3px 0; 84 | font-style: italic; 85 | } 86 | 87 | tt, code, kbd, samp { 88 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 89 | background: #f4f4f4; 90 | padding: 1px 5px; 91 | border-radius: 5px; 92 | } 93 | 94 | .class-description { 95 | font-size: 130%; 96 | line-height: 140%; 97 | margin-bottom: 1em; 98 | margin-top: 1em; 99 | } 100 | 101 | .class-description:empty { 102 | margin: 0 103 | } 104 | 105 | #main { 106 | float: right; 107 | min-width: 360px; 108 | width: calc(100% - 250px); 109 | } 110 | 111 | header { 112 | display: block 113 | } 114 | 115 | section { 116 | display: block; 117 | background-color: #fff; 118 | padding: 0 30px; 119 | } 120 | 121 | .variation { 122 | display: none 123 | } 124 | 125 | .signature-attributes { 126 | font-size: 60%; 127 | color: #aaa; 128 | font-style: italic; 129 | font-weight: lighter; 130 | } 131 | 132 | nav { 133 | float: left; 134 | display: block; 135 | width: 250px; 136 | background: #fff; 137 | overflow: auto; 138 | position: fixed; 139 | height: 100%; 140 | } 141 | 142 | nav h3 { 143 | margin-top: 12px; 144 | font-size: 13px; 145 | text-transform: uppercase; 146 | letter-spacing: 1px; 147 | font-weight: 700; 148 | line-height: 24px; 149 | margin: 15px 0 10px; 150 | padding: 0; 151 | color: #000; 152 | } 153 | 154 | nav ul { 155 | font-family: 'Lucida Grande', 'Lucida Sans Unicode', arial, sans-serif; 156 | font-size: 100%; 157 | line-height: 17px; 158 | padding: 0; 159 | margin: 0; 160 | list-style-type: none; 161 | } 162 | 163 | nav ul a, 164 | nav ul a:active { 165 | font-family: 'Montserrat', sans-serif; 166 | line-height: 18px; 167 | padding: 0; 168 | display: block; 169 | font-size: 12px; 170 | } 171 | 172 | nav ul a:hover, 173 | nav ul a:active { 174 | color: hsl(200, 100%, 43%); 175 | text-decoration: none; 176 | } 177 | 178 | nav > ul { 179 | padding: 0 10px; 180 | } 181 | 182 | nav > ul > li > a { 183 | color: #000; 184 | } 185 | 186 | nav ul ul { 187 | margin-bottom: 10px 188 | } 189 | 190 | nav ul ul a { 191 | color: hsl(207, 1%, 60%); 192 | border-left: 1px solid hsl(207, 10%, 86%); 193 | } 194 | 195 | nav ul ul a, 196 | nav ul ul a:active { 197 | padding-left: 20px 198 | } 199 | 200 | nav h2 { 201 | font-size: 12px; 202 | margin: 0; 203 | padding: 0; 204 | } 205 | 206 | nav > h2 > a { 207 | display: block; 208 | margin: 10px 0 -10px; 209 | color: hsl(202, 71%, 50%) !important; 210 | } 211 | 212 | footer { 213 | color: hsl(0, 0%, 28%); 214 | margin-left: 250px; 215 | display: block; 216 | padding: 15px; 217 | font-style: italic; 218 | font-size: 90%; 219 | } 220 | 221 | .ancestors { 222 | color: #999 223 | } 224 | 225 | .ancestors a { 226 | color: #999 !important; 227 | text-decoration: none; 228 | } 229 | 230 | .clear { 231 | clear: both 232 | } 233 | 234 | .important { 235 | font-weight: bold; 236 | color: #950B02; 237 | } 238 | 239 | .yes-def { 240 | text-indent: -1000px 241 | } 242 | 243 | .type-signature { 244 | color: #aaa 245 | } 246 | 247 | .name, .signature { 248 | font-family: Consolas, Monaco, 'Andale Mono', monospace 249 | } 250 | 251 | .details { 252 | margin-top: 14px; 253 | border-left: 2px solid #DDD; 254 | line-height: 30px; 255 | } 256 | 257 | .details dt { 258 | width: 120px; 259 | float: left; 260 | padding-left: 10px; 261 | } 262 | 263 | .details dd { 264 | margin-left: 70px 265 | } 266 | 267 | .details ul { 268 | margin: 0 269 | } 270 | 271 | .details ul { 272 | list-style-type: none 273 | } 274 | 275 | .details li { 276 | margin-left: 30px 277 | } 278 | 279 | .details pre.prettyprint { 280 | margin: 0 281 | } 282 | 283 | .details .object-value { 284 | padding-top: 0 285 | } 286 | 287 | .description { 288 | margin-bottom: 1em; 289 | margin-top: 1em; 290 | } 291 | 292 | .code-caption { 293 | font-style: italic; 294 | font-size: 107%; 295 | margin: 0; 296 | } 297 | 298 | .prettyprint { 299 | font-size: 13px; 300 | border: 1px solid #ddd; 301 | border-radius: 3px; 302 | box-shadow: 0 1px 3px hsla(0, 0%, 0%, 0.05); 303 | overflow: auto; 304 | } 305 | 306 | .prettyprint.source { 307 | width: inherit 308 | } 309 | 310 | .prettyprint code { 311 | font-size: 100%; 312 | line-height: 18px; 313 | display: block; 314 | margin: 0 30px; 315 | background-color: #fff; 316 | color: #4D4E53; 317 | } 318 | 319 | .prettyprint > code { 320 | padding: 15px 321 | } 322 | 323 | .prettyprint .linenums code { 324 | padding: 0 15px 325 | } 326 | 327 | .prettyprint .linenums li:first-of-type code { 328 | padding-top: 15px 329 | } 330 | 331 | .prettyprint code span.line { 332 | display: inline-block 333 | } 334 | 335 | .prettyprint.linenums { 336 | padding-left: 70px; 337 | -webkit-user-select: none; 338 | -moz-user-select: none; 339 | -ms-user-select: none; 340 | user-select: none; 341 | } 342 | 343 | .prettyprint.linenums ol { 344 | padding-left: 0 345 | } 346 | 347 | .prettyprint.linenums li { 348 | border-left: 3px #ddd solid 349 | } 350 | 351 | .prettyprint.linenums li.selected, .prettyprint.linenums li.selected * { 352 | background-color: lightyellow 353 | } 354 | 355 | .prettyprint.linenums li * { 356 | -webkit-user-select: text; 357 | -moz-user-select: text; 358 | -ms-user-select: text; 359 | user-select: text; 360 | } 361 | 362 | .params, .props { 363 | border-spacing: 0; 364 | border: 1px solid #ddd; 365 | border-collapse: collapse; 366 | border-radius: 3px; 367 | box-shadow: 0 1px 3px rgba(0,0,0,0.1); 368 | width: 100%; 369 | font-size: 14px; 370 | } 371 | 372 | .params .name, .props .name, .name code { 373 | color: #4D4E53; 374 | font-family: Consolas, Monaco, 'Andale Mono', monospace; 375 | font-size: 100%; 376 | } 377 | 378 | .params td, .params th, .props td, .props th { 379 | margin: 0px; 380 | text-align: left; 381 | vertical-align: top; 382 | padding: 10px; 383 | display: table-cell; 384 | } 385 | 386 | .params td { 387 | border-top: 1px solid #eee 388 | } 389 | 390 | .params thead tr, .props thead tr { 391 | background-color: #fff; 392 | font-weight: bold; 393 | } 394 | 395 | .params .params thead tr, .props .props thead tr { 396 | background-color: #fff; 397 | font-weight: bold; 398 | } 399 | 400 | .params td.description > p:first-child, .props td.description > p:first-child { 401 | margin-top: 0; 402 | padding-top: 0; 403 | } 404 | 405 | .params td.description > p:last-child, .props td.description > p:last-child { 406 | margin-bottom: 0; 407 | padding-bottom: 0; 408 | } 409 | 410 | dl.param-type { 411 | border-bottom: 1px solid hsl(0, 0%, 87%); 412 | margin-bottom: 30px; 413 | padding-bottom: 30px; 414 | } 415 | 416 | .param-type dt, .param-type dd { 417 | display: inline-block 418 | } 419 | 420 | .param-type dd { 421 | font-family: Consolas, Monaco, 'Andale Mono', monospace 422 | } 423 | 424 | .disabled { 425 | color: #454545 426 | } 427 | 428 | /* navicon button */ 429 | .navicon-button { 430 | display: none; 431 | position: relative; 432 | padding: 2.0625rem 1.5rem; 433 | transition: 0.25s; 434 | cursor: pointer; 435 | user-select: none; 436 | opacity: .8; 437 | } 438 | .navicon-button .navicon:before, .navicon-button .navicon:after { 439 | transition: 0.25s; 440 | } 441 | .navicon-button:hover { 442 | transition: 0.5s; 443 | opacity: 1; 444 | } 445 | .navicon-button:hover .navicon:before, .navicon-button:hover .navicon:after { 446 | transition: 0.25s; 447 | } 448 | .navicon-button:hover .navicon:before { 449 | top: .825rem; 450 | } 451 | .navicon-button:hover .navicon:after { 452 | top: -.825rem; 453 | } 454 | 455 | /* navicon */ 456 | .navicon { 457 | position: relative; 458 | width: 2.5em; 459 | height: .3125rem; 460 | background: #000; 461 | transition: 0.3s; 462 | border-radius: 2.5rem; 463 | } 464 | .navicon:before, .navicon:after { 465 | display: block; 466 | content: ""; 467 | height: .3125rem; 468 | width: 2.5rem; 469 | background: #000; 470 | position: absolute; 471 | z-index: -1; 472 | transition: 0.3s 0.25s; 473 | border-radius: 1rem; 474 | } 475 | .navicon:before { 476 | top: .625rem; 477 | } 478 | .navicon:after { 479 | top: -.625rem; 480 | } 481 | 482 | /* open */ 483 | .nav-trigger:checked + label:not(.steps) .navicon:before, 484 | .nav-trigger:checked + label:not(.steps) .navicon:after { 485 | top: 0 !important; 486 | } 487 | 488 | .nav-trigger:checked + label .navicon:before, 489 | .nav-trigger:checked + label .navicon:after { 490 | transition: 0.5s; 491 | } 492 | 493 | /* Minus */ 494 | .nav-trigger:checked + label { 495 | transform: scale(0.75); 496 | } 497 | 498 | /* × and + */ 499 | .nav-trigger:checked + label.plus .navicon, 500 | .nav-trigger:checked + label.x .navicon { 501 | background: transparent; 502 | } 503 | 504 | .nav-trigger:checked + label.plus .navicon:before, 505 | .nav-trigger:checked + label.x .navicon:before { 506 | transform: rotate(-45deg); 507 | background: #FFF; 508 | } 509 | 510 | .nav-trigger:checked + label.plus .navicon:after, 511 | .nav-trigger:checked + label.x .navicon:after { 512 | transform: rotate(45deg); 513 | background: #FFF; 514 | } 515 | 516 | .nav-trigger:checked + label.plus { 517 | transform: scale(0.75) rotate(45deg); 518 | } 519 | 520 | .nav-trigger:checked ~ nav { 521 | left: 0 !important; 522 | } 523 | 524 | .nav-trigger:checked ~ .overlay { 525 | display: block; 526 | } 527 | 528 | .nav-trigger { 529 | position: fixed; 530 | top: 0; 531 | clip: rect(0, 0, 0, 0); 532 | } 533 | 534 | .overlay { 535 | display: none; 536 | position: fixed; 537 | top: 0; 538 | bottom: 0; 539 | left: 0; 540 | right: 0; 541 | width: 100%; 542 | height: 100%; 543 | background: hsla(0, 0%, 0%, 0.5); 544 | z-index: 1; 545 | } 546 | 547 | @media only screen and (min-width: 320px) and (max-width: 680px) { 548 | body { 549 | overflow-x: hidden; 550 | } 551 | 552 | nav { 553 | background: #FFF; 554 | width: 250px; 555 | height: 100%; 556 | position: fixed; 557 | top: 0; 558 | right: 0; 559 | bottom: 0; 560 | left: -250px; 561 | z-index: 3; 562 | padding: 0 10px; 563 | transition: left 0.2s; 564 | } 565 | 566 | .navicon-button { 567 | display: inline-block; 568 | position: fixed; 569 | top: 1.5em; 570 | right: 0; 571 | z-index: 2; 572 | } 573 | 574 | #main { 575 | width: 100%; 576 | min-width: 360px; 577 | } 578 | 579 | #main h1.page-title { 580 | margin: 1em 0; 581 | } 582 | 583 | #main section { 584 | padding: 0; 585 | } 586 | 587 | footer { 588 | margin-left: 0; 589 | } 590 | } 591 | -------------------------------------------------------------------------------- /docs/scripts/prettify/prettify.js: -------------------------------------------------------------------------------- 1 | var q=null;window.PR_SHOULD_USE_CONTINUATION=!0; 2 | (function(){function L(a){function m(a){var f=a.charCodeAt(0);if(f!==92)return f;var b=a.charAt(1);return(f=r[b])?f:"0"<=b&&b<="7"?parseInt(a.substring(1),8):b==="u"||b==="x"?parseInt(a.substring(2),16):a.charCodeAt(1)}function e(a){if(a<32)return(a<16?"\\x0":"\\x")+a.toString(16);a=String.fromCharCode(a);if(a==="\\"||a==="-"||a==="["||a==="]")a="\\"+a;return a}function h(a){for(var f=a.substring(1,a.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),a= 3 | [],b=[],o=f[0]==="^",c=o?1:0,i=f.length;c122||(d<65||j>90||b.push([Math.max(65,j)|32,Math.min(d,90)|32]),d<97||j>122||b.push([Math.max(97,j)&-33,Math.min(d,122)&-33]))}}b.sort(function(a,f){return a[0]-f[0]||f[1]-a[1]});f=[];j=[NaN,NaN];for(c=0;ci[0]&&(i[1]+1>i[0]&&b.push("-"),b.push(e(i[1])));b.push("]");return b.join("")}function y(a){for(var f=a.source.match(/\[(?:[^\\\]]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),b=f.length,d=[],c=0,i=0;c=2&&a==="["?f[c]=h(j):a!=="\\"&&(f[c]=j.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return f.join("")}for(var t=0,s=!1,l=!1,p=0,d=a.length;p=5&&"lang-"===b.substring(0,5))&&!(o&&typeof o[1]==="string"))c=!1,b="src";c||(r[f]=b)}i=d;d+=f.length;if(c){c=o[1];var j=f.indexOf(c),k=j+c.length;o[2]&&(k=f.length-o[2].length,j=k-c.length);b=b.substring(5);B(l+i,f.substring(0,j),e,p);B(l+i+j,c,C(b,c),p);B(l+i+k,f.substring(k),e,p)}else p.push(l+i,b)}a.e=p}var h={},y;(function(){for(var e=a.concat(m), 9 | l=[],p={},d=0,g=e.length;d=0;)h[n.charAt(k)]=r;r=r[1];n=""+r;p.hasOwnProperty(n)||(l.push(r),p[n]=q)}l.push(/[\S\s]/);y=L(l)})();var t=m.length;return e}function u(a){var m=[],e=[];a.tripleQuotedStrings?m.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?m.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/, 10 | q,"'\"`"]):m.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&e.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var h=a.hashComments;h&&(a.cStyleComments?(h>1?m.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):m.push(["com",/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),e.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,q])):m.push(["com",/^#[^\n\r]*/, 11 | q,"#"]));a.cStyleComments&&(e.push(["com",/^\/\/[^\n\r]*/,q]),e.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));a.regexLiterals&&e.push(["lang-regex",/^(?:^^\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\(|\*|\*=|\+=|,|-=|->|\/|\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\^=|\^\^|\^\^=|{|\||\|=|\|\||\|\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\s*(\/(?=[^*/])(?:[^/[\\]|\\[\S\s]|\[(?:[^\\\]]|\\[\S\s])*(?:]|$))+\/)/]);(h=a.types)&&e.push(["typ",h]);a=(""+a.keywords).replace(/^ | $/g, 12 | "");a.length&&e.push(["kwd",RegExp("^(?:"+a.replace(/[\s,]+/g,"|")+")\\b"),q]);m.push(["pln",/^\s+/,q," \r\n\t\xa0"]);e.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,q],["pun",/^.[^\s\w"-$'./@\\`]*/,q]);return x(m,e)}function D(a,m){function e(a){switch(a.nodeType){case 1:if(k.test(a.className))break;if("BR"===a.nodeName)h(a), 13 | a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)e(a);break;case 3:case 4:if(p){var b=a.nodeValue,d=b.match(t);if(d){var c=b.substring(0,d.index);a.nodeValue=c;(b=b.substring(d.index+d[0].length))&&a.parentNode.insertBefore(s.createTextNode(b),a.nextSibling);h(a);c||a.parentNode.removeChild(a)}}}}function h(a){function b(a,d){var e=d?a.cloneNode(!1):a,f=a.parentNode;if(f){var f=b(f,1),g=a.nextSibling;f.appendChild(e);for(var h=g;h;h=g)g=h.nextSibling,f.appendChild(h)}return e} 14 | for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),e;(e=a.parentNode)&&e.nodeType===1;)a=e;d.push(a)}var k=/(?:^|\s)nocode(?:\s|$)/,t=/\r\n?|\n/,s=a.ownerDocument,l;a.currentStyle?l=a.currentStyle.whiteSpace:window.getComputedStyle&&(l=s.defaultView.getComputedStyle(a,q).getPropertyValue("white-space"));var p=l&&"pre"===l.substring(0,3);for(l=s.createElement("LI");a.firstChild;)l.appendChild(a.firstChild);for(var d=[l],g=0;g=0;){var h=m[e];A.hasOwnProperty(h)?window.console&&console.warn("cannot override language handler %s",h):A[h]=a}}function C(a,m){if(!a||!A.hasOwnProperty(a))a=/^\s*=o&&(h+=2);e>=c&&(a+=2)}}catch(w){"console"in window&&console.log(w&&w.stack?w.stack:w)}}var v=["break,continue,do,else,for,if,return,while"],w=[[v,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"], 18 | "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],F=[w,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],G=[w,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"], 19 | H=[G,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"],w=[w,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],I=[v,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"], 20 | J=[v,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],v=[v,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],K=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/,N=/\S/,O=u({keywords:[F,H,w,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END"+ 21 | I,J,v],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),A={};k(O,["default-code"]);k(x([],[["pln",/^[^]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]), 22 | ["default-markup","htm","html","mxml","xhtml","xml","xsl"]);k(x([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"]],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css", 23 | /^style\s*=\s*([^\s"'>]+)/i]]),["in.tag"]);k(x([],[["atv",/^[\S\s]+/]]),["uq.val"]);k(u({keywords:F,hashComments:!0,cStyleComments:!0,types:K}),["c","cc","cpp","cxx","cyc","m"]);k(u({keywords:"null,true,false"}),["json"]);k(u({keywords:H,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:K}),["cs"]);k(u({keywords:G,cStyleComments:!0}),["java"]);k(u({keywords:v,hashComments:!0,multiLineStrings:!0}),["bsh","csh","sh"]);k(u({keywords:I,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}), 24 | ["cv","py"]);k(u({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["perl","pl","pm"]);k(u({keywords:J,hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb"]);k(u({keywords:w,cStyleComments:!0,regexLiterals:!0}),["js"]);k(u({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes", 25 | hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);k(x([],[["str",/^[\S\s]+/]]),["regex"]);window.prettyPrintOne=function(a,m,e){var h=document.createElement("PRE");h.innerHTML=a;e&&D(h,e);E({g:m,i:e,h:h});return h.innerHTML};window.prettyPrint=function(a){function m(){for(var e=window.PR_SHOULD_USE_CONTINUATION?l.now()+250:Infinity;p=0){var k=k.match(g),f,b;if(b= 26 | !k){b=n;for(var o=void 0,c=b.firstChild;c;c=c.nextSibling)var i=c.nodeType,o=i===1?o?b:c:i===3?N.test(c.nodeValue)?b:o:o;b=(f=o===b?void 0:o)&&"CODE"===f.tagName}b&&(k=f.className.match(g));k&&(k=k[1]);b=!1;for(o=n.parentNode;o;o=o.parentNode)if((o.tagName==="pre"||o.tagName==="code"||o.tagName==="xmp")&&o.className&&o.className.indexOf("prettyprint")>=0){b=!0;break}b||((b=(b=n.className.match(/\blinenums\b(?::(\d+))?/))?b[1]&&b[1].length?+b[1]:!0:!1)&&D(n,b),d={g:k,h:n,i:b},E(d))}}p 2 | 3 | 4 | 5 | PESParser - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

PESParser

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 |
42 | 43 |

44 | PESParser 45 |

46 | 47 | 48 |
49 | 50 |
51 |
52 | 53 | 54 | 55 | 56 | 57 |

new PESParser(pes)

58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
Parameters:
72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 |
NameTypeDescription
pes 100 | 101 | 102 | HlsTsDataStream 103 | 104 | 105 | 106 | Data stream to parse
118 | 119 | 120 | 121 | 122 | 123 | 124 |
125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 |
Source:
152 |
155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 |
163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 |
181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 |

Methods

196 | 197 | 198 | 199 | 200 | 201 | 202 |

getData() → {Uint8Array}

203 | 204 | 205 | 206 | 207 | 208 |
209 | Get data stream as Uint8 byte array 210 |
211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 |
225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 |
Source:
252 |
255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 |
263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 |
Returns:
277 | 278 | 279 |
280 | Data stream 281 |
282 | 283 | 284 | 285 |
286 |
287 | Type 288 |
289 |
290 | 291 | Uint8Array 292 | 293 | 294 |
295 |
296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 |

getHeaderForByteOffset(offset) → {HlsTsPesHeader}

307 | 308 | 309 | 310 | 311 | 312 |
313 | Get a PES header at a specific position in the data stream 314 |
315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 |
Parameters:
325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 |
NameTypeDescription
offset 353 | 354 | 355 | number 356 | 357 | 358 | 359 | Position in the data stream
371 | 372 | 373 | 374 | 375 | 376 | 377 |
378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 |
Source:
405 |
408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 |
416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 |
Returns:
430 | 431 | 432 | 433 | 434 |
435 |
436 | Type 437 |
438 |
439 | 440 | HlsTsPesHeader 441 | 442 | 443 |
444 |
445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 |

getHeaders() → {Array.<HlsTsPesHeader>}

456 | 457 | 458 | 459 | 460 | 461 |
462 | Get PES headers in this data stream 463 |
464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 |
478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 |
Source:
505 |
508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 |
516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 |
Returns:
530 | 531 | 532 | 533 | 534 |
535 |
536 | Type 537 |
538 |
539 | 540 | Array.<HlsTsPesHeader> 541 | 542 | 543 |
544 |
545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 |

getId() → {number}

556 | 557 | 558 | 559 | 560 | 561 |
562 | Get program ID 563 |
564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 |
578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 |
Source:
605 |
608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 |
616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 |
Returns:
630 | 631 | 632 |
633 | Program ID 634 |
635 | 636 | 637 | 638 |
639 |
640 | Type 641 |
642 |
643 | 644 | number 645 | 646 | 647 |
648 |
649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 |
661 | 662 |
663 | 664 | 665 | 666 | 667 |
668 | 669 |
670 | 671 |
672 | Documentation generated by JSDoc 3.5.5 on Thu Apr 18 2019 09:49:52 GMT+0200 (CEST) using the Minami theme. 673 |
674 | 675 | 676 | 677 | 678 | -------------------------------------------------------------------------------- /docs/PESAACParser.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PESAACParser - Documentation 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 22 | 23 | 24 | 25 | 28 | 29 |
30 | 31 |

PESAACParser

32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
40 | 41 |
42 | 43 |

44 | PESAACParser 45 |

46 | 47 | 48 |
49 | 50 |
51 |
52 | 53 | 54 | 55 | 56 | 57 |

new PESAACParser()

58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 |
Source:
103 |
106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 |
114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 |
132 | 133 | 134 |

Extends

135 | 136 | 137 | 138 | 139 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 |

Methods

158 | 159 | 160 | 161 | 162 | 163 | 164 |

getAdtsFrames() → {Array.<AdtsFrame>}

165 | 166 | 167 | 168 | 169 | 170 |
171 | Get all ADTS Frames in this data stream 172 |
173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 |
187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 |
Source:
214 |
217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 |
225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 |
Returns:
239 | 240 | 241 | 242 | 243 |
244 |
245 | Type 246 |
247 |
248 | 249 | Array.<AdtsFrame> 250 | 251 | 252 |
253 |
254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 |

getData() → {Uint8Array}

265 | 266 | 267 | 268 | 269 | 270 |
271 | Get data stream as Uint8 byte array 272 |
273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 |
287 | 288 | 289 | 290 | 291 | 292 | 293 |
Inherited From:
294 |
297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 |
Source:
319 |
322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 |
330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 |
Returns:
344 | 345 | 346 |
347 | Data stream 348 |
349 | 350 | 351 | 352 |
353 |
354 | Type 355 |
356 |
357 | 358 | Uint8Array 359 | 360 | 361 |
362 |
363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 |

getHeaderForByteOffset(offset) → {HlsTsPesHeader}

374 | 375 | 376 | 377 | 378 | 379 |
380 | Get a PES header at a specific position in the data stream 381 |
382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 |
Parameters:
392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 |
NameTypeDescription
offset 420 | 421 | 422 | number 423 | 424 | 425 | 426 | Position in the data stream
438 | 439 | 440 | 441 | 442 | 443 | 444 |
445 | 446 | 447 | 448 | 449 | 450 | 451 |
Inherited From:
452 |
455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 |
Source:
477 |
480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 |
488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 |
Returns:
502 | 503 | 504 | 505 | 506 |
507 |
508 | Type 509 |
510 |
511 | 512 | HlsTsPesHeader 513 | 514 | 515 |
516 |
517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 |

getHeaders() → {Array.<HlsTsPesHeader>}

528 | 529 | 530 | 531 | 532 | 533 |
534 | Get PES headers in this data stream 535 |
536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 |
550 | 551 | 552 | 553 | 554 | 555 | 556 |
Inherited From:
557 |
560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 |
Source:
582 |
585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 |
593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 |
Returns:
607 | 608 | 609 | 610 | 611 |
612 |
613 | Type 614 |
615 |
616 | 617 | Array.<HlsTsPesHeader> 618 | 619 | 620 |
621 |
622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 |

getId() → {number}

633 | 634 | 635 | 636 | 637 | 638 |
639 | Get program ID 640 |
641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 |
655 | 656 | 657 | 658 | 659 | 660 | 661 |
Inherited From:
662 |
665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 |
Source:
687 |
690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 |
698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 |
Returns:
712 | 713 | 714 |
715 | Program ID 716 |
717 | 718 | 719 | 720 |
721 |
722 | Type 723 |
724 |
725 | 726 | number 727 | 728 | 729 |
730 |
731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 |
743 | 744 |
745 | 746 | 747 | 748 | 749 |
750 | 751 |
752 | 753 |
754 | Documentation generated by JSDoc 3.5.5 on Thu Apr 18 2019 09:49:52 GMT+0200 (CEST) using the Minami theme. 755 |
756 | 757 | 758 | 759 | 760 | --------------------------------------------------------------------------------