Created
March 1, 2019 03:51
-
-
Save sky0014/b7756c5da368c448b75db9f34f2a3da0 to your computer and use it in GitHub Desktop.
Large timestamp gap detected; may cause AV sync to drift check and aac frame generate code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AAC raw frame data | |
let dts = this._timestampBase + ts; | |
// check large timestamp gap caused av drift | |
if (this._expectTsAudio === -1) { | |
this._expectTsAudio = dts; // set base ts | |
} | |
let generated = false; | |
const delta = dts - this._expectTsAudio; | |
if (delta > this._driftThreshold) { | |
logger.warn(`Large timestamp gap detected; may cause AV sync to drift. time: ${dts} expected: ${this._expectTsAudio} delta: ${delta}`); | |
if (Config.enableFillAACGap) { | |
// 已生成空帧填补空隙,_driftThreshold不用变化 | |
// this._driftThreshold = delta; | |
// generate aac frame | |
const from = Math.round(this._expectTsAudio); | |
const to = dts; | |
const refSampleDuration = Math.round(meta.refSampleDuration); | |
const len = Math.round(delta / refSampleDuration) - 1; | |
dts = from; | |
const aacSample = { unit: aacData.data, dts: dts, pts: dts, cts: 0 }; | |
track.samples.push(aacSample); | |
track.length += aacData.data.length; | |
for (let i = 0; i < len; i++) { | |
const data = AAC.getSilentFrame(meta.codec, meta.channelCount); | |
dts += refSampleDuration; | |
if (i === len - 1) { | |
dts = to; | |
} | |
const aac = { unit: data, dts: dts, pts: dts, cts: 0 } | |
track.samples.push(aac); | |
track.length += data.length; | |
} | |
this._expectTsAudio = to; | |
generated = true; | |
logger.warn(`generated ${len} frames.`); | |
} else { | |
this._driftThreshold = delta; | |
} | |
} | |
if (!generated) { | |
const aacSample = { unit: aacData.data, dts: dts, pts: dts, cts: 0 }; | |
track.samples.push(aacSample); | |
track.length += aacData.data.length; | |
} | |
this._expectTsAudio += meta.refSampleDuration; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment