Error handling in ACodec and Nuplayer.

Codec errors (and codec not found errors) now trigger a controlled shutdown
of playback and signal errors to the MediaPlayer client.

Change-Id: I2ee23ff2a1422d05a1a21e50ecb87d7c7ab958cc
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index b06f20d..7fb141a 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -340,6 +340,11 @@
                 }
 
                 finishFlushIfPossible();
+            } else if (what == ACodec::kWhatError) {
+                LOGE("Received error from %s decoder, aborting playback.",
+                     audio ? "audio" : "video");
+
+                mRenderer->queueEOS(audio, UNKNOWN_ERROR);
             } else {
                 CHECK_EQ((int)what, (int)ACodec::kWhatDrainThisBuffer);
 
@@ -358,13 +363,24 @@
                 int32_t audio;
                 CHECK(msg->findInt32("audio", &audio));
 
+                int32_t finalResult;
+                CHECK(msg->findInt32("finalResult", &finalResult));
+
                 if (audio) {
                     mAudioEOS = true;
                 } else {
                     mVideoEOS = true;
                 }
 
-                LOGV("reached %s EOS", audio ? "audio" : "video");
+                if (finalResult == ERROR_END_OF_STREAM) {
+                    LOGV("reached %s EOS", audio ? "audio" : "video");
+                } else {
+                    LOGE("%s track encountered an error (0x%08x)",
+                         audio ? "audio" : "video", finalResult);
+
+                    notifyListener(
+                            MEDIA_ERROR, MEDIA_ERROR_UNKNOWN, finalResult);
+                }
 
                 if ((mAudioEOS || mAudioDecoder == NULL)
                         && (mVideoEOS || mVideoDecoder == NULL)) {