void NuPlayer::Renderer::onDrainVideoQueue() { if (mVideoQueue.empty()) { return; } QueueEntry *entry = &*mVideoQueue.begin(); if (entry->mBuffer == NULL) { // EOS notifyEOS(false /* audio */, entry->mFinalResult); mVideoQueue.erase(mVideoQueue.begin()); entry = NULL; mVideoLateByUs = 0ll; notifyPosition(); return; } int64_t realTimeUs; int64_t mediaTimeUs; if (mFlags & FLAG_REAL_TIME) { CHECK(entry->mBuffer->meta()->findInt64("timeUs", &realTimeUs)); } else { CHECK(entry->mBuffer->meta()->findInt64("timeUs", &mediaTimeUs)); realTimeUs = mediaTimeUs - mAnchorTimeMediaUs + mAnchorTimeRealUs; } mVideoLateByUs = ALooper::GetNowUs() - realTimeUs; bool tooLate = (mVideoLateByUs > 40000); if (tooLate) { ALOGV("video late by %lld us (%.2f secs)", mVideoLateByUs, mVideoLateByUs / 1E6); } else if (mFlags & FLAG_REAL_TIME) { ALOGV("rendering video at real time %.2f secs", realTimeUs / 1E6); } else { ALOGV("rendering video at media time %.2f secs", mediaTimeUs / 1E6); } entry->mNotifyConsumed->setInt32("render", !tooLate); entry->mNotifyConsumed->post(); mVideoQueue.erase(mVideoQueue.begin()); entry = NULL; if (!mVideoRenderingStarted) { mVideoRenderingStarted = true; notifyVideoRenderingStart(); } notifyIfMediaRenderingStarted(); notifyPosition(); }
//Data output and erase void NuPlayer::Renderer::onDrainVideoQueue() { if (mVideoQueue.empty()) { return; } QueueEntry *entry = &*mVideoQueue.begin(); if (entry->mBuffer == NULL) { // EOS if(entry->mFinalResult!=OK) { ALOGE("err %d, Line:%d", entry->mFinalResult,__LINE__); } notifyEOS(false /* audio */, entry->mFinalResult); mVideoQueue.erase(mVideoQueue.begin()); entry = NULL; mVideoLateByUs = 0ll; #ifndef ANDROID_DEFAULT_CODE notifyPosition(false/*video*/); #else notifyPosition(); #endif ALOGD("video position EOS"); return; } int64_t realTimeUs; #ifndef ANDROID_DEFAULT_CODE // mtk80902: shame google..mediaTimeUs may be used below int64_t mediaTimeUs = 0; #endif if (mFlags & FLAG_REAL_TIME) { CHECK(entry->mBuffer->meta()->findInt64("timeUs", &realTimeUs)); } else { #ifdef ANDROID_DEFAULT_CODE int64_t mediaTimeUs; #endif CHECK(entry->mBuffer->meta()->findInt64("timeUs", &mediaTimeUs)); realTimeUs = mediaTimeUs - mAnchorTimeMediaUs + mAnchorTimeRealUs; } mVideoLateByUs = ALooper::GetNowUs() - realTimeUs; #ifndef ANDROID_DEFAULT_CODE bool tooLate = (mVideoLateByUs > 250000); #else bool tooLate = (mVideoLateByUs > 40000); #endif if(mDebugDisableAVsync) { tooLate = false; } if(!mDropvideo) { tooLate = false; ALOGD("No audio data input"); } if (tooLate) { ALOGD("video (%.2f) late by %lld us (%.2f secs)", realTimeUs / 1E6, mVideoLateByUs, mVideoLateByUs / 1E6); } else { ALOGV("rendering video at media time %.2f secs", mediaTimeUs / 1E6); } #ifndef ANDROID_DEFAULT_CODE // if preformance not ok, show one ,then drop one static int32_t SinceLastDropped = 0; if(tooLate) { if (SinceLastDropped > 0) { //drop ALOGE("we're late dropping one after %d frames",SinceLastDropped); SinceLastDropped = 0; }else{ //not drop tooLate = false; SinceLastDropped ++; } }else{ SinceLastDropped ++; } entry->mNotifyConsumed->setInt64("realtimeus", realTimeUs); entry->mNotifyConsumed->setInt64("delaytimeus", -mVideoLateByUs); ALOGV("ACodec delay time(%lldus), video media time(%lldus), mAnchorTimeMediaUs(%lldus)", -mVideoLateByUs, mediaTimeUs, mAnchorTimeMediaUs); #endif entry->mNotifyConsumed->setInt32("render", !tooLate); entry->mNotifyConsumed->post(); mVideoQueue.erase(mVideoQueue.begin()); entry = NULL; if (!mVideoRenderingStarted) { mVideoRenderingStarted = true; notifyVideoRenderingStart(); } notifyIfMediaRenderingStarted(); #ifndef ANDROID_DEFAULT_CODE notifyPosition(false/*video*/); #else notifyPosition(); #endif }