am 5c4428f6: Fix integer overflow during MP4 atom processing

* commit '5c4428f6391478ae983e1fcf7c42c832aa1a5e69':
  Fix integer overflow during MP4 atom processing
diff --git a/cmds/stagefright/recordvideo.cpp b/cmds/stagefright/recordvideo.cpp
index 3bd1fe2..e02f111 100644
--- a/cmds/stagefright/recordvideo.cpp
+++ b/cmds/stagefright/recordvideo.cpp
@@ -43,6 +43,7 @@
     fprintf(stderr, "       -l encoder level. see omx il header (default: encoder specific)\n");
     fprintf(stderr, "       -p encoder profile. see omx il header (default: encoder specific)\n");
     fprintf(stderr, "       -v video codec: [0] AVC [1] M4V [2] H263 (default: 0)\n");
+    fprintf(stderr, "       -s(oftware) prefer software codec\n");
     fprintf(stderr, "The output file is /sdcard/output.mp4\n");
     exit(1);
 }
@@ -162,10 +163,11 @@
     int profile = -1;      // Encoder specific default
     int codec = 0;
     const char *fileName = "/sdcard/output.mp4";
+    bool preferSoftwareCodec = false;
 
     android::ProcessState::self()->startThreadPool();
     int res;
-    while ((res = getopt(argc, argv, "b:c:f:i:n:w:t:l:p:v:h")) >= 0) {
+    while ((res = getopt(argc, argv, "b:c:f:i:n:w:t:l:p:v:hs")) >= 0) {
         switch (res) {
             case 'b':
             {
@@ -233,6 +235,12 @@
                 break;
             }
 
+            case 's':
+            {
+                preferSoftwareCodec = true;
+                break;
+            }
+
             case 'h':
             default:
             {
@@ -278,13 +286,15 @@
 
     sp<MediaSource> encoder =
         OMXCodec::Create(
-                client.interface(), enc_meta, true /* createEncoder */, source);
+                client.interface(), enc_meta, true /* createEncoder */, source,
+                0, preferSoftwareCodec ? OMXCodec::kPreferSoftwareCodecs : 0);
 
     sp<MPEG4Writer> writer = new MPEG4Writer(fileName);
     writer->addSource(encoder);
     int64_t start = systemTime();
     CHECK_EQ((status_t)OK, writer->start());
     while (!writer->reachedEOS()) {
+        usleep(100000);
     }
     err = writer->stop();
     int64_t end = systemTime();
diff --git a/drm/common/DrmEngineBase.cpp b/drm/common/DrmEngineBase.cpp
index 1c345a2..a060f38 100644
--- a/drm/common/DrmEngineBase.cpp
+++ b/drm/common/DrmEngineBase.cpp
@@ -139,6 +139,11 @@
     return onOpenDecryptSession(uniqueId, decryptHandle, uri, mime);
 }
 
+status_t DrmEngineBase::openDecryptSession(int uniqueId, DecryptHandle* decryptHandle,
+        const DrmBuffer& buf, const String8& mimeType) {
+    return onOpenDecryptSession(uniqueId, decryptHandle, buf, mimeType);
+}
+
 status_t DrmEngineBase::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     return onCloseDecryptSession(uniqueId, decryptHandle);
 }
diff --git a/drm/common/IDrmManagerService.cpp b/drm/common/IDrmManagerService.cpp
index 9ac7118..5c84bb5 100644
--- a/drm/common/IDrmManagerService.cpp
+++ b/drm/common/IDrmManagerService.cpp
@@ -640,6 +640,33 @@
     return handle;
 }
 
+DecryptHandle* BpDrmManagerService::openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
+    ALOGV("Entering BpDrmManagerService::openDecryptSession");
+    Parcel data, reply;
+
+    data.writeInterfaceToken(IDrmManagerService::getInterfaceDescriptor());
+    data.writeInt32(uniqueId);
+    if (buf.data != NULL && buf.length > 0) {
+        data.writeInt32(buf.length);
+        data.write(buf.data, buf.length);
+    } else {
+        data.writeInt32(0);
+    }
+    data.writeString8(mimeType);
+
+    remote()->transact(OPEN_DECRYPT_SESSION_FOR_STREAMING, data, &reply);
+
+    DecryptHandle* handle = NULL;
+    if (0 != reply.dataAvail()) {
+        handle = new DecryptHandle();
+        readDecryptHandleFromParcelData(handle, reply);
+    } else {
+        ALOGV("no decryptHandle is generated in service side");
+    }
+    return handle;
+}
+
 status_t BpDrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     ALOGV("closeDecryptSession");
     Parcel data, reply;
@@ -1287,6 +1314,30 @@
         return DRM_NO_ERROR;
     }
 
+    case OPEN_DECRYPT_SESSION_FOR_STREAMING:
+    {
+        ALOGV("BnDrmManagerService::onTransact :OPEN_DECRYPT_SESSION_FOR_STREAMING");
+        CHECK_INTERFACE(IDrmManagerService, data, reply);
+
+        const int uniqueId = data.readInt32();
+        const int bufferSize = data.readInt32();
+        DrmBuffer buf((bufferSize > 0) ? (char *)data.readInplace(bufferSize) : NULL,
+                bufferSize);
+        const String8 mimeType(data.readString8());
+
+        DecryptHandle* handle = openDecryptSession(uniqueId, buf, mimeType);
+
+        if (handle != NULL) {
+            writeDecryptHandleToParcelData(handle, reply);
+            clearDecryptHandle(handle);
+            delete handle;
+            handle = NULL;
+        } else {
+            ALOGV("NULL decryptHandle is returned");
+        }
+        return DRM_NO_ERROR;
+    }
+
     case CLOSE_DECRYPT_SESSION:
     {
         ALOGV("BnDrmManagerService::onTransact :CLOSE_DECRYPT_SESSION");
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index 70a06b4..8e42467 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -469,6 +469,36 @@
     return handle;
 }
 
+DecryptHandle* DrmManager::openDecryptSession(
+        int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
+    Mutex::Autolock _l(mDecryptLock);
+    status_t result = DRM_ERROR_CANNOT_HANDLE;
+    Vector<String8> plugInIdList = mPlugInManager.getPlugInIdList();
+
+    DecryptHandle* handle = new DecryptHandle();
+    if (NULL != handle) {
+        handle->decryptId = mDecryptSessionId + 1;
+
+        for (size_t index = 0; index < plugInIdList.size(); index++) {
+            String8 plugInId = plugInIdList.itemAt(index);
+            IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
+            result = rDrmEngine.openDecryptSession(uniqueId, handle, buf, mimeType);
+
+            if (DRM_NO_ERROR == result) {
+                ++mDecryptSessionId;
+                mDecryptSessionMap.add(mDecryptSessionId, &rDrmEngine);
+                break;
+            }
+        }
+    }
+    if (DRM_NO_ERROR != result) {
+        delete handle;
+        handle = NULL;
+        ALOGV("DrmManager::openDecryptSession: no capable plug-in found");
+    }
+    return handle;
+}
+
 status_t DrmManager::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     Mutex::Autolock _l(mDecryptLock);
     status_t result = DRM_ERROR_UNKNOWN;
diff --git a/drm/drmserver/DrmManagerService.cpp b/drm/drmserver/DrmManagerService.cpp
index d9f8b5c..dc1120f 100644
--- a/drm/drmserver/DrmManagerService.cpp
+++ b/drm/drmserver/DrmManagerService.cpp
@@ -214,6 +214,16 @@
     return NULL;
 }
 
+DecryptHandle* DrmManagerService::openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
+    ALOGV("Entering DrmManagerService::openDecryptSession for streaming");
+    if (isProtectedCallAllowed()) {
+        return mDrmManager->openDecryptSession(uniqueId, buf, mimeType);
+    }
+
+    return NULL;
+}
+
 status_t DrmManagerService::closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) {
     ALOGV("Entering closeDecryptSession");
     if (!isProtectedCallAllowed()) {
diff --git a/drm/libdrmframework/DrmManagerClient.cpp b/drm/libdrmframework/DrmManagerClient.cpp
index 8768c08..d4db461 100644
--- a/drm/libdrmframework/DrmManagerClient.cpp
+++ b/drm/libdrmframework/DrmManagerClient.cpp
@@ -130,6 +130,11 @@
                     mUniqueId, uri, mime);
 }
 
+sp<DecryptHandle> DrmManagerClient::openDecryptSession(
+            const DrmBuffer& buf, const String8& mimeType) {
+    return mDrmManagerClientImpl->openDecryptSession(mUniqueId, buf, mimeType);
+}
+
 status_t DrmManagerClient::closeDecryptSession(sp<DecryptHandle> &decryptHandle) {
     return mDrmManagerClientImpl->closeDecryptSession(mUniqueId, decryptHandle);
 }
diff --git a/drm/libdrmframework/DrmManagerClientImpl.cpp b/drm/libdrmframework/DrmManagerClientImpl.cpp
index 2185422..0e8b7b1 100644
--- a/drm/libdrmframework/DrmManagerClientImpl.cpp
+++ b/drm/libdrmframework/DrmManagerClientImpl.cpp
@@ -263,6 +263,11 @@
     return handle;
 }
 
+sp<DecryptHandle> DrmManagerClientImpl::openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType) {
+    return getDrmManagerService()->openDecryptSession(uniqueId, buf, mimeType);
+}
+
 status_t DrmManagerClientImpl::closeDecryptSession(
         int uniqueId, sp<DecryptHandle> &decryptHandle) {
     status_t status = DRM_ERROR_UNKNOWN;
diff --git a/drm/libdrmframework/include/DrmManager.h b/drm/libdrmframework/include/DrmManager.h
index 073ea2f..3d518a4 100644
--- a/drm/libdrmframework/include/DrmManager.h
+++ b/drm/libdrmframework/include/DrmManager.h
@@ -114,6 +114,9 @@
 
     DecryptHandle* openDecryptSession(int uniqueId, const char* uri, const char* mime);
 
+    DecryptHandle* openDecryptSession(int uniqueId, const DrmBuffer& buf,
+            const String8& mimeType);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/include/DrmManagerClientImpl.h b/drm/libdrmframework/include/DrmManagerClientImpl.h
index 88912a5..f131eae 100644
--- a/drm/libdrmframework/include/DrmManagerClientImpl.h
+++ b/drm/libdrmframework/include/DrmManagerClientImpl.h
@@ -320,6 +320,18 @@
             int uniqueId, const char* uri, const char* mime);
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] uniqueId Unique identifier for a session
+     * @param[in] buf Data to initiate decrypt session
+     * @param[in] mimeType Mime type of the protected content
+     * @return
+     *     Handle for the decryption session
+     */
+    sp<DecryptHandle> openDecryptSession(int uniqueId, const DrmBuffer& buf,
+            const String8& mimeType);
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/drm/libdrmframework/include/DrmManagerService.h b/drm/libdrmframework/include/DrmManagerService.h
index 304ac22..d734faa 100644
--- a/drm/libdrmframework/include/DrmManagerService.h
+++ b/drm/libdrmframework/include/DrmManagerService.h
@@ -102,6 +102,9 @@
     DecryptHandle* openDecryptSession(
         int uniqueId, const char* uri, const char* mime);
 
+    DecryptHandle* openDecryptSession(int uniqueId, const DrmBuffer& buf,
+            const String8& mimeType);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/include/IDrmManagerService.h b/drm/libdrmframework/include/IDrmManagerService.h
index 5dab338..26d496d 100644
--- a/drm/libdrmframework/include/IDrmManagerService.h
+++ b/drm/libdrmframework/include/IDrmManagerService.h
@@ -70,6 +70,7 @@
         GET_ALL_SUPPORT_INFO,
         OPEN_DECRYPT_SESSION,
         OPEN_DECRYPT_SESSION_FROM_URI,
+        OPEN_DECRYPT_SESSION_FOR_STREAMING,
         CLOSE_DECRYPT_SESSION,
         INITIALIZE_DECRYPT_UNIT,
         DECRYPT,
@@ -144,6 +145,9 @@
     virtual DecryptHandle* openDecryptSession(
                 int uniqueId, const char* uri, const char* mime) = 0;
 
+    virtual DecryptHandle* openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType) = 0;
+
     virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle) = 0;
 
     virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
@@ -228,6 +232,9 @@
     virtual DecryptHandle* openDecryptSession(
                 int uniqueId, const char* uri, const char* mime);
 
+    virtual DecryptHandle* openDecryptSession(
+            int uniqueId, const DrmBuffer& buf, const String8& mimeType);
+
     virtual status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     virtual status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
diff --git a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
index 08f6e6d..6cebb97 100644
--- a/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
+++ b/drm/libdrmframework/plugins/common/include/DrmEngineBase.h
@@ -87,6 +87,9 @@
             int uniqueId, DecryptHandle* decryptHandle,
             const char* uri, const char* mime);
 
+    status_t openDecryptSession(int uniqueId, DecryptHandle* decryptHandle,
+            const DrmBuffer& buf, const String8& mimeType);
+
     status_t closeDecryptSession(int uniqueId, DecryptHandle* decryptHandle);
 
     status_t initializeDecryptUnit(int uniqueId, DecryptHandle* decryptHandle,
@@ -433,6 +436,21 @@
     }
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] uniqueId Unique identifier for a session
+     * @param[in] decryptHandle Handle for the current decryption session
+     * @param[in] buf Data to initiate decrypt session
+     * @param[in] mimeType Mime type of the protected content
+     * @return
+     *     DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
+     */
+    virtual status_t onOpenDecryptSession(int uniqueId, DecryptHandle* decryptHandle,
+            const DrmBuffer& buf, const String8& mimeType) {
+        return DRM_ERROR_CANNOT_HANDLE;
+    }
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/drm/libdrmframework/plugins/common/include/IDrmEngine.h b/drm/libdrmframework/plugins/common/include/IDrmEngine.h
index dcf5977..60f4c1b 100644
--- a/drm/libdrmframework/plugins/common/include/IDrmEngine.h
+++ b/drm/libdrmframework/plugins/common/include/IDrmEngine.h
@@ -345,6 +345,19 @@
         const char* uri, const char* mime) = 0;
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] uniqueId Unique identifier for a session
+     * @param[in] decryptHandle Handle for the current decryption session
+     * @param[in] buf Data to initiate decrypt session
+     * @param[in] mimeType Mime type of the protected content
+     * @return
+     *     DRM_ERROR_CANNOT_HANDLE for failure and DRM_NO_ERROR for success
+     */
+    virtual status_t openDecryptSession(int uniqueId, DecryptHandle* decryptHandle,
+            const DrmBuffer& buf, const String8& mimeType) = 0;
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] uniqueId Unique identifier for a session
diff --git a/include/drm/DrmManagerClient.h b/include/drm/DrmManagerClient.h
index c47bbfb..a5c6992 100644
--- a/include/drm/DrmManagerClient.h
+++ b/include/drm/DrmManagerClient.h
@@ -83,6 +83,16 @@
     sp<DecryptHandle> openDecryptSession(const char* uri, const char* mime);
 
     /**
+     * Open the decrypt session to decrypt the given protected content
+     *
+     * @param[in] buf Data to initiate decrypt session
+     * @param[in] mimeType Mime type of the protected content
+     * @return
+     *     Handle for the decryption session
+     */
+    sp<DecryptHandle> openDecryptSession(const DrmBuffer& buf, const String8& mimeType);
+
+    /**
      * Close the decrypt session for the given handle
      *
      * @param[in] decryptHandle Handle for the decryption session
diff --git a/include/media/stagefright/MPEG2TSWriter.h b/include/media/stagefright/MPEG2TSWriter.h
index a7c9ecf..2e2922e 100644
--- a/include/media/stagefright/MPEG2TSWriter.h
+++ b/include/media/stagefright/MPEG2TSWriter.h
@@ -69,6 +69,9 @@
 
     int64_t mNumTSPacketsWritten;
     int64_t mNumTSPacketsBeforeMeta;
+    int mPATContinuityCounter;
+    int mPMTContinuityCounter;
+    uint32_t mCrcTable[256];
 
     void init();
 
@@ -76,6 +79,8 @@
     void writeProgramAssociationTable();
     void writeProgramMap();
     void writeAccessUnit(int32_t sourceIndex, const sp<ABuffer> &buffer);
+    void initCrcTable();
+    uint32_t crc32(const uint8_t *start, size_t length);
 
     ssize_t internalWrite(const void *data, size_t size);
     status_t reset();
diff --git a/include/media/stagefright/MPEG4Writer.h b/include/media/stagefright/MPEG4Writer.h
index cd4e129..3596b38 100644
--- a/include/media/stagefright/MPEG4Writer.h
+++ b/include/media/stagefright/MPEG4Writer.h
@@ -186,6 +186,8 @@
     void release();
     status_t reset();
 
+    static uint32_t getMpeg4Time();
+
     MPEG4Writer(const MPEG4Writer &);
     MPEG4Writer &operator=(const MPEG4Writer &);
 };
diff --git a/libvideoeditor/vss/stagefrightshells/src/VideoEditorBuffer.c b/libvideoeditor/vss/stagefrightshells/src/VideoEditorBuffer.c
index 98919d2..f4cfa7c 100755
--- a/libvideoeditor/vss/stagefrightshells/src/VideoEditorBuffer.c
+++ b/libvideoeditor/vss/stagefrightshells/src/VideoEditorBuffer.c
@@ -53,6 +53,7 @@
 {
     M4OSA_ERR lerr = M4NO_ERROR;
     VIDEOEDITOR_BUFFER_Pool* pool;
+    M4OSA_UInt32 index;
 
     ALOGV("VIDEOEDITOR_BUFFER_allocatePool : ppool = 0x%x nbBuffers = %d ",
         ppool, nbBuffers);
@@ -79,6 +80,11 @@
         goto VIDEOEDITOR_BUFFER_allocatePool_Cleanup;
     }
 
+    for (index = 0; index < nbBuffers; index++)
+    {
+        pool->pNXPBuffer[index].pData = M4OSA_NULL;
+    }
+
     ALOGV("VIDEOEDITOR_BUFFER_allocatePool : Allocating Pool name buffer");
     pool->poolName = M4OSA_NULL;
     pool->poolName = (M4OSA_Char*)M4OSA_32bitAlignedMalloc(
diff --git a/media/common_time/ICommonClock.cpp b/media/common_time/ICommonClock.cpp
index 28b43ac..25ae69e 100644
--- a/media/common_time/ICommonClock.cpp
+++ b/media/common_time/ICommonClock.cpp
@@ -13,7 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <linux/socket.h>
+
+#include <sys/socket.h>
 
 #include <common_time/ICommonClock.h>
 #include <binder/Parcel.h>
diff --git a/media/common_time/ICommonTimeConfig.cpp b/media/common_time/ICommonTimeConfig.cpp
index 8eb37cb..67167b0 100644
--- a/media/common_time/ICommonTimeConfig.cpp
+++ b/media/common_time/ICommonTimeConfig.cpp
@@ -13,7 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include <linux/socket.h>
+
+#include <sys/socket.h>
 
 #include <common_time/ICommonTimeConfig.h>
 #include <binder/Parcel.h>
diff --git a/media/libmedia/Android.mk b/media/libmedia/Android.mk
index c8e1dc7..6afc505 100644
--- a/media/libmedia/Android.mk
+++ b/media/libmedia/Android.mk
@@ -61,7 +61,6 @@
     $(call include-path-for, graphics corecg) \
     $(TOP)/frameworks/native/include/media/openmax \
     external/icu4c/common \
-    external/expat/lib \
     $(call include-path-for, audio-effects) \
     $(call include-path-for, audio-utils)
 
diff --git a/media/libmedia/MediaProfiles.cpp b/media/libmedia/MediaProfiles.cpp
index 6929efa..48bbf8f 100644
--- a/media/libmedia/MediaProfiles.cpp
+++ b/media/libmedia/MediaProfiles.cpp
@@ -23,7 +23,7 @@
 #include <utils/Log.h>
 #include <utils/Vector.h>
 #include <cutils/properties.h>
-#include <expat.h>
+#include <libexpat/expat.h>
 #include <media/MediaProfiles.h>
 #include <media/stagefright/foundation/ADebug.h>
 #include <OMX_Video.h>
@@ -516,16 +516,16 @@
         // Check high and low from either camcorder profile or timelapse profile
         // but not both. Default, check camcorder profile
         size_t j = 0;
-        size_t n = 2;
+        size_t o = 2;
         if (isTimelapseProfile(quality)) {
             // Check timelapse profile instead.
             j = 2;
-            n = kNumRequiredProfiles;
+            o = kNumRequiredProfiles;
         } else {
             // Must be camcorder profile.
             CHECK(isCamcorderProfile(quality));
         }
-        for (; j < n; ++j) {
+        for (; j < o; ++j) {
             info = &(mRequiredProfileRefs[refIndex].mRefs[j]);
             if ((j % 2 == 0 && product > info->mResolutionProduct) ||  // low
                 (j % 2 != 0 && product < info->mResolutionProduct)) {  // high
diff --git a/media/libstagefright/Android.mk b/media/libstagefright/Android.mk
index 8ad1cb9..ac50470 100644
--- a/media/libstagefright/Android.mk
+++ b/media/libstagefright/Android.mk
@@ -58,7 +58,6 @@
         $(TOP)/frameworks/av/include/media/stagefright/timedtext \
         $(TOP)/frameworks/native/include/media/hardware \
         $(TOP)/frameworks/native/include/media/openmax \
-        $(TOP)/external/expat/lib \
         $(TOP)/external/flac/include \
         $(TOP)/external/tremolo \
         $(TOP)/external/openssl/include \
diff --git a/media/libstagefright/MPEG2TSWriter.cpp b/media/libstagefright/MPEG2TSWriter.cpp
index f702376..c9ed5bb 100644
--- a/media/libstagefright/MPEG2TSWriter.cpp
+++ b/media/libstagefright/MPEG2TSWriter.cpp
@@ -28,6 +28,7 @@
 #include <media/stagefright/MediaSource.h>
 #include <media/stagefright/MetaData.h>
 #include <media/stagefright/Utils.h>
+#include <arpa/inet.h>
 
 #include "include/ESDS.h"
 
@@ -418,6 +419,8 @@
                     } else {
                         postAVCFrame(buffer);
                     }
+                } else {
+                    readMore();
                 }
 
                 buffer->release();
@@ -471,7 +474,9 @@
       mStarted(false),
       mNumSourcesDone(0),
       mNumTSPacketsWritten(0),
-      mNumTSPacketsBeforeMeta(0) {
+      mNumTSPacketsBeforeMeta(0),
+      mPATContinuityCounter(0),
+      mPMTContinuityCounter(0) {
     init();
 }
 
@@ -482,7 +487,9 @@
       mStarted(false),
       mNumSourcesDone(0),
       mNumTSPacketsWritten(0),
-      mNumTSPacketsBeforeMeta(0) {
+      mNumTSPacketsBeforeMeta(0),
+      mPATContinuityCounter(0),
+      mPMTContinuityCounter(0) {
     init();
 }
 
@@ -495,13 +502,17 @@
       mStarted(false),
       mNumSourcesDone(0),
       mNumTSPacketsWritten(0),
-      mNumTSPacketsBeforeMeta(0) {
+      mNumTSPacketsBeforeMeta(0),
+      mPATContinuityCounter(0),
+      mPMTContinuityCounter(0) {
     init();
 }
 
 void MPEG2TSWriter::init() {
     CHECK(mFile != NULL || mWriteFunc != NULL);
 
+    initCrcTable();
+
     mLooper = new ALooper;
     mLooper->setName("MPEG2TSWriter");
 
@@ -729,11 +740,16 @@
     };
 
     sp<ABuffer> buffer = new ABuffer(188);
-    memset(buffer->data(), 0, buffer->size());
+    memset(buffer->data(), 0xff, buffer->size());
     memcpy(buffer->data(), kData, sizeof(kData));
 
-    static const unsigned kContinuityCounter = 5;
-    buffer->data()[3] |= kContinuityCounter;
+    if (++mPATContinuityCounter == 16) {
+        mPATContinuityCounter = 0;
+    }
+    buffer->data()[3] |= mPATContinuityCounter;
+
+    uint32_t crc = htonl(crc32(&buffer->data()[5], 12));
+    memcpy(&buffer->data()[17], &crc, sizeof(crc));
 
     CHECK_EQ(internalWrite(buffer->data(), buffer->size()), buffer->size());
 }
@@ -781,11 +797,13 @@
     };
 
     sp<ABuffer> buffer = new ABuffer(188);
-    memset(buffer->data(), 0, buffer->size());
+    memset(buffer->data(), 0xff, buffer->size());
     memcpy(buffer->data(), kData, sizeof(kData));
 
-    static const unsigned kContinuityCounter = 5;
-    buffer->data()[3] |= kContinuityCounter;
+    if (++mPMTContinuityCounter == 16) {
+        mPMTContinuityCounter = 0;
+    }
+    buffer->data()[3] |= mPMTContinuityCounter;
 
     size_t section_length = 5 * mSources.size() + 4 + 9;
     buffer->data()[6] |= section_length >> 8;
@@ -806,10 +824,8 @@
         *ptr++ = 0x00;
     }
 
-    *ptr++ = 0x00;
-    *ptr++ = 0x00;
-    *ptr++ = 0x00;
-    *ptr++ = 0x00;
+    uint32_t crc = htonl(crc32(&buffer->data()[5], 12+mSources.size()*5));
+    memcpy(&buffer->data()[17+mSources.size()*5], &crc, sizeof(crc));
 
     CHECK_EQ(internalWrite(buffer->data(), buffer->size()), buffer->size());
 }
@@ -822,7 +838,7 @@
     // transport_priority = b0
     // PID = b0 0001 1110 ???? (13 bits) [0x1e0 + 1 + sourceIndex]
     // transport_scrambling_control = b00
-    // adaptation_field_control = b01 (no adaptation field, payload only)
+    // adaptation_field_control = b??
     // continuity_counter = b????
     // -- payload follows
     // packet_startcode_prefix = 0x000001
@@ -852,7 +868,7 @@
     // the first fragment of "buffer" follows
 
     sp<ABuffer> buffer = new ABuffer(188);
-    memset(buffer->data(), 0, buffer->size());
+    memset(buffer->data(), 0xff, buffer->size());
 
     const unsigned PID = 0x1e0 + sourceIndex + 1;
 
@@ -870,6 +886,7 @@
     uint32_t PTS = (timeUs * 9ll) / 100ll;
 
     size_t PES_packet_length = accessUnit->size() + 8;
+    bool padding = (accessUnit->size() < (188 - 18));
 
     if (PES_packet_length >= 65536) {
         // This really should only happen for video.
@@ -883,7 +900,15 @@
     *ptr++ = 0x47;
     *ptr++ = 0x40 | (PID >> 8);
     *ptr++ = PID & 0xff;
-    *ptr++ = 0x10 | continuity_counter;
+    *ptr++ = (padding ? 0x30 : 0x10) | continuity_counter;
+    if (padding) {
+        int paddingSize = 188 - accessUnit->size() - 18;
+        *ptr++ = paddingSize - 1;
+        if (paddingSize >= 2) {
+            *ptr++ = 0x00;
+            ptr += paddingSize - 2;
+        }
+    }
     *ptr++ = 0x00;
     *ptr++ = 0x00;
     *ptr++ = 0x01;
@@ -911,6 +936,7 @@
 
     size_t offset = copy;
     while (offset < accessUnit->size()) {
+        bool lastAccessUnit = ((accessUnit->size() - offset) < 184);
         // for subsequent fragments of "buffer":
         // 0x47
         // transport_error_indicator = b0
@@ -918,11 +944,11 @@
         // transport_priority = b0
         // PID = b0 0001 1110 ???? (13 bits) [0x1e0 + 1 + sourceIndex]
         // transport_scrambling_control = b00
-        // adaptation_field_control = b01 (no adaptation field, payload only)
+        // adaptation_field_control = b??
         // continuity_counter = b????
         // the fragment of "buffer" follows.
 
-        memset(buffer->data(), 0, buffer->size());
+        memset(buffer->data(), 0xff, buffer->size());
 
         const unsigned continuity_counter =
             mSources.editItemAt(sourceIndex)->incrementContinuityCounter();
@@ -931,7 +957,18 @@
         *ptr++ = 0x47;
         *ptr++ = 0x00 | (PID >> 8);
         *ptr++ = PID & 0xff;
-        *ptr++ = 0x10 | continuity_counter;
+        *ptr++ = (lastAccessUnit ? 0x30 : 0x10) | continuity_counter;
+
+        if (lastAccessUnit) {
+            // Pad packet using an adaptation field
+            // Adaptation header all to 0 execpt size
+            uint8_t paddingSize = (uint8_t)184 - (accessUnit->size() - offset);
+            *ptr++ = paddingSize - 1;
+            if (paddingSize >= 2) {
+                *ptr++ = 0x00;
+                ptr += paddingSize - 2;
+            }
+        }
 
         size_t sizeLeft = buffer->data() + buffer->size() - ptr;
         size_t copy = accessUnit->size() - offset;
@@ -956,6 +993,33 @@
     }
 }
 
+void MPEG2TSWriter::initCrcTable() {
+    uint32_t poly = 0x04C11DB7;
+
+    for (int i = 0; i < 256; i++) {
+        uint32_t crc = i << 24;
+        for (int j = 0; j < 8; j++) {
+            crc = (crc << 1) ^ ((crc & 0x80000000) ? (poly) : 0);
+        }
+        mCrcTable[i] = crc;
+    }
+}
+
+/**
+ * Compute CRC32 checksum for buffer starting at offset start and for length
+ * bytes.
+ */
+uint32_t MPEG2TSWriter::crc32(const uint8_t *p_start, size_t length) {
+    uint32_t crc = 0xFFFFFFFF;
+    const uint8_t *p;
+
+    for (p = p_start; p < p_start + length; p++) {
+        crc = (crc << 8) ^ mCrcTable[((crc >> 24) ^ *p) & 0xFF];
+    }
+
+    return crc;
+}
+
 ssize_t MPEG2TSWriter::internalWrite(const void *data, size_t size) {
     if (mFile != NULL) {
         return fwrite(data, 1, size, mFile);
diff --git a/media/libstagefright/MPEG4Writer.cpp b/media/libstagefright/MPEG4Writer.cpp
index 755b502..6108298 100755
--- a/media/libstagefright/MPEG4Writer.cpp
+++ b/media/libstagefright/MPEG4Writer.cpp
@@ -236,11 +236,11 @@
     void writeDrefBox();
     void writeDinfBox();
     void writeDamrBox();
-    void writeMdhdBox(time_t now);
+    void writeMdhdBox(uint32_t now);
     void writeSmhdBox();
     void writeVmhdBox();
     void writeHdlrBox();
-    void writeTkhdBox(time_t now);
+    void writeTkhdBox(uint32_t now);
     void writeMp4aEsdsBox();
     void writeMp4vEsdsBox();
     void writeAudioFourCCBox();
@@ -723,8 +723,17 @@
     return err;
 }
 
-void MPEG4Writer::writeMvhdBox(int64_t durationUs) {
+uint32_t MPEG4Writer::getMpeg4Time() {
     time_t now = time(NULL);
+    // MP4 file uses time counting seconds since midnight, Jan. 1, 1904
+    // while time function returns Unix epoch values which starts
+    // at 1970-01-01. Lets add the number of seconds between them
+    uint32_t mpeg4Time = now + (66 * 365 + 17) * (24 * 60 * 60);
+    return mpeg4Time;
+}
+
+void MPEG4Writer::writeMvhdBox(int64_t durationUs) {
+    uint32_t now = getMpeg4Time();
     beginBox("mvhd");
     writeInt32(0);             // version=0, flags=0
     writeInt32(now);           // creation time
@@ -2357,7 +2366,7 @@
     ALOGV("%s track time scale: %d",
         mIsAudio? "Audio": "Video", mTimeScale);
 
-    time_t now = time(NULL);
+    uint32_t now = getMpeg4Time();
     mOwner->beginBox("trak");
         writeTkhdBox(now);
         mOwner->beginBox("mdia");
@@ -2570,7 +2579,7 @@
     mOwner->endBox();  // esds
 }
 
-void MPEG4Writer::Track::writeTkhdBox(time_t now) {
+void MPEG4Writer::Track::writeTkhdBox(uint32_t now) {
     mOwner->beginBox("tkhd");
     // Flags = 7 to indicate that the track is enabled, and
     // part of the presentation
@@ -2639,7 +2648,7 @@
     mOwner->endBox();
 }
 
-void MPEG4Writer::Track::writeMdhdBox(time_t now) {
+void MPEG4Writer::Track::writeMdhdBox(uint32_t now) {
     int64_t trakDurationUs = getDurationUs();
     mOwner->beginBox("mdhd");
     mOwner->writeInt32(0);             // version=0, flags=0
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index 67f5a22..2060699 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -1118,7 +1118,8 @@
             CHECK(msg->senderAwaitsResponse(&replyID));
 
             if ((mState != STARTED && mState != FLUSHING)
-                    || (mFlags & kFlagStickyError)) {
+                    || (mFlags & kFlagStickyError)
+                    || mOutputFormat == NULL) {
                 sp<AMessage> response = new AMessage;
                 response->setInt32("err", INVALID_OPERATION);
 
diff --git a/media/libstagefright/MediaCodecList.cpp b/media/libstagefright/MediaCodecList.cpp
index 9f6d4a3..d24337f 100644
--- a/media/libstagefright/MediaCodecList.cpp
+++ b/media/libstagefright/MediaCodecList.cpp
@@ -26,7 +26,7 @@
 #include <media/stagefright/OMXCodec.h>
 #include <utils/threads.h>
 
-#include <expat.h>
+#include <libexpat/expat.h>
 
 namespace android {
 
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index fde7ebf..a6636a1 100755
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -2048,9 +2048,13 @@
 }
 
 void OMXCodec::on_message(const omx_message &msg) {
+    // even in error state, we still need to process EMPTY_BUFFER_DONE
+    // and FILL_BUFFER_DONE event, or we will run into mediaserver crash issue
     if (mState == ERROR) {
-        ALOGW("Dropping OMX message - we're in ERROR state.");
-        return;
+        if (msg.type == omx_message::EVENT) {
+            ALOGW("Dropping OMX message - we're in ERROR state.");
+            return;
+        }
     }
 
     switch (msg.type) {
diff --git a/media/libstagefright/codecs/aacenc/Android.mk b/media/libstagefright/codecs/aacenc/Android.mk
index 1c342c8..820734d 100644
--- a/media/libstagefright/codecs/aacenc/Android.mk
+++ b/media/libstagefright/codecs/aacenc/Android.mk
@@ -71,8 +71,6 @@
 	$(LOCAL_PATH)/inc \
 	$(LOCAL_PATH)/basic_op
 
-LOCAL_CFLAGS := $(VO_CFLAGS)
-
 ifeq ($(VOTT), v5)
 LOCAL_CFLAGS += -DARMV5E -DARM_INASM -DARMV5_INASM
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/asm/ARMV5E
diff --git a/media/libstagefright/codecs/aacenc/SampleCode/Android.mk b/media/libstagefright/codecs/aacenc/SampleCode/Android.mk
index ba3f4d2..01016e7 100644
--- a/media/libstagefright/codecs/aacenc/SampleCode/Android.mk
+++ b/media/libstagefright/codecs/aacenc/SampleCode/Android.mk
@@ -5,8 +5,6 @@
     AAC_E_SAMPLES.c \
     ../../common/cmnMemory.c
 
-LOCAL_CFLAGS += $(VO_CFLAGS)
-
 LOCAL_MODULE_TAGS := debug
 
 LOCAL_MODULE := AACEncTest
diff --git a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
index 982f4fd..cc01927 100644
--- a/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
+++ b/media/libstagefright/codecs/aacenc/basic_op/oper_32b.c
@@ -344,8 +344,8 @@
 */
 Word32 pow2_xy(Word32 x, Word32 y)
 {
-  Word32 iPart;
-  Word32 fPart;
+  UWord32 iPart;
+  UWord32 fPart;
   Word32 res;
   Word32 tmp, tmp2;
   Word32 shift, shift2;
diff --git a/media/libstagefright/codecs/aacenc/inc/aac_rom.h b/media/libstagefright/codecs/aacenc/inc/aac_rom.h
index 8e206b7..0b6f656 100644
--- a/media/libstagefright/codecs/aacenc/inc/aac_rom.h
+++ b/media/libstagefright/codecs/aacenc/inc/aac_rom.h
@@ -57,7 +57,7 @@
 /*! $2^{-\frac{n}{16}}$ table */
 extern const Word16 pow2tominusNover16[17] ;
 
-extern Word32 specExpMantTableComb_enc[4][14];
+extern const Word32 specExpMantTableComb_enc[4][14];
 extern const UWord8 specExpTableComb_enc[4][14];
 
 extern const Word16 quantBorders[4][4];
diff --git a/media/libstagefright/codecs/aacenc/src/aac_rom.c b/media/libstagefright/codecs/aacenc/src/aac_rom.c
index 127322d..f08f3a9 100644
--- a/media/libstagefright/codecs/aacenc/src/aac_rom.c
+++ b/media/libstagefright/codecs/aacenc/src/aac_rom.c
@@ -1367,7 +1367,7 @@
   10, 10, 10, 10, 10, 13, 13
 };
 
-Word32 specExpMantTableComb_enc[4][14] =
+const Word32 specExpMantTableComb_enc[4][14] =
 {
   {0x40000000,  0x50a28be6,  0x6597fa95,  0x40000000,
    0x50a28be6,  0x6597fa95,  0x40000000,  0x50a28be6,
diff --git a/media/libstagefright/codecs/aacenc/src/aacenc.c b/media/libstagefright/codecs/aacenc/src/aacenc.c
index ad2f29a..d1c8621 100644
--- a/media/libstagefright/codecs/aacenc/src/aacenc.c
+++ b/media/libstagefright/codecs/aacenc/src/aacenc.c
@@ -357,9 +357,9 @@
 		if(config.sampleRate%8000 == 0)
 			tmp =480;
 		/* check the bitrate */
-		if(config.bitRate!=0 && (config.bitRate/config.nChannelsOut < 4000) ||
+		if(config.bitRate!=0 && ((config.bitRate/config.nChannelsOut < 4000) ||
            (config.bitRate/config.nChannelsOut > 160000) ||
-		   (config.bitRate > config.sampleRate*6*config.nChannelsOut))
+		   (config.bitRate > config.sampleRate*6*config.nChannelsOut)))
 		{
 			config.bitRate = 640*config.sampleRate/tmp*config.nChannelsOut;
 
diff --git a/media/libstagefright/codecs/aacenc/src/adj_thr.c b/media/libstagefright/codecs/aacenc/src/adj_thr.c
index 07b33b7..ccfe883 100644
--- a/media/libstagefright/codecs/aacenc/src/adj_thr.c
+++ b/media/libstagefright/codecs/aacenc/src/adj_thr.c
@@ -20,13 +20,16 @@
 
 *******************************************************************************/
 
+/* Include system headers before local headers - the local headers
+ * redefine __inline, which can mess up definitions in libc headers if
+ * they happen to use __inline. */
+#include <string.h>
 #include "basic_op.h"
 #include "oper_32b.h"
 #include "adj_thr_data.h"
 #include "adj_thr.h"
 #include "qc_data.h"
 #include "line_pe.h"
-#include <string.h>
 
 
 #define  minSnrLimit    0x6666 /* 1 dB */
diff --git a/media/libstagefright/codecs/aacenc/src/block_switch.c b/media/libstagefright/codecs/aacenc/src/block_switch.c
index 47fd15e..c80538f 100644
--- a/media/libstagefright/codecs/aacenc/src/block_switch.c
+++ b/media/libstagefright/codecs/aacenc/src/block_switch.c
@@ -51,7 +51,7 @@
 /*
   IIR high pass coeffs
 */
-Word32 hiPassCoeff[BLOCK_SWITCHING_IIR_LEN] = {
+const Word32 hiPassCoeff[BLOCK_SWITCHING_IIR_LEN] = {
   0xbec8b439, 0x609d4952  /* -0.5095f, 0.7548f */
 };
 
diff --git a/media/libstagefright/codecs/amrnb/common/include/frame_type_3gpp.h b/media/libstagefright/codecs/amrnb/common/include/frame_type_3gpp.h
index 3ebd929..3d482be 100644
--- a/media/libstagefright/codecs/amrnb/common/include/frame_type_3gpp.h
+++ b/media/libstagefright/codecs/amrnb/common/include/frame_type_3gpp.h
@@ -105,6 +105,34 @@
         AMR_NO_DATA         /* No data      */
     };
 
+typedef enum
+{
+    /*
+     *    One word (2-byte) to indicate type of frame type.
+     *    One word (2-byte) to indicate frame type.
+     *    One word (2-byte) to indicate mode.
+     *    N words (2-byte) containing N bits (bit 0 = 0xff81, bit 1 = 0x007f).
+     */
+    ETS = 0, /* Both AMR-Narrowband and AMR-Wideband */
+
+    /*
+     *    One word (2-byte) for sync word (good frames: 0x6b21, bad frames: 0x6b20)
+     *    One word (2-byte) for frame length N.
+     *    N words (2-byte) containing N bits (bit 0 = 0x007f, bit 1 = 0x0081).
+     */
+    ITU, /* AMR-Wideband */
+
+    /*
+     *   AMR-WB MIME/storage format, see RFC 3267 (sections 5.1 and 5.3) for details
+     */
+    MIME_IETF,
+
+    WMF, /* AMR-Narrowband */
+
+    IF2  /* AMR-Narrowband */
+
+} bitstream_format;
+
     /*----------------------------------------------------------------------------
     ; STRUCTURES TYPEDEF'S
     ----------------------------------------------------------------------------*/
diff --git a/media/libstagefright/codecs/amrnb/common/include/pvgsmamr.h b/media/libstagefright/codecs/amrnb/common/include/pvgsmamr.h
deleted file mode 100644
index b697524..0000000
--- a/media/libstagefright/codecs/amrnb/common/include/pvgsmamr.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* ------------------------------------------------------------------
- * Copyright (C) 1998-2009 PacketVideo
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
- * express or implied.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- * -------------------------------------------------------------------
- */
-/****************************************************************************************
-Portions of this file are derived from the following 3GPP standard:
-
-    3GPP TS 26.073
-    ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
-    Available from http://www.3gpp.org
-
-(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
-Permission to distribute, modify and use this file under the standard license
-terms listed above has been obtained from the copyright holder.
-****************************************************************************************/
-#ifndef __PVGSMAMR_H
-#define __PVGSMAMR_H
-
-
-// includes
-#include <e32std.h>
-#include <e32base.h>
-
-#include "sp_dec.h"
-#include "pvglobals.h"
-
-
-// PVGsmDecoder AO
-class CPVGsmDecoder : public CBase
-{
-    public:
-        IMPORT_C static CPVGsmDecoder* NewL(void);
-        IMPORT_C ~CPVGsmDecoder();
-        IMPORT_C TInt StartL(void);
-
-        // only port the API's used in PVPlayer 2.0
-        IMPORT_C TInt DecodeFrame(enum Mode mode, unsigned char* compressedBlock, unsigned char* audioBuffer);
-        IMPORT_C TInt InitDecoder(void);
-        IMPORT_C void ExitDecoder(void);
-
-    private:
-        CPVGsmDecoder();
-        void ConstructL(void);
-
-        Speech_Decode_FrameState* decState;
-        enum RXFrameType rx_type;
-        struct globalDataStruct *gds;
-};
-
-#endif
diff --git a/media/libstagefright/codecs/amrnb/common/pvgsmamrdecoderinterface.h b/media/libstagefright/codecs/amrnb/common/pvgsmamrdecoderinterface.h
deleted file mode 100644
index ccbed44..0000000
--- a/media/libstagefright/codecs/amrnb/common/pvgsmamrdecoderinterface.h
+++ /dev/null
@@ -1,183 +0,0 @@
-/* ------------------------------------------------------------------
- * Copyright (C) 1998-2009 PacketVideo
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
- * express or implied.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- * -------------------------------------------------------------------
- */
-//////////////////////////////////////////////////////////////////////////////////
-//                                                                              //
-//  File: pvgsmamrdecoderinterface.h                                            //
-//                                                                              //
-//////////////////////////////////////////////////////////////////////////////////
-
-#ifndef _PVGSMAMR_DECODER_INTERFACE_H
-#define _PVGSMAMR_DECODER_INTERFACE_H
-
-/*----------------------------------------------------------------------------
-; ENUMERATED TYPEDEF'S
-----------------------------------------------------------------------------*/
-
-typedef enum
-{
-    /*
-     *    One word (2-byte) to indicate type of frame type.
-     *    One word (2-byte) to indicate frame type.
-     *    One word (2-byte) to indicate mode.
-     *    N words (2-byte) containing N bits (bit 0 = 0xff81, bit 1 = 0x007f).
-     */
-    ETS = 0, /* Both AMR-Narrowband and AMR-Wideband */
-
-    /*
-     *    One word (2-byte) for sync word (good frames: 0x6b21, bad frames: 0x6b20)
-     *    One word (2-byte) for frame length N.
-     *    N words (2-byte) containing N bits (bit 0 = 0x007f, bit 1 = 0x0081).
-     */
-    ITU, /* AMR-Wideband */
-
-    /*
-     *   AMR-WB MIME/storage format, see RFC 3267 (sections 5.1 and 5.3) for details
-     */
-    MIME_IETF,
-
-    WMF, /* AMR-Narrowband */
-
-    IF2  /* AMR-Narrowband */
-
-} bitstream_format;
-
-
-
-/*----------------------------------------------------------------------------
-; STRUCTURES TYPEDEF'S
-----------------------------------------------------------------------------*/
-typedef struct
-{
-    int16_t prev_ft;
-    int16_t prev_mode;
-} RX_State;
-
-
-typedef struct tPVAmrDecoderExternal
-{
-    /*
-     * INPUT:
-     * Pointer to the input buffer that contains the encoded bistream data.
-     * The data is filled in such that the first bit transmitted is
-     * the most-significant bit (MSB) of the first array element.
-     * The buffer is accessed in a linear fashion for speed, and the number of
-     * bytes consumed varies frame to frame. This is use for mime/ietf data
-     */
-    uint8_t  *pInputBuffer;
-
-    /*
-     * INPUT:
-     * Pointer to the input buffer that contains the encoded stream data.
-     * The data is filled such that the first bit transmitted is
-     * in the  first int16_t element.
-     * The buffer is accessed in a linear fashion for speed, and the number of
-     * bytes consumed varies frame to frame.
-     */
-    int16_t  *pInputSampleBuffer;
-
-    /*
-     * INPUT: (but what is pointed to is an output)
-     * Pointer to the output buffer to hold the 16-bit PCM audio samples.
-     */
-    int16_t  *pOutputBuffer;
-
-    /*
-     * INPUT:
-     * Number of requested output audio channels. This relieves the calling
-     * environment from having to perform stereo-to-mono or mono-to-stereo
-     * conversions.
-     */
-    int32_t     desiredChannels;
-
-    /*
-         * INPUT:
-         * Format type of the encoded bitstream.
-         */
-    bitstream_format     input_format;
-
-    /*
-     * OUTPUT:
-     * The sampling rate decoded from the bitstream, in units of
-     * samples/second. For this release of the library this value does
-     * not change from frame to frame, but future versions will.
-     */
-    int32_t   samplingRate;
-
-    /*
-     * OUTPUT:
-     * This value is the bitrate in units of bits/second. IT
-     * is calculated using the number of bits consumed for the current frame,
-     * and then multiplying by the sampling_rate, divided by points in a frame.
-     * This value can changes frame to frame.
-     */
-    int32_t   bitRate;
-
-    /*
-     * OUTPUT:
-     * The number of channels decoded from the bitstream. The output data
-     * will have be the amount specified in the variable desiredChannels,
-     * this output is informative only, and can be ignored.
-     */
-    int32_t     encodedChannels;
-
-    /*
-     * OUTPUT:
-     * This value is the number of output PCM samples per channel.
-     * It is  320.
-     */
-    int16_t     frameLength;
-
-    /*
-     * OUTPUT:
-     * This value is the quality indicator. 1 (good)  0 (bad)
-    */
-    uint8_t     quality;
-
-
-    /*
-     * OUTPUT:
-     *  GSM AMR NB and WB mode (i.e. bit-rate )
-     */
-    int16_t     mode;
-    int16_t     mode_old;
-
-    /*
-     * OUTPUT:
-     *  GSM AMR NB and WB frame type ( speech_good, speech_bad, sid, etc.)
-     */
-    int16_t     frame_type;
-
-    int16_t reset_flag;
-    int16_t reset_flag_old;
-
-    /*
-     * OUTPUT:
-     *  Decoder  status
-     */
-    int32_t     status;
-
-    /*
-     * OUTPUT:
-     *  Rx status state
-     */
-    RX_State  rx_state;
-
-} tPVAmrDecoderExternal;
-
-#endif
-
diff --git a/media/libstagefright/codecs/amrnb/dec/Android.mk b/media/libstagefright/codecs/amrnb/dec/Android.mk
index 5dc5560..b48a459 100644
--- a/media/libstagefright/codecs/amrnb/dec/Android.mk
+++ b/media/libstagefright/codecs/amrnb/dec/Android.mk
@@ -42,8 +42,7 @@
         frameworks/av/media/libstagefright/include \
         $(LOCAL_PATH)/src \
         $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/../common/include \
-        $(LOCAL_PATH)/../common
+        $(LOCAL_PATH)/../common/include
 
 LOCAL_CFLAGS := \
         -DOSCL_UNUSED_ARG= -DOSCL_IMPORT_REF=
@@ -66,7 +65,6 @@
         $(LOCAL_PATH)/src \
         $(LOCAL_PATH)/include \
         $(LOCAL_PATH)/../common/include \
-        $(LOCAL_PATH)/../common
 
 LOCAL_CFLAGS := -DOSCL_IMPORT_REF=
 
diff --git a/media/libstagefright/codecs/amrnb/dec/include/pvamrnbdecoder_api.h b/media/libstagefright/codecs/amrnb/dec/include/pvamrnbdecoder_api.h
deleted file mode 100644
index 7b94320..0000000
--- a/media/libstagefright/codecs/amrnb/dec/include/pvamrnbdecoder_api.h
+++ /dev/null
@@ -1,122 +0,0 @@
-/* ------------------------------------------------------------------
- * Copyright (C) 1998-2009 PacketVideo
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
- * express or implied.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- * -------------------------------------------------------------------
- */
-/****************************************************************************************
-Portions of this file are derived from the following 3GPP standard:
-
-    3GPP TS 26.073
-    ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
-    Available from http://www.3gpp.org
-
-(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
-Permission to distribute, modify and use this file under the standard license
-terms listed above has been obtained from the copyright holder.
-****************************************************************************************/
-/*
- Name: pvamrnbdecoder_api.h
-
-------------------------------------------------------------------------------
- REVISION HISTORY
-
-
- Who:                                       Date:
- Description:
-
-------------------------------------------------------------------------------
- INCLUDE DESCRIPTION
-
- Main header file for the Packet Video AMR Narrow  Band  decoder library. The
- constants, structures, and functions defined within this file, along with
- a basic data types header file, is all that is needed to use and communicate
- with the library. The internal data structures within the library are
- purposely hidden.
-
-------------------------------------------------------------------------------
- REFERENCES
-
-------------------------------------------------------------------------------
-*/
-
-/*----------------------------------------------------------------------------
-; CONTINUE ONLY IF NOT ALREADY DEFINED
-----------------------------------------------------------------------------*/
-#ifndef _PVAMRNBDECODER_API_H
-#define _PVAMRNBDECODER_API_H
-
-#include    "pvgsmamrdecoderinterface.h"
-
-
-/*----------------------------------------------------------------------------
-; INCLUDES
-----------------------------------------------------------------------------*/
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-    /*----------------------------------------------------------------------------
-    ; MACROS
-    ; Define module specific macros here
-    ----------------------------------------------------------------------------*/
-
-    /*----------------------------------------------------------------------------
-    ; DEFINES
-    ; Include all pre-processor statements here.
-    ----------------------------------------------------------------------------*/
-#define MAX_NUM_FRAMES_PER_PACKET 20 /* Max number of frames per packet */
-
-#define MAX_NUM_PACKED_INPUT_BYTES 32 /* Max number of packed input bytes */
-
-#define L_FRAME      160
-
-    /*----------------------------------------------------------------------------
-    ; EXTERNAL VARIABLES REFERENCES
-    ; Declare variables used in this module but defined elsewhere
-    ----------------------------------------------------------------------------*/
-
-    /*----------------------------------------------------------------------------
-    ; SIMPLE TYPEDEF'S
-    ----------------------------------------------------------------------------*/
-
-    /*----------------------------------------------------------------------------
-    ; ENUMERATED TYPEDEF'S
-    ----------------------------------------------------------------------------*/
-
-    /*----------------------------------------------------------------------------
-    ; STRUCTURES TYPEDEF'S
-    ----------------------------------------------------------------------------*/
-
-
-    /*----------------------------------------------------------------------------
-    ; GLOBAL FUNCTION DEFINITIONS
-    ; Function Prototype declaration
-    ----------------------------------------------------------------------------*/
-
-
-
-    /*----------------------------------------------------------------------------
-    ; END
-    ----------------------------------------------------------------------------*/
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif  /* PVMP4AUDIODECODER_API_H */
-
-
diff --git a/media/libstagefright/codecs/amrnb/dec/src/amrdecode.h b/media/libstagefright/codecs/amrnb/dec/src/amrdecode.h
index db951b9..0988e17f 100644
--- a/media/libstagefright/codecs/amrnb/dec/src/amrdecode.h
+++ b/media/libstagefright/codecs/amrnb/dec/src/amrdecode.h
@@ -106,7 +106,6 @@
 #include    "typedef.h"
 #include    "mode.h"
 #include    "frame_type_3gpp.h"
-#include    "pvamrnbdecoder_api.h"
 
 /*--------------------------------------------------------------------------*/
 #ifdef __cplusplus
diff --git a/media/libstagefright/codecs/amrnb/dec/src/gsmamr_dec.h b/media/libstagefright/codecs/amrnb/dec/src/gsmamr_dec.h
index a9fdb1c..8f54ee8 100644
--- a/media/libstagefright/codecs/amrnb/dec/src/gsmamr_dec.h
+++ b/media/libstagefright/codecs/amrnb/dec/src/gsmamr_dec.h
@@ -86,7 +86,6 @@
 ----------------------------------------------------------------------------*/
 
 #include "gsm_amr_typedefs.h"
-#include "pvamrnbdecoder_api.h"
 #include "frame_type_3gpp.h"
 
 /*--------------------------------------------------------------------------*/
diff --git a/media/libstagefright/codecs/amrnb/dec/src/post_pro.cpp b/media/libstagefright/codecs/amrnb/dec/src/post_pro.cpp
index ce31793..8201e54 100644
--- a/media/libstagefright/codecs/amrnb/dec/src/post_pro.cpp
+++ b/media/libstagefright/codecs/amrnb/dec/src/post_pro.cpp
@@ -376,7 +376,7 @@
         L_tmp += ((Word32) st->x0) * c_b0;
         L_tmp += ((Word32) st->x1) * c_b1;
         L_tmp += ((Word32) x2) * c_b2;
-        L_tmp <<= 3;
+        L_tmp = L_shl(L_tmp, 3, pOverflow);
 
 
         /* Multiplication by two of output speech with saturation. */
diff --git a/media/libstagefright/codecs/amrnb/dec/src/pvgsmamrdecoder.cpp b/media/libstagefright/codecs/amrnb/dec/src/pvgsmamrdecoder.cpp
deleted file mode 100644
index 95b0b47..0000000
--- a/media/libstagefright/codecs/amrnb/dec/src/pvgsmamrdecoder.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/* ------------------------------------------------------------------
- * Copyright (C) 1998-2009 PacketVideo
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
- * express or implied.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- * -------------------------------------------------------------------
- */
-/****************************************************************************************
-Portions of this file are derived from the following 3GPP standard:
-
-    3GPP TS 26.073
-    ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
-    Available from http://www.3gpp.org
-
-(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
-Permission to distribute, modify and use this file under the standard license
-terms listed above has been obtained from the copyright holder.
-****************************************************************************************/
-
-#include "PVGSMAMRDecoder.h"
-
-
-/////////////////////////////////////////////////////////////////////////////
-OSCL_EXPORT_REF CPVGSMAMRDecoder::CPVGSMAMRDecoder()
-{
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-OSCL_EXPORT_REF CPVGSMAMRDecoder::~CPVGSMAMRDecoder()
-{
-    delete iDecState;
-    iDecState = NULL;
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-OSCL_EXPORT_REF int32 CPVGSMAMRDecoder::InitDecoder(void)
-{
-    return GSMInitDecode(&iDecState, (int8*)"Decoder");
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-OSCL_EXPORT_REF int32 CPVGSMAMRDecoder::DecodeFrame(Frame_Type_3GPP aType,
-        uint8* aCompressedBlock,
-        uint8* aAudioBuffer,
-        int32 aFormat)
-{
-    return AMRDecode(iDecState, aType, aCompressedBlock, (Word16*)aAudioBuffer, (Word16) aFormat);
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-OSCL_EXPORT_REF int32 CPVGSMAMRDecoder::ResetDecoder(void)
-{
-    return Speech_Decode_Frame_reset(iDecState);
-}
-
-
-/////////////////////////////////////////////////////////////////////////////
-OSCL_EXPORT_REF void CPVGSMAMRDecoder::TerminateDecoder(void)
-{
-    GSMDecodeFrameExit(&iDecState);
-    iDecState = NULL;
-}
-
diff --git a/media/libstagefright/codecs/amrnb/enc/Android.mk b/media/libstagefright/codecs/amrnb/enc/Android.mk
index d6e8b66..457656a 100644
--- a/media/libstagefright/codecs/amrnb/enc/Android.mk
+++ b/media/libstagefright/codecs/amrnb/enc/Android.mk
@@ -64,8 +64,7 @@
         frameworks/av/media/libstagefright/include \
         $(LOCAL_PATH)/src \
         $(LOCAL_PATH)/include \
-        $(LOCAL_PATH)/../common/include \
-        $(LOCAL_PATH)/../common
+        $(LOCAL_PATH)/../common/include
 
 LOCAL_CFLAGS := \
         -DOSCL_UNUSED_ARG=
diff --git a/media/libstagefright/codecs/amrnb/enc/src/g_pitch.cpp b/media/libstagefright/codecs/amrnb/enc/src/g_pitch.cpp
index f6235ad..5b80e2a 100644
--- a/media/libstagefright/codecs/amrnb/enc/src/g_pitch.cpp
+++ b/media/libstagefright/codecs/amrnb/enc/src/g_pitch.cpp
@@ -400,8 +400,9 @@
     }
     else
     {
-        s = 0;                      /* Avoid case of all zeros */
+        s = 0;  /* re-initialize calculations */
         p_y1 = &y1[0];
+        p_xn = &xn[0];
         for (i = (L_subfr >> 2); i != 0; i--)
         {
             L_temp = (Word32)(*(p_y1++) >> 2);
diff --git a/media/libstagefright/codecs/amrwbenc/Android.mk b/media/libstagefright/codecs/amrwbenc/Android.mk
index 71a60d3..edfd7b7 100644
--- a/media/libstagefright/codecs/amrwbenc/Android.mk
+++ b/media/libstagefright/codecs/amrwbenc/Android.mk
@@ -101,8 +101,6 @@
 	$(LOCAL_PATH)/src \
 	$(LOCAL_PATH)/inc
 
-LOCAL_CFLAGS := $(VO_CFLAGS)
-
 ifeq ($(VOTT), v5)
 LOCAL_CFLAGS += -DARM -DASM_OPT
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/asm/ARMV5E
diff --git a/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk b/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk
index 85ddceb..db34d08 100644
--- a/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk
+++ b/media/libstagefright/codecs/amrwbenc/SampleCode/Android.mk
@@ -10,7 +10,7 @@
 
 LOCAL_ARM_MODE := arm
 
-LOCAL_CFLAGS := $(VO_CFLAGS)
+LOCAL_CFLAGS := -DLINUX
 
 LOCAL_SHARED_LIBRARIES := \
     libstagefright \
diff --git a/media/libstagefright/codecs/amrwbenc/src/asm/ARMV5E/Filt_6k_7k_opt.s b/media/libstagefright/codecs/amrwbenc/src/asm/ARMV5E/Filt_6k_7k_opt.s
index 856ada8..8451195 100644
--- a/media/libstagefright/codecs/amrwbenc/src/asm/ARMV5E/Filt_6k_7k_opt.s
+++ b/media/libstagefright/codecs/amrwbenc/src/asm/ARMV5E/Filt_6k_7k_opt.s
@@ -43,7 +43,9 @@
           MOV     		r2, #30                     @ L_FIR - 1
           BL      		voAWB_Copy                   @ memcpy(x, mem, (L_FIR - 1)<<1)
 
-          LDR     		r10, Lable1                 @ get fir_7k address
+          ADR    		r3, Lable1                  @ get fir_7k address
+          LDR   		r10, [r3]
+          ADD   		r10, r3
 
           MOV           	r14, #0
           MOV                   r3, r8                      @ change myMemCopy to Copy, due to Copy will change r3 content
@@ -178,7 +180,7 @@
           LDMFD   		r13!, {r4 - r12, r15}
 
 Lable1:
-          .word   		fir_6k_7k
+          .word   		fir_6k_7k-Lable1
           @ENDFUNC
           .END
 
diff --git a/media/libstagefright/codecs/amrwbenc/src/asm/ARMV7/Filt_6k_7k_neon.s b/media/libstagefright/codecs/amrwbenc/src/asm/ARMV7/Filt_6k_7k_neon.s
index 14ba828..fc42a03 100644
--- a/media/libstagefright/codecs/amrwbenc/src/asm/ARMV7/Filt_6k_7k_neon.s
+++ b/media/libstagefright/codecs/amrwbenc/src/asm/ARMV7/Filt_6k_7k_neon.s
@@ -49,7 +49,9 @@
 
 
 
-          LDR     		r10, Lable1                 @ get fir_7k address
+          ADR     		r3, Lable1                  @ get fir_7k address
+          LDR    		r10, [r3]
+          ADD    		r10, r3
           MOV                   r3, r8                      @ change myMemCopy to Copy, due to Copy will change r3 content
           ADD     	    	r6, r13, #60                @ get x[L_FIR - 1] address
           MOV           	r7, r3                      @ get signal[i]
@@ -221,7 +223,7 @@
           LDMFD   		r13!, {r0 - r12, r15}
 
 Lable1:
-          .word   		fir_6k_7k
+          .word   		fir_6k_7k-Lable1
           @ENDFUNC
           .END
 
diff --git a/media/libstagefright/codecs/amrwbenc/src/asm/ARMV7/pred_lt4_1_neon.s b/media/libstagefright/codecs/amrwbenc/src/asm/ARMV7/pred_lt4_1_neon.s
index 6b782cb..8d2aaf2 100644
--- a/media/libstagefright/codecs/amrwbenc/src/asm/ARMV7/pred_lt4_1_neon.s
+++ b/media/libstagefright/codecs/amrwbenc/src/asm/ARMV7/pred_lt4_1_neon.s
@@ -40,7 +40,9 @@
           ADDLT         r2, r2, #4                                @ frac += UP_SAMP
           SUBLT         r4, r4, #2                                @ x--
 
-          LDR           r11, Lable1
+          ADR           r8, Lable1
+          LDR           r11, [r8]
+          ADD           r11, r8
           RSB           r2, r2, #3                                @ k = UP_SAMP - 1 - frac
           MOV           r8, #0                                    @ j = 0
 	  ADD           r11, r11, r2, LSL #6                      @ get inter4_2[k][]
@@ -94,7 +96,7 @@
           LDMFD   	r13!, {r4 - r12, r15}
 
 Lable1:
-          .word   	inter4_2
+          .word   	inter4_2-Lable1
           @ENDFUNC
           .END
 
diff --git a/media/libstagefright/codecs/avc/common/include/avcapi_common.h b/media/libstagefright/codecs/avc/common/include/avcapi_common.h
index 3331689..abffe6e 100644
--- a/media/libstagefright/codecs/avc/common/include/avcapi_common.h
+++ b/media/libstagefright/codecs/avc/common/include/avcapi_common.h
@@ -213,15 +213,15 @@
     memory usage.
 \param "size" "Size of requested memory in bytes."
 \param "attribute" "Some value specifying types, priority, etc. of the memory."
-\return "The address of the allocated memory casted to int"
+\return "The address of the allocated, zero-initialized memory"
 */
-typedef int (*FunctionType_Malloc)(void *userData, int32 size, int attribute);
+typedef void* (*FunctionType_Malloc)(void *userData, int32 size, int attribute);
 
 /** Function pointer to free
-\param "mem" "Pointer to the memory to be freed casted to int"
+\param "mem" "Pointer to the memory to be freed"
 \return "void"
 */
-typedef void (*FunctionType_Free)(void *userData, int mem);
+typedef void (*FunctionType_Free)(void *userData, void *mem);
 
 /** Debug logging information is returned to the application thru this function.
 \param "type"   "Type of logging message, see definition of AVCLogType."
diff --git a/media/libstagefright/codecs/avc/common/src/deblock.cpp b/media/libstagefright/codecs/avc/common/src/deblock.cpp
index 5ed4c82..de2d2b6 100644
--- a/media/libstagefright/codecs/avc/common/src/deblock.cpp
+++ b/media/libstagefright/codecs/avc/common/src/deblock.cpp
@@ -294,7 +294,8 @@
     int     filterLeftMbEdgeFlag = (mb_x != 0);
     int     filterTopMbEdgeFlag  = (mb_y != 0);
     int     pitch = video->currPic->pitch;
-    int     indexA, indexB, tmp;
+    int     indexA, indexB;
+    int     *tmp;
     int     Alpha, Beta, Alpha_c, Beta_c;
     int     mbNum = mb_y * video->PicWidthInMbs + mb_x;
     int     *clipTable, *clipTable_c, *qp_clip_tab;
@@ -386,7 +387,7 @@
     /* Save Alpha,  Beta and clipTable for future use, with the obselete variables filterLeftMbEdgeFlag, mbNum amd tmp */
     filterLeftMbEdgeFlag = Alpha;
     mbNum = Beta;
-    tmp = (int)clipTable;
+    tmp = clipTable;
 
     indexA = MbQ->QPc + video->FilterOffsetA;
     indexB = MbQ->QPc + video->FilterOffsetB;
@@ -486,7 +487,7 @@
     /* Note that Alpha_c, Beta_c and clipTable_c for chroma is already calculated */
     Alpha = filterLeftMbEdgeFlag;
     Beta = mbNum;
-    clipTable = (int *)tmp;
+    clipTable = tmp;
 
     GetStrength_HorizontalEdges(Strength + 4, MbQ); // Strength for 4 blks in 1 stripe, 0 => vertical edge
 
diff --git a/media/libstagefright/codecs/avc/common/src/dpb.cpp b/media/libstagefright/codecs/avc/common/src/dpb.cpp
index 2c4c7da..b5d0dfe 100644
--- a/media/libstagefright/codecs/avc/common/src/dpb.cpp
+++ b/media/libstagefright/codecs/avc/common/src/dpb.cpp
@@ -152,7 +152,7 @@
         framesize = (FrameHeightInMbs * PicWidthInMbs);
         if (video->mblock)
         {
-            avcHandle->CBAVC_Free(userData, (uint32)video->mblock);
+            avcHandle->CBAVC_Free(userData, video->mblock);
             video->mblock = NULL;
         }
         video->mblock = (AVCMacroblock*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCMacroblock) * framesize, DEFAULT_ATTR);
@@ -187,7 +187,7 @@
 
         if (video->MbToSliceGroupMap)
         {
-            avcHandle->CBAVC_Free(userData, (uint32)video->MbToSliceGroupMap);
+            avcHandle->CBAVC_Free(userData, video->MbToSliceGroupMap);
             video->MbToSliceGroupMap = NULL;
         }
         video->MbToSliceGroupMap = (int*) avcHandle->CBAVC_Malloc(userData, sizeof(uint) * PicSizeInMapUnits * 2, 7/*DEFAULT_ATTR*/);
@@ -212,14 +212,14 @@
     {
         if (dpb->fs[ii] != NULL)
         {
-            avcHandle->CBAVC_Free(userData, (int)dpb->fs[ii]);
+            avcHandle->CBAVC_Free(userData, dpb->fs[ii]);
             dpb->fs[ii] = NULL;
         }
     }
 #ifndef PV_MEMORY_POOL
     if (dpb->decoded_picture_buffer)
     {
-        avcHandle->CBAVC_Free(userData, (int)dpb->decoded_picture_buffer);
+        avcHandle->CBAVC_Free(userData, dpb->decoded_picture_buffer);
         dpb->decoded_picture_buffer = NULL;
     }
 #endif
diff --git a/media/libstagefright/codecs/avc/enc/Android.mk b/media/libstagefright/codecs/avc/enc/Android.mk
index 48923cf..845d1d3 100644
--- a/media/libstagefright/codecs/avc/enc/Android.mk
+++ b/media/libstagefright/codecs/avc/enc/Android.mk
@@ -28,7 +28,6 @@
     $(TOP)/frameworks/native/include/media/openmax
 
 LOCAL_CFLAGS := \
-    -D__arm__ \
     -DOSCL_IMPORT_REF= -DOSCL_UNUSED_ARG= -DOSCL_EXPORT_REF=
 
 include $(BUILD_STATIC_LIBRARY)
@@ -49,7 +48,6 @@
         $(LOCAL_PATH)/../common
 
 LOCAL_CFLAGS := \
-    -D__arm__ \
     -DOSCL_IMPORT_REF= -DOSCL_UNUSED_ARG= -DOSCL_EXPORT_REF=
 
 
diff --git a/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp b/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
index c6f658d..4133bdf 100644
--- a/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
+++ b/media/libstagefright/codecs/avc/enc/SoftAVCEncoder.cpp
@@ -131,13 +131,16 @@
     }
 }
 
-static int32_t MallocWrapper(
+static void* MallocWrapper(
         void *userData, int32_t size, int32_t attrs) {
-    return reinterpret_cast<int32_t>(malloc(size));
+    void *ptr = malloc(size);
+    if (ptr)
+        memset(ptr, 0, size);
+    return ptr;
 }
 
-static void FreeWrapper(void *userData, int32_t ptr) {
-    free(reinterpret_cast<void *>(ptr));
+static void FreeWrapper(void *userData, void* ptr) {
+    free(ptr);
 }
 
 static int32_t DpbAllocWrapper(void *userData,
@@ -843,12 +846,15 @@
         outQueue.erase(outQueue.begin());
         CHECK(!mInputBufferInfoVec.empty());
         InputBufferInfo *inputBufInfo = mInputBufferInfoVec.begin();
-        mInputBufferInfoVec.erase(mInputBufferInfoVec.begin());
         outHeader->nTimeStamp = inputBufInfo->mTimeUs;
         outHeader->nFlags |= (inputBufInfo->mFlags | OMX_BUFFERFLAG_ENDOFFRAME);
+        if (mSawInputEOS) {
+            outHeader->nFlags |= OMX_BUFFERFLAG_EOS;
+        }
         outHeader->nFilledLen = dataLength;
         outInfo->mOwnedByUs = false;
         notifyFillBufferDone(outHeader);
+        mInputBufferInfoVec.erase(mInputBufferInfoVec.begin());
     }
 }
 
diff --git a/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp b/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp
index d39885d..cf14e10 100644
--- a/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/avcenc_api.cpp
@@ -77,7 +77,6 @@
     }
 
     encvid = (AVCEncObject*) avcHandle->AVCObject;
-    memset(encvid, 0, sizeof(AVCEncObject)); /* reset everything */
 
     encvid->enc_state = AVCEnc_Initializing;
 
@@ -90,7 +89,6 @@
     }
 
     video = encvid->common;
-    memset(video, 0, sizeof(AVCCommonObj));
 
     /* allocate bitstream structure */
     encvid->bitstream = (AVCEncBitstream*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCEncBitstream), DEFAULT_ATTR);
@@ -106,7 +104,6 @@
     {
         return AVCENC_MEMORY_FAIL;
     }
-    memset(video->currSeqParams, 0, sizeof(AVCSeqParamSet));
 
     /* allocate picture parameter set structure */
     video->currPicParams = (AVCPicParamSet*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCPicParamSet), DEFAULT_ATTR);
@@ -114,7 +111,6 @@
     {
         return AVCENC_MEMORY_FAIL;
     }
-    memset(video->currPicParams, 0, sizeof(AVCPicParamSet));
 
     /* allocate slice header structure */
     video->sliceHdr = (AVCSliceHeader*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCSliceHeader), DEFAULT_ATTR);
@@ -122,7 +118,6 @@
     {
         return AVCENC_MEMORY_FAIL;
     }
-    memset(video->sliceHdr, 0, sizeof(AVCSliceHeader));
 
     /* allocate encoded picture buffer structure*/
     video->decPicBuf = (AVCDecPicBuffer*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCDecPicBuffer), DEFAULT_ATTR);
@@ -130,7 +125,6 @@
     {
         return AVCENC_MEMORY_FAIL;
     }
-    memset(video->decPicBuf, 0, sizeof(AVCDecPicBuffer));
 
     /* allocate rate control structure */
     encvid->rateCtrl = (AVCRateControl*) avcHandle->CBAVC_Malloc(userData, sizeof(AVCRateControl), DEFAULT_ATTR);
@@ -138,7 +132,6 @@
     {
         return AVCENC_MEMORY_FAIL;
     }
-    memset(encvid->rateCtrl, 0, sizeof(AVCRateControl));
 
     /* reset frame list, not really needed */
     video->currPic = NULL;
@@ -194,7 +187,6 @@
     {
         return AVCENC_MEMORY_FAIL;
     }
-    memset(encvid->mot16x16, 0, sizeof(AVCMV)*framesize);
 
     encvid->intraSearch = (uint8*) avcHandle->CBAVC_Malloc(userData, sizeof(uint8) * framesize, DEFAULT_ATTR);
     if (encvid->intraSearch == NULL)
@@ -573,7 +565,7 @@
     recon->pitch = currFS->frame.pitch;
     recon->disp_order = currFS->PicOrderCnt;
     recon->coding_order = currFS->FrameNum;
-    recon->id = (uint32) currFS->base_dpb; /* use the pointer as the id */
+    recon->id = (intptr_t) currFS->base_dpb; /* use the pointer as the id */
 
     currFS->IsOutputted |= 1;
 
@@ -610,32 +602,32 @@
 
         if (encvid->functionPointer != NULL)
         {
-            avcHandle->CBAVC_Free(userData, (int)encvid->functionPointer);
+            avcHandle->CBAVC_Free(userData, encvid->functionPointer);
         }
 
         if (encvid->min_cost)
         {
-            avcHandle->CBAVC_Free(userData, (int)encvid->min_cost);
+            avcHandle->CBAVC_Free(userData, encvid->min_cost);
         }
 
         if (encvid->intraSearch)
         {
-            avcHandle->CBAVC_Free(userData, (int)encvid->intraSearch);
+            avcHandle->CBAVC_Free(userData, encvid->intraSearch);
         }
 
         if (encvid->mot16x16)
         {
-            avcHandle->CBAVC_Free(userData, (int)encvid->mot16x16);
+            avcHandle->CBAVC_Free(userData, encvid->mot16x16);
         }
 
         if (encvid->rateCtrl)
         {
-            avcHandle->CBAVC_Free(userData, (int)encvid->rateCtrl);
+            avcHandle->CBAVC_Free(userData, encvid->rateCtrl);
         }
 
         if (encvid->overrunBuffer)
         {
-            avcHandle->CBAVC_Free(userData, (int)encvid->overrunBuffer);
+            avcHandle->CBAVC_Free(userData, encvid->overrunBuffer);
         }
 
         video = encvid->common;
@@ -643,45 +635,45 @@
         {
             if (video->MbToSliceGroupMap)
             {
-                avcHandle->CBAVC_Free(userData, (int)video->MbToSliceGroupMap);
+                avcHandle->CBAVC_Free(userData, video->MbToSliceGroupMap);
             }
             if (video->mblock != NULL)
             {
-                avcHandle->CBAVC_Free(userData, (int)video->mblock);
+                avcHandle->CBAVC_Free(userData, video->mblock);
             }
             if (video->decPicBuf != NULL)
             {
                 CleanUpDPB(avcHandle, video);
-                avcHandle->CBAVC_Free(userData, (int)video->decPicBuf);
+                avcHandle->CBAVC_Free(userData, video->decPicBuf);
             }
             if (video->sliceHdr != NULL)
             {
-                avcHandle->CBAVC_Free(userData, (int)video->sliceHdr);
+                avcHandle->CBAVC_Free(userData, video->sliceHdr);
             }
             if (video->currPicParams != NULL)
             {
                 if (video->currPicParams->slice_group_id)
                 {
-                    avcHandle->CBAVC_Free(userData, (int)video->currPicParams->slice_group_id);
+                    avcHandle->CBAVC_Free(userData, video->currPicParams->slice_group_id);
                 }
 
-                avcHandle->CBAVC_Free(userData, (int)video->currPicParams);
+                avcHandle->CBAVC_Free(userData, video->currPicParams);
             }
             if (video->currSeqParams != NULL)
             {
-                avcHandle->CBAVC_Free(userData, (int)video->currSeqParams);
+                avcHandle->CBAVC_Free(userData, video->currSeqParams);
             }
             if (encvid->bitstream != NULL)
             {
-                avcHandle->CBAVC_Free(userData, (int)encvid->bitstream);
+                avcHandle->CBAVC_Free(userData, encvid->bitstream);
             }
             if (video != NULL)
             {
-                avcHandle->CBAVC_Free(userData, (int)video);
+                avcHandle->CBAVC_Free(userData, video);
             }
         }
 
-        avcHandle->CBAVC_Free(userData, (int)encvid);
+        avcHandle->CBAVC_Free(userData, encvid);
 
         avcHandle->AVCObject = NULL;
     }
diff --git a/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp b/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp
index 75ab514..0e3037f 100644
--- a/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp
@@ -275,8 +275,8 @@
                 // allocate new overrun Buffer
                 if (encvid->overrunBuffer)
                 {
-                    encvid->avcHandle->CBAVC_Free((uint32*)encvid->avcHandle->userData,
-                                                  (int)encvid->overrunBuffer);
+                    encvid->avcHandle->CBAVC_Free(encvid->avcHandle->userData,
+                                                  encvid->overrunBuffer);
                 }
 
                 encvid->oBSize = stream->oBSize;
@@ -314,8 +314,8 @@
             // copy from the old buffer to new buffer
             memcpy(encvid->overrunBuffer, stream->overrunBuffer, stream->write_pos);
             // free old buffer
-            encvid->avcHandle->CBAVC_Free((uint32*)encvid->avcHandle->userData,
-                                          (int)stream->overrunBuffer);
+            encvid->avcHandle->CBAVC_Free(encvid->avcHandle->userData,
+                                          stream->overrunBuffer);
 
             // assign pointer to new buffer
             stream->overrunBuffer = encvid->overrunBuffer;
diff --git a/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp b/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
index ac62d78..a390f88 100644
--- a/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/motion_comp.cpp
@@ -198,7 +198,7 @@
     out_offset = 24 - blkwidth;
 
     //switch(x_pos&0x3){
-    switch (((uint32)ref)&0x3)
+    switch (((intptr_t)ref)&0x3)
     {
         case 1:
             offset =  picpitch - blkwidth - 3;
@@ -268,9 +268,9 @@
 void eHorzInterp1MC(uint8 *in, int inpitch, uint8 *out, int outpitch,
                     int blkwidth, int blkheight, int dx)
 {
-    uint8 *p_ref;
+    uint8 *p_ref, *tmp;
     uint32 *p_cur;
-    uint32 tmp, pkres;
+    uint32 pkres;
     int result, curr_offset, ref_offset;
     int j;
     int32 r0, r1, r2, r3, r4, r5;
@@ -288,14 +288,14 @@
         r13 = 0;
         for (j = blkheight; j > 0; j--)
         {
-            tmp = (uint32)(p_ref + blkwidth);
+            tmp = p_ref + blkwidth;
             r0 = p_ref[0];
             r1 = p_ref[2];
             r0 |= (r1 << 16);           /* 0,c,0,a */
             r1 = p_ref[1];
             r2 = p_ref[3];
             r1 |= (r2 << 16);           /* 0,d,0,b */
-            while ((uint32)p_ref < tmp)
+            while (p_ref < tmp)
             {
                 r2 = *(p_ref += 4); /* move pointer to e */
                 r3 = p_ref[2];
@@ -360,8 +360,8 @@
                 p_ref -= (ref_offset + blkwidth);   /* input */
                 p_cur -= (outpitch >> 2);
 
-                tmp = (uint32)(p_ref + blkwidth);
-                for (; (uint32)p_ref < tmp;)
+                tmp = p_ref + blkwidth;
+                for (; p_ref < tmp;)
                 {
 
                     r0 = *p_ref++;
@@ -434,14 +434,14 @@
         r13 = 0;
         for (j = blkheight; j > 0; j--)
         {
-            tmp = (uint32)(p_ref + blkwidth);
+            tmp = p_ref + blkwidth;
             r0 = p_ref[0];
             r1 = p_ref[2];
             r0 |= (r1 << 16);           /* 0,c,0,a */
             r1 = p_ref[1];
             r2 = p_ref[3];
             r1 |= (r2 << 16);           /* 0,d,0,b */
-            while ((uint32)p_ref < tmp)
+            while (p_ref < tmp)
             {
                 r2 = *(p_ref += 4); /* move pointer to e */
                 r3 = p_ref[2];
@@ -494,8 +494,8 @@
                 p_ref -= (ref_offset + blkwidth);   /* input */
                 p_cur -= (outpitch >> 2);
 
-                tmp = (uint32)(p_ref + blkwidth);
-                for (; (uint32)p_ref < tmp;)
+                tmp = p_ref + blkwidth;
+                for (; p_ref < tmp;)
                 {
 
                     r0 = *p_ref++;
@@ -558,9 +558,9 @@
 void eHorzInterp2MC(int *in, int inpitch, uint8 *out, int outpitch,
                     int blkwidth, int blkheight, int dx)
 {
-    int *p_ref;
+    int *p_ref, *tmp;
     uint32 *p_cur;
-    uint32 tmp, pkres;
+    uint32 pkres;
     int result, result2, curr_offset, ref_offset;
     int j, r0, r1, r2, r3, r4, r5;
 
@@ -575,8 +575,8 @@
 
         for (j = blkheight; j > 0 ; j--)
         {
-            tmp = (uint32)(p_ref + blkwidth);
-            for (; (uint32)p_ref < tmp;)
+            tmp = p_ref + blkwidth;
+            for (; p_ref < tmp;)
             {
 
                 r0 = p_ref[-2];
@@ -654,8 +654,8 @@
     {
         for (j = blkheight; j > 0 ; j--)
         {
-            tmp = (uint32)(p_ref + blkwidth);
-            for (; (uint32)p_ref < tmp;)
+            tmp = p_ref + blkwidth;
+            for (; p_ref < tmp;)
             {
 
                 r0 = p_ref[-2];
@@ -717,9 +717,8 @@
 void eHorzInterp3MC(uint8 *in, int inpitch, int *out, int outpitch,
                     int blkwidth, int blkheight)
 {
-    uint8 *p_ref;
+    uint8 *p_ref, *tmp;
     int   *p_cur;
-    uint32 tmp;
     int result, curr_offset, ref_offset;
     int j, r0, r1, r2, r3, r4, r5;
 
@@ -730,8 +729,8 @@
 
     for (j = blkheight; j > 0 ; j--)
     {
-        tmp = (uint32)(p_ref + blkwidth);
-        for (; (uint32)p_ref < tmp;)
+        tmp = p_ref + blkwidth;
+        for (; p_ref < tmp;)
         {
 
             r0 = p_ref[-2];
@@ -782,15 +781,14 @@
 void eVertInterp1MC(uint8 *in, int inpitch, uint8 *out, int outpitch,
                     int blkwidth, int blkheight, int dy)
 {
-    uint8 *p_cur, *p_ref;
-    uint32 tmp;
+    uint8 *p_cur, *p_ref, *tmp;
     int result, curr_offset, ref_offset;
     int j, i;
     int32 r0, r1, r2, r3, r4, r5, r6, r7, r8, r13;
     uint8  tmp_in[24][24];
 
     /* not word-aligned */
-    if (((uint32)in)&0x3)
+    if (((intptr_t)in)&0x3)
     {
         eCreateAlign(in, inpitch, -2, &tmp_in[0][0], blkwidth, blkheight + 5);
         in = &tmp_in[2][0];
@@ -811,8 +809,8 @@
             r13 = 0;
             p_ref = in;
             p_cur -= outpitch;  /* compensate for the first offset */
-            tmp = (uint32)(p_ref + ref_offset); /* limit */
-            while ((uint32)p_ref < tmp)  /* the loop un-rolled  */
+            tmp = p_ref + ref_offset; /* limit */
+            while (p_ref < tmp)  /* the loop un-rolled  */
             {
                 r0 = *((uint32*)(p_ref - (inpitch << 1))); /* load 4 bytes */
                 p_ref += inpitch;
@@ -885,8 +883,8 @@
                     p_ref = in + i;
                     p_cur -= outpitch;  /* compensate for the first offset */
 
-                    tmp = (uint32)(p_ref + ref_offset); /* limit */
-                    while ((uint32)p_ref < tmp)
+                    tmp = p_ref + ref_offset; /* limit */
+                    while (p_ref < tmp)
                     {                           /* loop un-rolled */
                         r0 = *(p_ref - (inpitch << 1));
                         r1 = *(p_ref - inpitch);
@@ -959,8 +957,8 @@
             r13 = 0;
             p_ref = in;
             p_cur -= outpitch;  /* compensate for the first offset */
-            tmp = (uint32)(p_ref + ref_offset); /* limit */
-            while ((uint32)p_ref < tmp)  /* the loop un-rolled  */
+            tmp = p_ref + ref_offset; /* limit */
+            while (p_ref < tmp)  /* the loop un-rolled  */
             {
                 r0 = *((uint32*)(p_ref - (inpitch << 1))); /* load 4 bytes */
                 p_ref += inpitch;
@@ -1023,8 +1021,8 @@
                 {
                     p_ref = in + i;
                     p_cur -= outpitch;  /* compensate for the first offset */
-                    tmp = (uint32)(p_ref + ref_offset); /* limit */
-                    while ((uint32)p_ref < tmp)
+                    tmp = p_ref + ref_offset; /* limit */
+                    while (p_ref < tmp)
                     {                           /* loop un-rolled */
                         r0 = *(p_ref - (inpitch << 1));
                         r1 = *(p_ref - inpitch);
@@ -1086,8 +1084,7 @@
                     int blkwidth, int blkheight)
 {
     int *p_cur;
-    uint8 *p_ref;
-    uint32 tmp;
+    uint8 *p_ref, *tmp;
     int result, curr_offset, ref_offset;
     int j, r0, r1, r2, r3, r4, r5;
 
@@ -1100,8 +1097,8 @@
         p_cur -= outpitch; /* compensate for the first offset */
         p_ref = in++;
 
-        tmp = (uint32)(p_ref + ref_offset); /* limit */
-        while ((uint32)p_ref < tmp)
+        tmp = p_ref + ref_offset; /* limit */
+        while (p_ref < tmp)
         {                           /* loop un-rolled */
             r0 = *(p_ref - (inpitch << 1));
             r1 = *(p_ref - inpitch);
@@ -1152,8 +1149,7 @@
                     int blkwidth, int blkheight, int dy)
 {
     uint8 *p_cur;
-    int *p_ref;
-    uint32 tmp;
+    int *p_ref, *tmp;
     int result, result2, curr_offset, ref_offset;
     int j, r0, r1, r2, r3, r4, r5;
 
@@ -1170,8 +1166,8 @@
             p_cur -= outpitch; /* compensate for the first offset */
             p_ref = in++;
 
-            tmp = (uint32)(p_ref + ref_offset); /* limit */
-            while ((uint32)p_ref < tmp)
+            tmp = p_ref + ref_offset; /* limit */
+            while (p_ref < tmp)
             {                           /* loop un-rolled */
                 r0 = *(p_ref - (inpitch << 1));
                 r1 = *(p_ref - inpitch);
@@ -1250,8 +1246,8 @@
             p_cur -= outpitch; /* compensate for the first offset */
             p_ref = in++;
 
-            tmp = (uint32)(p_ref + ref_offset); /* limit */
-            while ((uint32)p_ref < tmp)
+            tmp = p_ref + ref_offset; /* limit */
+            while (p_ref < tmp)
             {                           /* loop un-rolled */
                 r0 = *(p_ref - (inpitch << 1));
                 r1 = *(p_ref - inpitch);
@@ -1313,11 +1309,11 @@
 {
     int j, i;
     int result;
-    uint8 *p_cur, *p_ref, *p_tmp8;
+    uint8 *p_cur, *p_ref, *p_tmp8, *tmp;
     int curr_offset, ref_offset;
     uint8 tmp_res[24][24], tmp_in[24][24];
     uint32 *p_tmp;
-    uint32 tmp, pkres, tmp_result;
+    uint32 pkres, tmp_result;
     int32 r0, r1, r2, r3, r4, r5;
     int32 r6, r7, r8, r9, r10, r13;
 
@@ -1337,7 +1333,7 @@
     for (j = blkheight; j > 0; j--)
     {
         r13 = 0;
-        tmp = (uint32)(p_ref + blkwidth);
+        tmp = p_ref + blkwidth;
 
         //r0 = *((uint32*)p_ref);   /* d,c,b,a */
         //r1 = (r0>>8)&0xFF00FF;    /* 0,d,0,b */
@@ -1350,7 +1346,7 @@
         r2 = p_ref[3];
         r1 |= (r2 << 16);           /* 0,d,0,b */
 
-        while ((uint32)p_ref < tmp)
+        while (p_ref < tmp)
         {
             //r2 = *((uint32*)(p_ref+=4));/* h,g,f,e */
             //r3 = (r2>>8)&0xFF00FF;  /* 0,h,0,f */
@@ -1406,8 +1402,8 @@
             /* move back to the beginning of the line */
             p_ref -= (ref_offset + blkwidth);   /* input */
             p_tmp -= 6; /* intermediate output */
-            tmp = (uint32)(p_ref + blkwidth);
-            while ((uint32)p_ref < tmp)
+            tmp = p_ref + blkwidth;
+            while (p_ref < tmp)
             {
                 r0 = *p_ref++;
                 r1 = *p_ref++;
@@ -1465,7 +1461,7 @@
 
     /*  perform vertical interpolation */
     /* not word-aligned */
-    if (((uint32)in2)&0x3)
+    if (((intptr_t)in2)&0x3)
     {
         eCreateAlign(in2, inpitch, -2, &tmp_in[0][0], blkwidth, blkheight + 5);
         in2 = &tmp_in[2][0];
@@ -1485,8 +1481,8 @@
         p_tmp8 = &(tmp_res[0][j]); /* intermediate result */
         p_tmp8 -= 24;  /* compensate for the first offset */
         p_cur -= outpitch;  /* compensate for the first offset */
-        tmp = (uint32)(p_ref + pkres); /* limit */
-        while ((uint32)p_ref < tmp)  /* the loop un-rolled  */
+        tmp = p_ref + pkres; /* limit */
+        while (p_ref < tmp)  /* the loop un-rolled  */
         {
             /* Read 1 byte at a time is too slow, too many read and pack ops, need to call CreateAlign */
             /*p_ref8 = p_ref-(inpitch<<1);          r0 = p_ref8[0];         r1 = p_ref8[2];
@@ -1579,8 +1575,8 @@
                 p_tmp8 = &(tmp_res[0][j+i]); /* intermediate result */
                 p_tmp8 -= 24;  /* compensate for the first offset */
                 p_cur -= outpitch;  /* compensate for the first offset */
-                tmp = (uint32)(p_ref + pkres); /* limit */
-                while ((uint32)p_ref < tmp)  /* the loop un-rolled  */
+                tmp = p_ref + pkres; /* limit */
+                while (p_ref < tmp)  /* the loop un-rolled  */
                 {
                     r0 = *(p_ref - (inpitch << 1));
                     r1 = *(p_ref - inpitch);
@@ -1659,7 +1655,7 @@
     uint32 temp;
     uint8 byte;
 
-    if (((uint32)in)&3)
+    if (((intptr_t)in)&3)
     {
         for (j = blkheight; j > 0; j--)
         {
@@ -1720,7 +1716,7 @@
         else start = ref + x_pos;
 
         /* word-align start */
-        offset = (uint32)start & 0x3;
+        offset = (intptr_t)start & 0x3;
         if (offset) start -= offset;
 
         word1 = *((uint32*)start);
@@ -1746,7 +1742,7 @@
         else    start = ref + picpitch * (picheight - 1) + x_pos;
 
         /* word-align start */
-        offset = (uint32)start & 0x3;
+        offset = (intptr_t)start & 0x3;
         if (offset) start -= offset;
 
         word1 = *((uint32*)start);
@@ -2121,7 +2117,7 @@
     uint16 temp;
     uint8 byte;
 
-    if (((uint32)pRef)&1)
+    if (((intptr_t)pRef)&1)
     {
         for (j = blkheight; j > 0; j--)
         {
diff --git a/media/libstagefright/codecs/avc/enc/src/motion_est.cpp b/media/libstagefright/codecs/avc/enc/src/motion_est.cpp
index f650ef9..00c56c8 100644
--- a/media/libstagefright/codecs/avc/enc/src/motion_est.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/motion_est.cpp
@@ -176,7 +176,7 @@
 
     if (encvid->mvbits_array)
     {
-        avcHandle->CBAVC_Free(avcHandle->userData, (int)(encvid->mvbits_array));
+        avcHandle->CBAVC_Free(avcHandle->userData, encvid->mvbits_array);
         encvid->mvbits = NULL;
     }
 
diff --git a/media/libstagefright/codecs/avc/enc/src/rate_control.cpp b/media/libstagefright/codecs/avc/enc/src/rate_control.cpp
index 15b55fb..aa13873 100644
--- a/media/libstagefright/codecs/avc/enc/src/rate_control.cpp
+++ b/media/libstagefright/codecs/avc/enc/src/rate_control.cpp
@@ -190,7 +190,6 @@
         {
             goto CLEANUP_RC;
         }
-        memset(rateCtrl->pMP, 0, sizeof(MultiPass));
         rateCtrl->pMP->encoded_frames = -1; /* forget about the very first I frame */
 
         /* RDInfo **pRDSamples */
@@ -207,7 +206,6 @@
             {
                 goto CLEANUP_RC;
             }
-            for (j = 0; j < 32; j++)    memset(&(rateCtrl->pMP->pRDSamples[i][j]), 0, sizeof(RDInfo));
         }
         rateCtrl->pMP->frameRange = (int)(rateCtrl->frame_rate * 1.0); /* 1.0s time frame*/
         rateCtrl->pMP->frameRange = AVC_MAX(rateCtrl->pMP->frameRange, 5);
@@ -300,7 +298,7 @@
 
     if (rateCtrl->MADofMB)
     {
-        avcHandle->CBAVC_Free(avcHandle->userData, (int)(rateCtrl->MADofMB));
+        avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->MADofMB);
     }
 
     if (rateCtrl->pMP)
@@ -311,12 +309,12 @@
             {
                 if (rateCtrl->pMP->pRDSamples[i])
                 {
-                    avcHandle->CBAVC_Free(avcHandle->userData, (int)rateCtrl->pMP->pRDSamples[i]);
+                    avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP->pRDSamples[i]);
                 }
             }
-            avcHandle->CBAVC_Free(avcHandle->userData, (int)rateCtrl->pMP->pRDSamples);
+            avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP->pRDSamples);
         }
-        avcHandle->CBAVC_Free(avcHandle->userData, (int)(rateCtrl->pMP));
+        avcHandle->CBAVC_Free(avcHandle->userData, rateCtrl->pMP);
     }
 
     return ;
diff --git a/media/libstagefright/codecs/avc/enc/src/sad_halfpel_inline.h b/media/libstagefright/codecs/avc/enc/src/sad_halfpel_inline.h
index 3a21647..22f545a 100644
--- a/media/libstagefright/codecs/avc/enc/src/sad_halfpel_inline.h
+++ b/media/libstagefright/codecs/avc/enc/src/sad_halfpel_inline.h
@@ -24,7 +24,9 @@
 {
 #endif
 
-#if defined(__GNUC__) && defined(__arm__) /* ARM GNU COMPILER  */
+/* Intentionally not using the gcc asm version, since it is
+ * slightly slower than the plain C version on modern GCC versions. */
+#if !defined(__CC_ARM) /* Generic C version */
 
     __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
     {
@@ -74,14 +76,26 @@
 
     __inline int32 INTERP1_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
     {
-__asm__ volatile("rsbs	%1, %1, %2, asr #1\n\trsbmi %1, %1, #0\n\tadd  %0, %0, %1": "=r"(sad), "=r"(tmp): "r"(tmp2));
+        __asm__ volatile(
+            "rsbs       %1, %1, %2, asr #1\n\t"
+            "rsbmi      %1, %1, #0\n\t"
+            "add        %0, %0, %1"
+            : "+r"(sad), "+r"(tmp)
+            : "r"(tmp2)
+        );
 
         return sad;
     }
 
     __inline int32 INTERP2_SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
     {
-__asm__ volatile("rsbs	%1, %2, %1, asr #2\n\trsbmi %1, %1, #0\n\tadd	%0, %0, %1": "=r"(sad), "=r"(tmp): "r"(tmp2));
+        __asm__ volatile(
+            "rsbs       %1, %2, %1, asr #2\n\t"
+            "rsbmi      %1, %1, #0\n\t"
+            "add        %0, %0, %1"
+            : "+r"(sad), "+r"(tmp)
+            : "r"(tmp2)
+        );
 
         return sad;
     }
diff --git a/media/libstagefright/codecs/avc/enc/src/sad_inline.h b/media/libstagefright/codecs/avc/enc/src/sad_inline.h
index f39794f..47abc65 100644
--- a/media/libstagefright/codecs/avc/enc/src/sad_inline.h
+++ b/media/libstagefright/codecs/avc/enc/src/sad_inline.h
@@ -23,7 +23,9 @@
 {
 #endif
 
-#if defined(__GNUC__) && defined(__arm__) /* ARM GNU COMPILER  */
+/* Intentionally not using the gcc asm version, since it is
+ * slightly slower than the plain C version on modern GCC versions. */
+#if !defined(__CC_ARM) /* Generic C version */
 
     __inline int32 SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
     {
@@ -80,7 +82,7 @@
 
         x9 = 0x80808080; /* const. */
 
-        x8 = (uint32)ref & 0x3;
+        x8 = (intptr_t)ref & 0x3;
         if (x8 == 3)
             goto SadMBOffset3;
         if (x8 == 2)
@@ -340,7 +342,13 @@
 
     __inline int32 SUB_SAD(int32 sad, int32 tmp, int32 tmp2)
     {
-__asm__ volatile("rsbs	%1, %1, %2\n\trsbmi %1, %1, #0\n\tadd	%0, %0, %1": "=r"(sad): "r"(tmp), "r"(tmp2));
+        __asm__ volatile(
+            "rsbs       %1, %1, %2\n\t"
+            "rsbmi      %1, %1, #0\n\t"
+            "add        %0, %0, %1"
+            : "+r"(sad), "+r"(tmp)
+            : "r"(tmp2)
+        );
         return sad;
     }
 
@@ -348,7 +356,18 @@
     {
         int32 x7;
 
-__asm__ volatile("EOR	%1, %2, %0\n\tSUBS  %0, %2, %0\n\tEOR	%1, %1, %0\n\tAND  %1, %3, %1, lsr #1\n\tORRCC	%1, %1, #0x80000000\n\tRSB  %1, %1, %1, lsl #8\n\tADD  %0, %0, %1, asr #7\n\tEOR  %0, %0, %1, asr #7": "=r"(src1), "=&r"(x7): "r"(src2), "r"(mask));
+        __asm__ volatile(
+            "EOR        %1, %2, %0\n\t"
+            "SUBS       %0, %2, %0\n\t"
+            "EOR        %1, %1, %0\n\t"
+            "AND        %1, %3, %1, lsr #1\n\t"
+            "ORRCC      %1, %1, #0x80000000\n\t"
+            "RSB        %1, %1, %1, lsl #8\n\t"
+            "ADD        %0, %0, %1, asr #7\n\t"
+            "EOR        %0, %0, %1, asr #7"
+            : "+r"(src1), "=&r"(x7)
+            : "r"(src2), "r"(mask)
+        );
 
         return src1;
     }
@@ -357,12 +376,31 @@
     {
         int32 x7;
 
-__asm__ volatile("EOR	%1, %2, %0\n\tADDS  %0, %2, %0\n\tEOR  %1, %1, %0\n\tANDS  %1, %3, %1, rrx\n\tRSB  %1, %1, %1, lsl #8\n\tSUB	%0, %0, %1, asr #7\n\tEOR   %0, %0, %1, asr #7": "=r"(src1), "=&r"(x7): "r"(src2), "r"(mask));
+        __asm__ volatile(
+            "EOR        %1, %2, %0\n\t"
+            "ADDS       %0, %2, %0\n\t"
+            "EOR        %1, %1, %0\n\t"
+            "ANDS       %1, %3, %1, rrx\n\t"
+            "RSB        %1, %1, %1, lsl #8\n\t"
+            "SUB        %0, %0, %1, asr #7\n\t"
+            "EOR        %0, %0, %1, asr #7"
+            : "+r"(src1), "=&r"(x7)
+            : "r"(src2), "r"(mask)
+        );
 
         return src1;
     }
 
-#define sum_accumulate  __asm__ volatile("SBC  %0, %0, %1\n\tBIC   %1, %4, %1\n\tADD   %2, %2, %1, lsr #8\n\tSBC   %0, %0, %3\n\tBIC   %3, %4, %3\n\tADD   %2, %2, %3, lsr #8": "=&r" (x5), "=&r" (x10), "=&r" (x4), "=&r" (x11): "r" (x6));
+#define sum_accumulate  __asm__ volatile(              \
+    "SBC   %0, %0, %1\n\t"                             \
+    "BIC   %1, %4, %1\n\t"                             \
+    "ADD   %2, %2, %1, lsr #8\n\t"                     \
+    "SBC   %0, %0, %3\n\t"                             \
+    "BIC   %3, %4, %3\n\t"                             \
+    "ADD   %2, %2, %3, lsr #8"                         \
+    : "+r" (x5), "+r" (x10), "+r" (x4), "+r" (x11)     \
+    : "r" (x6)                                         \
+    );
 
 #define NUMBER 3
 #define SHIFT 24
@@ -404,7 +442,7 @@
 
         x8 = 16;
 ///
-__asm__ volatile("MVN	%0, #0xFF00": "=r"(x6));
+        __asm__ volatile("MVN   %0, #0xFF00": "=r"(x6));
 
 LOOP_SAD0:
         /****** process 8 pixels ******/
@@ -428,10 +466,10 @@
 
         /****** process 8 pixels ******/
         x11 = *((int32*)(ref + 4));
-__asm__ volatile("LDR	%0, [%1], %2": "=&r"(x10), "=r"(ref): "r"(lx));
+        __asm__ volatile("LDR   %0, [%1], %2": "=&r"(x10), "+r"(ref): "r"(lx));
         //x10 = *((int32*)ref); ref+=lx;
         x14 = *((int32*)(blk + 4));
-__asm__ volatile("LDR	%0, [%1], #16": "=&r"(x12), "=r"(blk));
+        __asm__ volatile("LDR   %0, [%1], #16": "=&r"(x12), "+r"(blk));
 
         /* process x11 & x14 */
         x11 = sad_4pixel(x11, x14, x9);
diff --git a/media/libstagefright/codecs/avc/enc/src/sad_mb_offset.h b/media/libstagefright/codecs/avc/enc/src/sad_mb_offset.h
index d5d4a42..20ca7eb 100644
--- a/media/libstagefright/codecs/avc/enc/src/sad_mb_offset.h
+++ b/media/libstagefright/codecs/avc/enc/src/sad_mb_offset.h
@@ -16,7 +16,9 @@
  * -------------------------------------------------------------------
  */
 
-#if defined(__GNUC__) && defined(__arm__) /* ARM GNU COMPILER  */
+/* Intentionally not using the gcc asm version, since it is
+ * slightly slower than the plain C version on modern GCC versions. */
+#if !defined(__CC_ARM) /* Generic C version */
 
 #if (NUMBER==3)
 __inline int32 sad_mb_offset3(uint8 *ref, uint8 *blk, int lx, int dmin)
@@ -227,7 +229,7 @@
     x4 = x5 = 0;
     x8 = 16; //<<===========*******
 
-__asm__ volatile("MVN	%0, #0xFF0000": "=r"(x6));
+    __asm__ volatile("MVN       %0, #0xFF0000": "=r"(x6));
 
 #if (NUMBER==3)
 LOOP_SAD3:
@@ -236,7 +238,7 @@
 #elif (NUMBER==1)
 LOOP_SAD1:
 #endif
-__asm__ volatile("BIC  %0, %0, #3": "=r"(ref));
+    __asm__ volatile("BIC  %0, %0, #3": "+r"(ref));
     /****** process 8 pixels ******/
     x11 = *((int32*)(ref + 12));
     x12 = *((int32*)(ref + 16));
@@ -244,11 +246,32 @@
     x14 = *((int32*)(blk + 12));
 
 #if (SHIFT==8)
-__asm__ volatile("MVN   %0, %0, lsr #8\n\tBIC   %0, %0, %1,lsl #24\n\tMVN   %1, %1,lsr #8\n\tBIC   %1, %1, %2,lsl #24": "=&r"(x10), "=&r"(x11): "r"(x12));
+    __asm__ volatile(
+        "MVN   %0, %0, lsr #8\n\t"
+        "BIC   %0, %0, %1, lsl #24\n\t"
+        "MVN   %1, %1, lsr #8\n\t"
+        "BIC   %1, %1, %2, lsl #24"
+        : "+r"(x10), "+r"(x11)
+        : "r"(x12)
+    );
 #elif (SHIFT==16)
-__asm__ volatile("MVN   %0, %0, lsr #16\n\tBIC   %0, %0, %1,lsl #16\n\tMVN   %1, %1,lsr #16\n\tBIC   %1, %1, %2,lsl #16": "=&r"(x10), "=&r"(x11): "r"(x12));
+    __asm__ volatile(
+        "MVN   %0, %0, lsr #16\n\t"
+        "BIC   %0, %0, %1, lsl #16\n\t"
+        "MVN   %1, %1, lsr #16\n\t"
+        "BIC   %1, %1, %2, lsl #16"
+        : "+r"(x10), "+r"(x11)
+        : "r"(x12)
+    );
 #elif (SHIFT==24)
-__asm__ volatile("MVN   %0, %0, lsr #24\n\tBIC   %0, %0, %1,lsl #8\n\tMVN   %1, %1,lsr #24\n\tBIC   %1, %1, %2,lsl #8": "=&r"(x10), "=&r"(x11): "r"(x12));
+    __asm__ volatile(
+        "MVN   %0, %0, lsr #24\n\t"
+        "BIC   %0, %0, %1, lsl #8\n\t"
+        "MVN   %1, %1, lsr #24\n\t"
+        "BIC   %1, %1, %2, lsl #8"
+        : "+r"(x10), "+r"(x11)
+        : "r"(x12)
+    );
 #endif
 
     x12 = *((int32*)(blk + 8));
@@ -268,13 +291,34 @@
     x14 = *((int32*)(blk + 4));
 
 #if (SHIFT==8)
-__asm__ volatile("MVN   %0, %0, lsr #8\n\tBIC   %0, %0, %1,lsl #24\n\tMVN   %1, %1,lsr #8\n\tBIC   %1, %1, %2,lsl #24": "=&r"(x10), "=&r"(x11): "r"(x12));
+    __asm__ volatile(
+        "MVN   %0, %0, lsr #8\n\t"
+        "BIC   %0, %0, %1, lsl #24\n\t"
+        "MVN   %1, %1, lsr #8\n\t"
+        "BIC   %1, %1, %2, lsl #24"
+        : "+r"(x10), "+r"(x11)
+        : "r"(x12)
+    );
 #elif (SHIFT==16)
-__asm__ volatile("MVN   %0, %0, lsr #16\n\tBIC   %0, %0, %1,lsl #16\n\tMVN   %1, %1,lsr #16\n\tBIC   %1, %1, %2,lsl #16": "=&r"(x10), "=&r"(x11): "r"(x12));
+    __asm__ volatile(
+        "MVN   %0, %0, lsr #16\n\t"
+        "BIC   %0, %0, %1, lsl #16\n\t"
+        "MVN   %1, %1, lsr #16\n\t"
+        "BIC   %1, %1, %2, lsl #16"
+        : "+r"(x10), "+r"(x11)
+        : "r"(x12)
+    );
 #elif (SHIFT==24)
-__asm__ volatile("MVN   %0, %0, lsr #24\n\tBIC   %0, %0, %1,lsl #8\n\tMVN   %1, %1,lsr #24\n\tBIC   %1, %1, %2,lsl #8": "=&r"(x10), "=&r"(x11): "r"(x12));
+    __asm__ volatile(
+        "MVN   %0, %0, lsr #24\n\t"
+        "BIC   %0, %0, %1, lsl #8\n\t"
+        "MVN   %1, %1, lsr #24\n\t"
+        "BIC   %1, %1, %2, lsl #8"
+        : "+r"(x10), "+r"(x11)
+        : "r"(x12)
+    );
 #endif
-__asm__ volatile("LDR   %0, [%1], #16": "=&r"(x12), "=r"(blk));
+    __asm__ volatile("LDR   %0, [%1], #16": "=&r"(x12), "+r"(blk));
 
     /* process x11 & x14 */
     x11 = sad_4pixelN(x11, x14, x9);
@@ -296,9 +340,9 @@
 #if (NUMBER==3)
             goto         LOOP_SAD3;
 #elif (NUMBER==2)
-goto         LOOP_SAD2;
+            goto         LOOP_SAD2;
 #elif (NUMBER==1)
-goto         LOOP_SAD1;
+            goto         LOOP_SAD1;
 #endif
         }
 
diff --git a/media/libstagefright/codecs/common/Android.mk b/media/libstagefright/codecs/common/Android.mk
index af8795a..a33cb92 100644
--- a/media/libstagefright/codecs/common/Android.mk
+++ b/media/libstagefright/codecs/common/Android.mk
@@ -14,19 +14,6 @@
 LOCAL_C_INCLUDES := \
 	$(LOCAL_PATH)/include
 
-LOCAL_CFLAGS := $(VO_CFLAGS)
-
-ifeq ($(VOTT), v5)
-LOCAL_CFLAGS += -DARM -DASM_OPT
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/asm/ARMV5E
-endif
-
-ifeq ($(VOTT), v7)
-LOCAL_CFLAGS += -DARM -DARMV7 -DASM_OPT
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/asm/ARMV5E
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/src/asm/ARMV7
-endif
-
 include $(BUILD_SHARED_LIBRARY)
 
 
diff --git a/media/libstagefright/codecs/common/Config.mk b/media/libstagefright/codecs/common/Config.mk
index 187f25c..a6d4286 100644
--- a/media/libstagefright/codecs/common/Config.mk
+++ b/media/libstagefright/codecs/common/Config.mk
@@ -20,5 +20,3 @@
 
 VOTEST := 0
 
-VO_CFLAGS:=-DLINUX
-
diff --git a/media/libstagefright/codecs/common/include/voType.h b/media/libstagefright/codecs/common/include/voType.h
index 5f659ab..da208d4 100644
--- a/media/libstagefright/codecs/common/include/voType.h
+++ b/media/libstagefright/codecs/common/include/voType.h
@@ -76,15 +76,6 @@
 /** VO_U16 is a 16 bit unsigned quantity that is 16 bit word aligned */
 typedef unsigned short VO_U16;
 
-/** VO_WCHAR is a 16 bit unsigned quantity that is 16 bit word aligned */
-#if defined _WIN32
-typedef unsigned short VO_WCHAR;
-typedef unsigned short* VO_PWCHAR;
-#elif defined LINUX
-typedef unsigned char VO_WCHAR;
-typedef unsigned char* VO_PWCHAR;
-#endif
-
 /** VO_S16 is a 16 bit signed quantity that is 16 bit word aligned */
 typedef signed short VO_S16;
 
@@ -150,21 +141,6 @@
  */
 typedef unsigned char* VO_PBYTE;
 
-/** The VO_PTCHAR type is intended to be used to pass arrays of wchar such as
-    unicode char between the application and the component and core.  The VO_PTCHAR
-    type is a 32 bit pointer to a zero terminated string.  The  pointer is word
-    aligned and the string is byte aligned.
- */
-/*
-#if !defined LINUX
-typedef unsigned short* VO_PTCHAR;
-typedef unsigned short* VO_TCHAR;
-#else
-typedef char* VO_PTCHAR;
-typedef char VO_TCHAR;
-#endif
-*/
-
 #ifndef NULL
 #ifdef __cplusplus
 #define NULL    0
diff --git a/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_dct_16_gcc.s b/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_dct_16_gcc.s
index f83732b..e61c8d3 100644
--- a/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_dct_16_gcc.s
+++ b/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_dct_16_gcc.s
@@ -369,7 +369,9 @@
 
 pvmp3_split:
         stmfd    sp!,{r4,r5,lr}
-        ldr      r2,constant16
+        adr      r1,constant16
+        ldr      r2,[r1]
+        add      r2,r1
         sub      r1,r0,#4
         mov      r3,#3
 loop1:
@@ -449,7 +451,7 @@
 constant15:
         .word      0x5a827980
 constant16:
-        .word      CosTable_dct32 + 60
+        .word      (CosTable_dct32 + 60)-constant16
 
 
 
diff --git a/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_mdct_18_gcc.s b/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_mdct_18_gcc.s
index 96230c5..575acd6 100644
--- a/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_mdct_18_gcc.s
+++ b/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_mdct_18_gcc.s
@@ -43,7 +43,7 @@
 pvmp3_mdct_18:
         stmfd    sp!,{r4-r11,lr}
         mov      r7,r2
-        ldr      r2,table
+        adr      r2,constdata$1
         mov      r6,r1
         add      r3,r2,#0x24
         add      r12,r3,#0x44
@@ -321,8 +321,6 @@
         smull    r2,r1,r0,r1
         str      r1,[r6,#0x3c]
         ldmfd    sp!,{r4-r11,pc}
-table:
-        .word      constdata$1
 
 @------------------------------------------------------------------------------
 
diff --git a/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_polyphase_filter_window_gcc.s b/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_polyphase_filter_window_gcc.s
index 4f45737..b74c849 100644
--- a/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_polyphase_filter_window_gcc.s
+++ b/media/libstagefright/codecs/mp3dec/src/asm/pvmp3_polyphase_filter_window_gcc.s
@@ -46,8 +46,10 @@
         stmfd    sp!,{r0-r2,r4-r11,lr}
 
         sub      sp,sp,#4
+        adr      r2,PolyPh_filter_coeff
+        ldr      r1,[r2]
+        add      r1,r2
         ldr      r2,[sp,#0xc]
-        ldr      r1,PolyPh_filter_coeff
 		
         sub      r2,r2,#1
         mov      r10,#1
@@ -224,7 +226,7 @@
         ldmfd    sp!,{r4-r11,pc}
 
 PolyPh_filter_coeff:
-        .word      pqmfSynthWin
+        .word      pqmfSynthWin-PolyPh_filter_coeff
 LOW_16BITS:
         .word      0x00007fff
 
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S
index e68bd8e..073dbba 100644
--- a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_DecodeCoeffsToPair_s.S
@@ -17,7 +17,8 @@
     SUB      sp,sp,#0x40
     LDR      r10,[r0,#0]
     LDR      r12,[r1,#0]
-    LDR      r6, =armVCM4P10_CAVLCCoeffTokenTables
+    LDR      r6, .LarmVCM4P10_CAVLCCoeffTokenTables
+P0: ADD      r6, pc
     LDR      r4,[sp,#0x68]
     LDRB     r9,[r10,#2]
     LDRB     r8,[r10,#1]
@@ -131,7 +132,8 @@
     LSRS     r8,r7,#1
     RSBCS    r8,r8,#0
     STRH     r8,[r2],#2
-    LDR      r9, =armVCM4P10_SuffixToLevel
+    LDR      r9, .LarmVCM4P10_SuffixToLevel
+P1: ADD      r9, pc
     LDRSB    r8,[r9,r4]
     TEQ      r4,#0
     MOVEQ    r4,#1
@@ -148,8 +150,9 @@
     SUB      lr,lr,#1
     BEQ      L0x2b0
     TEQ      r8,#4
-    LDREQ    r6, =(armVCM4P10_CAVLCTotalZeros2x2Tables - 4)
-    LDRNE    r6, =(armVCM4P10_CAVLCTotalZeroTables - 4)
+    LDREQ    r6, .LarmVCM4P10_CAVLCTotalZeros2x2Tables
+    LDRNE    r6, .LarmVCM4P10_CAVLCTotalZeroTables
+P2: ADD      r6, pc
     LDR      r6,[r6,r5,LSL #2]
     LSLS     r8,r11,r12
     MOVS     r7,#0x1e
@@ -175,7 +178,8 @@
     BIC      r7,r8,#0xf000
     CMP      r7,#0x10
     BGE      L0x33c
-    LDR      r3, =(armVCM4P10_CAVLCRunBeforeTables - 4)
+    LDR      r3, .LarmVCM4P10_CAVLCRunBeforeTables
+P3: ADD      r3, pc
     ADD      r4,sp,#0x2c
     MOVS     r1,r7
     ADD      lr,lr,r1
@@ -228,8 +232,9 @@
     LDR      r3,[sp,#8]
     LDR      r0,[r3,#0]
     TEQ      r8,#4
-    LDREQ    r6, =armVCM4P10_ZigZag_2x2
-    LDRNE    r6, =armVCM4P10_ZigZag_4x4
+    LDREQ    r6, .LarmVCM4P10_ZigZag_2x2
+    LDRNE    r6, .LarmVCM4P10_ZigZag_4x4
+P4: ADD      r6, pc
 L0x2ec:
     LDRB     r9,[r4],#1
     LDRB     r8,[r6,lr]
@@ -268,5 +273,19 @@
     POP      {r4-r12,pc}
     .endfunc
 
-    .end
+.LarmVCM4P10_CAVLCCoeffTokenTables:
+    .word   armVCM4P10_CAVLCCoeffTokenTables-(P0+8)
+.LarmVCM4P10_SuffixToLevel:
+    .word   armVCM4P10_SuffixToLevel-(P1+8)
+.LarmVCM4P10_CAVLCTotalZeros2x2Tables:
+    .word   (armVCM4P10_CAVLCTotalZeros2x2Tables - 4)-(P2+8)
+.LarmVCM4P10_CAVLCTotalZeroTables:
+    .word   (armVCM4P10_CAVLCTotalZeroTables - 4)-(P2+8)
+.LarmVCM4P10_CAVLCRunBeforeTables:
+    .word   (armVCM4P10_CAVLCRunBeforeTables - 4)-(P3+8)
+.LarmVCM4P10_ZigZag_2x2:
+    .word   armVCM4P10_ZigZag_2x2-(P4+8)
+.LarmVCM4P10_ZigZag_4x4:
+    .word   armVCM4P10_ZigZag_4x4-(P4+8)
 
+    .end
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S
index 66520da..8599cab 100644
--- a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/armVCM4P10_Interpolate_Chroma_s.S
@@ -9,20 +9,18 @@
     .arm
     .fpu neon
 
-    .section .rodata
+    .text
     .align 4
 
 armVCM4P10_WidthBranchTableMVIsNotZero:
-    .word   WidthIs2MVIsNotZero, WidthIs2MVIsNotZero
-    .word   WidthIs4MVIsNotZero, WidthIs4MVIsNotZero
-    .word   WidthIs8MVIsNotZero
+    .word   WidthIs2MVIsNotZero-(P0+8), WidthIs2MVIsNotZero-(P0+8)
+    .word   WidthIs4MVIsNotZero-(P0+8), WidthIs4MVIsNotZero-(P0+8)
+    .word   WidthIs8MVIsNotZero-(P0+8)
 
 armVCM4P10_WidthBranchTableMVIsZero:
-    .word   WidthIs2MVIsZero, WidthIs2MVIsZero
-    .word   WidthIs4MVIsZero, WidthIs4MVIsZero
-    .word   WidthIs8MVIsZero
-
-    .text
+    .word   WidthIs2MVIsZero-(P0+8), WidthIs2MVIsZero-(P0+8)
+    .word   WidthIs4MVIsZero-(P0+8), WidthIs4MVIsZero-(P0+8)
+    .word   WidthIs8MVIsZero-(P0+8)
 
     .global armVCM4P10_Interpolate_Chroma
     .func   armVCM4P10_Interpolate_Chroma
@@ -35,9 +33,9 @@
     RSB      r9,r7,#8
     CMN      r6,r7
     MOV      r10,#1
-    LDREQ    r11, =armVCM4P10_WidthBranchTableMVIsZero
+    ADREQ    r11, armVCM4P10_WidthBranchTableMVIsZero
     SUB      lr,r1,r10
-    LDRNE    r11, =armVCM4P10_WidthBranchTableMVIsNotZero
+    ADRNE    r11, armVCM4P10_WidthBranchTableMVIsNotZero
     VLD1.8   {d0},[r0],r10
     SMULBB   r12,r8,r9
     SMULBB   r9,r6,r9
@@ -48,7 +46,8 @@
     VDUP.8   d13,r9
     VDUP.8   d14,r8
     VDUP.8   d15,r6
-    LDR      pc,[r11,r4,LSL #1]
+    LDR      r11,[r11, r4, lsl #1]
+P0: ADD      pc,r11
 
 WidthIs8MVIsNotZero:
     VLD1.8   {d2},[r0],r10
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S
index be21ee7..bc0f7fa 100644
--- a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_DequantTransformResidualFromPairAndAdd_s.S
@@ -26,9 +26,12 @@
     MOV      r1,r4
     BL       armVCM4P10_UnpackBlock4x4  ;//
     LDR      r1,[sp,#0x60]
-    LDR      r11, =armVCM4P10_QPModuloTable
-    LDR      r10, =armVCM4P10_QPDivTable
-    LDR      r2,  =armVCM4P10_VMatrixU16
+    LDR      r11, .LarmVCM4P10_QPModuloTable
+P0: ADD      r11, pc
+    LDR      r10, .LarmVCM4P10_QPDivTable
+P1: ADD      r10, pc
+    LDR      r2, .LarmVCM4P10_VMatrixU16
+P2: ADD      r2, pc
     LDRSB    r12,[r11,r1]
     LDRSB    lr,[r10,r1]
     LDR      r10, =0x3020504
@@ -115,5 +118,12 @@
     POP      {r4-r12,pc}
     .endfunc
 
+.LarmVCM4P10_QPModuloTable:
+    .word   armVCM4P10_QPModuloTable-(P0+8)
+.LarmVCM4P10_QPDivTable:
+    .word   armVCM4P10_QPDivTable-(P1+8)
+.LarmVCM4P10_VMatrixU16:
+    .word   armVCM4P10_VMatrixU16-(P2+8)
+
     .end
 
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S
index 0d49e4b..a896a3a 100644
--- a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntraChroma_8x8_s.S
@@ -8,31 +8,31 @@
 
     .arm
     .fpu neon
-    .section .rodata
+    .text
     .align 4
 
 armVCM4P10_pIndexTable8x8:
-    .word  OMX_VC_CHROMA_DC,     OMX_VC_CHROMA_HOR
-    .word  OMX_VC_CHROMA_VERT,   OMX_VC_CHROMA_PLANE
+    .word  OMX_VC_CHROMA_DC-(P0+8),    OMX_VC_CHROMA_HOR-(P0+8)
+    .word  OMX_VC_CHROMA_VERT-(P0+8),  OMX_VC_CHROMA_PLANE-(P0+8)
 
 armVCM4P10_MultiplierTableChroma8x8:
     .hword   3, 2, 1,4
     .hword  -3,-2,-1,0
     .hword   1, 2, 3,4
 
-
-    .text
     .global omxVCM4P10_PredictIntraChroma_8x8
     .func   omxVCM4P10_PredictIntraChroma_8x8
 omxVCM4P10_PredictIntraChroma_8x8:
     PUSH     {r4-r10,lr}
     VPUSH    {d8-d15}
-    LDR      r8, =armVCM4P10_pIndexTable8x8
+    ADR      r8, armVCM4P10_pIndexTable8x8
     LDR      r6,[sp,#0x68]
     LDR      r4,[sp,#0x60]
     LDR      r5,[sp,#0x64]
     LDR      r7,[sp,#0x6c]
-    LDR      pc,[r8,r6,LSL #2]
+    LDR      r8,[r8,r6,LSL #2]
+P0: ADD      pc,r8
+
 OMX_VC_CHROMA_DC:
     TST      r7,#2
     BEQ      L0xe8
@@ -151,7 +151,7 @@
     VSUBL.U8 q7,d3,d2
     VSHR.U64 d3,d3,#8
     VSUBL.U8 q6,d3,d1
-    LDR      r2, =armVCM4P10_MultiplierTableChroma8x8
+    ADR      r2, armVCM4P10_MultiplierTableChroma8x8
     VSHL.I64 d4,d4,#16
     VEXT.8   d9,d4,d6,#2
     VLD1.16  {d10},[r2]!
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S
index 53268f6..3944f53 100644
--- a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_16x16_s.S
@@ -9,7 +9,7 @@
     .arm
     .fpu neon
 
-    .section .rodata
+    .text
     .align 4
 ;//-------------------------------------------------------
 ;// This table for implementing switch case of C in asm by
@@ -17,9 +17,8 @@
 ;//-------------------------------------------------------
 
 armVCM4P10_pIndexTable16x16:
-    .word  OMX_VC_16X16_VERT, OMX_VC_16X16_HOR
-    .word  OMX_VC_16X16_DC,   OMX_VC_16X16_PLANE
-
+    .word  OMX_VC_16X16_VERT-(P0+8), OMX_VC_16X16_HOR-(P0+8)
+    .word  OMX_VC_16X16_DC-(P0+8),   OMX_VC_16X16_PLANE-(P0+8)
 
 
 armVCM4P10_MultiplierTable16x16:
@@ -27,20 +26,20 @@
     .hword   0,  1,  2,  3,  4,  5,  6,  7
     .hword   8,  9, 10, 11, 12, 13, 14, 15
 
-    .text
 
     .global omxVCM4P10_PredictIntra_16x16
     .func   omxVCM4P10_PredictIntra_16x16
 omxVCM4P10_PredictIntra_16x16:
     PUSH     {r4-r12,lr}
     VPUSH    {d8-d15}
-    LDR      r9, =armVCM4P10_pIndexTable16x16
+    ADR      r9, armVCM4P10_pIndexTable16x16
     LDR      r6,[sp,#0x70]
     LDR      r4,[sp,#0x68]
     LDR      r5,[sp,#0x6c]
     LDR      r7,[sp,#0x74]
     MOV      r12,#0x10
-    LDR      pc,[r9,r6,LSL #2]
+    LDR      r9,[r9,r6,LSL #2]
+P0: ADD      pc,r9
 OMX_VC_16X16_VERT:
     VLD1.8   {d0,d1},[r1]
     ADD      r8,r3,r5
@@ -162,7 +161,7 @@
     VPOP     {d8-d15}
     POP      {r4-r12,pc}
 OMX_VC_16X16_PLANE:
-    LDR      r9, =armVCM4P10_MultiplierTable16x16
+    ADR      r9, armVCM4P10_MultiplierTable16x16
     VLD1.8   {d0,d1},[r1]
     VLD1.8   {d4[0]},[r2]
     ADD      r8,r0,r4
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S
index aa6d7ef..6646b7f 100644
--- a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_PredictIntra_4x4_s.S
@@ -9,27 +9,27 @@
     .arm
     .fpu neon
 
-    .section .rodata
+    .text
     .align 4
 
 armVCM4P10_pSwitchTable4x4:
-    .word OMX_VC_4x4_VERT,     OMX_VC_4x4_HOR
-    .word OMX_VC_4x4_DC,       OMX_VC_4x4_DIAG_DL
-    .word OMX_VC_4x4_DIAG_DR,  OMX_VC_4x4_VR
-    .word OMX_VC_4x4_HD,       OMX_VC_4x4_VL
-    .word OMX_VC_4x4_HU
-
-    .text
+    .word OMX_VC_4x4_VERT-(P0+8),     OMX_VC_4x4_HOR-(P0+8)
+    .word OMX_VC_4x4_DC-(P0+8),       OMX_VC_4x4_DIAG_DL-(P0+8)
+    .word OMX_VC_4x4_DIAG_DR-(P0+8),  OMX_VC_4x4_VR-(P0+8)
+    .word OMX_VC_4x4_HD-(P0+8),       OMX_VC_4x4_VL-(P0+8)
+    .word OMX_VC_4x4_HU-(P0+8)
 
     .global omxVCM4P10_PredictIntra_4x4
     .func   omxVCM4P10_PredictIntra_4x4
 omxVCM4P10_PredictIntra_4x4:
     PUSH     {r4-r12,lr}
     VPUSH    {d8-d12}
-    LDR      r8, =armVCM4P10_pSwitchTable4x4
+    ADR      r8, armVCM4P10_pSwitchTable4x4
     LDRD     r6,r7,[sp,#0x58]
     LDRD     r4,r5,[sp,#0x50]
-    LDR      pc,[r8,r6,LSL #2]
+    LDR      r8,[r8,r6,LSL #2]
+P0: ADD      pc, r8
+
 OMX_VC_4x4_HOR:
     ADD      r9,r0,r4
     ADD      r10,r4,r4
@@ -258,4 +258,3 @@
     .endfunc
 
     .end
-
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S
index 28a89cb..7ba3bd6 100644
--- a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantChromaDCFromPair_s.S
@@ -32,8 +32,10 @@
     beq     unpackLoop
     ldmia   r1, {r3, r4}
     str     r9, [r0, #0]
-    ldr     r5, =armVCM4P10_QPDivTable
-    ldr     r6, =armVCM4P10_VMatrixQPModTable
+    ldr     r5, .LarmVCM4P10_QPDivTable
+P0: add     r5, pc
+    ldr     r6, .LarmVCM4P10_VMatrixQPModTable
+P1: add     r6, pc
     saddsubx        r3, r3, r3
     saddsubx        r4, r4, r4
     ldrsb   r9, [r5, r2]
@@ -51,4 +53,9 @@
     pop     {r4-r10, pc}
     .endfunc
 
+.LarmVCM4P10_QPDivTable:
+    .word armVCM4P10_QPDivTable-(P0+8)
+.LarmVCM4P10_VMatrixQPModTable:
+    .word armVCM4P10_VMatrixQPModTable-(P1+8)
+
     .end
diff --git a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S
index a3a0715..640f096 100644
--- a/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S
+++ b/media/libstagefright/codecs/on2/h264dec/omxdl/arm_neon/vc/m4p10/src_gcc/omxVCM4P10_TransformDequantLumaDCFromPair_s.S
@@ -16,8 +16,10 @@
     PUSH     {r4-r6,lr}
     VPUSH    {d8-d13}
     VLD4.16  {d0,d1,d2,d3},[r0]
-    LDR      r2, =armVCM4P10_QPDivTable
-    LDR      r3, =armVCM4P10_VMatrixQPModTable
+    LDR      r2, .LarmVCM4P10_QPDivTable
+P0: ADD      r2, pc
+    LDR      r3, .LarmVCM4P10_VMatrixQPModTable
+P1: ADD      r3, pc
     VADD.I16 d4,d0,d1
     VADD.I16 d5,d2,d3
     VSUB.I16 d6,d0,d1
@@ -58,6 +60,11 @@
     POP      {r4-r6,pc}
     .endfunc
 
+.LarmVCM4P10_QPDivTable:
+    .word armVCM4P10_QPDivTable-(P0+8)
+.LarmVCM4P10_VMatrixQPModTable:
+    .word armVCM4P10_VMatrixQPModTable-(P1+8)
+
 .global omxVCM4P10_TransformDequantLumaDCFromPair
 .func   omxVCM4P10_TransformDequantLumaDCFromPair
 omxVCM4P10_TransformDequantLumaDCFromPair:
diff --git a/media/libstagefright/id3/ID3.cpp b/media/libstagefright/id3/ID3.cpp
index ca14054..69274ca 100644
--- a/media/libstagefright/id3/ID3.cpp
+++ b/media/libstagefright/id3/ID3.cpp
@@ -743,7 +743,8 @@
         n += 2;
     }
 
-    return n;
+    // Add size of null termination.
+    return n + 2;
 }
 
 const void *
diff --git a/media/libstagefright/matroska/MatroskaExtractor.cpp b/media/libstagefright/matroska/MatroskaExtractor.cpp
index 8c63df9..8f7d12b 100644
--- a/media/libstagefright/matroska/MatroskaExtractor.cpp
+++ b/media/libstagefright/matroska/MatroskaExtractor.cpp
@@ -894,16 +894,16 @@
         }
 
         BlockIterator iter(this, info->mTrackNum);
-        int32_t i = 0;
+        int32_t j = 0;
         int64_t thumbnailTimeUs = 0;
         size_t maxBlockSize = 0;
-        while (!iter.eos() && i < 20) {
+        while (!iter.eos() && j < 20) {
             if (iter.block()->IsKey()) {
-                ++i;
+                ++j;
 
                 size_t blockSize = 0;
-                for (int i = 0; i < iter.block()->GetFrameCount(); ++i) {
-                    blockSize += iter.block()->GetFrame(i).len;
+                for (int k = 0; k < iter.block()->GetFrameCount(); ++k) {
+                    blockSize += iter.block()->GetFrame(k).len;
                 }
 
                 if (blockSize > maxBlockSize) {
diff --git a/media/libstagefright/rtsp/APacketSource.cpp b/media/libstagefright/rtsp/APacketSource.cpp
index fc177d2..ddd2f06 100644
--- a/media/libstagefright/rtsp/APacketSource.cpp
+++ b/media/libstagefright/rtsp/APacketSource.cpp
@@ -110,14 +110,12 @@
     *height = 0;
 
     AString val;
-    if (!GetAttribute(params, "profile-level-id", &val)) {
-        return NULL;
+    sp<ABuffer> profileLevelID = NULL;
+    if (GetAttribute(params, "profile-level-id", &val)) {
+        profileLevelID = decodeHex(val);
+        CHECK_EQ(profileLevelID->size(), 3u);
     }
 
-    sp<ABuffer> profileLevelID = decodeHex(val);
-    CHECK(profileLevelID != NULL);
-    CHECK_EQ(profileLevelID->size(), 3u);
-
     Vector<sp<ABuffer> > paramSets;
 
     size_t numSeqParameterSets = 0;
@@ -176,8 +174,15 @@
     uint8_t *out = csd->data();
 
     *out++ = 0x01;  // configurationVersion
-    memcpy(out, profileLevelID->data(), 3);
-    out += 3;
+    if (profileLevelID != NULL) {
+        memcpy(out, profileLevelID->data(), 3);
+        out += 3;
+    } else {
+        *out++ = 0x42; // Baseline profile
+        *out++ = 0xE0; // Common subset for all profiles
+        *out++ = 0x0A; // Level 1
+    }
+
     *out++ = (0x3f << 2) | 1;  // lengthSize == 2 bytes
     *out++ = 0xe0 | numSeqParameterSets;
 
diff --git a/media/libstagefright/rtsp/ARTPConnection.cpp b/media/libstagefright/rtsp/ARTPConnection.cpp
index 44988a3..501a970 100644
--- a/media/libstagefright/rtsp/ARTPConnection.cpp
+++ b/media/libstagefright/rtsp/ARTPConnection.cpp
@@ -18,6 +18,7 @@
 #define LOG_TAG "ARTPConnection"
 #include <utils/Log.h>
 
+#include "ARTPAssembler.h"
 #include "ARTPConnection.h"
 
 #include "ARTPSource.h"
diff --git a/media/mtp/Android.mk b/media/mtp/Android.mk
index fc7fc4f..bee28d4 100644
--- a/media/mtp/Android.mk
+++ b/media/mtp/Android.mk
@@ -45,31 +45,3 @@
 LOCAL_SHARED_LIBRARIES := libutils libcutils libusbhost libbinder
 
 include $(BUILD_SHARED_LIBRARY)
-
-ifeq ($(HOST_OS),linux)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:=                                       \
-                  MtpDataPacket.cpp                     \
-                  MtpDebug.cpp                          \
-                  MtpDevice.cpp                         \
-                  MtpEventPacket.cpp                    \
-                  MtpDeviceInfo.cpp                     \
-                  MtpObjectInfo.cpp                     \
-                  MtpPacket.cpp                         \
-                  MtpProperty.cpp                       \
-                  MtpRequestPacket.cpp                  \
-                  MtpResponsePacket.cpp                 \
-                  MtpStorageInfo.cpp                    \
-                  MtpStringBuffer.cpp                   \
-                  MtpStorage.cpp                        \
-                  MtpUtils.cpp                          \
-
-LOCAL_MODULE:= libmtp
-
-LOCAL_CFLAGS := -DMTP_HOST
-
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-endif
diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp
index 0c8b3ce..3e4c55e 100644
--- a/services/audioflinger/AudioMixer.cpp
+++ b/services/audioflinger/AudioMixer.cpp
@@ -93,8 +93,12 @@
 
 effect_descriptor_t AudioMixer::dwnmFxDesc;
 
+// Ensure mConfiguredNames bitmask is initialized properly on all architectures.
+// The value of 1 << x is undefined in C when x >= 32.
+
 AudioMixer::AudioMixer(size_t frameCount, uint32_t sampleRate, uint32_t maxNumTracks)
-    :   mTrackNames(0), mConfiguredNames((1 << maxNumTracks) - 1), mSampleRate(sampleRate)
+    :   mTrackNames(0), mConfiguredNames((maxNumTracks >= 32 ? 0 : 1 << maxNumTracks) - 1),
+        mSampleRate(sampleRate)
 {
     // AudioMixer is not yet capable of multi-channel beyond stereo
     COMPILE_TIME_ASSERT_FUNCTION_SCOPE(2 == MAX_NUM_CHANNELS);
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index bf07f8b..385be50 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -721,9 +721,9 @@
     Mutex::Autolock lock(mLock);
     if (checkPidAndHardware() != NO_ERROR) return;
 
-    mCameraService->playSound(SOUND_RECORDING);
     disableMsgType(CAMERA_MSG_VIDEO_FRAME);
     mHardware->stopRecording();
+    mCameraService->playSound(SOUND_RECORDING);
 
     mPreviewBuffer.clear();
 }