mediacodec解析mp4( 五 )


}
val desiredUsec = mPrevMonoUsec + frameDelta // when we want to wake up
var nowUsec = System.nanoTime() / 1000
while (nowUsec < desiredUsec - 100 /*&& mState == RUNNING*/) {
var sleepTimeUsec = desiredUsec - nowUsec
if (sleepTimeUsec > 500000) {
sleepTimeUsec = 500000
}
try {
if (CHECK_SLEEP_TIME) {
val startNsec = System.nanoTime()
Thread.sleep(sleepTimeUsec / 1000, (sleepTimeUsec % 1000).toInt() * 1000)
val actualSleepNsec = System.nanoTime() - startNsec
Log.d(
TAG, "sleep=" + sleepTimeUsec + " actual=" + actualSleepNsec / 1000 +
" diff=" + Math.abs(actualSleepNsec / 1000 - sleepTimeUsec) +
" (usec)"
)
} else {
Thread.sleep(sleepTimeUsec / 1000, (sleepTimeUsec % 1000).toInt() * 1000)
}
} catch (ie: InterruptedException) {
}
nowUsec = System.nanoTime() / 1000
}
mPrevMonoUsec += frameDelta
mPrevPresentUsec += frameDelta
}
}
override fun postRender() {}
override fun loopReset() {
mLoopReset = true
}
companion object {
private const val TAG = "SpeedControlCallback"
private const val CHECK_SLEEP_TIME = false
private const val ONE_MILLION = 1000000L
}
}
以上就是mediaCodec的解码mp4视频轨道的代码了 。
如果你对音视频开发感兴趣,觉得文章对您有帮助,别忘了点赞、收藏哦!或者对本文的一些阐述有自己的看法,有任何问题,欢迎在下方评论区讨论!

推荐阅读