Loading media/libmediaplayerservice/nuplayer/GenericSource.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -546,10 +546,12 @@ void NuPlayer::GenericSource::cancelPollBuffering() { ++mPollBufferingGeneration; } void NuPlayer::GenericSource::notifyBufferingUpdate(int percentage) { void NuPlayer::GenericSource::notifyBufferingUpdate(int percentage, int64_t durationUs) { sp<AMessage> msg = dupNotify(); msg->setInt32("what", kWhatBufferingUpdate); msg->setInt32("percentage", percentage); msg->setInt64("duration", durationUs); msg->post(); } Loading Loading @@ -579,7 +581,7 @@ void NuPlayer::GenericSource::onPollBuffering() { } if (finalStatus == ERROR_END_OF_STREAM) { notifyBufferingUpdate(100); notifyBufferingUpdate(100, 0); cancelPollBuffering(); return; } else if (cachedDurationUs > 0ll && mDurationUs > 0ll) { Loading @@ -588,7 +590,7 @@ void NuPlayer::GenericSource::onPollBuffering() { percentage = 100; } notifyBufferingUpdate(percentage); notifyBufferingUpdate(percentage, cachedDurationUs); } schedulePollBuffering(); Loading media/libmediaplayerservice/nuplayer/GenericSource.h +1 −1 Original line number Diff line number Diff line Loading @@ -191,7 +191,7 @@ private: void schedulePollBuffering(); void cancelPollBuffering(); void onPollBuffering(); void notifyBufferingUpdate(int percentage); void notifyBufferingUpdate(int percentage, int64_t durationUs); DISALLOW_EVIL_CONSTRUCTORS(GenericSource); }; Loading media/libmediaplayerservice/nuplayer/NuPlayer.cpp +31 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,9 @@ namespace android { static int64_t kLowWaterMarkUs = 2000000ll; // 2secs static int64_t kHighWaterMarkUs = 5000000ll; // 5secs // TODO optimize buffer size for power consumption // The offload read buffer size is 32 KB but 24 KB uses less power. const size_t NuPlayer::kAggregateBufferSizeBytes = 24 * 1024; Loading Loading @@ -172,7 +175,9 @@ NuPlayer::NuPlayer() mNumFramesTotal(0ll), mNumFramesDropped(0ll), mVideoScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW), mStarted(false) { mStarted(false), mBuffering(false), mPlaying(false) { clearFlushComplete(); mPlayerExtendedStats = (PlayerExtendedStats *)ExtendedStats::Create( Loading Loading @@ -675,6 +680,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { } postScanSources(); mPlaying = true; break; } Loading Loading @@ -1027,6 +1033,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { ALOGW("pause called when renderer is gone or not set"); } PLAYER_STATS(profileStop, STATS_PROFILE_PAUSE); mPlaying = false; break; } Loading @@ -1047,6 +1054,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { } else { ALOGW("resume called when renderer is gone or not set"); } mPlaying = true; break; } Loading Loading @@ -1930,6 +1938,8 @@ void NuPlayer::performReset() { } mStarted = false; mBuffering = false; mPlaying = false; PLAYER_STATS(notifyEOS); PLAYER_STATS(dump); PLAYER_STATS(reset); Loading Loading @@ -2032,6 +2042,26 @@ void NuPlayer::onSourceNotify(const sp<AMessage> &msg) { int32_t percentage; CHECK(msg->findInt32("percentage", &percentage)); int64_t durationUs = 0; msg->findInt64("duration", &durationUs); bool eos = mVideoEOS || mAudioEOS || percentage == 100; // sources return 100% after EOS if (durationUs < kLowWaterMarkUs && mPlaying && !eos) { mBuffering = true; pause(); notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0); ALOGI("cache running low (< %g secs)..pausing", (double)durationUs / 1000000.0); } else if (eos || durationUs > kHighWaterMarkUs) { if (mBuffering && !mPlaying) { resume(); ALOGI("cache has filled up..resuming"); } notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0); mBuffering = false; } notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0); break; } Loading media/libmediaplayerservice/nuplayer/NuPlayer.h +2 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,8 @@ private: int32_t mVideoScalingMode; bool mStarted; bool mBuffering; bool mPlaying; inline const sp<Decoder> &getDecoder(bool audio) { return audio ? mAudioDecoder : mVideoDecoder; Loading Loading
media/libmediaplayerservice/nuplayer/GenericSource.cpp +5 −3 Original line number Diff line number Diff line Loading @@ -546,10 +546,12 @@ void NuPlayer::GenericSource::cancelPollBuffering() { ++mPollBufferingGeneration; } void NuPlayer::GenericSource::notifyBufferingUpdate(int percentage) { void NuPlayer::GenericSource::notifyBufferingUpdate(int percentage, int64_t durationUs) { sp<AMessage> msg = dupNotify(); msg->setInt32("what", kWhatBufferingUpdate); msg->setInt32("percentage", percentage); msg->setInt64("duration", durationUs); msg->post(); } Loading Loading @@ -579,7 +581,7 @@ void NuPlayer::GenericSource::onPollBuffering() { } if (finalStatus == ERROR_END_OF_STREAM) { notifyBufferingUpdate(100); notifyBufferingUpdate(100, 0); cancelPollBuffering(); return; } else if (cachedDurationUs > 0ll && mDurationUs > 0ll) { Loading @@ -588,7 +590,7 @@ void NuPlayer::GenericSource::onPollBuffering() { percentage = 100; } notifyBufferingUpdate(percentage); notifyBufferingUpdate(percentage, cachedDurationUs); } schedulePollBuffering(); Loading
media/libmediaplayerservice/nuplayer/GenericSource.h +1 −1 Original line number Diff line number Diff line Loading @@ -191,7 +191,7 @@ private: void schedulePollBuffering(); void cancelPollBuffering(); void onPollBuffering(); void notifyBufferingUpdate(int percentage); void notifyBufferingUpdate(int percentage, int64_t durationUs); DISALLOW_EVIL_CONSTRUCTORS(GenericSource); }; Loading
media/libmediaplayerservice/nuplayer/NuPlayer.cpp +31 −1 Original line number Diff line number Diff line Loading @@ -51,6 +51,9 @@ namespace android { static int64_t kLowWaterMarkUs = 2000000ll; // 2secs static int64_t kHighWaterMarkUs = 5000000ll; // 5secs // TODO optimize buffer size for power consumption // The offload read buffer size is 32 KB but 24 KB uses less power. const size_t NuPlayer::kAggregateBufferSizeBytes = 24 * 1024; Loading Loading @@ -172,7 +175,9 @@ NuPlayer::NuPlayer() mNumFramesTotal(0ll), mNumFramesDropped(0ll), mVideoScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW), mStarted(false) { mStarted(false), mBuffering(false), mPlaying(false) { clearFlushComplete(); mPlayerExtendedStats = (PlayerExtendedStats *)ExtendedStats::Create( Loading Loading @@ -675,6 +680,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { } postScanSources(); mPlaying = true; break; } Loading Loading @@ -1027,6 +1033,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { ALOGW("pause called when renderer is gone or not set"); } PLAYER_STATS(profileStop, STATS_PROFILE_PAUSE); mPlaying = false; break; } Loading @@ -1047,6 +1054,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { } else { ALOGW("resume called when renderer is gone or not set"); } mPlaying = true; break; } Loading Loading @@ -1930,6 +1938,8 @@ void NuPlayer::performReset() { } mStarted = false; mBuffering = false; mPlaying = false; PLAYER_STATS(notifyEOS); PLAYER_STATS(dump); PLAYER_STATS(reset); Loading Loading @@ -2032,6 +2042,26 @@ void NuPlayer::onSourceNotify(const sp<AMessage> &msg) { int32_t percentage; CHECK(msg->findInt32("percentage", &percentage)); int64_t durationUs = 0; msg->findInt64("duration", &durationUs); bool eos = mVideoEOS || mAudioEOS || percentage == 100; // sources return 100% after EOS if (durationUs < kLowWaterMarkUs && mPlaying && !eos) { mBuffering = true; pause(); notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0); ALOGI("cache running low (< %g secs)..pausing", (double)durationUs / 1000000.0); } else if (eos || durationUs > kHighWaterMarkUs) { if (mBuffering && !mPlaying) { resume(); ALOGI("cache has filled up..resuming"); } notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0); mBuffering = false; } notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0); break; } Loading
media/libmediaplayerservice/nuplayer/NuPlayer.h +2 −0 Original line number Diff line number Diff line Loading @@ -196,6 +196,8 @@ private: int32_t mVideoScalingMode; bool mStarted; bool mBuffering; bool mPlaying; inline const sp<Decoder> &getDecoder(bool audio) { return audio ? mAudioDecoder : mVideoDecoder; Loading