fix unintentional drift

Change-Id: I0bbf3d3f95296a41d71558d8de1ed2ed021f21cf
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index b22025a..b14a03c 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -444,6 +444,8 @@
         notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage * 100.0);
 
         postBufferingEvent_l();
+    } else {
+        LOGE("Not sending buffering status because duration is unknown.");
     }
 }
 
@@ -552,8 +554,6 @@
         seekAudioIfNecessary_l();
     }
 
-    postBufferingEvent_l();
-
     if (mFlags & AT_EOS) {
         // Legacy behaviour, if a stream finishes playing and then
         // is started again, we play from the start...
@@ -1230,6 +1230,8 @@
     mFlags |= PREPARED;
     mAsyncPrepareEvent = NULL;
     mPreparedCondition.broadcast();
+
+    postBufferingEvent_l();
 }
 
 status_t AwesomePlayer::suspend() {
diff --git a/media/libstagefright/codecs/aacdec/AACDecoder.cpp b/media/libstagefright/codecs/aacdec/AACDecoder.cpp
index 2ed8ef1..ae23691 100644
--- a/media/libstagefright/codecs/aacdec/AACDecoder.cpp
+++ b/media/libstagefright/codecs/aacdec/AACDecoder.cpp
@@ -203,25 +203,32 @@
 
     Int decoderErr = PVMP4AudioDecodeFrame(mConfig, mDecoderBuf);
 
+    size_t numOutBytes =
+        mConfig->frameLength * sizeof(int16_t) * mConfig->desiredChannels;
+
     if (decoderErr != MP4AUDEC_SUCCESS) {
-        LOGE("AAC decoder returned error %d", decoderErr);
+        LOGW("AAC decoder returned error %d, substituting silence", decoderErr);
 
-        buffer->release();
-        buffer = NULL;
+        memset(buffer->data(), 0, numOutBytes);
 
-        return ERROR_MALFORMED;
-    }
-
-    buffer->set_range(
-            0, mConfig->frameLength * sizeof(int16_t) * mConfig->desiredChannels);
-
-    mInputBuffer->set_range(
-            mInputBuffer->range_offset() + mConfig->inputBufferUsedLength,
-            mInputBuffer->range_length() - mConfig->inputBufferUsedLength);
-
-    if (mInputBuffer->range_length() == 0) {
+        // Discard input buffer.
         mInputBuffer->release();
         mInputBuffer = NULL;
+
+        // fall through
+    }
+
+    buffer->set_range(0, numOutBytes);
+
+    if (mInputBuffer != NULL) {
+        mInputBuffer->set_range(
+                mInputBuffer->range_offset() + mConfig->inputBufferUsedLength,
+                mInputBuffer->range_length() - mConfig->inputBufferUsedLength);
+
+        if (mInputBuffer->range_length() == 0) {
+            mInputBuffer->release();
+            mInputBuffer = NULL;
+        }
     }
 
     buffer->meta_data()->setInt64(