Propagate errors all the way through the MediaSources and send either MEDIA_PLAYBACK_COMPLETE or MEDIA_ERROR depending on the final reason for running out of buffers to play back.

related-to-bug: 2463749
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index b3a73b0..ab65b44 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -434,14 +434,22 @@
     }
     mStreamDoneEventPending = false;
 
-    if (mFlags & LOOPING) {
+    if (mStreamDoneStatus == ERROR_END_OF_STREAM && (mFlags & LOOPING)) {
         seekTo_l(0);
 
         if (mVideoSource != NULL) {
             postVideoEvent_l();
         }
     } else {
-        notifyListener_l(MEDIA_PLAYBACK_COMPLETE);
+        if (mStreamDoneStatus == ERROR_END_OF_STREAM) {
+            LOGV("MEDIA_PLAYBACK_COMPLETE");
+            notifyListener_l(MEDIA_PLAYBACK_COMPLETE);
+        } else {
+            LOGV("MEDIA_ERROR %d", mStreamDoneStatus);
+
+            notifyListener_l(
+                    MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, mStreamDoneStatus);
+        }
 
         pause_l();
 
@@ -802,7 +810,7 @@
                     continue;
                 }
 
-                postStreamDoneEvent_l();
+                postStreamDoneEvent_l(err);
                 return;
             }
 
@@ -904,11 +912,13 @@
     mQueue.postEventWithDelay(mVideoEvent, delayUs < 0 ? 10000 : delayUs);
 }
 
-void AwesomePlayer::postStreamDoneEvent_l() {
+void AwesomePlayer::postStreamDoneEvent_l(status_t status) {
     if (mStreamDoneEventPending) {
         return;
     }
     mStreamDoneEventPending = true;
+
+    mStreamDoneStatus = status;
     mQueue.postEvent(mStreamDoneEvent);
 }
 
@@ -947,9 +957,10 @@
         notifyListener_l(MEDIA_SEEK_COMPLETE);
     }
 
-    if (mWatchForAudioEOS && mAudioPlayer->reachedEOS()) {
+    status_t finalStatus;
+    if (mWatchForAudioEOS && mAudioPlayer->reachedEOS(&finalStatus)) {
         mWatchForAudioEOS = false;
-        postStreamDoneEvent_l();
+        postStreamDoneEvent_l(finalStatus);
     }
 
     postCheckAudioStatusEvent_l();