am 4f50ecc1: merge from open-source master

Merge commit '4f50ecc1cc90a03931e6cec0c89f5af44ab79f6b'

* commit '4f50ecc1cc90a03931e6cec0c89f5af44ab79f6b':
  empty initial commit
diff --git a/dspbridge/libbridge/DSPNode.c b/dspbridge/libbridge/DSPNode.c
index 8d345fb..dfac89f 100644
--- a/dspbridge/libbridge/DSPNode.c
+++ b/dspbridge/libbridge/DSPNode.c
@@ -216,8 +216,10 @@
 		DEBUGMSG(DSPAPI_ZONE_ERROR, (TEXT(
 			"NODE: DSPNode_Allocate:Failed to CMM handle\r\n")));
 	}
-	if (!DSP_SUCCEEDED(status))
+	if (!DSP_SUCCEEDED(status)) {
+		free(pGPPVirtAddr);
 		return status;
+	}
 
 	GetNodeType(*phNode, &nodeType);
 	if ((nodeType != NODE_DEVICE) && (pInfo.ulNumGPPSMSegs > 0)) {
diff --git a/libopencorehw/Android.mk b/libopencorehw/Android.mk
index 28cb526..73d4c38 100644
--- a/libopencorehw/Android.mk
+++ b/libopencorehw/Android.mk
@@ -1,3 +1,5 @@
+ifneq ($(BUILD_WITHOUT_PV),true)
+
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 
@@ -32,3 +34,4 @@
 
 include $(BUILD_SHARED_LIBRARY)
 
+endif
diff --git a/libopencorehw/android_surface_output_omap34xx.cpp b/libopencorehw/android_surface_output_omap34xx.cpp
index d476df5..8431a41 100644
--- a/libopencorehw/android_surface_output_omap34xx.cpp
+++ b/libopencorehw/android_surface_output_omap34xx.cpp
@@ -112,7 +112,7 @@
             // wait in the createOverlay call if the previous overlay is in the
             // process of being destroyed.
             for (int retry = 0; retry < 50; ++retry) {
-                ref = mSurface->createOverlay(displayWidth, displayHeight, videoFormat);
+                ref = mSurface->createOverlay(displayWidth, displayHeight, videoFormat, 0);
                 if (ref != NULL) break;
                 LOGD("Overlay create failed - retrying");
                 usleep(100000);
diff --git a/libstagefrighthw/Android.mk b/libstagefrighthw/Android.mk
index 37757c4..235decc 100644
--- a/libstagefrighthw/Android.mk
+++ b/libstagefrighthw/Android.mk
@@ -3,7 +3,8 @@
 
 LOCAL_SRC_FILES := \
     stagefright_overlay_output.cpp \
-    TIHardwareRenderer.cpp
+    TIHardwareRenderer.cpp \
+    TIOMXPlugin.cpp
 
 LOCAL_CFLAGS := $(PV_CFLAGS_MINUS_VISIBILITY)
 
@@ -16,6 +17,7 @@
         libutils                \
         libcutils               \
         libui                   \
+        libdl
 
 LOCAL_MODULE := libstagefrighthw
 
diff --git a/libstagefrighthw/TIHardwareRenderer.cpp b/libstagefrighthw/TIHardwareRenderer.cpp
index 53818d6..2a23585 100644
--- a/libstagefrighthw/TIHardwareRenderer.cpp
+++ b/libstagefrighthw/TIHardwareRenderer.cpp
@@ -48,7 +48,7 @@
     CHECK(mDecodedHeight > 0);
 
     sp<OverlayRef> ref = mISurface->createOverlay(
-            mDisplayWidth, mDisplayHeight, OVERLAY_FORMAT_CbYCrY_422_I);
+            mDecodedWidth, mDecodedHeight, OVERLAY_FORMAT_CbYCrY_422_I, 0);
 
     if (ref.get() == NULL) {
         LOGE("Unable to create the overlay!");
diff --git a/libstagefrighthw/TIOMXPlugin.cpp b/libstagefrighthw/TIOMXPlugin.cpp
new file mode 100644
index 0000000..d820532
--- /dev/null
+++ b/libstagefrighthw/TIOMXPlugin.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#include "TIOMXPlugin.h"
+
+#include <dlfcn.h>
+
+#include <media/stagefright/HardwareAPI.h>
+#include <media/stagefright/MediaDebug.h>
+
+namespace android {
+
+OMXPluginBase *createOMXPlugin() {
+    return new TIOMXPlugin;
+}
+
+TIOMXPlugin::TIOMXPlugin()
+    : mLibHandle(dlopen("libOMX_Core.so", RTLD_NOW)),
+      mInit(NULL),
+      mDeinit(NULL),
+      mComponentNameEnum(NULL),
+      mGetHandle(NULL),
+      mFreeHandle(NULL),
+      mGetRolesOfComponentHandle(NULL) {
+    if (mLibHandle != NULL) {
+        mInit = (InitFunc)dlsym(mLibHandle, "TIOMX_Init");
+        mDeinit = (DeinitFunc)dlsym(mLibHandle, "TIOMX_DeInit");
+
+        mComponentNameEnum =
+            (ComponentNameEnumFunc)dlsym(mLibHandle, "TIOMX_ComponentNameEnum");
+
+        mGetHandle = (GetHandleFunc)dlsym(mLibHandle, "TIOMX_GetHandle");
+        mFreeHandle = (FreeHandleFunc)dlsym(mLibHandle, "TIOMX_FreeHandle");
+
+        mGetRolesOfComponentHandle =
+            (GetRolesOfComponentFunc)dlsym(
+                    mLibHandle, "TIOMX_GetRolesOfComponent");
+
+        (*mInit)();
+    }
+}
+
+TIOMXPlugin::~TIOMXPlugin() {
+    if (mLibHandle != NULL) {
+        (*mDeinit)();
+
+        dlclose(mLibHandle);
+        mLibHandle = NULL;
+    }
+}
+
+OMX_ERRORTYPE TIOMXPlugin::makeComponentInstance(
+        const char *name,
+        const OMX_CALLBACKTYPE *callbacks,
+        OMX_PTR appData,
+        OMX_COMPONENTTYPE **component) {
+    if (mLibHandle == NULL) {
+        return OMX_ErrorUndefined;
+    }
+
+    return (*mGetHandle)(
+            reinterpret_cast<OMX_HANDLETYPE *>(component),
+            const_cast<char *>(name),
+            appData, const_cast<OMX_CALLBACKTYPE *>(callbacks));
+}
+
+OMX_ERRORTYPE TIOMXPlugin::destroyComponentInstance(
+        OMX_COMPONENTTYPE *component) {
+    if (mLibHandle == NULL) {
+        return OMX_ErrorUndefined;
+    }
+
+    return (*mFreeHandle)(reinterpret_cast<OMX_HANDLETYPE *>(component));
+}
+
+OMX_ERRORTYPE TIOMXPlugin::enumerateComponents(
+        OMX_STRING name,
+        size_t size,
+        OMX_U32 index) {
+    if (mLibHandle == NULL) {
+        return OMX_ErrorUndefined;
+    }
+
+    return (*mComponentNameEnum)(name, size, index);
+}
+
+OMX_ERRORTYPE TIOMXPlugin::getRolesOfComponent(
+        const char *name,
+        Vector<String8> *roles) {
+    roles->clear();
+
+    if (mLibHandle == NULL) {
+        return OMX_ErrorUndefined;
+    }
+
+    OMX_U32 numRoles;
+    OMX_ERRORTYPE err = (*mGetRolesOfComponentHandle)(
+            const_cast<OMX_STRING>(name), &numRoles, NULL);
+
+    if (err != OMX_ErrorNone) {
+        return err;
+    }
+
+    if (numRoles > 0) {
+        OMX_U8 **array = new OMX_U8 *[numRoles];
+        for (OMX_U32 i = 0; i < numRoles; ++i) {
+            array[i] = new OMX_U8[OMX_MAX_STRINGNAME_SIZE];
+        }
+
+        OMX_U32 numRoles2;
+        err = (*mGetRolesOfComponentHandle)(
+                const_cast<OMX_STRING>(name), &numRoles2, array);
+
+        CHECK_EQ(err, OMX_ErrorNone);
+        CHECK_EQ(numRoles, numRoles2);
+
+        for (OMX_U32 i = 0; i < numRoles; ++i) {
+            String8 s((const char *)array[i]);
+            roles->push(s);
+
+            delete[] array[i];
+            array[i] = NULL;
+        }
+
+        delete[] array;
+        array = NULL;
+    }
+
+    return OMX_ErrorNone;
+}
+
+}  // namespace android
diff --git a/libstagefrighthw/TIOMXPlugin.h b/libstagefrighthw/TIOMXPlugin.h
new file mode 100644
index 0000000..668c5ef
--- /dev/null
+++ b/libstagefrighthw/TIOMXPlugin.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * 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.
+ */
+
+#ifndef TI_OMX_PLUGIN_H_
+
+#define TI_OMX_PLUGIN_H_
+
+#include <media/stagefright/OMXPluginBase.h>
+
+namespace android {
+
+struct TIOMXPlugin : public OMXPluginBase {
+    TIOMXPlugin();
+    virtual ~TIOMXPlugin();
+
+    virtual OMX_ERRORTYPE makeComponentInstance(
+            const char *name,
+            const OMX_CALLBACKTYPE *callbacks,
+            OMX_PTR appData,
+            OMX_COMPONENTTYPE **component);
+
+    virtual OMX_ERRORTYPE destroyComponentInstance(
+            OMX_COMPONENTTYPE *component);
+
+    virtual OMX_ERRORTYPE enumerateComponents(
+            OMX_STRING name,
+            size_t size,
+            OMX_U32 index);
+
+    virtual OMX_ERRORTYPE getRolesOfComponent(
+            const char *name,
+            Vector<String8> *roles);
+
+private:
+    void *mLibHandle;
+
+    typedef OMX_ERRORTYPE (*InitFunc)();
+    typedef OMX_ERRORTYPE (*DeinitFunc)();
+    typedef OMX_ERRORTYPE (*ComponentNameEnumFunc)(
+            OMX_STRING, OMX_U32, OMX_U32);
+
+    typedef OMX_ERRORTYPE (*GetHandleFunc)(
+            OMX_HANDLETYPE *, OMX_STRING, OMX_PTR, OMX_CALLBACKTYPE *);
+
+    typedef OMX_ERRORTYPE (*FreeHandleFunc)(OMX_HANDLETYPE *);
+
+    typedef OMX_ERRORTYPE (*GetRolesOfComponentFunc)(
+            OMX_STRING, OMX_U32 *, OMX_U8 **);
+
+    InitFunc mInit;
+    DeinitFunc mDeinit;
+    ComponentNameEnumFunc mComponentNameEnum;
+    GetHandleFunc mGetHandle;
+    FreeHandleFunc mFreeHandle;
+    GetRolesOfComponentFunc mGetRolesOfComponentHandle;
+
+    TIOMXPlugin(const TIOMXPlugin &);
+    TIOMXPlugin &operator=(const TIOMXPlugin &);
+};
+
+}  // namespace android
+
+#endif  // TI_OMX_PLUGIN_H_
diff --git a/omx/Android.mk b/omx/Android.mk
index 3a39a52..06e44e9 100644
--- a/omx/Android.mk
+++ b/omx/Android.mk
@@ -9,7 +9,7 @@
 
 OMX_DEBUG := 0
 RESOURCE_MANAGER_ENABLED := 0
-PERF_INSTRUMENTATION := 1
+PERF_INSTRUMENTATION := 0
 PERF_CUSTOMIZABLE := 1
 PERF_READER := 1
 
@@ -22,6 +22,13 @@
 TI_OMX_CFLAGS += -D__PERF_INSTRUMENTATION__
 endif
 
+ifeq ($(BUILD_WITH_TI_AUDIO),1)
+TI_OMX_CFLAGS += -DBUILD_WITH_TI_AUDIO
+BUILD_AAC_DECODER := 1
+BUILD_MP3_DECODER := 1
+BUILD_WMA_DECODER := 1
+endif
+
 TI_OMX_TOP := $(LOCAL_PATH)
 TI_OMX_SYSTEM := $(TI_OMX_TOP)/system/src/openmax_il
 TI_OMX_VIDEO := $(TI_OMX_TOP)/video/src/openmax_il
diff --git a/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDec_Utils.c b/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDec_Utils.c
index 8f248d2..e133ae4 100644
--- a/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDec_Utils.c
+++ b/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDec_Utils.c
@@ -2692,14 +2692,14 @@
             if((pComponentPrivate->nEmptyThisBufferCount != pComponentPrivate->nEmptyBufferDoneCount) || (pComponentPrivate->nFillThisBufferCount != pComponentPrivate->nFillBufferDoneCount)) {
                 if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
                 {
-                    OMXDBG_PRINT(stderr, PRINT, 1, 0, "bufferReturned_mutex mutex lock error");
+                    OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex lock error\n",__LINE__);
                 }
-                OMXDBG_PRINT(stderr, PRINT, 1, 0, "pthread_cond_waiting for OMX to return all input and outbut buffers");
+                OMX_PRINT2(pComponentPrivate->dbg, ":: pthread_cond_waiting for OMX to return all input and outbut buffers\n");
                 pthread_cond_wait(&bufferReturned_condition, &bufferReturned_mutex);
-                OMXDBG_PRINT(stderr, PRINT, 1, 0, "OMX has returned all input and output buffers");
+                OMX_PRINT2(pComponentPrivate->dbg, ":: OMX has returned all input and output buffers\n");
                 if(pthread_mutex_unlock(&bufferReturned_mutex) != 0)
                 {
-                    OMXDBG_PRINT(stderr, PRINT, 1, 0, "bufferReturned_mutex mutex unlock error");
+                    OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex unlock error\n",__LINE__);
                 }
             }
             else
@@ -3922,13 +3922,13 @@
     {
         if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
         {
-            OMXDBG_PRINT(stderr, PRINT, 1, 0, "bufferReturned_mutex mutex lock error");
+            OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex lock error\n",__LINE__);
         }
         pthread_cond_broadcast(&bufferReturned_condition);
         OMX_PRINT1(pComponentPrivate->dbg, "Sending pthread signal that OMX has returned all buffers to app");
         if(pthread_mutex_unlock(&bufferReturned_mutex) != 0)
         {
-            OMX_PRINT1(pComponentPrivate->dbg, "bufferReturned_mutex mutex unlock error");
+            OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex unlock error\n",__LINE__);
         }
         return;
     }
diff --git a/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEncoder.c b/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEncoder.c
index c3f9e11..5d4d148 100644
--- a/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEncoder.c
+++ b/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEncoder.c
@@ -1820,14 +1820,19 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef= NULL;
     AACENC_COMPONENT_PRIVATE *pComponentPrivate= NULL;
-
+    BUFFERLIST *pBufferList = NULL;
     OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
-    OMX_CONF_CHECK_CMD(hComponent,pBuffer,1); 
+    OMX_CONF_CHECK_CMD(hComponent,pBuffer,1);
 
     pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)
             (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering AllocateBuffer\n", __LINE__);
 
+    if (nPortIndex != INPUT_PORT && nPortIndex != OUTPUT_PORT)
+    {
+        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AllocateBuffer: Error - Unknown port index %ld\n",__LINE__, nPortIndex);
+        return OMX_ErrorBadPortIndex;
+    }
     pPortDef = ((AACENC_COMPONENT_PRIVATE*)
                     pComponentPrivate)->pPortDef[nPortIndex];
 
@@ -1836,32 +1841,48 @@
     {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
-    }   
+    }
 #endif
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedBuffer(pComponentPrivate->pPERF,(*pBuffer)->pBuffer,nSizeBytes,PERF_ModuleMemory);
 #endif
+    if (pPortDef->bPopulated)
+    {
+        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AllocateBuffer - Error: port (%ld) already populated\n", __LINE__, nPortIndex);
+        eError = OMX_ErrorIncorrectStateOperation;
+        goto EXIT;
+    }
 
+
+    // FIXME:
+    // Should we remove the following while loop and just check make sure that
+    // pPortDef->bEnabled == true, as we do in UseBuffer()?
     OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef = %p\n", __LINE__, pPortDef);
     OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->bEnabled = %d\n", __LINE__, pPortDef->bEnabled);
-    while (1) 
+    while (1)
     {
-        if(pPortDef->bEnabled) 
+        if (pPortDef->bEnabled)
         {
             break;
         }
-        pComponentPrivate->AlloBuf_waitingsignal = 1;  
+        pComponentPrivate->AlloBuf_waitingsignal = 1;
 
 #ifndef UNDER_CE
-        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex); 
+        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
         pthread_cond_wait(&pComponentPrivate->AlloBuf_threshold, &pComponentPrivate->AlloBuf_mutex);
         pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
 #else
         OMX_WaitForEvent(&(pComponentPrivate->AlloBuf_event));
 #endif
         break;
+    }
 
+    if (nSizeBytes != pPortDef->nBufferSize)
+    {
+        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: nSizeBytes(%ld) != nBufferSize(%ld)\n", __LINE__, nSizeBytes, pPortDef->nBufferSize);
+        eError = OMX_ErrorBadParameter;
+        goto EXIT;
     }
 
     OMX_MALLOC_STRUCT(pBufferHeader, OMX_BUFFERHEADERTYPE);
@@ -1872,49 +1893,31 @@
     pBufferHeader->pBuffer += 128;
     OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader->pbuffer %p to %p \n",pBufferHeader->pBuffer,(pBufferHeader->pBuffer + sizeof(pBufferHeader->pBuffer)) );
 
-    if (nPortIndex == INPUT_PORT) 
+    if (nPortIndex == INPUT_PORT)
     {
+        pBufferList = pComponentPrivate->pInputBufferList;
         pBufferHeader->nInputPortIndex = nPortIndex;
         pBufferHeader->nOutputPortIndex = -1;
-        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pInputBufferList->pBufHdr[%d] = %p\n",__LINE__, pComponentPrivate->pInputBufferList->numBuffers,pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers]);
-        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
-        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pInputBufferList->numBuffers = %d \n",__LINE__, pComponentPrivate->pInputBufferList->numBuffers);
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->nBufferCountMin = %ld \n",__LINE__, pPortDef->nBufferCountMin);
-        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) 
-        {
-            pPortDef->bPopulated = OMX_TRUE;
-        }
-        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: INPUT PORT - pPortDef->bPopulated = %d\n",__LINE__, pPortDef->bPopulated);
     }
-    else if (nPortIndex == OUTPUT_PORT) 
+    else
     {
+        pBufferList = pComponentPrivate->pOutputBufferList;
         pBufferHeader->nInputPortIndex = -1;
         pBufferHeader->nOutputPortIndex = nPortIndex;
-        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
-        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pOutputBufferList->pBufHdr[%d] = %p\n",__LINE__, pComponentPrivate->pOutputBufferList->numBuffers,pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers]);
-        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pOutputBufferList->numBuffers = %d \n",__LINE__, pComponentPrivate->pOutputBufferList->numBuffers);
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->nBufferCountMin = %ld \n",__LINE__, pPortDef->nBufferCountMin);
-        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) 
-        {
-            pPortDef->bPopulated = OMX_TRUE;
-        }
-        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: OUTPUT PORT - pPortDef->bPopulated = %d\n",__LINE__, pPortDef->bPopulated);
     }
-    else 
+    pBufferList->pBufHdr[pBufferList->numBuffers] = pBufferHeader;
+    pBufferList->bBufferPending[pBufferList->numBuffers] = 0;
+    pBufferList->bufferOwner[pBufferList->numBuffers++] = 1;
+    if (pBufferList->numBuffers == pPortDef->nBufferCountActual)
     {
-        eError = OMX_ErrorBadPortIndex;
-        goto EXIT;
+        pPortDef->bPopulated = OMX_TRUE;
     }
 
-  if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&&
+    if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&&
        (pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled) &&
        (pComponentPrivate->InLoaded_readytoidle))
     {
-        pComponentPrivate->InLoaded_readytoidle = 0;                  
+        pComponentPrivate->InLoaded_readytoidle = 0;
 #ifndef UNDER_CE
         pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
         pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
@@ -1932,7 +1935,7 @@
     pComponentPrivate->nVersion = pBufferHeader->nVersion.nVersion;
     pBufferHeader->nSize = sizeof(OMX_BUFFERHEADERTYPE);
     *pBuffer = pBufferHeader;
-    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) 
+    if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated)
     {
         SendCommand (pComponentPrivate->pHandle,OMX_CommandPortEnable,pComponentPrivate->nEnableCommandParam,NULL);
     }
@@ -1943,7 +1946,6 @@
 
 EXIT:
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC:  AllocateBuffer returning eError =  %d\n",__LINE__,eError);
-
     OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader = %p\n",pBufferHeader);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader->pBuffer = %p\n",pBufferHeader->pBuffer);
     return eError;
@@ -1967,161 +1969,96 @@
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_CONF_CHECK_CMD(hComponent,1,pBuffer);
-    AACENC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
-    OMX_BUFFERHEADERTYPE* buff = NULL;
+    OMX_BUFFERHEADERTYPE* buffHdr = NULL;
     OMX_U8* tempBuff = NULL;
-    int i =0;
-    int inputIndex = -1;
-    int outputIndex = -1;
-    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U32 i = 0;
+    int bufferIndex = -1;
+    BUFFERLIST *pBuffList = NULL;
+    OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
+    AACENC_COMPONENT_PRIVATE *pComponentPrivate = ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
 
-    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
-    OMX_PRINT1 (pComponentPrivate->dbg, "%d :: AACENC: FreeBuffer\n", __LINE__);
+    OMX_PRINT1 (pComponentPrivate->dbg, "%d :: AACENC: FreeBuffer for port index %ld\n", __LINE__, nPortIndex);
 
-    pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate = %p\n", __LINE__,pComponentPrivate);
-    for (i=0; i < MAX_NUM_OF_BUFS; i++) 
+    if (nPortIndex != INPUT_PORT && nPortIndex != OUTPUT_PORT)
     {
-        buff = pComponentPrivate->pInputBufferList->pBufHdr[i];
-        if (buff == pBuffer) 
+        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: Error - Unknown port index %ld\n",__LINE__, nPortIndex);
+        return OMX_ErrorBadPortIndex;
+    }
+
+    pBuffList = ((nPortIndex == INPUT_PORT)? pComponentPrivate->pInputBufferList: pComponentPrivate->pOutputBufferList);
+    pPortDef = pComponentPrivate->pPortDef[nPortIndex];
+    for (i = 0; i < pPortDef->nBufferCountActual; ++i)
+    {
+        buffHdr = pBuffList->pBufHdr[i];
+        if (buffHdr == pBuffer)
         {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Found matching input buffer\n",__LINE__);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buff = %p\n",__LINE__,buff);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Found matching %s buffer\n",__LINE__, nPortIndex == INPUT_PORT? "input": "output");
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buffHdr = %p\n",__LINE__,buffHdr);
             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer);
-            inputIndex = i;
+            bufferIndex = i;
             break;
         }
-        else 
+        else
         {
             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: This is not a match\n",__LINE__);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buff = %p\n",__LINE__,buff);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buffHdr = %p\n",__LINE__,buffHdr);
             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer);
         }
     }
 
-    for (i=0; i < MAX_NUM_OF_BUFS; i++) 
+    if (bufferIndex == -1)
     {
-        buff = pComponentPrivate->pOutputBufferList->pBufHdr[i];
-        if (buff == pBuffer) 
-        {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: Found matching output buffer\n",__LINE__);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buff = %p\n",__LINE__,buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer);
-            outputIndex = i;
-            break;
-        }
-        else 
-        {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: This is not a match\n",__LINE__);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buff = %p\n",__LINE__,buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pBuffer = %p\n",__LINE__,pBuffer);
-        }
+        OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: Error - could not find match for buffer %p\n",__LINE__, pBuffer);
+        return OMX_ErrorBadParameter;
     }
 
-
-    if (inputIndex != -1) 
+    if (pBuffList->bufferOwner[bufferIndex] == 1)
     {
-        if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) 
+        tempBuff = buffHdr->pBuffer;
+        if (tempBuff != 0)
         {
-            tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
-            if (tempBuff != 0)
-            {
-                tempBuff -= 128;
-            }
-            OMX_MEMFREE_STRUCT(tempBuff);
+            tempBuff -= 128;
         }
+
 #ifdef __PERF_INSTRUMENTATION__
-            PERF_SendingBuffer(pComponentPrivate->pPERF,
-                               pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, 
-                               pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->nAllocLen,
-                               PERF_ModuleMemory );
-
+        PERF_SendingBuffer(pComponentPrivate->pPERF,
+                           buffHdr->pBuffer,
+                           buffHdr->nAllocLen,
+                           PERF_ModuleMemory);
 #endif
-        
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [FREE] %p\n",__LINE__,pComponentPrivate->pBufHeader[INPUT_PORT]);
-        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
-        pComponentPrivate->pInputBufferList->numBuffers--;
 
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pInputBufferList->numBuffers = %d \n",__LINE__,pComponentPrivate->pInputBufferList->numBuffers);
-        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountMin = %ld \n",__LINE__,pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountMin);
-        if (pComponentPrivate->pInputBufferList->numBuffers < pComponentPrivate->pPortDef[INPUT_PORT]->nBufferCountActual) 
-        {
-
-            pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated = OMX_FALSE;
-        }
-        
-        if(pComponentPrivate->pPortDef[INPUT_PORT]->bEnabled &&
-            pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
-            (pComponentPrivate->curState == OMX_StateIdle ||
-            pComponentPrivate->curState == OMX_StateExecuting ||
-            pComponentPrivate->curState == OMX_StatePause)) 
-        {
-            OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENC: PortUnpopulated\n",__LINE__);
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                    pHandle->pApplicationPrivate,
-                                                    OMX_EventError, 
-                                                    OMX_ErrorPortUnpopulated,
-                                                    OMX_TI_ErrorMinor, 
-                                                    "Input Port Unpopulated");
-        }
+        OMX_MEMFREE_STRUCT(tempBuff);
     }
-    else if (outputIndex != -1) 
+    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [FREE] %p\n",__LINE__, buffHdr);
+    OMX_MEMFREE_STRUCT(buffHdr);
+    pBuffList->pBufHdr[bufferIndex] = NULL;
+    pBuffList->numBuffers--;
+    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: numBuffers = %d \n",__LINE__, pBuffList->numBuffers);
+    if (pBuffList->numBuffers < pPortDef->nBufferCountActual)
     {
-        if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) 
-        {
-            tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
-            if (tempBuff != 0)
-            {
-               tempBuff -= 128;
-            }
-            OMX_MEMFREE_STRUCT(tempBuff);
-        }
-#ifdef __PERF_INSTRUMENTATION__
-            PERF_SendingBuffer(pComponentPrivate->pPERF,
-                               pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, 
-                               pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->nAllocLen,
-                               PERF_ModuleMemory);
-
-#endif
-        
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [FREE] %p\n",__LINE__,pComponentPrivate->pBufHeader[OUTPUT_PORT]);
-        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
-        pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex] = NULL;
-        pComponentPrivate->pOutputBufferList->numBuffers--;
-
-        OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pOutputBufferList->numBuffers = %d \n",__LINE__,pComponentPrivate->pOutputBufferList->numBuffers);
-        OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountMin = %ld \n",__LINE__,pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountMin);
-        if (pComponentPrivate->pOutputBufferList->numBuffers <
-            pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountActual) 
-        {
-
-            pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated = OMX_FALSE;
-        }
-        if(pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled &&
-            pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
-            (pComponentPrivate->curState == OMX_StateIdle ||
-            pComponentPrivate->curState == OMX_StateExecuting ||
-            pComponentPrivate->curState == OMX_StatePause)) 
-        {
-            OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENC: PortUnpopulated\n",__LINE__);
-            pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                    pHandle->pApplicationPrivate,
-                                                    OMX_EventError, 
-                                                    OMX_ErrorPortUnpopulated,
-                                                    OMX_TI_ErrorMinor, 
-                                                    "Output Port Unpopulated");
-        }
+        pPortDef->bPopulated = OMX_FALSE;
     }
-    else 
+
+    if (pPortDef->bEnabled &&
+        pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
+        (pComponentPrivate->curState == OMX_StateIdle ||
+         pComponentPrivate->curState == OMX_StateExecuting ||
+         pComponentPrivate->curState == OMX_StatePause))
     {
-        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Returning OMX_ErrorBadParameter\n",__LINE__);
-        eError = OMX_ErrorBadParameter;
+       OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: AACENC: PortUnpopulated\n",__LINE__);
+       pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                              pComponentPrivate->pHandle->pApplicationPrivate,
+                                              OMX_EventError,
+                                              OMX_ErrorPortUnpopulated,
+                                              OMX_TI_ErrorMinor,
+                                              "Port Unpopulated");
     }
+
     if ((!pComponentPrivate->pInputBufferList->numBuffers &&
          !pComponentPrivate->pOutputBufferList->numBuffers) &&
          pComponentPrivate->InIdle_goingtoloaded)
     {
-        pComponentPrivate->InIdle_goingtoloaded = 0;                  
+        pComponentPrivate->InIdle_goingtoloaded = 0;
 #ifndef UNDER_CE
         pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
         pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
@@ -2131,13 +2068,14 @@
 #endif
     }
 
-    if (pComponentPrivate->bDisableCommandPending && (pComponentPrivate->pInputBufferList->numBuffers + pComponentPrivate->pOutputBufferList->numBuffers == 0)) 
+    if (pComponentPrivate->bDisableCommandPending &&
+        (pComponentPrivate->pInputBufferList->numBuffers + pComponentPrivate->pOutputBufferList->numBuffers == 0))
     {
         SendCommand (pComponentPrivate->pHandle,OMX_CommandPortDisable,pComponentPrivate->bDisableCommandParam,NULL);
     }
 
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting FreeBuffer\n", __LINE__);
 EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting FreeBuffer\n", __LINE__);
     return eError;
 }
 
@@ -2161,10 +2099,16 @@
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef= NULL;
     AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
+    BUFFERLIST *pBufferList = NULL;
     OMX_CONF_CHECK_CMD(hComponent,ppBufferHdr,pBuffer);
 
     OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC: Entering UseBuffer\n", __LINE__);
     OMXDBG_PRINT(stderr, BUFFER, 2, 0, "%d :: AACENC: pBuffer = %p\n", __LINE__,pBuffer);
+    if (nPortIndex != INPUT_PORT && nPortIndex != OUTPUT_PORT)
+    {
+        OMX_ERROR4(pComponentPrivate->dbg, "UseBuffer: Error - Unknown port index %ld", nPortIndex);
+        return OMX_ErrorBadPortIndex;
+    }
     pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)
             (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
@@ -2182,14 +2126,19 @@
                             PERF_ModuleHLMM);
 #endif
 
+
     pPortDef = ((AACENC_COMPONENT_PRIVATE*)
                     pComponentPrivate)->pPortDef[nPortIndex];
-    OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef = %p\n", __LINE__,pPortDef);
-    OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: AACENC: pPortDef->bEnabled = %d\n", __LINE__,pPortDef->bEnabled);
-
-    if(!pPortDef->bEnabled) 
+    if (!pPortDef->bEnabled || pPortDef->bPopulated)
     {
-        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: In AllocateBuffer\n", __LINE__);
+        if (!pPortDef->bEnabled)
+        {
+            OMX_ERROR4(pComponentPrivate->dbg, "%d :: UseBuffer - Error: port (%ld) not enabled\n", __LINE__, nPortIndex);
+        }
+        if (pPortDef->bPopulated)
+        {
+            OMX_ERROR4(pComponentPrivate->dbg, "%d :: UseBuffer - Error: port (%ld) already populated\n", __LINE__, nPortIndex);
+        }
         eError = OMX_ErrorIncorrectStateOperation;
         goto EXIT;
     }
@@ -2197,10 +2146,9 @@
     OMX_PRINT2(pComponentPrivate->dbg, "AACENC: nSizeBytes = %ld\n",nSizeBytes);
     OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: pPortDef->nBufferSize = %ld\n",pPortDef->nBufferSize);
     OMX_PRBUFFER1(pComponentPrivate->dbg, "AACENC: pPortDef->bPopulated = %d\n",pPortDef->bPopulated);
-    if(nSizeBytes != pPortDef->nBufferSize || pPortDef->bPopulated) 
+    if(nSizeBytes != pPortDef->nBufferSize)
     {
-        OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error: In AllocateBuffer\n", __LINE__);
-        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: About to return OMX_ErrorBadParameter\n",__LINE__);
+        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: nSizeBytes(%ld) != nBufferSize(%ld)\n", __LINE__, nSizeBytes, pPortDef->nBufferSize);
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
@@ -2208,30 +2156,22 @@
     OMX_MALLOC_STRUCT(pBufferHeader, OMX_BUFFERHEADERTYPE);
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [ALLOC] %p\n",__LINE__,pBufferHeader);
-
-    if (nPortIndex == OUTPUT_PORT) 
+    if (nPortIndex == OUTPUT_PORT)
     {
+        pBufferList = pComponentPrivate->pOutputBufferList;
         pBufferHeader->nInputPortIndex = -1;
-        pBufferHeader->nOutputPortIndex = nPortIndex; 
-        pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
-        pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
-        pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
-        if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) 
-        {
-            pPortDef->bPopulated = OMX_TRUE;
-        }
-    }
-    else 
-    {
+        pBufferHeader->nOutputPortIndex = nPortIndex;
+    } else {
+        pBufferList = pComponentPrivate->pInputBufferList;
         pBufferHeader->nInputPortIndex = nPortIndex;
-        pBufferHeader->nOutputPortIndex = -1; 
-        pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
-        pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
-        pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 0;
-        if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) 
-        {
-            pPortDef->bPopulated = OMX_TRUE;
-        }
+        pBufferHeader->nOutputPortIndex = -1;
+    }
+    pBufferList->pBufHdr[pBufferList->numBuffers] = pBufferHeader;
+    pBufferList->bBufferPending[pBufferList->numBuffers] = 0;
+    pBufferList->bufferOwner[pBufferList->numBuffers++] = 0;
+    if (pBufferList->numBuffers == pPortDef->nBufferCountActual)
+    {
+        pPortDef->bPopulated = OMX_TRUE;
     }
 
     if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&&
@@ -2307,9 +2247,9 @@
     }
     else if (!(strcmp(cParameterName,"OMX.TI.AAC.Encode.Debug")))
     {
-	*pIndexType =OMX_IndexCustomDebug;
+        *pIndexType =OMX_IndexCustomDebug;
     }
-    else 
+    else
     {
         eError = OMX_ErrorBadParameter;
     }
@@ -2334,19 +2274,16 @@
       OMX_IN OMX_U32 nIndex)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
-    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
+    AACENC_COMPONENT_PRIVATE *pComponentPrivate = ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
     if(nIndex == 0)
     {
       memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
     }
-    else 
+    else
     {
       eError = OMX_ErrorNoMore;
-      goto EXIT;
     }
 
-EXIT:  
     return eError;
 };
 
diff --git a/omx/audio/src/openmax_il/mp3_dec/inc/OMX_Mp3Dec_Utils.h b/omx/audio/src/openmax_il/mp3_dec/inc/OMX_Mp3Dec_Utils.h
index d10ff36..023c54b 100644
--- a/omx/audio/src/openmax_il/mp3_dec/inc/OMX_Mp3Dec_Utils.h
+++ b/omx/audio/src/openmax_il/mp3_dec/inc/OMX_Mp3Dec_Utils.h
@@ -323,6 +323,13 @@
     MP3D_INPUT_PORT = 0,
     MP3D_OUTPUT_PORT
 }MP3D_COMP_PORT_TYPE;
+/* ======================================================================= */
+/**
+ * pthread variable to indicate OMX returned all buffers to app
+ */
+/* ======================================================================= */
+    pthread_mutex_t bufferReturned_mutex;
+    pthread_cond_t bufferReturned_condition;
 
 /* ======================================================================= */
 /** OMX_INDEXAUDIOTYPE: This enum is used by the TI OMX Component.
@@ -474,6 +481,7 @@
 typedef struct {
     /* Number of frames in a buffer */
     unsigned long ulFrameCount;
+    unsigned long ulIsLastBuffer;
 }MP3DEC_UAlgOutBufParamStruct;
 
 /* ======================================================================= */
@@ -728,16 +736,18 @@
     OMX_U32 bEnableCommandPending;
     OMX_U32 bEnableCommandParam;
 
+    /*Counts number of invalid buffers from DSP */
     OMX_U32 nInvalidFrameCount;
+    /* Count number of pending output buffrs */
     OMX_U32 numPendingBuffers;
     OMX_U32 bNoIdleOnStop;
     OMX_U32 bDspStoppedWhileExecuting;
     OMX_BOOL bLoadedCommandPending;
 
-    /** Number of FillBufferDones acomplished, used to transition to idle */
-    OMX_S32 nOutStandingFillDones;
-    OMX_S8 nUnhandledFillThisBuffers;
-    OMX_S8 nUnhandledEmptyThisBuffers;
+    /** Counts number of buffers received from client */
+    OMX_U32 nHandledFillThisBuffers;
+    /** Count number of buffers recieved from client */
+    OMX_U32 nHandledEmptyThisBuffers;
     OMX_BOOL bFlushOutputPortCommandPending;
     OMX_BOOL bFlushInputPortCommandPending;
 
@@ -1099,4 +1109,17 @@
 /*  =========================================================================*/
 OMX_U32 MP3DEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition);
 
+/*=======================================================================*/
+/*! @fn SignalIfAllBuffersAreReturned
+
+ * @brief Sends pthread signal to indicate OMX has returned all buffers to app
+
+ * @param  none
+
+ * @Return void
+
+ */
+/*=======================================================================*/
+void SignalIfAllBuffersAreReturned(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate);
+
 #endif
diff --git a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c
index c9c23fe..8321ec8 100644
--- a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c
+++ b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_Utils.c
@@ -347,6 +347,7 @@
         char_temp += EXTRA_BYTES;
         pTemp_lcml->pOpParam = (MP3DEC_UAlgOutBufParamStruct*)char_temp;
         pTemp_lcml->pOpParam->ulFrameCount = DONT_CARE;
+        pTemp_lcml->pOpParam->ulIsLastBuffer = 0;
 
         pTemp->nFlags = NORMAL_BUFFER;
         ((MP3DEC_COMPONENT_PRIVATE *)pTemp->pPlatformPrivate)->pHandle = pHandle;
@@ -1328,6 +1329,7 @@
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pComponentPrivate->pInputBufferList->pBufHdr[i]);
                         pComponentPrivate->nEmptyBufferDoneCount++;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                 }
 
@@ -1691,8 +1693,9 @@
     else if (command == OMX_CommandFlush) {
         OMX_U32 aParam[3] = {0};
         if(commandData == 0x0 || commandData == -1) {
-            OMX_ERROR2(pComponentPrivate->dbg, "Flushing input port:: unhandled ETB's = %d\n", pComponentPrivate->nUnhandledEmptyThisBuffers);
-            if (pComponentPrivate->nUnhandledEmptyThisBuffers == 0)  {
+            OMX_ERROR2(pComponentPrivate->dbg, "Flushing input port:: unhandled ETB's = %ld, handled ETB's = %ld\n",
+                       pComponentPrivate->nEmptyThisBufferCount, pComponentPrivate->nHandledEmptyThisBuffers);
+            if (pComponentPrivate->nEmptyThisBufferCount == pComponentPrivate->nHandledEmptyThisBuffers)  {
                 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
                 pComponentPrivate->first_buff = 0;
                 OMX_ERROR2(pComponentPrivate->dbg, "in flush IN:lcml_nCntApp && app_nBuf = %ld && %ld\n", pComponentPrivate->lcml_nCntApp, pComponentPrivate->app_nBuf);
@@ -1731,6 +1734,8 @@
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pComponentPrivate->pInputBufHdrPending[i]);
                         pComponentPrivate->pInputBufHdrPending[i] = NULL;
+                        pComponentPrivate->nEmptyBufferDoneCount++;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                     pComponentPrivate->nNumInputBufPending=0;    
                     pComponentPrivate->cbInfo.EventHandler(pHandle, 
@@ -1745,8 +1750,9 @@
             }
         }
         if(commandData == 0x1 || commandData == -1){
-            OMX_ERROR2(pComponentPrivate->dbg, "Flushing output port:: unhandled FTB's = %d\n", pComponentPrivate->nUnhandledFillThisBuffers);
-            if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
+            OMX_ERROR2(pComponentPrivate->dbg, "Flushing output port:: unhandled FTB's = %ld handled FTB's = %ld\n",
+                       pComponentPrivate->nFillThisBufferCount, pComponentPrivate->nHandledFillThisBuffers);
+            if (pComponentPrivate->nFillThisBufferCount == pComponentPrivate->nHandledFillThisBuffers)  {
                 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
                 /*pComponentPrivate->first_buff = 0;*/
                 OMX_PRBUFFER2(pComponentPrivate->dbg, "in flush OUT:lcml_nCntApp && app_nBuf = %ld && %ld\n", pComponentPrivate->lcml_nCntApp, pComponentPrivate->app_nBuf);
@@ -1785,8 +1791,9 @@
                                                                   pComponentPrivate->pHandle->pApplicationPrivate,
                                                                   pComponentPrivate->pOutputBufHdrPending[i]
                                                                   );
-                        pComponentPrivate->nOutStandingFillDones--;
+                        pComponentPrivate->nFillBufferDoneCount++;
                         pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                     pComponentPrivate->nNumOutputBufPending=0;
 
@@ -1856,25 +1863,17 @@
         goto EXIT;
     }
 
-
-
-    if (pComponentPrivate->curState == OMX_StateIdle){
-       if (eDir == OMX_DirInput) {
-               pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
-                       pComponentPrivate->pHandle->pApplicationPrivate,
-                       pBufHeader);
-               OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return input buffers\n", __LINE__, __FUNCTION__);
-               }
-       else if (eDir == OMX_DirOutput) {
-               pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
-                       pComponentPrivate->pHandle->pApplicationPrivate,
-                       pBufHeader);
-               OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return output buffers\n", __LINE__, __FUNCTION__);
-               }
-       goto EXIT;
-    }
     if (eDir == OMX_DirInput) {
-        pComponentPrivate->nUnhandledEmptyThisBuffers--;
+        pComponentPrivate->nHandledEmptyThisBuffers++;
+        if (pComponentPrivate->curState == OMX_StateIdle){
+            pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       pBufHeader);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return input buffers\n", __LINE__, __FUNCTION__);
+            pComponentPrivate->nEmptyBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+            goto EXIT;
+        }
         LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
         MP3D_LCML_BUFHEADERTYPE *pLcmlHdr;
         pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
@@ -2115,6 +2114,8 @@
                                            pComponentPrivate->pHandle,
                                            pComponentPrivate->pHandle->pApplicationPrivate,
                                            pBufHeader);
+                        pComponentPrivate->nEmptyBufferDoneCount++;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                     pComponentPrivate->lcml_nCntIp++;
                     pComponentPrivate->lcml_nIpBuf++;
@@ -2138,6 +2139,7 @@
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        pComponentPrivate->pInputBufferList->pBufHdr[0]);
             pComponentPrivate->nEmptyBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
         }
         if(pBufHeader->pMarkData){
             OMX_PRBUFFER2(pComponentPrivate->dbg, ":Detected pBufHeader->pMarkData\n");
@@ -2161,7 +2163,16 @@
         }
     }
     else if (eDir == OMX_DirOutput) {
-        pComponentPrivate->nUnhandledFillThisBuffers--;
+        pComponentPrivate->nHandledFillThisBuffers++;
+        if (pComponentPrivate->curState == OMX_StateIdle){
+            pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
+                                                      pComponentPrivate->pHandle->pApplicationPrivate,
+                                                      pBufHeader);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return output buffers\n", __LINE__, __FUNCTION__);
+            pComponentPrivate->nFillBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+            goto EXIT;
+        }
         LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
         MP3D_LCML_BUFHEADERTYPE *pLcmlHdr;
         OMX_PRBUFFER2(pComponentPrivate->dbg, ": pComponentPrivate->lcml_nOpBuf = %ld\n",pComponentPrivate->lcml_nOpBuf);
@@ -2420,6 +2431,7 @@
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        pLcmlHdr->pBufHdr);
             pComponentPrivate->nEmptyBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
             pComponentPrivate->lcml_nIpBuf--;
             pComponentPrivate->app_nBuf++;
 
@@ -2445,10 +2457,10 @@
                                                           pComponentPrivate->pHandle->pApplicationPrivate,
                                                           pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->nInvalidFrameCount++]
                                                           );
-                /*pComponentPrivate->nOutStandingFillDones--;*/
+                pComponentPrivate->nFillBufferDoneCount++;
                 pComponentPrivate->numPendingBuffers--;
+                SignalIfAllBuffersAreReturned(pComponentPrivate);
             }else {
-                pComponentPrivate->nOutStandingFillDones++;
                 eError = MP3DEC_GetCorresponding_LCMLHeader(pComponentPrivate, pBuffer, OMX_DirOutput, &pLcmlHdr);
                 if (eError != OMX_ErrorNone) {
                     OMX_ERROR4(pComponentPrivate->dbg, ":: Error: Invalid Buffer Came ...\n");
@@ -2483,18 +2495,16 @@
                 }
                 pComponentPrivate->num_Reclaimed_Op_Buff++;
 
-                if (pComponentPrivate->bIsEOFSent){ 		
+                if (pLcmlHdr->pOpParam->ulIsLastBuffer){
                     OMX_PRBUFFER2(pComponentPrivate->dbg, "Adding EOS flag to the output buffer\n");
-                    /* Send OMX_EventBufferFlag until PLAY COMPLETED DSP event is returned */
-                    /*
                     pLcmlHdr->pBufHdr->nFlags |= OMX_BUFFERFLAG_EOS;
                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                            pComponentPrivate->pHandle->pApplicationPrivate,
                                                            OMX_EventBufferFlag,
                                                            pLcmlHdr->pBufHdr->nOutputPortIndex,
                                                            pLcmlHdr->pBufHdr->nFlags, NULL);
-                    */
                     pComponentPrivate->bIsEOFSent = 0;
+                    pLcmlHdr->pOpParam->ulIsLastBuffer=0;
                 }
 
                 if(pComponentPrivate->frameMode){
@@ -2534,11 +2544,10 @@
                 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
                                                           pComponentPrivate->pHandle->pApplicationPrivate,
                                                           pLcmlHdr->pBufHdr);
-                pComponentPrivate->nOutStandingFillDones--;
                 pComponentPrivate->lcml_nOpBuf--;
                 pComponentPrivate->app_nBuf++;
                 pComponentPrivate->nFillBufferDoneCount++;
-
+                SignalIfAllBuffersAreReturned(pComponentPrivate);
             }
         }
     }else if(event == EMMCodecProcessingStoped) { 
@@ -2547,7 +2556,9 @@
 	pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
 						   pComponentPrivate->pHandle->pApplicationPrivate,
 						   pComponentPrivate->pInputBufHdrPending[i]);
-	pComponentPrivate->pInputBufHdrPending[i] = NULL;
+                    pComponentPrivate->nEmptyBufferDoneCount++;
+			        pComponentPrivate->pInputBufHdrPending[i] = NULL;
+                    SignalIfAllBuffersAreReturned(pComponentPrivate);
       }
       pComponentPrivate->nNumInputBufPending = 0;
       for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
@@ -2555,8 +2566,10 @@
 	pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
 						  pComponentPrivate->pHandle->pApplicationPrivate,
 						  pComponentPrivate->pOutputBufHdrPending[i]
-						  );                        pComponentPrivate->nOutStandingFillDones--;
-	pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+						  );
+                    pComponentPrivate->nFillBufferDoneCount++;
+			        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+                    SignalIfAllBuffersAreReturned(pComponentPrivate);
       }
       pComponentPrivate->nNumOutputBufPending=0;
         pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
@@ -2577,6 +2590,23 @@
                                               3456,
                                               NULL);
 #endif  
+            if((pComponentPrivate->nEmptyThisBufferCount != pComponentPrivate->nEmptyBufferDoneCount) || (pComponentPrivate->nFillThisBufferCount != pComponentPrivate->nFillBufferDoneCount)) {
+                if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
+                {
+                    OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex lock error\n",__LINE__);
+                }
+                OMX_PRINT2(pComponentPrivate->dbg, ":: pthread_cond_waiting for OMX to return all input and outbut buffers\n");
+                pthread_cond_wait(&bufferReturned_condition, &bufferReturned_mutex);
+                OMX_PRINT2(pComponentPrivate->dbg, ":: OMX has returned all input and output buffers\n");
+                if(pthread_mutex_unlock(&bufferReturned_mutex) != 0)
+                {
+                    OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex unlock error\n",__LINE__);
+                }
+            }
+            else
+            {
+                OMX_PRINT2(pComponentPrivate->dbg, ":: OMX has returned all input and output buffers\n");
+            }
             if(pComponentPrivate->bPreempted==0){
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
@@ -2650,33 +2680,6 @@
                                                    OMX_BUFFERFLAG_EOS,
                                                    NULL);
 #endif
-///incase any pending output buffers, clear them
-            for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
-                if (MP3DEC_IsPending(pComponentPrivate,pComponentPrivate->pOutputBufferList->pBufHdr[i],OMX_DirOutput)) {
-                    pComponentPrivate->lastout = pComponentPrivate->pOutputBufferList->pBufHdr[i];
-                }
-            }
-            for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
-                if (MP3DEC_IsPending(pComponentPrivate,pComponentPrivate->pOutputBufferList->pBufHdr[i],OMX_DirOutput)) {
-#ifdef __PERF_INSTRUMENTATION__
-                    PERF_SendingFrame(pComponentPrivate->pPERFcomp,
-                                      PREF(pComponentPrivate->pOutputBufferList->pBufHdr[i], pBuffer),
-                                      0,
-                                      PERF_ModuleHLMM);
-#endif                  
-                    pComponentPrivate->pOutputBufferList->pBufHdr[i]->nFilledLen = 0;
-                    if(pComponentPrivate->lastout == pComponentPrivate->pOutputBufferList->pBufHdr[i]){
-                        OMX_ERROR2(pComponentPrivate->dbg, "Mark EOS on OUT buffer!\n");
-                        pComponentPrivate->pOutputBufferList->pBufHdr[i]->nFlags |= OMX_BUFFERFLAG_EOS;
-                    }
-                    OMX_ERROR2(pComponentPrivate->dbg, "FillBufferDone!\n");
-                    pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
-                                                              pComponentPrivate->pHandle->pApplicationPrivate,
-                                                              pComponentPrivate->pOutputBufferList->pBufHdr[i]);
-                    pComponentPrivate->nFillBufferDoneCount++;
-                }
-            }
-//
         }
 
         if((int)args[5] == IUALG_WARN_CONCEALED) {
@@ -2779,7 +2782,9 @@
                         pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pComponentPrivate->pInputBufHdrPending[i]);
+                        pComponentPrivate->nEmptyBufferDoneCount++;
                         pComponentPrivate->pInputBufHdrPending[i] = NULL;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                     pComponentPrivate->nNumInputBufPending=0;
 
@@ -2820,8 +2825,9 @@
                                                                   pComponentPrivate->pHandle->pApplicationPrivate,
                                                                   pComponentPrivate->pOutputBufHdrPending[i]
                                                                   );
-                        pComponentPrivate->nOutStandingFillDones--;
+                        pComponentPrivate->nFillBufferDoneCount++;
                         pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                     pComponentPrivate->nNumOutputBufPending=0;
 
@@ -2847,8 +2853,6 @@
     }
     else if (event == EMMCodecProcessingPaused) { 
 
-        pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
-        pComponentPrivate->nUnhandledFillThisBuffers = 0;
         pComponentPrivate->curState = OMX_StatePause;
         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 
                                                pComponentPrivate->pHandle->pApplicationPrivate,
@@ -3555,6 +3559,7 @@
             char_temp += EXTRA_BYTES;
             pTemp_lcml->pOpParam = (MP3DEC_UAlgOutBufParamStruct*)char_temp;
             pTemp_lcml->pOpParam->ulFrameCount = DONT_CARE;
+            pTemp_lcml->pOpParam->ulIsLastBuffer = 0;
 
             pTemp->nFlags = NORMAL_BUFFER;
             ((MP3DEC_COMPONENT_PRIVATE *)pTemp->pPlatformPrivate)->pHandle = pHandle;
@@ -3606,3 +3611,34 @@
     nOutput = nOutput >> (32 - nBits) ;
     return nOutput;
 }
+/* ========================================================================== */
+/**
+* @SignalIfAllBuffersAreReturned() This function send signals if OMX returned all buffers to app
+*
+* @param AACDEC_COMPONENT_PRIVATE *pComponentPrivate
+*
+* @pre None
+*
+* @post None
+*
+* @return None
+*/
+/* ========================================================================== */
+void SignalIfAllBuffersAreReturned(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate)
+{
+    if((pComponentPrivate->nEmptyThisBufferCount == pComponentPrivate->nEmptyBufferDoneCount) && (pComponentPrivate->nFillThisBufferCount == pComponentPrivate->nFillBufferDoneCount))
+    {
+        if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
+        {
+            OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex lock error\n",__LINE__);
+        }
+        pthread_cond_broadcast(&bufferReturned_condition);
+        OMX_PRINT2(pComponentPrivate->dbg, ":: Sending pthread signal that OMX has returned all buffers to app\n");
+        if(pthread_mutex_unlock(&bufferReturned_mutex) != 0)
+        {
+            OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex unlock error\n",__LINE__);
+        }
+        return;
+    }
+}
+
diff --git a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c
index f37a26f..ea90b96 100644
--- a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c
+++ b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Decoder.c
@@ -333,8 +333,8 @@
     pComponentPrivate->nNumOutputBufPending = 0;
     pComponentPrivate->nNumOutputBufPause = 0;
     pComponentPrivate->SendAfterEOS = 0;    
-    pComponentPrivate->nUnhandledFillThisBuffers=0;
-    pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
+    pComponentPrivate->nHandledFillThisBuffers=0;
+    pComponentPrivate->nHandledEmptyThisBuffers = 0;
     pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
     pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
 
@@ -366,7 +366,6 @@
     pComponentPrivate->numPendingBuffers = 0;
     pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
     pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
-    pComponentPrivate->nOutStandingFillDones = 0;
     pComponentPrivate->sOutPortFormat.eEncoding = OMX_AUDIO_CodingPCM;
 
 
@@ -1559,13 +1558,13 @@
     pComponentPrivate->pMarkData = pBuffer->pMarkData;
     pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
 
-    pComponentPrivate->nUnhandledEmptyThisBuffers++;
     ret = write (pComponentPrivate->dataPipe[1], &pBuffer,
                  sizeof(OMX_BUFFERHEADERTYPE*));
     if (ret == -1) {
         MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
+    }else{
+        pComponentPrivate->nEmptyThisBufferCount++;
     }
-    pComponentPrivate->nEmptyThisBufferCount++;
     
  EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, " :: Exiting EmptyThisBuffer\n");
@@ -1683,13 +1682,13 @@
     OMX_PRCOMM2(pComponentPrivate->dbg, "Sending Emptied OUT buff %p\n",pBuffer);
     OMX_PRCOMM2(pComponentPrivate->dbg, "------------------------------------------\n");
 
-    pComponentPrivate->nUnhandledFillThisBuffers++;
     nRet = write (pComponentPrivate->dataPipe[1], &pBuffer,
                   sizeof (OMX_BUFFERHEADERTYPE*));
     if (nRet == -1) {
         MP3D_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
+    }else{
+        pComponentPrivate->nFillThisBufferCount++;
     }
-    pComponentPrivate->nFillThisBufferCount++;
 
  EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, ": Exiting FillThisBuffer\n");
diff --git a/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEncoder.c b/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEncoder.c
index 0a9f78a..5760d95 100644
--- a/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEncoder.c
+++ b/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEncoder.c
@@ -1115,7 +1115,15 @@
         case OMX_IndexParamAudioAmr:
 
                 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: SetParameter OMX_IndexParamAudioAmr \n",__LINE__);
-                pCompAmrParam = (OMX_AUDIO_PARAM_AMRTYPE *)pCompParam;
+
+                // Code below attempts to write to passed-in parameter block,
+                // which not only is illegal (it's supposed to be read-only),
+                // also in this particular case it seems to live in read-only
+                // memory or something.
+                OMX_AUDIO_PARAM_AMRTYPE copy;
+                memcpy(&copy, pCompParam, sizeof(copy));
+                pCompAmrParam = &copy;
+
                 if(pCompAmrParam->nPortIndex == 0) {         /* 0 means Input port */
                     memcpy(((AMRENC_COMPONENT_PRIVATE*)
                             pHandle->pComponentPrivate)->pcmParams, pCompAmrParam, sizeof(OMX_AUDIO_PARAM_AMRTYPE));
diff --git a/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEncoder.c b/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEncoder.c
index 2cf04f7..17c298b 100644
--- a/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEncoder.c
+++ b/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEncoder.c
@@ -1072,7 +1072,15 @@
     case OMX_IndexParamAudioAmr:
     {
         OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioAmr");
-        pCompAmrParam = (OMX_AUDIO_PARAM_AMRTYPE *)pCompParam;
+
+        // Code below attempts to write to passed-in parameter block,
+        // which not only is illegal (it's supposed to be read-only),
+        // also in this particular case it seems to live in read-only
+        // memory or something.
+        OMX_AUDIO_PARAM_AMRTYPE copy;
+        memcpy(&copy, pCompParam, sizeof(copy));
+        pCompAmrParam = &copy;
+
         if(pCompAmrParam->nPortIndex == 0) {         /* 0 means Input port */
             memcpy(((WBAMRENC_COMPONENT_PRIVATE*)
                     pHandle->pComponentPrivate)->pcmParams,
diff --git a/omx/audio/src/openmax_il/wma_dec/inc/OMX_WmaDec_Utils.h b/omx/audio/src/openmax_il/wma_dec/inc/OMX_WmaDec_Utils.h
index fbe2b90..4218d91 100644
--- a/omx/audio/src/openmax_il/wma_dec/inc/OMX_WmaDec_Utils.h
+++ b/omx/audio/src/openmax_il/wma_dec/inc/OMX_WmaDec_Utils.h
@@ -927,8 +927,6 @@
 
     struct OMX_TI_Debug dbg;        
 
-    OMX_BUFFERHEADERTYPE *lastout;
-
 } WMADEC_COMPONENT_PRIVATE;
 /* ===========================================================  */
 /**
diff --git a/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDec_Utils.c b/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDec_Utils.c
index 1ee42fb..9211c88 100644
--- a/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDec_Utils.c
+++ b/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDec_Utils.c
@@ -2291,11 +2291,6 @@
 
             for (i=0; i < pComponentPrivate_CC->pOutputBufferList->numBuffers; i++) {
                 if (WMADEC_IsPending(pComponentPrivate_CC,pComponentPrivate_CC->pOutputBufferList->pBufHdr[i],OMX_DirOutput)) {
-                    pComponentPrivate_CC->lastout = pComponentPrivate_CC->pOutputBufferList->pBufHdr[i];
-                }
-            }
-            for (i=0; i < pComponentPrivate_CC->pOutputBufferList->numBuffers; i++) {
-                if (WMADEC_IsPending(pComponentPrivate_CC,pComponentPrivate_CC->pOutputBufferList->pBufHdr[i],OMX_DirOutput)) {
 #ifdef __PERF_INSTRUMENTATION__
                     PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
                                       PREF(pComponentPrivate_CC->pOutputBufferList->pBufHdr[i], pBuffer),
@@ -2303,9 +2298,9 @@
                                       PERF_ModuleHLMM);
 #endif
                     pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->nFilledLen = 0;
-                    if(pComponentPrivate_CC->lastout == pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]){
-                        pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->nFlags |= OMX_BUFFERFLAG_EOS;
-                    }
+
+                    pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->nFlags |= OMX_BUFFERFLAG_EOS;
+
                     pComponentPrivate_CC->cbInfo.FillBufferDone (pComponentPrivate_CC->pHandle,
                                                                  pComponentPrivate_CC->pHandle->pApplicationPrivate,
                                                                  pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]);
@@ -2347,7 +2342,6 @@
 #endif              
             }
         }
-        pComponentPrivate_CC->first_buffer = 1;
     }
     
     if(event == EMMCodecDspMessageRecieved) {
diff --git a/omx/core_plugin/omx_core_plugin/Android.mk b/omx/core_plugin/omx_core_plugin/Android.mk
index ffdff71..222f0cb 100644
--- a/omx/core_plugin/omx_core_plugin/Android.mk
+++ b/omx/core_plugin/omx_core_plugin/Android.mk
@@ -1,3 +1,5 @@
+ifneq ($(BUILD_WITHOUT_PV),true)
+
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 LOCAL_PRELINK_MODULE := false
@@ -41,3 +43,4 @@
 
 include $(BUILD_SHARED_LIBRARY)
 
+endif
diff --git a/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDecoder.c b/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDecoder.c
index 9d14efb..37c72e2 100644
--- a/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDecoder.c
+++ b/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDecoder.c
@@ -2318,36 +2318,35 @@
 
 /*-------------------------------------------------------------------*/
 /**
-  * GetExtensionIndex_JpegDec() 
+  * GetExtensionIndex_JpegDec()
   *
-  * Free a video driver buffer.
+  * Get custom extension index.
   *
   * @retval OMX_ErrorNone                    Successful operation.
-  *         OMX_ErrorBadParameter            Invalid operation.    
+  *         OMX_ErrorBadParameter            Invalid operation.
   *         OMX_ErrorIncorrectStateOperation If called when port is disabled.
   **/
 /*-------------------------------------------------------------------*/
 OMX_ERRORTYPE GetExtensionIndex_JPEGDec(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE* pIndexType)
 {
-    OMX_U16 nIndex;
     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
     JPEGDEC_CUSTOM_PARAM_DEFINITION sJpegDecCustomParams[] = {
-    {"OMX.TI.JPEG.decode.Config.ProgressiveFactor", OMX_IndexCustomProgressiveFactor},
-    {"OMX.TI.JPEG.decode.Config.InputFrameWidth", OMX_IndexCustomInputFrameWidth},
-    {"OMX.TI.JPEG.decode.Config.OutputColorFormat", OMX_IndexCustomOutputColorFormat},
-    {"OMX.TI.JPEG.decode.Param.SectionDecode", OMX_IndexCustomSectionDecode},
-    {"OMX.TI.JPEG.decode.Param.SubRegionDecode", OMX_IndexCustomSubRegionDecode},
-    {"OMX.TI.JPEG.decode.Param.SetMaxResolution", OMX_IndexCustomSetMaxResolution},
-    {"OMX.TI.JPEG.decode.Debug", OMX_IndexCustomDebug},
-    {"",0x0}
+        {"OMX.TI.JPEG.decode.Config.ProgressiveFactor", OMX_IndexCustomProgressiveFactor},
+        {"OMX.TI.JPEG.decode.Config.InputFrameWidth", OMX_IndexCustomInputFrameWidth},
+        {"OMX.TI.JPEG.decode.Config.OutputColorFormat", OMX_IndexCustomOutputColorFormat},
+        {"OMX.TI.JPEG.decode.Param.SectionDecode", OMX_IndexCustomSectionDecode},
+        {"OMX.TI.JPEG.decode.Param.SubRegionDecode", OMX_IndexCustomSubRegionDecode},
+        {"OMX.TI.JPEG.decode.Param.SetMaxResolution", OMX_IndexCustomSetMaxResolution},
+        {"OMX.TI.JPEG.decode.Debug", OMX_IndexCustomDebug}
     };
 
-    /* Check parameter validity */    
+    /* Check parameter validity */
     OMX_CHECK_PARAM(hComponent);
     OMX_CHECK_PARAM(pIndexType);
-    *pIndexType = OMX_IndexMax;
 
-    for (nIndex = 0; strlen((const char*)sJpegDecCustomParams[nIndex].cCustomParamName); nIndex++){
+    const OMX_U32 nExtensions = sizeof(sJpegDecCustomParams)/sizeof(JPEGDEC_CUSTOM_PARAM_DEFINITION);
+    OMX_U32 nIndex;
+    for (nIndex = 0; nIndex < nExtensions; ++nIndex) {
         if (!strcmp((const char*)cParameterName, (const char*)(&(sJpegDecCustomParams[nIndex].cCustomParamName)))){
             *pIndexType = sJpegDecCustomParams[nIndex].nCustomParamIndex;
             eError = OMX_ErrorNone;
@@ -2355,11 +2354,10 @@
         }
     }
 
-    if(*pIndexType == OMX_IndexMax){
+    if (nIndx >= nExtensions) {
          eError = OMX_ErrorUnsupportedIndex;
     }
 
-    
 EXIT:
     return eError;
 }
diff --git a/omx/image/src/openmax_il/jpeg_enc/inc/OMX_JpegEnc_Utils.h b/omx/image/src/openmax_il/jpeg_enc/inc/OMX_JpegEnc_Utils.h
index 636d3ee..edc4048 100644
--- a/omx/image/src/openmax_il/jpeg_enc/inc/OMX_JpegEnc_Utils.h
+++ b/omx/image/src/openmax_il/jpeg_enc/inc/OMX_JpegEnc_Utils.h
@@ -88,7 +88,7 @@
 #define OMX_CustomCommandStopThread (OMX_CommandMax - 1)
 #define PADDING_128_BYTE 128
 #define PADDING_256_BYTE 256
-
+#define JPEGENC_THUMBNAIL_ABSENT_WARNING 4
 
 #ifdef UNDER_CE
     #include <oaf_debug.h>
diff --git a/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEnc_Utils.c b/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEnc_Utils.c
index b01aff7..f17486a 100644
--- a/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEnc_Utils.c
+++ b/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEnc_Utils.c
@@ -623,7 +623,7 @@
           lcml_dsp->ProfileID = 10;
       }
 #else
-    lcml_dsp->ProfileID = 1;
+    lcml_dsp->ProfileID = 2;
 #endif
 
 
@@ -649,12 +649,12 @@
     */
     ptCreateString[9] = 1;
 
-    ptCreateString[10] = 320; /* Maximum Horizontal Size of the Thumbnail for App0 marker */
-    ptCreateString[11] = 240; /* Maximum Vertical Size of the Thumbnail for App0 marker */
-    ptCreateString[12] = 320; /* Maximum Horizontal Size of the Thumbnail for App1 marker */
-    ptCreateString[13] = 240; /* Maximum Vertical Size of the Thumbnail for App1 marker */
-    ptCreateString[14] = 320; /* Maximum Horizontal Size of the Thumbnail for App13 marker */
-    ptCreateString[15] = 240; /* Maximum Vertical Size of the Thumbnail for App13 marker */
+    ptCreateString[10] = 512; /* Maximum Horizontal Size of the Thumbnail for App0 marker */
+    ptCreateString[11] = 384; /* Maximum Vertical Size of the Thumbnail for App0 marker */
+    ptCreateString[12] = 512; /* Maximum Horizontal Size of the Thumbnail for App1 marker */
+    ptCreateString[13] = 384; /* Maximum Vertical Size of the Thumbnail for App1 marker */
+    ptCreateString[14] = 512; /* Maximum Horizontal Size of the Thumbnail for App13 marker */
+    ptCreateString[15] = 384; /* Maximum Vertical Size of the Thumbnail for App13 marker */
     ptCreateString[16] = 0; /* Number of scans is always 0 */
     if (pPortDefIn->format.image.eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar)
     {
@@ -666,8 +666,8 @@
     	ptCreateString[17] = 1; //Convert flag
     }
 
-    ptCreateString[18] = 320; /* Maximum Horizontal Size of the Thumbnail for App5 marker */
-    ptCreateString[19] = 240; /* Maximum Vertical Size of the Thumbnail for App5 marker */
+    ptCreateString[18] = 512; /* Maximum Horizontal Size of the Thumbnail for App5 marker */
+    ptCreateString[19] = 384; /* Maximum Vertical Size of the Thumbnail for App5 marker */
 	
 #ifdef __JPEG_OMX_PPLIB_ENABLED__
 
@@ -2949,8 +2949,30 @@
     if ( event == EMMCodecDspError ) {
     
        OMX_PRDSP4(pComponentPrivate->dbg, "in EMMCodecDspError EMMCodec Args -> %x, %x\n", (int)argsCb[4] , (int)argsCb[5]);
+
+       if ((int)argsCb[4] == USN_ERR_PROCESS && (int)argsCb[5] == IUALG_ERR_INSUFF_BUFFER) {
+           OMX_PRDSP4(pComponentPrivate->dbg, "DSP Error. The allocated output buffer length is insufficient.\n");
+           pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                     pComponentPrivate->pHandle->pApplicationPrivate,
+                                     OMX_EventError,
+                                     OMX_ErrorInsufficientResources,
+                                     OMX_TI_ErrorCritical,
+                                     "The allocated output buffer length is insufficient");
+           goto EXIT;
+       }
+
        if ((int)argsCb[4] != 0x1 || (int)argsCb[5] != 0x500) {
-	   OMX_PRDSP4(pComponentPrivate->dbg, "DSP Error %x %x\n", (int)(argsCb[4]), (int)(argsCb[5]));
+	   if ((int)argsCb[5] == JPEGENC_THUMBNAIL_ABSENT_WARNING) {
+           OMX_PRDSP4(pComponentPrivate->dbg, "Thumbnail is not generated as it \
+                   exceeds 64K spec size limit for the given thumbnail resolution and yuv data\n");
+           pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                     pComponentPrivate->pHandle->pApplicationPrivate,
+                                     OMX_EventError,
+                                     OMX_ErrorUndefined,
+                                     OMX_TI_ErrorMinor,
+                                     "Thumbnail not generated as it exceeds 64K size limit set by spec");
+	       goto EXIT;
+	   }
            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                      pComponentPrivate->pHandle->pApplicationPrivate,
                                      OMX_EventError, 
diff --git a/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEncoder.c b/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEncoder.c
index 53015e0..a19f0fa 100644
--- a/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEncoder.c
+++ b/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEncoder.c
@@ -2328,7 +2328,7 @@
 
 /*-------------------------------------------------------------------*/
 /**
-  * JPEGENC_GetExtensionIndex() 
+  * JPEGENC_GetExtensionIndex()
   *
   * Return the index corresponding to the string.
   *
@@ -2338,30 +2338,29 @@
 /*-------------------------------------------------------------------*/
 OMX_ERRORTYPE JPEGENC_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, OMX_IN OMX_STRING cParameterName, OMX_OUT OMX_INDEXTYPE* pIndexType)
 {
-    OMX_U16 nIndex;
     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
     JPEGENC_CUSTOM_PARAM_DEFINITION sJpegEncCustomParams[] = {
-    {"OMX.TI.JPEG.encoder.Config.HuffmanTable", OMX_IndexCustomHuffmanTable},    
-    {"OMX.TI.JPEG.encoder.Config.CommentFlag", OMX_IndexCustomCommentFlag},
-    {"OMX.TI.JPEG.encoder.Config.CommentString", OMX_IndexCustomCommentString},
-    {"OMX.TI.JPEG.encoder.Config.InputFrameWidth", OMX_IndexCustomInputFrameWidth},
-    {"OMX.TI.JPEG.encoder.Config.InputFrameHeight", OMX_IndexCustomInputFrameHeight},
-    {"OMX.TI.JPEG.encoder.Config.APP0", OMX_IndexCustomAPP0},
-    {"OMX.TI.JPEG.encoder.Config.APP1", OMX_IndexCustomAPP1},
-    {"OMX.TI.JPEG.encoder.Config.APP5", OMX_IndexCustomAPP5},
-    {"OMX.TI.JPEG.encoder.Config.APP13", OMX_IndexCustomAPP13},
-    {"OMX.TI.JPEG.encoder.Config.QFactor", OMX_IndexCustomQFactor},
-    {"OMX.TI.JPEG.encoder.Config.DRI", OMX_IndexCustomDRI},
-    {"OMX.TI.JPEG.encoder.Config.Debug", OMX_IndexCustomDebug},
-    {"",0x0}
+        {"OMX.TI.JPEG.encoder.Config.HuffmanTable", OMX_IndexCustomHuffmanTable},
+        {"OMX.TI.JPEG.encoder.Config.CommentFlag", OMX_IndexCustomCommentFlag},
+        {"OMX.TI.JPEG.encoder.Config.CommentString", OMX_IndexCustomCommentString},
+        {"OMX.TI.JPEG.encoder.Config.InputFrameWidth", OMX_IndexCustomInputFrameWidth},
+        {"OMX.TI.JPEG.encoder.Config.InputFrameHeight", OMX_IndexCustomInputFrameHeight},
+        {"OMX.TI.JPEG.encoder.Config.APP0", OMX_IndexCustomAPP0},
+        {"OMX.TI.JPEG.encoder.Config.APP1", OMX_IndexCustomAPP1},
+        {"OMX.TI.JPEG.encoder.Config.APP5", OMX_IndexCustomAPP5},
+        {"OMX.TI.JPEG.encoder.Config.APP13", OMX_IndexCustomAPP13},
+        {"OMX.TI.JPEG.encoder.Config.QFactor", OMX_IndexCustomQFactor},
+        {"OMX.TI.JPEG.encoder.Config.DRI", OMX_IndexCustomDRI},
+        {"OMX.TI.JPEG.encoder.Config.Debug", OMX_IndexCustomDebug}
     };
 
-    /* Check parameter validity */    
+    /* Check parameter validity */
     OMX_CHECK_PARAM(hComponent);
     OMX_CHECK_PARAM(pIndexType);
-    *pIndexType = OMX_IndexMax;
 
-    for (nIndex = 0; strlen((const char*)sJpegEncCustomParams[nIndex].cCustomParamName); nIndex++){
+    OMX_U32 nIndex;
+    const OMX_U32 nExtensions = sizeof(sJpegEncCustomParams)/sizeof(JPEGENC_CUSTOM_PARAM_DEFINITION);
+    for (nIndex = 0; nIndex < nExtensions; ++nIndex) {
         if (!strcmp((const char*)cParameterName, (const char*)(&(sJpegEncCustomParams[nIndex].cCustomParamName)))){
             *pIndexType = sJpegEncCustomParams[nIndex].nCustomParamIndex;
             eError = OMX_ErrorNone;
@@ -2369,7 +2368,7 @@
         }
     }
 
-    if(*pIndexType == OMX_IndexMax){
+    if (nIndex >= nExtensions){
          eError = OMX_ErrorUnsupportedIndex;
     }
 
@@ -2378,4 +2377,3 @@
 }
 
 
-
diff --git a/omx/system/src/openmax_il/lcml/inc/usn.h b/omx/system/src/openmax_il/lcml/inc/usn.h
index 126dc08..76de9fb 100644
--- a/omx/system/src/openmax_il/lcml/inc/usn.h
+++ b/omx/system/src/openmax_il/lcml/inc/usn.h
@@ -85,7 +85,8 @@
     IUALG_ERR_NOT_SUPPORTED   = 0x0F02,
     IUALG_ERR_ARGUMENT        = 0x0F03,
     IUALG_ERR_NOT_READY       = 0x0F04,
-    IUALG_ERR_GENERAL         = 0x0FFF
+    IUALG_ERR_GENERAL         = 0x0FFF,
+    IUALG_ERR_INSUFF_BUFFER   = 0x8401
 }IUALG_Event;
 
 typedef enum {
diff --git a/omx/system/src/openmax_il/lcml/src/LCML_DspCodec.c b/omx/system/src/openmax_il/lcml/src/LCML_DspCodec.c
index 104a4dc..2ab0b1a 100644
--- a/omx/system/src/openmax_il/lcml/src/LCML_DspCodec.c
+++ b/omx/system/src/openmax_il/lcml/src/LCML_DspCodec.c
@@ -1217,6 +1217,8 @@
         {
             struct DSP_MSG msg;
             
+            pthread_mutex_lock(&phandle->mutex);
+
             if ((int)args[0] == USN_STRMCMD_FLUSH) {
                 msg.dwCmd = USN_GPPMSG_STRMCTRL | (int)args[1]; 
                 msg.dwArg1  = USN_STRMCMD_FLUSH;
@@ -1226,7 +1228,6 @@
             else 
             {
                 int i;
-                pthread_mutex_lock(&phandle->mutex);
                 for (i = 0; i < QUEUE_SIZE; i++)
                 {
                     /* searching for empty slot */
@@ -1585,7 +1586,7 @@
 
         if (threadState == EMessagingThreadCodecRunning) {
             waitForEventsTimeout = 10000;
-            getMessageTimeout = 10;
+            getMessageTimeout = 1000;
         }
         /* set the timeouts lower when the codec is stopped so that thread deletion response will be faster */        
         else if (threadState == EMessagingThreadCodecStopped) {        
diff --git a/omx/system/src/openmax_il/omx_core/src/Android.mk b/omx/system/src/openmax_il/omx_core/src/Android.mk
index 9c162b4..f0c6acf 100644
--- a/omx/system/src/openmax_il/omx_core/src/Android.mk
+++ b/omx/system/src/openmax_il/omx_core/src/Android.mk
@@ -13,11 +13,17 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libdl \
-	libVendor_ti_omx_config_parser \
 	liblog
 	
 LOCAL_CFLAGS := $(TI_OMX_CFLAGS)
 
+ifneq ($(BUILD_WITHOUT_PV),true)
+LOCAL_SHARED_LIBRARIES += \
+	libVendor_ti_omx_config_parser
+else
+LOCAL_CFLAGS += -DNO_OPENCORE
+endif
+
 LOCAL_MODULE:= libOMX_Core
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/omx/system/src/openmax_il/omx_core/src/OMX_Core.c b/omx/system/src/openmax_il/omx_core/src/OMX_Core.c
index f6176e9..c2ed3ea 100755
--- a/omx/system/src/openmax_il/omx_core/src/OMX_Core.c
+++ b/omx/system/src/openmax_il/omx_core/src/OMX_Core.c
@@ -20,8 +20,10 @@
 #include "OMX_Core.h"
 #include "OMX_ComponentRegistry.h"
 
+#ifndef NO_OPENCORE
 /** determine capabilities of a component before acually using it */
 #include "ti_omx_config_parser.h"
+#endif
 
 /** size for the array of allocated components.  Sets the maximum 
  * number of components that can be allocated at once */
@@ -56,7 +58,7 @@
     {"OMX.TI.Video.Decoder", "video_decoder.avc"},
     //{"OMX.TI.Video.Decoder", "video_decoder.mpeg2"},
     {"OMX.TI.Video.Decoder", "video_decoder.mpeg4"},
-    //{"OMX.TI.Video.Decoder", "video_decoder.wmv"},
+    {"OMX.TI.Video.Decoder", "video_decoder.wmv"},
     {"OMX.TI.Video.encoder", "video_encoder.mpeg4"},
     {"OMX.TI.Video.encoder", "video_encoder.h263"},
     {"OMX.TI.Video.encoder", "video_encoder.avc"},
@@ -83,12 +85,20 @@
     //{"OMX.TI.WBAMR.decode", "audio_decoder.amrwb"},
 
     /* Audio components */
-    //{"OMX.TI.MP3.decode", "audio_decoder.mp3"},
+#ifdef BUILD_WITH_TI_AUDIO
+    {"OMX.TI.MP3.decode", "audio_decoder.mp3"},
+#endif
     {"OMX.TI.AAC.encode", "audio_encoder.aac"},
-    //{"OMX.TI.AAC.decode", "audio_decoder.aac"},
+#ifdef BUILD_WITH_TI_AUDIO
+    {"OMX.TI.AAC.decode", "audio_decoder.aac"},
+#endif
 /*  {"OMX.TI.PCM.encode", NULL},
     {"OMX.TI.PCM.decode", NULL},
+*/
+#ifdef BUILD_WITH_TI_AUDIO
     {"OMX.TI.WMA.decode", "audio_decoder.wma"},
+#endif
+/*
     {"OMX.TI.RAG.decode", "audio_decoder.ra"},
     {"OMX.TI.IMAADPCM.decode", NULL},
     {"OMX.TI.IMAADPCM.encode", NULL},
@@ -167,7 +177,6 @@
     OMX_ERRORTYPE (*pComponentInit)(OMX_HANDLETYPE*);
     OMX_ERRORTYPE err = OMX_ErrorNone;
     OMX_COMPONENTTYPE *componentType;
-    const char* pErr = dlerror();
 
     if(pthread_mutex_lock(&mutex) != 0)
     {
@@ -246,7 +255,7 @@
                 /* Get a function pointer to the "OMX_ComponentInit" function.  If
                  * there is an error, we can't go on, so set the error code and exit */
                 pComponentInit = dlsym(pModules[i], "OMX_ComponentInit");
-                if( (pErr != NULL) || (pComponentInit == NULL) ) {
+                if( pComponentInit == NULL ) {
                     LOGE("%d:: dlsym failed for module %p\n", __LINE__, pModules[i]);
                     err = OMX_ErrorInvalidComponent;
                     goto CLEAN_UP;
@@ -757,6 +766,8 @@
 
 {
     OMX_BOOL Status = OMX_FALSE;
+#ifndef NO_OPENCORE
     Status = TIOMXConfigParser(aInputParameters, aOutputParameters);
+#endif
     return Status;
 }
diff --git a/omx/ti_omx_config_parser/Android.mk b/omx/ti_omx_config_parser/Android.mk
index 5c8ace8..c6a0021 100644
--- a/omx/ti_omx_config_parser/Android.mk
+++ b/omx/ti_omx_config_parser/Android.mk
@@ -1,3 +1,5 @@
+ifneq ($(BUILD_WITHOUT_PV),true)
+
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 $(call add-prebuilt-files, ETC)
@@ -54,3 +56,5 @@
 LOCAL_SHARED_LIBRARIES += libopencore_common
 
 include $(BUILD_SHARED_LIBRARY)
+
+endif
diff --git a/omx/ti_omx_config_parser/src/ti_m4v_config_parser.cpp b/omx/ti_omx_config_parser/src/ti_m4v_config_parser.cpp
index 5d6225c..a06f59c 100644
--- a/omx/ti_omx_config_parser/src/ti_m4v_config_parser.cpp
+++ b/omx/ti_omx_config_parser/src/ti_m4v_config_parser.cpp
@@ -99,6 +99,23 @@
     return status;
 }
 
+int16 SearchVOLHeader(mp4StreamType *psBits)
+{
+    uint32 codeword = 0;
+    int16 status = 0;
+    do
+    {
+        /* Search for VOL_HEADER */
+        status = SearchNextM4VFrame(psBits); /* search 0x00 0x00 0x01 */
+        if (status != 0)
+            return MP4_INVALID_VOL_PARAM;
+
+        status = ReadBits(psBits, VOL_START_CODE_LENGTH, &codeword);
+    }
+    while ((codeword != VOL_START_CODE) && (status == 0));
+    return status;
+}
+
 OSCL_EXPORT_REF int16 iGetM4VConfigInfo(uint8 *buffer, int32 length, int32 *width, int32 *height, int32 *display_width, int32 *display_height)
 {
     int16 status;
@@ -153,7 +170,12 @@
 
 
         ReadBits(psBits, 32, &codeword);
-        if (codeword != VISUAL_OBJECT_START_CODE) return MP4_INVALID_VOL_PARAM;
+        if (codeword != VISUAL_OBJECT_START_CODE)
+        {
+            if (SearchVOLHeader(psBits) != 0)
+                return MP4_INVALID_VOL_PARAM;
+            goto decode_vol;
+        }
 
         /*  is_visual_object_identifier            */
         ReadBits(psBits, 1, &codeword);
@@ -192,17 +214,8 @@
         }
         else
         {
-            int16 status = 0;
-            do
-            {
-                /* Search for VOL_HEADER */
-                status = SearchNextM4VFrame(psBits); /* search 0x00 0x00 0x01 */
-                if (status != 0)
-                    return MP4_INVALID_VOL_PARAM;
-
-                status = ReadBits(psBits, VOL_START_CODE_LENGTH, &codeword);
-            }
-            while ((codeword != VOL_START_CODE) && (status == 0));
+            if (SearchVOLHeader(psBits) != 0)
+                return MP4_INVALID_VOL_PARAM;
             goto decode_vol;
         }
         /* next_start_code() */
@@ -236,17 +249,8 @@
             }
             else
             {
-                int16 status = 0;
-                do
-                {
-                    /* Search for VOL_HEADER */
-                    status = SearchNextM4VFrame(psBits); /* search 0x00 0x00 0x01 */
-                    if (status != 0)
-                        return MP4_INVALID_VOL_PARAM;
-
-                    status = ReadBits(psBits, VOL_START_CODE_LENGTH, &codeword);
-                }
-                while ((codeword != VOL_START_CODE) && (status == 0));
+                if (SearchVOLHeader(psBits) != 0)
+                    return MP4_INVALID_VOL_PARAM;
                 goto decode_vol;
             }
         }
@@ -418,19 +422,8 @@
         }
         else
         {
-            int16 status = 0;
-            do
-            {
-                /* Search for VOL_HEADER */
-                status = SearchNextM4VFrame(psBits); /* search 0x00 0x00 0x01 */
-                if (status != 0)
-                {
-                    return MP4_INVALID_VOL_PARAM;
-                }
-
-                status = ReadBits(psBits, VOL_START_CODE_LENGTH, &codeword);
-            }
-            while ((codeword != VOL_START_CODE) && (status == 0));
+            if (SearchVOLHeader(psBits) != 0)
+                return MP4_INVALID_VOL_PARAM;
             goto decode_vol;
         }
     }
diff --git a/omx/video/src/openmax_il/video_decode/inc/OMX_VideoDec_Utils.h b/omx/video/src/openmax_il/video_decode/inc/OMX_VideoDec_Utils.h
index 0f17067..be41808 100644
--- a/omx/video/src/openmax_il/video_decode/inc/OMX_VideoDec_Utils.h
+++ b/omx/video/src/openmax_il/video_decode/inc/OMX_VideoDec_Utils.h
@@ -162,6 +162,13 @@
 #endif
 
 #define __STD_COMPONENT__
+
+/*
+ * MAX_PRIVATE_IN_BUFFERS and MAX_PRIVATE_OUT_BUFFERS must NOT be
+ * greater than MAX_PRIVATE_BUFFERS. MAX_PRIVATE_BUFFERS is set
+ * to 6 because 6 overlay buffers are currently being used for
+ * playback
+ */
 #define MAX_PRIVATE_IN_BUFFERS              6
 #define MAX_PRIVATE_OUT_BUFFERS             6
 #define MAX_PRIVATE_BUFFERS                 6
@@ -308,6 +315,7 @@
 
 #define VIDDEC_PADDING_FULL                           256
 #define VIDDEC_PADDING_HALF                           VIDDEC_PADDING_FULL / 2
+#define VIDDEC_ALIGNMENT                              4
 
 #define VIDDEC_CLEARFLAGS                             0
 #define H264VDEC_SN_MAX_NALUNITS                      1200
@@ -367,7 +375,7 @@
 #define VIDDEC_WMV_PROFILE_ID8                          8
 
 #define VIDDEC_MAX_QUEUE_SIZE                           256
-#define VIDDEC_WMV_BUFFER_OFFSET                        255 - 4
+#define VIDDEC_WMV_BUFFER_OFFSET                        (255 - 4)
 #define VIDDEC_WMV_ELEMSTREAM                           0
 #define VIDDEC_WMV_RCVSTREAM                            1
 
@@ -543,6 +551,7 @@
     VIDDEC_BUFFER_OWNER eBufferOwner;
     VIDDEC_TYPE_ALLOCATE bAllocByComponent;
     OMX_U32 nNumber;
+    OMX_U8* pOriginalBuffer;
 #ifdef VIDDEC_WMVPOINTERFIXED
      OMX_U8* pTempBuffer;
 #endif
@@ -920,7 +929,6 @@
 
     OMX_STATETYPE eIdleToLoad;
     OMX_STATETYPE eExecuteToIdle;
-    OMX_BOOL iEndofInputSent;
     OMX_BOOL bPipeCleaned;
     OMX_BOOL bFirstBuffer;
 
@@ -941,10 +949,10 @@
 #endif
     VIDDEC_RMPROXY_STATES eRMProxyState;
 
-    OMX_U8 nInputBCountDsp;
-    OMX_U8 nOutputBCountDsp;
-    OMX_U8 nInputBCountApp;
-    OMX_U8 nOutputBCountApp;
+    volatile int32_t nInputBCountDsp;
+    volatile int32_t nOutputBCountDsp;
+    volatile int32_t nInputBCountApp;
+    volatile int32_t nOutputBCountApp;
 
     VIDDEC_CBUFFER_BUFFERFLAGS aBufferFlags[CBUFFER_SIZE];
     VIDDEC_LCML_STATES eLCMLState;
@@ -1027,6 +1035,141 @@
     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]*/
 
 
+
+/*----------------------------------------------------------------------------*/
+/**
+  * OMX_ALIGN_BUFFER() Align the buffer to the desire number of bytes.
+  *
+  * This method will update the component function pointer to the handle
+  *
+  * @param _pBuffer_	    Pointer to align
+  * @param _nBytes_	    # of byte to alignment desire
+  *
+  **/
+/*----------------------------------------------------------------------------*/
+
+#define OMX_ALIGN_BUFFER(_pBuffer_, _nBytes_) \
+    _pBuffer_ = (OMX_U8*) ((((OMX_U32) _pBuffer_) + (_nBytes_ - 1)) & (~(_nBytes_ - 1)));
+
+/*----------------------------------------------------------------------------*/
+/**
+  * OMX_MALLOC_BUFFER_VIDDEC() Allocate buffer for video decoder component
+  *
+  * This method will allocate memory for the _pBuffer_. Taking care of cache
+  * coherency requirement and include configuration data if require.
+  *
+  * @param _pBuffer_	    Pointer to buffer to be use
+  * @param _nSize_	    # of byte to allocate
+  * @param _pOriginalBuffer_  Pointer to the original allocate address
+  *
+  **/
+/*----------------------------------------------------------------------------*/
+
+#define OMX_MALLOC_BUFFER_VIDDEC(_pBuffer_, _nSize_, _pOriginalBuffer_)	    \
+    _pBuffer_ =  OMX_MALLOC_STRUCT_SIZED(_pBuffer_, OMX_U8, _nSize_ + VIDDEC_PADDING_FULL + VIDDEC_WMV_BUFFER_OFFSET + VIDDEC_ALIGNMENT, pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);			\
+    _pOriginalBuffer_ = _pBuffer_;					    \
+    _pBuffer_ += VIDDEC_PADDING_HALF;					    \
+    OMX_ALIGN_BUFFER(_pBuffer_, VIDDEC_ALIGNMENT);
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  * OMX_FREE_VIDDEC() Free memory
+  *
+  * This method will free memory and set pointer to NULL
+  *
+  * @param _pBuffer_	    Pointer to free
+  *
+  **/
+/*----------------------------------------------------------------------------*/
+
+#define OMX_FREE_VIDDEC(_pBuffer_)					    \
+    if(_pBuffer_ != NULL){                                                  \
+	free(_pBuffer_);                                                    \
+	_pBuffer_ = NULL;                                                   \
+    }
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  * OMX_FREE_BUFFER_VIDDEC() Free video decoder buffer
+  *
+  * This method will free video decoder buffer
+  *
+  * @param _pBuffHead_	    Buffer header pointer
+  * @param _pCompPort_	    Component port will give us the reference to the
+  *			    desire buffer to free
+  *
+  **/
+/*----------------------------------------------------------------------------*/
+
+#define OMX_FREE_BUFFER_VIDDEC(_pBuffHead_, _pCompPort_)					    \
+    {												    \
+	int _nBufferCount_ = 0;									    \
+	OMX_U8* _pTemp_ = NULL;									    \
+												    \
+	for(_nBufferCount_ = 0; _nBufferCount_ < MAX_PRIVATE_BUFFERS; _nBufferCount_++){	    \
+            if(_pCompPort_->pBufferPrivate[_nBufferCount_]->pBufferHdr != NULL){		    \
+                _pTemp_ = (OMX_U8*)_pCompPort_->pBufferPrivate[_nBufferCount_]->pBufferHdr->pBuffer;	\
+                if(_pBuffHead_->pBuffer == _pTemp_){						    \
+                    break;									    \
+                }										    \
+	    }											    \
+        }											    \
+												    \
+        if(_nBufferCount_ == MAX_PRIVATE_BUFFERS){						    \
+            OMX_ERROR4(pComponentPrivate->dbg, "Error: Buffer NOT found to free: %p \n", _pBuffHead_->pBuffer);	    \
+            goto EXIT;										    \
+        }											    \
+												    \
+        _pBuffHead_->pBuffer = _pCompPort_->pBufferPrivate[_nBufferCount_]->pOriginalBuffer;		    \
+        OMX_PRBUFFER1(pComponentPrivate->dbg, "Free original allocated buffer: %p\n", _pBuffHead_->pBuffer);	\
+        OMX_FREE_VIDDEC(_pBuffHead_->pBuffer);							    \
+    }
+
+
+
+/*----------------------------------------------------------------------------*/
+/**
+  * OMX_WMV_INSERT_CODEC_DATA()
+  *
+  * This method will insert the codec data to the first frame to be sent to
+  * queue in LCML
+  *
+  * @param _pBuffHead_	    Buffer header pointer
+  * @param _pComponentPrivate_  Component private structure to provide needed
+  *				references
+  *
+  **/
+/*----------------------------------------------------------------------------*/
+
+#define OMX_WMV_INSERT_CODEC_DATA(_pBuffHead_, _pComponentPrivate_)			\
+    {											\
+	OMX_U8* _pTempBuffer_ = NULL;							\
+	/* Copy frame data in a temporary buffer*/					\
+        OMX_MALLOC_STRUCT_SIZED(_pTempBuffer_, OMX_U8, _pBuffHead_->nFilledLen, NULL);	\
+	memcpy (_pTempBuffer_, _pBuffHead_->pBuffer, _pBuffHead_->nFilledLen);		\
+											\
+        /*Copy configuration data at the begining of the buffer*/			\
+	memcpy (_pBuffHead_->pBuffer, _pComponentPrivate_->pCodecData, _pComponentPrivate_->nCodecDataSize);	\
+        _pBuffHead_->pBuffer += _pComponentPrivate_->nCodecDataSize;			\
+	/* Add frame start code */							\
+        (*(_pBuffHead_->pBuffer++)) = 0x00;						\
+	(*(_pBuffHead_->pBuffer++)) = 0x00;						\
+        (*(_pBuffHead_->pBuffer++)) = 0x01;						\
+	(*(_pBuffHead_->pBuffer++)) = 0x0d;						\
+											\
+        /* Insert again the frame buffer */						\
+	memcpy (_pBuffHead_->pBuffer, _pTempBuffer_, _pBuffHead_->nFilledLen);		\
+        /* pTempBuffer no longer need*/							\
+	OMX_FREE_VIDDEC(_pTempBuffer_);							\
+											\
+	_pBuffHead_->pBuffer -= (pComponentPrivate->nCodecDataSize + 4);		\
+        _pBuffHead_->nFilledLen += pComponentPrivate->nCodecDataSize + 4;		\
+    }
+
+
 #define OMX_CONF_INIT_STRUCT(_s_, _name_, dbg)       \
     memset((_s_), 0x0, sizeof(_name_));         \
     (_s_)->nSize = sizeof(_name_);              \
diff --git a/omx/video/src/openmax_il/video_decode/src/OMX_VideoDec_Thread.c b/omx/video/src/openmax_il/video_decode/src/OMX_VideoDec_Thread.c
index 7cfcf4b..92c7cd4 100644
--- a/omx/video/src/openmax_il/video_decode/src/OMX_VideoDec_Thread.c
+++ b/omx/video/src/openmax_il/video_decode/src/OMX_VideoDec_Thread.c
@@ -72,6 +72,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <cutils/atomic.h>
 
 #include "OMX_VideoDecoder.h"
 #include "OMX_VideoDec_Utils.h"
@@ -291,7 +292,7 @@
                                                                OMX_TI_ErrorSevere,
                                                                "Error from Component Thread while processing dsp Responses");
                     }
-                    pComponentPrivate->nOutputBCountDsp--;
+                    android_atomic_dec(&pComponentPrivate->nOutputBCountDsp);
                 }
                 if ((FD_ISSET(pComponentPrivate->filled_inpBuf_Q[VIDDEC_PIPE_READ], &rfds))){
                     OMX_PRSTATE2(pComponentPrivate->dbg, "eExecuteToIdle 0x%x\n",pComponentPrivate->eExecuteToIdle);
@@ -312,7 +313,7 @@
                                                                OMX_TI_ErrorSevere,
                                                                "Error from Component Thread while processing input buffer");
                     }
-                    pComponentPrivate->nInputBCountApp--;
+                    android_atomic_dec(&pComponentPrivate->nInputBCountApp);
                 }
                 }
                 if (FD_ISSET(pComponentPrivate->free_inpBuf_Q[VIDDEC_PIPE_READ], &rfds)) {
@@ -330,7 +331,7 @@
                                                                OMX_TI_ErrorSevere,
                                                                "Error from Component Thread while processing free input buffer");
                     }
-                    pComponentPrivate->nInputBCountDsp--;
+                    android_atomic_dec(&pComponentPrivate->nInputBCountDsp);
                 }
                 if (FD_ISSET(pComponentPrivate->free_outBuf_Q[VIDDEC_PIPE_READ], &rfds)) {
                      if(pComponentPrivate->bDynamicConfigurationInProgress){
@@ -348,7 +349,7 @@
                                                                OMX_TI_ErrorSevere,
                                                                "Error from Component Thread while processing free output buffer");
                     }
-                    pComponentPrivate->nOutputBCountApp--;
+                    android_atomic_dec(&pComponentPrivate->nOutputBCountApp);
                 }
             }
         }
@@ -450,7 +451,7 @@
                                                            OMX_TI_ErrorSevere,
                                                            "Error from Component Thread while processing dsp Responses");
                 }
-                pComponentPrivate->nOutputBCountDsp--;
+                android_atomic_dec(&pComponentPrivate->nOutputBCountDsp);
             }
             if ((FD_ISSET(pComponentPrivate->filled_inpBuf_Q[VIDDEC_PIPE_READ], &rfds))){
                 OMX_PRSTATE2(pComponentPrivate->dbg, "eExecuteToIdle 0x%x\n",pComponentPrivate->eExecuteToIdle);
@@ -465,7 +466,7 @@
                                                            OMX_TI_ErrorSevere,
                                                            "Error from Component Thread while processing input buffer");
                 }
-                pComponentPrivate->nInputBCountApp--;
+                android_atomic_dec(&pComponentPrivate->nInputBCountApp);
                 }
             }
             if (FD_ISSET(pComponentPrivate->free_inpBuf_Q[VIDDEC_PIPE_READ], &rfds)) {
@@ -479,7 +480,7 @@
                                                            OMX_TI_ErrorSevere,
                                                            "Error from Component Thread while processing free input buffer");
                 }
-                pComponentPrivate->nInputBCountDsp--;
+                android_atomic_dec(&pComponentPrivate->nInputBCountDsp);
             }
             if (FD_ISSET(pComponentPrivate->free_outBuf_Q[VIDDEC_PIPE_READ], &rfds)) {
                 OMX_PRSTATE2(pComponentPrivate->dbg, "eExecuteToIdle 0x%x\n",pComponentPrivate->eExecuteToIdle);
@@ -493,7 +494,7 @@
                                                            OMX_TI_ErrorSevere,
                                                            "Error from Component Thread while processing free output buffer");
                 }
-                pComponentPrivate->nOutputBCountApp--;
+                android_atomic_dec(&pComponentPrivate->nOutputBCountApp);
             }
         }
     }
diff --git a/omx/video/src/openmax_il/video_decode/src/OMX_VideoDec_Utils.c b/omx/video/src/openmax_il/video_decode/src/OMX_VideoDec_Utils.c
index 2efd5a8..ece2bf7 100644
--- a/omx/video/src/openmax_il/video_decode/src/OMX_VideoDec_Utils.c
+++ b/omx/video/src/openmax_il/video_decode/src/OMX_VideoDec_Utils.c
@@ -1144,7 +1144,6 @@
             pComponentPrivate->bIsStopping                      = 0;
             pComponentPrivate->bFirstBuffer                     = 1;
             pComponentPrivate->eIdleToLoad                      = OMX_StateInvalid;
-            pComponentPrivate->iEndofInputSent                  = 0;
             pComponentPrivate->nInputBCountDsp                  = 0;
             pComponentPrivate->nOutputBCountDsp                 = 0;
             pComponentPrivate->nInputBCountApp                  = 0;
@@ -1175,7 +1174,6 @@
             pComponentPrivate->bIsPaused                        = 0;
             pComponentPrivate->bIsStopping                      = 0;
             pComponentPrivate->bFirstBuffer                     = 1;
-            pComponentPrivate->iEndofInputSent                  = 0;
             pComponentPrivate->nInputBCountDsp                  = 0;
             pComponentPrivate->nOutputBCountDsp                 = 0;
             pComponentPrivate->nInputBCountApp                  = 0;
@@ -1823,6 +1821,7 @@
                 pComponentPrivate->sInSemaphore.bSignaled) {
                 VIDDEC_PTHREAD_SEMAPHORE_WAIT(pComponentPrivate->sInSemaphore);
             }
+
             OMX_PRBUFFER2(pComponentPrivate->dbg, "Populated VIDDEC_INPUT_PORT IN 0x%x\n",pComponentPrivate->pInPortDef->bPopulated);
             pComponentPrivate->bInPortSettingsChanged = OMX_FALSE;
             pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle,
@@ -1861,6 +1860,38 @@
     return eError;
 }
 
+OMX_ERRORTYPE VIDDEC_EmptyBufferDone(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE* pBufferHeader)
+{
+    //LOGI("VIDDEC_EmptyBufferDone: header %p buffer %p", pBufferHeader, pBufferHeader->pBuffer);
+    ((VIDDEC_BUFFER_PRIVATE* )pBufferHeader->pInputPortPrivate)->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
+
+    // No buffer flag EOS event needs to be sent for INPUT port
+
+    return pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
+                                                     pComponentPrivate->pHandle->pApplicationPrivate,
+                                                     pBufferHeader);
+}
+
+OMX_ERRORTYPE VIDDEC_FillBufferDone(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE* pBufferHeader)
+{
+    //LOGI("VIDDEC_FillBufferDone: header %p buffer %p", pBufferHeader, pBufferHeader->pBuffer);
+    ((VIDDEC_BUFFER_PRIVATE* )pBufferHeader->pOutputPortPrivate)->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
+
+    // OpenMAX-IL standard specifies that a component generates the OMX_EventBufferFlag event when an OUTPUT port
+    // emits a buffer with the OMX_BUFFERFLAG_EOS flag set in the nFlags field
+    if (pBufferHeader->nFlags & OMX_BUFFERFLAG_EOS) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventBufferFlag,
+                                               VIDDEC_OUTPUT_PORT,
+                                               pBufferHeader->nFlags,
+                                               NULL);
+    }
+
+    return pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
+                                                     pComponentPrivate->pHandle->pApplicationPrivate,
+                                                     pBufferHeader);
+}
 /* ========================================================================== */
 /**
   * Return Buffers()
@@ -1886,9 +1917,6 @@
     if (nParam1 == pComponentPrivate->pInPortFormat->nPortIndex || nParam1 == OMX_ALL) {
             for (i = 0; i < pComponentPrivate->pInPortDef->nBufferCountActual; i++) {
                     if((pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->eBufferOwner == VIDDEC_BUFFER_WITH_DSP) && bRetDSP){
-                        OMX_PRBUFFER1(pComponentPrivate->dbg, "inBuffer 0x%p eBufferOwner 0x%x\n",pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr,
-                            pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->eBufferOwner);
-                        pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
                         pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen = 0;
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -1898,9 +1926,7 @@
                                           PERF_ModuleHLMM);
 #endif
 
-                        eError = pComponentPrivate->cbInfo.EmptyBufferDone((OMX_HANDLETYPE *)pComponentPrivate->pHandle,
-                                    pComponentPrivate->pHandle->pApplicationPrivate,
-                                    (OMX_BUFFERHEADERTYPE*)pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr);
+                        eError = VIDDEC_EmptyBufferDone(pComponentPrivate, pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[i]->pBufferHdr);
                     }
             }
        }
@@ -1935,9 +1961,6 @@
                 OMX_PRINT1(pComponentPrivate->dbg, "non tunneling\n");
                 for (i = 0; i < pComponentPrivate->pOutPortDef->nBufferCountActual; i++) {
                         if((pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner == VIDDEC_BUFFER_WITH_DSP) && bRetDSP){
-                            OMX_PRBUFFER1(pComponentPrivate->dbg, "xBuffer 0x%p eBufferOwner 0x%x\n",pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr,
-                                pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner);
-                            pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
                             pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen = 0;
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -1946,12 +1969,9 @@
                                               pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr->nFilledLen,
                                               PERF_ModuleHLMM);
 #endif
-
                             pBuffHead = (OMX_BUFFERHEADERTYPE*)pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr;
                             VIDDEC_Propagate_Mark(pComponentPrivate, pBuffHead);
-                            eError = pComponentPrivate->cbInfo.FillBufferDone((OMX_HANDLETYPE *)pComponentPrivate->pHandle,
-                                       pComponentPrivate->pHandle->pApplicationPrivate,
-                                        (OMX_BUFFERHEADERTYPE*)pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[i]->pBufferHdr);
+                            eError = VIDDEC_FillBufferDone(pComponentPrivate, pBuffHead);
                        }
                 }
            }
@@ -2249,6 +2269,7 @@
         }
     }
 EXIT:
+
     OMX_PRINT1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError);
     return eError;
 
@@ -2304,7 +2325,6 @@
 #else
    void* pMyLCML;
    VIDDEC_fpo fpGetHandle;
-   char* error;
 #endif
 
     OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n");
@@ -2402,9 +2422,9 @@
                     goto EXIT;
                 }
                 fpGetHandle = dlsym(pMyLCML, "GetHandle");
-                if ((error = dlerror()) != NULL) {
+                if (!fpGetHandle) {
                     OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n");
-                    fputs(error, stderr);
+                    fputs(dlerror(), stderr);
                     dlclose(pMyLCML);
                     pMyLCML = NULL;
                     eError = OMX_ErrorBadParameter;
@@ -2685,7 +2705,6 @@
                               PERF_BoundaryComplete | PERF_BoundarySteadyState);
 #endif
                     pComponentPrivate->bIsPaused = 0;
-                    pComponentPrivate->iEndofInputSent = 0;
 /********************************************************************************************************************/
            if (pComponentPrivate->bIsStopping == OMX_TRUE) {
                 pComponentPrivate->bIsPaused = OMX_FALSE;
@@ -3082,7 +3101,6 @@
 
                 eError = OMX_ErrorNone;
                 pComponentPrivate->bIsPaused = 0;
-                pComponentPrivate->iEndofInputSent = 0;
                 pComponentPrivate->eState = OMX_StateExecuting;
                /* Decrement reference count with signal enabled */
                if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
@@ -4994,9 +5012,7 @@
                 /* We have received some part of the config Buffer.
                  * Send EmptyThisBuffer of the buffer we have just received to Client
                  */
-                pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                    pComponentPrivate->pHandle->pApplicationPrivate,
-                    pBuffHead);
+                VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                 /* Exit with out error to avoid sending again EmptyBufferDone in upper function*/
                 eError = OMX_ErrorNone;
                 goto EXIT;
@@ -5214,7 +5230,6 @@
     void* pUalgInpParams = NULL;
     LCML_DSP_INTERFACE* pLcmlHandle;
     OMX_PRBUFFER1(pComponentPrivate->dbg, "+++ENTERING\n");
-    OMX_PRBUFFER1(pComponentPrivate->dbg, "pComponentPrivate 0x%p iEndofInputSent 0x%x\n", pComponentPrivate, pComponentPrivate->iEndofInputSent);
     inpBufSize = pComponentPrivate->pInPortDef->nBufferSize;
     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
     ret = read(pComponentPrivate->filled_inpBuf_Q[0], &(pBuffHead), sizeof(pBuffHead));
@@ -5307,18 +5322,13 @@
                                                 size_dsp,
                                                 (OMX_U8*)&pComponentPrivate->pBufferTemp);
                     OMX_PRBUFFER1(pComponentPrivate->dbg, "Returning First Input Buffer to test application\n");
-                    pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                    pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                    OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
             #ifdef __PERF_INSTRUMENTATION__
                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                       pBuffHead->pBuffer,
                                       pBuffHead->nFilledLen,
                                       PERF_ModuleHLMM);
             #endif
-                    pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
-                                                               pComponentPrivate->pHandle->pApplicationPrivate,
-                                                               pBuffHead);
+                    VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                     pComponentPrivate->bFirstHeader = OMX_TRUE;
                     goto EXIT;
             }
@@ -5345,13 +5355,16 @@
                         memcpy (pComponentPrivate->pCodecData, pBuffHead->pBuffer + pBuffHead->nOffset, pBuffHead->nFilledLen);
 #endif
                         pComponentPrivate->nCodecDataSize = pBuffHead->nFilledLen;
+                        if(pComponentPrivate->nCodecDataSize > VIDDEC_WMV_BUFFER_OFFSET){
+                            OMX_ERROR4(pComponentPrivate->dbg, "Insufficient space in buffer pbuffer %p - nCodecDataSize %u\n",
+                                (void *)pBuffHead->pBuffer,pComponentPrivate->nCodecDataSize);
+                            eError = OMX_ErrorStreamCorrupt;
+                            goto EXIT;
+                        }
 #ifdef VIDDEC_ACTIVATEPARSER
                         eError = VIDDEC_ParseHeader( pComponentPrivate, pBuffHead);
 #endif
                         OMX_PRBUFFER1(pComponentPrivate->dbg, "Returning First Input Buffer to test application %x\n",eError);
-                        pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                        pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                        OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
                 #ifdef __PERF_INSTRUMENTATION__
                         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                           pBuffHead->pBuffer,
@@ -5365,46 +5378,13 @@
 #else
                         pBuffHead->nOffset = VIDDEC_WMV_BUFFER_OFFSET;
 #endif
-                        pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
-                                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                                   pBuffHead);
+                        VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                         return OMX_ErrorNone;
                    }
                    else {
-                        OMX_S32 nDifference = 0;
-                        OMX_U8* pTempBuffer = NULL;
+			/* VC-1: First data buffer received, add configuration data to it*/
                         pComponentPrivate->bFirstHeader = OMX_TRUE;
-#ifdef VIDDEC_WMVPOINTERFIXED
-                        pTempBuffer = pBuffHead->pBuffer;
-#else
-                        pTempBuffer = pBuffHead->pBuffer + pBuffHead->nOffset;
-#endif
-                        (*(--pTempBuffer)) = 0x0d;
-                        (*(--pTempBuffer)) = 0x01;
-                        (*(--pTempBuffer)) = 0x00;
-                        (*(--pTempBuffer)) = 0x00;
-                        pTempBuffer -= pComponentPrivate->nCodecDataSize;
-#ifdef VIDDEC_WMVPOINTERFIXED                        
-                        nDifference = pBuffHead->pBuffer - pTempBuffer;
-#else
-                        nDifference = pTempBuffer - pBuffHead->pBuffer;
-#endif
-                        if (nDifference < 0) {
-                            OMX_ERROR4(pComponentPrivate->dbg, "Insufficient space in buffer pbuffer %p - nOffset %p\n",
-                                (void *)pBuffHead->pBuffer,(void *)pBuffHead->nOffset);
-                            eError = OMX_ErrorStreamCorrupt;
-                            goto EXIT;
-                        }
-                        memcpy (pTempBuffer, pComponentPrivate->pCodecData, pComponentPrivate->nCodecDataSize);
-                        pBuffHead->nFilledLen += pComponentPrivate->nCodecDataSize + 4;
-#ifdef VIDDEC_WMVPOINTERFIXED
-                        pBuffHead->pBuffer = pTempBuffer;
-                        pBuffHead->nOffset = 0;
-#else
-                        pBuffHead->nOffset = pTempBuffer - pBuffHead->pBuffer;
-#endif
-                        OMX_PRBUFFER1(pComponentPrivate->dbg, "pTempBuffer %p - pBuffHead->pBuffer %p - pBuffHead->nOffset %lx\n",
-                            pTempBuffer,pBuffHead->pBuffer,pBuffHead->nOffset);
+                        OMX_WMV_INSERT_CODEC_DATA(pBuffHead, pComponentPrivate);
                         eError = OMX_ErrorNone;
                     }
                 }
@@ -5417,9 +5397,6 @@
                         if(eError != OMX_ErrorNone) {
                                 OMX_PRBUFFER1(pComponentPrivate->dbg, "Returning First Input Buffer to test application\n");
                                 pComponentPrivate->bFirstHeader = OMX_TRUE;
-                                pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                                pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                                OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
                         #ifdef __PERF_INSTRUMENTATION__
                                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                                   pBuffHead->pBuffer,
@@ -5433,9 +5410,7 @@
 #else
                                 pBuffHead->nOffset = VIDDEC_WMV_BUFFER_OFFSET;
 #endif
-                                pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                                                                          pComponentPrivate->pHandle->pApplicationPrivate,
-                                                                          pBuffHead);
+                            VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                             eError = OMX_ErrorNone;
                             goto EXIT;
                         }
@@ -5497,9 +5472,6 @@
                     if(eError != OMX_ErrorNone) {
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "Returning First Input Buffer to test application\n");
                             pComponentPrivate->bFirstHeader = OMX_TRUE;
-                            pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                            pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                            OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
                     #ifdef __PERF_INSTRUMENTATION__
                             PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                               pBuffHead->pBuffer,
@@ -5513,9 +5485,7 @@
 #else
                             pBuffHead->nOffset = VIDDEC_WMV_BUFFER_OFFSET;
 #endif
-                            pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                                                                      pComponentPrivate->pHandle->pApplicationPrivate,
-                                                                      pBuffHead);
+                        VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                         eError = OMX_ErrorNone;
                         goto EXIT;
                     }
@@ -5567,9 +5537,6 @@
                 }
 #endif
 
-                pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
         #ifdef __PERF_INSTRUMENTATION__
                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                   pBuffHead->pBuffer,
@@ -5577,9 +5544,7 @@
                                   PERF_ModuleHLMM);
         #endif
 
-                pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                                                          pComponentPrivate->pHandle->pApplicationPrivate,
-                                                          pBuffHead);
+                VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
             }
             eError = OMX_ErrorNone;
             goto EXIT;
@@ -5770,14 +5735,8 @@
 #endif
 
                 if(pComponentPrivate->bDynamicConfigurationInProgress){
-                    pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                    pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                    OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
-
                     OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending buffer back to client pBuffer=%p\n", pBuffHead->pBuffer);
-                    pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                                                              pComponentPrivate->pHandle->pApplicationPrivate,
-                                                              pBuffHead);
+                    VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                     goto EXIT;
                 }
 
@@ -5819,185 +5778,176 @@
             }
         }
 
-        if(pComponentPrivate->iEndofInputSent == 0){
-            pComponentPrivate->iEndofInputSent = 1;
-            OMX_PRBUFFER1(pComponentPrivate->dbg, "Sending EOS Empty eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
-            if(pComponentPrivate->eFirstBuffer.bSaveFirstBuffer == OMX_FALSE){
-                OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pUalgParams,OMX_PTR);
-            }
+        OMX_PRBUFFER1(pComponentPrivate->dbg, "Sending EOS Empty eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
+        if(pComponentPrivate->eFirstBuffer.bSaveFirstBuffer == OMX_FALSE){
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pUalgParams,OMX_PTR);
+        }
 
-            if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
-                if(pComponentPrivate->pUalgParams == NULL){
-                    OMX_U8* pTemp = NULL;
-                    OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
-                            H264VDEC_UALGInputParam,
-                            sizeof(H264VDEC_UALGInputParam) + VIDDEC_PADDING_FULL,
-                            pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
-                    pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
-                    pTemp += VIDDEC_PADDING_HALF;
-                    pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
-                }
-                size_dsp = sizeof(H264VDEC_UALGInputParam);
-                ((H264VDEC_UALGInputParam *)pComponentPrivate->pUalgParams)->lBuffCount = -1;
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
+        if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
+            if(pComponentPrivate->pUalgParams == NULL){
+                OMX_U8* pTemp = NULL;
+                OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
+                        H264VDEC_UALGInputParam,
+                        sizeof(H264VDEC_UALGInputParam) + VIDDEC_PADDING_FULL,
+                        pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
+                pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
+                pTemp += VIDDEC_PADDING_HALF;
+                pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
+            }
+            size_dsp = sizeof(H264VDEC_UALGInputParam);
+            ((H264VDEC_UALGInputParam *)pComponentPrivate->pUalgParams)->lBuffCount = -1;
+            OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
                     ((H264VDEC_UALGInputParam *)pComponentPrivate->pUalgParams)->lBuffCount);
+        }
+        else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) {
+            if(pComponentPrivate->pUalgParams == NULL){
+                OMX_U8* pTemp = NULL;
+                OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
+                        WMV9DEC_UALGInputParam,
+                        sizeof(WMV9DEC_UALGInputParam) + VIDDEC_PADDING_FULL,
+                        pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
+                pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
+                pTemp += VIDDEC_PADDING_HALF;
+                pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
             }
-            else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) {
-                if(pComponentPrivate->pUalgParams == NULL){
-                    OMX_U8* pTemp = NULL;
-                    OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
-                            WMV9DEC_UALGInputParam,
-                            sizeof(WMV9DEC_UALGInputParam) + VIDDEC_PADDING_FULL,
-                            pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
-                    pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
-                    pTemp += VIDDEC_PADDING_HALF;
-                    pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
-                }
-                size_dsp = sizeof(WMV9DEC_UALGInputParam);
-                ((WMV9DEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = -1;
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
+            size_dsp = sizeof(WMV9DEC_UALGInputParam);
+            ((WMV9DEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = -1;
+            OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
                     ((WMV9DEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount);
+        }
+        else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
+                pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
+            if(pComponentPrivate->pUalgParams == NULL){
+                OMX_U8* pTemp = NULL;
+                OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
+                        MP4VD_GPP_SN_UALGInputParams,
+                        sizeof(MP4VD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL,
+                        pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
+                pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
+                pTemp += VIDDEC_PADDING_HALF;
+                pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
             }
-            else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
-                     pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
-                if(pComponentPrivate->pUalgParams == NULL){
-                    OMX_U8* pTemp = NULL;
-                    OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
-                            MP4VD_GPP_SN_UALGInputParams,
-                            sizeof(MP4VD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL,
-                            pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
-                    pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
-                    pTemp += VIDDEC_PADDING_HALF;
-                    pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
-                }
-                size_dsp = sizeof(MP4VD_GPP_SN_UALGInputParams);
-                ((MP4VD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nBuffCount = -1;
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
+            size_dsp = sizeof(MP4VD_GPP_SN_UALGInputParams);
+            ((MP4VD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nBuffCount = -1;
+            OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
                     ((MP4VD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nBuffCount);
+        }
+        else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
+            if(pComponentPrivate->pUalgParams == NULL){
+                OMX_U8* pTemp = NULL;
+                OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
+                        MP2VDEC_UALGInputParam,
+                        sizeof(MP2VDEC_UALGInputParam) + VIDDEC_PADDING_FULL,
+                        pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
+                pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
+                pTemp += VIDDEC_PADDING_HALF;
+                pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
             }
-            else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
-                if(pComponentPrivate->pUalgParams == NULL){
-                    OMX_U8* pTemp = NULL;
-                    OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
-                            MP2VDEC_UALGInputParam,
-                            sizeof(MP2VDEC_UALGInputParam) + VIDDEC_PADDING_FULL,
-                            pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
-                    pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
-                    pTemp += VIDDEC_PADDING_HALF;
-                    pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
-                }
-                size_dsp = sizeof(MP2VDEC_UALGInputParam);
-                ((MP2VDEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = -1;
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
+            size_dsp = sizeof(MP2VDEC_UALGInputParam);
+            ((MP2VDEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = -1;
+            OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
                     ((MP2VDEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount);
-            }
+        }
 #ifdef VIDDEC_SPARK_CODE
-            else if (VIDDEC_SPARKCHECK) {
-                if(pComponentPrivate->pUalgParams == NULL){
-                    OMX_U8* pTemp = NULL;
-                    OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
-                            SPARKVD_GPP_SN_UALGInputParams,
-                            sizeof(SPARKVD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL,
-                            pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
-                    pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
-                    pTemp += VIDDEC_PADDING_HALF;
-                    pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
-                }
-                size_dsp = sizeof(SPARKVD_GPP_SN_UALGInputParams);
-                ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->lBuffCount = -1;
-                ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nIsSparkInput = 1;
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
+        else if (VIDDEC_SPARKCHECK) {
+            if(pComponentPrivate->pUalgParams == NULL){
+                OMX_U8* pTemp = NULL;
+                OMX_MALLOC_STRUCT_SIZED(pComponentPrivate->pUalgParams,
+                        SPARKVD_GPP_SN_UALGInputParams,
+                        sizeof(SPARKVD_GPP_SN_UALGInputParams) + VIDDEC_PADDING_FULL,
+                        pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
+                pTemp = (OMX_U8*)(pComponentPrivate->pUalgParams);
+                pTemp += VIDDEC_PADDING_HALF;
+                pComponentPrivate->pUalgParams = (OMX_PTR*)pTemp;
+            }
+            size_dsp = sizeof(SPARKVD_GPP_SN_UALGInputParams);
+            ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->lBuffCount = -1;
+            ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nIsSparkInput = 1;
+            OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
                     ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->lBuffCount);
-            }
+        }
 #endif
-            else {
-                eError = OMX_ErrorUnsupportedSetting;
-                goto EXIT;
-            }
+        else {
+            eError = OMX_ErrorUnsupportedSetting;
+            goto EXIT;
+        }
+
+#ifdef __PERF_INSTRUMENTATION__
+        PERF_SendingFrame(pComponentPrivate->pPERFcomp,
+                NULL, 0,
+                PERF_ModuleCommonLayer);
+#endif
+        if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload &&
+                pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy &&
+                pComponentPrivate->pLCML != NULL){
+            pComponentPrivate->pTempBuffHead.nFlags = 0;
+            pComponentPrivate->pTempBuffHead.nFlags |= OMX_BUFFERFLAG_EOS;
+            pComponentPrivate->pTempBuffHead.nFilledLen = 0;
+            pComponentPrivate->pTempBuffHead.pBuffer = NULL;
 
 #ifdef __PERF_INSTRUMENTATION__
             PERF_SendingFrame(pComponentPrivate->pPERFcomp,
-                              NULL, 0,
-                              PERF_ModuleCommonLayer);
-#endif
-            if(pComponentPrivate->eLCMLState != VidDec_LCML_State_Unload &&
-                pComponentPrivate->eLCMLState != VidDec_LCML_State_Destroy &&
-                pComponentPrivate->pLCML != NULL){
-                pComponentPrivate->pTempBuffHead.nFlags = 0;
-                pComponentPrivate->pTempBuffHead.nFlags |= OMX_BUFFERFLAG_EOS;
-                pComponentPrivate->pTempBuffHead.nFilledLen = 0;
-                pComponentPrivate->pTempBuffHead.pBuffer = NULL;
-                
-#ifdef __PERF_INSTRUMENTATION__
-                PERF_SendingFrame(pComponentPrivate->pPERFcomp,
-                                  pBuffHead->pBuffer,
-                                  pBuffHead->nFilledLen,
-                                  PERF_ModuleHLMM);
+                    pBuffHead->pBuffer,
+                    pBuffHead->nFilledLen,
+                    PERF_ModuleHLMM);
 #endif
 
-                if(pComponentPrivate->bDynamicConfigurationInProgress){
-                    pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                    pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                    OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending buffer back to client pBuffer=%p\n", pBuffHead->pBuffer);
-                    pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                                                              pComponentPrivate->pHandle->pApplicationPrivate,
-                                                              pBuffHead);
-                    goto EXIT;
-                }
+            if(pComponentPrivate->bDynamicConfigurationInProgress){
+                OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending buffer back to client pBuffer=%p\n", pBuffHead->pBuffer);
+                VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
+                goto EXIT;
+            }
 
-                OMX_PRDSP2(pComponentPrivate->dbg, "LCML_QueueBuffer(INPUT)\n");
+            OMX_PRDSP2(pComponentPrivate->dbg, "LCML_QueueBuffer(INPUT)\n");
 
-                /* Verify if first buffer as been stored. 
-                 * Handle case were only one frame is decoded */
-                if(pComponentPrivate->eFirstBuffer.bSaveFirstBuffer){
-                    eError = VIDDEC_CopyBuffer(pComponentPrivate, pBuffHead);
-                    if (eError != OMX_ErrorNone) {
-                        OMX_PRDSP4(pComponentPrivate->dbg, "VIDDEC_HandleDataBuf_FromApp: VIDDEC_CopyBuffer()= 0x%x\n", eError);
-                        if (eError == OMX_ErrorInsufficientResources) {
-                            goto EXIT;
-                        }
-                    }
-                    pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP;
-                    eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)
-                                                pLcmlHandle)->pCodecinterfacehandle,
-                                                ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) ? EMMCodecInputBufferMapBufLen : EMMCodecInputBuffer),
-                                                &pBuffHead->pBuffer[pBuffHead->nOffset],/*WMV_VC1_CHANGES*/
-                                                pBuffHead->nAllocLen,
-                                                pBuffHead->nFilledLen,
-                                                (OMX_U8 *)pComponentPrivate->pUalgParams,
-                                                size_dsp,
-                                                (OMX_U8 *)pBuffHead);
-                    if (eError != OMX_ErrorNone){
-                        OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer EOS (0x%x)\n",eError);
-                        eError = OMX_ErrorHardware;
+            /* Verify if first buffer as been stored. 
+             * Handle case were only one frame is decoded */
+            if(pComponentPrivate->eFirstBuffer.bSaveFirstBuffer){
+                eError = VIDDEC_CopyBuffer(pComponentPrivate, pBuffHead);
+                if (eError != OMX_ErrorNone) {
+                    OMX_PRDSP4(pComponentPrivate->dbg, "VIDDEC_HandleDataBuf_FromApp: VIDDEC_CopyBuffer()= 0x%x\n", eError);
+                    if (eError == OMX_ErrorInsufficientResources) {
                         goto EXIT;
                     }
                 }
-                else{
-                    eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
-                                                  ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) ? EMMCodecInputBufferMapBufLen : EMMCodecInputBuffer),
-                                                  NULL,
-                                                  0,
-                                                  0,
-                                                  (OMX_U8 *)pComponentPrivate->pUalgParams,
-                                                  size_dsp,
-                                                  (OMX_PTR)&pComponentPrivate->pTempBuffHead);
-                }
+                pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP;
+                eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)
+                            pLcmlHandle)->pCodecinterfacehandle,
+                        ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) ? EMMCodecInputBufferMapBufLen : EMMCodecInputBuffer),
+                        &pBuffHead->pBuffer[pBuffHead->nOffset],/*WMV_VC1_CHANGES*/
+                        pBuffHead->nAllocLen,
+                        pBuffHead->nFilledLen,
+                        (OMX_U8 *)pComponentPrivate->pUalgParams,
+                        size_dsp,
+                        (OMX_U8 *)pBuffHead);
                 if (eError != OMX_ErrorNone){
-                    OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer 1 (0x%x)\n",eError);
+                    OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer EOS (0x%x)\n",eError);
                     eError = OMX_ErrorHardware;
                     goto EXIT;
                 }
             }
-            else {
+            else{
+                eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
+                        ((pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV) ? EMMCodecInputBufferMapBufLen : EMMCodecInputBuffer),
+                        NULL,
+                        0,
+                        0,
+                        (OMX_U8 *)pComponentPrivate->pUalgParams,
+                        size_dsp,
+                        (OMX_PTR)&pComponentPrivate->pTempBuffHead);
+            }
+            if (eError != OMX_ErrorNone){
+                OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer 1 (0x%x)\n",eError);
                 eError = OMX_ErrorHardware;
                 goto EXIT;
             }
         }
+        else {
+            eError = OMX_ErrorHardware;
+            goto EXIT;
+        }
     }
     else {
-        pComponentPrivate->iEndofInputSent = 0;
         if(pBuffHead->nFilledLen != 0) {
             if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
                 pUalgInpParams = pBufferPrivate->pUalgParam;
@@ -6072,11 +6022,7 @@
                             pComponentPrivate->aCCDsize[pComponentPrivate->nCCDcnt++] = pBuffHead->nFilledLen;
 
                             OMX_PRINT1(pComponentPrivate->dbg,"send ccd buffer back to client\n");
-                            pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                            pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                            pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                                                      pComponentPrivate->pHandle->pApplicationPrivate,
-                                                      pBuffHead);
+                            VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                             goto EXIT;
                         }
                         else {
@@ -6312,14 +6258,8 @@
 #endif
 
                 if(pComponentPrivate->bDynamicConfigurationInProgress){
-                    pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                    pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                    OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
-
                     OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending buffer back to client pBuffer=%p\n", pBuffHead->pBuffer);
-                    pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                                                              pComponentPrivate->pHandle->pApplicationPrivate,
-                                                              pBuffHead);
+                    VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                     goto EXIT;
                 }
 #ifdef ANDROID
@@ -6656,19 +6596,7 @@
     #endif
 
                 VIDDEC_Propagate_Mark(pComponentPrivate, pBuffHead);
-                pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "standalone buffer eBufferOwner 0x%x  --  %lx\n", pBufferPrivate->eBufferOwner,pBuffHead->nFlags);
-                if((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS)){
-                    pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                        pComponentPrivate->pHandle->pApplicationPrivate,
-                                                        OMX_EventBufferFlag,
-                                                        VIDDEC_OUTPUT_PORT,
-                                                        OMX_BUFFERFLAG_EOS,
-                                                        NULL);
-                }
-                pComponentPrivate->cbInfo.FillBufferDone(pComponentPrivate->pHandle,
-                                                         pComponentPrivate->pHandle->pApplicationPrivate,
-                                                         pBuffHead);
+                VIDDEC_FillBufferDone(pComponentPrivate, pBuffHead);
             }
         }
     }
@@ -6709,10 +6637,7 @@
     }
     OMX_PRSTATE1(pComponentPrivate->dbg, "pBuffHead 0x%p eExecuteToIdle 0x%x\n", pBuffHead,pComponentPrivate->eExecuteToIdle);
     if (pBuffHead != NULL) {
-        pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
         pBuffHead->nAllocLen = inputbufsize;
-        pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
-        OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
 #ifdef __PERF_INSTRUMENTATION__
         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                           pBuffHead->pBuffer,
@@ -6720,9 +6645,7 @@
                           PERF_ModuleHLMM);
 #endif
 
-        pComponentPrivate->cbInfo.EmptyBufferDone(pComponentPrivate->pHandle,
-                                                  pComponentPrivate->pHandle->pApplicationPrivate,
-                                                  pBuffHead);
+        VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
     }
     OMX_PRBUFFER1(pComponentPrivate->dbg, "---EXITING(0x%x) \n",eError);
 EXIT:
@@ -7849,27 +7772,27 @@
         VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex);
         pComponentPrivate->bTransPause = 1;
     }
-    if (event == EMMCodecAlgCtrlAck) {
+    else if (event == EMMCodecAlgCtrlAck) {
         VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex);
         VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex);
         VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex);
         pComponentPrivate->bTransPause = 1;
     }
-    if (event == EMMCodecProcessingStoped) {
+    else if (event == EMMCodecProcessingStoped) {
         VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex);
         VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex);
         VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex);
         pComponentPrivate->bTransPause = 1;
         pComponentPrivate->bIsPaused = 0;
     }
-    if (event == EMMCodecProcessingStarted) {
+    else if (event == EMMCodecProcessingStarted) {
         VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex);
         VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex);
         VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex);
         pComponentPrivate->bTransPause = 1;
         pComponentPrivate->bIsPaused = 0;
     }
-    if (event == EMMCodecBufferProcessed) {
+    else if (event == EMMCodecBufferProcessed) {
         OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecBufferProcessed 0x%lx\n", (OMX_U32)argsCb [0]);
         if ((OMX_U32)argsCb [0] == EMMCodecOuputBuffer) {
             OMX_PRBUFFER1(pComponentPrivate->dbg, "EMMCodecOuputBuffer\n");
@@ -7930,7 +7853,7 @@
                             /*}*/
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFilledLen %lu\n", pBuffHead->nFilledLen);
                             pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate;
-                            pComponentPrivate->nOutputBCountDsp++;
+                            android_atomic_inc(&pComponentPrivate->nOutputBCountDsp);
                             pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
 #ifdef __PERF_INSTRUMENTATION__
@@ -8023,7 +7946,7 @@
       }
     }
     /************************************************************************************************/
-    if (event == EMMCodecBufferNotProcessed) {
+    else if (event == EMMCodecBufferNotProcessed) {
         OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecBufferNotProcessed\n");
         if ((OMX_U32)argsCb [0] == EMMCodecOuputBuffer) {
             OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
@@ -8082,7 +8005,7 @@
                             /*}*/
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFilledLen %lu\n", pBuffHead->nFilledLen);
                             pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate;
-                            pComponentPrivate->nOutputBCountDsp++;
+                            android_atomic_inc(&pComponentPrivate->nOutputBCountDsp);
                             pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
 #ifdef __PERF_INSTRUMENTATION__
@@ -8174,7 +8097,7 @@
         }
     }
     /************************************************************************************************/
-    if (event == EMMCodecDspError) {
+    else if (event == EMMCodecDspError) {
         OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecDspError\n");
         if((argsCb[4] == (void *)NULL) && (argsCb[5] == (void*)NULL)) {
             OMX_PRDSP4(pComponentPrivate->dbg, "DSP MMU_Fault\n");
@@ -8200,6 +8123,7 @@
                     OMX_PRDSP2(pComponentPrivate->dbg, "Received PLAYCOMPLETED\n");
                 }
                 else {
+                    OMX_PRDSP4(pComponentPrivate->dbg, "Error from the DSP: argsCb[5]=%d.\n", (int)argsCb [5]);
                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                            pComponentPrivate->pHandle->pApplicationPrivate,
                                            OMX_EventError,
@@ -8209,6 +8133,7 @@
                 }
             }
             else {
+                OMX_PRDSP4(pComponentPrivate->dbg, "Error from the DSP: argsCb[4]=%d.\n", (int)argsCb [4]);
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                            pComponentPrivate->pHandle->pApplicationPrivate,
                                            OMX_EventError,
@@ -8219,12 +8144,13 @@
             }
         }
         else {
+            OMX_PRDSP4(pComponentPrivate->dbg, "LCML Halted: argsCb[0]=%d.\n", (int)argsCb [0]);
             pComponentPrivate->bLCMLHalted = OMX_TRUE;
             pComponentPrivate->pHandle->SendCommand( pComponentPrivate->pHandle, OMX_CommandStateSet, -2, 0);
 
         }
     }
-    if (event == EMMCodecInternalError || event == EMMCodecInitError) {
+    else if (event == EMMCodecInternalError || event == EMMCodecInitError) {
         OMX_PRDSP4(pComponentPrivate->dbg, "EMMCodecInternalError || EMMCodecInitError\n");
         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                pComponentPrivate->pHandle->pApplicationPrivate,
@@ -8233,13 +8159,17 @@
                                                OMX_TI_ErrorCritical,
                                                "Error from the DSP");
     }
-    if (event == EMMCodecStrmCtrlAck) {
+    else if (event == EMMCodecStrmCtrlAck) {
         if ((int)argsCb [0] == USN_ERR_NONE) {
             OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecStrmCtrlAck\n");
             VIDDEC_PTHREAD_MUTEX_LOCK(pComponentPrivate->sMutex);
             VIDDEC_PTHREAD_MUTEX_SIGNAL(pComponentPrivate->sMutex);
             VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex);
+        } else {
+            OMX_PRDSP4(pComponentPrivate->dbg, "EMMCodecStrmCtrlAck: argsCb[0]=%d\n", (int)argsCb [0]);
         }
+    } else {
+        OMX_PRDSP4(pComponentPrivate->dbg, "Unknown event: %d\n", event);
     }
 
 EXIT:
@@ -8388,7 +8318,6 @@
    LPFNDLLFUNC1 fpGetHandle1;
 #else
    VIDDEC_fpo fpGetHandle;
-   char* error;
 #endif
 
 #ifndef UNDER_CE
@@ -8400,9 +8329,9 @@
         goto EXIT;
     }
     fpGetHandle = dlsym(pComponentPrivate->pModLCML, "GetHandle");
-    if ((error = dlerror()) != NULL) {
+    if (!fpGetHandle) {
         OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n");
-        fputs(error, stderr);
+        fputs(dlerror(), stderr);
         dlclose(pComponentPrivate->pModLCML);
         pComponentPrivate->pModLCML = NULL;
         eError = OMX_ErrorBadParameter;
@@ -9017,7 +8946,7 @@
         /* Disable if resolution higher than D1 NTSC (720x480) */
         if(pComponentPrivate->pOutPortDef->format.video.nFrameWidth > 480 || 
                 pComponentPrivate->pOutPortDef->format.video.nFrameHeight > 480){
-           bDisDeblocking = OMX_TRUE; 
+           bDisDeblocking = OMX_TRUE;
            LOGD("D1 or higher resolution: Disable Deblocking!!");
         }
     }
diff --git a/omx/video/src/openmax_il/video_decode/src/OMX_VideoDecoder.c b/omx/video/src/openmax_il/video_decode/src/OMX_VideoDecoder.c
index e03a5be..8450ad1 100644
--- a/omx/video/src/openmax_il/video_decode/src/OMX_VideoDecoder.c
+++ b/omx/video/src/openmax_il/video_decode/src/OMX_VideoDecoder.c
@@ -783,7 +783,6 @@
     pComp = (OMX_COMPONENTTYPE*)hComponent;
     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE*)pComp->pComponentPrivate;
 
-    /*add check if state != loaded or port not disabled*/
     if (pComponentPrivate->eState == OMX_StateInvalid) {
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
     }
@@ -836,15 +835,15 @@
 				switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat)
 				{
 				case OMX_VIDEO_CodingH263:
-				    pProfileLevel = &SupportedH263ProfileLevels;
+				    pProfileLevel = SupportedH263ProfileLevels;
                                     nNumberOfProfiles = sizeof(SupportedH263ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
 				    break;
 				case OMX_VIDEO_CodingMPEG4:
-				    pProfileLevel = &SupportedMPEG4ProfileLevels;
+				    pProfileLevel = SupportedMPEG4ProfileLevels;
                                     nNumberOfProfiles = sizeof(SupportedMPEG4ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
 				    break;
 				case OMX_VIDEO_CodingAVC:
-				    pProfileLevel = &SupportedAVCProfileLevels;
+				    pProfileLevel = SupportedAVCProfileLevels;
                                     nNumberOfProfiles = sizeof(SupportedAVCProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
 				    break;
                                 default:
@@ -1119,6 +1118,72 @@
 EXIT:
     return eError;
 }
+
+/*----------------------------------------------------------------------------*/
+/**
+  *  VIDDEC_CheckSetParameter() checks when it is valid calling OMX_SetParameter
+  *
+  * This method will update application callbacks
+  * the application.
+  *
+  * @param pComponentPrivate         handle for this instance of the component
+  * @param pCompParam                pointer to the parameter structure
+  * @param nParamIndex               parameter index
+  *
+  * @retval OMX_NoError              Success, ready to roll
+  *         OMX_ErrorIncorrectStateOperation   if the checks fails
+  **/
+/*----------------------------------------------------------------------------*/
+
+OMX_ERRORTYPE VIDDEC_CheckSetParameter(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_PTR pCompParam, OMX_INDEXTYPE nParamIndex) {
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+
+    if (pComponentPrivate->eState == OMX_StateInvalid) {
+        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
+    }
+
+    if (pComponentPrivate->eState != OMX_StateLoaded && pComponentPrivate->eState != OMX_StateWaitForResources) {
+        /*using OMX_CONFIG_ROTATIONTYPE because it is smallest structure that contains nPortIndex;*/
+        OMX_CONFIG_ROTATIONTYPE* pTempFormat = (OMX_CONFIG_ROTATIONTYPE*)pCompParam;
+
+        switch (nParamIndex) {
+            /*the indices corresponding to the parameter structures containing the field "nPortIndex"*/
+            case OMX_IndexParamCompBufferSupplier:
+            case OMX_IndexParamVideoPortFormat:
+            case OMX_IndexParamPortDefinition:
+            case OMX_IndexParamVideoWmv:
+            case OMX_IndexParamVideoMpeg4:
+            case OMX_IndexParamVideoMpeg2:
+            case OMX_IndexParamVideoAvc:
+            case OMX_IndexParamVideoH263:
+            case OMX_IndexConfigVideoMBErrorReporting:
+            case OMX_IndexParamCommonDeblocking:
+                if (pTempFormat->nPortIndex ==  pComponentPrivate->pInPortDef->nPortIndex) {
+                    if (pComponentPrivate->pInPortDef->bEnabled){
+                        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
+                    }
+                }
+                else if (pTempFormat->nPortIndex == pComponentPrivate->pOutPortDef->nPortIndex) {
+                    if (pComponentPrivate->pOutPortDef->bEnabled){
+                        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
+                    }
+                }/*it cannot be -1 because structure assignment will happen on one port*/
+                else {
+                    eError = OMX_ErrorBadPortIndex;
+                }
+                break;
+            default:
+                /*all other cases where pCompParam is integer or it doesn't support nPortIndex*/
+                if (!(pComponentPrivate->pInPortDef->bEnabled == OMX_FALSE ||
+                    pComponentPrivate->pOutPortDef->bEnabled == OMX_FALSE)) {
+                    OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
+                }
+        }
+    }
+EXIT:
+    return eError;
+}
+
 /*----------------------------------------------------------------------------*/
 /**
   *  VIDDEC_SetParameter() Sets application callbacks to the component
@@ -1150,9 +1215,11 @@
     pHandle= (OMX_COMPONENTTYPE*)hComp;
     pComponentPrivate = pHandle->pComponentPrivate;
 
-    if (pComponentPrivate->eState != OMX_StateLoaded && pComponentPrivate->eState != OMX_StateWaitForResources) {
-        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation);
-    }
+    eError = VIDDEC_CheckSetParameter(pComponentPrivate, pCompParam, nParamIndex);
+
+    if (eError != OMX_ErrorNone)
+        OMX_CONF_SET_ERROR_BAIL(eError , OMX_ErrorIncorrectStateOperation);
+
     switch (nParamIndex) {
         case OMX_IndexParamVideoPortFormat:
             {
@@ -1446,7 +1513,7 @@
                         pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263){
                         pComponentPrivate->pDeblockingParamType->bDeblocking = 
                             ((OMX_PARAM_DEBLOCKINGTYPE*)pCompParam)->bDeblocking;
-                        LOGD("Deblocking Enable");
+			 LOGD("Deblocking Enable");
                     break;
                 }
             }
@@ -1495,13 +1562,13 @@
                          switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat)
                          {
                              case OMX_VIDEO_CodingH263:
-                                 pProfileLevel = &SupportedH263ProfileLevels;
+                                 pProfileLevel = SupportedH263ProfileLevels;
                                  break;
                              case OMX_VIDEO_CodingMPEG4:
-                                 pProfileLevel = &SupportedMPEG4ProfileLevels;
+                                 pProfileLevel = SupportedMPEG4ProfileLevels;
                                  break;
                              case OMX_VIDEO_CodingAVC:
-                                 pProfileLevel = &SupportedAVCProfileLevels;
+                                 pProfileLevel = SupportedAVCProfileLevels;
                                  break;
                              default:
                                  return OMX_ErrorBadParameter;
@@ -2309,7 +2376,7 @@
     pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
     ret = pBufferPrivate->eBufferOwner;
     pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
-    pComponentPrivate->nInputBCountApp++;
+    android_atomic_inc(&pComponentPrivate->nInputBCountApp);
 
     OMX_PRBUFFER1(pComponentPrivate->dbg, "Writing pBuffer 0x%p OldeBufferOwner %ld nAllocLen %lu nFilledLen %lu eBufferOwner %d\n",
         pBuffHead, ret,pBuffHead->nAllocLen,pBuffHead->nFilledLen,pBufferPrivate->eBufferOwner);
@@ -2391,9 +2458,9 @@
     pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate;
     ret = pBufferPrivate->eBufferOwner;
     pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
-    pComponentPrivate->nOutputBCountApp++;
+    android_atomic_inc(&pComponentPrivate->nOutputBCountApp);
     pBuffHead->nFilledLen = 0;
-    /*pBuffHead->nFlags = 0;*/
+    pBuffHead->nFlags = 0;  // Clear flags
     OMX_PRBUFFER1(pComponentPrivate->dbg, "Writing pBuffer 0x%p OldeBufferOwner %d eBufferOwner %d nFilledLen %lu\n",
         pBuffHead, ret,pBufferPrivate->eBufferOwner,pBuffHead->nFilledLen);
     ret = write (pComponentPrivate->free_outBuf_Q[1], &(pBuffHead), sizeof (pBuffHead));
@@ -3075,20 +3142,8 @@
                              PERF_ModuleMemory);
 #endif
 
-           pTemp = (OMX_U8*)(pBuffHead->pBuffer);
-#ifdef VIDDEC_WMVPOINTERFIXED
-            if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV &&
-                nPortIndex == VIDDEC_INPUT_PORT &&
-                pComponentPrivate->ProcessMode == 0) {
-                pTemp -= VIDDEC_WMV_BUFFER_OFFSET;
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "Removing extra wmv padding %d pBuffer 0x%p\n", VIDDEC_WMV_BUFFER_OFFSET, 
-                    pTemp);
-            }
-#endif
-           pTemp -= VIDDEC_PADDING_HALF;
-           pBuffHead->pBuffer = (OMX_U8*)pTemp;
-           free(pBuffHead->pBuffer);
-           pBuffHead->pBuffer = NULL;
+           OMX_FREE_BUFFER_VIDDEC(pBuffHead, pCompPort);
+
         }
     }
 
@@ -3218,10 +3273,7 @@
     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef = NULL;
     VIDDEC_PORT_TYPE* pCompPort = NULL;
-    OMX_U8* pTemp = NULL;
     OMX_U8 pBufferCnt = 0;
-    OMX_U32 nTempSizeBytes = 0;
-    nTempSizeBytes = nSizeBytes;
 
     OMX_CONF_CHECK_CMD(hComponent, OMX_TRUE, OMX_TRUE);
 
@@ -3231,14 +3283,6 @@
     OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p pBuffHead 0x%p nPortIndex 0x%lx nSizeBytes 0x%lx\n",
         hComponent, *pBuffHead, nPortIndex, nSizeBytes);
 
-#ifdef VIDDEC_WMVPOINTERFIXED
-    if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV && 
-        nPortIndex == VIDDEC_INPUT_PORT &&
-        pComponentPrivate->ProcessMode == 0) {
-        nTempSizeBytes += VIDDEC_WMV_BUFFER_OFFSET;
-        OMX_PRBUFFER1(pComponentPrivate->dbg, "Adding extra wmv buffer add %d size %lu\n", VIDDEC_WMV_BUFFER_OFFSET, nTempSizeBytes);
-    }
-#endif
     if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
         pCompPort = pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT];
         pBufferCnt = pCompPort->nBufferCnt;
@@ -3269,7 +3313,10 @@
     *pBuffHead = pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr;
     memset(*pBuffHead, 0, sizeof(OMX_BUFFERHEADERTYPE));
     OMX_CONF_INIT_STRUCT(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr, OMX_BUFFERHEADERTYPE, pComponentPrivate->dbg);
-    OMX_MALLOC_STRUCT_SIZED(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer, OMX_U8, nSizeBytes + VIDDEC_PADDING_FULL,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);
+    /* Allocate Video Decoder buffer */
+    OMX_MALLOC_BUFFER_VIDDEC(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer,
+			nSizeBytes,
+			pCompPort->pBufferPrivate[pBufferCnt]->pOriginalBuffer);
     if (!pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer) {
         eError = OMX_ErrorInsufficientResources;
         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
@@ -3280,37 +3327,20 @@
                                                NULL);
         goto EXIT;
     }
-    pTemp = (OMX_U8*)pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer;
-    pTemp += VIDDEC_PADDING_HALF;
 #ifdef VIDDEC_WMVPOINTERFIXED
-    if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV && 
-        nPortIndex == VIDDEC_INPUT_PORT &&
-        pComponentPrivate->ProcessMode == 0) {
-        pTemp += VIDDEC_WMV_BUFFER_OFFSET;
-        pCompPort->pBufferPrivate[pBufferCnt]->pTempBuffer = (OMX_U8*)pTemp;
-        (*pBuffHead)->nOffset = 0;
-        OMX_PRBUFFER1(pComponentPrivate->dbg, "Adding extra wmv padding %d pBuffer 0x%p\n", VIDDEC_WMV_BUFFER_OFFSET,
-            pTemp);
-    }
+    pCompPort->pBufferPrivate[pBufferCnt]->pTempBuffer = (pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer);
+    (*pBuffHead)->nOffset = 0;
 #endif
-    pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer = (OMX_U8*)pTemp;
+
     (*pBuffHead)->pBuffer = (pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer);
-    (*pBuffHead)->nAllocLen = nTempSizeBytes;
+    (*pBuffHead)->nAllocLen = nSizeBytes;
     (*pBuffHead)->pAppPrivate = pAppPrivate;
     (*pBuffHead)->pPlatformPrivate = NULL;
     (*pBuffHead)->pInputPortPrivate = NULL;
     (*pBuffHead)->pOutputPortPrivate = NULL;
     (*pBuffHead)->nFlags = VIDDEC_CLEARFLAGS;
     (*pBuffHead)->pMarkData = NULL;
-#ifndef VIDDEC_WMVPOINTERFIXED
-    if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM &&
-        pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV && 
-        pComponentPrivate->ProcessMode == 0 &&
-        nPortIndex == VIDDEC_INPUT_PORT) {
-        /* vc-1 fix */
-        (*pBuffHead)->nOffset = VIDDEC_WMV_BUFFER_OFFSET;
-    }
-#endif
+
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
                        (*pBuffHead)->pBuffer,
@@ -3357,7 +3387,7 @@
         pCompPort->pBufferPrivate[pBufferCnt]->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
     }
 
-    pPortDef->nBufferSize = nTempSizeBytes;
+    pPortDef->nBufferSize = nSizeBytes;
     OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead 0x%p nAllocLen 0x%lx pBuffer %p eBufferOwner %d\n",
         *pBuffHead, (*pBuffHead)->nAllocLen, pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer, 
         pCompPort->pBufferPrivate[pBufferCnt]->eBufferOwner);
diff --git a/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_Utils.h b/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_Utils.h
index 05c3acb..e69dd5f 100644
--- a/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_Utils.h
+++ b/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_Utils.h
@@ -69,11 +69,11 @@
 #include <utils/Log.h>
 
 /* this is the max of VIDENC_MAX_NUM_OF_IN_BUFFERS and VIDENC_MAX_NUM_OF_OUT_BUFFERS */
-#define VIDENC_MAX_NUM_OF_BUFFERS     8
-#define VIDENC_MAX_NUM_OF_IN_BUFFERS  5
-#define VIDENC_MAX_NUM_OF_OUT_BUFFERS 8
-#define VIDENC_NUM_OF_IN_BUFFERS  4
-#define VIDENC_NUM_OF_OUT_BUFFERS 8
+#define VIDENC_MAX_NUM_OF_BUFFERS     10
+#define VIDENC_MAX_NUM_OF_IN_BUFFERS  10
+#define VIDENC_MAX_NUM_OF_OUT_BUFFERS 10
+#define VIDENC_NUM_OF_IN_BUFFERS  5
+#define VIDENC_NUM_OF_OUT_BUFFERS 10
 #define VIDENC_NUM_OF_PORTS 2
 
 
@@ -81,8 +81,6 @@
     #define GPP_PRIVATE_NODE_HEAP
 #endif
 
-#define VIDENC_NUM_CUSTOM_INDEXES 23
-
 #if 1
     #define __KHRONOS_CONF__
 #endif
diff --git a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c
index 826ebd8..2e9e977 100644
--- a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c
+++ b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Utils.c
@@ -3298,7 +3298,7 @@
         pCreatePhaseArgs->ulFrameRate > 15000)
     {
         pComponentPrivate->maxMVperMB = 1;
-        pComponentPrivate->intra4x4EnableIdc = INTRA4x4_NONE;
+        pComponentPrivate->intra4x4EnableIdc = INTRA4x4_ISLICES;
         pComponentPrivate->nIntraFrameInterval = 30;
         pComponentPrivate->nAIRRate = 0;
         /* Encoding preset = 4 enables DSP side optimizations for high resolutions */
@@ -3306,8 +3306,6 @@
         pCreatePhaseArgs->ulIntraFramePeriod = 0;
         /* Constant bit rate control enabled */
         pCreatePhaseArgs->ucRateControlAlgorithm = 1;
-        /* Disable deblocking */
-        pCreatePhaseArgs->ucDeblockingEnable  = 0;
         pCreatePhaseArgs->ucLevel = 30;
     }
 
@@ -3559,7 +3557,7 @@
     OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
     }
 
-    pCreatePhaseArgs->ucQPFirstIFrame         = (OMX_U8)pQuantization->nQpI;
+    pCreatePhaseArgs->ucQPFirstIFrame         = 8;
     pCreatePhaseArgs->ucProfile               = 1;
 
     if (pCreatePhaseArgs->ucIsMPEG4 == 1) 
diff --git a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c
index de69e70..8cf3bb8 100644
--- a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c
+++ b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEncoder.c
@@ -1651,15 +1651,15 @@
 				switch(pCompPortOut->pPortDef->format.video.eCompressionFormat)
        		         {
 				case OMX_VIDEO_CodingH263:
-					pProfileLevel = &SupportedH263ProfileLevels;
+					pProfileLevel = SupportedH263ProfileLevels;
                                         nNumberOfProfiles = sizeof(SupportedH263ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
 					break;
 				case OMX_VIDEO_CodingMPEG4:
-					pProfileLevel = &SupportedMPEG4ProfileLevels;
+					pProfileLevel = SupportedMPEG4ProfileLevels;
                                         nNumberOfProfiles = sizeof(SupportedMPEG4ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
 					break;
 				case OMX_VIDEO_CodingAVC:
-					pProfileLevel = &SupportedAVCProfileLevels;
+					pProfileLevel = SupportedAVCProfileLevels;
                                         nNumberOfProfiles = sizeof(SupportedAVCProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
 					break;
                                 default:
@@ -2091,13 +2091,13 @@
 			switch(pCompPortOut->pPortDef->format.video.eCompressionFormat)
 	            {
 			case OMX_VIDEO_CodingH263:
-				pProfileLevel = &SupportedH263ProfileLevels;
+				pProfileLevel = SupportedH263ProfileLevels;
 				break;
 			case OMX_VIDEO_CodingMPEG4:
-				pProfileLevel = &SupportedMPEG4ProfileLevels;
+				pProfileLevel = SupportedMPEG4ProfileLevels;
 				break;
 			case OMX_VIDEO_CodingAVC:
-				pProfileLevel = &SupportedAVCProfileLevels;
+				pProfileLevel = SupportedAVCProfileLevels;
 				break;
                         default:
                                eError = OMX_ErrorBadParameter;
@@ -2557,8 +2557,7 @@
                                        OMX_IN OMX_STRING cParameterName, 
                                        OMX_OUT OMX_INDEXTYPE* pIndexType)
 {
-    VIDENC_CUSTOM_DEFINITION sVideoEncodeCustomIndex[VIDENC_NUM_CUSTOM_INDEXES] = 
-    {
+    VIDENC_CUSTOM_DEFINITION sVideoEncodeCustomIndex[] = {
         {"OMX.TI.VideoEncode.Param.VBVSize", VideoEncodeCustomParamIndexVBVSize},
                                     {"OMX.TI.VideoEncode.Param.DeblockFilter", VideoEncodeCustomParamIndexDeblockFilter},
                                     {"OMX.TI.VideoEncode.Config.ForceIFrame", VideoEncodeCustomConfigIndexForceIFrame},
@@ -2589,9 +2588,8 @@
                                      {"OMX.TI.VideoEncode.Config.EncodingPreset", VideoEncodeCustomParamIndexEncodingPreset},
         {"OMX.TI.VideoEncode.Config.NALFormat", VideoEncodeCustomParamIndexNALFormat},
         {"OMX.TI.VideoEncode.Debug", VideoEncodeCustomConfigIndexDebug}
-                                   }; 
+    };
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    int nIndex = 0;
  
     if (!hComponent || !pIndexType) 
     {
@@ -2599,7 +2597,9 @@
         goto OMX_CONF_CMD_BAIL;
     }
 
-    for (nIndex = 0; nIndex < VIDENC_NUM_CUSTOM_INDEXES; nIndex++)
+    OMX_U32 nIndex = 0;
+    const OMX_U32 size = sizeof(sVideoEncodeCustomIndex)/sizeof(VIDENC_CUSTOM_DEFINITION);
+    for (nIndex = 0; nIndex < size; nIndex++)
     {
         if (!strcmp((const char*)cParameterName, (const char*)(&(sVideoEncodeCustomIndex[nIndex].cCustomName))))
         {
@@ -3969,20 +3969,20 @@
                                        OMX_IN OMX_U32 nIndex)
 {
     VIDENC_COMPONENT_PRIVATE *pComponentPrivate;
-	OMX_ERRORTYPE eError = OMX_ErrorNone;
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
 
     if (hComponent==NULL)
     {
-		goto OMX_CONF_CMD_BAIL;
-		eError= OMX_ErrorBadParameter;
-		}
-    
+        eError= OMX_ErrorBadParameter;
+        goto OMX_CONF_CMD_BAIL;
+    }
+
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
     if(nIndex == 0)
     {
-	  strncpy((char*)cRole, (char *)pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE - 1); 
-	}
+        strncpy((char*)cRole, (char *)pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE - 1);
+    }
     else
     {
       eError = OMX_ErrorNoMore;