-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
94 lines (90 loc) · 2.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
const Logger = require("logplease");
const ParseStream = require("./lib/parse_stream.js");
const AVCParser = require("./lib/pes/pes_avc_parser.js");
const AACParser = require("./lib/pes/pes_aac_parser.js");
/**
* @module HlsTs
*/
const HlsTS = {
streamParser: undefined,
/**
* Parse HLS TS when reading from a Stream
*
* @function parse
* @example
* fs.createReadStream("./seg-10s.ts")
* .pipe(hlsTs.parse({ debug: true }))
* .on("finish", function() {
* const avcPayload = hlsTs.getDataStreamByProgramType("avc");
* });
* @param {?HlsTsOptions} opts
* @return {ParseStream}
*/
parse: function(opts) {
if (opts && opts.debug) {
Logger.setLogLevel("DEBUG");
} else {
Logger.setLogLevel("INFO");
}
this.streamParser = new ParseStream(opts);
return this.streamParser;
},
/**
* Get the parsed program types
*
* @member {HlsTsProgramType[]} programs
*/
get programs() {
if (!this.streamParser) {
throw new Error("Nothing parsed yet");
}
return this.streamParser.getPrograms().getTypes();
},
/**
* Get all packets for a specific program type
*
* @function getPacketsByProgramType
* @param {string} type
* @return {HlsTsPacket[]}
*/
getPacketsByProgramType(type) {
if (!this.streamParser) {
throw new Error("Nothing parsed yet");
}
return this.streamParser.getPrograms().getPackets(type);
},
/**
* Get the data stream for a program type
*
* @function getDataStreamByProgramType
* @param {string} type
* @return {HlsTsDataStream}
*/
getDataStreamByProgramType(type) {
if (!this.streamParser) {
throw new Error("Nothing parsed yet");
}
return this.streamParser.getPrograms().getDataStream(type);
},
/**
* Create an AVC Parser that can parse an AVC data stream
*
* @function createAvcParser
* @param {HlsDataStream} dataStream
* @return {AVCParser}
*/
createAvcParser(dataStream) {
return new AVCParser(dataStream);
},
/**
* Create an AAC Parser that can parse an AAC data stream
*
* @function createAacParser
* @param {HlsDataStream} dataStream
* @return {AACParser}
*/
createAacParser(dataStream) {
return new AACParser(dataStream);
}
};
module.exports = HlsTS;