Make sure the OMX component is synchronously shutdown before we try to instantiate another one. Also properly cleanup the software AVC decoder to avoid leaking memory.

related-to-bug: 2404786
diff --git a/media/libstagefright/AwesomePlayer.cpp b/media/libstagefright/AwesomePlayer.cpp
index d6db59f..85019aa 100644
--- a/media/libstagefright/AwesomePlayer.cpp
+++ b/media/libstagefright/AwesomePlayer.cpp
@@ -249,7 +249,16 @@
 
     if (mVideoSource != NULL) {
         mVideoSource->stop();
+
+        // The following hack is necessary to ensure that the OMX
+        // component is completely released by the time we may try
+        // to instantiate it again.
+        wp<MediaSource> tmp = mVideoSource;
         mVideoSource.clear();
+        while (tmp.promote() != NULL) {
+            usleep(1000);
+        }
+        IPCThreadState::self()->flushCommands();
     }
 
     mAudioSource.clear();