forked from video-dev/hls.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demuxer-inline.js
52 lines (46 loc) · 1.63 KB
/
demuxer-inline.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
/* inline demuxer.
* probe fragments and instantiate appropriate demuxer depending on content type (TSDemuxer, AACDemuxer, ...)
*/
import Event from '../events';
import {ErrorTypes, ErrorDetails} from '../errors';
import AACDemuxer from '../demux/aacdemuxer';
import TSDemuxer from '../demux/tsdemuxer';
import MP4Remuxer from '../remux/mp4-remuxer';
import PassThroughRemuxer from '../remux/passthrough-remuxer';
class DemuxerInline {
constructor(hls,id, typeSupported, config=null) {
this.hls = hls;
this.id = id;
this.config = this.hls.config || config;
this.typeSupported = typeSupported;
}
destroy() {
var demuxer = this.demuxer;
if (demuxer) {
demuxer.destroy();
}
}
push(data, audioCodec, videoCodec, timeOffset, cc, level, sn, duration) {
var demuxer = this.demuxer;
if (!demuxer) {
let hls = this.hls,
id = this.id;
// probe for content type
if (TSDemuxer.probe(data)) {
if (this.typeSupported.mp2t === true) {
demuxer = new TSDemuxer(hls, id, PassThroughRemuxer, this.config);
} else {
demuxer = new TSDemuxer(hls, id, MP4Remuxer, this.config);
}
} else if(AACDemuxer.probe(data)) {
demuxer = new AACDemuxer(hls, id, MP4Remuxer, this.config);
} else {
hls.trigger(Event.ERROR, {type : ErrorTypes.MEDIA_ERROR, id : id, details: ErrorDetails.FRAG_PARSING_ERROR, fatal: true, reason: 'no demux matching with content found'});
return;
}
this.demuxer = demuxer;
}
demuxer.push(data,audioCodec,videoCodec,timeOffset,cc,level,sn,duration);
}
}
export default DemuxerInline;