void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) { switch (msg->what()) { case kWhatDrainAudioQueue: { int32_t generation; CHECK(msg->findInt32("generation", &generation)); if (generation != mAudioQueueGeneration) { break; } mDrainAudioQueuePending = false; if (onDrainAudioQueue()) { uint32_t numFramesPlayed; CHECK_EQ(mAudioSink->getPosition(&numFramesPlayed), (status_t)OK); uint32_t numFramesPendingPlayout = mNumFramesWritten - numFramesPlayed; // This is how long the audio sink will have data to // play back. int64_t delayUs = mAudioSink->msecsPerFrame() * numFramesPendingPlayout * 1000ll; // Let's give it more data after about half that time // has elapsed. postDrainAudioQueue(delayUs / 2); } break; } case kWhatDrainVideoQueue: { int32_t generation; CHECK(msg->findInt32("generation", &generation)); if (generation != mVideoQueueGeneration) { break; } mDrainVideoQueuePending = false; onDrainVideoQueue(); postDrainVideoQueue(); break; } case kWhatQueueBuffer: { onQueueBuffer(msg); break; } case kWhatQueueEOS: { onQueueEOS(msg); break; } case kWhatFlush: { onFlush(msg); break; } case kWhatAudioSinkChanged: { onAudioSinkChanged(); break; } case kWhatPause: { onPause(); break; } case kWhatResume: { onResume(); break; } default: TRESPASS(); break; } }
void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) { switch (msg->what()) { case kWhatDrainAudioQueue: { int32_t generation; CHECK(msg->findInt32("generation", &generation)); if (generation != mAudioQueueGeneration) { break; } mDrainAudioQueuePending = false; if (onDrainAudioQueue()) { uint32_t numFramesPlayed; CHECK_EQ(mAudioSink->getPosition(&numFramesPlayed), (status_t)OK); uint32_t numFramesPendingPlayout = mNumFramesWritten - numFramesPlayed; // This is how long the audio sink will have data to // play back. int64_t delayUs = mAudioSink->msecsPerFrame() * numFramesPendingPlayout * 1000ll; // Let's give it more data after about half that time // has elapsed. #ifndef ANDROID_DEFAULT_CODE // half that is to large, set it to 20ms if (numFramesPlayed > mNumFramesWritten) ALOGW("numFramesPlayed(%d) > mNumFramesWritten(%d), no reset @ kWhatDrainAudioQueue", numFramesPlayed, mNumFramesWritten); if (delayUs > 40000) delayUs = 40000; #endif postDrainAudioQueue(delayUs / 2); } break; } case kWhatDrainVideoQueue: { int32_t generation; CHECK(msg->findInt32("generation", &generation)); if (generation != mVideoQueueGeneration) { break; } mDrainVideoQueuePending = false; onDrainVideoQueue(); postDrainVideoQueue(); break; } case kWhatQueueBuffer: { onQueueBuffer(msg); break; } case kWhatQueueEOS: { LOGI("kWhatQueueEOS"); mNeedCheckBuffer = false; onQueueEOS(msg); break; } case kWhatFlush: { onFlush(msg); break; } case kWhatAudioSinkChanged: { onAudioSinkChanged(); break; } case kWhatPause: { onPause(); break; } case kWhatResume: { mIsbufferempty = false; onResume(); break; } #ifndef ANDROID_DEFAULT_CODE case kWhatCheckRenderBufferStatus: { ALOGV("kWhatCheckRenderBufferStatus need check buff : %s",mNeedCheckBuffer?"YES":"NO"); sp<AMessage> notify = mNotify->dup(); notify->setInt32("what", kWhatBufferNotify); int32_t rate = 0; ALOGV("mIsSeeking(%d) mVideoQueue.size(%d) mAudioQueue.size(%d)",mIsSeeking,mVideoQueue.size(),mAudioQueue.size()); if(mNeedCheckBuffer == true){ switch(mIsbufferempty){ case true: if(mIsSeeking == true) { // only check VideoQueue after seek if (mVideoQueue.size()>0){ ALOGV("kWhatCheckRenderBufferStatus full"); rate = 100; notify->setInt32("bufRate", rate); notify->post(); mIsSeeking = false; } } else { if(mDebugDisableAVsync)//Disable AV SYNC for debug { ALOGV("kWhatCheckRenderBufferStatus full"); rate = 100; notify->setInt32("bufRate", rate); notify->post(); } else if (mAudioQueue.size()>2)//Wait audio { ALOGV("kWhatCheckRenderBufferStatus full"); rate = 100; notify->setInt32("bufRate", rate); notify->post(); } } break; case false: if(mIsSeeking == true) { // only check VideoQueue after seek if (mVideoQueue.empty()) { mIsbufferempty = true; ALOGV("kWhatCheckRenderBufferStatus empty"); rate = 0; notify->setInt32("bufRate", rate); notify->post(); } } else { if(mDebugDisableAVsync)//Disable AV SYNC for debug { mIsbufferempty = true; ALOGV("kWhatCheckRenderBufferStatus empty"); rate = 0; notify->setInt32("bufRate", rate); notify->post(); } else if (mAudioQueue.empty())//Wait audio empty { mIsbufferempty = true; ALOGV("kWhatCheckRenderBufferStatus empty"); rate = 0; notify->setInt32("bufRate", rate); notify->post(); } } break; default: break; } }else{ rate = 100; notify->setInt32("bufRate", rate); notify->post(); } (new AMessage(kWhatCheckRenderBufferStatus, id()))->post(300000); break; } case kWhatStatusNotify: { int32_t status; sp<AMessage> message; CHECK(msg->findMessage("message", &message)); CHECK(message->findInt32("status", &status)); LOGI(" kWhatStatusNotify %d",status); switch(status){ case MEDIA_SEEK_COMPLETE: mIsSeeking = true; break; default: break; } break; } #endif default: TRESPASS(); break; } }