Merge "Bug 5201321 recover from mediaserver crash" into ics-mr1
diff --git a/src/android/AudioPlayer_to_android.cpp b/src/android/AudioPlayer_to_android.cpp
index 75084b7..8f60ead 100644
--- a/src/android/AudioPlayer_to_android.cpp
+++ b/src/android/AudioPlayer_to_android.cpp
@@ -839,7 +839,7 @@
         break;
 
       case android::GenericPlayer::kEventErrorAfterPrepare: {
-        SL_LOGI("kEventErrorAfterPrepare");
+        SL_LOGV("kEventErrorAfterPrepare");
 
         // assume no callback
         slPrefetchCallback callback = NULL;
@@ -847,12 +847,10 @@
 
         object_lock_exclusive(&ap->mObject);
         if (IsInterfaceInitialized(&ap->mObject, MPH_PREFETCHSTATUS)) {
-            SL_LOGI("inited");
             ap->mPrefetchStatus.mLevel = 0;
             ap->mPrefetchStatus.mStatus = SL_PREFETCHSTATUS_UNDERFLOW;
             if (!(~ap->mPrefetchStatus.mCallbackEventsMask &
                     (SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE))) {
-                SL_LOGI("enabled");
                 callback = ap->mPrefetchStatus.mCallback;
                 callbackPContext = ap->mPrefetchStatus.mContext;
             }
@@ -863,7 +861,6 @@
         SL_LOGE("Error after prepare: %d", data1);
 
         // callback with no lock held
-        SL_LOGE("callback=%p context=%p", callback, callbackPContext);
         if (NULL != callback) {
             (*callback)(&ap->mPrefetchStatus.mItf, callbackPContext,
                     SL_PREFETCHEVENT_FILLLEVELCHANGE | SL_PREFETCHEVENT_STATUSCHANGE);
diff --git a/src/android/android_GenericMediaPlayer.cpp b/src/android/android_GenericMediaPlayer.cpp
index a56a230..4abea4c 100644
--- a/src/android/android_GenericMediaPlayer.cpp
+++ b/src/android/android_GenericMediaPlayer.cpp
@@ -179,7 +179,8 @@
     mSeekTimeMsec(0),
     mVideoSurfaceTexture(0),
     mPlayer(0),
-    mPlayerClient(new MediaPlayerNotificationClient(this))
+    mPlayerClient(new MediaPlayerNotificationClient(this)),
+    mPlayerDeathNotifier(new MediaPlayerDeathNotifier(mPlayerClient))
 {
     SL_LOGD("GenericMediaPlayer::GenericMediaPlayer()");
 
diff --git a/src/android/android_GenericMediaPlayer.h b/src/android/android_GenericMediaPlayer.h
index e095dab..3e8fe81 100644
--- a/src/android/android_GenericMediaPlayer.h
+++ b/src/android/android_GenericMediaPlayer.h
@@ -32,7 +32,6 @@
 {
 public:
     MediaPlayerNotificationClient(GenericMediaPlayer* gmp);
-    virtual ~MediaPlayerNotificationClient();
 
     // IMediaPlayerClient implementation
     virtual void notify(int msg, int ext1, int ext2, const Parcel *obj);
@@ -44,6 +43,9 @@
     // completed successfully, or false if it completed unsuccessfully
     bool blockUntilPlayerPrepared();
 
+protected:
+    virtual ~MediaPlayerNotificationClient();
+
 private:
     const wp<GenericMediaPlayer> mGenericMediaPlayer;
     Mutex mLock;                        // protects mPlayerPrepared
@@ -57,6 +59,24 @@
 };
 
 
+class MediaPlayerDeathNotifier : public IMediaDeathNotifier {
+public:
+    MediaPlayerDeathNotifier(const sp<MediaPlayerNotificationClient> playerClient) :
+        mPlayerClient(playerClient) {
+    }
+
+    void died() {
+        mPlayerClient->notify(MEDIA_ERROR, MEDIA_ERROR_SERVER_DIED, 0, NULL);
+    }
+
+protected:
+    virtual ~MediaPlayerDeathNotifier() { }
+
+private:
+    const sp<MediaPlayerNotificationClient> mPlayerClient;
+};
+
+
 //--------------------------------------------------------------------------------------------------
 class GenericMediaPlayer : public GenericPlayer
 {
@@ -97,6 +117,9 @@
     // Receives Android MediaPlayer events from mPlayer
     const sp<MediaPlayerNotificationClient> mPlayerClient;
 
+    // Receives notifications about death of media.player service
+    const sp<MediaPlayerDeathNotifier> mPlayerDeathNotifier;
+
     // Return a reference to the media player service, or LOGE and return NULL after retries fail
     static const sp<IMediaPlayerService> getMediaPlayerService() {
         return IMediaDeathNotifier::getMediaPlayerService();
diff --git a/src/android/android_StreamPlayer.cpp b/src/android/android_StreamPlayer.cpp
index 6e14897..3847520 100644
--- a/src/android/android_StreamPlayer.cpp
+++ b/src/android/android_StreamPlayer.cpp
@@ -45,8 +45,7 @@
 }
 
 StreamSourceAppProxy::~StreamSourceAppProxy() {
-    // FIXME make this an SL_LOGV later; this just proves that the bug is fixed
-    SL_LOGI("StreamSourceAppProxy::~StreamSourceAppProxy()");
+    SL_LOGV("StreamSourceAppProxy::~StreamSourceAppProxy()");
     disconnect();
 }