From e47d44486f0a9f9b828b01d0fbaf84f5573f0aa2 Mon Sep 17 00:00:00 2001 From: Chong Zhang Date: Tue, 30 Sep 2014 13:12:22 -0700 Subject: send available codec buffer count with codec notification Bug: 14679336 Change-Id: Id927c96a9a14dd6ecd72540f0037d5841aa32154 --- .../libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp | 16 ++++++++++++---- media/libstagefright/MediaCodec.cpp | 17 +++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp index 7814bf1..601f6b5 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerDecoder.cpp @@ -604,13 +604,21 @@ void NuPlayer::Decoder::onMessageReceived(const sp &msg) { case kWhatCodecNotify: { if (!isStaleReply(msg)) { - if (!mPaused) { - while (handleAnInputBuffer()) { - } + int32_t numInput, numOutput; + + if (!msg->findInt32("input-buffers", &numInput)) { + numInput = INT32_MAX; } - while (handleAnOutputBuffer()) { + if (!msg->findInt32("output-buffers", &numOutput)) { + numOutput = INT32_MAX; } + + if (!mPaused) { + while (numInput-- > 0 && handleAnInputBuffer()) {} + } + + while (numOutput-- > 0 && handleAnOutputBuffer()) {} } requestCodecNotification(); diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index b56819c..b568063 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -2141,11 +2141,24 @@ void MediaCodec::postActivityNotificationIfPossible() { return; } - if ((mFlags & (kFlagStickyError + bool isErrorOrOutputChanged = + (mFlags & (kFlagStickyError | kFlagOutputBuffersChanged - | kFlagOutputFormatChanged)) + | kFlagOutputFormatChanged)); + + if (isErrorOrOutputChanged || !mAvailPortBuffers[kPortIndexInput].empty() || !mAvailPortBuffers[kPortIndexOutput].empty()) { + mActivityNotify->setInt32("input-buffers", + mAvailPortBuffers[kPortIndexInput].size()); + + if (isErrorOrOutputChanged) { + // we want consumer to dequeue as many times as it can + mActivityNotify->setInt32("output-buffers", INT32_MAX); + } else { + mActivityNotify->setInt32("output-buffers", + mAvailPortBuffers[kPortIndexOutput].size()); + } mActivityNotify->post(); mActivityNotify.clear(); } -- cgit v1.1