private long getJitterFreePTS ( long bufferPts , long bufferSamplesNum ) { long correctedPts = 0 ; long bufferDuration = ( 1000000 * bufferSamplesNum ) / ( mEncoderCore . mSampleRate ) ; bufferPts -= bufferDuration ; // accounts for the delay of acquiring the audio buffer if ( totalSamplesNum == 0 ) { // reset startPTS = bufferPts ; totalSamplesNum = 0 ; } correctedPts = startPTS + ( 1000000 * totalSamplesNum ) / ( mEncoderCore . mSampleRate ) ; if ( bufferPts - correctedPts >= 2 * bufferDuration ) { // reset startPTS = bufferPts ; totalSamplesNum = 0 ; correctedPts = startPTS ; } totalSamplesNum += bufferSamplesNum ; return correctedPts ; }
Ensures that each audio pts differs by a constant amount from the previous one .