update components

This commit is contained in:
Luke Pulverenti 2016-03-18 13:28:45 -04:00
parent 35f69d09ea
commit 51fcbbf744
15 changed files with 114 additions and 83 deletions

View file

@ -673,7 +673,7 @@ class StreamController extends EventHandler {
media.addEventListener('seeked', this.onvseeked);
media.addEventListener('ended', this.onvended);
if(this.levels && this.config.autoStartLoad) {
this.startLoad();
this.hls.startLoad();
}
}
@ -782,7 +782,7 @@ class StreamController extends EventHandler {
this.startLevelLoaded = false;
this.startFragRequested = false;
if (this.config.autoStartLoad) {
this.startLoad();
this.hls.startLoad();
}
}

View file

@ -49,8 +49,7 @@ import ID3 from '../demux/id3';
track.audiosamplerate = config.samplerate;
track.channelCount = config.channelCount;
track.codec = config.codec;
track.timescale = config.samplerate;
track.duration = config.samplerate * duration;
track.duration = duration;
logger.log(`parsed codec:${track.codec},rate:${config.samplerate},nb channel:${config.channelCount}`);
}
frameIndex = 0;

View file

@ -427,8 +427,7 @@
track.width = config.width;
track.height = config.height;
track.sps = [unit.data];
track.timescale = this.remuxer.timescale;
track.duration = this.remuxer.timescale * this._duration;
track.duration = this._duration;
var codecarray = unit.data.subarray(1, 4);
var codecstring = 'avc1.';
for (i = 0; i < 3; i++) {
@ -598,8 +597,7 @@
track.audiosamplerate = config.samplerate;
track.channelCount = config.channelCount;
track.codec = config.codec;
track.timescale = config.samplerate;
track.duration = config.samplerate * duration;
track.duration = duration;
logger.log(`parsed codec:${track.codec},rate:${config.samplerate},nb channel:${config.channelCount}`);
}
frameIndex = 0;

View file

@ -12,10 +12,6 @@ class DummyRemuxer {
return false;
}
get timescale() {
return this.PES_TIMESCALE;
}
destroy() {
}

View file

@ -172,6 +172,7 @@ class MP4 {
}
static mdhd(timescale, duration) {
duration *= timescale;
return MP4.box(MP4.types.mdhd, new Uint8Array([
0x00, // version 0
0x00, 0x00, 0x00, // flags
@ -243,6 +244,7 @@ class MP4 {
}
static mvhd(timescale,duration) {
duration*=timescale;
var
bytes = new Uint8Array([
0x00, // version 0
@ -424,7 +426,7 @@ class MP4 {
static tkhd(track) {
var id = track.id,
duration = track.duration,
duration = track.duration*track.timescale,
width = track.width,
height = track.height;
return MP4.box(MP4.types.tkhd, new Uint8Array([

View file

@ -21,10 +21,6 @@ class MP4Remuxer {
return false;
}
get timescale() {
return this.MP4_TIMESCALE;
}
destroy() {
}
@ -74,8 +70,22 @@ class MP4Remuxer {
if (computePTSDTS) {
initPTS = initDTS = Infinity;
}
if (audioTrack.config && audioSamples.length) {
audioTrack.timescale = audioTrack.audiosamplerate;
// MP4 duration (track duration in seconds multiplied by timescale) is coded on 32 bits
// we know that each AAC sample contains 1024 frames....
// in order to avoid overflowing the 32 bit counter for large duration, we use smaller timescale (timescale/gcd)
// we just need to ensure that AAC sample duration will still be an integer (will be 1024/gcd)
if (audioTrack.timescale * audioTrack.duration > Math.pow(2, 32)) {
let greatestCommonDivisor = function(a, b) {
if ( ! b) {
return a;
}
return greatestCommonDivisor(b, a % b);
};
audioTrack.timescale = audioTrack.audiosamplerate / greatestCommonDivisor(audioTrack.audiosamplerate,1024);
}
logger.log ('audio mp4 timescale :'+ audioTrack.timescale);
tracks.audio = {
container : 'audio/mp4',
codec : audioTrack.codec,
@ -91,6 +101,7 @@ class MP4Remuxer {
}
if (videoTrack.sps && videoTrack.pps && videoSamples.length) {
videoTrack.timescale = this.MP4_TIMESCALE;
tracks.video = {
container : 'video/mp4',
codec : videoTrack.codec,
@ -167,7 +178,12 @@ class MP4Remuxer {
}
mp4Sample.duration = sampleDuration;
} else {
var nextAvcDts = this.nextAvcDts,delta;
let nextAvcDts, delta;
if (contiguous) {
nextAvcDts = this.nextAvcDts;
} else {
nextAvcDts = timeOffset*pesTimeScale;
}
// first AVC sample of video track, normalize PTS/DTS
ptsnorm = this._PTSNormalize(pts, nextAvcDts);
dtsnorm = this._PTSNormalize(dts, nextAvcDts);
@ -252,6 +268,7 @@ class MP4Remuxer {
pesTimeScale = this.PES_TIMESCALE,
mp4timeScale = track.timescale,
pes2mp4ScaleFactor = pesTimeScale/mp4timeScale,
expectedSampleDuration = track.timescale * 1024 / track.audiosamplerate,
aacSample, mp4Sample,
unit,
mdat, moof,
@ -276,16 +293,22 @@ class MP4Remuxer {
ptsnorm = this._PTSNormalize(pts, lastDTS);
dtsnorm = this._PTSNormalize(dts, lastDTS);
// let's compute sample duration.
// there should be 1024 audio samples in one AAC frame
// sample Duration should be close to expectedSampleDuration
mp4Sample.duration = (dtsnorm - lastDTS) / pes2mp4ScaleFactor;
if(Math.abs(mp4Sample.duration - 1024) > 10) {
// not expected to happen ...
logger.log(`invalid AAC sample duration at PTS ${Math.round(pts/90)},should be 1024,found :${Math.round(mp4Sample.duration)}`);
if(Math.abs(mp4Sample.duration - expectedSampleDuration) > expectedSampleDuration/10) {
// more than 10% diff between sample duration and expectedSampleDuration .... lets log that
logger.log(`invalid AAC sample duration at PTS ${Math.round(pts/90)},should be 1024,found :${Math.round(mp4Sample.duration*track.audiosamplerate/track.timescale)}`);
}
mp4Sample.duration = 1024;
dtsnorm = 1024 * pes2mp4ScaleFactor + lastDTS;
// always adjust sample duration to avoid av sync issue
mp4Sample.duration = expectedSampleDuration;
dtsnorm = expectedSampleDuration * pes2mp4ScaleFactor + lastDTS;
} else {
var nextAacPts = this.nextAacPts,delta;
let nextAacPts, delta;
if (contiguous) {
nextAacPts = this.nextAacPts;
} else {
nextAacPts = timeOffset*pesTimeScale;
}
ptsnorm = this._PTSNormalize(pts, nextAacPts);
dtsnorm = this._PTSNormalize(dts, nextAacPts);
delta = Math.round(1000 * (ptsnorm - nextAacPts) / pesTimeScale);

View file

@ -9,15 +9,10 @@ class PassThroughRemuxer {
this.ISGenerated = false;
}
get passthrough() {
return true;
}
get timescale() {
return 0;
}
destroy() {
}