update components

This commit is contained in:
Luke Pulverenti 2016-02-01 12:02:17 -05:00
parent 2a72f0256e
commit 048ba20590
26 changed files with 1377 additions and 136 deletions

View file

@ -32,7 +32,7 @@ class MP4Remuxer {
this.ISGenerated = false;
}
remux(audioTrack,videoTrack,id3Track,timeOffset, contiguous) {
remux(audioTrack,videoTrack,id3Track,textTrack,timeOffset, contiguous) {
// generate Init Segment if needed
if (!this.ISGenerated) {
this.generateIS(audioTrack,videoTrack,timeOffset);
@ -49,6 +49,10 @@ class MP4Remuxer {
if (id3Track.samples.length) {
this.remuxID3(id3Track,timeOffset);
}
//logger.log('nb ID3 samples:' + audioTrack.samples.length);
if (textTrack.samples.length) {
this.remuxText(textTrack,timeOffset);
}
//notify end of parsing
this.observer.trigger(Event.FRAG_PARSED);
}
@ -264,6 +268,7 @@ class MP4Remuxer {
pts = aacSample.pts;
} else {
logger.warn('dropping past audio frame');
track.len -= aacSample.unit.byteLength;
}
});
@ -309,12 +314,17 @@ class MP4Remuxer {
// remember first PTS of our aacSamples, ensure value is positive
firstPTS = Math.max(0, ptsnorm);
firstDTS = Math.max(0, dtsnorm);
/* concatenate the audio data and construct the mdat in place
(need 8 more bytes to fill length and mdat type) */
mdat = new Uint8Array(track.len + 8);
view = new DataView(mdat.buffer);
view.setUint32(0, mdat.byteLength);
mdat.set(MP4.types.mdat, 4);
if(track.len > 0) {
/* concatenate the audio data and construct the mdat in place
(need 8 more bytes to fill length and mdat type) */
mdat = new Uint8Array(track.len + 8);
view = new DataView(mdat.buffer);
view.setUint32(0, mdat.byteLength);
mdat.set(MP4.types.mdat, 4);
} else {
// no audio samples
return;
}
}
mdat.set(unit, offset);
offset += unit.byteLength;
@ -382,6 +392,29 @@ class MP4Remuxer {
timeOffset = timeOffset;
}
remuxText(track,timeOffset) {
track.samples.sort(function(a, b) {
return (a.pts-b.pts);
});
var length = track.samples.length, sample;
// consume samples
if(length) {
for(var index = 0; index < length; index++) {
sample = track.samples[index];
// setting text pts, dts to relative time
// using this._initPTS and this._initDTS to calculate relative time
sample.pts = ((sample.pts - this._initPTS) / this.PES_TIMESCALE);
}
this.observer.trigger(Event.FRAG_PARSING_USERDATA, {
samples:track.samples
});
}
track.samples = [];
timeOffset = timeOffset;
}
_PTSNormalize(value, reference) {
var offset;
if (reference === undefined) {