Omx component change due to TI's socket node update from 25.9 to 25.14
diff --git a/omx/Android.mk b/omx/Android.mk
index 06e44e9..dbd90a4 100644
--- a/omx/Android.mk
+++ b/omx/Android.mk
@@ -14,19 +14,19 @@
 PERF_READER := 1
 
 TI_OMX_CFLAGS := -Wall -fpic -pipe -DSTATIC_TABLE -O0 -DOMAP_3430
-
 ifeq ($(RESOURCE_MANAGER_ENABLED),1)
 TI_OMX_CFLAGS += -DRESOURCE_MANAGER_ENABLED 
 endif
 ifeq ($(PERF_INSTRUMENTATION),1)
 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
+BUILD_AMRNB_DECODER := 1
+BUILD_AMRWB_DECODER := 1
 endif
 
 TI_OMX_TOP := $(LOCAL_PATH)
@@ -51,6 +51,15 @@
 	libPERF
 endif
 
+ifeq ($(ENABLE_RMPM_STUB),1)
+TI_OMX_CFLAGS += -D__ENABLE_RMPM_STUB__
+endif
+
+ifeq ($(DVFS_ENABLED),1)
+TI_OMX_CFLAGS += -DDVFS_ENABLED
+endif
+
+
 TI_OMX_COMP_C_INCLUDES := \
 	$(TI_OMX_INCLUDES) \
 	$(TI_BRIDGE_INCLUDES) \
@@ -58,18 +67,20 @@
 	$(TI_OMX_SYSTEM)/common/inc \
 	$(TI_OMX_SYSTEM)/perf/inc 
 
-#call to common omx
-include $(TI_OMX_SYSTEM)/omx_core/src/Android.mk
-include $(TI_OMX_SYSTEM)/lcml/src/Android.mk
 
 ifeq ($(PERF_INSTRUMENTATION),1)
 include $(TI_OMX_SYSTEM)/perf/Android.mk
 endif
+
 ifeq ($(PERF_READER),1)
 #TODO: Implement automatic building
 #include $(TI_OMX_SYSTEM)/perf/reader/Android.mk
 endif
 
+#call to common omx & system components
+include $(TI_OMX_SYSTEM)/omx_core/src/Android.mk
+include $(TI_OMX_SYSTEM)/lcml/src/Android.mk
+
 #call to audio
 include $(TI_OMX_AUDIO)/aac_dec/src/Android.mk
 include $(TI_OMX_AUDIO)/aac_enc/src/Android.mk
@@ -106,6 +117,7 @@
 include $(TI_OMX_VIDEO)/video_encode/Android.mk
 include $(TI_OMX_VIDEO)/video_encode/test/Android.mk
 include $(TI_OMX_VIDEO)/prepost_processor/Android.mk
+
 #call to image
 include $(TI_OMX_IMAGE)/jpeg_enc/Android.mk
 include $(TI_OMX_IMAGE)/jpeg_dec/Android.mk
@@ -117,3 +129,4 @@
 include $(TI_OMX_TOP)/ti_omx_config_parser/Android.mk
 
 endif
+
diff --git a/omx/audio/src/openmax_il/aac_dec/inc/OMX_AacDec_Utils.h b/omx/audio/src/openmax_il/aac_dec/inc/OMX_AacDec_Utils.h
index cb234d6..4daf12a 100644
--- a/omx/audio/src/openmax_il/aac_dec/inc/OMX_AacDec_Utils.h
+++ b/omx/audio/src/openmax_il/aac_dec/inc/OMX_AacDec_Utils.h
@@ -47,7 +47,11 @@
 #include "LCML_DspCodec.h"
 #include <pthread.h>
 #include <sched.h>
-/* #include <ResourceManagerProxyAPI.h> */
+
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
+
 #ifdef UNDER_CE
 #include <windows.h>
 #include <oaf_osal.h>
@@ -78,6 +82,7 @@
 #endif
  
 #define OBJECTTYPE_LC 2
+#define OBJECTTYPE_LTP 4
 #define OBJECTTYPE_HE 5
 #define OBJECTTYPE_HE2 29
 
@@ -231,10 +236,7 @@
 #else /* for Linux */
 
 #ifdef  AACDEC_DEBUG
-    #define AACDEC_DPRINT printf    //__android_log_print(ANDROID_LOG_VERBOSE, __FILE__,"%s %d:: ",__FUNCTION__, __LINE__);\
-	                            //__android_log_print(ANDROID_LOG_VERBOSE, __FILE__, __VA_ARGS__);\
-    	                            //__android_log_print(ANDROID_LOG_VERBOSE, __FILE__, "\n");
-
+    #define AACDEC_DPRINT printf
     #undef AACDEC_BUFPRINT printf
     #undef AACDEC_MEMPRINT printf
     #define AACDEC_STATEPRINT printf
@@ -264,45 +266,8 @@
 
 #define AACDEC_EPRINT LOGE
 
-                           /* __android_log_print(ANDROID_LOG_VERBOSE, __FILE__,"%s %d::	ERROR",__FUNCTION__, __LINE__);\
-	                    __android_log_print(ANDROID_LOG_VERBOSE, __FILE__, __VA_ARGS__);\
-    	                    __android_log_print(ANDROID_LOG_VERBOSE, __FILE__, "\n"); */
-
 #endif
 
-/* ======================================================================= */
-/**
- * @def    AACD_OMX_MALLOC   Macro to allocate Memory
- */
-/* ======================================================================= */
-#define AACD_OMX_MALLOC(_pStruct_, _sName_)                         \
-    _pStruct_ = (_sName_*)newmalloc(sizeof(_sName_));               \
-    if(_pStruct_ == NULL){                                          \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");            \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Malloc Failed\n",__LINE__);                   \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");            \
-        eError = OMX_ErrorInsufficientResources;                    \
-        goto EXIT;                                                  \
-    }                                                               \
-    memset(_pStruct_,0,sizeof(_sName_));                            \
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Malloced = %p\n",__LINE__,_pStruct_);
-
-/* ======================================================================= */
-/**
- * @def    AACDEC_OMX_MALLOC_SIZE   Macro to allocate Memory
- */
-/* ======================================================================= */
-#define AACDEC_OMX_MALLOC_SIZE(_ptr_, _size_,_name_)            \
-    _ptr_ = (_name_*)newmalloc(_size_);                         \
-    if(_ptr_ == NULL){                                          \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");        \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Malloc Failed\n",__LINE__);               \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");        \
-        eError = OMX_ErrorInsufficientResources;                \
-        goto EXIT;                                              \
-    }                                                           \
-    memset(_ptr_,0,_size_);                                     \
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Malloced = %p\n",__LINE__,_ptr_);
 
 /* ======================================================================= */
 /**
@@ -331,18 +296,6 @@
 
 /* ======================================================================= */
 /**
- * @def    AACDEC_OMX_FREE   Macro to free the Memory
- */
-/* ======================================================================= */
-#define AACDEC_OMX_FREE(ptr)                                            \
-    if(NULL != ptr) {                                                   \
-        OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Freeing Address = %p\n",__LINE__,ptr);   \
-        newfree(ptr);                                                   \
-        ptr = NULL;                                                     \
-    }
-
-/* ======================================================================= */
-/**
  * @def    OMX_CONF_INIT_STRUCT   Macro to Initialise the structure variables
  */
 /* ======================================================================= */
@@ -373,8 +326,6 @@
 /* ======================================================================= */
 #undef AACDEC_MEMDETAILS
 
-#define EXTRA_BYTES 128 /* For Cache alignment*/
-#define DSP_CACHE_ALIGNMENT 256 /* For Cache alignment*/
 #define AACDEC_OUTPUT_PORT 1
 #define AACDEC_INPUT_PORT 0
 #define AACDEC_APP_ID  100
@@ -434,21 +385,6 @@
 
 /* ======================================================================= */
 /**
- * @def    Mem test application
- */
-/* ======================================================================= */
-#undef AACDEC_DEBUGMEM 
-
-#ifdef AACDEC_DEBUGMEM
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__) 
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
-/* ======================================================================= */
-/**
  * @def    AACDec macros for MONO,STEREO_INTERLEAVED,STEREO_NONINTERLEAVED
  */
 /* ======================================================================= */
@@ -466,10 +402,10 @@
 
 /* ======================================================================= */
 /**
- * pthread variable to indicate OMX returned all buffers to app
+ * pthread variable to indicate OMX returned all buffers to app 
  */
 /* ======================================================================= */
-pthread_mutex_t bufferReturned_mutex;
+pthread_mutex_t bufferReturned_mutex; 
 pthread_cond_t bufferReturned_condition;
 
 /**
@@ -558,8 +494,8 @@
     long       DownSampleSbr;
     long       iEnablePS;
     long       lSamplingRateIdx;
-    long       nProfile;
     long       bRawFormat;
+    long       dualMonoMode;
 } MPEG4AACDEC_UALGParams;
 
 /* ======================================================================= */
@@ -656,7 +592,7 @@
 /* ==================================================================== */
 typedef struct {
     unsigned long ulFrameCount;
-  unsigned long isLastBuffer;
+    unsigned long isLastBuffer;
 }AACDEC_UAlgOutBufParamStruct;
 
 typedef struct AACDEC_UALGParams{
@@ -854,7 +790,10 @@
     /** Pointer to port priority management structure */
     OMX_PRIORITYMGMTTYPE* pPriorityMgmt;
 
-	/* RMPROXY_CALLBACKTYPE rmproxyCallback; */
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
     OMX_BOOL bPreempted;
 
 	
@@ -893,7 +832,7 @@
 
     OMX_U32 nOpBit;
     OMX_U32 parameteric_stereo;
-    OMX_U32 nProfile;
+    OMX_U32 dualMonoMode;
     OMX_U32 SBR;
     OMX_U32 RAW;
     OMX_U32 nFillThisBufferCount;
@@ -929,7 +868,6 @@
 #ifndef UNDER_CE    
     pthread_mutex_t AlloBuf_mutex;    
     pthread_cond_t AlloBuf_threshold;
-
     OMX_U8 AlloBuf_waitingsignal;
     
     pthread_mutex_t InLoaded_mutex;
@@ -948,8 +886,10 @@
     pthread_cond_t codecFlush_threshold;
     OMX_U8 codecFlush_waitingsignal;
 
-    OMX_S8 nUnhandledFillThisBuffers;
-    OMX_S8 nUnhandledEmptyThisBuffers;
+    OMX_U32 nUnhandledFillThisBuffers;
+    OMX_U32 nHandledFillThisBuffers;
+    OMX_U32 nUnhandledEmptyThisBuffers;
+    OMX_U32 nHandledEmptyThisBuffers;
     OMX_BOOL bFlushOutputPortCommandPending;
     OMX_BOOL bFlushInputPortCommandPending;
 #else
@@ -1333,8 +1273,9 @@
 /*================================================================== */
 OMX_U32 AACDEC_IsValid(AACDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir) ;
 
-/* void AACDEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData); */
-
+#ifdef RESOURCE_MANAGER_ENABLED
+void AACDEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
 /*=======================================================================*/
 /*! @fn AACDec_GetSampleRateIndexL
 
@@ -1361,18 +1302,23 @@
 /*  =========================================================================*/
 OMX_U32 AACDEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition);
 
+/*  =========================================================================*/
+/*  func    AACDEC_HandleUSNError
+ *
+ *  desc    Handles error messages returned by the dsp
+ *
+ * @Return n/a
+ *
+ *  =========================================================================*/
+void AACDEC_HandleUSNError (AACDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
+
 /*=======================================================================*/
-/*! @fn SignalIfAllBuffersAreReturned
-
- * @brief Sends pthread signal to indicate OMX has returned all buffers to app
-
- * @param  none
-
- * @Return void
-
+/*! @fn SignalIfAllBuffersAreReturned 
+ * @brief Sends pthread signal to indicate OMX has returned all buffers to app 
+ * @param  none 
+ * @Return void 
  */
 /*=======================================================================*/
 void SignalIfAllBuffersAreReturned(AACDEC_COMPONENT_PRIVATE *pComponentPrivate);
 
-
 #endif
diff --git a/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDec_CompThread.c b/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDec_CompThread.c
index 88e21da..028aae6 100644
--- a/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDec_CompThread.c
+++ b/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDec_CompThread.c
@@ -151,13 +151,11 @@
             pComponentPrivate->cbInfo.EventHandler (pHandle,
                                                     pHandle->pApplicationPrivate,
                                                     OMX_EventError,
-                                                    OMX_ErrorHardware, 
+                                                    OMX_ErrorInsufficientResources,
                                                     OMX_TI_ErrorSevere,
                                                     "Error from COmponent Thread in select");
-            eError = OMX_ErrorHardware;
-            break;
-            
-        } 
+            eError = OMX_ErrorInsufficientResources;
+        }
         else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) {
             OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: CMD pipe is set in Component Thread\n",__LINE__);
             nRet = AACDEC_HandleCommand (pComponentPrivate);
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 e133ae4..16d756e 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
@@ -77,29 +77,20 @@
 #include <stdio.h>
 
 /*------- Program Header Files -----------------------------------------------*/
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
+
 #include "LCML_DspCodec.h"
 #include "OMX_AacDec_Utils.h"
 #include "Aacdecsocket_ti.h"
 #include <decode_common_ti.h>
 #include "usn.h"
 
-#ifdef RESOURCE_MANAGER_ENABLED
-#include <ResourceManagerProxyAPI.h>
-#endif
-
 #ifdef UNDER_CE
 #define HASHINGENABLE 1
 #endif
 
-#ifdef AACDEC_DEBUGMEM
-void *arr[500];
-int lines[500];
-int bytes[500];
-char file[500][50];
-
-void * mymalloc(int line, char *s, int size);
-int myfree(void *dp, int line, char *s);
-#endif
 /* ================================================================================= * */
 /**
 * @fn AACDEC_Fill_LCMLInitParams() fills the LCML initialization structure.
@@ -129,7 +120,6 @@
     AACDEC_COMPONENT_PRIVATE *pComponentPrivate = (AACDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     AACD_LCML_BUFHEADERTYPE *pTemp_lcml;
     OMX_U32 size_lcml;
-    char *pTemp_char = NULL;
     char *ptr;
     pComponentPrivate->nRuntimeInputBuffers = 0;
     pComponentPrivate->nRuntimeOutputBuffers = 0;
@@ -186,7 +176,7 @@
     plcml_Init->Timeout = OMX_AACDEC_SN_TIMEOUT;
     plcml_Init->Alignment = 0;
     plcml_Init->Priority = OMX_AACDEC_SN_PRIORITY;
-    plcml_Init->ProfileID = -1; /* Previously 0 */
+    plcml_Init->ProfileID = -1;
 
     OMX_PRINT1(pComponentPrivate->dbg, "DLL name0 = %s\n",plcml_Init->NodeInfo.AllUUIDs[0].DllName);
     OMX_PRINT1(pComponentPrivate->dbg, "DLL name1 = %s\n",plcml_Init->NodeInfo.AllUUIDs[1].DllName);
@@ -202,7 +192,7 @@
 #else
 
         LCML_STRMATTR *strmAttr;
-        AACD_OMX_MALLOC(strmAttr, LCML_STRMATTR);
+        OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
         pComponentPrivate->strmAttr = strmAttr;
         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: AAC DECODER IS RUNNING UNDER DASF MODE \n",__LINE__);
 
@@ -258,7 +248,7 @@
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: bufAlloced = %lu\n",__LINE__,pComponentPrivate->bufAlloced);
     size_lcml = nIpBuf * sizeof(AACD_LCML_BUFHEADERTYPE);
 
-    AACDEC_OMX_MALLOC_SIZE(ptr,size_lcml,char);
+    OMX_MALLOC_SIZE(ptr,size_lcml,char);
     pTemp_lcml = (AACD_LCML_BUFHEADERTYPE *)ptr;
 
     pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC] = pTemp_lcml;
@@ -280,12 +270,9 @@
         pTemp_lcml->eDir = OMX_DirInput;
         pTemp_lcml->pOtherParams[i] = NULL;
 
-        AACDEC_OMX_MALLOC_SIZE(pTemp_lcml->pIpParam,
-                             (sizeof(AACDEC_UAlgInBufParamStruct) + DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
+                             sizeof(AACDEC_UAlgInBufParamStruct),
                              AACDEC_UAlgInBufParamStruct);
-        pTemp_char = (char*)pTemp_lcml->pIpParam;
-        pTemp_char += EXTRA_BYTES;
-        pTemp_lcml->pIpParam = (AACDEC_UAlgInBufParamStruct*)pTemp_char;
         pTemp_lcml->pIpParam->bLastBuffer = 0;
         pTemp_lcml->pIpParam->bConcealBuffer = 0;
 
@@ -301,7 +288,7 @@
     }
 
     size_lcml = nOpBuf * sizeof(AACD_LCML_BUFHEADERTYPE);
-    AACDEC_OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,AACD_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,AACD_LCML_BUFHEADERTYPE);
     pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC] = pTemp_lcml;
 
     for (i=0; i<nOpBuf; i++) {
@@ -318,15 +305,12 @@
         pTemp_lcml->eDir = OMX_DirOutput;
         pTemp_lcml->pOtherParams[i] = NULL;
 
-        AACDEC_OMX_MALLOC_SIZE(pTemp_lcml->pOpParam,
-                             (sizeof(AACDEC_UAlgOutBufParamStruct) + DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam,
+                             sizeof(AACDEC_UAlgOutBufParamStruct),
                              AACDEC_UAlgOutBufParamStruct);
-        pTemp_char = (char*)pTemp_lcml->pOpParam;
-        pTemp_char += EXTRA_BYTES;
-        pTemp_lcml->pOpParam = (AACDEC_UAlgOutBufParamStruct*)pTemp_char;
         pTemp_lcml->pOpParam->ulFrameCount = DONT_CARE;
-	pTemp_lcml->pOpParam->isLastBuffer = 0;
-
+        pTemp_lcml->pOpParam->isLastBuffer = 0;
+		
         pTemp->nFlags = NORMAL_BUFFER_AACDEC;
         ((AACDEC_COMPONENT_PRIVATE *)pTemp->pPlatformPrivate)->pHandle = pHandle;
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d ::Comp:  >>>>>>>>>>>>> OutBuffHeader[%d] = %p\n",
@@ -337,33 +321,17 @@
         pTemp_lcml++;
     }
     pComponentPrivate->bPortDefsAllocated = 1;
-    if (pComponentPrivate->aacParams->eAACProfile == OMX_AUDIO_AACObjectMain){
-        pComponentPrivate->nProfile = 0;
-    } else if (pComponentPrivate->aacParams->eAACProfile == OMX_AUDIO_AACObjectLC){
-        pComponentPrivate->nProfile = 1;
-    } else if (pComponentPrivate->aacParams->eAACProfile == OMX_AUDIO_AACObjectSSR){
-        pComponentPrivate->nProfile = 2;
-    } else if (pComponentPrivate->aacParams->eAACProfile == OMX_AUDIO_AACObjectLTP){
-        pComponentPrivate->nProfile = 3;
-    } else if (pComponentPrivate->aacParams->eAACProfile == OMX_AUDIO_AACObjectHE){
-        pComponentPrivate->nProfile = 1;
+    if (pComponentPrivate->aacParams->eAACProfile == OMX_AUDIO_AACObjectHE){
         pComponentPrivate->SBR = 1;
     } else if (pComponentPrivate->aacParams->eAACProfile == OMX_AUDIO_AACObjectHE_PS){
-        pComponentPrivate->nProfile = 1;
         pComponentPrivate->parameteric_stereo = PARAMETRIC_STEREO_AACDEC;
     }
 
-    AACDEC_OMX_MALLOC_SIZE(pComponentPrivate->pParams,(sizeof (USN_AudioCodecParams) + DSP_CACHE_ALIGNMENT),
+    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,sizeof (USN_AudioCodecParams),
                            USN_AudioCodecParams);
-    pTemp_char = (char*)pComponentPrivate->pParams;
-    pTemp_char += EXTRA_BYTES;
-    pComponentPrivate->pParams = (USN_AudioCodecParams*)pTemp_char;
 
-    AACDEC_OMX_MALLOC_SIZE(pComponentPrivate->AACDEC_UALGParam,(sizeof (MPEG4AACDEC_UALGParams) + DSP_CACHE_ALIGNMENT),
+    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->AACDEC_UALGParam,sizeof (MPEG4AACDEC_UALGParams),
                            MPEG4AACDEC_UALGParams);
-    pTemp_char = (char*)pComponentPrivate->AACDEC_UALGParam;
-    pTemp_char += EXTRA_BYTES;
-    pComponentPrivate->AACDEC_UALGParam = (MPEG4AACDEC_UALGParams*)pTemp_char;
 
 #ifdef __PERF_INSTRUMENTATION__
     pComponentPrivate->nLcml_nCntIp = 0;
@@ -512,19 +480,19 @@
     }
 
     if (pComponentPrivate->bPortDefsAllocated) {
-        AACDEC_OMX_FREE(pComponentPrivate->pPortDef[INPUT_PORT_AACDEC]);
-        AACDEC_OMX_FREE(pComponentPrivate->pPortDef[OUTPUT_PORT_AACDEC]);
-        AACDEC_OMX_FREE(pComponentPrivate->aacParams);
-        AACDEC_OMX_FREE(pComponentPrivate->pcmParams);
-        AACDEC_OMX_FREE(pComponentPrivate->pCompPort[INPUT_PORT_AACDEC]->pPortFormat);
-        AACDEC_OMX_FREE(pComponentPrivate->pCompPort[OUTPUT_PORT_AACDEC]->pPortFormat);
-        AACDEC_OMX_FREE(pComponentPrivate->pCompPort[INPUT_PORT_AACDEC]);
-        AACDEC_OMX_FREE(pComponentPrivate->pCompPort[OUTPUT_PORT_AACDEC]);
-        AACDEC_OMX_FREE(pComponentPrivate->sPortParam);
-        AACDEC_OMX_FREE(pComponentPrivate->pPriorityMgmt);
-        AACDEC_OMX_FREE(pComponentPrivate->pInputBufferList);
-        AACDEC_OMX_FREE(pComponentPrivate->pOutputBufferList);
-        AACDEC_OMX_FREE(pComponentPrivate->componentRole);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[INPUT_PORT_AACDEC]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[OUTPUT_PORT_AACDEC]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->aacParams);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pcmParams);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[INPUT_PORT_AACDEC]->pPortFormat);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[OUTPUT_PORT_AACDEC]->pPortFormat);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[INPUT_PORT_AACDEC]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[OUTPUT_PORT_AACDEC]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->sPortParam);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pPriorityMgmt);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->componentRole);
     }
 
 
@@ -761,6 +729,14 @@
                                                 p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString);
                     if (eError != OMX_ErrorNone) {
                         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error : InitMMCodec failed...>>>>>> \n",__LINE__);
+                        /* send an event to client */
+                        /* client should unload the component if the codec is not able to load */
+                        pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                         goto EXIT;
                     }
 #else
@@ -859,12 +835,13 @@
 #endif 
                     OMX_PRDSP2(pComponentPrivate->dbg, "%d :: In HandleCommand: Stopping the codec\n",__LINE__);
                     pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE;
-		    if (pComponentPrivate->codecStop_waitingsignal == 0){
+                    pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
+			if (pComponentPrivate->codecStop_waitingsignal == 0){
                         pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
                     }
                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
                                                MMCodecControlStop,(void *)pArgs);
-		    if (pComponentPrivate->codecStop_waitingsignal == 0){
+			 if (pComponentPrivate->codecStop_waitingsignal == 0){
                         pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
                         pComponentPrivate->codecStop_waitingsignal = 0;
                         pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
@@ -905,12 +882,13 @@
 #endif
                     OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Comp: Stop Command Received\n",__LINE__);
                     OMX_PRDSP2(pComponentPrivate->dbg, "%d: AACDECUTILS::About to call LCML_ControlCodec\n",__LINE__);
-		    if (pComponentPrivate->codecStop_waitingsignal == 0){
+                    pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
+			if (pComponentPrivate->codecStop_waitingsignal == 0){
                         pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
                     }
                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
                                                MMCodecControlStop,(void *)pArgs);
-		    if (pComponentPrivate->codecStop_waitingsignal == 0){
+			 if (pComponentPrivate->codecStop_waitingsignal == 0){
                         pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
                         pComponentPrivate->codecStop_waitingsignal = 0; // reset the wait condition for next time
                         pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
@@ -996,7 +974,7 @@
                         }
                     }
 
-                    OMX_PRINT2(pComponentPrivate->dbg, "%d :: pComponentPrivate->nProfile %lu \n",__LINE__,pComponentPrivate->nProfile);
+                    OMX_PRINT2(pComponentPrivate->dbg, "%d :: pComponentPrivate->dualMonoMode %lu \n",__LINE__,pComponentPrivate->dualMonoMode);
                     OMX_PRINT2(pComponentPrivate->dbg, "%d :: pComponentPrivate->parameteric_stereo  %lu \n",
                                    __LINE__,pComponentPrivate->parameteric_stereo);
                     OMX_PRINT2(pComponentPrivate->dbg, "%d :: pComponentPrivate->SBR  %lu \n",__LINE__,pComponentPrivate->SBR);
@@ -1011,7 +989,7 @@
                             }
                         }
                         pComponentPrivate->AACDEC_UALGParam->iEnablePS        = 1;/*Added for eAAC*/
-                        pComponentPrivate->AACDEC_UALGParam->nProfile         = pComponentPrivate->nProfile;
+                        pComponentPrivate->AACDEC_UALGParam->dualMonoMode     = pComponentPrivate->dualMonoMode;
                         pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx = AACDec_GetSampleRateIndexL(pComponentPrivate->aacParams->nSampleRate);
                         pComponentPrivate->AACDEC_UALGParam->bRawFormat       = 0;
                         if(pComponentPrivate->aacParams->eAACStreamFormat == OMX_AUDIO_AACStreamFormatRAW){
@@ -1030,7 +1008,7 @@
                                 }
                             }
                             pComponentPrivate->AACDEC_UALGParam->iEnablePS        = 0;
-                            pComponentPrivate->AACDEC_UALGParam->nProfile         = pComponentPrivate->nProfile;
+                            pComponentPrivate->AACDEC_UALGParam->dualMonoMode     = pComponentPrivate->dualMonoMode;
                             pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx = AACDec_GetSampleRateIndexL(pComponentPrivate->aacParams->nSampleRate);
                             pComponentPrivate->AACDEC_UALGParam->bRawFormat       = 0;
                             if(pComponentPrivate->aacParams->eAACStreamFormat == OMX_AUDIO_AACStreamFormatRAW){
@@ -1051,8 +1029,8 @@
                         OMX_PRINT2(pComponentPrivate->dbg, "%d::pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx::%ld\n",
                                       __LINE__,pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx);
                         OMX_PRINT2(pComponentPrivate->dbg, "%d::pComponentPrivate->SBR::%lu\n",__LINE__,pComponentPrivate->SBR);
-                        OMX_PRINT2(pComponentPrivate->dbg, "%d::pComponentPrivate->AACDEC_UALGParam->nProfile::%ld\n",
-                                      __LINE__,pComponentPrivate->AACDEC_UALGParam->nProfile);
+                        OMX_PRINT2(pComponentPrivate->dbg, "%d::pComponentPrivate->AACDEC_UALGParam->dualMonoMode::%ld\n",
+                                      __LINE__,pComponentPrivate->AACDEC_UALGParam->dualMonoMode);
                         OMX_PRINT2(pComponentPrivate->dbg, "%d::pComponentPrivate->AACDEC_UALGParam->bRawFormat::%ld\n",
                                       __LINE__,pComponentPrivate->AACDEC_UALGParam->bRawFormat);
                         pValues1[0] = IUALG_CMD_SETSTATUS;
@@ -1104,18 +1082,35 @@
                                       pComponentPrivate->pInputBufHdrPending[i] != NULL);
                         if (pComponentPrivate->pInputBufHdrPending[i] != NULL) {
                             AACD_LCML_BUFHEADERTYPE *pLcmlHdr;
-                            AACDEC_GetCorresponding_LCMLHeader(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
-                                                               OMX_DirInput, &pLcmlHdr);
-                                AACDEC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__);
-                                OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling LCML_QueueBuffer Line %d\n",__LINE__);
-                                eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                                          EMMCodecInputBuffer,
-                                                          pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
-                                                          pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
-                                                          pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
-                                                          (OMX_U8 *) pLcmlHdr->pIpParam,
-                                                          sizeof(AACDEC_UAlgInBufParamStruct),
-                                                          NULL);
+                            AACDEC_GetCorresponding_LCMLHeader(pComponentPrivate,
+                                                      pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
+                                                      OMX_DirInput,
+                                                      &pLcmlHdr);
+                            AACDEC_SetPending(pComponentPrivate,
+                                              pComponentPrivate->pInputBufHdrPending[i],
+                                              OMX_DirInput,
+                                              __LINE__);
+                            OMX_PRBUFFER2(pComponentPrivate->dbg,
+                                          "Calling LCML_QueueBuffer Line %d\n",__LINE__);
+                            eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                      EMMCodecInputBuffer,
+                                                      pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
+                                                      pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
+                                                      pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
+                                                      (OMX_U8 *) pLcmlHdr->pIpParam,
+                                                      sizeof(AACDEC_UAlgInBufParamStruct),
+                                                      NULL);
+                            if(eError != OMX_ErrorNone) {
+                                OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in LCML QueueBuffer for input\n");
+                                pComponentPrivate->curState = OMX_StateInvalid;
+                                pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                eError,
+                                                                OMX_TI_ErrorSevere,
+                                                                NULL);
+                                goto EXIT;
+                            }
                         }
                     }
                     pComponentPrivate->nNumInputBufPending = 0;
@@ -1136,6 +1131,17 @@
                                                       (OMX_U8 *) pLcmlHdr->pOpParam,
                                                       sizeof(AACDEC_UAlgOutBufParamStruct),
                                                       NULL);
+                                if(eError != OMX_ErrorNone) {
+                                OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in LCML QueueBuffer for output\n");
+                                pComponentPrivate->curState = OMX_StateInvalid;
+                                pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                eError,
+                                                                OMX_TI_ErrorSevere,
+                                                                NULL);
+                                goto EXIT;
+                            }
                         }
                     }
                     pComponentPrivate->nNumOutputBufPending = 0;
@@ -1206,10 +1212,15 @@
                 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
 #endif
 
-                OMX_PRSTATE2(pComponentPrivate->dbg, "%d: AACDECUTILS::Current State = %d\n",__LINE__,pComponentPrivate->curState);
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->numBuffers = %lu\n",
+                OMX_PRSTATE2(pComponentPrivate->dbg,
+                             "%d: AACDECUTILS::Current State = %d\n",
+                             __LINE__,
+                             pComponentPrivate->curState);
+                OMX_PRBUFFER2(pComponentPrivate->dbg,
+                              "pComponentPrivate->pInputBufferList->numBuffers = %lu\n",
                               pComponentPrivate->pInputBufferList->numBuffers);
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pOutputBufferList->numBuffers = %lu\n",
+                OMX_PRBUFFER2(pComponentPrivate->dbg,
+                              "pComponentPrivate->pOutputBufferList->numBuffers = %lu\n",
                               pComponentPrivate->pOutputBufferList->numBuffers);
 
                 if (pComponentPrivate->pInputBufferList->numBuffers || pComponentPrivate->pOutputBufferList->numBuffers) {
@@ -1269,6 +1280,14 @@
                     OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error pausing codec\n",__LINE__);
                     goto EXIT;
                 }
+#ifdef RESOURCE_MANAGER_ENABLED
+                    rm_error = RMProxy_NewSendCommand(pHandle, 
+                                                      RMProxy_StateSet, 
+                                                      OMX_AAC_Decoder_COMPONENT, 
+                                                      OMX_StateWaitForResources, 
+                                                      3456,
+                                                      NULL);
+#endif
                 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Component: Codec Is Paused\n",__LINE__);
                 break;
 
@@ -1363,7 +1382,6 @@
                 pComponentPrivate->pPortDef[INPUT_PORT_AACDEC]->bEnabled = OMX_FALSE;
             }
             if(commandData == 0x1 || commandData == -1){
-                char *pArgs = "damedesuStr";
                 pComponentPrivate->pPortDef[OUTPUT_PORT_AACDEC]->bEnabled = OMX_FALSE;
             }
         }
@@ -1512,6 +1530,17 @@
                                                           (OMX_U8 *) pLcmlHdr->pIpParam,
                                                           sizeof(AACDEC_UAlgInBufParamStruct),
                                                           NULL);
+                                if(eError != OMX_ErrorNone) {
+                                    OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in LCML QueueBuffer for input\n");
+                                    pComponentPrivate->curState = OMX_StateInvalid;
+                                    pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                    pHandle->pApplicationPrivate,
+                                                                    OMX_EventError,
+                                                                    eError,
+                                                                    OMX_TI_ErrorSevere,
+                                                                    NULL);
+                                    goto EXIT;
+                                }
                         }
                 }
                 pComponentPrivate->nNumInputBufPending = 0;
@@ -1564,6 +1593,17 @@
                                                       (OMX_U8 *) pLcmlHdr->pOpParam,
                                                       sizeof(AACDEC_UAlgOutBufParamStruct),
                                                       NULL);
+                                if(eError != OMX_ErrorNone) {
+                                    OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in LCML QueueBuffer for input\n");
+                                    pComponentPrivate->curState = OMX_StateInvalid;
+                                    pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                    pHandle->pApplicationPrivate,
+                                                                    OMX_EventError,
+                                                                    eError,
+                                                                    OMX_TI_ErrorSevere,
+                                                                    NULL);
+                                    goto EXIT;
+                                }
                         }
                     }
                     pComponentPrivate->nNumOutputBufPending = 0;    
@@ -1626,6 +1666,17 @@
                                                           (OMX_U8 *) pLcmlHdr->pIpParam,
                                                           sizeof(AACDEC_UAlgInBufParamStruct),
                                                           NULL);
+                             if(eError != OMX_ErrorNone) {
+                                OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in LCML QueueBuffer for input\n");
+                                pComponentPrivate->curState = OMX_StateInvalid;
+                                pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                eError,
+                                                                OMX_TI_ErrorSevere,
+                                                                NULL);
+                                goto EXIT;
+                            }
                          }
                      }
                      pComponentPrivate->nNumInputBufPending = 0;
@@ -1646,6 +1697,17 @@
                                                       (OMX_U8 *) pLcmlHdr->pOpParam,
                                                       sizeof(AACDEC_UAlgOutBufParamStruct),
                                                       NULL);
+                             if(eError != OMX_ErrorNone) {
+                                OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in LCML QueueBuffer for input\n");
+                                pComponentPrivate->curState = OMX_StateInvalid;
+                                pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                eError,
+                                                                OMX_TI_ErrorSevere,
+                                                                NULL);
+                                goto EXIT;
+                            }
                          }
                      }
                      pComponentPrivate->nNumOutputBufPending = 0;
@@ -1668,7 +1730,8 @@
     }
     else if (command == OMX_CommandFlush) {
         if(commandData == 0x0 || commandData == -1) {
-            if (pComponentPrivate->nUnhandledEmptyThisBuffers == 0)  {
+            OMX_ERROR2(pComponentPrivate->dbg, "Flushing input port:: unhandled ETB's = %ld, handled ETB's = %ld\n", pComponentPrivate->nUnhandledEmptyThisBuffers, pComponentPrivate->nHandledEmptyThisBuffers);
+            if (pComponentPrivate->nUnhandledEmptyThisBuffers == pComponentPrivate->nHandledEmptyThisBuffers) {
                 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
                 pComponentPrivate->first_buff = 0;
                     OMX_PRCOMM2(pComponentPrivate->dbg, "about to be Flushing input port\n");
@@ -1705,8 +1768,8 @@
                         pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pComponentPrivate->pInputBufHdrPending[i]);
-                        pComponentPrivate->nEmptyBufferDoneCount++;
                         pComponentPrivate->pInputBufHdrPending[i] = NULL;
+                        pComponentPrivate->nEmptyBufferDoneCount++;
                         SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                     pComponentPrivate->nNumInputBufPending=0;    
@@ -1722,14 +1785,17 @@
             }
         }
         if(commandData == 0x1 || commandData == -1){
-            if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
+            OMX_ERROR2(pComponentPrivate->dbg, "Flushing output port:: unhandled FTB's = %ld, handled FTB's = %ld\n", pComponentPrivate->nUnhandledFillThisBuffers, pComponentPrivate->nHandledFillThisBuffers);
+            if (pComponentPrivate->nUnhandledFillThisBuffers == pComponentPrivate->nHandledFillThisBuffers) {
                 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
                 pComponentPrivate->first_buff = 0;
+                OMX_ERROR2(pComponentPrivate->dbg, "About to be Flushing output port\n");
                 if(pComponentPrivate->num_Op_Issued && !pComponentPrivate->reconfigOutputPort ){ //no buffers sent to DSP yet
                     aParam[0] = USN_STRMCMD_FLUSH;
                     aParam[1] = 0x1;
                     aParam[2] = 0x0;
 
+                    OMX_ERROR2(pComponentPrivate->dbg, "Flushing output port dsp\n");
                     if (pComponentPrivate->codecFlush_waitingsignal == 0){
                             pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex);
                     }
@@ -1758,10 +1824,10 @@
                                                                   pComponentPrivate->pHandle->pApplicationPrivate,
                                                                   pComponentPrivate->pOutputBufHdrPending[i]
                                                                   );
-                        pComponentPrivate->nFillBufferDoneCount++;
                         pComponentPrivate->nOutStandingFillDones--;
-                        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+                        pComponentPrivate->nFillBufferDoneCount++; 
                         SignalIfAllBuffersAreReturned(pComponentPrivate);
+                        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
                     }
                     pComponentPrivate->nNumOutputBufPending=0;
 
@@ -1780,6 +1846,7 @@
         }
     }
  EXIT:
+    /* @NOTE: EXIT_COMPONENT_THRD is not REALLY an error, but a signal to ComponentThread.c */
     return eError;
 }
 
@@ -1797,19 +1864,26 @@
     OMX_U32 externsionSamplingFrequencyIdx = 0;
 
     iObjectType = AACDEC_GetBits(&nBitPosition, 5, pHeaderStream, OMX_TRUE);
-    if(iObjectType == OBJECTTYPE_LC){
-        pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectLC;
+
+    switch(iObjectType){
+        case OBJECTTYPE_HE:
+            pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectHE;
+            break;
+        case OBJECTTYPE_HE2:
+            pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectHE_PS;
+            break;
+        case OBJECTTYPE_LTP:
+            pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectLTP;
+            break;
+        case OBJECTTYPE_LC:
+        default:
+            pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectLC;
+            break;
     }
-    else if (iObjectType == OBJECTTYPE_HE){
-        pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectHE;
-    }
-    else if (iObjectType == OBJECTTYPE_HE2){
-        pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectHE_PS;
-    }
+
                     
     iSampleRateIndex = AACDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE);
     pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx = iSampleRateIndex;
-    pComponentPrivate->nProfile = pComponentPrivate->aacParams->eAACProfile;
 
     if(pComponentPrivate->pcmParams->nSamplingRate != AACDec_GetSampleRatebyIndex(iSampleRateIndex)){
         // output port needs reconfig. set the new values and mark the flag to do reconfig below.
@@ -1829,9 +1903,6 @@
 
     if (iObjectType == OBJECTTYPE_HE){
         externsionSamplingFrequencyIdx = AACDEC_GetBits(&nBitPosition, 4, pHeaderStream, OMX_TRUE);
-        /*pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx = externsionSamplingFrequencyIdx;*/
-        /*pComponentPrivate->pcmParams->nSamplingRate = 
-            AACDec_GetSampleRatebyIndex(externsionSamplingFrequencyIdx);*/
     }else {
         syncExtensionType = AACDEC_GetBits(&nBitPosition, 3, pHeaderStream, OMX_TRUE);
         syncExtensionType = AACDEC_GetBits(&nBitPosition, 11, pHeaderStream, OMX_TRUE);
@@ -1869,6 +1940,8 @@
                                                pBufHeader);
     pComponentPrivate->nEmptyBufferDoneCount++;
     SignalIfAllBuffersAreReturned(pComponentPrivate);
+
+
     return 0;
 
 }
@@ -1916,27 +1989,17 @@
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: The pBufHeader is not found in the list\n",__LINE__);
         goto EXIT;
     }
-    if (pComponentPrivate->curState == OMX_StateIdle){
-	if (eDir == OMX_DirInput) {
-		pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
-			pComponentPrivate->pHandle->pApplicationPrivate,
-			pBufHeader);
-                pComponentPrivate->nEmptyBufferDoneCount++;
-                SignalIfAllBuffersAreReturned(pComponentPrivate);
-		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);
-                pComponentPrivate->nFillBufferDoneCount++;
-                SignalIfAllBuffersAreReturned(pComponentPrivate);
-		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);
+            pComponentPrivate->nEmptyBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return input buffers\n", __LINE__, __FUNCTION__);
+            goto EXIT;
+        }
         LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
         AACD_LCML_BUFHEADERTYPE *pLcmlHdr;
         pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
@@ -1995,8 +2058,8 @@
                 
                 
 #ifdef ANDROID
-                if (pComponentPrivate->bConfigData){
-
+                if (pBufHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG ){
+                    pComponentPrivate->bConfigData = 1;
                     AACDEC_ParseHeader(pBufHeader,pComponentPrivate);
 
                     // if port config is needed send the event to the client
@@ -2048,27 +2111,21 @@
 
                 switch(pComponentPrivate->aacParams->eAACProfile){
                     case OMX_AUDIO_AACObjectLTP:
-                        pComponentPrivate->nProfile = EProfileLTP;
-                        pComponentPrivate->AACDEC_UALGParam->nProfile = EProfileLTP;
                         pComponentPrivate->AACDEC_UALGParam->iEnablePS =  0;
-                        pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 0;
+                        pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
                         break;
                     case OMX_AUDIO_AACObjectHE_PS:
-                        pComponentPrivate->AACDEC_UALGParam->nProfile = EProfileLC;
                         pComponentPrivate->AACDEC_UALGParam->iEnablePS =  1;
                         pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
                         pComponentPrivate->parameteric_stereo = PARAMETRIC_STEREO_AACDEC;
                         break;
                     case OMX_AUDIO_AACObjectHE:
-                        pComponentPrivate->AACDEC_UALGParam->nProfile = EProfileLC;
                         pComponentPrivate->AACDEC_UALGParam->iEnablePS =  1;
                         pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
 			break;
                     case OMX_AUDIO_AACObjectLC:
                     default: /* we will use LC profile as the default, SSR and Main Profiles are not supported */
                         OMX_PRDSP2(pComponentPrivate->dbg, "%s: IN Switch::ObjectLC\n", __FUNCTION__);
-                        pComponentPrivate->nProfile = EProfileLC;
-                        pComponentPrivate->AACDEC_UALGParam->nProfile = EProfileLC;
                         pComponentPrivate->AACDEC_UALGParam->iEnablePS =  1;
 
                         // always use down sample flag on for LC content, 
@@ -2088,7 +2145,7 @@
                         pComponentPrivate->AACDEC_UALGParam->lOutputFormat    = EAUDIO_INTERLEAVED;
                     }
                     pComponentPrivate->AACDEC_UALGParam->iEnablePS        = 1;/*Added for eAAC*/
-                    pComponentPrivate->AACDEC_UALGParam->nProfile         = pComponentPrivate->aacParams->eAACProfile;
+                    pComponentPrivate->AACDEC_UALGParam->dualMonoMode     = pComponentPrivate->dualMonoMode;
                     pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx = AACDec_GetSampleRateIndexL(pComponentPrivate->aacParams->nSampleRate);
                     pComponentPrivate->AACDEC_UALGParam->bRawFormat       = 0;
                     if(pComponentPrivate->aacParams->eAACStreamFormat == OMX_AUDIO_AACStreamFormatRAW){
@@ -2104,7 +2161,7 @@
                         pComponentPrivate->AACDEC_UALGParam->lOutputFormat    = EAUDIO_INTERLEAVED;
                     }
                     pComponentPrivate->AACDEC_UALGParam->iEnablePS        = 0;
-                    pComponentPrivate->AACDEC_UALGParam->nProfile         = pComponentPrivate->nProfile;
+                    pComponentPrivate->AACDEC_UALGParam->dualMonoMode     = pComponentPrivate->dualMonoMode;
                     pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx = AACDec_GetSampleRateIndexL(pComponentPrivate->aacParams->nSampleRate);
 
 
@@ -2120,7 +2177,7 @@
 #endif
 
                 OMX_PRCOMM2(pComponentPrivate->dbg, "Sending codec config params ::: \n");
-                OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->AACDEC_UALGParam->nProfile = %ld\n", pComponentPrivate->AACDEC_UALGParam->nProfile);
+                OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->AACDEC_UALGParam->dualMonoMode = %ld\n", pComponentPrivate->AACDEC_UALGParam->dualMonoMode);
                 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx = %ld\n", pComponentPrivate->AACDEC_UALGParam->lSamplingRateIdx);
                 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->AACDEC_UALGParam->iEnablePS = %ld\n", pComponentPrivate->AACDEC_UALGParam->iEnablePS);
                 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = %ld\n", pComponentPrivate->AACDEC_UALGParam->DownSampleSbr);
@@ -2176,7 +2233,7 @@
             if(!pComponentPrivate->framemode){
 	        if(pComponentPrivate->first_buff == 0){
 		    pComponentPrivate->first_TS = pBufHeader->nTimeStamp;
-                    OMX_PRINT2(pComponentPrivate->dbg, "in ts-%ld\n",pBufHeader->nTimeStamp);
+                    OMX_PRBUFFER2(pComponentPrivate->dbg, "in ts-%ld\n",pBufHeader->nTimeStamp);
 		    pComponentPrivate->first_buff = 1;
 	        }
             }
@@ -2184,19 +2241,31 @@
                                to LCML\n", __LINE__,pBufHeader,pBufHeader->pBuffer);
             if (pComponentPrivate->curState == OMX_StateExecuting) {
                 if (!AACDEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)) {
-                    if(!pComponentPrivate->bDspStoppedWhileExecuting) {
+                    if(!(pComponentPrivate->bDspStoppedWhileExecuting || pComponentPrivate->bNoIdleOnStop)) {
                         if(!pComponentPrivate->reconfigInputPort){
-                        AACDEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__);
-                        OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling LCML_QueueBuffer Line %d\n",__LINE__);
-                        OMX_PRBUFFER2(pComponentPrivate->dbg, "input pBufHeader->nFilledLen = %ld\n\n", pBufHeader->nFilledLen);
-                        eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
-                                                  EMMCodecInputBuffer,
-                                                  pBufHeader->pBuffer,
-                                                  pBufHeader->nAllocLen,
-                                                  pBufHeader->nFilledLen,
-                                                  (OMX_U8 *) pLcmlHdr->pIpParam,
-                                                  sizeof(AACDEC_UAlgInBufParamStruct),
-                                                  NULL);
+                            AACDEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__);
+                            OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling LCML_QueueBuffer Line %d\n",__LINE__);
+                            OMX_PRBUFFER2(pComponentPrivate->dbg, "input pBufHeader->nFilledLen = %ld\n\n", pBufHeader->nFilledLen);
+                            eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
+                                                      EMMCodecInputBuffer,
+                                                      pBufHeader->pBuffer,
+                                                      pBufHeader->nAllocLen,
+                                                      pBufHeader->nFilledLen,
+                                                      (OMX_U8 *) pLcmlHdr->pIpParam,
+                                                      sizeof(AACDEC_UAlgInBufParamStruct),
+                                                      NULL);
+                            if(eError != OMX_ErrorNone) {
+                                OMX_ERROR4(pComponentPrivate->dbg, ": Error Occurred in LCML QueueBuffer for input\n");
+                                pComponentPrivate->curState = OMX_StateInvalid;
+                                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                                pComponentPrivate->pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                eError,
+                                                                OMX_TI_ErrorSevere,
+                                                                NULL);
+                                goto EXIT;
+                            }
+                        
                         }
                         else{
                            OMX_PRBUFFER4(pComponentPrivate->dbg, "DON'T queue buffers during a reconfig!!\n");
@@ -2214,12 +2283,15 @@
                                           0,
                                           PERF_ModuleHLMM);
 #endif
+                        OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s DSP is stopping, returning input buffer \n",
+                                      __LINE__, __FUNCTION__);
                         pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pBufHeader
                                                                    );
                         pComponentPrivate->nEmptyBufferDoneCount++;
                         SignalIfAllBuffersAreReturned(pComponentPrivate);
+
                     }
                     pComponentPrivate->lcml_nCntIp++;
                     pComponentPrivate->lcml_nIpBuf++;
@@ -2264,7 +2336,16 @@
             OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL);
         }
     }else if (eDir == OMX_DirOutput) {
-        pComponentPrivate->nUnhandledFillThisBuffers--;
+        pComponentPrivate->nHandledFillThisBuffers++;
+        if (pComponentPrivate->curState == OMX_StateIdle){
+            pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
+                                                      pComponentPrivate->pHandle->pApplicationPrivate,
+                                                      pBufHeader);
+            pComponentPrivate->nFillBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return output buffers\n", __LINE__, __FUNCTION__);
+            goto EXIT;
+        }
         LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
         AACD_LCML_BUFHEADERTYPE *pLcmlHdr;
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d : pComponentPrivate->lcml_nOpBuf = %ld\n",__LINE__,pComponentPrivate->lcml_nOpBuf);
@@ -2293,10 +2374,10 @@
 
                     if (!AACDEC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput) &&
                         (pComponentPrivate->numPendingBuffers < pComponentPrivate->pOutputBufferList->numBuffers))  {
-                        if (!pComponentPrivate->bDspStoppedWhileExecuting){
+                        if (!(pComponentPrivate->bDspStoppedWhileExecuting || pComponentPrivate->bNoIdleOnStop)){
                             if(!pComponentPrivate->reconfigOutputPort){
-                                    AACDEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
-                                    eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
+                                AACDEC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
+                                eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
                                                       EMMCodecOuputBuffer,
                                                       pBufHeader->pBuffer,
                                                       pBufHeader->nAllocLen,
@@ -2307,6 +2388,12 @@
                                 if (eError != OMX_ErrorNone ) {
                                     OMX_ERROR4(pComponentPrivate->dbg, "%d :: Comp:: SetBuff OP: Error Occurred\n", __LINE__);
                                     eError = OMX_ErrorHardware;
+                                    pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                                pComponentPrivate->pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                eError,
+                                                                OMX_TI_ErrorSevere,
+                                                                NULL);
                                     goto EXIT;
                                 }
 
@@ -2318,6 +2405,14 @@
                             pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
                             OMX_PRDSP2(pComponentPrivate->dbg, "Reconfig:: byPassDSP!!\n");
                         }
+                    }else{
+                        OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s DSP is stopping, returning output buffer \n",
+                                      __LINE__, __FUNCTION__);
+                        pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
+                                                                  pComponentPrivate->pHandle->pApplicationPrivate,
+                                                                  pBufHeader);
+                        pComponentPrivate->nFillBufferDoneCount++;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                 }
             }
@@ -2620,7 +2715,7 @@
                 pLcmlHdr->pBufHdr->nTimeStamp = pComponentPrivate->temp_TS;
 			}
             }
-            OMX_PRINT2 (pComponentPrivate->dbg, "out ts-%lld\n",pLcmlHdr->pBufHdr->nTimeStamp);
+                        OMX_PRBUFFER2(pComponentPrivate->dbg, "outs-%lld\n",pLcmlHdr->pBufHdr->nTimeStamp);
 
   			/*Copying tick count information to output buffer*/
               pLcmlHdr->pBufHdr->nTickCount = (OMX_U32)pComponentPrivate->arrBufIndexTick[pComponentPrivate->OpBufindex];
@@ -2661,43 +2756,44 @@
 				pComponentPrivate->pHandle->pApplicationPrivate,
 				pComponentPrivate->pInputBufHdrPending[i]);
 				pComponentPrivate->pInputBufHdrPending[i] = NULL;
-                pComponentPrivate->nEmptyBufferDoneCount++;
-                SignalIfAllBuffersAreReturned(pComponentPrivate);
-	}
+            pComponentPrivate->nEmptyBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+	}		    
 	pComponentPrivate->nNumInputBufPending = 0;
 	for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
 		pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
 			pComponentPrivate->pHandle->pApplicationPrivate,
 			pComponentPrivate->pOutputBufHdrPending[i]);
-                pComponentPrivate->nFillBufferDoneCount++;
 		pComponentPrivate->nOutStandingFillDones--;
 		pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+                pComponentPrivate->nFillBufferDoneCount++;
                 SignalIfAllBuffersAreReturned(pComponentPrivate);
 	}
-	pComponentPrivate->nNumOutputBufPending=0;
+        pComponentPrivate->nNumOutputBufPending=0;
 	pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
         if(pComponentPrivate->codecStop_waitingsignal == 0){
             pComponentPrivate->codecStop_waitingsignal = 1;
             pthread_cond_signal(&pComponentPrivate->codecStop_threshold);
              OMX_PRDSP2(pComponentPrivate->dbg,"stop ack. received. stop waiting for sending disable command completed\n");
         }
-	pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
-        if (!pComponentPrivate->bNoIdleOnStop) {
+	  pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
             OMX_PRDSP2(pComponentPrivate->dbg, "setting state to idle after EMMCodecProcessingStoped event\n\n");
             pComponentPrivate->curState = OMX_StateIdle;
 
 #ifdef RESOURCE_MANAGER_ENABLED
             rm_error = RMProxy_NewSendCommand(pComponentPrivate->pHandle, RMProxy_StateSet, OMX_AAC_Decoder_COMPONENT, OMX_StateIdle, 3456, NULL);
 #endif
-            if((pComponentPrivate->nEmptyThisBufferCount != pComponentPrivate->nEmptyBufferDoneCount) || (pComponentPrivate->nFillThisBufferCount != pComponentPrivate->nFillBufferDoneCount)) {
-                if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
+
+            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)
+                if(pthread_mutex_unlock(&bufferReturned_mutex) != 0) 
                 {
                     OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex unlock error\n",__LINE__);
                 }
@@ -2706,6 +2802,7 @@
             {
                 OMX_PRINT1(pComponentPrivate->dbg, "OMX has returned all input and output buffers");
             }
+
             if (pComponentPrivate->bPreempted == 0) {
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
@@ -2723,10 +2820,7 @@
                                                        NULL);
                                 OMX_ERROR4(pComponentPrivate->dbg, "Error: pre-empted\n");
             }
-        }else {
-            pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE;
             pComponentPrivate->bNoIdleOnStop = OMX_FALSE;
-        }
     } else if(event == EMMCodecAlgCtrlAck) {
         OMX_PRDSP2(pComponentPrivate->dbg, "GOT MESSAGE USN_DSPACK_ALGCTRL \n");
     } else if (event == EMMCodecDspError) {
@@ -2734,169 +2828,43 @@
         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: arg4 = %d\n",__LINE__,(int)args[4]);
         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: arg5 = %d\n",__LINE__,(int)args[5]);
         OMX_PRDSP2(pComponentPrivate->dbg, "%d ::UTIL: EMMCodecDspError Here\n",__LINE__);
+        switch ( (OMX_U32) args [4])
+        {
+            /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
+             * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
+             * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
+             * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
+             * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
+             * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
+             * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
+             * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
+
 #ifdef _ERROR_PROPAGATION__
-        /* Cheking for MMU_fault */
-        if((args[4] == (void*)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) {
-            OMX_ERROR4(pComponentPrivate->dbg, "\n%d :: UTIL: MMU_Fault \n",__LINE__);
-            pComponentPrivate->bIsInvalidState = OMX_TRUE;
-            pComponentPrivate->curState = OMX_StateInvalid;
-            pHandle = pComponentPrivate->pHandle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorHardware, 
-                                                   OMX_TI_ErrorSevere,
-                                                   NULL);
-        }
-#endif
-        if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) {
-            OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: IUALG_WARN_PLAYCOMPLETED/USN_ERR_WARNING event received\n", __LINE__);
-#ifndef UNDER_CE
-            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                   OMX_EventBufferFlag,
-                                                   (OMX_U32)NULL,
-                                                   OMX_BUFFERFLAG_EOS,
-                                                   NULL);
-            pComponentPrivate->pLcmlBufHeader[0]->pIpParam->bLastBuffer = 0;
-#else
-            /* add callback to application to indicate SN/USN has completed playing of current set of date */
-            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                   OMX_EventBufferFlag,
-                                                   (OMX_U32)NULL,
-                                                   OMX_BUFFERFLAG_EOS,
-                                                   NULL);
-#endif
-		}
-
-        if((int)args[5] == IUALG_WARN_CONCEALED) {
-            OMX_PRDSP2(pComponentPrivate->dbg,  "Algorithm issued a warning. But can continue" );
-            OMX_PRINT2(pComponentPrivate->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);
-        }
-
-        if((int)args[5] == IUALG_ERR_GENERAL) {
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Cannot continue" );
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: arg5 = %x\n",__LINE__,(int)args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML_Callback: IUALG_ERR_GENERAL\n",__LINE__);
-            pHandle = pComponentPrivate->pHandle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError, 
-                                                   OMX_ErrorUndefined,
-                                                   OMX_TI_ErrorSevere, 
-                                                   NULL);
-        }
-
-        if( (int)args[5] == IUALG_ERR_DATA_CORRUPT ) {
-            char *pArgs = "damedesuStr";
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Corrupt data" );
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: arg5 = %x\n",__LINE__,(int)args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML_Callback: IUALG_ERR_DATA_CORRUPT\n",__LINE__);
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-#ifndef UNDER_CE
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError, 
-                                                   OMX_ErrorStreamCorrupt, 
-                                                   OMX_TI_ErrorMajor, 
-                                                   NULL);
-
-#else
-                OMX_ERROR4(pComponentPrivate->dbg, "Should stop codec first :: ERROR!\n");
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError, 
-                                                   OMX_ErrorUndefined,
-                                                   0, 
-                                                   NULL);
-#endif
-
-        }
-
-        if ( ( (int)args[4] == USN_ERR_WARNING ) && ( (int)args[5] == AACDEC_SBR_CONTENT)) {
-            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: LCML_Callback: SBR content detected \n" ,__LINE__);
-            if(pComponentPrivate->aacParams->eAACProfile != OMX_AUDIO_AACObjectHE &&
-               pComponentPrivate->aacParams->eAACProfile != OMX_AUDIO_AACObjectHE_PS){
-
-#ifndef ANDROID
-                pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectHE;
-                pComponentPrivate->AACDEC_UALGParam->nProfile = OMX_AUDIO_AACObjectHE;
-                pComponentPrivate->AACDEC_UALGParam->iEnablePS =  0;
-                pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
-
-                pValues[0] = IUALG_CMD_SETSTATUS;
-                pValues[1] = (OMX_U32)pComponentPrivate->AACDEC_UALGParam;
-                pValues[2] = sizeof(MPEG4AACDEC_UALGParams);
-
-                eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle)->pCodecinterfacehandle,
-                                           EMMCodecControlAlgCtrl,(void *)pValues);
-                if(eError != OMX_ErrorNone) {
-                    OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec StreamControl..\n",__LINE__);
+            case USN_ERR_PAUSE:
+            case USN_ERR_STOP:
+            case USN_ERR_ALGCTRL:
+            case USN_ERR_STRMCTRL:
+            case USN_ERR_UNKNOWN_MSG:
+                {
+                    pComponentPrivate->bIsInvalidState=OMX_TRUE;
                     pComponentPrivate->curState = OMX_StateInvalid;
-                    pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                           pComponentPrivate->pHandle->pApplicationPrivate,
-                                                           OMX_EventError,
-                                                           eError,
-                                                           OMX_TI_ErrorSevere,
-                                                           NULL);
-                    goto EXIT;
+                    pHandle = pComponentPrivate->pHandle;
+                    pComponentPrivate->cbInfo.EventHandler(pHandle,
+                            pHandle->pApplicationPrivate,
+                            OMX_EventError,
+                            OMX_ErrorInvalidState,
+                            OMX_TI_ErrorSevere,
+                            NULL);
                 }
-
-
+                break;
 #endif
 
-            }else{
-		AACDEC_DPRINT("%d %s-SBR reconfiguration not needed\n",__LINE__,__func__);
-	    }
-        }
-        if ( ( (int)args[4] == USN_ERR_WARNING ) && ( (int)args[5] == AACDEC_PS_CONTENT )){
-            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: LCML_Callback: PS content detected \n" ,__LINE__);
-            if(pComponentPrivate->aacParams->eAACProfile != OMX_AUDIO_AACObjectHE_PS){
-
-#ifndef ANDROID
-                pComponentPrivate->AACDEC_UALGParam->nProfile = OMX_AUDIO_AACObjectLC;
-                pComponentPrivate->AACDEC_UALGParam->lOutputFormat = EAUDIO_INTERLEAVED;
-                pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
-                pComponentPrivate->AACDEC_UALGParam->iEnablePS =  1;
-
-                pValues[0] = IUALG_CMD_SETSTATUS;
-                pValues[1] = (OMX_U32)pComponentPrivate->AACDEC_UALGParam;
-                pValues[2] = sizeof(MPEG4AACDEC_UALGParams);
-
-                eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle)->pCodecinterfacehandle,
-                                           EMMCodecControlAlgCtrl,(void *)pValues);
-                if(eError != OMX_ErrorNone) {
-                    OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec StreamControl..\n",__LINE__);
-                    pComponentPrivate->curState = OMX_StateInvalid;
-                    pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                           pComponentPrivate->pHandle->pApplicationPrivate,
-                                                           OMX_EventError,
-                                                           OMX_ErrorInvalidState,
-                                                           0,
-                                                           NULL);
-                    goto EXIT;
-                }
-#endif
-            }
-        }
-        if( (int)args[5] == IUALG_WARN_OVERFLOW ){
-            OMX_PRBUFFER2(pComponentPrivate->dbg,  "Algorithm error. Overflow" );
-        }
-        if( (int)args[5] == IUALG_WARN_UNDERFLOW ){
-            OMX_PRBUFFER2(pComponentPrivate->dbg,  "Algorithm error. Underflow" );
-        }
-        if( (int)args[4] == USN_ERR_PROCESS ){
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error Process" );
-            pHandle = pComponentPrivate->pHandle;
-
-            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorStreamCorrupt,
-                                                   OMX_TI_ErrorMajor,
-                                                   NULL);
+            case USN_ERR_WARNING:
+            case USN_ERR_PROCESS:
+                AACDEC_HandleUSNError (pComponentPrivate, (OMX_U32)args[5]);
+                break;
+            default:
+                break;
         }
     } else if (event == EMMCodecStrmCtrlAck) {
         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__);
@@ -2919,9 +2887,10 @@
                                       pComponentPrivate->pInputBufHdrPending[i]);
 
                     pComponentPrivate->nEmptyBufferDoneCount++;
+                    pComponentPrivate->pInputBufHdrPending[i] = NULL;
                     SignalIfAllBuffersAreReturned(pComponentPrivate);
-	            pComponentPrivate->pInputBufHdrPending[i] = NULL;
-                    }
+                   
+					}
                     pComponentPrivate->nNumInputBufPending=0;
                     
                     pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex);
@@ -2945,32 +2914,32 @@
             }
             else if ( args[2] == (void *)EMMCodecOuputBuffer) {
                 if (args[0] == (void *)USN_ERR_NONE ) {
-				    OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing output port in lcml_callback %d\n",__LINE__);
-						for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
+                    OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing output port in lcml_callback %d\n",__LINE__);
+                    for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
 #ifdef __PERF_INSTRUMENTATION__
-							PERF_SendingFrame(pComponentPrivate->pPERFcomp,
+                        PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                           PREF(pComponentPrivate->pOutputBufHdrPending[i],pBuffer),
                                           PREF(pComponentPrivate->pOutputBufHdrPending[i],nFilledLen),
                                           PERF_ModuleHLMM);
 #endif
 
-							pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
+                        pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
                                                                   pComponentPrivate->pHandle->pApplicationPrivate,
                                                                   pComponentPrivate->pOutputBufHdrPending[i]
                                                                   );
-							pComponentPrivate->nOutStandingFillDones--;
-                                                        pComponentPrivate->nFillBufferDoneCount++;
-							pComponentPrivate->pOutputBufHdrPending[i] = NULL;
-                                                        SignalIfAllBuffersAreReturned(pComponentPrivate);
-						}
+                        pComponentPrivate->nOutStandingFillDones--;
+                        pComponentPrivate->nFillBufferDoneCount++;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
+                        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+                    }
                     pComponentPrivate->nNumOutputBufPending=0;
 
                     pthread_mutex_lock(&pComponentPrivate->codecFlush_mutex);
                     if(pComponentPrivate->codecFlush_waitingsignal == 0){
-                        pComponentPrivate->codecFlush_waitingsignal = 1; 
+                        pComponentPrivate->codecFlush_waitingsignal = 1;
                         pthread_cond_signal(&pComponentPrivate->codecFlush_threshold);
-                        OMX_ERROR4(pComponentPrivate->dbg, "flush ack. received. for output port\n");
-                    }     
+                        OMX_PRCOMM2(pComponentPrivate->dbg, "flush ack. received. for output port\n");
+                    }
                     pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex);
                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                            pComponentPrivate->pHandle->pApplicationPrivate,
@@ -2986,8 +2955,6 @@
             }
         }
     }else if (event == EMMCodecProcessingPaused) {
-        pComponentPrivate->nUnhandledFillThisBuffers = 0;
-        pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
         pComponentPrivate->curState = OMX_StatePause;
         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, pComponentPrivate->pHandle->pApplicationPrivate,
                                                OMX_EventCmdComplete, OMX_CommandStateSet,
@@ -3222,63 +3189,42 @@
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     AACDEC_COMPONENT_PRIVATE *pComponentPrivate = (AACDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     AACD_LCML_BUFHEADERTYPE *pTemp_lcml;
-    char *pTemp = NULL;
     OMX_U32 nIpBuf = 0;
     OMX_U32 nOpBuf = 0;
     OMX_U32 i=0;
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Freeing:  pComponentPrivate->strmAttr = %p\n",
                     __LINE__, pComponentPrivate->strmAttr);
-    AACDEC_OMX_FREE(pComponentPrivate->strmAttr);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
 
     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC];
     for(i=0; i<nIpBuf; i++) {
         OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pTemp_lcml->pIpParam = %p\n",pTemp_lcml->pIpParam);
-        pTemp = (char*)pTemp_lcml->pIpParam;
-        if (pTemp != NULL) {
-            pTemp -= EXTRA_BYTES;
-        }
-        pTemp_lcml->pIpParam = (AACDEC_UAlgInBufParamStruct*)pTemp;
-        AACDEC_OMX_FREE(pTemp_lcml->pIpParam);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, AACDEC_UAlgInBufParamStruct);
         pTemp_lcml++;
     }
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC] = %p\n",
                     pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC]);
-    AACDEC_OMX_FREE(pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC]);
 
     nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
     pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC] = NULL;
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC];
     for(i=0; i<nOpBuf; i++) {
         OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pTemp_lcml->pOpParam = %p\n",pTemp_lcml->pOpParam);
-        pTemp = (char*)pTemp_lcml->pOpParam;
-        if (pTemp != NULL) {
-            pTemp -= EXTRA_BYTES;
-        }
-        pTemp_lcml->pOpParam = (AACDEC_UAlgOutBufParamStruct*)pTemp;
-        AACDEC_OMX_FREE(pTemp_lcml->pOpParam);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, AACDEC_UAlgOutBufParamStruct);
         pTemp_lcml++;
     }
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC] = %p\n",
                     pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC]);
-    AACDEC_OMX_FREE(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC]);
 
-    pTemp = (char*)pComponentPrivate->pParams;
-    if (pTemp != NULL) {
-        pTemp -= EXTRA_BYTES;
-    }
-    pComponentPrivate->pParams = (USN_AudioCodecParams*)pTemp;
-    AACDEC_OMX_FREE(pComponentPrivate->pParams);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, USN_AudioCodecParams);
 
-    pTemp = (char*)pComponentPrivate->AACDEC_UALGParam;
-    if (pTemp != NULL) {
-        pTemp -= EXTRA_BYTES;
-    }
-    pComponentPrivate->AACDEC_UALGParam = (MPEG4AACDEC_UALGParams*)pTemp;
-    AACDEC_OMX_FREE(pComponentPrivate->AACDEC_UALGParam);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->AACDEC_UALGParam, MPEG4AACDEC_UALGParams);
 }
 /* ========================================================================== */
 /**
@@ -3301,7 +3247,6 @@
     AACDEC_COMPONENT_PRIVATE *pComponentPrivate =
         (AACDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     AACD_LCML_BUFHEADERTYPE *pTemp_lcml;
-    char *pTemp = NULL;
     OMX_U32 nIpBuf = 0;
     OMX_U32 nOpBuf = 0;
     OMX_U32 i=0;
@@ -3312,18 +3257,13 @@
         for(i=0; i<nIpBuf; i++) {
             OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pIpParam = %p\n",
                           pTemp_lcml->pIpParam);
-            pTemp = (char*)pTemp_lcml->pIpParam;
-            if (pTemp != NULL) {
-                pTemp -= EXTRA_BYTES;
-            }
-            pTemp_lcml->pIpParam = (AACDEC_UAlgInBufParamStruct*)pTemp;
-            AACDEC_OMX_FREE(pTemp_lcml->pIpParam);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, AACDEC_UAlgInBufParamStruct);
             pTemp_lcml++;
         }
 
         OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing pLcmlBufHeader[INPUT_PORT_AACDEC] = %p\n",
                       pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC]);
-        AACDEC_OMX_FREE(pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC]);
 
     }else if(indexport == 1 || indexport == -1){
         nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
@@ -3331,18 +3271,13 @@
         for(i=0; i<nOpBuf; i++) {
             OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pOpParam = %p\n",
                           pTemp_lcml->pOpParam);
-            pTemp = (char*)pTemp_lcml->pOpParam;
-            if (pTemp != NULL) {
-                pTemp -= EXTRA_BYTES;
-            }
-            pTemp_lcml->pOpParam = (AACDEC_UAlgOutBufParamStruct*)pTemp;
-            AACDEC_OMX_FREE(pTemp_lcml->pOpParam);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, AACDEC_UAlgOutBufParamStruct);
             pTemp_lcml++;
         }
 
         OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pLcmlBufHeader[OUTPUT_PORT_AACDEC] = %p\n",
                       pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC]);
-        AACDEC_OMX_FREE(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC]);
 
     }else{
         OMX_ERROR4(pComponentPrivate->dbg, "Bad indexport!\n");
@@ -3455,7 +3390,7 @@
         sample_rate = 8000;
         break;
     default:
-        OMXDBG_PRINT(stderr, PRINT, 2, 0, "Invalid index: %d\n", index);
+        OMXDBG_PRINT(stderr, PRINT, 2, 0, "Invalid index\n");
         break;
     }
 
@@ -3671,7 +3606,7 @@
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: bufAlloced = %lu\n",__LINE__,pComponentPrivate->bufAlloced);
         size_lcml = nIpBuf * sizeof(AACD_LCML_BUFHEADERTYPE);
 
-        AACDEC_OMX_MALLOC_SIZE(ptr,size_lcml,char);
+        OMX_MALLOC_SIZE(ptr,size_lcml,char);
         pTemp_lcml = (AACD_LCML_BUFHEADERTYPE *)ptr;
 
         pComponentPrivate->pLcmlBufHeader[INPUT_PORT_AACDEC] = pTemp_lcml;
@@ -3694,12 +3629,9 @@
             pTemp_lcml->eDir = OMX_DirInput;
             pTemp_lcml->pOtherParams[i] = NULL;
 
-            AACDEC_OMX_MALLOC_SIZE(pTemp_lcml->pIpParam,
-                                   (sizeof(AACDEC_UAlgInBufParamStruct) + DSP_CACHE_ALIGNMENT),
+            OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
+                                   sizeof(AACDEC_UAlgInBufParamStruct),
                                    AACDEC_UAlgInBufParamStruct);
-            ptr = (char*)pTemp_lcml->pIpParam;
-            ptr += EXTRA_BYTES;
-            pTemp_lcml->pIpParam = (AACDEC_UAlgInBufParamStruct*)ptr;
 
             pTemp_lcml->pIpParam->bLastBuffer = 0;
 
@@ -3717,7 +3649,7 @@
     if(indexport == 1 || indexport == -1){
 
         size_lcml = nOpBuf * sizeof(AACD_LCML_BUFHEADERTYPE);
-        AACDEC_OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,AACD_LCML_BUFHEADERTYPE);
+        OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,AACD_LCML_BUFHEADERTYPE);
         pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT_AACDEC] = pTemp_lcml;
 
         for (i=0; i<nOpBuf; i++) {
@@ -3738,16 +3670,13 @@
             pTemp_lcml->eDir = OMX_DirOutput;
             pTemp_lcml->pOtherParams[i] = NULL;
 
-            AACDEC_OMX_MALLOC_SIZE(pTemp_lcml->pOpParam,
-                                   (sizeof(AACDEC_UAlgOutBufParamStruct) + DSP_CACHE_ALIGNMENT),
+            OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam,
+                                   sizeof(AACDEC_UAlgOutBufParamStruct),
                                    AACDEC_UAlgOutBufParamStruct);
-            ptr = (char*)pTemp_lcml->pOpParam;
-            ptr += EXTRA_BYTES;
-            pTemp_lcml->pOpParam = (AACDEC_UAlgOutBufParamStruct*)ptr;
 
             pTemp_lcml->pOpParam->ulFrameCount = DONT_CARE;
-	    pTemp_lcml->pOpParam->isLastBuffer = 0;
-
+            pTemp_lcml->pOpParam->isLastBuffer = 0;
+			
             pTemp->nFlags = NORMAL_BUFFER_AACDEC;
             ((AACDEC_COMPONENT_PRIVATE *)pTemp->pPlatformPrivate)->pHandle = pHandle;
             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d ::Comp:  >>>>>>>>>>>>> OutBuffHeader[%d] = %p\n",
@@ -3770,75 +3699,6 @@
     return eError;
 }
 
-#ifdef AACDEC_DEBUGMEM
-/* ========================================================================== */
-/**
-* @mymalloc() This function is used to debug memory leaks
-*
-* @param
-*
-* @pre None
-*
-* @post None
-*
-* @return None
-*/
-/* ========================================================================== */
-void * mymalloc(int line, char *s, int size)
-{
-    void *p;
-    int e=0;
-
-    p = malloc(size);
-    if(p==NULL){
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
-    }
-    else{
-        while((lines[e]!=0)&& (e<500) ){
-            e++;
-        }
-        arr[e]=p;
-        lines[e]=line;
-        bytes[e]=size;
-        strcpy(file[e],s);
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
-   }
-    return p;
-
-}
-
- /* ========================================================================== */
-/**
-* @myfree() This function is used to debug memory leaks
-*
-* @param
-*
-* @pre None
-*
-* @post None
-*
-* @return None
-*/
-/* ========================================================================== */
-int myfree(void *dp, int line, char *s)
-{
-    int q;
-    for(q=0;q<500;q++){
-        if(arr[q]==dp){
-            OMXDBG_PRINT(stderr, ERROR, 4, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
-            free(dp);
-            dp = NULL;
-            lines[q]=0;
-            strcpy(file[q],"");
-            break;
-        }
-    }
-    if(500==q)
-        OMXDBG_PRINT(stderr, PRINT, 2, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
-}
-#endif
-
-
 /*  =========================================================================*/
 /*  func    GetBits                                                          */
 /*                                                                           */
@@ -3876,7 +3736,161 @@
     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(AACDEC_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_PRINT1(pComponentPrivate->dbg, "Sending pthread signal that OMX has returned all buffers to app");
+        if(pthread_mutex_unlock(&bufferReturned_mutex) != 0) 
+        {
+            OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex unlock error\n",__LINE__);
+        }
+        return;
+    }
+}
+
+void AACDEC_HandleUSNError (AACDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
+{
+    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U8 pending_buffers = OMX_FALSE;
+    OMX_U32 i;
+    switch (arg)
+    {
+        case AACDEC_SBR_CONTENT:
+#ifndef ANDROID
+            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: LCML_Callback: SBR content detected \n" ,__LINE__);
+            if(pComponentPrivate->aacParams->eAACProfile != OMX_AUDIO_AACObjectHE &&
+               pComponentPrivate->aacParams->eAACProfile != OMX_AUDIO_AACObjectHE_PS){
+                pComponentPrivate->aacParams->eAACProfile = OMX_AUDIO_AACObjectHE;
+                pComponentPrivate->AACDEC_UALGParam->iEnablePS =  0;
+                pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
+
+                pValues[0] = IUALG_CMD_SETSTATUS;
+                pValues[1] = (OMX_U32)pComponentPrivate->AACDEC_UALGParam;
+                pValues[2] = sizeof(MPEG4AACDEC_UALGParams);
+
+                eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle)->pCodecinterfacehandle,
+                                           EMMCodecControlAlgCtrl,(void *)pValues);
+                if(eError != OMX_ErrorNone) {
+                    OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec StreamControl..\n",__LINE__);
+                    pComponentPrivate->curState = OMX_StateInvalid;
+                    pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                           pComponentPrivate->pHandle->pApplicationPrivate,
+                                                           OMX_EventError,
+                                                           eError,
+                                                           OMX_TI_ErrorSevere,
+                                                           NULL);
+                }
+#endif
+                break;
+        case AACDEC_PS_CONTENT:
+#ifndef ANDROID
+            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: LCML_Callback: PS content detected \n" ,__LINE__);
+            if(pComponentPrivate->aacParams->eAACProfile != OMX_AUDIO_AACObjectHE_PS){
+                pComponentPrivate->AACDEC_UALGParam->lOutputFormat = EAUDIO_INTERLEAVED;
+                pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
+                pComponentPrivate->AACDEC_UALGParam->iEnablePS =  1;
+
+                pValues[0] = IUALG_CMD_SETSTATUS;
+                pValues[1] = (OMX_U32)pComponentPrivate->AACDEC_UALGParam;
+                pValues[2] = sizeof(MPEG4AACDEC_UALGParams);
+
+                eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pComponentPrivate->pLcmlHandle)->pCodecinterfacehandle,
+                                           EMMCodecControlAlgCtrl,(void *)pValues);
+                if(eError != OMX_ErrorNone) {
+                    OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec StreamControl..\n",__LINE__);
+                    pComponentPrivate->curState = OMX_StateInvalid;
+                    pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                           pComponentPrivate->pHandle->pApplicationPrivate,
+                                                           OMX_EventError,
+                                                           OMX_ErrorInvalidState,
+                                                           0,
+                                                           NULL);
+                }
+            }
+#endif
+            break;
+        case IUALG_WARN_CONCEALED:
+        case IUALG_WARN_UNDERFLOW:
+        case IUALG_WARN_OVERFLOW:
+        case IUALG_WARN_ENDOFDATA:
+            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error" );
+            /* all of these are informative messages, Algo can recover, no need to notify the
+             * IL Client at this stage of the implementation */
+            break;
+        case IUALG_WARN_PLAYCOMPLETED:
+
+            {
+                OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: IUALG_WARN_PLAYCOMPLETED/USN_ERR_WARNING event received\n", __LINE__);
+#ifndef UNDER_CE
+                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       OMX_EventBufferFlag,
+                                                       (OMX_U32)NULL,
+                                                       OMX_BUFFERFLAG_EOS,
+                                                       NULL);
+                pComponentPrivate->pLcmlBufHeader[0]->pIpParam->bLastBuffer = 0;
+#else
+                /* add callback to application to indicate SN/USN has completed playing of current set of date */
+                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       OMX_EventBufferFlag,
+                                                       (OMX_U32)NULL,
+                                                       OMX_BUFFERFLAG_EOS,
+                                                       NULL);
+#endif
+            }
+            break;
+
+#ifdef _ERROR_PROPAGATION__
+        case IUALG_ERR_BAD_HANDLE:
+        case IUALG_ERR_DATA_CORRUPT:
+        case IUALG_ERR_NOT_SUPPORTED:
+        case IUALG_ERR_ARGUMENT:
+        case IUALG_ERR_NOT_READY:
+        case IUALG_ERR_GENERAL:
+
+            {
+                /* all of these are fatal messages, Algo can not recover
+                 * hence return an error */
+                OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error, cannot recover" );
+                pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                pComponentPrivate->curState = OMX_StateInvalid;
+                pHandle = pComponentPrivate->pHandle;
+                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                        pHandle->pApplicationPrivate,
+                        OMX_EventError,
+                        OMX_ErrorInvalidState,
+                        OMX_TI_ErrorSevere,
+                        NULL);
+            }
+            break;
+#endif
+        default:
+            break;
+    }
+}
+
+#ifdef RESOURCE_MANAGER_ENABLED
 void AACDEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
 {
     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
@@ -3895,42 +3909,10 @@
         }
     }
     else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
-        pCompPrivate->cbInfo.EventHandler (
-	                        pHandle, pHandle->pApplicationPrivate,
-	                        OMX_EventResourcesAcquired, 0,0,
-	                        NULL);
+        pCompPrivate->cbInfo.EventHandler (pHandle,
+                                           pHandle->pApplicationPrivate,
+                                           OMX_EventResourcesAcquired, 0,0,
+                                           NULL);
     }
 }
-*/
-
- /* ========================================================================== */
-/**
-* @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(AACDEC_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_PRINT1(pComponentPrivate->dbg, "Sending pthread signal that OMX has returned all buffers to app");
-        if(pthread_mutex_unlock(&bufferReturned_mutex) != 0)
-        {
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex unlock error\n",__LINE__);
-        }
-        return;
-    }
-}
-
+#endif
diff --git a/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDecoder.c b/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDecoder.c
index 67fd065..19171b3 100755
--- a/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDecoder.c
+++ b/omx/audio/src/openmax_il/aac_dec/src/OMX_AacDecoder.c
@@ -36,6 +36,13 @@
 * @rev  1.0
 */
 /* ----------------------------------------------------------------------------
+*!
+*! Revision History
+*! ===================================
+*! 13-Dec-2005 mf:  Initial Version. Change required per OMAPSWxxxxxxxxx
+*! to provide _________________.
+*!
+* ============================================================================= */
 
 /* ------compilation control switches -------------------------*/
 /****************************************************************
@@ -67,20 +74,20 @@
 #include <dbapi.h>
 
 /*------- Program Header Files -----------------------------------------------*/
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 
 #include "LCML_DspCodec.h"
 #include "OMX_AacDec_Utils.h"
 #include <TIDspOmx.h>
 
-#ifdef DSP_RENDERING_ON
-#include <AudioManagerAPI.h>
-#endif
 #ifdef RESOURCE_MANAGER_ENABLED
 #include <ResourceManagerProxyAPI.h>
 #endif
 
 #ifdef DSP_RENDERING_ON
-
+#include <AudioManagerAPI.h>
 #define FIFO1 "/dev/fifo.1"
 #define FIFO2 "/dev/fifo.2"
 #define PERMS 0666
@@ -114,9 +121,6 @@
 
 /*--------function prototypes ---------------------------------*/
 
-extern void * mymalloc(int line, char *s, int size);
-extern int myfree(void *dp, int line, char *s);
-
 static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp,
                                    OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData);
 static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
@@ -225,7 +229,7 @@
     pHandle->UseBuffer = UseBuffer;
     pHandle->ComponentRoleEnum = ComponentRoleEnum;
 
-    AACD_OMX_MALLOC(pHandle->pComponentPrivate,AACDEC_COMPONENT_PRIVATE);
+    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate,AACDEC_COMPONENT_PRIVATE);
 
     pComponentPrivate = pHandle->pComponentPrivate;
     pComponentPrivate->pHandle = pHandle;
@@ -244,20 +248,20 @@
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE; 
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; 
-    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE;
-    pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_FALSE;
+    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE; 
+    pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_FALSE; 
 #endif
 
 
-    AACD_OMX_MALLOC(pCompPort, AUDIODEC_PORT_TYPE);
+    OMX_MALLOC_GENERIC(pCompPort, AUDIODEC_PORT_TYPE);
     pComponentPrivate->pCompPort[INPUT_PORT_AACDEC] =  pCompPort;
 
-    AACD_OMX_MALLOC(pCompPort, AUDIODEC_PORT_TYPE);
+    OMX_MALLOC_GENERIC(pCompPort, AUDIODEC_PORT_TYPE);
     pComponentPrivate->pCompPort[OUTPUT_PORT_AACDEC] = pCompPort;
-    AACD_OMX_MALLOC(pTemp, AACDEC_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pTemp, AACDEC_BUFFERLIST);
     pComponentPrivate->pInputBufferList = pTemp;
 
-    AACD_OMX_MALLOC(pTemp, AACDEC_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pTemp, AACDEC_BUFFERLIST);
     pComponentPrivate->pOutputBufferList = pTemp;
 
     pComponentPrivate->pInputBufferList->numBuffers = 0;
@@ -270,17 +274,17 @@
 
     pComponentPrivate->bufAlloced = 0;
 
-    AACD_OMX_MALLOC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
     OMX_CONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
-    AACD_OMX_MALLOC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
     pComponentPrivate->sPortParam->nPorts = NUM_OF_PORTS_AACDEC;
     pComponentPrivate->sPortParam->nStartPortNumber = 0x0;
 
     pComponentPrivate->aacParams = NULL;
     pComponentPrivate->pcmParams = NULL;
-    AACD_OMX_MALLOC(aac_ip,OMX_AUDIO_PARAM_AACPROFILETYPE);
-    AACD_OMX_MALLOC(aac_op,OMX_AUDIO_PARAM_PCMMODETYPE);
+    OMX_MALLOC_GENERIC(aac_ip,OMX_AUDIO_PARAM_AACPROFILETYPE);
+    OMX_MALLOC_GENERIC(aac_op,OMX_AUDIO_PARAM_PCMMODETYPE);
     pComponentPrivate->aacParams = aac_ip;
     pComponentPrivate->pcmParams = aac_op;
 
@@ -299,8 +303,10 @@
     pComponentPrivate->strmAttr = NULL;
     pComponentPrivate->bDisableCommandParam = 0;
     pComponentPrivate->bEnableCommandParam = 0;
-    pComponentPrivate->nUnhandledFillThisBuffers=0;
+    pComponentPrivate->nUnhandledFillThisBuffers = 0;
+    pComponentPrivate->nHandledFillThisBuffers = 0;
     pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
+    pComponentPrivate->nHandledEmptyThisBuffers = 0;
     pComponentPrivate->SendAfterEOS = 1;    
     pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
     pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
@@ -337,20 +343,20 @@
     pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
     pComponentPrivate->nOutStandingFillDones = 0;
     pComponentPrivate->nOpBit = 0;
-    pComponentPrivate->nProfile = EProfileLC;
+    pComponentPrivate->dualMonoMode = 0;
     pComponentPrivate->bIsInvalidState = OMX_FALSE;
     pComponentPrivate->sOutPortFormat.eEncoding = OMX_AUDIO_CodingPCM;
 
     /* Initialize device string to the default value */
-    AACDEC_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString,(100*sizeof(OMX_STRING)),OMX_STRING);
+    OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString,(100*sizeof(OMX_STRING)),OMX_STRING);
     strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
     
     /* initialize role name */
-    AACD_OMX_MALLOC(pComponentPrivate->componentRole,OMX_PARAM_COMPONENTROLETYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->componentRole,OMX_PARAM_COMPONENTROLETYPE);
     strcpy((char*)pComponentPrivate->componentRole->cRole, AAC_DEC_ROLE);
 
-    AACD_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
-    AACD_OMX_MALLOC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
 
     pComponentPrivate->pPortDef[INPUT_PORT_AACDEC] = pPortDef_ip;
     pComponentPrivate->pPortDef[OUTPUT_PORT_AACDEC] = pPortDef_op;
@@ -394,7 +400,7 @@
     pPortDef_ip->nBufferCountActual                 = AACD_NUM_INPUT_BUFFERS;
     pPortDef_ip->nBufferCountMin                    = AACD_NUM_INPUT_BUFFERS;
     pPortDef_ip->nBufferSize                        = AACD_INPUT_BUFFER_SIZE;
-    pPortDef_ip->nBufferAlignment                   = EXTRA_BYTES;
+    pPortDef_ip->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
     pPortDef_ip->bEnabled                           = OMX_TRUE;
     pPortDef_ip->bPopulated                         = OMX_FALSE;
     pPortDef_ip->eDomain                            = OMX_PortDomainAudio;
@@ -410,7 +416,7 @@
     pPortDef_op->nBufferCountMin                    = AACD_NUM_OUTPUT_BUFFERS;
     pPortDef_op->nBufferCountActual                 = AACD_NUM_OUTPUT_BUFFERS;
     pPortDef_op->nBufferSize                        = AACD_OUTPUT_BUFFER_SIZE;
-    pPortDef_op->nBufferAlignment                   = EXTRA_BYTES;
+    pPortDef_op->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
     pPortDef_op->bEnabled                           = OMX_TRUE;
     pPortDef_op->bPopulated                         = OMX_FALSE;
     pPortDef_op->eDomain                            = OMX_PortDomainAudio;
@@ -419,8 +425,8 @@
     pPortDef_op->format.audio.pNativeRender         = NULL;
     pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
 
-    AACD_OMX_MALLOC(pComponentPrivate->pCompPort[INPUT_PORT_AACDEC]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
-    AACD_OMX_MALLOC(pComponentPrivate->pCompPort[OUTPUT_PORT_AACDEC]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[INPUT_PORT_AACDEC]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[OUTPUT_PORT_AACDEC]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[INPUT_PORT_AACDEC]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[OUTPUT_PORT_AACDEC]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
 
@@ -499,11 +505,11 @@
  EXIT:
     if(OMX_ErrorNone != eError) {
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__);
-        AACDEC_OMX_FREE(pPortDef_ip);
-        AACDEC_OMX_FREE(pPortDef_op);
-        AACDEC_OMX_FREE(aac_ip);
-        AACDEC_OMX_FREE(aac_op);
-        AACDEC_OMX_FREE(pTemp);
+        OMX_MEMFREE_STRUCT(pPortDef_ip);
+        OMX_MEMFREE_STRUCT(pPortDef_op);
+        OMX_MEMFREE_STRUCT(aac_ip);
+        OMX_MEMFREE_STRUCT(aac_op);
+        OMX_MEMFREE_STRUCT(pTemp);
     }
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting OMX_ComponentInit\n", __LINE__);
     return eError;
@@ -660,7 +666,10 @@
 
     /* add for acoustic control */
  EXIT:
-    OMX_PRINT1(pCompPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
+    if (pCompPrivate != NULL) {
+	OMX_PRINT1(pCompPrivate->dbg, "%d :: Returning = 0x%x\n",
+				       __LINE__, eError);
+    }
     return eError;
 }
 
@@ -722,6 +731,7 @@
     switch(nParamIndex){
     case OMX_IndexParamAudioInit:
         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: SetParameter OMX_IndexParamAudioInit \n",__LINE__);
+        AACDEC_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam ,1,1)
         memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
 
@@ -784,6 +794,7 @@
             
     case OMX_IndexParamAudioPcm:
 	OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Entering OMX_IndexParamAudioPcm\n", __LINE__);
+        AACDEC_OMX_CONF_CHECK_CMD(pComponentPrivate->pcmParams ,1,1)
         memcpy(ComponentParameterStructure,pComponentPrivate->pcmParams,sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
         break;
             
@@ -807,6 +818,7 @@
 #ifdef ANDROID
 	OMX_PRINT2(pComponentPrivate->dbg, "%d :: Entering OMX_IndexParamVideoInit\n", __LINE__);
         OMX_PRINT2(pComponentPrivate->dbg, "%d :: Entering OMX_IndexParamImageInit/OtherInit\n", __LINE__);
+        AACDEC_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam ,1,1)
 	memcpy(ComponentParameterStructure,pComponentPrivate->sPortParam,sizeof(OMX_PORT_PARAM_TYPE));
         eError = OMX_ErrorNone;
 #else
@@ -817,6 +829,7 @@
 
     case OMX_IndexParamPriorityMgmt:
 	OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Entering OMX_IndexParamPriorityMgmt\n", __LINE__);
+        AACDEC_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt ,1,1)
         memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
@@ -844,7 +857,10 @@
         break;
     }
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",
+				       __LINE__, eError);
+    }
     return eError;
 }
 
@@ -977,18 +993,21 @@
     case OMX_IndexParamPriorityMgmt:
         {
             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: SetParameter OMX_IndexParamPriorityMgmt \n",__LINE__);
+            AACDEC_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt,1,1)
             memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
         }
         break;
 
     case OMX_IndexParamAudioInit:
         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: SetParameter OMX_IndexParamAudioInit \n",__LINE__);
+        AACDEC_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1,1)
         memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
 
     case OMX_IndexParamStandardComponentRole:
         if (pCompParam) {
             pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
+            AACDEC_OMX_CONF_CHECK_CMD(pComponentPrivate->componentRole, 1,1)
             memcpy(pComponentPrivate->componentRole, (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
         } else {
             eError = OMX_ErrorBadParameter;
@@ -998,6 +1017,7 @@
     case OMX_IndexParamAudioPcm:
         if(pCompParam){
             pCompPcmParam = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
+            AACDEC_OMX_CONF_CHECK_CMD(pComponentPrivate->pcmParams, 1,1)
             memcpy(pComponentPrivate->pcmParams, pCompPcmParam, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
         }
         else{
@@ -1037,7 +1057,10 @@
         break;
     }
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",
+							__LINE__, eError);
+    }
     return eError;
 }
 
@@ -1083,7 +1106,6 @@
     case OMX_IndexParamAudioAac:
         aac_params = (OMX_AUDIO_PARAM_AACPROFILETYPE*)ComponentConfigStructure;
         if(aac_params->eAACProfile == OMX_AUDIO_AACObjectHE_PS){
-            pComponentPrivate->AACDEC_UALGParam->nProfile = OMX_AUDIO_AACObjectHE_PS;
             pComponentPrivate->AACDEC_UALGParam->iEnablePS =  1;
             pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
 
@@ -1106,7 +1128,6 @@
             }
         }
         if(aac_params->eAACProfile == OMX_AUDIO_AACObjectHE){
-            pComponentPrivate->AACDEC_UALGParam->nProfile = OMX_AUDIO_AACObjectHE;
             pComponentPrivate->AACDEC_UALGParam->iEnablePS =  0;
             pComponentPrivate->AACDEC_UALGParam->DownSampleSbr = 1;
 
@@ -1186,7 +1207,10 @@
         break;
     }
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",
+							__LINE__, eError);
+    }
     return eError;
 }
 
@@ -1332,7 +1356,7 @@
     }   
 #endif
 
-    AACD_OMX_MALLOC(streamInfo,TI_OMX_STREAM_INFO);
+    OMX_MALLOC_GENERIC(streamInfo,TI_OMX_STREAM_INFO);
     
     if(nConfigIndex == OMX_IndexCustomAacDecStreamIDConfig){
         /* copy component info */
@@ -1363,7 +1387,7 @@
     else if(nConfigIndex == OMX_IndexCustomDebug) {
 	OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
     }
-    AACDEC_OMX_FREE(streamInfo);
+    OMX_MEMFREE_STRUCT(streamInfo);
 
  EXIT:
     return eError;
@@ -1496,12 +1520,15 @@
     pComponentPrivate->pMarkData = pBuffer->pMarkData;
     pComponentPrivate->hMarkTargetComponent = pBuffer->hMarkTargetComponent;
 
-    pComponentPrivate->nUnhandledEmptyThisBuffers++;
     ret = write (pComponentPrivate->dataPipe[1], &pBuffer,sizeof(OMX_BUFFERHEADERTYPE*));
     if (ret == -1) {
         AACDEC_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
     }
-    pComponentPrivate->nEmptyThisBufferCount++;
+    else
+    {
+        pComponentPrivate->nUnhandledEmptyThisBuffers++;
+        pComponentPrivate->nEmptyThisBufferCount++;
+    }
 
  EXIT:
     return eError;
@@ -1598,12 +1625,15 @@
         pComponentPrivate->pMarkData = NULL;
     }
 
-    pComponentPrivate->nUnhandledFillThisBuffers++;
     nRet = write (pComponentPrivate->dataPipe[1], &pBuffer,sizeof (OMX_BUFFERHEADERTYPE*));
     if (nRet == -1) {
         AACDEC_OMX_ERROR_EXIT(eError,OMX_ErrorHardware,"write failed: OMX_ErrorHardware");
     }
-    pComponentPrivate->nFillThisBufferCount++;
+    else
+    {
+        pComponentPrivate->nUnhandledFillThisBuffers++;
+        pComponentPrivate->nFillThisBufferCount++;
+    }
 
  EXIT:
     return eError;
@@ -1686,17 +1716,17 @@
         }
     }
 
-    AACDEC_OMX_FREE(pComponentPrivate->sDeviceString);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_Boundary(pComponentPrivate->pPERF,PERF_BoundaryComplete | PERF_BoundaryCleanup);
     PERF_Done(pComponentPrivate->pPERF);
 #endif
     
-    OMX_PRBUFFER2(dbg, ":: Freeing: pComponentPrivate = %p\n",pComponentPrivate);
+    OMXDBG_PRINT(stderr, BUFFER, 2, 0, ":: Freeing: pComponentPrivate = %p\n",pComponentPrivate);
     OMX_PRINT1(dbg, "::*********** ComponentDeinit is Done************** \n");
     OMX_DBG_CLOSE(dbg);
-    AACDEC_OMX_FREE(pComponentPrivate);
+    OMX_MEMFREE_STRUCT(pComponentPrivate);
 
 
  EXIT:
@@ -1801,10 +1831,10 @@
 #endif
     }
 
-    AACD_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
     memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
 
-    AACDEC_OMX_MALLOC_SIZE(pBufferHeader->pBuffer,(nSizeBytes + DSP_CACHE_ALIGNMENT),OMX_U8);
+    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer,nSizeBytes,OMX_U8);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Malloced = %p\n",__LINE__,pBufferHeader->pBuffer);
     pBufferHeader->nVersion.nVersion = AACDEC_BUFHEADER_VERSION;
 
@@ -1814,7 +1844,6 @@
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Op Num = %ld\n",__LINE__,pComponentPrivate->pOutputBufferList->numBuffers);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "********************************************\n");
 
-    pBufferHeader->pBuffer += EXTRA_BYTES;
     pBufferHeader->pAppPrivate = pAppPrivate;
     pBufferHeader->pPlatformPrivate = pComponentPrivate;
     pBufferHeader->nAllocLen = nSizeBytes;
@@ -1884,8 +1913,8 @@
  EXIT:
     if(OMX_ErrorNone != eError) {
         OMX_PRINT1(pComponentPrivate->dbg, "%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__);
-        AACDEC_OMX_FREE(pBufferHeader->pBuffer);
-        AACDEC_OMX_FREE(pBufferHeader);
+	    OMX_MEMFREE_STRUCT_DSPALIGN(pBufferHeader->pBuffer, OMX_U8);
+        OMX_MEMFREE_STRUCT(pBufferHeader);
     }
     return eError;
 }
@@ -1961,13 +1990,7 @@
 
     if (inputIndex != -1) {
         if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
-            buff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
-            if (buff!= 0){
-                buff -= EXTRA_BYTES;
-            }
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "\n%d: Freeing:  %p IP Buffer\n",__LINE__,buff);
-            AACDEC_OMX_FREE(buff);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
             buff = NULL;
         }
 
@@ -1981,7 +2004,7 @@
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d: Freeing: %p IP Buf Header\n\n",__LINE__,
                         pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
 
-        AACDEC_OMX_FREE(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
         pComponentPrivate->pInputBufferList->pBufHdr[inputIndex] = NULL;
         pComponentPrivate->pInputBufferList->numBuffers--;
 
@@ -2014,13 +2037,7 @@
             pComponentPrivate->numPendingBuffers++;
         }
         if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
-            buff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
-            if (buff != 0){
-                buff -= EXTRA_BYTES;
-            }
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: FreeBuffer\n", __LINE__);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d: Freeing: %p OP Buffer\n",__LINE__,buff);
-            AACDEC_OMX_FREE(buff);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, OMX_U8);
             buff = NULL;
         }
 
@@ -2033,8 +2050,8 @@
 
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d: Freeing: %p OP Buf Header\n\n",__LINE__,
                         pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
-        AACDEC_OMX_FREE(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
-        AACDEC_OMX_FREE(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
         pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex] = NULL;
         pComponentPrivate->pOutputBufferList->numBuffers--;
 
@@ -2202,7 +2219,7 @@
                               "Bad Size or Port Disabled : OMX_ErrorBadParameter");
     }
 
-    AACD_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
 
     memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
     if (nPortIndex == OUTPUT_PORT_AACDEC) {
@@ -2322,9 +2339,14 @@
     pComponentPrivate = (AACDEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: pComponentPrivate = 0x%p\n",__LINE__, pComponentPrivate);
     if(nIndex == 0){
-        OMX_PRINT2(pComponentPrivate->dbg, "%d :: index=0\n",__LINE__);
-        memcpy(cRole, &pComponentPrivate->componentRole->cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
-        OMX_PRINT2(pComponentPrivate->dbg, "::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+        if (cRole == NULL) {
+            eError = OMX_ErrorBadParameter;
+	}
+	else {
+            OMX_PRINT2(pComponentPrivate->dbg, "%d :: index=0\n",__LINE__);
+            memcpy(cRole, &pComponentPrivate->componentRole->cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
+            OMX_PRINT2(pComponentPrivate->dbg, "::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+	}
     }
     else {
         eError = OMX_ErrorNoMore;
diff --git a/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEnc_CompThread.h b/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEnc_CompThread.h
index b31c154..2216563 100644
--- a/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEnc_CompThread.h
+++ b/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEnc_CompThread.h
@@ -24,6 +24,6 @@
 #define EXIT_COMPONENT_THRD  10
 
 
-void* ComponentThread (void* pThreadData);
+void* AACENC_ComponentThread (void* pThreadData);
 
 #endif
diff --git a/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEnc_Utils.h b/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEnc_Utils.h
index aa159ff..74735cc 100644
--- a/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEnc_Utils.h
+++ b/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEnc_Utils.h
@@ -26,7 +26,10 @@
 #include <OMX_TI_Debug.h>
 #include "LCML_DspCodec.h"
 #include "OMX_AacEncoder.h"
-/* #include <ResourceManagerProxyAPI.h> */
+
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 
 #define AACENC_MAJOR_VER 0x0001
 #define AACENC_MINOR_VER 0x0001
@@ -52,9 +55,6 @@
     #define PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX 0xFF7A347
 #endif
 
-#define EXTRA_BYTES 128 
-#define DSP_CACHE_ALIGNMENT 256 
-
 #ifdef __PERF_INSTRUMENTATION__
     #include "perf.h"
 #endif
@@ -83,30 +83,6 @@
     goto OMX_CONF_CMD_BAIL;         \
 }
 
-#define OMX_MALLOC_STRUCT(_pStruct_, _sName_)   \
-    _pStruct_ = (_sName_*)newmalloc(sizeof(_sName_));   \
-    if(_pStruct_ == NULL){  \
-        eError = OMX_ErrorInsufficientResources;    \
-        goto EXIT;  \
-    } \
-    memset(_pStruct_,0,sizeof(_sName_));
-    
-#define OMX_MALLOC_STRUCT_SIZE(_ptr_, _size_,_name_)    \
-    _ptr_ = (_name_ *)newmalloc(_size_);    \
-    if(_ptr_ == NULL){  \
-        eError = OMX_ErrorInsufficientResources;    \
-        goto EXIT;  \
-    } \
-    memset(_ptr_,0,_size_);
-    
-    
-#define OMX_MEMFREE_STRUCT(_pStruct_)\
-    OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "%d :: FREEING MEMORY = %p\n",__LINE__,_pStruct_);\
-    if(_pStruct_ != NULL){\
-        newfree(_pStruct_);\
-        _pStruct_ = NULL;\
-    }
-
 #define OMX_CLOSE_PIPE(_pStruct_,err)\
     OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "%d :: CLOSING PIPE \n",__LINE__);\
     err = close (_pStruct_);\
@@ -357,7 +333,10 @@
     
     OMX_PRIORITYMGMTTYPE* sPriorityMgmt;
     
-/*  RMPROXY_CALLBACKTYPE rmproxyCallback; */
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
     OMX_BOOL bPreempted;
     
     OMX_AUDIO_PARAM_PORTFORMATTYPE sInPortFormat;
@@ -395,9 +374,6 @@
     /** The pipes for sending buffers to the thread */
     int cmdDataPipe[2];
 
-    /** The pipes for sending buffers to the thread */
-  /*  int lcml_Pipe[2];  */
-
     /** Set to indicate component is stopping */
     OMX_U32 bIsStopping;
 
@@ -566,7 +542,7 @@
     pthread_cond_t codecFlush_threshold;
     OMX_U8 codecFlush_waitingsignal;
 
-pthread_mutex_t InLoaded_mutex;
+    pthread_mutex_t InLoaded_mutex;
     pthread_cond_t InLoaded_threshold;
     OMX_U8 InLoaded_readytoidle;
     
@@ -668,7 +644,6 @@
 *          OMX Error code = Error
 */
 /*================================================================== */
-/*OMX_ERRORTYPE AACENC_TransitionToIdle(AACENC_COMPONENT_PRIVATE *pComponentPrivate); */
 
 OMX_ERRORTYPE AACENC_TransitionToPause(AACENC_COMPONENT_PRIVATE *pComponentPrivate);
 
@@ -676,7 +651,9 @@
 
 OMX_ERRORTYPE AACENCWriteConfigHeader(AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr);
 
-/* void AACENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData); */
+#ifdef RESOURCE_MANAGER_ENABLED
+void AACENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
 
 #ifndef UNDER_CE
 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp);
@@ -696,6 +673,16 @@
 OMX_ERRORTYPE AddStateTransition(AACENC_COMPONENT_PRIVATE* pComponentPrivate);
 OMX_ERRORTYPE RemoveStateTransition(AACENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BOOL bEnableSignal);
 
+/*  =========================================================================*/
+/*  func    AACENC_HandleUSNError
+/*
+/*  desc    Handles error messages returned by the dsp
+/*
+/*@return n/a
+/*
+/*  =========================================================================*/
+void AACENC_HandleUSNError (AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
+
 
 #endif
 
diff --git a/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEncoder.h b/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEncoder.h
index 3fc0f07..21989ae 100644
--- a/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEncoder.h
+++ b/omx/audio/src/openmax_il/aac_enc/inc/OMX_AacEncoder.h
@@ -62,21 +62,6 @@
 #define MAX_NUM_OF_BUFS 10
 #define NUM_OF_PORTS 2
 
-/* ======================================================================= */
-/**
- * @def    Mem test application
- */
-/* ======================================================================= */
-#undef AACENC_DEBUGMEM 
-
-#ifdef AACENC_DEBUGMEM
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__) 
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
 typedef enum OMX_AACENC_INDEXAUDIOTYPE {
     OMX_IndexCustomAacEncHeaderInfoConfig = 0xFF000001,
     OMX_IndexCustomAacEncStreamIDConfig,
diff --git a/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEnc_CompThread.c b/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEnc_CompThread.c
index 539b52a..885a9dd 100644
--- a/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEnc_CompThread.c
+++ b/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEnc_CompThread.c
@@ -72,7 +72,7 @@
 #include "OMX_AacEnc_CompThread.h"
 
 
-void* ComponentThread (void* pThreadData)
+void* AACENC_ComponentThread (void* pThreadData)
 {
     int status;
     struct timespec tv;
@@ -125,9 +125,9 @@
         if (status == 0) 
         {
 
-            OMX_ERROR2(pComponentPrivate->dbg, "%d : bIsStopping = %ld\n",__LINE__, pComponentPrivate->bIsStopping);
-            OMX_ERROR2(pComponentPrivate->dbg, "%d : lcml_nOpBuf = %ld\n",__LINE__, pComponentPrivate->lcml_nOpBuf);
-            OMX_ERROR2(pComponentPrivate->dbg, "%d : lcml_nIpBuf = %ld\n",__LINE__, pComponentPrivate->lcml_nIpBuf);
+            OMX_PRINT1(pComponentPrivate->dbg, "%d : bIsStopping = %ld\n",__LINE__, pComponentPrivate->bIsStopping);
+            OMX_PRINT1(pComponentPrivate->dbg, "%d : lcml_nOpBuf = %ld\n",__LINE__, pComponentPrivate->lcml_nOpBuf);
+            OMX_PRINT1(pComponentPrivate->dbg, "%d : lcml_nIpBuf = %ld\n",__LINE__, pComponentPrivate->lcml_nIpBuf);
 
             if (pComponentPrivate->bIsThreadstop == 1)  
             {
@@ -148,20 +148,18 @@
                     goto EXIT;
                 }
              }
-             OMX_ERROR2(pComponentPrivate->dbg, "%d :: Component Time Out !!!!! \n",__LINE__);
+             OMX_PRINT2(pComponentPrivate->dbg, "%d :: Component Time Out !!!!! \n",__LINE__);
         } 
         else if(status == -1) 
         {
             OMX_ERROR2(pComponentPrivate->dbg, "%d :: Error in Select\n", __LINE__);
             pComponentPrivate->cbInfo.EventHandler (pHandle, pHandle->pApplicationPrivate, 
                                                     OMX_EventError,
-                                                    OMX_ErrorHardware,
+                                                    OMX_ErrorInsufficientResources,
                                                     OMX_TI_ErrorSevere,
                                                     "Error from Component Thread in select");
-            eError = OMX_ErrorHardware;
-            break;
-
-        } 
+            eError = OMX_ErrorInsufficientResources;
+        }
 
         else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds)) && (pComponentPrivate->curState != OMX_StatePause)) 
         {
diff --git a/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEnc_Utils.c b/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEnc_Utils.c
index c309e58..85957d4 100644
--- a/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEnc_Utils.c
+++ b/omx/audio/src/openmax_il/aac_enc/src/OMX_AacEnc_Utils.c
@@ -88,15 +88,6 @@
 #define HASHINGENABLE 1
 #endif
 
-#ifdef AACENC_DEBUGMEM
- void *arr[500]; 
- int lines[500]; 
- int bytes[500]; 
- char file[500][50];
-
-void * mymalloc(int line, char *s, int size);
-int myfree(void *dp, int line, char *s);
-#endif
 
 
 /* ========================================================================== */
@@ -124,7 +115,6 @@
     OMX_U32 i                               = 0;
     OMX_BUFFERHEADERTYPE *pTemp             = NULL;
     OMX_S32 size_lcml                       = 0;
-    char *pTemp_char                        = NULL;
     char *ptr;
     LCML_AACENC_BUFHEADERTYPE *pTemp_lcml   = NULL;
     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
@@ -187,7 +177,7 @@
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_AacEncUtils.c\n",__LINE__);
     if(pComponentPrivate->dasfmode == 1) {
         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring to DASF mode\n",__LINE__);
-        OMX_MALLOC_STRUCT(strmAttr, LCML_STRMATTR);
+        OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
         OMX_PRINT1(pComponentPrivate->dbg, "strmAttr %p \n",strmAttr);
         
         pComponentPrivate->strmAttr = strmAttr;
@@ -317,7 +307,7 @@
 
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_AacEncUtils.c\n",__LINE__);
     size_lcml = nIpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
-    OMX_MALLOC_STRUCT_SIZE(ptr, size_lcml,char);
+    OMX_MALLOC_SIZE(ptr, size_lcml,char);
     pTemp_lcml = (LCML_AACENC_BUFHEADERTYPE *)ptr;
     pComponentPrivate->pLcmlBufHeader[INPUT_PORT] = pTemp_lcml;
     for (i=0; i<nIpBuf; i++) 
@@ -333,12 +323,9 @@
         pTemp_lcml->buffer = pTemp;
         pTemp_lcml->eDir = OMX_DirInput;
 
-        OMX_MALLOC_STRUCT_SIZE(pTemp_lcml->pIpParam,
-                               (sizeof(AACENC_UAlgInBufParamStruct) + DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
+                               sizeof(AACENC_UAlgInBufParamStruct),
                                AACENC_UAlgInBufParamStruct);
-        pTemp_char = (char*)pTemp_lcml->pIpParam;
-        pTemp_char += EXTRA_BYTES;
-        pTemp_lcml->pIpParam = (AACENC_UAlgInBufParamStruct*)pTemp_char;
         OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml->pIpParam %p \n",pTemp_lcml->pIpParam);
         
         pTemp_lcml->pIpParam->bLastBuffer = 0;
@@ -351,7 +338,7 @@
     /* Allocate memory for all output buffer headers,  This memory pointer will be sent to LCML */
     size_lcml = nOpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
 
-    OMX_MALLOC_STRUCT_SIZE(ptr, size_lcml,char);
+    OMX_MALLOC_SIZE(ptr, size_lcml,char);
     pTemp_lcml = (LCML_AACENC_BUFHEADERTYPE *)ptr;
 
     pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
@@ -372,12 +359,9 @@
         pTemp_lcml->eDir = OMX_DirOutput;
         /* SN : Each output buffer may be accompanied by an output buffer parameters structure*/ 
 
-        OMX_MALLOC_STRUCT_SIZE(pTemp_lcml->pOpParam, 
-                               (sizeof(AACENC_UAlgOutBufParamStruct) + DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam, 
+                               sizeof(AACENC_UAlgOutBufParamStruct),
                                AACENC_UAlgOutBufParamStruct);
-        pTemp_char = (char*)pTemp_lcml->pOpParam;
-        pTemp_char += EXTRA_BYTES;
-        pTemp_lcml->pOpParam = (AACENC_UAlgOutBufParamStruct*)pTemp_char;
 
         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: size of pOpParam: %d \n",__LINE__,sizeof(pTemp_lcml->pOpParam->unFrameSizes));
         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: UTIL: numframes of pOpParam: %d \n\n",__LINE__,sizeof(pTemp_lcml->pOpParam->unNumFramesEncoded)) ;
@@ -392,14 +376,10 @@
     pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
 
 
-        OMX_MALLOC_STRUCT_SIZE(pComponentPrivate->ptAlgDynParams,
-                                (sizeof(MPEG4AACENC_UALGParams)+DSP_CACHE_ALIGNMENT),
+    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->ptAlgDynParams,
+                                sizeof(MPEG4AACENC_UALGParams),
                                 MPEG4AACENC_UALGParams); 
 
-        pTemp_char = (char*)pComponentPrivate->ptAlgDynParams;
-        pTemp_char += EXTRA_BYTES;
-        pComponentPrivate->ptAlgDynParams = (MPEG4AACENC_UALGParams*)pTemp_char;
-        
     OMX_PRINT2(pComponentPrivate->dbg, "UTIL: pComponentPrivate->ptAlgDynParams %p \n",pComponentPrivate->ptAlgDynParams);
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -482,9 +462,9 @@
 
     /* create the pipe used to send commands to the thread */
 #ifdef UNDER_CE     
-    eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr, ComponentThread, pComponentPrivate);
+    eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr, AACENC_ComponentThread, pComponentPrivate);
 #else   
-    eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL, ComponentThread, pComponentPrivate);
+    eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL, AACENC_ComponentThread, pComponentPrivate);
 #endif
     if (eError || !pComponentPrivate->ComponentThread) {
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Inside  AACENC_StartComponentThread\n", __LINE__);
@@ -598,7 +578,6 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 nIpBuf = 0;
     OMX_U32 nOpBuf = 0;
-    char *pTemp    = NULL;
     OMX_U32 i      = 0;
 
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering AACENC_CleanupInitParams()\n", __LINE__);
@@ -608,13 +587,7 @@
     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
     for(i=0; i<nIpBuf; i++) 
     {
-        pTemp = (char*)pTemp_lcml->pIpParam;
-        if (pTemp != NULL) 
-        {
-            pTemp -= 128;
-        }
-        pTemp_lcml->pIpParam = (AACENC_UAlgInBufParamStruct*)pTemp;
-        OMX_MEMFREE_STRUCT(pTemp_lcml->pIpParam);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, AACENC_UAlgInBufParamStruct);
         pTemp_lcml++;
     }
 
@@ -623,33 +596,16 @@
     nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
     for (i=0; i<nOpBuf; i++)
     {
-        pTemp = (char*)pTemp_lcml->pOpParam;
-        if (pTemp != NULL) 
-        {
-            pTemp -= 128;
-        }
-        pTemp_lcml->pOpParam = (AACENC_UAlgOutBufParamStruct*)pTemp;
-        OMX_MEMFREE_STRUCT(pTemp_lcml->pOpParam);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, AACENC_UAlgOutBufParamStruct);
         pTemp_lcml++;
     }
 
     OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
     OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
-    pTemp = (char*)pComponentPrivate->ptAlgDynParams;
-    if (pTemp != NULL) 
-    {        
-        pTemp -= 128;
-    }
-    pComponentPrivate->ptAlgDynParams = (MPEG4AACENC_UALGParams*)pTemp;
-    OMX_MEMFREE_STRUCT(pComponentPrivate->ptAlgDynParams);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->ptAlgDynParams, MPEG4AACENC_UALGParams);
     if(pComponentPrivate->dasfmode == 1) 
     {
-        pTemp = (char*)pComponentPrivate->pParams;
-        if (pTemp != NULL) {        
-            pTemp -= 128;
-        }
-        pComponentPrivate->pParams = (AACENC_AudioCodecParams*)pTemp;
-        OMX_MEMFREE_STRUCT(pComponentPrivate->pParams);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, AACENC_AudioCodecParams);
     }
 
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting Successfully AACENC_CleanupInitParams()\n",__LINE__);
@@ -743,7 +699,6 @@
     LCML_CALLBACKTYPE cb;
     LCML_DSP *pLcmlDsp = NULL;
     LCML_AACENC_BUFHEADERTYPE *pLcmlHdr;
-    char *pTemp_char = NULL;
     int inputPortFlag = 0;
     int outputPortFlag = 0;
 
@@ -864,6 +819,13 @@
                         if (pLcmlHandle == NULL) 
                         {
                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: LCML Handle is NULL........exiting..\n",__LINE__);
+                            eError = OMX_ErrorHardware;
+                            pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                             goto EXIT;
                         }
 
@@ -874,6 +836,12 @@
                         if(eError != OMX_ErrorNone) 
                         {
                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from AACENCFill_LCMLInitParams()\n",__LINE__);
+                            pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorMajor,
+                                                NULL);
                             goto EXIT;
                         }
                         pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
@@ -891,12 +859,12 @@
                             /* send an event to client */
                             /* client should unload the component if the codec is not able to load */
                             eError = OMX_ErrorInvalidState;
-                            pComponentPrivate->cbInfo.EventHandler (pHandle,
-                                    pHandle->pApplicationPrivate,
-                                    OMX_EventError,
-                                    eError,
-                                    OMX_TI_ErrorSevere,
-                                    NULL);
+                            pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                             goto EXIT;
                         }
 
@@ -913,8 +881,6 @@
                         OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: About to call RMProxy_SendCommand\n", __LINE__);
 #ifdef RESOURCE_MANAGER_ENABLED
 
-                        pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) AACENC_ResourceManagerCallback;
-                        rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource, OMX_AAC_Encoder_COMPONENT,AACENC_CPU_USAGE, 3456, &(pComponentPrivate->rmproxyCallback));
 
                         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: Returned from RMProxy_SendCommand\n", __LINE__);
                         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: RMProxy_SendCommand returned %d\n", __LINE__,rm_error);
@@ -999,6 +965,12 @@
                         if(eError != OMX_ErrorNone) 
                         {
                             OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Stop..\n",__LINE__);
+                            pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                             goto EXIT;
                         }
                         OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AACENC: After MMCodecControlStop\n", __LINE__);
@@ -1077,14 +1049,11 @@
                         {
                             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: ---- Comp: DASF Functionality is ON ---\n",__LINE__);
 
-                            OMX_MALLOC_STRUCT_SIZE(pComponentPrivate->pParams,
-                                (sizeof(AACENC_AudioCodecParams)+DSP_CACHE_ALIGNMENT),
+                            OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,
+                                sizeof(AACENC_AudioCodecParams),
                                 AACENC_AudioCodecParams); 
 
                             OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: pComponentPrivate->pParams %p \n",pComponentPrivate->pParams);
-                        pTemp_char = (char*)pComponentPrivate->pParams;
-                            pTemp_char += EXTRA_BYTES;
-                            pComponentPrivate->pParams = (AACENC_AudioCodecParams*)pTemp_char;
                             if(pComponentPrivate->unNumChannels == 1)   /*MONO*/
                                 pComponentPrivate->pParams->iAudioFormat = 0x0001;
                             else
@@ -1102,6 +1071,12 @@
                             if(eError != OMX_ErrorNone) 
                             {
                                 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec StreamControl..\n",__LINE__);
+                                pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                                 goto EXIT;
                             }
                         }
@@ -1129,6 +1104,12 @@
                         if(eError != OMX_ErrorNone) 
                         {
                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec StreamControl..\n",__LINE__);
+                            pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                             goto EXIT;
                         }
                         OMX_PRDSP1(pComponentPrivate->dbg, "%d :: AACENC: Algcontrol has been sent to DSP\n",__LINE__);
@@ -1138,6 +1119,12 @@
                         if(eError != OMX_ErrorNone) 
                         {
                             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Occurred in Codec Start..\n", __LINE__);
+                            pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                             goto EXIT;
                         }
                 }
@@ -1148,6 +1135,12 @@
                     if (eError != OMX_ErrorNone) 
                     {
                         OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: While Resuming the codec\n",__LINE__);
+                        pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                         goto EXIT;
                     }
                     for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) 
@@ -1167,6 +1160,16 @@
                                             (OMX_U8 *) pLcmlHdr->pIpParam,
                                             sizeof(AACENC_UAlgInBufParamStruct),
                                             NULL);
+                               if(eError != OMX_ErrorNone){
+                                   OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
+                                   pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
+                                   goto EXIT;
+                               }
                         }
                     }
                     pComponentPrivate->nNumInputBufPending =0;
@@ -1182,14 +1185,24 @@
                             
 
                                 eError = LCML_QueueBuffer( 
-                                ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                EMMCodecOuputBuffer,
-                                pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
-                                pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
-                                0,
-                                (OMX_U8 *) pLcmlHdr->pOpParam,
-                                sizeof(AACENC_UAlgOutBufParamStruct),
-                                NULL);
+                                             ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                             EMMCodecOuputBuffer,
+                                             pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
+                                             pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
+                                             0,
+                                             (OMX_U8 *) pLcmlHdr->pOpParam,
+                                             sizeof(AACENC_UAlgOutBufParamStruct),
+                                             NULL);
+                                if(eError != OMX_ErrorNone){
+                                   OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
+                                   pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
+                                   goto EXIT;
+                               }
                             }
                     }
                     pComponentPrivate->nNumOutputBufPending = 0;
@@ -1214,7 +1227,7 @@
 #endif
 
                 pComponentPrivate->curState = OMX_StateExecuting;
-
+ 
 #ifdef __PERF_INSTRUMENTATION__
                 PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySteadyState);
 #endif
@@ -1224,7 +1237,6 @@
                      return OMX_ErrorUndefined;
                 }
 
-
                 /*Send state change notificaiton to Application */
                 pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                        pHandle->pApplicationPrivate,
@@ -1827,6 +1839,17 @@
 EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting AACENCHandleCommand Function\n",__LINE__);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Returning %d\n",__LINE__,eError);
+    /* report the error to the client via event */
+    if(eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD){
+        OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
+        pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
+
+    }
     return eError;
 }
 
@@ -2147,7 +2170,9 @@
                     {
                         AACENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
                         pComponentPrivate->LastOutputBufferHdrQueued = pBufHeader;
-                        pLcmlHdr->pOpParam->unNumFramesEncoded=0; /* Resetting the value  for each time*/
+			if (pLcmlHdr != NULL) {
+			    pLcmlHdr->pOpParam->unNumFramesEncoded = 0; /* Resetting the value  for each time*/
+			}
                         eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
                                                   EMMCodecOuputBuffer, 
                                                   (OMX_U8 *)pBufHeader->pBuffer, 
@@ -2186,6 +2211,17 @@
     }
 EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: UTIL:Exiting from  HandleDataBuf_FromApp ..........>>>>>\n",__LINE__);
+    /* report the error to the client via event */
+    if(eError != OMX_ErrorNone){
+        OMX_ERROR4(pComponentPrivate->dbg, "%d:: Error: LCML QUEUE BUFFER\n",__LINE__);
+        pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, 
+                                                pComponentPrivate->pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
+
+    }
     return eError;
 }
 
@@ -2566,7 +2602,7 @@
         if(pComponentPrivate_CC->codecStop_waitingsignal == 0){
             pComponentPrivate_CC->codecStop_waitingsignal = 1;             
             pthread_cond_signal(&pComponentPrivate_CC->codecStop_threshold);
-            OMX_ERROR2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
+            OMX_PRINT2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
         }
         pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
 		
@@ -2638,137 +2674,49 @@
     
     else if (event == EMMCodecDspError) 
     {
-
-        for(j=0;j<9;j++)
+        OMX_PRSTATE2(pComponentPrivate_CC->dbg, "%d :: commandedState  = %d\n",__LINE__,(int)args[0]);
+        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: arg4 = %d\n",__LINE__,(int)args[4]);
+        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: arg5 = %d\n",__LINE__,(int)args[5]);
+        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d ::UTIL: EMMCodecDspError Here\n",__LINE__);
+        switch ( (OMX_U32) args [4])
         {
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "arg [%d] = %p \n",j,args[j]);
-        }
+            /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
+             * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
+             * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
+             * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
+             * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
+             * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
+             * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
+             * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
 
 #ifdef _ERROR_PROPAGATION__
-        /* Cheking for MMU_fault */
-        if((args[4] == (void*)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) 
-        {
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__);
-            pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
-            OMX_PRSTATE2(pComponentPrivate_CC->dbg, "State changed to OMX_StateInvalid Line %d\n",__LINE__);
-            
-            pComponentPrivate_CC->curState = OMX_StateInvalid;
-            pHandle = pComponentPrivate_CC->pHandle;
-            pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 
-                                   pHandle->pApplicationPrivate,
-                                   OMX_EventError,
-                                   OMX_ErrorHardware, 
-                                   OMX_TI_ErrorSevere,
-                                   NULL);
-        }
-#endif      
-        if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) 
-        {
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: Inside the LCML_Callback: IUALG_WARN_PLAYCOMPLETED\n",__LINE__);
-            pHandle = pComponentPrivate_CC->pHandle;
-            pComponentPrivate_CC->bPlayCompleteFlag = 1;
-            
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: UTIL: pComponentPrivate_CC->bPlayCompleteFlag = %ld \n",__LINE__,pComponentPrivate_CC->bPlayCompleteFlag);
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "bPlayCompleteFlag\n");
-            pComponentPrivate_CC->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS;  /* Extra feature Not used */
-            OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: UTIL: Buffer with EOS flag: %p \n",__LINE__,pComponentPrivate_CC->LastOutbuf);
-            /* add callback to application to indicate SN/USN has completed playing of current set of date */
-            pComponentPrivate_CC->cbInfo.EventHandler(pHandle,                
-                                    pHandle->pApplicationPrivate,
-                                    OMX_EventBufferFlag,
-                                    (OMX_U32)NULL,
-                                    OMX_BUFFERFLAG_EOS,NULL);
-        }
-
-        if((int)args[5] == IUALG_ERR_GENERAL) 
-        {
-            char *pArgs = "damedesuStr";
-            OMX_ERROR4(pComponentPrivate_CC->dbg,  "Algorithm error. Cannot continue" );
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);
-            OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: LCML_Callback: IUALG_ERR_GENERAL\n",__LINE__);
-            pHandle = pComponentPrivate_CC->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate_CC->pLcmlHandle;
-
-#ifndef UNDER_CE
-
-                        pComponentPrivate_CC->bIsStopping = 1;
-					if (pComponentPrivate_CC->codecStop_waitingsignal == 0){ 
-						pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex); 	
-					}
-                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                                  MMCodecControlStop,(void *)pArgs);
-
-                    if (pComponentPrivate_CC->codecStop_waitingsignal == 0){
-                        pthread_cond_wait(&pComponentPrivate_CC->codecStop_threshold, &pComponentPrivate_CC->codecStop_mutex);
-                        pComponentPrivate_CC->codecStop_waitingsignal = 0;
-                        pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
-                    }
-            if(eError != OMX_ErrorNone) 
-            {
-                OMX_ERROR4(pComponentPrivate_CC->dbg, "%d: Error Occurred in Codec Stop..\n",__LINE__);
-                goto EXIT;
-            }
-            OMX_PRSTATE2(pComponentPrivate_CC->dbg, "%d :: AACENC: Codec has been Stopped here\n",__LINE__);
-            pComponentPrivate_CC->curState = OMX_StateIdle;
-
-            /* Decrement reference count with signal enabled */
-            if(RemoveStateTransition(pComponentPrivate_CC, OMX_TRUE) != OMX_ErrorNone) {
-                 return OMX_ErrorUndefined;
-            }
-
-            pComponentPrivate_CC->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
-                                OMX_EventCmdComplete, OMX_CommandStateSet,OMX_StateIdle, NULL);
-#else
-            pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 
-                                                        pHandle->pApplicationPrivate,
-                                                        OMX_EventError, 
-                                                        OMX_ErrorUndefined,
-                                                        OMX_TI_ErrorSevere, 
-                                                        NULL);
+            case USN_ERR_PAUSE:
+            case USN_ERR_STOP:
+            case USN_ERR_ALGCTRL:
+            case USN_ERR_STRMCTRL:
+            case USN_ERR_UNKNOWN_MSG:
+                {
+                    pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
+                    pComponentPrivate_CC->curState = OMX_StateInvalid;
+                    pHandle = pComponentPrivate_CC->pHandle;
+                    pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
+                            pHandle->pApplicationPrivate,
+                            OMX_EventError,
+                            OMX_ErrorInvalidState,
+                            OMX_TI_ErrorSevere,
+                            NULL);
+                }
+                break;
 #endif
+
+            case USN_ERR_WARNING:
+            case USN_ERR_PROCESS:
+                AACENC_HandleUSNError (pComponentPrivate_CC, (OMX_U32)args[5]);
+                break;
+            default:
+                break;
         }
 
-        
-        if( (int)args[5] == IUALG_ERR_DATA_CORRUPT )
-        {
-            char *pArgs = "damedesuStr";
-            OMX_PRINT2(pComponentPrivate_CC->dbg,  "Algorithm error. Corrupt data" );
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);
-            OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: LCML_Callback: IUALG_ERR_DATA_CORRUPT\n",__LINE__);
-            pHandle = pComponentPrivate_CC->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate_CC->pLcmlHandle;
-#ifndef UNDER_CE
-
-                        pComponentPrivate_CC->bIsStopping = 1;
-					if (pComponentPrivate_CC->codecStop_waitingsignal == 0){ 
-						pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex); 	
-					}
-                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                                  MMCodecControlStop,(void *)pArgs);
-
-                    if (pComponentPrivate_CC->codecStop_waitingsignal == 0){
-                        pthread_cond_wait(&pComponentPrivate_CC->codecStop_threshold, &pComponentPrivate_CC->codecStop_mutex);
-                        pComponentPrivate_CC->codecStop_waitingsignal = 0;
-                        pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
-                    }
-            if(eError != OMX_ErrorNone) 
-            {
-                OMX_ERROR4(pComponentPrivate_CC->dbg, "%d: Error Occurred in Codec Stop..\n",__LINE__);
-                goto EXIT;
-            }
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: AACENC: Codec has been Stopped here\n",__LINE__);
-            pComponentPrivate_CC->curState = OMX_StateIdle;
-            pComponentPrivate_CC->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
-                                                      OMX_EventCmdComplete, OMX_ErrorNone,0, NULL);
-#else
-            pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 
-                                                    pHandle->pApplicationPrivate,
-                                                    OMX_EventError, 
-                                                    OMX_ErrorUndefined,
-                                                    OMX_TI_ErrorSevere, 
-                                                    NULL);
-#endif                  
-        }
     }
 
 
@@ -2825,8 +2773,17 @@
 
 EXIT:
     OMX_PRINT1(pComponentPrivate_CC->dbg, "%d:pComponentPrivate->curState = %d\n",__LINE__,pComponentPrivate_CC->curState);
-
     OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: UTIL: Exiting the LCML_Callback Function\n",__LINE__);
+    /* report the error to the client via event */
+    if(eError != OMX_ErrorNone){
+        OMX_ERROR4(pComponentPrivate_CC->dbg, "%d:: Error: \n",__LINE__);
+        pComponentPrivate_CC->cbInfo.EventHandler (pComponentPrivate_CC->pHandle, 
+                                                pComponentPrivate_CC->pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
+    }
     return eError;
 }
 
@@ -3169,7 +3126,7 @@
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: ------ Buffer Details ------------\n",__LINE__);
 
     size_lcml = nIpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
-    OMX_MALLOC_STRUCT_SIZE(pTemp_lcml, size_lcml, LCML_AACENC_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_AACENC_BUFHEADERTYPE);
     OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml %p to %p \n",pTemp_lcml,(pTemp_lcml + sizeof(pTemp_lcml) ));
     
     pComponentPrivate->pLcmlBufHeader[INPUT_PORT] = pTemp_lcml;
@@ -3186,7 +3143,7 @@
         pTemp_lcml->buffer = pTemp;
         pTemp_lcml->eDir = OMX_DirInput;
 
-        OMX_MALLOC_STRUCT(pTemp_lcml->pIpParam, AACENC_UAlgInBufParamStruct);
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam, sizeof(AACENC_UAlgInBufParamStruct), AACENC_UAlgInBufParamStruct);
         OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml %p to %p \n",pTemp_lcml,(pTemp_lcml + sizeof(pTemp_lcml) ));
         
         pTemp_lcml->pIpParam->bLastBuffer = 0;
@@ -3199,7 +3156,7 @@
     /* Allocate memory for all output buffer headers,  This memory pointer will be sent to LCML */
     size_lcml = nOpBuf * sizeof(LCML_AACENC_BUFHEADERTYPE);
 
-    OMX_MALLOC_STRUCT_SIZE(pTemp_lcml, size_lcml, LCML_AACENC_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_AACENC_BUFHEADERTYPE);
     OMX_PRDSP2(pComponentPrivate->dbg, "size_lcml %d to %lx \n", (int)size_lcml,(size_lcml + sizeof(size_lcml) ));
     
     pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
@@ -3224,7 +3181,7 @@
         pTemp_lcml->buffer = pTemp;
         pTemp_lcml->eDir = OMX_DirOutput;
 
-        OMX_MALLOC_STRUCT( pTemp_lcml->pOpParam, AACENC_UAlgOutBufParamStruct);
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam, sizeof(AACENC_UAlgOutBufParamStruct), AACENC_UAlgOutBufParamStruct);
         
         OMX_PRINT2(pComponentPrivate->dbg, "\n pTemp_lcml->pOpParam %p \n",pTemp_lcml->pOpParam);
         pTemp->nFlags = NORMAL_BUFFER;
@@ -3361,77 +3318,86 @@
     return index;
 }
 
-
-#ifdef AACENC_DEBUGMEM
-
-/* ========================================================================== */
-/**
-* @mymalloc() This function is used to debug memory leaks
-*
-* @param 
-*
-* @pre None
-*
-* @post None
-*
-* @return None
-*/
-/* ========================================================================== */
-void* mymalloc(int line, char *s, int size)
+/*  =========================================================================*/
+/*  func    AACENC_HandleUSNError
+/*
+/*  desc    Handles error messages returned by the dsp
+/*
+/*@return n/a
+/*
+/*  =========================================================================*/
+void AACENC_HandleUSNError (AACENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
 {
-   void *p;    
-   int e=0;
+    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U32 i;
+    switch (arg)
+    {
 
-   p = malloc(size);
-   if(p==NULL){
-       OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
-       }
-   else{
-         while((lines[e]!=0)&& (e<500) ){
-              e++;
-         }
-         arr[e]=p;
-         lines[e]=line;
-         bytes[e]=size;
-         strcpy(file[e],s);
-         OMXDBG_PRINT(stderr, BUFFER, 2, 0, "Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
-  }
-   return p;
-}
+        case IUALG_WARN_CONCEALED:
+        case IUALG_WARN_UNDERFLOW:
+        case IUALG_WARN_OVERFLOW:
+        case IUALG_WARN_ENDOFDATA:
+            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error" );
+            /* all of these are informative messages, Algo can recover, no need to notify the
+             * IL Client at this stage of the implementation */
+            break;
+        case IUALG_WARN_PLAYCOMPLETED:
 
- /* ========================================================================== */
-/**
-* @myfree() This function is used to debug memory leaks
-*
-* @param 
-*
-* @pre None
-*
-* @post None
-*
-* @return None
-*/
-/* ========================================================================== */
-int myfree(void *dp, int line, char *s){
-
-    int q;
-    for(q=0;q<500;q++){
-        if(arr[q]==dp){
-           OMXDBG_PRINT(stderr, PRINT, 2, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
-           free(dp);
-           dp = NULL;
-           lines[q]=0;
-           strcpy(file[q],"");
-           break;
-        }            
-     }    
-     if(500==q)
-         OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
-}
+            {
+                OMX_PRINT2(pComponentPrivate->dbg, "%d :: UTIL: IUALG_WARN_PLAYCOMPLETED/USN_ERR_WARNING event received\n", __LINE__);
+                pComponentPrivate->bPlayCompleteFlag = 1;
+#ifndef UNDER_CE
+                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       OMX_EventBufferFlag,
+                                                       (OMX_U32)NULL,
+                                                       OMX_BUFFERFLAG_EOS,
+                                                       NULL);
+                pComponentPrivate->pLcmlBufHeader[0]->pIpParam->bLastBuffer = 0;
+#else
+                /* add callback to application to indicate SN/USN has completed playing of current set of date */
+                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       OMX_EventBufferFlag,
+                                                       (OMX_U32)NULL,
+                                                       OMX_BUFFERFLAG_EOS,
+                                                       NULL);
 #endif
+            }
+            break;
+
+#ifdef _ERROR_PROPAGATION__
+        case IUALG_ERR_BAD_HANDLE:
+        case IUALG_ERR_DATA_CORRUPT:
+        case IUALG_ERR_NOT_SUPPORTED:
+        case IUALG_ERR_ARGUMENT:
+        case IUALG_ERR_NOT_READY:
+        case IUALG_ERR_GENERAL:
+
+            {
+                /* all of these are fatal messages, Algo can not recover
+                 * hence return an error */
+                OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error, cannot recover" );
+                pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                pComponentPrivate->curState = OMX_StateInvalid;
+                pHandle = pComponentPrivate->pHandle;
+                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                        pHandle->pApplicationPrivate,
+                        OMX_EventError,
+                        OMX_ErrorInvalidState,
+                        OMX_TI_ErrorSevere,
+                        NULL);
+            }
+            break;
+#endif
+        default:
+            break;
+    }
+}
 
 
-/* void AACENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+#ifdef RESOURCE_MANAGER_ENABLED
+void AACENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
 {
     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
     OMX_STATETYPE state = OMX_StateIdle;
@@ -3459,7 +3425,7 @@
     }
 
 }
-*/
+#endif
 
 OMX_ERRORTYPE AddStateTransition(AACENC_COMPONENT_PRIVATE* pComponentPrivate) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
@@ -3495,6 +3461,3 @@
 
     return eError;
 }
-
-
-
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 5d4d148..23125f8 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
@@ -82,7 +82,6 @@
 #ifdef RESOURCE_MANAGER_ENABLED
 #include <ResourceManagerProxyAPI.h>
 #endif
-#include <OMX_Component.h>
 #include "OMX_AacEncoder.h"
 #define  AAC_ENC_ROLE "audio_encoder.aac"
 #include "OMX_AacEnc_Utils.h"
@@ -161,20 +160,19 @@
 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
 {
 
+    OMX_ERRORTYPE rm_error = OMX_ErrorNone;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    OMX_CONF_CHECK_CMD(hComp,1,1);                              /* checking for NULL pointers */
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_op = NULL;
     AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_AUDIO_PARAM_AACPROFILETYPE *aac_ip = NULL;
     OMX_AUDIO_PARAM_AACPROFILETYPE *aac_op = NULL;
+    OMX_CONF_CHECK_CMD(hComp, 1, 1);                              /* checking for NULL pointers */
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
     OMX_AUDIO_PARAM_PCMMODETYPE *aac_pcm_ip = NULL;
     OMX_AUDIO_PARAM_PCMMODETYPE *aac_pcm_op = NULL;
     int i;
 
-    OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: AACENC : Entering OMX_ComponentInit\n", __LINE__);
-
     /*Set the all component function pointer to the handle*/
     pHandle->SetCallbacks           = SetCallbacks;
     pHandle->GetComponentVersion    = GetComponentVersion;
@@ -194,7 +192,7 @@
     pHandle->UseBuffer              = UseBuffer;
     pHandle->ComponentRoleEnum      = ComponentRoleEnum;
     
-    OMX_MALLOC_STRUCT(pHandle->pComponentPrivate, AACENC_COMPONENT_PRIVATE);
+    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, AACENC_COMPONENT_PRIVATE);
     ((AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
     
     /* Initialize component data structures to default values */
@@ -204,8 +202,8 @@
 
     /* ---------start of OMX_AUDIO_PARAM_AACPROFILETYPE --------- */
 
-    OMX_MALLOC_STRUCT(aac_ip, OMX_AUDIO_PARAM_AACPROFILETYPE);
-    OMX_MALLOC_STRUCT(aac_op, OMX_AUDIO_PARAM_AACPROFILETYPE);
+    OMX_MALLOC_GENERIC(aac_ip, OMX_AUDIO_PARAM_AACPROFILETYPE);
+    OMX_MALLOC_GENERIC(aac_op, OMX_AUDIO_PARAM_AACPROFILETYPE);
 
     ((AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->aacParams[INPUT_PORT] = aac_ip;
     ((AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->aacParams[OUTPUT_PORT] = aac_op;
@@ -226,8 +224,8 @@
 
     /* ---------start of OMX_AUDIO_PARAM_PCMMODETYPE --------- */
 
-    OMX_MALLOC_STRUCT(aac_pcm_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
-    OMX_MALLOC_STRUCT(aac_pcm_op, OMX_AUDIO_PARAM_PCMMODETYPE);
+    OMX_MALLOC_GENERIC(aac_pcm_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
+    OMX_MALLOC_GENERIC(aac_pcm_op, OMX_AUDIO_PARAM_PCMMODETYPE);
 
     aac_pcm_ip->nSize               = sizeof(OMX_AUDIO_PARAM_PCMMODETYPE);
     aac_pcm_ip->nBitPerSample       = 16;        /*Will be remapped for SN. 16:2,  24:3*/
@@ -252,7 +250,7 @@
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentNeedsNALStartCode = OMX_FALSE; 
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE; 
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE;
-    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE;
+    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; 
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_TRUE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE;
 #endif
@@ -263,12 +261,12 @@
                                                PERF_ModuleAudioDecode);
 #endif
 
-    OMX_MALLOC_STRUCT(pComponentPrivate->pInputBufferList, BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pInputBufferList, BUFFERLIST);
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pInputBufferList %p\n ", pComponentPrivate->pInputBufferList);
     pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */
 
-    OMX_MALLOC_STRUCT(pComponentPrivate->pOutputBufferList, BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pOutputBufferList, BUFFERLIST);
     pComponentPrivate->pOutputBufferList->numBuffers = 0; /* initialize number of buffers */
     OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pOutputBufferList %p\n ", pComponentPrivate->pOutputBufferList);
 
@@ -283,7 +281,7 @@
     pComponentPrivate->IpBufindex = 0;
     pComponentPrivate->OpBufindex = 0;
 
-    OMX_MALLOC_STRUCT_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING), void);
+    OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING), void);
     
     /* Initialize device string to the default value */
     strcpy((char*)pComponentPrivate->sDeviceString,"/rtmdn:i2:o1/codec\0");
@@ -386,12 +384,12 @@
 #endif
         
     /* port definition, input port */
-    OMX_MALLOC_STRUCT(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
     OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: pPortDef_ip %p \n",pPortDef_ip );
 
 
     /* port definition, output port */
-    OMX_MALLOC_STRUCT(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
     OMX_PRCOMM2(pComponentPrivate->dbg, "AACENC: pPortDef_op %p,  size: %x \n",pPortDef_op, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
 
     
@@ -406,7 +404,7 @@
     pPortDef_ip->eDir                   = OMX_DirInput;
     pPortDef_ip->bEnabled               = OMX_TRUE;
     pPortDef_ip->nBufferSize            = INPUT_AACENC_BUFFER_SIZE;
-    pPortDef_ip->nBufferAlignment       = EXTRA_BYTES;
+    pPortDef_ip->nBufferAlignment       = DSP_CACHE_ALIGNMENT;
     pPortDef_ip->bPopulated             = 0;
     pPortDef_ip->format.audio.eEncoding =OMX_AUDIO_CodingPCM;  
     pPortDef_ip->eDomain                = OMX_PortDomainAudio;
@@ -418,7 +416,7 @@
     pPortDef_op->eDir                   = OMX_DirOutput;
     pPortDef_op->bEnabled               = OMX_TRUE;
     pPortDef_op->nBufferSize            = OUTPUT_AACENC_BUFFER_SIZE;
-    pPortDef_op->nBufferAlignment       = EXTRA_BYTES;
+    pPortDef_op->nBufferAlignment       = DSP_CACHE_ALIGNMENT;
     pPortDef_op->bPopulated             = 0;
     pPortDef_op->format.audio.eEncoding = OMX_AUDIO_CodingAAC;   
     pPortDef_op->eDomain                = OMX_PortDomainAudio;
@@ -435,6 +433,14 @@
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from loading ResourceManagerProxy thread\n",__LINE__);
         goto EXIT;
     }
+    pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) AACENC_ResourceManagerCallback;
+    rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource, OMX_AAC_Encoder_COMPONENT,AACENC_CPU_USAGE, 3456, &(pComponentPrivate->rmproxyCallback));
+    if (rm_error != OMX_ErrorNone) {
+        RMProxy_NewSendCommand(pHandle, RMProxy_FreeResource, OMX_AAC_Encoder_COMPONENT, 0, 3456, NULL);
+        RMProxy_Deinitalize();
+        eError = OMX_ErrorInsufficientResources;
+        goto EXIT;
+    }
 #endif
 #ifndef UNDER_CE
 #ifdef DSP_RENDERING_ON
@@ -475,8 +481,11 @@
 
     pComponentPrivate->nPendingStateChangeRequests = 0;
 
+
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting OMX_ComponentInit\n", __LINE__);
+    if (pComponentPrivate != NULL) {
+        OMX_PRINT2(pComponentPrivate->dbg, "%d :: AACENC: Exiting OMX_ComponentInit\n", __LINE__);
+    }
     return eError;
 }
 
@@ -503,10 +512,11 @@
                                    OMX_PTR pAppData)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_CONF_CHECK_CMD(pComponent,1,1);                 /* Checking for NULL pointers:  pAppData is NULL for Khronos */
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
     
-    AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering SetCallbacks\n", __LINE__);
     if (pCallBacks == NULL) 
     {
@@ -523,7 +533,9 @@
     pComponentPrivate->curState = OMX_StateLoaded;
 
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetCallbacks\n", __LINE__);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetCallbacks\n", __LINE__);
+    }
     return eError;
 }
 
@@ -601,10 +613,12 @@
                                   OMX_U32 nParam,OMX_PTR pCmdData)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    AACENC_COMPONENT_PRIVATE *pCompPrivate = NULL;
     OMX_CONF_CHECK_CMD(phandle,1,1);        /*NOTE: Cmd,  pCmdData, nParam  are  NULL  for khronos*/
     int nRet = 0;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
-    AACENC_COMPONENT_PRIVATE *pCompPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+
+    pCompPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 
 #ifdef _ERROR_PROPAGATION__
     if (pCompPrivate->curState == OMX_StateInvalid)
@@ -637,12 +651,11 @@
     switch(Cmd) 
     {
         case OMX_CommandStateSet:
-
             if (nParam == OMX_StateLoaded) 
             {
                 pCompPrivate->bLoadedCommandPending = OMX_TRUE;
             }
-        
+       
             OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand\n",__LINE__);
             OMX_PRSTATE1(pCompPrivate->dbg, "%d :: AACENC: pCompPrivate->curState = %d\n",__LINE__,pCompPrivate->curState);
             if(pCompPrivate->curState == OMX_StateLoaded)
@@ -682,30 +695,30 @@
 
         case OMX_CommandFlush:
                 OMX_PRINT1(pCompPrivate->dbg, "%d :: IAACENC: nside SendCommand\n",__LINE__);
-                if(nParam > 1 && nParam != -1)
+                if(nParam > 1 && nParam != -1) 
                 {
                     eError = OMX_ErrorBadPortIndex;
                     goto EXIT;
                 }
                 break;
-
+            
         case OMX_CommandPortDisable:
                 OMX_PRDSP2(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand OMX_CommandPortDisable\n",__LINE__);
                 break;
-
+        
         case OMX_CommandPortEnable:
                 OMX_PRDSP2(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand OMX_CommandPortEnable\n",__LINE__);
                 break;
-
+        
         case OMX_CommandMarkBuffer:
                 OMX_PRDSP2(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand OMX_CommandMarkBuffer\n",__LINE__);
-                if (nParam > 0)
+                if (nParam > 0) 
                 {
                     eError = OMX_ErrorBadPortIndex;
                     goto EXIT;
                 }
                 break;
-
+        
         default:
                 OMX_ERROR4(pCompPrivate->dbg, "%d :: Error: Command Received Default error\n",__LINE__);
                 pCompPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
@@ -723,21 +736,22 @@
     OMX_PRCOMM2(pCompPrivate->dbg, "%d :: AACENC: pCompPrivate->cmdPipe[1] = %d  \n",__LINE__,pCompPrivate->cmdPipe[1]);
     OMX_PRCOMM2(pCompPrivate->dbg, "%d :: AACENC: &Cmd = %p  \n",__LINE__,&Cmd);
 
-    if (nRet == -1)
+    if (nRet == -1) 
     {
         OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Inside SendCommand\n",__LINE__);
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
 
-    if (Cmd == OMX_CommandMarkBuffer)
+    if (Cmd == OMX_CommandMarkBuffer) 
     {
         nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData, sizeof(OMX_PTR));
-    }
-    else
+    } 
+    else 
     {
         nRet = write(pCompPrivate->cmdDataPipe[1], &nParam, sizeof(OMX_U32));
     }
+    
 
     if (nRet == -1) {
         OMX_ERROR4(pCompPrivate->dbg, "%d :: OMX_ErrorInsufficientResources from SendCommand",__LINE__);
@@ -748,10 +762,11 @@
         }
         return OMX_ErrorInsufficientResources;
     }
-
-
+    
 EXIT:
-    OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Exiting SendCommand()\n", __LINE__);
+    if (pCompPrivate != NULL) {
+	OMX_PRINT1(pCompPrivate->dbg, "%d :: AACENC: Exiting SendCommand()\n", __LINE__);
+    }
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -770,8 +785,8 @@
 static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, OMX_PTR ComponentParameterStructure)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    OMX_CONF_CHECK_CMD(hComp,1,1);
     AACENC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
+    OMX_CONF_CHECK_CMD(hComp, 1, 1);
     OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure = NULL;
 
     pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
@@ -970,7 +985,9 @@
             break;
     }
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting GetParameter:: %x  error :: %x \n",__LINE__,nParamIndex,eError);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting GetParameter:: %x  error :: %x \n", __LINE__, nParamIndex, eError);
+    }
     return eError;
 }
 
@@ -990,8 +1007,8 @@
 static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex, OMX_PTR pCompParam)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    OMX_CONF_CHECK_CMD(hComp,1,1);
     AACENC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
+    OMX_CONF_CHECK_CMD(hComp, 1, 1);
     pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
     OMX_PARAM_COMPONENTROLETYPE  *pRole = NULL;
     OMX_PARAM_BUFFERSUPPLIERTYPE sBufferSupplier;
@@ -1046,6 +1063,7 @@
             if(((OMX_AUDIO_PARAM_AACPROFILETYPE *)(pCompParam))->nPortIndex ==
                                      pComponentPrivate->pPortDef[OUTPUT_PORT]->nPortIndex) 
             {
+                OMX_CONF_CHECK_CMD(pComponentPrivate->aacParams[OUTPUT_PORT], 1, 1);
                 memcpy(pComponentPrivate->aacParams[OUTPUT_PORT], pCompParam,
                                                sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
                 OMX_PRDSP2(pComponentPrivate->dbg, "AACENC: nSampleRate %ld\n",pComponentPrivate->aacParams[OUTPUT_PORT]->nSampleRate);
@@ -1071,7 +1089,8 @@
             else if(((OMX_AUDIO_PARAM_AACPROFILETYPE *)(pCompParam))->nPortIndex ==
                                      pComponentPrivate->pPortDef[INPUT_PORT]->nPortIndex) 
             {
-                                        memcpy(pComponentPrivate->aacParams[INPUT_PORT], pCompParam,
+                OMX_CONF_CHECK_CMD(pComponentPrivate->aacParams[INPUT_PORT], 1, 1);
+                memcpy(pComponentPrivate->aacParams[INPUT_PORT], pCompParam,
                                                sizeof(OMX_AUDIO_PARAM_AACPROFILETYPE));
             }
             else 
@@ -1173,8 +1192,10 @@
             break;
     }
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetParameter:: %x\n",__LINE__,nParamIndex);
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting the SetParameter() returned eError = %d\n",__LINE__, eError);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetParameter:: %x\n", __LINE__, nParamIndex);
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting the SetParameter() returned eError = %d\n", __LINE__, eError);
+    }
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -1197,7 +1218,7 @@
     AACENC_COMPONENT_PRIVATE *pComponentPrivate =  NULL;
     TI_OMX_STREAM_INFO *streamInfo = NULL;
 
-    OMX_MALLOC_STRUCT_SIZE(streamInfo, sizeof(TI_OMX_STREAM_INFO), void);
+    OMX_MALLOC_SIZE(streamInfo, sizeof(TI_OMX_STREAM_INFO), void);
     OMXDBG_PRINT(stderr, PRINT, 1, 0, "AACENC: streamInfo %p \n",streamInfo);
     
     pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)
@@ -1222,13 +1243,9 @@
 	OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
     }
 
-    if(streamInfo)
-    {
-        OMX_MEMFREE_STRUCT(streamInfo);
-        streamInfo = NULL;
-    }
-
-EXIT:    return eError;
+EXIT:
+    OMX_MEMFREE_STRUCT(streamInfo);
+    return eError;
 }
 /*-------------------------------------------------------------------*/
 /**
@@ -1303,7 +1320,7 @@
             {
                 eError = OMX_ErrorBadParameter;
                 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: OMX_ErrorBadParameter from SetConfig\n",__LINE__);
-                
+		goto EXIT;
             }
             FramesPerOutBuf = *ptrFramesPerOutBuf;
             pComponentPrivate->FramesPer_OutputBuffer= FramesPerOutBuf;
@@ -1369,8 +1386,10 @@
         break;
     }
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetConfig\n", __LINE__);
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Returning = 0x%x\n",__LINE__,eError);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting SetConfig\n", __LINE__);
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Returning = 0x%x\n", __LINE__, eError);
+    }
     return eError;
 
 
@@ -1389,7 +1408,6 @@
 
 static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComponent, OMX_STATETYPE* pState)
 {
-
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle = NULL;
     AACENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
@@ -1419,15 +1437,15 @@
            }
 
            /* No pending state transitions */
-	   *pState = ((AACENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->curState;
+          *pState = ((AACENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->curState;
             eError = OMX_ErrorNone;
         }
         else {
-           /* Wait for component to complete state transition */
+                  /* Wait for component to complete state transition */
            clock_gettime(CLOCK_REALTIME, &abs_time);
            abs_time.tv_sec += mutex_timeout;
            abs_time.tv_nsec = 0;
-           ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
+          ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
            if (!ret) {
               /* Component has completed state transitions*/
               *pState = ((AACENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->curState;
@@ -1446,7 +1464,7 @@
      else {
         eError = OMX_ErrorInvalidComponent;
         *pState = OMX_StateInvalid;
-    }
+     }
 
     return eError;
 
@@ -1473,12 +1491,13 @@
                                       OMX_BUFFERHEADERTYPE* pBuffer)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_CONF_CHECK_CMD(pComponent,pBuffer,1);
     int ret = 0;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
-    AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
 
+    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering EmptyThisBuffer\n", __LINE__);
 
     pPortDef = ((AACENC_COMPONENT_PRIVATE*) 
@@ -1551,7 +1570,9 @@
     pComponentPrivate->EmptythisbufferCount++;
 
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting EmptyThisBuffer\n", __LINE__);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting EmptyThisBuffer\n", __LINE__);
+    }
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -1572,13 +1593,13 @@
                                      OMX_BUFFERHEADERTYPE* pBuffer)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_CONF_CHECK_CMD(pComponent,pBuffer,1);
     int ret = 0;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
-    AACENC_COMPONENT_PRIVATE *pComponentPrivate =
-                         (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL;
 
+    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Entering FillThisBuffer\n", __LINE__);
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, "\n------------------------------------------\n\n");
@@ -1661,7 +1682,9 @@
     pComponentPrivate->FillthisbufferCount++;
 
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting FillThisBuffer error= %d \n", __LINE__,eError);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: AACENC: Exiting FillThisBuffer error= %d \n", __LINE__, eError);
+    }
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -1678,10 +1701,11 @@
 static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    struct OMX_TI_Debug dbg = {0};
+    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_CONF_CHECK_CMD(pHandle,1,1);
     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
-    AACENC_COMPONENT_PRIVATE *pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
-    struct OMX_TI_Debug dbg;
+    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
     dbg = pComponentPrivate->dbg;
 
     OMX_PRINT1(dbg, "%d :: AACENC: ComponentDeInit\n",__LINE__);
@@ -1820,14 +1844,15 @@
     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);
@@ -1841,83 +1866,80 @@
     {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
-    }
+    }   
 #endif
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedBuffer(pComponentPrivate->pPERF,(*pBuffer)->pBuffer,nSizeBytes,PERF_ModuleMemory);
 #endif
-    if (pPortDef->bPopulated)
+     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);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader %p\n",pBufferHeader);
 
-    OMX_MALLOC_STRUCT_SIZE(pBufferHeader->pBuffer, nSizeBytes + 256, OMX_U8);
+    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes, OMX_U8);
 
-    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;
     }
     else
-    {
-        pBufferList = pComponentPrivate->pOutputBufferList;
-        pBufferHeader->nInputPortIndex = -1;
-        pBufferHeader->nOutputPortIndex = nPortIndex;
+     {
+         pBufferList = pComponentPrivate->pOutputBufferList;
+         pBufferHeader->nInputPortIndex = -1;
+         pBufferHeader->nOutputPortIndex = nPortIndex;
     }
     pBufferList->pBufHdr[pBufferList->numBuffers] = pBufferHeader;
     pBufferList->bBufferPending[pBufferList->numBuffers] = 0;
     pBufferList->bufferOwner[pBufferList->numBuffers++] = 1;
     if (pBufferList->numBuffers == pPortDef->nBufferCountActual)
-    {
-        pPortDef->bPopulated = OMX_TRUE;
+    {  
+       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);
@@ -1935,7 +1957,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);
     }
@@ -1945,9 +1967,14 @@
 #endif
 
 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);
+    if (pComponentPrivate != NULL) {
+	OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC:  AllocateBuffer returning eError =  %d\n", __LINE__, eError);
+
+	OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader = %p\n", pBufferHeader);
+	if (pBufferHeader != NULL) {
+	    OMX_PRBUFFER2(pComponentPrivate->dbg, "AACENC: pBufferHeader->pBuffer = %p\n", pBufferHeader->pBuffer);
+	}
+    }
     return eError;
 }
 
@@ -1978,19 +2005,20 @@
     AACENC_COMPONENT_PRIVATE *pComponentPrivate = ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
 
     OMX_PRINT1 (pComponentPrivate->dbg, "%d :: AACENC: FreeBuffer for port index %ld\n", __LINE__, nPortIndex);
-
+    
     if (nPortIndex != INPUT_PORT && nPortIndex != OUTPUT_PORT)
     {
         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)
+        if (buffHdr == pBuffer) 
         {
             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);
@@ -1998,7 +2026,7 @@
             bufferIndex = i;
             break;
         }
-        else
+        else 
         {
             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: This is not a match\n",__LINE__);
             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: buffHdr = %p\n",__LINE__,buffHdr);
@@ -2006,28 +2034,22 @@
         }
     }
 
-    if (bufferIndex == -1)
+
+    if (bufferIndex == -1) 
     {
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: AACENC: Error - could not find match for buffer %p\n",__LINE__, pBuffer);
         return OMX_ErrorBadParameter;
     }
-
+    
     if (pBuffList->bufferOwner[bufferIndex] == 1)
     {
-        tempBuff = buffHdr->pBuffer;
-        if (tempBuff != 0)
-        {
-            tempBuff -= 128;
-        }
-
+            OMX_MEMFREE_STRUCT_DSPALIGN(buffHdr->pBuffer, OMX_U8);
 #ifdef __PERF_INSTRUMENTATION__
-        PERF_SendingBuffer(pComponentPrivate->pPERF,
-                           buffHdr->pBuffer,
-                           buffHdr->nAllocLen,
-                           PERF_ModuleMemory);
+            PERF_SendingBuffer(pComponentPrivate->pPERF,
+                               pBufHdr->pBuffer, 
+                               pBufHdr->nAllocLen,
+                               PERF_ModuleMemory);
 #endif
-
-        OMX_MEMFREE_STRUCT(tempBuff);
     }
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: AACENC: [FREE] %p\n",__LINE__, buffHdr);
     OMX_MEMFREE_STRUCT(buffHdr);
@@ -2053,12 +2075,11 @@
                                               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);
@@ -2068,8 +2089,7 @@
 #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);
     }
@@ -2109,6 +2129,7 @@
         OMX_ERROR4(pComponentPrivate->dbg, "UseBuffer: Error - Unknown port index %ld", nPortIndex);
         return OMX_ErrorBadPortIndex;
     }
+
     pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)
             (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
@@ -2126,10 +2147,10 @@
                             PERF_ModuleHLMM);
 #endif
 
-
     pPortDef = ((AACENC_COMPONENT_PRIVATE*)
                     pComponentPrivate)->pPortDef[nPortIndex];
-    if (!pPortDef->bEnabled || pPortDef->bPopulated)
+
+    if(!pPortDef->bEnabled || pPortDef->bPopulated) 
     {
         if (!pPortDef->bEnabled)
         {
@@ -2146,22 +2167,23 @@
     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)
+    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);
+    OMX_MALLOC_GENERIC(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;
-    } else {
+    } else {         
         pBufferList = pComponentPrivate->pInputBufferList;
         pBufferHeader->nInputPortIndex = nPortIndex;
         pBufferHeader->nOutputPortIndex = -1;
@@ -2171,7 +2193,7 @@
     pBufferList->bufferOwner[pBufferList->numBuffers++] = 0;
     if (pBufferList->numBuffers == pPortDef->nBufferCountActual)
     {
-        pPortDef->bPopulated = OMX_TRUE;
+         pPortDef->bPopulated = OMX_TRUE;
     }
 
     if((pComponentPrivate->pPortDef[OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled)&&
@@ -2205,8 +2227,12 @@
     }
 
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "AACENC: [UseBuffer] pBufferHeader = %p\n",pBufferHeader);
-    OMX_PRINT1(pComponentPrivate->dbg, "AACENC: [UseBuffer] pBufferHeader->pBuffer = %p\n",pBufferHeader->pBuffer);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "AACENC: [UseBuffer] pBufferHeader = %p\n", pBufferHeader);
+	if (pBufferHeader != NULL) {
+	    OMX_PRINT1(pComponentPrivate->dbg, "AACENC: [UseBuffer] pBufferHeader->pBuffer = %p\n", pBufferHeader->pBuffer);
+	}
+    }
 
     return eError;
 }
@@ -2231,7 +2257,6 @@
     if (!(strcmp(cParameterName,"OMX.TI.index.config.aacencHeaderInfo"))) 
     {
         *pIndexType = OMX_IndexCustomAacEncHeaderInfoConfig;
-        OMXDBG_PRINT(stderr, PRINT, 1, 0, "OMX_IndexCustomAacEncHeaderInfoConfig\n");
     }
     else if(!(strcmp(cParameterName,"OMX.TI.index.config.aacencstreamIDinfo"))) 
     {
@@ -2249,13 +2274,11 @@
     {
         *pIndexType =OMX_IndexCustomDebug;
     }
-    else
+    else 
     {
         eError = OMX_ErrorBadParameter;
     }
 
-    OMXDBG_PRINT(stderr, PRINT, 1, 0, "AACENC: Exiting GetExtensionIndex\n");
-
     return eError;
 }
 
@@ -2274,16 +2297,20 @@
       OMX_IN OMX_U32 nIndex)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    AACENC_COMPONENT_PRIVATE *pComponentPrivate = ((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate;
+    AACENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
+    pComponentPrivate = (AACENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     if(nIndex == 0)
     {
+      OMX_CONF_CHECK_CMD(cRole, 1, 1);
       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/aac_enc/tests/Android.mk b/omx/audio/src/openmax_il/aac_enc/tests/Android.mk
index f3da9a4..977007f 100644
--- a/omx/audio/src/openmax_il/aac_enc/tests/Android.mk
+++ b/omx/audio/src/openmax_il/aac_enc/tests/Android.mk
@@ -1,4 +1,3 @@
-ifeq ($(BUILD_AAC_ENC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -20,4 +19,3 @@
 LOCAL_MODULE:= AacEncoder_Test

 

 include $(BUILD_EXECUTABLE)

-endif

diff --git a/omx/audio/src/openmax_il/g711_dec/inc/OMX_G711Dec_Utils.h b/omx/audio/src/openmax_il/g711_dec/inc/OMX_G711Dec_Utils.h
index 9fe23fb..ce994f1 100755
--- a/omx/audio/src/openmax_il/g711_dec/inc/OMX_G711Dec_Utils.h
+++ b/omx/audio/src/openmax_il/g711_dec/inc/OMX_G711Dec_Utils.h
@@ -46,6 +46,10 @@
 #include <OMX_Component.h>
 #include <pthread.h>
 
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
+
 
 /* ======================================================================= */
 /**
@@ -336,8 +340,8 @@
     G711DEC_MEMPRINT("%d :: Malloced = %p\n",__LINE__,_ptr_);
 
 #define OMX_G711DECMEMFREE_STRUCT(_pStruct_)                    \
-    G711DEC_MEMPRINT("%d :: [FREE] %p\n",__LINE__,_pStruct_);   \
     if(_pStruct_ != NULL){                                      \
+    G711DEC_MEMPRINT("%d :: [FREE] %p\n",__LINE__,_pStruct_);   \
         newfree(_pStruct_);                                     \
         _pStruct_ = NULL;                                       \
     }
@@ -783,6 +787,9 @@
     /** Index to arrBufIndex[], used for output buffer timestamps */
     OMX_U8 OpBufindex;
 
+    /** Number of input buffers at runtime **/
+    OMX_U32 nRuntimeInputBuffers;
+
     /** Pointer to RM callback **/
 #ifdef RESOURCE_MANAGER_ENABLED
     RMPROXY_CALLBACKTYPE rmproxyCallback;
diff --git a/omx/audio/src/openmax_il/g711_dec/inc/OMX_G711Decoder.h b/omx/audio/src/openmax_il/g711_dec/inc/OMX_G711Decoder.h
index 5da3637..d8db0da 100755
--- a/omx/audio/src/openmax_il/g711_dec/inc/OMX_G711Decoder.h
+++ b/omx/audio/src/openmax_il/g711_dec/inc/OMX_G711Decoder.h
@@ -47,10 +47,18 @@
 #include <pthread.h>
 
 #ifndef UNDER_CE
+
+#ifdef DSP_RENDERING_ON
 #include <AudioManagerAPI.h>
+#endif
+
+#ifdef RESOURCE_MANAGER_ENABLED
 #include <ResourceManagerProxyAPI.h>
 #endif
 
+#endif
+
+
 /* ======================================================================= */
 /**
  * @def    EXTRA_BUFFBYTES                Num of Extra Bytes to be allocated
@@ -255,8 +263,8 @@
     G711DEC_MEMPRINT("%d :: Malloced = %p\n",__LINE__,_ptr_);
 
 #define OMX_G711DECMEMFREE_STRUCT(_pStruct_)                    \
-    G711DEC_MEMPRINT("%d :: [FREE] %p\n",__LINE__,_pStruct_);   \
     if(_pStruct_ != NULL){                                      \
+    G711DEC_MEMPRINT("%d :: [FREE] %p\n",__LINE__,_pStruct_);   \
         newfree(_pStruct_);                                     \
         _pStruct_ = NULL;                                       \
     }
@@ -706,7 +714,10 @@
     OMX_U8 OpBufindex;
 
     /** Pointer to RM callback **/
+#ifdef RESOURCE_MANAGER_ENABLED
     RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
     OMX_BOOL bPreempted;
 
     
@@ -720,6 +731,8 @@
     OMX_IndexCustomG711DecDataPath
 }OMX_G711DEC_INDEXAUDIOTYPE;
 
+#ifdef RESOURCE_MANAGER_ENABLED
 void G711DEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
 
 #endif /* OMX_G711DECODER_H */
diff --git a/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Dec_ComponentThread.c b/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Dec_ComponentThread.c
index 739ed93..e589f91 100755
--- a/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Dec_ComponentThread.c
+++ b/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Dec_ComponentThread.c
@@ -120,7 +120,8 @@
                                                     OMX_EventError,
                                                     OMX_ErrorInsufficientResources,0,
                                                     "Error from COmponent Thread in select");
-            exit(1);
+            eError = OMX_ErrorInsufficientResources;
+
         } else if (FD_ISSET(pComponentPrivate->dataPipe[0], &rfds)){
             G711DEC_DPRINT ("%d :: DATA pipe is set in Component Thread\n",__LINE__);
             ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader));
@@ -162,5 +163,5 @@
     }
  EXIT:
     G711DEC_DPRINT("%d::Exiting ComponentThread\n",__LINE__);
-    return (void*)OMX_ErrorNone;
+    return (void*)eError;
 }
diff --git a/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Dec_Utils.c b/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Dec_Utils.c
index 3d7975c..fe23b85 100755
--- a/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Dec_Utils.c
+++ b/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Dec_Utils.c
@@ -139,6 +139,7 @@
 
     nIpBuf = (OMX_U16)pComponentPrivate->pInputBufferList->numBuffers;
     nIpBufSize = pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]->nBufferSize;
+    pComponentPrivate->nRuntimeInputBuffers = nIpBuf;
     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
     nOpBufSize = pComponentPrivate->pPortDef[G711DEC_OUTPUT_PORT]->nBufferSize;
 
@@ -327,7 +328,9 @@
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->strmAttr);
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[G711DEC_INPUT_PORT]);
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[G711DEC_OUTPUT_PORT]);
-        OMX_G711DECMEMFREE_STRUCT(pTemp_lcml->pIpParam);
+	if (pTemp_lcml != NULL) {
+	    OMX_G711DECMEMFREE_STRUCT(pTemp_lcml->pIpParam);
+	}
     }
         
     return eError;
@@ -486,6 +489,9 @@
 
 
     }
+
+    OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
+
     if (pComponentPrivate->bPortDefsAllocated) {
         G711DEC_DPRINT("%d:::[G711DEC_FreeCompResources] \n", __LINE__);
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pPortDef[G711DEC_INPUT_PORT]);
@@ -498,6 +504,7 @@
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT] );
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
+        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pParams);
     }
     
     pComponentPrivate->bPortDefsAllocated = 0;
@@ -530,6 +537,7 @@
         pHandle->pComponentPrivate;
 
     LCML_G711DEC_BUFHEADERTYPE *pTemp_lcml = NULL;
+    OMX_U8 *pBufParmsTemp = NULL;
 
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 nIpBuf = 0;
@@ -537,16 +545,21 @@
 
     G711DEC_DPRINT ("%d :: G711DEC_CleanupInitParams()\n", __LINE__);
     
-    nIpBuf = (OMX_U16)pComponentPrivate->pInputBufferList->numBuffers;
+    nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->strmAttr);
 
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[G711DEC_INPUT_PORT];
     
     for(i=0; i<nIpBuf; i++) {
         OMX_G711DECMEMFREE_STRUCT(pTemp_lcml->pIpParam);
+        OMX_G711DECMEMFREE_STRUCT(pTemp_lcml->pBufferParam);
+        OMX_G711DECMEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
+        pBufParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam;
+        pBufParmsTemp -= 128;
+        OMX_G711DECMEMFREE_STRUCT(pBufParmsTemp);
         pTemp_lcml++;
     }
-    
+
     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[G711DEC_INPUT_PORT]);
     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[G711DEC_OUTPUT_PORT]);
 
@@ -790,7 +803,7 @@
                 pComponentPrivate->rmproxyCallback.RMPROXY_Callback = 
                     (void *) G711DEC_ResourceManagerCallback;
                     
-                if (pComponentPrivate->curState != OMX_StateWaitForResources){                
+                if (pComponentPrivate->curState != OMX_StateWaitForResources){
                     rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource, 
                                                       OMX_PCM_Decoder_COMPONENT, 
                                                       OMX_G711DEC_CPU,
@@ -1588,8 +1601,11 @@
                     
                     /* Shift the remaining bytes to the beginning of the pHoldBuffer */
                     pExtraData = pComponentPrivate->pHoldBuffer + frameLength;
+                    if (frameLength >= pComponentPrivate->nHoldLength)
+                        memcpy(pComponentPrivate->pHoldBuffer,pExtraData, pComponentPrivate->nHoldLength);
+                    else
+                        memmove(pComponentPrivate->pHoldBuffer,pExtraData, pComponentPrivate->nHoldLength);
 
-                    memcpy(pComponentPrivate->pHoldBuffer,pExtraData, pComponentPrivate->nHoldLength);
 
                     /* Clear the rest of the data from the pHoldBuffer */
                     pExtraData = pComponentPrivate->pHoldBuffer + pComponentPrivate->nHoldLength;
@@ -1956,6 +1972,12 @@
 
                     if ( pComponentPrivate->nHoldLength >= frameLength ) {
                         /* Copy the data from iHoldBuffer to dataPtr */
+                        if ((msgBuffer->buffer->pBuffer == NULL) ||
+                           (pComponentPrivate->pHoldBuffer == NULL)) {
+                           eError = OMX_ErrorBadParameter;
+			   goto EXIT;
+			}
+
                         memcpy(msgBuffer->buffer->pBuffer,
                                pComponentPrivate->pHoldBuffer,
                                frameLength);
@@ -2198,7 +2220,7 @@
             }
         }
     } else if (event == EMMCodecStrmCtrlAck) {
-        LCML_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__);
+        G711DEC_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__);
     }
     else if(event == EMMCodecProcessingStoped) {
         G711DEC_DPRINT("pComponentPrivate_CC->bNoIdleOnStop = %d\n",(int)pComponentPrivate_CC->bNoIdleOnStop);
@@ -2656,7 +2678,9 @@
     {
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[G711DEC_INPUT_PORT]);
         OMX_G711DECMEMFREE_STRUCT(strmAttr);
-        OMX_G711DECMEMFREE_STRUCT(pTemp_lcml->pIpParam);
+	if (pTemp_lcml != NULL) {
+	    OMX_G711DECMEMFREE_STRUCT(pTemp_lcml->pIpParam);
+	}
         OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[G711DEC_OUTPUT_PORT]);
     }
     return eError;
diff --git a/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Decoder.c b/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Decoder.c
index f29e8a8..dd611de 100755
--- a/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Decoder.c
+++ b/omx/audio/src/openmax_il/g711_dec/src/OMX_G711Decoder.c
@@ -83,7 +83,7 @@
 #define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
 void * mymalloc(int line, char *s, int size);
 #define newfree(z) myfree(z,__LINE__,__FILE__)
-int myfree(void *dp, int line, char *s);
+void myfree(void *dp, int line, char *s);
 #else
 #define newmalloc(x) malloc(x)
 #define newfree(z) free(z)
@@ -299,6 +299,7 @@
     pComponentPrivate->bIdleCommandPending = 0;
     pComponentPrivate->bDisableCommandParam = 0;
     pComponentPrivate->bEnableCommandParam = 0;
+    pComponentPrivate->nRuntimeInputBuffers = 0;
     
     for (i=0; i < MAX_NUM_OF_BUFS; i++) {
         pComponentPrivate->pInputBufHdrPending[i] = NULL;
@@ -449,16 +450,18 @@
  EXIT:
     if(eError == OMX_ErrorInsufficientResources)
     {
-        OMX_G711DECMEMFREE_STRUCT(pHandle->pComponentPrivate);
         OMX_G711DECMEMFREE_STRUCT(g711_ip);
         OMX_G711DECMEMFREE_STRUCT(g711_op);
-        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
-        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
-        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat);
-        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat);        
-        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]);
-        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]);
-        OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
+	 if (pComponentPrivate != NULL) {
+	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
+	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
+	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]->pPortFormat);
+	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]->pPortFormat);
+	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_INPUT_PORT]);
+	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->pCompPort[G711DEC_OUTPUT_PORT]);
+	     OMX_G711DECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
+	 }
+	 OMX_G711DECMEMFREE_STRUCT(pHandle->pComponentPrivate);
         OMX_G711DECMEMFREE_STRUCT(pPortDef_ip);
         OMX_G711DECMEMFREE_STRUCT(pPortDef_op);
 
@@ -1049,8 +1052,8 @@
 
     pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)
         (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
-
-    memcpy(ComponentConfigStructure,pComponentPrivate,sizeof(G711DEC_COMPONENT_PRIVATE));
+    if ((pComponentPrivate != NULL) && (ComponentConfigStructure != NULL))
+        memcpy(ComponentConfigStructure,pComponentPrivate,sizeof(G711DEC_COMPONENT_PRIVATE));
 
     return eError;
 }
@@ -1075,8 +1078,7 @@
     OMX_S16* deviceString = NULL;
     TI_OMX_DATAPATH dataPath;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
-    G711DEC_COMPONENT_PRIVATE *pComponentPrivate =
-        (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    G711DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     
     int *customFlag = NULL;
     TI_OMX_DSP_DEFINITION *configData = NULL; 
@@ -1092,6 +1094,7 @@
         goto EXIT;
     }
 
+    pComponentPrivate = (G711DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     switch (nConfigIndex) {
     case  OMX_IndexCustomG711DecHeaderInfoConfig:
         {
@@ -2020,7 +2023,7 @@
     }
 }
 
-int myfree(void *dp, int line, char *s){
+void myfree(void *dp, int line, char *s){
     int q = 0;
     for(q=0;q<500;q++){
         if(arr[q]==dp){
diff --git a/omx/audio/src/openmax_il/g711_dec/tests/Android.mk b/omx/audio/src/openmax_il/g711_dec/tests/Android.mk
index b28b29a..1421b8d 100755
--- a/omx/audio/src/openmax_il/g711_dec/tests/Android.mk
+++ b/omx/audio/src/openmax_il/g711_dec/tests/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_G711_DEC_TEST),1)
+ifeq ($(BUILD_G711_DEC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -21,4 +21,4 @@
 LOCAL_MODULE:= G711Decoder_Test

 

 include $(BUILD_EXECUTABLE)

-endif
+endif

diff --git a/omx/audio/src/openmax_il/g711_enc/inc/OMX_G711Enc_Utils.h b/omx/audio/src/openmax_il/g711_enc/inc/OMX_G711Enc_Utils.h
index 4f0dbf4..b97f30a 100755
--- a/omx/audio/src/openmax_il/g711_enc/inc/OMX_G711Enc_Utils.h
+++ b/omx/audio/src/openmax_il/g711_enc/inc/OMX_G711Enc_Utils.h
@@ -51,13 +51,13 @@
 #include "LCML_DspCodec.h"
 #include <TIDspOmx.h>
 
-/*#ifdef DSP_RENDERING_ON
+#ifdef DSP_RENDERING_ON
 #include <AudioManagerAPI.h>
-#endif*/
+#endif
 
-/*#ifndef UNDER_CE
-  #include <ResourceManagerProxyAPI.h>
-  #endif*/
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 
 #ifdef UNDER_CE
 #define sleep Sleep
@@ -167,8 +167,8 @@
     (_s_)->nVersion.s.nStep = 0x0
 
 #define OMX_G711ENC_MEMFREE_STRUCT(_pStruct_)                   \
-    G711ENC_MEMPRINT("%d :: [FREE] %p\n",__LINE__,_pStruct_);   \
     if(_pStruct_ != NULL){                                      \
+    G711ENC_MEMPRINT("%d :: [FREE] %p\n",__LINE__,_pStruct_);   \
         free(_pStruct_);                                        \
         _pStruct_ = NULL;                                       \
     }
@@ -238,16 +238,20 @@
 #define G711ENC_OUTPUT_BUFFER_SIZE 80
 /* ======================================================================= */
 /**
- * @def G711ENC_INPUT_FRAME_SIZE   Default output buffer size
+ * @def G711ENC_INPUT_FRAME_SIZE   Default input buffer size
  */
 /* ======================================================================= */
 #define G711ENC_INPUT_FRAME_SIZE 160
+#define G711ENC_INPUT_FRAME_SIZE_20MS 320
+#define G711ENC_INPUT_FRAME_SIZE_30MS 480
 /* ======================================================================= */
 /**
  * @def G711ENC_OUTPUT_FRAME_SIZE   Default output buffer size
  */
 /* ======================================================================= */
 #define G711ENC_OUTPUT_FRAME_SIZE 80
+#define G711ENC_OUTPUT_FRAME_SIZE_20MS 160
+#define G711ENC_OUTPUT_FRAME_SIZE_30MS 240
 /* ======================================================================= */
 /**
  * @def G711ENC_APP_ID  App ID Value setting
@@ -824,7 +828,12 @@
     OMX_U8 InLoaded_readytoidle;
 #endif
 
-    OMX_BOOL bPreempted;    
+    OMX_BOOL bPreempted;
+
+    /** Pointer to RM callback **/
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
 
 } G711ENC_COMPONENT_PRIVATE;
 
@@ -1131,4 +1140,11 @@
 /*================================================================== */
 void* G711ENC_CompThread(void* pThreadData);
 
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G711ENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
+
 #endif  /* OMX_G711ENC_UTILS__H */
diff --git a/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Enc_ComponentThread.c b/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Enc_ComponentThread.c
index 68e94ac..66ca4ce 100755
--- a/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Enc_ComponentThread.c
+++ b/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Enc_ComponentThread.c
@@ -142,7 +142,7 @@
                                                      OMX_ErrorInsufficientResources,
                                                      0,
                                                      "Error from CompThread in select");
-            exit(1);
+            eError = OMX_ErrorInsufficientResources;
 
         }
 
@@ -188,5 +188,5 @@
  EXIT:
     G711ENC_DPRINT("%d :: Exiting G711ENC_CompThread\n", __LINE__);
     G711ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);
-    return (void*)OMX_ErrorNone;
+    return (void*)eError;
 }
diff --git a/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Enc_Utils.c b/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Enc_Utils.c
index bc40775..dcff28e 100755
--- a/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Enc_Utils.c
+++ b/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Enc_Utils.c
@@ -481,6 +481,8 @@
     OMX_U32 i = 0;
     OMX_U8* pParmsTemp = NULL;
     G711ENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
+    OMX_U8 *pBufParmsTemp = NULL;
+    OMX_U8 *pFrameParmsTemp = NULL;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     G711ENC_COMPONENT_PRIVATE *pComponentPrivate = (G711ENC_COMPONENT_PRIVATE *)
         pHandle->pComponentPrivate;
@@ -500,6 +502,13 @@
     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
     for(i=0; i<nIpBuf; i++) {
         OMX_G711ENC_MEMFREE_STRUCT(pTemp_lcml->pIpParam);
+        pBufParmsTemp = (OMX_U8*)pTemp_lcml->pBufferParam; 
+        pBufParmsTemp -=EXTRA_BYTES;
+        OMX_G711ENC_MEMFREE_STRUCT(pBufParmsTemp);
+        OMX_G711ENC_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
+        pFrameParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam; 
+        pFrameParmsTemp -=EXTRA_BYTES;
+        OMX_G711ENC_MEMFREE_STRUCT(pFrameParmsTemp); 
         pTemp_lcml++;
     }
 
@@ -507,6 +516,11 @@
     nOpBuf =  pComponentPrivate->nRuntimeOutputBuffers;
     for(i=0; i<nOpBuf; i++) {
         OMX_G711ENC_MEMFREE_STRUCT(pTemp_lcml->pOpParam);
+        OMX_G711ENC_MEMFREE_STRUCT(pTemp_lcml->pBufferParam);
+        OMX_G711ENC_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
+        pBufParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam; 
+        pBufParmsTemp -=EXTRA_BYTES;
+        OMX_G711ENC_MEMFREE_STRUCT(pBufParmsTemp);
         pTemp_lcml++;
     }
 
@@ -1391,8 +1405,10 @@
     OMX_U8 nFrames = 0,i = 0;
     LCML_DSP_INTERFACE * phandle = NULL;
     OMX_U8* pBufParmsTemp = NULL;
-    OMX_U32 frameLength = 0;
-    
+
+    OMX_U32 frameLength_in;
+    OMX_U32 frameLength_out;
+
     LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *) pComponentPrivate->pLcmlHandle;
     G711ENC_DPRINT ("%d :: Entering G711ENC_HandleDataBufFromApp Function\n",__LINE__);
     /*Find the direction of the received buffer from buffer list */
@@ -1416,9 +1432,22 @@
                     G711ENC_DPRINT("%d :: Error: Invalid Buffer Came ...\n",__LINE__);
                     goto EXIT;
                 }
-                
-                frameLength = G711ENC_INPUT_FRAME_SIZE;  
-                nFrames = (OMX_U8)(pBufHeader->nFilledLen / frameLength);
+                switch (pComponentPrivate->frametype) {
+                case 0:
+                  frameLength_in = G711ENC_INPUT_FRAME_SIZE;
+                  break;
+                case 1:
+                  frameLength_in = G711ENC_INPUT_FRAME_SIZE_20MS;
+                  break;
+                case 2:
+                  frameLength_in = G711ENC_INPUT_FRAME_SIZE_30MS;
+                  break;
+                default:
+                  frameLength_in = G711ENC_INPUT_FRAME_SIZE;
+                  break;
+                }
+
+                nFrames = (OMX_U8)(pBufHeader->nFilledLen / frameLength_in);
                 pComponentPrivate->nNumOfFramesSent = nFrames;
                 phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 
@@ -1556,6 +1585,21 @@
             goto EXIT;
         }
 
+        switch (pComponentPrivate->frametype) {
+        case 0:
+          frameLength_out = G711ENC_OUTPUT_FRAME_SIZE;
+          break;
+        case 1:
+          frameLength_out = G711ENC_OUTPUT_FRAME_SIZE_20MS;
+          break;
+        case 2:
+          frameLength_out = G711ENC_OUTPUT_FRAME_SIZE_30MS;
+          break;
+        default:
+          frameLength_out = G711ENC_OUTPUT_FRAME_SIZE;
+          break;
+        }
+
         phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 
         if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && 
@@ -1608,7 +1652,7 @@
                         eError = LCML_QueueBuffer( pLcmlHandle->pCodecinterfacehandle,
                                                    EMMCodecOuputBuffer,
                                                    (OMX_U8 *)pBufHeader->pBuffer,
-                                                   G711ENC_OUTPUT_FRAME_SIZE * nFrames,
+                                                   frameLength_out * nFrames,
                                                    0,
                                                    (OMX_U8 *) pLcmlHdr->pBufferParam,
                                                    sizeof(G711ENC_ParamStruct),
@@ -2605,4 +2649,35 @@
     return eError;
 }
 
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G711ENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+{
+    OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
+    OMX_STATETYPE state = OMX_StateIdle;
+    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
+    G711ENC_COMPONENT_PRIVATE *pCompPrivate = NULL;
+
+    pCompPrivate = (G711ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+
+    if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted){
+        if (pCompPrivate->curState == OMX_StateExecuting || 
+            pCompPrivate->curState == OMX_StatePause) {
+
+            write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
+            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
+
+            pCompPrivate->bPreempted = 1;
+        }
+    }
+    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
+        pCompPrivate->cbInfo.EventHandler ( pHandle, 
+                                            pHandle->pApplicationPrivate,
+                                            OMX_EventResourcesAcquired, 
+                                            0, 0, NULL);
+    }
+}
+#endif
 
diff --git a/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Encoder.c b/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Encoder.c
index 8c60c6e..b10ee7a 100755
--- a/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Encoder.c
+++ b/omx/audio/src/openmax_il/g711_enc/src/OMX_G711Encoder.c
@@ -690,6 +690,10 @@
 
     switch(nParamIndex){
     case OMX_IndexParamAudioInit:
+        if (pComponentPrivate->sPortParam == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+        }
         G711ENC_DPRINT("%d :: GetParameter OMX_IndexParamAudioInit \n",__LINE__);
         memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
@@ -772,6 +776,10 @@
 
     case OMX_IndexParamPriorityMgmt:
         G711ENC_DPRINT("%d :: GetParameter OMX_IndexParamPriorityMgmt \n",__LINE__);
+        if (pComponentPrivate->sPriorityMgmt == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+	}
         memcpy(ComponentParameterStructure, pComponentPrivate->sPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
         
@@ -853,10 +861,20 @@
         G711ENC_DPRINT("%d :: SetParameter OMX_IndexParamAudioG711 \n",__LINE__);
         pCompG711Param = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
         if (pCompG711Param->nPortIndex == OMX_DirOutput) {
+            if (((G711ENC_COMPONENT_PRIVATE *)
+                    pHandle->pComponentPrivate)->G711Params[G711ENC_OUTPUT_PORT] == NULL) {
+                eError = OMX_ErrorBadParameter;
+		break;
+            }  
             memcpy(((G711ENC_COMPONENT_PRIVATE *)
                     pHandle->pComponentPrivate)->G711Params[G711ENC_OUTPUT_PORT], pCompG711Param, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
         }
         else if (pCompG711Param->nPortIndex == OMX_DirInput) {
+            if (((G711ENC_COMPONENT_PRIVATE *)
+                    pHandle->pComponentPrivate)->G711Params[G711ENC_INPUT_PORT] == NULL) {
+                eError = OMX_ErrorBadParameter;
+		break;
+            }  
             memcpy(((G711ENC_COMPONENT_PRIVATE *)
                     pHandle->pComponentPrivate)->G711Params[G711ENC_INPUT_PORT], pCompG711Param, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
         }
@@ -886,11 +904,19 @@
         }
         break;
     case OMX_IndexParamPriorityMgmt:
+	if (pComponentPrivate->sPriorityMgmt == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+	}
         G711ENC_DPRINT("%d :: SetParameter OMX_IndexParamPriorityMgmt \n",__LINE__);
         memcpy(pComponentPrivate->sPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
     case OMX_IndexParamAudioInit:
+	if (pComponentPrivate->sPortParam == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+	}
         G711ENC_DPRINT("%d :: SetParameter OMX_IndexParamAudioInit \n",__LINE__);
         memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
@@ -978,10 +1004,10 @@
                                 OMX_PTR ComponentConfigStructure)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    G711ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
     TI_OMX_DSP_DEFINITION *pTiDspDefinition = NULL;
     G711ENC_FTYPES *confFrameParams = NULL;
-    G711ENC_COMPONENT_PRIVATE *pComponentPrivate =(G711ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     TI_OMX_DATAPATH dataPath;
     OMX_S16 *customFlag = NULL;
     
@@ -992,6 +1018,7 @@
         goto EXIT;
     }
 
+    pComponentPrivate = (G711ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     G711ENC_DPRINT("Index: %x \n",nConfigIndex);
     switch (nConfigIndex) {
 
@@ -1085,8 +1112,7 @@
         *pState = OMX_StateLoaded;
     }
     eError = OMX_ErrorNone;
-    G711ENC_DPRINT("State = %d \n",((G711ENC_COMPONENT_PRIVATE*)
-                                    pHandle->pComponentPrivate)->curState );
+    G711ENC_DPRINT("State = %d \n", (*pState));
 
  EXIT:
     G711ENC_DPRINT("%d :: Exiting GetState\n", __LINE__);
diff --git a/omx/audio/src/openmax_il/g711_enc/tests/G711EncTest.c b/omx/audio/src/openmax_il/g711_enc/tests/G711EncTest.c
index 2839c6d..214800a 100755
--- a/omx/audio/src/openmax_il/g711_enc/tests/G711EncTest.c
+++ b/omx/audio/src/openmax_il/g711_enc/tests/G711EncTest.c
@@ -572,7 +572,7 @@
         audioinfo->nIpBufSize = atoi(argv[8]);
         APP_DPRINT("%d [TEST APP] input buffer size = %ld \n",__LINE__,audioinfo->nIpBufSize);
         audioinfo->nOpBufs = atoi(argv[9]);
-        if(audioinfo->nOpBufs > 4 && audioinfo->nOpBufs < 0){
+        if(audioinfo->nOpBufs > 4){
             APP_DPRINT( "Cannot support %ld Output buffers\n", audioinfo->nOpBufs);
             goto EXIT;          
         }        
@@ -1232,35 +1232,29 @@
                     nOutBuff++;
                     OMX_FillThisBuffer(pHandle, pBuf);
                     APP_DPRINT("%d [TEST APP] pBuf->nFlags = %ld\n",__LINE__, pBuf->nFlags);
-
-                    if(pBuf->nFlags == 1) {
-                        APP_DPRINT("%d [TEST APP] Sending OMX_StateIdle.........From APP \n",__LINE__);
-#ifdef OMX_GETTIME
-                        GT_START();
-#endif
-                        eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
-                        if(eError != OMX_ErrorNone) {
-                            printf("Error from SendCommand-Idle(Stop) State function\n");
-                            goto EXIT;
-                        }
-                        eError = WaitForState(pHandle, OMX_StateIdle);
-#ifdef OMX_GETTIME
-                        GT_END("Call to SendCommand <OMX_StateIdle>");
-#endif
-                        if ( eError != OMX_ErrorNone ){
-                            printf("Error:WaitForState has timed out %d", eError);
-                            goto EXIT;
-                        }
-                        audioinfo->dasfMode = 0;
-                        pBuf->nFlags = 0;
-                        APP_DPRINT("%d [TEST APP] Shutting down ---------- \n",__LINE__);
-                    }
                 }
                 if( FD_ISSET(Event_Pipe[0], &rfds) ) {
                     OMX_U8 pipeContents;
                     read(Event_Pipe[0], &pipeContents, sizeof(OMX_U8));
-                    printf("## RM event: %d\n",pipeContents);            
 
+                    if(pipeContents==2){
+                      eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
+                      if(eError != OMX_ErrorNone) {
+                        printf("Error from SendCommand-Idle(Stop) State function\n");
+                        goto EXIT;
+                      }
+                      eError = WaitForState(pHandle, OMX_StateIdle);
+#ifdef OMX_GETTIME
+                      GT_END("Call to SendCommand <OMX_StateIdle>");
+#endif
+                      if ( eError != OMX_ErrorNone ){
+                        printf("Error:WaitForState has timed out %d", eError);
+                        goto EXIT;
+                      }
+                      audioinfo->dasfMode = 0;
+                      //pBuf->nFlags = 0;
+                      APP_DPRINT("%d [TEST APP] Shutting down ---------- \n",__LINE__);
+                    }
                 }
             } /* While Loop Ending Here */
 
diff --git a/omx/audio/src/openmax_il/g722_dec/src/OMX_G722Dec_Utils.c b/omx/audio/src/openmax_il/g722_dec/src/OMX_G722Dec_Utils.c
index a75fe4d..37a7a75 100755
--- a/omx/audio/src/openmax_il/g722_dec/src/OMX_G722Dec_Utils.c
+++ b/omx/audio/src/openmax_il/g722_dec/src/OMX_G722Dec_Utils.c
@@ -156,7 +156,7 @@
                                                     pHandle,pHandle->pApplicationPrivate,
                                                     OMX_EventError,OMX_ErrorInsufficientResources, 0,
                                                     "Error from COmponent Thread in select");
-            goto EXIT;
+            eError = OMX_ErrorInsufficientResources;
 
         } else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) {
             /*                   && (pComponentPrivate->curState != OMX_StatePause)) { */
@@ -195,7 +195,7 @@
     pComponentPrivate->bCompThreadStarted = 0;
 
     G722DEC_DPRINT (":: Exiting ComponentThread \n");
-    return (void*)OMX_ErrorNone;
+    return (void*)eError;
 }
 /* ================================================================================= * */
 /**
diff --git a/omx/audio/src/openmax_il/g722_dec/src/OMX_G722Decoder.c b/omx/audio/src/openmax_il/g722_dec/src/OMX_G722Decoder.c
index 351346f..135a5b3 100755
--- a/omx/audio/src/openmax_il/g722_dec/src/OMX_G722Decoder.c
+++ b/omx/audio/src/openmax_il/g722_dec/src/OMX_G722Decoder.c
@@ -674,6 +674,7 @@
     switch(nParamIndex){
     case OMX_IndexParamAudioInit:
         G722DEC_DPRINT(":: GetParameter OMX_IndexParamAudioInit\n");
+        G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
         memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
 
@@ -741,6 +742,7 @@
 
     case OMX_IndexParamPriorityMgmt:
         G722DEC_DPRINT(" :: GetParameter OMX_IndexParamPriorityMgmt \n");
+        G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
         memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
@@ -908,12 +910,14 @@
 
     case OMX_IndexParamPriorityMgmt:
         G722DEC_DPRINT(":: SetParameter OMX_IndexParamPriorityMgmt \n");
+        G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
         memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, 
                sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
     case OMX_IndexParamAudioInit:
         G722DEC_DPRINT(":: SetParameter OMX_IndexParamAudioInit \n");
+        G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
         memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, 
                sizeof(OMX_PORT_PARAM_TYPE));
         break;
@@ -921,6 +925,7 @@
     case OMX_IndexParamStandardComponentRole:
         if (pCompParam) {
             pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
+            G722D_OMX_CONF_CHECK_CMD(pComponentPrivate->componentRole, 1, 1);
             memcpy(pComponentPrivate->componentRole, (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
         } else {
             eError = OMX_ErrorBadParameter;
@@ -1746,8 +1751,10 @@
  EXIT:
     if(OMX_ErrorNone != eError) {
         G722DEC_DPRINT("%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__);
-        G722D_OMX_FREE(pBufferHeader->pBuffer);
-        G722D_OMX_FREE(pBufferHeader);
+	 if (NULL != pBufferHeader) {
+	     G722D_OMX_FREE(pBufferHeader->pBuffer);
+	     G722D_OMX_FREE(pBufferHeader);
+	 }
     }
 
     return eError;
diff --git a/omx/audio/src/openmax_il/g722_dec/tests/Android.mk b/omx/audio/src/openmax_il/g722_dec/tests/Android.mk
index 6a0a827..3570e1e 100755
--- a/omx/audio/src/openmax_il/g722_dec/tests/Android.mk
+++ b/omx/audio/src/openmax_il/g722_dec/tests/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_G722_DEC_TEST),1)
+ifeq ($(BUILD_G722_DEC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -21,4 +21,4 @@
 LOCAL_MODULE:= G722Decoder_Test

 

 include $(BUILD_EXECUTABLE)

-endif
+endif

diff --git a/omx/audio/src/openmax_il/g722_enc/inc/OMX_G722Enc_Utils.h b/omx/audio/src/openmax_il/g722_enc/inc/OMX_G722Enc_Utils.h
index e2b67c7..2bca3fd 100755
--- a/omx/audio/src/openmax_il/g722_enc/inc/OMX_G722Enc_Utils.h
+++ b/omx/audio/src/openmax_il/g722_enc/inc/OMX_G722Enc_Utils.h
@@ -279,12 +279,12 @@
     (_s_)->nVersion.s.nRevision = 0x0;          \
     (_s_)->nVersion.s.nStep = 0x0
 
-#define OMX_G722MEMFREE_STRUCT(_pStruct_)                       \
-    G722ENC_MEMPRINT("%d :: [FREE] %p\n", __LINE__, _pStruct_); \
-    if(_pStruct_ != NULL)                                       \
-    {                                                           \
-        free(_pStruct_);                                        \
-        _pStruct_ = NULL;                                       \
+#define OMX_G722MEMFREE_STRUCT(_pStruct_)                           \
+    if(_pStruct_ != NULL)                                           \
+    {                                                               \
+        G722ENC_MEMPRINT("%d :: [FREE] %p\n", __LINE__, _pStruct_); \
+        free(_pStruct_);                                            \
+        _pStruct_ = NULL;                                           \
     }
 
 #define OMX_G722CLOSE_PIPE(_pStruct_,err)                       \
diff --git a/omx/audio/src/openmax_il/g722_enc/src/OMX_G722Enc_Utils.c b/omx/audio/src/openmax_il/g722_enc/src/OMX_G722Enc_Utils.c
index abb280a..9ae3eda 100755
--- a/omx/audio/src/openmax_il/g722_enc/src/OMX_G722Enc_Utils.c
+++ b/omx/audio/src/openmax_il/g722_enc/src/OMX_G722Enc_Utils.c
@@ -164,7 +164,7 @@
                                                     pHandle,pHandle->pApplicationPrivate,
                                                     OMX_EventError,OMX_ErrorInsufficientResources, 0,
                                                     "Error from COmponent Thread in select");
-            exit(1);
+            eError = OMX_ErrorInsufficientResources;
 
         } else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) {
             G722ENC_DPRINT ("%d :: CMD pipe is set in Component Thread\n",__LINE__);
@@ -218,7 +218,7 @@
     }
  EXIT:
     G722ENC_DPRINT ("%d :: Exiting ComponentThread \n",__LINE__);
-    return (void*)OMX_ErrorNone;
+    return (void*)eError;
 }
 
 /* ================================================================================= */
@@ -480,18 +480,6 @@
             arr = NULL;
         }
     
-        if (pTemp_lcml) {
-            G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pTemp_lcml);
-            free(pTemp_lcml);
-            pTemp_lcml = NULL;
-        }
-
-        if (pTemp_lcml->pIpParam) {
-            G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pTemp_lcml->pIpParam);
-            free(pTemp_lcml->pIpParam);
-            pTemp_lcml->pIpParam = NULL;
-        }
-
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
@@ -717,7 +705,7 @@
         }
 
         if (pComponentPrivate->pcmParams) {
-            G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pComponentPrivate->g722Params[G722ENC_INPUT_PORT]);
+            G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pComponentPrivate->pcmParams);
             free(pComponentPrivate->pcmParams);
             pComponentPrivate->pcmParams = NULL;
         }
@@ -1640,7 +1628,7 @@
         pComponentPrivate_CC->bNoIdleOnStop= OMX_FALSE;
     }
     else if(event == EMMCodecAlgCtrlAck) {
-        LCML_DPRINT ("GOT MESSAGE USN_DSPACK_ALGCTRL \n");
+        G722ENC_DPRINT ("GOT MESSAGE USN_DSPACK_ALGCTRL \n");
     }
     else if (event == EMMCodecDspError) {
         if(((int)args[4] == 1) && ((int)args[5] == 0x500)) {
@@ -1672,7 +1660,7 @@
         }
     }
     else if (event == EMMCodecStrmCtrlAck) {
-        LCML_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__);
+        G722ENC_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__);
         pComponentPrivate_CC->bStreamCtrlCalled = 1;
     
     }
@@ -2683,18 +2671,6 @@
             strmAttr = NULL;
         }
 
-        if (pTemp_lcml) {
-            G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pTemp_lcml);
-            free(pTemp_lcml);
-            pTemp_lcml = NULL;
-        }
-
-        if (pTemp_lcml->pIpParam) {
-            G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pTemp_lcml->pIpParam);
-            free(pTemp_lcml->pIpParam);
-            pTemp_lcml->pIpParam = NULL;
-        }
-
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
diff --git a/omx/audio/src/openmax_il/g722_enc/src/OMX_G722Encoder.c b/omx/audio/src/openmax_il/g722_enc/src/OMX_G722Encoder.c
index 73ad614..d9614b0 100755
--- a/omx/audio/src/openmax_il/g722_enc/src/OMX_G722Encoder.c
+++ b/omx/audio/src/openmax_il/g722_enc/src/OMX_G722Encoder.c
@@ -344,6 +344,34 @@
     }
     
     pComponentPrivate->sDeviceString = malloc(100*sizeof(OMX_STRING));
+    if (pComponentPrivate->sDeviceString == NULL) {
+	/* Free previously allocated memory before bailing */
+	if (pcm_ip) {
+	    G722ENC_MEMPRINT("%d:::[FREE] %p\n", __LINE__, pcm_ip);
+	    free(pcm_ip);
+	    pcm_ip = NULL;
+	}
+
+	if (pcm_op) {
+	    G722ENC_MEMPRINT("%d:::[FREE] %p\n", __LINE__, pcm_op);
+	    free(pcm_op);
+	    pcm_op = NULL;
+	}
+
+	if (pComponentPrivate->pInputBufferList) {
+	    G722ENC_MEMPRINT("%d:::[FREE] %p\n", __LINE__, pComponentPrivate->pInputBufferList);
+	    free(pComponentPrivate->pInputBufferList);
+	    pComponentPrivate->pInputBufferList = NULL;
+	}
+
+	if (pHandle->pComponentPrivate) {
+	    G722ENC_MEMPRINT("%d:::[FREE] %p\n", __LINE__, pHandle->pComponentPrivate);
+	    free(pHandle->pComponentPrivate);
+	    pHandle->pComponentPrivate = NULL;
+	}
+	eError = OMX_ErrorInsufficientResources;
+	goto EXIT;
+    }
     memset (pComponentPrivate->sDeviceString, 0, 100*sizeof(OMX_STRING));
     strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
     pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */
@@ -483,12 +511,6 @@
         G722ENC_DPRINT("%d :: malloc failed\n",__LINE__);
         /* Free previously allocated memory before bailing */
 
-        if (pHandle->pComponentPrivate) {
-            G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pHandle->pComponentPrivate);
-            free(pHandle->pComponentPrivate);
-            pHandle->pComponentPrivate = NULL;
-        }
-
         if (pcm_ip) {
             G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pcm_ip);
             free(pcm_ip);
@@ -513,6 +535,12 @@
             pComponentPrivate->pOutputBufferList = NULL;
         }
 
+	if (pHandle->pComponentPrivate) {
+	    G722ENC_MEMPRINT("%d:::[FREE] %p\n", __LINE__, pHandle->pComponentPrivate);
+	    free(pHandle->pComponentPrivate);
+	    pHandle->pComponentPrivate = NULL;
+	}
+
         if (pPortDef_ip) {
             G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,pPortDef_ip);
             free(pPortDef_ip);
@@ -760,13 +788,17 @@
     G722ENC_DPRINT ("%d :: Entering the GetParameter():: %x\n",__LINE__,nParamIndex);
 
     pComponentPrivate = (G722ENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
-    pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure;
+    if (pComponentPrivate == NULL) {
+	eError = OMX_ErrorBadParameter;
+	goto EXIT;
+    }
 
+    pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE *)ComponentParameterStructure;
     if (pParameterStructure == NULL) {
         eError = OMX_ErrorBadParameter;
         goto EXIT;
-
     }
+
     if(pComponentPrivate->curState == OMX_StateInvalid) {
         pComponentPrivate->cbInfo.EventHandler(
                                                hComp,
@@ -781,12 +813,7 @@
     switch(nParamIndex){
     case OMX_IndexParamAudioInit:
         G722ENC_DPRINT ("OMX_IndexParamAudioInit\n");
-        if (pComponentPrivate != NULL) {
-            memcpy(ComponentParameterStructure, &pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
-        }
-        else {
-            eError = OMX_ErrorBadParameter;
-        }
+	memcpy(ComponentParameterStructure, &pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
 
     case OMX_IndexParamPortDefinition:
@@ -841,6 +868,10 @@
     case OMX_IndexParamAudioAdpcm:
         if(((OMX_AUDIO_PARAM_ADPCMTYPE *)(ComponentParameterStructure))->nPortIndex ==
            G722ENC_INPUT_PORT) {
+	    if (pComponentPrivate->pcmParams == NULL) {
+                eError = OMX_ErrorBadParameter;
+		break;
+	    }
             memcpy(ComponentParameterStructure,
                    pComponentPrivate->pcmParams,
                    sizeof(OMX_AUDIO_PARAM_ADPCMTYPE)
@@ -848,7 +879,10 @@
         } 
         else if(((OMX_AUDIO_PARAM_ADPCMTYPE *)(ComponentParameterStructure))->nPortIndex ==
                 G722ENC_OUTPUT_PORT) {
-
+	    if (pComponentPrivate->g722Params == NULL) {
+                eError = OMX_ErrorBadParameter;
+		break;
+	    }
             memcpy(ComponentParameterStructure,
                    pComponentPrivate->g722Params,
                    sizeof(OMX_AUDIO_PARAM_ADPCMTYPE)
@@ -861,6 +895,10 @@
         break;
         
     case OMX_IndexParamPriorityMgmt:
+	if (pComponentPrivate->sPriorityMgmt == NULL) {
+             eError = OMX_ErrorBadParameter;
+	     break;
+	}
         memcpy(ComponentParameterStructure,
                pComponentPrivate->sPriorityMgmt,
                sizeof(OMX_PRIORITYMGMTTYPE));
@@ -995,6 +1033,10 @@
         break;
     case OMX_IndexParamPriorityMgmt:
         if (pComponentPrivate->curState == OMX_StateLoaded){
+	    if (pComponentPrivate->sPriorityMgmt == NULL) {
+                eError = OMX_ErrorBadParameter;
+	        break;
+	    }
             memcpy(pComponentPrivate->sPriorityMgmt,
                    (OMX_PRIORITYMGMTTYPE*)ComponentParameterStructure,
                    sizeof(OMX_PRIORITYMGMTTYPE));
@@ -1131,6 +1173,7 @@
  EXIT:
     if(streamInfo)
     {
+        G722ENC_MEMPRINT("%d:::[FREE] %p\n",__LINE__,streamInfo);
         free(streamInfo);
         streamInfo = NULL;
     }
@@ -1152,9 +1195,8 @@
                                 OMX_PTR ComponentConfigStructure)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    G722ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
-    G722ENC_COMPONENT_PRIVATE *pComponentPrivate =
-        (G722ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     TI_OMX_DSP_DEFINITION* pDspDefinition = NULL;
     OMX_AUDIO_CONFIG_VOLUMETYPE *pGainStructure = NULL;
     OMX_S16 *customFlag = NULL;
@@ -1167,6 +1209,7 @@
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
+    pComponentPrivate = (G722ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     G722ENC_DPRINT("Entering setConfig Switch statements\n");
     switch (nConfigIndex) 
     {
diff --git a/omx/audio/src/openmax_il/g722_enc/tests/Android.mk b/omx/audio/src/openmax_il/g722_enc/tests/Android.mk
index d9a38d9..7cc2fbd 100755
--- a/omx/audio/src/openmax_il/g722_enc/tests/Android.mk
+++ b/omx/audio/src/openmax_il/g722_enc/tests/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_G722_ENC_TEST),1)
+ifeq ($(BUILD_G722_ENC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -21,4 +21,4 @@
 LOCAL_MODULE:= G722EncTest

 

 include $(BUILD_EXECUTABLE)

-endif
+endif

diff --git a/omx/audio/src/openmax_il/g726_dec/inc/OMX_G726Dec_Utils.h b/omx/audio/src/openmax_il/g726_dec/inc/OMX_G726Dec_Utils.h
index 2b1b32d..cdbf6ba 100755
--- a/omx/audio/src/openmax_il/g726_dec/inc/OMX_G726Dec_Utils.h
+++ b/omx/audio/src/openmax_il/g726_dec/inc/OMX_G726Dec_Utils.h
@@ -53,7 +53,11 @@
 #include <stdlib.h>
 #else
 #include <pthread.h>
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
 #endif
+#endif
+
 
 #undef G726DEC_DEBUG           /* See all debug statement of the component */
 #undef G726DEC_MEMDETAILS      /* See memory details of the component */
@@ -685,6 +689,11 @@
     /* flag if the component is preempted for resource or policy reasons */
     OMX_BOOL bPreempted;
 
+    /** Pointer to RM callback **/
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
 
 } G726DEC_COMPONENT_PRIVATE;
 
@@ -968,6 +977,13 @@
                         OMX_U8 *pBuffer, OMX_DIRTYPE eDir) ;
 
 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle, int size, void* pArmPtr, DMM_BUFFER_OBJ* pDmmBuf);
-OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr);            
+OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr);
+
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G726DEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
 
 #endif
diff --git a/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Dec_CompThread.c b/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Dec_CompThread.c
index c8ace0e..c88ba54 100755
--- a/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Dec_CompThread.c
+++ b/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Dec_CompThread.c
@@ -142,7 +142,7 @@
                                                     pHandle,pHandle->pApplicationPrivate,
                                                     OMX_EventError,OMX_ErrorInsufficientResources, 0,
                                                     "Error from COmponent Thread in select");
-            goto EXIT;
+            eError = OMX_ErrorInsufficientResources;
 
         } else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) {
 
@@ -194,5 +194,5 @@
     pComponentPrivate->bCompThreadStarted = 0;
 
     G726DEC_DPRINT (":: Exiting ComponentThread \n");
-    return (void*)OMX_ErrorNone;
+    return (void*)eError;
 }
diff --git a/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Dec_Utils.c b/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Dec_Utils.c
index 4f58854..c9d6c99 100755
--- a/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Dec_Utils.c
+++ b/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Dec_Utils.c
@@ -342,7 +342,6 @@
  EXIT:
     if(eError == OMX_ErrorInsufficientResources || eError == OMX_ErrorBadParameter){
         G726D_OMX_FREE(strmAttr);
-        G726D_OMX_FREE(arr);
         G726D_OMX_FREE(pTemp_lcml);
     }
     G726DEC_DPRINT("Exiting G726DEC_Fill_LCMLInitParams\n");
@@ -2551,3 +2550,34 @@
     return eError;
 }
 
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G726DEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+{
+    OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
+    OMX_STATETYPE state = OMX_StateIdle;
+    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
+    G726DEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
+
+    pCompPrivate = (G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+
+    if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted){
+        if (pCompPrivate->curState == OMX_StateExecuting || 
+            pCompPrivate->curState == OMX_StatePause) {
+
+            write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
+            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
+
+            pCompPrivate->bPreempted = 1;
+        }
+    }
+    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
+        pCompPrivate->cbInfo.EventHandler ( pHandle, 
+                                            pHandle->pApplicationPrivate,
+                                            OMX_EventResourcesAcquired, 
+                                            0, 0, NULL);
+    }
+}
+#endif
diff --git a/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Decoder.c b/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Decoder.c
index a07e4ec..105f2a4 100755
--- a/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Decoder.c
+++ b/omx/audio/src/openmax_il/g726_dec/src/OMX_G726Decoder.c
@@ -695,6 +695,7 @@
     switch(nParamIndex){
     case OMX_IndexParamAudioInit:
         G726DEC_DPRINT(":: GetParameter OMX_IndexParamAudioInit\n");
+        G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
         memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
 
@@ -762,6 +763,7 @@
 
     case OMX_IndexParamPriorityMgmt:
         G726DEC_DPRINT(" :: GetParameter OMX_IndexParamPriorityMgmt \n");
+        G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
         memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
@@ -852,6 +854,7 @@
          * the error on invalid frequecy */
 
         if (pCompPcmParam->nPortIndex == G726D_OUTPUT_PORT) { /* means Output port */
+            G726D_OMX_CONF_CHECK_CMD(((G726DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->PcmParams, 1, 1);
             memcpy(((G726DEC_COMPONENT_PRIVATE *)
                     pHandle->pComponentPrivate)->PcmParams, pCompPcmParam, 
                    sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
@@ -868,6 +871,7 @@
         pCompG726Param = (OMX_AUDIO_PARAM_G726TYPE *)pCompParam;
 
         if(pCompG726Param->nPortIndex == G726D_INPUT_PORT) { /* means Input port */
+            G726D_OMX_CONF_CHECK_CMD(((G726DEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->G726Params, 1, 1);
             memcpy(((G726DEC_COMPONENT_PRIVATE*)
                     pHandle->pComponentPrivate)->G726Params, pCompG726Param, 
                    sizeof(OMX_AUDIO_PARAM_G726TYPE));
@@ -928,12 +932,14 @@
 
     case OMX_IndexParamPriorityMgmt:
         G726DEC_DPRINT(":: SetParameter OMX_IndexParamPriorityMgmt \n");
+        G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
         memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, 
                sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
     case OMX_IndexParamAudioInit:
         G726DEC_DPRINT(":: SetParameter OMX_IndexParamAudioInit \n");
+        G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
         memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, 
                sizeof(OMX_PORT_PARAM_TYPE));
         break;
@@ -941,6 +947,7 @@
     case OMX_IndexParamStandardComponentRole:
         if (pCompParam) {
             pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
+            G726D_OMX_CONF_CHECK_CMD(pComponentPrivate->componentRole, 1, 1);
             memcpy(pComponentPrivate->componentRole, (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
         } else {
             eError = OMX_ErrorBadParameter;
@@ -1785,8 +1792,10 @@
  EXIT:
     if(OMX_ErrorNone != eError) {
         G726DEC_DPRINT("%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__);
-        G726D_OMX_FREE(pBufferHeader->pBuffer);
-        G726D_OMX_FREE(pBufferHeader);
+	 if (pBufferHeader != NULL) {
+	     G726D_OMX_FREE(pBufferHeader->pBuffer);
+	     G726D_OMX_FREE(pBufferHeader);
+	 }
     }
 
     return eError;
diff --git a/omx/audio/src/openmax_il/g726_dec/tests/Android.mk b/omx/audio/src/openmax_il/g726_dec/tests/Android.mk
index b4acd27..4d0ffce 100755
--- a/omx/audio/src/openmax_il/g726_dec/tests/Android.mk
+++ b/omx/audio/src/openmax_il/g726_dec/tests/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_G726_DEC_TEST),1)
+ifeq ($(BUILD_G726_DEC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -21,4 +21,4 @@
 LOCAL_MODULE:= G726DecTest

 

 include $(BUILD_EXECUTABLE)

-endif
+endif

diff --git a/omx/audio/src/openmax_il/g726_enc/inc/OMX_G726Enc_Utils.h b/omx/audio/src/openmax_il/g726_enc/inc/OMX_G726Enc_Utils.h
index 5d7c0a3..d5069e4 100755
--- a/omx/audio/src/openmax_il/g726_enc/inc/OMX_G726Enc_Utils.h
+++ b/omx/audio/src/openmax_il/g726_enc/inc/OMX_G726Enc_Utils.h
@@ -53,6 +53,9 @@
 #include <OMX_Component.h>
 #include <TIDspOmx.h>
 
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 
 #ifdef UNDER_CE
 	#define sleep Sleep
@@ -688,6 +691,11 @@
     /** preempted flag */
     OMX_BOOL bPreempted;
 
+    /** Pointer to RM callback **/
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
 } G726ENC_COMPONENT_PRIVATE;
 
 
@@ -965,6 +973,13 @@
 						 OMX_DIRTYPE eDir);
 
 
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G726ENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
+
 /* ======================================================================= */
 /** OMX_G726ENC_INDEXAUDIOTYPE  Defines the custom configuration settings
 *                              for the component
diff --git a/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Enc_ComponentThread.c b/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Enc_ComponentThread.c
index be540ae..854deef 100755
--- a/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Enc_ComponentThread.c
+++ b/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Enc_ComponentThread.c
@@ -128,7 +128,7 @@
                              						 OMX_ErrorInsufficientResources,

                              						 0,

                              						 "Error from CompThread in select");

-            exit(1);

+            eError = OMX_ErrorInsufficientResources;
 

         } else if(FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) {

             /* Do not accept any command when the component is stopping */

@@ -175,5 +175,5 @@
 EXIT:

     G726ENC_DPRINT("%d :: Exiting G726ENC_CompThread\n", __LINE__);

     G726ENC_DPRINT("%d :: Returning = 0x%x\n",__LINE__,eError);

-    return (void*)OMX_ErrorNone;

+    return (void*)eError;

 }

diff --git a/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Enc_Utils.c b/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Enc_Utils.c
index 7b41cb3..2b2ed5a 100755
--- a/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Enc_Utils.c
+++ b/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Enc_Utils.c
@@ -70,6 +70,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 /*-------program files ----------------------------------------*/
+
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
+
 #include "OMX_G726Enc_Utils.h"
 #include "g726enc_sn_uuid.h"
 #include <encode_common_ti.h>
@@ -313,6 +318,11 @@
         pTemp_lcml->eDir = OMX_DirInput;
         
         pBufferParamTemp = (OMX_U8*)SafeMalloc( sizeof(G726ENC_ParamStruct) + 256);
+	if (pBufferParamTemp == NULL) {
+	    G726ENC_DPRINT("%d :: Memory Allocation Failed\n", __LINE__);
+	    eError = OMX_ErrorInsufficientResources;
+	    goto EXIT;
+	}
         memset(pBufferParamTemp, 0x0, sizeof(G726ENC_ParamStruct) + 256);
         pTemp_lcml->pIpParam =  (G726ENC_ParamStruct*)(pBufferParamTemp + 128);
         
@@ -519,6 +529,7 @@
     G726ENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     OMX_U8* pBufParmsTemp = NULL;
+    OMX_U8* pParamsTemp = NULL;        
     G726ENC_COMPONENT_PRIVATE *pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)
                                                      pHandle->pComponentPrivate;
     G726ENC_DPRINT("%d :: Entering G726ENC_CleanupInitParams()\n", __LINE__);
@@ -540,6 +551,10 @@
           pTemp_lcml++;
     }
 
+    pParamsTemp = (OMX_U8*)pComponentPrivate->pParams;
+    if (pParamsTemp != NULL)
+        pParamsTemp -= 128;
+    OMX_NBMEMFREE_STRUCT(pParamsTemp);
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[G726ENC_OUTPUT_PORT];
 
     for(i=0; i<pComponentPrivate->nRuntimeOutputBuffers; i++) {
@@ -726,10 +741,13 @@
                 
 #ifdef RESOURCE_MANAGER_ENABLED
                 /* Need check the resource with RM */
-                pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) G726_ResourceManagerCallback;
-				if (pComponentPrivate->curState != OMX_StateWaitForResources) {
-				    rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource, OMX_G726_Encoder_COMPONENT, 
-                                                               G726ENC_CPU, 3456,&(pComponentPrivate->rmproxyCallback));
+                pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) G726ENC_ResourceManagerCallback;
+                if (pComponentPrivate->curState != OMX_StateWaitForResources) {
+                    rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_RequestResource,
+                                                      OMX_G726_Encoder_COMPONENT, 
+                                                      G726ENC_CPU,
+                                                      3456,
+                                                      &(pComponentPrivate->rmproxyCallback));
                 if(rm_error == OMX_ErrorNone) {
                     /* resource is available */
                     pComponentPrivate->curState = OMX_StateIdle;
@@ -754,6 +772,13 @@
                     rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_G726_Encoder_COMPONENT, OMX_StateIdle, 3456,NULL);
 				
               }
+                pComponentPrivate->curState = OMX_StateIdle;
+                pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                        pHandle->pApplicationPrivate,
+                                                        OMX_EventCmdComplete,
+                                                        OMX_CommandStateSet,
+                                                        pComponentPrivate->curState,
+                                                        NULL);    				
 #else                
                 pComponentPrivate->curState = OMX_StateIdle;
                 pComponentPrivate->cbInfo.EventHandler( pHandle,
@@ -1414,14 +1439,7 @@
                 pComponentPrivate->nEmptyBufferDoneCount++;
             }
             if(pBufHeader->nFlags == OMX_BUFFERFLAG_EOS) {
-
-                pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags |= OMX_BUFFERFLAG_EOS;
-                pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
-                                                        pComponentPrivate->pHandle->pApplicationPrivate,
-                                                        OMX_EventBufferFlag,
-                                                        pComponentPrivate->pOutputBufferList->pBufHdr[0]->nOutputPortIndex,
-                                                        pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags, NULL);
-                pBufHeader->nFlags = 0;
+              pComponentPrivate->pOutputBufferList->pBufHdr[0]->nFlags |= OMX_BUFFERFLAG_EOS;
             }
             if(pBufHeader->pMarkData){
                 /* copy mark to output buffer header */
@@ -1880,6 +1898,7 @@
             if(pComponentPrivate->lastOutBufArrived!=NULL && !pComponentPrivate->dasfMode){
                      pComponentPrivate->lastOutBufArrived->nFlags = OMX_BUFFERFLAG_EOS;
                      pComponentPrivate->LastBufSent=0;
+                     /*TODO: add eventhandler to report eos to application*/
             }
         }
     }
@@ -2230,3 +2249,34 @@
     return eError;
 }
 
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G726ENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+{
+    OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
+    OMX_STATETYPE state = OMX_StateIdle;
+    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
+    G726ENC_COMPONENT_PRIVATE *pCompPrivate = NULL;
+
+    pCompPrivate = (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+
+    if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted){
+        if (pCompPrivate->curState == OMX_StateExecuting || 
+            pCompPrivate->curState == OMX_StatePause) {
+
+            write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
+            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
+
+            pCompPrivate->bPreempted = 1;
+        }
+    }
+    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
+        pCompPrivate->cbInfo.EventHandler ( pHandle, 
+                                            pHandle->pApplicationPrivate,
+                                            OMX_EventResourcesAcquired, 
+                                            0, 0, NULL);
+    }
+}
+#endif
diff --git a/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Encoder.c b/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Encoder.c
index 35bc7f1..f6d6ee5 100755
--- a/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Encoder.c
+++ b/omx/audio/src/openmax_il/g726_enc/src/OMX_G726Encoder.c
@@ -361,6 +361,11 @@
 
     strcpy((char*)pComponentPrivate->componentRole.cRole, "audio_encoder.g726"); 
     pComponentPrivate->sDeviceString = SafeMalloc(100*sizeof(OMX_STRING));
+    if (pComponentPrivate->sDeviceString == NULL) {
+	G726ENC_DPRINT("%d :: OMX_ErrorInsufficientResources", __LINE__);
+	eError = OMX_ErrorInsufficientResources;
+	goto EXIT;
+    }
     /* Initialize device string to the default value */
     strcpy((char*)pComponentPrivate->sDeviceString,":srcul/codec\0");
      
@@ -647,6 +652,10 @@
 
     switch(nParamIndex){
         case OMX_IndexParamAudioInit:
+	    if (pComponentPrivate->sPortParam == NULL) {
+	        eError = OMX_ErrorBadParameter;
+                break;
+	    }
             G726ENC_DPRINT("%d :: GetParameter OMX_IndexParamAudioInit \n",__LINE__);
             memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
             break;
@@ -709,6 +718,10 @@
 			break;
 
             case OMX_IndexParamPriorityMgmt:
+	        if (pComponentPrivate->sPriorityMgmt == NULL) {
+                    eError = OMX_ErrorBadParameter;
+		    break;
+		}
                 G726ENC_DPRINT("%d :: GetParameter OMX_IndexParamPriorityMgmt \n",__LINE__);
                 memcpy(ComponentParameterStructure, pComponentPrivate->sPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
                 break;
@@ -788,10 +801,20 @@
                 G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamAudioG726 \n",__LINE__);
                 pCompG726Param = (OMX_AUDIO_PARAM_G726TYPE *)pCompParam;
                 if (pCompG726Param->nPortIndex == OMX_DirOutput) {
+	            if (((G726ENC_COMPONENT_PRIVATE *)
+		        pHandle->pComponentPrivate)->G726Params[G726ENC_OUTPUT_PORT] == NULL) {
+	                eError = OMX_ErrorBadParameter;
+                        break;
+	            }
                     memcpy(((G726ENC_COMPONENT_PRIVATE *)
                             pHandle->pComponentPrivate)->G726Params[G726ENC_OUTPUT_PORT], pCompG726Param, sizeof(OMX_AUDIO_PARAM_G726TYPE));
                 }
                 else if (pCompG726Param->nPortIndex == OMX_DirInput) {
+		    if (((G726ENC_COMPONENT_PRIVATE *)
+		        pHandle->pComponentPrivate)->G726Params[G726ENC_INPUT_PORT] == NULL) {
+	                eError = OMX_ErrorBadParameter;
+                        break;
+	            }
                     memcpy(((G726ENC_COMPONENT_PRIVATE *)
                             pHandle->pComponentPrivate)->G726Params[G726ENC_INPUT_PORT], pCompG726Param, sizeof(OMX_AUDIO_PARAM_G726TYPE));
                 }
@@ -818,11 +841,19 @@
 			  }
         	break;
 		case OMX_IndexParamPriorityMgmt:
+		       if (pComponentPrivate->sPriorityMgmt == NULL) {
+                           eError = OMX_ErrorBadParameter;
+			   break;
+		       }
 				G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamPriorityMgmt \n",__LINE__);
 	        	memcpy(pComponentPrivate->sPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
 			break;
 
 	    case OMX_IndexParamAudioInit:
+		       if (pComponentPrivate->sPortParam == NULL) {
+                           eError = OMX_ErrorBadParameter;
+			   break;
+		       }
 				G726ENC_DPRINT("%d :: SetParameter OMX_IndexParamAudioInit \n",__LINE__);
 				memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
 		    break;
@@ -894,11 +925,10 @@
                                 OMX_PTR ComponentConfigStructure)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    G726ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
 	OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
 	TI_OMX_DSP_DEFINITION *pTiDspDefinition = NULL;
     TI_OMX_DATAPATH dataPath; 
-    G726ENC_COMPONENT_PRIVATE *pComponentPrivate =
-                         (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_S16 *customFlag = NULL;
     OMX_AUDIO_CONFIG_VOLUMETYPE *pGainStructure = NULL;
     OMX_U32 fdwrite = 0;
@@ -913,6 +943,7 @@
 		goto EXIT;
 	}
 
+	pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 	switch (nConfigIndex) {
 
 		case OMX_IndexCustomG726ENCModeConfig: 
@@ -1713,8 +1744,13 @@
     pComponentPrivate = (G726ENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
     if(nIndex == 0){
-      memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
-      G726ENC_DPRINT("::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+      if (cRole == NULL) {
+          eError = OMX_ErrorBadParameter;
+      }
+      else {
+          memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
+          G726ENC_DPRINT("::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+      }
     }
     else {
       eError = OMX_ErrorNoMore;
diff --git a/omx/audio/src/openmax_il/g726_enc/tests/Android.mk b/omx/audio/src/openmax_il/g726_enc/tests/Android.mk
index 3f2fed2..bec8501 100755
--- a/omx/audio/src/openmax_il/g726_enc/tests/Android.mk
+++ b/omx/audio/src/openmax_il/g726_enc/tests/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_G726_ENC_TEST),1)
+ifeq ($(BUILD_G726_ENC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -21,4 +21,4 @@
 LOCAL_MODULE:= G726EncTest

 

 include $(BUILD_EXECUTABLE)

-endif
+endif

diff --git a/omx/audio/src/openmax_il/g729_dec/inc/OMX_G729Decoder.h b/omx/audio/src/openmax_il/g729_dec/inc/OMX_G729Decoder.h
index 626286d..08ad342 100755
--- a/omx/audio/src/openmax_il/g729_dec/inc/OMX_G729Decoder.h
+++ b/omx/audio/src/openmax_il/g729_dec/inc/OMX_G729Decoder.h
@@ -54,6 +54,10 @@
 #include <OMX_Component.h>
 #include <pthread.h>
 
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
+
 #ifdef __PERF_INSTRUMENTATION__
 #include "perf.h"
 #endif
@@ -199,9 +203,9 @@
     (_s_)->nVersion.s.nStep = 0x0;
 
 #define OMX_G729MEMFREE_STRUCT(_pStruct_)                       \
-    G729DEC_MEMPRINT("%d :: [FREE] %p\n", __LINE__, _pStruct_); \
     if(_pStruct_ != NULL)                                       \
     {                                                           \
+        G729DEC_MEMPRINT("%d :: [FREE] %p\n", __LINE__, _pStruct_); \
         free(_pStruct_);                                        \
         _pStruct_ = NULL;                                       \
     }
@@ -637,6 +641,11 @@
 
     OMX_BOOL bPreempted;
 
+    /** Pointer to RM callback **/
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_OBJHANDLE pPERF, pPERFcomp;
@@ -694,6 +703,13 @@
 OMX_ERRORTYPE G729DEC_FreeCompResources(OMX_HANDLETYPE pComponent);
 void SendFlushCompleteEvent(G729DEC_COMPONENT_PRIVATE *pComponentPrivate, int port);
 
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G729DEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
+
 /*--------macros ----------------------------------------------*/
 #ifndef UNDER_CE
 #ifdef  G729DEC_DEBUG
diff --git a/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Dec_ComponentThread.c b/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Dec_ComponentThread.c
index 64dcc02..02e3a68 100755
--- a/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Dec_ComponentThread.c
+++ b/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Dec_ComponentThread.c
@@ -183,7 +183,7 @@
                                                     pHandle->pApplicationPrivate,
                                                     OMX_EventError,OMX_ErrorInsufficientResources,0,
                                                     "Error from COmponent Thread in select");
-            exit(1);
+            eError = OMX_ErrorInsufficientResources;
 
         } 
         else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))){
@@ -233,5 +233,5 @@
     }
  EXIT:
     G729DEC_DPRINT("%d::Exiting ComponentThread\n",__LINE__);
-    return (void*)OMX_ErrorNone;
+    return (void*)eError;
 }
diff --git a/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Dec_Utils.c b/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Dec_Utils.c
index 7e8b771..5a9abb0 100755
--- a/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Dec_Utils.c
+++ b/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Dec_Utils.c
@@ -276,7 +276,6 @@
             free(strmAttr);
             strmAttr = NULL;
         }
-        memset(pTemp_lcml, 0x0, size_lcml);     
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
@@ -1457,6 +1456,11 @@
              bufParamsArray += 128;
              memset(bufParamsArray, 0, 9 * sizeof(unsigned long int)); */
         pInBufStruct = (G729DEC_BufParamStruct*)pBufHeader->pInputPortPrivate;
+
+	 if (pInBufStruct == NULL) {
+	     G729DEC_EPRINT("%d :: Error: input port NULL ...\n", __LINE__);
+	     goto EXIT;
+	 }
         /* fill array for SN params */
         if(pInBufStruct->bNoUseDefaults == OMX_TRUE){ /*indicates that khronos conformance tests are NOT running */
             pComponentPrivate->bufParamsArray[0] = 0;
@@ -1496,11 +1500,9 @@
             pLcmlHdr->pIpParam->usLastFrame = 0;
             pComponentPrivate->bufParamsArray[0] = 0;
         }
-        if(pInBufStruct!=NULL){  
-            pLcmlHdr->pIpParam->usFrameLost = pInBufStruct->frameLost;
-            if(pInBufStruct->frameLost==1){
-                G729DEC_PRINT_INFO("Frame LOST event\n");
-            }
+	 pLcmlHdr->pIpParam->usFrameLost = pInBufStruct->frameLost;
+	 if (pInBufStruct->frameLost == 1) {
+	     G729DEC_PRINT_INFO("Frame LOST event\n");
         }
         /* Store time stamp information */
         pComponentPrivate->arrTimestamp[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;
@@ -1867,7 +1869,7 @@
     } 
     else if (event == EMMCodecStrmCtrlAck) 
     {
-        LCML_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__);
+        G729DEC_DPRINT("%d :: GOT MESSAGE USN_DSPACK_STRMCTRL ----\n",__LINE__);
         if (args[1] == (void *)USN_STRMCMD_FLUSH)
         {
             G729DEC_DPRINT("revceived USN_STRMCMD_FLUSH\n");
@@ -2494,3 +2496,35 @@
     return eError;
 }
 
+
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G729DEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+{
+    OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
+    OMX_STATETYPE state = OMX_StateIdle;
+    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
+    G729DEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
+
+    pCompPrivate = (G729DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+
+    if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted){
+        if (pCompPrivate->curState == OMX_StateExecuting || 
+            pCompPrivate->curState == OMX_StatePause) {
+
+            write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
+            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
+
+            pCompPrivate->bPreempted = 1;
+        }
+    }
+    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
+        pCompPrivate->cbInfo.EventHandler ( pHandle, 
+                                            pHandle->pApplicationPrivate,
+                                            OMX_EventResourcesAcquired, 
+                                            0, 0, NULL);
+    }
+}
+#endif
diff --git a/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Decoder.c b/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Decoder.c
index 8969d23..918d5f4 100755
--- a/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Decoder.c
+++ b/omx/audio/src/openmax_il/g729_dec/src/OMX_G729Decoder.c
@@ -275,7 +275,6 @@
     G729DEC_DPRINT("%d Malloced pcmParams = 0x%p\n",__LINE__,((G729DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pcmParams);
 
  
-    pComponentPrivate = pHandle->pComponentPrivate;
     OMX_G729MALLOC_STRUCT(pComponentPrivate->pInputBufferList, G729DEC_BUFFERLIST);
 
     pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */
@@ -323,6 +322,10 @@
     pComponentPrivate->bNoIdleOnStop = OMX_FALSE;
     pComponentPrivate->pParams = NULL;
     pComponentPrivate->sDeviceString = malloc(100*sizeof(OMX_STRING));
+    if (pComponentPrivate->sDeviceString == NULL) {
+	 G729DEC_DPRINT("%d ::malloc failed\n", __LINE__);
+	 goto EXIT;
+    }
     strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
     pComponentPrivate->IpBufindex = 0;
     pComponentPrivate->OpBufindex = 0;
@@ -864,6 +867,10 @@
         break;
 
     case OMX_IndexParamPriorityMgmt:
+        if (pComponentPrivate->sPriorityMgmt == NULL) {
+            eError = OMX_ErrorBadParameter;
+            goto EXIT;
+        }
         memcpy(ComponentParameterStructure, pComponentPrivate->sPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
@@ -954,14 +961,17 @@
         {
             OMX_AUDIO_PARAM_G729TYPE *pCompG729Param =
                 (OMX_AUDIO_PARAM_G729TYPE *)pCompParam;
-
-                                      
-            /* 0 means Input port */
-            if(pCompG729Param->nPortIndex == 0) {
-                memcpy(((G729DEC_COMPONENT_PRIVATE*)
-                        pHandle->pComponentPrivate)->g729Params,
-                       pCompG729Param, sizeof(OMX_AUDIO_PARAM_G729TYPE));
+	    if (((G729DEC_COMPONENT_PRIVATE*)
+	        pHandle->pComponentPrivate)->g729Params == NULL) {
+                eError = OMX_ErrorBadParameter;
+                goto EXIT;
             }
+            /* 0 means Input port */
+	    if(pCompG729Param->nPortIndex == 0) {
+		memcpy(((G729DEC_COMPONENT_PRIVATE*)
+	            pHandle->pComponentPrivate)->g729Params,
+		    pCompG729Param, sizeof(OMX_AUDIO_PARAM_G729TYPE));
+	    }
             else {
                 eError = OMX_ErrorBadPortIndex;
             }
@@ -996,6 +1006,11 @@
             goto EXIT;
         }
         else{
+	    if (pComponentPrivate->sPriorityMgmt == NULL) {
+                eError = OMX_ErrorBadParameter;
+                goto EXIT;
+            }
+
             memcpy(pComponentPrivate->sPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE)); 
                         
         }
@@ -1012,6 +1027,10 @@
         break;
 
     case OMX_IndexParamAudioPcm:
+        if (pComponentPrivate->pcmParams == NULL) {
+            eError = OMX_ErrorBadParameter;
+            goto EXIT;
+        }
         if(pCompParam){
             pPcmPort= (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
             memcpy(pComponentPrivate->pcmParams, pPcmPort, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
@@ -1072,8 +1091,11 @@
 
     pComponentPrivate = (G729DEC_COMPONENT_PRIVATE *)
         (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
-
-    memcpy(ComponentConfigStructure,pComponentPrivate,sizeof(G729DEC_COMPONENT_PRIVATE));
+  
+    if (pComponentPrivate == NULL) 
+        eError = OMX_ErrorBadParameter;
+    else
+        memcpy(ComponentConfigStructure,pComponentPrivate,sizeof(G729DEC_COMPONENT_PRIVATE));
 
     return eError;
 }
@@ -1096,8 +1118,7 @@
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
-    G729DEC_COMPONENT_PRIVATE *pComponentPrivate =
-        (G729DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    G729DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_S16 *customFlag = NULL;
     TI_OMX_DSP_DEFINITION *configData = NULL;
     
@@ -1114,6 +1135,8 @@
         goto EXIT;
     }
 
+    pComponentPrivate =
+	 (G729DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     switch (nConfigIndex) {
     case  OMX_IndexCustomG729DecHeaderInfoConfig:
         {
@@ -1530,58 +1553,18 @@
     PERF_Done(pComponentPrivate->pPERF);
 #endif 
 
-    if (pComponentPrivate->sDeviceString != NULL) {
-        free(pComponentPrivate->sDeviceString);
-    }
-
-    if (pComponentPrivate->pInputBufferList != NULL){
-        free(pComponentPrivate->pInputBufferList);
-        pComponentPrivate->pInputBufferList = NULL;
-    }
-
-    if (pComponentPrivate->pOutputBufferList != NULL){
-        free(pComponentPrivate->pOutputBufferList);
-        pComponentPrivate->pOutputBufferList = NULL;
-    }
-
-    if (pComponentPrivate->g729Params != NULL){
-        free (pComponentPrivate->g729Params);
-        pComponentPrivate->g729Params = NULL;
-    }
-
-    if (pComponentPrivate->pcmParams != NULL){
-        free (pComponentPrivate->pcmParams);
-        pComponentPrivate->pcmParams = NULL;
-    }    
-
-    if (pComponentPrivate->sPriorityMgmt != NULL){
-        free (pComponentPrivate->sPriorityMgmt);
-        pComponentPrivate->sPriorityMgmt = NULL;
-    }
-
-    if (pComponentPrivate->pPortDef[G729DEC_INPUT_PORT] != NULL){
-        free (pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]);
-        pComponentPrivate->pPortDef[G729DEC_INPUT_PORT] = NULL;
-    }
-
-    if (pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT] != NULL){
-        free (pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]);
-        pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT] = NULL;
-    }
-
-    if (pComponentPrivate->pInPortFormat != NULL){
-        free (pComponentPrivate->pInPortFormat);
-        pComponentPrivate->pInPortFormat = NULL;
-    }
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->g729Params);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pcmParams);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->sPriorityMgmt);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pPortDef[G729DEC_INPUT_PORT]);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pPortDef[G729DEC_OUTPUT_PORT]);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pInPortFormat);
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pOutPortFormat);
     
-    if (pComponentPrivate->pOutPortFormat != NULL){
-        free (pComponentPrivate->pOutPortFormat);
-        pComponentPrivate->pOutPortFormat = NULL;
-    }
-    
-    G729DEC_MEMPRINT("%d:[FREE] %p\n",__LINE__,pComponentPrivate);
-    free(pComponentPrivate);
-    pComponentPrivate = NULL;
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate);
     G729DEC_DPRINT ("%d ::After free(pComponentPrivate)\n",__LINE__);
 
     return eError;
@@ -1839,10 +1822,7 @@
                 tempBuff -= CACHE_ALIGNMENT;
                 OMX_G729MEMFREE_STRUCT(tempBuff);
             }
-            if ((G729DEC_BufParamStruct*)pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pInputPortPrivate != NULL){
-                free(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pInputPortPrivate);
-                pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pInputPortPrivate = NULL;
-            }
+            OMX_G729MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pInputPortPrivate);
         }
         OMX_G729MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
         pComponentPrivate->pInputBufferList->numBuffers--;
@@ -1880,10 +1860,7 @@
                 tempBuff -= CACHE_ALIGNMENT;
                 OMX_G729MEMFREE_STRUCT(tempBuff);
             }
-            if ((G729DEC_BufParamStruct*)pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pInputPortPrivate != NULL){
-                free(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pInputPortPrivate);
-                pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pInputPortPrivate = NULL;
-            }
+            OMX_G729MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pInputPortPrivate);
         }
         OMX_G729MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
 
diff --git a/omx/audio/src/openmax_il/g729_dec/tests/Android.mk b/omx/audio/src/openmax_il/g729_dec/tests/Android.mk
index cf681eb..d519981 100755
--- a/omx/audio/src/openmax_il/g729_dec/tests/Android.mk
+++ b/omx/audio/src/openmax_il/g729_dec/tests/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_G729_DEC_TEST),1)
+ifeq ($(BUILD_G729_DEC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -21,4 +21,4 @@
 LOCAL_MODULE:= G729DecTest

 

 include $(BUILD_EXECUTABLE)

-endif
+endif

diff --git a/omx/audio/src/openmax_il/g729_enc/inc/OMX_G729Enc_Utils.h b/omx/audio/src/openmax_il/g729_enc/inc/OMX_G729Enc_Utils.h
index 7d2f40a..2865ecd 100755
--- a/omx/audio/src/openmax_il/g729_enc/inc/OMX_G729Enc_Utils.h
+++ b/omx/audio/src/openmax_il/g729_enc/inc/OMX_G729Enc_Utils.h
@@ -64,6 +64,10 @@
 #include <OMX_Component.h>
 #include <TIDspOmx.h>
 
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
+
 #undef __G729_EPRINT__
 
 
@@ -201,9 +205,9 @@
     (_s_)->nVersion.s.nStep = 0x0
 
 #define OMX_G729MEMFREE_STRUCT(_pStruct_)                       \
-    G729ENC_MEMPRINT("%d :: [FREE] %p\n", __LINE__, _pStruct_); \
     if(_pStruct_ != NULL)                                       \
     {                                                           \
+        G729ENC_MEMPRINT("%d :: [FREE] %p\n", __LINE__, _pStruct_); \
         free(_pStruct_);                                        \
         _pStruct_ = NULL;                                       \
     }
@@ -882,6 +886,10 @@
 
     OMX_BOOL bPreempted;
 
+    /** Pointer to RM callback **/
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
     
 } G729ENC_COMPONENT_PRIVATE;
 
@@ -1192,5 +1200,13 @@
  */
 /*================================================================== */
 OMX_ERRORTYPE G729ENC_TransitionToIdle(G729ENC_COMPONENT_PRIVATE *pComponentPrivate);
+
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G729ENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
+
 #endif  /* OMX_G729ENC_UTILS__H */
 
diff --git a/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Enc_ComponentThread.c b/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Enc_ComponentThread.c
index dfb6da7..e26b94c 100755
--- a/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Enc_ComponentThread.c
+++ b/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Enc_ComponentThread.c
@@ -176,7 +176,7 @@
                                                    OMX_ErrorInsufficientResources,
                                                    0,
                                                    "");
-            exit(1);
+            eError = OMX_ErrorInsufficientResources;
         }
         else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) 
         {
@@ -235,5 +235,5 @@
     PERF_Done(pComponentPrivate->pPERFcomp);
 #endif
     G729ENC_DPRINT("Exiting. Returning = 0x%x\n", eError);
-    return (void*)OMX_ErrorNone;
+    return (void*)eError;
 }
diff --git a/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Enc_Utils.c b/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Enc_Utils.c
index 84e98f9..c3028f3 100755
--- a/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Enc_Utils.c
+++ b/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Enc_Utils.c
@@ -432,6 +432,8 @@
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     G729ENC_COMPONENT_PRIVATE *pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *)
         pHandle->pComponentPrivate;
+    OMX_U8* pAlgParmTemp = (OMX_U8*)pComponentPrivate->pAlgParam;
+    OMX_U8* pParmsTemp = (OMX_U8*)pComponentPrivate->pParams;
     
     G729ENC_DPRINT("Entering\n");
     if (pComponentPrivate->bPortDefsAllocated)
@@ -450,6 +452,17 @@
         OMX_G729CLOSE_PIPE(pComponentPrivate->cmdDataPipe[1],err);
 
     }
+
+    if (pAlgParmTemp != NULL)
+        pAlgParmTemp -= 128;
+    pComponentPrivate->pAlgParam = (G729ENC_TALGCtrl*)pAlgParmTemp;
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pAlgParam);
+
+    if (pParmsTemp != NULL)
+        pParmsTemp -= 128;
+    pComponentPrivate->pParams = (G729ENC_AudioCodecParams*)pParmsTemp;
+    OMX_G729MEMFREE_STRUCT(pComponentPrivate->pParams);
+
     if (pComponentPrivate->bPortDefsAllocated)
     {
         OMX_G729MEMFREE_STRUCT(pComponentPrivate->pPortDef[G729ENC_INPUT_PORT]);
@@ -881,8 +894,8 @@
                         goto EXIT;      
                     }
                     memset(pAlgParmTemp, 0x0, sizeof(G729ENC_TALGCtrl) + 256);
+                    G729ENC_MEMPRINT("%d :: [ALLOC] %p\n",__LINE__,pAlgParmTemp);
                     pComponentPrivate->pAlgParam = (G729ENC_TALGCtrl*)(pAlgParmTemp + 128);
-                    G729ENC_MEMPRINT("%d :: [ALLOC] %p\n",__LINE__,pComponentPrivate->pAlgParam);
                     pComponentPrivate->pAlgParam->vadFlag = pComponentPrivate->g729Params->bDTX;
                     pComponentPrivate->pAlgParam->size = sizeof( G729ENC_TALGCtrl );
                     pComponentPrivate->pAlgParam->frameSize = 0;
@@ -1989,9 +2002,17 @@
                         /* Remove the copied data from pHoldBuffer. */
 
                         /*OMAPS00101094*/
-                        memcpy(pComponentPrivate->pHoldBuffer, 
-                               pComponentPrivate->pHoldBuffer + frameLength,
-                               pComponentPrivate->nHoldLength - frameLength);
+			if (pComponentPrivate->nHoldLength - frameLength < frameLength) {
+                            memcpy(pComponentPrivate->pHoldBuffer, 
+                                   pComponentPrivate->pHoldBuffer + frameLength,
+                                   pComponentPrivate->nHoldLength - frameLength);
+			}
+			else {
+                            memmove(pComponentPrivate->pHoldBuffer, 
+                                   pComponentPrivate->pHoldBuffer + frameLength,
+                                   pComponentPrivate->nHoldLength - frameLength);
+			}
+			
                         /*OMAPS00101094*/
                         pComponentPrivate->nHoldLength = pComponentPrivate->nHoldLength - frameLength;
                         G729ENC_DPRINT("pComponentPrivate->nHoldLength = %d\n",
@@ -2688,3 +2709,34 @@
     return eError;
 }
 
+#ifdef RESOURCE_MANAGER_ENABLED
+/***********************************
+ *  Callback to the RM                                       *
+ ***********************************/
+void G729ENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+{
+    OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
+    OMX_STATETYPE state = OMX_StateIdle;
+    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
+    G729ENC_COMPONENT_PRIVATE *pCompPrivate = NULL;
+
+    pCompPrivate = (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+
+    if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted){
+        if (pCompPrivate->curState == OMX_StateExecuting || 
+            pCompPrivate->curState == OMX_StatePause) {
+
+            write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
+            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
+
+            pCompPrivate->bPreempted = 1;
+        }
+    }
+    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
+        pCompPrivate->cbInfo.EventHandler ( pHandle, 
+                                            pHandle->pApplicationPrivate,
+                                            OMX_EventResourcesAcquired, 
+                                            0, 0, NULL);
+    }
+}
+#endif
diff --git a/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Encoder.c b/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Encoder.c
index db6915a..751931d 100755
--- a/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Encoder.c
+++ b/omx/audio/src/openmax_il/g729_enc/src/OMX_G729Encoder.c
@@ -383,6 +383,12 @@
     pComponentPrivate->bPreempted = OMX_FALSE;
 
     pComponentPrivate->sDeviceString = malloc(100*sizeof(OMX_STRING));
+    if (pComponentPrivate->sDeviceString == NULL) {
+	G729ENC_EPRINT("OMX_ErrorInsufficientResources.\n");
+	eError = OMX_ErrorInsufficientResources;
+	goto EXIT;
+    }
+
     strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
         
     
@@ -742,6 +748,10 @@
     {
     case OMX_IndexParamAudioInit:
         G729ENC_DPRINT("case OMX_IndexParamAudioInit\n");
+	if (pComponentPrivate->sPortParam == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+	}
         memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, 
                sizeof(OMX_PORT_PARAM_TYPE));
         break;
@@ -834,6 +844,10 @@
         }
         break;            
     case OMX_IndexParamPriorityMgmt:
+	if (pComponentPrivate->sPriorityMgmt == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+	}
         G729ENC_DPRINT("Case OMX_IndexParamPriorityMgmt\n");
         memcpy(ComponentParameterStructure,
                pComponentPrivate->sPriorityMgmt,
@@ -981,12 +995,20 @@
         }
         break;
     case OMX_IndexParamPriorityMgmt:
+        if (pComponentPrivate->sPriorityMgmt == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+	}
         G729ENC_DPRINT("Case OMX_IndexParamPriorityMgmt\n");
         memcpy(pComponentPrivate->sPriorityMgmt,
                (OMX_PRIORITYMGMTTYPE*)pCompParam,
                sizeof(OMX_PRIORITYMGMTTYPE));
         break;
     case OMX_IndexParamAudioInit:
+        if (pComponentPrivate->sPortParam == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+	}
         G729ENC_DPRINT("SetParameter OMX_IndexParamAudioInit\n");
         memcpy(pComponentPrivate->sPortParam,
                (OMX_PORT_PARAM_TYPE*)pCompParam,
@@ -1005,6 +1027,10 @@
 
     case OMX_IndexParamAudioPcm:
         if(pCompParam){
+        if (pComponentPrivate->pcmParams == NULL) {
+            eError = OMX_ErrorBadParameter;
+	    break;
+	}
             pPcmPort= (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
             memcpy(pComponentPrivate->pcmParams, pPcmPort, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
         }
@@ -1095,10 +1121,9 @@
                                 OMX_PTR ComponentConfigStructure)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    G729ENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
     TI_OMX_DSP_DEFINITION *pTiDspDefinition = NULL;
-    G729ENC_COMPONENT_PRIVATE *pComponentPrivate =
-        (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     TI_OMX_DSP_DEFINITION *configData = NULL;
     OMX_AUDIO_CONFIG_VOLUMETYPE *pGainStructure = NULL;
     TI_OMX_DATAPATH dataPath;
@@ -1110,6 +1135,8 @@
         G729ENC_EPRINT("Invalid HANDLE OMX_ErrorBadParameter.\n");
         goto EXIT;
     }
+
+    pComponentPrivate = (G729ENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 #ifdef _ERROR_PROPAGATION__
     if (pComponentPrivate->curState == OMX_StateInvalid)
     {
diff --git a/omx/audio/src/openmax_il/g729_enc/tests/Android.mk b/omx/audio/src/openmax_il/g729_enc/tests/Android.mk
index 9df93a0..507c814 100755
--- a/omx/audio/src/openmax_il/g729_enc/tests/Android.mk
+++ b/omx/audio/src/openmax_il/g729_enc/tests/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_G729_ENC_TEST),1)
+ifeq ($(BUILD_G729_ENC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -21,4 +21,4 @@
 LOCAL_MODULE:= G729EncTest_common

 

 include $(BUILD_EXECUTABLE)

-endif
+endif

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 023c54b..92468ee 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
@@ -56,10 +56,9 @@
 #endif
 
 #ifndef UNDER_CE
-#define MP3D_RM_MANAGER /* Enable to use Resource Manager functionality */
-/* #include <ResourceManagerProxyAPI.h> */
-#else
-#undef MP3D_RM_MANAGER /* Enable to use Resource Manager functionality */
+
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
 #endif
 
 
@@ -82,7 +81,7 @@
     #define PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX 0xFF7A347
 #endif
 
-
+#endif
 
 #define MP3DEC_MAJOR_VER 0x1/* Major number of the component */
 #define MP3DEC_MINOR_VER 0x1 /* Mnor number of the component */
@@ -119,9 +118,6 @@
 #define MP3D_STEREO_INTERLEAVED_STREAM  2 /* Stereo Interleaved stream index */
 #define MP3D_STEREO_NONINTERLEAVED_STREAM  3 /* Stereo Non-Interleaved stream index */
 
-#define EXTRA_BYTES 128 /* For Cache alignment*/
-#define DSP_CACHE_ALIGNMENT 256 /* For Cache alignment*/
-
 #define MP3D_STEREO_STREAM  2
 
 #define NUM_OF_PORTS 0x2 /* Number of ports of component */
@@ -237,32 +233,6 @@
 
 #endif
 
-#define MP3D_OMX_MALLOC(_pStruct_, _sName_)   \
-    _pStruct_ = (_sName_*)newmalloc(sizeof(_sName_));      \
-    if(_pStruct_ == NULL){      \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");	\
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Malloc Failed\n",__LINE__); \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n"); \
-        eError = OMX_ErrorInsufficientResources; \
-        goto EXIT;      \
-    } \
-    memset(_pStruct_,0,sizeof(_sName_));\
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Malloced = %p\n",__LINE__,_pStruct_);
-
-
-
-#define MP3D_OMX_MALLOC_SIZE(_ptr_, _size_,_name_)   \
-    _ptr_ = (_name_ *)newmalloc(_size_);      \
-    if(_ptr_ == NULL){      \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n"); \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Malloc Failed\n",__LINE__); \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n"); \
-        eError = OMX_ErrorInsufficientResources; \
-        goto EXIT;      \
-    } \
-    memset(_ptr_,0,_size_); \
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Malloced = %p\n",__LINE__,_ptr_);
-
 #define MP3D_OMX_ERROR_EXIT(_e_, _c_, _s_)\
     _e_ = _c_;\
     OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n**************** OMX ERROR ************************\n");\
@@ -279,14 +249,6 @@
     }                                           \
 }
 
-#define MP3D_OMX_FREE(ptr) \
-    if(NULL != ptr) { \
-        OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Freeing Address = %p\n",__LINE__,ptr); \
-        newfree(ptr); \
-        ptr = NULL; \
-    }
-
-
 #define OMX_CONF_INIT_STRUCT(_s_, _name_)       \
     memset((_s_), 0x0, sizeof(_name_)); \
     (_s_)->nSize = sizeof(_name_);              \
@@ -323,13 +285,14 @@
     MP3D_INPUT_PORT = 0,
     MP3D_OUTPUT_PORT
 }MP3D_COMP_PORT_TYPE;
+
 /* ======================================================================= */
 /**
- * pthread variable to indicate OMX returned all buffers to app
+ * pthread variable to indicate OMX returned all buffers to app 
  */
 /* ======================================================================= */
-    pthread_mutex_t bufferReturned_mutex;
-    pthread_cond_t bufferReturned_condition;
+    pthread_mutex_t bufferReturned_mutex; 
+    pthread_cond_t bufferReturned_condition; 
 
 /* ======================================================================= */
 /** OMX_INDEXAUDIOTYPE: This enum is used by the TI OMX Component.
@@ -682,10 +645,12 @@
     OMX_PORT_PARAM_TYPE* pPortParamType;
     /** Pointer to port priority management structure */
     OMX_PRIORITYMGMTTYPE* pPriorityMgmt;
-	
-/*  RMPROXY_CALLBACKTYPE rmproxyCallback; */
-	OMX_BOOL bPreempted;
-	
+
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+    OMX_BOOL bPreempted;
+    
     /** Contains the port related info of both the ports */
     MP3D_AUDIODEC_PORT_TYPE *pCompPort[NUM_OF_PORTS];
     /* Checks whether or not buffer were allocated by appliction */
@@ -736,9 +701,7 @@
     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;
@@ -1083,6 +1046,7 @@
 /* ================================================================================ * */
 void MP3DEC_CleanupInitParamsEx(OMX_HANDLETYPE pComponent,OMX_U32 indexport);
 
+#ifdef RESOURCE_MANAGER_ENABLED
 /* =================================================================================== */
 /**
 *  MP3_ResourceManagerCallback() Callback from Resource Manager
@@ -1092,7 +1056,8 @@
 *  @return None
 */
 /* =================================================================================== */
-/* void MP3_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData); */
+void MP3_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
 
 OMX_ERRORTYPE MP3DECFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent,OMX_U32 indexport);
 void MP3DEC_SetPending(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber);
@@ -1110,16 +1075,26 @@
 OMX_U32 MP3DEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition);
 
 /*=======================================================================*/
-/*! @fn SignalIfAllBuffersAreReturned
+/*! @fn SignalIfAllBuffersAreReturned 
 
- * @brief Sends pthread signal to indicate OMX has returned all buffers to app
+ * @brief Sends pthread signal to indicate OMX has returned all buffers to app 
 
- * @param  none
+ * @param  none 
 
- * @Return void
+ * @Return void 
 
  */
 /*=======================================================================*/
 void SignalIfAllBuffersAreReturned(MP3DEC_COMPONENT_PRIVATE *pComponentPrivate);
 
+/*  =========================================================================*/
+/*  func    MP3DEC_HandleUSNError
+/*
+/*  desc    Handles error messages returned by the dsp
+/*
+/*@return n/a
+/*
+/*  =========================================================================*/
+void MP3DEC_HandleUSNError (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
+
 #endif
diff --git a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_CompThread.c b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_CompThread.c
index 4dd9760..c4a9cb0 100644
--- a/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_CompThread.c
+++ b/omx/audio/src/openmax_il/mp3_dec/src/OMX_Mp3Dec_CompThread.c
@@ -164,8 +164,7 @@
                                                     OMX_ErrorInsufficientResources, 
                                                     OMX_TI_ErrorSevere,
                                                     "Error from COmponent Thread in select");
-            eError = OMX_ErrorInsufficientResources; 
-            break;
+            eError = OMX_ErrorInsufficientResources;
 
         } else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) {
             int ret;
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 8321ec8..2909d9a 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
@@ -82,7 +82,6 @@
 #include <decode_common_ti.h>
 #include "usn.h"
 
-/*#ifdef MP3D_RM_MANAGER*/
 #ifdef RESOURCE_MANAGER_ENABLED
 #include <ResourceManagerProxyAPI.h>
 #endif
@@ -97,15 +96,6 @@
 }
 #endif
 
-#ifdef MP3DEC_MEMDEBUG
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
-
 /* ================================================================================= * */
 /**
  * @fn MP3DEC_Fill_LCMLInitParams() fills the LCML initialization structure.
@@ -133,7 +123,6 @@
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     MP3DEC_COMPONENT_PRIVATE *pComponentPrivate =(MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     MP3D_LCML_BUFHEADERTYPE *pTemp_lcml;
-    char *char_temp = NULL;
     OMX_U32 size_lcml;
     OMX_U8 *ptr;
 
@@ -204,7 +193,7 @@
                             "Flag DSP_RENDERING_ON Must Be Defined To Use Rendering");
 #else
         LCML_STRMATTR *strmAttr;
-        MP3D_OMX_MALLOC(strmAttr, LCML_STRMATTR);
+        OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
         OMX_PRBUFFER2(pComponentPrivate->dbg, ": Malloc strmAttr = %p\n",strmAttr);
         pComponentPrivate->strmAttr = strmAttr;
         OMX_PRDSP2(pComponentPrivate->dbg, ":: MP3 DECODER IS RUNNING UNDER DASF MODE \n");
@@ -282,7 +271,7 @@
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, ":: bufAlloced = %d\n",pComponentPrivate->bufAlloced);
     size_lcml = nIpBuf * sizeof(MP3D_LCML_BUFHEADERTYPE);
-    MP3D_OMX_MALLOC_SIZE(ptr,size_lcml,OMX_U8);
+    OMX_MALLOC_SIZE(ptr,size_lcml,OMX_U8);
     pTemp_lcml = (MP3D_LCML_BUFHEADERTYPE *)ptr;
 
     pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT] = pTemp_lcml;
@@ -302,12 +291,9 @@
         pTemp_lcml->pBufHdr = pTemp;
         pTemp_lcml->eDir = OMX_DirInput;
         pTemp_lcml->pOtherParams[i] = NULL;
-        MP3D_OMX_MALLOC_SIZE(pTemp_lcml->pIpParam,
-                             (sizeof(MP3DEC_UAlgInBufParamStruct) + DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
+                             sizeof(MP3DEC_UAlgInBufParamStruct),
                              MP3DEC_UAlgInBufParamStruct);
-        char_temp = (char*)pTemp_lcml->pIpParam;
-        char_temp += EXTRA_BYTES;
-        pTemp_lcml->pIpParam = (MP3DEC_UAlgInBufParamStruct*)char_temp;
         pTemp_lcml->pIpParam->bLastBuffer = 0;
 
         pTemp->nFlags = NORMAL_BUFFER;
@@ -321,7 +307,7 @@
     }
 
     size_lcml = nOpBuf * sizeof(MP3D_LCML_BUFHEADERTYPE);
-    MP3D_OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,MP3D_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,MP3D_LCML_BUFHEADERTYPE);
     pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT] = pTemp_lcml;
 
     for (i=0; i<nOpBuf; i++) {
@@ -340,12 +326,9 @@
         pTemp_lcml->pBufHdr = pTemp;
         pTemp_lcml->eDir = OMX_DirOutput;
         pTemp_lcml->pOtherParams[i] = NULL;
-        MP3D_OMX_MALLOC_SIZE(pTemp_lcml->pOpParam,
-                             (sizeof(MP3DEC_UAlgOutBufParamStruct) + DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam,
+                             sizeof(MP3DEC_UAlgOutBufParamStruct),
                              MP3DEC_UAlgOutBufParamStruct);
-        char_temp = (char*)pTemp_lcml->pOpParam;
-        char_temp += EXTRA_BYTES;
-        pTemp_lcml->pOpParam = (MP3DEC_UAlgOutBufParamStruct*)char_temp;
         pTemp_lcml->pOpParam->ulFrameCount = DONT_CARE;
         pTemp_lcml->pOpParam->ulIsLastBuffer = 0;
 
@@ -357,16 +340,10 @@
         pTemp_lcml++;
     }
     pComponentPrivate->bPortDefsAllocated = 1;
-    MP3D_OMX_MALLOC_SIZE(pComponentPrivate->pParams,(sizeof(USN_AudioCodecParams) + DSP_CACHE_ALIGNMENT),
+    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,sizeof(USN_AudioCodecParams),
                          USN_AudioCodecParams);
-    char_temp = (char*) pComponentPrivate->pParams;
-    char_temp +=EXTRA_BYTES;
-    pComponentPrivate->pParams = (USN_AudioCodecParams *)char_temp;
-    MP3D_OMX_MALLOC_SIZE(pComponentPrivate->ptAlgDynParams,(sizeof(MP3DEC_UALGParams) + DSP_CACHE_ALIGNMENT),
+    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->ptAlgDynParams,sizeof(MP3DEC_UALGParams),
                          MP3DEC_UALGParams);
-    char_temp = (char*) pComponentPrivate->ptAlgDynParams;
-    char_temp += EXTRA_BYTES;
-    pComponentPrivate->ptAlgDynParams = (MP3DEC_UALGParams *) char_temp;
 
 #ifdef __PERF_INSTRUMENTATION__
     pComponentPrivate->nLcml_nCntIp = 0;
@@ -533,18 +510,18 @@
 
     if (pComponentPrivate->bPortDefsAllocated) {
 
-        MP3D_OMX_FREE(pComponentPrivate->pPortDef[MP3D_INPUT_PORT]);
-        MP3D_OMX_FREE(pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]);
-        MP3D_OMX_FREE(pComponentPrivate->mp3Params);
-        MP3D_OMX_FREE (pComponentPrivate->pcmParams);
-        MP3D_OMX_FREE(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat);
-        MP3D_OMX_FREE (pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat);
-        MP3D_OMX_FREE (pComponentPrivate->pCompPort[MP3D_INPUT_PORT]);
-        MP3D_OMX_FREE (pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]);
-        MP3D_OMX_FREE (pComponentPrivate->sPortParam);
-        MP3D_OMX_FREE (pComponentPrivate->pPriorityMgmt);
-        MP3D_OMX_FREE(pComponentPrivate->pInputBufferList);
-        MP3D_OMX_FREE(pComponentPrivate->pOutputBufferList);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[MP3D_INPUT_PORT]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->mp3Params);
+        OMX_MEMFREE_STRUCT (pComponentPrivate->pcmParams);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat);
+        OMX_MEMFREE_STRUCT (pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat);
+        OMX_MEMFREE_STRUCT (pComponentPrivate->pCompPort[MP3D_INPUT_PORT]);
+        OMX_MEMFREE_STRUCT (pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]);
+        OMX_MEMFREE_STRUCT (pComponentPrivate->sPortParam);
+        OMX_MEMFREE_STRUCT (pComponentPrivate->pPriorityMgmt);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
     }
 
     pComponentPrivate->bPortDefsAllocated = 0;
@@ -773,6 +750,14 @@
                                                 p,&pLcmlHandle,(void *)p,&cb, (OMX_STRING)pComponentPrivate->sDeviceString);
                     if (eError != OMX_ErrorNone){
                         OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error : InitMMCodec failed...>>>>>> \n",__LINE__);
+                        /* send an event to client */
+                        /* client should unload the component if the codec is not able to load */
+                        pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                         goto EXIT;
                     }
 #else
@@ -1057,6 +1042,7 @@
                     OMX_PRDSP2(pComponentPrivate->dbg, ": Comp: Resume Command Came from App\n");
                     OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec\n");
                     OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec  START %d\n", __LINE__);
+                    pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
                                                EMMCodecControlStart,(void *)pArgs);
 
@@ -1243,6 +1229,15 @@
                     goto EXIT;
                 }
                 OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Pause\n\n");
+#ifdef RESOURCE_MANAGER_ENABLED         
+                rm_error = RMProxy_NewSendCommand(pHandle,
+                                                  RMProxy_StateSet,
+                                                  OMX_MP3_Decoder_COMPONENT,
+                                                  OMX_StatePause,
+                                                  3456,
+                                                  NULL);
+#endif  
+
                 break;
 
             case OMX_StateWaitForResources:
@@ -1811,6 +1806,14 @@
     }
  EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting HandleCommand Function, error = %d\n", eError);
+    if (eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -1928,8 +1931,6 @@
                 }
 
                 if(pBufHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG || pComponentPrivate->bConfigData){
-                    //bConfigData flag is used to indicate if we need to parse the frame header here, 
-                    //under most circumstances, we should get this hint from the CODECCONFIG buffer flag.
 		    OMX_PRBUFFER2(pComponentPrivate->dbg, "Detected OMX_BUFFERFLAG_CODECCONFIG\n, \tproceed with parsing config data\n"); 
                     // parse the frame header
                     pComponentPrivate->pStreamData.nSyncWord = MP3DEC_GetBits(&nBitPosition, 11, pHeaderStream, OMX_TRUE);
@@ -2038,6 +2039,7 @@
                     }
                     pComponentPrivate->bConfigData = 0;
                 }
+                pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
                                            EMMCodecControlStart,
                                            (void *)pArgs);
@@ -2235,8 +2237,13 @@
     }
  EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, ": Exiting from  HandleDataBuf_FromApp: %x \n",eError);
-    if(eError == OMX_ErrorBadParameter) {
-        OMX_ERROR4(pComponentPrivate->dbg, ": Error = OMX_ErrorBadParameter\n");
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
     }
     return eError;
 }
@@ -2495,7 +2502,7 @@
                 }
                 pComponentPrivate->num_Reclaimed_Op_Buff++;
 
-                if (pLcmlHdr->pOpParam->ulIsLastBuffer){
+                if (pLcmlHdr->pOpParam->ulIsLastBuffer){ 		
                     OMX_PRBUFFER2(pComponentPrivate->dbg, "Adding EOS flag to the output buffer\n");
                     pLcmlHdr->pBufHdr->nFlags |= OMX_BUFFERFLAG_EOS;
                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
@@ -2515,7 +2522,7 @@
                         pComponentPrivate->first_buff = 2;
                         pLcmlHdr->pBufHdr->nTimeStamp = pComponentPrivate->first_TS;
                         pComponentPrivate->temp_TS = pLcmlHdr->pBufHdr->nTimeStamp;
-                        OMX_PRBUFFER1(pComponentPrivate->dbg, "first_ts = %lld\n",
+                        OMX_PRBUFFER2(pComponentPrivate->dbg, "first_ts = %lld\n",
                                    pComponentPrivate->temp_TS);
                     }else{ 
                         time_stmp = pLcmlHdr->pBufHdr->nFilledLen / (pComponentPrivate->pcmParams->nChannels * 
@@ -2524,7 +2531,7 @@
                         /* Update time stamp information */
                         pComponentPrivate->temp_TS += time_stmp;
                         pLcmlHdr->pBufHdr->nTimeStamp = pComponentPrivate->temp_TS;
-                        OMX_PRBUFFER1(pComponentPrivate->dbg, "out ts = %lld\n",
+                        OMX_PRBUFFER2(pComponentPrivate->dbg, "out ts = %lld\n",
                                    pComponentPrivate->temp_TS);
                     }
                 }
@@ -2551,32 +2558,31 @@
             }
         }
     }else if(event == EMMCodecProcessingStoped) { 
-      for (i = 0; i < pComponentPrivate->nNumInputBufPending; i++) {
-	OMX_ERROR4(pComponentPrivate->dbg, ":: %d %s returning pending inputbuffer CB %d\n", __LINE__, __FUNCTION__, i);
-	pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
-						   pComponentPrivate->pHandle->pApplicationPrivate,
-						   pComponentPrivate->pInputBufHdrPending[i]);
+                        for (i = 0; i < pComponentPrivate->nNumInputBufPending; i++) {
+					pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
+					pComponentPrivate->pHandle->pApplicationPrivate,
+					pComponentPrivate->pInputBufHdrPending[i]);
                     pComponentPrivate->nEmptyBufferDoneCount++;
 			        pComponentPrivate->pInputBufHdrPending[i] = NULL;
                     SignalIfAllBuffersAreReturned(pComponentPrivate);
-      }
-      pComponentPrivate->nNumInputBufPending = 0;
-      for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
-	OMX_ERROR4(pComponentPrivate->dbg, ":: %d %s returning pending outputbuffer CB %d\n", __LINE__, __FUNCTION__, i);
-	pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
-						  pComponentPrivate->pHandle->pApplicationPrivate,
+			}
+			pComponentPrivate->nNumInputBufPending = 0;
+			for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
+					pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
+					pComponentPrivate->pHandle->pApplicationPrivate,
 						  pComponentPrivate->pOutputBufHdrPending[i]
 						  );
                     pComponentPrivate->nFillBufferDoneCount++;
 			        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
                     SignalIfAllBuffersAreReturned(pComponentPrivate);
-      }
-      pComponentPrivate->nNumOutputBufPending=0;
+			}
+			pComponentPrivate->nNumOutputBufPending=0;
+
         pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
         if(pComponentPrivate->codecStop_waitingsignal == 0){
             pComponentPrivate->codecStop_waitingsignal = 1;             
             pthread_cond_signal(&pComponentPrivate->codecStop_threshold);
-            OMX_ERROR2(pComponentPrivate->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
+            OMX_ERROR4(pComponentPrivate->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
         }
         pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
         if (!pComponentPrivate->bNoIdleOnStop) {
@@ -2591,7 +2597,7 @@
                                               NULL);
 #endif  
             if((pComponentPrivate->nEmptyThisBufferCount != pComponentPrivate->nEmptyBufferDoneCount) || (pComponentPrivate->nFillThisBufferCount != pComponentPrivate->nFillBufferDoneCount)) {
-                if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
+                if(pthread_mutex_lock(&bufferReturned_mutex) != 0) 
                 {
                     OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: bufferReturned_mutex mutex lock error\n",__LINE__);
                 }
@@ -2635,133 +2641,44 @@
         OMX_PRDSP1(pComponentPrivate->dbg, ":: commandedState  = %p\n",args[0]);
         OMX_PRINT2(pComponentPrivate->dbg, ":: arg4 = %p\n",args[4]);
         OMX_PRINT2(pComponentPrivate->dbg, ":: arg5 = %p\n",args[5]);
+        switch ( (OMX_U32) args [4])
+        {
+            /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
+             * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
+             * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
+             * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
+             * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
+             * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
+             * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
+             * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
+
 #ifdef _ERROR_PROPAGATION__
-        /* Cheking for MMU_fault */
-        if((args[4] == (void *)USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) {
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__);
-            pComponentPrivate->bIsInvalidState=OMX_TRUE;
-            pComponentPrivate->curState = OMX_StateInvalid;
-            pHandle = pComponentPrivate->pHandle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorHardware,
-                                                   OMX_TI_ErrorSevere,
-                                                   NULL);
-        }
-#endif      
-
-        OMX_ERROR2(pComponentPrivate->dbg, ":: --------- EMMCodecDspError Here\n");
-        if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) {
-            OMX_ERROR4(pComponentPrivate->dbg, "IUALG_WARN_PLAYCOMPLETED!\n");
-#ifndef UNDER_CE
-            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                   OMX_EventBufferFlag,
-                                                   MP3D_OUTPUT_PORT,
-                                                   OMX_BUFFERFLAG_EOS,
-                                                   NULL);
-            if(pComponentPrivate->dasfmode){
-                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                       pComponentPrivate->pHandle->pApplicationPrivate,
-                                                       OMX_EventBufferFlag,
-                                                       MP3D_INPUT_PORT,
-                                                       OMX_BUFFERFLAG_EOS,
-                                                       NULL);
-            }
-            pComponentPrivate->pLcmlBufHeader[0]->pIpParam->bLastBuffer = 0;
-
-#else
-            /* add callback to application to indicate SN/USN has completed playing of current set of data */
-            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                   OMX_EventBufferFlag,
-                                                   MP3D_INPUT_PORT,
-                                                   OMX_BUFFERFLAG_EOS,
-                                                   NULL);
+            case USN_ERR_PAUSE:
+            case USN_ERR_STOP:
+            case USN_ERR_ALGCTRL:
+            case USN_ERR_STRMCTRL:
+            case USN_ERR_UNKNOWN_MSG:
+                {
+                    pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                    pComponentPrivate->curState = OMX_StateInvalid;
+                    pHandle = pComponentPrivate->pHandle;
+                    pComponentPrivate->cbInfo.EventHandler(pHandle,
+                            pHandle->pApplicationPrivate,
+                            OMX_EventError,
+                            OMX_ErrorInvalidState,
+                            OMX_TI_ErrorSevere,
+                            NULL);
+                }
+                break;
 #endif
-        }
 
-        if((int)args[5] == IUALG_WARN_CONCEALED) {
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm issued a warning. But can continue" );
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);
+            case USN_ERR_WARNING:
+            case USN_ERR_PROCESS:
+                MP3DEC_HandleUSNError (pComponentPrivate, (OMX_U32)args[5]);
+                break;
+            default:
+                break;
         }
-
-	if((int)args[5] == IUALG_ERR_NOT_SUPPORTED) {
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Parameter not supported" );
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML_Callback: IUALG_ERR_NOT_SUPPORTED\n",__LINE__);
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-	    // pComponentPrivate->curState = OMX_StateInvalid;
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError, 
-                                                   OMX_ErrorInsufficientResources,
-                                                   OMX_TI_ErrorSevere, 
-                                                   NULL);
-	}
-
-
-        if((int)args[5] == IUALG_ERR_GENERAL) {
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Cannot continue" );
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML_Callback: IUALG_ERR_GENERAL\n",__LINE__);
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError, 
-                                                   OMX_ErrorUndefined,
-                                                   OMX_TI_ErrorSevere, 
-                                                   NULL);
-        }
-
-        if( (int)args[5] == IUALG_ERR_DATA_CORRUPT ){
-            char *pArgs = "damedesuStr";
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML_Callback: IUALG_ERR_DATA_CORRUPT\n",__LINE__);
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-#ifndef UNDER_CE
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError, 
-                                                   OMX_ErrorStreamCorrupt, 
-                                                   OMX_TI_ErrorMajor, 
-                                                   NULL);
-            OMX_PRDSP2(pComponentPrivate->dbg, ": MP3DECUTILS::About to call LCML_ControlCodec STOP %d\n", __LINE__);
-            eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                       MMCodecControlStop,(void *)pArgs);
-            if(eError != OMX_ErrorNone) {
-                OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Stop..\n",
-                              __LINE__);
-                goto EXIT;
-            }
-            OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: MP3DEC: Codec has been Stopped here\n",__LINE__);
-            pComponentPrivate->curState = OMX_StateIdle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventCmdComplete, 
-                                                   OMX_ErrorNone,
-                                                   0, 
-                                                   NULL);
-#else
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError, 
-                                                   OMX_ErrorUndefined,
-                                                   OMX_TI_ErrorSevere, 
-                                                   NULL);
-#endif                  
-        }
-        if( (int)args[5] == IUALG_WARN_OVERFLOW ){
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Overflow" );
-        }
-        if( (int)args[5] == IUALG_WARN_UNDERFLOW ){
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Underflow" );
-        }
-
     } else if (event == EMMCodecStrmCtrlAck) {
  
 
@@ -2792,7 +2709,7 @@
                     if(pComponentPrivate->codecFlush_waitingsignal == 0){
                         pComponentPrivate->codecFlush_waitingsignal = 1; 
                         pthread_cond_signal(&pComponentPrivate->codecFlush_threshold);
-                        OMX_ERROR2(pComponentPrivate->dbg, "flush ack. received. for input port\n");
+                        OMX_ERROR4(pComponentPrivate->dbg, "flush ack. received. for input port\n");
                     }     
                     pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex);
 
@@ -2835,7 +2752,7 @@
                     if(pComponentPrivate->codecFlush_waitingsignal == 0){
                         pComponentPrivate->codecFlush_waitingsignal = 1; 
                         pthread_cond_signal(&pComponentPrivate->codecFlush_threshold);
-                        OMX_ERROR2(pComponentPrivate->dbg, "flush ack. received. for output port\n");
+                        OMX_ERROR4(pComponentPrivate->dbg, "flush ack. received. for output port\n");
                     }     
                     pthread_mutex_unlock(&pComponentPrivate->codecFlush_mutex);
                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle, 
@@ -3150,23 +3067,17 @@
     OMX_U32 nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
 
     OMX_U32 i=0;
-    char *tempt = NULL;
 
     OMX_PRINT1(pComponentPrivate->dbg, ":: MP3DEC_CleanupInitParams()\n");
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing:  pComponentPrivate->strmAttr = %p\n", pComponentPrivate->strmAttr);
-    MP3D_OMX_FREE(pComponentPrivate->strmAttr); 
+    OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr); 
 
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT];
 	
     for(i=0; i<nIpBuf; i++) {
         OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pTemp_lcml->pIpParam = %p\n",pTemp_lcml->pIpParam);
-        tempt = (char*)pTemp_lcml->pIpParam;
-        if(tempt != NULL){
-            tempt -= EXTRA_BYTES;
-        }
-        pTemp_lcml->pIpParam = (MP3DEC_UAlgInBufParamStruct*)tempt;
-        MP3D_OMX_FREE(pTemp_lcml->pIpParam);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, MP3DEC_UAlgInBufParamStruct);
 
         pTemp_lcml++;
     }
@@ -3175,38 +3086,22 @@
     
     OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT] = %p\n",
                     pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]);
-    MP3D_OMX_FREE(pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]);
 
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT];
     for(i=0; i<nOpBuf; i++) {
         OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pTemp_lcml->pOpParam = %p\n",pTemp_lcml->pOpParam);
-
-        tempt = (char*)pTemp_lcml->pOpParam;
-        if(tempt != NULL){
-            tempt -= EXTRA_BYTES;
-        }
-        pTemp_lcml->pOpParam = (MP3DEC_UAlgOutBufParamStruct*)tempt;
-        MP3D_OMX_FREE(pTemp_lcml->pOpParam);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, MP3DEC_UAlgOutBufParamStruct);
         pTemp_lcml++;
     }
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, ":: Freeing: pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT] = %p\n",
                     pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]);
-    MP3D_OMX_FREE(pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]);
     
-    tempt = (char*)pComponentPrivate->pParams;
-    if(tempt != NULL){
-        tempt -= EXTRA_BYTES;
-    }
-    pComponentPrivate->pParams = (USN_AudioCodecParams *) tempt;
-    MP3D_OMX_FREE(pComponentPrivate->pParams);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, USN_AudioCodecParams);
     
-    tempt = (char *) pComponentPrivate->ptAlgDynParams;
-    if(tempt != NULL) {
-        tempt -= EXTRA_BYTES;
-    }
-    pComponentPrivate->ptAlgDynParams = (MP3DEC_UALGParams*) tempt;
-    MP3D_OMX_FREE(pComponentPrivate->ptAlgDynParams);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->ptAlgDynParams, MP3DEC_UALGParams);
     
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting Successfully MP3DEC_CleanupInitParams()\n");
 
@@ -3233,7 +3128,6 @@
     MP3DEC_COMPONENT_PRIVATE *pComponentPrivate =
         (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     MP3D_LCML_BUFHEADERTYPE *pTemp_lcml;
-    char *pTemp = NULL;
     OMX_U32 nIpBuf = 0;
     OMX_U32 nOpBuf = 0;
     OMX_U32 i=0;
@@ -3244,18 +3138,13 @@
         for(i=0; i<nIpBuf; i++) {
             OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pIpParam = %p\n",
                           pTemp_lcml->pIpParam);
-            pTemp = (char*)pTemp_lcml->pIpParam;
-            if (pTemp != NULL) {
-                pTemp -= EXTRA_BYTES;
-            }
-            pTemp_lcml->pIpParam = (MP3DEC_UAlgInBufParamStruct*)pTemp;
-            MP3D_OMX_FREE(pTemp_lcml->pIpParam);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, MP3DEC_UAlgInBufParamStruct);
             pTemp_lcml++;
         }
 
         OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing pLcmlBufHeader[MP3D_INPUT_PORT] = %p\n",
                       pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]);
-        MP3D_OMX_FREE(pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT]);
 
     }else if(indexport == 1 || indexport == -1){
         nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
@@ -3263,18 +3152,13 @@
         for(i=0; i<nOpBuf; i++) {
             OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pOpParam = %p\n",
                           pTemp_lcml->pOpParam);
-            pTemp = (char*)pTemp_lcml->pOpParam;
-            if (pTemp != NULL) {
-                pTemp -= EXTRA_BYTES;
-            }
-            pTemp_lcml->pOpParam = (MP3DEC_UAlgOutBufParamStruct*)pTemp;
-            MP3D_OMX_FREE(pTemp_lcml->pOpParam);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pOpParam, MP3DEC_UAlgOutBufParamStruct);
             pTemp_lcml++;
         }
 
         OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: pLcmlBufHeader[MP3D_OUTPUT_PORT] = %p\n",
                       pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]);
-        MP3D_OMX_FREE(pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT]);
 
     }else{
         OMX_ERROR4(pComponentPrivate->dbg, "Bad indexport!\n");
@@ -3472,7 +3356,6 @@
     MP3D_LCML_BUFHEADERTYPE *pTemp_lcml;
     OMX_U32 size_lcml;
     OMX_U8 *ptr;
-    char *char_temp = NULL;
 
     OMX_PRINT1(pComponentPrivate->dbg, ":: Entered Fill_LCMLInitParams");
 
@@ -3491,7 +3374,7 @@
         OMX_PRBUFFER2(pComponentPrivate->dbg, ":: bufAlloced = %d\n",pComponentPrivate->bufAlloced);
         size_lcml = nIpBuf * sizeof(MP3D_LCML_BUFHEADERTYPE);
 
-        MP3D_OMX_MALLOC_SIZE(ptr,size_lcml,OMX_U8);
+        OMX_MALLOC_SIZE(ptr,size_lcml,OMX_U8);
         pTemp_lcml = (MP3D_LCML_BUFHEADERTYPE *)ptr;
 
         pComponentPrivate->pLcmlBufHeader[MP3D_INPUT_PORT] = pTemp_lcml;
@@ -3512,13 +3395,9 @@
             pTemp_lcml->eDir = OMX_DirInput;
             pTemp_lcml->pOtherParams[i] = NULL;
 
-            MP3D_OMX_MALLOC_SIZE(pTemp_lcml->pIpParam,
-                                 (sizeof(MP3DEC_UAlgInBufParamStruct) + DSP_CACHE_ALIGNMENT),
+            OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam,
+                                 sizeof(MP3DEC_UAlgInBufParamStruct),
                                  MP3DEC_UAlgInBufParamStruct);
-            char_temp = (char*)pTemp_lcml->pIpParam;
-            char_temp += EXTRA_BYTES;
-            pTemp_lcml->pIpParam = (MP3DEC_UAlgInBufParamStruct*)char_temp;
-
             pTemp_lcml->pIpParam->bLastBuffer = 0;
 
             pTemp->nFlags = NORMAL_BUFFER;
@@ -3534,7 +3413,7 @@
 
     if(indexport == 1 || indexport == -1){
         size_lcml = nOpBuf * sizeof(MP3D_LCML_BUFHEADERTYPE);
-        MP3D_OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,MP3D_LCML_BUFHEADERTYPE);
+        OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,MP3D_LCML_BUFHEADERTYPE);
         pComponentPrivate->pLcmlBufHeader[MP3D_OUTPUT_PORT] = pTemp_lcml;
 
         for (i=0; i<nOpBuf; i++) {
@@ -3552,12 +3431,9 @@
             pTemp_lcml->eDir = OMX_DirOutput;
             pTemp_lcml->pOtherParams[i] = NULL;
 
-            MP3D_OMX_MALLOC_SIZE(pTemp_lcml->pOpParam,
-                                 (sizeof(MP3DEC_UAlgOutBufParamStruct) + DSP_CACHE_ALIGNMENT),
+            OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pOpParam,
+                                 sizeof(MP3DEC_UAlgOutBufParamStruct),
                                  MP3DEC_UAlgOutBufParamStruct);
-            char_temp = (char*)pTemp_lcml->pOpParam;
-            char_temp += EXTRA_BYTES;
-            pTemp_lcml->pOpParam = (MP3DEC_UAlgOutBufParamStruct*)char_temp;
             pTemp_lcml->pOpParam->ulFrameCount = DONT_CARE;
             pTemp_lcml->pOpParam->ulIsLastBuffer = 0;
 
@@ -3611,9 +3487,10 @@
     nOutput = nOutput >> (32 - nBits) ;
     return nOutput;
 }
+
 /* ========================================================================== */
 /**
-* @SignalIfAllBuffersAreReturned() This function send signals if OMX returned all buffers to app
+* @SignalIfAllBuffersAreReturned() This function send signals if OMX returned all buffers to app 
 *
 * @param AACDEC_COMPONENT_PRIVATE *pComponentPrivate
 *
@@ -3628,7 +3505,7 @@
 {
     if((pComponentPrivate->nEmptyThisBufferCount == pComponentPrivate->nEmptyBufferDoneCount) && (pComponentPrivate->nFillThisBufferCount == pComponentPrivate->nFillBufferDoneCount))
     {
-        if(pthread_mutex_lock(&bufferReturned_mutex) != 0)
+        if(pthread_mutex_lock(&bufferReturned_mutex) != 0) 
         {
             OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex lock error\n",__LINE__);
         }
@@ -3642,3 +3519,113 @@
     }
 }
 
+/*  =========================================================================*/
+/*  func    MP3DEC_HandleUSNError
+/*
+/*  desc    Handles error messages returned by the dsp
+/*
+/*@return n/a
+/*
+/*  =========================================================================*/
+void MP3DEC_HandleUSNError (MP3DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
+{
+    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U8 pending_buffers = OMX_FALSE;
+    OMX_U32 i;
+    switch (arg)
+    {
+        case IUALG_WARN_CONCEALED:
+        case IUALG_WARN_UNDERFLOW:
+        case IUALG_WARN_OVERFLOW:
+        case IUALG_WARN_ENDOFDATA:
+            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error" );
+            /* all of these are informative messages, Algo can recover, no need to notify the
+             * IL Client at this stage of the implementation */
+            break;
+        case IUALG_WARN_PLAYCOMPLETED:
+
+            {
+            OMX_ERROR4(pComponentPrivate->dbg, "IUALG_WARN_PLAYCOMPLETED!\n");
+#ifndef UNDER_CE
+            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                   pComponentPrivate->pHandle->pApplicationPrivate,
+                                                   OMX_EventBufferFlag,
+                                                   OMX_DirOutput,
+                                                   OMX_BUFFERFLAG_EOS,
+                                                   NULL);
+            if(pComponentPrivate->dasfmode){
+                pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       OMX_EventBufferFlag,
+                                                       (OMX_U32)NULL,
+                                                       OMX_BUFFERFLAG_EOS,
+                                                       NULL);
+            }
+            pComponentPrivate->pLcmlBufHeader[0]->pIpParam->bLastBuffer = 0;
+#else
+            /* add callback to application to indicate SN/USN has completed playing of current set of date */
+            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                   pComponentPrivate->pHandle->pApplicationPrivate,
+                                                   OMX_EventBufferFlag,
+                                                   (OMX_U32)NULL,
+                                                   OMX_BUFFERFLAG_EOS,
+                                                   NULL);
+#endif
+            }
+            break;
+
+#ifdef _ERROR_PROPAGATION__
+        case IUALG_ERR_BAD_HANDLE:
+        case IUALG_ERR_DATA_CORRUPT:
+        case IUALG_ERR_NOT_SUPPORTED:
+        case IUALG_ERR_ARGUMENT:
+        case IUALG_ERR_NOT_READY:
+        case IUALG_ERR_GENERAL:
+
+            {
+                /* all of these are fatal messages, Algo can not recover
+                 * hence return an error */
+                OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error, cannot recover" );
+                pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                pComponentPrivate->curState = OMX_StateInvalid;
+                pHandle = pComponentPrivate->pHandle;
+                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                        pHandle->pApplicationPrivate,
+                        OMX_EventError,
+                        OMX_ErrorInvalidState,
+                        OMX_TI_ErrorSevere,
+                        NULL);
+            }
+            break;
+#endif
+        default:
+            break;
+    }
+}
+
+#ifdef RESOURCE_MANAGER_ENABLED
+void MP3_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+{
+    OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
+    OMX_STATETYPE state = OMX_StateIdle;
+    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
+    MP3DEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
+
+    pCompPrivate = (MP3DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+
+    if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) {
+        if (pCompPrivate->curState == OMX_StateExecuting ||
+            pCompPrivate->curState == OMX_StatePause) {
+            write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
+            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
+            pCompPrivate->bPreempted = 1;
+        }
+    }
+    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
+        pCompPrivate->cbInfo.EventHandler (pHandle,
+                                           pHandle->pApplicationPrivate,
+                                           OMX_EventResourcesAcquired, 0,0,
+                                           NULL);
+    }
+}
+#endif
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 ea90b96..7703961 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
@@ -100,19 +100,6 @@
 /* define component role */
 #define MP3_DEC_ROLE "audio_decoder.mp3"
 
-
-#ifdef MP3DEC_MEMDEBUG
-void *arr[500]; int lines[500]; int bytes[500]; char file[500][50];
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-void * mymalloc(int line, char *s, int size);
-int myfree(void *dp, int line, char *s);
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
-
 /****************************************************************
 *  EXTERNAL REFERENCES NOTE : only use if not found in header file
 ****************************************************************/
@@ -247,7 +234,7 @@
     pHandle->UseBuffer = UseBuffer;
     pHandle->GetExtensionIndex = GetExtensionIndex;
     pHandle->ComponentRoleEnum = ComponentRoleEnum;
-    MP3D_OMX_MALLOC(pHandle->pComponentPrivate,MP3DEC_COMPONENT_PRIVATE);
+    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate,MP3DEC_COMPONENT_PRIVATE);
 
     pComponentPrivate = pHandle->pComponentPrivate;
     pComponentPrivate->pHandle = pHandle;
@@ -270,15 +257,15 @@
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_FALSE;
 
 
-    MP3D_OMX_MALLOC(pCompPort, MP3D_AUDIODEC_PORT_TYPE);
+    OMX_MALLOC_GENERIC(pCompPort, MP3D_AUDIODEC_PORT_TYPE);
     pComponentPrivate->pCompPort[MP3D_INPUT_PORT] =  pCompPort;
 
-    MP3D_OMX_MALLOC(pCompPort, MP3D_AUDIODEC_PORT_TYPE);
+    OMX_MALLOC_GENERIC(pCompPort, MP3D_AUDIODEC_PORT_TYPE);
     pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT] = pCompPort;
-    MP3D_OMX_MALLOC(pTemp, MP3D_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pTemp, MP3D_BUFFERLIST);
     pComponentPrivate->pInputBufferList = pTemp;
 
-    MP3D_OMX_MALLOC(pTemp, MP3D_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pTemp, MP3D_BUFFERLIST);
     pComponentPrivate->pOutputBufferList = pTemp;
 
     pComponentPrivate->pInputBufferList->numBuffers = 0;
@@ -291,9 +278,9 @@
 
     pComponentPrivate->bufAlloced = 0;
 
-    MP3D_OMX_MALLOC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
     OMX_CONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
-    MP3D_OMX_MALLOC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
     pComponentPrivate->sPortParam->nPorts = NUM_OF_PORTS;
     pComponentPrivate->sPortParam->nStartPortNumber = 0x0;
@@ -301,8 +288,8 @@
 
     pComponentPrivate->pcmParams = NULL;
 
-    MP3D_OMX_MALLOC(mp3_ip,OMX_AUDIO_PARAM_MP3TYPE);
-    MP3D_OMX_MALLOC(mp3_op,OMX_AUDIO_PARAM_PCMMODETYPE);
+    OMX_MALLOC_GENERIC(mp3_ip,OMX_AUDIO_PARAM_MP3TYPE);
+    OMX_MALLOC_GENERIC(mp3_op,OMX_AUDIO_PARAM_PCMMODETYPE);
 
 
     pComponentPrivate->mp3Params = mp3_ip;
@@ -403,8 +390,8 @@
     pComponentPrivate->InIdle_goingtoloaded = 0;
 #endif
 
-    MP3D_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
-    MP3D_OMX_MALLOC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
 
     pComponentPrivate->pPortDef[MP3D_INPUT_PORT] = pPortDef_ip;
     pComponentPrivate->pPortDef[MP3D_OUTPUT_PORT] = pPortDef_op;
@@ -416,7 +403,7 @@
     pPortDef_ip->nBufferCountActual                 = MP3D_NUM_INPUT_BUFFERS;
     pPortDef_ip->nBufferCountMin                    = MP3D_NUM_INPUT_BUFFERS;
     pPortDef_ip->nBufferSize                        = MP3D_INPUT_BUFFER_SIZE;
-    pPortDef_ip->nBufferAlignment                   = EXTRA_BYTES;
+    pPortDef_ip->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
     pPortDef_ip->bEnabled                           = OMX_TRUE;
     pPortDef_ip->bPopulated                         = OMX_FALSE;
     pPortDef_ip->eDomain                            = OMX_PortDomainAudio;
@@ -433,7 +420,7 @@
     pPortDef_op->nBufferCountMin                    = MP3D_NUM_OUTPUT_BUFFERS;
     pPortDef_op->nBufferCountActual                 = MP3D_NUM_OUTPUT_BUFFERS;
     pPortDef_op->nBufferSize                        = MP3D_OUTPUT_BUFFER_SIZE;
-    pPortDef_op->nBufferAlignment                   = EXTRA_BYTES;
+    pPortDef_op->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
     pPortDef_op->bEnabled                           = OMX_TRUE;
     pPortDef_op->bPopulated                         = OMX_FALSE;
     pPortDef_op->eDomain                            = OMX_PortDomainAudio;
@@ -442,8 +429,8 @@
     pPortDef_op->format.audio.pNativeRender         = NULL;
     pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
 
-    MP3D_OMX_MALLOC(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
-    MP3D_OMX_MALLOC(pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[MP3D_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pCompPort[MP3D_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
 
@@ -517,12 +504,12 @@
  EXIT:
     if(OMX_ErrorNone != eError) {
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__);
-        MP3D_OMX_FREE(pPortDef_ip);
-        MP3D_OMX_FREE(pPortDef_op);
-        MP3D_OMX_FREE(mp3_ip);
-        MP3D_OMX_FREE(mp3_op);
-        MP3D_OMX_FREE(pComponentPrivate);
-        MP3D_OMX_FREE(pTemp);
+        OMX_MEMFREE_STRUCT(pPortDef_ip);
+        OMX_MEMFREE_STRUCT(pPortDef_op);
+        OMX_MEMFREE_STRUCT(mp3_ip);
+        OMX_MEMFREE_STRUCT(mp3_op);
+        OMX_MEMFREE_STRUCT(pComponentPrivate);
+        OMX_MEMFREE_STRUCT(pTemp);
     }
     OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting OMX_ComponentInit\n");
     return eError;
@@ -716,7 +703,7 @@
                                    OMX_PTR ComponentParameterStructure)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    MP3DEC_COMPONENT_PRIVATE  *pComponentPrivate;
+    MP3DEC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure;
     /*    OMX_PARAM_BUFFERSUPPLIERTYPE *pBufferSupplier;*/
 
@@ -748,6 +735,7 @@
     switch(nParamIndex){
     case OMX_IndexParamAudioInit:
         OMX_PRDSP2(pComponentPrivate->dbg, ":: GetParameter OMX_IndexParamAudioInit\n");
+        MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
         memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
     case OMX_IndexParamPortDefinition:
@@ -810,6 +798,7 @@
 
     case OMX_IndexParamPriorityMgmt:
         OMX_PRDSP2(pComponentPrivate->dbg, " :: GetParameter OMX_IndexParamPriorityMgmt \n");
+        MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
         memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
 
         break;
@@ -874,8 +863,10 @@
         break;
     }
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, " :: Exiting GetParameter\n");
-    OMX_PRINT1(pComponentPrivate->dbg, " :: Returning = 0x%x\n",eError);
+    if (pComponentPrivate != NULL) {
+	 OMX_PRINT1(pComponentPrivate->dbg, " :: Exiting GetParameter\n");
+	 OMX_PRINT1(pComponentPrivate->dbg, " :: Returning = 0x%x\n", eError);
+    }
     return eError;
 }
 
@@ -906,7 +897,7 @@
                                    OMX_PTR pCompParam)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    MP3DEC_COMPONENT_PRIVATE  *pComponentPrivate;
+    MP3DEC_COMPONENT_PRIVATE  *pComponentPrivate = NULL;
     OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE *pComponentParamPort = NULL;
     OMX_AUDIO_PARAM_MP3TYPE *pCompMp3Param = NULL;
@@ -953,6 +944,7 @@
         OMX_PRDSP2(pComponentPrivate->dbg, " :: SetParameter OMX_IndexParamAudioMp3 \n");
         pCompMp3Param = (OMX_AUDIO_PARAM_MP3TYPE *)pCompParam;
         if(pCompMp3Param->nPortIndex == MP3D_INPUT_PORT) {
+            MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->mp3Params, 1, 1);
             memcpy(pComponentPrivate->mp3Params,pCompMp3Param,sizeof(OMX_AUDIO_PARAM_MP3TYPE));
         } 
         else {
@@ -1006,11 +998,13 @@
         break;
     case OMX_IndexParamPriorityMgmt:
         OMX_PRDSP2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamPriorityMgmt \n");
+        MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->pPriorityMgmt, 1, 1);
         memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
     case OMX_IndexParamAudioInit:
         OMX_PRDSP2(pComponentPrivate->dbg, ":: SetParameter OMX_IndexParamAudioInit \n");
+        MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->sPortParam, 1, 1);
         memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
 
@@ -1028,6 +1022,7 @@
         OMX_PRDSP2(pComponentPrivate->dbg, " :: SetParameter OMX_IndexParamAudioPcm \n");
         pPcmPort= (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
         if(pPcmPort->nPortIndex == MP3D_OUTPUT_PORT){
+            MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate->pcmParams, 1, 1);
             memcpy(pComponentPrivate->pcmParams, pPcmPort, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
         }else{
             OMX_ERROR4(pComponentPrivate->dbg, ":: OMX_ErrorBadPortIndex from SetParameter");
@@ -1068,8 +1063,10 @@
         break;
     }
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetParameter\n");
-    OMX_PRINT1(pComponentPrivate->dbg, ":: Returning = 0x%x\n",eError);
+    if (pComponentPrivate != NULL) {
+	 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetParameter\n");
+	 OMX_PRINT1(pComponentPrivate->dbg, ":: Returning = 0x%x\n", eError);
+    }
     return eError;
 }
 
@@ -1092,7 +1089,7 @@
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
-    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
+    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
 #ifdef DSP_RENDERING_ON
     OMX_AUDIO_CONFIG_MUTETYPE *pMuteStructure = NULL;
     OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL;
@@ -1258,8 +1255,10 @@
         break;
     }
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetConfig\n");
-    OMX_PRINT1(pComponentPrivate->dbg, " :: Returning = 0x%x\n",eError);
+    if (pComponentPrivate != NULL) {
+	 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetConfig\n");
+	 OMX_PRINT1(pComponentPrivate->dbg, " :: Returning = 0x%x\n", eError);
+    }
     return eError;
 }
 
@@ -1290,7 +1289,7 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
 
-    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
+    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
 
 
     MP3D_OMX_CONF_CHECK_CMD(pHandle,1,1);
@@ -1309,7 +1308,9 @@
     OMX_PRSTATE2(pComponentPrivate->dbg, "****************** Component State Set to Loaded\n\n");
     pComponentPrivate->curState = OMX_StateLoaded;
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetCallbacks\n");
+    if (pComponentPrivate != NULL) {
+	 OMX_PRINT1(pComponentPrivate->dbg, ":: Exiting SetCallbacks\n");
+    }
     return eError;
 }
 
@@ -1405,19 +1406,16 @@
     }   
 #endif
     
-    MP3D_OMX_MALLOC(streamInfo,TI_OMX_STREAM_INFO);
-    if(streamInfo == NULL) {
-        eError = OMX_ErrorBadParameter;
-        goto EXIT;
-    }
+    OMX_MALLOC_GENERIC(streamInfo,TI_OMX_STREAM_INFO);
     
     if(nConfigIndex == OMX_IndexCustomMp3DecStreamInfoConfig) {
         streamInfo->streamId = pComponentPrivate->streamID;
+        MP3D_OMX_CONF_CHECK_CMD(ComponentConfigStructure, 1, 1);
         memcpy(ComponentConfigStructure,streamInfo,sizeof(TI_OMX_STREAM_INFO));
     } else if(nConfigIndex == OMX_IndexCustomDebug) {
 	OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
     }
-    MP3D_OMX_FREE(streamInfo);
+    OMX_MEMFREE_STRUCT(streamInfo);
     
  EXIT:
     return eError;
@@ -1495,7 +1493,7 @@
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
-    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
+    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
     int ret=0;
     
@@ -1567,7 +1565,9 @@
     }
     
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, " :: Exiting EmptyThisBuffer\n");
+    if (pComponentPrivate != NULL) {
+	 OMX_PRINT1(pComponentPrivate->dbg, " :: Exiting EmptyThisBuffer\n");
+    }
     return eError;
 }
 
@@ -1596,7 +1596,7 @@
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
-    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
+    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     int nRet=0;
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
 
@@ -1691,7 +1691,9 @@
     }
 
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, ": Exiting FillThisBuffer\n");
+    if (pComponentPrivate != NULL) {
+	 OMX_PRINT1(pComponentPrivate->dbg, ": Exiting FillThisBuffer\n");
+    }
     return eError;
 }
 
@@ -1719,7 +1721,7 @@
     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
     MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     int k=0, k2 = 0;
-    struct OMX_TI_Debug dbg;
+    struct OMX_TI_Debug dbg = {0};
 
     MP3D_OMX_CONF_CHECK_CMD(pComponent,1,1)
         pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)pComponent->pComponentPrivate;
@@ -1771,13 +1773,13 @@
                   PERF_BoundaryComplete | PERF_BoundaryCleanup);
     PERF_Done(pComponentPrivate->pPERF);
 #endif
-    MP3D_OMX_FREE(pComponentPrivate->sDeviceString);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
 
     OMX_PRBUFFER2(dbg, ":: Freeing: pComponentPrivate = %p\n",pComponentPrivate);
     OMX_PRINT1(dbg, "::*********** ComponentDeinit is Done************** \n");
  EXIT:
     OMX_DBG_CLOSE(dbg);
-    MP3D_OMX_FREE(pComponentPrivate);
+    OMX_MEMFREE_STRUCT(pComponentPrivate);
     return eError;
 }
 
@@ -1851,7 +1853,7 @@
                    OMX_IN OMX_U32 nSizeBytes)
 {
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
-    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate;
+    MP3DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_BUFFERHEADERTYPE *pBufferHeader = NULL;
 
@@ -1860,6 +1862,7 @@
     pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     OMX_PRINT1 (pComponentPrivate->dbg,"Entering AllocateBuffer\n");
     
+    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
 #ifdef _ERROR_PROPAGATION__
     if (pComponentPrivate->curState == OMX_StateInvalid){
         eError = OMX_ErrorInvalidState;
@@ -1867,7 +1870,6 @@
     }   
 #endif
 
-    MP3D_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
     pPortDef = ((MP3DEC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
 
     MP3D_OMX_CONF_CHECK_CMD(pPortDef, 1, 1);
@@ -1883,15 +1885,11 @@
 #endif
     }
 
-    MP3D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
     memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
 
     /* This extra 256 bytes memory is required to avoid DSP caching issues */
-    pBufferHeader->pBuffer = (OMX_U8 *)newmalloc(nSizeBytes + DSP_CACHE_ALIGNMENT);
-    if(NULL == pBufferHeader->pBuffer) {
-        OMX_ERROR4(pComponentPrivate->dbg, " :: Malloc Failed\n");
-        goto EXIT;
-    }
+    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes, OMX_U8);
     OMX_PRBUFFER2(pComponentPrivate->dbg, ": Malloced = %p\n",pBufferHeader->pBuffer);
     pBufferHeader->nVersion.nVersion = MP3DEC_BUFHEADER_VERSION;
 
@@ -1903,8 +1901,6 @@
     OMX_PRBUFFER2(pComponentPrivate->dbg, " :: Op Num = %ld\n", pComponentPrivate->pOutputBufferList->numBuffers);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "********************************************\n");
 
-    pBufferHeader->pBuffer += EXTRA_BYTES;
-
     pBufferHeader->pAppPrivate = pAppPrivate;
     pBufferHeader->pPlatformPrivate = pComponentPrivate;
     pBufferHeader->nAllocLen = nSizeBytes;
@@ -1935,7 +1931,7 @@
     } else if (nPortIndex == MP3D_OUTPUT_PORT) {
         pBufferHeader->nInputPortIndex = -1;
         pBufferHeader->nOutputPortIndex = nPortIndex;
-        MP3D_OMX_MALLOC(pBufferHeader->pOutputPortPrivate,MP3DEC_BUFDATA);
+        OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate,MP3DEC_BUFDATA);
         pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
 
         pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
@@ -1989,9 +1985,13 @@
 
  EXIT:
     if(OMX_ErrorNone != eError) {
-        OMX_ERROR4(pComponentPrivate->dbg, "%d :: ************* ERROR: Freeing Other Malloced Resources\n",__LINE__);
-        MP3D_OMX_FREE(pBufferHeader->pBuffer);
-        MP3D_OMX_FREE(pBufferHeader);
+	 if (pComponentPrivate != NULL) {
+	     OMX_ERROR4(pComponentPrivate->dbg, "%d :: ************* ERROR: Freeing Other Malloced Resources\n", __LINE__);
+	}
+	if (pBufferHeader != NULL) {
+	     OMX_MEMFREE_STRUCT_DSPALIGN(pBufferHeader->pBuffer, OMX_U8);
+	     OMX_MEMFREE_STRUCT(pBufferHeader);
+	}
     }
     return eError;
 }
@@ -2057,14 +2057,7 @@
 
     if (inputIndex != -1) {
         if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
-            buff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
-            if (buff != 0){
-                buff -= EXTRA_BYTES;
-            }
-            OMX_PRBUFFER2(pComponentPrivate->dbg, ":[FREE] %p\n",buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "\n Freeing:  %p IP Buffer\n",buff);
-            MP3D_OMX_FREE(buff);
-            buff = NULL;
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
         }
 #ifdef __PERF_INSTRUMENTATION__
         PERF_SendingBuffer(pComponentPrivate->pPERF,
@@ -2075,7 +2068,7 @@
         OMX_PRBUFFER2(pComponentPrivate->dbg, "Freeing: %p IP Buf Header\n\n",
                         pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
 
-        MP3D_OMX_FREE(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
         pComponentPrivate->pInputBufferList->pBufHdr[inputIndex] = NULL;
         pComponentPrivate->pInputBufferList->numBuffers--;
 
@@ -2121,15 +2114,7 @@
         }
 
         if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
-            buff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
-            if (buff != 0){
-                buff -= EXTRA_BYTES;
-            }
-            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: FreeBuffer\n");
-            OMX_PRBUFFER2(pComponentPrivate->dbg, ":[FREE] %p\n",buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, " Freeing: %p OP Buffer\n",buff);
-            MP3D_OMX_FREE(buff);
-            buff = NULL;
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, OMX_U8);
         }
 #ifdef __PERF_INSTRUMENTATION__
         PERF_SendingBuffer(pComponentPrivate->pPERF,
@@ -2139,8 +2124,8 @@
 #endif
         OMX_PRBUFFER2(pComponentPrivate->dbg, " Freeing: %p OP Buf Header\n\n",
                         pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
-        MP3D_OMX_FREE(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
-        MP3D_OMX_FREE(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
         pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex] = NULL;
         pComponentPrivate->pOutputBufferList->numBuffers--;
 
@@ -2308,13 +2293,13 @@
     }
 #endif  
 
-    MP3D_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
     memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
 
     if (nPortIndex == MP3D_OUTPUT_PORT) {
         pBufferHeader->nInputPortIndex = -1;
         pBufferHeader->nOutputPortIndex = nPortIndex;
-        MP3D_OMX_MALLOC(pBufferHeader->pOutputPortPrivate,MP3DEC_BUFDATA);
+        OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate,MP3DEC_BUFDATA);
         pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
         pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
         pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
@@ -2422,7 +2407,10 @@
    
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     pComponentPrivate = (MP3DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
-    if(nIndex == 0){
+    if (cRole == NULL){
+        eError = OMX_ErrorBadParameter;
+    }
+    else if(nIndex == 0){
         memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
         OMX_PRINT1(pComponentPrivate->dbg, "[ComponenetRoleEnum] cRole = %s\n",cRole);
     }
@@ -2492,41 +2480,4 @@
      return ret;
 }
 #endif
-#ifdef MP3DEC_MEMDEBUG
-void * mymalloc(int line, char *s, int size)
-{
-   void *p;    
-   int e=0;
-   p = malloc(size);
-   if(p==NULL){
-       OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
-       }
-   else{
-         while((lines[e]!=0)&& (e<500) ){
-              e++;
-         }
-         arr[e]=p;
-         lines[e]=line;
-         bytes[e]=size;
-         strcpy(file[e],s);
-         OMXDBG_PRINT(stderr, BUFFER, 2, 0, "Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
-   }
-   return p;
-}
 
-int myfree(void *dp, int line, char *s){
-    int q;
-    for(q=0;q<500;q++){
-        if(arr[q]==dp){
-	   OMXDBG_PRINT(stderr, PRINT, 2, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
-           free(dp);
-           dp = NULL;
-           lines[q]=0;
-           strcpy(file[q],"");
-           break;
-        }            
-     }    
-     if(500==q)
-	 OMXDBG_PRINT(stderr, PRINT, 2, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
-}
-#endif
diff --git a/omx/audio/src/openmax_il/nbamr_dec/inc/OMX_AmrDec_Utils.h b/omx/audio/src/openmax_il/nbamr_dec/inc/OMX_AmrDec_Utils.h
index 3801274..cba32aa 100644
--- a/omx/audio/src/openmax_il/nbamr_dec/inc/OMX_AmrDec_Utils.h
+++ b/omx/audio/src/openmax_il/nbamr_dec/inc/OMX_AmrDec_Utils.h
@@ -136,17 +136,12 @@
 OMX_ERRORTYPE NBAMRDECFill_LCMLInitParams(OMX_HANDLETYPE pHandle,
                   LCML_DSP *plcml_Init,OMX_U16 arr[]);
 
-
 OMX_ERRORTYPE NBAMRDECGetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader, OMX_DIRTYPE *eDir);
 OMX_U32 NBAMRDECHandleCommand (AMRDEC_COMPONENT_PRIVATE *pComponentPrivate);
 
 OMX_ERRORTYPE NBAMRDECHandleDataBuf_FromApp(OMX_BUFFERHEADERTYPE *pBufHeader,
         AMRDEC_COMPONENT_PRIVATE *pComponentPrivate);
 
-
-/* OMX_ERRORTYPE NBAMRDECHandleDataBuf_FromLCML(AMRDEC_COMPONENT_PRIVATE* pComponentPrivate); */
-
-
 void  AddHeader(BYTE **pFileBuf);    
 void  ResetPtr(BYTE **pFileBuf);     
 OMX_HANDLETYPE NBAMRDECGetLCMLHandle(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate);
@@ -157,11 +152,14 @@
 OMX_U32 NBAMRDEC_IsPending(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir);
 OMX_ERRORTYPE NBAMRDECFill_LCMLInitParamsEx(OMX_HANDLETYPE pComponent);
 OMX_U32 NBAMRDEC_IsValid(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir) ;
-/* OMX_ERRORTYPE NBAMRDEC_TransitionToIdle(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate); */
 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle, int size, void* pArmPtr, DMM_BUFFER_OBJ* pDmmBuf, struct OMX_TI_Debug dbg);
 OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg);
-/*void NBAMR_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData); */
 
+#ifdef RESOURCE_MANAGER_ENABLED
+void NBAMR_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
+
+void NBAMRDEC_HandleUSNError (AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
 #ifdef UNDER_CE
 	#ifndef _OMX_EVENT_
 		#define _OMX_EVENT_
diff --git a/omx/audio/src/openmax_il/nbamr_dec/inc/OMX_AmrDecoder.h b/omx/audio/src/openmax_il/nbamr_dec/inc/OMX_AmrDecoder.h
index 48fa120..833cfe2 100644
--- a/omx/audio/src/openmax_il/nbamr_dec/inc/OMX_AmrDecoder.h
+++ b/omx/audio/src/openmax_il/nbamr_dec/inc/OMX_AmrDecoder.h
@@ -46,7 +46,10 @@
 #include <OMX_Component.h>
 #include <pthread.h>
 #include <OMX_TI_Debug.h>
-/* #include <ResourceManagerProxyAPI.h> */
+
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 
 #ifdef __PERF_INSTRUMENTATION__
     #include "perf.h"
@@ -56,9 +59,6 @@
 #include <AudioManagerAPI.h>
 #endif
 
-#ifndef UNDER_CE
-/*#include <ResourceManagerProxyAPI.h> */
-#endif
 
 #ifndef ANDROID
     #define ANDROID
@@ -205,6 +205,18 @@
  */
 /* ======================================================================= */
 #define IP_BUFFERSIZE 4096
+/* ======================================================================= */
+/**
+ * @def    NUM_MIME_BYTES_ARRAY               amrMimeBytes array size
+ */
+/* ======================================================================= */
+#define NUM_MIME_BYTES_ARRAY 16
+/* ======================================================================= */
+/**
+ * @def    NUM_IF2_BYTES_ARRAY                amrIF2Bytes array size
+ */
+/* ======================================================================= */
+#define NUM_IF2_BYTES_ARRAY 16
 
 /* ======================================================================= */
 /**
@@ -298,6 +310,13 @@
 /* ======================================================================= */
 #define _ERROR_PROPAGATION__
 
+/* ======================================================================= */
+/**
+* pthread variable to indicate OMX returned all buffers to app 
+*/
+/* ======================================================================= */
+pthread_mutex_t bufferReturned_mutex; 
+pthread_cond_t bufferReturned_condition; 
 
 /* ======================================================================= */
 /** NBAMRDEC_COMP_PORT_TYPE  Port Type
@@ -584,9 +603,6 @@
     /** The pipes for sending buffers to the thread */
     int cmdDataPipe[2];
 
-    /** The pipes for sending buffers to the thread */
-    /* int lcml_Pipe[2]; */
-
     /** Set to indicate component is stopping */
     OMX_U32 bIsStopping;
 
@@ -678,10 +694,10 @@
    OMX_U32 bPlayCompleteFlag;
 
    /** NBAMR Mime Bytes */
-   OMX_U32 amrMimeBytes[16];
+   OMX_U32 amrMimeBytes[NUM_MIME_BYTES_ARRAY];
    
    /**NBAMR IF2 Bytes**/
-   OMX_U32 amrIF2Bytes[16];
+   OMX_U32 amrIF2Bytes[NUM_IF2_BYTES_ARRAY];
 
    /** Number of Bytes holding to be sent*/
    OMX_U32 nHoldLength;
@@ -805,6 +821,14 @@
     /** Flag to flush SN after EOS in order to process more buffers after EOS**/
     OMX_U8 SendAfterEOS;    
 
+    /** Flag to mark the first sent buffer**/
+    OMX_U8 first_buff;
+    /** First Time Stamp sent **/
+    OMX_TICKS first_TS;
+
+    /** Temporal time stamp **/
+    OMX_TICKS temp_TS;
+
     OMX_BOOL bLoadedCommandPending;
     
     OMX_PARAM_COMPONENTROLETYPE componentRole;
@@ -812,7 +836,9 @@
     /** Pointer to port priority management structure */
     OMX_PRIORITYMGMTTYPE* pPriorityMgmt;
 
-/*  RMPROXY_CALLBACKTYPE rmproxyCallback; */
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
 
     OMX_BOOL bPreempted;
     OMX_BOOL bFrameLost;
@@ -839,4 +865,17 @@
         OMX_IndexCustomDebug
 }OMX_NBAMRDEC_INDEXAUDIOTYPE;
 
+/*=======================================================================*/
+/*! @fn SignalIfAllBuffersAreReturned 
+
+ * @brief Sends pthread signal to indicate OMX has returned all buffers to app 
+
+ * @param  none 
+
+ * @Return void 
+
+ */
+/*=======================================================================*/
+void SignalIfAllBuffersAreReturned(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate);
+
 #endif /* OMX_AMRDECODER_H */
diff --git a/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDec_ComponentThread.c b/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDec_ComponentThread.c
index 55147ba..65fcb40 100644
--- a/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDec_ComponentThread.c
+++ b/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDec_ComponentThread.c
@@ -154,7 +154,6 @@
                                                     OMX_TI_ErrorSevere,
                                                     "Error from Component Thread in select");
             eError = OMX_ErrorInsufficientResources;
-            break;
         }
         else if (FD_ISSET (pComponentPrivate->dataPipe[0], &rfds)) {
             OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_ComponentThread.c :: DATA pipe is set in Component Thread\n",__LINE__);
diff --git a/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDec_Utils.c b/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDec_Utils.c
index b29b814..6096b24 100644
--- a/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDec_Utils.c
+++ b/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDec_Utils.c
@@ -79,17 +79,6 @@
 /* Log for Android system*/
 #include <utils/Log.h>
 
-#ifdef NBAMRDEC_DEBUGMEM
-extern void * mymalloc(int line, char *s, int size);
-int myfree(void *dp, int line, char *s);
-
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
 /* ======================================================================= */
 /**
  * @def    DASF    Defines the value for identify DASF ON
@@ -134,7 +123,6 @@
     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
     AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
     LCML_NBAMRDEC_BUFHEADERTYPE *pTemp_lcml;
-    char *pTemp_char = NULL;
     char *ptr;
 
     pComponentPrivate = pHandle->pComponentPrivate; 
@@ -202,8 +190,6 @@
         OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
         
         pComponentPrivate->strmAttr = strmAttr;
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p\n",__LINE__,strmAttr);
-
         strmAttr->uSegid = 0;
         strmAttr->uAlignment = 0;
         strmAttr->uTimeout = NBAMRD_TIMEOUT;
@@ -545,31 +531,12 @@
         } */
         
     }
-    if (pComponentPrivate->pPriorityMgmt != NULL ) {
-            OMX_MEMFREE_STRUCT (pComponentPrivate->pPriorityMgmt);
-    }
-        
-
-   OMX_PRMGR2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c ::[NBAMRDEC_FreeCompResources] \n", __LINE__);
-   if (pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]) {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]);
-            OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]);
-   }
-
-    if (pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]) {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]);
-            OMX_MEMFREE_STRUCT (pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]);
-    }
-        
-    if (pComponentPrivate->amrParams[NBAMRDEC_INPUT_PORT]) {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->amrParams[NBAMRDEC_INPUT_PORT]);
-            OMX_MEMFREE_STRUCT(pComponentPrivate->amrParams[NBAMRDEC_INPUT_PORT]);
-    }
-
-    if (pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT]) {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT]);
-            OMX_MEMFREE_STRUCT (pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT]);
-    }
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pPriorityMgmt);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRDEC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRDEC_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->amrParams[NBAMRDEC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT]);
         
     pComponentPrivate->bPortDefsAllocated = 0;
     /* Removing sleep() calls. */
@@ -606,96 +573,46 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 nIpBuf = 0;
     OMX_U16 i=0;
-    OMX_U8* pParmsTemp;
-    OMX_U8* pBufParmsTemp;
-       LCML_DSP_INTERFACE *pLcmlHandle;
+    LCML_DSP_INTERFACE *pLcmlHandle;
     LCML_DSP_INTERFACE *pLcmlHandleAux;
-    char *pTemp = NULL;
     
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDEC_CleanupInitParams()\n", __LINE__);
 
-    if (pComponentPrivate->strmAttr!=NULL) {
-        OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
-    }
-   
+    OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
+
     OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams,AMRDEC_AudioCodecParams);
           
     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT];
     for(i=0; i<nIpBuf; i++) {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pTemp_lcml->pFrameParam);
         if(pTemp_lcml->pFrameParam!=NULL){ 
-              OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam,NBAMRDEC_FrameStruct);
-              pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;             
-              pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
-              OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc,
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, NBAMRDEC_FrameStruct);
+            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;             
+            pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
+            OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc,
                                (void*)pTemp_lcml->pBufferParam->pParamElem,
                                pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
-                   /*comentarios*/            
-                   // pBufParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam;
-                   // pBufParmsTemp -= EXTRA_BYTES;
-                   // OMX_NBDECMEMFREE_STRUCT(pBufParmsTemp);
-                   // pBufParmsTemp = NULL;
-                   // pTemp_lcml->pFrameParam = NULL;
         }
-    
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pTemp_lcml->pBufferParam);
-        // if(pTemp_lcml->pBufferParam!=NULL){
-              // OMX_NBDECMEMFREE_STRUCT(pTemp_lcml->pBufferParam);
-              // pTemp_lcml->pBufferParam = NULL;
-        // }
-        /**/
-        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam,NBAMRDEC_ParamStruct);
-        /**/
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pTemp_lcml->pDmmBuf);
-   
-        if(pTemp_lcml->pDmmBuf!=NULL){
-             OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
-        }
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, NBAMRDEC_ParamStruct);
+        OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
         pTemp_lcml++;
     }
 
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT];
     for(i=0; i<pComponentPrivate->nRuntimeOutputBuffers; i++){
-                                                                                                                       
-
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pTemp_lcml->pFrameParam);
         if(pTemp_lcml->pFrameParam!=NULL){
-                /**/
-               OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam,NBAMRDEC_FrameStruct);
-                /**/                                          
-                  pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-                  pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
-                  OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc,
+               OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, NBAMRDEC_FrameStruct);
+               pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
+               pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
+               OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc,
                               (void*)pTemp_lcml->pBufferParam->pParamElem,
                                pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
-                                          
-                   // pBufParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam;
-                   // pBufParmsTemp -= EXTRA_BYTES;
-                   // OMX_NBDECMEMFREE_STRUCT(pBufParmsTemp);
-                   // pBufParmsTemp = NULL;
-                   // pTemp_lcml->pFrameParam = NULL;                     
         }
-    
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pTemp_lcml->pBufferParam);
-        /**/
-        // if(pTemp_lcml->pBufferParam!=NULL){  
-            // OMX_NBDECMEMFREE_STRUCT(pTemp_lcml->pBufferParam);
-            // pTemp_lcml->pBufferParam = NULL;
-       // }
-       OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam,NBAMRDEC_ParamStruct);
-       /**/
-    
-       OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pTemp_lcml->pDmmBuf);
-       if(pTemp_lcml->pDmmBuf!=NULL){
-            OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
-       }
-       pTemp_lcml++;
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, NBAMRDEC_ParamStruct);
+        OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
+        pTemp_lcml++;
     }    
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT]);
     OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT]);
-
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT]);
     OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT]);
     return eError;
 }
@@ -776,7 +693,6 @@
     LCML_CALLBACKTYPE cb;
     LCML_DSP *pLcmlDsp;
     AMRDEC_AudioCodecParams *pParams;
-    OMX_U8 *pParmsTemp;
     ssize_t ret;
     LCML_NBAMRDEC_BUFHEADERTYPE *pLcmlHdr = NULL;
     int inputPortFlag=0,outputPortFlag=0;
@@ -921,6 +837,14 @@
                 if(eError != OMX_ErrorNone) {
                     OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Error returned from\
                         LCML_Init()\n",__LINE__);
+                    /* send an event to client */
+                    /* client should unload the component if the codec is not able to load */
+                    pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                     goto EXIT;
                 }
 
@@ -1016,8 +940,8 @@
                     } 
             
                     OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams, sizeof(AMRDEC_AudioCodecParams), AMRDEC_AudioCodecParams);
+                                    
                     pParams = pComponentPrivate->pParams;
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [ALLOC] %p\n",__LINE__,pParams);
                     pParams->iAudioFormat = 1;
                     pParams->iSamplingRate = 8000;
                     pParams->iStrmId = pComponentPrivate->streamID;
@@ -1080,7 +1004,9 @@
                                                             NULL);  
                     goto EXIT;
                 }
-
+               /* pComponentPrivate->bStopSent=1;
+                OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
+                pComponentPrivate->nHoldLength = 0;*/
             } 
             else if(pComponentPrivate->curState == OMX_StatePause) {
                 OMX_U8 *pArgs = (void*)"damedesuStr";
@@ -1391,7 +1317,15 @@
                                                         NULL);
                goto EXIT;
            }
-
+#ifdef RESOURCE_MANAGER_ENABLED
+/* notify RM of pause so resources can be redistributed if needed */
+           rm_error = RMProxy_NewSendCommand(pHandle,
+                                             RMProxy_StateSet,
+                                             OMX_NBAMR_Decoder_COMPONENT,
+                                             OMX_StatePause,
+                                             3456,
+                                             NULL);
+#endif
                 OMX_PRINT2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Comp: OMX_AmrDecUtils.c\n",__LINE__);
            break;
 
@@ -1507,6 +1441,7 @@
                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                        pComponentPrivate->pInputBufferList->pBufHdr[i]
                                        );
+                    SignalIfAllBuffersAreReturned(pComponentPrivate);
                 }
             }            
         }
@@ -1692,6 +1627,7 @@
         if(commandData == 0x0 || commandData == -1) {
             if(pComponentPrivate->nUnhandledEmptyThisBuffers == 0) {
                 pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
+                pComponentPrivate->first_buff = 0;
 
                 aParam[0] = USN_STRMCMD_FLUSH; 
                 aParam[1] = 0x0; 
@@ -1712,6 +1648,7 @@
             OMX_PRCOMM1(pComponentPrivate->dbg, "Flushing out port %d\n",pComponentPrivate->nUnhandledFillThisBuffers);
             if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
                 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
+                pComponentPrivate->first_buff = 0;
 
                 aParam[0] = USN_STRMCMD_FLUSH; 
                 aParam[1] = 0x1; 
@@ -1732,6 +1669,14 @@
 EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Exiting NBAMRDECHandleCommand Function\n",__LINE__);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Returning %d\n",__LINE__,eError);
+    if (eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -1769,11 +1714,8 @@
     OMX_U32 holdBufferSize;
     OMX_U8 nFrames =0;    
     LCML_DSP_INTERFACE * phandle;
-    OMX_U8 *pBufParmsTemp;
     OMX_U8 bufSize=0;
     AMRDEC_AudioCodecParams *pParams;
-    OMX_U8 *pParmsTemp;
-   // OMX_STRING p = "hello";
    OMX_STRING p = "";
     
     OMX_U32 nFilledLenLocal;
@@ -1800,24 +1742,22 @@
                                                                      __LINE__);
         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__);
-		}
+    if (pBufHeader->pBuffer == NULL) {
+        eError = OMX_ErrorBadParameter;
 	goto EXIT;
-  }
+    }
 
     if (eDir == OMX_DirInput) {
         pComponentPrivate->nUnhandledEmptyThisBuffers--;
+        if (pComponentPrivate->curState == OMX_StateIdle){
+            pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       pBufHeader);
+            pComponentPrivate->nEmptyBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return input buffers\n", __LINE__, __FUNCTION__);
+            goto EXIT;
+        }
         pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
         if ( pBufHeader->nFilledLen > 0) {
             pComponentPrivate->bBypassDSP = 0;
@@ -1827,7 +1767,7 @@
                 {
                     OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleDa\
 taBuf_FromApp - reading NBAMRDEC_MIMEMODE\n",__LINE__);
-
+                    frameLength=INPUT_NBAMRDEC_BUFFER_SIZE_MIME;
                     if(pComponentPrivate->using_rtsp==1){ /* formating data */
                         nFilledLenLocal=pBufHeader->nFilledLen; 
                         while(TRUE)
@@ -1875,6 +1815,7 @@
                             nFrames++;                                                
                         }
                         free(TOCframetype);
+			 TOCframetype = NULL;
                     }
                     frameType = 0;
                     nFrames = 0;
@@ -1885,10 +1826,23 @@
                         index = (frameType >> 3) & 0x0F;
                         if(nFrames)
                         {
+                            if (((nFrames*INPUT_NBAMRDEC_BUFFER_SIZE_MIME) + pBufHeader->nFilledLen) 
+			       > pBufHeader->nAllocLen) {
+                               OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
+                               goto EXIT;
+                           }
                             memmove(pBufHeader->pBuffer + (nFrames*INPUT_NBAMRDEC_BUFFER_SIZE_MIME),
                                     pBufHeader->pBuffer + i,
                                     pBufHeader->nFilledLen);                                                    
                         }
+			if ((index >= NUM_MIME_BYTES_ARRAY) || 
+			   ((index < NUM_MIME_BYTES_ARRAY) && 
+			   (pComponentPrivate->amrMimeBytes[index] == 0))) {
+                           OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: no more frames index=%d", __LINE__, (int)index);
+                           if (index < NUM_MIME_BYTES_ARRAY)
+                               OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: no more frames mimebytes=%d", __LINE__, (int)pComponentPrivate->amrMimeBytes[index]);
+                               break;
+                        }
                         if (pComponentPrivate->amrMimeBytes[index] > pBufHeader->nFilledLen){
                             pBufHeader->nFilledLen = 0;
                         }else{
@@ -1910,6 +1864,7 @@
                 else if (pComponentPrivate->mimemode == NBAMRDEC_IF2)
                 {
                     OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: NBAMRDECHandleDataBuf_FromApp - reading NBAMRDEC_IF2MODE\n", __LINE__);
+                    frameLength=INPUT_NBAMRDEC_BUFFER_SIZE_IF2;
                     nFrames = 0;
                     i = 0;
                     while (pBufHeader->nFilledLen > 0)
@@ -1919,10 +1874,23 @@
                         index = frameType&0x0F;
                         if (nFrames)
                         {
+                            if (((nFrames*INPUT_NBAMRDEC_BUFFER_SIZE_IF2) + pBufHeader->nFilledLen) 
+			       > pBufHeader->nAllocLen) {
+                               OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
+                               goto EXIT;
+                            }
                             memmove(pBufHeader->pBuffer + (nFrames *INPUT_NBAMRDEC_BUFFER_SIZE_IF2), 
                                     pBufHeader->pBuffer + i, 
                                     pBufHeader->nFilledLen);
                         }
+                        if ((index >= NUM_IF2_BYTES_ARRAY) || 
+			   ((index < NUM_IF2_BYTES_ARRAY) && 
+			   (pComponentPrivate->amrIF2Bytes[index] == 0))) {
+                           OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: no more frames index=%d", __LINE__, (int)index);
+                           if (index < NUM_IF2_BYTES_ARRAY)
+                               OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: no more frames mimebytes=%d", __LINE__, (int)pComponentPrivate->amrIF2Bytes[index]);
+                               break;
+                        }
                         if(pComponentPrivate->amrIF2Bytes[index] > pBufHeader->nFilledLen){
                             pBufHeader->nFilledLen=0;
                         }else{
@@ -1951,6 +1919,12 @@
                         }
                         /* Copy the extra data into pHoldBuffer. Size will be nHoldLength. */
                         pExtraData = pBufHeader->pBuffer + bufSize*nFrames;
+			if (pComponentPrivate->nHoldLength >
+			   (bufSize * (pComponentPrivate->pInputBufferList->numBuffers + 3)))
+			   {
+                               OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
+                               goto EXIT;
+			   }
                         memcpy (pComponentPrivate->pHoldBuffer, pExtraData, pComponentPrivate->nHoldLength);
                     }
                 }
@@ -1981,6 +1955,7 @@
                             pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
                                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                                        pBufHeader);
+                            SignalIfAllBuffersAreReturned(pComponentPrivate);
                         }
                         else {
                             pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
@@ -2021,6 +1996,12 @@
                 nFrames = (OMX_U8)(pComponentPrivate->nHoldLength / frameLength);
                 if ( nFrames >= 1 )  {
                     /* Copy the data from pComponentPrivate->pHoldBuffer to pBufHeader->pBuffer*/
+		    /* check the pBufHeader boundery before copying */
+		    if ((nFrames*frameLength) > pBufHeader->nAllocLen)
+		    {
+                        OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
+			goto EXIT;
+		    }
                     memcpy(pBufHeader->pBuffer,pComponentPrivate->pHoldBuffer,nFrames*frameLength);
                     pBufHeader->nFilledLen = nFrames*frameLength;
     
@@ -2049,6 +2030,7 @@
                         pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pBufHeader);
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                         goto EXIT;
                     }
                     else {
@@ -2066,6 +2048,7 @@
                 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
                                                            pComponentPrivate->pHandle->pApplicationPrivate,
                                                            pComponentPrivate->pInputBufferList->pBufHdr[0]);
+                SignalIfAllBuffersAreReturned(pComponentPrivate);
                 goto EXIT;
             }
             else{
@@ -2160,7 +2143,6 @@
                     
                     OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,sizeof(AMRDEC_AudioCodecParams),AMRDEC_AudioCodecParams);
                     pParams = pComponentPrivate->pParams;
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [ALLOC] %p\n",__LINE__,pParams);
                     pParams->iAudioFormat = 1;
                     pParams->iSamplingRate = 8000;
                     pParams->iStrmId = pComponentPrivate->streamID;
@@ -2245,6 +2227,11 @@
             pComponentPrivate->IpBufindex++;
             pComponentPrivate->IpBufindex %= pPortDefIn->nBufferCountActual;
 
+            if(pComponentPrivate->first_buff == 0){
+                pComponentPrivate->first_TS = pBufHeader->nTimeStamp;
+                OMX_PRBUFFER2(pComponentPrivate->dbg, "in ts-%ld\n",pBufHeader->nTimeStamp);
+                pComponentPrivate->first_buff = 1;
+            }
             
             for (i=0; i < INPUT_NBAMRDEC_BUFFER_SIZE_MIME; i++) {
                 OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Queueing pBufHeader->pBuffer[%d] = %x\n",__LINE__,i,pBufHeader->pBuffer[i]);
@@ -2322,10 +2309,25 @@
                     pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
                                                                pComponentPrivate->pHandle->pApplicationPrivate,
                                                                pBufHeader);
+                    SignalIfAllBuffersAreReturned(pComponentPrivate);
                 }                
             }
         }
-
+        else
+        {
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "line %d:: No Frames in Buffer, calling EmptyBufferDone\n",__LINE__);
+            pComponentPrivate->nEmptyBufferDoneCount++;
+#ifdef __PERF_INSTRUMENTATION__
+            PERF_SendingFrame(pComponentPrivate->pPERFcomp,
+                                      pBufHeader->pBuffer,
+                                      0,
+                                      PERF_ModuleHLMM);
+#endif
+            pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       pBufHeader);
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+        }
         if (pComponentPrivate->bFlushInputPortCommandPending) {
             OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL);
         }
@@ -2335,6 +2337,15 @@
          * there is an outstanding input buffer already issued on input stream
          */
         pComponentPrivate->nUnhandledFillThisBuffers--;
+        if (pComponentPrivate->curState == OMX_StateIdle){
+            pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
+                                                      pComponentPrivate->pHandle->pApplicationPrivate,
+                                                      pBufHeader);
+            pComponentPrivate->nFillBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return output buffers\n", __LINE__, __FUNCTION__);
+            goto EXIT;
+        }
         eError = NBAMRDECGetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);     
         phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 
@@ -2425,8 +2436,19 @@
     }
 
 EXIT:
+    if (TOCframetype != NULL) {
+	 free(TOCframetype);
+    }
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Exiting from  NBAMRDECHandleDataBuf_FromApp \n",__LINE__);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Returning error %d\n",__LINE__,eError);
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -2516,7 +2538,6 @@
     
     AMRDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)args[6])->pComponentPrivate;
-    static OMX_U32 TS = 0;
     static double time_stmp = 0;
     pHandle = pComponentPrivate->pHandle;
     
@@ -2608,6 +2629,7 @@
                 pComponentPrivate->cbInfo.EmptyBufferDone (pHandle,
                                                            pHandle->pApplicationPrivate,
                                                            pLcmlHdr->buffer);
+                SignalIfAllBuffersAreReturned(pComponentPrivate);
                 pComponentPrivate->lcml_nIpBuf--;
                 pComponentPrivate->app_nBuf++;
             }
@@ -2665,10 +2687,16 @@
                 }
             }
             /* Copying time stamp information to output buffer */
-            time_stmp = pLcmlHdr->buffer->nFilledLen / (1 * (((OMX_AUDIO_PARAM_PCMMODETYPE*)pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT])->nBitPerSample / 8));
-            time_stmp = (time_stmp / ((OMX_AUDIO_PARAM_PCMMODETYPE*)pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT])->nSamplingRate) * 1000;
-            TS += (OMX_U32)(time_stmp*1000);
-            pLcmlHdr->buffer->nTimeStamp = TS;
+            if(pComponentPrivate->first_buff == 1){
+                pComponentPrivate->first_buff = 2;
+                pLcmlHdr->buffer->nTimeStamp = pComponentPrivate->first_TS;
+                pComponentPrivate->temp_TS = pLcmlHdr->buffer->nTimeStamp;
+            }else{
+                time_stmp = pLcmlHdr->buffer->nFilledLen / (1 * (((OMX_AUDIO_PARAM_PCMMODETYPE*)pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT])->nBitPerSample / 8));
+                time_stmp = (time_stmp / ((OMX_AUDIO_PARAM_PCMMODETYPE*)pComponentPrivate->amrParams[NBAMRDEC_OUTPUT_PORT])->nSamplingRate) * 1000;
+                pComponentPrivate->temp_TS += (OMX_U32)(time_stmp*1000);
+                pLcmlHdr->buffer->nTimeStamp = pComponentPrivate->temp_TS;
+            }
             /* Copying nTickCount information to output buffer */
             pLcmlHdr->buffer->nTickCount = pComponentPrivate->arrTickCount[pComponentPrivate->OpBufindex];
             pComponentPrivate->OpBufindex++;
@@ -2689,6 +2717,7 @@
             pComponentPrivate->cbInfo.FillBufferDone (pHandle,
                                                       pHandle->pApplicationPrivate,
                                                       pLcmlHdr->buffer);
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
             pComponentPrivate->lcml_nOpBuf--;
             pComponentPrivate->app_nBuf++;
             pComponentPrivate->nOutStandingFillDones--;
@@ -2706,6 +2735,8 @@
                         pComponentPrivate->cbInfo.EmptyBufferDone (pHandle,
                                                                    pHandle->pApplicationPrivate,
                                                                    pComponentPrivate->pInputBufHdrPending[i]);
+                        pComponentPrivate->nEmptyBufferDoneCount++;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                         pComponentPrivate->pInputBufHdrPending[i] = NULL;
                     }
                     pComponentPrivate->nNumInputBufPending=0;
@@ -2727,6 +2758,8 @@
                         pComponentPrivate->cbInfo.FillBufferDone (pHandle,
                                                                   pHandle->pApplicationPrivate,
                                                                   pComponentPrivate->pOutputBufHdrPending[i]);
+                        pComponentPrivate->nFillBufferDoneCount++;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                         pComponentPrivate->pOutputBufHdrPending[i] = NULL;
                     }
                     pComponentPrivate->nNumOutputBufPending=0;
@@ -2748,13 +2781,17 @@
 		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++) {
 		pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
 			pComponentPrivate->pHandle->pApplicationPrivate,
 			pComponentPrivate->pOutputBufHdrPending[i]);
+            pComponentPrivate->nFillBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
 		pComponentPrivate->nOutStandingFillDones--;
 		pComponentPrivate->pOutputBufHdrPending[i] = NULL;
 	}
@@ -2788,6 +2825,25 @@
                                             3456, 
                                             NULL);
 #endif
+            /*
+            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"); 
+                }
+                OMXDBG_PRINT(stderr, PRINT, 1, 0, "pthread_cond_waiting for OMX to return all input and outbut buffers");
+                pthread_cond_wait(&bufferReturned_condition, &bufferReturned_mutex);
+                OMXDBG_PRINT(stderr, PRINT, 1, 0, "OMX has returned all input and output buffers"); 
+                if(pthread_mutex_unlock(&bufferReturned_mutex) != 0) 
+                {
+                    OMXDBG_PRINT(stderr, PRINT, 1, 0, "bufferReturned_mutex mutex unlock error");  
+                }
+            }
+            else
+            {
+                OMXDBG_PRINT(stderr, PRINT, 1, 0, "OMX has returned all input and output buffers"); 
+            }
+            */
             if(pComponentPrivate->bPreempted == 0){
                 pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                    pHandle->pApplicationPrivate,
@@ -2808,8 +2864,6 @@
         }
     }
     else if (event == EMMCodecProcessingPaused) {
-        pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
-        pComponentPrivate->nUnhandledFillThisBuffers = 0;
         pComponentPrivate->curState = OMX_StatePause;
         /* Send StateChangeNotification to application */
         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
@@ -2821,144 +2875,44 @@
     
     }
     else if (event == EMMCodecDspError) {
+        switch ( (OMX_U32) args [4])
+        {
+        /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
+             * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
+             * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
+             * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
+             * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
+             * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
+             * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
+             * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
+
 #ifdef _ERROR_PROPAGATION__
-        /* Cheking for MMU_fault */
-        if(((int) args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] ==(void*) NULL)) {
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: UTIL: MMU_Fault \n",__LINE__);
-            pComponentPrivate->bIsInvalidState=OMX_TRUE;
-            pComponentPrivate->curState = OMX_StateInvalid;
-            pHandle = pComponentPrivate->pHandle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorInvalidState, 
-                                                   OMX_TI_ErrorSevere,
-                                                   NULL);
-        }
-#endif             
-        if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) {
-            pHandle = pComponentPrivate->pHandle;
-            OMX_PRDSP1(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__);
-            if(pComponentPrivate->LastOutbuf!=NULL && !pComponentPrivate->dasfmode){
-                pComponentPrivate->LastOutbuf->nFlags = OMX_BUFFERFLAG_EOS;
-            }
-                 
-            /* add callback to application to indicate SN/USN has completed playing of current set of date */
-            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,                  
-                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                   OMX_EventBufferFlag,
-                                                   (OMX_U32)NULL,
-                                                   OMX_BUFFERFLAG_EOS,
-                                                   NULL);
-        }
-        if((int)args[5] == IUALG_WARN_CONCEALED) {
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm issued a warning. But can continue" );
-        }
-        /****/        
-        if((int)args[5] == IUALG_ERR_GENERAL) {
-            char *pArgs = "damedesuStr";
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Cannot continue" );
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: arg5 = %x\n",__LINE__,(int)args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML_Callback: IUALG_ERR_GENERAL\n",__LINE__);
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-#ifndef UNDER_CE
-            if (pComponentPrivate->codecStop_waitingsignal == 0){ 
-                pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);    
-            }
-            eError = LCML_ControlCodec(
-                                       ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                       MMCodecControlStop,(void *)pArgs);
-            if (pComponentPrivate->codecStop_waitingsignal == 0){
-                pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
-                pComponentPrivate->codecStop_waitingsignal = 0;
-                pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
-            }
+            case USN_ERR_PAUSE:
+            case USN_ERR_STOP:
+            case USN_ERR_ALGCTRL:
+            case USN_ERR_STRMCTRL:
+            case USN_ERR_UNKNOWN_MSG: 
 
-            if(eError != OMX_ErrorNone) {
-                OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Stop..\n",
-                              __LINE__);
-                pComponentPrivate->curState = OMX_StateInvalid;
-                pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                        pHandle->pApplicationPrivate,
-                                                        OMX_EventError, 
-                                                        eError,
-                                                        OMX_TI_ErrorSevere, 
-                                                        NULL);
-                goto EXIT;
-            }
-            OMX_PRSTATE2(pComponentPrivate->dbg, "%d :: AMRDEC: Codec has been Stopped here\n",__LINE__);
-            pComponentPrivate->curState = OMX_StateIdle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                    pHandle->pApplicationPrivate,
-                                                    OMX_EventCmdComplete, 
-                                                    OMX_ErrorNone,
-                                                    0, 
-                                                    NULL);
-#else
-            pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                    pHandle->pApplicationPrivate,
-                                                    OMX_EventError, 
-                                                    OMX_ErrorUndefined,
-                                                    OMX_TI_ErrorSevere, 
-                                                    NULL);
-#endif
-        }
-        if( (int)args[5] == IUALG_ERR_DATA_CORRUPT )
-            {
-                char *pArgs = "damedesuStr";
-                OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Corrupt data" );
-                OMX_ERROR4(pComponentPrivate->dbg, "%d :: arg5 = %x\n",__LINE__,(int)args[5]);
-                OMX_ERROR4(pComponentPrivate->dbg, "%d :: LCML_Callback: IUALG_ERR_DATA_CORRUPT\n",__LINE__);
-                pHandle = pComponentPrivate->pHandle;
-                pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-#ifndef UNDER_CE
-                if (pComponentPrivate->codecStop_waitingsignal == 0){ 
-                    pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);    
-                }
-                eError = LCML_ControlCodec(
-                                           ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                           MMCodecControlStop,(void *)pArgs);
-                if (pComponentPrivate->codecStop_waitingsignal == 0){
-                    pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
-                    pComponentPrivate->codecStop_waitingsignal = 0;
-                    pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
-                }
-
-                if(eError != OMX_ErrorNone) {
-                    OMX_ERROR4(pComponentPrivate->dbg, "%d: Error Occurred in Codec Stop..\n",
-                                  __LINE__);
+                {
+                    pComponentPrivate->bIsInvalidState=OMX_TRUE;
                     pComponentPrivate->curState = OMX_StateInvalid;
+                    pHandle = pComponentPrivate->pHandle;
                     pComponentPrivate->cbInfo.EventHandler(pHandle, 
-                                                        pHandle->pApplicationPrivate,
-                                                        OMX_EventError, 
-                                                        eError,
-                                                        OMX_TI_ErrorSevere, 
-                                                        NULL);
-                    goto EXIT;
+                            pHandle->pApplicationPrivate,
+                            OMX_EventError,
+                            OMX_ErrorInvalidState, 
+                            OMX_TI_ErrorSevere,
+                            NULL);
                 }
-                OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: AMRDEC: Codec has been Stopped here\n",__LINE__);
-                pComponentPrivate->curState = OMX_StateIdle;
-                pComponentPrivate->cbInfo.EventHandler(
-                                                       pHandle, pHandle->pApplicationPrivate,
-                                                       OMX_EventCmdComplete, OMX_ErrorNone,0, NULL);
-#else
-                pComponentPrivate->cbInfo.EventHandler(
-                                                       pHandle, pHandle->pApplicationPrivate,
-                                                       OMX_EventError, OMX_ErrorUndefined,OMX_TI_ErrorSevere, NULL);
-#endif                        
-            }                                        
-        if( (int)args[5] == IUALG_WARN_OVERFLOW ){
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Overflow, sending to Idle\n" );
-#ifdef RESOURCE_MANAGER_ENABLED         
-            rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_WBAMR_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL);
-#endif                     
-        }
-        if( (int)args[5] == IUALG_WARN_UNDERFLOW ){
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Underflow, sending to Idle\n" );
-#ifdef RESOURCE_MANAGER_ENABLED         
-            rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_WBAMR_Decoder_COMPONENT, OMX_StateIdle, 3456,NULL);
-#endif         
+                break;
+#endif
+
+            case USN_ERR_WARNING:
+            case USN_ERR_PROCESS:
+                NBAMRDEC_HandleUSNError (pComponentPrivate, (OMX_U32)args[5]);
+                break;
+            default:
+                break;
         }
     }
 
@@ -3049,7 +3003,7 @@
             if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
     OMX_PRDSP1(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Inside NBAMRDECGetCorresponding_LCMLHeader..\n",__LINE__);
                 *ppLcmlHdr = pLcmlBufHeader;
-                 OMX_ERROR2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Corresponding LCML Header Found\n",__LINE__);
+                OMX_PRDSP2(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: Corresponding LCML Header Found\n",__LINE__);
                  goto EXIT;
             }
             pLcmlBufHeader++;
@@ -3109,6 +3063,7 @@
     if ((error = (void*)dlerror()) != NULL) 
     {
         fputs((void*)error, stderr);
+	dlclose(handle);
         goto EXIT;
     }
     eError = (*fpGetHandle)(&pHandle);
@@ -3116,6 +3071,7 @@
         eError = OMX_ErrorUndefined;
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_AmrDec_Utils.c :: eError != OMX_ErrorNone...\n",__LINE__);
         pHandle = NULL;
+        dlclose(handle);
         goto EXIT;
     }
     pComponentPrivate->bLcmlHandleOpened = 1;
@@ -3345,7 +3301,6 @@
     OMX_MALLOC_SIZE(ptr, size_lcml,char);
     pTemp_lcml = (LCML_NBAMRDEC_BUFHEADERTYPE *)ptr;
     
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p\n",__LINE__,pTemp_lcml);
     pComponentPrivate->pLcmlBufHeader[NBAMRDEC_INPUT_PORT] = pTemp_lcml;
 
     for (i=0; i<nIpBuf; i++) {
@@ -3382,7 +3337,6 @@
     size_lcml = (OMX_S16)nOpBuf * sizeof(LCML_NBAMRDEC_BUFHEADERTYPE);
 
     OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,LCML_NBAMRDEC_BUFHEADERTYPE);
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p\n",__LINE__,pTemp_lcml);
 
     pComponentPrivate->pLcmlBufHeader[NBAMRDEC_OUTPUT_PORT] = pTemp_lcml;
 
@@ -3604,7 +3558,25 @@
 }
 #endif
 
-/*void NBAMR_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+void SignalIfAllBuffersAreReturned(AMRDEC_COMPONENT_PRIVATE *pComponentPrivate)
+{
+    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__);
+        }
+        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;
+    }
+}
+#ifdef RESOURCE_MANAGER_ENABLED
+void NBAMR_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
 {
     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
     OMX_STATETYPE state = OMX_StateIdle;
@@ -3627,9 +3599,66 @@
                             pHandle, pHandle->pApplicationPrivate,
                             OMX_EventResourcesAcquired, 0,0,
                             NULL);
-            
-        
     }
-
 }
-*/
+#endif
+
+void NBAMRDEC_HandleUSNError (AMRDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
+{
+    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U8 pending_buffers = OMX_FALSE;
+    OMX_U32 i;
+    switch (arg)
+    {
+        case IUALG_WARN_CONCEALED:
+        case IUALG_WARN_UNDERFLOW:
+        case IUALG_WARN_OVERFLOW:
+        case IUALG_WARN_ENDOFDATA:
+            /* all of these are informative messages, Algo can recover, no need to notify the 
+             * IL Client at this stage of the implementation */
+            break;
+
+        case IUALG_WARN_PLAYCOMPLETED:
+        {
+            pHandle = pComponentPrivate->pHandle;
+            OMX_PRDSP1(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__);
+            if(pComponentPrivate->LastOutbuf!=NULL && !pComponentPrivate->dasfmode){
+                pComponentPrivate->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS;
+            }
+                 
+            /* add callback to application to indicate SN/USN has completed playing of current set of date */
+            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,                  
+                                                   pComponentPrivate->pHandle->pApplicationPrivate,
+                                                   OMX_EventBufferFlag,
+                                                   (OMX_U32)NULL,
+                                                   OMX_BUFFERFLAG_EOS,
+                                                   NULL);
+        }
+            break;
+
+#ifdef _ERROR_PROPAGATION__
+        case IUALG_ERR_BAD_HANDLE:
+        case IUALG_ERR_DATA_CORRUPT:
+        case IUALG_ERR_NOT_SUPPORTED:
+        case IUALG_ERR_ARGUMENT:
+        case IUALG_ERR_NOT_READY:
+        case IUALG_ERR_GENERAL:
+        {
+        /* all of these are fatal messages, Algo can not recover
+                 * hence return an error */
+                pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                pComponentPrivate->curState = OMX_StateInvalid;
+                pHandle = pComponentPrivate->pHandle;
+                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                        pHandle->pApplicationPrivate,
+                        OMX_EventError,
+                        OMX_ErrorInvalidState,
+                        OMX_TI_ErrorSevere,
+                        NULL);
+            }
+            break;
+#endif
+        default:
+            break;
+    }
+}
diff --git a/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDecoder.c b/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDecoder.c
index 52bee79..95961ca 100644
--- a/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDecoder.c
+++ b/omx/audio/src/openmax_il/nbamr_dec/src/OMX_AmrDecoder.c
@@ -73,7 +73,6 @@
 /*-------program files ----------------------------------------*/
 #include <OMX_Component.h>
 #include <TIDspOmx.h>
-#include <OMX_TI_Common.h>
 
 #include "OMX_AmrDecoder.h"
 #include "OMX_AmrDec_Utils.h"
@@ -81,24 +80,6 @@
 /* Log for Android system*/
 #include <utils/Log.h>
 
-#ifdef NBAMRDEC_DEBUGMEM
-
-
-void *arr[500];
-int lines[500];
-int bytes[500];
-char file[500][50];
-
-void * mymalloc(int line, char *s, int size);
-int myfree(void *dp, int line, char *s);
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
 #define AMRNB_DEC_ROLE "audio_decoder.amrnb"
 
 
@@ -217,7 +198,7 @@
 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
 {
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip, *pPortDef_op;
-    AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
+    AMRDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_AUDIO_PARAM_AMRTYPE *amr_ip;
     OMX_AUDIO_PARAM_PCMMODETYPE *amr_op;
     OMX_ERRORTYPE error = OMX_ErrorNone;
@@ -247,17 +228,7 @@
     pHandle->ComponentRoleEnum = ComponentRoleEnum;
 
     /*Allocate the memory for Component private data area */
-    // pHandle->pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)
-                                     // newmalloc (sizeof(AMRDEC_COMPONENT_PRIVATE));
-    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, AMRDEC_COMPONENT_PRIVATE);
-
-    // if(pHandle->pComponentPrivate == NULL) {
-        // error = OMX_ErrorInsufficientResources;
-        // goto EXIT;
-    // }
-
-    // memset(pHandle->pComponentPrivate, 0x0, sizeof(AMRDEC_COMPONENT_PRIVATE));
-    // OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c\n", __LINE__);
+    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, AMRDEC_COMPONENT_PRIVATE); 
 
     ((AMRDEC_COMPONENT_PRIVATE *)
                 pHandle->pComponentPrivate)->pHandle = pHandle;
@@ -270,9 +241,7 @@
 
     error = OMX_ErrorNone;
 
-//    amr_ip = (OMX_AUDIO_PARAM_AMRTYPE *)newmalloc(sizeof(OMX_AUDIO_PARAM_AMRTYPE));
-    OMX_MALLOC_GENERIC(amr_ip , OMX_AUDIO_PARAM_AMRTYPE);
-    //amr_op = (OMX_AUDIO_PARAM_PCMMODETYPE *)newmalloc(sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+    OMX_MALLOC_GENERIC(amr_ip , OMX_AUDIO_PARAM_AMRTYPE); 
     OMX_MALLOC_GENERIC(amr_op , OMX_AUDIO_PARAM_PCMMODETYPE);
 
 
@@ -300,12 +269,9 @@
         pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_FALSE;
 
 
-    //pComponentPrivate->pInputBufferList = newmalloc(sizeof(NBAMRDEC_BUFFERLIST));
-    OMX_MALLOC_GENERIC(pComponentPrivate->pInputBufferList, NBAMRDEC_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pInputBufferList, NBAMRDEC_BUFFERLIST); 
     pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */
-    //pComponentPrivate->pOutputBufferList = newmalloc(sizeof(NBAMRDEC_BUFFERLIST));
-    OMX_MALLOC_GENERIC(pComponentPrivate->pOutputBufferList, NBAMRDEC_BUFFERLIST);
-    
+    OMX_MALLOC_GENERIC(pComponentPrivate->pOutputBufferList, NBAMRDEC_BUFFERLIST); 
     OMX_MALLOC_GENERIC(pComponentPrivate->pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
          
     pComponentPrivate->pOutputBufferList->numBuffers = 0; /* initialize number of buffers */
@@ -381,6 +347,10 @@
     pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
     pComponentPrivate->bFlushInputPortCommandPending = OMX_FALSE;
     
+    pComponentPrivate->first_buff = 0;
+    pComponentPrivate->first_TS = 0;
+    pComponentPrivate->temp_TS = 0;
+
     for (i=0; i < MAX_NUM_OF_BUFS; i++) {
         pComponentPrivate->pInputBufHdrPending[i] = NULL;
         pComponentPrivate->pOutputBufHdrPending[i] = NULL;
@@ -404,7 +374,6 @@
     pComponentPrivate->bPreempted = OMX_FALSE;    
     pComponentPrivate->using_rtsp = 0;
     
-    //pComponentPrivate->sDeviceString = newmalloc(100*sizeof(OMX_STRING));
     OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, (100*sizeof(char)),OMX_STRING);
     strcpy((char*)pComponentPrivate->sDeviceString,"/eteedn:i0:o0/codec\0");
 
@@ -542,8 +511,10 @@
 #endif
 
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::OMX_ComponentInit - returning %d\n", __LINE__,error);
-    OMX_PRINT2(pComponentPrivate->dbg, "%s: OUT", __FUNCTION__);
+    if (pComponentPrivate != NULL) {
+	 OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c ::OMX_ComponentInit - returning %d\n", __LINE__, error);
+	 OMX_PRINT2(pComponentPrivate->dbg, "%s: OUT", __FUNCTION__);
+    }
     return error;
 }
 
@@ -938,7 +909,12 @@
 
              
         case OMX_IndexParamPriorityMgmt:
-             memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
+	     if (NULL == pComponentPrivate->pPriorityMgmt) {
+	         eError = OMX_ErrorBadParameter;
+	     }
+             else {
+                  memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
+	     }
         break;
             
         case OMX_IndexParamCompBufferSupplier:
@@ -1124,7 +1100,12 @@
                  eError = OMX_ErrorIncorrectStateOperation;
                  break;
             }
-            memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
+	    if (NULL == pComponentPrivate->pPriorityMgmt) {
+	        eError = OMX_ErrorBadParameter;
+	    }
+	    else {
+	        memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
+	    }
             break;
 
         case OMX_IndexParamStandardComponentRole: 
@@ -1195,13 +1176,7 @@
     AMRDEC_COMPONENT_PRIVATE *pComponentPrivate;
     TI_OMX_STREAM_INFO *streamInfo;
 
-//  streamInfo = newmalloc(sizeof(TI_OMX_STREAM_INFO));
     OMX_MALLOC_GENERIC(streamInfo, TI_OMX_STREAM_INFO);
-    // if(streamInfo == NULL)
-    // {
-        // eError = OMX_ErrorBadParameter;
-        // goto EXIT;
-    // }
 
     pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)
             (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
@@ -1212,7 +1187,10 @@
         goto EXIT;
     }
 #endif
-
+    if (NULL == ComponentConfigStructure) {
+        eError = OMX_ErrorBadParameter;
+	goto EXIT;
+    }
     if(nConfigIndex == OMX_IndexCustomNbAmrDecStreamIDConfig)
     {
         /* copy component info */
@@ -1224,13 +1202,8 @@
         OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
     }
 
-    // if(streamInfo)
-    // {
-        OMX_MEMFREE_STRUCT(streamInfo);
-        //streamInfo = NULL;
-    //}
-
 EXIT:
+    OMX_MEMFREE_STRUCT(streamInfo);
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -1252,6 +1225,11 @@
 {
 OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
+    if (pHandle == NULL) {
+	 OMXDBG_PRINT(stderr, ERROR, 2, 0, "%d ::OMX_AmrDecoder.c :: About to return OMX_ErrorBadParameter\n", __LINE__);
+	 eError = OMX_ErrorBadParameter;
+	 goto EXIT;
+    }
     AMRDEC_COMPONENT_PRIVATE *pComponentPrivate =
                          (AMRDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_S16 *customFlag = NULL;
@@ -1263,11 +1241,6 @@
     OMX_AUDIO_CONFIG_VOLUMETYPE *pVolumeStructure = NULL;
 #endif
     OMX_PRINT1(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: Entering SetConfig\n", __LINE__);
-    if (pHandle == NULL) {
-        OMX_ERROR4(pComponentPrivate->dbg, "%d ::OMX_AmrDecoder.c :: Invalid HANDLE OMX_ErrorBadParameter \n",__LINE__);
-        eError = OMX_ErrorBadParameter;
-        goto EXIT;
-    }
 
 #ifdef _ERROR_PROPAGATION__
     if (pComponentPrivate->curState == OMX_StateInvalid){
@@ -1749,17 +1722,9 @@
     OMX_PRINT2(dbg, "%d ::OMX_AmrDecoder.c ::ComponentDeInit\n",__LINE__);
     /* Wait for thread to exit so we can get the status into "error" */
 
-  
-        
-    if(pComponentPrivate->pInputBufferList!=NULL){
-         OMX_PRBUFFER2(dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pInputBufferList);
-         OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
-    }
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
 
-    if(pComponentPrivate->pOutputBufferList!=NULL){
-         OMX_PRBUFFER2(dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pOutputBufferList);
-         OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
-    }
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
     
     /* close the pipe handles */
     NBAMRDEC_FreeCompResources(pHandle);
@@ -1769,13 +1734,11 @@
                   PERF_BoundaryComplete | PERF_BoundaryCleanup);
     PERF_Done(pComponentPrivate->pPERF);
 #endif
-    if (pComponentPrivate->sDeviceString != NULL) {
-        OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
-    }
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
     OMX_PRINT1(dbg, "%d ::After NBAMRDEC_FreeCompResources\n",__LINE__);
     OMX_MEMFREE_STRUCT(pComponentPrivate);
       
-    OMX_PRINT1(dbg, "%d ::After OMX_NBDECMEMFREE_STRUCT(pComponentPrivate)\n",__LINE__);
+    OMX_PRINT1(dbg, "%d ::After OMX_MEMFREE_STRUCT(pComponentPrivate)\n",__LINE__);
     OMX_DBG_CLOSE(dbg);
     return eError;
 }
@@ -1839,7 +1802,7 @@
                     pComponentPrivate)->pPortDef[nPortIndex];
 #ifdef _ERROR_PROPAGATION__
     if (pComponentPrivate->curState == OMX_StateInvalid){
-    OMX_PRINT1(pComponentPrivate->dbg, "AllocateBuffer %d\n",__LINE__);
+    OMX_PRBUFFER1(pComponentPrivate->dbg, "AllocateBuffer %d\n",__LINE__);
 
         eError = OMX_ErrorInvalidState;
         goto EXIT;
@@ -1864,25 +1827,9 @@
 #endif
         break;
     }
-    //pBufferHeader = (OMX_BUFFERHEADERTYPE*)newmalloc(sizeof(OMX_BUFFERHEADERTYPE));
     OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
-    // if (pBufferHeader == NULL) {
-        // eError = OMX_ErrorInsufficientResources;
-        // goto EXIT;
-    // }
-    //memset(pBufferHeader, 0x0, sizeof(OMX_BUFFERHEADERTYPE));
 
-    //pBufferHeader->pBuffer = (OMX_U8 *)newmalloc(nSizeBytes + EXTRA_BUFFBYTES);
-    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer,nSizeBytes,OMX_U8);
-    // if (pBufferHeader->pBuffer == NULL) {
-        // /* Free previously allocated memory before bailing */
-        // if (pBufferHeader) {
-            // newfree(pBufferHeader);
-            // pBufferHeader = NULL;
-        // }
-        // eError = OMX_ErrorInsufficientResources;
-        // goto EXIT;
-    // }
+    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes,OMX_U8);
 
     if (nPortIndex == NBAMRDEC_INPUT_PORT) {
         pBufferHeader->nInputPortIndex = nPortIndex;
@@ -1902,7 +1849,6 @@
     else if (nPortIndex == NBAMRDEC_OUTPUT_PORT) {
                 pBufferHeader->nInputPortIndex = -1;
         pBufferHeader->nOutputPortIndex = nPortIndex; 
-        //        pBufferHeader->pOutputPortPrivate = (NBAMRDEC_BUFDATA*) newmalloc(sizeof(NBAMRDEC_BUFDATA));
         OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate, NBAMRDEC_BUFDATA);
         pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
         pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
@@ -1980,7 +1926,6 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     AMRDEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
     OMX_BUFFERHEADERTYPE* buff;
-    OMX_U8* tempBuff;
     OMX_S16 i;
     OMX_S16 inputIndex = -1;
     OMX_S16 outputIndex = -1;
@@ -2031,10 +1976,8 @@
                  PERF_ModuleMemory);
 #endif
             if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer);
-                OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer,OMX_U8);
-             }
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pBufHeader[NBAMRDEC_INPUT_PORT]);
+                OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
+            }
             OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
             pComponentPrivate->pInputBufferList->numBuffers--;
             if (pComponentPrivate->pInputBufferList->numBuffers <
@@ -2060,11 +2003,11 @@
                        PERF_ModuleMemory);
 #endif
             if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer);
                 OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer,OMX_U8);
             }
             OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
             OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
+            pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex] = NULL;
             pComponentPrivate->pOutputBufferList->numBuffers--;
 
             if (pComponentPrivate->pOutputBufferList->numBuffers <
@@ -2166,14 +2109,7 @@
         goto EXIT;
     }*/
 
-    //pBufferHeader = (OMX_BUFFERHEADERTYPE*)newmalloc(sizeof(OMX_BUFFERHEADERTYPE));
-    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
-    // if (pBufferHeader == 0) {
-        // OMX_ERROR4(pComponentPrivate->dbg, "newmalloc failed\n");
-        // eError = OMX_ErrorInsufficientResources;
-        // goto EXIT;
-    // }
-    // memset((pBufferHeader), 0x0, sizeof(OMX_BUFFERHEADERTYPE));
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE); 
 
     if (nPortIndex == NBAMRDEC_OUTPUT_PORT) {
         pBufferHeader->nInputPortIndex = -1;
@@ -2301,8 +2237,13 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     pComponentPrivate = (AMRDEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     if(nIndex == 0){
-      memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
-      OMX_PRINT1(pComponentPrivate->dbg, "::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+      if (NULL == cRole) {
+          eError = OMX_ErrorBadParameter;
+      }
+      else {
+          memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
+          OMX_PRINT1(pComponentPrivate->dbg, "::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+      }
     }
     else {
       eError = OMX_ErrorNoMore;
@@ -2318,6 +2259,7 @@
    p = malloc(size);
    if(p==NULL){
        OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not  available\n");
+       /* exit(1); */
        }
    else{
          while((lines[e]!=0)&& (e<500) ){
diff --git a/omx/audio/src/openmax_il/nbamr_enc/inc/OMX_AmrEnc_Utils.h b/omx/audio/src/openmax_il/nbamr_enc/inc/OMX_AmrEnc_Utils.h
index 4fbbcff..91a0455 100644
--- a/omx/audio/src/openmax_il/nbamr_enc/inc/OMX_AmrEnc_Utils.h
+++ b/omx/audio/src/openmax_il/nbamr_enc/inc/OMX_AmrEnc_Utils.h
@@ -65,7 +65,10 @@
 #include "OMX_TI_Common.h"
 #include "OMX_TI_Debug.h"
 #include <TIDspOmx.h>
-/* #include <ResourceManagerProxyAPI.h> */
+
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 
 #ifdef __PERF_INSTRUMENTATION__
     #include "perf.h"
@@ -222,14 +225,6 @@
     (_s_)->nVersion.s.nRevision = 0x0;      \
     (_s_)->nVersion.s.nStep = 0x0
 
-#define OMX_NBMEMFREE_STRUCT(_pStruct_)\
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: [FREE] %p\n",__LINE__,_pStruct_);\
-    if(_pStruct_ != NULL){\
-        newfree(_pStruct_);\
-        _pStruct_ = NULL;\
-    }
-
-
 #define OMX_NBCLOSE_PIPE(_pStruct_,err)\
     OMXDBG_PRINT(stderr, COMM, 2, OMX_DBG_BASEMASK, "%d :: CLOSING PIPE \n",__LINE__); \
     err = close (_pStruct_);\
@@ -239,32 +234,6 @@
         goto EXIT;\
     }
 
-#define NBAMRENC_OMX_MALLOC(_pStruct_, _sName_)   \
-    _pStruct_ = (_sName_*)newmalloc(sizeof(_sName_));      \
-    if(_pStruct_ == NULL){      \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n"); \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Malloc Failed\n",__LINE__); \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n"); \
-        eError = OMX_ErrorInsufficientResources; \
-        goto EXIT;      \
-    } \
-    memset(_pStruct_,0,sizeof(_sName_));\
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Malloced = %p\n",__LINE__,_pStruct_);
-
-
-
-#define NBAMRENC_OMX_MALLOC_SIZE(_ptr_, _size_,_name_)   \
-    _ptr_ = (_name_ *)newmalloc(_size_);      \
-    if(_ptr_ == NULL){      \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n"); \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Malloc Failed\n",__LINE__); \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n"); \
-        eError = OMX_ErrorInsufficientResources; \
-        goto EXIT;      \
-    } \
-    memset(_ptr_,0,_size_); \
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Malloced = %p\n",__LINE__,_ptr_);
-
 #define NBAMRENC_OMX_ERROR_EXIT(_e_, _c_, _s_)\
     _e_ = _c_;\
     OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n**************** OMX ERROR ************************\n");\
@@ -272,24 +241,6 @@
     OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n**************** OMX ERROR ************************\n");\
     goto EXIT;
 
-#define NBAMRENC_OMX_FREE(ptr) \
-    if(NULL != ptr) { \
-        OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Freeing Address = %p\n",__LINE__,ptr); \
-        newfree(ptr); \
-        ptr = NULL; \
-    }
-    
-
-/* ======================================================================= */
-/**
- * @def EXTRA_BYTES      Extra bytes For Cache alignment
- *      DSP_CACHE_ALIGNMENT    Cache alignment value
- */
-/* ======================================================================= */
-
-#define EXTRA_BYTES 128 
-#define DSP_CACHE_ALIGNMENT 256 
-    
 /* ======================================================================= */
 /**
  * @def NBAMRENC_NUM_INPUT_BUFFERS   Default number of input buffers
@@ -646,23 +597,23 @@
 /* =================================================================================== */
 /**
 * NBAMRENC_TALGCtrl                 Socket Node Alg Control parameters.
+* NBAMRENC_TALGCtrlDTX                 Socket Node Alg Control parameters (DTX).
 * NBAMRENC_UAlgInBufParamStruct     Input Buffer Param Structure
 * NBAMRENC_UAlgOutBufParamStruct    Output Buffer Param Structure
 */
 /* =================================================================================== */
 /* Algorithm specific command parameters */
 typedef struct {
-    unsigned int iSize;
+    int iSize;
     unsigned int iBitrate;
-    unsigned int iDTX;
-    unsigned int iMode;
-    unsigned int iFrameSize;
-    unsigned int iNoiseSuppressionMode;
-    unsigned int ittyTddMode;
-    unsigned int idtmfMode;
-    unsigned int idataTransmit;
+
 }NBAMRENC_TALGCtrl;
 
+typedef struct {
+    int iSize;
+    unsigned int iVADFlag;
+
+}NBAMRENC_TALGCtrlDTX;
 /* =================================================================================== */
 /**
 * NBAMRENC_UAlgInBufParamStruct     Input Buffer Param Structure
@@ -763,7 +714,10 @@
     OMX_PORT_PARAM_TYPE* sPortParam;
     OMX_PRIORITYMGMTTYPE* sPriorityMgmt;
     
-    /* RMPROXY_CALLBACKTYPE rmproxyCallback; */
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
     OMX_BOOL bPreempted;
     
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef[NBAMRENC_NUM_OF_PORTS];
@@ -798,9 +752,9 @@
 
     OMX_U32 nMultiFrameMode;
 
-    OMX_U32 fdwrite;
+    OMX_S32 fdwrite;
 
-    OMX_U32 fdread;
+    OMX_S32 fdread;
 
     /** Set to indicate component is stopping */
     OMX_U32 bIsStopping;
@@ -869,6 +823,8 @@
 
     NBAMRENC_TALGCtrl *pAlgParam;
 
+    NBAMRENC_TALGCtrlDTX *pAlgParamDTX;
+
     NBAMRENC_AudioCodecParams *pParams;
 
     OMX_STRING cComponentName;
@@ -977,8 +933,6 @@
     OMX_U32 nPendingStateChangeRequests;
     pthread_mutex_t mutexStateChangeRequest;
     pthread_cond_t StateChangeCondition;
-
-
 } AMRENC_COMPONENT_PRIVATE;
 
 
@@ -1241,9 +1195,9 @@
                          OMX_U8 *pBuffer,
                          OMX_DIRTYPE eDir);
 
-                         
-/* void NBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData); */
-
+#ifdef RESOURCE_MANAGER_ENABLED
+void NBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
 /* ======================================================================= */
 /** OMX_NBAMRENC_INDEXAUDIOTYPE  Defines the custom configuration settings
 *                              for the component
@@ -1262,8 +1216,11 @@
 
 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle, int size, void* pArmPtr, DMM_BUFFER_OBJ* pDmmBuf, struct OMX_TI_Debug dbg);
 OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg);
+
+void NBAMRENC_HandleUSNError (AMRENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
 OMX_ERRORTYPE AddStateTransition(AMRENC_COMPONENT_PRIVATE *pComponentPrivate);
 OMX_ERRORTYPE RemoveStateTransition(AMRENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_BOOL bEnableSignal);
+
 /*===============================================================*/
 
 typedef enum {
diff --git a/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEnc_ComponentThread.c b/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEnc_ComponentThread.c
index a3a2cd6..b189ea6 100644
--- a/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEnc_ComponentThread.c
+++ b/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEnc_ComponentThread.c
@@ -156,7 +156,7 @@
                     goto EXIT;
                 }
              }
-             OMX_ERROR2(pComponentPrivate->dbg, "%d :: Component Time Out !!!!! \n",__LINE__);
+             OMX_PRINT1(pComponentPrivate->dbg, "%d :: Component Time Out !!!!! \n",__LINE__);
         } else if(-1 == status) {
             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error in Select\n", __LINE__);
             pComponentPrivate->cbInfo.EventHandler ( pHandle,
@@ -166,7 +166,6 @@
                                                      OMX_TI_ErrorSevere,
                                                      "Error from Component Thread in select");
             eError = OMX_ErrorInsufficientResources;
-            break;
 
         } else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))
                    && (pComponentPrivate->curState != OMX_StatePause)) {
diff --git a/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEnc_Utils.c b/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEnc_Utils.c
index b2c96c5..fb6eba7 100644
--- a/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEnc_Utils.c
+++ b/omx/audio/src/openmax_il/nbamr_enc/src/OMX_AmrEnc_Utils.c
@@ -94,65 +94,6 @@
     #include <ResourceManagerProxyAPI.h>
 #endif
 
-#ifdef NBAMRENC_DEBUGMEM
-  void *arr[500];
-  int lines[500];
-  int bytes[500];
-  char file[500][50];
-
-
-void * mymalloc(int line, char *s, int size);
-int mynewfree(void *dp, int line, char *s);
-
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-
-void * mymalloc(int line, char *s, int size)
-{
-   void *p;    
-   int e=0;
-/*   p = malloc(size);*/
-   p = calloc(1,size);
-   if(p==NULL){
-       OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
-       }
-   else{
-         while((lines[e]!=0)&& (e<500) ){
-              e++;
-         }
-         arr[e]=p;
-         lines[e]=line;
-         bytes[e]=size;
-         strcpy(file[e],s);
-         OMXDBG_PRINT(stderr, ERROR, 4, 0, "Allocating %d bytes on address %p, line %d file %s\n", size, p, line, s);
-   }
-   return p;
-}
-
-int myfree(void *dp, int line, char *s){
-    int q;
-    if(dp==NULL){
-                 OMXDBG_PRINT(stderr, ERROR, 4, 0, "NULL can't be deleted\n");
-                 return 0;
-    }
-    for(q=0;q<500;q++){
-        if(arr[q]==dp){
-           OMXDBG_PRINT(stderr, ERROR, 4, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
-           free(dp);
-           dp = NULL;
-           lines[q]=0;
-           strcpy(file[q],"");
-           break;
-        }            
-     }    
-     if(500==q)
-         OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
-}
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
 /* ========================================================================== */
 /**
 * @NBAMRENC_FillLCMLInitParams () This function is used by the component thread to
@@ -181,8 +122,6 @@
     NBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
     OMX_U16 i;
     OMX_U32 size_lcml;
-    OMX_U8 *pBufferParamTemp;
-    char *pTemp_char = NULL;
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_FillLCMLInitParams\n",__LINE__);
     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
     nIpBufSize = pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->nBufferSize;
@@ -224,7 +163,7 @@
 
     if(pComponentPrivate->dasfMode == 1) {
         OMX_PRDSP2(pComponentPrivate->dbg, "%d :: Codec is configuring to DASF mode\n",__LINE__);
-        NBAMRENC_OMX_MALLOC(pComponentPrivate->strmAttr, LCML_STRMATTR);
+        OMX_MALLOC_GENERIC(pComponentPrivate->strmAttr, LCML_STRMATTR);
         pComponentPrivate->strmAttr->uSegid = NBAMRENC_DEFAULT_SEGMENT;
         pComponentPrivate->strmAttr->uAlignment = 0;
         pComponentPrivate->strmAttr->uTimeout = NBAMRENC_SN_TIMEOUT;
@@ -315,7 +254,7 @@
      * This memory pointer will be sent to LCML */
     size_lcml = nIpBuf * sizeof(NBAMRENC_LCML_BUFHEADERTYPE);
     
-    NBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE);
 
     pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT] = pTemp_lcml;
     for (i=0; i<nIpBuf; i++) {
@@ -331,16 +270,13 @@
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer);
         pTemp_lcml->eDir = OMX_DirInput;
 
-        
-        NBAMRENC_OMX_MALLOC_SIZE(pBufferParamTemp, sizeof(NBAMRENC_ParamStruct) + DSP_CACHE_ALIGNMENT,OMX_U8);
-
-        pTemp_lcml->pBufferParam =  (NBAMRENC_ParamStruct*)(pBufferParamTemp + EXTRA_BYTES);
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam, sizeof(NBAMRENC_ParamStruct),OMX_U8);
 
         pTemp_lcml->pBufferParam->usNbFrames=0;
         pTemp_lcml->pBufferParam->pParamElem=NULL;
         pTemp_lcml->pFrameParam=NULL;
         
-        NBAMRENC_OMX_MALLOC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
+        OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
         /* This means, it is not a last buffer. This flag is to be modified by
          * the application to indicate the last buffer */
@@ -353,8 +289,7 @@
      * This memory pointer will be sent to LCML */
     size_lcml = nOpBuf * sizeof(NBAMRENC_LCML_BUFHEADERTYPE);
 
-    NBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE);
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [ALLOC]  %p\n",__LINE__,pTemp_lcml);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE);
 
     pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT] = pTemp_lcml;
     for (i=0; i<nOpBuf; i++) {
@@ -371,19 +306,15 @@
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer);
         pTemp_lcml->eDir = OMX_DirOutput;
         
-        NBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml->pBufferParam,
-                                (sizeof(NBAMRENC_ParamStruct)+DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
+                                sizeof(NBAMRENC_ParamStruct),
                                 NBAMRENC_ParamStruct); 
 
-        pTemp_char = (char*)pTemp_lcml->pBufferParam;
-        pTemp_char += EXTRA_BYTES;
-        pTemp_lcml->pBufferParam = (NBAMRENC_ParamStruct*)pTemp_char;
-        
         pTemp_lcml->pBufferParam->usNbFrames=0;
         pTemp_lcml->pBufferParam->pParamElem=NULL;
         pTemp_lcml->pFrameParam=NULL;
 
-        NBAMRENC_OMX_MALLOC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
+        OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
         pTemp->nFlags = NBAMRENC_NORMAL_BUFFER;
         pTemp++;
@@ -502,6 +433,7 @@
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     AMRENC_COMPONENT_PRIVATE *pComponentPrivate = (AMRENC_COMPONENT_PRIVATE *)
                                                      pHandle->pComponentPrivate;
+
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_FreeCompResources\n",__LINE__);
 
     if (pComponentPrivate->bCompThreadStarted) {
@@ -513,20 +445,24 @@
         OMX_NBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[1],err);
     }
 
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pcmParams);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->amrParams);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, NBAMRENC_TALGCtrl);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParamDTX, NBAMRENC_TALGCtrlDTX);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, NBAMRENC_AudioCodecParams);
 
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]->pPortFormat);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]->pPortFormat);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pcmParams);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->amrParams);
 
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->sPortParam);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->sPriorityMgmt);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]->pPortFormat);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]->pPortFormat);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]);
+
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sPortParam);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sPriorityMgmt);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
 
 EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_FreeCompResources()\n",__LINE__);
@@ -556,9 +492,7 @@
     OMX_U32 nOpBuf = 0;
     OMX_U16 i = 0;
     NBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml;
-    OMX_U8* pAlgParmTemp;
-    OMX_U8* pBufParmsTemp;
-    char *pTemp = NULL;
+	
     LCML_DSP_INTERFACE *pLcmlHandle;
     LCML_DSP_INTERFACE *pLcmlHandleAux;
 
@@ -569,20 +503,17 @@
 
     if(pComponentPrivate->dasfMode == 1) {
 
-        OMX_NBMEMFREE_STRUCT(pComponentPrivate->strmAttr);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
     }
 
-    pAlgParmTemp = (OMX_U8*)pComponentPrivate->pAlgParam;
-    if (pAlgParmTemp != NULL){
-       pAlgParmTemp -= EXTRA_BYTES;}
-    pComponentPrivate->pAlgParam = (NBAMRENC_TALGCtrl*)pAlgParmTemp;
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pAlgParam);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, NBAMRENC_TALGCtrl);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParamDTX, NBAMRENC_TALGCtrlDTX);
 
-        pComponentPrivate->nHoldLength = 0;
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pHoldBuffer2);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->iHoldBuffer);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->iMMFDataLastBuffer);
+    pComponentPrivate->nHoldLength = 0;
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer2);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->iHoldBuffer);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->iMMFDataLastBuffer);
 
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT];
     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
@@ -595,28 +526,13 @@
                                (void*)pTemp_lcml->pBufferParam->pParamElem,
                                pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
                                                                        
-              pBufParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam;
-              pBufParmsTemp -= EXTRA_BYTES;
-              OMX_NBMEMFREE_STRUCT(pBufParmsTemp);
-              pBufParmsTemp = NULL;
-              pTemp_lcml->pFrameParam = NULL;
+              OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, NBAMRENC_FrameStruct);
         }
 
-    pTemp = (char*)pTemp_lcml->pBufferParam;
-    if (pTemp != NULL) {        
-        pTemp -= EXTRA_BYTES;
+    OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, NBAMRENC_ParamStruct);
+    OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
+    pTemp_lcml++;
     }
-    pTemp_lcml->pBufferParam = (NBAMRENC_ParamStruct*)pTemp;
-    OMX_NBMEMFREE_STRUCT(pTemp_lcml->pBufferParam);
-    
-
-        if(pTemp_lcml->pDmmBuf!=NULL){
-             OMX_NBMEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
-             pTemp_lcml->pDmmBuf = NULL;
-        }
-        pTemp_lcml++;
-    }
-
 
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT];
     nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
@@ -631,32 +547,17 @@
                                pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
 #endif
               
-              pBufParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam;
-              pBufParmsTemp -= EXTRA_BYTES;
-              OMX_NBMEMFREE_STRUCT(pBufParmsTemp);
-              pBufParmsTemp = NULL;
-              pTemp_lcml->pFrameParam = NULL;              
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, NBAMRENC_FrameStruct);
         }
 
-pTemp = (char*)pTemp_lcml->pBufferParam;
-    if (pTemp != NULL) {        
-        pTemp -= EXTRA_BYTES;
-    }
-    pTemp_lcml->pBufferParam = (NBAMRENC_ParamStruct*)pTemp;
-    OMX_NBMEMFREE_STRUCT(pTemp_lcml->pBufferParam);
-    
-
-
-        if(pTemp_lcml->pDmmBuf!=NULL){
-             OMX_NBMEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
-             pTemp_lcml->pDmmBuf = NULL;
-        }
-        pTemp_lcml++;
+    OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, NBAMRENC_ParamStruct);
+    OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
+    pTemp_lcml++;
     }
 
 
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT]);
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT]);
 
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_CleanupInitParams()\n",__LINE__);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
@@ -741,8 +642,6 @@
     OMX_U16 arr[100];
     char *pArgs = "damedesuStr";
     char *p = "hello";
-    OMX_U8* pParmsTemp;
-    OMX_U8* pAlgParmTemp;
     OMX_U16 i = 0;
     OMX_U32 ret = 0;
     OMX_U8 inputPortFlag=0,outputPortFlag=0;    
@@ -879,12 +778,12 @@
                     /* send an event to client */
                     /* client should unload the component if the codec is not able to load */
                     eError = OMX_ErrorInvalidState;
-                    pComponentPrivate->cbInfo.EventHandler (pHandle,
-                                                            pHandle->pApplicationPrivate,
-                                                            OMX_EventError,
-                                                            eError,
-                                                            OMX_TI_ErrorSevere,
-                                                            NULL);
+                    pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
                     goto EXIT;
                 }
 
@@ -894,10 +793,10 @@
 
                 if (pComponentPrivate->curState != OMX_StateWaitForResources){
 
-                    rm_error = RMProxy_NewSendCommand(pHandle,
-                                                        RMProxy_RequestResource,
-                                                        OMX_NBAMR_Encoder_COMPONENT, NBAMRENC_CPU_LOAD,
-                                                        3456, &(pComponentPrivate->rmproxyCallback));
+                    rm_error = RMProxy_NewSendCommand(pHandle, 
+                                                        RMProxy_RequestResource, 
+                                                        OMX_NBAMR_Encoder_COMPONENT, NBAMRENC_CPU_LOAD, 
+                                                        3456, &(pComponentPrivate->rmproxyCallback));   
 
                     if(rm_error == OMX_ErrorNone) {
                         /* resource is available */
@@ -913,9 +812,9 @@
 
                         pComponentPrivate->cbInfo.EventHandler(pHandle,
                                 pHandle->pApplicationPrivate,
-                                OMX_EventCmdComplete,
+                                OMX_EventCmdComplete, 
                                 OMX_CommandStateSet,
-                                pComponentPrivate->curState,
+                                pComponentPrivate->curState, 
                                 NULL);
 
                         rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_NBAMR_Encoder_COMPONENT, OMX_StateIdle, 3456, NULL);
@@ -942,9 +841,9 @@
 
                     pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                             pHandle->pApplicationPrivate,
-                                                            OMX_EventCmdComplete,
+                                                            OMX_EventCmdComplete, 
                                                             OMX_CommandStateSet,
-                                                            pComponentPrivate->curState,
+                                                            pComponentPrivate->curState, 
                                                             NULL);
 
                 rm_error = RMProxy_NewSendCommand(pHandle,
@@ -955,7 +854,7 @@
                                                        NULL);
 
             }
-#else
+#else           
                 pComponentPrivate->curState = OMX_StateIdle;
 
                 /* Decrement reference count with signal enabled */
@@ -971,7 +870,7 @@
                                                         NULL);
 
 #endif
-
+                
             }
             else if (pComponentPrivate->curState == OMX_StateExecuting) {
                 OMX_PRSTATE1(pComponentPrivate->dbg, "%d :: Setting Component to OMX_StateIdle\n",__LINE__);
@@ -993,22 +892,13 @@
                     pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
                 }
                     
-                pAlgParmTemp = (OMX_U8*)pComponentPrivate->pAlgParam;
-                if (pAlgParmTemp != NULL)
-                   pAlgParmTemp -= EXTRA_BYTES;
-                pComponentPrivate->pAlgParam = (NBAMRENC_TALGCtrl*)pAlgParmTemp;
-                OMX_NBMEMFREE_STRUCT(pComponentPrivate->pAlgParam);
+                OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, NBAMRENC_TALGCtrl);
+                OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParamDTX, NBAMRENC_TALGCtrlDTX);
                 
                 pComponentPrivate->nOutStandingFillDones = 0;
                                 pComponentPrivate->nOutStandingEmptyDones = 0; 
 
-    
-                pParmsTemp = (OMX_U8*)pComponentPrivate->pParams;
-                if (pParmsTemp != NULL){
-                     pParmsTemp -= EXTRA_BYTES;
-                }
-                pComponentPrivate->pParams = (NBAMRENC_AudioCodecParams*)pParmsTemp;
-                OMX_NBMEMFREE_STRUCT(pComponentPrivate->pParams);
+                OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, NBAMRENC_AudioCodecParams);
 
                 if(eError != OMX_ErrorNone) {
                     OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error from LCML_ControlCodec MMCodecControlStop..\n",__LINE__);
@@ -1070,25 +960,20 @@
                 pComponentPrivate->nEmptyBufferDoneCount = 0;
                 pComponentPrivate->nEmptyThisBufferCount =0;
 
-                                
+                OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pAlgParam, sizeof(NBAMRENC_TALGCtrl),OMX_U8);
+                OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pAlgParamDTX, sizeof(NBAMRENC_TALGCtrlDTX),OMX_U8);
                 
-                NBAMRENC_OMX_MALLOC_SIZE(pAlgParmTemp, sizeof(NBAMRENC_TALGCtrl) + DSP_CACHE_ALIGNMENT,OMX_U8);
-                
-                pComponentPrivate->pAlgParam = (NBAMRENC_TALGCtrl*)(pAlgParmTemp + EXTRA_BYTES);
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [ALLOC] %p\n",__LINE__,pComponentPrivate->pAlgParam);
-
                 pComponentPrivate->pAlgParam->iBitrate = pComponentPrivate->amrParams->eAMRBandMode;
                 if (pComponentPrivate->amrParams->eAMRDTXMode == OMX_AUDIO_AMRDTXModeOnAuto) {
-                    pComponentPrivate->pAlgParam->iDTX = OMX_TRUE;
+                    pComponentPrivate->pAlgParamDTX->iVADFlag = OMX_TRUE;
                 }
                 else {
-                    pComponentPrivate->pAlgParam->iDTX = OMX_FALSE;
+                    pComponentPrivate->pAlgParamDTX->iVADFlag = OMX_FALSE;
                 }
-
                 pComponentPrivate->pAlgParam->iSize = sizeof (NBAMRENC_TALGCtrl);
-
+                pComponentPrivate->pAlgParamDTX->iSize = sizeof (NBAMRENC_TALGCtrlDTX);
                 OMX_PRINT2(pComponentPrivate->dbg, "%d :: pAlgParam->iBitrate = %d\n",__LINE__,pComponentPrivate->pAlgParam->iBitrate);
-                OMX_PRINT2(pComponentPrivate->dbg, "%d :: pAlgParam->iDTX  = %d\n",__LINE__,pComponentPrivate->pAlgParam->iDTX);
+                OMX_PRINT2(pComponentPrivate->dbg, "%d :: pAlgParamDTX->iVADFlag  = %d\n",__LINE__,pComponentPrivate->pAlgParamDTX->iVADFlag);
 
                 cmdValues[0] = ALGCMD_BITRATE;                  /*setting the bit-rate*/
                 cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParam;
@@ -1103,8 +988,8 @@
                     goto EXIT;
                 }
                 cmdValues[0] = ALGCMD_DTX;                  /*setting DTX mode*/
-                cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParam;
-                cmdValues[2] = sizeof (NBAMRENC_TALGCtrl);
+                cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParamDTX;
+                cmdValues[2] = sizeof (NBAMRENC_TALGCtrlDTX);
                 p = (void *)&cmdValues;
                 OMX_PRCOMM1(pComponentPrivate->dbg, "%d :: EMMCodecControlAlgCtrl-2 Sending...\n",__LINE__);
                 /* Sending ALGCTRL MESSAGE BITRATE to DSP via LCML_ControlCodec*/
@@ -1117,11 +1002,7 @@
                 if(pComponentPrivate->dasfMode == 1) {
                     OMX_PRDSP2(pComponentPrivate->dbg, "%d :: ---- Comp: DASF Functionality is ON ---\n",__LINE__);
 
-                    
-                    NBAMRENC_OMX_MALLOC_SIZE(pParmsTemp, sizeof(NBAMRENC_AudioCodecParams) + DSP_CACHE_ALIGNMENT,OMX_U8);
-
-                    pComponentPrivate->pParams = (NBAMRENC_AudioCodecParams*)(pParmsTemp + EXTRA_BYTES);
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: [ALLOC] %p\n",__LINE__,pComponentPrivate->pParams);
+                    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams, sizeof(NBAMRENC_AudioCodecParams),OMX_U8);
 
                     pComponentPrivate->pParams->iAudioFormat = 1;
                     pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID;
@@ -1663,6 +1544,14 @@
 EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting NBAMRENC_HandleCommand Function\n",__LINE__);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
+    if (eError != OMX_ErrorNone && eError != NBAMRENC_EXIT_COMPONENT_THRD) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -1693,8 +1582,6 @@
     OMX_U8* pExtraData = NULL;
     OMX_U8 nFrames=0,i;
     LCML_DSP_INTERFACE * phandle = NULL;
-    OMX_U8* pBufParmsTemp = NULL;
-
 
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering NBAMRENC_HandleDataBufFromApp Function\n",__LINE__);
     /*Find the direction of the received buffer from buffer list */
@@ -1715,7 +1602,7 @@
                                         pComponentPrivate->nHoldLength = pBufHeader->nFilledLen - frameLength*nFrames;
                                         if (pComponentPrivate->nHoldLength > 0) {/* something need to be hold in pHoldBuffer */
                                                 if (pComponentPrivate->pHoldBuffer == NULL) {
-                                                   NBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8);
+                                                   OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8);
                                                 }
                                                 
                                                 /* Copy the extra data into pHoldBuffer. Size will be nHoldLength. */
@@ -1738,11 +1625,8 @@
                                                 pComponentPrivate->nHoldLength = pBufHeader->nFilledLen;
                                                 /* save the data into pHoldBuffer */
                                                 if (pComponentPrivate->pHoldBuffer == NULL) {
-                                                    NBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8); 
+                                                    OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8); 
                                                 }
-                                                /* Not enough data to be sent. Copy all received data into pHoldBuffer.*/
-                                                /* Size to be copied will be iHoldLen == mmData->BufferSize() */
-                                                memset(pComponentPrivate->pHoldBuffer, 0, NBAMRENC_INPUT_FRAME_SIZE);
                                                 
                                                 if(pComponentPrivate->nHoldLength <= NBAMRENC_INPUT_FRAME_SIZE) {
                                                     memcpy(pComponentPrivate->pHoldBuffer, pBufHeader->pBuffer, pComponentPrivate->nHoldLength);
@@ -1784,7 +1668,7 @@
                                                      into hold buffer*/
                                         remainingBytes = pComponentPrivate->nHoldLength+pBufHeader->nFilledLen-pBufHeader->nAllocLen;
                                         if (pComponentPrivate->pHoldBuffer2 == NULL) {
-                                                        NBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer2, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8);
+                                                        OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer2, NBAMRENC_INPUT_FRAME_SIZE,OMX_U8);
                                         }
                                         pExtraData = (pBufHeader->pBuffer)+(pBufHeader->nFilledLen-remainingBytes);
                                         memcpy(pComponentPrivate->pHoldBuffer2,pExtraData,remainingBytes);
@@ -1875,11 +1759,7 @@
                 phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 
                 if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){
-                        pBufParmsTemp = (OMX_U8*)pLcmlHdr->pFrameParam; /*This means that more memory need to be used*/
-                        pBufParmsTemp -=EXTRA_BYTES;
-                        OMX_NBMEMFREE_STRUCT(pBufParmsTemp);
-                        pLcmlHdr->pFrameParam = NULL;
-                        pBufParmsTemp =NULL;
+                        OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam, NBAMRENC_FrameStruct);
                         OMX_DmmUnMap(phandle->dspCodec->hProc, /*Unmap DSP memory used*/
                                    (void*)pLcmlHdr->pBufferParam->pParamElem,
                                    pLcmlHdr->pDmmBuf->pReserved, pComponentPrivate->dbg);
@@ -1887,8 +1767,7 @@
                 }
 
                 if(pLcmlHdr->pFrameParam==NULL ){
-                        NBAMRENC_OMX_MALLOC_SIZE(pBufParmsTemp, (sizeof(NBAMRENC_FrameStruct)*nFrames) + DSP_CACHE_ALIGNMENT,OMX_U8);
-                        pLcmlHdr->pFrameParam =  (NBAMRENC_FrameStruct*)(pBufParmsTemp + EXTRA_BYTES);
+                        OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam, (sizeof(NBAMRENC_FrameStruct)*nFrames),OMX_U8);
                         eError = OMX_DmmMap(phandle->dspCodec->hProc,
                                         nFrames*sizeof(NBAMRENC_FrameStruct),
                                         (void*)pLcmlHdr->pFrameParam,
@@ -2023,13 +1902,9 @@
      phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 
      if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){
-                   pBufParmsTemp = (OMX_U8*)pLcmlHdr->pFrameParam; /*This means that more memory need to be used*/
-                   pBufParmsTemp -=EXTRA_BYTES;
-                   OMX_NBMEMFREE_STRUCT(pBufParmsTemp);
-                   pLcmlHdr->pFrameParam = NULL;
-                   pBufParmsTemp =NULL;
+                   OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam, NBAMRENC_FrameStruct);
 #ifndef UNDER_CE
-                  OMX_DmmUnMap(phandle->dspCodec->hProc,
+                   OMX_DmmUnMap(phandle->dspCodec->hProc,
                                    (void*)pLcmlHdr->pBufferParam->pParamElem,
                                    pLcmlHdr->pDmmBuf->pReserved, pComponentPrivate->dbg);
 #endif
@@ -2038,11 +1913,9 @@
          }
 
      if(pLcmlHdr->pFrameParam==NULL ){
-                    NBAMRENC_OMX_MALLOC_SIZE(pBufParmsTemp, (sizeof(NBAMRENC_FrameStruct)*nFrames ) + DSP_CACHE_ALIGNMENT,OMX_U8);
-                   pLcmlHdr->pFrameParam =  (NBAMRENC_FrameStruct*)(pBufParmsTemp + EXTRA_BYTES);
-                   pLcmlHdr->pBufferParam->pParamElem = NULL;
+                   OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam, (sizeof(NBAMRENC_FrameStruct)*nFrames ),OMX_U8);
 #ifndef UNDER_CE
-                 eError = OMX_DmmMap(phandle->dspCodec->hProc,
+                   eError = OMX_DmmMap(phandle->dspCodec->hProc,
                                        nFrames*sizeof(NBAMRENC_FrameStruct),
                                        (void*)pLcmlHdr->pFrameParam,
                                        (pLcmlHdr->pDmmBuf), pComponentPrivate->dbg);
@@ -2128,7 +2001,7 @@
         pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i];
         if(pBufHeader == pBuf) {
             *eDir = OMX_DirInput;
-            OMX_ERROR2(pComponentPrivate->dbg, "%d :: pBufHeader = %p is INPUT BUFFER pBuf = %p\n",__LINE__,pBufHeader,pBuf);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pBufHeader = %p is INPUT BUFFER pBuf = %p\n",__LINE__,pBufHeader,pBuf);
             flag = 0;
             goto EXIT;
         }
@@ -2139,7 +2012,7 @@
         pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i];
         if(pBufHeader == pBuf) {
             *eDir = OMX_DirOutput;
-            OMX_ERROR2(pComponentPrivate->dbg, "%d :: pBufHeader = %p is OUTPUT BUFFER pBuf = %p\n",__LINE__,pBufHeader,pBuf);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pBufHeader = %p is OUTPUT BUFFER pBuf = %p\n",__LINE__,pBufHeader,pBuf);
             flag = 0;
             goto EXIT;
         }
@@ -2566,7 +2439,7 @@
         if(pComponentPrivate_CC->codecStop_waitingsignal == 0){
             pComponentPrivate_CC->codecStop_waitingsignal = 1;             
             pthread_cond_signal(&pComponentPrivate_CC->codecStop_threshold);
-            OMX_ERROR2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
+            OMX_PRINT2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
         }
         pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
         
@@ -2622,10 +2495,10 @@
             pComponentPrivate_CC->ProcessingOutputBuf=0;
             
             pComponentPrivate_CC->nHoldLength = 0;
-        pComponentPrivate_CC->InBuf_Eos_alreadysent  =0;
+            pComponentPrivate_CC->InBuf_Eos_alreadysent = 0;
         
-            OMX_NBMEMFREE_STRUCT(pComponentPrivate_CC->pHoldBuffer);
-            OMX_NBMEMFREE_STRUCT(pComponentPrivate_CC->iMMFDataLastBuffer);
+            OMX_MEMFREE_STRUCT(pComponentPrivate_CC->pHoldBuffer);
+            OMX_MEMFREE_STRUCT(pComponentPrivate_CC->iMMFDataLastBuffer);
         
             pComponentPrivate_CC->curState = OMX_StateIdle;
 #ifdef RESOURCE_MANAGER_ENABLED
@@ -2674,118 +2547,44 @@
         OMX_PRINT2(pComponentPrivate_CC->dbg, "%d :: GOT MESSAGE USN_DSPACK_ALGCTRL \n",__LINE__);
     }
         else if (event == EMMCodecDspError) {
+            switch ( (OMX_U32) args [4])
+            {
+            /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
+             * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
+             * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
+             * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
+             * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
+             * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
+             * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
+             * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
+
 #ifdef _ERROR_PROPAGATION__
-            /* Cheking for MMU_fault */
-            if(((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] ==(void*) NULL)) {
-                pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
-                pComponentPrivate_CC->curState = OMX_StateInvalid;
-                pHandle = pComponentPrivate_CC->pHandle;
-                pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
-                                                           pHandle->pApplicationPrivate,
-                                                           OMX_EventError,
-                                                           OMX_ErrorInvalidState,
-                                                           OMX_TI_ErrorSevere,
-                                                           NULL);
+                case USN_ERR_PAUSE:
+                case USN_ERR_STOP:
+                case USN_ERR_ALGCTRL:
+                case USN_ERR_STRMCTRL:
+                case USN_ERR_UNKNOWN_MSG: 
+                {
+                    pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
+                    pComponentPrivate_CC->curState = OMX_StateInvalid;
+                    pHandle = pComponentPrivate_CC->pHandle;
+                    pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 
+                            pHandle->pApplicationPrivate,
+                            OMX_EventError,
+                            OMX_ErrorInvalidState, 
+                            OMX_TI_ErrorSevere,
+                            NULL);
+                }
+                    break;
+#endif
+
+                case USN_ERR_WARNING:
+                case USN_ERR_PROCESS:
+                    NBAMRENC_HandleUSNError (pComponentPrivate_CC, (OMX_U32)args[5]);
+                    break;
+                default:
+                    break;
             }
-#endif
-                if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) {
-                        pHandle = pComponentPrivate_CC->pHandle;
-                        OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__);
-                        OMX_PRINT2(pComponentPrivate_CC->dbg, "IUALG_WARN_PLAYCOMPLETED Received\n");
-                        if(pComponentPrivate_CC->LastOutbuf!=NULL){
-                                    pComponentPrivate_CC->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS;
-                        }
-                        pComponentPrivate_CC->cbInfo.EventHandler(pComponentPrivate_CC->pHandle,
-                                                                pComponentPrivate_CC->pHandle->pApplicationPrivate,
-                                                                OMX_EventBufferFlag,
-                                                                (OMX_U32)NULL,
-                                                                OMX_BUFFERFLAG_EOS,
-                                                                NULL);
-                }
-                if((int)args[5] == IUALG_ERR_GENERAL) {
-                        char *pArgs = "damedesuStr";
-                        OMX_ERROR4(pComponentPrivate_CC->dbg,  "Algorithm error. Cannot continue" );
-                        OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);                        
-                        OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: LCML_Callback: IUALG_ERR_GENERAL\n",__LINE__);
-                        pHandle = pComponentPrivate_CC->pHandle;
-                        pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate_CC->pLcmlHandle;
-#ifndef UNDER_CE
-
-                        pComponentPrivate_CC->bIsStopping = 1;
-                        if (pComponentPrivate_CC->codecStop_waitingsignal == 0){ 
-                            pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex);     
-                        }
-
-                        eError = LCML_ControlCodec(
-                                ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                MMCodecControlStop,(void *)pArgs);
-
-                        if (pComponentPrivate_CC->codecStop_waitingsignal == 0){
-                            pthread_cond_wait(&pComponentPrivate_CC->codecStop_threshold, &pComponentPrivate_CC->codecStop_mutex);
-                            pComponentPrivate_CC->codecStop_waitingsignal = 0;
-                            pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
-                        }
-
-                        if(eError != OMX_ErrorNone) {
-                                OMX_ERROR4(pComponentPrivate_CC->dbg, "%d: Error Occurred in Codec Stop..\n",
-                                __LINE__);
-                                goto EXIT;
-                        }
-                        OMX_PRSTATE2(pComponentPrivate_CC->dbg, "%d :: AMRENC: Codec has been Stopped here\n",__LINE__);
-                        pComponentPrivate_CC->curState = OMX_StateIdle;
-                        pComponentPrivate_CC->cbInfo.EventHandler(
-                                        pHandle, pHandle->pApplicationPrivate,
-                                        OMX_EventCmdComplete, OMX_ErrorNone,0, NULL);
-#else
-                        pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 
-                                                                    pHandle->pApplicationPrivate,
-                                                                    OMX_EventError, 
-                                                                    OMX_ErrorUndefined,
-                                                                    OMX_TI_ErrorSevere, 
-                                                                    NULL);
-#endif
-                }
-                if( (int)args[5] == IUALG_ERR_DATA_CORRUPT ){
-                        char *pArgs = "damedesuStr";
-                        OMX_ERROR4(pComponentPrivate_CC->dbg,  "Algorithm error. Corrupt data" );
-                        OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: arg5 = %p\n",__LINE__,args[5]);
-                        OMX_ERROR4(pComponentPrivate_CC->dbg, "%d :: LCML_Callback: IUALG_ERR_DATA_CORRUPT\n",__LINE__);
-                        pHandle = pComponentPrivate_CC->pHandle;
-                        pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate_CC->pLcmlHandle;
-#ifndef UNDER_CE
-                        pComponentPrivate_CC->bIsStopping = 1;
-                        if (pComponentPrivate_CC->codecStop_waitingsignal == 0){ 
-                            pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex);     
-                        }
-
-                        eError = LCML_ControlCodec(
-                                ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                        MMCodecControlStop,(void *)pArgs);
-
-                        if (pComponentPrivate_CC->codecStop_waitingsignal == 0){
-                            pthread_cond_wait(&pComponentPrivate_CC->codecStop_threshold, &pComponentPrivate_CC->codecStop_mutex);
-                            pComponentPrivate_CC->codecStop_waitingsignal = 0;
-                            pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
-                        }
-
-                        if(eError != OMX_ErrorNone) {
-                                OMX_ERROR4(pComponentPrivate_CC->dbg, "%d: Error Occurred in Codec Stop..\n",__LINE__);
-                                goto EXIT;
-                        }
-                        OMX_PRSTATE2(pComponentPrivate_CC->dbg, "%d :: AMRENC: Codec has been Stopped here\n",__LINE__);
-                        pComponentPrivate_CC->curState = OMX_StateIdle;
-                        pComponentPrivate_CC->cbInfo.EventHandler(
-                                pHandle, pHandle->pApplicationPrivate,
-                                OMX_EventCmdComplete, OMX_ErrorNone,0, NULL);
-#else
-                        pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 
-                                                                    pHandle->pApplicationPrivate,
-                                                                    OMX_EventError, 
-                                                                    OMX_ErrorUndefined,
-                                                                    OMX_TI_ErrorSevere, 
-                                                                    NULL);
-#endif
-                }
         }
         else if (event == EMMCodecProcessingPaused) {
             pComponentPrivate_CC->nUnhandledEmptyThisBuffers = 0;
@@ -2836,8 +2635,10 @@
     }
 #endif
 EXIT:
-    OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Exiting the NBAMRENC_LCMLCallback Function\n",__LINE__);
-    OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
+    if (pComponentPrivate_CC != NULL) {
+	OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Exiting the NBAMRENC_LCMLCallback Function\n", __LINE__);
+	OMX_PRINT1(pComponentPrivate_CC->dbg, "%d :: Returning = 0x%x\n", __LINE__, eError);
+    }
 
     return eError;
 }
@@ -3083,13 +2884,11 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
     OMX_BUFFERHEADERTYPE *pTemp;
-    char *ptr;
     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
     AMRENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
     NBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
     OMX_U16 i;
     OMX_U32 size_lcml;
-    OMX_U8  *pBufferParamTemp;
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: NBAMRENC_FillLCMLInitParamsEx\n",__LINE__);
     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
     nIpBufSize = pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT]->nBufferSize;
@@ -3104,7 +2903,7 @@
     /* Allocate memory for all input buffer headers..
      * This memory pointer will be sent to LCML */
     size_lcml = nIpBuf * sizeof(NBAMRENC_LCML_BUFHEADERTYPE);
-    NBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE);
     
     pComponentPrivate->pLcmlBufHeader[NBAMRENC_INPUT_PORT] = pTemp_lcml;
     for (i=0; i<nIpBuf; i++) {
@@ -3120,14 +2919,11 @@
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer);
         pTemp_lcml->eDir = OMX_DirInput;
 
-        NBAMRENC_OMX_MALLOC_SIZE(pBufferParamTemp, sizeof(NBAMRENC_ParamStruct) + DSP_CACHE_ALIGNMENT,OMX_U8);
-
-        pTemp_lcml->pBufferParam =  (NBAMRENC_ParamStruct*)(pBufferParamTemp + EXTRA_BYTES);
-        
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam, sizeof(NBAMRENC_ParamStruct), OMX_U8);
         pTemp_lcml->pBufferParam->usNbFrames=0;
         pTemp_lcml->pBufferParam->pParamElem=NULL;
         pTemp_lcml->pFrameParam=NULL;
-        NBAMRENC_OMX_MALLOC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
+        OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
         pTemp->nFlags = NBAMRENC_NORMAL_BUFFER;
         pTemp++;
@@ -3137,7 +2933,7 @@
     /* Allocate memory for all output buffer headers..
      * This memory pointer will be sent to LCML */
     size_lcml = nOpBuf * sizeof(NBAMRENC_LCML_BUFHEADERTYPE);
-    NBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,NBAMRENC_LCML_BUFHEADERTYPE);
 
     pComponentPrivate->pLcmlBufHeader[NBAMRENC_OUTPUT_PORT] = pTemp_lcml;
     for (i=0; i<nOpBuf; i++) {
@@ -3154,19 +2950,13 @@
         OMX_PRBUFFER1(pComponentPrivate->dbg, "%d :: pTemp_lcml->buffer->pBuffer = %p \n",__LINE__,pTemp_lcml->buffer->pBuffer);
         pTemp_lcml->eDir = OMX_DirOutput;
 
-        NBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml->pBufferParam,
-                                (sizeof(NBAMRENC_ParamStruct)+DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
+                                sizeof(NBAMRENC_ParamStruct),
                                 NBAMRENC_ParamStruct); 
-                                
-        ptr = (char*)pTemp_lcml->pBufferParam;
-        ptr += EXTRA_BYTES;
-        pTemp_lcml->pBufferParam = (NBAMRENC_ParamStruct*)ptr;
-        
         pTemp_lcml->pBufferParam->usNbFrames=0;
         pTemp_lcml->pBufferParam->pParamElem=NULL;
         pTemp_lcml->pFrameParam=NULL;
-        NBAMRENC_OMX_MALLOC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
-
+        OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
         pTemp->nFlags = NBAMRENC_NORMAL_BUFFER;
         pTemp++;
@@ -3281,7 +3071,6 @@
 {
     DSP_STATUS status = DSP_SOK;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-/*    printf("OMX UnReserve DSP: %p\n",pResPtr);*/
     if(pMapPtr == NULL)
     {
         OMX_ERROR4(dbg, "pMapPtr is NULL\n");
@@ -3320,8 +3109,8 @@
 }
 
 
-
-/* void NBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+#ifdef RESOURCE_MANAGER_ENABLED
+void NBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
 {
     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
     OMX_STATETYPE state = OMX_StateIdle;
@@ -3331,7 +3120,7 @@
     pCompPrivate = (AMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 
     if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) {
-        if (pCompPrivate->curState == OMX_StateExecuting ||
+        if (pCompPrivate->curState == OMX_StateExecuting || 
             pCompPrivate->curState == OMX_StatePause) {
             write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
             write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
@@ -3345,11 +3134,68 @@
                             OMX_EventResourcesAcquired, 0,0,
                             NULL);
 
-
     }
+}
+#endif
 
-} */
+void NBAMRENC_HandleUSNError (AMRENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
+{
+    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U8 pending_buffers = OMX_FALSE;
+    OMX_U32 i;
+    switch (arg)
+    {
+        case IUALG_WARN_CONCEALED:
+        case IUALG_WARN_UNDERFLOW:
+        case IUALG_WARN_OVERFLOW:
+        case IUALG_WARN_ENDOFDATA:
+            /* all of these are informative messages, Algo can recover, no need to notify the 
+             * IL Client at this stage of the implementation */
+            break;
 
+        case IUALG_WARN_PLAYCOMPLETED:
+        {
+            pHandle = pComponentPrivate->pHandle;
+            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__);
+            OMX_PRINT2(pComponentPrivate->dbg, "IUALG_WARN_PLAYCOMPLETED Received\n");
+            if(pComponentPrivate->LastOutbuf!=NULL){
+                pComponentPrivate->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS;
+            }
+            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                            pComponentPrivate->pHandle->pApplicationPrivate,
+                            OMX_EventBufferFlag,
+                            (OMX_U32)NULL,
+                            OMX_BUFFERFLAG_EOS,
+                            NULL);
+        }
+            break;
+
+#ifdef _ERROR_PROPAGATION__
+        case IUALG_ERR_BAD_HANDLE:
+        case IUALG_ERR_DATA_CORRUPT:
+        case IUALG_ERR_NOT_SUPPORTED:
+        case IUALG_ERR_ARGUMENT:
+        case IUALG_ERR_NOT_READY:
+        case IUALG_ERR_GENERAL:
+        {
+        /* all of these are fatal messages, Algo can not recover
+                 * hence return an error */
+                pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                pComponentPrivate->curState = OMX_StateInvalid;
+                pHandle = pComponentPrivate->pHandle;
+                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                        pHandle->pApplicationPrivate,
+                        OMX_EventError,
+                        OMX_ErrorInvalidState,
+                        OMX_TI_ErrorSevere,
+                        NULL);
+            }
+            break;
+#endif
+        default:
+            break;
+    }
+}
 OMX_ERRORTYPE AddStateTransition(AMRENC_COMPONENT_PRIVATE *pComponentPrivate) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
@@ -3385,6 +3231,3 @@
     return eError;
 }
 
-
-
-
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 5760d95..db06645 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
@@ -119,17 +119,6 @@
 /*--------function prototypes ---------------------------------*/
 #define AMRNB_DEC_ROLE "audio_encoder.amrnb"
 
-#ifdef NBAMRENC_DEBUGMEM
-extern void * mymalloc(int line, char *s, int size);
-extern int myfree(void *dp, int line, char *s);
-
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
 static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp,
         OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData);
 static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
@@ -247,7 +236,7 @@
 
 
     /*Allocate the memory for Component private data area */
-    NBAMRENC_OMX_MALLOC(pHandle->pComponentPrivate, AMRENC_COMPONENT_PRIVATE);
+    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, AMRENC_COMPONENT_PRIVATE);
 
 
     ((AMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
@@ -262,7 +251,7 @@
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE;
-    pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE;
+    pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_FALSE;
 #endif
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -270,13 +259,13 @@
                                            PERF_ModuleLLMM | PERF_ModuleAudioDecode);
 #endif
 
-    NBAMRENC_OMX_MALLOC(pCompPort, NBAMRENC_PORT_TYPE);
+    OMX_MALLOC_GENERIC(pCompPort, NBAMRENC_PORT_TYPE);
     pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT] = pCompPort;
 
-    NBAMRENC_OMX_MALLOC(pCompPort, NBAMRENC_PORT_TYPE);
+    OMX_MALLOC_GENERIC(pCompPort, NBAMRENC_PORT_TYPE);
     pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT] = pCompPort;
 
-    NBAMRENC_OMX_MALLOC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
     OMX_NBCONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
 
     /* Initialize sPortParam data structures to default values */
@@ -284,28 +273,28 @@
     pComponentPrivate->sPortParam->nStartPortNumber = 0x0;
 
     /* Malloc and Set pPriorityMgmt defaults */
-    NBAMRENC_OMX_MALLOC(pComponentPrivate->sPriorityMgmt, OMX_PRIORITYMGMTTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->sPriorityMgmt, OMX_PRIORITYMGMTTYPE);
     OMX_NBCONF_INIT_STRUCT(pComponentPrivate->sPriorityMgmt, OMX_PRIORITYMGMTTYPE);
 
     /* Initialize sPriorityMgmt data structures to default values */
     pComponentPrivate->sPriorityMgmt->nGroupPriority = -1;
     pComponentPrivate->sPriorityMgmt->nGroupID = -1;
 
-    NBAMRENC_OMX_MALLOC(amr_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
+    OMX_MALLOC_GENERIC(amr_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
     OMX_NBCONF_INIT_STRUCT(amr_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
     pComponentPrivate->pcmParams = amr_ip;
 
 
-    NBAMRENC_OMX_MALLOC(amr_op, OMX_AUDIO_PARAM_AMRTYPE);
+    OMX_MALLOC_GENERIC(amr_op, OMX_AUDIO_PARAM_AMRTYPE);
     OMX_NBCONF_INIT_STRUCT(amr_op, OMX_AUDIO_PARAM_AMRTYPE);
     pComponentPrivate->amrParams = amr_op;
 
     /* newmalloc and initialize number of input buffers */
-    NBAMRENC_OMX_MALLOC(pComponentPrivate->pInputBufferList, NBAMRENC_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pInputBufferList, NBAMRENC_BUFFERLIST);
     pComponentPrivate->pInputBufferList->numBuffers = 0;
 
     /* newmalloc and initialize number of output buffers */
-    NBAMRENC_OMX_MALLOC(pComponentPrivate->pOutputBufferList, NBAMRENC_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pOutputBufferList, NBAMRENC_BUFFERLIST);
     pComponentPrivate->pOutputBufferList->numBuffers = 0;
 
     for (i=0; i < NBAMRENC_MAX_NUM_OF_BUFS; i++) {
@@ -314,7 +303,7 @@
     }
 
     /* Set input port defaults */
-    NBAMRENC_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
     OMX_NBCONF_INIT_STRUCT(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
     pComponentPrivate->pPortDef[NBAMRENC_INPUT_PORT] = pPortDef_ip;
 
@@ -325,7 +314,7 @@
     pPortDef_ip->nBufferCountActual                 = 5; //NBAMRENC_NUM_INPUT_BUFFERS;
     pPortDef_ip->nBufferCountMin                    = 5; //NBAMRENC_NUM_INPUT_BUFFERS;
     pPortDef_ip->nBufferSize                        = NBAMRENC_INPUT_FRAME_SIZE;
-    pPortDef_ip->nBufferAlignment                   = EXTRA_BYTES;
+    pPortDef_ip->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
     pPortDef_ip->bEnabled                           = OMX_TRUE;
     pPortDef_ip->bPopulated                         = OMX_FALSE;
     pPortDef_ip->eDomain                            = OMX_PortDomainAudio;
@@ -335,7 +324,7 @@
     pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE;
 
     /* Set output port defaults */
-    NBAMRENC_OMX_MALLOC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
     OMX_NBCONF_INIT_STRUCT(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
     pComponentPrivate->pPortDef[NBAMRENC_OUTPUT_PORT] = pPortDef_op;
 
@@ -344,7 +333,7 @@
     pPortDef_op->nBufferCountMin                    = 9; //NBAMRENC_NUM_OUTPUT_BUFFERS;
     pPortDef_op->nBufferCountActual                 = 9; //NBAMRENC_NUM_OUTPUT_BUFFERS;
     pPortDef_op->nBufferSize                        = 320; //NBAMRENC_OUTPUT_FRAME_SIZE;
-    pPortDef_ip->nBufferAlignment                   = EXTRA_BYTES;
+    pPortDef_ip->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
     pPortDef_op->bEnabled                           = OMX_TRUE;
     pPortDef_op->bPopulated                         = OMX_FALSE;
     pPortDef_op->eDomain                            = OMX_PortDomainAudio;
@@ -353,7 +342,7 @@
     pPortDef_op->format.audio.pNativeRender         = NULL;
     pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
 
-    NBAMRENC_OMX_MALLOC(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     OMX_NBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     /* Set input port format defaults */
     pPortFormat = pComponentPrivate->pCompPort[NBAMRENC_INPUT_PORT]->pPortFormat;
@@ -380,7 +369,7 @@
     amr_op->eAMRFrameFormat =OMX_AUDIO_AMRFrameFormatConformance;
 
 
-    NBAMRENC_OMX_MALLOC(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     OMX_NBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     /* Set output port format defaults */
     pPortFormat = pComponentPrivate->pCompPort[NBAMRENC_OUTPUT_PORT]->pPortFormat;
@@ -484,7 +473,7 @@
     pComponentPrivate->ProcessingInputBuf = 0;
     pComponentPrivate->ProcessingOutputBuf = 0;
 
-    NBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING),OMX_STRING);
+    OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING),OMX_STRING);
 
     /* Initialize device string to the default value */
     strcpy((char*)pComponentPrivate->sDeviceString,":srcul/codec\0");
@@ -543,6 +532,7 @@
 #endif
 
 #ifndef UNDER_CE
+#ifdef DSP_RENDERING_ON
     /* start Audio Manager to get streamId */
     if((pComponentPrivate->fdwrite=open(FIFO1,O_WRONLY))<0) {
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: [NBAMRE Encoder Component] - failure to open WRITE pipe\n",__LINE__);
@@ -550,10 +540,9 @@
 
     if((pComponentPrivate->fdread=open(FIFO2,O_RDONLY))<0) {
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: [NBAMRE Encoder Component] - failure to open READ pipe\n",__LINE__);
-    }
-
+    }    
 #endif
-
+#endif
    if(pthread_mutex_init(&pComponentPrivate->mutexStateChangeRequest, NULL)) {
        return OMX_ErrorUndefined;
    }
@@ -811,8 +800,10 @@
               return OMX_ErrorUndefined;
            }
         }
-        return OMX_ErrorInsufficientResources;
+        eError = OMX_ErrorInsufficientResources;
+        goto EXIT;
     }
+
 #ifdef DSP_RENDERING_ON
 
 
@@ -905,7 +896,10 @@
 #endif
     switch(nParamIndex){
         case OMX_IndexParamAudioInit:
-
+            if (pComponentPrivate->sPortParam == NULL) {
+                eError = OMX_ErrorBadParameter;
+		break;
+	    }
             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: GetParameter OMX_IndexParamAudioInit \n",__LINE__);
             memcpy(ComponentParameterStructure, pComponentPrivate->sPortParam, sizeof(OMX_PORT_PARAM_TYPE));
             break;
@@ -957,6 +951,10 @@
             break;
 
         case OMX_IndexParamAudioAmr:
+            if (pComponentPrivate->amrParams == NULL) {
+                eError = OMX_ErrorBadParameter;
+	        break;
+	    }
             memcpy(ComponentParameterStructure, pComponentPrivate->amrParams, sizeof(OMX_AUDIO_PARAM_AMRTYPE));
             switch (((OMX_AUDIO_PARAM_AMRTYPE *)(ComponentParameterStructure))->eAMRBandMode)
             {
@@ -991,11 +989,19 @@
             break;
 
       case OMX_IndexParamPriorityMgmt:
+            if (pComponentPrivate->sPriorityMgmt == NULL) {
+                eError = OMX_ErrorBadParameter;
+	        break;
+	    }
             OMX_PRDSP2(pComponentPrivate->dbg, "%d :: GetParameter OMX_IndexParamPriorityMgmt \n",__LINE__);
             memcpy(ComponentParameterStructure, pComponentPrivate->sPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
             break;
 
       case OMX_IndexParamAudioPcm:
+          if (pComponentPrivate->pcmParams == NULL) {
+              eError = OMX_ErrorBadParameter;
+	      break;
+	  }
           memcpy(ComponentParameterStructure, pComponentPrivate->pcmParams, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
           break;
 
@@ -1115,15 +1121,7 @@
         case OMX_IndexParamAudioAmr:
 
                 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: SetParameter OMX_IndexParamAudioAmr \n",__LINE__);
-
-                // 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;
-
+                pCompAmrParam = (OMX_AUDIO_PARAM_AMRTYPE *)pCompParam;
                 if(pCompAmrParam->nPortIndex == 0) {         /* 0 means Input port */
                     memcpy(((AMRENC_COMPONENT_PRIVATE*)
                             pHandle->pComponentPrivate)->pcmParams, pCompAmrParam, sizeof(OMX_AUDIO_PARAM_AMRTYPE));
@@ -1167,6 +1165,10 @@
                                   OMX_PRDSP2(pComponentPrivate->dbg, "%d :: SetParameter OMX_IndexParamAudioAmr:: pCompAmrParam->eAMRBandMode =DEFAULT!! SN_AUDIO_BR122 \n",__LINE__);
                                   break;
                     }
+		    if (((AMRENC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate)->amrParams == NULL) {
+                        eError = OMX_ErrorBadParameter;
+			goto EXIT;
+		    }
                     memcpy(((AMRENC_COMPONENT_PRIVATE *)
                             pHandle->pComponentPrivate)->amrParams, pCompAmrParam, sizeof(OMX_AUDIO_PARAM_AMRTYPE));
                     if (pCompAmrParam->eAMRFrameFormat == OMX_AUDIO_AMRFrameFormatConformance) {
@@ -1212,11 +1214,19 @@
             break;
             
         case OMX_IndexParamPriorityMgmt:
+	        if (pComponentPrivate->sPriorityMgmt == NULL) {
+                    eError = OMX_ErrorBadParameter;
+		    break;
+		}
                 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: SetParameter OMX_IndexParamPriorityMgmt \n",__LINE__);
                 memcpy(pComponentPrivate->sPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
             break;
 
         case OMX_IndexParamAudioInit:
+	        if (pComponentPrivate->sPortParam == NULL) {
+                    eError = OMX_ErrorBadParameter;
+		    break;
+		}
                 OMX_PRDSP2(pComponentPrivate->dbg, "%d :: SetParameter OMX_IndexParamAudioInit \n",__LINE__);
                 memcpy(pComponentPrivate->sPortParam, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
             break;
@@ -1231,7 +1241,7 @@
         break;
 
         case OMX_IndexParamAudioPcm:
-            if(pCompParam){
+            if(pCompParam && (pComponentPrivate->pcmParams)){
                  amr_ip = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
                  memcpy(pComponentPrivate->pcmParams, amr_ip, sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
             }
@@ -1294,11 +1304,7 @@
                          (AMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 
     TI_OMX_STREAM_INFO *streamInfo;
-    NBAMRENC_OMX_MALLOC(streamInfo, TI_OMX_STREAM_INFO);
-    if(streamInfo == NULL){
-        eError = OMX_ErrorBadParameter;
-        goto EXIT;
-    }
+    OMX_MALLOC_GENERIC(streamInfo, TI_OMX_STREAM_INFO);
 #ifdef _ERROR_PROPAGATION__
     if (pComponentPrivate->curState == OMX_StateInvalid){
         eError = OMX_ErrorInvalidState;
@@ -1313,8 +1319,8 @@
     OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
     }
 
-    OMX_NBMEMFREE_STRUCT(streamInfo);
 EXIT:
+    OMX_MEMFREE_STRUCT(streamInfo);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting GetConfig. Returning = 0x%x\n",__LINE__,eError);
     return eError;
 }
@@ -1336,10 +1342,9 @@
                                 OMX_PTR ComponentConfigStructure)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    AMRENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
     TI_OMX_DSP_DEFINITION *pTiDspDefinition;
-    AMRENC_COMPONENT_PRIVATE *pComponentPrivate =
-                         (AMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_S16 *customFlag = NULL;      
     
     TI_OMX_DATAPATH dataPath;                   
@@ -1348,12 +1353,14 @@
     AM_COMMANDDATATYPE cmd_data;
 #endif    
                          
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Entering SetConfig\n", __LINE__);
+    AMRENC_DPRINT("%d :: Entering SetConfig\n", __LINE__);
     if (pHandle == NULL) {
-        OMX_ERROR4(pComponentPrivate->dbg, "%d :: Invalid HANDLE OMX_ErrorBadParameter \n",__LINE__);
+	AMRENC_DPRINT("%d :: Invalid HANDLE OMX_ErrorBadParameter \n", __LINE__);
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
+
+    pComponentPrivate = (AMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 #ifdef _ERROR_PROPAGATION__
     if (pComponentPrivate->curState == OMX_StateInvalid){
         eError = OMX_ErrorInvalidState;
@@ -1433,8 +1440,10 @@
         break;
     }
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting SetConfig\n", __LINE__);
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n",__LINE__,eError);
+    if (pComponentPrivate != NULL) {
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting SetConfig\n", __LINE__);
+	OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning = 0x%x\n", __LINE__, eError);
+    }
     return eError;
 }
 
@@ -1800,18 +1809,14 @@
 
     pthread_mutex_destroy(&pComponentPrivate->mutexStateChangeRequest);
     pthread_cond_destroy(&pComponentPrivate->StateChangeCondition);
-
 #ifdef __PERF_INSTRUMENTATION__
     PERF_Boundary(pComponentPrivate->pPERF,
                   PERF_BoundaryComplete | PERF_BoundaryCleanup);
     PERF_Done(pComponentPrivate->pPERF);
 #endif
 
-    if (pComponentPrivate->sDeviceString != NULL) {
-        newfree(pComponentPrivate->sDeviceString);
-    }
-
-    OMX_NBMEMFREE_STRUCT(pComponentPrivate);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
+    OMX_MEMFREE_STRUCT(pComponentPrivate);
 
 EXIT:
     OMXDBG_PRINT(stderr, PRINT, 1, 0, "%d :: Exiting ComponentDeInit Returning 0x%x\n", __LINE__, eError);
@@ -1900,21 +1905,10 @@
         break;
     }
 
-    NBAMRENC_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
 
-    NBAMRENC_OMX_MALLOC_SIZE(pBufferHeader->pBuffer, nSizeBytes + 256,OMX_U8);
+    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes, OMX_U8);
     
-    if (pBufferHeader->pBuffer == NULL) {
-        /* Free previously allocated memory before bailing */
-        if (pBufferHeader) {
-            newfree(pBufferHeader);
-            pBufferHeader = NULL;
-        }
-        eError = OMX_ErrorInsufficientResources;
-        goto EXIT;
-    }
-    pBufferHeader->pBuffer += 128;
-            
     if (nPortIndex == NBAMRENC_INPUT_PORT) {        
         pBufferHeader->nInputPortIndex = nPortIndex;
         pBufferHeader->nOutputPortIndex = -1;
@@ -1932,7 +1926,7 @@
         pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
         pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
         pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 1;
-        NBAMRENC_OMX_MALLOC(pBufferHeader->pOutputPortPrivate, NBAMRENC_BUFDATA);
+        OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate, NBAMRENC_BUFDATA);
 
         if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
             pPortDef->bPopulated = OMX_TRUE;
@@ -2013,7 +2007,6 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     AMRENC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
     OMX_BUFFERHEADERTYPE* buff;
-    OMX_U8* tempBuff;
     int i = 0;
     int inputIndex = -1;
     int outputIndex = -1;
@@ -2060,10 +2053,7 @@
 
     if (inputIndex != -1) {
         if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
-            tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
-            if (tempBuff != 0)
-               tempBuff -= 128;
-            OMX_NBMEMFREE_STRUCT(tempBuff);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
         }
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -2073,7 +2063,7 @@
                        PERF_ModuleMemory );
 #endif
         
-        OMX_NBMEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
 
             pComponentPrivate->pInputBufferList->numBuffers--;
         if (pComponentPrivate->pInputBufferList->numBuffers <
@@ -2096,10 +2086,7 @@
     }
     else if (outputIndex != -1) {
          if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
-            tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
-            if (tempBuff != 0)
-               tempBuff -= 128;
-            OMX_NBMEMFREE_STRUCT(tempBuff);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, OMX_U8);
         }
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -2109,8 +2096,8 @@
                        PERF_ModuleMemory );
 #endif
 
-        OMX_NBMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
-        OMX_NBMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
 
         pComponentPrivate->pOutputBufferList->numBuffers--;
         if (pComponentPrivate->pOutputBufferList->numBuffers <
@@ -2219,7 +2206,7 @@
         goto EXIT;
     }
 
-    NBAMRENC_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
     
     if (nPortIndex == NBAMRENC_OUTPUT_PORT) {
         pBufferHeader->nInputPortIndex = -1;
@@ -2227,7 +2214,7 @@
         pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
         pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
         pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
-        NBAMRENC_OMX_MALLOC(pBufferHeader->pOutputPortPrivate, NBAMRENC_BUFDATA);
+        OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate, NBAMRENC_BUFDATA);
 
         if (pComponentPrivate->pOutputBufferList->numBuffers == pPortDef->nBufferCountActual) {
             pPortDef->bPopulated = OMX_TRUE;
@@ -2401,8 +2388,13 @@
     pComponentPrivate = (AMRENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
     if(nIndex == 0){
-      memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
-      OMX_PRINT1(pComponentPrivate->dbg, "::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+      if (cRole == NULL) {
+          eError = OMX_ErrorBadParameter;
+      }
+      else {
+          memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); 
+          OMX_PRINT1(pComponentPrivate->dbg, "::::In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+      }
     }
     else {
       eError = OMX_ErrorNoMore;
diff --git a/omx/audio/src/openmax_il/wbamr_dec/inc/OMX_WbAmrDec_Utils.h b/omx/audio/src/openmax_il/wbamr_dec/inc/OMX_WbAmrDec_Utils.h
index f7d1122..ffdace0 100644
--- a/omx/audio/src/openmax_il/wbamr_dec/inc/OMX_WbAmrDec_Utils.h
+++ b/omx/audio/src/openmax_il/wbamr_dec/inc/OMX_WbAmrDec_Utils.h
@@ -24,8 +24,9 @@
 #include <OMX_Component.h>
 #include "OMX_TI_Common.h"
 #include "OMX_WbAmrDecoder.h"
-/* #include <ResourceManagerProxyAPI.h> */
-
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 
 
 /* ======================================================================= */
@@ -138,7 +139,6 @@
 #define WBAMR_DEC_DLL_NAME "wbamrdec_sn.dll64P"
 #endif
 
-
 /* ===========================================================  */
 /**
 *  WBAMR_DEC_StartComponentThread()  Starts component thread
@@ -367,12 +367,16 @@
 /*================================================================== */
 OMX_U32 WBAMR_DEC_IsValid(WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U8 *pBuffer, OMX_DIRTYPE eDir) ;
 
-/* void WBAMRDEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData); */
+#ifdef RESOURCE_MANAGER_ENABLED
+void WBAMRDEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
 
 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle, int size, void* pArmPtr, DMM_BUFFER_OBJ* pDmmBuf, struct OMX_TI_Debug dbg);
 
 OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg);
 
+void WBAMRDEC_HandleUSNError (WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
+
 #ifdef UNDER_CE
 	#ifndef _OMX_EVENT_
 		#define _OMX_EVENT_
diff --git a/omx/audio/src/openmax_il/wbamr_dec/inc/OMX_WbAmrDecoder.h b/omx/audio/src/openmax_il/wbamr_dec/inc/OMX_WbAmrDecoder.h
index a7db97a..c933df5 100644
--- a/omx/audio/src/openmax_il/wbamr_dec/inc/OMX_WbAmrDecoder.h
+++ b/omx/audio/src/openmax_il/wbamr_dec/inc/OMX_WbAmrDecoder.h
@@ -55,7 +55,10 @@
 #ifdef DSP_RENDERING_ON
 #include <AudioManagerAPI.h>
 #endif
-/* #include <ResourceManagerProxyAPI.h> */
+ 
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 #endif
 
 #ifndef ANDROID
@@ -173,6 +176,18 @@
  */
 /* ======================================================================= */
 #define IP_WBAMRDEC_BUFFERSIZE 8192
+/* ======================================================================= */
+/**
+ * @def    NUM_MIME_BYTES_ARRAY               amrMimeBytes array size
+ */
+/* ======================================================================= */
+#define NUM_MIME_BYTES_ARRAY 16
+/* ======================================================================= */
+/**
+ * @def    NUM_IF2_BYTES_ARRAY                amrIF2Bytes array size
+ */
+/* ======================================================================= */
+#define NUM_IF2_BYTES_ARRAY 16
 
 /* ======================================================================= */
 /**
@@ -240,6 +255,13 @@
     OMX_IndexCustomDebug
 }OMX_INDEXAUDIOTYPE_WBAMRDEC;
 
+/* ======================================================================= */
+/**
+ * pthread variable to indicate OMX returned all buffers to app 
+ */
+/* ======================================================================= */
+pthread_mutex_t bufferReturned_mutex; 
+pthread_cond_t bufferReturned_condition; 
 
 /* ======================================================================= */
 /** WBAMR_DEC_StreamType  Stream types
@@ -511,7 +533,7 @@
     OMX_U32 lcml_nOpBuf;
 
     OMX_U32 app_nBuf;
-    OMX_U32 wbamrIf2Bytes[16];                        /*Array With IF2 Lenght Information*/
+    OMX_U32 wbamrIf2Bytes[NUM_IF2_BYTES_ARRAY];                        /*Array With IF2 Lenght Information*/
     OMX_U32 lcml_nCntIp;
     OMX_U32 lcml_nCntOpReceived;
     OMX_U32 num_Reclaimed_Op_Buff;
@@ -538,7 +560,7 @@
     WBAMR_DEC_BUFFERLIST *pOutputBufferList;
     LCML_STRMATTR *strmAttr;
     OMX_U32 nVersion;
-    OMX_U32 wbamrMimeBytes[16];
+    OMX_U32 wbamrMimeBytes[NUM_MIME_BYTES_ARRAY];
     OMX_U32 nHoldLength;
     OMX_U8* pHoldBuffer;
     OMX_U32 bLcmlHandleOpened;
@@ -632,9 +654,11 @@
     
     /** Pointer to port priority management structure */
     OMX_PRIORITYMGMTTYPE* pPriorityMgmt;
-    
-/*  RMPROXY_CALLBACKTYPE rmproxyCallback; */
-    
+
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
     OMX_BOOL bPreempted;
     OMX_BOOL bFrameLost;
 
@@ -647,4 +671,17 @@
 
 } WBAMR_DEC_COMPONENT_PRIVATE;
 
+/*=======================================================================*/
+/*! @fn SignalIfAllBuffersAreReturned 
+
+ * @brief Sends pthread signal to indicate OMX has returned all buffers to app 
+
+ * @param  none 
+
+ * @Return void 
+
+ */
+/*=======================================================================*/
+void SignalIfAllBuffersAreReturned(WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate);
+
 #endif /* OMX_WBAMR_DECODER_H */
diff --git a/omx/audio/src/openmax_il/wbamr_dec/src/Android.mk b/omx/audio/src/openmax_il/wbamr_dec/src/Android.mk
index 06aafd7..3c46117 100644
--- a/omx/audio/src/openmax_il/wbamr_dec/src/Android.mk
+++ b/omx/audio/src/openmax_il/wbamr_dec/src/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_AMRWB_DECODER),1)
+ifeq ($(BUILD_AMRWB_DECODER),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -27,4 +27,4 @@
 LOCAL_MODULE:= libOMX.TI.WBAMR.decode

 

 include $(BUILD_SHARED_LIBRARY)
-endif
+endif

diff --git a/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDec_ComponentThread.c b/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDec_ComponentThread.c
index 41d4827..6f72a80 100644
--- a/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDec_ComponentThread.c
+++ b/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDec_ComponentThread.c
@@ -152,7 +152,7 @@
                     goto EXIT;
                 }
             }
-            OMX_ERROR2(pComponentPrivate->dbg,"Component Time Out !!!!!!!!!!!! \n");
+            OMX_PRINT2(pComponentPrivate->dbg,"Component Time Out !!!!!!!!!!!! \n");
         } else if (-1 == status) {
             OMX_ERROR4(pComponentPrivate->dbg, "Error in Select\n");
             pComponentPrivate->cbInfo.EventHandler (pHandle,
@@ -162,7 +162,6 @@
                                                     OMX_TI_ErrorSevere,
                                                     "Error from Component Thread in select");
             eError = OMX_ErrorInsufficientResources;
-            break;
 
         } else if (FD_ISSET (pComponentPrivate->dataPipe[0], &rfds)) {
             OMX_PRCOMM2(pComponentPrivate->dbg, "DATA pipe is set in Component Thread\n");
diff --git a/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDec_Utils.c b/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDec_Utils.c
index de24cf5..9bdb80b 100644
--- a/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDec_Utils.c
+++ b/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDec_Utils.c
@@ -36,6 +36,17 @@
 * @rev  0.1
 */
 /* ----------------------------------------------------------------------------
+*!
+*! Revision History
+*! ===================================
+*! 10-Sept-2005 mf:  Initial Version. Change required per OMAPSWxxxxxxxxx
+*! to provide _________________.
+*!
+*!
+*! 10-Sept-2005 mf:
+*! This is newest file
+* =========================================================================== */
+
 
 /* ------compilation control switches -------------------------*/
 /****************************************************************
@@ -72,22 +83,6 @@
 #include "usn.h"
 #include "LCML_DspCodec.h"
 
-#ifdef RESOURCE_MANAGER_ENABLED
-#include <ResourceManagerProxyAPI.h>
-#endif
-
-#ifdef WBAMRDEC_DEBUGMEM
-extern void * mymalloc(int line, char *s, int size);
-int myfree(void *dp, int line, char *s);
-
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
-
 /* ========================================================================== */
 /**
 * @WBAMR_DEC_Fill_LCMLInitParams () This function is used by the component thread to
@@ -118,7 +113,6 @@
     OMX_BUFFERHEADERTYPE *pTemp;
     int size_lcml;
     LCML_STRMATTR *strmAttr = NULL;
-    char *pTemp_char = NULL;
     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
     WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate;
     LCML_WBAMR_DEC_BUFHEADERTYPE *pTemp_lcml;
@@ -188,7 +182,6 @@
         OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
 
         pComponentPrivate->strmAttr = strmAttr;
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[ALLOC] %p\n",strmAttr);
 
         strmAttr->uSegid = 0;
         strmAttr->uAlignment = 0;
@@ -304,15 +297,14 @@
         pTemp_lcml->eDir = OMX_DirInput;
 
         OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
-                        sizeof(WBAMRDEC_ParamStruct),
-                        WBAMRDEC_ParamStruct);
+                                  sizeof(WBAMRDEC_ParamStruct),
+                                  WBAMRDEC_ParamStruct);
         pTemp_lcml->pBufferParam->usNbFrames =0;
         pTemp_lcml->pBufferParam->pParamElem = NULL;
         pTemp_lcml->pFrameParam = NULL;
 
         OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
-
         /* This means, it is not a last buffer. This flag is to be modified by
          * the application to indicate the last buffer */
         pTemp->nFlags = WBAMR_DEC_NORMAL_BUFFER;
@@ -343,8 +335,8 @@
         pTemp_lcml->pFrameParam = NULL;
 
         OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
-                                 sizeof(WBAMRDEC_ParamStruct),
-                                 WBAMRDEC_ParamStruct);
+                                  sizeof(WBAMRDEC_ParamStruct),
+                                  WBAMRDEC_ParamStruct);
 
         pTemp_lcml->pBufferParam->usNbFrames =0;
         pTemp_lcml->pBufferParam->pParamElem = NULL;
@@ -409,7 +401,7 @@
     pComponentPrivate->app_nBuf = 0;
     pComponentPrivate->num_Reclaimed_Op_Buff = 0;
 
-    /* create the pipe used to send command data to the thread */
+    /* create the pipe used to send buffers to the thread */
     eError = pipe (pComponentPrivate->cmdDataPipe);
     if (eError) {
         eError = OMX_ErrorInsufficientResources;
@@ -513,31 +505,12 @@
         }
 
     }
-    if (pComponentPrivate->pPriorityMgmt != NULL ) {
-        OMX_MEMFREE_STRUCT (pComponentPrivate->pPriorityMgmt);
-    }
-
-    OMX_PRBUFFER1(pComponentPrivate->dbg, "[WBAMR_DEC_FreeCompResources] \n");
-    if (pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]) {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]);
-        OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]);
-     }
-
-    if (pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]) {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]);
-        OMX_MEMFREE_STRUCT (pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]);
-     }
-
-    if (pComponentPrivate->wbamrParams[WBAMR_DEC_INPUT_PORT]!=NULL) {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->wbamrParams[WBAMR_DEC_INPUT_PORT]);
-        OMX_MEMFREE_STRUCT(pComponentPrivate->wbamrParams[WBAMR_DEC_INPUT_PORT]);
-     }
-
-    if (pComponentPrivate->wbamrParams[WBAMR_DEC_OUTPUT_PORT]!=NULL) {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->wbamrParams[WBAMR_DEC_OUTPUT_PORT]);
-        OMX_MEMFREE_STRUCT (pComponentPrivate->wbamrParams[WBAMR_DEC_OUTPUT_PORT]);
-     }
-
+    OMX_MEMFREE_STRUCT (pComponentPrivate->pPriorityMgmt);
+    OMX_MEMFREE_STRUCT (pComponentPrivate->pHoldBuffer);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT (pComponentPrivate->pPortDef[WBAMR_DEC_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->wbamrParams[WBAMR_DEC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT (pComponentPrivate->wbamrParams[WBAMR_DEC_OUTPUT_PORT]);
     pComponentPrivate->bPortDefsAllocated = 0;
 #ifndef UNDER_CE
     OMX_PRDSP1(pComponentPrivate->dbg, "\n\n FreeCompResources: Destroying mutexes.\n\n");
@@ -570,27 +543,21 @@
 
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 nIpBuf = 0;
-    OMX_U8* pParmsTemp;
     OMX_U16 i=0;
-    OMX_U8* pBufParmsTemp;
-    char *pTemp = NULL;
     LCML_DSP_INTERFACE *pLcmlHandle;
     LCML_DSP_INTERFACE *pLcmlHandleAux;
     OMX_PRINT1(pComponentPrivate->dbg, "WBAMR_DEC_CleanupInitParams()\n");
 
+    OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
 
-    if (pComponentPrivate->strmAttr!=NULL) {
-        OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
-    }
-
-    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams,WBAMR_DEC_AudioCodecParams);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, WBAMR_DEC_AudioCodecParams);
 
     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[WBAMR_DEC_INPUT_PORT];
     for(i=0; i<nIpBuf; i++) {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pTemp_lcml->pFrameParam);
+
         if(pTemp_lcml->pFrameParam!=NULL){
-            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam,WAMRDEC_FrameStruct);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, WAMRDEC_FrameStruct);
             pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
             pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
             OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc,
@@ -598,14 +565,8 @@
                          pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
         }
 
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pTemp_lcml->pBufferParam);
-        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam,WBAMRDEC_ParamStruct);
-
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pTemp_lcml->pDmmBuf);
-
-        if(pTemp_lcml->pDmmBuf!=NULL){
-            OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
-        }
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, WBAMRDEC_ParamStruct);
+        OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
         pTemp_lcml++;
     }
 
@@ -613,9 +574,8 @@
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[WBAMR_DEC_OUTPUT_PORT];
     for(i=0; i<pComponentPrivate->nRuntimeOutputBuffers; i++){
 
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pTemp_lcml->pFrameParam);
         if(pTemp_lcml->pFrameParam!=NULL){
-            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam,WAMRDEC_FrameStruct);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, WAMRDEC_FrameStruct);
             pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
             pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
             OMX_DmmUnMap(pLcmlHandleAux->dspCodec->hProc,
@@ -623,21 +583,12 @@
                          pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
         }
 
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pTemp_lcml->pBufferParam);
-        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam,WBAMRDEC_ParamStruct);
-
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pTemp_lcml->pDmmBuf);
-        if(pTemp_lcml->pDmmBuf!=NULL){
-            OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
-         }
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, WBAMRDEC_ParamStruct);
+        OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
         pTemp_lcml++;
     }
 
-
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->pLcmlBufHeader[WBAMR_DEC_INPUT_PORT]);
     OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[WBAMR_DEC_INPUT_PORT]);
-
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->pLcmlBufHeader[WBAMR_DEC_OUTPUT_PORT]);
     OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[WBAMR_DEC_OUTPUT_PORT]);
     return eError;
 }
@@ -708,7 +659,6 @@
     OMX_STATETYPE commandedState;
     OMX_U32 commandData;
     OMX_HANDLETYPE pLcmlHandle = pComponentPrivate->pLcmlHandle;
-    OMX_U8* pParmsTemp;
 
     OMX_U16 i;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
@@ -981,7 +931,6 @@
 
                     OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams, sizeof(WBAMR_DEC_AudioCodecParams),WBAMR_DEC_AudioCodecParams);
                     pParams = pComponentPrivate->pParams;
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "[ALLOC] %p\n",pParams);
 
                     pParams->iAudioFormat = 1;
                     pParams->iSamplingRate = 16000;
@@ -1016,6 +965,7 @@
                 OMX_PRDSP2(pComponentPrivate->dbg, "AMRDEC: About to set bIsStopping bit\n");
 
                 OMX_PRDSP2(pComponentPrivate->dbg, "About to call LCML_ControlCodec(STOP)\n");
+
                 if (pComponentPrivate->codecStop_waitingsignal == 0){ 
                     pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);    
                 }
@@ -1039,10 +989,7 @@
                     goto EXIT;
                 }
                 pComponentPrivate->bStopSent=1;
-
-                if (pComponentPrivate->pHoldBuffer) {
-                    OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
-                }
+                OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
                 pComponentPrivate->nHoldLength = 0;
             }
 
@@ -1079,7 +1026,7 @@
 #ifdef RESOURCE_MANAGER_ENABLED
                 rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_WBAMR_Decoder_COMPONENT, OMX_StateIdle, 3456, NULL);
 #endif
-                OMX_ERROR2(pComponentPrivate->dbg, "OMX_AmrDec_Utils.c :: The component is stopped\n");
+                OMX_PRINT2(pComponentPrivate->dbg, "OMX_AmrDec_Utils.c :: The component is stopped\n");
                 pComponentPrivate->cbInfo.EventHandler (
                                                         pHandle,pHandle->pApplicationPrivate,
                                                         OMX_EventCmdComplete,OMX_CommandStateSet,pComponentPrivate->curState,
@@ -1114,6 +1061,7 @@
             else if (pComponentPrivate->curState == OMX_StateIdle) {
                 OMX_PRINT2(pComponentPrivate->dbg, "Comp: OMX_AmrDecUtils.c\n");
 
+                pComponentPrivate->nFillThisBufferCount = 0;
                 pComponentPrivate->nFillBufferDoneCount = 0;
                 pComponentPrivate->bStopSent=0;
 
@@ -1366,6 +1314,14 @@
                                                        NULL);
                 goto EXIT;
             }
+#ifdef RESOURCE_MANAGER_ENABLED
+            rm_error = RMProxy_NewSendCommand(pHandle,
+                                              RMProxy_StateSet,
+                                              OMX_WBAMR_Decoder_COMPONENT,
+                                              OMX_StatePause,
+                                              3456,
+                                              NULL);
+#endif
 
             OMX_PRINT2(pComponentPrivate->dbg, "Comp: OMX_AmrDecUtils.c\n");
             break;
@@ -1481,6 +1437,7 @@
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pComponentPrivate->pInputBufferList->pBufHdr[i]
                                                                    );
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                 }
             }
@@ -1490,6 +1447,7 @@
                 if (pComponentPrivate->curState == OMX_StateExecuting) {
                     pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
                     OMX_PRINT1(pComponentPrivate->dbg, "OMX_WBAmrDec_Utils.c :: Calling LCML_ControlCodec()\n");
+
                 if (pComponentPrivate->codecStop_waitingsignal == 0){ 
                     pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);    
                 }
@@ -1730,6 +1688,14 @@
  EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting WBAMR_DEC_HandleCommand Function\n");
     OMX_PRINT1(pComponentPrivate->dbg, "Returning %d\n",eError);
+    if (eError != OMX_ErrorNone && eError != WBAMR_DEC_EXIT_COMPONENT_THRD ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -1764,7 +1730,6 @@
     OMX_U16 i;
     OMX_U32 holdBufferSize;
     OMX_U8 nFrames =0;
-    OMX_U8 *pBufParmsTemp;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
 
     OMX_U32 nFilledLenLocal;
@@ -1772,7 +1737,6 @@
     OMX_U16 offset = 0;
 
     WBAMR_DEC_AudioCodecParams *pParams;
-    OMX_U8 *pParmsTemp;
     OMX_STRING p = "damedesuStr";
     DSP_STATUS status;
     OMX_BOOL isFrameParamChanged=OMX_FALSE;
@@ -1789,23 +1753,21 @@
         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( pBufHeader->pBuffer == NULL) {
+        eError = OMX_ErrorBadParameter;
+        goto EXIT;
     }
     if (eDir == OMX_DirInput) {
         pComponentPrivate->nUnhandledEmptyThisBuffers--;
+        if (pComponentPrivate->curState == OMX_StateIdle){
+            pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       pBufHeader);
+            pComponentPrivate->nEmptyBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return input buffers\n", __LINE__, __FUNCTION__);
+            goto EXIT;
+        }
         pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
         if ( pBufHeader->nFilledLen > 0)
         {
@@ -1862,6 +1824,7 @@
                             nFrames++;
                         }
                         free(TOCframetype);
+			 TOCframetype = NULL;
                     }
                     frameType = 0;
                     nFrames = 0;
@@ -1872,10 +1835,23 @@
                         index = (frameType >> 3) & 0x0F;
                         if(nFrames)
                         { /*The first frame has no need to be moved*/
+                            if (((nFrames*INPUT_WBAMRDEC_BUFFER_SIZE_MIME) + pBufHeader->nFilledLen) 
+			       > pBufHeader->nAllocLen) {
+                               OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_WbAmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
+                               goto EXIT;
+                           }
                             memmove(pBufHeader->pBuffer + (nFrames*INPUT_WBAMRDEC_BUFFER_SIZE_MIME),
                                     pBufHeader->pBuffer + i,
                                     pBufHeader->nFilledLen);
                         }
+			if ((index >= NUM_MIME_BYTES_ARRAY) || 
+			   ((index < NUM_MIME_BYTES_ARRAY) && 
+			   (pComponentPrivate->wbamrMimeBytes[index] == 0))) {
+                           OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_WbAmrDec_Utils.c :: no more frames index=%d", __LINE__, (int)index);
+                           if (index < NUM_MIME_BYTES_ARRAY)
+                               OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_WbAmrDec_Utils.c :: no more frames mimebytes=%d", __LINE__, (int) pComponentPrivate->wbamrMimeBytes[index]);
+                               break;
+                        }
                         pBufHeader->nFilledLen -= pComponentPrivate->wbamrMimeBytes[index];
                         i = (nFrames*INPUT_WBAMRDEC_BUFFER_SIZE_MIME) + (OMX_U16)pComponentPrivate->wbamrMimeBytes[index];
                         nFrames++;
@@ -1894,10 +1870,23 @@
                         index = (frameType >> 4) & 0x0F;
                         if (nFrames)
                         {
+                            if (((nFrames*INPUT_WBAMRDEC_BUFFER_SIZE_IF2) + pBufHeader->nFilledLen) 
+			       > pBufHeader->nAllocLen) {
+                               OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_WbAmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
+                               goto EXIT;
+                            }
                             memmove(pBufHeader->pBuffer + (nFrames *INPUT_WBAMRDEC_BUFFER_SIZE_IF2),
                                     pBufHeader->pBuffer + i,
                                     pBufHeader->nFilledLen);
                         }
+                        if ((index >= NUM_IF2_BYTES_ARRAY) || 
+			   ((index < NUM_IF2_BYTES_ARRAY) && 
+			   (pComponentPrivate->wbamrIf2Bytes[index] == 0))) {
+                           OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_WbAmrDec_Utils.c :: no more frames index=%d", __LINE__, (int)index);
+                           if (index < NUM_IF2_BYTES_ARRAY)
+                               OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: OMX_WbAmrDec_Utils.c :: no more frames mimebytes=%d", __LINE__, (int)pComponentPrivate->wbamrIf2Bytes[index]);
+                               break;
+                        }
                         pBufHeader->nFilledLen -= pComponentPrivate->wbamrIf2Bytes[index];
                         i = (nFrames *INPUT_WBAMRDEC_BUFFER_SIZE_IF2) + (OMX_U16)pComponentPrivate->wbamrIf2Bytes[index];
                         nFrames++;
@@ -1922,6 +1911,13 @@
                         }
                         /* Copy the extra data into pHoldBuffer. Size will be nHoldLength. */
                         pExtraData = pBufHeader->pBuffer + INPUT_WBAMRDEC_BUFFER_SIZE*nFrames;
+			/* check the pHoldBuffer boundary before copying */
+			if (pComponentPrivate->nHoldLength >
+			   (INPUT_WBAMRDEC_BUFFER_SIZE * (pComponentPrivate->pInputBufferList->numBuffers + 3)))
+			   {
+                               OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_WbAmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
+                               goto EXIT;
+			   }
                         memcpy (pComponentPrivate->pHoldBuffer, pExtraData, pComponentPrivate->nHoldLength);
                     }
                 }
@@ -1954,6 +1950,7 @@
                             pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
                                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                                        pBufHeader);
+                            SignalIfAllBuffersAreReturned(pComponentPrivate);
                         }
                         else {
                             pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
@@ -1990,13 +1987,22 @@
                 nFrames = (OMX_U8)(pComponentPrivate->nHoldLength / frameLength);
                 if ( nFrames >= 1 )  {
                     /* Copy the data from pComponentPrivate->pHoldBuffer to pBufHeader->pBuffer*/
+		    /* check the pBufHeader boundery before copying */
+		    if ((nFrames*frameLength) > pBufHeader->nAllocLen)
+		    {
+                        OMX_ERROR4(pComponentPrivate->dbg, "%d :: OMX_WbAmrDec_Utils.c :: ERROR: Trying to write beyond buffer boundaries!",__LINE__);
+			goto EXIT;
+		    }
                     memcpy(pBufHeader->pBuffer,pComponentPrivate->pHoldBuffer,nFrames*frameLength);
                     pBufHeader->nFilledLen = nFrames*frameLength;
                     /* Now the pHoldBuffer has pBufHeader->nFilledLen fewer bytes, update nHoldLength*/
                     pComponentPrivate->nHoldLength = pComponentPrivate->nHoldLength - pBufHeader->nFilledLen;
                     /* Shift the remaining bytes to the beginning of the pHoldBuffer */
                     pExtraData = pComponentPrivate->pHoldBuffer + pBufHeader->nFilledLen;
-                    memcpy(pComponentPrivate->pHoldBuffer,pExtraData,pComponentPrivate->nHoldLength);
+		    if (pComponentPrivate->nHoldLength < pBufHeader->nFilledLen)
+                        memcpy(pComponentPrivate->pHoldBuffer,pExtraData,pComponentPrivate->nHoldLength);
+		    else
+                        memmove(pComponentPrivate->pHoldBuffer,pExtraData,pComponentPrivate->nHoldLength);
                     /* Clear the rest of the data from the pHoldBuffer */
                     /*pExtraData = pComponentPrivate->pHoldBuffer + pComponentPrivate->nHoldLength;*/
                     /*mset(pExtraData,0,holdBufferSize - pComponentPrivate->nHoldLength);*/
@@ -2015,6 +2021,7 @@
                                                                    pComponentPrivate->pHandle,
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pBufHeader);
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                         goto EXIT;
                     }
                     else {
@@ -2032,7 +2039,8 @@
                 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
                                                            pComponentPrivate->pHandle->pApplicationPrivate,
                                                            pComponentPrivate->pInputBufferList->pBufHdr[0]);
-                goto EXIT;
+                SignalIfAllBuffersAreReturned(pComponentPrivate);
+               goto EXIT;
             }
             else{
                 nFrames=1;
@@ -2063,17 +2071,15 @@
             phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 
             if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){
-
-                OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam,WAMRDEC_FrameStruct);
-
+                OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam, WAMRDEC_FrameStruct); /*This means that more memory need to be used*/
                 OMX_DmmUnMap(phandle->dspCodec->hProc, /*Unmap DSP memory used*/
                              (void*)pLcmlHdr->pBufferParam->pParamElem,
                              pLcmlHdr->pDmmBuf->pReserved, pComponentPrivate->dbg);
                 pLcmlHdr->pBufferParam->pParamElem = NULL;
             }
-            if(pLcmlHdr->pFrameParam==NULL ){
-                OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam,(sizeof(WAMRDEC_FrameStruct)*nFrames),WAMRDEC_FrameStruct);
 
+            if(pLcmlHdr->pFrameParam==NULL ){
+                OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam, (sizeof(WAMRDEC_FrameStruct)*nFrames),WAMRDEC_FrameStruct);
                 eError = OMX_DmmMap(phandle->dspCodec->hProc,
                                     nFrames*sizeof(WAMRDEC_FrameStruct),
                                     (void*)pLcmlHdr->pFrameParam,
@@ -2126,9 +2132,8 @@
                                                                "AM: No Stream ID Available");
                         goto EXIT;
                     }
-                    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,sizeof(WBAMR_DEC_AudioCodecParams),WBAMR_DEC_AudioCodecParams);
-                    pParams = pComponentPrivate->pParams;
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "[ALLOC] %p\n",pParams);
+                    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams, sizeof(WBAMR_DEC_AudioCodecParams),WBAMR_DEC_AudioCodecParams);
+                    pParams =  pComponentPrivate->pParams;
 
                     pParams->iAudioFormat = 1;
                     pParams->iSamplingRate = 16000;
@@ -2272,6 +2277,21 @@
                 }
             }
         }
+        else
+        {
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "line %d:: No Frames in Buffer, calling EmptyBufferDone\n",__LINE__);
+            pComponentPrivate->nEmptyBufferDoneCount++;
+#ifdef __PERF_INSTRUMENTATION__
+            PERF_SendingFrame(pComponentPrivate->pPERFcomp,
+                                      pBufHeader->pBuffer,
+                                      0,
+                                      PERF_ModuleHLMM);
+#endif
+            pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
+                                                       pComponentPrivate->pHandle->pApplicationPrivate,
+                                                       pBufHeader);
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+        }
 
         if (pComponentPrivate->bFlushInputPortCommandPending) {
             OMX_SendCommand(pComponentPrivate->pHandle,OMX_CommandFlush,0,NULL);
@@ -2285,6 +2305,15 @@
 
         /*******/
         pComponentPrivate->nUnhandledFillThisBuffers--;
+        if (pComponentPrivate->curState == OMX_StateIdle){
+            pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
+                                                      pComponentPrivate->pHandle->pApplicationPrivate,
+                                                      pBufHeader);
+            pComponentPrivate->nFillBufferDoneCount++;
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, ":: %d %s In idle state return output buffers\n", __LINE__, __FUNCTION__);
+            goto EXIT;
+        }
         eError = WBAMR_DEC_GetCorresponding_LCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);
 
         phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
@@ -2300,7 +2329,7 @@
         nFrames = (OMX_U8)(pBufHeader->nAllocLen/OUTPUT_WBAMRDEC_BUFFER_SIZE);
 
         if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){
-            OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam,WAMRDEC_FrameStruct);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam, WAMRDEC_FrameStruct);
             OMX_DmmUnMap(phandle->dspCodec->hProc, /*Unmap DSP memory used*/
                          (void*)pLcmlHdr->pBufferParam->pParamElem,
                          pLcmlHdr->pDmmBuf->pReserved, pComponentPrivate->dbg);
@@ -2308,8 +2337,7 @@
         }
 
         if(pLcmlHdr->pFrameParam==NULL ){
-            OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam,(sizeof(WAMRDEC_FrameStruct)*nFrames),WAMRDEC_FrameStruct);
-
+            OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam, (sizeof(WAMRDEC_FrameStruct)*nFrames),WAMRDEC_FrameStruct);
             eError = OMX_DmmMap(phandle->dspCodec->hProc,
                                 nFrames*sizeof(WAMRDEC_FrameStruct),
                                 (void*)pLcmlHdr->pFrameParam,
@@ -2376,8 +2404,19 @@
     }
 
  EXIT:
+    if (TOCframetype != NULL) {
+	 free(TOCframetype);
+    }
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting from  WBAMR_DEC_HandleDataBuf_FromApp \n");
     OMX_PRINT1(pComponentPrivate->dbg, "Returning error %d\n",eError);
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -2414,7 +2453,7 @@
         if(pBufHeader == pBuf)
         {
             *eDir = OMX_DirInput;
-            OMX_ERROR2(pComponentPrivate->dbg, "WBAMR_DEC_Buffer %p is INPUT BUFFER\n", pBufHeader);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "WBAMR_DEC_Buffer %p is INPUT BUFFER\n", pBufHeader);
             flag = 0;
             goto EXIT;
         }
@@ -2429,7 +2468,7 @@
         if(pBufHeader == pBuf)
         {
             *eDir = OMX_DirOutput;
-            OMX_ERROR2(pComponentPrivate->dbg, "WBAMR_DEC_Buffer %p is OUTPUT BUFFER\n", pBufHeader);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "WBAMR_DEC_Buffer %p is OUTPUT BUFFER\n", pBufHeader);
             flag = 0;
             goto EXIT;
         }
@@ -2570,6 +2609,7 @@
             pComponentPrivate->cbInfo.EmptyBufferDone (pHandle,
                                                        pHandle->pApplicationPrivate,
                                                        pLcmlHdr->buffer);
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
             pComponentPrivate->lcml_nIpBuf--;
             pComponentPrivate->app_nBuf++;
 
@@ -2642,6 +2682,7 @@
             pComponentPrivate->cbInfo.FillBufferDone (pHandle,
                                                       pHandle->pApplicationPrivate,
                                                       pLcmlHdr->buffer);
+            SignalIfAllBuffersAreReturned(pComponentPrivate);
             pComponentPrivate->lcml_nOpBuf--;
             pComponentPrivate->app_nBuf++;
             pComponentPrivate->nFillBufferDoneCount++;
@@ -2660,6 +2701,7 @@
                                                                    pHandle->pApplicationPrivate,
                                                                    pComponentPrivate->pInputBufHdrPending[i]);
                         pComponentPrivate->pInputBufHdrPending[i] = NULL;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                     pComponentPrivate->nNumInputBufPending=0;
                     pComponentPrivate->cbInfo.EventHandler(pHandle,
@@ -2681,6 +2723,8 @@
                                                                   pHandle->pApplicationPrivate,
                                                                   pComponentPrivate->pOutputBufHdrPending[i]);
                         pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+                        pComponentPrivate->nFillBufferDoneCount++;
+                        SignalIfAllBuffersAreReturned(pComponentPrivate);
                     }
                     pComponentPrivate->nNumOutputBufPending=0;
                     pComponentPrivate->cbInfo.EventHandler(pHandle,
@@ -2697,26 +2741,30 @@
         }
     }
     else if(event == EMMCodecProcessingStoped) {
-        for (i = 0; i < pComponentPrivate->nNumInputBufPending; i++) {
+      for (i = 0; i < pComponentPrivate->nNumInputBufPending; i++) {
 		pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
 				pComponentPrivate->pHandle->pApplicationPrivate,
 				pComponentPrivate->pInputBufHdrPending[i]);
 				pComponentPrivate->pInputBufHdrPending[i] = NULL;
+				pComponentPrivate->nEmptyBufferDoneCount++;
+                SignalIfAllBuffersAreReturned(pComponentPrivate);
 	}
 	pComponentPrivate->nNumInputBufPending = 0;
 	for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
 		pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
 			pComponentPrivate->pHandle->pApplicationPrivate,
 			pComponentPrivate->pOutputBufHdrPending[i]);
-		pComponentPrivate->nOutStandingFillDones--;
-		pComponentPrivate->pOutputBufHdrPending[i] = NULL;
+        pComponentPrivate->nFillBufferDoneCount++;
+        SignalIfAllBuffersAreReturned(pComponentPrivate);
+ 	    pComponentPrivate->nOutStandingFillDones--;
+        pComponentPrivate->pOutputBufHdrPending[i] = NULL;
 	}
 	pComponentPrivate->nNumOutputBufPending=0;
         pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);
         if(pComponentPrivate->codecStop_waitingsignal == 0){
             pComponentPrivate->codecStop_waitingsignal = 1;             
             pthread_cond_signal(&pComponentPrivate->codecStop_threshold);
-            OMX_ERROR2(pComponentPrivate->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
+            OMX_PRINT2(pComponentPrivate->dbg, "stop ack. received. stop waiting for sending disable command completed\n");
         }
         pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
 
@@ -2738,6 +2786,24 @@
                                             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
+            {
+                OMXDBG_PRINT(stderr, PRINT, 1, 0, "OMX has returned all input and output buffers"); 
+            }
+
             if (pComponentPrivate->bPreempted == 0) {
                 pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                        pHandle->pApplicationPrivate,
@@ -2761,8 +2827,6 @@
         }
     }
     else if (event == EMMCodecProcessingPaused) {
-        pComponentPrivate->nUnhandledEmptyThisBuffers = 0;
-        pComponentPrivate->nUnhandledFillThisBuffers = 0;
         pComponentPrivate->curState = OMX_StatePause;
         /* Send StateChangeNotification to application */
         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
@@ -2774,164 +2838,44 @@
 
     }
     else if (event == EMMCodecDspError) {
+        switch ( (OMX_U32) args [4])
+        {
+        /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
+             * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
+             * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
+             * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
+             * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
+             * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
+             * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
+             * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
+
 #ifdef _ERROR_PROPAGATION__
-        /* Cheking for MMU_fault */
+            case USN_ERR_PAUSE:
+            case USN_ERR_STOP:
+            case USN_ERR_ALGCTRL:
+            case USN_ERR_STRMCTRL:
+            case USN_ERR_UNKNOWN_MSG: 
 
-        if(((int)args[4] == NULL) && (args[5] == (void*) NULL)) {
-            printf("MMU_Fault");
-            pComponentPrivate->bIsInvalidState=OMX_TRUE;
-            pComponentPrivate->curState = OMX_StateInvalid;
-            pHandle = pComponentPrivate->pHandle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorInvalidState,
-                                                   OMX_TI_ErrorCritical,
-                                                   "DSP MMU FAULT");
-        }
+                {
+                    pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                    pComponentPrivate->curState = OMX_StateInvalid;
+                    pHandle = pComponentPrivate->pHandle;
+                    pComponentPrivate->cbInfo.EventHandler(pHandle, 
+                            pHandle->pApplicationPrivate,
+                            OMX_EventError,
+                            OMX_ErrorInvalidState, 
+                            OMX_TI_ErrorSevere,
+                            NULL);
+                }
+                break;
+#endif
 
-        if(((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*) NULL)) {
-            OMX_ERROR4(pComponentPrivate->dbg, "UTIL: MMU_Fault \n");
-            pComponentPrivate->bIsInvalidState=OMX_TRUE;
-            pComponentPrivate->curState = OMX_StateInvalid;
-            pHandle = pComponentPrivate->pHandle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorInvalidState,
-                                                   OMX_TI_ErrorSevere,
-                                                   NULL);
-        }
-#endif
-        if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) {
-            pHandle = pComponentPrivate->pHandle;
-            OMX_PRDSP2(pComponentPrivate->dbg, "GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n");
-            if(pComponentPrivate->LastOutbuf!=NULL && !pComponentPrivate->dasfmode){
-                pComponentPrivate->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS;
-            }
-            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                   OMX_EventBufferFlag,
-                                                   (OMX_U32) NULL,
-                                                   OMX_BUFFERFLAG_EOS,
-                                                   NULL);
-        }
-        if((int)args[5] == IUALG_WARN_CONCEALED) {
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm issued a warning. But can continue" );
-            OMX_ERROR4(pComponentPrivate->dbg, "arg5 = %x\n",(int)args[5]);
-        }
-        if((int)args[5] == IUALG_ERR_GENERAL) {
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Cannot continue" );
-            OMX_ERROR4(pComponentPrivate->dbg, "arg5 = %x\n",(int)args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "LCML_Callback: IUALG_ERR_GENERAL\n");
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-#ifndef UNDER_CE
-                if (pComponentPrivate->codecStop_waitingsignal == 0){ 
-                    pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);    
-                }
-            eError = LCML_ControlCodec(
-                                       ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                       MMCodecControlStop,(void *)pArgs);
-                if (pComponentPrivate->codecStop_waitingsignal == 0){
-                    pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
-                    pComponentPrivate->codecStop_waitingsignal = 0;
-                    pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
-                }
-            if(eError != OMX_ErrorNone) {
-                OMX_ERROR4(pComponentPrivate->dbg, "Error Occurred in Codec Stop..\n");
-                pComponentPrivate->curState = OMX_StateInvalid;
-                pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                       pHandle->pApplicationPrivate,
-                                                       OMX_EventError,
-                                                       eError,
-                                                       OMX_TI_ErrorSevere,
-                                                       NULL);
-                goto EXIT;
-            }
-            OMX_PRINT2(pComponentPrivate->dbg, "AMRENC: Codec has been Stopped here\n");
-            pComponentPrivate->curState = OMX_StateIdle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventCmdComplete,
-                                                   OMX_ErrorNone,
-                                                   0,
-                                                   NULL);
-#else
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorUndefined,
-                                                   OMX_TI_ErrorSevere,
-                                                   NULL);
-#endif
-        }
-        if( (int)args[5] == IUALG_ERR_DATA_CORRUPT ){
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Corrupt data" );
-            OMX_ERROR4(pComponentPrivate->dbg, "arg5 = %x\n",(int)args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "LCML_Callback: IUALG_ERR_DATA_CORRUPT\n");
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-#ifndef UNDER_CE
-                if (pComponentPrivate->codecStop_waitingsignal == 0){ 
-                    pthread_mutex_lock(&pComponentPrivate->codecStop_mutex);    
-                }
-            eError = LCML_ControlCodec(
-                                       ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                       MMCodecControlStop,(void *)pArgs);
-                if (pComponentPrivate->codecStop_waitingsignal == 0){
-                    pthread_cond_wait(&pComponentPrivate->codecStop_threshold, &pComponentPrivate->codecStop_mutex);
-                    pComponentPrivate->codecStop_waitingsignal = 0;
-                    pthread_mutex_unlock(&pComponentPrivate->codecStop_mutex);
-                }
-            if(eError != OMX_ErrorNone) {
-                OMX_ERROR4(pComponentPrivate->dbg, "Error Occurred in Codec Stop..\n");
-                pComponentPrivate->curState = OMX_StateInvalid;
-                pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                       pHandle->pApplicationPrivate,
-                                                       OMX_EventError,
-                                                       eError,
-                                                       OMX_TI_ErrorSevere,
-                                                       NULL);
-                goto EXIT;
-            }
-            OMX_PRINT2(pComponentPrivate->dbg, "AMRENC: Codec has been Stopped here\n");
-            pComponentPrivate->curState = OMX_StateIdle;
-            pComponentPrivate->cbInfo.EventHandler(
-                                                   pHandle, pHandle->pApplicationPrivate,
-                                                   OMX_EventCmdComplete, OMX_ErrorNone,0, NULL);
-#else
-            pComponentPrivate->cbInfo.EventHandler(
-                                                   pHandle, pHandle->pApplicationPrivate,
-                                                   OMX_EventError, OMX_ErrorUndefined,OMX_TI_ErrorSevere, NULL);
-#endif
-        }
-        if( (int)args[5] == IUALG_WARN_OVERFLOW ){
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Overflow, sending to Idle\n" );
-#ifdef RESOURCE_MANAGER_ENABLED
-            rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_WBAMR_Decoder_COMPONENT, OMX_StateIdle, 3456, NULL);
-
-#endif
-        }
-        if( (int)args[5] == IUALG_WARN_UNDERFLOW ){
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Underflow, sending to Idle\n" );
-#ifdef RESOURCE_MANAGER_ENABLED
-            rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_WBAMR_Decoder_COMPONENT, OMX_StateIdle, 3456, NULL);
-#endif
-        }
-
-        if((int)args[5] == IUALG_ERR_NOT_SUPPORTED) {
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Parameter not supported" );
-            OMX_ERROR4(pComponentPrivate->dbg, "arg5 = %p\n",args[5]);
-            OMX_ERROR4(pComponentPrivate->dbg, "LCML_Callback: IUALG_ERR_NOT_SUPPORTED\n");
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-            pComponentPrivate->curState = OMX_StateIdle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorInsufficientResources,OMX_TI_ErrorSevere, NULL);
-            goto EXIT;
+            case USN_ERR_WARNING:
+            case USN_ERR_PROCESS:
+                WBAMRDEC_HandleUSNError (pComponentPrivate, (OMX_U32)args[5]);
+                break;
+            default:
+                break;
         }
 
     }
@@ -3021,7 +2965,7 @@
         for(i=0; i<nIpBuf; i++) {
             if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
                 *ppLcmlHdr = pLcmlBufHeader;
-                OMX_ERROR2(pComponentPrivate->dbg, "Corresponding LCML Header Found\n");
+                OMX_PRDSP2(pComponentPrivate->dbg, "Corresponding LCML Header Found\n");
                 goto EXIT;
             }
             pLcmlBufHeader++;
@@ -3351,7 +3295,6 @@
     OMX_U16 i;
     OMX_BUFFERHEADERTYPE *pTemp;
     int size_lcml;
-    char *ptr;
 
     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
     WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate;
@@ -3380,8 +3323,6 @@
 
     size_lcml = nIpBuf * sizeof(LCML_WBAMR_DEC_BUFHEADERTYPE);
     OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,LCML_WBAMR_DEC_BUFHEADERTYPE);
-
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "[ALLOC] %p\n",pTemp_lcml);
     pComponentPrivate->pLcmlBufHeader[WBAMR_DEC_INPUT_PORT] = pTemp_lcml;
 
     for (i=0; i<nIpBuf; i++) {
@@ -3396,8 +3337,8 @@
         pTemp_lcml->eDir = OMX_DirInput;
 
         OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
-                                 sizeof(WBAMRDEC_ParamStruct),
-                                 WBAMRDEC_ParamStruct);
+                                  sizeof(WBAMRDEC_ParamStruct),
+                                  WBAMRDEC_ParamStruct);
 
         OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
@@ -3416,8 +3357,6 @@
      * This memory pointer will be sent to LCML */
     size_lcml = nOpBuf * sizeof(LCML_WBAMR_DEC_BUFHEADERTYPE);
     OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,LCML_WBAMR_DEC_BUFHEADERTYPE);
-
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "[ALLOC] %p\n",pTemp_lcml);
     pComponentPrivate->pLcmlBufHeader[WBAMR_DEC_OUTPUT_PORT] = pTemp_lcml;
 
     for (i=0; i<nOpBuf; i++) {
@@ -3432,8 +3371,8 @@
         pTemp_lcml->pFrameParam = NULL;
 
         OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
-                                 sizeof(WBAMRDEC_ParamStruct),
-                                 WBAMRDEC_ParamStruct);
+                                  sizeof(WBAMRDEC_ParamStruct),
+                                  WBAMRDEC_ParamStruct);
 
         pTemp_lcml->pBufferParam->usNbFrames =0;
         pTemp_lcml->pBufferParam->pParamElem = NULL;
@@ -3638,7 +3577,39 @@
      return ret;
 }
 #endif
-/*
+
+/* ========================================================================== */
+/**
+* @SignalIfAllBuffersAreReturned() This function send signals if OMX returned all buffers to app 
+*
+* @param WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate
+*
+* @pre None
+*
+* @post None
+*
+* @return None
+*/
+/* ========================================================================== */
+void SignalIfAllBuffersAreReturned(WBAMR_DEC_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_PRINT1(pComponentPrivate->dbg, "Sending pthread signal that OMX has returned all buffers to app"); 
+        if(pthread_mutex_unlock(&bufferReturned_mutex) != 0) 
+        {
+            OMX_ERROR4(pComponentPrivate->dbg, "%d :: bufferReturned_mutex mutex unlock error\n",__LINE__); 
+        }
+        return;
+    }
+}
+
+#ifdef RESOURCE_MANAGER_ENABLED
 void WBAMRDEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
 {
     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
@@ -3667,4 +3638,66 @@
     }
 
 }
-*/
+#endif
+
+void WBAMRDEC_HandleUSNError (WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
+{
+    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U8 pending_buffers = OMX_FALSE;
+    OMX_U32 i;
+    switch (arg)
+    {
+        case IUALG_WARN_CONCEALED:
+        case IUALG_WARN_UNDERFLOW:
+        case IUALG_WARN_OVERFLOW:
+        case IUALG_WARN_ENDOFDATA:
+            /* all of these are informative messages, Algo can recover, no need to notify the 
+             * IL Client at this stage of the implementation */
+            break;
+
+        case IUALG_WARN_PLAYCOMPLETED:
+        {
+            pHandle = pComponentPrivate->pHandle;
+            OMX_PRDSP1(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n",__LINE__);
+            if(pComponentPrivate->LastOutbuf!=NULL && !pComponentPrivate->dasfmode){
+                pComponentPrivate->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS;
+            }
+                 
+            /* add callback to application to indicate SN/USN has completed playing of current set of date */
+            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,                  
+                                                   pComponentPrivate->pHandle->pApplicationPrivate,
+                                                   OMX_EventBufferFlag,
+                                                   (OMX_U32)NULL,
+                                                   OMX_BUFFERFLAG_EOS,
+                                                   NULL);
+        }
+            break;
+
+#ifdef _ERROR_PROPAGATION__
+        case IUALG_ERR_BAD_HANDLE:
+        case IUALG_ERR_DATA_CORRUPT:
+        case IUALG_ERR_NOT_SUPPORTED:
+        case IUALG_ERR_ARGUMENT:
+        case IUALG_ERR_NOT_READY:
+        case IUALG_ERR_GENERAL:
+        {
+        /* all of these are fatal messages, Algo can not recover
+                 * hence return an error */
+                pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                pComponentPrivate->curState = OMX_StateInvalid;
+                pHandle = pComponentPrivate->pHandle;
+                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                        pHandle->pApplicationPrivate,
+                        OMX_EventError,
+                        OMX_ErrorInvalidState,
+                        OMX_TI_ErrorSevere,
+                        NULL);
+            }
+            break;
+#endif
+        default:
+            break;
+    }
+}
+
+
diff --git a/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDecoder.c b/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDecoder.c
index ca28a3d..e69dca9 100644
--- a/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDecoder.c
+++ b/omx/audio/src/openmax_il/wbamr_dec/src/OMX_WbAmrDecoder.c
@@ -36,6 +36,14 @@
  * @rev  0.1
  */
 /* ----------------------------------------------------------------------------
+ *!
+ *! Revision History
+ *! ===================================
+ *! 12-Sept-2005 mf:  Initial Version. Change required per OMAPSWxxxxxxxxx
+ *! to provide _________________.
+ *!
+ * ============================================================================= */
+
 
 /* ------compilation control switches -------------------------*/
 /****************************************************************
@@ -74,27 +82,10 @@
 /*-------program files ----------------------------------------*/
 #include <OMX_Component.h>
 #include <TIDspOmx.h>
-#include <OMX_TI_Common.h>
 
 #include "OMX_WbAmrDecoder.h"
 #include "OMX_WbAmrDec_Utils.h"
 
-#ifdef WBAMRDEC_DEBUGMEM
-
-void *arr[500];
-int lines[500];
-int bytes[500];
-char file[500][50];
-
-void * mymalloc(int line, char *s, int size);
-int myfree(void *dp, int line, char *s);
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
 #define AMRWB_DEC_ROLE "audio_decoder.amrwb"
 
 
@@ -203,7 +194,7 @@
 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
 {
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip, *pPortDef_op;
-    WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate;
+    WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_AUDIO_PARAM_AMRTYPE *amr_ip;
     OMX_AUDIO_PARAM_PCMMODETYPE *amr_op;
     OMX_ERRORTYPE error = OMX_ErrorNone;
@@ -235,6 +226,7 @@
     /*Allocate the memory for Component private data area */
     OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, WBAMR_DEC_COMPONENT_PRIVATE);
 
+
     ((WBAMR_DEC_COMPONENT_PRIVATE *)
      pHandle->pComponentPrivate)->pHandle = pHandle;
 
@@ -263,7 +255,7 @@
                                            PERF_ModuleAudioDecode);
 #endif
 
-#if ANDROID /* currently using default values until more is understood */
+#ifdef ANDROID /* currently using default values until more is understood */
     pComponentPrivate->iPVCapabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; /* this should be true always for TI components */
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE;
@@ -421,7 +413,6 @@
 #endif
     OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
 
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "[ALLOC] %p\n",pPortDef_ip);
     OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, "[ALLOC] %p\n",pPortDef_op);
@@ -437,7 +428,7 @@
     pPortDef_ip->nPortIndex = 0x0;
     pPortDef_ip->nBufferCountActual = NUM_WBAMRDEC_INPUT_BUFFERS;
     pPortDef_ip->nBufferCountMin = NUM_WBAMRDEC_INPUT_BUFFERS;
-    pPortDef_ip->nBufferAlignment = EXTRA_BYTES;
+    pPortDef_ip->nBufferAlignment = DSP_CACHE_ALIGNMENT;
     pPortDef_ip->eDir = OMX_DirInput;
     pPortDef_ip->bEnabled = OMX_TRUE;
     /* Use bigger IN buffer size for PV-Android */
@@ -449,7 +440,7 @@
     pPortDef_op->nPortIndex = 0x1;
     pPortDef_op->nBufferCountActual = NUM_WBAMRDEC_OUTPUT_BUFFERS;
     pPortDef_op->nBufferCountMin = NUM_WBAMRDEC_OUTPUT_BUFFERS;
-    pPortDef_op->nBufferAlignment = EXTRA_BYTES;
+    pPortDef_op->nBufferAlignment = DSP_CACHE_ALIGNMENT;
     pPortDef_op->eDir = OMX_DirOutput;
     pPortDef_op->bEnabled = OMX_TRUE;
     pPortDef_op->nBufferSize = OUTPUT_WBAMRDEC_BUFFER_SIZE;
@@ -491,7 +482,9 @@
                        PERF_FOURCC('W','B','D','T'));
 #endif
  EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting - returning %d\n",error);
+    if (pComponentPrivate != NULL) {
+	 OMX_PRINT1(pComponentPrivate->dbg, "Exiting - returning %d\n", error);
+    }
     return error;
 }
 
@@ -891,6 +884,10 @@
         }
         break;
     case OMX_IndexParamPriorityMgmt:
+        if (pComponentPrivate->pPriorityMgmt == NULL) {
+	    eError = OMX_ErrorBadPortIndex;
+	    break;
+	}
         memcpy(ComponentParameterStructure, pComponentPrivate->pPriorityMgmt, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
@@ -1074,6 +1071,10 @@
         if (pComponentPrivate->curState != OMX_StateLoaded) {
             eError = OMX_ErrorIncorrectStateOperation;
         }
+	if (pComponentPrivate->pPriorityMgmt == NULL) {
+	    eError = OMX_ErrorBadParameter;
+	    break;
+	}
         memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
 
@@ -1161,8 +1162,8 @@
         OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
     }
 
-    OMX_MEMFREE_STRUCT(streamInfo);
  EXIT:
+    OMX_MEMFREE_STRUCT(streamInfo);
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting GetConfig. Returning = 0x%x\n",eError);
     return eError;
 }
@@ -1185,8 +1186,7 @@
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
-    WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate =
-        (WBAMR_DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    WBAMR_DEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_S16 *customFlag = NULL;
     TI_OMX_DSP_DEFINITION *configData;
     TI_OMX_DATAPATH dataPath;
@@ -1201,6 +1201,7 @@
         goto EXIT;
     }
 
+    pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 #ifdef _ERROR_PROPAGATION__
     if (pComponentPrivate->curState == OMX_StateInvalid){
         eError = OMX_ErrorInvalidState;
@@ -1642,17 +1643,9 @@
     eError = WBAMR_DEC_StopComponentThread(pHandle);
     /* Wait for thread to exit so we can get the status into "error" */
 
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
 
-    if(pComponentPrivate->pInputBufferList!=NULL){
-        OMX_PRBUFFER2(dbg, "[FREE] %p\n",pComponentPrivate->pInputBufferList);
-        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
-    }
-
-    if(pComponentPrivate->pOutputBufferList!=NULL){
-        OMX_PRBUFFER2(dbg, "[FREE] %p\n",pComponentPrivate->pOutputBufferList);
-        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
-    }
-
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
 
     /* close the pipe handles */
     WBAMR_DEC_FreeCompResources(pHandle);
@@ -1662,13 +1655,10 @@
                   PERF_BoundaryComplete | PERF_BoundaryCleanup);
     PERF_Done(pComponentPrivate->pPERF);
 #endif
-    if (pComponentPrivate->sDeviceString != NULL) {
-        OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
-    }
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
     OMX_PRINT2(dbg, "After WBAMR_DEC_FreeCompResources\n");
 
     OMX_MEMFREE_STRUCT(pComponentPrivate);
-    OMX_PRINT1(dbg, "After newfree(pComponentPrivate)\n");
     OMX_DBG_CLOSE(dbg);
     return eError;
 }
@@ -1752,7 +1742,7 @@
     }
 
     OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
-    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer,nSizeBytes,OMX_U8);
+    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes,OMX_U8);
 
     if (nPortIndex == WBAMR_DEC_INPUT_PORT) {
         pBufferHeader->nInputPortIndex = nPortIndex;
@@ -1772,7 +1762,6 @@
     else if (nPortIndex == WBAMR_DEC_OUTPUT_PORT) {
         pBufferHeader->nInputPortIndex = -1;
         pBufferHeader->nOutputPortIndex = nPortIndex;
-        //pBufferHeader->pOutputPortPrivate = (WBAMRDEC_BUFDATA*) malloc(sizeof(WBAMRDEC_BUFDATA));
         OMX_MALLOC_GENERIC(pBufferHeader->pOutputPortPrivate, WBAMRDEC_BUFDATA);
         pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
         pComponentPrivate->pOutputBufferList->bBufferPending[pComponentPrivate->pOutputBufferList->numBuffers] = 0;
@@ -1843,7 +1832,6 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     WBAMR_DEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
     OMX_BUFFERHEADERTYPE* buff;
-    OMX_U8* tempBuff;
     int i;
     int inputIndex = -1;
     int outputIndex = -1;
@@ -1894,12 +1882,10 @@
                            PERF_ModuleMemory);
 #endif
         if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer);
-            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer,OMX_U8);
-         }
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->pBufHeader[WBAMR_DEC_INPUT_PORT]);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
+        }
         OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
-       pComponentPrivate->pInputBufferList->numBuffers--;
+        pComponentPrivate->pInputBufferList->numBuffers--;
         if (pComponentPrivate->pInputBufferList->numBuffers <
             pComponentPrivate->pPortDef[WBAMR_DEC_INPUT_PORT]->nBufferCountMin) {
 
@@ -1923,9 +1909,8 @@
                            PERF_ModuleMemory);
 #endif
         if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "[FREE] %p\n",pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer);
-            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer,OMX_U8);
-         }
+        OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, OMX_U8);
+        }
         OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pOutputPortPrivate);
         OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
         pComponentPrivate->pOutputBufferList->numBuffers--;
@@ -2129,8 +2114,13 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     pComponentPrivate = (WBAMR_DEC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     if(nIndex == 0){
-        memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
-        OMX_PRINT1(pComponentPrivate->dbg, "In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+        if (cRole == NULL) {
+            eError = OMX_ErrorBadParameter;
+	}
+	else {
+            memcpy(cRole, &pComponentPrivate->componentRole.cRole, sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
+            OMX_PRINT1(pComponentPrivate->dbg, "In ComponenetRoleEnum: cRole is set to %s\n",cRole);
+	}
     }
     else {
         eError = OMX_ErrorNoMore;
@@ -2146,6 +2136,7 @@
     p = malloc(size);
     if(p==NULL){
         OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
+        /* exit(1); */
     }
     else{
         while((lines[e]!=0)&& (e<500) ){
diff --git a/omx/audio/src/openmax_il/wbamr_dec/tests/WBAmrDecTest.c b/omx/audio/src/openmax_il/wbamr_dec/tests/WBAmrDecTest.c
index 363122b..1cf0aa0 100644
--- a/omx/audio/src/openmax_il/wbamr_dec/tests/WBAmrDecTest.c
+++ b/omx/audio/src/openmax_il/wbamr_dec/tests/WBAmrDecTest.c
@@ -57,7 +57,7 @@
 #include <OMX_Component.h>
 #include <OMX_Core.h>
 #include <OMX_Audio.h>
-#include <TIDspOmx.h>
+/*#include <TIDspOmx.h>*/
 
 #include <pthread.h>
 #include <stdio.h>
@@ -496,7 +496,7 @@
     OMX_BUFFERHEADERTYPE* pOutputBufferHeader[10];
     OMX_BUFFERHEADERTYPE* pBuf;
     bInvalidState=OMX_FALSE;
-    TI_OMX_DATAPATH dataPath;
+    /* TI_OMX_DATAPATH dataPath;*/
     FILE* fOut = NULL;
     FILE* fIn = fopen(argv[1], "r");
 
@@ -523,11 +523,11 @@
     int wbamrdecfdread;
 #endif
 
-    TI_OMX_DSP_DEFINITION* audioinfo;
+    /*TI_OMX_DSP_DEFINITION* audioinfo;*/
     OMX_AUDIO_CONFIG_MUTETYPE* pCompPrivateStructMute = NULL; 
     OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructVolume = NULL; 
 
-	TI_OMX_STREAM_INFO *streaminfo;
+	/*TI_OMX_STREAM_INFO *streaminfo;
     streaminfo = newmalloc(sizeof(TI_OMX_STREAM_INFO));
 	audioinfo = newmalloc(sizeof(TI_OMX_DSP_DEFINITION));
 	
@@ -537,8 +537,9 @@
         error = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
+	
     ArrayOfPointers[0]=(TI_OMX_STREAM_INFO*)streaminfo;
-    ArrayOfPointers[1]=(TI_OMX_DSP_DEFINITION*)audioinfo;
+    ArrayOfPointers[1]=(TI_OMX_DSP_DEFINITION*)audioinfo;*/
 
     pthread_mutex_init(&WaitForState_mutex, NULL);
     pthread_cond_init (&WaitForState_threshold, NULL);
@@ -1070,12 +1071,12 @@
     }
 
 	/* get TeeDN or ACDN mode */
-	audioinfo->acousticMode = atoi(argv[8]);
-
+	/*audioinfo->acousticMode = atoi(argv[8]);*/
+	/*
     if (audioinfo->acousticMode == OMX_TRUE) {
         printf("Using Acoustic Device Node Path\n");
-        dataPath = DATAPATH_ACDN;
-    }
+	dataPath = DATAPATH_ACDN;
+    }*/
     else if (dasfmode) {
 #ifdef RTM_PATH    
         printf("Using Real Time Mixer Path\n");
@@ -1088,7 +1089,7 @@
 #endif        
     }
 
-    audioinfo->dasfMode = dasfmode;
+    /*audioinfo->dasfMode = dasfmode;*/
     error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamrheaderinfo",&index);
 	if (error != OMX_ErrorNone) {
 		printf("Error getting extension index\n");
@@ -1114,26 +1115,26 @@
     streamId = audioinfo->streamId;
 #endif
 	
-	error = OMX_SetConfig (pHandle, index, audioinfo);
+	/*error = OMX_SetConfig (pHandle, index, audioinfo);
     if(error != OMX_ErrorNone) {
         error = OMX_ErrorBadParameter;
         APP_DPRINT("%d :: Error from OMX_SetConfig() function\n",__LINE__);
         goto EXIT;
     }
-
-    error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamr.datapath",&index);
+	*/
+    /*error = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamr.datapath",&index);
 	if (error != OMX_ErrorNone) {
 		printf("Error getting extension index\n");
 		goto EXIT;
-	}
+	}*/
     
 
-	error = OMX_SetConfig (pHandle, index, &dataPath);
+	/*error = OMX_SetConfig (pHandle, index, &dataPath);
     if(error != OMX_ErrorNone) {
         error = OMX_ErrorBadParameter;
         APP_DPRINT("%d :: AmrDecTest.c :: Error from OMX_SetConfig() function\n",__LINE__);
         goto EXIT;
-    }
+    }*/
 
 
      /* default setting for Mute/Unmute */ 
@@ -1745,9 +1746,9 @@
 			goto EXIT;
     }
    
-    newfree(audioinfo);
+    /*newfree(audioinfo);
     
-    newfree(streaminfo);
+    newfree(streaminfo);*/
 
 
 	
diff --git a/omx/audio/src/openmax_il/wbamr_enc/inc/OMX_WbAmrEnc_Utils.h b/omx/audio/src/openmax_il/wbamr_enc/inc/OMX_WbAmrEnc_Utils.h
index 5a18c7d..ce044b0 100644
--- a/omx/audio/src/openmax_il/wbamr_enc/inc/OMX_WbAmrEnc_Utils.h
+++ b/omx/audio/src/openmax_il/wbamr_enc/inc/OMX_WbAmrEnc_Utils.h
@@ -61,33 +61,36 @@
 
 #include "LCML_DspCodec.h"
 #include <semaphore.h>
-/* #include <ResourceManagerProxyAPI.h> */
+
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
 
 #ifdef __PERF_INSTRUMENTATION__
-    #include "perf.h"
+#include "perf.h"
 #endif
 
 #include <OMX_Component.h>
 #include "OMX_TI_Common.h"
 #include "OMX_TI_Debug.h"
 #ifdef DSP_RENDERING_ON
-    #include <AudioManagerAPI.h>
+#include <AudioManagerAPI.h>
 #endif
 
 #ifdef UNDER_CE
-    #define sleep Sleep
+#define sleep Sleep
 #endif
 
 #ifndef ANDROID
-    #define ANDROID
+#define ANDROID
 #endif
 
 #ifdef ANDROID
-    #undef LOG_TAG
-    #define LOG_TAG "OMX_WBAMRENC"
+#undef LOG_TAG
+#define LOG_TAG "OMX_WBAMRENC"
 
-    /* PV opencore capability custom parameter index */
-    #define PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX 0xFF7A347
+/* PV opencore capability custom parameter index */
+#define PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX 0xFF7A347
 #endif
 
 /* ======================================================================= */
@@ -115,7 +118,7 @@
 
 /* ======================================================================= */
 /**
- *  M A C R O S FOR MALLOC and MEMORY FREE and CLOSING PIPES
+ *  M A C R O S FOR MEMORY and CLOSING PIPES
  */
 /* ======================================================================= */
 
@@ -127,13 +130,6 @@
     (_s_)->nVersion.s.nRevision = 0x0;      \
     (_s_)->nVersion.s.nStep = 0x0
 
-#define OMX_WBMEMFREE_STRUCT(_pStruct_)\
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "FREEING MEMORY = %p\n",_pStruct_);\
-    if(_pStruct_ != NULL){\
-        newfree(_pStruct_);\
-        _pStruct_ = NULL;\
-    }
-
 #define OMX_WBCLOSE_PIPE(_pStruct_,err)\
     OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "Closing pipes = %d\n",_pStruct_);\
     err = close (_pStruct_);\
@@ -143,49 +139,11 @@
         goto EXIT;\
     }
 
-#define WBAMRENC_OMX_MALLOC(_pStruct_, _sName_)   \
-    _pStruct_ = (_sName_*)newmalloc(sizeof(_sName_));      \
-    if(_pStruct_ == NULL){      \
-        OMXDBG_PRINT(stderr, ERROR, 4, OMX_DBG_BASEMASK, "Malloc Failed\n"); \
-        eError = OMX_ErrorInsufficientResources; \
-        goto EXIT;      \
-    } \
-    memset(_pStruct_,0,sizeof(_sName_));\
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "Malloced = %p\n",_pStruct_);
-
-
-
-#define WBAMRENC_OMX_MALLOC_SIZE(_ptr_, _size_,_name_)   \
-    _ptr_ = (_name_ *)newmalloc(_size_);      \
-    if(_ptr_ == NULL){      \
-        OMXDBG_PRINT(stderr, ERROR, 4, OMX_DBG_BASEMASK, "Malloc Failed\n"); \
-        eError = OMX_ErrorInsufficientResources; \
-        goto EXIT;      \
-    } \
-    memset(_ptr_,0,_size_); \
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "Malloced = %p\n",_ptr_);
-
 #define WBAMRENC_OMX_ERROR_EXIT(_e_, _c_, _s_)\
     _e_ = _c_;\
     OMXDBG_PRINT(stderr, ERROR, 4, OMX_DBG_BASEMASK, "Error Name: %s : Error Num = %x", _s_, _e_);\
     goto EXIT;
 
-#define WBAMRENC_OMX_FREE(ptr) \
-    if(NULL != ptr) { \
-        OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "Freeing Address = %p\n",ptr); \
-        newfree(ptr); \
-        ptr = NULL; \
-    }
-
-/* ======================================================================= */
-/**
- * @def EXTRA_BYTES      Extra bytes For Cache alignment
- *      DSP_CACHE_ALIGNMENT    Cache alignment value
- */
-/* ======================================================================= */
-
-#define EXTRA_BYTES 128 
-#define DSP_CACHE_ALIGNMENT 256 
 /* ======================================================================= */
 /**
  * @def    WBAMRENC_SAMPLING_FREQUENCY   Sampling frequency
@@ -259,9 +217,9 @@
  */
 /* ======================================================================= */
 #ifdef UNDER_CE
-    #define WBAMRENC_USN_DLL_NAME "\\windows\\usn.dll64P"
+#define WBAMRENC_USN_DLL_NAME "\\windows\\usn.dll64P"
 #else
-    #define WBAMRENC_USN_DLL_NAME "usn.dll64P"
+#define WBAMRENC_USN_DLL_NAME "usn.dll64P"
 #endif
 
 /* ======================================================================= */
@@ -270,9 +228,9 @@
  */
 /* ======================================================================= */
 #ifdef UNDER_CE
-    #define WBAMRENC_DLL_NAME "\\windows\\wbamrenc_sn.dll64P"
+#define WBAMRENC_DLL_NAME "\\windows\\wbamrenc_sn.dll64P"
 #else
-    #define WBAMRENC_DLL_NAME "wbamrenc_sn.dll64P"
+#define WBAMRENC_DLL_NAME "wbamrenc_sn.dll64P"
 #endif
 
 /* ======================================================================= */
@@ -316,9 +274,9 @@
 /* ======================================================================= */
 enum WBAMRENC_MimeMode {
     WBAMRENC_FORMATCONFORMANCE = 0,
-    WBAMRENC_MIMEMODE, 
+    WBAMRENC_MIMEMODE,
     WBAMRENC_IF2
-    };
+};
 
 /* ======================================================================= */
 /*
@@ -396,7 +354,7 @@
 typedef enum WBAMRENC_COMP_PORT_TYPE {
     WBAMRENC_INPUT_PORT = 0,
     WBAMRENC_OUTPUT_PORT
-}WBAMRENC_COMP_PORT_TYPE;
+} WBAMRENC_COMP_PORT_TYPE;
 
 /* ======================================================================= */
 /** AUDIO_SN_WBAMRBANDMODETYPE
@@ -406,17 +364,17 @@
  */
 /*  ====================================================================== */
 typedef enum AUDIO_SN_WBAMRBANDMODETYPE {
-     SN_AUDIO_BR2385 = 8,
-     SN_AUDIO_BR2305,
-     SN_AUDIO_BR1985,
-     SN_AUDIO_BR1825,
-     SN_AUDIO_BR1585,
-     SN_AUDIO_BR1425,
-     SN_AUDIO_BR1265,
-     SN_AUDIO_BR885,
-     SN_AUDIO_BR660,
-     SN_AUDIO_WBAMRBandModeMax = 0x7FFFFFFF
-}AUDIO_SN_WBAMRBANDMODETYPE;
+    SN_AUDIO_BR2385 = 8,
+    SN_AUDIO_BR2305,
+    SN_AUDIO_BR1985,
+    SN_AUDIO_BR1825,
+    SN_AUDIO_BR1585,
+    SN_AUDIO_BR1425,
+    SN_AUDIO_BR1265,
+    SN_AUDIO_BR885,
+    SN_AUDIO_BR660,
+    SN_AUDIO_WBAMRBandModeMax = 0x7FFFFFFF
+} AUDIO_SN_WBAMRBANDMODETYPE;
 
 /* ======================================================================= */
 /** WBAMRENC_BUFFER_Dir  Buffer Direction
@@ -430,7 +388,7 @@
 typedef enum {
     WBAMRENC_DIRECTION_INPUT,
     WBAMRENC_DIRECTION_OUTPUT
-}WBAMRENC_BUFFER_Dir;
+} WBAMRENC_BUFFER_Dir;
 
 /* ======================================================================= */
 /** WBAMRENC_BUFFS  Buffer details
@@ -444,7 +402,7 @@
 typedef struct WBAMRENC_BUFFS {
     char BufHeader;
     char Buffer;
-}WBAMRENC_BUFFS;
+} WBAMRENC_BUFFS;
 
 /* ======================================================================= */
 /** WBAMRENC_BUFFERHEADERTYPE_INFO
@@ -458,7 +416,7 @@
 typedef struct WBAMRENC_BUFFERHEADERTYPE_INFO {
     OMX_BUFFERHEADERTYPE* pBufHeader[WBAMRENC_MAX_NUM_OF_BUFS];
     WBAMRENC_BUFFS bBufOwner[WBAMRENC_MAX_NUM_OF_BUFS];
-}WBAMRENC_BUFFERHEADERTYPE_INFO;
+} WBAMRENC_BUFFERHEADERTYPE_INFO;
 
 
 typedef OMX_ERRORTYPE (*WBAMRENC_fpo)(OMX_HANDLETYPE);
@@ -472,28 +430,27 @@
     unsigned long  iSamplingRate;
     unsigned long  iStrmId;
     unsigned short iAudioFormat;
-}WBAMRENC_AudioCodecParams;
+} WBAMRENC_AudioCodecParams;
 
 /* =================================================================================== */
 /**
 * WBAMRENC_TALGCtrl                 Socket Node Alg Control parameters.
+* WBAMRENC_TALGCtrlDTX              Socket Node Alg Control parameters (DTX).
 * WBAMRENC_UAlgInBufParamStruct     Input Buffer Param Structure
 * WBAMRENC_UAlgOutBufParamStruct    Output Buffer Param Structure
 */
 /* =================================================================================== */
 /* Algorithm specific command parameters */
 typedef struct {
-    unsigned int iSize;
+    int iSize;
     unsigned int iBitrate;
-    unsigned int iDTX;
-    unsigned int iMode;
-    unsigned int iFrameSize;
-    unsigned int iNoiseSuppressionMode;
-    unsigned int ittyTddMode;
-    unsigned int idtmfMode;
-    unsigned int idataTransmit;
-}WBAMRENC_TALGCtrl;
+} WBAMRENC_TALGCtrl;
 
+typedef struct {
+    int iSize;
+    unsigned int iVADFlag;
+
+} WBAMRENC_TALGCtrlDTX;
 /* =================================================================================== */
 /**
 * WBAMRENC_UAlgInBufParamStruct     Input Buffer Param Structure
@@ -501,13 +458,13 @@
 */
 /* =================================================================================== */
 typedef struct {
-        unsigned long int usLastFrame;
-}WBAMRENC_FrameStruct;
+    unsigned long int usLastFrame;
+} WBAMRENC_FrameStruct;
 
-typedef struct{
-         unsigned long int usNbFrames;
-         WBAMRENC_FrameStruct *pParamElem;
-}WBAMRENC_ParamStruct;
+typedef struct {
+    unsigned long int usNbFrames;
+    WBAMRENC_FrameStruct *pParamElem;
+} WBAMRENC_ParamStruct;
 
 /* =================================================================================== */
 /**
@@ -517,7 +474,7 @@
 /* =================================================================================== */
 typedef struct {
     unsigned long ulFrameCount;
-}WBAMRENC_UAlgOutBufParamStruct;
+} WBAMRENC_UAlgOutBufParamStruct;
 
 /* =================================================================================== */
 /**
@@ -525,12 +482,12 @@
 */
 /* =================================================================================== */
 typedef struct WBAMRENC_LCML_BUFHEADERTYPE {
-      WBAMRENC_BUFFER_Dir eDir;
-      WBAMRENC_FrameStruct *pFrameParam;
-      WBAMRENC_ParamStruct *pBufferParam;
-      DMM_BUFFER_OBJ* pDmmBuf;
-      OMX_BUFFERHEADERTYPE* buffer;
-}WBAMRENC_LCML_BUFHEADERTYPE;
+    WBAMRENC_BUFFER_Dir eDir;
+    WBAMRENC_FrameStruct *pFrameParam;
+    WBAMRENC_ParamStruct *pBufferParam;
+    DMM_BUFFER_OBJ* pDmmBuf;
+    OMX_BUFFERHEADERTYPE* buffer;
+} WBAMRENC_LCML_BUFHEADERTYPE;
 
 typedef struct _WBAMRENC_BUFFERLIST WBAMRENC_BUFFERLIST;
 
@@ -539,7 +496,7 @@
 * _WBAMRENC_BUFFERLIST Structure for buffer list
 */
 /* ================================================================================== */
-struct _WBAMRENC_BUFFERLIST{
+struct _WBAMRENC_BUFFERLIST {
     OMX_BUFFERHEADERTYPE sBufHdr;
     OMX_BUFFERHEADERTYPE *pBufHdr[WBAMRENC_MAX_NUM_OF_BUFS];
     OMX_U32 bufferOwner[WBAMRENC_MAX_NUM_OF_BUFS];
@@ -563,28 +520,27 @@
 } WBAMRENC_PORT_TYPE;
 
 #ifdef UNDER_CE
-    #ifndef _OMX_EVENT_
-        #define _OMX_EVENT_
-        typedef struct OMX_Event {
-            HANDLE event;
-        } OMX_Event;
-    #endif
-    int OMX_CreateEvent(OMX_Event *event);
-    int OMX_SignalEvent(OMX_Event *event);
-    int OMX_WaitForEvent(OMX_Event *event);
-    int OMX_DestroyEvent(OMX_Event *event);
+#ifndef _OMX_EVENT_
+#define _OMX_EVENT_
+typedef struct OMX_Event {
+    HANDLE event;
+} OMX_Event;
+#endif
+int OMX_CreateEvent(OMX_Event *event);
+int OMX_SignalEvent(OMX_Event *event);
+int OMX_WaitForEvent(OMX_Event *event);
+int OMX_DestroyEvent(OMX_Event *event);
 #endif
 
 typedef struct WBAMRENC_BUFDATA {
-   OMX_U8 nFrames;     
-}WBAMRENC_BUFDATA;
+    OMX_U8 nFrames;
+} WBAMRENC_BUFDATA;
 /* =================================================================================== */
 /**
 * WBAMRENC_COMPONENT_PRIVATE Component private data Structure
 */
 /* =================================================================================== */
-typedef struct WBAMRENC_COMPONENT_PRIVATE
-{
+typedef struct WBAMRENC_COMPONENT_PRIVATE {
     /** Array of pointers to BUFFERHEADERTYPE structues
         This pBufHeader[INPUT_PORT] will point to all the
         BUFFERHEADERTYPE structures related to input port,
@@ -600,8 +556,11 @@
     OMX_CALLBACKTYPE cbInfo;
     OMX_PORT_PARAM_TYPE* sPortParam;
     OMX_PRIORITYMGMTTYPE* sPriorityMgmt;
-    
-    /*  RMPROXY_CALLBACKTYPE rmproxyCallback; */
+
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
+
     OMX_BOOL bPreempted;
 
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef[WBAMRENC_NUM_OF_PORTS];
@@ -637,9 +596,9 @@
 
     OMX_U32 nMultiFrameMode;
 
-    OMX_U32 fdwrite;
+    OMX_S32 fdwrite;
 
-    OMX_U32 fdread;
+    OMX_S32 fdread;
 
     /** Set to indicate component is stopping */
     OMX_U32 bIsThreadstop;
@@ -666,8 +625,8 @@
 
     OMX_U32 amrMimeBytes[16];
 
-    OMX_U32 amrIf2Bytes[16];     
-    
+    OMX_U32 amrIf2Bytes[16];
+
     OMX_U32 iHoldLen;
 
     OMX_U32 nHoldLength;
@@ -710,6 +669,8 @@
 
     WBAMRENC_TALGCtrl *pAlgParam;
 
+    WBAMRENC_TALGCtrlDTX *pAlgParamDTX;
+
     WBAMRENC_AudioCodecParams *pParams;
 
     OMX_STRING cComponentName;
@@ -722,7 +683,7 @@
 
     OMX_BUFFERHEADERTYPE *iMMFDataLastBuffer;
 
-    OMX_U8* pHoldBuffer,*pHoldBuffer2;
+    OMX_U8* pHoldBuffer, *pHoldBuffer2;
 
     OMX_U8* iHoldBuffer;
 
@@ -731,11 +692,11 @@
     OMX_U32 bNoIdleOnStop;
 
     /** Flag set when socket node is stopped */
-    OMX_U32 bDspStoppedWhileExecuting;  
-    
+    OMX_U32 bDspStoppedWhileExecuting;
+
     /** Number of outstanding FillBufferDone() calls */
     OMX_S32 nOutStandingFillDones;
-    
+
     OMX_S32 nOutStandingEmptyDones;
 
 #ifndef UNDER_CE
@@ -752,7 +713,7 @@
     OMX_U8 InIdle_goingtoloaded;
 
     pthread_mutex_t ToLoaded_mutex;
-    /*    
+    /*
           sem_t allobuf;
           sem_t inloaded;
           sem_t inidle;
@@ -783,21 +744,21 @@
 
     OMX_STRING* sDeviceString;
     void* ptrLibLCML;
-    
+
     /** Circular array to keep buffer timestamps */
-    OMX_S64 arrBufIndex[WBAMRENC_MAX_NUM_OF_BUFS]; 
+    OMX_S64 arrBufIndex[WBAMRENC_MAX_NUM_OF_BUFS];
     /** Circular array to keep buffer nTickCounts */
-    OMX_S64 arrTickCount[WBAMRENC_MAX_NUM_OF_BUFS]; 
+    OMX_S64 arrTickCount[WBAMRENC_MAX_NUM_OF_BUFS];
     /** Index to arrBufIndex[], used for input buffer timestamps */
     OMX_U8 IpBufindex;
     /** Index to arrBufIndex[], used for output buffer timestamps */
-    OMX_U8 OpBufindex;  
-    
+    OMX_U8 OpBufindex;
+
     OMX_S8 ProcessingInputBuf;
-    OMX_S8 ProcessingOutputBuf;    
-    
+    OMX_S8 ProcessingOutputBuf;
+
     OMX_BOOL bLoadedCommandPending;
-    
+
     OMX_PARAM_COMPONENTROLETYPE componentRole;
 
     /* Pointer to OpenCore capabilities structure */
@@ -877,9 +838,9 @@
 */
 /* =================================================================================== */
 OMX_ERRORTYPE WBAMRENC_GetCorrespondingLCMLHeader(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate,
-                                                  OMX_U8 *pBuffer,
-                                                  OMX_DIRTYPE eDir,
-                                                  WBAMRENC_LCML_BUFHEADERTYPE **ppLcmlHdr);
+        OMX_U8 *pBuffer,
+        OMX_DIRTYPE eDir,
+        WBAMRENC_LCML_BUFHEADERTYPE **ppLcmlHdr);
 /* =================================================================================== */
 /**
 *  WBAMRENC_LCMLCallback() Callback from LCML
@@ -909,8 +870,8 @@
 */
 /* =================================================================================== */
 OMX_ERRORTYPE WBAMRENC_FillLCMLInitParams(OMX_HANDLETYPE pHandle,
-                                          LCML_DSP *plcml_Init,
-                                          OMX_U16 arr[]);
+        LCML_DSP *plcml_Init,
+        OMX_U16 arr[]);
 /* =================================================================================== */
 /**
 *  WBAMRENC_GetBufferDirection() Returns direction of pBufHeader
@@ -926,7 +887,7 @@
 */
 /* =================================================================================== */
 OMX_ERRORTYPE WBAMRENC_GetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader,
-                                          OMX_DIRTYPE *eDir);
+        OMX_DIRTYPE *eDir);
 /* ===========================================================  */
 /**
 *  WBAMRENC_HandleCommand()  Handles commands sent via SendCommand()
@@ -940,8 +901,8 @@
 */
 /* =================================================================================== */
 OMX_U32 WBAMRENC_HandleCommand(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate,
-                                OMX_COMMANDTYPE cmd,
-                                OMX_U32 cmdData);
+                               OMX_COMMANDTYPE cmd,
+                               OMX_U32 cmdData);
 /* =================================================================================== */
 /**
 *  WBAMRENC_HandleDataBufFromApp()  Handles data buffers received
@@ -956,7 +917,7 @@
 */
 /* =================================================================================== */
 OMX_ERRORTYPE WBAMRENC_HandleDataBufFromApp(OMX_BUFFERHEADERTYPE *pBufHeader,
-                                            WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate);
+        WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate);
 /* =================================================================================== */
 /**
 *  WBAMRENC_GetLCMLHandle()  Get the handle to the LCML
@@ -1071,7 +1032,11 @@
 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle, int size, void* pArmPtr, DMM_BUFFER_OBJ* pDmmBuf, struct OMX_TI_Debug dbg);
 OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg);
 
-/* void WBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData); */
+#ifdef RESOURCE_MANAGER_ENABLED
+void WBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
+
+void WBAMRENC_HandleUSNError (WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
 
 /*===============================================================*/
 
@@ -1083,10 +1048,9 @@
     IUALG_CMD_USERSETCMDSTART  = 100,
     IUALG_CMD_USERGETCMDSTART  = 150,
     IUALG_CMD_FLUSH            = 0x100
-}IUALG_Cmd;
+} IUALG_Cmd;
 
-typedef enum
-{
+typedef enum {
     ALGCMD_BITRATE = IUALG_CMD_USERSETCMDSTART,
     ALGCMD_DTX
 
diff --git a/omx/audio/src/openmax_il/wbamr_enc/inc/OMX_WbAmrEncoder.h b/omx/audio/src/openmax_il/wbamr_enc/inc/OMX_WbAmrEncoder.h
index 626de72..78de670 100644
--- a/omx/audio/src/openmax_il/wbamr_enc/inc/OMX_WbAmrEncoder.h
+++ b/omx/audio/src/openmax_il/wbamr_enc/inc/OMX_WbAmrEncoder.h
@@ -146,6 +146,6 @@
     OMX_IndexCustomWbAmrEncStreamIDConfig,
     OMX_WbIndexCustomDataPath,
     OMX_IndexCustomDebug
-}WBAMRENC_OMX_INDEXAUDIOTYPE;
+} WBAMRENC_OMX_INDEXAUDIOTYPE;
 
 #endif /* OMX_WBAMRENCODER_H */
diff --git a/omx/audio/src/openmax_il/wbamr_enc/inc/wbamrencsocket_ti.h b/omx/audio/src/openmax_il/wbamr_enc/inc/wbamrencsocket_ti.h
index 2a6a49d..c1e5cb0 100644
--- a/omx/audio/src/openmax_il/wbamr_enc/inc/wbamrencsocket_ti.h
+++ b/omx/audio/src/openmax_il/wbamr_enc/inc/wbamrencsocket_ti.h
@@ -18,32 +18,32 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
-/* =============================================================================

-*             Texas Instruments OMAP(TM) Platform Software

-*  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.

-*

-*  Use of this software is controlled by the terms and conditions found

-*  in the license agreement under which this software has been supplied.

-* ============================================================================

-* */

-/**

-* @file wbamrencsocket_ti.h

-*

-* Auto-generated UUID structures for DSP/BIOS Bridge nodes.

-* Do not modify.

-*

-* @path $(CSLPATH)\

-*

-* @rev 0.1

-*/

+/* =============================================================================
+*             Texas Instruments OMAP(TM) Platform Software
+*  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
+*
+*  Use of this software is controlled by the terms and conditions found
+*  in the license agreement under which this software has been supplied.
+* ============================================================================
+* */
+/**
+* @file wbamrencsocket_ti.h
+*
+* Auto-generated UUID structures for DSP/BIOS Bridge nodes.
+* Do not modify.
+*
+* @path $(CSLPATH)\
+*
+* @rev 0.1
+*/
 /* ---------------------------------------------------------------------------

  * */

 #ifndef WBAMRENCSOCKET_TI_H

 #define WBAMRENCSOCKET_TI_H

 /* This variable specifies UUID of WBAMR Encoder Socket Node */

 struct DSP_UUID WBAMRENCSOCKET_TI_UUID = {

-	0xc452fc78, 0x764d, 0x4f3c, 0x97, 0xdd, {

-	0x17, 0x27, 0xfc, 0xcd, 0x7f, 0xe9

+    0xc452fc78, 0x764d, 0x4f3c, 0x97, 0xdd, {

+        0x17, 0x27, 0xfc, 0xcd, 0x7f, 0xe9

     }

 };

 #endif /* WBAMRENCSOCKET_TI_H */

diff --git a/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEnc_CompThread.c b/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEnc_CompThread.c
index 2ddf6a0..4cac76e 100644
--- a/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEnc_CompThread.c
+++ b/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEnc_CompThread.c
@@ -86,8 +86,7 @@
 */
 /* ================================================================================ */
 
-void* WBAMRENC_CompThread(void* pThreadData)
-{
+void* WBAMRENC_CompThread(void* pThreadData) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     int status;
     struct timespec tv;
@@ -98,16 +97,16 @@
     OMX_BUFFERHEADERTYPE *pBufHeader = NULL;
     WBAMRENC_COMPONENT_PRIVATE* pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE*)pThreadData;
     OMX_COMPONENTTYPE *pHandle = pComponentPrivate->pHandle;
-    
+
     OMX_U32 commandData;
     OMX_COMMANDTYPE command;
-    
+
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
 
 #ifdef __PERF_INSTRUMENTATION__
     pComponentPrivate->pPERFcomp = PERF_Create(PERF_FOURCC('W', 'B', 'E', '_'),
-                                               PERF_ModuleComponent |
-                                               PERF_ModuleAudioDecode);
+                                   PERF_ModuleComponent |
+                                   PERF_ModuleAudioDecode);
 #endif
 
     fdmax = pComponentPrivate->cmdPipe[0];
@@ -128,72 +127,80 @@
         sigset_t set;
         sigemptyset (&set);
         sigaddset (&set, SIGALRM);
-        status = pselect (fdmax+1, &rfds, NULL, NULL, &tv, &set);
+        status = pselect (fdmax + 1, &rfds, NULL, NULL, &tv, &set);
 #else
-        status = select (fdmax+1, &rfds, NULL, NULL, &tv);
+        status = select (fdmax + 1, &rfds, NULL, NULL, &tv);
 #endif
 
         if (pComponentPrivate->bIsThreadstop == 1) {
             OMX_ERROR4(pComponentPrivate->dbg, "Comp Thrd Exiting!\n");
             goto EXIT;
         }
+
         if (0 == status) {
             if (pComponentPrivate->bIsThreadstop == 1)  {
                 pComponentPrivate->bIsThreadstop = 0;
                 pComponentPrivate->lcml_nOpBuf = 0;
                 pComponentPrivate->lcml_nIpBuf = 0;
                 pComponentPrivate->app_nBuf = 0;
+
                 if (pComponentPrivate->curState != OMX_StateIdle) {
                     OMX_ERROR4(pComponentPrivate->dbg, "curState is not OMX_StateIdle\n");
                     goto EXIT;
                 }
             }
+
             OMX_PRINT2(pComponentPrivate->dbg, "Component Time Out !!!!! \n");
-        } else if(-1 == status) {
+        } else if (-1 == status) {
             OMX_ERROR4(pComponentPrivate->dbg, "Error in Select\n");
             pComponentPrivate->cbInfo.EventHandler ( pHandle,
-                                                     pHandle->pApplicationPrivate,
-                                                     OMX_EventError,
-                                                     OMX_ErrorInsufficientResources,
-                                                     OMX_TI_ErrorSevere,
-                                                     "Error from Component Thread in select");
-            eError = OMX_ErrorInsufficientResources; 
-            break;
-        } 
-        else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) {
+                    pHandle->pApplicationPrivate,
+                    OMX_EventError,
+                    OMX_ErrorInsufficientResources,
+                    OMX_TI_ErrorSevere,
+                    "Error from Component Thread in select");
+            eError = OMX_ErrorInsufficientResources;
+        } else if ((FD_ISSET (pComponentPrivate->dataPipe[0], &rfds))) {
             OMX_PRCOMM2(pComponentPrivate->dbg, "DATA pipe is set in Component Thread\n");
 
             ret = read(pComponentPrivate->dataPipe[0], &pBufHeader, sizeof(pBufHeader));
+
             if (ret == -1) {
                 OMX_ERROR4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
                 goto EXIT;
             }
-            eError = WBAMRENC_HandleDataBufFromApp(pBufHeader,pComponentPrivate);
+
+            eError = WBAMRENC_HandleDataBufFromApp(pBufHeader, pComponentPrivate);
+
             if (eError != OMX_ErrorNone) {
                 OMX_ERROR2(pComponentPrivate->dbg, "WBAMRENC_HandleDataBufFromApp returned error\n");
                 break;
             }
-        }
-        else if(FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) {
+        } else if (FD_ISSET (pComponentPrivate->cmdPipe[0], &rfds)) {
             /* Do not accept any command when the component is stopping */
             OMX_PRINT1(pComponentPrivate->dbg, "CMD pipe is set in Component Thread\n");
             ret = read(pComponentPrivate->cmdPipe[0], &command, sizeof (command));
+
             if (ret == -1) {
                 OMX_ERROR4(pComponentPrivate->dbg, "Error in Reading from the Data pipe\n");
                 eError = OMX_ErrorHardware;
                 goto EXIT;
             }
+
             ret = read(pComponentPrivate->cmdDataPipe[0], &commandData, sizeof (commandData));
+
             if (ret == -1) {
                 OMX_ERROR4(pComponentPrivate->dbg, "Error in Reading from the Data pipe\n");
                 eError = OMX_ErrorHardware;
                 goto EXIT;
             }
-            nRet = WBAMRENC_HandleCommand(pComponentPrivate,command,commandData);
+
+            nRet = WBAMRENC_HandleCommand(pComponentPrivate, command, commandData);
+
             if (nRet == WBAMRENC_EXIT_COMPONENT_THRD) {
                 pComponentPrivate->curState = OMX_StateLoaded;
 #ifdef __PERF_INSTRUMENTATION__
-                PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup);
+                PERF_Boundary(pComponentPrivate->pPERFcomp, PERF_BoundaryComplete | PERF_BoundaryCleanup);
 #endif
 
                 if (pComponentPrivate->bPreempted == 0) {
@@ -203,8 +210,7 @@
                                                             OMX_ErrorNone,
                                                             pComponentPrivate->curState,
                                                             NULL);
-                }
-                else {
+                } else {
                     pComponentPrivate->cbInfo.EventHandler( pHandle,
                                                             pHandle->pApplicationPrivate,
                                                             OMX_EventError,
@@ -213,17 +219,18 @@
                                                             NULL);
                     pComponentPrivate->bPreempted = 0;
                 }
-                    
+
             }
         }
     }
- EXIT:
+
+EXIT:
 #ifdef __PERF_INSTRUMENTATION__
     PERF_Done(pComponentPrivate->pPERFcomp);
 #endif
 
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting WBAMRENC_CompThread\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return (void*)eError;
 }
 
diff --git a/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEnc_Utils.c b/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEnc_Utils.c
index d8a984d..8713be8 100644
--- a/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEnc_Utils.c
+++ b/omx/audio/src/openmax_il/wbamr_enc/src/OMX_WbAmrEnc_Utils.c
@@ -86,66 +86,6 @@
 #include <ResourceManagerProxyAPI.h>
 #endif
 
-#ifdef WBAMRENC_DEBUGMEM
- void *arr[500];
- int lines[500];
- int bytes[500];
- char file[500][50];
-
-
-void * mymalloc(int line, char *s, int size);
-int mynewfree(void *dp, int line, char *s);
-
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-
-void * mymalloc(int line, char *s, int size)
-{
-    void *p;
-    int e=0;
-    /*   p = malloc(size);*/
-    p = calloc(1,size);
-    if(p==NULL){
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
-    }
-    else{
-        while((lines[e]!=0)&& (e<500) ){
-            e++;
-        }
-        arr[e]=p;
-        lines[e]=line;
-        bytes[e]=size;
-        strcpy(file[e],s);
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "Allocating %d bytes on address %p, line %d file %s\n", size, p, line, s);
-    }
-    return p;
-}
-
-int myfree(void *dp, int line, char *s){
-    int q;
-    if(dp==NULL){
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "NULL can't be deleted\n");
-        return 0;
-    }
-    for(q=0;q<500;q++){
-        if(arr[q]==dp){
-            OMXDBG_PRINT(stderr, ERROR, 4, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
-            free(dp);
-            dp = NULL;
-            lines[q]=0;
-            strcpy(file[q],"");
-            break;
-        }
-    }
-    if(500==q)
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
-    return 1;
-}
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
 /* ========================================================================== */
 /**
  * @WBAMRENC_FillLCMLInitParams () This function is used by the component thread to
@@ -164,17 +104,15 @@
 /* ========================================================================== */
 
 OMX_ERRORTYPE WBAMRENC_FillLCMLInitParams(OMX_HANDLETYPE pComponent,
-                                          LCML_DSP *plcml_Init, OMX_U16 arr[])
-{
+        LCML_DSP *plcml_Init, OMX_U16 arr[]) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
+    OMX_U32 nIpBuf, nIpBufSize, nOpBuf, nOpBufSize;
     OMX_BUFFERHEADERTYPE *pTemp;
     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
     WBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
     OMX_U32 i;
     OMX_U32 size_lcml;
-    OMX_U8 *pBufferParamTemp;
     char *pTemp_char = NULL;
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
@@ -189,13 +127,13 @@
     OMX_PRBUFFER2(pComponentPrivate->dbg,
                   "------ Buffer Details -----------\n");
     OMX_PRBUFFER2(pComponentPrivate->dbg,
-                  "Input  Buffer Count = %ld\n",nIpBuf);
+                  "Input  Buffer Count = %ld\n", nIpBuf);
     OMX_PRBUFFER2(pComponentPrivate->dbg,
-                  "Input  Buffer Size = %ld\n",nIpBufSize);
+                  "Input  Buffer Size = %ld\n", nIpBufSize);
     OMX_PRBUFFER2(pComponentPrivate->dbg,
-                  "Output Buffer Count = %ld\n",nOpBuf);
+                  "Output Buffer Count = %ld\n", nOpBuf);
     OMX_PRBUFFER2(pComponentPrivate->dbg,
-                  "Output Buffer Size = %ld\n",nOpBufSize);
+                  "Output Buffer Size = %ld\n", nOpBufSize);
     OMX_PRBUFFER2(pComponentPrivate->dbg,
                   "------ Buffer Details ------------\n");
     /* Fill Input Buffers Info for LCML */
@@ -212,11 +150,11 @@
     plcml_Init->NodeInfo.nNumOfDLLs = 3;
 
     plcml_Init->NodeInfo.AllUUIDs[0].uuid = &WBAMRENCSOCKET_TI_UUID;
-    strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName,WBAMRENC_DLL_NAME);
+    strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[0].DllName, WBAMRENC_DLL_NAME);
     plcml_Init->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
 
     plcml_Init->NodeInfo.AllUUIDs[1].uuid = &WBAMRENCSOCKET_TI_UUID;
-    strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName,WBAMRENC_DLL_NAME);
+    strcpy ((char*)plcml_Init->NodeInfo.AllUUIDs[1].DllName, WBAMRENC_DLL_NAME);
     plcml_Init->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
 
     plcml_Init->NodeInfo.AllUUIDs[2].uuid = &USN_TI_UUID;
@@ -225,10 +163,10 @@
     plcml_Init->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
     plcml_Init->DeviceInfo.TypeofDevice = 0;
 
-    if(pComponentPrivate->dasfMode == 1) {
+    if (pComponentPrivate->dasfMode == 1) {
         OMX_PRDSP2(pComponentPrivate->dbg,
                    "Codec is configuring to DASF mode\n");
-        WBAMRENC_OMX_MALLOC(pComponentPrivate->strmAttr, LCML_STRMATTR);
+        OMX_MALLOC_GENERIC(pComponentPrivate->strmAttr, LCML_STRMATTR);
         pComponentPrivate->strmAttr->uSegid = WBAMRENC_DEFAULT_SEGMENT;
         pComponentPrivate->strmAttr->uAlignment = 0;
         pComponentPrivate->strmAttr->uTimeout = WBAMRENC_SN_TIMEOUT;
@@ -240,14 +178,14 @@
         /* Device is Configuring to Record Mode */
         plcml_Init->DeviceInfo.TypeofRender = 1;
 
-        if(pComponentPrivate->acdnMode == 1) {
+        if (pComponentPrivate->acdnMode == 1) {
             /* ACDN mode */
             plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &ACDN_TI_UUID;
-        }
-        else {
+        } else {
             /* DASF/TeeDN mode */
             plcml_Init->DeviceInfo.AllUUIDs[0].uuid = &DCTN_TI_UUID;
         }
+
         plcml_Init->DeviceInfo.DspStream = pComponentPrivate->strmAttr;
     }
 
@@ -262,41 +200,38 @@
     arr[0] = WBAMRENC_STREAM_COUNT;
     arr[1] = WBAMRENC_INPUT_PORT;
 
-    if(pComponentPrivate->dasfMode == 1) {
+    if (pComponentPrivate->dasfMode == 1) {
         arr[2] = WBAMRENC_INSTRM;
         arr[3] = WBAMRENC_NUM_INPUT_BUFFERS_DASF;
-    }
-    else {
+    } else {
         arr[2] = WBAMRENC_DMM;
+
         if (pComponentPrivate->pInputBufferList->numBuffers) {
             arr[3] = (OMX_U16) pComponentPrivate->pInputBufferList->numBuffers;
-        }
-        else {
+        } else {
             arr[3] = 1;
         }
     }
 
     arr[4] = WBAMRENC_OUTPUT_PORT;
     arr[5] = WBAMRENC_DMM;
+
     if (pComponentPrivate->pOutputBufferList->numBuffers) {
         arr[6] = (OMX_U16) pComponentPrivate->pOutputBufferList->numBuffers;
-    }
-    else {
+    } else {
         arr[6] = 1;
     }
 
     OMX_PRDSP2(pComponentPrivate->dbg, "Codec is configuring to WBAMR mode\n");
     arr[7] = WBAMRENC_WBAMR;
 
-    if(pComponentPrivate->frameMode == WBAMRENC_MIMEMODE) {
+    if (pComponentPrivate->frameMode == WBAMRENC_MIMEMODE) {
         OMX_PRDSP2(pComponentPrivate->dbg, "Codec is configuring MIME mode\n");
         arr[8] = WBAMRENC_MIMEMODE;
-    }
-    else if(pComponentPrivate->frameMode == WBAMRENC_IF2 ){
+    } else if (pComponentPrivate->frameMode == WBAMRENC_IF2 ) {
         OMX_PRDSP2(pComponentPrivate->dbg, "Codec is configuring IF2 mode\n");
         arr[8] = WBAMRENC_IF2;
-    }
-    else {
+    } else {
         OMX_PRDSP2(pComponentPrivate->dbg,
                    "Codec is configuring FORMAT CONFORMANCE mode\n");
         arr[8] = WBAMRENC_FORMATCONFORMANCE;
@@ -311,10 +246,11 @@
     size_lcml = nIpBuf * sizeof(WBAMRENC_LCML_BUFHEADERTYPE);
 
 
-    WBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml,size_lcml,WBAMRENC_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, WBAMRENC_LCML_BUFHEADERTYPE);
 
     pComponentPrivate->pLcmlBufHeader[WBAMRENC_INPUT_PORT] = pTemp_lcml;
-    for (i=0; i<nIpBuf; i++) {
+
+    for (i = 0; i < nIpBuf; i++) {
         OMX_PRINT2(pComponentPrivate->dbg, "INPUT--------- Inside Ip Loop\n");
         pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
@@ -329,17 +265,15 @@
                       pTemp_lcml->buffer->pBuffer);
         pTemp_lcml->eDir = OMX_DirInput;
 
-        WBAMRENC_OMX_MALLOC_SIZE(pBufferParamTemp,
-                                 (sizeof(WBAMRENC_ParamStruct) + DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam ,
+                                 sizeof(WBAMRENC_ParamStruct),
                                  OMX_U8);
 
-        pTemp_lcml->pBufferParam =  (WBAMRENC_ParamStruct*)(pBufferParamTemp + EXTRA_BYTES);
+        pTemp_lcml->pBufferParam->usNbFrames = 0;
+        pTemp_lcml->pBufferParam->pParamElem = NULL;
+        pTemp_lcml->pFrameParam = NULL;
 
-        pTemp_lcml->pBufferParam->usNbFrames=0;
-        pTemp_lcml->pBufferParam->pParamElem=NULL;
-        pTemp_lcml->pFrameParam=NULL;
-
-        WBAMRENC_OMX_MALLOC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
+        OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
         pTemp->nFlags = WBAMRENC_NORMAL_BUFFER;
         pTemp++;
@@ -350,10 +284,11 @@
      * This memory pointer will be sent to LCML */
     size_lcml = nOpBuf * sizeof(WBAMRENC_LCML_BUFHEADERTYPE);
 
-    WBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,WBAMRENC_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, WBAMRENC_LCML_BUFHEADERTYPE);
 
     pComponentPrivate->pLcmlBufHeader[WBAMRENC_OUTPUT_PORT] = pTemp_lcml;
-    for (i=0; i<nOpBuf; i++) {
+
+    for (i = 0; i < nOpBuf; i++) {
         OMX_PRINT2(pComponentPrivate->dbg, "OUTPUT--------- Inside Op Loop\n");
         pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
@@ -369,19 +304,15 @@
                       pTemp_lcml->buffer->pBuffer);
         pTemp_lcml->eDir = OMX_DirOutput;
 
-        WBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml->pBufferParam,
-                                 (sizeof(WBAMRENC_ParamStruct)+DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
+                                 sizeof(WBAMRENC_ParamStruct),
                                  WBAMRENC_ParamStruct);
 
-        pTemp_char = (char*)pTemp_lcml->pBufferParam;
-        pTemp_char += EXTRA_BYTES;
-        pTemp_lcml->pBufferParam = (WBAMRENC_ParamStruct*)pTemp_char;
+        pTemp_lcml->pBufferParam->usNbFrames = 0;
+        pTemp_lcml->pBufferParam->pParamElem = NULL;
+        pTemp_lcml->pFrameParam = NULL;
 
-        pTemp_lcml->pBufferParam->usNbFrames=0;
-        pTemp_lcml->pBufferParam->pParamElem=NULL;
-        pTemp_lcml->pFrameParam=NULL;
-
-        WBAMRENC_OMX_MALLOC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
+        OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
         pTemp->nFlags = WBAMRENC_NORMAL_BUFFER;
         pTemp++;
@@ -395,9 +326,9 @@
 
 
     pComponentPrivate->bInitParamsInitialized = 1;
- EXIT:
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return eError;
 }
 
@@ -416,8 +347,7 @@
  */
 /* ========================================================================== */
 
-OMX_ERRORTYPE WBAMRENC_StartComponentThread(OMX_HANDLETYPE pComponent)
-{
+OMX_ERRORTYPE WBAMRENC_StartComponentThread(OMX_HANDLETYPE pComponent) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate =
@@ -439,14 +369,17 @@
 
     /* create the pipe used to send buffers to the thread */
     eError = pipe (pComponentPrivate->cmdDataPipe);
+
     if (eError) {
         eError = OMX_ErrorInsufficientResources;
         OMX_ERROR4(pComponentPrivate->dbg,
                    "Error while creating cmdDataPipe\n");
         goto EXIT;
     }
+
     /* create the pipe used to send buffers to the thread */
     eError = pipe (pComponentPrivate->dataPipe);
+
     if (eError) {
         eError = OMX_ErrorInsufficientResources;
         OMX_ERROR4(pComponentPrivate->dbg, "Error while creating dataPipe\n");
@@ -455,6 +388,7 @@
 
     /* create the pipe used to send commands to the thread */
     eError = pipe (pComponentPrivate->cmdPipe);
+
     if (eError) {
         eError = OMX_ErrorInsufficientResources;
         OMX_ERROR4(pComponentPrivate->dbg, "Error while creating cmdPipe\n");
@@ -473,15 +407,16 @@
                              WBAMRENC_CompThread,
                              pComponentPrivate);
 #endif
+
     if (eError || !pComponentPrivate->ComponentThread) {
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
 
     pComponentPrivate->bCompThreadStarted = 1;
- EXIT:
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return eError;
 }
 
@@ -500,40 +435,44 @@
  */
 /* ========================================================================== */
 
-OMX_ERRORTYPE WBAMRENC_FreeCompResources(OMX_HANDLETYPE pComponent)
-{
+OMX_ERRORTYPE WBAMRENC_FreeCompResources(OMX_HANDLETYPE pComponent) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_ERRORTYPE err = OMX_ErrorNone;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)
-        pHandle->pComponentPrivate;
+            pHandle->pComponentPrivate;
+
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
 
     if (pComponentPrivate->bCompThreadStarted) {
         OMX_PRDSP1(pComponentPrivate->dbg, "Closing pipes\n");
-        OMX_WBCLOSE_PIPE(pComponentPrivate->dataPipe[0],err);
-        OMX_WBCLOSE_PIPE(pComponentPrivate->dataPipe[1],err);
-        OMX_WBCLOSE_PIPE(pComponentPrivate->cmdPipe[0],err);
-        OMX_WBCLOSE_PIPE(pComponentPrivate->cmdPipe[1],err);
-        OMX_WBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[0],err);
-        OMX_WBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[1],err);
+        OMX_WBCLOSE_PIPE(pComponentPrivate->dataPipe[0], err);
+        OMX_WBCLOSE_PIPE(pComponentPrivate->dataPipe[1], err);
+        OMX_WBCLOSE_PIPE(pComponentPrivate->cmdPipe[0], err);
+        OMX_WBCLOSE_PIPE(pComponentPrivate->cmdPipe[1], err);
+        OMX_WBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[0], err);
+        OMX_WBCLOSE_PIPE(pComponentPrivate->cmdDataPipe[1], err);
     }
 
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, WBAMRENC_TALGCtrl);
+
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, WBAMRENC_AudioCodecParams);
+
     OMX_PRDSP1(pComponentPrivate->dbg, "Freeing private memory structures\n");
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pcmParams);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->amrParams);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pcmParams);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->amrParams);
 
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]);
 
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->sPortParam);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->sPriorityMgmt);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sPortParam);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sPriorityMgmt);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
 
 #ifndef UNDER_CE
     OMX_PRDSP1(pComponentPrivate->dbg, "Destroying mutexes\n");
@@ -550,9 +489,9 @@
     OMX_DestroyEvent(&(pComponentPrivate->InIdle_event));
     OMX_DestroyEvent(&(pComponentPrivate->AlloBuf_event));
 #endif
- EXIT:
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return eError;
 }
 
@@ -571,46 +510,40 @@
  */
 /* ========================================================================== */
 
-OMX_ERRORTYPE WBAMRENC_CleanupInitParams(OMX_HANDLETYPE pComponent)
-{
+OMX_ERRORTYPE WBAMRENC_CleanupInitParams(OMX_HANDLETYPE pComponent) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 nIpBuf = 0;
     OMX_U32 nOpBuf = 0;
     OMX_U32 i = 0;
     WBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml;
-    OMX_U8* pAlgParmTemp;
-    OMX_U8* pBufParmsTemp;
-    char *pTemp = NULL;
 
     LCML_DSP_INTERFACE *pLcmlHandle;
     LCML_DSP_INTERFACE *pLcmlHandleAux;
 
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)
-        pHandle->pComponentPrivate;
+            pHandle->pComponentPrivate;
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
 
-    if(pComponentPrivate->dasfMode == 1) {
-        OMX_WBMEMFREE_STRUCT(pComponentPrivate->strmAttr);
+    if (pComponentPrivate->dasfMode == 1) {
+        OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
     }
-    pAlgParmTemp = (OMX_U8*)pComponentPrivate->pAlgParam;
-    if (pAlgParmTemp != NULL){
-        pAlgParmTemp -= EXTRA_BYTES;
-    }
-    pComponentPrivate->pAlgParam = (WBAMRENC_TALGCtrl*)pAlgParmTemp;
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pAlgParam);
 
-    if(pComponentPrivate->nMultiFrameMode == 1) {
-        OMX_WBMEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
-        OMX_WBMEMFREE_STRUCT(pComponentPrivate->iHoldBuffer);
-        OMX_WBMEMFREE_STRUCT(pComponentPrivate->iMMFDataLastBuffer);
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, WBAMRENC_TALGCtrl);
+
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParamDTX, WBAMRENC_TALGCtrlDTX);
+
+    if (pComponentPrivate->nMultiFrameMode == 1) {
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->iHoldBuffer);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->iMMFDataLastBuffer);
     }
 
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[WBAMRENC_INPUT_PORT];
     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
 
-    for(i=0; i<nIpBuf; i++) {
-        if(pTemp_lcml->pFrameParam!=NULL){
+    for (i = 0; i < nIpBuf; i++) {
+        if (pTemp_lcml->pFrameParam != NULL) {
 
             pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
             pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
@@ -618,33 +551,26 @@
                          (void*)pTemp_lcml->pBufferParam->pParamElem,
                          pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
 
-            pBufParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam;
-            pBufParmsTemp -= EXTRA_BYTES;
-            OMX_WBMEMFREE_STRUCT(pBufParmsTemp);
-            pBufParmsTemp = NULL;
-            pTemp_lcml->pFrameParam = NULL;
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, OMX_U8);
         }
 
-        pTemp = (char*)pTemp_lcml->pBufferParam;
-        if (pTemp != NULL) {
-            pTemp -= EXTRA_BYTES;
-        }
-        pTemp_lcml->pBufferParam = (WBAMRENC_ParamStruct*)pTemp;
-        OMX_WBMEMFREE_STRUCT(pTemp_lcml->pBufferParam);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, WBAMRENC_ParamStruct);
 
 
-        if(pTemp_lcml->pDmmBuf!=NULL){
-            OMX_WBMEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
+        if (pTemp_lcml->pDmmBuf != NULL) {
+            OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
             pTemp_lcml->pDmmBuf = NULL;
         }
+
         pTemp_lcml++;
     }
 
     pTemp_lcml = pComponentPrivate->pLcmlBufHeader[WBAMRENC_OUTPUT_PORT];
     nOpBuf = pComponentPrivate->nRuntimeOutputBuffers;
-    for(i=0; i<nOpBuf; i++) {
 
-        if(pTemp_lcml->pFrameParam!=NULL){
+    for (i = 0; i < nOpBuf; i++) {
+
+        if (pTemp_lcml->pFrameParam != NULL) {
             pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
             pLcmlHandleAux = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 #ifndef UNDER_CE
@@ -653,32 +579,25 @@
                          pTemp_lcml->pDmmBuf->pReserved, pComponentPrivate->dbg);
 #endif
 
-            pBufParmsTemp = (OMX_U8*)pTemp_lcml->pFrameParam;
-            pBufParmsTemp -= EXTRA_BYTES;
-            OMX_WBMEMFREE_STRUCT(pBufParmsTemp);
-            pBufParmsTemp = NULL;
-            pTemp_lcml->pFrameParam = NULL;
 
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pFrameParam, OMX_U8);
         }
 
-        pTemp = (char*)pTemp_lcml->pBufferParam;
-        if (pTemp != NULL) {
-            pTemp -= EXTRA_BYTES;
-        }
-        pTemp_lcml->pBufferParam = (WBAMRENC_ParamStruct*)pTemp;
-        OMX_WBMEMFREE_STRUCT(pTemp_lcml->pBufferParam);
-        if(pTemp_lcml->pDmmBuf!=NULL){
-            OMX_WBMEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pBufferParam, WBAMRENC_ParamStruct);
+
+        if (pTemp_lcml->pDmmBuf != NULL) {
+            OMX_MEMFREE_STRUCT(pTemp_lcml->pDmmBuf);
             pTemp_lcml->pDmmBuf = NULL;
         }
+
         pTemp_lcml++;
     }
 
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[WBAMRENC_INPUT_PORT]);
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[WBAMRENC_OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[WBAMRENC_INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[WBAMRENC_OUTPUT_PORT]);
 
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return eError;
 }
 
@@ -697,35 +616,37 @@
  */
 /* ========================================================================== */
 
-OMX_ERRORTYPE WBAMRENC_StopComponentThread(OMX_HANDLETYPE pComponent)
-{
+OMX_ERRORTYPE WBAMRENC_StopComponentThread(OMX_HANDLETYPE pComponent) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_ERRORTYPE threadError = OMX_ErrorNone;
     int pthreadError = 0;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)pComponent;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)
-        pHandle->pComponentPrivate;
+            pHandle->pComponentPrivate;
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
     pComponentPrivate->bIsThreadstop = 1;
     OMX_PRINT2(pComponentPrivate->dbg, "About to call pthread_join\n");
     write (pComponentPrivate->cmdPipe[1], &pComponentPrivate->bIsThreadstop, sizeof(OMX_U16));
     pthreadError = pthread_join (pComponentPrivate->ComponentThread,
-                                 (void*)&threadError);
+                                 (void*) & threadError);
+
     if (0 != pthreadError) {
         eError = OMX_ErrorHardware;
         OMX_ERROR4(pComponentPrivate->dbg,
-                   "Error closing ComponentThread - pthreadError = %d\n",pthreadError);
+                   "Error closing ComponentThread - pthreadError = %d\n", pthreadError);
         goto EXIT;
     }
+
     if (OMX_ErrorNone != threadError && OMX_ErrorNone != eError) {
         eError = OMX_ErrorInsufficientResources;
         OMX_ERROR4(pComponentPrivate->dbg,
                    "Error while closing Component Thread\n");
         goto EXIT;
     }
- EXIT:
+
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return eError;
 }
 
@@ -747,8 +668,7 @@
 
 OMX_U32 WBAMRENC_HandleCommand (WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate,
                                 OMX_COMMANDTYPE cmd,
-                                OMX_U32 cmdData)
-{
+                                OMX_U32 cmdData) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMMANDTYPE command = cmd;
     OMX_STATETYPE commandedState;
@@ -763,10 +683,8 @@
     OMX_U32 commandData = cmdData;
     OMX_U16 arr[100];
     char *pArgs = "damedesuStr";
-    OMX_U8* pParmsTemp;
-    OMX_U8* pAlgParmTemp;
     OMX_U32 i = 0;
-    OMX_U8 inputPortFlag=0,outputPortFlag=0;
+    OMX_U8 inputPortFlag = 0, outputPortFlag = 0;
     WBAMRENC_LCML_BUFHEADERTYPE *pLcmlHdr = NULL;
 
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
@@ -782,182 +700,193 @@
                          commandData,
                          PERF_ModuleLLMM);
 #endif
+
     if (command == OMX_CommandStateSet) {
         commandedState = (OMX_STATETYPE)commandData;
-        if (pComponentPrivate->curState == commandedState){
+
+        if (pComponentPrivate->curState == commandedState) {
             pComponentPrivate->cbInfo.EventHandler ( pHandle,
-                                                     pHandle->pApplicationPrivate,
-                                                     OMX_EventError,
-                                                     OMX_ErrorSameState,
-                                                     OMX_TI_ErrorMinor,
-                                                     NULL);
+                    pHandle->pApplicationPrivate,
+                    OMX_EventError,
+                    OMX_ErrorSameState,
+                    OMX_TI_ErrorMinor,
+                    NULL);
             OMX_ERROR4(pComponentPrivate->dbg,
                        "OMX_ErrorSameState Given by Comp\n");
-        }else{
-            switch(commandedState) {
-            case OMX_StateIdle:
-                OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StateIdle \n");
-                OMX_PRSTATE2(pComponentPrivate->dbg,
-                             "curState = %d\n",
-                             pComponentPrivate->curState);
-                if (pComponentPrivate->curState == OMX_StateLoaded) {
+        } else {
+            switch (commandedState) {
+                case OMX_StateIdle:
+                    OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StateIdle \n");
                     OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "OMX_StateLoaded -> OMX_StateIdle \n");
+                                 "curState = %d\n",
+                                 pComponentPrivate->curState);
+
+                    if (pComponentPrivate->curState == OMX_StateLoaded) {
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "OMX_StateLoaded -> OMX_StateIdle \n");
 #ifdef __PERF_INSTRUMENTATION__
-                    PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySetup);
+                        PERF_Boundary(pComponentPrivate->pPERFcomp, PERF_BoundaryStart | PERF_BoundarySetup);
 #endif
 
-                    if (pComponentPrivate->dasfMode == 1) {
-                        pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled= FALSE;
-                        pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated= FALSE;
-                        if(pComponentPrivate->streamID == 0) {
-                            OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n");
-                            OMX_ERROR4(pComponentPrivate->dbg, "Error = OMX_ErrorInsufficientResources\n");
-                            OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n");
-                            eError = OMX_ErrorInsufficientResources;
-                            pComponentPrivate->curState = OMX_StateInvalid;
-                            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                                   pHandle->pApplicationPrivate,
-                                                                   OMX_EventError,
-                                                                   OMX_ErrorInvalidState,
-                                                                   OMX_TI_ErrorMajor,
-                                                                   "No Stream ID Available");
+                        if (pComponentPrivate->dasfMode == 1) {
+                            pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled = FALSE;
+                            pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated = FALSE;
+
+                            if (pComponentPrivate->streamID == 0) {
+                                OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n");
+                                OMX_ERROR4(pComponentPrivate->dbg, "Error = OMX_ErrorInsufficientResources\n");
+                                OMX_ERROR4(pComponentPrivate->dbg, "**************************************\n");
+                                eError = OMX_ErrorInsufficientResources;
+                                pComponentPrivate->curState = OMX_StateInvalid;
+                                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                                                                       pHandle->pApplicationPrivate,
+                                                                       OMX_EventError,
+                                                                       OMX_ErrorInvalidState,
+                                                                       OMX_TI_ErrorMajor,
+                                                                       "No Stream ID Available");
+                                goto EXIT;
+                            }
+                        }
+
+                        if (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated &&
+                                pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled)  {
+                            inputPortFlag = 1;
+                        }
+
+                        if (pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated &&
+                                pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled) {
+                            outputPortFlag = 1;
+                        }
+
+                        if (!pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated &&
+                                !pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled)  {
+                            inputPortFlag = 1;
+                        }
+
+                        if (!pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated &&
+                                !pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled) {
+                            outputPortFlag = 1;
+                        }
+
+                        if (!(inputPortFlag && outputPortFlag)) {
+                            pComponentPrivate->InLoaded_readytoidle = 1;
+#ifndef UNDER_CE
+                            pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
+                            pthread_cond_wait(&pComponentPrivate->InLoaded_threshold,
+                                              &pComponentPrivate->InLoaded_mutex);
+                            pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
+#else
+                            OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
+#endif
+                        }
+
+                        cb.LCML_Callback = (void *) WBAMRENC_LCMLCallback;
+                        pLcmlHandle = (OMX_HANDLETYPE) WBAMRENC_GetLCMLHandle(pComponentPrivate);
+
+                        if (pLcmlHandle == NULL) {
+                            OMX_ERROR4(pComponentPrivate->dbg,
+                                       "LCML Handle is NULL........exiting..\n");
                             goto EXIT;
                         }
-                    }
 
-                    if (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated &&
-                        pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled)  {
-                        inputPortFlag = 1;
-                    }
-                    if (pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated &&
-                        pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled) {
-                        outputPortFlag = 1;
-                    }
-                    if (!pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated &&
-                        !pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled)  {
-                        inputPortFlag = 1;
-                    }
-                    if (!pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated &&
-                        !pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled) {
-                        outputPortFlag = 1;
-                    }
+                        /* Got handle of dsp via phandle filling information about DSP Specific things */
+                        pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
+                        eError = WBAMRENC_FillLCMLInitParams(pHandle, pLcmlDsp, arr);
 
-                    if(!(inputPortFlag && outputPortFlag)){
-                        pComponentPrivate->InLoaded_readytoidle = 1;
-#ifndef UNDER_CE
-                        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
-                        pthread_cond_wait(&pComponentPrivate->InLoaded_threshold,
-                                          &pComponentPrivate->InLoaded_mutex);
-                        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
-#else
-                        OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
-#endif
-                    }
+                        if (eError != OMX_ErrorNone) {
+                            OMX_ERROR4(pComponentPrivate->dbg,
+                                       "Error from WBAMRENCFill_LCMLInitParams()\n");
+                            goto EXIT;
+                        }
 
-                    cb.LCML_Callback = (void *) WBAMRENC_LCMLCallback;
-                    pLcmlHandle = (OMX_HANDLETYPE) WBAMRENC_GetLCMLHandle(pComponentPrivate);
-                    if (pLcmlHandle == NULL) {
-                        OMX_ERROR4(pComponentPrivate->dbg,
-                                   "LCML Handle is NULL........exiting..\n");
-                        goto EXIT;
-                    }
-
-                    /* Got handle of dsp via phandle filling information about DSP Specific things */
-                    pLcmlDsp = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
-                    eError = WBAMRENC_FillLCMLInitParams(pHandle, pLcmlDsp, arr);
-                    if(eError != OMX_ErrorNone) {
-                        OMX_ERROR4(pComponentPrivate->dbg,
-                                   "Error from WBAMRENCFill_LCMLInitParams()\n");
-                        goto EXIT;
-                    }
-
-                    pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
-                    cb.LCML_Callback = (void *) WBAMRENC_LCMLCallback;
+                        pComponentPrivate->pLcmlHandle = (LCML_DSP_INTERFACE *)pLcmlHandle;
+                        cb.LCML_Callback = (void *) WBAMRENC_LCMLCallback;
 
 #ifndef UNDER_CE
 
-                    OMX_PRDSP2(pComponentPrivate->dbg,
-                               "Calling LCML_InitMMCodecEx...\n");
+                        OMX_PRDSP2(pComponentPrivate->dbg,
+                                   "Calling LCML_InitMMCodecEx...\n");
 
-                    eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
-                                                pArgs,
-                                                &pLcmlHandle,
-                                                (void *)pArgs,
-                                                &cb,
-                                                (OMX_STRING)pComponentPrivate->sDeviceString);
+                        eError = LCML_InitMMCodecEx(((LCML_DSP_INTERFACE *)pLcmlHandle)->pCodecinterfacehandle,
+                                                    pArgs,
+                                                    &pLcmlHandle,
+                                                    (void *)pArgs,
+                                                    &cb,
+                                                    (OMX_STRING)pComponentPrivate->sDeviceString);
 #else
-                    eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                              pArgs,&pLcmlHandle,
-                                              (void *)pArgs,
-                                              &cb);
+                        eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                  pArgs, &pLcmlHandle,
+                                                  (void *)pArgs,
+                                                  &cb);
 #endif
 
-                    if(eError != OMX_ErrorNone) {
-                        OMX_ERROR4(pComponentPrivate->dbg ,"Error returned from LCML_InitMMCodecEx\n");
-                        /* send an event to client */
-                        /* client should unload the component if the codec is not able to load */
+                        if (eError != OMX_ErrorNone) {
+                            OMX_ERROR4(pComponentPrivate->dbg,
+                                       "Error returned from LCML_InitMMCodecEx\n");
+                            /* send an event to client */
+                            /* client should unload the component if the codec is not able to load */
                         eError = OMX_ErrorInvalidState;
-                        pComponentPrivate->cbInfo.EventHandler (pHandle,
-                                                            pHandle->pApplicationPrivate,
-                                                            OMX_EventError,
-                                                            eError,
-                                                            OMX_TI_ErrorSevere,
-                                                            NULL);
-                        goto EXIT;
-                    }
+                            pComponentPrivate->cbInfo.EventHandler (pHandle,
+                                                                    pHandle->pApplicationPrivate,
+                                                                    OMX_EventError,
+                                                                    eError,
+                                                                    OMX_TI_ErrorSevere,
+                                                                    NULL);
+                            goto EXIT;
+                        }
+
 #ifdef RESOURCE_MANAGER_ENABLED
-                    /* Need check the resource with RM */
+                        /* Need check the resource with RM */
 
-                    pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) WBAMRENC_ResourceManagerCallback;
+                        pComponentPrivate->rmproxyCallback.RMPROXY_Callback = (void *) WBAMRENC_ResourceManagerCallback;
 
-                    if (pComponentPrivate->curState != OMX_StateWaitForResources){
+                        if (pComponentPrivate->curState != OMX_StateWaitForResources) {
 
-                        rm_error = RMProxy_NewSendCommand(pHandle,
-                                                          RMProxy_RequestResource,
-                                                          OMX_WBAMR_Encoder_COMPONENT,
-                                                          WBAMRENC_CPU_LOAD,
-                                                          3456,
-                                                          &(pComponentPrivate->rmproxyCallback));
-                        if(rm_error == OMX_ErrorNone) {
-                            /* resource is available */
+                            rm_error = RMProxy_NewSendCommand(pHandle,
+                                                              RMProxy_RequestResource,
+                                                              OMX_WBAMR_Encoder_COMPONENT,
+                                                              WBAMRENC_CPU_LOAD,
+                                                              3456,
+                                                              &(pComponentPrivate->rmproxyCallback));
+
+                            if (rm_error == OMX_ErrorNone) {
+                                /* resource is available */
 #ifdef __PERF_INSTRUMENTATION__
-                            PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySetup);
+                                PERF_Boundary(pComponentPrivate->pPERFcomp, PERF_BoundaryComplete | PERF_BoundarySetup);
 #endif
-                            pComponentPrivate->curState = OMX_StateIdle;
+                                pComponentPrivate->curState = OMX_StateIdle;
 
                             /* Decrement reference count with signal enabled */
                             if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
                                 return OMX_ErrorUndefined;
                             }
 
-                            pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                                    pHandle->pApplicationPrivate,
-                                                                    OMX_EventCmdComplete,
-                                                                    OMX_CommandStateSet,
-                                                                    pComponentPrivate->curState,
-                                                                    NULL);
+                                pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                        pHandle->pApplicationPrivate,
+                                                                        OMX_EventCmdComplete,
+                                                                        OMX_CommandStateSet,
+                                                                        pComponentPrivate->curState,
+                                                                        NULL);
 
-                            rm_error = RMProxy_NewSendCommand(pHandle,
-                                                              RMProxy_StateSet,
-                                                              OMX_WBAMR_Encoder_COMPONENT,
-                                                              OMX_StateIdle,
-                                                              3456,
-                                                              NULL);
-                        }
-                        else if(rm_error == OMX_ErrorInsufficientResources) {
-                            /* resource is not available, need set state to OMX_StateWaitForResources */
-                            pComponentPrivate->curState = OMX_StateWaitForResources;
-                            pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                                    pHandle->pApplicationPrivate,
-                                                                    OMX_EventCmdComplete,
-                                                                    OMX_CommandStateSet,
-                                                                    pComponentPrivate->curState,
-                                                                    NULL);
-                            OMX_ERROR4(pComponentPrivate->dbg,
-                                       "Comp: OMX_ErrorInsufficientResources\n");
-                        }
-                    }else{
+                                rm_error = RMProxy_NewSendCommand(pHandle,
+                                                                  RMProxy_StateSet,
+                                                                  OMX_WBAMR_Encoder_COMPONENT,
+                                                                  OMX_StateIdle,
+                                                                  3456,
+                                                                  NULL);
+                            } else if (rm_error == OMX_ErrorInsufficientResources) {
+                                /* resource is not available, need set state to OMX_StateWaitForResources */
+                                pComponentPrivate->curState = OMX_StateWaitForResources;
+                                pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                        pHandle->pApplicationPrivate,
+                                                                        OMX_EventCmdComplete,
+                                                                        OMX_CommandStateSet,
+                                                                        pComponentPrivate->curState,
+                                                                        NULL);
+                                OMX_ERROR4(pComponentPrivate->dbg,
+                                           "Comp: OMX_ErrorInsufficientResources\n");
+                            }
+                        } else {
 
                         pComponentPrivate->curState = OMX_StateIdle;
                         /* Decrement reference count with signal enabled */
@@ -965,98 +894,90 @@
                             return OMX_ErrorUndefined;
                         }
 
-                        pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                                pHandle->pApplicationPrivate,
-                                                                OMX_EventCmdComplete,
-                                                                OMX_CommandStateSet,
-                                                                pComponentPrivate->curState,
-                                                                NULL);
-                        rm_error = RMProxy_NewSendCommand(pHandle,
-                                                          RMProxy_StateSet,
-                                                          OMX_WBAMR_Encoder_COMPONENT,
-                                                          OMX_StateIdle,
-                                                          3456,
-                                                          NULL);
+                            pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                    pHandle->pApplicationPrivate,
+                                                                    OMX_EventCmdComplete,
+                                                                    OMX_CommandStateSet,
+                                                                    pComponentPrivate->curState,
+                                                                    NULL);
+                            rm_error = RMProxy_NewSendCommand(pHandle,
+                                                              RMProxy_StateSet,
+                                                              OMX_WBAMR_Encoder_COMPONENT,
+                                                              OMX_StateIdle,
+                                                              3456,
+                                                              NULL);
 
-                    }
+                        }
 
 #else
-                    pComponentPrivate->curState = OMX_StateIdle;
+                        pComponentPrivate->curState = OMX_StateIdle;
 
                     /* Decrement reference count with signal enabled */
                     if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
                          return OMX_ErrorUndefined;
                     }
 
-                    pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                            pHandle->pApplicationPrivate,
-                                                            OMX_EventCmdComplete,
-                                                            OMX_CommandStateSet,
-                                                            pComponentPrivate->curState,
-                                                            NULL);
-#endif
-
-
-#ifdef __PERF_INSTRUMENTATION__
-                    PERF_Boundary(pComponentPrivate->pPERFcomp,
-                                  PERF_BoundaryComplete | PERF_BoundarySetup);
-#endif
-
-
-                }
-                else if (pComponentPrivate->curState == OMX_StateExecuting) {
-                    OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "OMX_StateExecuting -> OMX_StateIdle \n");
-                    OMX_PRDSP1(pComponentPrivate->dbg,"Stop codec\n");
-                    OMX_PRINT2(pComponentPrivate->dbg,
-                               "Codec - MMCodecControlStop\n");
-#ifdef __PERF_INSTRUMENTATION__
-                    PERF_Boundary(pComponentPrivate->pPERFcomp,
-                                  PERF_BoundaryComplete | PERF_BoundarySteadyState);
-#endif
-                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                               MMCodecControlStop,
-                                               (void *)pArgs);
-
-                    pAlgParmTemp = (OMX_U8*)pComponentPrivate->pAlgParam;
-                    if (pAlgParmTemp != NULL)
-                        pAlgParmTemp -= EXTRA_BYTES;
-                    pComponentPrivate->pAlgParam = (WBAMRENC_TALGCtrl*)pAlgParmTemp;
-                    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pAlgParam);
-                    if (pComponentPrivate->pHoldBuffer) {
-                        OMX_WBMEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
-                        pComponentPrivate->pHoldBuffer = NULL;
-                    }
-                    pComponentPrivate->nOutStandingFillDones = 0;
-                    pComponentPrivate->nOutStandingEmptyDones = 0;
-                    pComponentPrivate->nHoldLength = 0;
-                    pComponentPrivate->InBuf_Eos_alreadysent = 0;
-                    pParmsTemp = (OMX_U8*)pComponentPrivate->pParams;
-                    if (pParmsTemp != NULL){
-                        pParmsTemp -= EXTRA_BYTES;
-                    }
-                    pComponentPrivate->pParams = (WBAMRENC_AudioCodecParams*)pParmsTemp;
-                    OMX_WBMEMFREE_STRUCT(pComponentPrivate->pParams);
-
-                    if(eError != OMX_ErrorNone) {
-                        OMX_ERROR4(pComponentPrivate->dbg,
-                                   "Error from LCML_ControlCodec MMCodecControlStop..\n");
-                        pComponentPrivate->curState = OMX_StateInvalid;
                         pComponentPrivate->cbInfo.EventHandler( pHandle,
                                                                 pHandle->pApplicationPrivate,
-                                                                OMX_EventError,
-                                                                eError,
-                                                                OMX_TI_ErrorSevere,
+                                                                OMX_EventCmdComplete,
+                                                                OMX_CommandStateSet,
+                                                                pComponentPrivate->curState,
                                                                 NULL);
-                        goto EXIT;
-                    }
+#endif
 
-                }
-                else if(pComponentPrivate->curState == OMX_StatePause) {
-                    OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "OMX_StatePause -> OMX_StateIdle \n");
 
-                    pComponentPrivate->curState = OMX_StateIdle;
+#ifdef __PERF_INSTRUMENTATION__
+                        PERF_Boundary(pComponentPrivate->pPERFcomp,
+                                      PERF_BoundaryComplete | PERF_BoundarySetup);
+#endif
+
+
+                    } else if (pComponentPrivate->curState == OMX_StateExecuting) {
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "OMX_StateExecuting -> OMX_StateIdle \n");
+                        OMX_PRDSP1(pComponentPrivate->dbg, "Stop codec\n");
+                        OMX_PRINT2(pComponentPrivate->dbg,
+                                   "Codec - MMCodecControlStop\n");
+#ifdef __PERF_INSTRUMENTATION__
+                        PERF_Boundary(pComponentPrivate->pPERFcomp,
+                                      PERF_BoundaryComplete | PERF_BoundarySteadyState);
+#endif
+                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                   MMCodecControlStop,
+                                                   (void *)pArgs);
+
+                        OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParam, WBAMRENC_TALGCtrl);
+                        OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pAlgParamDTX, WBAMRENC_TALGCtrlDTX);
+
+                        if (pComponentPrivate->pHoldBuffer) {
+                            OMX_MEMFREE_STRUCT(pComponentPrivate->pHoldBuffer);
+                            pComponentPrivate->pHoldBuffer = NULL;
+                        }
+
+                        pComponentPrivate->nOutStandingFillDones = 0;
+                        pComponentPrivate->nOutStandingEmptyDones = 0;
+                        pComponentPrivate->nHoldLength = 0;
+                        pComponentPrivate->InBuf_Eos_alreadysent = 0;
+                        OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, WBAMRENC_AudioCodecParams);
+
+                        if (eError != OMX_ErrorNone) {
+                            OMX_ERROR4(pComponentPrivate->dbg,
+                                       "Error from LCML_ControlCodec MMCodecControlStop..\n");
+                            pComponentPrivate->curState = OMX_StateInvalid;
+                            pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                    pHandle->pApplicationPrivate,
+                                                                    OMX_EventError,
+                                                                    eError,
+                                                                    OMX_TI_ErrorSevere,
+                                                                    NULL);
+                            goto EXIT;
+                        }
+
+                    } else if (pComponentPrivate->curState == OMX_StatePause) {
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "OMX_StatePause -> OMX_StateIdle \n");
+
+                        pComponentPrivate->curState = OMX_StateIdle;
 
                     /* Decrement reference count with signal enabled */
                     if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
@@ -1064,205 +985,224 @@
                     }
 
 #ifdef __PERF_INSTRUMENTATION__
-                    PERF_Boundary(pComponentPrivate->pPERFcomp,
-                                  PERF_BoundaryComplete | PERF_BoundarySteadyState);
+                        PERF_Boundary(pComponentPrivate->pPERFcomp,
+                                      PERF_BoundaryComplete | PERF_BoundarySteadyState);
 #endif
 #ifdef RESOURCE_MANAGER_ENABLED
-                    rm_error = RMProxy_NewSendCommand(pHandle,
-                                                      RMProxy_StateSet,
-                                                      OMX_WBAMR_Encoder_COMPONENT,
-                                                      OMX_StateIdle,
-                                                      3456,
-                                                      NULL);
+                        rm_error = RMProxy_NewSendCommand(pHandle,
+                                                          RMProxy_StateSet,
+                                                          OMX_WBAMR_Encoder_COMPONENT,
+                                                          OMX_StateIdle,
+                                                          3456,
+                                                          NULL);
 #endif
-                    OMX_PRINT1(pComponentPrivate->dbg,
-                               "The component is stopped\n");
-
-
-                    pComponentPrivate->cbInfo.EventHandler ( pHandle,
-                                                             pHandle->pApplicationPrivate,
-                                                             OMX_EventCmdComplete,
-                                                             OMX_CommandStateSet,
-                                                             pComponentPrivate->curState,
-                                                             NULL);
-                } else {    /* This means, it is invalid state from application */
-                    pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                            pHandle->pApplicationPrivate,
-                                                            OMX_EventError,
-                                                            OMX_ErrorIncorrectStateTransition,
-                                                            OMX_TI_ErrorMinor,
-                                                            "Invalid State");
-                    OMX_ERROR4(pComponentPrivate->dbg,
-                               "OMX_ErrorIncorrectStateTransition\n");
-                }
-                break;
-
-            case OMX_StateExecuting:
-                OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StateExecuting\n");
-                if (pComponentPrivate->curState == OMX_StateIdle) {
-                    /* Sending commands to DSP via LCML_ControlCodec third argument
-                       is not used for time being */
-                    OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "OMX_StateIdle -> OMX_StateExecuting\n");
-                    if( pComponentPrivate->pAlgParam == NULL){
-                        WBAMRENC_OMX_MALLOC_SIZE(pAlgParmTemp,
-                                                 sizeof(WBAMRENC_TALGCtrl) + DSP_CACHE_ALIGNMENT,
-                                                 OMX_U8);
-                        pComponentPrivate->pAlgParam = (WBAMRENC_TALGCtrl*)(pAlgParmTemp + EXTRA_BYTES);
-                        OMX_PRBUFFER2(pComponentPrivate->dbg,
-                                      "pAlgParam %p\n",pComponentPrivate->pAlgParam);
-                    }
-                    pComponentPrivate->nNumInputBufPending = 0;
-                    pComponentPrivate->nNumOutputBufPending = 0;
-
-                    pComponentPrivate->nNumOfFramesSent=0;
-
-                    pComponentPrivate->nEmptyBufferDoneCount = 0;
-                    pComponentPrivate->nEmptyThisBufferCount =0;
-
-                    pComponentPrivate->pAlgParam->iBitrate = pComponentPrivate->amrParams->eAMRBandMode;
-                    pComponentPrivate->pAlgParam->iDTX = pComponentPrivate->amrParams->eAMRDTXMode;
-                    pComponentPrivate->pAlgParam->iSize = sizeof (WBAMRENC_TALGCtrl);
-
-                    OMX_PRINT2(pComponentPrivate->dbg,
-                               "pAlgParam->iBitrate = %d\n",
-                               pComponentPrivate->pAlgParam->iBitrate);
-                    OMX_PRINT2(pComponentPrivate->dbg,
-                               "pAlgParam->iDTX  = %d\n",
-                               pComponentPrivate->pAlgParam->iDTX);
-
-                    cmdValues[0] = ALGCMD_BITRATE;                  /*setting the bit-rate*/
-                    cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParam;
-                    cmdValues[2] = sizeof (WBAMRENC_TALGCtrl);
-
-                    OMX_PRINT2(pComponentPrivate->dbg,
-                               "Codec - EMMCodecControlAlgCtrl\n");
-                    /* Sending ALGCTRL MESSAGE DTX to DSP via LCML_ControlCodec*/
-                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                               EMMCodecControlAlgCtrl,
-                                               (void *)cmdValues);
-                    if (eError != OMX_ErrorNone) {
+                        OMX_PRINT1(pComponentPrivate->dbg,
+                                   "The component is stopped\n");
+                        pComponentPrivate->cbInfo.EventHandler ( pHandle,
+                                pHandle->pApplicationPrivate,
+                                OMX_EventCmdComplete,
+                                OMX_CommandStateSet,
+                                pComponentPrivate->curState,
+                                NULL);
+                    } else {    /* This means, it is invalid state from application */
+                        pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                OMX_ErrorIncorrectStateTransition,
+                                                                OMX_TI_ErrorMinor,
+                                                                "Invalid State");
                         OMX_ERROR4(pComponentPrivate->dbg,
-                                   "Error from LCML_ControlCodec EMMCodecControlAlgCtrl = %x\n",eError);
-                        goto EXIT;
+                                   "OMX_ErrorIncorrectStateTransition\n");
                     }
 
-                    cmdValues[0] = ALGCMD_DTX; /*setting DTX mode*/
-                    cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParam;
-                    cmdValues[2] = sizeof (WBAMRENC_TALGCtrl);
+                    break;
 
-                    OMX_PRINT2(pComponentPrivate->dbg,
-                               "Codec - EMMCodecControlAlgCtrl\n");
-                    /* Sending ALGCTRL MESSAGE BITRATE to DSP via LCML_ControlCodec*/
-                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                               EMMCodecControlAlgCtrl,
-                                               (void *)cmdValues);
-                    if (eError != OMX_ErrorNone) {
-                        OMX_ERROR4(pComponentPrivate->dbg,
-                                   "Error from LCML_ControlCodec EMMCodecControlAlgCtrl = %x\n",eError);
-                        goto EXIT;
-                    }
-                    if(pComponentPrivate->dasfMode == 1) {
-                        OMX_PRDSP2(pComponentPrivate->dbg,
-                                   "---- Comp: DASF Functionality is ON ---\n");
+                case OMX_StateExecuting:
+                    OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StateExecuting\n");
 
-                        WBAMRENC_OMX_MALLOC_SIZE(pParmsTemp,
-                                                 sizeof(WBAMRENC_AudioCodecParams) + DSP_CACHE_ALIGNMENT,
-                                                 OMX_U8);
+                    if (pComponentPrivate->curState == OMX_StateIdle) {
+                        /* Sending commands to DSP via LCML_ControlCodec third argument
+                           is not used for time being */
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "OMX_StateIdle -> OMX_StateExecuting\n");
 
-                        pComponentPrivate->pParams = (WBAMRENC_AudioCodecParams*)(pParmsTemp + EXTRA_BYTES);
-                        OMX_PRBUFFER2(pComponentPrivate->dbg,
-                                      "pParams %p\n",pComponentPrivate->pParams);
+                        if ( pComponentPrivate->pAlgParam == NULL) {
+                            OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pAlgParam,
+                                                     sizeof(WBAMRENC_TALGCtrl),
+                                                     OMX_U8);
+                            OMX_PRBUFFER2(pComponentPrivate->dbg,
+                                          "pAlgParam %p\n", pComponentPrivate->pAlgParam);
+                        }
 
-                        pComponentPrivate->pParams->iAudioFormat = 1;
-                        pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID;
-                        pComponentPrivate->pParams->iSamplingRate = WBAMRENC_SAMPLING_FREQUENCY;
-                        pValues[0] = USN_STRMCMD_SETCODECPARAMS;
-                        pValues[1] = (OMX_U32)pComponentPrivate->pParams;
-                        pValues[2] = sizeof(WBAMRENC_AudioCodecParams);
-                        /* Sending STRMCTRL MESSAGE to DSP via LCML_ControlCodec*/
+                        if ( pComponentPrivate->pAlgParamDTX == NULL) {
+                            OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pAlgParamDTX,
+                                                     sizeof(WBAMRENC_TALGCtrl),
+                                                     OMX_U8);
+                            OMX_PRBUFFER2(pComponentPrivate->dbg,
+                                          "pAlgParamDTX %p\n", pComponentPrivate->pAlgParamDTX);
+                        }
+
+                        pComponentPrivate->nNumInputBufPending = 0;
+                        pComponentPrivate->nNumOutputBufPending = 0;
+
+                        pComponentPrivate->nNumOfFramesSent = 0;
+
+                        pComponentPrivate->nEmptyBufferDoneCount = 0;
+                        pComponentPrivate->nEmptyThisBufferCount = 0;
+
+                        pComponentPrivate->pAlgParam->iBitrate = pComponentPrivate->amrParams->eAMRBandMode;
+                        pComponentPrivate->pAlgParamDTX->iVADFlag = pComponentPrivate->amrParams->eAMRDTXMode;
+                        pComponentPrivate->pAlgParam->iSize = sizeof (WBAMRENC_TALGCtrl);
+                        pComponentPrivate->pAlgParamDTX->iSize = sizeof (WBAMRENC_TALGCtrl);
+
+                        OMX_PRINT2(pComponentPrivate->dbg,
+                                   "pAlgParam->iBitrate = %d\n",
+                                   pComponentPrivate->pAlgParam->iBitrate);
+                        OMX_PRINT2(pComponentPrivate->dbg,
+                                   "pAlgParam->iDTX  = %d\n",
+                                   pComponentPrivate->pAlgParamDTX->iVADFlag);
+
+                        cmdValues[0] = ALGCMD_BITRATE;                  /*setting the bit-rate*/
+                        cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParam;
+                        cmdValues[2] = sizeof (WBAMRENC_TALGCtrl);
+
+                        OMX_PRINT2(pComponentPrivate->dbg,
+                                   "Codec - EMMCodecControlAlgCtrl\n");
+                        /* Sending ALGCTRL MESSAGE DTX to DSP via LCML_ControlCodec*/
                         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                                   EMMCodecControlStrmCtrl,
-                                                   (void *)pValues);
-                        if(eError != OMX_ErrorNone) {
+                                                   EMMCodecControlAlgCtrl,
+                                                   (void *)cmdValues);
+
+                        if (eError != OMX_ErrorNone) {
                             OMX_ERROR4(pComponentPrivate->dbg,
-                                       "Error from LCML_ControlCodec EMMCodecControlStrmCtrl = %x\n",eError);
+                                       "Error from LCML_ControlCodec EMMCodecControlAlgCtrl = %x\n", eError);
                             goto EXIT;
                         }
-                    }
-                    /* Sending START MESSAGE to DSP via LCML_ControlCodec*/
-                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                               EMMCodecControlStart,
-                                               (void *)pArgs);
-                    if(eError != OMX_ErrorNone) {
-                        OMX_ERROR4(pComponentPrivate->dbg,
-                                   "Error from LCML_ControlCodec EMMCodecControlStart = %x\n",eError);
-                        goto EXIT;
-                    }
 
-                } else if (pComponentPrivate->curState == OMX_StatePause) {
-                    OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "OMX_StatePause -> OMX_StateExecuting\n");
+                        cmdValues[0] = ALGCMD_DTX; /*setting DTX mode*/
+                        cmdValues[1] = (OMX_U32)pComponentPrivate->pAlgParamDTX;
+                        cmdValues[2] = sizeof (WBAMRENC_TALGCtrlDTX);
 
-                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                               EMMCodecControlStart,
-                                               (void *)pArgs);
-                    if (eError != OMX_ErrorNone) {
-                        OMX_ERROR4(pComponentPrivate->dbg,
-                                   "Error While Resuming the codec = %x\n",eError);
-                        goto EXIT;
-                    }
+                        OMX_PRINT2(pComponentPrivate->dbg,
+                                   "Codec - EMMCodecControlAlgCtrl\n");
+                        /* Sending ALGCTRL MESSAGE BITRATE to DSP via LCML_ControlCodec*/
+                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                   EMMCodecControlAlgCtrl,
+                                                   (void *)cmdValues);
 
-                    for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) {
-                        if (pComponentPrivate->pInputBufHdrPending[i]) {
-                            WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate, pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr);
-                            WBAMRENC_SetPending(pComponentPrivate,pComponentPrivate->pInputBufHdrPending[i],OMX_DirInput,__LINE__);
-
-                            eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                                      EMMCodecInputBuffer,
-                                                      pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
-                                                      pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
-                                                      pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
-                                                      (OMX_U8 *) pLcmlHdr->pBufferParam,
-                                                      sizeof(WBAMRENC_ParamStruct),
-                                                      NULL);
+                        if (eError != OMX_ErrorNone) {
+                            OMX_ERROR4(pComponentPrivate->dbg,
+                                       "Error from LCML_ControlCodec EMMCodecControlAlgCtrl = %x\n", eError);
+                            goto EXIT;
                         }
-                    }
-                    pComponentPrivate->nNumInputBufPending = 0;
 
-                    for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
-                        if (pComponentPrivate->pOutputBufHdrPending[i]) {
-                            WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, OMX_DirOutput, &pLcmlHdr);
-                            WBAMRENC_SetPending(pComponentPrivate,pComponentPrivate->pOutputBufHdrPending[i],OMX_DirOutput,__LINE__);
-                            eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                                      EMMCodecOuputBuffer,
-                                                      pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
-                                                      pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
-                                                      pComponentPrivate->pOutputBufHdrPending[i]->nFilledLen,
-                                                      (OMX_U8 *) pLcmlHdr->pBufferParam,
-                                                      sizeof(WBAMRENC_ParamStruct),
-                                                      NULL);
+                        if (pComponentPrivate->dasfMode == 1) {
+                            OMX_PRDSP2(pComponentPrivate->dbg,
+                                       "---- Comp: DASF Functionality is ON ---\n");
+
+                            OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams,
+                                                     sizeof(WBAMRENC_AudioCodecParams),
+                                                     OMX_U8);
+
+                            OMX_PRBUFFER2(pComponentPrivate->dbg,
+                                          "pParams %p\n", pComponentPrivate->pParams);
+
+                            pComponentPrivate->pParams->iAudioFormat = 1;
+                            pComponentPrivate->pParams->iStrmId = pComponentPrivate->streamID;
+                            pComponentPrivate->pParams->iSamplingRate = WBAMRENC_SAMPLING_FREQUENCY;
+                            pValues[0] = USN_STRMCMD_SETCODECPARAMS;
+                            pValues[1] = (OMX_U32)pComponentPrivate->pParams;
+                            pValues[2] = sizeof(WBAMRENC_AudioCodecParams);
+                            /* Sending STRMCTRL MESSAGE to DSP via LCML_ControlCodec*/
+                            eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                       EMMCodecControlStrmCtrl,
+                                                       (void *)pValues);
+
+                            if (eError != OMX_ErrorNone) {
+                                OMX_ERROR4(pComponentPrivate->dbg,
+                                           "Error from LCML_ControlCodec EMMCodecControlStrmCtrl = %x\n", eError);
+                                goto EXIT;
+                            }
                         }
-                    }
-                    pComponentPrivate->nNumOutputBufPending = 0;
-                } else {
-                    pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                            pHandle->pApplicationPrivate,
-                                                            OMX_EventError,
-                                                            OMX_ErrorIncorrectStateTransition,
-                                                            OMX_TI_ErrorMinor,
-                                                            "Incorrect State Transition");
-                    OMX_ERROR4(pComponentPrivate->dbg,
-                               "OMX_ErrorIncorrectStateTransition Given by Comp\n");
-                    goto EXIT;
 
-                }
+                        /* Sending START MESSAGE to DSP via LCML_ControlCodec*/
+                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                   EMMCodecControlStart,
+                                                   (void *)pArgs);
+
+                        if (eError != OMX_ErrorNone) {
+                            OMX_ERROR4(pComponentPrivate->dbg,
+                                       "Error from LCML_ControlCodec EMMCodecControlStart = %x\n", eError);
+                            goto EXIT;
+                        }
+
+                    } else if (pComponentPrivate->curState == OMX_StatePause) {
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "OMX_StatePause -> OMX_StateExecuting\n");
+
+                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                   EMMCodecControlStart,
+                                                   (void *)pArgs);
+
+                        if (eError != OMX_ErrorNone) {
+                            OMX_ERROR4(pComponentPrivate->dbg,
+                                       "Error While Resuming the codec = %x\n", eError);
+                            goto EXIT;
+                        }
+
+                        for (i = 0; i < pComponentPrivate->nNumInputBufPending; i++) {
+                            if (pComponentPrivate->pInputBufHdrPending[i]) {
+                                WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate, pComponentPrivate->pInputBufHdrPending[i]->pBuffer, OMX_DirInput, &pLcmlHdr);
+                                WBAMRENC_SetPending(pComponentPrivate, pComponentPrivate->pInputBufHdrPending[i], OMX_DirInput, __LINE__);
+
+                                eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                          EMMCodecInputBuffer,
+                                                          pComponentPrivate->pInputBufHdrPending[i]->pBuffer,
+                                                          pComponentPrivate->pInputBufHdrPending[i]->nAllocLen,
+                                                          pComponentPrivate->pInputBufHdrPending[i]->nFilledLen,
+                                                          (OMX_U8 *) pLcmlHdr->pBufferParam,
+                                                          sizeof(WBAMRENC_ParamStruct),
+                                                          NULL);
+                            }
+                        }
+
+                        pComponentPrivate->nNumInputBufPending = 0;
+
+                        for (i = 0; i < pComponentPrivate->nNumOutputBufPending; i++) {
+                            if (pComponentPrivate->pOutputBufHdrPending[i]) {
+                                WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate, pComponentPrivate->pOutputBufHdrPending[i]->pBuffer, OMX_DirOutput, &pLcmlHdr);
+                                WBAMRENC_SetPending(pComponentPrivate, pComponentPrivate->pOutputBufHdrPending[i], OMX_DirOutput, __LINE__);
+                                eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                          EMMCodecOuputBuffer,
+                                                          pComponentPrivate->pOutputBufHdrPending[i]->pBuffer,
+                                                          pComponentPrivate->pOutputBufHdrPending[i]->nAllocLen,
+                                                          pComponentPrivate->pOutputBufHdrPending[i]->nFilledLen,
+                                                          (OMX_U8 *) pLcmlHdr->pBufferParam,
+                                                          sizeof(WBAMRENC_ParamStruct),
+                                                          NULL);
+                            }
+                        }
+
+                        pComponentPrivate->nNumOutputBufPending = 0;
+                    } else {
+                        pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                OMX_ErrorIncorrectStateTransition,
+                                                                OMX_TI_ErrorMinor,
+                                                                "Incorrect State Transition");
+                        OMX_ERROR4(pComponentPrivate->dbg,
+                                   "OMX_ErrorIncorrectStateTransition Given by Comp\n");
+                        goto EXIT;
+
+                    }
+
 #ifdef RESOURCE_MANAGER_ENABLED
-                rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_WBAMR_Encoder_COMPONENT, OMX_StateExecuting, 3456, NULL);
+                    rm_error = RMProxy_NewSendCommand(pHandle, RMProxy_StateSet, OMX_WBAMR_Encoder_COMPONENT, OMX_StateExecuting, 3456, NULL);
 #endif
-                pComponentPrivate->curState = OMX_StateExecuting;
+                    pComponentPrivate->curState = OMX_StateExecuting;
 #ifdef __PERF_INSTRUMENTATION__
-                PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundarySteadyState);
+                    PERF_Boundary(pComponentPrivate->pPERFcomp, PERF_BoundaryStart | PERF_BoundarySteadyState);
 #endif
 
                 /* Decrement reference count with signal enabled */
@@ -1270,29 +1210,30 @@
                       return OMX_ErrorUndefined;
                 }
 
-                pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                        pHandle->pApplicationPrivate,
-                                                        OMX_EventCmdComplete,
-                                                        OMX_CommandStateSet,
-                                                        pComponentPrivate->curState,
-                                                        NULL);
-                OMX_PRINT2(pComponentPrivate->dbg, "OMX_CommandStateSet Given by Comp\n");
-                break;
+                    pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                            pHandle->pApplicationPrivate,
+                                                            OMX_EventCmdComplete,
+                                                            OMX_CommandStateSet,
+                                                            pComponentPrivate->curState,
+                                                            NULL);
+                    OMX_PRINT2(pComponentPrivate->dbg, "OMX_CommandStateSet Given by Comp\n");
+                    break;
 
-            case OMX_StateLoaded:
-                OMX_PRDSP2(pComponentPrivate->dbg, "To OMX_StateLoaded\n");
-                if (pComponentPrivate->curState == OMX_StateWaitForResources){
-                    OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "OMX_StateWaitForResources -> OMX_StateLoaded\n");
-                    OMX_PRMGR2(pComponentPrivate->dbg,
-                               "OMX_StateWaitForResources\n");
+                case OMX_StateLoaded:
+                    OMX_PRDSP2(pComponentPrivate->dbg, "To OMX_StateLoaded\n");
+
+                    if (pComponentPrivate->curState == OMX_StateWaitForResources) {
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "OMX_StateWaitForResources -> OMX_StateLoaded\n");
+                        OMX_PRMGR2(pComponentPrivate->dbg,
+                                   "OMX_StateWaitForResources\n");
 #ifdef __PERF_INSTRUMENTATION__
-                    PERF_Boundary(pComponentPrivate->pPERFcomp,
-                                  PERF_BoundaryStart | PERF_BoundaryCleanup);
+                        PERF_Boundary(pComponentPrivate->pPERFcomp,
+                                      PERF_BoundaryStart | PERF_BoundaryCleanup);
 #endif
-                    pComponentPrivate->curState = OMX_StateLoaded;
+                        pComponentPrivate->curState = OMX_StateLoaded;
 #ifdef __PERF_INSTRUMENTATION__
-                    PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundaryCleanup);
+                        PERF_Boundary(pComponentPrivate->pPERFcomp, PERF_BoundaryComplete | PERF_BoundaryCleanup);
 #endif
 
                    /* Decrement reference count with signal enabled */
@@ -1300,191 +1241,208 @@
                        return OMX_ErrorUndefined;
                    }
 
-                    pComponentPrivate->cbInfo.EventHandler ( pHandle,
-                                                             pHandle->pApplicationPrivate,
-                                                             OMX_EventCmdComplete,
-                                                             OMX_CommandStateSet,
-                                                             pComponentPrivate->curState,
-                                                             NULL);
-                    OMX_PRINT2(pComponentPrivate->dbg,
-                               "OMX_CommandStateSet Given by Comp\n");
-                    break;
-                }
-                if (pComponentPrivate->curState != OMX_StateIdle) {
-                    OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "Not OMX_StateIdle -> OMX_StateLoaded\n");
+                        pComponentPrivate->cbInfo.EventHandler ( pHandle,
+                                pHandle->pApplicationPrivate,
+                                OMX_EventCmdComplete,
+                                OMX_CommandStateSet,
+                                pComponentPrivate->curState,
+                                NULL);
+                        OMX_PRINT2(pComponentPrivate->dbg,
+                                   "OMX_CommandStateSet Given by Comp\n");
+                        break;
+                    }
 
-                    pComponentPrivate->cbInfo.EventHandler ( pHandle,
-                                                             pHandle->pApplicationPrivate,
-                                                             OMX_EventError,
-                                                             OMX_ErrorIncorrectStateTransition,
-                                                             OMX_TI_ErrorMinor,
-                                                             "Incorrect State Transition");
-                    OMX_ERROR4(pComponentPrivate->dbg,
-                               "Error: OMX_ErrorIncorrectStateTransition Given by Comp\n");
-                    goto EXIT;
-                }
+                    if (pComponentPrivate->curState != OMX_StateIdle) {
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "Not OMX_StateIdle -> OMX_StateLoaded\n");
+
+                        pComponentPrivate->cbInfo.EventHandler ( pHandle,
+                                pHandle->pApplicationPrivate,
+                                OMX_EventError,
+                                OMX_ErrorIncorrectStateTransition,
+                                OMX_TI_ErrorMinor,
+                                "Incorrect State Transition");
+                        OMX_ERROR4(pComponentPrivate->dbg,
+                                   "Error: OMX_ErrorIncorrectStateTransition Given by Comp\n");
+                        goto EXIT;
+                    }
+
 #ifdef __PERF_INSTRUMENTATION__
-                PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryStart | PERF_BoundaryCleanup);
+                    PERF_Boundary(pComponentPrivate->pPERFcomp, PERF_BoundaryStart | PERF_BoundaryCleanup);
 #endif
-                OMX_PRBUFFER2(pComponentPrivate->dbg,
-                              "Evaluating if all buffers are free\n");
+                    OMX_PRBUFFER2(pComponentPrivate->dbg,
+                                  "Evaluating if all buffers are free\n");
 
-                if (pComponentPrivate->pInputBufferList->numBuffers ||
-                    pComponentPrivate->pOutputBufferList->numBuffers) {
-                    pComponentPrivate->InIdle_goingtoloaded = 1;
+                    if (pComponentPrivate->pInputBufferList->numBuffers ||
+                            pComponentPrivate->pOutputBufferList->numBuffers) {
+                        pComponentPrivate->InIdle_goingtoloaded = 1;
 #ifndef UNDER_CE
-                    pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
-                    pthread_cond_wait(&pComponentPrivate->InIdle_threshold,
-                                      &pComponentPrivate->InIdle_mutex);
-                    pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
+                        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
+                        pthread_cond_wait(&pComponentPrivate->InIdle_threshold,
+                                          &pComponentPrivate->InIdle_mutex);
+                        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
 #else
-                    OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
+                        OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
 #endif
-                    pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
-                }
-                /* Now Deinitialize the component No error should be returned from
-                 * this function. It should clean the system as much as possible */
-                WBAMRENC_CleanupInitParams(pHandle);
-                eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                           EMMCodecControlDestroy,
-                                           (void *)pArgs);
-                if (eError != OMX_ErrorNone) {
-                    OMX_ERROR4(pComponentPrivate->dbg,
-                               "Error: LCML_ControlCodec EMMCodecControlDestroy = %x\n", eError);
-                    goto EXIT;
-                }
-                /*Closing LCML Lib*/
-                if (pComponentPrivate->ptrLibLCML != NULL){
-                    OMX_PRDSP2(pComponentPrivate->dbg,"Closing LCML library\n");
-                    dlclose( pComponentPrivate->ptrLibLCML);
-                    pComponentPrivate->ptrLibLCML = NULL;
-                }
+                        pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
+                    }
 
-#ifdef __PERF_INSTRUMENTATION__
-                PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, PERF_ModuleComponent);
-#endif
-                eError = WBAMRENC_EXIT_COMPONENT_THRD;
-                pComponentPrivate->bInitParamsInitialized = 0;
-                pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
-                break;
-
-            case OMX_StatePause:
-                OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StatePause\n");
-                if (pComponentPrivate->curState != OMX_StateExecuting &&
-                    pComponentPrivate->curState != OMX_StateIdle) {
-                    OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "Not OMX_StateExecuting not OMX_StateIdle -> OMX_StatePause\n");
-                    pComponentPrivate->cbInfo.EventHandler ( pHandle,
-                                                             pHandle->pApplicationPrivate,
-                                                             OMX_EventError,
-                                                             OMX_ErrorIncorrectStateTransition,
-                                                             OMX_TI_ErrorMinor,
-                                                             "Incorrect State Transition");
-                    OMX_ERROR4(pComponentPrivate->dbg,
-                               "Error: OMX_ErrorIncorrectStateTransition Given by Comp\n");
-                    goto EXIT;
-                }
-#ifdef __PERF_INSTRUMENTATION__
-                PERF_Boundary(pComponentPrivate->pPERFcomp,PERF_BoundaryComplete | PERF_BoundarySteadyState);
-#endif
-                eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                           EMMCodecControlPause,
-                                           (void *)pArgs);
-                if (eError != OMX_ErrorNone) {
-                    OMX_ERROR4(pComponentPrivate->dbg,
-                               "Error: LCML_ControlCodec EMMCodecControlPause = %x\n",eError);
-                    goto EXIT;
-                }
-                OMX_PRSTATE2(pComponentPrivate->dbg,
-                             "OMX_CommandStateSet Given by Comp\n");
-                break;
-
-            case OMX_StateWaitForResources:
-                OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StateWaitForResources\n");
-                if (pComponentPrivate->curState == OMX_StateLoaded) {
-                    OMX_PRSTATE2(pComponentPrivate->dbg,
-                                 "OMX_StateLoaded -> OMX_StateWaitForResources\n");
-
-#ifdef RESOURCE_MANAGER_ENABLED
-                    rm_error = RMProxy_NewSendCommand(pHandle,
-                                                      RMProxy_StateSet,
-                                                      OMX_WBAMR_Encoder_COMPONENT,
-                                                      OMX_StateWaitForResources,
-                                                      3456,
-                                                      NULL);
-#endif
-
-                    pComponentPrivate->curState = OMX_StateWaitForResources;
-                    pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                            pHandle->pApplicationPrivate,
-                                                            OMX_EventCmdComplete,
-                                                            OMX_CommandStateSet,
-                                                            pComponentPrivate->curState,
-                                                            NULL);
-                    OMX_PRINT2(pComponentPrivate->dbg,
-                               "OMX_CommandStateSet Given by Comp\n");
-                } else {
-                    pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                            pHandle->pApplicationPrivate,
-                                                            OMX_EventError,
-                                                            OMX_ErrorIncorrectStateTransition,
-                                                            OMX_TI_ErrorMinor,
-                                                            "Incorrect State Transition");
-                    OMX_ERROR4(pComponentPrivate->dbg,
-                               "Error: OMX_ErrorIncorrectStateTransition Given by Comp\n");
-                }
-                break;
-
-            case OMX_StateInvalid:
-                OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StateInvalid\n");
-                if (pComponentPrivate->curState != OMX_StateWaitForResources &&
-                    pComponentPrivate->curState != OMX_StateInvalid &&
-                    pComponentPrivate->curState != OMX_StateLoaded) {
-
+                    /* Now Deinitialize the component No error should be returned from
+                     * this function. It should clean the system as much as possible */
+                    WBAMRENC_CleanupInitParams(pHandle);
                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
                                                EMMCodecControlDestroy,
                                                (void *)pArgs);
-                }
-                pComponentPrivate->curState = OMX_StateInvalid;
-                pComponentPrivate->cbInfo.EventHandler( pHandle,
-                                                        pHandle->pApplicationPrivate,
-                                                        OMX_EventError,
-                                                        OMX_ErrorInvalidState,
-                                                        OMX_TI_ErrorSevere,
-                                                        "Incorrect State Transition");
 
-                OMX_ERROR4(pComponentPrivate->dbg,
-                           "OMX_ErrorInvalidState Given by Comp\n");
-                WBAMRENC_CleanupInitParams(pHandle);
-                break;
+                    if (eError != OMX_ErrorNone) {
+                        OMX_ERROR4(pComponentPrivate->dbg,
+                                   "Error: LCML_ControlCodec EMMCodecControlDestroy = %x\n", eError);
+                        goto EXIT;
+                    }
 
-            case OMX_StateMax:
-                OMX_PRINT2(pComponentPrivate->dbg, "To Cmd OMX_StateMax\n");
-                break;
+                    /*Closing LCML Lib*/
+                    if (pComponentPrivate->ptrLibLCML != NULL) {
+                        OMX_PRDSP2(pComponentPrivate->dbg, "Closing LCML library\n");
+                        dlclose( pComponentPrivate->ptrLibLCML);
+                        pComponentPrivate->ptrLibLCML = NULL;
+                    }
+
+#ifdef __PERF_INSTRUMENTATION__
+                    PERF_SendingCommand(pComponentPrivate->pPERF, -1, 0, PERF_ModuleComponent);
+#endif
+                    eError = WBAMRENC_EXIT_COMPONENT_THRD;
+                    pComponentPrivate->bInitParamsInitialized = 0;
+                    pComponentPrivate->bLoadedCommandPending = OMX_FALSE;
+                    break;
+
+                case OMX_StatePause:
+                    OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StatePause\n");
+
+                    if (pComponentPrivate->curState != OMX_StateExecuting &&
+                            pComponentPrivate->curState != OMX_StateIdle) {
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "Not OMX_StateExecuting not OMX_StateIdle -> OMX_StatePause\n");
+                        pComponentPrivate->cbInfo.EventHandler ( pHandle,
+                                pHandle->pApplicationPrivate,
+                                OMX_EventError,
+                                OMX_ErrorIncorrectStateTransition,
+                                OMX_TI_ErrorMinor,
+                                "Incorrect State Transition");
+                        OMX_ERROR4(pComponentPrivate->dbg,
+                                   "Error: OMX_ErrorIncorrectStateTransition Given by Comp\n");
+                        goto EXIT;
+                    }
+
+#ifdef __PERF_INSTRUMENTATION__
+                    PERF_Boundary(pComponentPrivate->pPERFcomp, PERF_BoundaryComplete | PERF_BoundarySteadyState);
+#endif
+                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                               EMMCodecControlPause,
+                                               (void *)pArgs);
+
+                    if (eError != OMX_ErrorNone) {
+                        OMX_ERROR4(pComponentPrivate->dbg,
+                                   "Error: LCML_ControlCodec EMMCodecControlPause = %x\n", eError);
+                        goto EXIT;
+                    }
+
+                    OMX_PRSTATE2(pComponentPrivate->dbg,
+                                 "OMX_CommandStateSet Given by Comp\n");
+                    break;
+
+                case OMX_StateWaitForResources:
+                    OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StateWaitForResources\n");
+
+                    if (pComponentPrivate->curState == OMX_StateLoaded) {
+                        OMX_PRSTATE2(pComponentPrivate->dbg,
+                                     "OMX_StateLoaded -> OMX_StateWaitForResources\n");
+
+#ifdef RESOURCE_MANAGER_ENABLED
+                        rm_error = RMProxy_NewSendCommand(pHandle,
+                                                          RMProxy_StateSet,
+                                                          OMX_WBAMR_Encoder_COMPONENT,
+                                                          OMX_StateWaitForResources,
+                                                          3456,
+                                                          NULL);
+#endif
+
+                        pComponentPrivate->curState = OMX_StateWaitForResources;
+                        pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                pHandle->pApplicationPrivate,
+                                                                OMX_EventCmdComplete,
+                                                                OMX_CommandStateSet,
+                                                                pComponentPrivate->curState,
+                                                                NULL);
+                        OMX_PRINT2(pComponentPrivate->dbg,
+                                   "OMX_CommandStateSet Given by Comp\n");
+                    } else {
+                        pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                                pHandle->pApplicationPrivate,
+                                                                OMX_EventError,
+                                                                OMX_ErrorIncorrectStateTransition,
+                                                                OMX_TI_ErrorMinor,
+                                                                "Incorrect State Transition");
+                        OMX_ERROR4(pComponentPrivate->dbg,
+                                   "Error: OMX_ErrorIncorrectStateTransition Given by Comp\n");
+                    }
+
+                    break;
+
+                case OMX_StateInvalid:
+                    OMX_PRSTATE2(pComponentPrivate->dbg, "To OMX_StateInvalid\n");
+
+                    if (pComponentPrivate->curState != OMX_StateWaitForResources &&
+                            pComponentPrivate->curState != OMX_StateInvalid &&
+                            pComponentPrivate->curState != OMX_StateLoaded) {
+
+                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                   EMMCodecControlDestroy,
+                                                   (void *)pArgs);
+                    }
+
+                    pComponentPrivate->curState = OMX_StateInvalid;
+                    pComponentPrivate->cbInfo.EventHandler( pHandle,
+                                                            pHandle->pApplicationPrivate,
+                                                            OMX_EventError,
+                                                            OMX_ErrorInvalidState,
+                                                            OMX_TI_ErrorSevere,
+                                                            "Incorrect State Transition");
+
+                    OMX_ERROR4(pComponentPrivate->dbg,
+                               "OMX_ErrorInvalidState Given by Comp\n");
+                    WBAMRENC_CleanupInitParams(pHandle);
+                    break;
+
+                case OMX_StateMax:
+                    OMX_PRINT2(pComponentPrivate->dbg, "To Cmd OMX_StateMax\n");
+                    break;
             } /* End of Switch */
         }
     } else if (command == OMX_CommandMarkBuffer) {
         OMX_PRBUFFER2(pComponentPrivate->dbg, "OMX_CommandMarkBuffer\n");
-        if(!pComponentPrivate->pMarkBuf){
+
+        if (!pComponentPrivate->pMarkBuf) {
             /* TODO Need to handle multiple marks */
             pComponentPrivate->pMarkBuf = (OMX_MARKTYPE *)(commandData);
         }
     } else if (command == OMX_CommandPortDisable) {
         if (!pComponentPrivate->bDisableCommandPending) {
-            if(commandData == 0x0 || commandData == -1){
+            if (commandData == 0x0 || commandData == -1) {
                 pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled = OMX_FALSE;
             }
-            if(commandData == 0x1 || commandData == -1){
+
+            if (commandData == 0x1 || commandData == -1) {
                 pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled = OMX_FALSE;
+
                 if (pComponentPrivate->curState == OMX_StateExecuting) {
                     pComponentPrivate->bNoIdleOnStop = OMX_TRUE;
                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                               MMCodecControlStop,(void *)pArgs);
+                                               MMCodecControlStop, (void *)pArgs);
                 }
             }
         }
-        OMX_PRCOMM2(pComponentPrivate->dbg, "commandData = %ld\n",commandData);
+
+        OMX_PRCOMM2(pComponentPrivate->dbg, "commandData = %ld\n", commandData);
         OMX_PRCOMM2(pComponentPrivate->dbg,
                     "WBAMRENC_INPUT_PORT bPopulated = %d\n",
                     pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated);
@@ -1492,8 +1450,8 @@
                     "WBAMRENC_OUTPUT_PORT bPopulated = %d\n",
                     pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated);
 
-        if(commandData == 0x0) {
-            if(!pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated){
+        if (commandData == 0x0) {
+            if (!pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated) {
                 /* return cmdcomplete event if input unpopulated */
                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -1501,15 +1459,14 @@
                                                        WBAMRENC_INPUT_PORT,
                                                        NULL);
                 pComponentPrivate->bDisableCommandPending = 0;
-            }
-            else{
+            } else {
                 pComponentPrivate->bDisableCommandPending = 1;
                 pComponentPrivate->bDisableCommandParam = commandData;
             }
         }
 
-        if(commandData == 0x1) {
-            if (!pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated){
+        if (commandData == 0x1) {
+            if (!pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated) {
                 /* return cmdcomplete event if output unpopulated */
                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -1517,16 +1474,15 @@
                                                        WBAMRENC_OUTPUT_PORT,
                                                        NULL);
                 pComponentPrivate->bDisableCommandPending = 0;
-            }
-            else {
+            } else {
                 pComponentPrivate->bDisableCommandPending = 1;
                 pComponentPrivate->bDisableCommandParam = commandData;
             }
         }
 
-        if(commandData == -1) {
+        if (commandData == -1) {
             if (!pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated &&
-                !pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated){
+                    !pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated) {
 
                 /* return cmdcomplete event if inout & output unpopulated */
                 pComponentPrivate->cbInfo.EventHandler(pHandle, pHandle->pApplicationPrivate,
@@ -1541,44 +1497,43 @@
                                                        WBAMRENC_OUTPUT_PORT,
                                                        NULL);
                 pComponentPrivate->bDisableCommandPending = 0;
-            }
-            else {
+            } else {
                 pComponentPrivate->bDisableCommandPending = 1;
                 pComponentPrivate->bDisableCommandParam = commandData;
             }
         }
 
-    }
-    else if (command == OMX_CommandPortEnable) {
-        if(!pComponentPrivate->bEnableCommandPending) {
-            if(commandData == 0x0 || commandData == -1){
+    } else if (command == OMX_CommandPortEnable) {
+        if (!pComponentPrivate->bEnableCommandPending) {
+            if (commandData == 0x0 || commandData == -1) {
                 /* enable in port */
                 OMX_PRCOMM2(pComponentPrivate->dbg, "setting input port to enabled\n");
                 pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled = OMX_TRUE;
 
-                if(pComponentPrivate->AlloBuf_waitingsignal)
-                {
+                if (pComponentPrivate->AlloBuf_waitingsignal) {
                     pComponentPrivate->AlloBuf_waitingsignal = 0;
                 }
             }
-            if(commandData == 0x1 || commandData == -1){
+
+            if (commandData == 0x1 || commandData == -1) {
                 /* enable out port */
-                if(pComponentPrivate->AlloBuf_waitingsignal)
-                    {
-                        pComponentPrivate->AlloBuf_waitingsignal = 0;
+                if (pComponentPrivate->AlloBuf_waitingsignal) {
+                    pComponentPrivate->AlloBuf_waitingsignal = 0;
 #ifndef UNDER_CE
-                        pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
-                        pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
-                        pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
+                    pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
+                    pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
+                    pthread_mutex_unlock(&pComponentPrivate->AlloBuf_mutex);
 #else
-                        OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
+                    OMX_SignalEvent(&(pComponentPrivate->AlloBuf_event));
 #endif
-                    }
+                }
+
                 if (pComponentPrivate->curState == OMX_StateExecuting) {
                     pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
                     eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                               EMMCodecControlStart,(void *)pArgs);
+                                               EMMCodecControlStart, (void *)pArgs);
                 }
+
                 OMX_PRCOMM2(pComponentPrivate->dbg, "setting output port to enabled\n");
                 pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled = OMX_TRUE;
                 OMX_PRCOMM2(pComponentPrivate->dbg,
@@ -1587,9 +1542,9 @@
             }
         }
 
-        if(commandData == 0x0){
+        if (commandData == 0x0) {
             if (pComponentPrivate->curState == OMX_StateLoaded ||
-                pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated) {
+                    pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated) {
                 pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                        pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -1597,15 +1552,13 @@
                                                        WBAMRENC_INPUT_PORT,
                                                        NULL);
                 pComponentPrivate->bEnableCommandPending = 0;
-            }
-            else {
+            } else {
                 pComponentPrivate->bEnableCommandPending = 1;
                 pComponentPrivate->bEnableCommandParam = commandData;
             }
-        }
-        else if(commandData == 0x1) {
+        } else if (commandData == 0x1) {
             if (pComponentPrivate->curState == OMX_StateLoaded ||
-                pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated){
+                    pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated) {
                 pComponentPrivate->cbInfo.EventHandler( pHandle,
                                                         pHandle->pApplicationPrivate,
                                                         OMX_EventCmdComplete,
@@ -1613,16 +1566,14 @@
                                                         WBAMRENC_OUTPUT_PORT,
                                                         NULL);
                 pComponentPrivate->bEnableCommandPending = 0;
-            }
-            else {
+            } else {
                 pComponentPrivate->bEnableCommandPending = 1;
                 pComponentPrivate->bEnableCommandParam = commandData;
             }
-        }
-        else if(commandData == -1) {
+        } else if (commandData == -1) {
             if (pComponentPrivate->curState == OMX_StateLoaded ||
-                (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated
-                 && pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated)){
+                    (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated
+                     && pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated)) {
                 pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                        pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -1637,12 +1588,12 @@
                                                        NULL);
                 pComponentPrivate->bEnableCommandPending = 0;
                 WBAMRENC_FillLCMLInitParamsEx(pHandle);
-            }
-            else {
+            } else {
                 pComponentPrivate->bEnableCommandPending = 1;
                 pComponentPrivate->bEnableCommandParam = commandData;
             }
         }
+
 #ifndef UNDER_CE
         pthread_mutex_lock(&pComponentPrivate->AlloBuf_mutex);
         pthread_cond_signal(&pComponentPrivate->AlloBuf_threshold);
@@ -1652,10 +1603,10 @@
 #endif
 
     } else if (command == OMX_CommandFlush) {
-        if(commandData == 0x0 || commandData == -1){
+        if (commandData == 0x0 || commandData == -1) {
             OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing input port\n");
 
-            for (i=0; i < pComponentPrivate->nNumInputBufPending; i++) {
+            for (i = 0; i < pComponentPrivate->nNumInputBufPending; i++) {
 #ifdef __PERF_INSTRUMENTATION__
                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                   pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer,
@@ -1664,12 +1615,13 @@
 #endif
 
                 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
-                                                           pComponentPrivate->pHandle->pApplicationPrivate,
-                                                           pComponentPrivate->pInputBufHdrPending[i]);
+                        pComponentPrivate->pHandle->pApplicationPrivate,
+                        pComponentPrivate->pInputBufHdrPending[i]);
                 pComponentPrivate->nEmptyBufferDoneCount++;
                 pComponentPrivate->nOutStandingEmptyDones--;
             }
-            pComponentPrivate->nNumInputBufPending=0;
+
+            pComponentPrivate->nNumInputBufPending = 0;
             pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                    pHandle->pApplicationPrivate,
                                                    OMX_EventCmdComplete,
@@ -1678,10 +1630,10 @@
                                                    NULL);
         }
 
-        if(commandData == 0x1 || commandData == -1){
+        if (commandData == 0x1 || commandData == -1) {
             OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing output port\n");
 
-            for (i=0; i < pComponentPrivate->nNumOutputBufPending; i++) {
+            for (i = 0; i < pComponentPrivate->nNumOutputBufPending; i++) {
 #ifdef __PERF_INSTRUMENTATION__
                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                   pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer,
@@ -1689,12 +1641,13 @@
                                   PERF_ModuleHLMM);
 #endif
                 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
-                                                          pComponentPrivate->pHandle->pApplicationPrivate,
-                                                          pComponentPrivate->pOutputBufHdrPending[i]);
+                        pComponentPrivate->pHandle->pApplicationPrivate,
+                        pComponentPrivate->pOutputBufHdrPending[i]);
                 pComponentPrivate->nFillBufferDoneCount++;
                 pComponentPrivate->nOutStandingFillDones--;
             }
-            pComponentPrivate->nNumOutputBufPending=0;
+
+            pComponentPrivate->nNumOutputBufPending = 0;
             pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                    pHandle->pApplicationPrivate,
                                                    OMX_EventCmdComplete,
@@ -1704,9 +1657,19 @@
         }
     }
 
- EXIT:
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
+
+    if (eError != OMX_ErrorNone && eError != WBAMRENC_EXIT_COMPONENT_THRD) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
+
     return eError;
 }
 
@@ -1726,23 +1689,22 @@
  */
 /* ========================================================================== */
 OMX_ERRORTYPE WBAMRENC_HandleDataBufFromApp(OMX_BUFFERHEADERTYPE* pBufHeader,
-                                            WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate)
-{
+        WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_DIRTYPE eDir;
     WBAMRENC_LCML_BUFHEADERTYPE *pLcmlHdr;
     LCML_DSP_INTERFACE *pLcmlHandle = (LCML_DSP_INTERFACE *)
-        pComponentPrivate->pLcmlHandle;
+                                      pComponentPrivate->pLcmlHandle;
     OMX_U32 frameLength, remainingBytes;
     OMX_U8* pExtraData;
-    OMX_U8 nFrames=0,i;
+    OMX_U8 nFrames = 0, i;
     LCML_DSP_INTERFACE * phandle;
-    OMX_U8* pBufParmsTemp;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
     /*Find the direction of the received buffer from buffer list */
     eError = WBAMRENC_GetBufferDirection(pBufHeader, &eDir);
+
     if (eError != OMX_ErrorNone) {
         OMX_ERROR4(pComponentPrivate->dbg, "The pBufHeader is not found in the list\n");
         goto EXIT;
@@ -1751,62 +1713,67 @@
     if (eDir == OMX_DirInput) {
         pComponentPrivate->nEmptyThisBufferCount++;
         pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
+
         if (pBufHeader->nFilledLen > 0) {
             if (pComponentPrivate->nHoldLength == 0) {
                 frameLength = WBAMRENC_INPUT_FRAME_SIZE;
                 nFrames = (OMX_U8)(pBufHeader->nFilledLen / frameLength);
 
-                if ( nFrames>=1 ) {/* At least there is 1 frame in the buffer */
+                if ( nFrames >= 1 ) {/* At least there is 1 frame in the buffer */
 
-                    pComponentPrivate->nHoldLength = pBufHeader->nFilledLen - frameLength*nFrames;
+                    pComponentPrivate->nHoldLength = pBufHeader->nFilledLen - frameLength * nFrames;
+
                     if (pComponentPrivate->nHoldLength > 0) {/* something need to be hold in pHoldBuffer */
                         if (pComponentPrivate->pHoldBuffer == NULL) {
-                            WBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer,
-                                                     WBAMRENC_INPUT_BUFFER_SIZE,
-                                                     OMX_U8);
+                            OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer,
+                                            WBAMRENC_INPUT_BUFFER_SIZE,
+                                            OMX_U8);
                         }
+
                         memset(pComponentPrivate->pHoldBuffer, 0, WBAMRENC_INPUT_BUFFER_SIZE);
                         /* Copy the extra data into pHoldBuffer. Size will be nHoldLength. */
-                        pExtraData = pBufHeader->pBuffer + frameLength*nFrames;
+                        pExtraData = pBufHeader->pBuffer + frameLength * nFrames;
 
-                        if(pComponentPrivate->nHoldLength <= WBAMRENC_INPUT_BUFFER_SIZE) {
+                        if (pComponentPrivate->nHoldLength <= WBAMRENC_INPUT_BUFFER_SIZE) {
                             memcpy(pComponentPrivate->pHoldBuffer,
                                    pExtraData,
                                    pComponentPrivate->nHoldLength);
-                        }
-                        else {
+                        } else {
                             OMX_ERROR4(pComponentPrivate->dbg,
                                        "Error: pHoldLength is bigger than the input frame size\n");
                             goto EXIT;
                         }
-                        pBufHeader->nFilledLen-=pComponentPrivate->nHoldLength;
+
+                        pBufHeader->nFilledLen -= pComponentPrivate->nHoldLength;
                     }
-                }
-                else {
-                    if ( !pComponentPrivate->InBuf_Eos_alreadysent ){
+                } else {
+                    if ( !pComponentPrivate->InBuf_Eos_alreadysent ) {
                         /* received buffer with less than 1 AMR frame length. Save the data in pHoldBuffer.*/
                         pComponentPrivate->nHoldLength = pBufHeader->nFilledLen;
+
                         /* save the data into pHoldBuffer */
                         if (pComponentPrivate->pHoldBuffer == NULL) {
-                            WBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer,
-                                                     WBAMRENC_INPUT_BUFFER_SIZE,
-                                                     OMX_U8);
+                            OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer,
+                                            WBAMRENC_INPUT_BUFFER_SIZE,
+                                            OMX_U8);
                         }
+
                         /* Not enough data to be sent. Copy all received data into pHoldBuffer.*/
                         /* Size to be copied will be iHoldLen == mmData->BufferSize() */
                         memset(pComponentPrivate->pHoldBuffer, 0, WBAMRENC_INPUT_BUFFER_SIZE);
-                        if(pComponentPrivate->nHoldLength <= WBAMRENC_INPUT_BUFFER_SIZE) {
+
+                        if (pComponentPrivate->nHoldLength <= WBAMRENC_INPUT_BUFFER_SIZE) {
                             memcpy(pComponentPrivate->pHoldBuffer,
                                    pBufHeader->pBuffer,
                                    pComponentPrivate->nHoldLength);
                             /* since not enough data, we shouldn't send anything to SN, but instead request to EmptyBufferDone again.*/
-                        }
-                        else {
+                        } else {
                             OMX_ERROR4(pComponentPrivate->dbg,
                                        "Error: pHoldLength is bigger than the input frame size\n");
                             goto EXIT;
                         }
                     }
+
                     if (pComponentPrivate->curState != OMX_StatePause) {
                         OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling EmptyBufferDone\n");
 #ifdef __PERF_INSTRUMENTATION__
@@ -1816,11 +1783,10 @@
                                           PERF_ModuleHLMM);
 #endif
                         pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
-                                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                                   pBufHeader);
+                                pComponentPrivate->pHandle->pApplicationPrivate,
+                                pBufHeader);
                         pComponentPrivate->nEmptyBufferDoneCount++;
-                    }
-                    else {
+                    } else {
                         pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
                     }
 
@@ -1828,53 +1794,55 @@
                     goto EXIT;
                 }
             } else {
-                if((pComponentPrivate->nHoldLength+pBufHeader->nFilledLen) > pBufHeader->nAllocLen){
+                if ((pComponentPrivate->nHoldLength + pBufHeader->nFilledLen) > pBufHeader->nAllocLen) {
                     /*means that a second Acumulator must be used to insert holdbuffer to pbuffer and save remaining bytes
                       into hold buffer*/
-                    remainingBytes = pComponentPrivate->nHoldLength+pBufHeader->nFilledLen-pBufHeader->nAllocLen;
+                    remainingBytes = pComponentPrivate->nHoldLength + pBufHeader->nFilledLen - pBufHeader->nAllocLen;
+
                     if (pComponentPrivate->pHoldBuffer2 == NULL) {
-                        WBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer2,
-                                                 WBAMRENC_INPUT_BUFFER_SIZE,
-                                                 OMX_U8);
+                        OMX_MALLOC_SIZE(pComponentPrivate->pHoldBuffer2,
+                                        WBAMRENC_INPUT_BUFFER_SIZE,
+                                        OMX_U8);
                     }
-                    pExtraData = (pBufHeader->pBuffer)+(pBufHeader->nFilledLen-remainingBytes);
+
+                    pExtraData = (pBufHeader->pBuffer) + (pBufHeader->nFilledLen - remainingBytes);
                     memcpy(pComponentPrivate->pHoldBuffer2,
                            pExtraData,
                            remainingBytes);
-                    pBufHeader->nFilledLen-=remainingBytes;
-                    memmove(pBufHeader->pBuffer+ pComponentPrivate->nHoldLength,
+                    pBufHeader->nFilledLen -= remainingBytes;
+                    memmove(pBufHeader->pBuffer + pComponentPrivate->nHoldLength,
                             pBufHeader->pBuffer,
                             pBufHeader->nFilledLen);
                     memcpy(pBufHeader->pBuffer,
                            pComponentPrivate->pHoldBuffer,
                            pComponentPrivate->nHoldLength);
-                    pBufHeader->nFilledLen+=pComponentPrivate->nHoldLength;
+                    pBufHeader->nFilledLen += pComponentPrivate->nHoldLength;
                     memcpy(pComponentPrivate->pHoldBuffer,
                            pComponentPrivate->pHoldBuffer2,
                            remainingBytes);
-                    pComponentPrivate->nHoldLength=remainingBytes;
-                    remainingBytes=0;
-                }
-                else{
-                    memmove(pBufHeader->pBuffer+pComponentPrivate->nHoldLength,
+                    pComponentPrivate->nHoldLength = remainingBytes;
+                    remainingBytes = 0;
+                } else {
+                    memmove(pBufHeader->pBuffer + pComponentPrivate->nHoldLength,
                             pBufHeader->pBuffer,
                             pBufHeader->nFilledLen);
                     memcpy(pBufHeader->pBuffer,
                            pComponentPrivate->pHoldBuffer,
                            pComponentPrivate->nHoldLength);
-                    pBufHeader->nFilledLen+=pComponentPrivate->nHoldLength;
-                    pComponentPrivate->nHoldLength=0;
+                    pBufHeader->nFilledLen += pComponentPrivate->nHoldLength;
+                    pComponentPrivate->nHoldLength = 0;
                 }
+
                 frameLength = WBAMRENC_INPUT_BUFFER_SIZE;
                 nFrames = (OMX_U8)(pBufHeader->nFilledLen / frameLength);
-                pComponentPrivate->nHoldLength = pBufHeader->nFilledLen - frameLength*nFrames;
-                pExtraData = pBufHeader->pBuffer + pBufHeader->nFilledLen-pComponentPrivate->nHoldLength;
+                pComponentPrivate->nHoldLength = pBufHeader->nFilledLen - frameLength * nFrames;
+                pExtraData = pBufHeader->pBuffer + pBufHeader->nFilledLen - pComponentPrivate->nHoldLength;
                 memcpy(pComponentPrivate->pHoldBuffer,
                        pExtraData,
                        pComponentPrivate->nHoldLength);
-                pBufHeader->nFilledLen-=pComponentPrivate->nHoldLength;
+                pBufHeader->nFilledLen -= pComponentPrivate->nHoldLength;
 
-                if(nFrames < 1 ){
+                if (nFrames < 1 ) {
                     if (pComponentPrivate->curState != OMX_StatePause) {
                         OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling EmptyBufferDone\n");
 #ifdef __PERF_INSTRUMENTATION__
@@ -1884,18 +1852,17 @@
                                           PERF_ModuleHLMM);
 #endif
                         pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
-                                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                                   pBufHeader);
+                                pComponentPrivate->pHandle->pApplicationPrivate,
+                                pBufHeader);
                         pComponentPrivate->nEmptyBufferDoneCount++;
                         goto EXIT;
-                    }
-                    else {
+                    } else {
                         pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
                     }
                 }
             }
-        }else{
-            if((pBufHeader->nFlags & OMX_BUFFERFLAG_EOS)!= OMX_BUFFERFLAG_EOS){
+        } else {
+            if ((pBufHeader->nFlags & OMX_BUFFERFLAG_EOS) != OMX_BUFFERFLAG_EOS) {
                 if (pComponentPrivate->dasfMode == 0 && !pBufHeader->pMarkData) {
 #ifdef __PERF_INSTRUMENTATION__
                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
@@ -1904,24 +1871,24 @@
                                       PERF_ModuleHLMM);
 #endif
                     pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
-                                                               pComponentPrivate->pHandle->pApplicationPrivate,
-                                                               pComponentPrivate->pInputBufferList->pBufHdr[0]);
+                            pComponentPrivate->pHandle->pApplicationPrivate,
+                            pComponentPrivate->pInputBufferList->pBufHdr[0]);
                     pComponentPrivate->nEmptyBufferDoneCount++;
                     pComponentPrivate->ProcessingInputBuf--;
                 }
-            }
-            else{
+            } else {
                 frameLength = WBAMRENC_INPUT_FRAME_SIZE;
-                nFrames=1;
+                nFrames = 1;
             }
         }
 
-        if(nFrames >= 1){
+        if (nFrames >= 1) {
 
             eError = WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,
-                                                         pBufHeader->pBuffer,
-                                                         OMX_DirInput,
-                                                         &pLcmlHdr);
+                     pBufHeader->pBuffer,
+                     OMX_DirInput,
+                     &pLcmlHdr);
+
             if (eError != OMX_ErrorNone) {
                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Error: Invalid Buffer Came ...\n");
                 goto EXIT;
@@ -1929,7 +1896,7 @@
 
 #ifdef __PERF_INSTRUMENTATION__
             PERF_SendingFrame(pComponentPrivate->pPERFcomp,
-                              PREF(pBufHeader,pBuffer),
+                              PREF(pBufHeader, pBuffer),
                               pPortDefIn->nBufferSize,
                               PERF_ModuleCommonLayer);
 #endif
@@ -1938,12 +1905,8 @@
             pComponentPrivate->nNumOfFramesSent = nFrames;
             phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 
-            if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){
-                pBufParmsTemp = (OMX_U8*)pLcmlHdr->pFrameParam; /*This means that more memory need to be used*/
-                pBufParmsTemp -=EXTRA_BYTES;
-                OMX_WBMEMFREE_STRUCT(pBufParmsTemp);
-                pLcmlHdr->pFrameParam = NULL;
-                pBufParmsTemp =NULL;
+            if ( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam != NULL) ) {
+                OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam, OMX_U8);
 
                 OMX_DmmUnMap(phandle->dspCodec->hProc, /*Unmap DSP memory used*/
                              (void*)pLcmlHdr->pBufferParam->pParamElem,
@@ -1951,30 +1914,33 @@
                 pLcmlHdr->pBufferParam->pParamElem = NULL;
             }
 
-            if(pLcmlHdr->pFrameParam==NULL ){
-                WBAMRENC_OMX_MALLOC_SIZE(pBufParmsTemp,
-                                         (sizeof(WBAMRENC_FrameStruct)*(nFrames)) + DSP_CACHE_ALIGNMENT,
+            if (pLcmlHdr->pFrameParam == NULL ) {
+                OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam,
+                                         (sizeof(WBAMRENC_FrameStruct)*(nFrames)),
                                          OMX_U8);
-                pLcmlHdr->pFrameParam =  (WBAMRENC_FrameStruct*)(pBufParmsTemp + EXTRA_BYTES);
 
                 eError = OMX_DmmMap(phandle->dspCodec->hProc,
-                                    (nFrames*sizeof(WBAMRENC_FrameStruct)),
+                                    (nFrames * sizeof(WBAMRENC_FrameStruct)),
                                     (void*)pLcmlHdr->pFrameParam,
                                     (pLcmlHdr->pDmmBuf), pComponentPrivate->dbg);
-                if (eError != OMX_ErrorNone){
+
+                if (eError != OMX_ErrorNone) {
                     OMX_ERROR4(pComponentPrivate->dbg, "OMX_DmmMap ERRROR!!!!\n");
                     goto EXIT;
                 }
+
                 pLcmlHdr->pBufferParam->pParamElem = (WBAMRENC_FrameStruct *) pLcmlHdr->pDmmBuf->pMapped;/*DSP Address*/
             }
 
-            for(i=0;i<nFrames;i++){
-                (pLcmlHdr->pFrameParam+i)->usLastFrame = 0;
+            for (i = 0; i < nFrames; i++) {
+                (pLcmlHdr->pFrameParam + i)->usLastFrame = 0;
             }
-            if(pBufHeader->nFlags & OMX_BUFFERFLAG_EOS) {
-                (pLcmlHdr->pFrameParam+(nFrames-1))->usLastFrame = OMX_BUFFERFLAG_EOS;
+
+            if (pBufHeader->nFlags & OMX_BUFFERFLAG_EOS) {
+                (pLcmlHdr->pFrameParam + (nFrames - 1))->usLastFrame = OMX_BUFFERFLAG_EOS;
                 pComponentPrivate->InBuf_Eos_alreadysent = 1; /*TRUE*/
             }
+
             pLcmlHdr->pBufferParam->usNbFrames = nFrames;
             /* Store time stamp information */
             pComponentPrivate->arrBufIndex[pComponentPrivate->IpBufindex] = pBufHeader->nTimeStamp;
@@ -1984,9 +1950,9 @@
             pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[OMX_DirOutput]->nBufferCountActual;
 
             if (pComponentPrivate->curState == OMX_StateExecuting) {
-                if(!pComponentPrivate->bDspStoppedWhileExecuting) {
-                    if (!WBAMRENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)) {
-                        WBAMRENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirInput,__LINE__);
+                if (!pComponentPrivate->bDspStoppedWhileExecuting) {
+                    if (!WBAMRENC_IsPending(pComponentPrivate, pBufHeader, OMX_DirInput)) {
+                        WBAMRENC_SetPending(pComponentPrivate, pBufHeader, OMX_DirInput, __LINE__);
                         OMX_PRINT1(pComponentPrivate->dbg,
                                    "IN BUFFER = %p (%ld)\n",
                                    pBufHeader->pBuffer,
@@ -1994,40 +1960,42 @@
                         eError = LCML_QueueBuffer( pLcmlHandle->pCodecinterfacehandle,
                                                    EMMCodecInputBuffer,
                                                    (OMX_U8 *)pBufHeader->pBuffer,
-                                                   frameLength*nFrames,
+                                                   frameLength * nFrames,
                                                    pBufHeader->nFilledLen,
                                                    (OMX_U8 *) pLcmlHdr->pBufferParam,
                                                    sizeof(WBAMRENC_ParamStruct),
                                                    NULL);
+
                         if (eError != OMX_ErrorNone) {
                             eError = OMX_ErrorHardware;
                             goto EXIT;
                         }
+
                         pComponentPrivate->lcml_nCntIp++;
                         pComponentPrivate->lcml_nIpBuf++;
                     }
                 }
-            }
-            else if (pComponentPrivate->curState == OMX_StatePause){
+            } else if (pComponentPrivate->curState == OMX_StatePause) {
                 pComponentPrivate->pInputBufHdrPending[pComponentPrivate->nNumInputBufPending++] = pBufHeader;
             }
+
             pComponentPrivate->ProcessingInputBuf--;
         }
 
-        if(pBufHeader->pMarkData){
-            if(pComponentPrivate->pOutputBufferList->pBufHdr[0]!=NULL) {
+        if (pBufHeader->pMarkData) {
+            if (pComponentPrivate->pOutputBufferList->pBufHdr[0] != NULL) {
                 /* copy mark to output buffer header */
                 OMX_PRBUFFER2(pComponentPrivate->dbg,
                               "Copy mark to buffer %p\n",
                               pComponentPrivate->pOutputBufferList->pBufHdr[0]);
                 pComponentPrivate->pOutputBufferList->pBufHdr[0]->pMarkData = pBufHeader->pMarkData;
                 pComponentPrivate->pOutputBufferList->pBufHdr[0]->hMarkTargetComponent = pBufHeader->hMarkTargetComponent;
-            }
-            else{
+            } else {
                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Buffer Mark on NULL\n");
             }
+
             /* trigger event handler if we are supposed to */
-            if((pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle) && pBufHeader->pMarkData){
+            if ((pBufHeader->hMarkTargetComponent == pComponentPrivate->pHandle) && pBufHeader->pMarkData) {
                 OMX_PRINT2(pComponentPrivate->dbg, "OMX Event Mark\n");
                 pComponentPrivate->cbInfo.EventHandler( pComponentPrivate->pHandle,
                                                         pComponentPrivate->pHandle->pApplicationPrivate,
@@ -2038,7 +2006,7 @@
             }
 
             if (pComponentPrivate->curState != OMX_StatePause &&
-                !WBAMRENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirInput)){
+                    !WBAMRENC_IsPending(pComponentPrivate, pBufHeader, OMX_DirInput)) {
                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling EmptyBufferDone\n");
 #ifdef __PERF_INSTRUMENTATION__
                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
@@ -2047,8 +2015,8 @@
                                   PERF_ModuleHLMM);
 #endif
                 pComponentPrivate->cbInfo.EmptyBufferDone( pComponentPrivate->pHandle,
-                                                           pComponentPrivate->pHandle->pApplicationPrivate,
-                                                           pBufHeader);
+                        pComponentPrivate->pHandle->pApplicationPrivate,
+                        pBufHeader);
                 pComponentPrivate->nEmptyBufferDoneCount++;
             }
         }
@@ -2058,19 +2026,16 @@
          */
 
         nFrames = pComponentPrivate->nNumOfFramesSent;
-        if(nFrames == 0)
+
+        if (nFrames == 0)
             nFrames = 1;
 
-        eError = WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);
+        eError = WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate, pBufHeader->pBuffer, OMX_DirOutput, &pLcmlHdr);
 
         phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)pLcmlHandle->pCodecinterfacehandle)->pCodec);
 
-        if( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam!=NULL) ){
-            pBufParmsTemp = (OMX_U8*)pLcmlHdr->pFrameParam; /*This means that more memory need to be used*/
-            pBufParmsTemp -=EXTRA_BYTES;
-            OMX_WBMEMFREE_STRUCT(pBufParmsTemp);
-            pLcmlHdr->pFrameParam = NULL;
-            pBufParmsTemp =NULL;
+        if ( (pLcmlHdr->pBufferParam->usNbFrames < nFrames) && (pLcmlHdr->pFrameParam != NULL) ) {
+            OMX_MEMFREE_STRUCT_DSPALIGN(pLcmlHdr->pFrameParam, OMX_U8);
 #ifndef UNDER_CE
             OMX_DmmUnMap(phandle->dspCodec->hProc,
                          (void*)pLcmlHdr->pBufferParam->pParamElem,
@@ -2079,23 +2044,22 @@
 #endif
         }
 
-        if(pLcmlHdr->pFrameParam==NULL ){
-            WBAMRENC_OMX_MALLOC_SIZE(pBufParmsTemp,
-                                     (sizeof(WBAMRENC_FrameStruct)*nFrames) + DSP_CACHE_ALIGNMENT,
+        if (pLcmlHdr->pFrameParam == NULL ) {
+            OMX_MALLOC_SIZE_DSPALIGN(pLcmlHdr->pFrameParam,
+                                     sizeof(WBAMRENC_FrameStruct)*nFrames,
                                      OMX_U8);
 
-            pLcmlHdr->pFrameParam =  (WBAMRENC_FrameStruct*)(pBufParmsTemp + EXTRA_BYTES );
             pLcmlHdr->pBufferParam->pParamElem = NULL;
 #ifndef UNDER_CE
             eError = OMX_DmmMap(phandle->dspCodec->hProc,
-                                (nFrames*sizeof(WBAMRENC_FrameStruct)),
+                                (nFrames * sizeof(WBAMRENC_FrameStruct)),
                                 (void*)pLcmlHdr->pFrameParam,
-                                (pLcmlHdr->pDmmBuf),pComponentPrivate->dbg );
-            if (eError != OMX_ErrorNone)
-                {
-                    OMX_ERROR4(pComponentPrivate->dbg, "OMX_DmmMap ERRROR!!!!\n");
-                    goto EXIT;
-                }
+                                (pLcmlHdr->pDmmBuf), pComponentPrivate->dbg );
+
+            if (eError != OMX_ErrorNone) {
+                OMX_ERROR4(pComponentPrivate->dbg, "OMX_DmmMap ERRROR!!!!\n");
+                goto EXIT;
+            }
 
             pLcmlHdr->pBufferParam->pParamElem = (WBAMRENC_FrameStruct *)pLcmlHdr->pDmmBuf->pMapped; /*DSP Address*/
 #endif
@@ -2105,13 +2069,14 @@
 
 #ifdef __PERF_INSTRUMENTATION__
         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
-                          PREF(pBufHeader,pBuffer),
+                          PREF(pBufHeader, pBuffer),
                           0,
                           PERF_ModuleCommonLayer);
 #endif
+
         if (pComponentPrivate->curState == OMX_StateExecuting) {
-            if (!WBAMRENC_IsPending(pComponentPrivate,pBufHeader,OMX_DirOutput)) {
-                WBAMRENC_SetPending(pComponentPrivate,pBufHeader,OMX_DirOutput,__LINE__);
+            if (!WBAMRENC_IsPending(pComponentPrivate, pBufHeader, OMX_DirOutput)) {
+                WBAMRENC_SetPending(pComponentPrivate, pBufHeader, OMX_DirOutput, __LINE__);
                 OMX_PRINT1(pComponentPrivate->dbg,
                            "OUT BUFFER = %p (%d)\n",
                            pBufHeader->pBuffer,
@@ -2124,26 +2089,37 @@
                                            (OMX_U8 *) pLcmlHdr->pBufferParam,
                                            sizeof(WBAMRENC_ParamStruct),
                                            NULL);
+
                 if (eError != OMX_ErrorNone ) {
                     OMX_ERROR4(pComponentPrivate->dbg, "IssuingDSP OP: Error Occurred\n");
                     eError = OMX_ErrorHardware;
                     goto EXIT;
                 }
+
                 pComponentPrivate->lcml_nOpBuf++;
             }
-        }
-        else if(pComponentPrivate->curState == OMX_StatePause){
+        } else if (pComponentPrivate->curState == OMX_StatePause) {
             pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
         }
 
         pComponentPrivate->ProcessingOutputBuf--;
-    }
-    else {
+    } else {
         eError = OMX_ErrorBadParameter;
     }
- EXIT:
+
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning error %d\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning error %d\n", eError);
+
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
+
     return eError;
 }
 
@@ -2159,19 +2135,20 @@
 /*-------------------------------------------------------------------*/
 
 OMX_ERRORTYPE WBAMRENC_GetBufferDirection(OMX_BUFFERHEADERTYPE *pBufHeader,
-                                          OMX_DIRTYPE *eDir)
-{
+        OMX_DIRTYPE *eDir) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate = pBufHeader->pPlatformPrivate;
     OMX_U32 nBuf = 0;
     OMX_BUFFERHEADERTYPE *pBuf = NULL;
-    OMX_U32 flag = 1,i = 0;
+    OMX_U32 flag = 1, i = 0;
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
     /*Search this buffer in input buffers list */
     nBuf = pComponentPrivate->pInputBufferList->numBuffers;
-    for(i=0; i<nBuf; i++) {
+
+    for (i = 0; i < nBuf; i++) {
         pBuf = pComponentPrivate->pInputBufferList->pBufHdr[i];
-        if(pBufHeader == pBuf) {
+
+        if (pBufHeader == pBuf) {
             *eDir = OMX_DirInput;
             OMX_PRBUFFER2(pComponentPrivate->dbg,
                           "pBufHeader = %p is INPUT BUFFER pBuf = %p\n",
@@ -2181,15 +2158,18 @@
             goto EXIT;
         }
     }
+
     /*Search this buffer in output buffers list */
     nBuf = pComponentPrivate->pOutputBufferList->numBuffers;
-    for(i=0; i<nBuf; i++) {
+
+    for (i = 0; i < nBuf; i++) {
         pBuf = pComponentPrivate->pOutputBufferList->pBufHdr[i];
-        if(pBufHeader == pBuf) {
+
+        if (pBufHeader == pBuf) {
             *eDir = OMX_DirOutput;
-            OMX_ERROR2(pComponentPrivate->dbg, "pBufHeader = %p is OUTPUT BUFFER pBuf = %p\n",
-                       pBufHeader,
-                       pBuf);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBufHeader = %p is OUTPUT BUFFER pBuf = %p\n",
+                          pBufHeader,
+                          pBuf);
             flag = 0;
             goto EXIT;
         }
@@ -2201,9 +2181,10 @@
         eError = OMX_ErrorUndefined;
         goto EXIT;
     }
- EXIT:
+
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return eError;
 }
 
@@ -2219,10 +2200,9 @@
  **/
 /* -------------------------------------------------------------------*/
 OMX_ERRORTYPE WBAMRENC_GetCorrespondingLCMLHeader(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate,
-                                                  OMX_U8 *pBuffer,
-                                                  OMX_DIRTYPE eDir,
-                                                  WBAMRENC_LCML_BUFHEADERTYPE **ppLcmlHdr)
-{
+        OMX_U8 *pBuffer,
+        OMX_DIRTYPE eDir,
+        WBAMRENC_LCML_BUFHEADERTYPE **ppLcmlHdr) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     WBAMRENC_LCML_BUFHEADERTYPE *pLcmlBufHeader;
 
@@ -2234,6 +2214,7 @@
     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
+
     while (!pComponentPrivate->bInitParamsInitialized) {
         OMX_PRSTATE2(pComponentPrivate->dbg,
                      "Waiting for init to complete........\n");
@@ -2243,38 +2224,45 @@
         Sleep(0);
 #endif
     }
-    if(eDir == OMX_DirInput) {
+
+    if (eDir == OMX_DirInput) {
         pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[WBAMRENC_INPUT_PORT];
-        for(i = 0; i < nIpBuf; i++) {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
+
+        for (i = 0; i < nIpBuf; i++) {
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n", pBuffer);
             OMX_PRBUFFER2(pComponentPrivate->dbg,
                           "pLcmlBufHeader->buffer->pBuffer = %p\n",
                           pLcmlBufHeader->buffer->pBuffer);
-            if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
+
+            if (pBuffer == pLcmlBufHeader->buffer->pBuffer) {
                 *ppLcmlHdr = pLcmlBufHeader;
-                OMX_ERROR2(pComponentPrivate->dbg,
+                OMX_PRDSP2(pComponentPrivate->dbg,
                            "Corresponding Input LCML Header Found = %p\n",
                            pLcmlBufHeader);
                 eError = OMX_ErrorNone;
                 goto EXIT;
             }
+
             pLcmlBufHeader++;
         }
     } else if (eDir == OMX_DirOutput) {
         pLcmlBufHeader = pComponentPrivate->pLcmlBufHeader[WBAMRENC_OUTPUT_PORT];
-        for(i = 0; i < nOpBuf; i++) {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n",pBuffer);
+
+        for (i = 0; i < nOpBuf; i++) {
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p\n", pBuffer);
             OMX_PRBUFFER2(pComponentPrivate->dbg,
                           "pLcmlBufHeader->buffer->pBuffer = %p\n",
                           pLcmlBufHeader->buffer->pBuffer);
-            if(pBuffer == pLcmlBufHeader->buffer->pBuffer) {
+
+            if (pBuffer == pLcmlBufHeader->buffer->pBuffer) {
                 *ppLcmlHdr = pLcmlBufHeader;
-                OMX_ERROR2(pComponentPrivate->dbg,
+                OMX_PRDSP2(pComponentPrivate->dbg,
                            "Corresponding Output LCML Header Found = %p\n",
                            pLcmlBufHeader);
                 eError = OMX_ErrorNone;
                 goto EXIT;
             }
+
             pLcmlBufHeader++;
         }
     } else {
@@ -2282,9 +2270,9 @@
         eError = OMX_ErrorUndefined;
     }
 
- EXIT:
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return eError;
 }
 
@@ -2304,13 +2292,12 @@
                               **/
 /*-------------------------------------------------------------------*/
 
-OMX_ERRORTYPE WBAMRENC_LCMLCallback (TUsnCodecEvent event,void * args[10])
-{
+OMX_ERRORTYPE WBAMRENC_LCMLCallback (TUsnCodecEvent event, void * args[10]) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U8 *pBuffer = args[1];
     WBAMRENC_LCML_BUFHEADERTYPE *pLcmlHdr;
 
-    OMX_U16 i,index,frameLength, length;
+    OMX_U16 i, index, frameLength, length;
     OMX_COMPONENTTYPE *pHandle;
     LCML_DSP_INTERFACE *pLcmlHandle;
     OMX_U8 nFrames;
@@ -2321,242 +2308,256 @@
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
 
-    switch(event) {
+    switch (event) {
 
-    case EMMCodecDspError:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecDspError\n");
-        break;
+        case EMMCodecDspError:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecDspError\n");
+            break;
 
-    case EMMCodecInternalError:
-        OMX_ERROR4(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecInternalError\n");
-        break;
+        case EMMCodecInternalError:
+            OMX_ERROR4(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecInternalError\n");
+            break;
 
-    case EMMCodecInitError:
-        OMX_ERROR4(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecInitError\n");
-        break;
+        case EMMCodecInitError:
+            OMX_ERROR4(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecInitError\n");
+            break;
 
-    case EMMCodecDspMessageRecieved:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecDspMessageRecieved\n");
-        break;
+        case EMMCodecDspMessageRecieved:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecDspMessageRecieved\n");
+            break;
 
-    case EMMCodecBufferProcessed:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecBufferProcessed\n");
-        break;
+        case EMMCodecBufferProcessed:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecBufferProcessed\n");
+            break;
 
-    case EMMCodecProcessingStarted:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingStarted\n");
-        break;
+        case EMMCodecProcessingStarted:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingStarted\n");
+            break;
 
-    case EMMCodecProcessingPaused:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingPaused\n");
-        break;
+        case EMMCodecProcessingPaused:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingPaused\n");
+            break;
 
-    case EMMCodecProcessingStoped:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingStoped\n");
-        break;
+        case EMMCodecProcessingStoped:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingStoped\n");
+            break;
 
-    case EMMCodecProcessingEof:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingEof\n");
-        break;
+        case EMMCodecProcessingEof:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecProcessingEof\n");
+            break;
 
-    case EMMCodecBufferNotProcessed:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecBufferNotProcessed\n");
-        break;
+        case EMMCodecBufferNotProcessed:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecBufferNotProcessed\n");
+            break;
 
-    case EMMCodecAlgCtrlAck:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecAlgCtrlAck\n");
-        break;
+        case EMMCodecAlgCtrlAck:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecAlgCtrlAck\n");
+            break;
 
-    case EMMCodecStrmCtrlAck:
-        OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecStrmCtrlAck\n");
-        break;
+        case EMMCodecStrmCtrlAck:
+            OMX_PRDSP2(pComponentPrivate->dbg, "[LCML CALLBACK EVENT]  EMMCodecStrmCtrlAck\n");
+            break;
     }
 
-    if(event == EMMCodecBufferProcessed)
-        {
-            if((OMX_U32)args[0] == EMMCodecInputBuffer) {
-                pComponentPrivate->nOutStandingEmptyDones++;
-                eError = WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,pBuffer, OMX_DirInput, &pLcmlHdr);
+    if (event == EMMCodecBufferProcessed) {
+        if ((OMX_U32)args[0] == EMMCodecInputBuffer) {
+            pComponentPrivate->nOutStandingEmptyDones++;
+            eError = WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate, pBuffer, OMX_DirInput, &pLcmlHdr);
+
+            if (eError != OMX_ErrorNone) {
+                OMX_ERROR4(pComponentPrivate->dbg, "Error: Invalid Buffer Came ...\n");
+                goto EXIT;
+            }
+
+#ifdef __PERF_INSTRUMENTATION__
+            PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
+                               PREF(pLcmlHdr->buffer, pBuffer),
+                               0,
+                               PERF_ModuleCommonLayer);
+#endif
+
+            WBAMRENC_ClearPending(pComponentPrivate, pLcmlHdr->buffer, OMX_DirInput, __LINE__);
+
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling EmptyBufferDone\n");
+#ifdef __PERF_INSTRUMENTATION__
+            PERF_SendingFrame(pComponentPrivate->pPERFcomp,
+                              pLcmlHdr->buffer->pBuffer,
+                              0,
+                              PERF_ModuleHLMM);
+#endif
+            pComponentPrivate->cbInfo.EmptyBufferDone(pHandle,
+                    pHandle->pApplicationPrivate,
+                    pLcmlHdr->buffer);
+
+
+            pComponentPrivate->nEmptyBufferDoneCount++;
+            pComponentPrivate->nOutStandingEmptyDones--;
+            pComponentPrivate->lcml_nIpBuf--;
+            pComponentPrivate->app_nBuf++;
+        } else if ((OMX_U32)args[0] == EMMCodecOuputBuffer) {
+
+            if (!WBAMRENC_IsValid(pComponentPrivate, pBuffer, OMX_DirOutput)) {
+
+                for (i = 0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
+#ifdef __PERF_INSTRUMENTATION__
+                    PERF_SendingFrame(pComponentPrivate->pPERFcomp,
+                                      pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer,
+                                      pComponentPrivate->pOutputBufferList->pBufHdr[i]->nFilledLen,
+                                      PERF_ModuleHLMM);
+#endif
+                    pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
+                            pComponentPrivate->pHandle->pApplicationPrivate,
+                            pComponentPrivate->pOutputBufferList->pBufHdr[i++]
+                                                             );
+                }
+            } else {
+                OMX_PRBUFFER2(pComponentPrivate->dbg, "OUTPUT: pBuffer = %p\n", pBuffer);
+                pComponentPrivate->nOutStandingFillDones++;
+                eError = WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,
+                         pBuffer,
+                         OMX_DirOutput,
+                         &pLcmlHdr);
+
                 if (eError != OMX_ErrorNone) {
                     OMX_ERROR4(pComponentPrivate->dbg, "Error: Invalid Buffer Came ...\n");
                     goto EXIT;
                 }
+
+                OMX_PRBUFFER2(pComponentPrivate->dbg,
+                              "Output: pLcmlHdr->buffer->pBuffer = %p\n",
+                              pLcmlHdr->buffer->pBuffer);
+                pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8];
+                pComponentPrivate->lcml_nCntOpReceived++;
 #ifdef __PERF_INSTRUMENTATION__
                 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
-                                   PREF(pLcmlHdr->buffer,pBuffer),
-                                   0,
+                                   PREF(pLcmlHdr->buffer, pBuffer),
+                                   PREF(pLcmlHdr->buffer, nFilledLen),
                                    PERF_ModuleCommonLayer);
-#endif
+                pComponentPrivate->nLcml_nCntOpReceived++;
 
-                WBAMRENC_ClearPending(pComponentPrivate,pLcmlHdr->buffer,OMX_DirInput,__LINE__);
-
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "Calling EmptyBufferDone\n");
-#ifdef __PERF_INSTRUMENTATION__
-                PERF_SendingFrame(pComponentPrivate->pPERFcomp,
-                                  pLcmlHdr->buffer->pBuffer,
-                                  0,
-                                  PERF_ModuleHLMM);
-#endif
-                pComponentPrivate->cbInfo.EmptyBufferDone(pHandle,
-                                                          pHandle->pApplicationPrivate,
-                                                          pLcmlHdr->buffer);
-
-
-                pComponentPrivate->nEmptyBufferDoneCount++;
-                pComponentPrivate->nOutStandingEmptyDones--;
-                pComponentPrivate->lcml_nIpBuf--;
-                pComponentPrivate->app_nBuf++;
-            }
-            else if((OMX_U32)args[0] == EMMCodecOuputBuffer) {
-
-                if (!WBAMRENC_IsValid(pComponentPrivate,pBuffer,OMX_DirOutput)) {
-
-                    for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
-#ifdef __PERF_INSTRUMENTATION__
-                        PERF_SendingFrame(pComponentPrivate->pPERFcomp,
-                                          pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer,
-                                          pComponentPrivate->pOutputBufferList->pBufHdr[i]->nFilledLen,
-                                          PERF_ModuleHLMM);
-#endif
-                        pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
-                                                                  pComponentPrivate->pHandle->pApplicationPrivate,
-                                                                  pComponentPrivate->pOutputBufferList->pBufHdr[i++]
-                                                                  );
-                    }
-                } else {
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "OUTPUT: pBuffer = %p\n", pBuffer);
-                    pComponentPrivate->nOutStandingFillDones++;
-                    eError = WBAMRENC_GetCorrespondingLCMLHeader(pComponentPrivate,
-                                                                 pBuffer,
-                                                                 OMX_DirOutput,
-                                                                 &pLcmlHdr);
-                    if (eError != OMX_ErrorNone) {
-                        OMX_ERROR4(pComponentPrivate->dbg, "Error: Invalid Buffer Came ...\n");
-                        goto EXIT;
-                    }
-
-                    OMX_PRBUFFER2(pComponentPrivate->dbg,
-                                  "Output: pLcmlHdr->buffer->pBuffer = %p\n",
-                                  pLcmlHdr->buffer->pBuffer);
-                    pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8];
-                    pComponentPrivate->lcml_nCntOpReceived++;
-#ifdef __PERF_INSTRUMENTATION__
-                    PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
-                                       PREF(pLcmlHdr->buffer,pBuffer),
-                                       PREF(pLcmlHdr->buffer,nFilledLen),
-                                       PERF_ModuleCommonLayer);
-                    pComponentPrivate->nLcml_nCntOpReceived++;
-                    if ((pComponentPrivate->nLcml_nCntIp >= 1) && (pComponentPrivate->nLcml_nCntOpReceived == 1)) {
-                        PERF_Boundary(pComponentPrivate->pPERFcomp,
-                                      PERF_BoundaryStart | PERF_BoundarySteadyState);
-                    }
-#endif
-                    OMX_PRBUFFER2(pComponentPrivate->dbg,
-                                  "Output: pBuffer = %ld\n",
-                                  pLcmlHdr->buffer->nFilledLen);
-
-                    WBAMRENC_ClearPending(pComponentPrivate,
-                                          pLcmlHdr->buffer,
-                                          OMX_DirOutput,
-                                          __LINE__);
-                    pComponentPrivate->LastOutbuf = pLcmlHdr->buffer;
-                    if((pComponentPrivate->frameMode == WBAMRENC_MIMEMODE)&&(pLcmlHdr->buffer->nFilledLen)) {
-                        nFrames = (OMX_U8)(pLcmlHdr->buffer->nFilledLen / WBAMRENC_OUTPUT_BUFFER_SIZE_MIME);
-                        frameLength=0;
-                        length=0;
-                        for(i=0;i<nFrames;i++){
-                            index = (pLcmlHdr->buffer->pBuffer[i*WBAMRENC_OUTPUT_BUFFER_SIZE_MIME] >> 3) & 0x0F;
-                            if(pLcmlHdr->buffer->nFilledLen == 0)
-                                length = 0;
-                            else
-                                length = (OMX_U16)pComponentPrivate->amrMimeBytes[index];
-                            if (i){
-                                memmove( pLcmlHdr->buffer->pBuffer + frameLength,
-                                         pLcmlHdr->buffer->pBuffer + (i * WBAMRENC_OUTPUT_BUFFER_SIZE_MIME),
-                                         length);
-                            }
-                            frameLength += length;
-                        }
-                        pLcmlHdr->buffer->nFilledLen= frameLength;
-
-                    }
-
-                    else if((pComponentPrivate->frameMode == WBAMRENC_IF2)&&(pLcmlHdr->buffer->nFilledLen)) {
-                        nFrames = (OMX_U8)( pLcmlHdr->buffer->nFilledLen / WBAMRENC_OUTPUT_BUFFER_SIZE_IF2);
-                        frameLength=0;
-                        length=0;
-                        for(i=0;i<nFrames;i++){
-                            index = (pLcmlHdr->buffer->pBuffer[i*WBAMRENC_OUTPUT_BUFFER_SIZE_IF2] >> 4) & 0x0F;
-                            if(pLcmlHdr->buffer->nFilledLen == 0)
-                                length = 0;
-                            else
-                                length = (OMX_U16)pComponentPrivate->amrIf2Bytes[index];
-                            if (i){
-                                memmove( pLcmlHdr->buffer->pBuffer + frameLength,
-                                         pLcmlHdr->buffer->pBuffer + (i * WBAMRENC_OUTPUT_BUFFER_SIZE_IF2),
-                                         length);
-                            }
-
-                            frameLength += length;
-                        }
-                        pLcmlHdr->buffer->nFilledLen= frameLength;
-                    }
-                    else{
-                        nFrames = pLcmlHdr->buffer->nFilledLen/WBAMRENC_OUTPUT_FRAME_SIZE;
-                    }
-
-                    if( !pComponentPrivate->dasfMode ){
-                        /* Copying time stamp information to output buffer */
-                        pLcmlHdr->buffer->nTimeStamp = (OMX_TICKS)pComponentPrivate->arrBufIndex[pComponentPrivate->OpBufindex];
-                        /* Copying nTickCount information to output buffer */
-                        pLcmlHdr->buffer->nTickCount = pComponentPrivate->arrTickCount[pComponentPrivate->OpBufindex];
-                        pComponentPrivate->OpBufindex++;
-                        pComponentPrivate->OpBufindex %= pComponentPrivate->pPortDef[OMX_DirOutput]->nBufferCountActual;
-                    }
-
-                    if(pComponentPrivate->InBuf_Eos_alreadysent){
-
-                        pLcmlHdr->buffer->nFlags |= OMX_BUFFERFLAG_EOS;
-
-                        pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                               pHandle->pApplicationPrivate,
-                                                               OMX_EventBufferFlag,
-                                                               pLcmlHdr->buffer->nOutputPortIndex,
-                                                               pLcmlHdr->buffer->nFlags,
-                                                               NULL);
-                        pComponentPrivate->InBuf_Eos_alreadysent = 0;
-                    }
-
-                    /* Non Multi Frame Mode has been tested here */
-#ifdef __PERF_INSTRUMENTATION__
-                    PERF_SendingBuffer(pComponentPrivate->pPERFcomp,
-                                       pLcmlHdr->buffer->pBuffer,
-                                       pLcmlHdr->buffer->nFilledLen,
-                                       PERF_ModuleHLMM);
-#endif
-                    pComponentPrivate->nFillBufferDoneCount++;
-                    pComponentPrivate->nOutStandingFillDones--;
-                    pComponentPrivate->lcml_nOpBuf--;
-                    pComponentPrivate->app_nBuf++;
-
-                    pComponentPrivate->cbInfo.FillBufferDone(pHandle,
-                                                             pHandle->pApplicationPrivate,
-                                                             pLcmlHdr->buffer);
-
-                    OMX_PRBUFFER2(pComponentPrivate->dbg,
-                                  "Incrementing app_nBuf = %ld\n",
-                                  pComponentPrivate->app_nBuf);
+                if ((pComponentPrivate->nLcml_nCntIp >= 1) && (pComponentPrivate->nLcml_nCntOpReceived == 1)) {
+                    PERF_Boundary(pComponentPrivate->pPERFcomp,
+                                  PERF_BoundaryStart | PERF_BoundarySteadyState);
                 }
+
+#endif
+                OMX_PRBUFFER2(pComponentPrivate->dbg,
+                              "Output: pBuffer = %ld\n",
+                              pLcmlHdr->buffer->nFilledLen);
+
+                WBAMRENC_ClearPending(pComponentPrivate,
+                                      pLcmlHdr->buffer,
+                                      OMX_DirOutput,
+                                      __LINE__);
+                pComponentPrivate->LastOutbuf = pLcmlHdr->buffer;
+
+                if ((pComponentPrivate->frameMode == WBAMRENC_MIMEMODE) && (pLcmlHdr->buffer->nFilledLen)) {
+                    nFrames = (OMX_U8)(pLcmlHdr->buffer->nFilledLen / WBAMRENC_OUTPUT_BUFFER_SIZE_MIME);
+                    frameLength = 0;
+                    length = 0;
+
+                    for (i = 0; i < nFrames; i++) {
+                        index = (pLcmlHdr->buffer->pBuffer[i*WBAMRENC_OUTPUT_BUFFER_SIZE_MIME] >> 3) & 0x0F;
+
+                        if (pLcmlHdr->buffer->nFilledLen == 0)
+                            length = 0;
+                        else
+                            length = (OMX_U16)pComponentPrivate->amrMimeBytes[index];
+
+                        if (i) {
+                            memmove( pLcmlHdr->buffer->pBuffer + frameLength,
+                                     pLcmlHdr->buffer->pBuffer + (i * WBAMRENC_OUTPUT_BUFFER_SIZE_MIME),
+                                     length);
+                        }
+
+                        frameLength += length;
+                    }
+
+                    pLcmlHdr->buffer->nFilledLen = frameLength;
+
+                }
+
+                else if ((pComponentPrivate->frameMode == WBAMRENC_IF2) && (pLcmlHdr->buffer->nFilledLen)) {
+                    nFrames = (OMX_U8)( pLcmlHdr->buffer->nFilledLen / WBAMRENC_OUTPUT_BUFFER_SIZE_IF2);
+                    frameLength = 0;
+                    length = 0;
+
+                    for (i = 0; i < nFrames; i++) {
+                        index = (pLcmlHdr->buffer->pBuffer[i*WBAMRENC_OUTPUT_BUFFER_SIZE_IF2] >> 4) & 0x0F;
+
+                        if (pLcmlHdr->buffer->nFilledLen == 0)
+                            length = 0;
+                        else
+                            length = (OMX_U16)pComponentPrivate->amrIf2Bytes[index];
+
+                        if (i) {
+                            memmove( pLcmlHdr->buffer->pBuffer + frameLength,
+                                     pLcmlHdr->buffer->pBuffer + (i * WBAMRENC_OUTPUT_BUFFER_SIZE_IF2),
+                                     length);
+                        }
+
+                        frameLength += length;
+                    }
+
+                    pLcmlHdr->buffer->nFilledLen = frameLength;
+                } else {
+                    nFrames = pLcmlHdr->buffer->nFilledLen / WBAMRENC_OUTPUT_FRAME_SIZE;
+                }
+
+                if ( !pComponentPrivate->dasfMode ) {
+                    /* Copying time stamp information to output buffer */
+                    pLcmlHdr->buffer->nTimeStamp = (OMX_TICKS)pComponentPrivate->arrBufIndex[pComponentPrivate->OpBufindex];
+                    /* Copying nTickCount information to output buffer */
+                    pLcmlHdr->buffer->nTickCount = pComponentPrivate->arrTickCount[pComponentPrivate->OpBufindex];
+                    pComponentPrivate->OpBufindex++;
+                    pComponentPrivate->OpBufindex %= pComponentPrivate->pPortDef[OMX_DirOutput]->nBufferCountActual;
+                }
+
+                if (pComponentPrivate->InBuf_Eos_alreadysent) {
+
+                    pLcmlHdr->buffer->nFlags |= OMX_BUFFERFLAG_EOS;
+
+                    pComponentPrivate->cbInfo.EventHandler(pHandle,
+                                                           pHandle->pApplicationPrivate,
+                                                           OMX_EventBufferFlag,
+                                                           pLcmlHdr->buffer->nOutputPortIndex,
+                                                           pLcmlHdr->buffer->nFlags,
+                                                           NULL);
+                    pComponentPrivate->InBuf_Eos_alreadysent = 0;
+                }
+
+                /* Non Multi Frame Mode has been tested here */
+#ifdef __PERF_INSTRUMENTATION__
+                PERF_SendingBuffer(pComponentPrivate->pPERFcomp,
+                                   pLcmlHdr->buffer->pBuffer,
+                                   pLcmlHdr->buffer->nFilledLen,
+                                   PERF_ModuleHLMM);
+#endif
+                pComponentPrivate->nFillBufferDoneCount++;
+                pComponentPrivate->nOutStandingFillDones--;
+                pComponentPrivate->lcml_nOpBuf--;
+                pComponentPrivate->app_nBuf++;
+
+                pComponentPrivate->cbInfo.FillBufferDone(pHandle,
+                        pHandle->pApplicationPrivate,
+                        pLcmlHdr->buffer);
+
+                OMX_PRBUFFER2(pComponentPrivate->dbg,
+                              "Incrementing app_nBuf = %ld\n",
+                              pComponentPrivate->app_nBuf);
             }
         }
-    else if (event == EMMCodecStrmCtrlAck) {
+    } else if (event == EMMCodecStrmCtrlAck) {
         OMX_PRDSP2(pComponentPrivate->dbg, "GOT MESSAGE USN_DSPACK_STRMCTRL \n");
+
         if (args[1] == (void *)USN_STRMCMD_FLUSH) {
             pHandle = pComponentPrivate->pHandle;
+
             if ( args[2] == (void *)EMMCodecInputBuffer) {
                 if (args[0] == (void *)USN_ERR_NONE ) {
                     OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing input port\n");
-                    for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
+
+                    for (i = 0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
 
 #ifdef __PERF_INSTRUMENTATION__
                         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
@@ -2566,8 +2567,8 @@
 #endif
 
                         pComponentPrivate->cbInfo.EmptyBufferDone (pHandle,
-                                                                   pHandle->pApplicationPrivate,
-                                                                   pComponentPrivate->pInputBufHdrPending[i]);
+                                pHandle->pApplicationPrivate,
+                                pComponentPrivate->pInputBufHdrPending[i]);
                         pComponentPrivate->nEmptyBufferDoneCount++;
                         pComponentPrivate->nOutStandingEmptyDones--;
 
@@ -2584,11 +2585,11 @@
                                "LCML reported error while flushing input port\n");
                     goto EXIT;
                 }
-            }
-            else if ( args[2] == (void *)EMMCodecOuputBuffer) {
+            } else if ( args[2] == (void *)EMMCodecOuputBuffer) {
                 if (args[0] == (void *)USN_ERR_NONE ) {
                     OMX_PRCOMM2(pComponentPrivate->dbg, "Flushing output port\n");
-                    for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
+
+                    for (i = 0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
 #ifdef __PERF_INSTRUMENTATION__
                         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                                           pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer,
@@ -2596,12 +2597,13 @@
                                           PERF_ModuleHLMM);
 #endif
                         pComponentPrivate->cbInfo.FillBufferDone (pHandle,
-                                                                  pHandle->pApplicationPrivate,
-                                                                  pComponentPrivate->pOutputBufHdrPending[i]);
+                                pHandle->pApplicationPrivate,
+                                pComponentPrivate->pOutputBufHdrPending[i]);
                         pComponentPrivate->nFillBufferDoneCount++;
                         pComponentPrivate->nOutStandingFillDones--;
 
                     }
+
                     pComponentPrivate->cbInfo.EventHandler(pHandle,
                                                            pHandle->pApplicationPrivate,
                                                            OMX_EventCmdComplete,
@@ -2614,22 +2616,25 @@
                 }
             }
         }
-    }
-    else if(event == EMMCodecProcessingStoped) {
+    } else if (event == EMMCodecProcessingStoped) {
         OMX_PRINT2(pComponentPrivate->dbg, "GOT MESSAGE USN_DSPACK_STOP \n");
 
-        if((pComponentPrivate->nMultiFrameMode == 1) && (pComponentPrivate->frameMode == WBAMRENC_MIMEMODE)) {
+        if ((pComponentPrivate->nMultiFrameMode == 1) && (pComponentPrivate->frameMode == WBAMRENC_MIMEMODE)) {
             /*Sending Last Buufer Data which on iHoldBuffer to App */
             OMX_PRBUFFER2(pComponentPrivate->dbg,
                           "Sending iMMFDataLastBuffer Data which on iHoldBuffer to App\n");
-            WBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->iMMFDataLastBuffer,
-                                     WBAMRENC_OUTPUT_BUFFER_SIZE_MIME * (pComponentPrivate->pOutputBufferList->numBuffers + 1),
-                                     OMX_BUFFERHEADERTYPE);
+            OMX_MALLOC_SIZE(pComponentPrivate->iMMFDataLastBuffer,
+                            WBAMRENC_OUTPUT_BUFFER_SIZE_MIME * (pComponentPrivate->pOutputBufferList->numBuffers + 1),
+                            OMX_BUFFERHEADERTYPE);
 
             OMX_PRINT2(pComponentPrivate->dbg,
                        "pComponentPrivate->iHoldLen = %ld \n",
                        pComponentPrivate->iHoldLen);
             /* Copy the data from iHoldBuffer to dataPtr */
+	    if (pComponentPrivate->iHoldBuffer == NULL) {
+	        eError = OMX_ErrorBadParameter;
+		goto EXIT;
+	    }
             memcpy(pComponentPrivate->iMMFDataLastBuffer,
                    pComponentPrivate->iHoldBuffer,
                    pComponentPrivate->iHoldLen);
@@ -2647,8 +2652,8 @@
                               PERF_ModuleHLMM);
 #endif
             pComponentPrivate->cbInfo.FillBufferDone( pComponentPrivate->pHandle,
-                                                      pComponentPrivate->pHandle->pApplicationPrivate,
-                                                      pComponentPrivate->iMMFDataLastBuffer);
+                    pComponentPrivate->pHandle->pApplicationPrivate,
+                    pComponentPrivate->iMMFDataLastBuffer);
             pComponentPrivate->nFillBufferDoneCount++;
             pComponentPrivate->nOutStandingFillDones--;
             pComponentPrivate->lcml_nOpBuf--;
@@ -2659,7 +2664,7 @@
                           pComponentPrivate->app_nBuf);
         }
 
-        for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
+        for (i = 0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
 
             if (pComponentPrivate->pInputBufferList->bBufferPending[i]) {
 #ifdef __PERF_INSTRUMENTATION__
@@ -2670,8 +2675,8 @@
 #endif
 
                 pComponentPrivate->cbInfo.EmptyBufferDone (pComponentPrivate->pHandle,
-                                                           pComponentPrivate->pHandle->pApplicationPrivate,
-                                                           pComponentPrivate->pInputBufferList->pBufHdr[i]);
+                        pComponentPrivate->pHandle->pApplicationPrivate,
+                        pComponentPrivate->pInputBufferList->pBufHdr[i]);
                 pComponentPrivate->nEmptyBufferDoneCount++;
 
                 pComponentPrivate->nOutStandingEmptyDones--;
@@ -2681,7 +2686,8 @@
                                       __LINE__);
             }
         }
-        for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
+
+        for (i = 0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
             if (pComponentPrivate->pOutputBufferList->bBufferPending[i]) {
 #ifdef __PERF_INSTRUMENTATION__
                 PERF_SendingFrame(pComponentPrivate->pPERFcomp,
@@ -2690,8 +2696,8 @@
                                   PERF_ModuleHLMM);
 #endif
                 pComponentPrivate->cbInfo.FillBufferDone (pComponentPrivate->pHandle,
-                                                          pComponentPrivate->pHandle->pApplicationPrivate,
-                                                          pComponentPrivate->pOutputBufferList->pBufHdr[i]);
+                        pComponentPrivate->pHandle->pApplicationPrivate,
+                        pComponentPrivate->pOutputBufferList->pBufHdr[i]);
                 pComponentPrivate->nFillBufferDoneCount++;
                 pComponentPrivate->nOutStandingFillDones--;
 
@@ -2704,11 +2710,11 @@
 
 
         if (!pComponentPrivate->bNoIdleOnStop) {
-            pComponentPrivate->nNumOutputBufPending=0;
+            pComponentPrivate->nNumOutputBufPending = 0;
 
-            pComponentPrivate->ProcessingInputBuf=0;
-            pComponentPrivate->ProcessingOutputBuf=0;
-            pComponentPrivate->InBuf_Eos_alreadysent  =0;
+            pComponentPrivate->ProcessingInputBuf = 0;
+            pComponentPrivate->ProcessingOutputBuf = 0;
+            pComponentPrivate->InBuf_Eos_alreadysent  = 0;
             pComponentPrivate->curState = OMX_StateIdle;
 
             /* Decrement reference count with signal enabled */
@@ -2732,8 +2738,7 @@
                                                        OMX_CommandStateSet,
                                                        pComponentPrivate->curState,
                                                        NULL);
-            }
-            else {
+            } else {
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        OMX_EventError,
@@ -2742,116 +2747,60 @@
                                                        NULL);
             }
 
-        }else{
-            pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
+        } else {
+            pComponentPrivate->bNoIdleOnStop = OMX_FALSE;
             pComponentPrivate->bDspStoppedWhileExecuting = OMX_TRUE;
         }
     }
 
-    else if(event == EMMCodecDspMessageRecieved) {
-        OMX_PRSTATE2(pComponentPrivate->dbg, "commandedState  = %ld\n",(OMX_U32)args[0]);
-        OMX_PRINT2(pComponentPrivate->dbg, "arg1 = %ld\n",(OMX_U32)args[1]);
-        OMX_PRINT2(pComponentPrivate->dbg, "arg2 = %ld\n",(OMX_U32)args[2]);
+    else if (event == EMMCodecDspMessageRecieved) {
+        OMX_PRSTATE2(pComponentPrivate->dbg, "commandedState  = %ld\n", (OMX_U32)args[0]);
+        OMX_PRINT2(pComponentPrivate->dbg, "arg1 = %ld\n", (OMX_U32)args[1]);
+        OMX_PRINT2(pComponentPrivate->dbg, "arg2 = %ld\n", (OMX_U32)args[2]);
 
-        if(0x0500 == (OMX_U32)args[2]) {
+        if (0x0500 == (OMX_U32)args[2]) {
             OMX_PRINT2(pComponentPrivate->dbg, "EMMCodecDspMessageRecieved\n");
         }
-    }
-    else if(event == EMMCodecAlgCtrlAck) {
+    } else if (event == EMMCodecAlgCtrlAck) {
         OMX_PRDSP2(pComponentPrivate->dbg, "GOT MESSAGE USN_DSPACK_ALGCTRL \n");
-    }
-    else if (event == EMMCodecDspError) {
-#ifdef _ERROR_PROPAGATION__
-        /* Cheking for MMU_fault */
-        if(((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*) NULL)) {
-            pComponentPrivate->bIsInvalidState=OMX_TRUE;
-            pComponentPrivate->curState = OMX_StateInvalid;
-            pHandle = pComponentPrivate->pHandle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorInvalidState,
-                                                   OMX_TI_ErrorSevere,
-                                                   NULL);
-        }
-#endif
-        if(((int)args[4] == USN_ERR_WARNING) && ((int)args[5] == IUALG_WARN_PLAYCOMPLETED)) {
-            pHandle = pComponentPrivate->pHandle;
-            OMX_PRDSP2(pComponentPrivate->dbg, "GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n");
-            if(pComponentPrivate->LastOutbuf)
-                pComponentPrivate->LastOutbuf->nFlags = OMX_BUFFERFLAG_EOS;
+    } else if (event == EMMCodecDspError) {
+        switch ( (OMX_U32) args [4]) {
+                /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
+                 * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
+                 * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
+                 * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
+                 * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
+                 * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
+                 * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
+                 * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
 
-            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
-                                                   pComponentPrivate->pHandle->pApplicationPrivate,
-                                                   OMX_EventBufferFlag,
-                                                   (OMX_U32)NULL,
-                                                   OMX_BUFFERFLAG_EOS,
-                                                   NULL);
-        }
-        if((int)args[5] == IUALG_ERR_GENERAL) {
-            char *pArgs = "damedesuStr";
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Cannot continue" );
-            OMX_ERROR4(pComponentPrivate->dbg, "LCML_Callback: IUALG_ERR_GENERAL\n");
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-#ifndef UNDER_CE
-            eError = LCML_ControlCodec(
-                                       ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                       MMCodecControlStop,(void *)pArgs);
-            if(eError != OMX_ErrorNone) {
-                OMX_ERROR4(pComponentPrivate->dbg, "Error Occurred in Codec Stop..\n");
-                goto EXIT;
+#ifdef _ERROR_PROPAGATION__
+            case USN_ERR_PAUSE:
+            case USN_ERR_STOP:
+            case USN_ERR_ALGCTRL:
+            case USN_ERR_STRMCTRL:
+            case USN_ERR_UNKNOWN_MSG: {
+                pComponentPrivate->bIsInvalidState = OMX_TRUE;
+                pComponentPrivate->curState = OMX_StateInvalid;
+                pHandle = pComponentPrivate->pHandle;
+                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                                                       pHandle->pApplicationPrivate,
+                                                       OMX_EventError,
+                                                       OMX_ErrorInvalidState,
+                                                       OMX_TI_ErrorSevere,
+                                                       NULL);
             }
-            OMX_PRINT2(pComponentPrivate->dbg, "Codec has been Stopped\n");
-            pComponentPrivate->curState = OMX_StateIdle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventCmdComplete,
-                                                   OMX_ErrorNone,
-                                                   0,
-                                                   NULL);
-#else
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorUndefined,
-                                                   OMX_TI_ErrorSevere,
-                                                   NULL);
+            break;
 #endif
+
+            case USN_ERR_WARNING:
+            case USN_ERR_PROCESS:
+                WBAMRENC_HandleUSNError (pComponentPrivate, (OMX_U32)args[5]);
+                break;
+            default:
+                break;
         }
-        if( (int)args[5] == IUALG_ERR_DATA_CORRUPT ){
-            char *pArgs = "damedesuStr";
-            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm error. Corrupt data" );
-            OMX_ERROR4(pComponentPrivate->dbg, "LCML_Callback: IUALG_ERR_DATA_CORRUPT\n");
-            pHandle = pComponentPrivate->pHandle;
-            pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate->pLcmlHandle;
-#ifndef UNDER_CE
-            eError = LCML_ControlCodec(
-                                       ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                       MMCodecControlStop,(void *)pArgs);
-            if(eError != OMX_ErrorNone) {
-                OMX_ERROR4(pComponentPrivate->dbg, "Error Occurred in Codec Stop..\n");
-                goto EXIT;
-            }
-            OMX_PRINT2(pComponentPrivate->dbg, "Codec has been Stopped\n");
-            pComponentPrivate->curState = OMX_StateIdle;
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventCmdComplete,
-                                                   OMX_ErrorNone,
-                                                   0,
-                                                   NULL);
-#else
-            pComponentPrivate->cbInfo.EventHandler(pHandle,
-                                                   pHandle->pApplicationPrivate,
-                                                   OMX_EventError,
-                                                   OMX_ErrorUndefined,
-                                                   OMX_TI_ErrorSevere,
-                                                   NULL);
-#endif
-        }
-    }
-    else if (event == EMMCodecProcessingPaused) {
+    } else if (event == EMMCodecProcessingPaused) {
         pComponentPrivate->curState = OMX_StatePause;
 
         /* Decrement reference count with signal enabled */
@@ -2866,11 +2815,12 @@
                                                 pComponentPrivate->curState,
                                                 NULL);
     }
+
 #ifdef _ERROR_PROPAGATION__
-    else if (event ==EMMCodecInitError){
+    else if (event == EMMCodecInitError) {
         /* Cheking for MMU_fault */
-        if(((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) {
-            pComponentPrivate->bIsInvalidState=OMX_TRUE;
+        if (((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) {
+            pComponentPrivate->bIsInvalidState = OMX_TRUE;
             pComponentPrivate->curState = OMX_StateInvalid;
             pHandle = pComponentPrivate->pHandle;
             pComponentPrivate->cbInfo.EventHandler(pHandle,
@@ -2880,12 +2830,11 @@
                                                    OMX_TI_ErrorSevere,
                                                    NULL);
         }
-    }
-    else if (event ==EMMCodecInternalError){
+    } else if (event == EMMCodecInternalError) {
         /* Cheking for MMU_fault */
-        if(((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) {
+        if (((int)args[4] == USN_ERR_UNKNOWN_MSG) && (args[5] == (void*)NULL)) {
             OMX_ERROR4(pComponentPrivate->dbg, "MMU_Fault\n");
-            pComponentPrivate->bIsInvalidState=OMX_TRUE;
+            pComponentPrivate->bIsInvalidState = OMX_TRUE;
             pComponentPrivate->curState = OMX_StateInvalid;
             pHandle = pComponentPrivate->pHandle;
             pComponentPrivate->cbInfo.EventHandler(pHandle,
@@ -2897,10 +2846,11 @@
         }
 
     }
+
 #endif
- EXIT:
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
 
     return eError;
 }
@@ -2913,8 +2863,7 @@
  */
 /* ================================================================================= */
 #ifndef UNDER_CE
-OMX_HANDLETYPE WBAMRENC_GetLCMLHandle(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate)
-{
+OMX_HANDLETYPE WBAMRENC_GetLCMLHandle(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_ERRORTYPE (*fpGetHandle)(OMX_HANDLETYPE);
     OMX_HANDLETYPE pHandle = NULL;
@@ -2923,17 +2872,22 @@
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
     handle = dlopen("libLCML.so", RTLD_LAZY);
+
     if (!handle) {
         fputs(dlerror(), stderr);
         goto EXIT;
     }
+
     fpGetHandle = dlsym (handle, "GetHandle");
+
     if ((error = dlerror()) != NULL) {
         fputs(error, stderr);
         goto EXIT;
     }
+
     eError = (*fpGetHandle)(&pHandle);
-    if(eError != OMX_ErrorNone) {
+
+    if (eError != OMX_ErrorNone) {
         eError = OMX_ErrorUndefined;
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorUndefined...\n");
         pHandle = NULL;
@@ -2943,39 +2897,43 @@
     pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE*)pComponentPrivate;
     ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
 
-    pComponentPrivate->ptrLibLCML=handle;           /* saving LCML lib pointer  */
+    pComponentPrivate->ptrLibLCML = handle;         /* saving LCML lib pointer  */
 
- EXIT:
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return pHandle;
 }
 
 #else
 /*WINDOWS Explicit dll load procedure*/
-OMX_HANDLETYPE WBAMRENC_GetLCMLHandle(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate)
-{
+OMX_HANDLETYPE WBAMRENC_GetLCMLHandle(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate) {
     typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
     OMX_HANDLETYPE pHandle = NULL;
     OMX_ERRORTYPE eError;
     HINSTANCE hDLL;               // Handle to DLL
     LPFNDLLFUNC1 fpGetHandle1;
-    hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL,0);
+    hDLL = LoadLibraryEx(TEXT("OAF_BML.dll"), NULL, 0);
+
     if (hDLL == NULL) {
 
         OMX_ERROR4(pComponentPrivate->dbg, "BML Load Failed!!!\n");
         return pHandle;
     }
-    fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,TEXT("GetHandle"));
+
+    fpGetHandle1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, TEXT("GetHandle"));
+
     if (!fpGetHandle1) {
         // handle the error
         FreeLibrary(hDLL);
 
         return pHandle;
     }
+
     // call the function
     eError = fpGetHandle1(&pHandle);
-    if(eError != OMX_ErrorNone) {
+
+    if (eError != OMX_ErrorNone) {
         eError = OMX_ErrorUndefined;
         OMX_ERROR4(pComponentPrivate->dbg, "eError != OMX_ErrorNone...\n");
 
@@ -2983,6 +2941,7 @@
         pHandle = NULL;
         return pHandle;
     }
+
     ((LCML_DSP_INTERFACE*)pHandle)->pComponentPrivate = pComponentPrivate;
     return pHandle;
 }
@@ -3003,19 +2962,17 @@
  */
 /* ================================================================================ */
 void WBAMRENC_SetPending(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate,
-                         OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
-{
+                         OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber) {
     OMX_U16 i;
 
     if (eDir == OMX_DirInput) {
-        for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
+        for (i = 0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
                 pComponentPrivate->pInputBufferList->bBufferPending[i] = 1;
             }
         }
-    }
-    else {
-        for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
+    } else {
+        for (i = 0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
 
                 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 1;
@@ -3038,19 +2995,17 @@
  */
 /* ================================================================================ */
 void WBAMRENC_ClearPending(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate,
-                           OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber)
-{
+                           OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir, OMX_U32 lineNumber) {
     OMX_U16 i;
 
     if (eDir == OMX_DirInput) {
-        for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
+        for (i = 0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
                 pComponentPrivate->pInputBufferList->bBufferPending[i] = 0;
             }
         }
-    }
-    else {
-        for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
+    } else {
+        for (i = 0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
                 pComponentPrivate->pOutputBufferList->bBufferPending[i] = 0;
             }
@@ -3072,24 +3027,23 @@
  */
 /* ================================================================================ */
 OMX_U32 WBAMRENC_IsPending(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate,
-                           OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir)
-{
+                           OMX_BUFFERHEADERTYPE *pBufHdr, OMX_DIRTYPE eDir) {
     OMX_U16 i;
 
     if (eDir == OMX_DirInput) {
-        for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
+        for (i = 0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
             if (pBufHdr == pComponentPrivate->pInputBufferList->pBufHdr[i]) {
                 return pComponentPrivate->pInputBufferList->bBufferPending[i];
             }
         }
-    }
-    else {
-        for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
+    } else {
+        for (i = 0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
             if (pBufHdr == pComponentPrivate->pOutputBufferList->pBufHdr[i]) {
                 return pComponentPrivate->pOutputBufferList->bBufferPending[i];
             }
         }
     }
+
     return -1;
 }
 /* ================================================================================= */
@@ -3107,25 +3061,24 @@
  */
 /* ================================================================================ */
 OMX_U32 WBAMRENC_IsValid(WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate,
-                         OMX_U8 *pBuffer, OMX_DIRTYPE eDir)
-{
+                         OMX_U8 *pBuffer, OMX_DIRTYPE eDir) {
     OMX_U16 i;
-    int found=0;
+    int found = 0;
 
     if (eDir == OMX_DirInput) {
-        for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
+        for (i = 0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
             if (pBuffer == pComponentPrivate->pInputBufferList->pBufHdr[i]->pBuffer) {
                 found = 1;
             }
         }
-    }
-    else {
-        for (i=0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
+    } else {
+        for (i = 0; i < pComponentPrivate->pOutputBufferList->numBuffers; i++) {
             if (pBuffer == pComponentPrivate->pOutputBufferList->pBufHdr[i]->pBuffer) {
                 found = 1;
             }
         }
     }
+
     return found;
 }
 /* ========================================================================== */
@@ -3144,10 +3097,9 @@
  * @return none
  */
 /* ========================================================================== */
-OMX_ERRORTYPE WBAMRENC_FillLCMLInitParamsEx(OMX_HANDLETYPE pComponent)
-{
+OMX_ERRORTYPE WBAMRENC_FillLCMLInitParamsEx(OMX_HANDLETYPE pComponent) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    OMX_U32 nIpBuf,nIpBufSize,nOpBuf,nOpBufSize;
+    OMX_U32 nIpBuf, nIpBufSize, nOpBuf, nOpBufSize;
     OMX_BUFFERHEADERTYPE *pTemp;
     char *ptr;
     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
@@ -3155,7 +3107,6 @@
     WBAMRENC_LCML_BUFHEADERTYPE *pTemp_lcml = NULL;
     OMX_U16 i;
     OMX_U32 size_lcml;
-    OMX_U8 *pBufferParamTemp;
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering\n");
     nIpBuf = pComponentPrivate->pInputBufferList->numBuffers;
@@ -3163,19 +3114,20 @@
     nOpBuf = pComponentPrivate->pOutputBufferList->numBuffers;
     nOpBufSize = pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nBufferSize;
     OMX_PRBUFFER2(pComponentPrivate->dbg, "------ Buffer Details -----------\n");
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "Input  Buffer Count = %ld\n",nIpBuf);
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "Input  Buffer Size = %ld\n",nIpBufSize);
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "Output Buffer Count = %ld\n",nOpBuf);
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "Output Buffer Size = %ld\n",nOpBufSize);
+    OMX_PRBUFFER2(pComponentPrivate->dbg, "Input  Buffer Count = %ld\n", nIpBuf);
+    OMX_PRBUFFER2(pComponentPrivate->dbg, "Input  Buffer Size = %ld\n", nIpBufSize);
+    OMX_PRBUFFER2(pComponentPrivate->dbg, "Output Buffer Count = %ld\n", nOpBuf);
+    OMX_PRBUFFER2(pComponentPrivate->dbg, "Output Buffer Size = %ld\n", nOpBufSize);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "------ Buffer Details ------------\n");
     /* Allocate memory for all input buffer headers..
      * This memory pointer will be sent to LCML */
     size_lcml = nIpBuf * sizeof(WBAMRENC_LCML_BUFHEADERTYPE);
-    WBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,WBAMRENC_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, WBAMRENC_LCML_BUFHEADERTYPE);
 
 
     pComponentPrivate->pLcmlBufHeader[WBAMRENC_INPUT_PORT] = pTemp_lcml;
-    for (i=0; i<nIpBuf; i++) {
+
+    for (i = 0; i < nIpBuf; i++) {
         OMX_PRCOMM2(pComponentPrivate->dbg, "INPUT--------- Inside Ip Loop\n");
         pTemp = pComponentPrivate->pInputBufferList->pBufHdr[i];
         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
@@ -3185,18 +3137,16 @@
         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
         pTemp->nTickCount = WBAMRENC_NOT_USED;
         pTemp_lcml->buffer = pTemp;
-        OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml->buffer->pBuffer = %p \n",pTemp_lcml->buffer->pBuffer);
+        OMX_PRDSP2(pComponentPrivate->dbg, "pTemp_lcml->buffer->pBuffer = %p \n", pTemp_lcml->buffer->pBuffer);
         pTemp_lcml->eDir = OMX_DirInput;
 
-        WBAMRENC_OMX_MALLOC_SIZE(pBufferParamTemp, sizeof(WBAMRENC_ParamStruct) + DSP_CACHE_ALIGNMENT,OMX_U8);
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam, sizeof(WBAMRENC_ParamStruct), OMX_U8);
 
-        pTemp_lcml->pBufferParam =  (WBAMRENC_ParamStruct*)(pBufferParamTemp + EXTRA_BYTES);
+        pTemp_lcml->pBufferParam->usNbFrames = 0;
+        pTemp_lcml->pBufferParam->pParamElem = NULL;
+        pTemp_lcml->pFrameParam = NULL;
 
-        pTemp_lcml->pBufferParam->usNbFrames=0;
-        pTemp_lcml->pBufferParam->pParamElem=NULL;
-        pTemp_lcml->pFrameParam=NULL;
-
-        WBAMRENC_OMX_MALLOC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
+        OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
 
         /* This means, it is not a last buffer. This flag is to be modified by
@@ -3210,11 +3160,12 @@
      * This memory pointer will be sent to LCML */
     size_lcml = nOpBuf * sizeof(WBAMRENC_LCML_BUFHEADERTYPE);
 
-    WBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml,WBAMRENC_LCML_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, WBAMRENC_LCML_BUFHEADERTYPE);
 
 
     pComponentPrivate->pLcmlBufHeader[WBAMRENC_OUTPUT_PORT] = pTemp_lcml;
-    for (i=0; i<nOpBuf; i++) {
+
+    for (i = 0; i < nOpBuf; i++) {
         OMX_PRCOMM2(pComponentPrivate->dbg, "OUTPUT--------- Inside Op Loop\n");
         pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
         pTemp->nSize = sizeof(OMX_BUFFERHEADERTYPE);
@@ -3225,24 +3176,19 @@
         pTemp->pPlatformPrivate = pHandle->pComponentPrivate;
         pTemp->nTickCount = WBAMRENC_NOT_USED;
         pTemp_lcml->buffer = pTemp;
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "pTemp_lcml->buffer->pBuffer = %p \n",pTemp_lcml->buffer->pBuffer);
+        OMX_PRBUFFER2(pComponentPrivate->dbg, "pTemp_lcml->buffer->pBuffer = %p \n", pTemp_lcml->buffer->pBuffer);
         pTemp_lcml->eDir = OMX_DirOutput;
 
-        WBAMRENC_OMX_MALLOC_SIZE(pTemp_lcml->pBufferParam,
-                                 (sizeof(WBAMRENC_ParamStruct)+DSP_CACHE_ALIGNMENT),
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pBufferParam,
+                                 sizeof(WBAMRENC_ParamStruct),
                                  WBAMRENC_ParamStruct);
 
-        ptr = (char*)pTemp_lcml->pBufferParam;
-        ptr += EXTRA_BYTES;
-        pTemp_lcml->pBufferParam = (WBAMRENC_ParamStruct*)ptr;
+        pTemp_lcml->pBufferParam->usNbFrames = 0;
+        pTemp_lcml->pBufferParam->pParamElem = NULL;
+        pTemp_lcml->pFrameParam = NULL;
 
 
-        pTemp_lcml->pBufferParam->usNbFrames=0;
-        pTemp_lcml->pBufferParam->pParamElem=NULL;
-        pTemp_lcml->pFrameParam=NULL;
-
-
-        WBAMRENC_OMX_MALLOC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
+        OMX_MALLOC_GENERIC(pTemp_lcml->pDmmBuf, DMM_BUFFER_OBJ);
 
         /* This means, it is not a last buffer. This flag is to be modified by
          * the application to indicate the last buffer */
@@ -3250,10 +3196,11 @@
         pTemp++;
         pTemp_lcml++;
     }
+
     pComponentPrivate->bInitParamsInitialized = 1;
- EXIT:
+EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting\n");
-    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Returning = 0x%x\n", eError);
     return eError;
 }
 
@@ -3271,21 +3218,18 @@
 OMX_ERRORTYPE OMX_DmmMap(DSP_HPROCESSOR ProcHandle,
                          int size,
                          void* pArmPtr,
-                         DMM_BUFFER_OBJ* pDmmBuf, struct OMX_TI_Debug dbg)
-{
+                         DMM_BUFFER_OBJ* pDmmBuf, struct OMX_TI_Debug dbg) {
     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
     DSP_STATUS status;
     int nSizeReserved = 0;
 
-    if(pDmmBuf == NULL)
-    {
+    if (pDmmBuf == NULL) {
         OMX_ERROR4 (dbg, "pBuf is NULL\n");
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
 
-    if(pArmPtr == NULL)
-    {
+    if (pArmPtr == NULL) {
         OMX_ERROR4 (dbg, "pBuf is NULL\n");
         eError = OMX_ErrorBadParameter;
         goto EXIT;
@@ -3295,20 +3239,20 @@
     pDmmBuf->pAllocated = pArmPtr;
 
     /* Reserve */
-    nSizeReserved = ROUND_TO_PAGESIZE(size) + 2*DMM_PAGE_SIZE ;
+    nSizeReserved = ROUND_TO_PAGESIZE(size) + 2 * DMM_PAGE_SIZE ;
     status = DSPProcessor_ReserveMemory(ProcHandle, nSizeReserved, &(pDmmBuf->pReserved));
 
-    if(DSP_FAILED(status))
-    {
+    if (DSP_FAILED(status)) {
         OMX_ERROR4 (dbg, "DSPProcessor_ReserveMemory() failed - error 0x%x", (int) status);
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
+
     pDmmBuf->nSize = size;
     OMX_PRBUFFER2 (dbg, "DMM MAP Reserved: %p, size 0x%x (%d)\n",
-            pDmmBuf->pReserved,
-            nSizeReserved,
-            nSizeReserved);
+                   pDmmBuf->pReserved,
+                   nSizeReserved,
+                   nSizeReserved);
     /* Map */
     status = DSPProcessor_Map(ProcHandle,
                               pDmmBuf->pAllocated,/* Arm addres of data to Map on DSP*/
@@ -3316,27 +3260,29 @@
                               pDmmBuf->pReserved, /* reserved space */
                               &(pDmmBuf->pMapped), /* returned map pointer */
                               0); /* final param is reserved.  set to zero. */
-    if(DSP_FAILED(status))
-    {
+
+    if (DSP_FAILED(status)) {
         OMX_ERROR4 (dbg, "DSPProcessor_Map() failed - error 0x%x",
-                     (int)status);
+                    (int)status);
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
+
     OMX_PRBUFFER2 (dbg, "DMM Mapped: %p, size 0x%x (%d)\n",
-                 pDmmBuf->pMapped, size,size);
+                   pDmmBuf->pMapped, size, size);
 
     /* Issue an initial memory flush to ensure cache coherency */
     status = DSPProcessor_FlushMemory(ProcHandle, pDmmBuf->pAllocated, size, 0);
-    if(DSP_FAILED(status))
-    {
+
+    if (DSP_FAILED(status)) {
         OMX_ERROR4 (dbg, "Unable to flush mapped buffer: error 0x%x",
-                (int)status);
+                    (int)status);
         goto EXIT;
     }
+
     eError = OMX_ErrorNone;
 
- EXIT:
+EXIT:
     return eError;
 }
 
@@ -3350,43 +3296,41 @@
  *  @retval OMX_ErrorNone  - Success
  *          OMX_ErrorHardware  -  Hardware Error
  ** ==========================================================================*/
-OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg)
-{
+OMX_ERRORTYPE OMX_DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg) {
     DSP_STATUS status = DSP_SOK;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     /*    printf("OMX UnReserve DSP: %p\n",pResPtr);*/
 
-    if(pMapPtr == NULL)
-    {
+    if (pMapPtr == NULL) {
         OMX_ERROR4 (dbg, "pMapPtr is NULL\n");
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
-    if(pResPtr == NULL)
-    {
+
+    if (pResPtr == NULL) {
         OMX_ERROR4 (dbg, "pResPtr is NULL\n");
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
-    status = DSPProcessor_UnMap(ProcHandle,pMapPtr);
-    if(DSP_FAILED(status))
-    {
+
+    status = DSPProcessor_UnMap(ProcHandle, pMapPtr);
+
+    if (DSP_FAILED(status)) {
         OMX_ERROR4 (dbg, "DSPProcessor_UnMap() failed - error 0x%x", (int)status);
     }
 
     OMX_PRINT2 (dbg, "unreserving  structure =0x%p\n", pResPtr);
-    status = DSPProcessor_UnReserveMemory(ProcHandle,pResPtr);
-    if(DSP_FAILED(status))
-    {
-        OMX_ERROR4(dbg, "DSPProcessor_UnReserveMemory() failed - error 0x%x",(int)status);
+    status = DSPProcessor_UnReserveMemory(ProcHandle, pResPtr);
+
+    if (DSP_FAILED(status)) {
+        OMX_ERROR4(dbg, "DSPProcessor_UnReserveMemory() failed - error 0x%x", (int)status);
     }
 
- EXIT:
+EXIT:
     return eError;
 }
-
-/* void WBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
-{
+#ifdef RESOURCE_MANAGER_ENABLED
+void WBAMRENC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData) {
     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
     OMX_STATETYPE state = OMX_StateIdle;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
@@ -3396,24 +3340,81 @@
 
     if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) {
         if (pCompPrivate->curState == OMX_StateExecuting ||
-            pCompPrivate->curState == OMX_StatePause) {
+                pCompPrivate->curState == OMX_StatePause) {
             write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
-            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
+            write (pCompPrivate->cmdDataPipe[1], &state , sizeof(OMX_U32));
 
             pCompPrivate->bPreempted = 1;
         }
-    }
-    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
+    } else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired) {
         pCompPrivate->cbInfo.EventHandler (
-                            pHandle, pHandle->pApplicationPrivate,
-                            OMX_EventResourcesAcquired, 0,0,
-                            NULL);
+            pHandle, pHandle->pApplicationPrivate,
+            OMX_EventResourcesAcquired, 0, 0,
+            NULL);
 
 
     }
 
-} */
+}
+#endif
 
+void WBAMRENC_HandleUSNError (WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg) {
+    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U8 pending_buffers = OMX_FALSE;
+    OMX_U32 i;
+
+    switch (arg) {
+        case IUALG_WARN_CONCEALED:
+        case IUALG_WARN_UNDERFLOW:
+        case IUALG_WARN_OVERFLOW:
+        case IUALG_WARN_ENDOFDATA:
+            /* all of these are informative messages, Algo can recover, no need to notify the
+             * IL Client at this stage of the implementation */
+            break;
+
+        case IUALG_WARN_PLAYCOMPLETED: {
+            pHandle = pComponentPrivate->pHandle;
+            OMX_PRDSP2(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n", __LINE__);
+            OMX_PRINT2(pComponentPrivate->dbg, "IUALG_WARN_PLAYCOMPLETED Received\n");
+
+            if (pComponentPrivate->LastOutbuf != NULL) {
+                pComponentPrivate->LastOutbuf->nFlags |= OMX_BUFFERFLAG_EOS;
+            }
+
+            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                                   pComponentPrivate->pHandle->pApplicationPrivate,
+                                                   OMX_EventBufferFlag,
+                                                   (OMX_U32)NULL,
+                                                   OMX_BUFFERFLAG_EOS,
+                                                   NULL);
+        }
+        break;
+
+#ifdef _ERROR_PROPAGATION__
+        case IUALG_ERR_BAD_HANDLE:
+        case IUALG_ERR_DATA_CORRUPT:
+        case IUALG_ERR_NOT_SUPPORTED:
+        case IUALG_ERR_ARGUMENT:
+        case IUALG_ERR_NOT_READY:
+        case IUALG_ERR_GENERAL: {
+            /* all of these are fatal messages, Algo can not recover
+                     * hence return an error */
+            pComponentPrivate->bIsInvalidState = OMX_TRUE;
+            pComponentPrivate->curState = OMX_StateInvalid;
+            pHandle = pComponentPrivate->pHandle;
+            pComponentPrivate->cbInfo.EventHandler(pHandle,
+                                                   pHandle->pApplicationPrivate,
+                                                   OMX_EventError,
+                                                   OMX_ErrorInvalidState,
+                                                   OMX_TI_ErrorSevere,
+                                                   NULL);
+        }
+        break;
+#endif
+        default:
+            break;
+    }
+}
 OMX_ERRORTYPE AddStateTransition(WBAMRENC_COMPONENT_PRIVATE* pComponentPrivate) {
 
     OMX_ERRORTYPE eError = OMX_ErrorNone;
@@ -3454,4 +3455,3 @@
     return eError;
 }
 
-
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 17c298b..c282add 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
@@ -90,17 +90,6 @@
 #include "OMX_WbAmrEncoder.h"
 #include "OMX_WbAmrEnc_Utils.h"
 
-#ifdef WBAMRENC_DEBUGMEM
-extern void * mymalloc(int line, char *s, int size);
-extern int myfree(void *dp, int line, char *s);
-
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
 /****************************************************************
  *  EXTERNAL REFERENCES NOTE : only use if not found in header file
  ****************************************************************/
@@ -127,12 +116,12 @@
 static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE hComp,
                                    OMX_CALLBACKTYPE* pCallBacks, OMX_PTR pAppData);
 static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
-                                          OMX_STRING pComponentName,
-                                          OMX_VERSIONTYPE* pComponentVersion,
-                                          OMX_VERSIONTYPE* pSpecVersion,
-                                          OMX_UUIDTYPE* pComponentUUID);
+        OMX_STRING pComponentName,
+        OMX_VERSIONTYPE* pComponentVersion,
+        OMX_VERSIONTYPE* pSpecVersion,
+        OMX_UUIDTYPE* pComponentUUID);
 static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE hComp, OMX_COMMANDTYPE nCommand,
-                                  OMX_U32 nParam,OMX_PTR pCmdData);
+                                  OMX_U32 nParam, OMX_PTR pCmdData);
 static OMX_ERRORTYPE GetParameter(OMX_HANDLETYPE hComp, OMX_INDEXTYPE nParamIndex,
                                   OMX_PTR ComponentParamStruct);
 static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
@@ -150,9 +139,9 @@
 static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE hComp, OMX_BUFFERHEADERTYPE* pBuffer);
 static OMX_ERRORTYPE GetState (OMX_HANDLETYPE hComp, OMX_STATETYPE* pState);
 static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
-                                             OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
-                                             OMX_U32 nTunneledPort,
-                                             OMX_TUNNELSETUPTYPE* pTunnelSetup);
+        OMX_U32 nPort, OMX_HANDLETYPE hTunneledComp,
+        OMX_U32 nTunneledPort,
+        OMX_TUNNELSETUPTYPE* pTunnelSetup);
 static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle);
 static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
                                      OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
@@ -196,8 +185,7 @@
  *         OMX_ErrorInsufficientResources If the newmalloc fails
  **/
 /*-------------------------------------------------------------------*/
-OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp)
-{
+OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComp) {
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef_ip, *pPortDef_op;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate;
     OMX_AUDIO_PARAM_PCMMODETYPE *amr_ip;
@@ -229,7 +217,7 @@
     pHandle->ComponentRoleEnum = ComponentRoleEnum;
 
     /*Allocate the memory for Component private data area */
-    WBAMRENC_OMX_MALLOC(pHandle->pComponentPrivate, WBAMRENC_COMPONENT_PRIVATE);
+    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, WBAMRENC_COMPONENT_PRIVATE);
 
     ((WBAMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
     pComponentPrivate = pHandle->pComponentPrivate;
@@ -237,8 +225,8 @@
     OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_WBAMRENC");
 
 #ifdef ANDROID
-    pComponentPrivate->iPVCapabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE; 
-    pComponentPrivate->iPVCapabilityFlags.iOMXComponentNeedsNALStartCode = OMX_FALSE; 
+    pComponentPrivate->iPVCapabilityFlags.iIsOMXComponentMultiThreaded = OMX_TRUE;
+    pComponentPrivate->iPVCapabilityFlags.iOMXComponentNeedsNALStartCode = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE;
@@ -247,18 +235,18 @@
 #endif
 
 #ifdef __PERF_INSTRUMENTATION__
-    pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('W','B','_','E'),
+    pComponentPrivate->pPERF = PERF_Create(PERF_FOURCC('W', 'B', '_', 'E'),
                                            PERF_ModuleLLMM |
                                            PERF_ModuleAudioDecode);
 #endif
 
-    WBAMRENC_OMX_MALLOC(pCompPort, WBAMRENC_PORT_TYPE);
+    OMX_MALLOC_GENERIC(pCompPort, WBAMRENC_PORT_TYPE);
     pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT] = pCompPort;
 
-    WBAMRENC_OMX_MALLOC(pCompPort, WBAMRENC_PORT_TYPE);
+    OMX_MALLOC_GENERIC(pCompPort, WBAMRENC_PORT_TYPE);
     pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT] = pCompPort;
 
-    WBAMRENC_OMX_MALLOC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
     OMX_WBCONF_INIT_STRUCT(pComponentPrivate->sPortParam, OMX_PORT_PARAM_TYPE);
 
     /* Initialize sPortParam data structures to default values */
@@ -266,8 +254,8 @@
     pComponentPrivate->sPortParam->nStartPortNumber = 0x0;
 
     /* Malloc and Set pPriorityMgmt defaults */
-    WBAMRENC_OMX_MALLOC(pComponentPrivate->sPriorityMgmt,
-                        OMX_PRIORITYMGMTTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->sPriorityMgmt,
+                       OMX_PRIORITYMGMTTYPE);
     OMX_WBCONF_INIT_STRUCT(pComponentPrivate->sPriorityMgmt,
                            OMX_PRIORITYMGMTTYPE);
 
@@ -275,38 +263,38 @@
     pComponentPrivate->sPriorityMgmt->nGroupPriority = -1;
     pComponentPrivate->sPriorityMgmt->nGroupID = -1;
 
-    WBAMRENC_OMX_MALLOC(amr_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
+    OMX_MALLOC_GENERIC(amr_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
     OMX_WBCONF_INIT_STRUCT(amr_ip, OMX_AUDIO_PARAM_PCMMODETYPE);
     pComponentPrivate->pcmParams = amr_ip;
 
-    WBAMRENC_OMX_MALLOC(amr_op, OMX_AUDIO_PARAM_AMRTYPE);
+    OMX_MALLOC_GENERIC(amr_op, OMX_AUDIO_PARAM_AMRTYPE);
     OMX_WBCONF_INIT_STRUCT(amr_op, OMX_AUDIO_PARAM_AMRTYPE);
     pComponentPrivate->amrParams = amr_op;
 
     /* newmalloc and initialize number of input buffers */
-    WBAMRENC_OMX_MALLOC(pComponentPrivate->pInputBufferList,
-                        WBAMRENC_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pInputBufferList,
+                       WBAMRENC_BUFFERLIST);
     pComponentPrivate->pInputBufferList->numBuffers = 0;
 
     /* newmalloc and initialize number of output buffers */
-    WBAMRENC_OMX_MALLOC(pComponentPrivate->pOutputBufferList,
-                        WBAMRENC_BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pOutputBufferList,
+                       WBAMRENC_BUFFERLIST);
     pComponentPrivate->pOutputBufferList->numBuffers = 0;
 
-    for (i=0; i < WBAMRENC_MAX_NUM_OF_BUFS; i++) {
+    for (i = 0; i < WBAMRENC_MAX_NUM_OF_BUFS; i++) {
         pComponentPrivate->pOutputBufferList->pBufHdr[i] = NULL;
         pComponentPrivate->pInputBufferList->pBufHdr[i] = NULL;
     }
 
-    WBAMRENC_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString,
-                             100*sizeof(OMX_STRING),
-                             OMX_STRING);
+    OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString,
+                    100*sizeof(OMX_STRING),
+                    OMX_STRING);
 
     /* Initialize device string to the default value */
-    strcpy((char*)pComponentPrivate->sDeviceString,":srcul/codec\0");
+    strcpy((char*)pComponentPrivate->sDeviceString, ":srcul/codec\0");
 
     /* Set input port defaults */
-    WBAMRENC_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
     OMX_WBCONF_INIT_STRUCT(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
     pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT] = pPortDef_ip;
 
@@ -315,7 +303,7 @@
     pPortDef_ip->nBufferCountActual                 = WBAMRENC_NUM_INPUT_BUFFERS;
     pPortDef_ip->nBufferCountMin                    = WBAMRENC_NUM_INPUT_BUFFERS;
     pPortDef_ip->nBufferSize                        = WBAMRENC_INPUT_FRAME_SIZE;
-    pPortDef_ip->nBufferAlignment                   = EXTRA_BYTES;
+    pPortDef_ip->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
     pPortDef_ip->bEnabled                           = OMX_TRUE;
     pPortDef_ip->bPopulated                         = OMX_FALSE;
     pPortDef_ip->eDomain                            = OMX_PortDomainAudio;
@@ -325,7 +313,7 @@
     pPortDef_ip->format.audio.bFlagErrorConcealment = OMX_FALSE;
 
     /* Set output port defaults */
-    WBAMRENC_OMX_MALLOC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
     OMX_WBCONF_INIT_STRUCT(pPortDef_op, OMX_PARAM_PORTDEFINITIONTYPE);
     pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT] = pPortDef_op;
 
@@ -333,7 +321,7 @@
     pPortDef_op->eDir                               = OMX_DirOutput;
     pPortDef_op->nBufferCountMin                    = WBAMRENC_NUM_OUTPUT_BUFFERS;
     pPortDef_op->nBufferCountActual                 = WBAMRENC_NUM_OUTPUT_BUFFERS;
-    pPortDef_op->nBufferAlignment                   = EXTRA_BYTES;
+    pPortDef_op->nBufferAlignment                   = DSP_CACHE_ALIGNMENT;
     pPortDef_op->nBufferSize                        = 640; //WBAMRENC_OUTPUT_FRAME_SIZE;
     pPortDef_op->bEnabled                           = OMX_TRUE;
     pPortDef_op->bPopulated                         = OMX_FALSE;
@@ -343,7 +331,7 @@
     pPortDef_op->format.audio.pNativeRender         = NULL;
     pPortDef_op->format.audio.bFlagErrorConcealment = OMX_FALSE;
 
-    WBAMRENC_OMX_MALLOC(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
     OMX_WBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat, OMX_AUDIO_PARAM_PORTFORMATTYPE);
 
     pComponentPrivate->bPreempted = OMX_FALSE;
@@ -357,7 +345,7 @@
 
     amr_ip->nPortIndex = WBAMRENC_INPUT_PORT;
     amr_ip->nChannels = 1;
-    amr_ip->eNumData= OMX_NumericalDataSigned;
+    amr_ip->eNumData = OMX_NumericalDataSigned;
     amr_ip->nBitPerSample = 16;
     amr_ip->nSamplingRate = 16000;
     amr_ip->ePCMMode = OMX_AUDIO_PCMModeLinear;
@@ -367,11 +355,11 @@
     amr_op->nPortIndex = WBAMRENC_OUTPUT_PORT;
     amr_op->nChannels = 1;
     amr_op->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
-    amr_op->eAMRDTXMode= OMX_AUDIO_AMRDTXModeOff;
-    amr_op->eAMRFrameFormat =OMX_AUDIO_AMRFrameFormatConformance;
+    amr_op->eAMRDTXMode = OMX_AUDIO_AMRDTXModeOff;
+    amr_op->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatConformance;
 
-    WBAMRENC_OMX_MALLOC(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat,
-                        OMX_AUDIO_PARAM_PORTFORMATTYPE);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat,
+                       OMX_AUDIO_PARAM_PORTFORMATTYPE);
     OMX_WBCONF_INIT_STRUCT(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat,
                            OMX_AUDIO_PARAM_PORTFORMATTYPE);
 
@@ -441,18 +429,20 @@
     pComponentPrivate->iHoldBuffer = NULL;
     pComponentPrivate->pHoldBuffer = NULL;
     pComponentPrivate->nHoldLength = 0;
-    for (i=0; i < WBAMRENC_MAX_NUM_OF_BUFS; i++) {
+
+    for (i = 0; i < WBAMRENC_MAX_NUM_OF_BUFS; i++) {
         pComponentPrivate->pInputBufHdrPending[i] = NULL;
         pComponentPrivate->pOutputBufHdrPending[i] = NULL;
         pComponentPrivate->arrTickCount[i] = 0;
         pComponentPrivate->arrBufIndex[i] = 0;
     }
+
     pComponentPrivate->nNumInputBufPending = 0;
     pComponentPrivate->nNumOutputBufPending = 0;
     pComponentPrivate->bDisableCommandPending = 0;
     pComponentPrivate->nNumOfFramesSent = 0;
 
-    pComponentPrivate->bNoIdleOnStop= OMX_FALSE;
+    pComponentPrivate->bNoIdleOnStop = OMX_FALSE;
     pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
     pComponentPrivate->nOutStandingFillDones = 0;
     pComponentPrivate->nOutStandingEmptyDones = 0;
@@ -491,35 +481,38 @@
 
 #ifdef RESOURCE_MANAGER_ENABLED
     eError = RMProxy_NewInitalize();
-    OMX_PRINT2(pComponentPrivate->dbg,"Initialize RM");
+    OMX_PRINT2(pComponentPrivate->dbg, "Initialize RM");
+
     if (eError != OMX_ErrorNone) {
         OMX_ERROR4(pComponentPrivate->dbg, "RM Initialization error %d",
                    eError);
         goto EXIT;
     }
+
 #endif
 
     eError = WBAMRENC_StartComponentThread(pHandle);
     OMX_PRINT2(pComponentPrivate->dbg, "ComponentThread started");
+
     if (eError != OMX_ErrorNone) {
         OMX_ERROR4(pComponentPrivate->dbg, "Error while starting \
-ComponentThread %d",eError);
+ComponentThread %d", eError);
         goto EXIT;
     }
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ThreadCreated(pComponentPrivate->pPERF,
                        pComponentPrivate->ComponentThread,
-                       PERF_FOURCC('W','B','E','T'));
+                       PERF_FOURCC('W', 'B', 'E', 'T'));
 #endif
 
 #ifndef UNDER_CE
 
-    if((pComponentPrivate->fdwrite=open(FIFO1,O_WRONLY))<0) {
+    if ((pComponentPrivate->fdwrite = open(FIFO1, O_WRONLY)) < 0) {
         OMX_PRCOMM4(pComponentPrivate->dbg, "Failure to open Write pipe");
     }
 
-    if((pComponentPrivate->fdread=open(FIFO2,O_RDONLY))<0) {
+    if ((pComponentPrivate->fdread = open(FIFO2, O_RDONLY)) < 0) {
         OMX_PRCOMM4(pComponentPrivate->dbg, "Failure to open Read pipe");
     }
 
@@ -534,9 +527,8 @@
   if(pthread_cond_init (&pComponentPrivate->StateChangeCondition, NULL)) {
      return OMX_ErrorUndefined;
   }
-
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exit Returning = 0x%x",eError);
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "Exit Returning = 0x%x", eError);
     return eError;
 }
 
@@ -560,8 +552,7 @@
 
 static OMX_ERRORTYPE SetCallbacks (OMX_HANDLETYPE pComponent,
                                    OMX_CALLBACKTYPE* pCallBacks,
-                                   OMX_PTR pAppData)
-{
+                                   OMX_PTR pAppData) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*)pComponent;
@@ -569,6 +560,7 @@
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate =
         (WBAMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_PRINT1(pComponentPrivate->dbg, "Enter");
+
     if (pCallBacks == NULL) {
         eError = OMX_ErrorBadParameter;
         OMX_PRDSP4(pComponentPrivate->dbg, "Empty callbacks from the\
@@ -584,8 +576,8 @@
 
     pComponentPrivate->curState = OMX_StateLoaded;
 
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exit Returning = 0x%x",eError);
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "Exit Returning = 0x%x", eError);
     return eError;
 }
 
@@ -607,33 +599,35 @@
 /*-------------------------------------------------------------------*/
 
 static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
-                                          OMX_STRING pComponentName,
-                                          OMX_VERSIONTYPE* pComponentVersion,
-                                          OMX_VERSIONTYPE* pSpecVersion,
-                                          OMX_UUIDTYPE* pComponentUUID)
-{
+        OMX_STRING pComponentName,
+        OMX_VERSIONTYPE* pComponentVersion,
+        OMX_VERSIONTYPE* pSpecVersion,
+        OMX_UUIDTYPE* pComponentUUID) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE*) hComp;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *) pHandle->pComponentPrivate;
     OMX_PRINT1(pComponentPrivate->dbg, "Enter");
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
     }
+
 #endif
+
     /* Copy component version structure */
-    if(pComponentVersion != NULL && pComponentName != NULL) {
+    if (pComponentVersion != NULL && pComponentName != NULL) {
         strcpy(pComponentName, pComponentPrivate->cComponentName);
         memcpy(pComponentVersion, &(pComponentPrivate->ComponentVersion.s), sizeof(pComponentPrivate->ComponentVersion.s));
-    }
-    else {
+    } else {
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter!");
         eError = OMX_ErrorBadParameter;
     }
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x",eError);
+
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x", eError);
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -654,8 +648,7 @@
 static OMX_ERRORTYPE SendCommand (OMX_HANDLETYPE phandle,
                                   OMX_COMMANDTYPE Cmd,
                                   OMX_U32 nParam,
-                                  OMX_PTR pCmdData)
-{
+                                  OMX_PTR pCmdData) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)phandle;
     WBAMRENC_COMPONENT_PRIVATE *pCompPrivate =
@@ -663,90 +656,100 @@
     int nRet = 0;
 
     OMX_PRINT1(pCompPrivate->dbg, "Entering");
-    if(pCompPrivate->curState == OMX_StateInvalid) {
+
+    if (pCompPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         OMX_ERROR4(pCompPrivate->dbg, "OMX_ErrorInvalidState!");
         goto EXIT;
     }
+
 #ifdef __PERF_INSTRUMENTATION__
     PERF_SendingCommand(pCompPrivate->pPERF,
                         Cmd,
                         (Cmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam,
                         PERF_ModuleComponent);
 #endif
-    switch(Cmd) {
-    case OMX_CommandStateSet:
-        OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandStateSet-%ld",nParam);
-        if (nParam == OMX_StateLoaded) {
-            pCompPrivate->bLoadedCommandPending = OMX_TRUE;
-        }
-        if(pCompPrivate->curState == OMX_StateLoaded) {
-            if((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) {
-                pCompPrivate->cbInfo.EventHandler ( pHandle,
-                                                    pHandle->pApplicationPrivate,
-                                                    OMX_EventError,
-                                                    OMX_ErrorIncorrectStateTransition,
-                                                    OMX_TI_ErrorMinor,
-                                                    NULL);
-                goto EXIT;
+
+    switch (Cmd) {
+        case OMX_CommandStateSet:
+            OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandStateSet-%ld", nParam);
+
+            if (nParam == OMX_StateLoaded) {
+                pCompPrivate->bLoadedCommandPending = OMX_TRUE;
             }
 
-            if(nParam == OMX_StateInvalid) {
-                OMX_PRDSP2(pCompPrivate->dbg, "nParam = OMX_StateInvalid!");
-                pCompPrivate->curState = OMX_StateInvalid;
-                pCompPrivate->cbInfo.EventHandler ( pHandle,
-                                                    pHandle->pApplicationPrivate,
-                                                    OMX_EventError,
-                                                    OMX_ErrorInvalidState,
-                                                    OMX_TI_ErrorMinor,
-                                                    NULL);
-                goto EXIT;
+            if (pCompPrivate->curState == OMX_StateLoaded) {
+                if ((nParam == OMX_StateExecuting) || (nParam == OMX_StatePause)) {
+                    pCompPrivate->cbInfo.EventHandler ( pHandle,
+                                                        pHandle->pApplicationPrivate,
+                                                        OMX_EventError,
+                                                        OMX_ErrorIncorrectStateTransition,
+                                                        OMX_TI_ErrorMinor,
+                                                        NULL);
+                    goto EXIT;
+                }
+
+                if (nParam == OMX_StateInvalid) {
+                    OMX_PRDSP2(pCompPrivate->dbg, "nParam = OMX_StateInvalid!");
+                    pCompPrivate->curState = OMX_StateInvalid;
+                    pCompPrivate->cbInfo.EventHandler ( pHandle,
+                                                        pHandle->pApplicationPrivate,
+                                                        OMX_EventError,
+                                                        OMX_ErrorInvalidState,
+                                                        OMX_TI_ErrorMinor,
+                                                        NULL);
+                    goto EXIT;
+                }
             }
-        }
 
          /* Add a pending transition */
          if(AddStateTransition(pCompPrivate) != OMX_ErrorNone) {
                return OMX_ErrorUndefined;
          }
         
-        break;
-    case OMX_CommandFlush:
-        OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandFlush %ld",nParam);
-        if(nParam > 1 && nParam != -1) {
-            eError = OMX_ErrorBadPortIndex;
-            OMX_ERROR4(pCompPrivate->dbg,
-                       "OMX_CommandFlush - OMX_ErrorBadPortIndex");
-            goto EXIT;
-        }
-        break;
-    case OMX_CommandPortDisable:
-        OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandPortDisable");
-        break;
-    case OMX_CommandPortEnable:
-        OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandPortEnable");
-        break;
-    case OMX_CommandMarkBuffer:
-        OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandMarkBuffer");
-        if (nParam > 0) {
-            eError = OMX_ErrorBadPortIndex;
-            OMX_ERROR4(pCompPrivate->dbg,
-                       "OMX_CommandMarkBuffer - OMX_ErrorBadPortIndex!");
-            goto EXIT;
-        }
-        break;
-    default:
-        OMX_PRDSP2(pCompPrivate->dbg, "Invalid OMX Command");
-        pCompPrivate->cbInfo.EventHandler ( pHandle,
-                                            pHandle->pApplicationPrivate,
-                                            OMX_EventError,
-                                            OMX_ErrorUndefined,
-                                            OMX_TI_ErrorMinor,
-                                            "Invalid Command");
-        break;
+            break;
+        case OMX_CommandFlush:
+            OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandFlush %ld", nParam);
+
+            if (nParam > 1 && nParam != -1) {
+                eError = OMX_ErrorBadPortIndex;
+                OMX_ERROR4(pCompPrivate->dbg,
+                           "OMX_CommandFlush - OMX_ErrorBadPortIndex");
+                goto EXIT;
+            }
+
+            break;
+        case OMX_CommandPortDisable:
+            OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandPortDisable");
+            break;
+        case OMX_CommandPortEnable:
+            OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandPortEnable");
+            break;
+        case OMX_CommandMarkBuffer:
+            OMX_PRDSP2(pCompPrivate->dbg, "OMX_CommandMarkBuffer");
+
+            if (nParam > 0) {
+                eError = OMX_ErrorBadPortIndex;
+                OMX_ERROR4(pCompPrivate->dbg,
+                           "OMX_CommandMarkBuffer - OMX_ErrorBadPortIndex!");
+                goto EXIT;
+            }
+
+            break;
+        default:
+            OMX_PRDSP2(pCompPrivate->dbg, "Invalid OMX Command");
+            pCompPrivate->cbInfo.EventHandler ( pHandle,
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError,
+                                                OMX_ErrorUndefined,
+                                                OMX_TI_ErrorMinor,
+                                                "Invalid Command");
+            break;
 
     }
 
     nRet = write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
+
     if (nRet == -1) {
         eError = OMX_ErrorInsufficientResources;
         OMX_ERROR4(pCompPrivate->dbg, "OMX_ErrorInsufficientResources!");
@@ -754,23 +757,24 @@
     }
 
     if (Cmd == OMX_CommandMarkBuffer) {
-        nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData,sizeof(OMX_PTR));
+        nRet = write(pCompPrivate->cmdDataPipe[1], &pCmdData, sizeof(OMX_PTR));
     } else {
-        nRet = write(pCompPrivate->cmdDataPipe[1], &nParam,sizeof(OMX_U32));
+        nRet = write(pCompPrivate->cmdDataPipe[1], &nParam, sizeof(OMX_U32));
     }
 
     if (nRet == -1) {
-        OMX_ERROR4(pCompPrivate->dbg, "%d :: OMX_ErrorInsufficientResources from SendCommand",__LINE__);
+        OMX_ERROR4(pCompPrivate->dbg, "OMX_ErrorInsufficientResources");
         if(Cmd == OMX_CommandStateSet) {
            if(RemoveStateTransition(pCompPrivate, OMX_FALSE) != OMX_ErrorNone) {
               return OMX_ErrorUndefined;
            }
         }
-        return OMX_ErrorInsufficientResources;
-     }
+        eError = OMX_ErrorInsufficientResources;
+        goto EXIT;
+    }
 
- EXIT:
-    OMX_PRINT1(pCompPrivate->dbg, "Exiting Returning = 0x%x",eError);
+EXIT:
+    OMX_PRINT1(pCompPrivate->dbg, "Exiting Returning = 0x%x", eError);
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -788,8 +792,7 @@
 
 static OMX_ERRORTYPE GetParameter (OMX_HANDLETYPE hComp,
                                    OMX_INDEXTYPE nParamIndex,
-                                   OMX_PTR ComponentParameterStructure)
-{
+                                   OMX_PTR ComponentParameterStructure) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     WBAMRENC_COMPONENT_PRIVATE  *pComponentPrivate;
     OMX_PARAM_PORTDEFINITIONTYPE *pParameterStructure;
@@ -798,6 +801,7 @@
     pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)(((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
     pParameterStructure = (OMX_PARAM_PORTDEFINITIONTYPE*)ComponentParameterStructure;
     OMX_PRINT1(pComponentPrivate->dbg, "Entering");
+
     if (pParameterStructure == NULL) {
         eError = OMX_ErrorBadParameter;
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadPortIndex!");
@@ -805,200 +809,215 @@
     }
 
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
     }
+
 #else
-    if(pComponentPrivate->curState == OMX_StateInvalid) {
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorIncorrectStateOperation;
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorIncorrectStateOperation!");
         goto EXIT;
     }
+
 #endif
-    switch(nParamIndex){
-    case OMX_IndexParamAudioInit:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioInit");
-        memcpy(ComponentParameterStructure,
-               pComponentPrivate->sPortParam,
-               sizeof(OMX_PORT_PARAM_TYPE));
-    }
-    break;
 
-    case OMX_IndexParamPortDefinition:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamPortDefinition");
-        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
-           pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nPortIndex) {
+    switch (nParamIndex) {
+        case OMX_IndexParamAudioInit: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioInit");
+            if (pComponentPrivate->sPortParam == NULL) {
+	        eError = OMX_ErrorBadParameter;
+	        break;
+	    }
+
             memcpy(ComponentParameterStructure,
-                   pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT],
-                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
-        } else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
-                  pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nPortIndex) {
-            memcpy(ComponentParameterStructure,
-                   pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT],
-                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
-        } else {
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "OMX_IndexParamPortDefinition - OMX_ErrorBadPortIndex");
-            eError = OMX_ErrorBadPortIndex;
+                   pComponentPrivate->sPortParam,
+                   sizeof(OMX_PORT_PARAM_TYPE));
         }
-    }
-    break;
-
-    case OMX_IndexParamAudioPortFormat:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioPortFormat");
-        if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
-           pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nPortIndex) {
-            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
-               pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat->nPortIndex) {
-                eError = OMX_ErrorNoMore;
-            }
-            else {
-                memcpy(ComponentParameterStructure,
-                       pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat,
-                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
-            }
-        }
-        else if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
-                pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nPortIndex){
-            if(((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
-               pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat->nPortIndex) {
-                eError = OMX_ErrorNoMore;
-            }
-            else {
-                memcpy(ComponentParameterStructure,
-                       pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat,
-                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
-            }
-        }
-        else {
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "OMX_IndexParamAudioPortFormat - OMX_ErrorBadPortIndex");
-            eError = OMX_ErrorBadPortIndex;
-        }
-    }
-    break;
-
-    case OMX_IndexParamAudioAmr:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioAmr");
-        memcpy(ComponentParameterStructure,
-               pComponentPrivate->amrParams,
-               sizeof(OMX_AUDIO_PARAM_AMRTYPE));
-        pCompAmrParam = (OMX_AUDIO_PARAM_AMRTYPE *)ComponentParameterStructure;
-        switch (pCompAmrParam->eAMRBandMode)
-        {
-        case SN_AUDIO_BR660:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
-            break;
-        case SN_AUDIO_BR885:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB1;
-            break;
-        case SN_AUDIO_BR1265:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB2;
-            break;
-        case SN_AUDIO_BR1425:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB3;
-            break;
-        case SN_AUDIO_BR1585:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB4;
-            break;
-        case SN_AUDIO_BR1825:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB5;
-            break;
-        case SN_AUDIO_BR1985:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB6;
-            break;
-        case SN_AUDIO_BR2305:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB7;
-            break;
-        case SN_AUDIO_BR2385:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB8;
-            break;
-        default:
-            pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
-            break;
-        }
-
-    }
-    break;
-
-    case OMX_IndexParamPriorityMgmt:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamPriorityMgmt");
-        memcpy(ComponentParameterStructure,
-               pComponentPrivate->sPriorityMgmt,
-               sizeof(OMX_PRIORITYMGMTTYPE));
-    }
-    break;
-
-    case OMX_IndexParamAudioPcm:
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioPcm");
-        memcpy(ComponentParameterStructure,
-               pComponentPrivate->pcmParams,
-               sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
         break;
 
-    case OMX_IndexParamCompBufferSupplier:
-        OMX_PRDSP2(pComponentPrivate->dbg,"OMX_IndexParamCompBufferSupplier");
-        if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == WBAMRENC_INPUT_PORT) {
-            OMX_PRDSP2(pComponentPrivate->dbg,
-                       "nPortIndex %d ",WBAMRENC_INPUT_PORT);
-        }
-        else if(((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == WBAMRENC_OUTPUT_PORT) {
-            OMX_PRDSP2(pComponentPrivate->dbg,
-                       "nPortIndex %d ", WBAMRENC_OUTPUT_PORT);
-        }
-        else {
-            OMX_PRDSP2(pComponentPrivate->dbg,
-                       "OMX_IndexParamCompBufferSupplier - OMX_ErrorBadPortIndex");
-            eError = OMX_ErrorBadPortIndex;
+        case OMX_IndexParamPortDefinition: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamPortDefinition");
+
+            if (((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
+                    pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nPortIndex) {
+                memcpy(ComponentParameterStructure,
+                       pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT],
+                       sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+            } else if (((OMX_PARAM_PORTDEFINITIONTYPE *)(ComponentParameterStructure))->nPortIndex ==
+                       pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nPortIndex) {
+                memcpy(ComponentParameterStructure,
+                       pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT],
+                       sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+            } else {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "OMX_IndexParamPortDefinition - OMX_ErrorBadPortIndex");
+                eError = OMX_ErrorBadPortIndex;
+            }
         }
         break;
 
+        case OMX_IndexParamAudioPortFormat: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioPortFormat");
+
+            if (((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
+                    pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nPortIndex) {
+                if (((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
+                        pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat->nPortIndex) {
+                    eError = OMX_ErrorNoMore;
+                } else {
+                    memcpy(ComponentParameterStructure,
+                           pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat,
+                           sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+                }
+            } else if (((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nPortIndex ==
+                       pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nPortIndex) {
+                if (((OMX_AUDIO_PARAM_PORTFORMATTYPE *)(ComponentParameterStructure))->nIndex >
+                        pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat->nPortIndex) {
+                    eError = OMX_ErrorNoMore;
+                } else {
+                    memcpy(ComponentParameterStructure,
+                           pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat,
+                           sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+                }
+            } else {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "OMX_IndexParamAudioPortFormat - OMX_ErrorBadPortIndex");
+                eError = OMX_ErrorBadPortIndex;
+            }
+        }
+        break;
+
+        case OMX_IndexParamAudioAmr: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioAmr");
+	    if (pComponentPrivate->amrParams == NULL) {
+	        eError = OMX_ErrorBadParameter;
+	        break;
+	    }
+            memcpy(ComponentParameterStructure,
+                   pComponentPrivate->amrParams,
+                   sizeof(OMX_AUDIO_PARAM_AMRTYPE));
+            pCompAmrParam = (OMX_AUDIO_PARAM_AMRTYPE *)ComponentParameterStructure;
+
+            switch (pCompAmrParam->eAMRBandMode) {
+                case SN_AUDIO_BR660:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
+                    break;
+                case SN_AUDIO_BR885:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB1;
+                    break;
+                case SN_AUDIO_BR1265:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB2;
+                    break;
+                case SN_AUDIO_BR1425:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB3;
+                    break;
+                case SN_AUDIO_BR1585:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB4;
+                    break;
+                case SN_AUDIO_BR1825:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB5;
+                    break;
+                case SN_AUDIO_BR1985:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB6;
+                    break;
+                case SN_AUDIO_BR2305:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB7;
+                    break;
+                case SN_AUDIO_BR2385:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB8;
+                    break;
+                default:
+                    pCompAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
+                    break;
+            }
+
+        }
+        break;
+
+        case OMX_IndexParamPriorityMgmt: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamPriorityMgmt");
+	    if (pComponentPrivate->sPriorityMgmt == NULL) {
+	        eError = OMX_ErrorBadParameter;
+                break; 		
+	    }
+            memcpy(ComponentParameterStructure,
+                   pComponentPrivate->sPriorityMgmt,
+                   sizeof(OMX_PRIORITYMGMTTYPE));
+        }
+        break;
+
+        case OMX_IndexParamAudioPcm:
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioPcm");
+	    if (pComponentPrivate->pcmParams == NULL) {
+	        eError = OMX_ErrorBadParameter;
+                break; 		
+	    }
+            memcpy(ComponentParameterStructure,
+                   pComponentPrivate->pcmParams,
+                   sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+            break;
+
+        case OMX_IndexParamCompBufferSupplier:
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamCompBufferSupplier");
+
+            if (((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == WBAMRENC_INPUT_PORT) {
+                OMX_PRDSP2(pComponentPrivate->dbg,
+                           "nPortIndex %d ", WBAMRENC_INPUT_PORT);
+            } else if (((OMX_PARAM_BUFFERSUPPLIERTYPE *)(ComponentParameterStructure))->nPortIndex == WBAMRENC_OUTPUT_PORT) {
+                OMX_PRDSP2(pComponentPrivate->dbg,
+                           "nPortIndex %d ", WBAMRENC_OUTPUT_PORT);
+            } else {
+                OMX_PRDSP2(pComponentPrivate->dbg,
+                           "OMX_IndexParamCompBufferSupplier - OMX_ErrorBadPortIndex");
+                eError = OMX_ErrorBadPortIndex;
+            }
+
+            break;
+
 #ifdef ANDROID
-    case (OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX:
-    {
-        PV_OMXComponentCapabilityFlagsType* pCap_flags =
-            (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure;
-        pCap_flags = (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure;
-        if (NULL == pCap_flags)
-        {
-            OMX_ERROR4(pComponentPrivate->dbg, "ERROR PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX");
-            eError =  OMX_ErrorBadParameter;
-            goto EXIT;
+        case (OMX_INDEXTYPE) PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX: {
+            PV_OMXComponentCapabilityFlagsType* pCap_flags =
+                (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure;
+            pCap_flags = (PV_OMXComponentCapabilityFlagsType *) ComponentParameterStructure;
+
+            if (NULL == pCap_flags) {
+                OMX_ERROR4(pComponentPrivate->dbg, "ERROR PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX");
+                eError =  OMX_ErrorBadParameter;
+                goto EXIT;
+            }
+
+            OMX_PRINT1(pComponentPrivate->dbg, "Copying PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX");
+            memcpy(pCap_flags,
+                   &(pComponentPrivate->iPVCapabilityFlags),
+                   sizeof(PV_OMXComponentCapabilityFlagsType));
+            eError = OMX_ErrorNone;
         }
-        OMX_PRINT1(pComponentPrivate->dbg, "Copying PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX");
-        memcpy(pCap_flags,
-               &(pComponentPrivate->iPVCapabilityFlags),
-               sizeof(PV_OMXComponentCapabilityFlagsType));
-        eError = OMX_ErrorNone;
-    }
-    break;
+        break;
 #endif
 
-    case OMX_IndexParamVideoInit:
+        case OMX_IndexParamVideoInit:
+            break;
+
+        case OMX_IndexParamImageInit:
+            break;
+
+        case OMX_IndexParamOtherInit:
+            break;
+
+
+        default: {
+            OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedIndex!");
+            eError = OMX_ErrorUnsupportedIndex;
+        }
         break;
-
-    case OMX_IndexParamImageInit:
-        break;
-
-    case OMX_IndexParamOtherInit:
-        break;
-
-
-    default:
-    {
-        OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedIndex!");
-        eError = OMX_ErrorUnsupportedIndex;
     }
-    break;
-    }
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x",eError);
+
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x", eError);
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -1016,10 +1035,9 @@
 
 static OMX_ERRORTYPE SetParameter (OMX_HANDLETYPE hComp,
                                    OMX_INDEXTYPE nParamIndex,
-                                   OMX_PTR pCompParam)
-{
+                                   OMX_PTR pCompParam) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    OMX_COMPONENTTYPE* pHandle= (OMX_COMPONENTTYPE*)hComp;
+    OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
     WBAMRENC_COMPONENT_PRIVATE  *pComponentPrivate;
     OMX_AUDIO_PARAM_PORTFORMATTYPE* pComponentParam = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE *pComponentParamPort = NULL;
@@ -1032,6 +1050,7 @@
 
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering");
+
     if (pCompParam == NULL) {
         eError = OMX_ErrorBadParameter;
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter!");
@@ -1043,215 +1062,227 @@
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorIncorrectStateOperation!");
         goto EXIT;
     }
+
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
     }
+
 #endif
-    switch(nParamIndex) {
-    case OMX_IndexParamAudioPortFormat:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioPortFormat");
-        pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
-        if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat->nPortIndex ) {
-            memcpy(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat,
-                   pComponentParam,
-                   sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
-        } else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat->nPortIndex ) {
-            memcpy(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat,
-                   pComponentParam,
-                   sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
-        } else {
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "OMX_IndexParamAudioPortFormat - OMX_ErrorBadPortIndex!");
-            eError = OMX_ErrorBadPortIndex;
-        }
-    }
-    break;
-    case OMX_IndexParamAudioAmr:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioAmr");
 
-        // 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;
+    switch (nParamIndex) {
+        case OMX_IndexParamAudioPortFormat: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioPortFormat");
+            pComponentParam = (OMX_AUDIO_PARAM_PORTFORMATTYPE *)pCompParam;
 
-        if(pCompAmrParam->nPortIndex == 0) {         /* 0 means Input port */
-            memcpy(((WBAMRENC_COMPONENT_PRIVATE*)
-                    pHandle->pComponentPrivate)->pcmParams,
-                   pCompAmrParam,
-                   sizeof(OMX_AUDIO_PARAM_AMRTYPE));
-        } else if (pCompAmrParam->nPortIndex == 1) { /* 1 means Output port */
-            switch (pCompAmrParam->eAMRBandMode)
-            {
-            case OMX_AUDIO_AMRBandModeWB0:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR660;
-                break;
-            case OMX_AUDIO_AMRBandModeWB1:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR885;
-                break;
-            case OMX_AUDIO_AMRBandModeWB2:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1265;
-                break;
-            case OMX_AUDIO_AMRBandModeWB3:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1425;
-                break;
-            case OMX_AUDIO_AMRBandModeWB4:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1585;
-                break;
-            case OMX_AUDIO_AMRBandModeWB5:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1825;
-                break;
-            case OMX_AUDIO_AMRBandModeWB6:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1985;
-                break;
-            case OMX_AUDIO_AMRBandModeWB7:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR2305;
-                break;
-            case OMX_AUDIO_AMRBandModeWB8:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR2385;
-                break;
-            default:
-                pCompAmrParam->eAMRBandMode = SN_AUDIO_BR660;
-                break;
-            }
-            memcpy(((WBAMRENC_COMPONENT_PRIVATE *)
-                    pHandle->pComponentPrivate)->amrParams,
-                   pCompAmrParam,
-                   sizeof(OMX_AUDIO_PARAM_AMRTYPE));
-
-            if (pCompAmrParam->eAMRFrameFormat == OMX_AUDIO_AMRFrameFormatConformance) {
-                pComponentPrivate->frameMode = WBAMRENC_FORMATCONFORMANCE;
-            }
-            else if(pCompAmrParam->eAMRFrameFormat == OMX_AUDIO_AMRFrameFormatFSF){
-                pComponentPrivate->frameMode = WBAMRENC_MIMEMODE;
-            }
-            else {
-                pComponentPrivate->frameMode = WBAMRENC_IF2;
+            if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat->nPortIndex ) {
+                memcpy(pComponentPrivate->pCompPort[WBAMRENC_INPUT_PORT]->pPortFormat,
+                       pComponentParam,
+                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+            } else if ( pComponentParam->nPortIndex == pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat->nPortIndex ) {
+                memcpy(pComponentPrivate->pCompPort[WBAMRENC_OUTPUT_PORT]->pPortFormat,
+                       pComponentParam,
+                       sizeof(OMX_AUDIO_PARAM_PORTFORMATTYPE));
+            } else {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "OMX_IndexParamAudioPortFormat - OMX_ErrorBadPortIndex!");
+                eError = OMX_ErrorBadPortIndex;
             }
         }
-        else {
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "OMX_IndexParamAudioAmr - OMX_ErrorBadPortIndex!");
-            eError = OMX_ErrorBadPortIndex;
-        }
-    }
-    break;
-    case OMX_IndexParamPortDefinition:
-    {
-        pComponentParamPort = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamPortDefinition");
-        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
-           pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nPortIndex) {
-            OMX_PRINT2(pComponentPrivate->dbg, "nPortIndex %d",WBAMRENC_INPUT_PORT);
-            memcpy(pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT],
-                   pCompParam,
-                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
-        }
-        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
-                pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nPortIndex) {
-            OMX_PRINT2(pComponentPrivate->dbg, "nPortIndex %d",WBAMRENC_OUTPUT_PORT);
-            memcpy(pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT],
-                   pCompParam,
-                   sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
-        }
-        else {
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "OMX_IndexParamPortDefinition - OMX_ErrorBadPortIndex");
-            eError = OMX_ErrorBadPortIndex;
-        }
-    }
-    break;
-    case OMX_IndexParamPriorityMgmt:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamPriorityMgmt");
-        memcpy(pComponentPrivate->sPriorityMgmt,
-               (OMX_PRIORITYMGMTTYPE*)pCompParam,
-               sizeof(OMX_PRIORITYMGMTTYPE));
-    }
-    break;
+        break;
+        case OMX_IndexParamAudioAmr: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioAmr");
+            pCompAmrParam = (OMX_AUDIO_PARAM_AMRTYPE *)pCompParam;
 
-    case OMX_IndexParamAudioInit:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioInit");
-        memcpy(pComponentPrivate->sPortParam,
-               (OMX_PORT_PARAM_TYPE*)pCompParam,
-               sizeof(OMX_PORT_PARAM_TYPE));
-    }
-    break;
+            if (pCompAmrParam->nPortIndex == 0) {        /* 0 means Input port */
+	        if (((WBAMRENC_COMPONENT_PRIVATE*) pHandle->pComponentPrivate)->pcmParams == NULL) {
+		    eError = OMX_ErrorBadParameter;
+		    break;
+	        }
+                memcpy(((WBAMRENC_COMPONENT_PRIVATE*)
+                        pHandle->pComponentPrivate)->pcmParams,
+                       pCompAmrParam,
+                       sizeof(OMX_AUDIO_PARAM_AMRTYPE));
+            } else if (pCompAmrParam->nPortIndex == 1) { /* 1 means Output port */
+                switch (pCompAmrParam->eAMRBandMode) {
+                    case OMX_AUDIO_AMRBandModeWB0:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR660;
+                        break;
+                    case OMX_AUDIO_AMRBandModeWB1:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR885;
+                        break;
+                    case OMX_AUDIO_AMRBandModeWB2:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1265;
+                        break;
+                    case OMX_AUDIO_AMRBandModeWB3:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1425;
+                        break;
+                    case OMX_AUDIO_AMRBandModeWB4:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1585;
+                        break;
+                    case OMX_AUDIO_AMRBandModeWB5:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1825;
+                        break;
+                    case OMX_AUDIO_AMRBandModeWB6:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR1985;
+                        break;
+                    case OMX_AUDIO_AMRBandModeWB7:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR2305;
+                        break;
+                    case OMX_AUDIO_AMRBandModeWB8:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR2385;
+                        break;
+                    default:
+                        pCompAmrParam->eAMRBandMode = SN_AUDIO_BR660;
+                        break;
+                }
 
-    case OMX_IndexParamStandardComponentRole:
-        OMX_PRDSP2(pComponentPrivate->dbg,
-                   "OMX_IndexParamStandardComponentRole");
-        if (pCompParam) {
-            pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
-            memcpy(&(pComponentPrivate->componentRole),
-                   (void *)pRole,
-                   sizeof(OMX_PARAM_COMPONENTROLETYPE));
-        } else {
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "OMX_IndexParamStandardComponentRole - OMX_ErrorBadParameter");
-            eError = OMX_ErrorBadParameter;
+	        if (((WBAMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->amrParams == NULL) {
+	            eError = OMX_ErrorBadParameter;
+                    break; 
+	        }
+                memcpy(((WBAMRENC_COMPONENT_PRIVATE *)
+                        pHandle->pComponentPrivate)->amrParams,
+                       pCompAmrParam,
+                       sizeof(OMX_AUDIO_PARAM_AMRTYPE));
+
+                if (pCompAmrParam->eAMRFrameFormat == OMX_AUDIO_AMRFrameFormatConformance) {
+                    pComponentPrivate->frameMode = WBAMRENC_FORMATCONFORMANCE;
+                } else if (pCompAmrParam->eAMRFrameFormat == OMX_AUDIO_AMRFrameFormatFSF) {
+                    pComponentPrivate->frameMode = WBAMRENC_MIMEMODE;
+                } else {
+                    pComponentPrivate->frameMode = WBAMRENC_IF2;
+                }
+            } else {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "OMX_IndexParamAudioAmr - OMX_ErrorBadPortIndex!");
+                eError = OMX_ErrorBadPortIndex;
+            }
+        }
+        break;
+        case OMX_IndexParamPortDefinition: {
+            pComponentParamPort = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamPortDefinition");
+
+            if (((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
+                    pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nPortIndex) {
+                OMX_PRINT2(pComponentPrivate->dbg, "nPortIndex %d", WBAMRENC_INPUT_PORT);
+                memcpy(pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT],
+                       pCompParam,
+                       sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+            } else if (((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
+                       pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nPortIndex) {
+                OMX_PRINT2(pComponentPrivate->dbg, "nPortIndex %d", WBAMRENC_OUTPUT_PORT);
+                memcpy(pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT],
+                       pCompParam,
+                       sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+            } else {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "OMX_IndexParamPortDefinition - OMX_ErrorBadPortIndex");
+                eError = OMX_ErrorBadPortIndex;
+            }
+        }
+        break;
+        case OMX_IndexParamPriorityMgmt: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamPriorityMgmt");
+	    if (pComponentPrivate->sPriorityMgmt == NULL) {
+	        eError = OMX_ErrorBadParameter;
+                break; 
+	    }
+            memcpy(pComponentPrivate->sPriorityMgmt,
+                   (OMX_PRIORITYMGMTTYPE*)pCompParam,
+                   sizeof(OMX_PRIORITYMGMTTYPE));
         }
         break;
 
-    case OMX_IndexParamAudioPcm:
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioPcm");
-        if(pCompParam){
-            amr_ip = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
-            memcpy(pComponentPrivate->pcmParams,
-                   amr_ip,
-                   sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
-        }
-        else{
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "OMX_IndexParamAudioPcm - OMX_ErrorBadParameter");
-            eError = OMX_ErrorBadParameter;
+        case OMX_IndexParamAudioInit: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioInit");
+	    if (pComponentPrivate->sPortParam == NULL) {
+	        eError = OMX_ErrorBadParameter;
+                break; 
+	    }
+            memcpy(pComponentPrivate->sPortParam,
+                   (OMX_PORT_PARAM_TYPE*)pCompParam,
+                   sizeof(OMX_PORT_PARAM_TYPE));
         }
         break;
 
-    case OMX_IndexParamCompBufferSupplier:
-        OMX_PRDSP2(pComponentPrivate->dbg,
-                   "OMX_IndexParamCompBufferSupplier");
-        if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
-           pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nPortIndex) {
-            OMX_PRINT2(pComponentPrivate->dbg,
-                       "nPortIndex %d",WBAMRENC_INPUT_PORT);
-            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput;
-            memcpy(&sBufferSupplier,
-                   pCompParam,
-                   sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
-        }
-        else if(((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
-                pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nPortIndex){
-            OMX_PRINT2(pComponentPrivate->dbg,
-                       "nPortIndex %d",WBAMRENC_OUTPUT_PORT);
-            sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput;
-            memcpy(&sBufferSupplier,
-                   pCompParam,
-                   sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
-        }
-        else {
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "OMX_IndexParamCompBufferSupplier - OMX_ErrorBadPortIndex");
-            eError = OMX_ErrorBadPortIndex;
+        case OMX_IndexParamStandardComponentRole:
+            OMX_PRDSP2(pComponentPrivate->dbg,
+                       "OMX_IndexParamStandardComponentRole");
+
+            if (pCompParam) {
+                pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
+                memcpy(&(pComponentPrivate->componentRole),
+                       (void *)pRole,
+                       sizeof(OMX_PARAM_COMPONENTROLETYPE));
+            } else {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "OMX_IndexParamStandardComponentRole - OMX_ErrorBadParameter");
+                eError = OMX_ErrorBadParameter;
+            }
+
+            break;
+
+        case OMX_IndexParamAudioPcm:
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexParamAudioPcm");
+
+            if (pCompParam) {
+                amr_ip = (OMX_AUDIO_PARAM_PCMMODETYPE *)pCompParam;
+	        if (pComponentPrivate->pcmParams == NULL) {
+	            eError = OMX_ErrorBadParameter;
+                    break; 
+	        }
+                memcpy(pComponentPrivate->pcmParams,
+                       amr_ip,
+                       sizeof(OMX_AUDIO_PARAM_PCMMODETYPE));
+            } else {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "OMX_IndexParamAudioPcm - OMX_ErrorBadParameter");
+                eError = OMX_ErrorBadParameter;
+            }
+
+            break;
+
+        case OMX_IndexParamCompBufferSupplier:
+            OMX_PRDSP2(pComponentPrivate->dbg,
+                       "OMX_IndexParamCompBufferSupplier");
+
+            if (((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
+                    pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nPortIndex) {
+                OMX_PRINT2(pComponentPrivate->dbg,
+                           "nPortIndex %d", WBAMRENC_INPUT_PORT);
+                sBufferSupplier.eBufferSupplier = OMX_BufferSupplyInput;
+                memcpy(&sBufferSupplier,
+                       pCompParam,
+                       sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
+            } else if (((OMX_PARAM_PORTDEFINITIONTYPE *)(pCompParam))->nPortIndex ==
+                       pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nPortIndex) {
+                OMX_PRINT2(pComponentPrivate->dbg,
+                           "nPortIndex %d", WBAMRENC_OUTPUT_PORT);
+                sBufferSupplier.eBufferSupplier = OMX_BufferSupplyOutput;
+                memcpy(&sBufferSupplier,
+                       pCompParam,
+                       sizeof(OMX_PARAM_BUFFERSUPPLIERTYPE));
+            } else {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "OMX_IndexParamCompBufferSupplier - OMX_ErrorBadPortIndex");
+                eError = OMX_ErrorBadPortIndex;
+            }
+
+            break;
+
+        default: {
+            OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedIndex!");
+            eError = OMX_ErrorUnsupportedIndex;
         }
         break;
+    }
 
-    default:
-    {
-        OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorUnsupportedIndex!");
-        eError = OMX_ErrorUnsupportedIndex;
-    }
-    break;
-    }
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "ExitingReturning = 0x%x",eError);
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "ExitingReturning = 0x%x", eError);
     return eError;
 }
 
@@ -1270,8 +1301,7 @@
 
 static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComp,
                                 OMX_INDEXTYPE nConfigIndex,
-                                OMX_PTR ComponentConfigStructure)
-{
+                                OMX_PTR ComponentConfigStructure) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate =
@@ -1281,26 +1311,28 @@
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering");
 
-    WBAMRENC_OMX_MALLOC(streamInfo, TI_OMX_STREAM_INFO);
+    OMX_MALLOC_GENERIC(streamInfo, TI_OMX_STREAM_INFO);
 
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
-        OMX_WBMEMFREE_STRUCT(streamInfo);
+        OMX_MEMFREE_STRUCT(streamInfo);
         goto EXIT;
     }
+
 #endif
-    if(nConfigIndex == OMX_IndexCustomWbAmrEncStreamIDConfig){
+
+    if (nConfigIndex == OMX_IndexCustomWbAmrEncStreamIDConfig) {
         streamInfo->streamId = pComponentPrivate->streamID;
-        memcpy(ComponentConfigStructure,streamInfo,sizeof(TI_OMX_STREAM_INFO));
-    }
-    else if(nConfigIndex == OMX_IndexCustomDebug){
-	OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
+        memcpy(ComponentConfigStructure, streamInfo, sizeof(TI_OMX_STREAM_INFO));
+    } else if (nConfigIndex == OMX_IndexCustomDebug) {
+        OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
     }
 
-    OMX_WBMEMFREE_STRUCT(streamInfo);
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting, returning = 0x%x",eError);
+    OMX_MEMFREE_STRUCT(streamInfo);
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "Exiting, returning = 0x%x", eError);
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -1318,12 +1350,10 @@
 
 static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComp,
                                 OMX_INDEXTYPE nConfigIndex,
-                                OMX_PTR ComponentConfigStructure)
-{
+                                OMX_PTR ComponentConfigStructure) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
+    WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     OMX_COMPONENTTYPE* pHandle = (OMX_COMPONENTTYPE*)hComp;
-    WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate =
-        (WBAMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     OMX_S16 *customFlag = NULL;
     TI_OMX_DSP_DEFINITION *configData;
 
@@ -1333,147 +1363,166 @@
     AM_COMMANDDATATYPE cmd_data;
 #endif
 
-    OMX_PRINT1(pComponentPrivate->dbg, "Entering");
+    /* OMX_PRINT1(pComponentPrivate->dbg, "Entering"); */
     if (pHandle == NULL) {
-        OMX_ERROR4(pComponentPrivate->dbg,
-                   "Invalid HANDLE OMX_ErrorBadParameter");
+        /* OMX_ERROR4(pComponentPrivate->dbg, "Invalid HANDLE OMX_ErrorBadParameter"); */
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
+
+    pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    OMX_PRINT1(pComponentPrivate->dbg, "Entering");
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
     }
+
 #endif
+
     switch (nConfigIndex) {
-    case OMX_IndexCustomWbAmrEncHeaderInfoConfig:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg,
-                   "OMX_IndexCustomWbAmrEncHeaderInfoConfig");
-        configData = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure;
-        if (configData == NULL) {
-            eError = OMX_ErrorBadParameter;
-            OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
-            goto EXIT;
-        }
-        pComponentPrivate->acdnMode = configData->acousticMode;
-        pComponentPrivate->dasfMode = configData->dasfMode;
-        if( 2 == pComponentPrivate->dasfMode ){
-            pComponentPrivate->dasfMode--;
-        }
-        pComponentPrivate->streamID = configData->streamId;
-        break;
-    }
-    case OMX_WbIndexCustomModeAmrConfig:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexCustomModeAmrConfig");
-        customFlag = (OMX_S16*)ComponentConfigStructure;
-        if (customFlag == NULL) {
-            eError = OMX_ErrorBadParameter;
-            OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
-            goto EXIT;
-        }
-        pComponentPrivate->amrMode = *customFlag;
-        break;
-    }
-    case OMX_WbIndexCustomModeDasfConfig:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexCustomModeDasfConfig");
-        customFlag = (OMX_S16*)ComponentConfigStructure;
-        if (customFlag == NULL) {
-            eError = OMX_ErrorBadParameter;
-            OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
-            goto EXIT;
-        }
-        pComponentPrivate->dasfMode = *customFlag;
-        if( 2 == pComponentPrivate->dasfMode ){
-            pComponentPrivate->dasfMode--;
-        }
-        break;
-    }
-    case OMX_WbIndexCustomModeMimeConfig:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexCustomModeMimeConfig");
-        customFlag = (OMX_S16*)ComponentConfigStructure;
-        if (customFlag == NULL) {
-            eError = OMX_ErrorBadParameter;
-            OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
-            goto EXIT;
-        }
-        pComponentPrivate->frameMode = *customFlag;
-        break;
-    }
-    case OMX_WbIndexCustomModeMultiFrameConfig:
-    {
-        OMX_PRDSP2(pComponentPrivate->dbg,
-                   "OMX_WbIndexCustomModeMultiFrameConfig");
-        customFlag = (OMX_S16*)ComponentConfigStructure;
-        if (customFlag == NULL) {
-            eError = OMX_ErrorBadParameter;
-            OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
-            goto EXIT;
-        }
-        pComponentPrivate->nMultiFrameMode = *customFlag;
-        break;
-    }
+        case OMX_IndexCustomWbAmrEncHeaderInfoConfig: {
+            OMX_PRDSP2(pComponentPrivate->dbg,
+                       "OMX_IndexCustomWbAmrEncHeaderInfoConfig");
+            configData = (TI_OMX_DSP_DEFINITION*)ComponentConfigStructure;
 
-    case OMX_IndexConfigAudioVolume:
+            if (configData == NULL) {
+                eError = OMX_ErrorBadParameter;
+                OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
+                goto EXIT;
+            }
+
+            pComponentPrivate->acdnMode = configData->acousticMode;
+            pComponentPrivate->dasfMode = configData->dasfMode;
+
+            if ( 2 == pComponentPrivate->dasfMode ) {
+                pComponentPrivate->dasfMode--;
+            }
+
+            pComponentPrivate->streamID = configData->streamId;
+            break;
+        }
+        case OMX_WbIndexCustomModeAmrConfig: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexCustomModeAmrConfig");
+            customFlag = (OMX_S16*)ComponentConfigStructure;
+
+            if (customFlag == NULL) {
+                eError = OMX_ErrorBadParameter;
+                OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
+                goto EXIT;
+            }
+
+            pComponentPrivate->amrMode = *customFlag;
+            break;
+        }
+        case OMX_WbIndexCustomModeDasfConfig: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexCustomModeDasfConfig");
+            customFlag = (OMX_S16*)ComponentConfigStructure;
+
+            if (customFlag == NULL) {
+                eError = OMX_ErrorBadParameter;
+                OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
+                goto EXIT;
+            }
+
+            pComponentPrivate->dasfMode = *customFlag;
+
+            if ( 2 == pComponentPrivate->dasfMode ) {
+                pComponentPrivate->dasfMode--;
+            }
+
+            break;
+        }
+        case OMX_WbIndexCustomModeMimeConfig: {
+            OMX_PRDSP2(pComponentPrivate->dbg, "OMX_IndexCustomModeMimeConfig");
+            customFlag = (OMX_S16*)ComponentConfigStructure;
+
+            if (customFlag == NULL) {
+                eError = OMX_ErrorBadParameter;
+                OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
+                goto EXIT;
+            }
+
+            pComponentPrivate->frameMode = *customFlag;
+            break;
+        }
+        case OMX_WbIndexCustomModeMultiFrameConfig: {
+            OMX_PRDSP2(pComponentPrivate->dbg,
+                       "OMX_WbIndexCustomModeMultiFrameConfig");
+            customFlag = (OMX_S16*)ComponentConfigStructure;
+
+            if (customFlag == NULL) {
+                eError = OMX_ErrorBadParameter;
+                OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter");
+                goto EXIT;
+            }
+
+            pComponentPrivate->nMultiFrameMode = *customFlag;
+            break;
+        }
+
+        case OMX_IndexConfigAudioVolume:
 #ifdef DSP_RENDERING_ON
-        pGainStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure;
-        cmd_data.hComponent = hComp;
-        cmd_data.AM_Cmd = AM_CommandSWGain;
-        cmd_data.param1 = pGainStructure->sVolume.nValue;
-        cmd_data.param2 = 0;
-        cmd_data.streamID = pComponentPrivate->streamID;
+            pGainStructure = (OMX_AUDIO_CONFIG_VOLUMETYPE *)ComponentConfigStructure;
+            cmd_data.hComponent = hComp;
+            cmd_data.AM_Cmd = AM_CommandSWGain;
+            cmd_data.param1 = pGainStructure->sVolume.nValue;
+            cmd_data.param2 = 0;
+            cmd_data.streamID = pComponentPrivate->streamID;
 
-        if((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data)))<0)
-        {
-            OMX_ERROR4(pComponentPrivate->dbg,
-                       "Fail to send command to audio manager");
-        }
-        else
-        {
-            OMX_PRINT1(pComponentPrivate->dbg,
-                       "Success to send command to audio manager");
-        }
+            if ((write(pComponentPrivate->fdwrite, &cmd_data, sizeof(cmd_data))) < 0) {
+                OMX_ERROR4(pComponentPrivate->dbg,
+                           "Fail to send command to audio manager");
+            } else {
+                OMX_PRINT1(pComponentPrivate->dbg,
+                           "Success to send command to audio manager");
+            }
+
 #endif
-        break;
-
-    case  OMX_WbIndexCustomDataPath:
-        customFlag = (OMX_S16*)ComponentConfigStructure;
-        dataPath = *customFlag;
-        switch(dataPath) {
-        case DATAPATH_APPLICATION:
-            OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString,
-                                 RENDERTYPE_ENCODER,
-                                 pComponentPrivate->streamID);
             break;
 
-        case DATAPATH_APPLICATION_RTMIXER:
-            strcpy((char*)pComponentPrivate->sDeviceString,
-                   (char*)RTM_STRING_ENCODER);
+        case  OMX_WbIndexCustomDataPath:
+            customFlag = (OMX_S16*)ComponentConfigStructure;
+            dataPath = *customFlag;
+
+            switch (dataPath) {
+                case DATAPATH_APPLICATION:
+                    OMX_MMMIXER_DATAPATH(pComponentPrivate->sDeviceString,
+                                         RENDERTYPE_ENCODER,
+                                         pComponentPrivate->streamID);
+                    break;
+
+                case DATAPATH_APPLICATION_RTMIXER:
+                    strcpy((char*)pComponentPrivate->sDeviceString,
+                           (char*)RTM_STRING_ENCODER);
+                    break;
+
+                case DATAPATH_ACDN:
+                    strcpy((char*)pComponentPrivate->sDeviceString,
+                           (char*)ACDN_STRING_ENCODER);
+                    break;
+                default:
+                    break;
+            }
+
             break;
 
-        case DATAPATH_ACDN:
-            strcpy((char*)pComponentPrivate->sDeviceString,
-                   (char*)ACDN_STRING_ENCODER);
+        case OMX_IndexCustomDebug:
+            OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
             break;
+
         default:
+            eError = OMX_ErrorUnsupportedIndex;
             break;
-        }
-        break;
-
-    case OMX_IndexCustomDebug:
-        OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
-	break;
-
-    default:
-        eError = OMX_ErrorUnsupportedIndex;
-        break;
     }
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting SetConfig Returning = 0x%x",eError);
+
+EXIT:
+
+    if (pComponentPrivate != NULL) {
+        OMX_PRINT1(pComponentPrivate->dbg, "Exiting SetConfig Returning = 0x%x", eError);
+    }
+
     return eError;
 }
 
@@ -1569,8 +1618,7 @@
 /*-------------------------------------------------------------------*/
 
 static OMX_ERRORTYPE EmptyThisBuffer (OMX_HANDLETYPE pComponent,
-                                      OMX_BUFFERHEADERTYPE* pBuffer)
-{
+                                      OMX_BUFFERHEADERTYPE* pBuffer) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     int ret = 0;
 
@@ -1581,10 +1629,12 @@
         (WBAMRENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
     pPortDef = ((WBAMRENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[WBAMRENC_INPUT_PORT];
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
     }
+
 #endif
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedFrame(pComponentPrivate->pPERF,
@@ -1594,6 +1644,7 @@
 #endif
 
     OMX_PRBUFFER2(pComponentPrivate->dbg, "Entering");
+
     if (pBuffer == NULL) {
         eError = OMX_ErrorBadParameter;
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadParameter!");
@@ -1626,7 +1677,7 @@
     }
 
     if (pComponentPrivate->curState != OMX_StateExecuting && pComponentPrivate->curState != OMX_StatePause) {
-        eError= OMX_ErrorIncorrectStateOperation;
+        eError = OMX_ErrorIncorrectStateOperation;
         OMX_PRDSP4(pComponentPrivate->dbg,
                    "OMX_ErrorIncorrectStateOperation!");
         goto EXIT;
@@ -1636,7 +1687,7 @@
     OMX_PRBUFFER2(pComponentPrivate->dbg,
                   "--------------------------------------------------------");
     OMX_PRBUFFER2(pComponentPrivate->dbg,
-                  "Sending Filled ip buff = %p to CompThread",pBuffer);
+                  "Sending Filled ip buff = %p to CompThread", pBuffer);
     OMX_PRBUFFER2(pComponentPrivate->dbg,
                   "--------------------------------------------------------");
 
@@ -1647,15 +1698,17 @@
     ret = write (pComponentPrivate->dataPipe[1],
                  &pBuffer,
                  sizeof(OMX_BUFFERHEADERTYPE*));
+
     if (ret == -1) {
         OMX_ERROR4(pComponentPrivate->dbg,
                    "Error in Writing to the Data pipe");
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
+
     pComponentPrivate->nEmptyThisBufferCount++;
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x",eError);
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x", eError);
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -1673,8 +1726,7 @@
 /*-------------------------------------------------------------------*/
 
 static OMX_ERRORTYPE FillThisBuffer (OMX_HANDLETYPE pComponent,
-                                     OMX_BUFFERHEADERTYPE* pBuffer)
-{
+                                     OMX_BUFFERHEADERTYPE* pBuffer) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     int ret = 0;
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
@@ -1684,10 +1736,12 @@
     pPortDef = ((WBAMRENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[WBAMRENC_OUTPUT_PORT];
 
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
     }
+
 #endif
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedFrame(pComponentPrivate->pPERF,
@@ -1729,8 +1783,8 @@
         goto EXIT;
     }
 
-    if(pComponentPrivate->curState != OMX_StateExecuting &&
-       pComponentPrivate->curState != OMX_StatePause) {
+    if (pComponentPrivate->curState != OMX_StateExecuting &&
+            pComponentPrivate->curState != OMX_StatePause) {
         eError = OMX_ErrorIncorrectStateOperation;
         OMX_ERROR4(pComponentPrivate->dbg,
                    "OMX_ErrorIncorrectStateOperation");
@@ -1738,7 +1792,8 @@
     }
 
     pComponentPrivate->app_nBuf--;
-    if(pComponentPrivate->pMarkBuf != NULL){
+
+    if (pComponentPrivate->pMarkBuf != NULL) {
         pBuffer->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
         pBuffer->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
         pComponentPrivate->pMarkBuf = NULL;
@@ -1751,21 +1806,23 @@
     }
 
     OMX_PRBUFFER2(pComponentPrivate->dbg,
-                  "Sending Emptied op buff = %p to CompThread",pBuffer);
+                  "Sending Emptied op buff = %p to CompThread", pBuffer);
 
     pComponentPrivate->ProcessingOutputBuf++;
     ret = write (pComponentPrivate->dataPipe[1],
                  &pBuffer,
                  sizeof (OMX_BUFFERHEADERTYPE*));
+
     if (ret == -1) {
         OMX_ERROR4(pComponentPrivate->dbg,
                    "Error in Writing to the Data pipe");
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
+
     pComponentPrivate->nFillThisBufferCount++;
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x",eError);
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x", eError);
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -1779,8 +1836,7 @@
  **/
 /*-------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle)
-{
+static OMX_ERRORTYPE ComponentDeInit(OMX_HANDLETYPE pHandle) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
 
@@ -1806,30 +1862,35 @@
                                     0,
                                     3456,
                                     NULL);
+
     if (eError != OMX_ErrorNone) {
         OMX_ERROR4(dbg,
                    "Error returned from destroy ResourceManagerProxy thread");
     }
 
     eError = RMProxy_Deinitalize();
+
     if (eError != OMX_ErrorNone) {
         OMX_ERROR4(dbg, "Error from RMProxy_Deinitalize");
         goto EXIT;
     }
+
 #endif
 
     pthread_mutex_destroy(&pComponentPrivate->mutexStateChangeRequest);
     pthread_cond_destroy(&pComponentPrivate->StateChangeCondition);
-
     pComponentPrivate->bIsThreadstop = 1;
     eError = WBAMRENC_StopComponentThread(pHandle);
+
     if (eError != OMX_ErrorNone) {
         OMX_ERROR4(dbg, "Error from WBAMRENC_StopComponentThread");
         goto EXIT;
     }
+
     /* Wait for thread to exit so we can get the status into "eError" */
     /* close the pipe handles */
     eError = WBAMRENC_FreeCompResources(pHandle);
+
     if (eError != OMX_ErrorNone) {
         OMX_ERROR4(dbg, "Error from WBAMRENC_FreeCompResources");
         goto EXIT;
@@ -1840,13 +1901,14 @@
                   PERF_BoundaryComplete | PERF_BoundaryCleanup);
     PERF_Done(pComponentPrivate->pPERF);
 #endif
+
     if (pComponentPrivate->sDeviceString != NULL) {
         newfree(pComponentPrivate->sDeviceString);
     }
 
-    OMX_WBMEMFREE_STRUCT(pComponentPrivate);
- EXIT:
-    OMX_PRINT1(dbg, "Exiting ComponentDeInit Returning = 0x%x",eError);
+    OMX_MEMFREE_STRUCT(pComponentPrivate);
+EXIT:
+    OMX_PRINT1(dbg, "Exiting ComponentDeInit Returning = 0x%x", eError);
     OMX_DBG_CLOSE(dbg);
     return eError;
 }
@@ -1868,16 +1930,15 @@
 /*-------------------------------------------------------------------*/
 
 static OMX_ERRORTYPE ComponentTunnelRequest (OMX_HANDLETYPE hComp,
-                                             OMX_U32 nPort,
-                                             OMX_HANDLETYPE hTunneledComp,
-                                             OMX_U32 nTunneledPort,
-                                             OMX_TUNNELSETUPTYPE* pTunnelSetup)
-{
+        OMX_U32 nPort,
+        OMX_HANDLETYPE hTunneledComp,
+        OMX_U32 nTunneledPort,
+        OMX_TUNNELSETUPTYPE* pTunnelSetup) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     eError = OMX_ErrorNotImplemented;
     OMXDBG_PRINT(stderr, PRINT, 1, 0, "Entering");
     OMXDBG_PRINT(stderr, PRINT, 1, 0, "Exiting");
-    OMXDBG_PRINT(stderr, PRINT, 2, 0, "Returning = 0x%x",eError);
+    OMXDBG_PRINT(stderr, PRINT, 2, 0, "Returning = 0x%x", eError);
     return eError;
 }
 
@@ -1907,19 +1968,21 @@
     OMX_BUFFERHEADERTYPE *pBufferHeader;
 
     pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)
-        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
+                        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
     pPortDef = ((WBAMRENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
     }
+
 #endif
     OMX_PRBUFFER2(pComponentPrivate->dbg, "Entering");
-    OMX_PRINT2(pComponentPrivate->dbg, "pPortDef = %p",pPortDef);
+    OMX_PRINT2(pComponentPrivate->dbg, "pPortDef = %p", pPortDef);
     OMX_PRINT2(pComponentPrivate->dbg,
-               "pPortDef->bEnabled = %d",pPortDef->bEnabled);
+               "pPortDef->bEnabled = %d", pPortDef->bEnabled);
 
     while (!pPortDef->bEnabled) {
         pComponentPrivate->AlloBuf_waitingsignal = 1;
@@ -1933,8 +1996,8 @@
 #endif
     }
 
-    WBAMRENC_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
-    WBAMRENC_OMX_MALLOC_SIZE(pBufferHeader->pBuffer, nSizeBytes + 256,OMX_U8);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_SIZE(pBufferHeader->pBuffer, nSizeBytes + 256, OMX_U8);
 
     if (pBufferHeader->pBuffer == NULL) {
         /* Free previously allocated memory before bailing */
@@ -1942,6 +2005,7 @@
             newfree(pBufferHeader);
             pBufferHeader = NULL;
         }
+
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
@@ -1954,13 +2018,13 @@
         pComponentPrivate->pInputBufferList->pBufHdr[pComponentPrivate->pInputBufferList->numBuffers] = pBufferHeader;
         pComponentPrivate->pInputBufferList->bBufferPending[pComponentPrivate->pInputBufferList->numBuffers] = 0;
         pComponentPrivate->pInputBufferList->bufferOwner[pComponentPrivate->pInputBufferList->numBuffers++] = 1;
+
         if (pComponentPrivate->pInputBufferList->numBuffers == pPortDef->nBufferCountActual) {
             pPortDef->bPopulated = OMX_TRUE;
             OMX_PRINT2(pComponentPrivate->dbg,
                        "pPortDef->bPopulated = %d", pPortDef->bPopulated);
         }
-    }
-    else if (nPortIndex == WBAMRENC_OUTPUT_PORT) {
+    } else if (nPortIndex == WBAMRENC_OUTPUT_PORT) {
         pBufferHeader->nInputPortIndex = -1;
         pBufferHeader->nOutputPortIndex = nPortIndex;
         pComponentPrivate->pOutputBufferList->pBufHdr[pComponentPrivate->pOutputBufferList->numBuffers] = pBufferHeader;
@@ -1972,28 +2036,26 @@
             OMX_PRINT2(pComponentPrivate->dbg,
                        "pPortDef->bPopulated = %d", pPortDef->bPopulated);
         }
-    }
-    else {
+    } else {
         eError = OMX_ErrorBadPortIndex;
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorBadPortIndex");
         goto EXIT;
     }
 
     if (((pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated ==
-          pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled)&&
-         (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated ==
-          pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled) &&
-         (pComponentPrivate->InLoaded_readytoidle)))
-        {
-            pComponentPrivate->InLoaded_readytoidle = 0;
+            pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled) &&
+            (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated ==
+             pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled) &&
+            (pComponentPrivate->InLoaded_readytoidle))) {
+        pComponentPrivate->InLoaded_readytoidle = 0;
 #ifndef UNDER_CE
-            pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
-            pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
-            pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
+        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
+        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
+        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
 #else
-            OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
+        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
 #endif
-        }
+    }
 
     pBufferHeader->pAppPrivate = pAppPrivate;
     pBufferHeader->pPlatformPrivate = pComponentPrivate;
@@ -2007,10 +2069,10 @@
     if (pComponentPrivate->bEnableCommandPending && pPortDef->bPopulated) {
         SendCommand (pComponentPrivate->pHandle,
                      OMX_CommandPortEnable,
-                     pComponentPrivate->bEnableCommandParam,NULL);
+                     pComponentPrivate->bEnableCommandParam, NULL);
     }
 
- EXIT:
+EXIT:
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedBuffer(pComponentPrivate->pPERF,
@@ -2018,7 +2080,7 @@
                         PERF_ModuleMemory);
 #endif
 
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x", eError);
     return eError;
 }
 
@@ -2037,8 +2099,7 @@
 
 static OMX_ERRORTYPE FreeBuffer(OMX_IN  OMX_HANDLETYPE hComponent,
                                 OMX_IN  OMX_U32 nPortIndex,
-                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer)
-{
+                                OMX_IN  OMX_BUFFERHEADERTYPE* pBuffer) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     WBAMRENC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
     OMX_BUFFERHEADERTYPE* buff;
@@ -2049,42 +2110,43 @@
     OMX_COMPONENTTYPE *pHandle;
 
     pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)
-        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
+                        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
     pHandle = (OMX_COMPONENTTYPE *) pComponentPrivate->pHandle;
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering");
-    for (i=0; i < WBAMRENC_MAX_NUM_OF_BUFS; i++) {
+
+    for (i = 0; i < WBAMRENC_MAX_NUM_OF_BUFS; i++) {
         buff = pComponentPrivate->pInputBufferList->pBufHdr[i];
+
         if (buff == pBuffer) {
             OMX_PRBUFFER2(pComponentPrivate->dbg,
                           "Found matching input buffer");
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p",buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p",pBuffer);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p", buff);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p", pBuffer);
             inputIndex = i;
             break;
-        }
-        else {
+        } else {
             OMX_PRBUFFER2(pComponentPrivate->dbg, "This is not a match");
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p",buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p",pBuffer);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p", buff);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p", pBuffer);
         }
     }
 
-    for (i=0; i < WBAMRENC_MAX_NUM_OF_BUFS; i++) {
+    for (i = 0; i < WBAMRENC_MAX_NUM_OF_BUFS; i++) {
         buff = pComponentPrivate->pOutputBufferList->pBufHdr[i];
+
         if (buff == pBuffer) {
             OMX_PRBUFFER2(pComponentPrivate->dbg,
                           "Found matching output buffer");
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p",buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p",pBuffer);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p", buff);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p", pBuffer);
             outputIndex = i;
             break;
-        }
-        else {
+        } else {
             OMX_PRBUFFER2(pComponentPrivate->dbg, "This is not a match");
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p",buff);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p",pBuffer);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "buff = %p", buff);
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "pBuffer = %p", pBuffer);
         }
     }
 
@@ -2092,10 +2154,12 @@
     if (inputIndex != -1) {
         if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
             tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
-            if (tempBuff != 0){
+
+            if (tempBuff != 0) {
                 tempBuff -= 128;
             }
-            OMX_WBMEMFREE_STRUCT(tempBuff);
+
+            OMX_MEMFREE_STRUCT(tempBuff);
         }
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -2104,19 +2168,21 @@
                            pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->nAllocLen,
                            PERF_ModuleMemory );
 #endif
-        OMX_WBMEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
 
         pComponentPrivate->pInputBufferList->numBuffers--;
+
         if (pComponentPrivate->pInputBufferList->numBuffers <
-            pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nBufferCountMin) {
+                pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->nBufferCountMin) {
 
             pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated = OMX_FALSE;
         }
-        if(pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled &&
-           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
-           (pComponentPrivate->curState == OMX_StateIdle ||
-            pComponentPrivate->curState == OMX_StateExecuting ||
-            pComponentPrivate->curState == OMX_StatePause)) {
+
+        if (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled &&
+                pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
+                (pComponentPrivate->curState == OMX_StateIdle ||
+                 pComponentPrivate->curState == OMX_StateExecuting ||
+                 pComponentPrivate->curState == OMX_StatePause)) {
             pComponentPrivate->cbInfo.EventHandler( pHandle,
                                                     pHandle->pApplicationPrivate,
                                                     OMX_EventError,
@@ -2124,33 +2190,37 @@
                                                     OMX_TI_ErrorMinor,
                                                     "Input Port Unpopulated");
         }
-    }
-    else if (outputIndex != -1) {
+    } else if (outputIndex != -1) {
         if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
             tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
-            if (tempBuff != 0){
+
+            if (tempBuff != 0) {
                 tempBuff -= 128;
             }
-            OMX_WBMEMFREE_STRUCT(tempBuff);
+
+            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_WBMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
 
         pComponentPrivate->pOutputBufferList->numBuffers--;
+
         if (pComponentPrivate->pOutputBufferList->numBuffers <
-            pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nBufferCountMin) {
+                pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->nBufferCountMin) {
             pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated = OMX_FALSE;
         }
-        if(pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled &&
-           pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
-           (pComponentPrivate->curState == OMX_StateIdle ||
-            pComponentPrivate->curState == OMX_StateExecuting ||
-            pComponentPrivate->curState == OMX_StatePause)) {
+
+        if (pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled &&
+                pComponentPrivate->bLoadedCommandPending == OMX_FALSE &&
+                (pComponentPrivate->curState == OMX_StateIdle ||
+                 pComponentPrivate->curState == OMX_StateExecuting ||
+                 pComponentPrivate->curState == OMX_StatePause)) {
             pComponentPrivate->cbInfo.EventHandler( pHandle,
                                                     pHandle->pApplicationPrivate,
                                                     OMX_EventError,
@@ -2158,8 +2228,7 @@
                                                     OMX_TI_ErrorMinor,
                                                     "Output Port Unpopulated");
         }
-    }
-    else {
+    } else {
         OMX_ERROR4(pComponentPrivate->dbg, "Returning OMX_ErrorBadParameter");
         eError = OMX_ErrorBadParameter;
     }
@@ -2171,30 +2240,29 @@
                   pComponentPrivate->InIdle_goingtoloaded);
 
     if ((!pComponentPrivate->pInputBufferList->numBuffers &&
-         !pComponentPrivate->pOutputBufferList->numBuffers) &&
-        pComponentPrivate->InIdle_goingtoloaded)
-        {
+            !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);
-            pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
+        pthread_mutex_lock(&pComponentPrivate->InIdle_mutex);
+        pthread_cond_signal(&pComponentPrivate->InIdle_threshold);
+        pthread_mutex_unlock(&pComponentPrivate->InIdle_mutex);
 #else
-            OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
+        OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
 #endif
-        }
+    }
 
     if (pComponentPrivate->bDisableCommandPending &&
-        (pComponentPrivate->pInputBufferList->numBuffers +
-         pComponentPrivate->pOutputBufferList->numBuffers == 0)) {
+            (pComponentPrivate->pInputBufferList->numBuffers +
+             pComponentPrivate->pOutputBufferList->numBuffers == 0)) {
         SendCommand (pComponentPrivate->pHandle,
                      OMX_CommandPortDisable,
                      pComponentPrivate->bDisableCommandParam,
                      NULL);
     }
 
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x",eError);
+    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x", eError);
     return eError;
 }
 
@@ -2215,35 +2283,36 @@
                                 OMX_IN OMX_U32 nPortIndex,
                                 OMX_IN OMX_PTR pAppPrivate,
                                 OMX_IN OMX_U32 nSizeBytes,
-                                OMX_IN OMX_U8* pBuffer)
-{
+                                OMX_IN OMX_U8* pBuffer) {
     OMX_PARAM_PORTDEFINITIONTYPE *pPortDef;
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_BUFFERHEADERTYPE *pBufferHeader;
 
     pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)
-        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
+                        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
 #ifdef _ERROR_PROPAGATION__
-    if (pComponentPrivate->curState == OMX_StateInvalid){
+
+    if (pComponentPrivate->curState == OMX_StateInvalid) {
         eError = OMX_ErrorInvalidState;
         goto EXIT;
     }
+
 #endif
     pPortDef = ((WBAMRENC_COMPONENT_PRIVATE*)pComponentPrivate)->pPortDef[nPortIndex];
     OMX_PRINT1(pComponentPrivate->dbg, "Entering");
     OMX_PRBUFFER2(pComponentPrivate->dbg, "pPortDef->bPopulated = %d",
                   pPortDef->bPopulated);
 
-    if(!pPortDef->bEnabled) {
+    if (!pPortDef->bEnabled) {
         OMX_ERROR4(pComponentPrivate->dbg, "OMX_ErrorIncorrectStateOperation");
         eError = OMX_ErrorIncorrectStateOperation;
         goto EXIT;
     }
 
 
-    WBAMRENC_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
 
     if (nPortIndex == WBAMRENC_OUTPUT_PORT) {
         pBufferHeader->nInputPortIndex = -1;
@@ -2253,40 +2322,40 @@
         pComponentPrivate->pOutputBufferList->bufferOwner[pComponentPrivate->pOutputBufferList->numBuffers++] = 0;
 
         if (pComponentPrivate->pOutputBufferList->numBuffers ==
-            pPortDef->nBufferCountActual) {
+                pPortDef->nBufferCountActual) {
             pPortDef->bPopulated = OMX_TRUE;
         }
-    }
-    else {
+    } else {
         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->nBufferCountActual) {
             pPortDef->bPopulated = OMX_TRUE;
         }
     }
 
     if (((!pComponentPrivate->dasfMode) &&
-         ((pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled)&&
-          (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled) &&
-          (pComponentPrivate->InLoaded_readytoidle)))/*File Mode*/
-        ||
-        ((pComponentPrivate->dasfMode) &&
-         ((pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled)&&
-          (pComponentPrivate->InLoaded_readytoidle))))/*Dasf Mode*/
-        {
-            pComponentPrivate->InLoaded_readytoidle = 0;
+            ((pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled) &&
+             (pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMRENC_INPUT_PORT]->bEnabled) &&
+             (pComponentPrivate->InLoaded_readytoidle)))/*File Mode*/
+            ||
+            ((pComponentPrivate->dasfMode) &&
+             ((pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bPopulated == pComponentPrivate->pPortDef[WBAMRENC_OUTPUT_PORT]->bEnabled) &&
+              (pComponentPrivate->InLoaded_readytoidle)))) { /*Dasf Mode*/
+        pComponentPrivate->InLoaded_readytoidle = 0;
 #ifndef UNDER_CE
-            pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
-            pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
-            pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
+        pthread_mutex_lock(&pComponentPrivate->InLoaded_mutex);
+        pthread_cond_signal(&pComponentPrivate->InLoaded_threshold);
+        pthread_mutex_unlock(&pComponentPrivate->InLoaded_mutex);
 #else
-            OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
+        OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
 #endif
-        }
+    }
+
     pBufferHeader->pAppPrivate = pAppPrivate;
     pBufferHeader->pPlatformPrivate = pComponentPrivate;
     pBufferHeader->nAllocLen = nSizeBytes;
@@ -2302,8 +2371,8 @@
                         pBuffer, nSizeBytes,
                         PERF_ModuleHLMM);
 #endif
- EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x",eError);
+EXIT:
+    OMX_PRINT1(pComponentPrivate->dbg, "Exiting Returning = 0x%x", eError);
     return eError;
 }
 
@@ -2318,31 +2387,24 @@
 /* ================================================================================ */
 static OMX_ERRORTYPE GetExtensionIndex(OMX_IN  OMX_HANDLETYPE hComponent,
                                        OMX_IN  OMX_STRING cParameterName,
-                                       OMX_OUT OMX_INDEXTYPE* pIndexType)
-{
+                                       OMX_OUT OMX_INDEXTYPE* pIndexType) {
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
     pComponentPrivate = (WBAMRENC_COMPONENT_PRIVATE *)
-        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
+                        (((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering");
 
-    if(!(strcmp(cParameterName,"OMX.TI.index.config.wbamrheaderinfo"))) {
+    if (!(strcmp(cParameterName, "OMX.TI.index.config.wbamrheaderinfo"))) {
         *pIndexType = OMX_IndexCustomWbAmrEncHeaderInfoConfig;
-    }
-    else if(!(strcmp(cParameterName,"OMX.TI.index.config.wbamrstreamIDinfo"))){
+    } else if (!(strcmp(cParameterName, "OMX.TI.index.config.wbamrstreamIDinfo"))) {
         *pIndexType = OMX_IndexCustomWbAmrEncStreamIDConfig;
-    }
-    else if(!(strcmp(cParameterName,"OMX.TI.index.config.wbamr.datapath")))
-    {
+    } else if (!(strcmp(cParameterName, "OMX.TI.index.config.wbamr.datapath"))) {
         *pIndexType = OMX_WbIndexCustomDataPath;
-    }
-    else if(!(strcmp(cParameterName,"OMX.TI.WBAMR.Encode.Debug")))
-    {
+    } else if (!(strcmp(cParameterName, "OMX.TI.WBAMR.Encode.Debug"))) {
         *pIndexType = OMX_IndexCustomDebug;
-    }
-    else {
+    } else {
         eError = OMX_ErrorBadParameter;
     }
 
@@ -2356,52 +2418,62 @@
  * @fns Sleep replace for WIN CE
  */
 /* ================================================================================ */
-int OMX_CreateEvent(OMX_Event *event){
+int OMX_CreateEvent(OMX_Event *event) {
     int ret = OMX_ErrorNone;
     HANDLE createdEvent = NULL;
-    if(event == NULL){
+
+    if (event == NULL) {
         ret = OMX_ErrorBadParameter;
         goto EXIT;
     }
+
     event->event  = CreateEvent(NULL, TRUE, FALSE, NULL);
-    if(event->event == NULL)
+
+    if (event->event == NULL)
         ret = (int)GetLastError();
- EXIT:
+
+EXIT:
     return ret;
 }
 
-int OMX_SignalEvent(OMX_Event *event){
+int OMX_SignalEvent(OMX_Event *event) {
     int ret = OMX_ErrorNone;
-    if(event == NULL){
+
+    if (event == NULL) {
         ret = OMX_ErrorBadParameter;
         goto EXIT;
     }
+
     SetEvent(event->event);
     ret = (int)GetLastError();
- EXIT:
+EXIT:
     return ret;
 }
 
 int OMX_WaitForEvent(OMX_Event *event) {
     int ret = OMX_ErrorNone;
-    if(event == NULL){
+
+    if (event == NULL) {
         ret = OMX_ErrorBadParameter;
         goto EXIT;
     }
+
     WaitForSingleObject(event->event, INFINITE);
     ret = (int)GetLastError();
- EXIT:
+EXIT:
     return ret;
 }
 
 int OMX_DestroyEvent(OMX_Event *event) {
     int ret = OMX_ErrorNone;
-    if(event == NULL){
+
+    if (event == NULL) {
         ret = OMX_ErrorBadParameter;
         goto EXIT;
     }
+
     CloseHandle(event->event);
- EXIT:
+EXIT:
     return ret;
 }
 #endif
@@ -2416,10 +2488,9 @@
  */
 /* ================================================================================ */
 static OMX_ERRORTYPE ComponentRoleEnum(
-                                       OMX_IN OMX_HANDLETYPE hComponent,
-                                       OMX_OUT OMX_U8 *cRole,
-                                       OMX_IN OMX_U32 nIndex)
-{
+    OMX_IN OMX_HANDLETYPE hComponent,
+    OMX_OUT OMX_U8 *cRole,
+    OMX_IN OMX_U32 nIndex) {
     WBAMRENC_COMPONENT_PRIVATE *pComponentPrivate;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
@@ -2427,14 +2498,18 @@
 
     OMX_PRINT1(pComponentPrivate->dbg, "Entering");
 
-    if(nIndex == 0){
-        memcpy(cRole,
-               &pComponentPrivate->componentRole.cRole,
-               sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
-        OMX_PRINT2(pComponentPrivate->dbg,
-                   "cRole is set to %s for nIndex %ld",cRole,nIndex);
-    }
-    else {
+    if (nIndex == 0) {
+        if (cRole == NULL) {
+            eError = OMX_ErrorBadParameter;
+	}
+	else {
+            memcpy(cRole,
+                   &pComponentPrivate->componentRole.cRole,
+                   sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE);
+            OMX_PRINT2(pComponentPrivate->dbg,
+                       "cRole is set to %s for nIndex %ld", cRole, nIndex);
+        }
+    } else {
         eError = OMX_ErrorNoMore;
     }
 
diff --git a/omx/audio/src/openmax_il/wbamr_enc/tests/WbAmrEncTest.c b/omx/audio/src/openmax_il/wbamr_enc/tests/WbAmrEncTest.c
index deef32d..f3eb61b 100644
--- a/omx/audio/src/openmax_il/wbamr_enc/tests/WbAmrEncTest.c
+++ b/omx/audio/src/openmax_il/wbamr_enc/tests/WbAmrEncTest.c
@@ -67,14 +67,14 @@
 #include <OMX_Audio.h>
 #include <TIDspOmx.h>
 
-#ifdef DSP_RENDERING_ON 
+#ifdef DSP_RENDERING_ON
 #include <AudioManagerAPI.h>
 #endif
 #include <time.h>
 
 #ifdef OMX_GETTIME
-    #include <OMX_Common_Utils.h>
-    #include <OMX_GetTime.h>     /*Headers for Performance & measuremet    */
+#include <OMX_Common_Utils.h>
+#include <OMX_GetTime.h>     /*Headers for Performance & measuremet    */
 #endif
 FILE *fpRes;
 
@@ -98,8 +98,8 @@
 #define WBAPP_NUM_OUTPUT_BUFFERS 1
 /* ======================================================================= */
 /**
- * @def WBAPP_INPUT_BUFFER_SIZE   	  Default input buffer size
- *		WBAPP_INPUT_BUFFER_SIZE_DASF  Default input buffer size DASF
+ * @def WBAPP_INPUT_BUFFER_SIZE       Default input buffer size
+ *      WBAPP_INPUT_BUFFER_SIZE_DASF  Default input buffer size DASF
  */
 /* ======================================================================= */
 #define WBAPP_INPUT_BUFFER_SIZE 640
@@ -119,7 +119,7 @@
 
 /* ======================================================================= */
 /*
- * @def	WBAMRENC_APP_ID  App ID Value setting
+ * @def WBAMRENC_APP_ID  App ID Value setting
  */
 /* ======================================================================= */
 #define WBAMRENC_APP_ID 100
@@ -141,31 +141,31 @@
 
 
 #ifdef  APP_INFO
-        #define APP_IPRINT(...)    fprintf(stderr,__VA_ARGS__)			/* Information prints */
+#define APP_IPRINT(...)    fprintf(stderr,__VA_ARGS__)          /* Information prints */
 #else
-        #define APP_IPRINT(...)
+#define APP_IPRINT(...)
 #endif
 
 
 #ifdef APP_DEBUG
-    #define APP_DPRINT(...)    fprintf(stderr,__VA_ARGS__)
+#define APP_DPRINT(...)    fprintf(stderr,__VA_ARGS__)
 #else
-    #define APP_DPRINT(...)
+#define APP_DPRINT(...)
 #endif
 
 #ifdef APP_MEMCHECK
-    #define APP_MEMPRINT(...)    fprintf(stderr,__VA_ARGS__)
+#define APP_MEMPRINT(...)    fprintf(stderr,__VA_ARGS__)
 #else
-    #define APP_MEMPRINT(...)
+#define APP_MEMPRINT(...)
 #endif
 
 #undef APP_DEBUGMEM
 
 #ifdef OMX_GETTIME
-  OMX_ERRORTYPE eError = OMX_ErrorNone;
-  int GT_FlagE = 0;  /* Fill Buffer 1 = First Buffer,  0 = Not First Buffer  */
-  int GT_FlagF = 0;  /*Empty Buffer  1 = First Buffer,  0 = Not First Buffer  */
-  static OMX_NODE* pListHead = NULL;
+OMX_ERRORTYPE eError = OMX_ErrorNone;
+int GT_FlagE = 0;  /* Fill Buffer 1 = First Buffer,  0 = Not First Buffer  */
+int GT_FlagF = 0;  /*Empty Buffer  1 = First Buffer,  0 = Not First Buffer  */
+static OMX_NODE* pListHead = NULL;
 #endif
 
 #ifdef APP_DEBUGMEM
@@ -173,53 +173,56 @@
 int lines[500];
 int bytes[500];
 char file[500][50];
-int ind=0;
+int ind = 0;
 
 #define newmalloc(x) mynewmalloc(__LINE__,__FILE__,x)
 #define newfree(z) mynewfree(z,__LINE__,__FILE__)
 
-void * mynewmalloc(int line, char *s, int size)
-{
-   void *p;    
-   int e=0;
-   p = calloc(1,size);
-   if(p==NULL){
-       APP_IPRINT("Memory not available\n");
-       exit(1);
-       }
-   else{
-         while((lines[e]!=0)&& (e<500) ){
-              e++;
-         }
-         arr[e]=p;
-         lines[e]=line;
-         bytes[e]=size;
-         strcpy(file[e],s);
-         APP_IPRINT("Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
-         return p;
-   }
+void * mynewmalloc(int line, char *s, int size) {
+    void *p;
+    int e = 0;
+    p = calloc(1, size);
+
+    if (p == NULL) {
+        APP_IPRINT("Memory not available\n");
+        exit(1);
+    } else {
+        while ((lines[e] != 0) && (e < 500) ) {
+            e++;
+        }
+
+        arr[e] = p;
+        lines[e] = line;
+        bytes[e] = size;
+        strcpy(file[e], s);
+        APP_IPRINT("Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
+        return p;
+    }
 }
 
-int mynewfree(void *dp, int line, char *s){
+int mynewfree(void *dp, int line, char *s) {
     int q;
-    if(dp==NULL){
-                 APP_IPRINT("NULL can't be deleted\n");
-                 return 0;
-    }
-    for(q=0;q<500;q++){
-        if(arr[q]==dp){
-           APP_IPRINT("Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
-           free(dp);
-           dp = NULL;
-           lines[q]=0;
-           strcpy(file[q],"");
-           break;
-        }            
-     }    
-     if(500==q)
-         APP_IPRINT("\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
 
-	 return 1;
+    if (dp == NULL) {
+        APP_IPRINT("NULL can't be deleted\n");
+        return 0;
+    }
+
+    for (q = 0; q < 500; q++) {
+        if (arr[q] == dp) {
+            APP_IPRINT("Deleting %d bytes on address %p, line %d file %s\n", bytes[q], dp, line, s);
+            free(dp);
+            dp = NULL;
+            lines[q] = 0;
+            strcpy(file[q], "");
+            break;
+        }
+    }
+
+    if (500 == q)
+        APP_IPRINT("\n\nPointer not found. Line:%d    File%s!!\n\n", line, s);
+
+    return 1;
 }
 #else
 #define newmalloc(x) malloc(x)
@@ -227,8 +230,8 @@
 #endif
 
 typedef struct WBAMRENC_BUFDATA {
-   OMX_U8 nFrames;     
-}WBAMRENC_BUFDATA;
+    OMX_U8 nFrames;
+} WBAMRENC_BUFDATA;
 
 /* ======================================================================= */
 /**
@@ -236,17 +239,17 @@
  */
 /* ======================================================================= */
 
-#define OMX_WBAPP_CONF_INIT_STRUCT(_s_, _name_)	\
-    memset((_s_), 0x0, sizeof(_name_));	\
-    (_s_)->nSize = sizeof(_name_);		\
-    (_s_)->nVersion.s.nVersionMajor = 0x1;	\
-    (_s_)->nVersion.s.nVersionMinor = 0x0;	\
-    (_s_)->nVersion.s.nRevision = 0x0;		\
+#define OMX_WBAPP_CONF_INIT_STRUCT(_s_, _name_) \
+    memset((_s_), 0x0, sizeof(_name_)); \
+    (_s_)->nSize = sizeof(_name_);      \
+    (_s_)->nVersion.s.nVersionMajor = 0x1;  \
+    (_s_)->nVersion.s.nVersionMinor = 0x0;  \
+    (_s_)->nVersion.s.nRevision = 0x0;      \
     (_s_)->nVersion.s.nStep = 0x0
 
-#define OMX_WBAPP_INIT_STRUCT(_s_, _name_)	\
-    memset((_s_), 0x0, sizeof(_name_));	\
-
+#define OMX_WBAPP_INIT_STRUCT(_s_, _name_)  \
+    memset((_s_), 0x0, sizeof(_name_)); \
+     
 #define OMX_WBAPP_MALLOC_STRUCT(_pStruct_, _sName_)   \
     _pStruct_ = (_sName_*)newmalloc(sizeof(_sName_));      \
     if(_pStruct_ == NULL){      \
@@ -261,21 +264,21 @@
 /* ======================================================================= */
 /** WBAPP_COMP_PORT_TYPE  Port types
  *
- *  @param  WBAPP_INPUT_PORT			Input port
+ *  @param  WBAPP_INPUT_PORT            Input port
  *
- *  @param  WBAPP_OUTPUT_PORT			Output port
+ *  @param  WBAPP_OUTPUT_PORT           Output port
  */
 /*  ====================================================================== */
 /*This enum must not be changed. */
 typedef enum WBAPP_COMP_PORT_TYPE {
     WBAPP_INPUT_PORT = 0,
     WBAPP_OUTPUT_PORT
-}WBAPP_COMP_PORT_TYPE;
+} WBAPP_COMP_PORT_TYPE;
 
 /* ======================================================================= */
 /**
  * @def WBAPP_MAX_NUM_OF_BUFS      Maximum number of buffers
- * @def	WBAPP_NUM_CHANNELS 		   Number of Channels
+ * @def WBAPP_NUM_CHANNELS         Number of Channels
  * @def WBAPP_SAMPLING_FREQUENCY   Sampling frequency
  */
 /* ======================================================================= */
@@ -304,7 +307,7 @@
 int nRead;
 WBAMRENC_BUFDATA* OutputFrames;
 
-#ifdef DSP_RENDERING_ON 
+#ifdef DSP_RENDERING_ON
 AM_COMMANDDATATYPE cmd_data;
 #endif
 
@@ -312,181 +315,185 @@
 
 #ifndef USE_BUFFER
 int FreeAllResources( OMX_HANDLETYPE *pHandle,
-			                OMX_BUFFERHEADERTYPE* pBufferIn,
-			                OMX_BUFFERHEADERTYPE* pBufferOut,
-			                int NIB, int NOB,
-			                FILE* fIn, FILE* fOut);
+                      OMX_BUFFERHEADERTYPE* pBufferIn,
+                      OMX_BUFFERHEADERTYPE* pBufferOut,
+                      int NIB, int NOB,
+                      FILE* fIn, FILE* fOut);
 #else
 int  FreeAllResources(OMX_HANDLETYPE *pHandle,
-						  OMX_U8* UseInpBuf[],
-						  OMX_U8* UseOutBuf[], 			
-						  int NIB, int NOB,
-						  FILE* fIn, FILE* fOut);
-#endif	
+                      OMX_U8* UseInpBuf[],
+                      OMX_U8* UseOutBuf[],
+                      int NIB, int NOB,
+                      FILE* fIn, FILE* fOut);
+#endif
 int IpBuf_Pipe[2];
 int OpBuf_Pipe[2];
 int Event_Pipe[2];
 
 fd_set rfds;
 int done = 0;
-int DasfMode =0;
-int mframe=0;
+int DasfMode = 0;
+int mframe = 0;
 
 int preempted = 0;
 
 /* safe routine to get the maximum of 2 integers */
-int maxint(int a, int b)
-{
-   return (a>b) ? a : b;
+int maxint(int a, int b) {
+    return (a > b) ? a : b;
 }
 
 /* This method will wait for the component to get to the state
  * specified by the DesiredState input. */
 static OMX_ERRORTYPE WaitForState(OMX_HANDLETYPE* pHandle,
-                                  OMX_STATETYPE DesiredState)
-{
-     OMX_STATETYPE CurState = OMX_StateInvalid;
-     OMX_ERRORTYPE eError = OMX_ErrorNone;
-     OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
+                                  OMX_STATETYPE DesiredState) {
+    OMX_STATETYPE CurState = OMX_StateInvalid;
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
 
-     eError = pComponent->GetState(pHandle, &CurState);
-     if (CurState == OMX_StateInvalid && bInvalidState == OMX_TRUE)
-	 {
-		 	eError = OMX_ErrorInvalidState;
-	 }
+    eError = pComponent->GetState(pHandle, &CurState);
 
-    if(CurState != DesiredState){
-        WaitForState_flag = 1;
-        TargetedState = DesiredState;
-        pthread_mutex_lock(&WaitForState_mutex); 
-        pthread_cond_wait(&WaitForState_threshold, &WaitForState_mutex);/*Going to sleep till signal arrives*/
-        pthread_mutex_unlock(&WaitForState_mutex);                 
+    if (CurState == OMX_StateInvalid && bInvalidState == OMX_TRUE) {
+        eError = OMX_ErrorInvalidState;
     }
 
-	return eError;
-	 
+    if (CurState != DesiredState) {
+        WaitForState_flag = 1;
+        TargetedState = DesiredState;
+        pthread_mutex_lock(&WaitForState_mutex);
+        pthread_cond_wait(&WaitForState_threshold, &WaitForState_mutex);/*Going to sleep till signal arrives*/
+        pthread_mutex_unlock(&WaitForState_mutex);
+    }
+
+    return eError;
+
 }
 
 OMX_ERRORTYPE EventHandler(
-        OMX_HANDLETYPE hComponent,
-        OMX_PTR pAppData,
-        OMX_EVENTTYPE eEvent,
-        OMX_U32 nData1,
-        OMX_U32 nData2,
-        OMX_PTR pEventData)
-{
-   APP_DPRINT( "%d :: App: Entering EventHandler \n", __LINE__);
-   OMX_ERRORTYPE eError = OMX_ErrorNone;
-   OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)hComponent;
-   OMX_STATETYPE state;
+    OMX_HANDLETYPE hComponent,
+    OMX_PTR pAppData,
+    OMX_EVENTTYPE eEvent,
+    OMX_U32 nData1,
+    OMX_U32 nData2,
+    OMX_PTR pEventData) {
+    APP_DPRINT( "%d :: App: Entering EventHandler \n", __LINE__);
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)hComponent;
+    OMX_STATETYPE state;
 
-   OMX_U8 writeValue;  
+    OMX_U8 writeValue;
 
-   eError = pComponent->GetState (hComponent, &state);
-   if(eError != OMX_ErrorNone) {
-       APP_DPRINT("%d :: App: Error returned from GetState\n",__LINE__);
-       goto EXIT;
-   }
-   APP_DPRINT( "%d :: App: Component eEvent = %d\n", __LINE__,eEvent);
-   switch (eEvent) {
-	   APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__,state);
-       case OMX_EventCmdComplete:
-           APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__,state);
-		if (nData1 == OMX_CommandPortDisable) {
-			if (nData2 == WBAPP_INPUT_PORT) {
-				inputPortDisabled = 1;
-			}
-			if (nData2 == WBAPP_OUTPUT_PORT) {
-				outputPortDisabled = 1;
-			}
-		}
+    eError = pComponent->GetState (hComponent, &state);
 
-		if ((nData1 == OMX_CommandStateSet) && (TargetedState == nData2) && 
-            (WaitForState_flag)){
-            WaitForState_flag = 0;
-            pthread_mutex_lock(&WaitForState_mutex);
-            pthread_cond_signal(&WaitForState_threshold);
-            pthread_mutex_unlock(&WaitForState_mutex);
-        }
-           break;
-       case OMX_EventError:
-		   if (nData1 == OMX_ErrorInvalidState) {
-                 APP_IPRINT("Event Handler Invalid!!!\n\n");
-		   		bInvalidState =OMX_TRUE;
-		   }
-		   else if(nData1 == OMX_ErrorResourcesPreempted) {
-            preempted=1;
-            writeValue = 0;  
+    if (eError != OMX_ErrorNone) {
+        APP_DPRINT("%d :: App: Error returned from GetState\n", __LINE__);
+        goto EXIT;
+    }
+
+    APP_DPRINT( "%d :: App: Component eEvent = %d\n", __LINE__, eEvent);
+
+    switch (eEvent) {
+            APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__, state);
+        case OMX_EventCmdComplete:
+            APP_DPRINT( "%d :: App: Component State Changed To %d\n", __LINE__, state);
+
+            if (nData1 == OMX_CommandPortDisable) {
+                if (nData2 == WBAPP_INPUT_PORT) {
+                    inputPortDisabled = 1;
+                }
+
+                if (nData2 == WBAPP_OUTPUT_PORT) {
+                    outputPortDisabled = 1;
+                }
+            }
+
+            if ((nData1 == OMX_CommandStateSet) && (TargetedState == nData2) &&
+                    (WaitForState_flag)) {
+                WaitForState_flag = 0;
+                pthread_mutex_lock(&WaitForState_mutex);
+                pthread_cond_signal(&WaitForState_threshold);
+                pthread_mutex_unlock(&WaitForState_mutex);
+            }
+
+            break;
+        case OMX_EventError:
+
+            if (nData1 == OMX_ErrorInvalidState) {
+                APP_IPRINT("Event Handler Invalid!!!\n\n");
+                bInvalidState = OMX_TRUE;
+            } else if (nData1 == OMX_ErrorResourcesPreempted) {
+                preempted = 1;
+                writeValue = 0;
+                write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
+            } else if (nData1 == OMX_ErrorResourcesLost) {
+                WaitForState_flag = 0;
+                pthread_mutex_lock(&WaitForState_mutex);
+                pthread_cond_signal(&WaitForState_threshold);/*Sending Waking Up Signal*/
+                pthread_mutex_unlock(&WaitForState_mutex);
+            }
+
+            break;
+        case OMX_EventMax:
+            APP_DPRINT( "%d :: App: Component OMX_EventMax = %d\n", __LINE__, eEvent);
+            break;
+        case OMX_EventMark:
+            APP_DPRINT( "%d :: App: Component OMX_EventMark = %d\n", __LINE__, eEvent);
+            break;
+        case OMX_EventPortSettingsChanged:
+            APP_DPRINT( "%d :: App: Component OMX_EventPortSettingsChanged = %d\n", __LINE__, eEvent);
+            break;
+        case OMX_EventBufferFlag:
+            APP_DPRINT( "%d :: App: Component OMX_EventBufferFlag = %d\n", __LINE__, eEvent);
+            writeValue = 2;
             write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
-	       }
-	       else if (nData1 == OMX_ErrorResourcesLost) { 
-	            WaitForState_flag = 0;
-	            pthread_mutex_lock(&WaitForState_mutex);
-	            pthread_cond_signal(&WaitForState_threshold);/*Sending Waking Up Signal*/
-	            pthread_mutex_unlock(&WaitForState_mutex);
-	        }
-           break;
-       case OMX_EventMax:
-       	   APP_DPRINT( "%d :: App: Component OMX_EventMax = %d\n", __LINE__,eEvent);
-           break;
-       case OMX_EventMark:
-       	   APP_DPRINT( "%d :: App: Component OMX_EventMark = %d\n", __LINE__,eEvent);
-           break;
-       case OMX_EventPortSettingsChanged:
-       	   APP_DPRINT( "%d :: App: Component OMX_EventPortSettingsChanged = %d\n", __LINE__,eEvent);
-       	   break;
-       case OMX_EventBufferFlag:
-       	   APP_DPRINT( "%d :: App: Component OMX_EventBufferFlag = %d\n", __LINE__,eEvent);
-		   writeValue = 2;  
-	       write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
-           break;
-       case OMX_EventResourcesAcquired:
-       	   APP_DPRINT( "%d :: App: Component OMX_EventResourcesAcquired = %d\n", __LINE__,eEvent);
-		   writeValue = 1;
-           write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
-           preempted=0;
+            break;
+        case OMX_EventResourcesAcquired:
+            APP_DPRINT( "%d :: App: Component OMX_EventResourcesAcquired = %d\n", __LINE__, eEvent);
+            writeValue = 1;
+            write(Event_Pipe[1], &writeValue, sizeof(OMX_U8));
+            preempted = 0;
 
-       	   break;
-       default:
-           break;
+            break;
+        default:
+            break;
 
-   }
+    }
+
 EXIT:
-	APP_DPRINT( "%d :: App: Exiting EventHandler \n", __LINE__);
-	return eError;
+    APP_DPRINT( "%d :: App: Exiting EventHandler \n", __LINE__);
+    return eError;
 }
 
-void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
-{
-	if (!preempted) 
-    	write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
-	
+void FillBufferDone (OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer) {
+    if (!preempted)
+        write(OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
+
 #ifdef OMX_GETTIME
-	if (GT_FlagF == 1 ) /* First Buffer Reply*/  /* 1 = First Buffer,  0 = Not First Buffer  */
-    {
-		GT_END("Call to FillBufferDone  <First: FillBufferDone>");
+
+    if (GT_FlagF == 1 ) /* First Buffer Reply*/ { /* 1 = First Buffer,  0 = Not First Buffer  */
+        GT_END("Call to FillBufferDone  <First: FillBufferDone>");
         GT_FlagF = 0 ;   /* 1 = First Buffer,  0 = Not First Buffer  */
     }
+
 #endif
 }
 
-void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer)
-{
+void EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* pBuffer) {
     write(IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
 #ifdef OMX_GETTIME
-    if (GT_FlagE == 1 ) /* First Buffer Reply*/  /* 1 = First Buffer,  0 = Not First Buffer  */
-    {
-      GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>");
-	  GT_FlagE = 0;   /* 1 = First Buffer,  0 = Not First Buffer  */
+
+    if (GT_FlagE == 1 ) /* First Buffer Reply*/ { /* 1 = First Buffer,  0 = Not First Buffer  */
+        GT_END("Call to EmptyBufferDone <First: EmptyBufferDone>");
+        GT_FlagE = 0;   /* 1 = First Buffer,  0 = Not First Buffer  */
     }
+
 #endif
 }
 
-int main(int argc, char* argv[])
-{
+int main(int argc, char* argv[]) {
     OMX_CALLBACKTYPE AmrCaBa = {(void *)EventHandler,
-				(void*)EmptyBufferDone,
-                                (void*)FillBufferDone};
+                                (void*)EmptyBufferDone,
+                                (void*)FillBufferDone
+                               };
     OMX_HANDLETYPE pHandle;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 AppData = WBAMRENC_APP_ID;
@@ -496,1489 +503,1611 @@
     OMX_STATETYPE state;
     OMX_BUFFERHEADERTYPE* pInputBufferHeader[WBAPP_MAX_NUM_OF_BUFS];
     OMX_BUFFERHEADERTYPE* pOutputBufferHeader[WBAPP_MAX_NUM_OF_BUFS];
-    bInvalidState=OMX_FALSE;
+    bInvalidState = OMX_FALSE;
 #ifdef USE_BUFFER
     OMX_U8* pInputBuffer[WBAPP_MAX_NUM_OF_BUFS];
-	OMX_U8* pOutputBuffer[WBAPP_MAX_NUM_OF_BUFS];
-#endif	
-	FILE* fIn = NULL;
-	FILE* fOut = NULL;
+    OMX_U8* pOutputBuffer[WBAPP_MAX_NUM_OF_BUFS];
+#endif
+    FILE* fIn = NULL;
+    FILE* fOut = NULL;
     struct timeval tv;
     int retval, i, j, k, kk, tcID = 0;
     int frmCount = 0;
     int frmCnt = 1;
-	int testcnt = 0;
-	int testcnt1 = 0;
-	int status = 0;
-	int fdmax = 0;
+    int testcnt = 0;
+    int testcnt1 = 0;
+    int status = 0;
+    int fdmax = 0;
 
     int nFrameCount = 1;
     int nFrameLen = 0;
     int nIpBuff = 1;
     int nOutBuff = 1;
-    int numOfInputBuffer=0;
-    int numOfOutputBuffer=0;
-    OMX_INDEXTYPE index;  
-    int NoDataRead=0;
-    OMX_U32	streamId;
+    int numOfInputBuffer = 0;
+    int numOfOutputBuffer = 0;
+    OMX_INDEXTYPE index;
+    int NoDataRead = 0;
+    OMX_U32 streamId;
     TI_OMX_DATAPATH dataPath;
     TI_OMX_DSP_DEFINITION *audioinfo;
-    OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructGain = NULL;    
-int wbamrencfdwrite;
-int wbamrencfdread;
+    OMX_AUDIO_CONFIG_VOLUMETYPE* pCompPrivateStructGain = NULL;
+    int wbamrencfdwrite;
+    int wbamrencfdread;
 
     pthread_mutex_init(&WaitForState_mutex, NULL);
     pthread_cond_init (&WaitForState_threshold, NULL);
     WaitForState_flag = 0;
-    
+
     srand ( time(NULL) );
-	APP_IPRINT("------------------------------------------------------\n");
+    APP_IPRINT("------------------------------------------------------\n");
     APP_IPRINT("This is Main Thread In WBAMR ENCODER Test Application:\n");
     APP_IPRINT("Test Core 1.5 - " __DATE__ ":" __TIME__ "\n");
     APP_IPRINT("------------------------------------------------------\n");
 
 #ifdef OMX_GETTIME
-    APP_IPRINT("Line %d\n",__LINE__);
-      GTeError = OMX_ListCreate(&pListHead);
-        APP_IPRINT("Line %d\n",__LINE__);
-      APP_IPRINT("eError = %d\n",GTeError);
-      GT_START();
-  APP_IPRINT("Line %d\n",__LINE__);
+    APP_IPRINT("Line %d\n", __LINE__);
+    GTeError = OMX_ListCreate(&pListHead);
+    APP_IPRINT("Line %d\n", __LINE__);
+    APP_IPRINT("eError = %d\n", GTeError);
+    GT_START();
+    APP_IPRINT("Line %d\n", __LINE__);
 #endif
 
-	
+
     /* check the input parameters */
-    if((argc < 14) || (argc > 15)) {
-		APP_IPRINT("%d :: Usage: [TestApp] [O/P] [FUNC_ID_X] [FM/DM] [WBAMR/EFR] [BITRATE] [DTXON/OFF] [NONMIME/MIME/IF2] [ACDNON/OFF] [FRAMES] [1 to N] [1 to N] [MFON]\n",__LINE__);
+    if ((argc < 14) || (argc > 15)) {
+        APP_IPRINT("%d :: Usage: [TestApp] [O/P] [FUNC_ID_X] [FM/DM] [WBAMR/EFR] [BITRATE] [DTXON/OFF] [NONMIME/MIME/IF2] [ACDNON/OFF] [FRAMES] [1 to N] [1 to N] [MFON]\n", __LINE__);
         goto EXIT;
     }
 
     /* check to see that the input file exists */
     struct stat sb = {0};
     status = stat(argv[1], &sb);
-    if( status != 0 ) {
+
+    if ( status != 0 ) {
         APP_IPRINT("Cannot find file %s. (%u)\n", argv[1], errno);
         goto EXIT;
     }
 
     /* Open the file of data to be encoded. */
-		fIn = fopen(argv[1], "r");
-		if( fIn == NULL ) {
-			APP_IPRINT("Error:  failed to open the input file %s\n", argv[1]);
-			goto EXIT;
-		}
-	/* Open the file of data to be written. */
-        fOut = fopen(argv[2], "w");
-        if( fOut == NULL ) {
-            APP_IPRINT("Error:  failed to open the output file %s\n", argv[2]);
-            goto EXIT;
+    fIn = fopen(argv[1], "r");
+
+    if ( fIn == NULL ) {
+        APP_IPRINT("Error:  failed to open the input file %s\n", argv[1]);
+        goto EXIT;
     }
-    
-	if(!strcmp(argv[3],"FUNC_ID_1")) {
-		APP_IPRINT("%d :: ### Testing TESTCASE 1 PLAY TILL END ###\n",__LINE__);
-		testcnt = 1;
-		testcnt1 = 1;
-		tcID = 1;
-	} else if(!strcmp(argv[3],"FUNC_ID_2")) {
-		APP_IPRINT("%d :: ### Testing TESTCASE 2 STOP IN THE END ###\n",__LINE__);
-		testcnt = 1;
-		testcnt1 = 1;
-		tcID = 2;
-	} else if(!strcmp(argv[3],"FUNC_ID_3")) {
-		APP_IPRINT("%d :: ### Testing TESTCASE 3 PAUSE - RESUME IN BETWEEN ###\n",__LINE__);
-		testcnt = 1;
-		testcnt1 = 1;
-		tcID = 3;
-	} else if(!strcmp(argv[3],"FUNC_ID_4")) {
-		APP_IPRINT("%d :: ### Testing TESTCASE 4 STOP IN BETWEEN ###\n",__LINE__);
-		testcnt = 2;
-		testcnt1 = 1;
-		tcID = 4;
-		APP_IPRINT("######## testcnt = %d #########\n",testcnt);
-    } else if(!strcmp(argv[3],"FUNC_ID_5")){
-        APP_IPRINT("%d :: ### Testing TESTCASE 5 ENCODE without Deleting component Here ###\n",__LINE__);
-        if (argc == 15)
-        {
+
+    /* Open the file of data to be written. */
+    fOut = fopen(argv[2], "w");
+
+    if ( fOut == NULL ) {
+        APP_IPRINT("Error:  failed to open the output file %s\n", argv[2]);
+        goto EXIT;
+    }
+
+    if (!strcmp(argv[3], "FUNC_ID_1")) {
+        APP_IPRINT("%d :: ### Testing TESTCASE 1 PLAY TILL END ###\n", __LINE__);
+        testcnt = 1;
+        testcnt1 = 1;
+        tcID = 1;
+    } else if (!strcmp(argv[3], "FUNC_ID_2")) {
+        APP_IPRINT("%d :: ### Testing TESTCASE 2 STOP IN THE END ###\n", __LINE__);
+        testcnt = 1;
+        testcnt1 = 1;
+        tcID = 2;
+    } else if (!strcmp(argv[3], "FUNC_ID_3")) {
+        APP_IPRINT("%d :: ### Testing TESTCASE 3 PAUSE - RESUME IN BETWEEN ###\n", __LINE__);
+        testcnt = 1;
+        testcnt1 = 1;
+        tcID = 3;
+    } else if (!strcmp(argv[3], "FUNC_ID_4")) {
+        APP_IPRINT("%d :: ### Testing TESTCASE 4 STOP IN BETWEEN ###\n", __LINE__);
+        testcnt = 2;
+        testcnt1 = 1;
+        tcID = 4;
+        APP_IPRINT("######## testcnt = %d #########\n", testcnt);
+    } else if (!strcmp(argv[3], "FUNC_ID_5")) {
+        APP_IPRINT("%d :: ### Testing TESTCASE 5 ENCODE without Deleting component Here ###\n", __LINE__);
+
+        if (argc == 15) {
             testcnt = atoi(argv[14]);
-        }
-        else
-        {
+        } else {
             testcnt = 20;  /*20 cycles by default*/
         }
+
         testcnt1 = 1;
         tcID = 5;
-    } else if(!strcmp(argv[3],"FUNC_ID_6")) {
-        APP_IPRINT("%d :: ### Testing TESTCASE 6 ENCODE with Deleting component Here ###\n",__LINE__);
-        if (argc == 15)
-        {
+    } else if (!strcmp(argv[3], "FUNC_ID_6")) {
+        APP_IPRINT("%d :: ### Testing TESTCASE 6 ENCODE with Deleting component Here ###\n", __LINE__);
+
+        if (argc == 15) {
             testcnt1 = atoi(argv[14]);
-        }
-        else
-        {
+        } else {
             testcnt1 = 20;  /*20 cycles by default*/
         }
+
         testcnt = 1;
         tcID = 6;
-    } else if(!strcmp(argv[3],"FUNC_ID_7")) {
-        APP_IPRINT("%d :: ### Testing TESTCASE 7 ENCODE with Volume Control ###\n",__LINE__);
+    } else if (!strcmp(argv[3], "FUNC_ID_7")) {
+        APP_IPRINT("%d :: ### Testing TESTCASE 7 ENCODE with Volume Control ###\n", __LINE__);
         testcnt = 1;
         testcnt1 = 1;
         tcID = 7;
-    } else if(!strcmp(argv[3],"FUNC_ID_8")) {
-        APP_IPRINT("%d :: ### Testing PLAY TILL END  WITH TWO FRAMES BY BUFFER###\n",__LINE__);
+    } else if (!strcmp(argv[3], "FUNC_ID_8")) {
+        APP_IPRINT("%d :: ### Testing PLAY TILL END  WITH TWO FRAMES BY BUFFER###\n", __LINE__);
         testcnt = 1;
-        testcnt1 =1;
+        testcnt1 = 1;
         tcID = 1;
         mframe = 1;
     } else {
-        APP_IPRINT("%d :: ### Invalid test case###\n",__LINE__);
+        APP_IPRINT("%d :: ### Invalid test case###\n", __LINE__);
         goto EXIT;
     }
-	for(j = 0; j < testcnt1; j++) {
 
-#ifdef DSP_RENDERING_ON 
+    for (j = 0; j < testcnt1; j++) {
 
-		if((wbamrencfdwrite=open(FIFO1,O_WRONLY))<0) {
+#ifdef DSP_RENDERING_ON
+
+        if ((wbamrencfdwrite = open(FIFO1, O_WRONLY)) < 0) {
             APP_IPRINT("[AMRTEST] - failure to open WRITE pipe\n");
-        }
-        else {
+        } else {
             APP_IPRINT("[AMRTEST] - opened WRITE pipe\n");
         }
 
-        if((wbamrencfdread=open(FIFO2,O_RDONLY))<0) {
+        if ((wbamrencfdread = open(FIFO2, O_RDONLY)) < 0) {
             APP_IPRINT("[AMRTEST] - failure to open READ pipe\n");
             goto EXIT;
-        }
-        else {
+        } else {
             APP_IPRINT("[AMRTEST] - opened READ pipe\n");
         }
 
 #endif
 
-    /* Create a pipe used to queue data from the callback. */
-    retval = pipe(IpBuf_Pipe);
-    if( retval != 0) {
-        APP_DPRINT("Error:Fill Data Pipe failed to open\n");
-        goto EXIT;
-    }
+        /* Create a pipe used to queue data from the callback. */
+        retval = pipe(IpBuf_Pipe);
 
-    retval = pipe(OpBuf_Pipe);
-    if( retval != 0) {
-        APP_DPRINT("Error:Empty Data Pipe failed to open\n");
-        goto EXIT;
-    }
+        if ( retval != 0) {
+            APP_DPRINT("Error:Fill Data Pipe failed to open\n");
+            goto EXIT;
+        }
 
-	retval = pipe(Event_Pipe);
-    if( retval != 0) {
-		    APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
-		    goto EXIT;
-	}
-	
-    /* save off the "max" of the handles for the selct statement */
-    fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]);
-	fdmax = maxint(fdmax,Event_Pipe[0]);
-	
-    eError = TIOMX_Init();
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT("%d :: Error returned by OMX_Init()\n",__LINE__);
-        goto EXIT;
-    }
+        retval = pipe(OpBuf_Pipe);
 
-	TI_OMX_STREAM_INFO *streaminfo;
-	
-    OMX_WBAPP_MALLOC_STRUCT(streaminfo, TI_OMX_STREAM_INFO);
-    OMX_WBAPP_MALLOC_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
-	OMX_WBAPP_INIT_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
+        if ( retval != 0) {
+            APP_DPRINT("Error:Empty Data Pipe failed to open\n");
+            goto EXIT;
+        }
 
-    ArrayOfPointers[0]=(TI_OMX_STREAM_INFO*)streaminfo;
-    ArrayOfPointers[1]=(TI_OMX_DSP_DEFINITION*)audioinfo;
+        retval = pipe(Event_Pipe);
 
-	if(j > 0) {
-		APP_IPRINT ("%d :: Encoding the file for %d Time in TESTCASE 6\n",__LINE__,j+1);
-		fIn = fopen(argv[1], "r");
-		if( fIn == NULL ) {
-			fprintf(stderr, "Error:  failed to open the file %s for read only access\n",argv[1]);
-			goto EXIT;
-		}
+        if ( retval != 0) {
+            APP_DPRINT( "Error:Empty Data Pipe failed to open\n");
+            goto EXIT;
+        }
 
-		fOut = fopen("TC6_WbAmr1.amr", "w");
-		if( fOut == NULL ) {
-			fprintf(stderr, "Error:  failed to create the output file %s\n",argv[2]);
-			goto EXIT;
-		}
-	 }
+        /* save off the "max" of the handles for the selct statement */
+        fdmax = maxint(IpBuf_Pipe[0], OpBuf_Pipe[0]);
+        fdmax = maxint(fdmax, Event_Pipe[0]);
 
-    /* Load the WBAMR Encoder Component */
+        eError = TIOMX_Init();
+
+        if (eError != OMX_ErrorNone) {
+            APP_DPRINT("%d :: Error returned by OMX_Init()\n", __LINE__);
+            goto EXIT;
+        }
+
+        TI_OMX_STREAM_INFO *streaminfo;
+
+        OMX_WBAPP_MALLOC_STRUCT(streaminfo, TI_OMX_STREAM_INFO);
+        OMX_WBAPP_MALLOC_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
+        OMX_WBAPP_INIT_STRUCT(audioinfo, TI_OMX_DSP_DEFINITION);
+
+        ArrayOfPointers[0] = (TI_OMX_STREAM_INFO*)streaminfo;
+        ArrayOfPointers[1] = (TI_OMX_DSP_DEFINITION*)audioinfo;
+
+        if (j > 0) {
+            APP_IPRINT ("%d :: Encoding the file for %d Time in TESTCASE 6\n", __LINE__, j + 1);
+            fIn = fopen(argv[1], "r");
+
+            if ( fIn == NULL ) {
+                fprintf(stderr, "Error:  failed to open the file %s for read only access\n", argv[1]);
+                goto EXIT;
+            }
+
+            fOut = fopen("TC6_WbAmr1.amr", "w");
+
+            if ( fOut == NULL ) {
+                fprintf(stderr, "Error:  failed to create the output file %s\n", argv[2]);
+                goto EXIT;
+            }
+        }
+
+        /* Load the WBAMR Encoder Component */
 
 #ifdef OMX_GETTIME
-	GT_START();
-    eError = OMX_GetHandle(&pHandle, strWbAmrEncoder, &AppData, &AmrCaBa);
-	GT_END("Call to GetHandle");
-#else 
-    eError = TIOMX_GetHandle(&pHandle, strWbAmrEncoder, &AppData, &AmrCaBa);
+        GT_START();
+        eError = OMX_GetHandle(&pHandle, strWbAmrEncoder, &AppData, &AmrCaBa);
+        GT_END("Call to GetHandle");
+#else
+        eError = TIOMX_GetHandle(&pHandle, strWbAmrEncoder, &AppData, &AmrCaBa);
 #endif
 
-    if((eError != OMX_ErrorNone) || (pHandle == NULL)) {
-        APP_DPRINT("Error in Get Handle function\n");
-        goto EXIT;
-    }
+        if ((eError != OMX_ErrorNone) || (pHandle == NULL)) {
+            APP_DPRINT("Error in Get Handle function\n");
+            goto EXIT;
+        }
 
-	/* Setting No.Of Input and Output Buffers for the Component */
-	numOfInputBuffer = atoi(argv[11]);
-	APP_IPRINT("\n%d :: App: audioinfo->nIpBufs = %d \n",__LINE__,numOfInputBuffer);
+        /* Setting No.Of Input and Output Buffers for the Component */
+        numOfInputBuffer = atoi(argv[11]);
+        APP_IPRINT("\n%d :: App: audioinfo->nIpBufs = %d \n", __LINE__, numOfInputBuffer);
 
-	numOfOutputBuffer = atoi(argv[12]);
-	APP_IPRINT("\n%d :: App: audioinfo->numOfOutputBuffer = %d \n",__LINE__,numOfOutputBuffer);
+        numOfOutputBuffer = atoi(argv[12]);
+        APP_IPRINT("\n%d :: App: audioinfo->numOfOutputBuffer = %d \n", __LINE__, numOfOutputBuffer);
 
 
-    OMX_WBAPP_MALLOC_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
-	OMX_WBAPP_CONF_INIT_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
+        OMX_WBAPP_MALLOC_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
+        OMX_WBAPP_CONF_INIT_STRUCT(pCompPrivateStruct, OMX_PARAM_PORTDEFINITIONTYPE);
 
-    ArrayOfPointers[2]=(OMX_PARAM_PORTDEFINITIONTYPE*)pCompPrivateStruct;
-    APP_DPRINT("%d :: Setting input port config\n",__LINE__);
-    pCompPrivateStruct->nSize 							   = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
-    pCompPrivateStruct->nVersion.s.nVersionMajor           = 0xF1;
-    pCompPrivateStruct->nVersion.s.nVersionMinor 		   = 0xF2;
-    pCompPrivateStruct->nPortIndex                         = WBAPP_INPUT_PORT;
-    pCompPrivateStruct->eDir                               = OMX_DirInput;
-    pCompPrivateStruct->nBufferCountActual                 = numOfInputBuffer;
-    pCompPrivateStruct->nBufferCountMin                    = numOfInputBuffer;
-    pCompPrivateStruct->nBufferSize                        = WBAPP_INPUT_BUFFER_SIZE;
-    pCompPrivateStruct->bEnabled                           = OMX_TRUE;
-    pCompPrivateStruct->bPopulated                         = OMX_FALSE;
-    pCompPrivateStruct->eDomain                            = OMX_PortDomainAudio;
-	pCompPrivateStruct->format.audio.eEncoding             = OMX_AUDIO_CodingAMR;
-	pCompPrivateStruct->format.audio.cMIMEType             = NULL;
-	pCompPrivateStruct->format.audio.pNativeRender         = NULL;
-	pCompPrivateStruct->format.audio.bFlagErrorConcealment = OMX_FALSE;    /*Send input port config*/
-	APP_DPRINT("%d :: Setting input port config\n",__LINE__);
-	if(!(strcmp(argv[8],"NONMIME"))) {
-		pCompPrivateStruct->format.audio.cMIMEType = "NONMIME";
-    	APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
-    											__LINE__,pCompPrivateStruct->format.audio.cMIMEType);
-	} else if(!(strcmp(argv[8],"MIME"))) {
-    	pCompPrivateStruct->format.audio.cMIMEType = "MIME";
-    	APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
-    											__LINE__,pCompPrivateStruct->format.audio.cMIMEType);
-	} else if(!(strcmp(argv[8],"IF2"))) {
-		pCompPrivateStruct->format.audio.cMIMEType = "IF2";
-		APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
-												__LINE__,pCompPrivateStruct->format.audio.cMIMEType);
-		
-	} else {
-		eError = OMX_ErrorBadParameter;
-		APP_IPRINT("\n%d :: App: audioinfo->amrMIMEMode Sending Bad Parameter\n",__LINE__);
-		APP_IPRINT("%d :: App: Should Be One of these Modes MIME, NONMIME, IF2\n",__LINE__);
-		goto EXIT;
-	}
+        ArrayOfPointers[2] = (OMX_PARAM_PORTDEFINITIONTYPE*)pCompPrivateStruct;
+        APP_DPRINT("%d :: Setting input port config\n", __LINE__);
+        pCompPrivateStruct->nSize                              = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
+        pCompPrivateStruct->nVersion.s.nVersionMajor           = 0xF1;
+        pCompPrivateStruct->nVersion.s.nVersionMinor           = 0xF2;
+        pCompPrivateStruct->nPortIndex                         = WBAPP_INPUT_PORT;
+        pCompPrivateStruct->eDir                               = OMX_DirInput;
+        pCompPrivateStruct->nBufferCountActual                 = numOfInputBuffer;
+        pCompPrivateStruct->nBufferCountMin                    = numOfInputBuffer;
+        pCompPrivateStruct->nBufferSize                        = WBAPP_INPUT_BUFFER_SIZE;
+        pCompPrivateStruct->bEnabled                           = OMX_TRUE;
+        pCompPrivateStruct->bPopulated                         = OMX_FALSE;
+        pCompPrivateStruct->eDomain                            = OMX_PortDomainAudio;
+        pCompPrivateStruct->format.audio.eEncoding             = OMX_AUDIO_CodingAMR;
+        pCompPrivateStruct->format.audio.cMIMEType             = NULL;
+        pCompPrivateStruct->format.audio.pNativeRender         = NULL;
+        pCompPrivateStruct->format.audio.bFlagErrorConcealment = OMX_FALSE;    /*Send input port config*/
+        APP_DPRINT("%d :: Setting input port config\n", __LINE__);
+
+        if (!(strcmp(argv[8], "NONMIME"))) {
+            pCompPrivateStruct->format.audio.cMIMEType = "NONMIME";
+            APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
+                       __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
+        } else if (!(strcmp(argv[8], "MIME"))) {
+            pCompPrivateStruct->format.audio.cMIMEType = "MIME";
+            APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
+                       __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
+        } else if (!(strcmp(argv[8], "IF2"))) {
+            pCompPrivateStruct->format.audio.cMIMEType = "IF2";
+            APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
+                       __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
+
+        } else {
+            eError = OMX_ErrorBadParameter;
+            APP_IPRINT("\n%d :: App: audioinfo->amrMIMEMode Sending Bad Parameter\n", __LINE__);
+            APP_IPRINT("%d :: App: Should Be One of these Modes MIME, NONMIME, IF2\n", __LINE__);
+            goto EXIT;
+        }
 
 
-	if(!(strcmp(argv[4],"FM"))) {
-		audioinfo->dasfMode = 0;
-		DasfMode = 0;
-    	APP_DPRINT("\n%d :: App: audioinfo->dasfMode = %x \n",__LINE__,audioinfo->dasfMode);
-	} else if(!(strcmp(argv[4],"DM"))){
-		audioinfo->dasfMode = 1;
-		DasfMode =1;
-    	APP_DPRINT("\n%d :: App: audioinfo->dasfMode = %x \n",__LINE__,audioinfo->dasfMode);
-		APP_DPRINT("%d :: WBAMR ENCODER RUNNING UNDER DASF MODE \n",__LINE__);
-		pCompPrivateStruct->nBufferCountActual = 0;
-	}
-    else {
-		eError = OMX_ErrorBadParameter;
-		APP_IPRINT("\n%d :: App: audioinfo->dasfMode Sending Bad Parameter\n",__LINE__);
-		APP_IPRINT("%d :: App: Should Be One of these Modes FM, DM\n",__LINE__);
-		goto EXIT;
-	}
+        if (!(strcmp(argv[4], "FM"))) {
+            audioinfo->dasfMode = 0;
+            DasfMode = 0;
+            APP_DPRINT("\n%d :: App: audioinfo->dasfMode = %x \n", __LINE__, audioinfo->dasfMode);
+        } else if (!(strcmp(argv[4], "DM"))) {
+            audioinfo->dasfMode = 1;
+            DasfMode = 1;
+            APP_DPRINT("\n%d :: App: audioinfo->dasfMode = %x \n", __LINE__, audioinfo->dasfMode);
+            APP_DPRINT("%d :: WBAMR ENCODER RUNNING UNDER DASF MODE \n", __LINE__);
+            pCompPrivateStruct->nBufferCountActual = 0;
+        } else {
+            eError = OMX_ErrorBadParameter;
+            APP_IPRINT("\n%d :: App: audioinfo->dasfMode Sending Bad Parameter\n", __LINE__);
+            APP_IPRINT("%d :: App: Should Be One of these Modes FM, DM\n", __LINE__);
+            goto EXIT;
+        }
 
 
-	if(audioinfo->dasfMode == 0) {
-		if((atoi(argv[10])) != 0) {
-			eError = OMX_ErrorBadParameter;
-			APP_IPRINT("\n%d :: App: No. of Frames Sending Bad Parameter\n",__LINE__);
-			APP_IPRINT("%d :: App: For FILE mode argv[10] Should Be --> 0\n",__LINE__);
-			APP_IPRINT("%d :: App: For DASF mode argv[10] Should be greater than zero depends on number of frames user want to encode\n",__LINE__);
-			goto EXIT;
-		}
-	} else {
-		if((atoi(argv[10])) == 0) {
-			eError = OMX_ErrorBadParameter;
-			APP_IPRINT("\n%d :: App: No. of Frames Sending Bad Parameter\n",__LINE__);
-			APP_IPRINT("%d :: App: For DASF mode argv[10] Should be greater than zero depends on number of frames user want to encode\n",__LINE__);
-			APP_IPRINT("%d :: App: For FILE mode argv[10] Should Be --> 0\n",__LINE__);
-			goto EXIT;
-		}
-	}
+        if (audioinfo->dasfMode == 0) {
+            if ((atoi(argv[10])) != 0) {
+                eError = OMX_ErrorBadParameter;
+                APP_IPRINT("\n%d :: App: No. of Frames Sending Bad Parameter\n", __LINE__);
+                APP_IPRINT("%d :: App: For FILE mode argv[10] Should Be --> 0\n", __LINE__);
+                APP_IPRINT("%d :: App: For DASF mode argv[10] Should be greater than zero depends on number of frames user want to encode\n", __LINE__);
+                goto EXIT;
+            }
+        } else {
+            if ((atoi(argv[10])) == 0) {
+                eError = OMX_ErrorBadParameter;
+                APP_IPRINT("\n%d :: App: No. of Frames Sending Bad Parameter\n", __LINE__);
+                APP_IPRINT("%d :: App: For DASF mode argv[10] Should be greater than zero depends on number of frames user want to encode\n", __LINE__);
+                APP_IPRINT("%d :: App: For FILE mode argv[10] Should Be --> 0\n", __LINE__);
+                goto EXIT;
+            }
+        }
 
-	if(!(strcmp(argv[9],"ACDNOFF"))) {
-		 audioinfo->acousticMode = 0;
-    	APP_DPRINT("\n%d :: App: audioinfo->acousticMode = %x \n",__LINE__,audioinfo->acousticMode);
-	} else if(!(strcmp(argv[9],"ACDNON"))) {
-		audioinfo->acousticMode = 1;
-		APP_DPRINT("\n%d :: App: audioinfo->acousticMode = %x \n",__LINE__,audioinfo->acousticMode);
-	} else {
-		eError = OMX_ErrorBadParameter;
-		APP_IPRINT("\n%d :: App: audioinfo->acousticMode Sending Bad Parameter\n",__LINE__);
-		APP_IPRINT("%d :: App: Should Be One of these Modes ACDNON, ACDNOFF\n",__LINE__);
-		goto EXIT;
-	}  
+        if (!(strcmp(argv[9], "ACDNOFF"))) {
+            audioinfo->acousticMode = 0;
+            APP_DPRINT("\n%d :: App: audioinfo->acousticMode = %x \n", __LINE__, audioinfo->acousticMode);
+        } else if (!(strcmp(argv[9], "ACDNON"))) {
+            audioinfo->acousticMode = 1;
+            APP_DPRINT("\n%d :: App: audioinfo->acousticMode = %x \n", __LINE__, audioinfo->acousticMode);
+        } else {
+            eError = OMX_ErrorBadParameter;
+            APP_IPRINT("\n%d :: App: audioinfo->acousticMode Sending Bad Parameter\n", __LINE__);
+            APP_IPRINT("%d :: App: Should Be One of these Modes ACDNON, ACDNOFF\n", __LINE__);
+            goto EXIT;
+        }
+
 #ifdef OMX_GETTIME
-	GT_START();
-	eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
-	GT_END("Set Parameter Test-SetParameter");
+        GT_START();
+        eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
+        GT_END("Set Parameter Test-SetParameter");
 #else
-    eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
+        eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
 #endif
-    if (eError != OMX_ErrorNone) {
-        eError = OMX_ErrorBadParameter;
-        APP_DPRINT("%d :: OMX_ErrorBadParameter\n",__LINE__);
-        goto EXIT;
-    }
-    APP_MEMPRINT("%d :: Setting output port config\n",__LINE__);
-    pCompPrivateStruct->nSize 							   = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
-    pCompPrivateStruct->nVersion.s.nVersionMajor           = 0xF1;
-    pCompPrivateStruct->nVersion.s.nVersionMinor 		   = 0xF2;
-    pCompPrivateStruct->nPortIndex                         = WBAPP_OUTPUT_PORT;
-    pCompPrivateStruct->eDir                               = OMX_DirOutput;
-    pCompPrivateStruct->nBufferCountActual                 = numOfOutputBuffer;
-    pCompPrivateStruct->nBufferCountMin                    = numOfOutputBuffer;
-    pCompPrivateStruct->nBufferSize                        = WBAPP_OUTPUT_BUFFER_SIZE;
-    pCompPrivateStruct->bEnabled                           = OMX_TRUE;
-    pCompPrivateStruct->bPopulated                         = OMX_FALSE;
-    pCompPrivateStruct->eDomain                            = OMX_PortDomainAudio;
-	pCompPrivateStruct->format.audio.eEncoding             = OMX_AUDIO_CodingAMR;
-	pCompPrivateStruct->format.audio.cMIMEType             = NULL;
-	pCompPrivateStruct->format.audio.pNativeRender         = NULL;
-	pCompPrivateStruct->format.audio.bFlagErrorConcealment = OMX_FALSE;    /*Send input port config*/
 
-    OMX_WBAPP_MALLOC_STRUCT(pAmrParam, OMX_AUDIO_PARAM_AMRTYPE);
-	OMX_WBAPP_CONF_INIT_STRUCT(pAmrParam, OMX_AUDIO_PARAM_AMRTYPE);
-    ArrayOfPointers[3] = (OMX_AUDIO_PARAM_AMRTYPE *)pAmrParam;
+        if (eError != OMX_ErrorNone) {
+            eError = OMX_ErrorBadParameter;
+            APP_DPRINT("%d :: OMX_ErrorBadParameter\n", __LINE__);
+            goto EXIT;
+        }
 
-	if(!(strcmp(argv[8],"NONMIME"))) {
-		pCompPrivateStruct->format.audio.cMIMEType = "NONMIME";
-		pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatConformance;
-    	APP_DPRINT("\n%d :: App: pCompPrivateStruct->cMIMEType --> %s \n",__LINE__,argv[3]);
-		/**< Codec Configuring to WBAMR Mode Buffer Size to 116 */
-    	pCompPrivateStruct->nBufferSize = WBAPP_OUTPUT_BUFFER_SIZE;
-	}
-    if(!(strcmp(argv[8],"MIME"))) {
-    	pCompPrivateStruct->format.audio.cMIMEType = "MIME";
-		pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
-    	APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
-    											__LINE__,pCompPrivateStruct->format.audio.cMIMEType);
-		/**< Codec Configuring to MIME Mode Buffer Size to 61 */
-    	pCompPrivateStruct->nBufferSize = WBAPP_OUTPUT_BUFFER_SIZE_MIME;
-		} 
-	else if(!(strcmp(argv[8],"IF2"))) {
-		pCompPrivateStruct->format.audio.cMIMEType = "IF2";
-		pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatIF2;
-		APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
-												__LINE__,pCompPrivateStruct->format.audio.cMIMEType);		
-	}
-	
-    APP_DPRINT("\n%d :: App: pCompPrivateStruct->nBufferSize --> %ld \n",__LINE__, pCompPrivateStruct->nBufferSize);
+        APP_MEMPRINT("%d :: Setting output port config\n", __LINE__);
+        pCompPrivateStruct->nSize                              = sizeof (OMX_PARAM_PORTDEFINITIONTYPE);
+        pCompPrivateStruct->nVersion.s.nVersionMajor           = 0xF1;
+        pCompPrivateStruct->nVersion.s.nVersionMinor           = 0xF2;
+        pCompPrivateStruct->nPortIndex                         = WBAPP_OUTPUT_PORT;
+        pCompPrivateStruct->eDir                               = OMX_DirOutput;
+        pCompPrivateStruct->nBufferCountActual                 = numOfOutputBuffer;
+        pCompPrivateStruct->nBufferCountMin                    = numOfOutputBuffer;
+        pCompPrivateStruct->nBufferSize                        = WBAPP_OUTPUT_BUFFER_SIZE;
+        pCompPrivateStruct->bEnabled                           = OMX_TRUE;
+        pCompPrivateStruct->bPopulated                         = OMX_FALSE;
+        pCompPrivateStruct->eDomain                            = OMX_PortDomainAudio;
+        pCompPrivateStruct->format.audio.eEncoding             = OMX_AUDIO_CodingAMR;
+        pCompPrivateStruct->format.audio.cMIMEType             = NULL;
+        pCompPrivateStruct->format.audio.pNativeRender         = NULL;
+        pCompPrivateStruct->format.audio.bFlagErrorConcealment = OMX_FALSE;    /*Send input port config*/
+
+        OMX_WBAPP_MALLOC_STRUCT(pAmrParam, OMX_AUDIO_PARAM_AMRTYPE);
+        OMX_WBAPP_CONF_INIT_STRUCT(pAmrParam, OMX_AUDIO_PARAM_AMRTYPE);
+        ArrayOfPointers[3] = (OMX_AUDIO_PARAM_AMRTYPE *)pAmrParam;
+
+        if (!(strcmp(argv[8], "NONMIME"))) {
+            pCompPrivateStruct->format.audio.cMIMEType = "NONMIME";
+            pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatConformance;
+            APP_DPRINT("\n%d :: App: pCompPrivateStruct->cMIMEType --> %s \n", __LINE__, argv[3]);
+            /**< Codec Configuring to WBAMR Mode Buffer Size to 116 */
+            pCompPrivateStruct->nBufferSize = WBAPP_OUTPUT_BUFFER_SIZE;
+        }
+
+        if (!(strcmp(argv[8], "MIME"))) {
+            pCompPrivateStruct->format.audio.cMIMEType = "MIME";
+            pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatFSF;
+            APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
+                       __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
+            /**< Codec Configuring to MIME Mode Buffer Size to 61 */
+            pCompPrivateStruct->nBufferSize = WBAPP_OUTPUT_BUFFER_SIZE_MIME;
+        } else if (!(strcmp(argv[8], "IF2"))) {
+            pCompPrivateStruct->format.audio.cMIMEType = "IF2";
+            pAmrParam->eAMRFrameFormat = OMX_AUDIO_AMRFrameFormatIF2;
+            APP_DPRINT("\n%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",
+                       __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
+        }
+
+        APP_DPRINT("\n%d :: App: pCompPrivateStruct->nBufferSize --> %ld \n", __LINE__, pCompPrivateStruct->nBufferSize);
 #ifdef OMX_GETTIME
-	GT_START();
-    eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
-	GT_END("Set Parameter Test-SetParameter");
+        GT_START();
+        eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
+        GT_END("Set Parameter Test-SetParameter");
 #else
-    eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
-#endif	
-    if (eError != OMX_ErrorNone) {
-        eError = OMX_ErrorBadParameter;
-        APP_DPRINT("%d :: OMX_ErrorBadParameter\n",__LINE__);
-        goto EXIT;
-    }
-
-    pAmrParam->nSize                    = sizeof(OMX_AUDIO_PARAM_AMRTYPE);
-    pAmrParam->nVersion.s.nVersionMajor = 0xF1;
-    pAmrParam->nVersion.s.nVersionMinor = 0xF2;
-    pAmrParam->nPortIndex               = WBAPP_INPUT_PORT;
-    pAmrParam->nChannels                = WBAPP_NUM_OF_CHANNELS;
-#ifdef OMX_GETTIME
-	GT_START();
-    eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
-	GT_END("Set Parameter Test-SetParameter");
-#else
-    eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
+        eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pCompPrivateStruct);
 #endif
-    if (eError != OMX_ErrorNone) {
-        eError = OMX_ErrorBadParameter;
-		APP_DPRINT("%d :: OMX_ErrorBadParameter\n",__LINE__);
-        goto EXIT;
-    }
-    pAmrParam->nSize                    = sizeof(OMX_AUDIO_PARAM_AMRTYPE);
-    pAmrParam->nVersion.s.nVersionMajor = 0xF1;
-    pAmrParam->nVersion.s.nVersionMinor = 0xF2;
-    pAmrParam->nPortIndex               = WBAPP_OUTPUT_PORT;
-    pAmrParam->nChannels                = WBAPP_NUM_OF_CHANNELS;
-	pAmrParam->eAMRBandMode 			= OMX_AUDIO_AMRBandModeUnused;
-	pAmrParam->eAMRDTXMode				= OMX_AUDIO_AMRDTXModeOff;
-	if(!(strcmp(argv[6],"BR2385"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB8;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else if(!(strcmp(argv[6],"BR2305"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB7;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else if(!(strcmp(argv[6],"BR1985"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB6;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else if(!(strcmp(argv[6],"BR1825"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB5;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else if(!(strcmp(argv[6],"BR1585"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB4;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else if(!(strcmp(argv[6],"BR1425"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB3;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else if(!(strcmp(argv[6],"BR1265"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB2;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else if(!(strcmp(argv[6],"BR885"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB1;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else if(!(strcmp(argv[6],"BR660"))) {
-		pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n",__LINE__,pAmrParam->eAMRBandMode);
-	} else {
-		eError = OMX_ErrorBadParameter;
-		APP_IPRINT("\n%d :: App: pAmrParam->eAMRBandMode Sending Bad Parameter\n",__LINE__);
-		APP_IPRINT("%d :: App: Should Be One of these BitRates BR2385, BR2305, BR1985, BR1825, BR1585, BR1425, BR1265, BR885, BR660\n",__LINE__);
-		goto EXIT;
-	}
 
-    APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode --> %d \n",__LINE__,pAmrParam->eAMRBandMode);
+        if (eError != OMX_ErrorNone) {
+            eError = OMX_ErrorBadParameter;
+            APP_DPRINT("%d :: OMX_ErrorBadParameter\n", __LINE__);
+            goto EXIT;
+        }
 
-    if(!(strcmp(argv[7],"DTXON"))) {
-    	/**< AMR Discontinuous Transmission Mode is enabled  */
-    	pAmrParam->eAMRDTXMode = OMX_AUDIO_AMRDTXModeOnVAD1;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRDTXMode --> %s \n",__LINE__,argv[7]);
-	} else if(!(strcmp(argv[7],"DTXOFF"))) {
-		/**< AMR Discontinuous Transmission Mode is disabled */
-		pAmrParam->eAMRDTXMode = OMX_AUDIO_AMRDTXModeOff;
-    	APP_DPRINT("\n%d :: App: pAmrParam->eAMRDTXMode --> %s \n",__LINE__,argv[7]);
-	} else {
-		eError = OMX_ErrorBadParameter;
-		APP_IPRINT("\n%d :: App: pAmrParam->eAMRDTXMode Sending Bad Parameter\n",__LINE__);
-		APP_IPRINT("%d :: App: Should Be One of these Modes DTXON, DTXOFF\n",__LINE__);
-		goto EXIT;
-	}
+        pAmrParam->nSize                    = sizeof(OMX_AUDIO_PARAM_AMRTYPE);
+        pAmrParam->nVersion.s.nVersionMajor = 0xF1;
+        pAmrParam->nVersion.s.nVersionMinor = 0xF2;
+        pAmrParam->nPortIndex               = WBAPP_INPUT_PORT;
+        pAmrParam->nChannels                = WBAPP_NUM_OF_CHANNELS;
 #ifdef OMX_GETTIME
-	GT_START();
-    eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
-	GT_END("Set Parameter Test-SetParameter");
+        GT_START();
+        eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
+        GT_END("Set Parameter Test-SetParameter");
 #else
-    eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
-#endif	
-    if (eError != OMX_ErrorNone) {
-        eError = OMX_ErrorBadParameter;
-        APP_DPRINT("%d :: OMX_ErrorBadParameter\n",__LINE__);
-        goto EXIT;
-    }
+        eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
+#endif
+
+        if (eError != OMX_ErrorNone) {
+            eError = OMX_ErrorBadParameter;
+            APP_DPRINT("%d :: OMX_ErrorBadParameter\n", __LINE__);
+            goto EXIT;
+        }
+
+        pAmrParam->nSize                    = sizeof(OMX_AUDIO_PARAM_AMRTYPE);
+        pAmrParam->nVersion.s.nVersionMajor = 0xF1;
+        pAmrParam->nVersion.s.nVersionMinor = 0xF2;
+        pAmrParam->nPortIndex               = WBAPP_OUTPUT_PORT;
+        pAmrParam->nChannels                = WBAPP_NUM_OF_CHANNELS;
+        pAmrParam->eAMRBandMode             = OMX_AUDIO_AMRBandModeUnused;
+        pAmrParam->eAMRDTXMode              = OMX_AUDIO_AMRDTXModeOff;
+
+        if (!(strcmp(argv[6], "BR2385"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB8;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else if (!(strcmp(argv[6], "BR2305"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB7;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else if (!(strcmp(argv[6], "BR1985"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB6;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else if (!(strcmp(argv[6], "BR1825"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB5;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else if (!(strcmp(argv[6], "BR1585"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB4;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else if (!(strcmp(argv[6], "BR1425"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB3;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else if (!(strcmp(argv[6], "BR1265"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB2;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else if (!(strcmp(argv[6], "BR885"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB1;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else if (!(strcmp(argv[6], "BR660"))) {
+            pAmrParam->eAMRBandMode = OMX_AUDIO_AMRBandModeWB0;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode = %d \n", __LINE__, pAmrParam->eAMRBandMode);
+        } else {
+            eError = OMX_ErrorBadParameter;
+            APP_IPRINT("\n%d :: App: pAmrParam->eAMRBandMode Sending Bad Parameter\n", __LINE__);
+            APP_IPRINT("%d :: App: Should Be One of these BitRates BR2385, BR2305, BR1985, BR1825, BR1585, BR1425, BR1265, BR885, BR660\n", __LINE__);
+            goto EXIT;
+        }
+
+        APP_DPRINT("\n%d :: App: pAmrParam->eAMRBandMode --> %d \n", __LINE__, pAmrParam->eAMRBandMode);
+
+        if (!(strcmp(argv[7], "DTXON"))) {
+            /**< AMR Discontinuous Transmission Mode is enabled  */
+            pAmrParam->eAMRDTXMode = OMX_AUDIO_AMRDTXModeOnVAD1;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRDTXMode --> %s \n", __LINE__, argv[7]);
+        } else if (!(strcmp(argv[7], "DTXOFF"))) {
+            /**< AMR Discontinuous Transmission Mode is disabled */
+            pAmrParam->eAMRDTXMode = OMX_AUDIO_AMRDTXModeOff;
+            APP_DPRINT("\n%d :: App: pAmrParam->eAMRDTXMode --> %s \n", __LINE__, argv[7]);
+        } else {
+            eError = OMX_ErrorBadParameter;
+            APP_IPRINT("\n%d :: App: pAmrParam->eAMRDTXMode Sending Bad Parameter\n", __LINE__);
+            APP_IPRINT("%d :: App: Should Be One of these Modes DTXON, DTXOFF\n", __LINE__);
+            goto EXIT;
+        }
+
+#ifdef OMX_GETTIME
+        GT_START();
+        eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
+        GT_END("Set Parameter Test-SetParameter");
+#else
+        eError = OMX_SetParameter (pHandle, OMX_IndexParamAudioAmr, pAmrParam);
+#endif
+
+        if (eError != OMX_ErrorNone) {
+            eError = OMX_ErrorBadParameter;
+            APP_DPRINT("%d :: OMX_ErrorBadParameter\n", __LINE__);
+            goto EXIT;
+        }
 
 
         /* setting for stream gain */
-		pCompPrivateStructGain = newmalloc (sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE));
-		if(pCompPrivateStructGain == NULL) 
-		{
-			APP_DPRINT("%d :: App: Malloc Failed\n",__LINE__);
-			goto EXIT;
-		}
+        pCompPrivateStructGain = newmalloc (sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE));
+
+        if (pCompPrivateStructGain == NULL) {
+            APP_DPRINT("%d :: App: Malloc Failed\n", __LINE__);
+            goto EXIT;
+        }
+
         ArrayOfPointers[4] = (OMX_AUDIO_CONFIG_VOLUMETYPE*) pCompPrivateStructGain;
 
-		/* default setting for gain */
-		pCompPrivateStructGain->nSize = sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE);
-		pCompPrivateStructGain->nVersion.s.nVersionMajor	= 0xF1;
-		pCompPrivateStructGain->nVersion.s.nVersionMinor	= 0xF2;
-		pCompPrivateStructGain->nPortIndex					= OMX_DirOutput;
-		pCompPrivateStructGain->bLinear						= OMX_FALSE;
-		pCompPrivateStructGain->sVolume.nValue				= 50;				/* actual volume */
-		pCompPrivateStructGain->sVolume.nMin				= 0;				/* min volume */
-		pCompPrivateStructGain->sVolume.nMax				= 100;				/* max volume */
+        /* default setting for gain */
+        pCompPrivateStructGain->nSize = sizeof(OMX_AUDIO_CONFIG_VOLUMETYPE);
+        pCompPrivateStructGain->nVersion.s.nVersionMajor    = 0xF1;
+        pCompPrivateStructGain->nVersion.s.nVersionMinor    = 0xF2;
+        pCompPrivateStructGain->nPortIndex                  = OMX_DirOutput;
+        pCompPrivateStructGain->bLinear                     = OMX_FALSE;
+        pCompPrivateStructGain->sVolume.nValue              = 50;               /* actual volume */
+        pCompPrivateStructGain->sVolume.nMin                = 0;                /* min volume */
+        pCompPrivateStructGain->sVolume.nMax                = 100;              /* max volume */
 
 
-    if (audioinfo->acousticMode == OMX_TRUE) {
-        APP_IPRINT("Using Acoustic Devide Node Path\n");
-        dataPath = DATAPATH_ACDN;
-		fprintf("HERE %d \n", __LINE__);
-    }
-    else if (audioinfo->dasfMode) {
-#ifdef RTM_PATH    
-        APP_IPRINT("Using Real Time Mixer Path\n");
-        dataPath = DATAPATH_APPLICATION_RTMIXER;
-		fprintf("HERE %d \n", __LINE__);
+        if (audioinfo->acousticMode == OMX_TRUE) {
+            APP_IPRINT("Using Acoustic Devide Node Path\n");
+            dataPath = DATAPATH_ACDN;
+            fprintf("HERE %d \n", __LINE__);
+        } else if (audioinfo->dasfMode) {
+#ifdef RTM_PATH
+            APP_IPRINT("Using Real Time Mixer Path\n");
+            dataPath = DATAPATH_APPLICATION_RTMIXER;
+            fprintf("HERE %d \n", __LINE__);
 #endif
 
 #ifdef ETEEDN_PATH
-        APP_IPRINT("Using Eteedn Path\n");
-        dataPath = DATAPATH_APPLICATION;
-		fprintf("HERE %d \n", __LINE__);
-#endif        
-    }
-
-    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamrheaderinfo",&index);
-	if (eError != OMX_ErrorNone) {
-		APP_IPRINT("Error getting extension index\n");
-		goto EXIT;
-	}
-
-#ifdef DSP_RENDERING_ON 		
-    cmd_data.hComponent = pHandle;
-    cmd_data.AM_Cmd = AM_CommandIsInputStreamAvailable;
-    
-    cmd_data.param1 = 0;
-
-    if((write(wbamrencfdwrite, &cmd_data, sizeof(cmd_data)))<0) {
-        APP_IPRINT("%d ::WbAmrEncTest.c ::[WBAMR Enc Component] - send command to audio manager\n", __LINE__);
-    }
-    if((read(wbamrencfdread, &cmd_data, sizeof(cmd_data)))<0) {
-        APP_IPRINT("%d ::WbAmrEncTest.c ::[WBAMR Enc Component] - failure to get data from the audio manager\n", __LINE__);
-		goto EXIT;
-    }
-    audioinfo->streamId = cmd_data.streamID;
-    streamId = audioinfo->streamId;
-#endif	
-
-	eError = OMX_SetConfig (pHandle, index, audioinfo);
-    if(eError != OMX_ErrorNone) {
-        eError = OMX_ErrorBadParameter;
-        APP_DPRINT("%d :: Error from OMX_SetConfig() function\n",__LINE__);
-        goto EXIT;
-    }    
-
-    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamr.datapath",&index);
-	if (eError != OMX_ErrorNone) {
-		APP_IPRINT("Error getting extension index\n");
-		goto EXIT;
-	}
-	eError = OMX_SetConfig (pHandle, index, &dataPath);
-    if(eError != OMX_ErrorNone) {
-        eError = OMX_ErrorBadParameter;
-        APP_DPRINT("%d :: AmrDecTest.c :: Error from OMX_SetConfig() function\n",__LINE__);
-        goto EXIT;
-    }
-#ifdef OMX_GETTIME
-	GT_START();
+            APP_IPRINT("Using Eteedn Path\n");
+            dataPath = DATAPATH_APPLICATION;
+            fprintf("HERE %d \n", __LINE__);
 #endif
-    eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT("Error from SendCommand-Idle(Init) State function\n");
-        goto EXIT;
-    }	
-	sleep(1);
-	
-	
+        }
+
+        eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamrheaderinfo", &index);
+
+        if (eError != OMX_ErrorNone) {
+            APP_IPRINT("Error getting extension index\n");
+            goto EXIT;
+        }
+
+#ifdef DSP_RENDERING_ON
+        cmd_data.hComponent = pHandle;
+        cmd_data.AM_Cmd = AM_CommandIsInputStreamAvailable;
+
+        cmd_data.param1 = 0;
+
+        if ((write(wbamrencfdwrite, &cmd_data, sizeof(cmd_data))) < 0) {
+            APP_IPRINT("%d ::WbAmrEncTest.c ::[WBAMR Enc Component] - send command to audio manager\n", __LINE__);
+        }
+
+        if ((read(wbamrencfdread, &cmd_data, sizeof(cmd_data))) < 0) {
+            APP_IPRINT("%d ::WbAmrEncTest.c ::[WBAMR Enc Component] - failure to get data from the audio manager\n", __LINE__);
+            goto EXIT;
+        }
+
+        audioinfo->streamId = cmd_data.streamID;
+        streamId = audioinfo->streamId;
+#endif
+
+        eError = OMX_SetConfig (pHandle, index, audioinfo);
+
+        if (eError != OMX_ErrorNone) {
+            eError = OMX_ErrorBadParameter;
+            APP_DPRINT("%d :: Error from OMX_SetConfig() function\n", __LINE__);
+            goto EXIT;
+        }
+
+        eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamr.datapath", &index);
+
+        if (eError != OMX_ErrorNone) {
+            APP_IPRINT("Error getting extension index\n");
+            goto EXIT;
+        }
+
+        eError = OMX_SetConfig (pHandle, index, &dataPath);
+
+        if (eError != OMX_ErrorNone) {
+            eError = OMX_ErrorBadParameter;
+            APP_DPRINT("%d :: AmrDecTest.c :: Error from OMX_SetConfig() function\n", __LINE__);
+            goto EXIT;
+        }
+
+#ifdef OMX_GETTIME
+        GT_START();
+#endif
+        eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
+
+        if (eError != OMX_ErrorNone) {
+            APP_DPRINT("Error from SendCommand-Idle(Init) State function\n");
+            goto EXIT;
+        }
+
+        sleep(1);
+
+
 #ifndef USE_BUFFER
-		APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n",__LINE__);
-		if(!DasfMode) {
-		/* allocate input buffer */
-			for(i = 0; i < numOfInputBuffer; i++) {
-				APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pInputBufferHeader[%d]\n",__LINE__, i);
-				eError = OMX_AllocateBuffer(pHandle, &pInputBufferHeader[i], 0, NULL, WBAPP_INPUT_BUFFER_SIZE*2);
-				if(eError != OMX_ErrorNone) {
-					APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pInputBufferHeader[%d]\n",__LINE__, i);
-					goto EXIT;
-				}
-			}
-		}
-		APP_DPRINT("\n%d :: App: pCompPrivateStruct->nBufferSize --> %ld \n",__LINE__,pCompPrivateStruct->nBufferSize);
-		for(i = 0; i < numOfOutputBuffer; i++) {
-			/* allocate output buffer */
-			APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pOutputBufferHeader[%d]\n",__LINE__, i);
-			eError = OMX_AllocateBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize*2);
-			if(eError != OMX_ErrorNone) {
-				APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pOutputBufferHeader[%d]\n",__LINE__, i);
-				goto EXIT;
-			}
-		}
+        APP_DPRINT("%d :: About to call OMX_AllocateBuffer\n", __LINE__);
+
+        if (!DasfMode) {
+            /* allocate input buffer */
+            for (i = 0; i < numOfInputBuffer; i++) {
+                APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pInputBufferHeader[%d]\n", __LINE__, i);
+                eError = OMX_AllocateBuffer(pHandle, &pInputBufferHeader[i], 0, NULL, WBAPP_INPUT_BUFFER_SIZE * 2);
+
+                if (eError != OMX_ErrorNone) {
+                    APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pInputBufferHeader[%d]\n", __LINE__, i);
+                    goto EXIT;
+                }
+            }
+        }
+
+        APP_DPRINT("\n%d :: App: pCompPrivateStruct->nBufferSize --> %ld \n", __LINE__, pCompPrivateStruct->nBufferSize);
+
+        for (i = 0; i < numOfOutputBuffer; i++) {
+            /* allocate output buffer */
+            APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pOutputBufferHeader[%d]\n", __LINE__, i);
+            eError = OMX_AllocateBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize * 2);
+
+            if (eError != OMX_ErrorNone) {
+                APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pOutputBufferHeader[%d]\n", __LINE__, i);
+                goto EXIT;
+            }
+        }
+
 #else
-		if(!DasfMode) {
-			for(i = 0; i < numOfInputBuffer; i++) {
-				pInputBuffer[i] = (OMX_U8*)newmalloc(WBAPP_INPUT_BUFFER_SIZE*2 + 256);
-				APP_MEMPRINT("%d :: [TESTAPP ALLOC] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
-				if(NULL == pInputBuffer[i]) {
-					APP_DPRINT("%d :: Malloc Failed\n",__LINE__);
-					eError = OMX_ErrorInsufficientResources;
-					goto EXIT;
-				}
-				pInputBuffer[i] = pInputBuffer[i] + 128;
-				
-				/*	allocate input buffer */
-				APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
-				eError = OMX_UseBuffer(pHandle, &pInputBufferHeader[i], 0, NULL, WBAPP_INPUT_BUFFER_SIZE*2, pInputBuffer[i]);
-				if(eError != OMX_ErrorNone) {
-					APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
-					goto EXIT;
-				}
-			}
-		}
-	
-		for(i = 0; i < numOfOutputBuffer; i++) {
-			pOutputBuffer[i] = newmalloc (pCompPrivateStruct->nBufferSize*2 + 256);
-			APP_MEMPRINT("%d :: [TESTAPP ALLOC] pOutputBuffer[%d] = %p\n",__LINE__,i,pOutputBuffer[i]);
-			if(NULL == pOutputBuffer[i]) {
-				APP_DPRINT("%d :: Malloc Failed\n",__LINE__);
-				eError = OMX_ErrorInsufficientResources;
-				goto EXIT;
-			}
-			pOutputBuffer[i] = pOutputBuffer[i] + 128;
-	
-			/* allocate output buffer */
-			APP_DPRINT("%d :: About to call OMX_UseBuffer\n",__LINE__);
-			eError = OMX_UseBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize*2, pOutputBuffer[i]);
-			if(eError != OMX_ErrorNone) {
-				APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n",__LINE__);
-				goto EXIT;
-			}
-		}
+
+        if (!DasfMode) {
+            for (i = 0; i < numOfInputBuffer; i++) {
+                pInputBuffer[i] = (OMX_U8*)newmalloc(WBAPP_INPUT_BUFFER_SIZE * 2 + 256);
+                APP_MEMPRINT("%d :: [TESTAPP ALLOC] pInputBuffer[%d] = %p\n", __LINE__, i, pInputBuffer[i]);
+
+                if (NULL == pInputBuffer[i]) {
+                    APP_DPRINT("%d :: Malloc Failed\n", __LINE__);
+                    eError = OMX_ErrorInsufficientResources;
+                    goto EXIT;
+                }
+
+                pInputBuffer[i] = pInputBuffer[i] + 128;
+
+                /*  allocate input buffer */
+                APP_DPRINT("%d :: About to call OMX_UseBuffer\n", __LINE__);
+                eError = OMX_UseBuffer(pHandle, &pInputBufferHeader[i], 0, NULL, WBAPP_INPUT_BUFFER_SIZE * 2, pInputBuffer[i]);
+
+                if (eError != OMX_ErrorNone) {
+                    APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n", __LINE__);
+                    goto EXIT;
+                }
+            }
+        }
+
+        for (i = 0; i < numOfOutputBuffer; i++) {
+            pOutputBuffer[i] = newmalloc (pCompPrivateStruct->nBufferSize * 2 + 256);
+            APP_MEMPRINT("%d :: [TESTAPP ALLOC] pOutputBuffer[%d] = %p\n", __LINE__, i, pOutputBuffer[i]);
+
+            if (NULL == pOutputBuffer[i]) {
+                APP_DPRINT("%d :: Malloc Failed\n", __LINE__);
+                eError = OMX_ErrorInsufficientResources;
+                goto EXIT;
+            }
+
+            pOutputBuffer[i] = pOutputBuffer[i] + 128;
+
+            /* allocate output buffer */
+            APP_DPRINT("%d :: About to call OMX_UseBuffer\n", __LINE__);
+            eError = OMX_UseBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize * 2, pOutputBuffer[i]);
+
+            if (eError != OMX_ErrorNone) {
+                APP_DPRINT("%d :: Error returned by OMX_UseBuffer()\n", __LINE__);
+                goto EXIT;
+            }
+        }
+
 #endif
-    /* Wait for startup to complete */
-    eError = WaitForState(pHandle, OMX_StateIdle);
+        /* Wait for startup to complete */
+        eError = WaitForState(pHandle, OMX_StateIdle);
 #ifdef OMX_GETTIME
-	GT_END("Call to SendCommand <OMX_StateIdle & Allocated the buffers & Cleared it>");
-#endif		
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
-        goto EXIT;
-    }
- 
-    if (audioinfo->dasfMode) { 
-         /* get streamID back to application */ 
-         eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamrstreamIDinfo",&index); 
-         if (eError != OMX_ErrorNone) { 
-             APP_IPRINT("Error getting extension index\n"); 
-             goto EXIT; 
-         } 
-      
-         eError = OMX_GetConfig (pHandle, index, streaminfo); 
-         if(eError != OMX_ErrorNone) { 
-             eError = OMX_ErrorBadParameter; 
-             APP_DPRINT("%d :: PcmDecTest.c :: Error from OMX_GetConfig() function\n",__LINE__); 
-             goto EXIT; 
-         }       
-         streamId = streaminfo->streamId; 
-         APP_IPRINT("***************StreamId=%d******************\n", (int)streamId); 
-     }     
-   
-    for(i = 0; i < testcnt; i++) {
-	frmCnt = 1;
-	nFrameCount = 1;
-	nOutBuff = 1;
-	nIpBuff  = 1;
-	if(i > 0) {
-		APP_IPRINT ("%d :: Encoding the file for %d Time\n",__LINE__,i+1);
-		fIn = fopen(argv[1], "r");
-		if(fIn == NULL) {
-			fprintf(stderr, "Error:  failed to open the file %s for readonly access\n", argv[1]);
-			goto EXIT;
-		}
-		fOut = fopen("TC5_WbAmr1.amr", "w");
-		if(fOut == NULL) {
-			fprintf(stderr, "Error:  failed to create the output file %s\n", argv[2]);
-			goto EXIT;
-		}
-	}
-
-    APP_IPRINT("%d :: App: pAmrParam->eAMRBandMode --> %d \n",__LINE__,pAmrParam->eAMRBandMode);
-   	APP_IPRINT("%d :: App: pAmrParam->eAMRDTXMode --> %s \n",__LINE__,argv[4]);
-    APP_IPRINT("%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n",__LINE__,pCompPrivateStruct->format.audio.cMIMEType);
-
-	APP_IPRINT("%d :: App: Sending OMX_StateExecuting Command\n",__LINE__);
-#ifdef OMX_GETTIME
-	GT_START()
+        GT_END("Call to SendCommand <OMX_StateIdle & Allocated the buffers & Cleared it>");
 #endif
-    eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT("Error from SendCommand-Executing State function\n");
-        goto EXIT;
-    }
-    eError = WaitForState(pHandle, OMX_StateExecuting);
+
+        if (eError != OMX_ErrorNone) {
+            APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
+            goto EXIT;
+        }
+
+        if (audioinfo->dasfMode) {
+            /* get streamID back to application */
+            eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.index.config.wbamrstreamIDinfo", &index);
+
+            if (eError != OMX_ErrorNone) {
+                APP_IPRINT("Error getting extension index\n");
+                goto EXIT;
+            }
+
+            eError = OMX_GetConfig (pHandle, index, streaminfo);
+
+            if (eError != OMX_ErrorNone) {
+                eError = OMX_ErrorBadParameter;
+                APP_DPRINT("%d :: PcmDecTest.c :: Error from OMX_GetConfig() function\n", __LINE__);
+                goto EXIT;
+            }
+
+            streamId = streaminfo->streamId;
+            APP_IPRINT("***************StreamId=%d******************\n", (int)streamId);
+        }
+
+        for (i = 0; i < testcnt; i++) {
+            frmCnt = 1;
+            nFrameCount = 1;
+            nOutBuff = 1;
+            nIpBuff  = 1;
+
+            if (i > 0) {
+                APP_IPRINT ("%d :: Encoding the file for %d Time\n", __LINE__, i + 1);
+                fIn = fopen(argv[1], "r");
+
+                if (fIn == NULL) {
+                    fprintf(stderr, "Error:  failed to open the file %s for readonly access\n", argv[1]);
+                    goto EXIT;
+                }
+
+                fOut = fopen("TC5_WbAmr1.amr", "w");
+
+                if (fOut == NULL) {
+                    fprintf(stderr, "Error:  failed to create the output file %s\n", argv[2]);
+                    goto EXIT;
+                }
+            }
+
+            APP_IPRINT("%d :: App: pAmrParam->eAMRBandMode --> %d \n", __LINE__, pAmrParam->eAMRBandMode);
+            APP_IPRINT("%d :: App: pAmrParam->eAMRDTXMode --> %s \n", __LINE__, argv[4]);
+            APP_IPRINT("%d :: App: pCompPrivateStruct->format.audio.cMIMEType --> %s \n", __LINE__, pCompPrivateStruct->format.audio.cMIMEType);
+
+            APP_IPRINT("%d :: App: Sending OMX_StateExecuting Command\n", __LINE__);
 #ifdef OMX_GETTIME
-	GT_END("Call to SendCommand <OMX_StateExecuting>");
+            GT_START()
 #endif
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
-        goto EXIT;
-    }
+            eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
 
-    if (audioinfo->dasfMode ) { 
-		APP_IPRINT("%d :: App: No.of Frames Encoding = %d\n",__LINE__, atoi(argv[10]));
-	}
+            if (eError != OMX_ErrorNone) {
+                APP_DPRINT("Error from SendCommand-Executing State function\n");
+                goto EXIT;
+            }
 
-    pComponent = (OMX_COMPONENTTYPE *)pHandle;
- 
-	if(audioinfo->dasfMode == 0) {
-		for (k=0; k < numOfInputBuffer; k++) {
-			OMX_BUFFERHEADERTYPE* pBuffer = pInputBufferHeader[k];
-			pBuffer->nFlags=0;
-		#ifdef OMX_GETTIME
-			if (k==0)
-			{ 
-				GT_FlagE=1;  /* 1 = First Buffer,  0 = Not First Buffer  */
-				GT_START(); /* Empty Bufffer */
-			}
-		#endif
-            eError =  send_input_buffer(pHandle, pBuffer, fIn); 			
-		}
-	}
+            eError = WaitForState(pHandle, OMX_StateExecuting);
+#ifdef OMX_GETTIME
+            GT_END("Call to SendCommand <OMX_StateExecuting>");
+#endif
 
-	for (kk = 0; kk < numOfOutputBuffer; kk++) {
-		APP_DPRINT("%d :: App: Calling FillThisBuffer \n",__LINE__);
-	#ifdef OMX_GETTIME
-         if (kk==0)
-         { 
-            GT_FlagF=1;  /* 1 = First Buffer,  0 = Not First Buffer  */
-            GT_START(); /* Fill Buffer */
-         }
-	#endif
+            if (eError != OMX_ErrorNone) {
+                APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
+                goto EXIT;
+            }
 
-		pComponent->FillThisBuffer(pHandle, pOutputBufferHeader[kk]);
+            if (audioinfo->dasfMode ) {
+                APP_IPRINT("%d :: App: No.of Frames Encoding = %d\n", __LINE__, atoi(argv[10]));
+            }
 
-	}
+            pComponent = (OMX_COMPONENTTYPE *)pHandle;
 
-	eError = pComponent->GetState(pHandle, &state);
-	if(eError != OMX_ErrorNone) {
-		APP_DPRINT("%d :: pComponent->GetState has returned status %X\n",__LINE__, eError);
-		goto EXIT;
-	}
-    retval = 1;
-     
+            if (audioinfo->dasfMode == 0) {
+                for (k = 0; k < numOfInputBuffer; k++) {
+                    OMX_BUFFERHEADERTYPE* pBuffer = pInputBufferHeader[k];
+                    pBuffer->nFlags = 0;
+#ifdef OMX_GETTIME
+
+                    if (k == 0) {
+                        GT_FlagE = 1;  /* 1 = First Buffer,  0 = Not First Buffer  */
+                        GT_START(); /* Empty Bufffer */
+                    }
+
+#endif
+                    eError =  send_input_buffer(pHandle, pBuffer, fIn);
+                }
+            }
+
+            for (kk = 0; kk < numOfOutputBuffer; kk++) {
+                APP_DPRINT("%d :: App: Calling FillThisBuffer \n", __LINE__);
+#ifdef OMX_GETTIME
+
+                if (kk == 0) {
+                    GT_FlagF = 1;  /* 1 = First Buffer,  0 = Not First Buffer  */
+                    GT_START(); /* Fill Buffer */
+                }
+
+#endif
+
+                pComponent->FillThisBuffer(pHandle, pOutputBufferHeader[kk]);
+
+            }
+
+            eError = pComponent->GetState(pHandle, &state);
+
+            if (eError != OMX_ErrorNone) {
+                APP_DPRINT("%d :: pComponent->GetState has returned status %X\n", __LINE__, eError);
+                goto EXIT;
+            }
+
+            retval = 1;
+
 
 #ifndef WAITFORRESOURCES
-    while( (eError == OMX_ErrorNone) && (state != OMX_StateIdle)  && (state != OMX_StateInvalid) ) {                  
-	if(1){
+
+            while ( (eError == OMX_ErrorNone) && (state != OMX_StateIdle)  && (state != OMX_StateInvalid) ) {
+                if (1) {
 #else
-   while(1) {
-        if((eError == OMX_ErrorNone) && (state != OMX_StateIdle) && (state != OMX_StateInvalid) ){ 
+
+            while (1) {
+                if ((eError == OMX_ErrorNone) && (state != OMX_StateIdle) && (state != OMX_StateInvalid) ) {
 #endif
-        FD_ZERO(&rfds);
-        FD_SET(IpBuf_Pipe[0], &rfds);
-        FD_SET(OpBuf_Pipe[0], &rfds);
-		FD_SET(Event_Pipe[0], &rfds);
+                    FD_ZERO(&rfds);
+                    FD_SET(IpBuf_Pipe[0], &rfds);
+                    FD_SET(OpBuf_Pipe[0], &rfds);
+                    FD_SET(Event_Pipe[0], &rfds);
 
-        tv.tv_sec = 1;
-        tv.tv_usec = 0;
-		frmCount++;
-        retval = select(fdmax+1, &rfds, NULL, NULL, &tv);
-        if(retval == -1) {
-            perror("select()");
-            APP_DPRINT( " :: Error \n");
-            break;
-        }
-        
-        if(!retval){
-              NoDataRead++;
-              if(NoDataRead==2){
-                      APP_IPRINT("Stoping component since No data is read from the pipes\n");          
-                      StopComponent(pHandle); 
-                      }
-              }        
-        else{
-                 NoDataRead=0;
-             }
-		switch (tcID) {
-		case 1:
-		case 2:
-        case 3:
-        case 4:             
-		case 5:
-		case 6:
-        case 7:
-			if(audioinfo->dasfMode == 0) {
-				if(FD_ISSET(IpBuf_Pipe[0], &rfds)) {                                           
-					OMX_BUFFERHEADERTYPE* pBuffer;
-					read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
-					if ((frmCount==14 || frmCount==15) && tcID ==3){ /*Pause the component*/
-						APP_IPRINT("App: Pausing Component for 2 Seconds\n");
-						PauseComponent(pHandle);
-						sleep(2);
-						APP_IPRINT("App: Resume Component\n");
-						PlayComponent(pHandle);
-					}
-					if (frmCount==20 && tcID ==4){ /*Stop the component*/
-                        tcID = 1;
-						StopComponent(pHandle);
-						break;
+                    tv.tv_sec = 1;
+                    tv.tv_usec = 0;
+                    frmCount++;
+                    retval = select(fdmax + 1, &rfds, NULL, NULL, &tv);
+
+                    if (retval == -1) {
+                        perror("select()");
+                        APP_DPRINT( " :: Error \n");
+                        break;
                     }
-					eError =  send_input_buffer(pHandle, pBuffer, fIn);
-				}
-			} else {
-                   if (frmCount == 15 && tcID == 3){  /*Pause the component*/
-                        tcID = 1;
-						APP_IPRINT("App: Pausing Component for 2 Seconds\n");
-						PauseComponent(pHandle);
-						sleep(2);
-						APP_IPRINT("App: Resume Component\n");
-						PlayComponent(pHandle);						
-					}
-					if (frmCount == 20 && tcID == 4){ /*Stop the component*/
-						StopComponent(pHandle);
-						break;
+
+                    if (!retval) {
+                        NoDataRead++;
+
+                        if (NoDataRead == 2) {
+                            APP_IPRINT("Stoping component since No data is read from the pipes\n");
+                            StopComponent(pHandle);
+                        }
+                    } else {
+                        NoDataRead = 0;
                     }
-					APP_DPRINT("%d :: WBAMR ENCODER RUNNING UNDER DASF MODE \n",__LINE__);
-					if(nFrameCount == 10 && tcID == 7)								
-					{
-							/* set high gain for record stream */
-							APP_IPRINT("[WBAMR encoder] --- will set stream gain to high\n");
-            				pCompPrivateStructGain->sVolume.nValue = 0x8000;
-							eError = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain);
-							if (eError != OMX_ErrorNone) 
-							{
-								eError = OMX_ErrorBadParameter;
-								goto EXIT;
-							}
-					}
-					if(nFrameCount == 250 && tcID == 7)
-					{
-							/* set low gain for record stream */
-							APP_IPRINT("[WBAMR encoder] --- will set stream gain to low\n");
-            				pCompPrivateStructGain->sVolume.nValue = 0x2000;
-							eError = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain);
-							if (eError != OMX_ErrorNone) 
-							{
-								eError = OMX_ErrorBadParameter;
-								goto EXIT;
-							}							
-					}
-					if(nFrameCount == atoi(argv[10])) {
-						StopComponent(pHandle);  
-					}
-					APP_DPRINT("%d :: WBAMR ENCODER READING DATA FROM DASF  \n",__LINE__);
-				}
-		break;				
-		default:
-				APP_DPRINT("%d :: ### Simple DEFAULT Case Here ###\n",__LINE__);
-		}
 
-        if( FD_ISSET(OpBuf_Pipe[0], &rfds) ) {
-            OMX_BUFFERHEADERTYPE* pBuf;
-            read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
-            APP_DPRINT("%d :: App: pBuf->nFilledLen = %ld\n",__LINE__, pBuf->nFilledLen);
-            nFrameLen = pBuf->nFilledLen;
-            if(!(strcmp(pCompPrivateStruct->format.audio.cMIMEType,"MIME"))) {
-	            if(1 == nFrameCount) {
-                   char MimeHeader[] = {0x23, 0x21, 0x41, 0x4d, 0x52, 0x2d, 0x57, 0x42, 0x0a};
-                   fwrite(MimeHeader, 1, WBAMRENC_MIME_HEADER_LEN, fOut);
-	               fflush(fOut);
-                   APP_IPRINT("%d :: App: MIME Supported:: FrameLen = %d\n",__LINE__, nFrameLen);
-                }
-            }
-			APP_DPRINT("%d :: App: nFrameLen = %d \n",__LINE__, nFrameLen);
-            if (nFrameLen != 0) {
-				APP_DPRINT("%d :: Writing OutputBuffer No: %d to the file nWrite = %d \n",__LINE__, nOutBuff, nFrameLen);
-				fwrite(pBuf->pBuffer, 1, nFrameLen, fOut);
-				fflush(fOut);
-			}
+                    switch (tcID) {
+                        case 1:
+                        case 2:
+                        case 3:
+                        case 4:
+                        case 5:
+                        case 6:
+                        case 7:
 
-			if(pBuf->nFlags == OMX_BUFFERFLAG_EOS) {                            
-   				   APP_IPRINT("%d :: App: OMX_BUFFERFLAG_EOS is received\n",__LINE__);
-				   APP_IPRINT("%d :: App: Shutting down ---------- \n",__LINE__);				   
-				   StopComponent(pHandle);
-				   pBuf->nFlags = 0;
-			}
-			else{
-				nFrameCount++;
-				nOutBuff++;
-  		        pComponent->FillThisBuffer(pHandle, pBuf);
-				APP_DPRINT("%d :: App: pBuf->nFlags = %ld\n",__LINE__, pBuf->nFlags);
-			}
-        }
+                            if (audioinfo->dasfMode == 0) {
+                                if (FD_ISSET(IpBuf_Pipe[0], &rfds)) {
+                                    OMX_BUFFERHEADERTYPE* pBuffer;
+                                    read(IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
 
-if( FD_ISSET(Event_Pipe[0], &rfds) ) {
-                OMX_U8 pipeContents;
-                read(Event_Pipe[0], &pipeContents, sizeof(OMX_U8));
+                                    if ((frmCount == 14 || frmCount == 15) && tcID == 3) { /*Pause the component*/
+                                        APP_IPRINT("App: Pausing Component for 2 Seconds\n");
+                                        PauseComponent(pHandle);
+                                        sleep(2);
+                                        APP_IPRINT("App: Resume Component\n");
+                                        PlayComponent(pHandle);
+                                    }
 
-                if (pipeContents == 0) {
-                    APP_IPRINT("Test app received OMX_ErrorResourcesPreempted\n");
-                    WaitForState(pHandle,OMX_StateIdle);
+                                    if (frmCount == 20 && tcID == 4) { /*Stop the component*/
+                                        tcID = 1;
+                                        StopComponent(pHandle);
+                                        break;
+                                    }
 
-					for(i=0; i < numOfInputBuffer; i++) {
-						APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n",__LINE__, i);
-						eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
-						if((eError != OMX_ErrorNone)) {
-							APP_DPRINT("%d:: Error in FreeBuffer function\n",__LINE__);
-							goto EXIT;
-						}
-						
-					}
+                                    eError =  send_input_buffer(pHandle, pBuffer, fIn);
+                                }
+                            } else {
+                                if (frmCount == 15 && tcID == 3) { /*Pause the component*/
+                                    tcID = 1;
+                                    APP_IPRINT("App: Pausing Component for 2 Seconds\n");
+                                    PauseComponent(pHandle);
+                                    sleep(2);
+                                    APP_IPRINT("App: Resume Component\n");
+                                    PlayComponent(pHandle);
+                                }
 
-					for(i=0; i < numOfOutputBuffer; i++) {
-						APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n",__LINE__, i);
-						eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
-						if((eError != OMX_ErrorNone)) {
-							APP_DPRINT("%d :: Error in Free Buffer function\n",__LINE__);
-							goto EXIT;
-						}
-						
-				    }
+                                if (frmCount == 20 && tcID == 4) { /*Stop the component*/
+                                    StopComponent(pHandle);
+                                    break;
+                                }
+
+                                APP_DPRINT("%d :: WBAMR ENCODER RUNNING UNDER DASF MODE \n", __LINE__);
+
+                                if (nFrameCount == 10 && tcID == 7) {
+                                    /* set high gain for record stream */
+                                    APP_IPRINT("[WBAMR encoder] --- will set stream gain to high\n");
+                                    pCompPrivateStructGain->sVolume.nValue = 0x8000;
+                                    eError = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain);
+
+                                    if (eError != OMX_ErrorNone) {
+                                        eError = OMX_ErrorBadParameter;
+                                        goto EXIT;
+                                    }
+                                }
+
+                                if (nFrameCount == 250 && tcID == 7) {
+                                    /* set low gain for record stream */
+                                    APP_IPRINT("[WBAMR encoder] --- will set stream gain to low\n");
+                                    pCompPrivateStructGain->sVolume.nValue = 0x2000;
+                                    eError = OMX_SetConfig(pHandle, OMX_IndexConfigAudioVolume, pCompPrivateStructGain);
+
+                                    if (eError != OMX_ErrorNone) {
+                                        eError = OMX_ErrorBadParameter;
+                                        goto EXIT;
+                                    }
+                                }
+
+                                if (nFrameCount == atoi(argv[10])) {
+                                    StopComponent(pHandle);
+                                }
+
+                                APP_DPRINT("%d :: WBAMR ENCODER READING DATA FROM DASF  \n", __LINE__);
+                            }
+
+                            break;
+                        default:
+                            APP_DPRINT("%d :: ### Simple DEFAULT Case Here ###\n", __LINE__);
+                    }
+
+                    if ( FD_ISSET(OpBuf_Pipe[0], &rfds) ) {
+                        OMX_BUFFERHEADERTYPE* pBuf;
+                        read(OpBuf_Pipe[0], &pBuf, sizeof(pBuf));
+                        APP_DPRINT("%d :: App: pBuf->nFilledLen = %ld\n", __LINE__, pBuf->nFilledLen);
+                        nFrameLen = pBuf->nFilledLen;
+
+                        if (!(strcmp(pCompPrivateStruct->format.audio.cMIMEType, "MIME"))) {
+                            if (1 == nFrameCount) {
+                                char MimeHeader[] = {0x23, 0x21, 0x41, 0x4d, 0x52, 0x2d, 0x57, 0x42, 0x0a};
+                                fwrite(MimeHeader, 1, WBAMRENC_MIME_HEADER_LEN, fOut);
+                                fflush(fOut);
+                                APP_IPRINT("%d :: App: MIME Supported:: FrameLen = %d\n", __LINE__, nFrameLen);
+                            }
+                        }
+
+                        APP_DPRINT("%d :: App: nFrameLen = %d \n", __LINE__, nFrameLen);
+
+                        if (nFrameLen != 0) {
+                            APP_DPRINT("%d :: Writing OutputBuffer No: %d to the file nWrite = %d \n", __LINE__, nOutBuff, nFrameLen);
+                            fwrite(pBuf->pBuffer, 1, nFrameLen, fOut);
+                            fflush(fOut);
+                        }
+
+                        if (pBuf->nFlags == OMX_BUFFERFLAG_EOS) {
+                            APP_IPRINT("%d :: App: OMX_BUFFERFLAG_EOS is received\n", __LINE__);
+                            APP_IPRINT("%d :: App: Shutting down ---------- \n", __LINE__);
+                            StopComponent(pHandle);
+                            pBuf->nFlags = 0;
+                        } else {
+                            nFrameCount++;
+                            nOutBuff++;
+                            pComponent->FillThisBuffer(pHandle, pBuf);
+                            APP_DPRINT("%d :: App: pBuf->nFlags = %ld\n", __LINE__, pBuf->nFlags);
+                        }
+                    }
+
+                    if ( FD_ISSET(Event_Pipe[0], &rfds) ) {
+                        OMX_U8 pipeContents;
+                        read(Event_Pipe[0], &pipeContents, sizeof(OMX_U8));
+
+                        if (pipeContents == 0) {
+                            APP_IPRINT("Test app received OMX_ErrorResourcesPreempted\n");
+                            WaitForState(pHandle, OMX_StateIdle);
+
+                            for (i = 0; i < numOfInputBuffer; i++) {
+                                APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n", __LINE__, i);
+                                eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
+
+                                if ((eError != OMX_ErrorNone)) {
+                                    APP_DPRINT("%d:: Error in FreeBuffer function\n", __LINE__);
+                                    goto EXIT;
+                                }
+
+                            }
+
+                            for (i = 0; i < numOfOutputBuffer; i++) {
+                                APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n", __LINE__, i);
+                                eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
+
+                                if ((eError != OMX_ErrorNone)) {
+                                    APP_DPRINT("%d :: Error in Free Buffer function\n", __LINE__);
+                                    goto EXIT;
+                                }
+
+                            }
+
 #ifdef USE_BUFFER
 
-		for(i=0; i < numOfInputBuffer; i++) {
-			if(pInputBuffer[i] != NULL){
-	       		APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
-	            pInputBuffer[i] = pInputBuffer[i] - 128;       		
-				newfree(pInputBuffer[i]);
-				pInputBuffer[i] = NULL;
-			}
-		}
-					
-#endif                        
+                            for (i = 0; i < numOfInputBuffer; i++) {
+                                if (pInputBuffer[i] != NULL) {
+                                    APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n", __LINE__, i, pInputBuffer[i]);
+                                    pInputBuffer[i] = pInputBuffer[i] - 128;
+                                    newfree(pInputBuffer[i]);
+                                    pInputBuffer[i] = NULL;
+                                }
+                            }
 
-                	OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
-                    WaitForState(pHandle, OMX_StateLoaded); 
-
-                    OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateWaitForResources,NULL);
-                    WaitForState(pHandle,OMX_StateWaitForResources);
-                }
-                else if (pipeContents == 1) {
-                    APP_IPRINT("Test app received OMX_ErrorResourcesAcquired\n");
-
-                    OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateIdle,NULL);
-			  		for(i = 0; i < numOfOutputBuffer; i++) {
-						/* allocate output buffer */
-						APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pOutputBufferHeader[%d]\n",__LINE__, i);
-						eError = OMX_AllocateBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize*2);
-						if(eError != OMX_ErrorNone) {
-							APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pOutputBufferHeader[%d]\n",__LINE__, i);
-							goto EXIT;
-						}
-					}
-
-                    WaitForState(pHandle,OMX_StateIdle);
-
-                    OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateExecuting,NULL);
-                    WaitForState(pHandle,OMX_StateExecuting);
-
-                    rewind(fIn);
-					for(i=0; i < numOfInputBuffer; i++) {
-	                    send_input_buffer (pHandle, pOutputBufferHeader[i], fIn);
-					}
-                }                
-
-                if (pipeContents == 2) {
-
-#ifdef OMX_GETTIME
-                    GT_START();
 #endif
-                                
-                    OMX_SendCommand(pHandle,OMX_CommandStateSet,OMX_StateIdle,NULL);
-                    WaitForState(pHandle,OMX_StateIdle);
+
+                            OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
+                            WaitForState(pHandle, OMX_StateLoaded);
+
+                            OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateWaitForResources, NULL);
+                            WaitForState(pHandle, OMX_StateWaitForResources);
+                        } else if (pipeContents == 1) {
+                            APP_IPRINT("Test app received OMX_ErrorResourcesAcquired\n");
+
+                            OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
+
+                            for (i = 0; i < numOfOutputBuffer; i++) {
+                                /* allocate output buffer */
+                                APP_DPRINT("%d :: About to call OMX_AllocateBuffer for pOutputBufferHeader[%d]\n", __LINE__, i);
+                                eError = OMX_AllocateBuffer(pHandle, &pOutputBufferHeader[i], 1, NULL, pCompPrivateStruct->nBufferSize * 2);
+
+                                if (eError != OMX_ErrorNone) {
+                                    APP_DPRINT("%d :: Error returned by OMX_AllocateBuffer for pOutputBufferHeader[%d]\n", __LINE__, i);
+                                    goto EXIT;
+                                }
+                            }
+
+                            WaitForState(pHandle, OMX_StateIdle);
+
+                            OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
+                            WaitForState(pHandle, OMX_StateExecuting);
+
+                            rewind(fIn);
+
+                            for (i = 0; i < numOfInputBuffer; i++) {
+                                send_input_buffer (pHandle, pOutputBufferHeader[i], fIn);
+                            }
+                        }
+
+                        if (pipeContents == 2) {
 
 #ifdef OMX_GETTIME
-                    GT_END("Call to SendCommand <OMX_StateIdle>");
+                            GT_START();
+#endif
+
+                            OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
+                            WaitForState(pHandle, OMX_StateIdle);
+
+#ifdef OMX_GETTIME
+                            GT_END("Call to SendCommand <OMX_StateIdle>");
 #endif
 
 #ifdef WAITFORRESOURCES
-					for(i=0; i < numOfInputBuffer; i++) {
-						APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n",__LINE__, i);
-						eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
-						if((eError != OMX_ErrorNone)) {
-							APP_DPRINT("%d:: Error in FreeBuffer function\n",__LINE__);
-							goto EXIT;
-						}
-						
-					}
 
-					for(i=0; i < numOfOutputBuffer; i++) {
-						APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n",__LINE__, i);
-						eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
-						if((eError != OMX_ErrorNone)) {
-							APP_DPRINT("%d :: Error in Free Buffer function\n",__LINE__);
-							goto EXIT;
-						}
-						
-				    }
-                                
-                	OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
-                    WaitForState(pHandle, OMX_StateLoaded); 
+                            for (i = 0; i < numOfInputBuffer; i++) {
+                                APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n", __LINE__, i);
+                                eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
 
+                                if ((eError != OMX_ErrorNone)) {
+                                    APP_DPRINT("%d:: Error in FreeBuffer function\n", __LINE__);
+                                    goto EXIT;
+                                }
+
+                            }
+
+                            for (i = 0; i < numOfOutputBuffer; i++) {
+                                APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n", __LINE__, i);
+                                eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
+
+                                if ((eError != OMX_ErrorNone)) {
+                                    APP_DPRINT("%d :: Error in Free Buffer function\n", __LINE__);
+                                    goto EXIT;
+                                }
+
+                            }
+
+                            OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
+                            WaitForState(pHandle, OMX_StateLoaded);
+
+                            goto SHUTDOWN;
+#endif
+                        }
+                    }
+
+
+                    eError = pComponent->GetState(pHandle, &state);
+
+                    if (eError != OMX_ErrorNone) {
+                        APP_DPRINT("%d :: pComponent->GetState has returned status %X\n", __LINE__, eError);
+                        goto EXIT;
+                    }
+
+                } else if (preempted) {
+                    sched_yield();
+                } else {
                     goto SHUTDOWN;
-#endif
+                }
+
+            } /* While Loop Ending Here */
+
+            APP_IPRINT("%d :: App: The current state of the component = %d \n", __LINE__, state);
+            fclose(fOut);
+            fclose(fIn);
+            FirstTime = 1;
+            NoDataRead = 0;
+
+            if (tcID == 4)
+                tcID = 1;
+
+            APP_IPRINT("%d :: App: WBAMR Encoded = %d Frames \n", __LINE__, (nOutBuff));
+        } /*Test Case 4 & 5 Inner for loop ends here  */
+
+        /* newfree the Allocate and Use Buffers */
+        APP_IPRINT("%d :: App: Freeing the Allocate OR Use Buffers in TestApp\n", __LINE__);
+
+        if (!DasfMode) {
+            for (i = 0; i < numOfInputBuffer; i++) {
+                APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n", __LINE__, i);
+                eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
+
+                if ((eError != OMX_ErrorNone)) {
+                    APP_DPRINT("%d:: Error in FreeBuffer function\n", __LINE__);
+                    goto EXIT;
                 }
             }
-
-
-		eError = pComponent->GetState(pHandle, &state);
-        if(eError != OMX_ErrorNone) {
-                APP_DPRINT("%d :: pComponent->GetState has returned status %X\n",__LINE__, eError);
-                goto EXIT;
         }
 
-}
-            else if (preempted) {
-                sched_yield();
-            }
-            else {
-                goto SHUTDOWN;
-            }    
-			
-    } /* While Loop Ending Here */
-    	APP_IPRINT("%d :: App: The current state of the component = %d \n",__LINE__,state);
-    	fclose(fOut);
-    	fclose(fIn);
-        FirstTime = 1;
-        NoDataRead = 0;
-		if(tcID == 4)
-		    tcID =1;
-		APP_IPRINT("%d :: App: WBAMR Encoded = %d Frames \n",__LINE__,(nOutBuff));
-    } /*Test Case 4 & 5 Inner for loop ends here  */
-	/* newfree the Allocate and Use Buffers */
-	APP_IPRINT("%d :: App: Freeing the Allocate OR Use Buffers in TestApp\n",__LINE__);
-	if(!DasfMode) {
-		for(i=0; i < numOfInputBuffer; i++) {
-			APP_DPRINT("%d :: App: About to newfree pInputBufferHeader[%d]\n",__LINE__, i);
-			eError = OMX_FreeBuffer(pHandle, WBAPP_INPUT_PORT, pInputBufferHeader[i]);
-			if((eError != OMX_ErrorNone)) {
-				APP_DPRINT("%d:: Error in FreeBuffer function\n",__LINE__);
-				goto EXIT;
-			}
-		}
-	}
-	for(i=0; i < numOfOutputBuffer; i++) {
-		APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n",__LINE__, i);
-		eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
-		if((eError != OMX_ErrorNone)) {
-			APP_DPRINT("%d :: Error in Free Buffer function\n",__LINE__);
-			goto EXIT;
-		}
-    }
-#ifdef USE_BUFFER
-	/* newfree the App Allocated Buffers */
-	APP_IPRINT("%d :: App: Freeing the App Allocated Buffers in TestApp\n",__LINE__);
-	if(!DasfMode) {
-		for(i=0; i < numOfInputBuffer; i++) {
-			if(pInputBuffer[i] != NULL){
-	       		APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,pInputBuffer[i]);
-	            pInputBuffer[i] = pInputBuffer[i] - 128;       		
-				newfree(pInputBuffer[i]);
-				pInputBuffer[i] = NULL;
-			}
-		}
-	}
+        for (i = 0; i < numOfOutputBuffer; i++) {
+            APP_DPRINT("%d :: App: About to newfree pOutputBufferHeader[%d]\n", __LINE__, i);
+            eError = OMX_FreeBuffer(pHandle, WBAPP_OUTPUT_PORT, pOutputBufferHeader[i]);
 
-	for(i=0; i < numOfOutputBuffer; i++) {		
-		if(pOutputBuffer[i] != NULL){
-    		APP_MEMPRINT("%d :: App: [TESTAPPFREE] pOutputBuffer[%d] = %p\n",__LINE__,i, pOutputBuffer[i]);                            
-            pOutputBuffer[i] = pOutputBuffer[i] - 128;
-			newfree(pOutputBuffer[i]);
-			pOutputBuffer[i] = NULL;
-		}
-	}
+            if ((eError != OMX_ErrorNone)) {
+                APP_DPRINT("%d :: Error in Free Buffer function\n", __LINE__);
+                goto EXIT;
+            }
+        }
+
+#ifdef USE_BUFFER
+        /* newfree the App Allocated Buffers */
+        APP_IPRINT("%d :: App: Freeing the App Allocated Buffers in TestApp\n", __LINE__);
+
+        if (!DasfMode) {
+            for (i = 0; i < numOfInputBuffer; i++) {
+                if (pInputBuffer[i] != NULL) {
+                    APP_MEMPRINT("%d :: App: [TESTAPPFREE] pInputBuffer[%d] = %p\n", __LINE__, i, pInputBuffer[i]);
+                    pInputBuffer[i] = pInputBuffer[i] - 128;
+                    newfree(pInputBuffer[i]);
+                    pInputBuffer[i] = NULL;
+                }
+            }
+        }
+
+        for (i = 0; i < numOfOutputBuffer; i++) {
+            if (pOutputBuffer[i] != NULL) {
+                APP_MEMPRINT("%d :: App: [TESTAPPFREE] pOutputBuffer[%d] = %p\n", __LINE__, i, pOutputBuffer[i]);
+                pOutputBuffer[i] = pOutputBuffer[i] - 128;
+                newfree(pOutputBuffer[i]);
+                pOutputBuffer[i] = NULL;
+            }
+        }
+
 #endif
-	APP_IPRINT ("%d :: App: Sending the OMX_StateLoaded Command\n",__LINE__);
+        APP_IPRINT ("%d :: App: Sending the OMX_StateLoaded Command\n", __LINE__);
 #ifdef OMX_GETTIME
-	GT_START();
+        GT_START();
 #endif
-    eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateLoaded, NULL);
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT("%d:: Error from SendCommand-Idle State function\n",__LINE__);
-        goto EXIT;
-    }
-    eError = WaitForState(pHandle, OMX_StateLoaded);
+        eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
+
+        if (eError != OMX_ErrorNone) {
+            APP_DPRINT("%d:: Error from SendCommand-Idle State function\n", __LINE__);
+            goto EXIT;
+        }
+
+        eError = WaitForState(pHandle, OMX_StateLoaded);
 #ifdef OMX_GETTIME
-	GT_END("Call to SendCommand <OMX_StateLoaded>");
+        GT_END("Call to SendCommand <OMX_StateLoaded>");
 #endif
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
-        goto EXIT;
-    }
-    
-	APP_IPRINT ("%d :: App: Sending the OMX_CommandPortDisable Command\n",__LINE__);
-	eError = OMX_SendCommand(pHandle, OMX_CommandPortDisable, -1, NULL);
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT("%d:: Error from SendCommand OMX_CommandPortDisable\n",__LINE__);
-        goto EXIT;
-    }
+
+        if (eError != OMX_ErrorNone) {
+            APP_DPRINT( "Error:  WaitForState reports an eError %X\n", eError);
+            goto EXIT;
+        }
+
+        APP_IPRINT ("%d :: App: Sending the OMX_CommandPortDisable Command\n", __LINE__);
+        eError = OMX_SendCommand(pHandle, OMX_CommandPortDisable, -1, NULL);
+
+        if (eError != OMX_ErrorNone) {
+            APP_DPRINT("%d:: Error from SendCommand OMX_CommandPortDisable\n", __LINE__);
+            goto EXIT;
+        }
 
 
 #ifdef WAITFORRESOURCES
-    eError = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateWaitForResources, NULL);
-    if(eError != OMX_ErrorNone) {
-        APP_DPRINT ("%d Error from SendCommand-Idle State function\n",__LINE__);
-        goto EXIT;
-    }
-    eError = WaitForState(pHandle, OMX_StateWaitForResources);
+        eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateWaitForResources, NULL);
 
-    /* temporarily put this here until I figure out what should really happen here */
-    sleep(10);
-    /* temporarily put this here until I figure out what should really happen here */
-#endif    
+        if (eError != OMX_ErrorNone) {
+            APP_DPRINT ("%d Error from SendCommand-Idle State function\n", __LINE__);
+            goto EXIT;
+        }
+
+        eError = WaitForState(pHandle, OMX_StateWaitForResources);
+
+        /* temporarily put this here until I figure out what should really happen here */
+        sleep(10);
+        /* temporarily put this here until I figure out what should really happen here */
+#endif
 SHUTDOWN:
 
 
-	APP_IPRINT("%d :: App: Freeing the Memory Allocated in TestApp\n",__LINE__);
+        APP_IPRINT("%d :: App: Freeing the Memory Allocated in TestApp\n", __LINE__);
 
-    APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n",__LINE__,pAmrParam);
-    if(pAmrParam != NULL){
-	    newfree(pAmrParam);
-	    pAmrParam = NULL;
-	}
-    APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n",__LINE__,pCompPrivateStruct);
-	if(pCompPrivateStruct != NULL){
-		newfree(pCompPrivateStruct);
-		pCompPrivateStruct = NULL;
-	}
-    APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n",__LINE__,audioinfo);
-	if(audioinfo != NULL){
-		newfree(audioinfo);
-		audioinfo = NULL;
-	}
-	
-	if (streaminfo!=NULL){
-         newfree(streaminfo);
-         streaminfo =NULL;
-    }
-	APP_IPRINT("%d :: App: Closing the Input and Output Pipes\n",__LINE__);
-	eError = close (IpBuf_Pipe[0]);
-	if (0 != eError && OMX_ErrorNone == eError) {
-		eError = OMX_ErrorHardware;
-		APP_DPRINT("%d :: Error while closing IpBuf_Pipe[0]\n",__LINE__);
-		goto EXIT;
-	}
-	eError = close (IpBuf_Pipe[1]);
-	if (0 != eError && OMX_ErrorNone == eError) {
-		eError = OMX_ErrorHardware;
-		APP_DPRINT("%d :: Error while closing IpBuf_Pipe[1]\n",__LINE__);
-		goto EXIT;
-	}
-	eError = close (OpBuf_Pipe[0]);
-	if (0 != eError && OMX_ErrorNone == eError) {
-		eError = OMX_ErrorHardware;
-		APP_DPRINT("%d :: Error while closing OpBuf_Pipe[0]\n",__LINE__);
-		goto EXIT;
-	}
-	eError = close (OpBuf_Pipe[1]);
-	if (0 != eError && OMX_ErrorNone == eError) {
-		eError = OMX_ErrorHardware;
-		APP_DPRINT("%d :: Error while closing OpBuf_Pipe[1]\n",__LINE__);
-		goto EXIT;
-	}
+        APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n", __LINE__, pAmrParam);
+
+        if (pAmrParam != NULL) {
+            newfree(pAmrParam);
+            pAmrParam = NULL;
+        }
+
+        APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n", __LINE__, pCompPrivateStruct);
+
+        if (pCompPrivateStruct != NULL) {
+            newfree(pCompPrivateStruct);
+            pCompPrivateStruct = NULL;
+        }
+
+        APP_MEMPRINT("%d :: App: [TESTAPPFREE] %p\n", __LINE__, audioinfo);
+
+        if (audioinfo != NULL) {
+            newfree(audioinfo);
+            audioinfo = NULL;
+        }
+
+        if (streaminfo != NULL) {
+            newfree(streaminfo);
+            streaminfo = NULL;
+        }
+
+        APP_IPRINT("%d :: App: Closing the Input and Output Pipes\n", __LINE__);
+        eError = close (IpBuf_Pipe[0]);
+
+        if (0 != eError && OMX_ErrorNone == eError) {
+            eError = OMX_ErrorHardware;
+            APP_DPRINT("%d :: Error while closing IpBuf_Pipe[0]\n", __LINE__);
+            goto EXIT;
+        }
+
+        eError = close (IpBuf_Pipe[1]);
+
+        if (0 != eError && OMX_ErrorNone == eError) {
+            eError = OMX_ErrorHardware;
+            APP_DPRINT("%d :: Error while closing IpBuf_Pipe[1]\n", __LINE__);
+            goto EXIT;
+        }
+
+        eError = close (OpBuf_Pipe[0]);
+
+        if (0 != eError && OMX_ErrorNone == eError) {
+            eError = OMX_ErrorHardware;
+            APP_DPRINT("%d :: Error while closing OpBuf_Pipe[0]\n", __LINE__);
+            goto EXIT;
+        }
+
+        eError = close (OpBuf_Pipe[1]);
+
+        if (0 != eError && OMX_ErrorNone == eError) {
+            eError = OMX_ErrorHardware;
+            APP_DPRINT("%d :: Error while closing OpBuf_Pipe[1]\n", __LINE__);
+            goto EXIT;
+        }
 
 
-	eError = close(Event_Pipe[0]);
-	if (0 != eError && OMX_ErrorNone == eError) {
-		eError = OMX_ErrorHardware;
-		APP_DPRINT("%d :: Error while closing Event_Pipe[0]\n",__LINE__);
-		goto EXIT;
-	}
-		
-	eError = close(Event_Pipe[1]);
-	if (0 != eError && OMX_ErrorNone == eError) {
-		eError = OMX_ErrorHardware;
-		APP_DPRINT("%d :: Error while closing Event_Pipe[1]\n",__LINE__);
-		goto EXIT;
-	}
-	
-	
-	APP_IPRINT("%d :: App: Free the Component handle\n",__LINE__);
-    /* Unload the WBAMR Encoder Component */
-    eError = TIOMX_FreeHandle(pHandle);
-	if((eError != OMX_ErrorNone)) {
-		APP_DPRINT("%d :: Error in Free Handle function\n",__LINE__);
-		goto EXIT;
-	}
+        eError = close(Event_Pipe[0]);
+
+        if (0 != eError && OMX_ErrorNone == eError) {
+            eError = OMX_ErrorHardware;
+            APP_DPRINT("%d :: Error while closing Event_Pipe[0]\n", __LINE__);
+            goto EXIT;
+        }
+
+        eError = close(Event_Pipe[1]);
+
+        if (0 != eError && OMX_ErrorNone == eError) {
+            eError = OMX_ErrorHardware;
+            APP_DPRINT("%d :: Error while closing Event_Pipe[1]\n", __LINE__);
+            goto EXIT;
+        }
+
+
+        APP_IPRINT("%d :: App: Free the Component handle\n", __LINE__);
+        /* Unload the WBAMR Encoder Component */
+        eError = TIOMX_FreeHandle(pHandle);
+
+        if ((eError != OMX_ErrorNone)) {
+            APP_DPRINT("%d :: Error in Free Handle function\n", __LINE__);
+            goto EXIT;
+        }
 
 
 
 
-	APP_IPRINT("%d :: App: Free Handle returned Successfully\n",__LINE__);
-	
-	APP_DPRINT("%d :: Deleting %p\n",__LINE__,pCompPrivateStructGain);
-	newfree(pCompPrivateStructGain);
+        APP_IPRINT("%d :: App: Free Handle returned Successfully\n", __LINE__);
 
-#ifdef DSP_RENDERING_ON 
-    cmd_data.hComponent = pHandle;
-    cmd_data.AM_Cmd = AM_Exit;
+        APP_DPRINT("%d :: Deleting %p\n", __LINE__, pCompPrivateStructGain);
+        newfree(pCompPrivateStructGain);
 
-    if((write(wbamrencfdwrite, &cmd_data, sizeof(cmd_data)))<0)
-        APP_IPRINT("%d ::- send command to audio manager\n",__LINE__);
+#ifdef DSP_RENDERING_ON
+        cmd_data.hComponent = pHandle;
+        cmd_data.AM_Cmd = AM_Exit;
 
-    close(wbamrencfdwrite);
-    close(wbamrencfdread);
-#endif	
+        if ((write(wbamrencfdwrite, &cmd_data, sizeof(cmd_data))) < 0)
+            APP_IPRINT("%d ::- send command to audio manager\n", __LINE__);
+
+        close(wbamrencfdwrite);
+        close(wbamrencfdread);
+#endif
 
 
 
-	} /*Outer for loop ends here */
+    } /*Outer for loop ends here */
 
 
-	
-    APP_IPRINT("%d :: *********************************************************************\n",__LINE__);
-    APP_IPRINT("%d :: NOTE: An output file %s has been created in file system\n",__LINE__,argv[2]);
-    APP_IPRINT("%d :: *********************************************************************\n",__LINE__);
-    
-    eError = TIOMX_Deinit(); 
-    if( (eError != OMX_ErrorNone)) {
-			APP_DPRINT("APP: Error in Deinit Core function\n");
-			goto EXIT;
+
+    APP_IPRINT("%d :: *********************************************************************\n", __LINE__);
+    APP_IPRINT("%d :: NOTE: An output file %s has been created in file system\n", __LINE__, argv[2]);
+    APP_IPRINT("%d :: *********************************************************************\n", __LINE__);
+
+    eError = TIOMX_Deinit();
+
+    if ( (eError != OMX_ErrorNone)) {
+        APP_DPRINT("APP: Error in Deinit Core function\n");
+        goto EXIT;
     }
 
-	pthread_mutex_destroy(&WaitForState_mutex);
+    pthread_mutex_destroy(&WaitForState_mutex);
     pthread_cond_destroy(&WaitForState_threshold);
 
 EXIT:
-	if(bInvalidState==OMX_TRUE)
-	{
+
+    if (bInvalidState == OMX_TRUE) {
 #ifndef USE_BUFFER
-		eError = FreeAllResources(pHandle,
-								pInputBufferHeader[0],
-								pOutputBufferHeader[0],
-								numOfInputBuffer,
-								numOfOutputBuffer,
-								fIn,
-                                fOut);
+        eError = FreeAllResources(pHandle,
+                                  pInputBufferHeader[0],
+                                  pOutputBufferHeader[0],
+                                  numOfInputBuffer,
+                                  numOfOutputBuffer,
+                                  fIn,
+                                  fOut);
 #else
-		eError = FreeAllResources(pHandle,
-									pInputBuffer,
-									pOutputBuffer,
-									numOfInputBuffer,
-									numOfOutputBuffer,
-									fIn,
-                                    fOut);
+        eError = FreeAllResources(pHandle,
+                                  pInputBuffer,
+                                  pOutputBuffer,
+                                  numOfInputBuffer,
+                                  numOfOutputBuffer,
+                                  fIn,
+                                  fOut);
 #endif
-   }
-   
-#ifdef APP_DEBUGMEM    
-    APP_IPRINT("\n-Printing memory not deleted-\n");
-    for(i=0;i<500;i++){
-        if (lines[i]!=0){
-             APP_IPRINT(" --->%d Bytes allocated on File:%s Line: %d\n",bytes[i],file[i],lines[i]); 
-             }
     }
+
+#ifdef APP_DEBUGMEM
+    APP_IPRINT("\n-Printing memory not deleted-\n");
+
+    for (i = 0; i < 500; i++) {
+        if (lines[i] != 0) {
+            APP_IPRINT(" --->%d Bytes allocated on File:%s Line: %d\n", bytes[i], file[i], lines[i]);
+        }
+    }
+
 #endif
 
 #ifdef OMX_GETTIME
-	GT_END("WBAMR_ENC test <End>");
-	OMX_ListDestroy(pListHead);	
+    GT_END("WBAMR_ENC test <End>");
+    OMX_ListDestroy(pListHead);
 #endif
     return eError;
 }
 
 
-OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn)
-{
-	OMX_ERRORTYPE error = OMX_ErrorNone;
-	OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle; 
+OMX_ERRORTYPE send_input_buffer(OMX_HANDLETYPE pHandle, OMX_BUFFERHEADERTYPE* pBuffer, FILE *fIn) {
+    OMX_ERRORTYPE error = OMX_ErrorNone;
+    OMX_COMPONENTTYPE *pComponent = (OMX_COMPONENTTYPE *)pHandle;
 
-	if(FirstTime){
-		if(mframe){
-			nRead = fread(pBuffer->pBuffer, 1, WBAPP_INPUT_BUFFER_SIZE*2, fIn);
-		}
-		else{
-			nRead = fread(pBuffer->pBuffer, 1, WBAPP_INPUT_BUFFER_SIZE, fIn);
-		}		
-		pBuffer->nFilledLen = nRead;
-	}
-	else{
-		memcpy(pBuffer->pBuffer, NextBuffer,nRead);
-		pBuffer->nFilledLen = nRead;
-	}
-	
-	if(mframe){
-			nRead = fread(NextBuffer, 1, WBAPP_INPUT_BUFFER_SIZE*2, fIn);
-	}
-	else{
-			nRead = fread(NextBuffer, 1, WBAPP_INPUT_BUFFER_SIZE, fIn);
-	}	
-	
-	if(nRead < WBAPP_INPUT_BUFFER_SIZE && !DasfMode){
-
-	#ifdef OMX_GETTIME
-		GT_START();
-	#endif
-		error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
-    	error = WaitForState(pHandle, OMX_StateIdle);
-	#ifdef OMX_GETTIME
-		GT_END("Call to SendCommand <OMX_StateIdle>");
-	#endif
-		if(error != OMX_ErrorNone) {
-			APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n",__LINE__);
-			goto EXIT;
-		}
-		
-		pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
-	}else{
-          pBuffer->nFlags = 0;
-	}
-		
-	if(pBuffer->nFilledLen!=0){
-    	if(pBuffer->nFlags == OMX_BUFFERFLAG_EOS){
-                           APP_IPRINT("Sending Last Input Buffer from App\n");
+    if (FirstTime) {
+        if (mframe) {
+            nRead = fread(pBuffer->pBuffer, 1, WBAPP_INPUT_BUFFER_SIZE * 2, fIn);
+        } else {
+            nRead = fread(pBuffer->pBuffer, 1, WBAPP_INPUT_BUFFER_SIZE, fIn);
         }
+
+        pBuffer->nFilledLen = nRead;
+    } else {
+        memcpy(pBuffer->pBuffer, NextBuffer, nRead);
+        pBuffer->nFilledLen = nRead;
+    }
+
+    if (mframe) {
+        nRead = fread(NextBuffer, 1, WBAPP_INPUT_BUFFER_SIZE * 2, fIn);
+    } else {
+        nRead = fread(NextBuffer, 1, WBAPP_INPUT_BUFFER_SIZE, fIn);
+    }
+
+    if (nRead < WBAPP_INPUT_BUFFER_SIZE && !DasfMode) {
+
+#ifdef OMX_GETTIME
+        GT_START();
+#endif
+        error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
+        error = WaitForState(pHandle, OMX_StateIdle);
+#ifdef OMX_GETTIME
+        GT_END("Call to SendCommand <OMX_StateIdle>");
+#endif
+
+        if (error != OMX_ErrorNone) {
+            APP_DPRINT ("%d :: Error from SendCommand-Idle(Stop) State function\n", __LINE__);
+            goto EXIT;
+        }
+
+        pBuffer->nFlags = OMX_BUFFERFLAG_EOS;
+    } else {
+        pBuffer->nFlags = 0;
+    }
+
+    if (pBuffer->nFilledLen != 0) {
+        if (pBuffer->nFlags == OMX_BUFFERFLAG_EOS) {
+            APP_IPRINT("Sending Last Input Buffer from App\n");
+        }
+
         pBuffer->nTimeStamp = rand() % 100;
 
-		if (!preempted) {		
-		    error = pComponent->EmptyThisBuffer(pHandle, pBuffer);
-	        if (error == OMX_ErrorIncorrectStateOperation) 
-					error = 0;		
-		}
+        if (!preempted) {
+            error = pComponent->EmptyThisBuffer(pHandle, pBuffer);
+
+            if (error == OMX_ErrorIncorrectStateOperation)
+                error = 0;
+        }
     }
-   	FirstTime=0;
+
+    FirstTime = 0;
 EXIT:
-	return error;	
+    return error;
 }
-OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle)
-{
+OMX_ERRORTYPE StopComponent(OMX_HANDLETYPE *pHandle) {
     OMX_ERRORTYPE error = OMX_ErrorNone;
 #ifdef OMX_GETTIME
-	GT_START();
+    GT_START();
 #endif
 
-	APP_IPRINT("%d :: APP: Sending Stop.........From APP \n",__LINE__);
+    APP_IPRINT("%d :: APP: Sending Stop.........From APP \n", __LINE__);
 
-	error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateIdle, NULL);
-	if(error != OMX_ErrorNone) {
-                    fprintf(stderr,"\nError from SendCommand-Idle(Stop) State function!!!!!!!!\n");
-                    goto EXIT;
-		}
-	error =	WaitForState(pHandle, OMX_StateIdle);
+    error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
+
+    if (error != OMX_ErrorNone) {
+        fprintf(stderr, "\nError from SendCommand-Idle(Stop) State function!!!!!!!!\n");
+        goto EXIT;
+    }
+
+    error = WaitForState(pHandle, OMX_StateIdle);
 #ifdef OMX_GETTIME
-	GT_END("Call to SendCommand <OMX_StateIdle>");
+    GT_END("Call to SendCommand <OMX_StateIdle>");
 #endif
-    if(error != OMX_ErrorNone) {
-					fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
-					goto EXIT;
-	}
+
+    if (error != OMX_ErrorNone) {
+        fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
+        goto EXIT;
+    }
+
 EXIT:
     return error;
 }
 
-OMX_ERRORTYPE PauseComponent(OMX_HANDLETYPE *pHandle)
-{
+OMX_ERRORTYPE PauseComponent(OMX_HANDLETYPE *pHandle) {
     OMX_ERRORTYPE error = OMX_ErrorNone;
 #ifdef OMX_GETTIME
-	GT_START();
+    GT_START();
 #endif
-    error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StatePause, NULL);
-	if(error != OMX_ErrorNone) {
-                    fprintf (stderr,"\nError from SendCommand-Pause State function!!!!!!\n");
-                    goto EXIT;
-		}
-	error =	WaitForState(pHandle, OMX_StatePause);
+    error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StatePause, NULL);
+
+    if (error != OMX_ErrorNone) {
+        fprintf (stderr, "\nError from SendCommand-Pause State function!!!!!!\n");
+        goto EXIT;
+    }
+
+    error = WaitForState(pHandle, OMX_StatePause);
 
 #ifdef OMX_GETTIME
-	GT_END("Call to SendCommand <OMX_StatePause>");
+    GT_END("Call to SendCommand <OMX_StatePause>");
 #endif
-    if(error != OMX_ErrorNone) {
-					fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
-					goto EXIT;
-	}
+
+    if (error != OMX_ErrorNone) {
+        fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
+        goto EXIT;
+    }
+
 EXIT:
     return error;
 }
 
-OMX_ERRORTYPE PlayComponent(OMX_HANDLETYPE *pHandle)
-{
+OMX_ERRORTYPE PlayComponent(OMX_HANDLETYPE *pHandle) {
     OMX_ERRORTYPE error = OMX_ErrorNone;
 #ifdef OMX_GETTIME
-	GT_START();
+    GT_START();
 #endif
-    error = OMX_SendCommand(pHandle,OMX_CommandStateSet, OMX_StateExecuting, NULL);
-	if(error != OMX_ErrorNone) {
-                    fprintf (stderr,"\nError from SendCommand-Executing State function!!!!!!!\n");
-                    goto EXIT;
-		}
-	error =	WaitForState(pHandle, OMX_StateExecuting);
+    error = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
+
+    if (error != OMX_ErrorNone) {
+        fprintf (stderr, "\nError from SendCommand-Executing State function!!!!!!!\n");
+        goto EXIT;
+    }
+
+    error = WaitForState(pHandle, OMX_StateExecuting);
 #ifdef OMX_GETTIME
-	GT_END("Call to SendCommand <OMX_StateExecuting>");
+    GT_END("Call to SendCommand <OMX_StateExecuting>");
 #endif
-    if(error != OMX_ErrorNone) {
-					fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
-					goto EXIT;
-	}
+
+    if (error != OMX_ErrorNone) {
+        fprintf(stderr, "\nError:  WaitForState reports an error %X!!!!!!!\n", error);
+        goto EXIT;
+    }
+
 EXIT:
     return error;
 }
 /*=================================================================
 
-							Freeing All allocated resources
-							
+                            Freeing All allocated resources
+
 ==================================================================*/
 #ifndef USE_BUFFER
 int FreeAllResources( OMX_HANDLETYPE *pHandle,
-			                OMX_BUFFERHEADERTYPE* pBufferIn,
-			                OMX_BUFFERHEADERTYPE* pBufferOut,
-			                int NIB, int NOB,
-			                FILE* fileIn, FILE* fileOut)
-{
-	APP_IPRINT("%d::Freeing all resources by state invalid \n",__LINE__);
-	OMX_ERRORTYPE eError = OMX_ErrorNone;
-	OMX_U16 i; 
+                      OMX_BUFFERHEADERTYPE* pBufferIn,
+                      OMX_BUFFERHEADERTYPE* pBufferOut,
+                      int NIB, int NOB,
+                      FILE* fileIn, FILE* fileOut) {
+    APP_IPRINT("%d::Freeing all resources by state invalid \n", __LINE__);
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+    OMX_U16 i;
 
-	if(!DasfMode) {
-		for(i=0; i < NIB; i++) {
-			   APP_IPRINT("%d :: APP: About to free pInputBufferHeader[%d]\n",__LINE__, i);
-			   eError = OMX_FreeBuffer(pHandle, OMX_DirInput, pBufferIn+i);
+    if (!DasfMode) {
+        for (i = 0; i < NIB; i++) {
+            APP_IPRINT("%d :: APP: About to free pInputBufferHeader[%d]\n", __LINE__, i);
+            eError = OMX_FreeBuffer(pHandle, OMX_DirInput, pBufferIn + i);
 
-		}
-	}
+        }
+    }
 
-	for(i=0; i < NOB; i++) {
-		   APP_IPRINT("%d :: APP: About to free pOutputBufferHeader[%d]\n",__LINE__, i);
-		   eError = OMX_FreeBuffer(pHandle, OMX_DirOutput, pBufferOut+i);
-	}
+    for (i = 0; i < NOB; i++) {
+        APP_IPRINT("%d :: APP: About to free pOutputBufferHeader[%d]\n", __LINE__, i);
+        eError = OMX_FreeBuffer(pHandle, OMX_DirOutput, pBufferOut + i);
+    }
 
-	/*i value is fixed by the number calls to malloc in the App */
-	for(i=0; i<5;i++)  
-	{
-		if (ArrayOfPointers[i] != NULL)
-			free(ArrayOfPointers[i]);
-	}
+    /*i value is fixed by the number calls to malloc in the App */
+    for (i = 0; i < 5; i++) {
+        if (ArrayOfPointers[i] != NULL)
+            free(ArrayOfPointers[i]);
+    }
 
-	TIOMX_FreeHandle(pHandle);
+    TIOMX_FreeHandle(pHandle);
 
-	return eError;
+    return eError;
 }
 
 
 /*=================================================================
 
-							Freeing the resources with USE_BUFFER define
-							
+                            Freeing the resources with USE_BUFFER define
+
 ==================================================================*/
 #else
 
 int FreeAllResources(OMX_HANDLETYPE *pHandle,
-							OMX_U8* UseInpBuf[],
-							OMX_U8* UseOutBuf[], 			
-							int NIB,int NOB,
-							FILE* fileIn, FILE* fileOut)
-{
+                     OMX_U8* UseInpBuf[],
+                     OMX_U8* UseOutBuf[],
+                     int NIB, int NOB,
+                     FILE* fileIn, FILE* fileOut) {
 
-		OMX_ERRORTYPE eError = OMX_ErrorNone;
-		OMX_U16 i; 
-		APP_IPRINT("%d::Freeing all resources by state invalid \n",__LINE__);
-    	/* free the UseBuffers */
-	    for(i=0; i < NIB; i++) {
-		   UseInpBuf[i] = UseInpBuf[i] - 128;
-		   APP_IPRINT("%d :: [TESTAPPFREE] pInputBuffer[%d] = %p\n",__LINE__,i,(UseInpBuf[i]));
-		   if(UseInpBuf[i] != NULL){
-			  newfree(UseInpBuf[i]);
-			  UseInpBuf[i] = NULL;
-		   }
-		}
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+    OMX_U16 i;
+    APP_IPRINT("%d::Freeing all resources by state invalid \n", __LINE__);
 
-	    for(i=0; i < NOB; i++) {
-		   UseOutBuf[i] = UseOutBuf[i] - 128;
-		   APP_IPRINT("%d :: [TESTAPPFREE] pOutputBuffer[%d] = %p\n",__LINE__,i, UseOutBuf[i]);
-		   if(UseOutBuf[i] != NULL){
-			  newfree(UseOutBuf[i]);
-			  UseOutBuf[i] = NULL;
-		   }
-		}
+    /* free the UseBuffers */
+    for (i = 0; i < NIB; i++) {
+        UseInpBuf[i] = UseInpBuf[i] - 128;
+        APP_IPRINT("%d :: [TESTAPPFREE] pInputBuffer[%d] = %p\n", __LINE__, i, (UseInpBuf[i]));
 
-	/*i value is fixed by the number calls to malloc in the App */
-		for(i=0; i<5;i++)  
-		{
-			if (ArrayOfPointers[i] != NULL)
-				free(ArrayOfPointers[i]);
-		}
-	
-		OMX_FreeHandle(pHandle);
-	
-		return eError;
+        if (UseInpBuf[i] != NULL) {
+            newfree(UseInpBuf[i]);
+            UseInpBuf[i] = NULL;
+        }
+    }
+
+    for (i = 0; i < NOB; i++) {
+        UseOutBuf[i] = UseOutBuf[i] - 128;
+        APP_IPRINT("%d :: [TESTAPPFREE] pOutputBuffer[%d] = %p\n", __LINE__, i, UseOutBuf[i]);
+
+        if (UseOutBuf[i] != NULL) {
+            newfree(UseOutBuf[i]);
+            UseOutBuf[i] = NULL;
+        }
+    }
+
+    /*i value is fixed by the number calls to malloc in the App */
+    for (i = 0; i < 5; i++) {
+        if (ArrayOfPointers[i] != NULL)
+            free(ArrayOfPointers[i]);
+    }
+
+    OMX_FreeHandle(pHandle);
+
+    return eError;
 }
 
 #endif
diff --git a/omx/audio/src/openmax_il/wma_dec/inc/OMX_WmaDec_ComponentThread.h b/omx/audio/src/openmax_il/wma_dec/inc/OMX_WmaDec_ComponentThread.h
index 5615574..a0ce076 100644
--- a/omx/audio/src/openmax_il/wma_dec/inc/OMX_WmaDec_ComponentThread.h
+++ b/omx/audio/src/openmax_il/wma_dec/inc/OMX_WmaDec_ComponentThread.h
@@ -46,7 +46,7 @@
 
 /* ===========================================================  */
 /**
-*  ComponentThread()  Component thread
+*  WMADEC_ComponentThread()  Component thread
 * 
 *
 *  @param pThreadData		Thread data
@@ -55,7 +55,7 @@
 *
 */
 /*================================================================== */
-void* ComponentThread (void* pThreadData);
+void* WMADEC_ComponentThread (void* pThreadData);
 void WMAD_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
 
 #endif
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 4218d91..b00f2fe 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
@@ -44,10 +44,8 @@
 #define OMX_WMADECODER_H
 #include <pthread.h>
 
-#include <OMX_Component.h>
-#include <TIDspOmx.h>
 #include <OMX_TI_Common.h>
-#include <OMX_TI_Debug.h>
+#include <TIDspOmx.h>
 #include "LCML_DspCodec.h"
 #define _ERROR_PROPAGATION__ 
 
@@ -55,6 +53,10 @@
 #include "perf.h"
 #endif
 
+#ifdef RESOURCE_MANAGER_ENABLED
+#include <ResourceManagerProxyAPI.h>
+#endif
+
 #include <OMX_Component.h> 
 
 #ifndef ANDROID
@@ -336,18 +338,6 @@
  */
 /* ======================================================================= */
 #define WMADEC_DEFAULT_SAMPLEPERBLOCK 8704
-/* ======================================================================= */
-
-/**
- * @def    WMA_CACHE_ALIGN   Number of bytes for cache alignment
- */
-/* ======================================================================= */
-#define WMA_CACHE_ALIGN 128
-/**
- * @def    WMA_CACHE_ALIGN   Number of bytes for cache alignment
- */
-/* ======================================================================= */
-#define WMA_EXTRA_BYTES 256
 /**
  * @def    WMADEC_DEBUG   Turns debug messaging on and off
  */
@@ -361,12 +351,6 @@
 #undef WMADEC_MEMCHECK
 /* ======================================================================= */
 /**
- * @def    WMADEC_MEMDEBUG   Enable memory leaks debuf info
- */
-/* ======================================================================= */
-#undef WMADEC_MEMDEBUG 
-/* ======================================================================= */
-/**
  * @def    WMADEC_USN_DLL_NAME   USN DLL name
  */
 /* ======================================================================= */
@@ -446,50 +430,6 @@
 #define WMADEC_NUM_OF_PORTS 2
 /* ======================================================================= */
 /**
- *  M A C R O FOR ALLOCATE MEMORY 
- */
-/* ======================================================================= */
-#define WMAD_OMX_MALLOC(_pStruct_, _sName_)                             \
-    _pStruct_ = (_sName_*)newmalloc(sizeof(_sName_));                   \
-    if(_pStruct_ == NULL){                                              \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");                \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Malloc Failed\n",__LINE__);                       \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");                \
-        eError = OMX_ErrorInsufficientResources;                        \
-        goto EXIT;                                                      \
-    }                                                                   \
-    memset(_pStruct_,0,sizeof(_sName_));                                \
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Malloced = %p\n",__LINE__,_pStruct_);
-
-
-#define WMAD_OMX_MALLOC_SIZE(_ptr_, _size_,_name_)              \
-    _ptr_ = (_name_ *)newmalloc(_size_);                        \
-    if(_ptr_ == NULL){                                          \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");        \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "%d :: Malloc Failed\n",__LINE__);               \
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "***********************************\n");        \
-        eError = OMX_ErrorInsufficientResources;                \
-        goto EXIT;                                              \
-    }                                                           \
-    memset(_ptr_,0,_size_);                                     \
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: Malloced = %p\n",__LINE__,_ptr_);
-
-
-/* ======================================================================= */
-/**
- *  M A C R O FOR MEMORY FREE 
- */
-/* ======================================================================= */
-
-#define OMX_WMADECMEMFREE_STRUCT(_pStruct_)                     \
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: [FREE] %p\n",__LINE__,_pStruct_);    \
-    if(_pStruct_ != NULL){                                      \
-    	newfree(_pStruct_);                                     \
-        _pStruct_ = NULL;                                       \
-    }
-
-/* ======================================================================= */
-/**
  *  W M A       T Y P E S
  */
 /* ======================================================================= */
@@ -588,6 +528,7 @@
 typedef struct {
     /* Number of frames in a buffer */
     unsigned long ulFrameCount;
+    bool ulIsLastBuffer;
 }WMADEC_UAlgOutBufParamStruct;
 /* =================================================================================== */
 /**
@@ -613,6 +554,7 @@
     OMX_BUFFERHEADERTYPE *pBufHdr[MAX_NUM_OF_BUFS]; /* records buffer header send by client */ 
     OMX_U32 bufferOwner[MAX_NUM_OF_BUFS];
     OMX_U32 bBufferPending[MAX_NUM_OF_BUFS];
+    OMX_U8 EosFlagSent;
 };
 
 
@@ -860,8 +802,14 @@
 
     /** Flag to flush SN after EOS in order to process more buffers after EOS**/
     OMX_U8 SendAfterEOS;		
- 
+
+    OMX_U8 InputEosSet;
+
     OMX_BOOL bPreempted;
+
+#ifdef RESOURCE_MANAGER_ENABLED
+    RMPROXY_CALLBACKTYPE rmproxyCallback;
+#endif
 	
     /* Removing sleep() calls. Definition. */
 #ifndef UNDER_CE
@@ -927,6 +875,8 @@
 
     struct OMX_TI_Debug dbg;        
 
+    OMX_BUFFERHEADERTYPE *lastout;
+
 } WMADEC_COMPONENT_PRIVATE;
 /* ===========================================================  */
 /**
@@ -1291,7 +1241,7 @@
 OMX_ERRORTYPE WMADEC_TransitionToIdle(WMADEC_COMPONENT_PRIVATE *pComponentPrivate);
 /* ===========================================================  */
 /**
- *  ComponentThread()  Component thread
+ *  WMADEC_ComponentThread()  Component thread
  *
  *  @param pThreadData		Thread data
  *
@@ -1300,7 +1250,7 @@
  *
  */
 /*================================================================== */
-void* ComponentThread (void* pThreadData);
+void* WMADEC_ComponentThread (void* pThreadData);
  
 
 /* ======================================================================= */
@@ -1340,7 +1290,19 @@
 /*  =========================================================================*/
 OMX_ERRORTYPE WMADEC_Parser(OMX_U8* pBuffer, RCA_HEADER *pStreamData, struct OMX_TI_Debug dbg);
 
+/*  =========================================================================*/
+/*  func    WMADEC_HandleUSNError                                                                                    */
+/*                                                                                                                                              */
+/*  desc    Handles error messages returned by the dsp                                                        */
+/*                                                                                                                                              */
+/*@return n/a                                                                                                                           */
+/*                                                                                                                                              */
+/*  =========================================================================*/
+void WMADEC_HandleUSNError (WMADEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg);
 
+#ifdef RESOURCE_MANAGER_ENABLED
+void WMAD_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
+#endif
 
 #endif
 
diff --git a/omx/audio/src/openmax_il/wma_dec/src/Android.mk b/omx/audio/src/openmax_il/wma_dec/src/Android.mk
index dde59f8..56c3a45 100644
--- a/omx/audio/src/openmax_il/wma_dec/src/Android.mk
+++ b/omx/audio/src/openmax_il/wma_dec/src/Android.mk
@@ -1,4 +1,4 @@
-ifeq ($(BUILD_WMA_DECODER),1)
+ifeq ($(BUILD_WMA_DECODER),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -26,4 +26,4 @@
 LOCAL_MODULE:= libOMX.TI.WMA.decode

 
 include $(BUILD_SHARED_LIBRARY)
-endif
+endif

diff --git a/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDec_ComponentThread.c b/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDec_ComponentThread.c
index 51b8920..e35405f 100644
--- a/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDec_ComponentThread.c
+++ b/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDec_ComponentThread.c
@@ -69,12 +69,12 @@
 #include "OMX_WmaDec_Utils.h" 
 /* ================================================================================= */
 /**
-* @fn ComponentThread() Component thread
+* @fn WMADEC_ComponentThread() Component thread
 *
 *  @see         OMX_ComponentThread.h
 */
 /* ================================================================================ */
-void* ComponentThread (void* pThreadData)
+void* WMADEC_ComponentThread (void* pThreadData)
 {
     int status;
     struct timespec tv;
@@ -155,8 +155,6 @@
                                                      0,
                                                      "Error from Component Thread in select");
             eError = OMX_ErrorInsufficientResources;
-            break;
-
         } 
         else if (FD_ISSET (pComponentPrivate->dataPipe[0], &rfds)) {
             OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: DATA pipe is set in Component Thread\n",__LINE__);
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
old mode 100644
new mode 100755
index 9211c88..7625e5f
--- 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
@@ -44,7 +44,7 @@
  *!
  *!
  *! 10-Sept-2005 mf:
- *! This is newest file
+ *! This is newest file 
  * =========================================================================== */
 
 
@@ -90,14 +90,6 @@
 }
 #endif
 
-#ifdef WMADEC_MEMDEBUG
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
 /* ========================================================================== */
 /**
  * @WMADECFill_LCMLInitParams () This function is used by the component thread to
@@ -125,7 +117,6 @@
     OMX_U16 index;
     LCML_WMADEC_BUFHEADERTYPE *pTemp_lcml = NULL;
     LCML_STRMATTR *strmAttr = NULL;
-    char *pTemp_char = NULL;
     LCML_DSP_INTERFACE *pHandle;
     WMADEC_COMPONENT_PRIVATE *pComponentPrivate, *pComponentPrivate_CC;
 
@@ -180,28 +171,15 @@
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
     plcml_Init->DeviceInfo.TypeofDevice =0;
     
-    WMAD_OMX_MALLOC_SIZE(pComponentPrivate->pDynParams, sizeof(WMADEC_UALGParams) + 256,WMADEC_UALGParams);
-    pTemp_char = (char*)pComponentPrivate->pDynParams;
-    pTemp_char += 128;
-    pComponentPrivate->pDynParams = (WMADEC_UALGParams*)pTemp_char;    
+    OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pDynParams, sizeof(WMADEC_UALGParams), WMADEC_UALGParams);
 
     pComponentPrivate->first_buffer=1;
     
     if(pComponentPrivate_CC->dasfmode == 1)
     {
-        WMAD_OMX_MALLOC_SIZE(pComponentPrivate->pParams, sizeof(WMADEC_AudioCodecParams) + 256, WMADEC_AudioCodecParams);
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pComponentPrivate->pParams);
-        if(NULL == pComponentPrivate->pParams)
-        {
-            OMX_ERROR4(pComponentPrivate->dbg, "Memory Allocation Failed");
-            eError = OMX_ErrorInsufficientResources;
-            goto EXIT;                          
-        }
-        pTemp_char = (char*)pComponentPrivate->pParams;
-        pTemp_char += 128;
-        pComponentPrivate->pParams = (WMADEC_AudioCodecParams*)pTemp_char;
+        OMX_MALLOC_SIZE_DSPALIGN(pComponentPrivate->pParams, sizeof(WMADEC_AudioCodecParams), WMADEC_AudioCodecParams);
     
-        WMAD_OMX_MALLOC(strmAttr, LCML_STRMATTR);
+        OMX_MALLOC_GENERIC(strmAttr, LCML_STRMATTR);
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,strmAttr);
 
         if (strmAttr == NULL)
@@ -299,13 +277,13 @@
 
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
     size_lcml = nIpBuf * sizeof(LCML_WMADEC_BUFHEADERTYPE);
-    WMAD_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml);
     OMX_PRDSP2(pComponentPrivate->dbg, "Line %d::pTemp_lcml = %p",__LINE__,pTemp_lcml);
     if(pTemp_lcml == NULL)
     {
         /* Free previously allocated memory before bailing */
-        OMX_WMADECMEMFREE_STRUCT(strmAttr);
+        OMX_MEMFREE_STRUCT(strmAttr);
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
@@ -331,20 +309,14 @@
         pTemp->nTickCount = NOT_USED;
         pTemp_lcml->buffer = pTemp;
         pTemp_lcml->eDir = OMX_DirInput;
-        WMAD_OMX_MALLOC_SIZE(pTemp_lcml->pIpParam, 
-                             sizeof(WMADEC_UAlgInBufParamStruct) + 256,
+        OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam, 
+                             sizeof(WMADEC_UAlgInBufParamStruct),
                              WMADEC_UAlgInBufParamStruct);
-        pTemp_char = (char*)pTemp_lcml->pIpParam;
-        pTemp_char += 128;
-        pTemp_lcml->pIpParam = (WMADEC_UAlgInBufParamStruct*)pTemp_char;
-        
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml->pIpParam);
         if (pTemp_lcml->pIpParam == NULL)
         {
             /* Free previously allocated memory before bailing */
-            OMX_WMADECMEMFREE_STRUCT(strmAttr);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:::[FREE] %p",__LINE__,pTemp_lcml);
-            OMX_WMADECMEMFREE_STRUCT(pTemp_lcml );
+            OMX_MEMFREE_STRUCT(strmAttr);
+            OMX_MEMFREE_STRUCT(pTemp_lcml );
 
             goto EXIT;
         }
@@ -360,16 +332,20 @@
     /* Allocate memory for all output buffer headers..
      * This memory pointer will be sent to LCML */
     size_lcml = pComponentPrivate_CC->pOutputBufferList->numBuffers * sizeof(LCML_WMADEC_BUFHEADERTYPE);
-    WMAD_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
+    OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml);
     if(pTemp_lcml == NULL)
     {
         /* Free previously allocated memory before bailing */
-        OMX_WMADECMEMFREE_STRUCT(strmAttr);
+        OMX_MEMFREE_STRUCT(strmAttr);
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
     pComponentPrivate_CC->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
+
+    pComponentPrivate_CC->pOutputBufferList->EosFlagSent      = 0;
+    pComponentPrivate_CC->InputEosSet = 0;
+
     for (i=0; i<nOpBuf; i++)
     {
         pTemp = pComponentPrivate_CC->pOutputBufferList->pBufHdr[i];
@@ -470,10 +446,10 @@
     /* Create the Component Thread */
 #ifdef UNDER_CE     
     eError = pthread_create (&(pComponentPrivate->ComponentThread), &attr, 
-                             ComponentThread, pComponentPrivate);
+                             WMADEC_ComponentThread, pComponentPrivate);
 #else   
     eError = pthread_create (&(pComponentPrivate->ComponentThread), NULL,
-                             ComponentThread, pComponentPrivate);
+                             WMADEC_ComponentThread, pComponentPrivate);
 #endif
     if (eError || !pComponentPrivate->ComponentThread)
     {
@@ -482,6 +458,14 @@
     }
     pComponentPrivate->bCompThreadStarted = 1;
  EXIT:
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -578,9 +562,7 @@
             OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
             OMX_PRCOMM2(pComponentPrivate->dbg, "freeing pComponentPrivate->pPortDef[INPUT_PORT] = \
                           %p",pComponentPrivate->pPortDef[INPUT_PORT]);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,
-                            pComponentPrivate->pPortDef[INPUT_PORT]);
-            OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pPortDef[INPUT_PORT]);
+            OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[INPUT_PORT]);
         }
         OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
 
@@ -589,18 +571,14 @@
             OMX_PRINT1(pComponentPrivate->dbg, "%d:::[WMADEC_FreeCompResources] ", __LINE__);
             OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[OUTPUT_PORT] = %p",
                           pComponentPrivate->pPortDef[OUTPUT_PORT]);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,
-                            pComponentPrivate->pPortDef[OUTPUT_PORT]);
-            OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pPortDef[OUTPUT_PORT]);
+            OMX_MEMFREE_STRUCT(pComponentPrivate->pPortDef[OUTPUT_PORT]);
         }
 
         if (pComponentPrivate->wmaParams[INPUT_PORT])
         {
             OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->wmaParams[INPUT_PORT] = %p",
                           pComponentPrivate->wmaParams[INPUT_PORT]);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,
-                            pComponentPrivate->wmaParams[INPUT_PORT]);
-            OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->wmaParams[INPUT_PORT]);
+            OMX_MEMFREE_STRUCT(pComponentPrivate->wmaParams[INPUT_PORT]);
         }
 
         if (pComponentPrivate->wmaParams[OUTPUT_PORT])
@@ -609,9 +587,7 @@
                           pComponentPrivate->wmaParams[OUTPUT_PORT]);
             OMX_PRCOMM2(pComponentPrivate->dbg, "wmaParams[OUTPUT_PORT]->nPortIndex = %ld",
                           pComponentPrivate->wmaParams[OUTPUT_PORT]->nPortIndex);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,
-                            pComponentPrivate->wmaParams[OUTPUT_PORT]);
-            OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->wmaParams[OUTPUT_PORT]);
+            OMX_MEMFREE_STRUCT(pComponentPrivate->wmaParams[OUTPUT_PORT]);
             OMX_PRCOMM2(pComponentPrivate->dbg, "after pComponentPrivate->wmaParams[OUTPUT_PORT] = \
                           %p",pComponentPrivate->wmaParams[OUTPUT_PORT]);
         }
@@ -666,40 +642,14 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 nIpBuf = 0;
     OMX_U16 i=0;
-    char *pTemp = NULL;    
 
-    if (pComponentPrivate->strmAttr)
-    {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,pComponentPrivate->strmAttr);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->strmAttr);
 
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->strmAttr);
-    }
+    OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pDynParams, WMADEC_UALGParams);
 
-    if(pComponentPrivate->pDynParams)
-    {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, ":: [FREE]: pComponentPrivate->pDynParams = %p",
-                        pComponentPrivate->pDynParams);
-                        
-        pTemp = (char*)pComponentPrivate->pDynParams;
-        if (pTemp != NULL)
-        {
-            pTemp -= 128;
-        }
-        pComponentPrivate->pDynParams = (WMADEC_UALGParams*)pTemp;
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pDynParams);
-    }
     if (pComponentPrivate->dasfmode == 1)
     {
-        OMX_PRBUFFER2(pComponentPrivate->dbg, ":: [FREE]: pComponentPrivate->pParams = %p",
-                        pComponentPrivate->pParams);
-                        
-        pTemp = (char*)pComponentPrivate->pParams;
-        if (pTemp != NULL)
-        {       
-            pTemp -= 128;
-        }
-        pComponentPrivate->pParams = (WMADEC_AudioCodecParams*)pTemp;        
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pParams);
+        OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pParams, WMADEC_AudioCodecParams);
     }    
     
     nIpBuf = pComponentPrivate->nRuntimeInputBuffers;
@@ -710,15 +660,7 @@
         for(i=0; i<nIpBuf; i++)
         {
             OMX_PRDSP2(pComponentPrivate->dbg, "freeing pTemp_lcml->pIpParam = %p", pTemp_lcml->pIpParam);
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,pTemp_lcml->pIpParam);
-            
-            pTemp = (char*)pTemp_lcml->pIpParam;
-            if(pTemp != NULL){
-                pTemp -= 128;
-            }
-            pTemp_lcml->pIpParam = (WMADEC_UAlgInBufParamStruct*)pTemp;
-       
-            OMX_WMADECMEMFREE_STRUCT(pTemp_lcml->pIpParam);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pTemp_lcml->pIpParam, WMADEC_UAlgInBufParamStruct);
             pTemp_lcml++;
         }
     }
@@ -728,14 +670,14 @@
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,
                     pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
                     
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[INPUT_PORT]);
     OMX_PRCOMM2(pComponentPrivate->dbg, "freeing pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = %p",
                   pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
                   
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p",__LINE__,
                     pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
                     
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT]);
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting Successfully WMADEC_CleanupInitParams()");
     return eError;
 }
@@ -814,8 +756,7 @@
     OMX_U32 commandData;
     char *pArgs = "damedesuStr";
 #ifndef UNDER_CE
-    OMX_U16 i,j;
-    int numCalls;
+    OMX_U16 i;
 #endif
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     LCML_DSP_INTERFACE *pLcmlHandle;
@@ -932,6 +873,10 @@
             OMX_PRSTATE2(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd OMX_StateMax::",
                           __LINE__);
             break;
+        default:
+            OMX_PRSTATE2(pComponentPrivate->dbg, "%d: WMADECHandleCommand: Cmd Unknown::",
+                          __LINE__);
+            break;
         } /* End of Switch */
 
     }
@@ -951,7 +896,7 @@
         if(commandData == 0x0){
             /* disable port */
             for (i=0; i < pComponentPrivate->pInputBufferList->numBuffers; i++) {
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->bBufferPending[%ld] = %d",i,
+                OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->pInputBufferList->bBufferPending[%d] = %ld",i,
                               pComponentPrivate->pInputBufferList->bBufferPending[i]);
                 if (WMADEC_IsPending(pComponentPrivate,pComponentPrivate->pInputBufferList->pBufHdr[i],OMX_DirInput)) {
                     /* Real solution is flush buffers from DSP.  Until we have the ability to do that 
@@ -996,7 +941,6 @@
                 }
             }
         }
-        OMX_PRCOMM2(pComponentPrivate->dbg, "I'm here Line %d",__LINE__);
         OMX_PRCOMM2(pComponentPrivate->dbg, "commandData = %ld",commandData);
         OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated = %d",
                       pComponentPrivate->pPortDef[INPUT_PORT]->bPopulated);
@@ -1086,14 +1030,13 @@
             {
                 /* enable out port */
                 char *pArgs = "damedesuStr";
-                OMX_PRCOMM2(pComponentPrivate->dbg, "============SETTING OUTPUT PORT TO ENABLED====================");
                 pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = OMX_TRUE;
                 OMX_PRCOMM2(pComponentPrivate->dbg, "pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled = %d",
                               pComponentPrivate->pPortDef[OUTPUT_PORT]->bEnabled);
                 
                 if (pComponentPrivate->curState == OMX_StateExecuting && pComponentPrivate->bDspStoppedWhileExecuting){
                     pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
-                    OMX_PRDSP2(pComponentPrivate->dbg, "=========================CALLING CONTROL START AT POT ENABLE===========================");
+
                     eError = LCML_ControlCodec(
                                                ((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
                                                EMMCodecControlStart,(void *)pArgs);
@@ -1149,12 +1092,10 @@
                                                        OMX_CommandPortEnable,
                                                        OUTPUT_PORT, NULL);
                 if(pComponentPrivate->reconfigOutputPort){
-                    OMX_PRCOMM2(pComponentPrivate->dbg, "==============================We can send input buffers againg!=========================");
                     pComponentPrivate->reconfigOutputPort = 0;
                     WMADECFill_LCMLInitParamsEx(pHandle,commandData);
                 }          
 
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "=======Before sending pending buffers==============");
                 OMX_PRBUFFER2(pComponentPrivate->dbg, "pComponentPrivate->nNumInputBufPending=%ld",pComponentPrivate->nNumInputBufPending);
                 for (i=0; i < pComponentPrivate->nNumInputBufPending; i++){                
                     if (pComponentPrivate->pInputBufHdrPending[i]){
@@ -1303,6 +1244,14 @@
  EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Exiting WMADECHandleCommand Function",__LINE__);
     OMX_PRINT1(pComponentPrivate->dbg, "%d :: Returning %d",__LINE__,eError);
+    if (eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -1350,25 +1299,17 @@
         OMX_ERROR4(pComponentPrivate->dbg, "%d :: The PBufHeader is not found in the list", __LINE__);
         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", __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", __LINE__, __FUNCTION__);
-		}
-	goto EXIT;
-    }
 
     if (eDir == OMX_DirInput)
     {
-        pComponentPrivate->nUnhandledEmptyThisBuffers--;    
+        pComponentPrivate->nUnhandledEmptyThisBuffers--;
+        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", __LINE__, __FUNCTION__);
+            goto EXIT;
+        }
         pPortDefIn = pComponentPrivate->pPortDef[OMX_DirInput];
         if ( (pBufHeader->nFilledLen > 0) || (pBufHeader->nFlags & OMX_BUFFERFLAG_EOS))
         {
@@ -1518,8 +1459,10 @@
             if (pBufHeader->nFlags & OMX_BUFFERFLAG_EOS){
                 pLcmlHdr->pIpParam->bLastBuffer = 1;
                 pComponentPrivate->SendAfterEOS = 1;
+                pComponentPrivate->InputEosSet = 1;
+                pComponentPrivate->pOutputBufferList->EosFlagSent = 0;
                 OMX_PRINT1(pComponentPrivate->dbg, "%d :: OMX_WmaDec_Utils.c : pComponentPrivate->SendAfterEOS %d",__LINE__,pComponentPrivate->SendAfterEOS);
-            }
+             }
             /*Store tick count information*/
             pComponentPrivate->arrBufIndexTick[pComponentPrivate->IpBufindex] = pBufHeader->nTickCount;
             /* Store time stamp information */
@@ -1527,7 +1470,6 @@
             pComponentPrivate->IpBufindex++;
             pComponentPrivate->IpBufindex %= pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferCountActual;
             OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Output Buffer TimeStamp %lld", __LINE__, pComponentPrivate->arrBufIndex[pComponentPrivate->IpBufindex]);
-
 #ifdef ANDROID
             if(pComponentPrivate->first_buffer)
             {
@@ -1663,9 +1605,17 @@
     else if (eDir == OMX_DirOutput) 
     {
         pComponentPrivate->nUnhandledFillThisBuffers--;
+        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", __LINE__, __FUNCTION__);
+            goto EXIT;
+        }
         OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending output buffer to LCML ");
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d Comp:: Sending Emptied Output buffer=%p to LCML",
                        __LINE__,pBufHeader);
+
 #ifdef __PERF_INSTRUMENTATION__
         PERF_SendingFrame(pComponentPrivate_CC->pPERFcomp,
                           PREF(pBufHeader,pBuffer),
@@ -1693,21 +1643,21 @@
                                     eError = OMX_ErrorHardware;
                                     goto EXIT;
                                 }
-				pComponentPrivate->lcml_nOpBuf++;
+                            pComponentPrivate->lcml_nOpBuf++;
                             }
                         }
-		 } else{
-		   pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
+                } else{
+                     pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
 		   OMX_PRBUFFER2(pComponentPrivate->dbg, "Don't queue while doing a reconfig:: output buffer, num pending = %ld", pComponentPrivate->nNumOutputBufPending);
-		 }
+                }
              }else if (pComponentPrivate->curState == OMX_StatePause) {
-	       pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
+                 pComponentPrivate->pOutputBufHdrPending[pComponentPrivate->nNumOutputBufPending++] = pBufHeader;
              }
          }
          if (pComponentPrivate->bFlushOutputPortCommandPending) {
-	   OMX_SendCommand( pComponentPrivate->pHandle, OMX_CommandFlush, 1, NULL);
-	 }
-    }
+            OMX_SendCommand( pComponentPrivate->pHandle, OMX_CommandFlush, 1, NULL);
+         }
+     }
     else
     {
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d : BufferHeader %p, Buffer %p Unknown ..........",
@@ -1716,6 +1666,14 @@
     }
  EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "%d : Exiting from  WMADECHandleDataBuf_FromApp ",__LINE__);
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -1788,6 +1746,14 @@
     }
  EXIT:
     OMX_ERROR1(pComponentPrivate->dbg, "%d :: Exiting WMADECGetBufferDirection Function",__LINE__);
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -1941,7 +1907,6 @@
     LCML_WMADEC_BUFHEADERTYPE *pLcmlHdr;
     WMADEC_COMPONENT_PRIVATE *pComponentPrivate_CC = NULL;      
     OMX_COMPONENTTYPE *pHandle                                     = NULL;
-    OMX_U8 pending_buffers = OMX_FALSE;
 #ifdef WMADEC_DEBUG
     LCML_DSP_INTERFACE *phandle;
 #endif
@@ -1959,9 +1924,7 @@
     phandle = (LCML_DSP_INTERFACE *)args[6];
 #endif
     pLcmlHandle = (LCML_DSP_INTERFACE *)pComponentPrivate_CC->pLcmlHandle;
-    OMX_PRINT1(pComponentPrivate_CC->dbg, "======================RECEIVED SOME CALLBACK===============");
-    OMX_PRINT1(pComponentPrivate_CC->dbg, "[CURRENT STATE-------------------------------------->] %d",
-                  pComponentPrivate_CC->curState);
+
     switch(event)
     {
     case EMMCodecDspError:
@@ -2047,7 +2010,6 @@
         } 
         else if ((OMX_U32)args [0] == EMMCodecOuputBuffer)
         {
-            OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "=======================OUTPUT BUFFER PROCESSED========================");
             OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "%d :: Output: pBuffer = %p",__LINE__, pBuffer);
             if (!WMADEC_IsValid(pComponentPrivate_CC,pBuffer,OMX_DirOutput))
             {
@@ -2078,6 +2040,16 @@
                                   __LINE__);
                     goto EXIT;
                 }
+
+
+                if(pComponentPrivate_CC->InputEosSet || pComponentPrivate_CC->pOutputBufferList->EosFlagSent)
+                {
+                   OMX_PRDSP2(pComponentPrivate_CC->dbg, " EOS Flag OR INPUT EOS ");
+                   pComponentPrivate_CC->InputEosSet = 0;
+                   pComponentPrivate_CC->pOutputBufferList->EosFlagSent = 0;
+                   pLcmlHdr->buffer->nFlags |= OMX_BUFFERFLAG_EOS;
+                }
+
                 pLcmlHdr->buffer->nFilledLen = (OMX_U32)args[8];
             
                 OMX_PRBUFFER2(pComponentPrivate_CC->dbg, "pLcmlHdr->buffer->nFilledLen = %ld", pLcmlHdr->buffer->nFilledLen);
@@ -2165,7 +2137,7 @@
                                           PREF(pComponentPrivate_CC->pOutputBufHdrPending[i],pBuffer),
                                           PREF(pComponentPrivate_CC->pOutputBufHdrPending[i],nFilledLen),
                                           PERF_ModuleHLMM);
-#endif  
+#endif
                         pComponentPrivate_CC->cbInfo.FillBufferDone (pComponentPrivate_CC->pHandle,
                                                                      pComponentPrivate_CC->pHandle->pApplicationPrivate,
                                                                      pComponentPrivate_CC->pOutputBufHdrPending[i]
@@ -2200,6 +2172,7 @@
     } 
     else if(event == EMMCodecProcessingStoped)
     {
+
 	for (i = 0; i < pComponentPrivate_CC->nNumInputBufPending; i++) {
 		pComponentPrivate_CC->cbInfo.EmptyBufferDone (pComponentPrivate_CC->pHandle,
 				pComponentPrivate_CC->pHandle->pApplicationPrivate,
@@ -2215,13 +2188,13 @@
 		pComponentPrivate_CC->pOutputBufHdrPending[i] = NULL;
 	}
 	pComponentPrivate_CC->nNumOutputBufPending=0;
-        pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex);
+	pthread_mutex_lock(&pComponentPrivate_CC->codecStop_mutex);
         if(pComponentPrivate_CC->codecStop_waitingsignal == 0){
             pComponentPrivate_CC->codecStop_waitingsignal = 1;             
             pthread_cond_signal(&pComponentPrivate_CC->codecStop_threshold);
             OMX_PRCOMM2(pComponentPrivate_CC->dbg, "stop ack. received. stop waiting for sending disable command completed");
         }
-        pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
+	  pthread_mutex_unlock(&pComponentPrivate_CC->codecStop_mutex);
 
         if (!pComponentPrivate_CC->bNoIdleOnStop)
         {
@@ -2261,86 +2234,44 @@
     else if (event == EMMCodecDspError)
     {
 
+        switch ( (OMX_U32) args [4])
+        {
+            /* USN_ERR_NONE,: Indicates that no error encountered during execution of the command and the command execution completed succesfully.
+             * USN_ERR_WARNING,: Indicates that process function returned a warning. The exact warning is returned in Arg2 of this message.
+             * USN_ERR_PROCESS,: Indicates that process function returned a error type. The exact error type is returnd in Arg2 of this message.
+             * USN_ERR_PAUSE,: Indicates that execution of pause resulted in error.
+             * USN_ERR_STOP,: Indicates that execution of stop resulted in error.
+             * USN_ERR_ALGCTRL,: Indicates that execution of alg control resulted in error.
+             * USN_ERR_STRMCTRL,: Indiactes the execution of STRM control command, resulted in error.
+             * USN_ERR_UNKNOWN_MSG,: Indicates that USN received an unknown command. */
+
 #ifdef _ERROR_PROPAGATION__
-        for(i=0;i<9;i++)
-        {
-            OMX_PRINT2(pComponentPrivate_CC->dbg, "arg [%d] = %p ",i,args[i]);
-        }
-        /* Cheking for MMU_fault */
-        OMX_PRINT2(pComponentPrivate_CC->dbg, "Printing ERROR CODE args 4 =%d",(int)args[4]);
-        OMX_PRINT2(pComponentPrivate_CC->dbg, "Printing ERROR CODE args 5 =%d",(int)args[5]);
-        
-        if((args[4] == (void *)USN_ERR_UNKNOWN_MSG) && (args[5] == NULL))
-        {               
-            pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
-            pComponentPrivate_CC->curState = OMX_StateInvalid;
-            pHandle = pComponentPrivate_CC->pHandle;
-            pComponentPrivate_CC->cbInfo.EventHandler(pHandle, 
-                                                      pHandle->pApplicationPrivate,
-                                                      OMX_EventError,
-                                                      OMX_ErrorInvalidState, 
-                                                      OMX_TI_ErrorSevere,
-                                                      NULL);
-        }
-#endif
-        if (((int)args[4] == USN_ERR_WARNING) && 
-            ((int)args[5] == IUALG_WARN_PLAYCOMPLETED))
-        {
-            OMX_PRDSP2(pComponentPrivate_CC->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED",
-                          __LINE__);
+            case USN_ERR_PAUSE:
+            case USN_ERR_STOP:
+            case USN_ERR_ALGCTRL:
+            case USN_ERR_STRMCTRL:
+            case USN_ERR_UNKNOWN_MSG:
 
-            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),
-                                      0,
-                                      PERF_ModuleHLMM);
-#endif
-                    pComponentPrivate_CC->pOutputBufferList->pBufHdr[i]->nFilledLen = 0;
-
-                    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]);
-                    pComponentPrivate_CC->nOutStandingFillDones++;
-                    pending_buffers = OMX_TRUE;
-                }else{
-                  if((i == pComponentPrivate_CC->pOutputBufferList->numBuffers-1) && !pending_buffers){
-                    /*is last iteration and no pending buffers were found*/
-                    pending_buffers = OMX_FALSE;
-                  }
+                {
+                    pComponentPrivate_CC->bIsInvalidState=OMX_TRUE;
+                    pComponentPrivate_CC->curState = OMX_StateInvalid;
+                    pHandle = pComponentPrivate_CC->pHandle;
+                    pComponentPrivate_CC->cbInfo.EventHandler(pHandle,
+                            pHandle->pApplicationPrivate,
+                            OMX_EventError,
+                            OMX_ErrorInvalidState,
+                            OMX_TI_ErrorSevere,
+                            NULL);
                 }
-            }
-            if(!pComponentPrivate_CC->dasfmode)
-            {
-              if(!pending_buffers){
-                /*turning on EOS on last buffer queued (extra check)*/
-                    pComponentPrivate_CC->LastOutputBufferHdrQueued->nFlags |=
-                      OMX_BUFFERFLAG_EOS;
-                    pComponentPrivate_CC->cbInfo.FillBufferDone (pComponentPrivate_CC->pHandle,
-                                                                     pComponentPrivate_CC->pHandle->pApplicationPrivate,
-                                                                     pComponentPrivate_CC->LastOutputBufferHdrQueued);
-                                                                     }
-                pComponentPrivate_CC->cbInfo.EventHandler(
-                                                          pComponentPrivate_CC->pHandle,
-                                                          pComponentPrivate_CC->pHandle->pApplicationPrivate,
-                                                          OMX_EventBufferFlag,
-                                                          pComponentPrivate_CC->LastOutputBufferHdrQueued->nOutputPortIndex,
-                                                          pComponentPrivate_CC->LastOutputBufferHdrQueued->nFlags, (OMX_PTR)OMX_BUFFERFLAG_EOS);
+                break;
+#endif
 
-            } else
-            {
-#ifndef UNDER_CE
-                pComponentPrivate_CC->cbInfo.EventHandler(
-                                                          pComponentPrivate_CC->pHandle,
-                                                          pComponentPrivate_CC->pHandle->pApplicationPrivate,
-                                                          OMX_EventBufferFlag,
-                                                          (OMX_U32) NULL,
-                                                          OMX_BUFFERFLAG_EOS, (OMX_PTR)OMX_BUFFERFLAG_EOS);
-#endif              
-            }
+            case USN_ERR_WARNING:
+            case USN_ERR_PROCESS:
+                WMADEC_HandleUSNError (pComponentPrivate_CC, (OMX_U32)args[5]);
+                break;
+            default:
+                break;
         }
     }
     
@@ -2794,6 +2725,14 @@
         if(eError != OMX_ErrorNone)
         {
             OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error returned from LCML_Init() error = %d",__LINE__, eError);
+            /* send an event to client */
+            /* client should unload the component if the codec is not able to load */
+            pComponentPrivate->cbInfo.EventHandler (pHandle, 
+                                                pHandle->pApplicationPrivate,
+                                                OMX_EventError, 
+                                                eError,
+                                                OMX_TI_ErrorSevere,
+                                                NULL);
             goto EXIT;
         }
 #else
@@ -2977,6 +2916,14 @@
     }
 
  EXIT:
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 /* ================================================================================= */
@@ -3102,6 +3049,14 @@
 
     
  EXIT:
+    if (eError != OMX_ErrorNone && eError != EXIT_COMPONENT_THRD ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -3345,6 +3300,14 @@
                                             OMX_EventCmdComplete, OMX_CommandStateSet,
                                             pComponentPrivate->curState, NULL);
  EXIT:
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 
@@ -3411,9 +3374,26 @@
         goto EXIT;
     }
 
-    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
- EXIT:
+#ifdef RESOURCE_MANAGER_ENABLED
+/* notify RM that codec is paused, resources can be redistributed if needed */
+    eError = RMProxy_NewSendCommand(pHandle,
+                                      RMProxy_StateSet,
+                                      OMX_WMA_Decoder_COMPONENT,
+                                      OMX_StatePause,
+                                      1234,
+                                      NULL);
+#endif
 
+    OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c\n",__LINE__);
+ EXIT:
+    if (eError != OMX_ErrorNone ) {
+        pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               OMX_EventError,
+                                               eError,
+                                               OMX_TI_ErrorSevere,
+                                               NULL);
+    }
     return eError;
 }
 /* ================================================================================= */
@@ -3682,7 +3662,6 @@
     OMX_U16 i;
     OMX_BUFFERHEADERTYPE *pTemp;
     int size_lcml;
-    char *char_temp = NULL;
     LCML_WMADEC_BUFHEADERTYPE *pTemp_lcml = NULL;
     LCML_DSP_INTERFACE *pHandle = (LCML_DSP_INTERFACE *)pComponent;
     WMADEC_COMPONENT_PRIVATE *pComponentPrivate = pHandle->pComponentPrivate;
@@ -3705,7 +3684,7 @@
     if(indexport == 0 || indexport == -1){
         OMX_PRINT1(pComponentPrivate->dbg, "%d :: Comp: OMX_WmaDecUtils.c",__LINE__);
         size_lcml = nIpBuf * sizeof(LCML_WMADEC_BUFHEADERTYPE);
-        WMAD_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
+        OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml);
         OMX_PRDSP1(pComponentPrivate->dbg, "Line %d::pTemp_lcml = %p",__LINE__,pTemp_lcml);
     
@@ -3733,21 +3712,15 @@
             pTemp_lcml->buffer = pTemp;
             pTemp_lcml->eDir = OMX_DirInput;
 
-            WMAD_OMX_MALLOC_SIZE(pTemp_lcml->pIpParam, 
-                                 sizeof(WMADEC_UAlgInBufParamStruct)+256,
+            OMX_MALLOC_SIZE_DSPALIGN(pTemp_lcml->pIpParam, 
+                                 sizeof(WMADEC_UAlgInBufParamStruct),
                                  WMADEC_UAlgInBufParamStruct);
                              
-            char_temp = (char*)pTemp_lcml->pIpParam;
-            char_temp += 128;
-            pTemp_lcml->pIpParam = (WMADEC_UAlgInBufParamStruct*)char_temp;
-        
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml->pIpParam);
             if (pTemp_lcml->pIpParam == NULL)
             {
                 /* Free previously allocated memory before bailing */
                 if (pTemp_lcml != NULL) {
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:::[FREE] %p",__LINE__,pTemp_lcml);
-                    OMX_WMADECMEMFREE_STRUCT(pTemp_lcml);
+                    OMX_MEMFREE_STRUCT(pTemp_lcml);
                 }
 
                 OMX_ERROR4(pComponentPrivate->dbg, "%d :: Error: Malloc Failed...Exiting..",__LINE__);
@@ -3765,7 +3738,7 @@
         /* Allocate memory for all output buffer headers..
          * This memory pointer will be sent to LCML */
         size_lcml = nOpBuf * sizeof(LCML_WMADEC_BUFHEADERTYPE);
-        WMAD_OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
+        OMX_MALLOC_SIZE(pTemp_lcml, size_lcml, LCML_WMADEC_BUFHEADERTYPE);
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p",__LINE__,pTemp_lcml);
     
         if(pTemp_lcml == NULL)
@@ -3777,6 +3750,9 @@
     
         pComponentPrivate->pLcmlBufHeader[OUTPUT_PORT] = pTemp_lcml;
 
+        pComponentPrivate->pOutputBufferList->EosFlagSent = 0;
+        pComponentPrivate->InputEosSet = 0;
+
         for (i=0; i<nOpBuf; i++)
         {
             pTemp = pComponentPrivate->pOutputBufferList->pBufHdr[i];
@@ -3900,3 +3876,101 @@
     return eError;
 }
 
+/*  =========================================================================*/
+/*  func    WMADEC_HandleUSNError                                                                                    */
+/*                                                                                                                                              */
+/*  desc    Handles error messages returned by the dsp                                                        */
+/*                                                                                                                                              */
+/*@return n/a                                                                                                                           */
+/*                                                                                                                                              */
+/*  =========================================================================*/
+void WMADEC_HandleUSNError (WMADEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 arg)
+{
+    OMX_COMPONENTTYPE *pHandle = NULL;
+    OMX_U8 pending_buffers = OMX_FALSE;
+    OMX_U32 i;
+    switch (arg)
+    {
+        case IUALG_WARN_CONCEALED:
+        case IUALG_WARN_UNDERFLOW:
+        case IUALG_WARN_OVERFLOW:
+        case IUALG_WARN_ENDOFDATA:
+            OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error" );
+            /* all of these are informative messages, Algo can recover, no need to notify the
+             * IL Client at this stage of the implementation */
+            break;
+
+        case IUALG_WARN_PLAYCOMPLETED:
+            {
+                OMX_PRDSP2(pComponentPrivate->dbg, "%d :: GOT MESSAGE IUALG_WARN_PLAYCOMPLETED\n", __LINE__);
+                pComponentPrivate->pOutputBufferList->EosFlagSent = 1;
+                pComponentPrivate->cbInfo.EventHandler(
+                        pComponentPrivate->pHandle,
+                        pComponentPrivate->pHandle->pApplicationPrivate,
+                        OMX_EventBufferFlag,
+                        (OMX_U32) NULL,
+                        OMX_BUFFERFLAG_EOS, (OMX_PTR)OMX_BUFFERFLAG_EOS);
+            }
+            break;
+
+#ifdef _ERROR_PROPAGATION__
+        case IUALG_ERR_BAD_HANDLE:
+        case IUALG_ERR_DATA_CORRUPT:
+        case IUALG_ERR_NOT_SUPPORTED:
+        case IUALG_ERR_ARGUMENT:
+        case IUALG_ERR_NOT_READY:
+        case IUALG_ERR_GENERAL:
+
+            {
+                /* all of these are fatal messages, Algo can not recover
+                 * hence return an error */
+                OMX_ERROR4(pComponentPrivate->dbg,  "Algorithm Error, cannot recover" );
+                pComponentPrivate->bIsInvalidState=OMX_TRUE;
+                pComponentPrivate->curState = OMX_StateInvalid;
+                pHandle = pComponentPrivate->pHandle;
+                pComponentPrivate->cbInfo.EventHandler(pHandle,
+                        pHandle->pApplicationPrivate,
+                        OMX_EventError,
+                        OMX_ErrorInvalidState,
+                        OMX_TI_ErrorSevere,
+                        NULL);
+            }
+            break;
+#endif
+        default:
+            break;
+    }
+}
+
+
+#ifdef RESOURCE_MANAGER_ENABLED
+void WMAD_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData)
+{
+    OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
+    OMX_STATETYPE state = OMX_StateIdle;
+    OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
+    WMADEC_COMPONENT_PRIVATE *pCompPrivate = NULL;
+
+    pCompPrivate = (WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+
+    if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesPreempted) {
+        if (pCompPrivate->curState == OMX_StateExecuting ||
+            pCompPrivate->curState == OMX_StatePause) {
+            write (pCompPrivate->cmdPipe[1], &Cmd, sizeof(Cmd));
+            write (pCompPrivate->cmdDataPipe[1], &state ,sizeof(OMX_U32));
+
+            pCompPrivate->bPreempted = 1;
+        }
+    }
+    else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired){
+        pCompPrivate->cbInfo.EventHandler (
+                            pHandle, pHandle->pApplicationPrivate,
+                            OMX_EventResourcesAcquired, 0,0,
+                            NULL);
+
+
+    }
+
+}
+#endif
+
diff --git a/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDecoder.c b/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDecoder.c
index f1ff735..030c53f 100644
--- a/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDecoder.c
+++ b/omx/audio/src/openmax_il/wma_dec/src/OMX_WmaDecoder.c
@@ -71,7 +71,6 @@
 #include <dbapi.h>
 
 /*-------program files ----------------------------------------*/
-#include <OMX_Component.h>
 #include "OMX_WmaDec_Utils.h"
 /* interface with audio manager */
 #define FIFO1 "/dev/fifo.1"
@@ -85,25 +84,6 @@
 #endif
 #define WMA_DEC_ROLE "audio_decoder.wma"
 
-#ifdef WMADEC_MEMDEBUG
-void *arr[500];
-int lines[500];
-int bytes[500];
-char file[500][50];
-#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
-#define newfree(z) myfree(z,__LINE__,__FILE__)
-void * mymalloc(int line, char *s, int size);
-int myfree(void *dp, int line, char *s);
-#else
-#define newmalloc(x) malloc(x)
-#define newfree(z) free(z)
-#endif
-
- 
-/*FILE *fp = NULL;  /*For dumping buffest debugging ANDROID*/
-   
-   
-    
 /****************************************************************
  *  EXTERNAL REFERENCES NOTE : only use if not found in header file
  ****************************************************************/
@@ -236,7 +216,7 @@
 
  
     /*Allocate the memory for Component private data area */
-    WMAD_OMX_MALLOC(pHandle->pComponentPrivate, WMADEC_COMPONENT_PRIVATE);
+    OMX_MALLOC_GENERIC(pHandle->pComponentPrivate, WMADEC_COMPONENT_PRIVATE);
     ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->pHandle = pHandle;
 
     /* Initialize component data structures to default values */
@@ -245,9 +225,9 @@
 
     eError = OMX_ErrorNone;
  
-    WMAD_OMX_MALLOC(wma_ip, OMX_AUDIO_PARAM_WMATYPE);
-    WMAD_OMX_MALLOC(wma_op, OMX_AUDIO_PARAM_PCMMODETYPE);
-    WMAD_OMX_MALLOC(rcaheader, RCA_HEADER);
+    OMX_MALLOC_GENERIC(wma_ip, OMX_AUDIO_PARAM_WMATYPE);
+    OMX_MALLOC_GENERIC(wma_op, OMX_AUDIO_PARAM_PCMMODETYPE);
+    OMX_MALLOC_GENERIC(rcaheader, RCA_HEADER);
     
     ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->wma_op=wma_op;
     ((WMADEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate)->rcaheader=rcaheader;
@@ -257,7 +237,7 @@
 
  
     pComponentPrivate = pHandle->pComponentPrivate;
-    WMAD_OMX_MALLOC(pComponentPrivate->pInputBufferList, BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pInputBufferList, BUFFERLIST);
     OMX_DBG_INIT(pComponentPrivate->dbg, "OMX_DBG_WMADEC");
     
 #ifdef __PERF_INSTRUMENTATION__
@@ -273,17 +253,17 @@
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalOutputBufferAlloc = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsExternalInputBufferAlloc = OMX_FALSE;
     pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsMovableInputBuffers = OMX_FALSE; 
-    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_TRUE; 
-    pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_TRUE; 
+    pComponentPrivate->iPVCapabilityFlags.iOMXComponentSupportsPartialFrames = OMX_FALSE; 
+    pComponentPrivate->iPVCapabilityFlags.iOMXComponentCanHandleIncompleteFrames = OMX_FALSE; 
 #endif
     
     pComponentPrivate->pInputBufferList->numBuffers = 0; /* initialize number of buffers */
     pComponentPrivate->bDspStoppedWhileExecuting = OMX_FALSE;
-    WMAD_OMX_MALLOC(pComponentPrivate->pOutputBufferList, BUFFERLIST);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pOutputBufferList, BUFFERLIST);
  
     pComponentPrivate->pOutputBufferList->numBuffers = 0; /* initialize number of buffers */
-    WMAD_OMX_MALLOC(pComponentPrivate->pHeaderInfo, WMA_HeadInfo);
-    WMAD_OMX_MALLOC(pComponentPrivate->pDspDefinition, TI_OMX_DSP_DEFINITION);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pHeaderInfo, WMA_HeadInfo);
+    OMX_MALLOC_GENERIC(pComponentPrivate->pDspDefinition, TI_OMX_DSP_DEFINITION);
  
     /* Temporarily treat these as default values for Khronos tests */
     pComponentPrivate->pHeaderInfo->iPackets.dwLo           =   178 ;
@@ -368,7 +348,7 @@
     pComponentPrivate->sOutPortFormat.nIndex = 1;
     pComponentPrivate->sOutPortFormat.nPortIndex = OUTPUT_PORT;
     
-    WMAD_OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING), OMX_STRING);
+    OMX_MALLOC_SIZE(pComponentPrivate->sDeviceString, 100*sizeof(OMX_STRING), OMX_STRING);
 
     
     /* PCM format defaults */
@@ -424,8 +404,8 @@
 #endif
     /* Removing sleep() calls. Initialization.*/        
     
-    WMAD_OMX_MALLOC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
-    WMAD_OMX_MALLOC(pPortDef_op,OMX_PARAM_PORTDEFINITIONTYPE );
+    OMX_MALLOC_GENERIC(pPortDef_ip, OMX_PARAM_PORTDEFINITIONTYPE);
+    OMX_MALLOC_GENERIC(pPortDef_op,OMX_PARAM_PORTDEFINITIONTYPE );
 
     OMX_PRCOMM2(pComponentPrivate->dbg, "%d ::pPortDef_ip = %p\n", __LINE__,pPortDef_ip);
     OMX_PRCOMM2(pComponentPrivate->dbg, "%d ::pPortDef_op = %p\n", __LINE__,pPortDef_op);
@@ -441,7 +421,7 @@
     pPortDef_ip->nBufferCountMin = NUM_WMADEC_INPUT_BUFFERS;
     pPortDef_ip->eDir = OMX_DirInput;
     pPortDef_ip->bEnabled = OMX_TRUE;
-    pPortDef_ip->nBufferAlignment = WMA_CACHE_ALIGN;
+    pPortDef_ip->nBufferAlignment = DSP_CACHE_ALIGNMENT;
     pPortDef_ip->nBufferSize = INPUT_WMADEC_BUFFER_SIZE;
     pPortDef_ip->bPopulated = 0;
     pPortDef_ip->eDomain = OMX_PortDomainAudio;
@@ -450,7 +430,7 @@
     pPortDef_op->nPortIndex = 0x1;
     pPortDef_op->nBufferCountActual = NUM_WMADEC_OUTPUT_BUFFERS;
     pPortDef_op->nBufferCountMin = NUM_WMADEC_OUTPUT_BUFFERS;
-    pPortDef_op->nBufferAlignment = WMA_CACHE_ALIGN;
+    pPortDef_op->nBufferAlignment = DSP_CACHE_ALIGNMENT;
     pPortDef_op->eDir = OMX_DirOutput;
     pPortDef_op->bEnabled = OMX_TRUE;
     if(pComponentPrivate->pPortDef[OUTPUT_PORT]->nBufferSize == 0)
@@ -517,16 +497,16 @@
     OMX_PRINT2(pComponentPrivate->dbg, "%d ::OMX_ComponentInit - returning %d\n", __LINE__,eError);
     if(eError == OMX_ErrorInsufficientResources)
     {
-        OMX_WMADECMEMFREE_STRUCT(pPortDef_op);
-        OMX_WMADECMEMFREE_STRUCT(pPortDef_ip);
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pDspDefinition);
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pHeaderInfo);
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList); 
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
-        OMX_WMADECMEMFREE_STRUCT(wma_op);
-        OMX_WMADECMEMFREE_STRUCT(wma_ip);
-        OMX_WMADECMEMFREE_STRUCT(pHandle->pComponentPrivate);
+        OMX_MEMFREE_STRUCT(pPortDef_op);
+        OMX_MEMFREE_STRUCT(pPortDef_ip);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pDspDefinition);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pHeaderInfo);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList); 
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
+        OMX_MEMFREE_STRUCT(wma_op);
+        OMX_MEMFREE_STRUCT(wma_ip);
+        OMX_MEMFREE_STRUCT(pHandle->pComponentPrivate);
         
     }
     return eError;
@@ -1173,7 +1153,7 @@
     WMADEC_COMPONENT_PRIVATE *pComponentPrivate;
     TI_OMX_STREAM_INFO *streamInfo;
 
-    WMAD_OMX_MALLOC(streamInfo, TI_OMX_STREAM_INFO);
+    OMX_MALLOC_GENERIC(streamInfo, TI_OMX_STREAM_INFO);
     pComponentPrivate = (WMADEC_COMPONENT_PRIVATE *)
         (((OMX_COMPONENTTYPE*)hComp)->pComponentPrivate);
 
@@ -1605,19 +1585,19 @@
     /* close the pipe handles */
     WMADEC_FreeCompResources(pHandle);
     OMX_PRINT1(dbg, "%d ::After WMADEC_FreeCompResources\n",__LINE__);
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pHeaderInfo);
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pDspDefinition);
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->sDeviceString);
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->rcaheader);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pHeaderInfo);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pDspDefinition);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->sDeviceString);
+    OMX_MEMFREE_STRUCT(pComponentPrivate->rcaheader);
 #ifdef __PERF_INSTRUMENTATION__
     OMX_PRDSP1(dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
     PERF_Boundary(pComponentPrivate->pPERF,
                   PERF_BoundaryComplete | PERF_BoundaryCleanup);
     PERF_Done(pComponentPrivate->pPERF);
 #endif
-    OMX_WMADECMEMFREE_STRUCT(pComponentPrivate);
+    OMX_MEMFREE_STRUCT(pComponentPrivate);
     OMX_PRINT1(dbg, "%d ::After free(pComponentPrivate)\n",__LINE__);
     OMX_DBG_CLOSE(dbg);
     return eError;
@@ -1706,22 +1686,18 @@
 
     }
 
-    WMAD_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
 
     memset(pBufferHeader, 0x0, sizeof(OMX_BUFFERHEADERTYPE));
 
-    WMAD_OMX_MALLOC_SIZE(pBufferHeader->pBuffer, nSizeBytes + WMA_EXTRA_BYTES, OMX_U8);
-    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p\n",__LINE__,pBufferHeader->pBuffer);
+    OMX_MALLOC_SIZE_DSPALIGN(pBufferHeader->pBuffer, nSizeBytes, OMX_U8);
     if(NULL == pBufferHeader->pBuffer) {
 	    OMX_PRBUFFER2(pComponentPrivate->dbg, "%d :: Malloc Failed\n",__LINE__);
         if (pBufferHeader) {
-            OMX_WMADECMEMFREE_STRUCT(pBufferHeader);
+            OMX_MEMFREE_STRUCT(pBufferHeader);
         }
         goto EXIT;
     }
-    pBufferHeader->pBuffer += WMA_CACHE_ALIGN;
-
-
 
     if (nPortIndex == INPUT_PORT)
     {
@@ -1820,7 +1796,6 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     WMADEC_COMPONENT_PRIVATE * pComponentPrivate = NULL;
     OMX_BUFFERHEADERTYPE* buff;
-    OMX_U8* tempBuff;
     int i;
     int inputIndex = -1;
     int outputIndex = -1;
@@ -1865,11 +1840,7 @@
 
     if (inputIndex != -1) {
         if (pComponentPrivate->pInputBufferList->bufferOwner[inputIndex] == 1) {
-            tempBuff = pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer;
-            if (tempBuff != 0){
-                tempBuff -= WMA_CACHE_ALIGN;}
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,tempBuff);
-            OMX_WMADECMEMFREE_STRUCT(tempBuff);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]->pBuffer, OMX_U8);
         }
 #ifdef __PERF_INSTRUMENTATION__
         OMX_PRDSP1(pComponentPrivate->dbg, "PERF %d :: OMX_WmaDecoder.c\n",__LINE__);
@@ -1879,7 +1850,7 @@
                            PERF_ModuleMemory);
 #endif
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pInputBufferList->pBufHdr[inputIndex]);
         pComponentPrivate->pInputBufferList->numBuffers--;
             
         if (pComponentPrivate->pInputBufferList->numBuffers < 
@@ -1900,11 +1871,7 @@
     }
     else if (outputIndex != -1) {
         if (pComponentPrivate->pOutputBufferList->bufferOwner[outputIndex] == 1) {
-            tempBuff = pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer;
-            if (tempBuff != 0){
-                tempBuff -= WMA_CACHE_ALIGN;}
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,tempBuff);
-            OMX_WMADECMEMFREE_STRUCT(tempBuff);
+            OMX_MEMFREE_STRUCT_DSPALIGN(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]->pBuffer, OMX_U8);
         }
             
 #ifdef __PERF_INSTRUMENTATION__
@@ -1916,7 +1883,7 @@
 #endif
 
         OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[FREE] %p\n",__LINE__,pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
-        OMX_WMADECMEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
+        OMX_MEMFREE_STRUCT(pComponentPrivate->pOutputBufferList->pBufHdr[outputIndex]);
         pComponentPrivate->pOutputBufferList->numBuffers--;
     
         if (pComponentPrivate->pOutputBufferList->numBuffers < 
@@ -2069,7 +2036,7 @@
 #endif  
 
     OMX_PRINT1(pComponentPrivate->dbg, "Line %d\n",__LINE__); 
-    WMAD_OMX_MALLOC(pBufferHeader, OMX_BUFFERHEADERTYPE);
+    OMX_MALLOC_GENERIC(pBufferHeader, OMX_BUFFERHEADERTYPE);
     OMX_PRBUFFER2(pComponentPrivate->dbg, "%d:[ALLOC] %p\n",__LINE__,pBufferHeader);
 
     if (pBufferHeader == 0) {
@@ -2271,41 +2238,3 @@
 }
 #endif
 
-#ifdef WMADEC_MEMDEBUG
-void * mymalloc(int line, char *s, int size)
-{
-    void *p;    
-    int e=0;
-    p = malloc(size);
-    if(p==NULL){
-        OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
-    }
-    else{
-        while((lines[e]!=0)&& (e<500) ){
-            e++;
-        }
-        arr[e]=p;
-        lines[e]=line;
-        bytes[e]=size;
-        strcpy(file[e],s);
-        OMXDBG_PRINT(stderr, BUFFER, 2, 0, "Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
-    }
-    return p;
-}
-
-int myfree(void *dp, int line, char *s){
-    int q;
-    for(q=0;q<500;q++){
-        if(arr[q]==dp){
-            OMXDBG_PRINT(stderr, ERROR, 4, 0, "Deleting %d bytes on address %p, line %d file %s\n", bytes[q],dp, line, s);
-            free(dp);
-            dp = NULL;
-            lines[q]=0;
-            strcpy(file[q],"");
-            break;
-        }            
-    }    
-    if(500==q)
-    OMXDBG_PRINT(stderr, PRINT, 2, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
-}
-#endif
diff --git a/omx/audio/src/openmax_il/wma_dec/tests/Android.mk b/omx/audio/src/openmax_il/wma_dec/tests/Android.mk
index 9bd8f16..7970e6f 100644
--- a/omx/audio/src/openmax_il/wma_dec/tests/Android.mk
+++ b/omx/audio/src/openmax_il/wma_dec/tests/Android.mk
@@ -1,5 +1,4 @@
 ifeq ($(BUILD_WMA_DEC_TEST),1)

-

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

diff --git a/omx/audio/src/openmax_il/wma_dec/tests/WmaDecTest.c b/omx/audio/src/openmax_il/wma_dec/tests/WmaDecTest.c
index dd8fca3..b62d52a 100644
--- a/omx/audio/src/openmax_il/wma_dec/tests/WmaDecTest.c
+++ b/omx/audio/src/openmax_il/wma_dec/tests/WmaDecTest.c
@@ -67,7 +67,7 @@
     #include "OMX_GetTime.h"     /*Headers for Performance & measuremet    */
 #endif
   
-#define INPUT_WMADEC_BUFFER_SIZE 4096 * 2
+#define INPUT_WMADEC_BUFFER_SIZE 4096 * 4
 #define OUTPUT_WMADEC_BUFFER_SIZE 4096 * 10
 #define NUM_WMADEC_INPUT_BUFFERS 1
 #define NUM_WMADEC_OUTPUT_BUFFERS 1
@@ -79,7 +79,7 @@
 #define OMX_WMADEC_NonMIME 1
 #define MIME_HEADER_LEN 6
 #define WINDOW_PLAY_OFFSET 2
-#define APP_DEBUG
+#undef APP_DEBUG
 #undef APP_MEMCHECK
 #undef TWOINPUTBUFFERS
 #undef USE_BUFFER 
@@ -229,7 +229,7 @@
 
 int fill_data (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn);
 int fill_data_tc7 (OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn);
-
+int unParse_Header (OMX_U8* pBuffer, FILE *fIn, int * payload);
 void ConfigureAudio();
 
 OMX_STRING strWmaEncoder = "OMX.TI.WMA.decode";
@@ -1578,7 +1578,9 @@
     else {
         APP_DPRINT("Send input buffer nRead = %d\n",nRead);
         pBuffer->nFilledLen = nRead;
-        pBuffer->nFlags = 0;
+        if(!(pBuffer->nFlags & OMX_BUFFERFLAG_CODECCONFIG)){
+          pBuffer->nFlags = 0;
+        }
         pComponent->EmptyThisBuffer(pHandle, pBuffer);
     }
     return error;
@@ -1627,14 +1629,18 @@
     int nRead;
     OMX_U32 packetSize;
     OMX_U8 byteOffset;
+    static OMX_U8 first_cap = 0;
+    static OMX_U8 first_buff = 0;
     static int totalRead = 0;
     static int fileHdrReadFlag = 0;
     static int ccnt = 1;
-    
+    static int payload=0;
+    OMX_U8 temp = 0;
     nRead = 0;
     byteOffset = 0;
     if(frameMode)
     {
+      /* TODO: Update framemode TC to match component */
         if (!fileHdrReadFlag) {
             /*The first input buffer readed have the .rca header information*/
             nRead = fread(pBuf->pBuffer, 1, 70, fIn);
@@ -1651,7 +1657,22 @@
     }
     else
     {
-        nRead = fread(pBuf->pBuffer, 1, INPUT_WMADEC_BUFFER_SIZE, fIn);
+      if(first_buff){
+        if (first_cap){
+          fread(&temp,5,1,fIn); // moving file 5 bytes
+        }
+        first_cap =1;
+        nRead = fread(pBuf->pBuffer, 1, payload, fIn);
+        if(pBuf->nFlags & OMX_BUFFERFLAG_CODECCONFIG)
+        {
+          pBuf->nFlags = 0;
+        }
+      }
+      else{
+        nRead = unParse_Header(pBuf->pBuffer,fIn, &payload);
+        pBuf->nFlags = OMX_BUFFERFLAG_CODECCONFIG;
+        first_buff=1;
+      }
     }
     totalRead += nRead;
     pBuf->nFilledLen = nRead;
@@ -1741,7 +1762,6 @@
 
 void fill_init_params(OMX_HANDLETYPE pHandle,const char * filename,int dasfmode, TI_OMX_DATAPATH * dataPath)
 {
-    APP_DPRINT("Here\n");
     OMX_ERRORTYPE error = OMX_ErrorNone;
     WMA_HeadInfo* pHeaderInfo;
 	OMX_INDEXTYPE index;
@@ -2026,4 +2046,34 @@
 }
 
 #endif
+/* ================================================================================= */
+/**
+* @fn unParse_Header
+* To match Android OMX Component, wee need to extract the info from the rca pattern
+* to build the config buffer.
+*/
+/* ================================================================================ */
+int unParse_Header (OMX_U8* pBuffer, FILE *fIn, int * payload){
 
+  OMX_U8* tempBuffer= malloc(75);
+  memset(pBuffer,0x00,75);
+  memset(tempBuffer,0x00,75);
+  fread(tempBuffer,75,1,fIn);
+  tempBuffer+=42;
+  memcpy(pBuffer,tempBuffer,sizeof(OMX_U16));
+  tempBuffer+=2;
+  memcpy(pBuffer+2,tempBuffer,sizeof(OMX_U16));
+  tempBuffer+=2;
+  memcpy(pBuffer+4,tempBuffer,sizeof(OMX_U32));
+  tempBuffer+=4;
+  memcpy(pBuffer+8,tempBuffer,sizeof(OMX_U32));
+  tempBuffer+=4;
+  memcpy(pBuffer+12,tempBuffer,sizeof(OMX_U16));
+  tempBuffer+=2;
+  memcpy(pBuffer+14,tempBuffer,sizeof(OMX_U16));
+  tempBuffer+=8;
+  memcpy(pBuffer+22,tempBuffer,sizeof(OMX_U16));
+  tempBuffer += 7;
+  *payload = *((OMX_U16*)tempBuffer);
+  return 28;
+}
diff --git a/omx/core_plugin/omx_core_plugin/Android.mk b/omx/core_plugin/omx_core_plugin/Android.mk
index 222f0cb..ffdff71 100644
--- a/omx/core_plugin/omx_core_plugin/Android.mk
+++ b/omx/core_plugin/omx_core_plugin/Android.mk
@@ -1,5 +1,3 @@
-ifneq ($(BUILD_WITHOUT_PV),true)
-
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 LOCAL_PRELINK_MODULE := false
@@ -43,4 +41,3 @@
 
 include $(BUILD_SHARED_LIBRARY)
 
-endif
diff --git a/omx/image/src/openmax_il/jpeg_dec/Android.mk b/omx/image/src/openmax_il/jpeg_dec/Android.mk
index fa9347f..c9a4418 100644
--- a/omx/image/src/openmax_il/jpeg_dec/Android.mk
+++ b/omx/image/src/openmax_il/jpeg_dec/Android.mk
@@ -18,7 +18,7 @@
 	
 LOCAL_CFLAGS := $(TI_OMX_CFLAGS) -DOMAP_2430 #-DOMX_DEBUG
 
-LOCAL_MODULE:= libOMX.TI.JPEG.decode
+LOCAL_MODULE:= libOMX.TI.JPEG.decoder
 
 include $(BUILD_SHARED_LIBRARY)
 endif
@@ -32,7 +32,7 @@
 LOCAL_C_INCLUDES := $(TI_OMX_COMP_C_INCLUDES) \
 	$(TI_OMX_IMAGE)/jpeg_dec/inc \
 
-LOCAL_SHARED_LIBRARIES := libOMX.TI.JPEG.decode
+LOCAL_SHARED_LIBRARIES := libOMX.TI.JPEG.decoder
 
 LOCAL_CFLAGS := -Wall -fpic -pipe -O0 -DOMX_DEBUG=1
 
diff --git a/omx/image/src/openmax_il/jpeg_dec/inc/OMX_JpegDec_Utils.h b/omx/image/src/openmax_il/jpeg_dec/inc/OMX_JpegDec_Utils.h
index 61b8f2e..bb6880c 100644
--- a/omx/image/src/openmax_il/jpeg_dec/inc/OMX_JpegDec_Utils.h
+++ b/omx/image/src/openmax_il/jpeg_dec/inc/OMX_JpegDec_Utils.h
@@ -48,8 +48,11 @@
 #include <sys/time.h>
 #include <stdio.h>
 #include <errno.h>
-#include "OMX_TI_Common.h"
-#include "OMX_TI_Debug.h"
+#include <OMX_TI_Common.h>
+#include <OMX_TI_Debug.h>
+
+#include <utils/Log.h>
+#define LOG_TAG "OMX_JPGDEC"
 
 #ifdef RESOURCE_MANAGER_ENABLED
 #include <ResourceManagerProxyAPI.h>
@@ -237,7 +240,7 @@
 
 
 #define OMX_DPRINT_ADDRESS(_s_, _ptr_)  \
-    OMX_PRINT2((_pComponentPrivate_)->dbg, "%s = %p\n", _s_, _ptr_);
+    OMX_PRINT2(pComponentPrivate->dbg, "%s = %p\n", _s_, _ptr_);
 
 #ifdef RESOURCE_MANAGER_ENABLED
 #define OMX_GET_RM_VALUE(_Res_, _RM_) \
@@ -258,7 +261,7 @@
         _RM_ = 90;  \
         }   \
         \
-    OMX_PRMGR2((_pComponentPrivate_)->dbg, "Value in MHz requested to RM = %d\n",_RM_); \
+    OMX_PRMGR2(pComponentPrivate->dbg, "Value in MHz requested to RM = %d\n",_RM_); \
 }
 #endif
 
@@ -399,7 +402,7 @@
     OMX_PORT_PARAM_TYPE* pOtherPortType;
     /* Handle for use with async callbacks */
     OMX_CALLBACKTYPE cbInfo;
-    /*Component name OMX.TI.JPEG.decode*/
+    /*Component name OMX.TI.JPEG.decoder*/
     OMX_STRING      cComponentName;
     OMX_VERSIONTYPE ComponentVersion;
     OMX_VERSIONTYPE SpecVersion;
@@ -481,7 +484,7 @@
     OMX_U32 ulInFrameSize;      /*same as buffer size*/
     OMX_U32 ulInDisplayWidth;   /*Width of the buffer into which the image is to be decoded*/
     OMX_U32 ulInReserved0;      /*could be like thumbnail decode only*/
-    OMX_U32 ulInReserved1;      /*could be output format – later. Let’s fix it to 422 always now*/
+    OMX_U32 ulInReserved1;      /*could be output format � later. Let�s fix it to 422 always now*/
     OMX_U32 ulInReserved2;      /*could be post processing flag*/
     OMX_U32 ulInReserved3;
     OMX_U32 ulInResizeOption;   /*Rescale factor */
@@ -518,7 +521,7 @@
     OMX_U32 ulOutReserved0;
     OMX_U32 ulOutReserved1;
     OMX_U32 ulOutReserved2;
-    OMX_U32 lastMCU;            /* 1-Decoded all MCUÂ’s0 - Decoding not completed*/
+    OMX_U32 lastMCU;            /* 1-Decoded all MCU�s0 - Decoding not completed*/
     OMX_U32 stride[3];          /*Stride values for Y, U, and V components*/
     OMX_U32 ulOutputHeight;     /* Output Height */
     OMX_U32 ulOutputWidth;      /* Output Width*/
diff --git a/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDec_Thread.c b/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDec_Thread.c
index bd3e6c8..7ac8f8e 100644
--- a/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDec_Thread.c
+++ b/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDec_Thread.c
@@ -129,8 +129,7 @@
                                                    OMX_ErrorInsufficientResources,
                                                    OMX_TI_ErrorSevere,
                                                    "Error from COmponent Thread in select");
-            eError = OMX_ErrorInsufficientResources;
-            goto EXIT;
+	     eError = OMX_ErrorInsufficientResources;
         }
         else {
             if ((FD_ISSET(pComponentPrivate->nCmdPipe[0], &rfds)) ||
@@ -255,7 +254,7 @@
 #ifdef __PERF_INSTRUMENTATION__
     PERF_Done(pComponentPrivate->pPERFcomp);
 #endif
-    return(void*)eError;
+    return (void *)eError;
 
 }
 
diff --git a/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDec_Utils.c b/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDec_Utils.c
index 8497632..2b5367f 100644
--- a/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDec_Utils.c
+++ b/omx/image/src/openmax_il/jpeg_dec/src/OMX_JpegDec_Utils.c
@@ -137,7 +137,13 @@
     }
 
     /*calling gethandle and passing phandle to be filled */
-    eError = (*fpGetHandle)(&LCML_pHandle);
+    if ( fpGetHandle != NULL ) {
+        eError = (*fpGetHandle)(&LCML_pHandle);
+    }
+    else  {
+        eError = OMX_ErrorInvalidComponent;
+        goto EXIT;
+    }
     if (eError != OMX_ErrorNone) {
         eError = OMX_ErrorUndefined;
         OMX_PRDSP5(pComponentPrivate->dbg, "eError != OMX_ErrorNone... in (*fpGetHandle)(&LCML_pHandle);\n");
@@ -400,6 +406,7 @@
     OMX_COMMANDTYPE eCmd = OMX_CustomCommandStopThread;
     struct OMX_TI_Debug dbg;
 
+    OMX_DBG_INIT_BASE(dbg);
     if (!pComponentPrivate) {
 	OMXDBG_PRINT(stderr, ERROR, 5, 0, "pComponentPrivate is NULL.\n");
         goto EXIT;
@@ -569,11 +576,11 @@
     OMX_CHECK_PARAM(pComponent);
     pHandle = (OMX_COMPONENTTYPE *)pComponent;
     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
+
     pPortDefIn = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef;
     pPortDefOut = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef;
 
-    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-
     lcml_dsp->In_BufInfo.DataTrMethod = DMM_METHOD;
     lcml_dsp->Out_BufInfo.DataTrMethod = DMM_METHOD;
 
@@ -949,7 +956,7 @@
         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
         OMX_PRDSP2(pComponentPrivate->dbg, "eError %x\n", eError); 
         if (eError != OMX_ErrorNone) {
-            goto EXIT;
+            goto PRINT_EXIT;
         }
 #ifdef UNDER_CE
     nTimeOut = 0;
@@ -1012,7 +1019,7 @@
         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
 	OMX_PRDSP2(pComponentPrivate->dbg, "eError %x\n", eError); 
        if (eError != OMX_ErrorNone) {
-            goto EXIT;
+            goto PRINT_EXIT;
         }
 #ifdef UNDER_CE
         nTimeOut = 0;
@@ -1071,8 +1078,9 @@
                                        JPEGDEC_OUTPUT_PORT,
                                        NULL);
     }
-EXIT:
+PRINT_EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting HandleCommand nFlush Function\n");
+EXIT:
     return eError;
 
 }   /* End of HandleCommandFlush */
@@ -1167,14 +1175,14 @@
                 }
                 if(eError != OMX_ErrorNone){
                     OMX_PRBUFFER4(pComponentPrivate->dbg, "Port population time out\n");
-                    goto EXIT;
+                    goto PRINT_EXIT;
                 }
             }
 
             eError =  GetLCMLHandleJpegDec(pHandle);
             if (eError != OMX_ErrorNone) {
 		OMX_PRDSP5(pComponentPrivate->dbg, "GetLCMLHandle failed...\n");
-                goto EXIT;
+                goto PRINT_EXIT;
             }
 
             pLcmlHandle =(LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
@@ -1192,7 +1200,7 @@
             eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb);
             if (eError != OMX_ErrorNone) {
 	        OMX_PRDSP4(pComponentPrivate->dbg, "InitMMCodec failed...\n");
-                goto EXIT;
+                goto PRINT_EXIT;
             }
             else {
                 pComponentPrivate->nIsLCMLActive = 1;
@@ -1201,7 +1209,7 @@
             eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, EMMCodecControlUsnEos, NULL);
             if (eError != OMX_ErrorNone) {
                 OMX_PRDSP4(pComponentPrivate->dbg, "Enable EOS at LCML failed...\n");
-                goto EXIT;
+                goto PRINT_EXIT;
             }
             /* need check the resource with RM */
 
@@ -1525,7 +1533,7 @@
                 }
             }
             if (eError != OMX_ErrorNone){ /*Verify if UnPopulation compleate*/
-                goto EXIT;
+                goto PRINT_EXIT;
             }
 
 #ifdef RESOURCE_MANAGER_ENABLED
@@ -1617,8 +1625,9 @@
         break;
     } /* End of Switch */
 
-EXIT:
+PRINT_EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exiting HandleCommand Function %x\n", eError);
+EXIT:
     return eError;
 } 
   /* End of HandleCommandJpegDec */
@@ -1904,8 +1913,8 @@
     }
 
 
-EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exit\n");
+EXIT:
     return eError;
 }   /* End of HandleDataBuf_FromDspJpegDec */
 
@@ -1951,8 +1960,8 @@
                                               pBuffHead);
     }
 
-EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "JPEGexiting\n");
+EXIT:
     return eError;
 }   /* End of HandleFreeDataBufJpegDec */
 
@@ -2196,15 +2205,15 @@
     OMX_COMMANDTYPE Cmd = OMX_CommandStateSet;
     OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *)cbData.hComponent;
     JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
-    OMX_ERRORTYPE RM_Error = *(cbData.RM_Error);
+    OMX_ERRORTYPE eError = *(cbData.RM_Error);
     
     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 
     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1); 
 
-    OMX_PRINT1(pComponentPrivate->dbg, "RM_Error = %x\n", RM_Error);
+    OMX_PRINT1(pComponentPrivate->dbg, "RM_Error = %x\n", eError);
 
-    if (RM_Error == OMX_RmProxyCallback_ResourcesPreempted) {
+    if (eError == OMX_RmProxyCallback_ResourcesPreempted) {
 
         pComponentPrivate->bPreempted = 1;
         
@@ -2234,7 +2243,7 @@
         write (pComponentPrivate->nCmdDataPipe[1], &(pComponentPrivate->nToState) ,sizeof(OMX_U32));
         
     }
-    else if (RM_Error == OMX_RmProxyCallback_ResourcesAcquired ){
+    else if (eError == OMX_RmProxyCallback_ResourcesAcquired ){
 
         if (pComponentPrivate->nCurState == OMX_StateWaitForResources) /* Wait for Resource Response */
         {
@@ -2255,7 +2264,8 @@
         }            
         
     }
-
+    EXIT:
+        OMX_PRMGR2(pComponentPrivate->dbg, "OMX_RmProxyCallback exiting.\n");
 }
 #endif
 
@@ -2313,18 +2323,20 @@
 void LinkedList_AddElement(LinkedList *LinkedList, void *pValue) {
     /* create new node and fill the value */
     Node *pNewNode = (Node *)malloc(sizeof(Node));
-    pNewNode->pValue = (void *)pValue;
-    /*printf("LinkedList:::: Pointer=%p has been added.\n", pNewNode->pValue); */
-    /* add new node on the root to implement quick FIFO */
-    /* modify new node pointers */
-    if(LinkedList->pRoot == NULL) {
-        pNewNode->pNextNode = NULL;
+    if ( pNewNode != NULL )  {
+        pNewNode->pValue = (void *)pValue;
+        /*printf("LinkedList:::: Pointer=%p has been added.\n", pNewNode->pValue); */
+        /* add new node on the root to implement quick FIFO */
+        /* modify new node pointers */
+        if(LinkedList->pRoot == NULL) {
+            pNewNode->pNextNode = NULL;
+        }
+        else {
+             pNewNode->pNextNode = LinkedList->pRoot;
+        }
+        /*modify root */
+        LinkedList->pRoot = pNewNode;
     }
-    else {
-         pNewNode->pNextNode = LinkedList->pRoot;
-    }
-    /*modify root */
-    LinkedList->pRoot = pNewNode;
 }
 
 void LinkedList_FreeElement(LinkedList *LinkedList, void *pValue) {
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 37c72e2..9f8d66d 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
@@ -71,7 +71,7 @@
 #endif
 
 /*----------------------Global-----------------------------------*/
-OMX_STRING cJPEGdecName = "OMX.TI.JPEG.decode"; 
+OMX_STRING cJPEGdecName = "OMX.TI.JPEG.decoder";
 
 
 /* ---------------------------- Fucntion prototypes -----------------*/
@@ -177,12 +177,12 @@
     OMX_CHECK_PARAM(hComponent);
     pHandle = (OMX_COMPONENTTYPE *)hComponent;
     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
+
     pPortDef = pComponentPrivate->pCompPort[nPortIndex]->pPortDef;
     nBufferCount = pComponentPrivate->pCompPort[nPortIndex]->nBuffCount;
     pCompPort = pComponentPrivate->pCompPort[nPortIndex];
 
-    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-
     OMX_PRINT1(pComponentPrivate->dbg, "Entering function AllocateBuffer_JPEGDec\n");
 
     OMX_PRBUFFER1(pComponentPrivate->dbg, "In AllocateBuffer_JPEGDec %d %lu %lu\n", 
@@ -323,21 +323,21 @@
     OMX_CHECK_PARAM(hComponent);
     OMX_CHECK_PARAM(pBuffHead);
 
-    if (nPortIndex != 1 && nPortIndex != 0) {
-	    eError = OMX_ErrorBadPortIndex;
-	    goto EXIT;
-    }
-
     pHandle = (OMX_COMPONENTTYPE *)hComponent;
     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 
     JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);  
 
+    if (nPortIndex != 1 && nPortIndex != 0) {
+	    eError = OMX_ErrorBadPortIndex;
+	    goto PRINT_EXIT;
+    }
+
     OMX_PRBUFFER2(pComponentPrivate->dbg, "JPEG-D: Entering funtion FreeBuffer_JPEGDec %lu %p\n", nPortIndex, pBuffHead);
     
     if(pComponentPrivate->nCurState == OMX_StateLoaded){
         eError = OMX_ErrorIncorrectStateOperation;
-	goto EXIT;
+	goto PRINT_EXIT;
     }
     pPortDef = pComponentPrivate->pCompPort[nPortIndex]->pPortDef;
     nBufferCount = pComponentPrivate->pCompPort[nPortIndex]->nBuffCount;
@@ -367,7 +367,7 @@
     }
     else {
         eError = OMX_ErrorBadPortIndex; 
-	goto EXIT;
+	goto PRINT_EXIT;
     }
 
     if (pBuffPrivate->bAllocbyComponent == OMX_TRUE) {
@@ -439,8 +439,9 @@
                                                 NULL);              
         }
     }
-EXIT: 
+PRINT_EXIT: 
     OMX_PRINT1(pComponentPrivate->dbg, "Exit from FreeBuffer function error = %x\n", eError);
+EXIT: 
     return eError;
 }   /* End of FreeBuffer_JPEGDec */
 
@@ -475,11 +476,13 @@
 
     pHandle = (OMX_COMPONENTTYPE *)hComponent;
     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1); 
+
     pPortDef = pComponentPrivate->pCompPort[nPortIndex]->pPortDef;
     nBufferCount = pComponentPrivate->pCompPort[nPortIndex]->nBuffCount;
     hTunnelComponent = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->hTunnelComponent;
 
-    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);                                                                                OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion UseBuffer_JPEGDec\n");
+    OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion UseBuffer_JPEGDec\n");
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedFrame(pComponentPrivate->pPERF,
@@ -969,11 +972,11 @@
     OMX_CHECK_PARAM(hComponent);
     pHandle = (OMX_COMPONENTTYPE *)hComponent;
     pComponentPrivate = (JPEGDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
+    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
+
     pPortDefIn = pComponentPrivate->pCompPort[JPEGDEC_INPUT_PORT]->pPortDef;
     pPortDefOut = pComponentPrivate->pCompPort[JPEGDEC_OUTPUT_PORT]->pPortDef;
 
-    JPEGDEC_OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-
     OMX_PRINT1(pComponentPrivate->dbg, "Entering funtion SendCommand_JPEGDec %u %lu\n", Cmd, nParam);
 
     if (pComponentPrivate->nCurState == OMX_StateInvalid) {
@@ -1140,7 +1143,7 @@
 
     if (pComponentPrivate->nCurState == OMX_StateInvalid) {
         eError = OMX_ErrorIncorrectStateOperation;
-        goto EXIT;
+        goto PRINT_EXIT;
     }
 
     switch (nParamIndex) {
@@ -1268,9 +1271,9 @@
         break;
     }
 
-
-EXIT:
+PRINT_EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "EXIT\n");
+EXIT:
     return eError;
 }   /* End of GetParameter_JPEGDec */
 
@@ -1434,8 +1437,8 @@
             {
                 OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE* pQuantizationTable = (OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE*)pCompParam;
                 OMX_MEMCPY_CHECK(pQuantizationTable);
-                memcpy(pComponentPrivate->pQuantTable, pQuantizationTable, sizeof(OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE));
                 OMX_MEMCPY_CHECK(pComponentPrivate->pQuantTable);
+                memcpy(pComponentPrivate->pQuantTable, pQuantizationTable, sizeof(OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE));
         }
     break;
 
@@ -1443,8 +1446,8 @@
             {
                 OMX_PARAM_COMPONENTROLETYPE* pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
                 OMX_MEMCPY_CHECK(pRole);
-                memcpy(pComponentPrivate->pCompRole, pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE ));
                 OMX_MEMCPY_CHECK(pComponentPrivate->pCompRole);
+                memcpy(pComponentPrivate->pCompRole, pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE ));
         }
     break;
         
@@ -1453,8 +1456,8 @@
                     {
                 OMX_IMAGE_PARAM_HUFFMANTTABLETYPE* pHuffmanTable = (OMX_IMAGE_PARAM_HUFFMANTTABLETYPE *)pCompParam;
                 OMX_MEMCPY_CHECK(pHuffmanTable);
-                memcpy(pComponentPrivate->pHuffmanTable, pHuffmanTable, sizeof(OMX_IMAGE_PARAM_HUFFMANTTABLETYPE ));
                 OMX_MEMCPY_CHECK(pComponentPrivate->pHuffmanTable);
+                memcpy(pComponentPrivate->pHuffmanTable, pHuffmanTable, sizeof(OMX_IMAGE_PARAM_HUFFMANTTABLETYPE ));
         }
     break;
 
@@ -1464,8 +1467,8 @@
         {
             OMX_CUSTOM_IMAGE_DECODE_SECTION* pSectionDecode = pCompParam;
             OMX_MEMCPY_CHECK(pSectionDecode);
-            memcpy(pComponentPrivate->pSectionDecode, pSectionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SECTION));
             OMX_MEMCPY_CHECK(pComponentPrivate->pSectionDecode);
+            memcpy(pComponentPrivate->pSectionDecode, pSectionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SECTION));
         }
     break;
 
@@ -1473,8 +1476,8 @@
         {
             OMX_CUSTOM_IMAGE_DECODE_SUBREGION* pSubRegionDecode = pCompParam;
             OMX_MEMCPY_CHECK(pSubRegionDecode);
-            memcpy(pComponentPrivate->pSubRegionDecode, pSubRegionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SUBREGION));
             OMX_MEMCPY_CHECK(pComponentPrivate->pSubRegionDecode);
+            memcpy(pComponentPrivate->pSubRegionDecode, pSubRegionDecode, sizeof(OMX_CUSTOM_IMAGE_DECODE_SUBREGION));
         }
     break;
     
@@ -1667,8 +1670,8 @@
             break;
         }
 
-        memcpy(pComponentPrivate->pScalePrivate, pScaleFactor, sizeof(OMX_CONFIG_SCALEFACTORTYPE));
         OMX_MEMCPY_CHECK(pComponentPrivate->pScalePrivate);
+        memcpy(pComponentPrivate->pScalePrivate, pScaleFactor, sizeof(OMX_CONFIG_SCALEFACTORTYPE));
         break;
     }
 
@@ -1993,6 +1996,7 @@
     JPEGDEC_COMPONENT_PRIVATE *pComponentPrivate = NULL; 
     struct OMX_TI_Debug dbg;
 
+    OMX_DBG_INIT_BASE(dbg);
     OMX_CHECK_PARAM(hComponent);
     pHandle = (OMX_COMPONENTTYPE *)hComponent;
 
@@ -2318,35 +2322,36 @@
 
 /*-------------------------------------------------------------------*/
 /**
-  * GetExtensionIndex_JpegDec()
+  * GetExtensionIndex_JpegDec() 
   *
-  * Get custom extension index.
+  * Free a video driver buffer.
   *
   * @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}
+    {"OMX.TI.JPEG.decoder.Config.ProgressiveFactor", OMX_IndexCustomProgressiveFactor},
+    {"OMX.TI.JPEG.decoder.Config.InputFrameWidth", OMX_IndexCustomInputFrameWidth},
+    {"OMX.TI.JPEG.decoder.Config.OutputColorFormat", OMX_IndexCustomOutputColorFormat},
+    {"OMX.TI.JPEG.decoder.Param.SectionDecode", OMX_IndexCustomSectionDecode},
+    {"OMX.TI.JPEG.decoder.Param.SubRegionDecode", OMX_IndexCustomSubRegionDecode},
+    {"OMX.TI.JPEG.decoder.Param.SetMaxResolution", OMX_IndexCustomSetMaxResolution},
+    {"OMX.TI.JPEG.decoder.Debug", OMX_IndexCustomDebug},
+    {"",0x0}
     };
 
-    /* Check parameter validity */
+    /* Check parameter validity */    
     OMX_CHECK_PARAM(hComponent);
     OMX_CHECK_PARAM(pIndexType);
+    *pIndexType = OMX_IndexMax;
 
-    const OMX_U32 nExtensions = sizeof(sJpegDecCustomParams)/sizeof(JPEGDEC_CUSTOM_PARAM_DEFINITION);
-    OMX_U32 nIndex;
-    for (nIndex = 0; nIndex < nExtensions; ++nIndex) {
+    for (nIndex = 0; strlen((const char*)sJpegDecCustomParams[nIndex].cCustomParamName); nIndex++){
         if (!strcmp((const char*)cParameterName, (const char*)(&(sJpegDecCustomParams[nIndex].cCustomParamName)))){
             *pIndexType = sJpegDecCustomParams[nIndex].nCustomParamIndex;
             eError = OMX_ErrorNone;
@@ -2354,10 +2359,11 @@
         }
     }
 
-    if (nIndx >= nExtensions) {
+    if(*pIndexType == OMX_IndexMax){
          eError = OMX_ErrorUnsupportedIndex;
     }
 
+    
 EXIT:
     return eError;
 }
diff --git a/omx/image/src/openmax_il/jpeg_dec/tests/JPEGTest.c b/omx/image/src/openmax_il/jpeg_dec/tests/JPEGTest.c
index 2cff578..56642f2 100755
--- a/omx/image/src/openmax_il/jpeg_dec/tests/JPEGTest.c
+++ b/omx/image/src/openmax_il/jpeg_dec/tests/JPEGTest.c
@@ -905,7 +905,7 @@
     PRINT("Calling OMX_SetParameter\n");
 
 	/* Set max width & height value*/
-    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decode.Param.SetMaxResolution", (OMX_INDEXTYPE*)&nCustomIndex);
+    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decoder.Param.SetMaxResolution", (OMX_INDEXTYPE*)&nCustomIndex);
     if ( eError != OMX_ErrorNone ) {
         printf ("JPEGDec test:: %d:error= %x\n", __LINE__, eError);
         goto EXIT;
@@ -1152,7 +1152,7 @@
         goto EXIT;
     }
 
-    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decode.Config.ProgressiveFactor", (OMX_INDEXTYPE*)&nCustomIndex);
+    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decoder.Config.ProgressiveFactor", (OMX_INDEXTYPE*)&nCustomIndex);
     if ( eError != OMX_ErrorNone ) {
         printf ("JPEGDec test:: %d:error= %x\n", __LINE__, eError);
         goto EXIT;
@@ -1163,7 +1163,7 @@
         goto EXIT;
     }
 
-    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decode.Config.OutputColorFormat", (OMX_INDEXTYPE*)&nCustomIndex);
+    eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decoder.Config.OutputColorFormat", (OMX_INDEXTYPE*)&nCustomIndex);
     if ( eError != OMX_ErrorNone ) {
         printf ("JPEGDec test:: %d:error= %x\n", __LINE__, eError);
         goto EXIT;
@@ -1176,7 +1176,7 @@
     }
 
     if(nMCURow){
-        eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decode.Param.SectionDecode", (OMX_INDEXTYPE*)&nCustomIndex);
+        eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decoder.Param.SectionDecode", (OMX_INDEXTYPE*)&nCustomIndex);
         if ( eError != OMX_ErrorNone ) {
             printf ("JPEGDec test:: %d:error= %x\n", __LINE__, eError);
             goto EXIT;
@@ -1197,7 +1197,7 @@
     }
 
     if(nXOrg || nYOrg || nXLength || nYLength){
-        eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decode.Param.SubRegionDecode", (OMX_INDEXTYPE*)&nCustomIndex);
+        eError = OMX_GetExtensionIndex(pHandle, "OMX.TI.JPEG.decoder.Param.SubRegionDecode", (OMX_INDEXTYPE*)&nCustomIndex);
         if ( eError != OMX_ErrorNone ) {
             printf ("JPEGDec test:: %d:error= %x\n", __LINE__, eError);
             goto EXIT;
@@ -1562,7 +1562,7 @@
     unsigned int numProcs;
     char* argv[2];
    
-    argv[0] = "/system/lib/dsp/baseimage.dof";
+    argv[0] = "/lib/dsp/baseimage.dof";
     
     status = (DBAPI)DspManager_Open(0, NULL);
     if (DSP_FAILED(status)) {
diff --git a/omx/image/src/openmax_il/jpeg_dec/tests/JPEGTest.h b/omx/image/src/openmax_il/jpeg_dec/tests/JPEGTest.h
index ed5f72b..246a3d1 100755
--- a/omx/image/src/openmax_il/jpeg_dec/tests/JPEGTest.h
+++ b/omx/image/src/openmax_il/jpeg_dec/tests/JPEGTest.h
@@ -76,7 +76,7 @@
 #ifdef UNDER_CE
 OMX_STRING StrJpegDecoder= "OMX.TI.IMAGE.JPEG.DEC";
 #else
-OMX_STRING StrJpegDecoder= "OMX.TI.JPEG.Decoder";
+OMX_STRING StrJpegDecoder= "OMX.TI.JPEG.decoder";
 #endif	
 
 
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 edc4048..dbcbf45 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
@@ -70,6 +70,8 @@
 #endif
 #include "OMX_JpegEnc_CustomCmd.h"
 
+#include <utils/Log.h>
+#define LOG_TAG "OMX_JPGENC"
 
 #ifdef __PERF_INSTRUMENTATION__
 #include "perf.h"
@@ -86,8 +88,9 @@
 #define COMP_MAX_NAMESIZE 127
 
 #define OMX_CustomCommandStopThread (OMX_CommandMax - 1)
-#define PADDING_128_BYTE 128
-#define PADDING_256_BYTE 256
+
+#define PADDING_128_BYTE	128
+#define PADDING_256_BYTE	256
 #define JPEGENC_THUMBNAIL_ABSENT_WARNING 4
 
 #ifdef UNDER_CE
@@ -107,6 +110,9 @@
 
 #define DSP_MMU_FAULT_HANDLING
 
+//JPEG Encoder Specific DSP Err Codes
+#define IUALG_ERR_INSUFF_BUFFER 0x8401
+
 /*Linked List */
 
 typedef struct Node {
@@ -402,6 +408,8 @@
     OMX_BOOL bSetLumaQuantizationTable;
     OMX_BOOL bSetChromaQuantizationTable;
     OMX_BOOL bSetHuffmanTable;
+	OMX_BOOL bConvert420pTo422i;
+	OMX_BOOL bPPLibEnable;
     OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE *pCustomLumaQuantTable;
     OMX_IMAGE_PARAM_QUANTIZATIONTABLETYPE *pCustomChromaQuantTable;
     JPEGENC_CUSTOM_HUFFMANTTABLETYPE *pHuffmanTable;
@@ -468,7 +476,6 @@
     pthread_mutex_t mutexStateChangeRequest;
     pthread_cond_t StateChangeCondition;
 
-
 } JPEGENC_COMPONENT_PRIVATE;
 
 
@@ -593,7 +600,9 @@
     OMX_IndexCustomQFactor,
     OMX_IndexCustomDRI,
     OMX_IndexCustomHuffmanTable,
-    OMX_IndexCustomDebug
+    OMX_IndexCustomDebug,
+	OMX_IndexCustomColorFormatConvertion_420pTo422i,
+	OMX_IndexCustomPPLibEnable
 }OMX_INDEXIMAGETYPE;
 
 typedef struct IUALG_Buf {
diff --git a/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEnc_Thread.c b/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEnc_Thread.c
index 813596f..2cda26e 100644
--- a/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEnc_Thread.c
+++ b/omx/image/src/openmax_il/jpeg_enc/src/OMX_JpegEnc_Thread.c
@@ -149,9 +149,8 @@
             pComponentPrivate->cbInfo.EventHandler (pComponentPrivate->pHandle, pComponentPrivate->pHandle->pApplicationPrivate,
                                                     OMX_EventError, OMX_ErrorInsufficientResources, OMX_TI_ErrorSevere,
                                                     "Error from COmponent Thread in select");
-            eError = OMX_ErrorInsufficientResources;
+	     eError = OMX_ErrorInsufficientResources;
             break;
-
         } else {
             if ( (FD_ISSET (pComponentPrivate->filled_inpBuf_Q[0], &rfds))
                  && (pComponentPrivate->nCurState != OMX_StatePause) ) {
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 f17486a..57c7b92 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
@@ -129,7 +129,9 @@
 
     handle = dlopen("libLCML.so", RTLD_LAZY);
     if ( !handle ) {
-        fputs(dlerror(), stderr);
+        if ( (error = (char *)dlerror()) != NULL ) {
+            fputs(error, stderr);
+        }
         eError = OMX_ErrorComponentNotFound;
         goto EXIT;
     }
@@ -142,7 +144,13 @@
     }
 
     /*  calling gethandle and passing phandle to b filled   */
-    eError = (*fpGetHandle)(&LCML_pHandle);
+    if ( fpGetHandle != NULL ) {
+        eError = (*fpGetHandle)(&LCML_pHandle);
+    }
+    else  {
+        eError = OMX_ErrorInvalidComponent;
+        goto EXIT;
+    }
 
     if ( eError != OMX_ErrorNone ) {
         eError = OMX_ErrorUndefined;
@@ -230,8 +238,8 @@
        }
    }
 
-EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exit form JPEGEnc Disable Port eError is = %x\n",eError);
+EXIT:
     return eError;
 }
 
@@ -422,14 +430,14 @@
     OMX_U32 nParam = 0;
     struct OMX_TI_Debug dbg;
 
+    OMX_DBG_INIT_BASE(dbg);
+    OMX_CHECK_PARAM(pComponentPrivate);
+
 #ifdef __PERF_INSTRUMENTATION__
         PERF_Boundary(pComponentPrivate->pPERF,
                       PERF_BoundaryStart | PERF_BoundaryCleanup);
 #endif
 
-    OMX_DBG_INIT_BASE(dbg);
-    OMX_CHECK_PARAM(pComponentPrivate);
-
     if ( pComponentPrivate->pLCML != NULL && pComponentPrivate->isLCMLActive) {
     	LCML_ControlCodec(((LCML_DSP_INTERFACE*)pComponentPrivate->pLCML)->pCodecinterfacehandle,EMMCodecControlDestroy,NULL);
     	dlclose(pComponentPrivate->pDllHandle);
@@ -623,10 +631,11 @@
           lcml_dsp->ProfileID = 10;
       }
 #else
+    /* according to JPEG Enc SN Interface guide */
+    /* if PPLib is not enabled than  use profile 1 by default */
     lcml_dsp->ProfileID = 2;
 #endif
 
-
     /* CrPhArgs for JpegEnc */
     ptCreateString[0] = JPGENC_SNTEST_STRMCNT;
     ptCreateString[1] = JPGENC_SNTEST_INSTRMID; /* Stream ID   */
@@ -656,15 +665,37 @@
     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)
+
+/*
+this option supportsonly up to 3 mega pixels
+	if (pPortDefIn->format.image.eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar)
     {
     	ptCreateString[16] = 1;
     }
+*/
 
     ptCreateString[17] = 0;
     if ( pPortDefIn->format.image.eColorFormat == OMX_COLOR_Format32bitARGB8888){
     	ptCreateString[17] = 1; //Convert flag
     }
+	
+	/*Do an internal conversion from YUV420P to YUV422I and encode so that
+	this JPEG would be viewable using the TI JPEG decoder*/
+	else if (pComponentPrivate->bConvert420pTo422i ){
+		if (pPortDefIn->format.image.eColorFormat == OMX_COLOR_FormatYUV420PackedPlanar ){
+			ptCreateString[17] = 10;
+			if(pComponentPrivate->bPPLibEnable)
+			{
+				/* memory requirement for having both conversion and pplib is much larger */
+				lcml_dsp->ProfileID +=3;
+			}
+		}
+		else{
+			OMX_PRMGR4(pComponentPrivate->dbg, "Error invalid ColorFormat for YUVConvertion\n");
+			eError=-1;
+			goto EXIT;
+		}
+	}
 
     ptCreateString[18] = 512; /* Maximum Horizontal Size of the Thumbnail for App5 marker */
     ptCreateString[19] = 384; /* Maximum Vertical Size of the Thumbnail for App5 marker */
@@ -686,7 +717,8 @@
     //                7:422_IN_UY_WS, 8:422_IN_YU_WS, 9:YUV420P, 10:GRAY8, 11:GRAY4, 12:GRAY2_IN, 13:GRAY1
     if (pPortDefIn->format.image.eColorFormat ==  OMX_COLOR_FormatCbYCrY
         ||  pPortDefIn->format.image.eColorFormat == OMX_COLOR_Format32bitARGB8888
-        ||  pPortDefIn->format.image.eColorFormat == OMX_COLOR_FormatYCbYCr)
+        ||  pPortDefIn->format.image.eColorFormat == OMX_COLOR_FormatYCbYCr
+        ||  ptCreateString[17] == 10)
     {
         ptCreateStringPPLIB[14] = 5;
     }
@@ -704,7 +736,8 @@
 
     //YuvOutputFormat
     // --> 0 = OFF, 1 = YUV420, 2 = YUV422ILE, 3 = YUV422IBE
-    if (pPortDefIn->format.image.eColorFormat ==  OMX_COLOR_FormatYUV420PackedPlanar)
+    if (pPortDefIn->format.image.eColorFormat ==  OMX_COLOR_FormatYUV420PackedPlanar
+        && ptCreateString[17] != 10)
     {
         ptCreateStringPPLIB[15] = 1;
     }
@@ -718,7 +751,13 @@
     //     7 = GRAY8, 8 = GRAY4, 9 = GRAY2, 10 = GRAY1
     ptCreateStringPPLIB[16] = 0;
 
-    ptCreateString[34] = END_OF_CR_PHASE_ARGS;
+    if(pComponentPrivate->bPPLibEnable)
+    {
+        ptCreateString[34] = END_OF_CR_PHASE_ARGS;
+    }else
+    {
+        ptCreateString[20] = END_OF_CR_PHASE_ARGS;
+    }
 #else
     ptCreateString[20] = END_OF_CR_PHASE_ARGS;
 #endif
@@ -746,7 +785,7 @@
         pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
         if (eError != OMX_ErrorNone) {
-            goto EXIT;
+            goto PRINT_EXIT;
         }
 
         pthread_mutex_lock(&pComponentPrivate->jpege_mutex);
@@ -768,7 +807,7 @@
         pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
         if (eError != OMX_ErrorNone) {
-            goto EXIT;
+            goto PRINT_EXIT;
         }
 
         pthread_mutex_lock(&pComponentPrivate->jpege_mutex);
@@ -782,8 +821,9 @@
         pComponentPrivate->bFlushComplete = OMX_FALSE;
     }
 
+    PRINT_EXIT:
+        OMX_PRINT1(pComponentPrivate->dbg, "Exiting HandleCommand FLush Function JEPG Encoder\n");
     EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "Exiting HandleCommand FLush Function JEPG Encoder\n");
     return eError;
 
 }
@@ -808,7 +848,7 @@
         pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
         if (eError != OMX_ErrorNone) {
-            goto EXIT;
+            goto PRINT_EXIT;
         }
        OMX_PRDSP2(pComponentPrivate->dbg, "sent EMMCodecControlStrmCtrl command\n");
 
@@ -890,7 +930,7 @@
         pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,EMMCodecControlStrmCtrl, (void*)aParam);
         if (eError != OMX_ErrorNone) {
-            goto EXIT;
+            goto PRINT_EXIT;
         }
         OMX_PRDSP2(pComponentPrivate->dbg, "(1) sent EMMCodecControlStrmCtrl command\n");
 
@@ -939,7 +979,7 @@
             ret = read(pComponentPrivate->free_outBuf_Q[0], &pBuffHead, sizeof(pBuffHead));
             if ( ret == -1 ) {
                 OMX_PRCOMM4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
-                goto EXIT;
+                goto PRINT_EXIT;
             }
             OMX_PRCOMM1(pComponentPrivate->dbg, "after read\n");
             if (pBuffHead != NULL) {
@@ -974,8 +1014,9 @@
                                                NULL);
     }
 
+    PRINT_EXIT:
+        OMX_PRINT1(pComponentPrivate->dbg, "Exiting HandleCommand FLush Function JEPG Encoder\n");
     EXIT:
-   OMX_PRINT1(pComponentPrivate->dbg, "Exiting HandleCommand FLush Function JEPG Encoder\n");
     return eError;
 
 }
@@ -1548,6 +1589,7 @@
             PERF_Boundary(pComponentPrivate->pPERFcomp,
                           PERF_BoundaryComplete | PERF_BoundarySetup);
 #endif
+
             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                               pComponentPrivate->pHandle->pApplicationPrivate,
                           OMX_EventCmdComplete,
@@ -1758,6 +1800,7 @@
             PERF_Boundary(pComponentPrivate->pPERFcomp,
                           PERF_BoundarySteadyState| PERF_BoundaryComplete);
 #endif
+
          /* Decrement reference count with signal enabled */
          if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
                return OMX_ErrorUndefined;
@@ -1800,12 +1843,11 @@
                 goto EXIT;
             }
             /*
-            pComponentPrivate->nCurState = OMX_StatePause;
+            pComponentPrivate->nCurState = OMX_StatePause; */
             /* Decrement reference count with signal enabled */
             if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
                    return OMX_ErrorUndefined;
-            }
-
+           }
             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,pComponentPrivate->pHandle->pApplicationPrivate,
                                                    OMX_EventCmdComplete, OMX_CommandStateSet, pComponentPrivate->nCurState, NULL);
         } else {
@@ -1955,7 +1997,6 @@
                 if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
                   return OMX_ErrorUndefined;
                 }
-
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -2099,7 +2140,7 @@
     if (pComponentPrivate->pOutParams != NULL)
     {
         pComponentPrivate->pOutParams = (OMX_U8*)pComponentPrivate->pOutParams - PADDING_128_BYTE;
-        OMX_FREE(pComponentPrivate->pOutParams);
+	OMX_FREE(pComponentPrivate->pOutParams);
     }
     OMX_MALLOC(pComponentPrivate->pOutParams,sizeof(PPLIB_UALGRunTimeParam_t) + PADDING_256_BYTE);
     pComponentPrivate->pOutParams = (OMX_U8*)pComponentPrivate->pOutParams + PADDING_128_BYTE;
@@ -2822,10 +2863,12 @@
     int i;
 
     JPEGENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
-    OMX_COMPONENTTYPE *pHandle;
+    OMX_COMPONENTTYPE *pHandle = NULL;
 
     if ( ((LCML_DSP_INTERFACE*)argsCb[6] ) != NULL ) {
         pComponentPrivate = (JPEGENC_COMPONENT_PRIVATE*)((LCML_DSP_INTERFACE*)argsCb[6])->pComponentPrivate;
+        OMX_CHECK_PARAM(pComponentPrivate);
+
         pHandle = (OMX_COMPONENTTYPE *)pComponentPrivate->pHandle; 
     }
     else {
@@ -2917,7 +2960,7 @@
             eError = HandleJpegEncFreeDataBuf(pComponentPrivate, pBuffHead);
         }
     }
-    goto EXIT;
+    goto PRINT_EXIT;
     } /* end     if ( event == EMMCodecBufferProcessed ) */
 
     if ( event == EMMCodecProcessingStoped ) {
@@ -2943,36 +2986,35 @@
 
         OMX_TRACE1(pComponentPrivate->dbg, "after stop signal\n");
 
-        goto EXIT;
+        goto PRINT_EXIT;
     }
 
     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");
+        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");
            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                      pComponentPrivate->pHandle->pApplicationPrivate,
                                      OMX_EventError,
                                      OMX_ErrorInsufficientResources,
                                      OMX_TI_ErrorCritical,
                                      "The allocated output buffer length is insufficient");
-           goto EXIT;
+           goto PRINT_EXIT;
        }
-
        if ((int)argsCb[4] != 0x1 || (int)argsCb[5] != 0x500) {
-	   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;
-	   }
+		   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, 
@@ -2987,7 +3029,7 @@
                                                    OMX_ErrorInvalidState,
                                                    OMX_TI_ErrorCritical,
                                                    "DSP Hardware Error");
-           goto EXIT;
+           goto PRINT_EXIT;
        }
 #ifdef DSP_MMU_FAULT_HANDLING
         /* Cheking for MMU_fault */
@@ -3012,7 +3054,7 @@
                                                OMX_ErrorHardware, 
                                                OMX_TI_ErrorCritical,
                                                NULL);
-        goto EXIT;
+        goto PRINT_EXIT;
     }
     if ( event == EMMCodecProcessingPaused ) {
         OMX_PRDSP2(pComponentPrivate->dbg, "ENTERING TO EMMCodecProcessingPaused JPEG Encoder\n");
@@ -3046,9 +3088,9 @@
         pthread_mutex_unlock(&pComponentPrivate->jpege_mutex);
         */
     }
-
-EXIT:
+PRINT_EXIT:
     OMX_PRDSP1(pComponentPrivate->dbg, "Exiting the LCML_Callback function\n");
+EXIT:
     return eError;
 }
 /*-------------------------------------------------------------------*/
@@ -3194,21 +3236,26 @@
 void LinkedList_AddElement(LinkedList *LinkedList, void *pValue) {
     /* create new node and fill the value */
     Node *pNewNode = (Node *)malloc(sizeof(Node));
-    pNewNode->pValue = (void *)pValue;
-    /*printf("LinkedList:::: Pointer=%p has been added.\n", pNewNode->pValue); */
-    /* add new node on the root to implement quick FIFO */
-    /* modify new node pointers */
+    if ( pNewNode != NULL ) {
+        pNewNode->pValue = (void *)pValue;
+        /*printf("LinkedList:::: Pointer=%p has been added.\n", pNewNode->pValue); */
+        /* add new node on the root to implement quick FIFO */
+        /* modify new node pointers */
 
-    pthread_mutex_lock(&LinkedList->lock);
-    if(LinkedList->pRoot == NULL) {
-        pNewNode->pNextNode = NULL;
+        pthread_mutex_lock(&LinkedList->lock);
+        if(LinkedList->pRoot == NULL) {
+            pNewNode->pNextNode = NULL;
+        }
+        else {
+             pNewNode->pNextNode = LinkedList->pRoot;
+        }
+        /*modify root */
+        LinkedList->pRoot = pNewNode;
+        pthread_mutex_unlock(&LinkedList->lock);
     }
     else {
-         pNewNode->pNextNode = LinkedList->pRoot;
+         LOGE("Linked list memory allocation failed.\n" );
     }
-    /*modify root */
-    LinkedList->pRoot = pNewNode;
-    pthread_mutex_unlock(&LinkedList->lock);
 }
 
 void LinkedList_FreeElement(LinkedList *LinkedList, void *pValue) {
@@ -3245,9 +3292,9 @@
         pTempNode = LinkedList->pRoot->pNextNode;
         /*printf("LinkedList:::: Pointer=%p has been freed\n", LinkedList->pRoot->pValue); */
         if(LinkedList->pRoot->pValue != NULL) {
-            free(LinkedList->pRoot->pValue);
-            LinkedList->pRoot->pValue = NULL;
-        }
+		free(LinkedList->pRoot->pValue);
+		LinkedList->pRoot->pValue = NULL;
+	}
         free(LinkedList->pRoot);
         LinkedList->pRoot = pTempNode;
         nodes++;
@@ -3276,14 +3323,14 @@
 OMX_ERRORTYPE AddStateTransition(JPEGENC_COMPONENT_PRIVATE* pComponentPrivate) {
 
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-
+     
     if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
        return OMX_ErrorUndefined;
     }
 
     /* Increment state change request reference count */
     pComponentPrivate->nPendingStateChangeRequests++;
-
+    
     if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
        return OMX_ErrorUndefined;
     }
@@ -3293,24 +3340,22 @@
 
 OMX_ERRORTYPE RemoveStateTransition(JPEGENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BOOL bEnableSignal) {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-
+     
      /* Decrement state change request reference count*/
     if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
        return OMX_ErrorUndefined;
     }
 
     pComponentPrivate->nPendingStateChangeRequests--;
-
+     
     /* If there are no more pending requests, signal the thread waiting on this*/
     if(!pComponentPrivate->nPendingStateChangeRequests && bEnableSignal) {
        pthread_cond_signal(&(pComponentPrivate->StateChangeCondition));
     }
-
+ 
     if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
        return OMX_ErrorUndefined;
     }
-
+    
     return eError;
 }
-
-
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 a19f0fa..5cbcc84 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
@@ -209,7 +209,7 @@
     } 
     else {
             eError = OMX_ErrorBadPortIndex;
-            goto EXIT;
+            goto PRINT_EXIT;
     }
 
     if (pBuffPrivate->bAllocByComponent == OMX_TRUE) {
@@ -269,9 +269,9 @@
         }
     }
 
-EXIT:
+PRINT_EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exit from FreeBuffer\n");
-
+EXIT:
     return eError;
 }
 
@@ -524,13 +524,22 @@
     pComponentPrivate->bSetHuffmanTable = OMX_FALSE;
     pComponentPrivate->bSetLumaQuantizationTable = OMX_FALSE;
     pComponentPrivate->bSetChromaQuantizationTable = OMX_FALSE;    
-    
+    pComponentPrivate->bConvert420pTo422i = OMX_FALSE;
+#ifdef __JPEG_OMX_PPLIB_ENABLED__
+    pComponentPrivate->bPPLibEnable = OMX_TRUE;
+#else
+    pComponentPrivate->bPPLibEnable = OMX_FALSE;
+#endif
+
     pComponentPrivate->InParams.pInParams = NULL;
     pComponentPrivate->InParams.size = 0;   
     pComponentPrivate->bPreempted = OMX_FALSE;
+
 #ifdef __JPEG_OMX_PPLIB_ENABLED__
     pComponentPrivate->pOutParams = NULL;
 #endif
+
+
     OMX_MALLOC(pComponentPrivate->pDynParams, sizeof(IDMJPGE_TIGEM_DynamicParams)+256);
     if (!pComponentPrivate->pDynParams) {
         eError = OMX_ErrorInsufficientResources;
@@ -689,7 +698,6 @@
     }
     pComponentPrivate->nPendingStateChangeRequests = 0;
 
-
 #ifdef RESOURCE_MANAGER_ENABLED
     /* load the ResourceManagerProxy thread */
     eError = RMProxy_NewInitalizeEx(OMX_COMPONENTTYPE_IMAGE);
@@ -857,12 +865,10 @@
 
     switch ( Cmd ) {
     case OMX_CommandStateSet:
-
          /* Add a pending transition */
          if(AddStateTransition(pCompPrivate) != OMX_ErrorNone) {
              return OMX_ErrorUndefined;
          }
-
         eCmd = SetState;
         pCompPrivate->nToState = nParam;
         break;
@@ -1004,7 +1010,7 @@
 
     if ( pComponentPrivate->nCurState == OMX_StateInvalid ) {
         eError = OMX_ErrorInvalidState;
-        goto EXIT;
+        goto PRINT_EXIT;
     }
     pInpPortType = pComponentPrivate->pCompPort[JPEGENC_INP_PORT];
     pOutPortType = pComponentPrivate->pCompPort[JPEGENC_OUT_PORT];
@@ -1126,9 +1132,9 @@
         eError = OMX_ErrorUnsupportedIndex;
         break;
     }
-
-EXIT:
+PRINT_EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Exit function eError = %x\n", eError);
+EXIT:
     return eError;
 
 }
@@ -1175,19 +1181,21 @@
 
     pInpPortType = pComponentPrivate->pCompPort[JPEGENC_INP_PORT];
     pOutPortType = pComponentPrivate->pCompPort[JPEGENC_OUT_PORT];
+    OMX_CHECK_PARAM(pInpPortType);
+    OMX_CHECK_PARAM(pOutPortType);
 
     switch ( nParamIndex ) {
     case OMX_IndexParamImagePortFormat:
     {
         OMX_IMAGE_PARAM_PORTFORMATTYPE* pComponentParam = (OMX_IMAGE_PARAM_PORTFORMATTYPE *)pCompParam;
+        OMX_MEMCPY_CHECK(pInpPortType->pPortFormat);
+        OMX_MEMCPY_CHECK(pOutPortType->pPortFormat);
         if ( pComponentParam->nPortIndex == pInpPortType->pPortFormat->nPortIndex )
         {
             memcpy(pInpPortType->pPortFormat, pComponentParam, sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE));
-            OMX_MEMCPY_CHECK(pInpPortType->pPortFormat);
         } 
         else if ( pComponentParam->nPortIndex == pOutPortType->pPortFormat->nPortIndex ) {
             memcpy(pOutPortType->pPortFormat, pComponentParam, sizeof(OMX_IMAGE_PARAM_PORTFORMATTYPE));
-            OMX_MEMCPY_CHECK(pOutPortType->pPortFormat);
         }
         else {
              eError = OMX_ErrorBadPortIndex;
@@ -1196,20 +1204,20 @@
     }
     case OMX_IndexParamImageInit:
     {
-        memcpy(pComponentPrivate->pPortParamType, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
         OMX_MEMCPY_CHECK(pComponentPrivate->pPortParamType);
+        memcpy(pComponentPrivate->pPortParamType, (OMX_PORT_PARAM_TYPE*)pCompParam, sizeof(OMX_PORT_PARAM_TYPE));
         break;
     }
     case OMX_IndexParamPortDefinition:
     {
         OMX_PARAM_PORTDEFINITIONTYPE* pComponentParam = (OMX_PARAM_PORTDEFINITIONTYPE *)pCompParam;
+        OMX_MEMCPY_CHECK(pInpPortType->pPortDef);
+        OMX_MEMCPY_CHECK(pOutPortType->pPortDef);
         if ( pComponentParam->nPortIndex == pInpPortType->pPortDef->nPortIndex ) {
             memcpy(pInpPortType->pPortDef, pComponentParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
-            OMX_MEMCPY_CHECK(pInpPortType->pPortDef);
         } 
         else if ( pComponentParam->nPortIndex == pOutPortType->pPortDef->nPortIndex ) {
             memcpy(pOutPortType->pPortDef, pComponentParam, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
-            OMX_MEMCPY_CHECK(pOutPortType->pPortDef);
         } 
         else {
             eError = OMX_ErrorBadPortIndex;
@@ -1218,14 +1226,14 @@
     }
     case OMX_IndexParamPriorityMgmt:
     {
-        memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
         OMX_MEMCPY_CHECK(pComponentPrivate->pPriorityMgmt);
+        memcpy(pComponentPrivate->pPriorityMgmt, (OMX_PRIORITYMGMTTYPE*)pCompParam, sizeof(OMX_PRIORITYMGMTTYPE));
         break;
     }
     case OMX_IndexParamQFactor:
     {           
-        memcpy(pComponentPrivate->pQualityfactor, (OMX_IMAGE_PARAM_QFACTORTYPE*)pCompParam, sizeof(OMX_IMAGE_PARAM_QFACTORTYPE));
         OMX_MEMCPY_CHECK(pComponentPrivate->pQualityfactor);
+        memcpy(pComponentPrivate->pQualityfactor, (OMX_IMAGE_PARAM_QFACTORTYPE*)pCompParam, sizeof(OMX_IMAGE_PARAM_QFACTORTYPE));
         break;
     }
     case OMX_IndexParamCompBufferSupplier:
@@ -1355,7 +1363,7 @@
 {
     OMX_ERRORTYPE      eError   = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle  = NULL;
-    JPEGENC_COMPONENT_PRIVATE *pComponentPrivate;
+    JPEGENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
     
     OMX_CHECK_PARAM(hComp);
 
@@ -1379,10 +1387,6 @@
 	case OMX_IndexCustomAPP0:
 		{
 			JPEG_APPTHUMB_MARKER *pMarkerInfo = (JPEG_APPTHUMB_MARKER *) ComponentConfigStructure;
-			if (pMarkerInfo->nThumbnailHeight < 0 || pMarkerInfo->nThumbnailWidth < 0) {
-				eError = OMX_ErrorBadParameter;
-				goto EXIT;
-			}
 
 			if (pComponentPrivate->sAPP0.pMarkerBuffer != NULL) {
 					OMX_FREE(pComponentPrivate->sAPP0.pMarkerBuffer);
@@ -1403,10 +1407,6 @@
 	case OMX_IndexCustomAPP1:
 		{
 			JPEG_APPTHUMB_MARKER *pMarkerInfo = (JPEG_APPTHUMB_MARKER *) ComponentConfigStructure;
-			if (pMarkerInfo->nThumbnailHeight < 0 || pMarkerInfo->nThumbnailWidth < 0) {
-				eError = OMX_ErrorBadParameter;
-				goto EXIT;
-			}
 
 			if (pComponentPrivate->sAPP1.pMarkerBuffer != NULL) {
 				OMX_FREE(pComponentPrivate->sAPP1.pMarkerBuffer);
@@ -1427,10 +1427,6 @@
 	case OMX_IndexCustomAPP5:
 		{
 			JPEG_APPTHUMB_MARKER *pMarkerInfo = (JPEG_APPTHUMB_MARKER *) ComponentConfigStructure;
-			if (pMarkerInfo->nThumbnailHeight < 0 || pMarkerInfo->nThumbnailWidth < 0) {
-				eError = OMX_ErrorBadParameter;
-				goto EXIT;
-			}
 
 			if (pComponentPrivate->sAPP5.pMarkerBuffer != NULL) {
 				OMX_FREE(pComponentPrivate->sAPP5.pMarkerBuffer);
@@ -1517,8 +1513,8 @@
     }
     case OMX_IndexCustomQFactor:
     {           
-        memcpy(pComponentPrivate->pQualityfactor, (OMX_IMAGE_PARAM_QFACTORTYPE*)ComponentConfigStructure, sizeof(OMX_IMAGE_PARAM_QFACTORTYPE));
         OMX_MEMCPY_CHECK(pComponentPrivate->pQualityfactor);
+        memcpy(pComponentPrivate->pQualityfactor, (OMX_IMAGE_PARAM_QFACTORTYPE*)ComponentConfigStructure, sizeof(OMX_IMAGE_PARAM_QFACTORTYPE));
         break;
     }
     case OMX_IndexConfigCommonInputCrop :
@@ -1537,6 +1533,21 @@
     case OMX_IndexCustomDebug:
         OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
 	break;
+
+	case OMX_IndexCustomColorFormatConvertion_420pTo422i :
+	{
+		pComponentPrivate->bConvert420pTo422i = *((OMX_BOOL*)ComponentConfigStructure);
+		break;
+	}
+
+	 case OMX_IndexCustomPPLibEnable :
+	{
+#ifdef __JPEG_OMX_PPLIB_ENABLED__
+		pComponentPrivate->bPPLibEnable = *((OMX_BOOL*)ComponentConfigStructure);
+#endif
+		break;
+	}
+
     default:
         eError = OMX_ErrorUnsupportedIndex;
         break;
@@ -1550,8 +1561,8 @@
         }
     }
 
-EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "Inside JPEGENC_SetConfig function\n");
+EXIT:
     return eError;
 }
 
@@ -1572,7 +1583,6 @@
 /*-------------------------------------------------------------------*/
 static OMX_ERRORTYPE JPEGENC_GetState (OMX_HANDLETYPE hComponent, OMX_STATETYPE* pState)
 {
-
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle = NULL;
     JPEGENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
@@ -1580,49 +1590,50 @@
     int nPendingStateChangeRequests = 0;
     int ret = 0;
     /* Set to sufficiently high value */
-    int mutex_timeout = 3;
+    int mutex_timeout = 3; 
 
     if(hComponent == NULL || pState == NULL) {
         return OMX_ErrorBadParameter;
     }
 
+
     pHandle = (OMX_COMPONENTTYPE*)hComponent;
     pComponentPrivate = (JPEGENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
-
+    
     /* Retrieve current state */
     if (pHandle && pHandle->pComponentPrivate) {
-        /* Check for any pending state transition requests */
+        /* Check for any pending state transition requests */ 
         if(pthread_mutex_lock(&pComponentPrivate->mutexStateChangeRequest)) {
             return OMX_ErrorUndefined;
         }
         nPendingStateChangeRequests = pComponentPrivate->nPendingStateChangeRequests;
         if(!nPendingStateChangeRequests) {
            if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
-               return OMX_ErrorUndefined;
+               return OMX_ErrorUndefined; 
            }
-
+           
            /* No pending state transitions */
 	   *pState = ((JPEGENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->nCurState;
             eError = OMX_ErrorNone;
         }
         else {
-           /* Wait for component to complete state transition */
+       	   /* Wait for component to complete state transition */
            clock_gettime(CLOCK_REALTIME, &abs_time);
-           abs_time.tv_sec += mutex_timeout;
+           abs_time.tv_sec += mutex_timeout; 
            abs_time.tv_nsec = 0;
-           ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
+	   ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time); 
            if (!ret) {
               /* Component has completed state transitions*/
               *pState = ((JPEGENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->nCurState;
               if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
-                 return OMX_ErrorUndefined;
+                 return OMX_ErrorUndefined; 
               }
               eError = OMX_ErrorNone;
            }
            else if(ret == ETIMEDOUT) {
               /* Unlock mutex in case of timeout */
               pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest);
-              return OMX_ErrorTimeout;
+              return OMX_ErrorTimeout; 
            }
         }
      }
@@ -1630,10 +1641,6 @@
         eError = OMX_ErrorInvalidComponent;
         *pState = OMX_StateInvalid;
     }
-
-    return eError;
-
-EXIT:
     return eError;
 }
 
@@ -1660,12 +1667,13 @@
     OMX_ERRORTYPE              eError            = OMX_ErrorNone;
     OMX_COMPONENTTYPE         *pHandle           = NULL;
     JPEGENC_COMPONENT_PRIVATE *pComponentPrivate = NULL;
-    JPEGENC_BUFFER_PRIVATE    *pBuffPrivate;
+    JPEGENC_BUFFER_PRIVATE    *pBuffPrivate = NULL;
     OMX_HANDLETYPE             hTunnelComponent;
     int i;
     int ret;
 
     OMX_CHECK_PARAM(pComponent);
+    OMX_CHECK_PARAM(pBuffHead);
 
     pHandle = (OMX_COMPONENTTYPE *)pComponent;
     pComponentPrivate = (JPEGENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
@@ -1684,7 +1692,6 @@
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
-
     if ( pBuffHead->nSize != sizeof(OMX_BUFFERHEADERTYPE) ) {
         eError = OMX_ErrorBadParameter;
         OMX_PRBUFFER4(pComponentPrivate->dbg, "JPEG-ENC: buffer header size is not correct\n");
@@ -1924,10 +1931,8 @@
 	pHandle = (OMX_COMPONENTTYPE *)hComponent;
 	pComponentPrivate = (JPEGENC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 	memcpy(&dbg, &(pComponentPrivate->dbg), sizeof(dbg));
-
         pthread_mutex_destroy(&pComponentPrivate->mutexStateChangeRequest);
         pthread_cond_destroy(&pComponentPrivate->StateChangeCondition);
-
 	JPEGEnc_Free_ComponentResources(pComponentPrivate);
 
 #ifdef RESOURCE_MANAGER_ENABLED
@@ -1942,8 +1947,6 @@
 	}
 
 #endif
-
-
     
 EXIT:
 #if 0
@@ -2328,7 +2331,7 @@
 
 /*-------------------------------------------------------------------*/
 /**
-  * JPEGENC_GetExtensionIndex()
+  * JPEGENC_GetExtensionIndex() 
   *
   * Return the index corresponding to the string.
   *
@@ -2338,27 +2341,31 @@
 /*-------------------------------------------------------------------*/
 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}
+    {"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},
+    {"OMX.TI.JPEG.encoder.Config.ColorFormatConvertion_420pTo422i", OMX_IndexCustomColorFormatConvertion_420pTo422i},
+    {"OMX.TI.JPEG.encoder.Config.PPLibEnable", OMX_IndexCustomPPLibEnable},
+    {"",0x0}
     };
 
-    /* Check parameter validity */
+    /* Check parameter validity */    
     OMX_CHECK_PARAM(hComponent);
     OMX_CHECK_PARAM(pIndexType);
+    *pIndexType = OMX_IndexMax;
 
-    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)))){
@@ -2368,7 +2375,7 @@
         }
     }
 
-    if (nIndex >= nExtensions){
+    if(*pIndexType == OMX_IndexMax){
          eError = OMX_ErrorUnsupportedIndex;
     }
 
@@ -2377,3 +2384,4 @@
 }
 
 
+
diff --git a/omx/image/src/openmax_il/jpeg_enc/test/JPEGTestEnc.c b/omx/image/src/openmax_il/jpeg_enc/test/JPEGTestEnc.c
index b8fc8e1..fc936e4 100755
--- a/omx/image/src/openmax_il/jpeg_enc/test/JPEGTestEnc.c
+++ b/omx/image/src/openmax_il/jpeg_enc/test/JPEGTestEnc.c
@@ -62,6 +62,7 @@
 #include <OMX_Component.h>
 #include "OMX_JpegEnc_CustomCmd.h"
 #include "JPEGTestEnc.h"
+#include "OMX_JpegEnc_Utils.h"
 
 /* DSP recovery includes */
 #include <qosregistry.h>
@@ -80,8 +81,7 @@
 #ifdef UNDER_CE
 OMX_STRING StrJpegEncoder= "OMX.TI.IMAGE.JPEG.ENC"; 
 #else
- OMX_STRING StrJpegEncoder= "OMX.TI.JPEG.Encoder"; 
-/* OMX_STRING StrJpegEncoder= "OMX.TI.JPEG.encoder"; */
+ OMX_STRING StrJpegEncoder= "OMX.TI.JPEG.Encoder";
 #endif
 
 OMX_U8 APPLICATION1_NOTHUMB[]={
@@ -718,6 +718,7 @@
     MyEvent.pEventInfo = pEventData;
     PRINT("Inside Test Application EventHandler function\n");
     eError = pComponent->GetState (hComponent, &state);
+
     if ( eError != OMX_ErrorNone ) {
         PRINT("Error: From JPEGENC_GetState\n");
     }
@@ -1017,6 +1018,7 @@
     printf("w.. Width Of Image\n");
     printf("h.. Height Of Image\n");
     printf("f.. Input Of Image:\n    1.- YUV 420 Planer\n    2.- YUV 422 Interleaved UYVY\n    3.- 32 bit RAW (RGB32)\n    4.- 16 bit RAW (RGB16)\n    5.- YUV 422 Interleaved YUYV\n");
+    printf("z.. 420p to 422i conversion before encode \n");
     printf("q.. Quality Factor Of Image: 1 to 100\n");
     printf("b.. Exit Buffer: 1 o 2\n");
     printf("c.. Marker Comment: The comment string length should be less than 255 characters\n");
@@ -1081,6 +1083,8 @@
     OMX_PARAM_PORTDEFINITIONTYPE* pOutPortDef = NULL;
     OMX_CONFIG_RECTTYPE sCrop;
 
+    OMX_BOOL bConvertion_420pTo422i = OMX_FALSE;
+
 #ifdef UNDER_CE
     TCHAR* szInFile = NULL;
     TCHAR* szOutFile = NULL; 
@@ -1120,7 +1124,7 @@
 #endif
 
     int next_option;
-    const char* const short_options = "i:o:w:h:f:q:b:c:x:y:s:k:t:u:r:v:l:n:p:ajemd";
+    const char* const short_options = "i:o:w:h:f:q:b:c:x:y:s:k:t:u:r:v:l:n:p:ajemdvlz";
     const struct option long_options[] = 
     {
         { "InputFile",1, NULL, 'i' },
@@ -1147,6 +1151,7 @@
         { "MarkerAPP5",0,NULL,'d'},
         { "CroppedWidth",0,NULL,'v'},               
         { "CroppedHeight",0,NULL,'l'},                       
+        { "420pTo422iConversion",0,NULL,'z'},
         { NULL, 0, NULL, 0 }                
     };
 
@@ -1223,6 +1228,11 @@
         inputformat=atoi(optarg);
         break;
     
+        case 'z':
+        bConvertion_420pTo422i = OMX_TRUE;
+        PRINT("\n ********* bConvertion_420pTo422i is set to TRUE \n");
+        break;
+
         case 'q':
         qualityfactor=atoi(optarg);
         break;
@@ -1532,6 +1542,9 @@
 	if ( inputformat == 2 || inputformat == 3 || inputformat == 4 ) {
 	     pOutPortDef->format.image.eColorFormat =  OMX_COLOR_FormatCbYCrY; 
 	}
+	else if ( inputformat == 1 && bConvertion_420pTo422i ) {
+	    pOutPortDef->format.image.eColorFormat =  OMX_COLOR_FormatCbYCrY;
+	}
 	else {
 	    pOutPortDef->format.image.eColorFormat = OMX_COLOR_FormatYUV420PackedPlanar;
 	}
@@ -1559,6 +1572,13 @@
 	   goto EXIT;
 	}
     
+	error = OMX_SetConfig(pHandle, OMX_IndexCustomColorFormatConvertion_420pTo422i, &bConvertion_420pTo422i);
+	if ( error != OMX_ErrorNone ) {
+	    printf("%d::APP_Error at function call: %x\n", __LINE__, error);
+	   error = OMX_ErrorBadParameter;
+	   goto EXIT;
+	}
+
 	if (bSetCustomQuatizationTable){
 
 		pQuantizationTable->eQuantizationTable = OMX_IMAGE_QuantizationTableLuma;
@@ -2025,7 +2045,7 @@
     
 	error = TIOMX_Deinit();
 	if ( error != OMX_ErrorNone ) {
-	    printf("Error returned by OMX_Init()\n");
+	    printf("Error returned by OMX_DeInit()\n");
 	}
 
 #ifdef STRESS
@@ -2053,7 +2073,7 @@
     unsigned int numProcs;
     char* argv[2];
    
-    argv[0] = "/system/lib/dsp/baseimage.dof";
+    argv[0] = "/lib/dsp/baseimage.dof";
     
     status = (DBAPI)DspManager_Open(0, NULL);
     if (DSP_FAILED(status)) {
diff --git a/omx/system/src/openmax_il/common/inc/OMX_TI_Common.h b/omx/system/src/openmax_il/common/inc/OMX_TI_Common.h
index 947189d..7822483 100755
--- a/omx/system/src/openmax_il/common/inc/OMX_TI_Common.h
+++ b/omx/system/src/openmax_il/common/inc/OMX_TI_Common.h
@@ -1,54 +1,74 @@
-/* ====================================================================
-*             Texas Instruments OMAP(TM) Platform Software
-* (c) Copyright Texas Instruments, Incorporated. All Rights Reserved.
-*
-* Use of this software is controlled by the terms and conditions found
-* in the license agreement under which this software has been supplied.
-* ==================================================================== */
 
+/*
+ * Copyright (C) Texas Instruments - http://www.ti.com/
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+/* =============================================================================
+*             Texas Instruments OMAP(TM) Platform Software
+*  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
+*
+*  Use of this software is controlled by the terms and conditions found 
+*  in the license agreement under which this software has been supplied.
+* =========================================================================== */
 /** OMX_TI_Common.h
- *  The LCML header file contains the definitions used by both the
- *  application and the component to access common items.
+  *  The LCML header file contains the definitions used by both the
+  *  application and the component to access common items.
  */
 
 #ifndef __OMX_TI_COMMON_H__
 #define __OMX_TI_COMMON_H__
 
-#include <OMX_Component.h>
-#include <OMX_TI_Debug.h>
+#include "OMX_Component.h"
+#include "OMX_TI_Debug.h"
 
-/* OMX_TI_SEVERITYTYPE enumeration is used to indicate severity level of errors returned by TI OpenMax components. 
-   Critcal	Requires reboot/reset DSP
-   Severe	Have to unload components and free memory and try again
-   Major	Can be handled without unloading the component
-   Minor	Essentially informational 
-*/
+/* OMX_TI_SEVERITYTYPE enumeration is used to indicate severity level of errors
+          returned by TI OpenMax components.
+    Critical      Requires reboot/reset DSP
+    Severe       Have to unload components and free memory and try again
+    Major        Can be handled without unloading the component
+    Minor        Essentially informational
+ */
 typedef enum OMX_TI_SEVERITYTYPE {
-	OMX_TI_ErrorCritical=1,
-	OMX_TI_ErrorSevere,
-	OMX_TI_ErrorMajor,
-	OMX_TI_ErrorMinor
+    OMX_TI_ErrorCritical = 1,
+    OMX_TI_ErrorSevere,
+    OMX_TI_ErrorMajor,
+    OMX_TI_ErrorMinor
 } OMX_TI_SEVERITYTYPE;
 
 /* ======================================================================= */
 /**
  * @def    EXTRA_BYTES   For Cache alignment
-	       DSP_CACHE_ALIGNMENT  For Cache alignment
+           DSP_CACHE_ALIGNMENT  For Cache alignment
  *
  */
 /* ======================================================================= */
-#define EXTRA_BYTES 128
-#define DSP_CACHE_ALIGNMENT 256
+#define EXTRA_BYTES 256
+#define DSP_CACHE_ALIGNMENT 128
 
 /* ======================================================================= */
 /**
- * @def    OMX_MALLOC   Macro to allocate Memory
+ * @def    OMX_MALLOC_GENERIC   Macro to allocate Memory
  */
 /* ======================================================================= */
 #define OMX_MALLOC_GENERIC(_pStruct_, _sName_)                         \
     OMX_MALLOC_SIZE(_pStruct_,sizeof(_sName_),_sName_)
 
-   /* ======================================================================= */
+/* ======================================================================= */
 /**
  * @def    OMX_MALLOC_SIZE   Macro to allocate Memory
  */
@@ -71,8 +91,8 @@
  */
 /* ======================================================================= */
 #define OMX_MALLOC_SIZE_DSPALIGN(_ptr_, _size_,_name_)            \
-    OMX_MALLOC_SIZE(_ptr_, _size_ + DSP_CACHE_ALIGNMENT, _name_); \
-    _ptr_ = (_name_*)(((OMX_U8*)_ptr_ + EXTRA_BYTES));
+    OMX_MALLOC_SIZE(_ptr_, _size_ + EXTRA_BYTES, _name_); \
+    _ptr_ = (_name_*)(((OMX_U8*)_ptr_ + DSP_CACHE_ALIGNMENT));
 
 /* ======================================================================= */
 /**
@@ -80,10 +100,10 @@
  */
 /* ======================================================================= */
 #define OMX_MEMFREE_STRUCT(_pStruct_)\
-    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: [FREE] %p\n",__LINE__,_pStruct_);\
+    OMXDBG_PRINT(stderr, BUFFER, 2, OMX_DBG_BASEMASK, "%d :: [FREE] %p\n",__LINE__,_pStruct_); \
     if(_pStruct_ != NULL){\
-       newfree(_pStruct_);\
-	_pStruct_ = NULL;\
+        newfree(_pStruct_);\
+        _pStruct_ = NULL;\
     }
 
 /* ======================================================================= */
@@ -93,10 +113,9 @@
 /* ======================================================================= */
 #define OMX_MEMFREE_STRUCT_DSPALIGN(_pStruct_,_name_)\
     if(_pStruct_ != NULL){\
-      _pStruct_ = (_name_*)(((OMX_U8*)_pStruct_ - EXTRA_BYTES));\
-      OMX_MEMFREE_STRUCT(_pStruct_);\
+        _pStruct_ = (_name_*)(((OMX_U8*)_pStruct_ - DSP_CACHE_ALIGNMENT));\
+        OMX_MEMFREE_STRUCT(_pStruct_);\
     }
 
-#endif
+#endif /*  end of  #ifndef __OMX_TI_COMMON_H__ */
 /* File EOF */
-
diff --git a/omx/system/src/openmax_il/common/inc/OMX_TI_Debug.h b/omx/system/src/openmax_il/common/inc/OMX_TI_Debug.h
index 8d41e9a..6dfae32 100644
--- a/omx/system/src/openmax_il/common/inc/OMX_TI_Debug.h
+++ b/omx/system/src/openmax_il/common/inc/OMX_TI_Debug.h
@@ -544,4 +544,67 @@
 #define OMX_DBG_COL_STATE OMX_DBG_COL_BLUE
 #endif
 
+#ifdef OMX_MEMDEBUG
+#define mem_array_size=500;
+
+void *arr[mem_array_size];
+int lines[mem_array_size];
+int bytes[mem_array_size];
+char file[mem_array_size][50];
+
+#define newmalloc(x) mymalloc(__LINE__,__FILE__,x)
+#define newfree(z) myfree(z,__LINE__,__FILE__)
+
+void * mymalloc(int line, char *s, int size);
+int myfree(void *dp, int line, char *s);
+
+void * mymalloc(int line, char *s, int size)
+{
+   void *p;    
+   int e=0;
+   p = malloc(size);
+   if(p==NULL){
+       OMXDBG_PRINT(stderr, ERROR, 4, 0, "Memory not available\n");
+       /* ddexit(1); */
+       }
+   else{
+         while((lines[e]!=0)&& (e<(mem_array_size - 1)) ){
+              e++;
+         }
+         arr[e]=p;
+         lines[e]=line;
+         bytes[e]=size;
+         strcpy(file[e],s);
+         OMXDBG_PRINT(stderr, BUFFER, 2, 0, 
+            "Allocating %d bytes on address %p, line %d file %s pos %d\n", size, p, line, s, e);
+   }
+   return p;
+}
+
+int myfree(void *dp, int line, char *s){
+    int q;
+    for(q=0;q<mem_array_size;q++){
+        if(arr[q]==dp){
+           OMXDBG_PRINT(stderr, PRINT, 2, 0, "Deleting %d bytes on address %p, line %d file %s\n",
+                   bytes[q],dp, line, s);
+           free(dp);
+           dp = NULL;
+           lines[q]=0;
+           strcpy(file[q],"");
+           break;
+        }            
+     }    
+     if(mem_array_size==q){
+         OMXDBG_PRINT(stderr, PRINT, 2, 0, "\n\nPointer not found. Line:%d    File%s!!\n\n",line, s);
+     }
+}
+
+#else
+
+#define newmalloc(x) malloc(x)
+#define newfree(z) free(z)
+
+#endif
+
+
 #endif
diff --git a/omx/system/src/openmax_il/common/inc/TIDspOmx.h b/omx/system/src/openmax_il/common/inc/TIDspOmx.h
index 1886832..3e427f0 100644
--- a/omx/system/src/openmax_il/common/inc/TIDspOmx.h
+++ b/omx/system/src/openmax_il/common/inc/TIDspOmx.h
@@ -609,8 +609,7 @@
     int i = sizeof(OMX_MMMIXER_ITOA_str) - 1;\
     do {\
         OMX_MMMIXER_ITOA_str[--i] = '0' + _integer_ % 10;\
-    }\
-    while ((_integer_ = _integer_ / 10) && i >= 0);\
+    } while ((_integer_ = _integer_ / 10) && i > 0);\
     strcpy(_alpha_,&OMX_MMMIXER_ITOA_str[i]);\
 }    
 
diff --git a/omx/system/src/openmax_il/lcml/inc/LCML_CodecInterface.h b/omx/system/src/openmax_il/lcml/inc/LCML_CodecInterface.h
index 18ecd3d..acaeca7 100644
--- a/omx/system/src/openmax_il/lcml/inc/LCML_CodecInterface.h
+++ b/omx/system/src/openmax_il/lcml/inc/LCML_CodecInterface.h
@@ -35,7 +35,7 @@
 #define __LCML_CODECINTERFACE_H__
 
 #include <OMX_Core.h>
-
+#include <OMX_TI_Debug.h>
 /** 
  * Commands to send messages to codec 
  */
@@ -62,6 +62,8 @@
     EMMCodecScratchBuffer*/
     EMMCodecInputBufferMapBufLen  = 1000,
     EMMCodecOutputBufferMapBufLen  = 1001,
+    EMMCodecInputBufferMapReuse  = 1002,
+    EMMCodecOutputBufferMapReuse  = 1003,
     EMMCodecInputBuffer  = 2000,
     EMMCodecStream0      = 2000,
     EMMCodecOuputBuffer  = 2001,
@@ -126,6 +128,7 @@
 
     OMX_PTR pCodecPrivate;
     OMX_HANDLETYPE pCodec;
+    struct OMX_TI_Debug dbg;
 
 }LCML_CODEC_INTERFACE;
 
diff --git a/omx/system/src/openmax_il/lcml/inc/LCML_DspCodec.h b/omx/system/src/openmax_il/lcml/inc/LCML_DspCodec.h
index 44cea39..a5482e7 100644
--- a/omx/system/src/openmax_il/lcml/inc/LCML_DspCodec.h
+++ b/omx/system/src/openmax_il/lcml/inc/LCML_DspCodec.h
@@ -38,6 +38,9 @@
 #define MAX_OBJS                10
 #define MAX_STREAMS             10
 
+/* 720p implementation */
+#define MAX_DMM_BUFFERS 20
+
 /*DSP specific*/
 #define DSP_DOF_IMAGE           "baseimage.dof"
 #define TI_PROCESSOR_DSP        0
@@ -48,22 +51,20 @@
 #define QUEUE_SIZE              20
 #define ROUND_TO_PAGESIZE(n)    ((((n)+4095)/DMM_PAGE_SIZE)*DMM_PAGE_SIZE)
 
-#if 1
-    #define __ERROR_PROPAGATION__ 
-#endif
+#define __ERROR_PROPAGATION__
 
 
+/*switch on/off here */
 #ifndef UNDER_CE
-    #define LCML_ERROR_PRINT printf
-/*    #define LCML_DPRINT(...)    fprintf(stderr,__VA_ARGS__)*/
-   #define LCML_DPRINT(...) 
+#ifdef ANDROID
+    #include <utils/Log.h>
+#endif
 #else
     #include <oaf_osal.h>
     #include <oaf_debug.h>
 #endif
 
 
-
 #ifdef __PERF_INSTRUMENTATION__
 #include "perf.h"
 #endif
@@ -171,9 +172,9 @@
 
 /** ========================================================================
 *  The LCML_WaitForEvent Wait for a event sychronously
-*  @param  hInterface -  Handle of the component to be accessed.  This is the 
+*  @param  hInterface -  Handle of the component to be accessed.  This is the
 *      component handle returned by the call to the GetHandle function.
-*  @param  event - Event occured 
+*  @param  event - Event occured
 *  @param  args - Array of "void *" that contains the associated arguments for
 *             occured event
 *
@@ -190,11 +191,11 @@
         event,                                             \
         args)                          /* Macro End */
 
-        
+
 /** ========================================================================
-*  The LCML_QueueBuffer send data to DSP convert it into USN format and send 
+*  The LCML_QueueBuffer send data to DSP convert it into USN format and send
 *  it to DSP via setbuff
-*  @param [in] hInterface -  Handle of the component to be accessed.  This is 
+*  @param [in] hInterface -  Handle of the component to be accessed.  This is
 *      the component handle returned by the call to the GetHandle function.
 *  @param  bufType - type of buffer
 *  @param  buffer - pointer to buffer
@@ -202,7 +203,7 @@
 *  @param  bufferSizeUsed - length of used buffer
 *  @param  auxInfo - pointer to parameter
 *  @param  auxInfoLen - length of  parameter
-*  @param  usrArg - not used 
+*  @param  usrArg - not used
 *  @return OMX_ERRORTYPE
 *      If the command successfully executes, the return code will be
 *      OMX_NoError.  Otherwise the appropriate OMX error will be returned.
@@ -227,9 +228,9 @@
         usrArg)
 
 /** ========================================================================
-*  The LCML_ControlCodec send command to DSP convert it into USN format and 
+*  The LCML_ControlCodec send command to DSP convert it into USN format and
 *  send it to DSP
-*  @param  hInterface -  Handle of the component to be accessed.  This is the 
+*  @param  hInterface -  Handle of the component to be accessed.  This is the
 *      component handle returned by the call to the GetHandle function.
 *  @param  bufType - type of buffer
 *  @param  iCodecCmd -  command refer TControlCmd
@@ -257,14 +258,14 @@
 OMX_ERRORTYPE GetHandle (OMX_HANDLETYPE* hInterface );
 
 /**
-* Struct derives codec interface which have interface to implement for using 
-* generic codec and also have pointer to DSP specific data and have queues for 
+* Struct derives codec interface which have interface to implement for using
+* generic codec and also have pointer to DSP specific data and have queues for
 * storing input and output data
 */
 typedef struct LCML_DSP_INTERFACE
 {
     OMX_HANDLETYPE pCodecinterfacehandle;  /* handle to interface struct LCML_CODEC_INTERFACE *dspcodecinterface */
-    struct LCML_DSP *dspCodec; 
+    struct LCML_DSP *dspCodec;
     OMX_PTR pComponentPrivate;
     void * iUsrArg;
     /*queue to store USN structure*/
@@ -274,11 +275,11 @@
     OMX_U32 iBufinputcount;
     OMX_U32 iBufoutputcount;
     OMX_U32 pshutdownFlag;
-#ifdef __ERROR_PROPAGATION__    
+#ifdef __ERROR_PROPAGATION__
     struct DSP_NOTIFICATION * g_aNotificationObjects[3];
 #else
     struct DSP_NOTIFICATION * g_aNotificationObjects[1];
-#endif    
+#endif
     pthread_t g_tidMessageThread;
     OMX_U32 algcntlmapped[QUEUE_SIZE];
     DMM_BUFFER_OBJ *pAlgcntlDmmBuf[QUEUE_SIZE];
@@ -291,6 +292,10 @@
 #ifdef __PERF_INSTRUMENTATION__
     PERF_OBJHANDLE pPERF, pPERFcomp;
 #endif
+    DMM_BUFFER_OBJ mapped_dmm_buffers[MAX_DMM_BUFFERS];
+    OMX_U32 mapped_buffer_count;
+    OMX_BOOL ReUseMap;
+    pthread_mutex_t m_isStopped_mutex;
 
 }LCML_DSP_INTERFACE;
 
diff --git a/omx/system/src/openmax_il/lcml/src/Android.mk b/omx/system/src/openmax_il/lcml/src/Android.mk
index 48ee8dc..cd50ead 100644
--- a/omx/system/src/openmax_il/lcml/src/Android.mk
+++ b/omx/system/src/openmax_il/lcml/src/Android.mk
@@ -4,17 +4,20 @@
 
 LOCAL_PRELINK_MODULE := false
 
+
 LOCAL_SRC_FILES:= \
 	LCML_DspCodec.c
 
 LOCAL_C_INCLUDES += \
 	$(TI_OMX_INCLUDES) \
 	$(TI_BRIDGE_INCLUDES) \
-	$(TI_OMX_SYSTEM)/lcml/inc \
+	$(TI_OMX_SYSTEM)/common/inc	\
+	$(TI_OMX_SYSTEM)/lcml/inc	\
 	$(TI_OMX_SYSTEM)/perf/inc
 
 LOCAL_SHARED_LIBRARIES := \
 	libdl 		\
+	liblog \
 	libbridge	\
 	libOMX_Core
 
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 2ab0b1a..8eaf01a 100644
--- a/omx/system/src/openmax_il/lcml/src/LCML_DspCodec.c
+++ b/omx/system/src/openmax_il/lcml/src/LCML_DspCodec.c
@@ -61,18 +61,19 @@
 #define CEXEC_DONE 1
 /*DSP_HNODE hDasfNode;*/
 #define ABS_DLL_NAME_LENGTH 128
-
+#undef LOG_TAG
+#define LOG_TAG "TI_LCML"
 
 #define LCML_MALLOC(p,s,t) \
     p = (t*)malloc(s);                  \
     if (NULL == p){             \
-        LCML_DPRINT("LCML:::::::: ERROR(#%d F:%s)!!! Ran out of memory while trying to allocate %d bytes!!!\n",__LINE__,__FUNCTION__,s);    \
+        OMXDBG_PRINT(stderr, ERROR, 4, OMX_DBG_BASEMASK, "LCML:::::::: ERROR(#%d F:%s)!!! Ran out of memory while trying to allocate %d bytes!!!\n",__LINE__,__FUNCTION__,s);    \
     }else { \
-        LCML_DPRINT("LCML:::::::: (#%d F:%s)Success to allocate %d bytes ... pointer %p\n",__LINE__,__FUNCTION__,s,p); \
+        OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "LCML:::::::: (#%d F:%s)Success to allocate %d bytes ... pointer %p\n",__LINE__,__FUNCTION__,s,p); \
     }
 
 #define LCML_FREE(p)    \
-        LCML_DPRINT("LCML:::::::: (#%d F:%s)Freeing pointer %p done",__LINE__,__FUNCTION__,p); \
+        OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "LCML:::::::: (#%d F:%s)Freeing pointer %p done",__LINE__,__FUNCTION__,p); \
         free(p);    
 
 /*Prototyping*/
@@ -103,14 +104,14 @@
                                   void *args[10]);
 static OMX_ERRORTYPE DmmMap(DSP_HPROCESSOR ProcHandle,
                      OMX_U32 size,
-                     OMX_U32 sizeUsed,
                      void* pArmPtr,
                      DMM_BUFFER_OBJ* pDmmBuf,
-                     OMX_U32 MapBufLen);
-                     
+                     struct OMX_TI_Debug dbg);
+
 static OMX_ERRORTYPE DmmUnMap(DSP_HPROCESSOR ProcHandle,
                               void *pMapPtr,
-                              void *pResPtr);
+                              void *pResPtr,
+                              struct OMX_TI_Debug dbg);
 static OMX_ERRORTYPE DeleteDspResource(LCML_DSP_INTERFACE *hInterface);
 static OMX_ERRORTYPE FreeResources(LCML_DSP_INTERFACE *hInterface);
 
@@ -132,8 +133,8 @@
     LCML_DSP_INTERFACE* pHandle;
     struct LCML_CODEC_INTERFACE *dspcodecinterface ;
 
-    LCML_DPRINT("%d :: GetHandle application\n",__LINE__);
-     LCML_MALLOC(*hInterface,sizeof(LCML_DSP_INTERFACE),LCML_DSP_INTERFACE);
+    OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "%d :: GetHandle application\n",__LINE__);
+    LCML_MALLOC(*hInterface,sizeof(LCML_DSP_INTERFACE),LCML_DSP_INTERFACE);
 
     if (hInterface == NULL)
     {
@@ -151,6 +152,7 @@
         goto EXIT;
     }
     memset(dspcodecinterface, 0, sizeof(LCML_CODEC_INTERFACE));
+    OMX_DBG_INIT (dspcodecinterface->dbg, "TI_LCML");
 
     pHandle->pCodecinterfacehandle = dspcodecinterface;
     dspcodecinterface->InitMMCodec = InitMMCodec;
@@ -168,9 +170,9 @@
     memset(pHandle->dspCodec, 0, sizeof(LCML_DSP));
 
     pthread_mutex_init (&pHandle->mutex, NULL);
-    LCML_DPRINT("%p :: GetHandle application\n",pHandle);
     dspcodecinterface->pCodec = *hInterface;
-    LCML_DPRINT("%p :: GetHandle application\n",pHandle->dspCodec);
+    OMX_PRINT2 (dspcodecinterface->dbg, "GetHandle application handle %p dspCodec %p",pHandle, pHandle->dspCodec);
+
 EXIT:
     return (err);
 }
@@ -204,7 +206,7 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 dllinfo;
 
-    LCML_DPRINT("%d :: InitMMCodecEx application\n", __LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: InitMMCodecEx application\n", __LINE__);
 
     if (hInt == NULL )
     {
@@ -231,7 +233,7 @@
         k = append_dsp_path(DSP_DOF_IMAGE, argv);
         if (k < 0)
         {
-            LCML_DPRINT("%d :: append_dsp_path returned an error!\n", __LINE__);
+            OMX_PRDSP4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
             eError = OMX_ErrorBadParameter;
             goto ERROR;
         }
@@ -249,6 +251,11 @@
         PERF_Boundary(phandle->pPERF,
                       PERF_BoundaryStart | PERF_BoundarySetup);
 #endif
+        /* 720p implementation */
+        {
+            pthread_mutex_init(&phandle->m_isStopped_mutex, NULL);
+            phandle->mapped_buffer_count = 0;
+        }
         /* INIT DSP RESOURCE */
         if(pCallbacks)
             phandle->dspCodec->Callbacks.LCML_Callback = pCallbacks->LCML_Callback;
@@ -259,25 +266,25 @@
         }
 
         /* INITIALIZATION OF DSP */
-        LCML_DPRINT("%d :: Entering Init_DSPSubSystem\n", __LINE__);
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Entering Init_DSPSubSystem\n", __LINE__);
         status = DspManager_Open(0, NULL);
         DSP_ERROR_EXIT(status, "DSP Manager Open", ERROR);
-        LCML_DPRINT("DspManager_Open Successful\n");
+        OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DspManager_Open Successful\n");
 
         /* Attach and get handle to processor */
         status = DSPProcessor_Attach(TI_PROCESSOR_DSP, NULL, &(phandle->dspCodec->hProc));
         DSP_ERROR_EXIT(status, "Attach processor", ERROR);
-        LCML_DPRINT("DSPProcessor_Attach Successful\n");
-        LCML_DPRINT("Base Image is Already Loaded\n");
+        OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DSPProcessor_Attach Successful\n");
+        OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Base Image is Already Loaded\n");
 
         for (dllinfo=0; dllinfo < phandle->dspCodec->NodeInfo.nNumOfDLLs; dllinfo++)
         {
-            LCML_DPRINT("%d :: Register Component Node\n",phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Register Component Node\n",phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
 
             k = append_dsp_path((char*)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].DllName, abs_dsp_path);
             if (k < 0)
             {
-                LCML_DPRINT("%d :: append_dsp_path returned an error!\n", __LINE__);
+                OMX_PRDSP4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
                 eError = OMX_ErrorBadParameter;
                 goto ERROR;
             }
@@ -292,33 +299,33 @@
         NodeAttrIn.cbStruct = sizeof(struct DSP_NODEATTRIN);
         NodeAttrIn.iPriority = phandle->dspCodec->Priority;
         NodeAttrIn.uTimeout = phandle->dspCodec->Timeout;
-NodeAttrIn.uTimeout = 1000; /* WORKAROUND */       
+        NodeAttrIn.uTimeout = 1000; /* WORKAROUND */       
         NodeAttrIn.uProfileID= phandle->dspCodec->ProfileID;
         /* Prepare Create Phase Argument */
-        LCML_DPRINT("%d :: Prepare Create Phase Argument \n", __LINE__);
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Prepare Create Phase Argument \n", __LINE__);
         /* TO DO check is application setting it properly */
         i = 0;
         if(phandle->dspCodec->pCrPhArgs !=NULL)
         {
             while((phandle->dspCodec->pCrPhArgs[i] != END_OF_CR_PHASE_ARGS) && (i < LCML_DATA_SIZE))
             {
-                LCML_DPRINT("%d :: copying Create Phase Argument \n", i);
+                OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: copying Create Phase Argument \n", i);
                 crData.cData[i] = phandle->dspCodec->pCrPhArgs[i];
-                LCML_DPRINT("%d :: CR PH arg[%d] = %d \n",__LINE__, i, crData.cData[i]);
+                OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: CR PH arg[%d] = %d \n",__LINE__, i, crData.cData[i]);
                 i++;
-                LCML_DPRINT("%d : Inside create phase while loop\n", __LINE__);
             }
         }
         else
         {
-            LCML_DPRINT("%d :: ILLEGAL CREATEPHASE SET IT ..\n", __LINE__);
+            OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL CREATEPHASE SET IT ..\n", __LINE__);
             eError = OMX_ErrorBadParameter;
             goto ERROR;
         }
 
         if (i >= LCML_DATA_SIZE)
         {
-            LCML_DPRINT("%d :: Reached end of Create Phase Args Array. Did not find END_OF_CR_PHASE_ARGS marker. \n", __LINE__);
+            OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, 
+                    "%d :: Reached end of Create Phase Args Array. Did not find END_OF_CR_PHASE_ARGS marker. \n", __LINE__);
             eError = OMX_ErrorBadParameter;
             goto ERROR;            
         }
@@ -326,27 +333,25 @@
         /* LCML_DPRINT("Create Phase args  strlen = %d\n",strlen(crData.cData)); */
         /* crData.cbData = sizeof (ULONG) + strlen(crData.cData); */
         crData.cbData = i*2;
-        LCML_DPRINT("Create Phase args  strlen = %ld\n", crData.cbData);
+        OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Create Phase args  strlen = %ld\n", crData.cbData);
 
         status = DSPNode_Allocate(phandle->dspCodec->hProc,
                                   (struct DSP_UUID *)phandle->dspCodec->NodeInfo.AllUUIDs[0].uuid,
                                   (struct DSP_CBDATA*)&crData,
                                   &NodeAttrIn,&(phandle->dspCodec->hNode));
         DSP_ERROR_EXIT(status, "Allocate Component", ERROR);
-        LCML_DPRINT("%d :: DSPNode_Allocate Successfully\n", __LINE__);
+        OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Allocate Successfully\n", __LINE__);
 
         pArgs = (struct DSP_CBDATA *)argsBuf;
         strcpy((char*)pArgs->cData, Args);
         pArgs->cbData = (ULONG)strlen ((char *)pArgs->cData);
 
         /* For debugging on connect DSP nodes */
-        LCML_DPRINT("[LCML] - struct DSP_CBDATA.cbData (length): %d\n", (int)pArgs->cbData);
-        LCML_DPRINT("[LCML] - struct DSP_CBDATA.cData: %s\n", (char *)pArgs->cData);
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "[LCML] - struct DSP_CBDATA.cbData (length): %d %s\n", (int)pArgs->cbData, (char *)pArgs->cData);
 
         if (phandle->dspCodec->DeviceInfo.TypeofDevice == 1)
         {
-            LCML_DPRINT("%d :: Audio Device Selected\n", __LINE__);
-            LCML_DPRINT("%d :: -------- DASF Functionality ------- \n",__LINE__);
+            OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Audio Device Selected\n", __LINE__);
             status = DSPNode_Allocate(phandle->dspCodec->hProc,
                                       (struct DSP_UUID *)phandle->dspCodec->DeviceInfo.AllUUIDs[0].uuid,
                                       NULL,
@@ -355,14 +360,13 @@
             DSP_ERROR_EXIT(status, "DASF Allocate Component", ERROR);
 
 
-            LCML_DPRINT("%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
-            LCML_DPRINT("%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
+            OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
             if(phandle->dspCodec->DeviceInfo.DspStream != NULL)
             {
                 if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
                 {
                     /* render for playback */
-                    LCML_DPRINT("%d :: Render for playback\n", __LINE__);
+                    OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for playback\n", __LINE__);
                     status = DSPNode_ConnectEx(phandle->dspCodec->hNode,
                                                0,
                                                (phandle->dspCodec->hDasfNode),
@@ -374,7 +378,7 @@
                 else if(phandle->dspCodec->DeviceInfo.TypeofRender == 1)
                 {
                     /* render for record */
-                    LCML_DPRINT("%d :: Render for record\n", __LINE__);
+                    OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for record\n", __LINE__);
                     status = DSPNode_ConnectEx(phandle->dspCodec->hDasfNode,
                                                0,
                                                phandle->dspCodec->hNode,
@@ -386,7 +390,7 @@
             }
             else
             {
-                LCML_DPRINT("%d :: ILLEGAL STREAM PARAMETER SET IT ..\n",__LINE__);
+                OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL STREAM PARAMETER SET IT ..\n",__LINE__);
                 eError = OMX_ErrorBadParameter;
                 goto ERROR;
             }
@@ -394,21 +398,21 @@
 
         status = DSPNode_Create(phandle->dspCodec->hNode);
         DSP_ERROR_EXIT(status, "Create the Node", ERROR);
-        LCML_DPRINT("%d :: After DSPNode_Create !!! \n", __LINE__);
+        OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: After DSPNode_Create !!! \n", __LINE__);
 
         status = DSPNode_Run(phandle->dspCodec->hNode);
         DSP_ERROR_EXIT (status, "Goto RUN mode", ERROR);
-        LCML_DPRINT("%d :: DSPNode_Run Successfully\n", __LINE__);
+        OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Run Successfully\n", __LINE__);
 
         if ((phandle->dspCodec->In_BufInfo.DataTrMethod == DMM_METHOD) || (phandle->dspCodec->Out_BufInfo.DataTrMethod == DMM_METHOD))
         {
             struct DSP_NOTIFICATION* notification;
-            LCML_DPRINT("%d :: Registering the Node for Messaging\n",__LINE__);
+            OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
 
 	        LCML_MALLOC(notification,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION)
             if(notification == NULL)
             {
-                LCML_DPRINT("%d :: malloc failed....\n",__LINE__);
+                OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
                 goto ERROR;
             }
             memset(notification, 0, sizeof(struct DSP_NOTIFICATION));
@@ -419,36 +423,36 @@
 #ifdef __ERROR_PROPAGATION__
             struct DSP_NOTIFICATION* notification_mmufault;
 
-            LCML_DPRINT("%d :: Registering the Node for Messaging\n",__LINE__);
+            OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
 
             LCML_MALLOC(notification_mmufault,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
             if(notification_mmufault == NULL)
             {
-                LCML_DPRINT("%d :: malloc failed....\n",__LINE__);
+                OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
                 goto ERROR;
             }
             memset(notification_mmufault,0,sizeof(struct DSP_NOTIFICATION));
-            
+
             status = DSPProcessor_RegisterNotify(phandle->dspCodec->hProc, DSP_MMUFAULT, DSP_SIGNALEVENT, notification_mmufault);
             DSP_ERROR_EXIT(status, "DSP node register notify DSP_MMUFAULT", ERROR);
             phandle->g_aNotificationObjects[1] =  notification_mmufault;
-            
+
             struct DSP_NOTIFICATION* notification_syserror ;
-           
-            LCML_DPRINT("%d :: Registering the Node for Messaging\n",__LINE__);
+
+            OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
 
             LCML_MALLOC(notification_syserror,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
             if(notification_syserror == NULL)
             {
-                LCML_DPRINT("%d :: malloc failed....\n",__LINE__);
+                OMX_ERROR4  (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
                 goto ERROR;
             }
             memset(notification_syserror,0,sizeof(struct DSP_NOTIFICATION));
-            
+
             status = DSPProcessor_RegisterNotify(phandle->dspCodec->hProc, DSP_SYSERROR, DSP_SIGNALEVENT, notification_syserror);
             DSP_ERROR_EXIT(status, "DSP node register notify DSP_SYSERROR", ERROR);
             phandle->g_aNotificationObjects[2] =  notification_syserror;
-#endif     
+#endif
         }
 
         /* Listener thread */
@@ -461,7 +465,7 @@
                                 (void*)phandle);
         if (tmperr || !phandle->g_tidMessageThread)
         {
-            LCML_DPRINT("Thread creation failed: 0x%x",tmperr);
+            OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Thread creation failed: 0x%x",tmperr);
             eError = OMX_ErrorInsufficientResources;
             goto ERROR;
         }
@@ -474,7 +478,7 @@
         /* init buffers buffer counter */
         phandle->iBufinputcount = 0;
         phandle->iBufoutputcount = 0;
-        
+
         for (i = 0; i < QUEUE_SIZE; i++)
         {
             phandle->Arminputstorage[i] = NULL;
@@ -494,7 +498,7 @@
 #ifndef CEXEC_DONE
     LCML_FREE(argv);
 #endif
-    LCML_DPRINT("%d :: Exiting Init_DSPSubSystem\n", __LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Exiting Init_DSPSubSystem\n error = %x\n", __LINE__, eError);
     return eError;
 }
 
@@ -527,7 +531,7 @@
     k = append_dsp_path(DSP_DOF_IMAGE, argv);
     if (k < 0)
     {
-        LCML_DPRINT("%d :: append_dsp_path returned an error!\n", __LINE__);
+        OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
         eError = OMX_ErrorBadParameter;
         goto ERROR;
     }
@@ -539,7 +543,7 @@
     int tmperr;
     char abs_dsp_path[ABS_DLL_NAME_LENGTH];
 
-    LCML_DPRINT("%d :: InitMMCodec application\n",__LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: InitMMCodec application\n",__LINE__);
 
     if (hInt == NULL )
     {
@@ -547,8 +551,6 @@
         goto ERROR;
     }
 
-
-
     phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)hInt)->pCodec);
 #ifdef __PERF_INSTRUMENTATION__
     phandle->pPERF = PERF_Create(PERF_FOURCC('C','M','L',' '),
@@ -560,6 +562,12 @@
                   PERF_BoundaryStart | PERF_BoundarySetup);
 #endif
 
+    /* 720p implementation */
+    {
+        pthread_mutex_init(&phandle->m_isStopped_mutex, NULL);
+        phandle->mapped_buffer_count = 0;
+    }
+
     /* INIT DSP RESOURCE */
     if(pCallbacks)
     {
@@ -572,25 +580,25 @@
     }
 
     /* INITIALIZATION OF DSP */
-    LCML_DPRINT("%d :: Entering Init_DSPSubSystem\n", __LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Entering Init_DSPSubSystem\n", __LINE__);
     status = DspManager_Open(0, NULL);
     DSP_ERROR_EXIT(status, "DSP Manager Open", ERROR);
-    LCML_DPRINT("DspManager_Open Successful\n");
+    OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DspManager_Open Successful\n");
 
     /* Attach and get handle to processor */
     status = DSPProcessor_Attach(TI_PROCESSOR_DSP, NULL, &(phandle->dspCodec->hProc));
     DSP_ERROR_EXIT(status, "Attach processor", ERROR);
-    LCML_DPRINT("DSPProcessor_Attach Successful\n");
-    LCML_DPRINT("Base Image is Already Loaded\n");
+    OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "DSPProcessor_Attach Successful\n");
+    OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Base Image is Already Loaded\n");
 
     for(dllinfo=0; dllinfo < phandle->dspCodec->NodeInfo.nNumOfDLLs; dllinfo++)
     {
-        LCML_DPRINT("%d :: Register Component Node\n",phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Register Component Node\n",phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
 
         k = append_dsp_path((char*)phandle->dspCodec->NodeInfo.AllUUIDs[dllinfo].DllName, abs_dsp_path);
         if (k < 0)
         {
-            LCML_DPRINT("%d :: append_dsp_path returned an error!\n", __LINE__);
+            OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: append_dsp_path returned an error!\n", __LINE__);
             eError = OMX_ErrorBadParameter;
             goto ERROR;
         }
@@ -611,50 +619,49 @@
     NodeAttrIn.uProfileID= phandle->dspCodec->ProfileID;
     /* Prepare Create Phase Argument */
 
-    LCML_DPRINT("%d :: Prepare Create Phase Argument \n",__LINE__);
+    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Prepare Create Phase Argument \n",__LINE__);
     /* TO DO check is application setting it properly */
     if(phandle->dspCodec->pCrPhArgs !=NULL)
     {
         while((phandle->dspCodec->pCrPhArgs[i] != END_OF_CR_PHASE_ARGS) && (i < LCML_DATA_SIZE))
         {
-            LCML_DPRINT("%d :: copying Create Phase Argument \n",i);
+            OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: copying Create Phase Argument \n",i);
             crData.cData[i] =phandle->dspCodec->pCrPhArgs[i];
-            LCML_DPRINT("%d :: CR PH arg[%d] = %d \n",__LINE__,i,crData.cData[i]);
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: CR PH arg[%d] = %d \n",__LINE__,i,crData.cData[i]);
             i++;
-            LCML_DPRINT("%d : Inside create phase while loop\n",__LINE__);
         }
     }
     else
     {
-        LCML_DPRINT("%d :: ILLEGAL CREATEPHASE SET IT ..\n",__LINE__);
+        OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL CREATEPHASE SET IT ..\n",__LINE__);
         eError = OMX_ErrorBadParameter;
         goto ERROR;
     }
 
     if (i >= LCML_DATA_SIZE)
     {
-       LCML_DPRINT("%d :: Reached end of Create Phase Args Array. Did not find END_OF_CR_PHASE_ARGS marker. \n", __LINE__);
+        OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, 
+                "%d :: Reached end of Create Phase Args Array. Did not find END_OF_CR_PHASE_ARGS marker. \n", __LINE__);
        eError = OMX_ErrorBadParameter;
        goto ERROR;
     }
 
 
-    /* LCML_DPRINT("Create Phase args  strlen = %d\n",strlen(crData.cData)); */
+    /* LCML_DPRINT ("Create Phase args  strlen = %d\n",strlen(crData.cData)); */
     /* crData.cbData = sizeof (ULONG) + strlen(crData.cData); */
     crData.cbData = i * 2;
-    LCML_DPRINT("Create Phase args  strlen = %ld\n", crData.cbData);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Create Phase args  strlen = %ld\n", crData.cbData);
 
     status = DSPNode_Allocate(phandle->dspCodec->hProc,
                              (struct DSP_UUID *)phandle->dspCodec->NodeInfo.AllUUIDs[0].uuid,
                              (struct DSP_CBDATA*)&crData, &NodeAttrIn,
                              &(phandle->dspCodec->hNode));
     DSP_ERROR_EXIT(status, "Allocate Component", ERROR);
-    LCML_DPRINT("%d :: DSPNode_Allocate Successfully\n", __LINE__);
+    OMX_PRDSP1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Allocate Successfully\n", __LINE__);
 
     if(phandle->dspCodec->DeviceInfo.TypeofDevice == 1)
     {
-        LCML_DPRINT("%d :: Audio Device Selected\n", __LINE__);
-        LCML_DPRINT("%d :: -------- DASF Functionality ------- \n",__LINE__);
+        OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Audio Device Selected\n", __LINE__);
         status = DSPNode_Allocate(phandle->dspCodec->hProc,
                                  (struct DSP_UUID *)phandle->dspCodec->DeviceInfo.AllUUIDs[0].uuid,
                                  NULL,
@@ -662,13 +669,13 @@
                                  &(phandle->dspCodec->hDasfNode));
         DSP_ERROR_EXIT(status, "DASF Allocate Component", ERROR);
 
-        LCML_DPRINT("%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
+        OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DASF DSPNode_Allocate Successfully\n", __LINE__);
         if(phandle->dspCodec->DeviceInfo.DspStream !=NULL)
         {
             if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
             {
                 /* render for playback */
-                LCML_DPRINT("%d :: Render for playback\n", __LINE__);
+                OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for playback\n", __LINE__);
                 status = DSPNode_Connect(phandle->dspCodec->hNode,
                                          0,
                                          phandle->dspCodec->hDasfNode,
@@ -679,7 +686,7 @@
             else if(phandle->dspCodec->DeviceInfo.TypeofRender == 1)
             {
                 /* render for record */
-                LCML_DPRINT("%d :: Render for record\n", __LINE__);
+                OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Render for record\n", __LINE__);
                 status = DSPNode_Connect(phandle->dspCodec->hDasfNode,
                                          0,
                                          phandle->dspCodec->hNode,
@@ -690,7 +697,7 @@
         }
         else
         {
-            LCML_DPRINT("%d :: ILLEGAL STREAM PARAMETER SET IT ..\n",__LINE__);
+            OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: ILLEGAL STREAM PARAMETER SET IT ..\n",__LINE__);
             eError = OMX_ErrorBadParameter;
             goto ERROR;
         }
@@ -698,22 +705,22 @@
 
     status = DSPNode_Create(phandle->dspCodec->hNode);
     DSP_ERROR_EXIT(status, "Create the Node", ERROR);
-    LCML_DPRINT("%d :: After DSPNode_Create !!! \n", __LINE__);
+    OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: After DSPNode_Create !!! \n", __LINE__);
 
     status = DSPNode_Run (phandle->dspCodec->hNode);
     DSP_ERROR_EXIT (status, "Goto RUN mode", ERROR);
-    LCML_DPRINT("%d :: DSPNode_Run Successfully\n", __LINE__);
+    OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: DSPNode_Run Successfully\n", __LINE__);
 
     if ((phandle->dspCodec->In_BufInfo.DataTrMethod == DMM_METHOD) ||
         (phandle->dspCodec->Out_BufInfo.DataTrMethod == DMM_METHOD))
     {
         struct DSP_NOTIFICATION* notification;
-        LCML_DPRINT("%d :: Registering the Node for Messaging\n",__LINE__);
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
 
         LCML_MALLOC(notification,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
         if(notification == NULL)
         {
-            LCML_DPRINT("%d :: malloc failed....\n",__LINE__);
+            OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
             goto ERROR;
         }
         memset(notification,0,sizeof(struct DSP_NOTIFICATION));
@@ -721,39 +728,39 @@
         status = DSPNode_RegisterNotify(phandle->dspCodec->hNode, DSP_NODEMESSAGEREADY, DSP_SIGNALEVENT, notification);
         DSP_ERROR_EXIT(status, "DSP node register notify", ERROR);
         phandle->g_aNotificationObjects[0] =  notification;
-#ifdef __ERROR_PROPAGATION__      
+#ifdef __ERROR_PROPAGATION__
         struct DSP_NOTIFICATION* notification_mmufault;
-       
-        LCML_DPRINT("%d :: Registering the Node for Messaging\n",__LINE__);
+
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
 
         LCML_MALLOC(notification_mmufault,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
         if(notification_mmufault == NULL)
         {
-            LCML_DPRINT("%d :: malloc failed....\n",__LINE__);
+            OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
             goto ERROR;
         }
         memset(notification_mmufault,0,sizeof(struct DSP_NOTIFICATION));
-        
+
         status = DSPProcessor_RegisterNotify(phandle->dspCodec->hProc, DSP_MMUFAULT, DSP_SIGNALEVENT, notification_mmufault);
         DSP_ERROR_EXIT(status, "DSP node register notify DSP_MMUFAULT", ERROR);
         phandle->g_aNotificationObjects[1] =  notification_mmufault;
-        
+
         struct DSP_NOTIFICATION* notification_syserror ;
-       
-        LCML_DPRINT("%d :: Registering the Node for Messaging\n",__LINE__);
+
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Registering the Node for Messaging\n",__LINE__);
 
         LCML_MALLOC(notification_syserror,sizeof(struct DSP_NOTIFICATION),struct DSP_NOTIFICATION);
         if(notification_syserror == NULL)
         {
-            LCML_DPRINT("%d :: malloc failed....\n",__LINE__);
+            OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: malloc failed....\n",__LINE__);
             goto ERROR;
         }
         memset(notification_syserror,0,sizeof(struct DSP_NOTIFICATION));
-        
+
         status = DSPProcessor_RegisterNotify(phandle->dspCodec->hProc, DSP_SYSERROR, DSP_SIGNALEVENT, notification_syserror);
         DSP_ERROR_EXIT(status, "DSP node register notify DSP_SYSERROR", ERROR);
         phandle->g_aNotificationObjects[2] =  notification_syserror;
-#endif       
+#endif
     }
 
     /* Listener thread */
@@ -766,7 +773,7 @@
                             (void*)phandle);
     if(tmperr || !phandle->g_tidMessageThread)
     {
-        LCML_DPRINT("Thread creation failed: 0x%x",tmperr);
+        OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "Thread creation failed: 0x%x",tmperr);
         eError = OMX_ErrorInsufficientResources;
         goto ERROR;
     }
@@ -779,7 +786,7 @@
     /* init buffers buffer counter */
     phandle->iBufinputcount =0;
     phandle->iBufoutputcount =0;
-    
+
     for (i = 0; i < QUEUE_SIZE; i++)
     {
         phandle->Arminputstorage[i] = NULL;
@@ -799,7 +806,7 @@
 #ifndef CEXEC_DONE
     LCML_FREE(argv);
 #endif
-    LCML_DPRINT("%d :: Exiting Init_DSPSubSystem\n", __LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInt)->dbg, "%d :: Exiting Init_DSPSubSystem\n", __LINE__);
     return eError;
 }
 
@@ -822,7 +829,6 @@
                                   void * args[10] )
 {
     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
-    LCML_DPRINT("%d :: WaitForEvent application\n",__LINE__);
     return eError;
 }
 
@@ -850,7 +856,7 @@
                                   OMX_S32 auxInfoLen ,OMX_U8 * usrArg )
 {
     LCML_DSP_INTERFACE * phandle;
-    int streamId = 0;
+    OMX_U32 streamId = 0;
     DSP_STATUS status;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     char * tmp2=NULL;
@@ -858,18 +864,19 @@
     int commandId;
     struct DSP_MSG msg;
     OMX_U32 MapBufLen=0;
+    OMX_BOOL mappedBufferFound = false;
 
-    LCML_DPRINT("%d :: QueueBuffer application\n",__LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: QueueBuffer application\n",__LINE__);
 
-    if (hComponent == NULL)
+    if (hComponent == NULL )
     {
         eError = OMX_ErrorInsufficientResources;
-        return eError;
+        goto EXIT;
     }
 
     phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)hComponent)->pCodec);
 
-    LCML_DPRINT("LCML QueueBuffer: phandle->iBufinputcount is %d (%p) \n", phandle->iBufinputcount, phandle);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "LCML QueueBuffer: phandle->iBufinputcount is %lu (%p) \n", phandle->iBufinputcount, phandle);
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_XferingBuffer(phandle->pPERF,
@@ -883,7 +890,7 @@
     if (tmp2 == NULL)
     {
             eError = OMX_ErrorInsufficientResources;
-            goto EXIT;
+            goto MUTEX_UNLOCK;
     }
     memset(tmp2,0,sizeof(TArmDspCommunicationStruct)+256);
     phandle->commStruct = (TArmDspCommunicationStruct *)(tmp2 + 128);
@@ -900,7 +907,7 @@
     if (phandle->bUsnEos == OMX_TRUE) {
         phandle->commStruct->iEOSFlag = (((OMX_BUFFERHEADERTYPE*)usrArg)->nFlags & 0x00000001);
     }
-    else { 
+    else {
         phandle->commStruct->iEOSFlag = 0;
     }
     phandle->commStruct->iUsrArg = (OMX_U32) usrArg;
@@ -908,17 +915,27 @@
     phandle->iBufinputcount = phandle->iBufinputcount % QUEUE_SIZE;
     phandle->commStruct->Bufoutindex = phandle->iBufoutputcount;
     phandle->commStruct->BufInindex = phandle->iBufinputcount;
-    if (bufType == EMMCodecInputBufferMapBufLen)
+    switch (bufType)
     {
-        bufType = EMMCodecInputBuffer;
-        MapBufLen = 1;
+        case EMMCodecInputBufferMapBufLen:
+            bufType = EMMCodecInputBuffer;
+            MapBufLen = 1;
+            break;
+        case EMMCodecOutputBufferMapBufLen:
+            bufType = EMMCodecOuputBuffer;
+            MapBufLen = 1;
+            break;
+        case EMMCodecInputBufferMapReuse:
+            bufType = EMMCodecInputBuffer;
+            phandle->ReUseMap = 1;
+            break;
+        case EMMCodecOutputBufferMapReuse:
+            bufType = EMMCodecOuputBuffer;
+            phandle->ReUseMap = 1;
+            break;
+        default:
+            break;
     }
-    else if (bufType == EMMCodecOutputBufferMapBufLen)
-    {
-        bufType = EMMCodecOuputBuffer;
-        MapBufLen = 1;
-    }
-
 
     if ((bufType >= EMMCodecStream0) && (bufType <= (EMMCodecStream0 + 20)))
     {
@@ -934,7 +951,7 @@
         pDmmBuf = pDmmBuf + phandle->iBufinputcount;
         phandle->iBufinputcount++;
         phandle->iBufinputcount = phandle->iBufinputcount % QUEUE_SIZE;
-        LCML_DPRINT("VPP port %d use InDmmBuffer (%d) %p\n", streamId, phandle->iBufinputcount, pDmmBuf);
+        OMX_PRBUFFER1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "VPP port %lu use InDmmBuffer (%lu) %p\n", streamId, phandle->iBufinputcount, pDmmBuf);
 
     }
     else if (bufType == EMMCodecOuputBuffer || streamId % 2)
@@ -947,65 +964,142 @@
     }
     else
     {
-        LCML_DPRINT("Unrecognized buffer type..");
+        OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Unrecognized buffer type..");
         eError = OMX_ErrorBadParameter;
         if(tmp2)
         {
             free(tmp2);
             phandle->commStruct = NULL;
         }
-        goto EXIT;
+        goto MUTEX_UNLOCK;
     }
     commandId = USN_GPPMSG_SET_BUFF|streamId;
-    LCML_DPRINT("Sending command ID 0x%x",commandId);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending command ID 0x%x",commandId);
     if( pDmmBuf == NULL)
     {
         eError = OMX_ErrorInsufficientResources;
-        goto EXIT;
+        goto MUTEX_UNLOCK;
     }
-    LCML_DPRINT("buffer = 0x%p bufferlen = %ld auxInfo = 0x%p auxInfoLen %ld\n",
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "buffer = 0x%p bufferlen = %ld auxInfo = 0x%p auxInfoLen %ld\n",
         buffer, bufferLen, auxInfo, auxInfoLen );
 
     phandle->commStruct->iArmbufferArg = (OMX_U32)buffer;
     if ((buffer != NULL) && (bufferLen != 0))
     {
-        LCML_DPRINT("mapping buffer \n");
+        OMX_U32 i;
+        DSP_STATUS status;
 
-        if (bufType == EMMCodecInputBuffer || !(streamId % 2)) {
-            if (MapBufLen)
-            {
-                /*using this option only when not mapping the entire memory region
-                 * can cause a DSP MMU FAULT or DSP SYS ERROR */
-
-                eError = DmmMap(phandle->dspCodec->hProc, bufferLen, bufferSizeUsed,buffer, (pDmmBuf), MapBufLen);
-            }
-            else
-            {
-                phandle->commStruct->iBufferSize = bufferSizeUsed ? bufferSizeUsed : bufferLen;
-                eError = DmmMap(phandle->dspCodec->hProc, bufferSizeUsed ? bufferSizeUsed: bufferLen, bufferSizeUsed,buffer, (pDmmBuf), MapBufLen);
-            }
-        }
-        else if (bufType == EMMCodecOuputBuffer || streamId % 2) {
-            eError = DmmMap(phandle->dspCodec->hProc, bufferLen, 0,buffer, (pDmmBuf), MapBufLen);
-        }
-        if (eError != OMX_ErrorNone)
+        if (phandle->ReUseMap)
         {
-            goto EXIT;
+            mappedBufferFound = false;
+            for(i = 0; i <= phandle->mapped_buffer_count; i++)
+            {
+                if(phandle->mapped_dmm_buffers[i].pAllocated == buffer)
+                {
+                    mappedBufferFound = true;
+                    *pDmmBuf = phandle->mapped_dmm_buffers[i];
+                     OMX_PRBUFFER1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Re-using pDmmBuf %p mapped %p\n", pDmmBuf, pDmmBuf->pMapped);
+
+                    if(bufType == EMMCodecInputBuffer)
+                    {
+                        /* Issue a memory flush for input buffer to ensure cache coherency */
+                        status = DSPProcessor_FlushMemory(phandle->dspCodec->hProc, pDmmBuf->pAllocated, bufferSizeUsed, (bufferSizeUsed > 512*1024) ? 3: 0);
+                        if(DSP_FAILED(status))
+                        {
+                            goto MUTEX_UNLOCK;
+                        }
+                    }
+
+                    else if(bufType == EMMCodecOuputBuffer)
+                    {
+                        /* Issue an memory invalidate for output buffer */
+                        if (bufferLen > 512*1024)
+                        {
+                            status = DSPProcessor_FlushMemory(phandle->dspCodec->hProc, pDmmBuf->pAllocated, bufferLen, 3);
+                            if(DSP_FAILED(status))
+                            {
+                                goto MUTEX_UNLOCK;
+                            }
+                        }
+                        else
+                        {
+                            status = DSPProcessor_InvalidateMemory(phandle->dspCodec->hProc, pDmmBuf->pAllocated, bufferLen);
+                            if(DSP_FAILED(status))
+                            {
+                                goto MUTEX_UNLOCK;
+                            }
+                        }
+                    }
+
+                    break;
+                }
+            }
+
+            if(false == mappedBufferFound)
+            {
+                if (bufType == EMMCodecInputBuffer || !(streamId % 2))
+                {
+                        phandle->commStruct->iBufferSize = bufferSizeUsed ? bufferSizeUsed : bufferLen;
+                        eError = DmmMap(phandle->dspCodec->hProc, bufferLen,buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
+                }
+                else if (bufType == EMMCodecOuputBuffer || streamId % 2) {
+                    eError = DmmMap(phandle->dspCodec->hProc, bufferLen, buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
+                }
+                if (eError != OMX_ErrorNone)
+                {
+                    goto MUTEX_UNLOCK;
+                }
+
+                /*720p implementation */
+                phandle->commStruct->iBufferPtr = (OMX_U32) pDmmBuf->pMapped;
+                /* storing reserve address for buffer */
+                pDmmBuf->bufReserved = pDmmBuf->pReserved;
+                if(phandle->mapped_buffer_count <= MAX_DMM_BUFFERS)
+                {
+                    phandle->mapped_dmm_buffers[phandle->mapped_buffer_count++] = *pDmmBuf;
+                }
+            }
+        phandle->commStruct->iBufferPtr = (OMX_U32) pDmmBuf->pMapped;
+        }
+        else
+        {
+
+            OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Mapping buffer continously\n");
+            if (bufType == EMMCodecInputBuffer || !(streamId % 2))
+            {
+                if (MapBufLen)
+                {
+                    /*using this option only when not mapping the entire memory region
+                     * can cause a DSP MMU FAULT or DSP SYS ERROR */
+                    eError = DmmMap(phandle->dspCodec->hProc, bufferLen, buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
+                }
+                else
+                {
+                    phandle->commStruct->iBufferSize = bufferSizeUsed ? bufferSizeUsed : bufferLen;
+                    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Mapping Size %ld out of %ld", bufferSizeUsed, bufferLen);
+                    eError = DmmMap(phandle->dspCodec->hProc, bufferSizeUsed ? bufferSizeUsed : bufferLen,buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
+                }
+            }
+            else if (bufType == EMMCodecOuputBuffer || streamId % 2) {
+                eError = DmmMap(phandle->dspCodec->hProc, bufferLen, buffer, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
+            }
+            if (eError != OMX_ErrorNone)
+            {
+                goto MUTEX_UNLOCK;
+            }
+            phandle->commStruct->iBufferPtr = (OMX_U32) pDmmBuf->pMapped;
+            pDmmBuf->bufReserved = pDmmBuf->pReserved;
         }
 
-        phandle->commStruct->iBufferPtr = (OMX_U32) pDmmBuf->pMapped;
-        /* storing reserve address for buffer */
-        pDmmBuf->bufReserved = pDmmBuf->pReserved;
-        LCML_DPRINT("reserved buffer 0x%p  reserved1 buffer 0x%p \n", pDmmBuf->pReserved, pDmmBuf->bufReserved);
     }
 
     if (auxInfoLen != 0 && auxInfo != NULL )
     {
-        LCML_DPRINT("mapping parameter \n");
-        eError = DmmMap(phandle->dspCodec->hProc, phandle->commStruct->iParamSize, phandle->commStruct->iParamSize, (void*)phandle->commStruct->iParamPtr, (pDmmBuf), 0);
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "mapping parameter \n");
+        eError = DmmMap(phandle->dspCodec->hProc, phandle->commStruct->iParamSize, (void*)phandle->commStruct->iParamPtr, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
         if (eError != OMX_ErrorNone)
         {
-            goto EXIT;
+            goto MUTEX_UNLOCK;
         }
 
         phandle->commStruct->iParamPtr = (OMX_U32 )pDmmBuf->pMapped ;
@@ -1013,26 +1107,26 @@
         pDmmBuf->paramReserved = pDmmBuf->pReserved;
     }
 
-    eError = DmmMap(phandle->dspCodec->hProc, sizeof(TArmDspCommunicationStruct),sizeof(TArmDspCommunicationStruct), (void *)phandle->commStruct, (pDmmBuf), 0);
+    eError = DmmMap(phandle->dspCodec->hProc, sizeof(TArmDspCommunicationStruct),(void *)phandle->commStruct, (pDmmBuf), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
     if (eError != OMX_ErrorNone)
     {
-        goto EXIT;
+        goto MUTEX_UNLOCK;
     }
-    
+
     /* storing mapped address of struct */
     phandle->commStruct->iArmArg = (OMX_U32)pDmmBuf->pMapped;
-    
-    LCML_DPRINT("sending SETBUFF \n");
+
+    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "sending SETBUFF \n");
     msg.dwCmd = commandId;
     msg.dwArg1 = (int)pDmmBuf->pMapped;
     msg.dwArg2 = 0;
 
     status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
-    LCML_DPRINT("after SETBUFF \n");
-    DSP_ERROR_EXIT (status, "Send message to node", EXIT);
-
-EXIT:
+    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "after SETBUFF \n");
+    DSP_ERROR_EXIT (status, "Send message to node", MUTEX_UNLOCK);
+MUTEX_UNLOCK:
     pthread_mutex_unlock(&phandle->mutex);
+EXIT:
     return eError;
 }
 
@@ -1058,13 +1152,12 @@
     DSP_STATUS status;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
-    LCML_DPRINT("%d :: ControlCodec application\n",__LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: ControlCodec application\n",__LINE__);
     if (hComponent == NULL )
     {
         eError= OMX_ErrorInsufficientResources;
-        return eError;
+        goto EXIT;
     }
-
     phandle = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE *)hComponent)->pCodec);
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -1078,12 +1171,12 @@
         case EMMCodecControlPause:
         {
             struct DSP_MSG msg = {USN_GPPMSG_PAUSE, 0, 0};
-            LCML_DPRINT("Sending PAUSE command");
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending PAUSE command");
 #ifdef __PERF_INSTRUMENTATION__
             PERF_SendingCommand(phandle->pPERF,
                                 msg.dwCmd,
                                 msg.dwArg1,
-                                PERF_ModuleSocketNode);                                
+                                PERF_ModuleSocketNode);
 #endif
             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
@@ -1092,12 +1185,12 @@
         case EMMCodecControlStart:
         {
             struct DSP_MSG msg = {USN_GPPMSG_PLAY, 0, 0};
-            LCML_DPRINT("Sending PLAY --1 command");
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending PLAY --1 command");
 #ifdef __PERF_INSTRUMENTATION__
             PERF_SendingCommand(phandle->pPERF,
                                 msg.dwCmd,
                                 msg.dwArg1,
-                                PERF_ModuleSocketNode);                                
+                                PERF_ModuleSocketNode);
 #endif
             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
@@ -1106,12 +1199,12 @@
         case MMCodecControlStop:
         {
             struct DSP_MSG msg = {USN_GPPMSG_STOP, 0, 0};
-            LCML_DPRINT("Sending STOP command\n");
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Sending STOP command\n");
 #ifdef __PERF_INSTRUMENTATION__
             PERF_SendingCommand(phandle->pPERF,
                                 msg.dwCmd,
                                 msg.dwArg1,
-                                PERF_ModuleSocketNode);                                
+                                PERF_ModuleSocketNode);
 #endif
             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
@@ -1120,7 +1213,7 @@
         case EMMCodecControlDestroy:
         {
             int pthreadError = 0;
-            LCML_DPRINT("Destroy the codec");
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Destroy the codec");
 #ifdef __PERF_INSTRUMENTATION__
             PERF_Boundary(phandle->pPERF,
                           PERF_BoundaryStart | PERF_BoundaryCleanup);
@@ -1132,9 +1225,42 @@
             if (0 != pthreadError)
             {
                 eError = OMX_ErrorHardware;
-                LCML_DPRINT("%d :: Error while closing Component Thread\n", pthreadError);
+                OMX_ERROR4 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "%d :: Error while closing Component Thread\n", pthreadError);
             }
-            LCML_DPRINT("Destroy the codec %d",eError);
+            OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "Destroy the codec %d",eError);
+            /* 720p implementation */
+            /*DeleteDspResource (phandle);*/
+            if (phandle->ReUseMap)
+            {
+                pthread_mutex_lock(&phandle->m_isStopped_mutex);
+                /*If you are able to obtain the lock then the Messaging thread has exited*/
+                pthread_mutex_unlock(&phandle->m_isStopped_mutex);
+            }
+
+            if (phandle->ReUseMap)
+            {
+                OMX_U32 i;
+
+                /* Unmap buffers */
+                for(i=0; i< phandle->mapped_buffer_count; i++)
+                {
+                    DmmUnMap(phandle->dspCodec->hProc,(void*)phandle->mapped_dmm_buffers[i].pMapped,
+                            phandle->mapped_dmm_buffers[i].bufReserved, ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
+                }
+
+                for(i = 0; i <= phandle->mapped_buffer_count; i++)
+                {
+                    phandle->mapped_dmm_buffers[i].pAllocated = 0;
+                    phandle->mapped_dmm_buffers[i].pReserved = 0;
+                    phandle->mapped_dmm_buffers[i].pMapped = 0;
+                    phandle->mapped_dmm_buffers[i].bufReserved = 0;
+                    phandle->mapped_dmm_buffers[i].paramReserved = 0;
+                    phandle->mapped_dmm_buffers[i].nSize = 0;
+                }
+
+                phandle->mapped_buffer_count = 0;
+            }
+
             DeleteDspResource (phandle);
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -1156,12 +1282,12 @@
         {
             /* todo: Check to see if the arguments are valid */
             struct DSP_MSG msg = {(int)args[0], (int)args[1], (int)args[2]};
-            LCML_DPRINT("message to codec");
+            OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "message to codec");
 #ifdef __PERF_INSTRUMENTATION__
             PERF_SendingCommand(phandle->pPERF,
                                 msg.dwCmd,
                                 msg.dwArg1,
-                                PERF_ModuleSocketNode);                                
+                                PERF_ModuleSocketNode);
 #endif
             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
@@ -1178,54 +1304,62 @@
                 if (phandle->pAlgcntlDmmBuf[i] == NULL)
                     break;
             }
-            if(i >= QUEUE_SIZE)
-            {
-                pthread_mutex_unlock(&phandle->mutex);
-                eError = OMX_ErrorUndefined;
-                goto EXIT;
-            }
-            LCML_MALLOC(phandle->pAlgcntlDmmBuf[i],sizeof(DMM_BUFFER_OBJ),DMM_BUFFER_OBJ);
-            if(phandle->pAlgcntlDmmBuf[i] == NULL)
-            {
-                eError = OMX_ErrorInsufficientResources;
-                pthread_mutex_unlock(&phandle->mutex);
-                goto EXIT;
-            }
-            memset(phandle->pAlgcntlDmmBuf[i],0,sizeof(DMM_BUFFER_OBJ));
-            eError = DmmMap(phandle->dspCodec->hProc,(int)args[2],(int)args[2], args[1],(phandle->pAlgcntlDmmBuf[i]), 0);
-            if (eError != OMX_ErrorNone)
-            {
-                pthread_mutex_unlock(&phandle->mutex);
-                goto EXIT;
-            }
-            phandle->algcntlmapped[i] = 1;
-            msg.dwCmd = USN_GPPMSG_ALGCTRL;
-            msg.dwArg1 = (int)args[0];
-            msg.dwArg2 = (int)phandle->pAlgcntlDmmBuf[i]->pMapped;
+                    if(i >= QUEUE_SIZE)
+                    {
+                        pthread_mutex_unlock(&phandle->mutex);
+                        eError = OMX_ErrorUndefined;
+                        goto EXIT;
+                    }
+
+                    LCML_MALLOC(phandle->pAlgcntlDmmBuf[i],sizeof(DMM_BUFFER_OBJ),DMM_BUFFER_OBJ);
+                    if(phandle->pAlgcntlDmmBuf[i] == NULL)
+                    {
+                        eError = OMX_ErrorInsufficientResources;
+                        pthread_mutex_unlock(&phandle->mutex);
+                        goto EXIT;
+                    }
+
+                    memset(phandle->pAlgcntlDmmBuf[i],0,sizeof(DMM_BUFFER_OBJ));
+
+                    eError = DmmMap(phandle->dspCodec->hProc,(int)args[2], args[1],(phandle->pAlgcntlDmmBuf[i]), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
+                    if (eError != OMX_ErrorNone)
+                    {
+                        pthread_mutex_unlock(&phandle->mutex);
+                        goto EXIT;
+                    }
+                    phandle->algcntlmapped[i] = 1;
+                    msg.dwCmd = USN_GPPMSG_ALGCTRL;
+                    msg.dwArg1 = (int)args[0];
+                    msg.dwArg2 = (int)phandle->pAlgcntlDmmBuf[i]->pMapped;
 #ifdef __PERF_INSTRUMENTATION__
-            PERF_SendingCommand(phandle->pPERF,
-                                msg.dwCmd,
-                                msg.dwArg1,
-                                PERF_ModuleSocketNode);                                
+                    PERF_SendingCommand(phandle->pPERF,
+                                        msg.dwCmd,
+                                        msg.dwArg1,
+                                        PERF_ModuleSocketNode);
 #endif
-            status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
-            pthread_mutex_unlock(&phandle->mutex);
-            DSP_ERROR_EXIT (status, "Send message to node", EXIT);
-            break;
-        }
+                    status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
+                    pthread_mutex_unlock(&phandle->mutex);
+                    DSP_ERROR_EXIT (status, "Send message to node", EXIT);
+                    break;
+                }
         case EMMCodecControlStrmCtrl:
         {
             struct DSP_MSG msg;
-            
-            pthread_mutex_lock(&phandle->mutex);
 
+            pthread_mutex_lock(&phandle->mutex);
             if ((int)args[0] == USN_STRMCMD_FLUSH) {
-                msg.dwCmd = USN_GPPMSG_STRMCTRL | (int)args[1]; 
+                msg.dwCmd = USN_GPPMSG_STRMCTRL | (int)args[1];
                 msg.dwArg1  = USN_STRMCMD_FLUSH;
                 msg.dwArg2  = 0;
                 phandle->flush_pending[(int)args[1]]= 1;
+#ifdef __PERF_INSTRUMENTATION__
+                PERF_SendingCommand(phandle->pPERF,
+                                 msg.dwCmd,
+                                 msg.dwArg1,
+                                 PERF_ModuleSocketNode);
+#endif
             }
-            else 
+            else
             {
                 int i;
                 for (i = 0; i < QUEUE_SIZE; i++)
@@ -1234,58 +1368,58 @@
                     if (phandle->pStrmcntlDmmBuf[i] == NULL)
                         break;
                 }
-                if(i >= QUEUE_SIZE)
-                {
-                    eError=OMX_ErrorUndefined;
-                    pthread_mutex_unlock(&phandle->mutex);
-                    goto EXIT;
-                }
+                        if(i >= QUEUE_SIZE)
+                        {
+                            eError=OMX_ErrorUndefined;
+                            pthread_mutex_unlock(&phandle->mutex);
+                            goto EXIT;
+                        }
 
-                LCML_MALLOC(phandle->pStrmcntlDmmBuf[i],sizeof(DMM_BUFFER_OBJ),DMM_BUFFER_OBJ);
-                if(phandle->pStrmcntlDmmBuf[i] == NULL)
-                {
-                    eError = OMX_ErrorInsufficientResources;
-                    pthread_mutex_unlock(&phandle->mutex);
-                    goto EXIT;
-                }
-                
-                memset(phandle->pStrmcntlDmmBuf[i],0,sizeof(DMM_BUFFER_OBJ)); //ATC
-                
-                eError = DmmMap(phandle->dspCodec->hProc, (int)args[2],(int)args[2], args[1],(phandle->pStrmcntlDmmBuf[i]), 0);
-                if (eError != OMX_ErrorNone)
-                {
-                    pthread_mutex_unlock(&phandle->mutex);
-                    goto EXIT;
-                }
-                phandle->strmcntlmapped[i] = 1;
-                if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
-                {
-                    /* playback mode */
-                    msg.dwCmd = USN_GPPMSG_STRMCTRL | 0x01;
-                    msg.dwArg1 = (int)args[0];
-                    msg.dwArg2 = (int)phandle->pStrmcntlDmmBuf[i]->pMapped;
-                }
-                else if(phandle->dspCodec->DeviceInfo.TypeofRender == 1)
-                {
-                    /* record mode */
-                    msg.dwCmd = USN_GPPMSG_STRMCTRL;
-                    msg.dwArg1 = (int)args[0];
-                    msg.dwArg2 = (int)phandle->pStrmcntlDmmBuf[i]->pMapped;
-                }
+                        LCML_MALLOC(phandle->pStrmcntlDmmBuf[i],sizeof(DMM_BUFFER_OBJ),DMM_BUFFER_OBJ);
+                        if(phandle->pStrmcntlDmmBuf[i] == NULL)
+                        {
+                            eError = OMX_ErrorInsufficientResources;
+                            pthread_mutex_unlock(&phandle->mutex);
+                            goto EXIT;
+                        }
+
+                        memset(phandle->pStrmcntlDmmBuf[i],0,sizeof(DMM_BUFFER_OBJ)); //ATC
+
+                        eError = DmmMap(phandle->dspCodec->hProc, (int)args[2], args[1],(phandle->pStrmcntlDmmBuf[i]), ((LCML_CODEC_INTERFACE *)hComponent)->dbg);
+                        if (eError != OMX_ErrorNone)
+                        {
+                            pthread_mutex_unlock(&phandle->mutex);
+                            goto EXIT;
+                        }
+                        phandle->strmcntlmapped[i] = 1;
+                        if(phandle->dspCodec->DeviceInfo.TypeofRender == 0)
+                        {
+                            /* playback mode */
+                            msg.dwCmd = USN_GPPMSG_STRMCTRL | 0x01;
+                            msg.dwArg1 = (int)args[0];
+                            msg.dwArg2 = (int)phandle->pStrmcntlDmmBuf[i]->pMapped;
+                        }
+                        else if(phandle->dspCodec->DeviceInfo.TypeofRender == 1)
+                        {
+                            /* record mode */
+                            msg.dwCmd = USN_GPPMSG_STRMCTRL;
+                            msg.dwArg1 = (int)args[0];
+                            msg.dwArg2 = (int)phandle->pStrmcntlDmmBuf[i]->pMapped;
+                        }
             }
 #ifdef __PERF_INSTRUMENTATION__
-            PERF_SendingCommand(phandle->pPERF,
-                                msg.dwCmd,
-                                msg.dwArg1,
-                                PERF_ModuleSocketNode);                                
+                        PERF_SendingCommand(phandle->pPERF,
+                                            msg.dwCmd,
+                                            msg.dwArg1,
+                                            PERF_ModuleSocketNode);
 #endif
             status = DSPNode_PutMessage (phandle->dspCodec->hNode, &msg, DSP_FOREVER);
             pthread_mutex_unlock(&phandle->mutex);
             DSP_ERROR_EXIT (status, "Send message to node", EXIT);
 
-            LCML_DPRINT("STRMControl: arg[0]: message = %x\n",(int)args[0]);
-            LCML_DPRINT("STRMControl: arg[1]: address = %p\n",args[1]);
-            LCML_DPRINT("STRMControl: arg[2]: size = %d\n",(int)args[2]);
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "STRMControl: arg[0]: message = %x\n",(int)args[0]);
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "STRMControl: arg[1]: address = %p\n",args[1]);
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)hComponent)->dbg, "STRMControl: arg[2]: size = %d\n",(int)args[2]);
             break;
         }
         case EMMCodecControlUsnEos:
@@ -1293,7 +1427,7 @@
             phandle->bUsnEos = OMX_TRUE;
             break;
         }
-        
+
     }
 
 EXIT:
@@ -1314,10 +1448,9 @@
 ** ==========================================================================*/
 OMX_ERRORTYPE DmmMap(DSP_HPROCESSOR ProcHandle,
                      OMX_U32 size,
-                     OMX_U32 sizeUsed,
                      void* pArmPtr,
-                     DMM_BUFFER_OBJ* pDmmBuf, 
-                     OMX_U32 MapBufLen)
+                     DMM_BUFFER_OBJ* pDmmBuf,
+                     struct OMX_TI_Debug dbg)
 {
     OMX_ERRORTYPE eError = OMX_ErrorUndefined;
     DSP_STATUS status;
@@ -1325,14 +1458,14 @@
 
     if(pDmmBuf == NULL)
     {
-        LCML_DPRINT("pBuf is NULL\n");
+        OMX_ERROR4 (dbg, "pBuf is NULL\n");
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
 
     if(pArmPtr == NULL)
     {
-        LCML_DPRINT("pBuf is NULL\n");
+        OMX_ERROR4 (dbg, "pBuf is NULL\n");
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
@@ -1345,14 +1478,14 @@
     status = DSPProcessor_ReserveMemory(ProcHandle, nSizeReserved, &(pDmmBuf->pReserved));
     if(DSP_FAILED(status))
     {
-        LCML_DPRINT("DSPProcessor_ReserveMemory() failed - error 0x%x", (int)status);
+        OMX_ERROR4 (dbg, "DSPProcessor_ReserveMemory() failed - error 0x%x", (int)status);
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
     pDmmBuf->nSize = size;
 
-	
-    LCML_DPRINT(" DMM MAP Reserved: %p (for buf %p), size 0x%x (%d)\n", pDmmBuf->pReserved, pArmPtr, nSizeReserved,nSizeReserved);
+
+    OMX_PRBUFFER2 (dbg, " DMM MAP Reserved: %p (for buf %p), size 0x%x (%d)", pDmmBuf->pReserved, pArmPtr, nSizeReserved,nSizeReserved);
 
     /* Map */
     status = DSPProcessor_Map(ProcHandle,
@@ -1363,11 +1496,11 @@
                               0); /* final param is reserved.  set to zero. */
     if(DSP_FAILED(status))
     {
-        LCML_DPRINT("DSPProcessor_Map() failed - error 0x%x", (int)status);
+        OMX_ERROR4 (dbg, "DSPProcessor_Map() failed - error 0x%x", (int)status);
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
-    LCML_DPRINT("DMM Mapped: %p, size 0x%x (%d)\n",pDmmBuf->pMapped, size,size);
+    OMX_PRBUFFER1 (dbg, "DMM Mapped: %p, size 0x%lx (%ld)",pDmmBuf->pMapped, size,size);
 
     /* Previously we used to Flush or Invalidate the mapped buffer.  This was
      * removed due to bridge is now handling the flush/invalidate operation */
@@ -1388,46 +1521,40 @@
 *  @retval OMX_ErrorNone  - Success
 *          OMX_ErrorHardware  -  Hardware Error
 ** ==========================================================================*/
-OMX_ERRORTYPE DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr)
+OMX_ERRORTYPE DmmUnMap(DSP_HPROCESSOR ProcHandle, void* pMapPtr, void* pResPtr, struct OMX_TI_Debug dbg )
 {
     DSP_STATUS status = DSP_SOK;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
     if(pMapPtr == NULL)
     {
-        LCML_DPRINT("pMapPtr is NULL\n");
+        OMX_ERROR4 (dbg, "pMapPtr is NULL\n");
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
     if(pResPtr == NULL)
     {
-        LCML_DPRINT("pResPtr is NULL\n");
+        OMX_ERROR4 (dbg, "pResPtr is NULL\n");
         eError = OMX_ErrorBadParameter;
         goto EXIT;
     }
     status = DSPProcessor_UnMap(ProcHandle,pMapPtr);
     if(DSP_FAILED(status))
     {
-        LCML_DPRINT("DSPProcessor_UnMap() failed - error 0x%x",(int)status);
+        OMX_PRDSP4 (dbg, "DSPProcessor_UnMap() failed - error 0x%x",(int)status);
    }
 
-    LCML_DPRINT("unreserving  structure =0x%p\n",pResPtr );
+    OMX_PRINT2 (dbg, "unreserving  structure =0x%p\n",pResPtr );
     status = DSPProcessor_UnReserveMemory(ProcHandle,pResPtr);
     if(DSP_FAILED(status))
     {
-        LCML_DPRINT("DSPProcessor_UnReserveMemory() failed - error 0x%x", (int)status);
+        OMX_PRDSP4 (dbg, "DSPProcessor_UnReserveMemory() failed - error 0x%x", (int)status);
     }
 
 EXIT:
     return eError;
 }
 
-#ifdef UNDER_CE
-#define LCML_DPRINT
-#else
-#define LCML_DPRINT(...)    
-#endif
-
 /** ========================================================================
 * FreeResources () method is used to allocate the memory using DMM.
 *
@@ -1441,7 +1568,7 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     LCML_DSP_INTERFACE *codec;
 
-    LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
+    OMX_PRINT1 ((struct OMX_TI_Debug)(((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg), "%d :: LCML:: FreeResources\n",__LINE__);
     if(hInterface->dspCodec != NULL)
     {
         LCML_FREE(hInterface->dspCodec);
@@ -1450,8 +1577,10 @@
     codec = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle)->pCodec);
     if(codec != NULL)
     {
+        pthread_mutex_destroy(&codec->m_isStopped_mutex);
         pthread_mutex_lock(&codec->mutex);
-        LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
+
+        OMX_PRINT1 ((struct OMX_TI_Debug)(((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg), "%d :: LCML:: FreeResources\n",__LINE__);
         if(codec->g_aNotificationObjects[0]!= NULL)
         {
             LCML_FREE(codec->g_aNotificationObjects[0]);
@@ -1468,6 +1597,7 @@
                 codec->g_aNotificationObjects[2] = NULL;
             }
  #endif
+            OMX_DBG_CLOSE((struct OMX_TI_Debug )(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle)->dbg));
             LCML_FREE(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle));
             hInterface->pCodecinterfacehandle = NULL;
         }
@@ -1475,9 +1605,7 @@
         pthread_mutex_destroy (&codec->mutex);
         LCML_FREE(codec);
         codec = NULL;
-
     }
-    LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
     return eError;
 }
 
@@ -1499,11 +1627,11 @@
     LCML_DSP_INTERFACE *codec;
 
     /* Get current state of node, if it is running, then only terminate it */
-    
+
     status = DSPNode_GetAttr(hInterface->dspCodec->hNode, &nodeAttr, sizeof(nodeAttr));
     DSP_ERROR_EXIT (status, "DeInit: Error in Node GetAtt ", EXIT);
         status = DSPNode_Terminate(hInterface->dspCodec->hNode, &nExit);
-    LCML_DPRINT("%d :: LCML:: Node Has Been Terminated --1\n",__LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: LCML:: Node Has Been Terminated --1\n",__LINE__);
     codec = (LCML_DSP_INTERFACE *)(((LCML_CODEC_INTERFACE*)hInterface->pCodecinterfacehandle)->pCodec);
     if(codec->g_aNotificationObjects[0]!= NULL)
     {
@@ -1514,21 +1642,22 @@
        /* status = DSPNode_RegisterNotify(hInterface->dspCodec->hProc, 0, DSP_SIGNALEVENT, codec->g_aNotificationObjects[1]);
         DSP_ERROR_EXIT(status, "DSP node de-register notify", EXIT);*/
     }
-#endif    
+#endif
     if (hInterface->dspCodec->DeviceInfo.TypeofDevice == 1) {
         /* delete DASF node */
         status = DSPNode_Delete(hInterface->dspCodec->hDasfNode);
         DSP_ERROR_EXIT (status, "DeInit: DASF Node Delete ", EXIT);
-        LCML_DPRINT("%d :: Deleted the DASF node Successfully\n",__LINE__);
+        OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Deleted the DASF node Successfully\n",__LINE__);
     }
 	/* delete SN */
-	status = DSPNode_Delete(hInterface->dspCodec->hNode);
-    LCML_DPRINT("%d :: Deleted the node Successfully\n",__LINE__);
+    status = DSPNode_Delete(hInterface->dspCodec->hNode);
+    DSP_ERROR_EXIT (status, "DeInit: Codec Node Delete ", EXIT);
+    OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Deleted the node Successfully\n",__LINE__);
 
-    LCML_DPRINT("%d :: Entering UnLoadDLLs \n", __LINE__);
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Entering UnLoadDLLs \n", __LINE__);
     for(dllinfo=0;dllinfo < hInterface->dspCodec->NodeInfo.nNumOfDLLs ;dllinfo++)
     {
-        LCML_DPRINT("%d :: Register Component Node\n",hInterface->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
+        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)hInterface->pCodecinterfacehandle)->dbg, "%d :: Register Component Node\n",hInterface->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
         status = DSPManager_UnregisterObject ((struct DSP_UUID *) hInterface->dspCodec->NodeInfo.AllUUIDs[dllinfo].uuid,
                                                                                         hInterface->dspCodec->NodeInfo.AllUUIDs[dllinfo].eDllType);
         /*DSP_ERROR_EXIT (status, "Unregister DSP Object, Socket UUID ", EXIT);*/
@@ -1565,22 +1694,26 @@
     int waitForEventsTimeout = 1000;
     int getMessageTimeout = 10;
 
-    LCML_DPRINT("\n*****************Inside the Messaging thread************\n");
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Inside the Messaging thread\n");
 #ifdef __PERF_INSTRUMENTATION__
-    ((LCML_DSP_INTERFACE *)arg)->pPERFcomp = 
+    ((LCML_DSP_INTERFACE *)arg)->pPERFcomp =
         PERF_Create(PERF_FOURCC('C','M','L','T'),
                     PERF_ModuleAudioDecode | PERF_ModuleAudioEncode |
                     PERF_ModuleVideoDecode | PERF_ModuleVideoEncode |
                     PERF_ModuleImageDecode | PERF_ModuleImageEncode |
                     PERF_ModuleCommonLayer);
 #endif
+    if (((LCML_DSP_INTERFACE *)arg)->ReUseMap)
+    {
+        pthread_mutex_lock(&((LCML_DSP_INTERFACE *)arg)->m_isStopped_mutex);
+    }
 
     /* get message from DSP */
     while (1)
     {
         if (((LCML_DSP_INTERFACE *)arg)->pshutdownFlag == 1)
         {
-            LCML_DPRINT("Breaking out of loop inmessaging thread \n");
+            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Breaking out of loop inmessaging thread \n");
             break;
         }
 
@@ -1588,23 +1721,23 @@
             waitForEventsTimeout = 10000;
             getMessageTimeout = 1000;
         }
-        /* set the timeouts lower when the codec is stopped so that thread deletion response will be faster */        
-        else if (threadState == EMessagingThreadCodecStopped) {        
+        /* set the timeouts lower when the codec is stopped so that thread deletion response will be faster */
+        else if (threadState == EMessagingThreadCodecStopped) {
             waitForEventsTimeout = 10;
             getMessageTimeout = 10;
         }
 
-#ifdef __ERROR_PROPAGATION__        
+#ifdef __ERROR_PROPAGATION__
         status = DSPManager_WaitForEvents(((LCML_DSP_INTERFACE *)arg)->g_aNotificationObjects, 3, &index, waitForEventsTimeout);
 #else
         status = DSPManager_WaitForEvents(((LCML_DSP_INTERFACE *)arg)->g_aNotificationObjects, 1, &index, waitForEventsTimeout);
-#endif       
+#endif
         if (DSP_SUCCEEDED(status))
         {
-            LCML_DPRINT("GOT notofication FROM DSP HANDLE IT \n");
-#ifdef __ERROR_PROPAGATION__            
+            OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT notofication FROM DSP HANDLE IT \n");
+#ifdef __ERROR_PROPAGATION__
             if (index == 0){
-#endif            
+#endif
             /* Pull all available messages out of the message loop */
             while (DSP_SUCCEEDED(status))
             {
@@ -1612,18 +1745,21 @@
                 status = DSPNode_GetMessage(((LCML_DSP_INTERFACE *)arg)->dspCodec->hNode, &msg, getMessageTimeout);
                 if (DSP_SUCCEEDED(status))
                 {
-                    int streamId = (msg.dwCmd & 0x000000ff);
+                    OMX_U32 streamId = (msg.dwCmd & 0x000000ff);
                     int commandId = msg.dwCmd & 0xffffff00;
                     TMMCodecBufferType bufType ;/* = EMMCodecScratchBuffer; */
                     TUsnCodecEvent  event = EMMCodecInternalError;
-                    void * args[10];
+                    void * args[10] = {};
                     TArmDspCommunicationStruct  *tmpDspStructAddress = NULL;
                     LCML_DSP_INTERFACE *hDSPInterface = ((LCML_DSP_INTERFACE *)arg) ;
                     DMM_BUFFER_OBJ* pDmmBuf = NULL;
 
-                    LCML_DPRINT("GOT MESSAGE FROM DSP HANDLE IT  %d \n", index);
-                    LCML_DPRINT("msg = 0x%lx arg1 = 0x%lx arg2 = 0x%lx", msg.dwCmd, msg.dwArg1, msg.dwArg2);
-                    LCML_DPRINT("Message EMMCodecOuputBuffer outside loop");
+                    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                            "GOT MESSAGE FROM DSP HANDLE IT  %d \n", index);
+                    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                            "msg = 0x%lx arg1 = 0x%lx arg2 = 0x%lx", msg.dwCmd, msg.dwArg1, msg.dwArg2);
+                    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                            "Message EMMCodecOuputBuffer outside loop");
 #ifdef __PERF_INSTRUMENTATION__
                     PERF_ReceivedCommand(hDSPInterface->pPERFcomp,
                                          msg.dwCmd, msg.dwArg1,
@@ -1632,22 +1768,24 @@
 
                     if (commandId == USN_DSPMSG_BUFF_FREE )
                     {
-                        threadState = EMessagingThreadCodecRunning;                    
+                        threadState = EMessagingThreadCodecRunning;
  #ifdef __PERF_INSTRUMENTATION__
                                         PERF_XferingBuffer(hDSPInterface->pPERFcomp,
                                                           args [1],
                                                           (OMX_U32) args [8],
                                                           PERF_ModuleSocketNode,
                                                           PERF_ModuleLLMM);
-#endif                       
+#endif
                         pthread_mutex_lock(&hDSPInterface->mutex);
                         if (!(streamId % 2))
                         {
                             int i = 0;
                             int j = 0;
                             bufType = streamId + EMMCodecStream0;
-                            LCML_DPRINT("Address Arminputstorage %p \n", ((LCML_DSP_INTERFACE *)arg)->Arminputstorage);
-                            LCML_DPRINT("Address dspinterface %p \n", ((LCML_DSP_INTERFACE *)arg));
+                            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                    "Address Arminputstorage %p \n", ((LCML_DSP_INTERFACE *)arg)->Arminputstorage);
+                            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                    "Address dspinterface %p \n", ((LCML_DSP_INTERFACE *)arg));
 
                             hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
                             i = hDSPInterface->iBufinputcount;
@@ -1655,17 +1793,17 @@
                             {
                                 if (hDSPInterface->Arminputstorage[i] != NULL && hDSPInterface ->Arminputstorage[i]->iArmArg == msg.dwArg1)
                                 {
-                                    LCML_DPRINT("InputBuffer loop");
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "InputBuffer loop");
                                     tmpDspStructAddress = ((LCML_DSP_INTERFACE *)arg)->Arminputstorage[i] ;
                                     hDSPInterface->Arminputstorage[i] =NULL;
                                     pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
-                                    LCML_DPRINT("Address output  matching index= %ld \n ",tmpDspStructAddress->BufInindex);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Address output  matching index= %ld \n ",tmpDspStructAddress->BufInindex);
                                     break;
                                 }
                                 i++;
                                 i = i % QUEUE_SIZE;
-                                LCML_DPRINT("Message EMMCodecInputBuffer loop");
+                                OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Message EMMCodecInputBuffer loop");
                             }
                         }
                         else if (streamId % 2)
@@ -1673,8 +1811,8 @@
                             int i = 0;
                             int j = 0;
                             bufType = streamId + EMMCodecStream0;;
-                            LCML_DPRINT("Address Armoutputstorage %p \n ",((LCML_DSP_INTERFACE *)arg)->Armoutputstorage);
-                            LCML_DPRINT("Address dspinterface %p \n ",((LCML_DSP_INTERFACE *)arg));
+                            OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Address Armoutputstorage %p \n ",((LCML_DSP_INTERFACE *)arg)->Armoutputstorage);
+                            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Address dspinterface %p \n ",((LCML_DSP_INTERFACE *)arg));
 
                             hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
                             i = hDSPInterface->iBufoutputcount;
@@ -1683,24 +1821,26 @@
                                 if( hDSPInterface ->Armoutputstorage[i] != NULL
                                         && hDSPInterface ->Armoutputstorage[i]->iArmArg == msg.dwArg1)
                                 {
-                                    LCML_DPRINT("output buffer loop");
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "output buffer loop");
                                     tmpDspStructAddress = hDSPInterface->Armoutputstorage[i] ;
                                     hDSPInterface ->Armoutputstorage[i] =NULL;
                                     pDmmBuf = hDSPInterface ->dspCodec->OutDmmBuffer;
                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->Bufoutindex);
-                                    LCML_DPRINT("Address output  matching index= %ld\n ",tmpDspStructAddress->Bufoutindex);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "Address output  matching index= %ld\n ",tmpDspStructAddress->Bufoutindex);
                                     break;
                                 }
                                 i++;
                                 i = i % QUEUE_SIZE;
-                                LCML_DPRINT("Message EMMCodecOuputBuffer loop");
+                                OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                        "Message EMMCodecOuputBuffer loop");
                             }
                         }
 
                         if (tmpDspStructAddress != NULL)
                         {
                             char *tmp2 = NULL;
-                            
+
                             event = EMMCodecBufferProcessed;
                             args[0] = (void *) bufType;
                             args[1] = (void *) tmpDspStructAddress->iArmbufferArg; /* arm address fpr buffer */
@@ -1718,29 +1858,36 @@
                             args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
                             /* managing buffers  and free buffer logic */
 
-                            LCML_DPRINT("GOT MESSAGE EMMCodecBufferProcessed  and now unmapping buffer type %p \n", args[2]);
+                            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                    "GOT MESSAGE EMMCodecBufferProcessed  and now unmapping buffer type %p \n", args[2]);
 
                             if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
                             {
-                                LCML_DPRINT("GOT MESSAGE EMMCodecBufferProcessed and now unmapping buufer %lx\n size=%ld",
+                                OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                        "GOT MESSAGE EMMCodecBufferProcessed and now unmapping buufer %lx\n size=%ld",
                                              tmpDspStructAddress ->iBufferPtr, tmpDspStructAddress ->iBufferSize);
-
-                                DmmUnMap(hDSPInterface->dspCodec->hProc,
-                                         (void*)tmpDspStructAddress->iBufferPtr,
-                                         pDmmBuf->bufReserved);
+                                /* 720p implementation */
+                                if (!hDSPInterface->ReUseMap)
+                                {
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc,
+                                            (void*)tmpDspStructAddress->iBufferPtr,
+                                            pDmmBuf->bufReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
+                                }
                             }
 
                             if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
                             {
-                                LCML_DPRINT("GOT MESSAGE EMMCodecBufferProcessed and now unmapping parameter buufer\n");
+                                OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                        "GOT MESSAGE EMMCodecBufferProcessed and now unmapping parameter buufer\n");
 
                                 DmmUnMap(hDSPInterface ->dspCodec->hProc,
                                          (void*)tmpDspStructAddress->iParamPtr,
-                                         pDmmBuf->paramReserved);
+                                         pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                             }
 
-                            LCML_DPRINT("GOT MESSAGE EMMCodecBufferProcessed  and now unmapping  structure =0x%p\n",tmpDspStructAddress );
-                            DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                            OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                    "GOT MESSAGE EMMCodecBufferProcessed  and now unmapping  structure =0x%p\n",tmpDspStructAddress );
+                            DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                             tmp2 = (char *)tmpDspStructAddress;
                             tmp2 = (tmp2 - 128);
                             if (tmp2)
@@ -1757,27 +1904,30 @@
 
                     else if (commandId == USN_DSPACK_STOP)
                     {
-                        threadState = EMessagingThreadCodecStopped;                    
-                        
+                        threadState = EMessagingThreadCodecStopped;
+
                         /* Start of USN_DSPACK_STOP */
                         int i = 0;
                         int j = 0;
                         int k = 0;
-                        LCML_DPRINT("GOT MESSAGE EMMCodecProcessingStoped \n");
+                        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                "GOT MESSAGE EMMCodecProcessingStoped \n");
                         pthread_mutex_lock(&hDSPInterface->mutex);
-                        LCML_DPRINT("LCMLSTOP: hDSPInterface->dspCodec->DeviceInfo.TypeofDevice %d\n", hDSPInterface->dspCodec->DeviceInfo.TypeofDevice);
+                        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                "LCMLSTOP: hDSPInterface->dspCodec->DeviceInfo.TypeofDevice %d\n", hDSPInterface->dspCodec->DeviceInfo.TypeofDevice);
                         if (hDSPInterface->dspCodec->DeviceInfo.TypeofDevice == 0)
                         {
                             j = 0;
                             hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
                             i = hDSPInterface->iBufinputcount;
-                            
+
                             hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
                             k = hDSPInterface->iBufoutputcount;
 
                             while(j++ < QUEUE_SIZE)
                             {
-                                LCML_DPRINT("LCMLSTOP: %d hDSPInterface->Arminputstorage[i] = %p\n", i, hDSPInterface->Arminputstorage[i]);
+                                OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                        "LCMLSTOP: %d hDSPInterface->Arminputstorage[i] = %p\n", i, hDSPInterface->Arminputstorage[i]);
                                 if (hDSPInterface->Arminputstorage[i] != NULL)
                                 {
                                     char *tmp2 = NULL;
@@ -1786,7 +1936,8 @@
 
                                     pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
-                                    LCML_DPRINT("pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
+                                    OMX_PRBUFFER1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
 
                                     event = EMMCodecBufferProcessed;
                                     args[0] = (void *) EMMCodecInputBuffer;
@@ -1795,33 +1946,41 @@
                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg; /* arm address for param */
                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
-                                    args[6] = (void *) arg;  /* handle */                            
+                                    args[6] = (void *) arg;  /* handle */
                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;  /* user arguments */
                                     /* USN updates*/
                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
 
-                                    LCML_DPRINT("LCMLSTOP: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
-                                            tmpDspStructAddress->iBufferPtr,
-                                            tmpDspStructAddress->iParamPtr,
-                                            msg.dwArg1);
+                                    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "LCMLSTOP: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
+                                            (void *)tmpDspStructAddress->iBufferPtr,
+                                            (void *)tmpDspStructAddress->iParamPtr,
+                                            (void *)msg.dwArg1);
                                     if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
                                     {
-                                        DmmUnMap(hDSPInterface->dspCodec->hProc,
-                                                 (void*)tmpDspStructAddress->iBufferPtr,
-                                                 pDmmBuf->bufReserved);
+                                        if (!hDSPInterface->ReUseMap)
+                                        {
+                                            DmmUnMap(hDSPInterface->dspCodec->hProc,
+                                                    (void*)tmpDspStructAddress->iBufferPtr,
+                                                    pDmmBuf->bufReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
+                                        }
                                     }
 
                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
                                     {
                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
                                                  (void*)tmpDspStructAddress->iParamPtr,
-                                                 pDmmBuf->paramReserved);
+                                                 pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     }
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
 
-                                    tmp2 = (char*)tmpDspStructAddress;
-                                    tmp2 = ( tmp2 - 128);
-                                    LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
+                                    if (NULL != tmpDspStructAddress)
+                                    {
+                                        tmp2 = (char*)tmpDspStructAddress;
+                                        tmp2 = ( tmp2 - 128);
+                                    }
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "%d :: LCML:: FreeResources\n",__LINE__);
                                     if (tmp2)
                                     {
                                         LCML_FREE(tmp2);
@@ -1838,8 +1997,9 @@
 #endif
                                     hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
                                 }
-                                
-                                LCML_DPRINT("LCMLSTOP: %d hDSPInterface->Armoutputstorage[k] = %p\n", k, hDSPInterface->Armoutputstorage[k]);
+
+                                OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                        "LCMLSTOP: %d hDSPInterface->Armoutputstorage[k] = %p\n", k, hDSPInterface->Armoutputstorage[k]);
                                 if (hDSPInterface->Armoutputstorage[k] != NULL)
                                 {
                                     char * tmp2 = NULL;
@@ -1855,34 +2015,41 @@
                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg; /* arm address for param */
                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
-                                    args[6] = (void *) arg;  /* handle */                           
+                                    args[6] = (void *) arg;  /* handle */
                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;  /* user arguments */
                                     /* USN updates*/
 
-                                    LCML_DPRINT("LCMLSTOP: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
-                                            tmpDspStructAddress->iBufferPtr,
-                                            tmpDspStructAddress->iParamPtr,
-                                            msg.dwArg1);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
+                                            "LCMLSTOP: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
+                                            (void *)tmpDspStructAddress->iBufferPtr,
+                                            (void *)tmpDspStructAddress->iParamPtr,
+                                            (void *)msg.dwArg1);
                                     if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
                                     {
-                                    LCML_DPRINT("tmpDspStructAddress ->iBufferPtr is not NULL\n");
-                                        DmmUnMap(hDSPInterface->dspCodec->hProc,
-                                                 (void*)tmpDspStructAddress->iBufferPtr,
-                                                 pDmmBuf->bufReserved);
+                                        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                                "tmpDspStructAddress ->iBufferPtr is not NULL\n");
+                                        if (!hDSPInterface->ReUseMap)
+                                        {
+                                            DmmUnMap(hDSPInterface->dspCodec->hProc,
+                                                    (void*)tmpDspStructAddress->iBufferPtr,
+                                                    pDmmBuf->bufReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
+                                        }
                                     }
 
                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
                                     {
-                                    LCML_DPRINT("tmpDspStructAddress->iParamPtr is not NULL\n");
+                                        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                                "tmpDspStructAddress->iParamPtr is not NULL\n");
                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
                                                  (void*)tmpDspStructAddress->iParamPtr,
-                                                 pDmmBuf->paramReserved);
+                                                 pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     }
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
 
                                     tmp2 = (char *) tmpDspStructAddress;
                                     tmp2 = ( tmp2 - 128);
-                                    LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "%d :: LCML:: FreeResources\n",__LINE__);
                                     if(tmp2)
                                     {
                                         LCML_FREE(tmp2);
@@ -1911,21 +2078,23 @@
                         pthread_mutex_unlock(&hDSPInterface->mutex);
                         args[6] = (void *) arg;  /* handle */
                         event = EMMCodecProcessingStoped;
-                        
+
                     } /* end of USN_DSPACK_STOP */
                     else if (commandId == USN_DSPACK_PAUSE)
                     {
-                    
+
                         event = EMMCodecProcessingPaused;
-                        LCML_DPRINT("GOT MESSAGE EMMCodecProcessingPaused \n");
+                        OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                "GOT MESSAGE EMMCodecProcessingPaused \n");
                         args[6] = (void *) arg;  /* handle */
                     }
                     else if (commandId == USN_DSPMSG_EVENT)
                     {
-                        threadState = EMessagingThreadCodecStopped;                    
-                    
+                        threadState = EMessagingThreadCodecStopped;
+
                         event = EMMCodecDspError;
-                        LCML_DPRINT("GOT MESSAGE EMMCodecDspError \n");
+                        OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                "GOT MESSAGE EMMCodecDspError \n");
                         args[0] = (void *) msg.dwCmd;
                         args[4] = (void *) msg.dwArg1;
                         args[5] = (void *) msg.dwArg2;
@@ -1933,7 +2102,7 @@
                     }
                     else if (commandId == USN_DSPACK_ALGCTRL)
                     {
-                    
+
                         int i;
                         event = EMMCodecAlgCtrlAck;
                         pthread_mutex_lock(&hDSPInterface->mutex);
@@ -1944,7 +2113,8 @@
                                 (((LCML_DSP_INTERFACE *)arg)->algcntlmapped[i]) &&
                                 (pDmmBuf->pMapped == (void *)msg.dwArg2))
                             {
-                                DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, 
+                                        ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                 LCML_FREE(pDmmBuf);
                                 pDmmBuf = NULL;
                                 ((LCML_DSP_INTERFACE *)arg)->algcntlmapped[i] = 0;
@@ -1954,12 +2124,12 @@
                         }
                         args[0] = (void *) msg.dwArg1;
                         args[6] = (void *) arg;  /* handle */
-                        LCML_DPRINT("GOT MESSAGE USN_DSPACK_ALGCTRL \n");
+                        OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE USN_DSPACK_ALGCTRL \n");
                         pthread_mutex_unlock(&hDSPInterface->mutex);
                     }
                     else if (commandId == USN_DSPACK_STRMCTRL)
                     {
-                    
+
                         int i = 0;
                         int j = 0;
                         int ackType = 0;
@@ -1973,7 +2143,8 @@
                             i = hDSPInterface->iBufinputcount;
                             while(j++ < QUEUE_SIZE)
                             {
-                                LCML_DPRINT("LCMLFLUSH: %d hDSPInterface->Arminputstorage[i] = %p\n", i, hDSPInterface->Arminputstorage[i]);
+                                OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                        "LCMLFLUSH: %d hDSPInterface->Arminputstorage[i] = %p\n", i, hDSPInterface->Arminputstorage[i]);
                                 if (hDSPInterface->Arminputstorage[i] != NULL)
                                 {
                                     char *tmp2 = NULL;
@@ -1981,7 +2152,8 @@
 
                                     pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
-                                    LCML_DPRINT("pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
+                                    OMX_PRBUFFER2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
 
                                     event = EMMCodecBufferProcessed;
                                     args[0] = (void *) EMMCodecInputBuffer;
@@ -1990,33 +2162,46 @@
                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg;
                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
-                                    args[6] = (void *) arg;            
+                                    args[6] = (void *) arg;
                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;
 
                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
 
-                                    LCML_DPRINT("LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
-                                            tmpDspStructAddress->iBufferPtr,
-                                            tmpDspStructAddress->iParamPtr,
-                                            msg.dwArg1);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
+                                            (void *)tmpDspStructAddress->iBufferPtr,
+                                            (void *)tmpDspStructAddress->iParamPtr,
+                                            (void *)msg.dwArg1);
+
                                     if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
                                     {
-                                        DmmUnMap(hDSPInterface->dspCodec->hProc,
-                                                 (void*)tmpDspStructAddress->iBufferPtr,
-                                                 pDmmBuf->bufReserved);
+                                        /* 720p implementation */
+                                        if (!hDSPInterface->ReUseMap)
+                                        {
+                                            DmmUnMap(hDSPInterface->dspCodec->hProc,
+                                                    (void*)tmpDspStructAddress->iBufferPtr,
+                                                    pDmmBuf->bufReserved, 
+                                                    ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
+                                        }
                                     }
 
                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
                                     {
                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
                                                  (void*)tmpDspStructAddress->iParamPtr,
-                                                 pDmmBuf->paramReserved);
+                                                 pDmmBuf->paramReserved, 
+                                                 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     }
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, 
+                                            ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
 
-                                    tmp2 = (char*)tmpDspStructAddress;
-                                    tmp2 = ( tmp2 - 128);
-                                    LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
+                                    if (NULL != tmpDspStructAddress)
+                                    {
+                                        tmp2 = (char*)tmpDspStructAddress;
+                                        tmp2 = ( tmp2 - 128);
+                                    }
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "%d :: LCML:: FreeResources\n",__LINE__);
                                     if (tmp2)
                                     {
                                         LCML_FREE(tmp2);
@@ -2043,7 +2228,8 @@
                                     (((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i]) &&
                                     (pDmmBuf->pMapped == (void *)msg.dwArg2))
                                 {
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, 
+                                            ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     LCML_FREE(pDmmBuf);
                                     pDmmBuf = NULL;
                                     ((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i] = 0;
@@ -2051,17 +2237,18 @@
                                     break;
                                 }
                             }
-                        } 
+                        }
                         else if (hDSPInterface->flush_pending[1] && (streamId == 1) && (msg.dwArg1 == USN_ERR_NONE))
                         {
                             hDSPInterface->flush_pending[1] = 0;
-                            ackType = USN_STRMCMD_FLUSH;                            
+                            ackType = USN_STRMCMD_FLUSH;
                             j = 0;
                             hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
                             i = hDSPInterface->iBufoutputcount;
                             while(j++ < QUEUE_SIZE)
                             {
-                                LCML_DPRINT("LCMLFLUSH: %d hDSPInterface->Armoutputstorage[i] = %p\n", i, hDSPInterface->Armoutputstorage[i]);
+                                OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                        "LCMLFLUSH: %d hDSPInterface->Armoutputstorage[i] = %p\n", i, hDSPInterface->Armoutputstorage[i]);
                                 if (hDSPInterface->Armoutputstorage[i] != NULL)
                                 {
                                     char * tmp2 = NULL;
@@ -2077,34 +2264,45 @@
                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg;
                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
-                                    args[6] = (void *) arg;           
+                                    args[6] = (void *) arg;
                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;
 
 
-                                    LCML_DPRINT("LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
-                                            tmpDspStructAddress->iBufferPtr,
-                                            tmpDspStructAddress->iParamPtr,
-                                            msg.dwArg1);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
+                                            (void *)tmpDspStructAddress->iBufferPtr,
+                                            (void *)tmpDspStructAddress->iParamPtr,
+                                            (void *)msg.dwArg1);
                                     if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
                                     {
-                                    LCML_DPRINT("tmpDspStructAddress ->iBufferPtr is not NULL\n");
-                                        DmmUnMap(hDSPInterface->dspCodec->hProc,
-                                                 (void*)tmpDspStructAddress->iBufferPtr,
-                                                 pDmmBuf->bufReserved);
+                                        /* 720p implementation */
+                                        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                                "tmpDspStructAddress ->iBufferPtr is not NULL\n");
+                                        if (!hDSPInterface->ReUseMap)
+                                        {
+                                            DmmUnMap(hDSPInterface->dspCodec->hProc,
+                                                    (void*)tmpDspStructAddress->iBufferPtr,
+                                                    pDmmBuf->bufReserved, 
+                                                    ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
+                                        }
                                     }
 
                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
                                     {
-                                    LCML_DPRINT("tmpDspStructAddress->iParamPtr is not NULL\n");
+                                        OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                                "tmpDspStructAddress->iParamPtr is not NULL\n");
                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
                                                  (void*)tmpDspStructAddress->iParamPtr,
-                                                 pDmmBuf->paramReserved);
+                                                 pDmmBuf->paramReserved, 
+                                                 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     }
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, 
+                                            ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
 
                                     tmp2 = (char *) tmpDspStructAddress;
                                     tmp2 = ( tmp2 - 128);
-                                    LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "%d :: LCML:: FreeResources\n",__LINE__);
                                     if(tmp2)
                                     {
                                         LCML_FREE(tmp2);
@@ -2134,7 +2332,8 @@
                                     (((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i]) &&
                                     (pDmmBuf->pMapped == (void *)msg.dwArg2))
                                 {
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved, 
+                                            ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     LCML_FREE(pDmmBuf);
                                     pDmmBuf = NULL;
                                     ((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i] = 0;
@@ -2146,13 +2345,14 @@
                         if (hDSPInterface->flush_pending[2] && (streamId == 2) && (msg.dwArg1 == USN_ERR_NONE))
                         {
                             hDSPInterface->flush_pending[0] = 0;
-                            ackType = USN_STRMCMD_FLUSH;                            
+                            ackType = USN_STRMCMD_FLUSH;
                             j = 0;
                             hDSPInterface->iBufinputcount = hDSPInterface->iBufinputcount % QUEUE_SIZE;
                             i = hDSPInterface->iBufinputcount;
                             while(j++ < QUEUE_SIZE)
                             {
-                                LCML_DPRINT("LCMLFLUSH (port 2): %d hDSPInterface->Arminputstorage[i] = %p (stream ID %d)\n", i, hDSPInterface->Arminputstorage[i], streamId);
+                                OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                        "LCMLFLUSH (port 2): %d hDSPInterface->Arminputstorage[i] = %p (stream ID %lu)\n", i, hDSPInterface->Arminputstorage[i], streamId);
                                 if ((hDSPInterface->Arminputstorage[i] != NULL) && (hDSPInterface->Arminputstorage[i]->iStreamID == streamId))
                                 {
                                     char *tmp2 = NULL;
@@ -2160,7 +2360,8 @@
 
                                     pDmmBuf = hDSPInterface ->dspCodec->InDmmBuffer;
                                     pDmmBuf = pDmmBuf + (tmpDspStructAddress->BufInindex);
-                                    LCML_DPRINT("pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
+                                    OMX_PRBUFFER2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "pDmmBuf->pMapped %p\n", pDmmBuf->pMapped);
 
                                     event = EMMCodecBufferProcessed;
                                     args[0] = (void *) EMMCodecInputBuffer;
@@ -2169,33 +2370,40 @@
                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg;
                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
-                                    args[6] = (void *) arg;            
+                                    args[6] = (void *) arg;
                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;
 
                                     args[8] = (void *) tmpDspStructAddress->iBufSizeUsed ;
 
-                                    LCML_DPRINT("LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
-                                            tmpDspStructAddress->iBufferPtr,
-                                            tmpDspStructAddress->iParamPtr,
-                                            msg.dwArg1);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
+                                            (void *)tmpDspStructAddress->iBufferPtr,
+                                            (void *)tmpDspStructAddress->iParamPtr,
+                                            (void *)msg.dwArg1);
                                     if (tmpDspStructAddress->iBufferPtr != (OMX_U32)NULL)
                                     {
-                                        DmmUnMap(hDSPInterface->dspCodec->hProc,
-                                                 (void*)tmpDspStructAddress->iBufferPtr,
-                                                 pDmmBuf->bufReserved);
+                                        /* 720p implementation */
+                                        if (!hDSPInterface->ReUseMap)
+                                        {
+                                            DmmUnMap(hDSPInterface->dspCodec->hProc,
+                                                    (void*)tmpDspStructAddress->iBufferPtr,
+                                                    pDmmBuf->bufReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
+                                        }
                                     }
 
                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
                                     {
                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
                                                  (void*)tmpDspStructAddress->iParamPtr,
-                                                 pDmmBuf->paramReserved);
+                                                 pDmmBuf->paramReserved, ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     }
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
+                                            ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
 
                                     tmp2 = (char*)tmpDspStructAddress;
                                     tmp2 = ( tmp2 - 128);
-                                    LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "%d :: LCML:: FreeResources\n",__LINE__);
                                     if (tmp2)
                                     {
                                         LCML_FREE(tmp2);
@@ -2215,17 +2423,18 @@
                                 i++;
                                 i = i % QUEUE_SIZE;
                             }
-                        } 
+                        }
                         else if (hDSPInterface->flush_pending[3] && (streamId == 3) && (msg.dwArg1 == USN_ERR_NONE))
                         {
                             hDSPInterface->flush_pending[1] = 0;
-                            ackType = USN_STRMCMD_FLUSH;                            
+                            ackType = USN_STRMCMD_FLUSH;
                             j = 0;
                             hDSPInterface->iBufoutputcount = hDSPInterface->iBufoutputcount % QUEUE_SIZE;
                             i = hDSPInterface->iBufoutputcount;
                             while(j++ < QUEUE_SIZE)
                             {
-                                LCML_DPRINT("LCMLFLUSH: %d hDSPInterface->Armoutputstorage[i] = %p (stream id %d)\n", i, hDSPInterface->Armoutputstorage[i], streamId);
+                                OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg,
+                                        "LCMLFLUSH: %d hDSPInterface->Armoutputstorage[i] = %p (stream id %lu)\n", i, hDSPInterface->Armoutputstorage[i], streamId);
                                 if ((hDSPInterface->Armoutputstorage[i] != NULL) && (hDSPInterface->Armoutputstorage[i]->iStreamID == streamId))
                                 {
                                     char * tmp2 = NULL;
@@ -2241,34 +2450,45 @@
                                     args[3] = (void *) tmpDspStructAddress->iArmParamArg;
                                     args[4] = (void *) tmpDspStructAddress->iParamSize;
                                     args[5] = (void *) tmpDspStructAddress->iArmArg;
-                                    args[6] = (void *) arg;           
+                                    args[6] = (void *) arg;
                                     args[7] = (void *) tmpDspStructAddress->iUsrArg;
 
 
-                                    LCML_DPRINT("LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
-                                            tmpDspStructAddress->iBufferPtr,
-                                            tmpDspStructAddress->iParamPtr,
-                                            msg.dwArg1);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "LCMLFLUSH: tmpDspStructAddress->iBufferPtr %p, tmpDspStructAddress->iParamPtr %p, msg.dwArg1 %p\n",
+                                            (void *)tmpDspStructAddress->iBufferPtr,
+                                            (void *)tmpDspStructAddress->iParamPtr,
+                                            (void *)msg.dwArg1);
                                     if (tmpDspStructAddress ->iBufferPtr != (OMX_U32)NULL)
                                     {
-                                    LCML_DPRINT("tmpDspStructAddress ->iBufferPtr is not NULL\n");
-                                        DmmUnMap(hDSPInterface->dspCodec->hProc,
-                                                 (void*)tmpDspStructAddress->iBufferPtr,
-                                                 pDmmBuf->bufReserved);
+                                        /* 720p implementation */
+                                        OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                                "tmpDspStructAddress ->iBufferPtr is not NULL\n");
+                                        if (!hDSPInterface->ReUseMap)
+                                        {
+                                            DmmUnMap(hDSPInterface->dspCodec->hProc,
+                                                    (void*)tmpDspStructAddress->iBufferPtr,
+                                                    pDmmBuf->bufReserved,
+                                                    ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
+                                        }
                                     }
 
                                     if (tmpDspStructAddress->iParamPtr != (OMX_U32)NULL)
                                     {
-                                    LCML_DPRINT("tmpDspStructAddress->iParamPtr is not NULL\n");
+                                        OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                                "tmpDspStructAddress->iParamPtr is not NULL\n");
                                         DmmUnMap(hDSPInterface ->dspCodec->hProc,
                                                  (void*)tmpDspStructAddress->iParamPtr,
-                                                 pDmmBuf->paramReserved);
+                                                 pDmmBuf->paramReserved,
+                                                 ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     }
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
+                                            ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
 
                                     tmp2 = (char *) tmpDspStructAddress;
                                     tmp2 = ( tmp2 - 128);
-                                    LCML_DPRINT("%d :: LCML:: FreeResources\n",__LINE__);
+                                    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, 
+                                            "%d :: LCML:: FreeResources\n",__LINE__);
                                     if(tmp2)
                                     {
                                         LCML_FREE(tmp2);
@@ -2301,7 +2521,8 @@
                                     (((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i]) &&
                                     (pDmmBuf->pMapped == (void *)msg.dwArg2))
                                 {
-                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved);
+                                    DmmUnMap(hDSPInterface->dspCodec->hProc, pDmmBuf->pMapped, pDmmBuf->pReserved,
+                                            ((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg);
                                     LCML_FREE(pDmmBuf);
                                     pDmmBuf = NULL;
                                     ((LCML_DSP_INTERFACE *)arg)->strmcntlmapped[i] = 0;
@@ -2311,14 +2532,14 @@
                             }
                         }
                         pthread_mutex_unlock(&hDSPInterface->mutex);
-                        
+
                         event = EMMCodecStrmCtrlAck;
-                        bufType = streamId + EMMCodecStream0;  
+                        bufType = streamId + EMMCodecStream0;
                         args[0] = (void *) msg.dwArg1; /* SN error status */
                         args[1] = (void *) ackType;    /* acknowledge Id */
                         args[2] = (void *) bufType;    /* port Id */
                         args[6] = (void *) arg;        /* handle */
-                        LCML_DPRINT("GOT MESSAGE USN_DSPACK_STRMCTRL \n");
+                        OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE USN_DSPACK_STRMCTRL \n");
                     }
                     else
                     {
@@ -2327,11 +2548,11 @@
                         args[1] = (void *) msg.dwArg1;
                         args[2] = (void *) msg.dwArg2;
                         args[6] = (void *) arg;  /* handle */
-                        LCML_DPRINT("GOT MESSAGE EMMCodecDspMessageRecieved \n");
+                        OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "GOT MESSAGE EMMCodecDspMessageRecieved \n");
                     }
 
                     /* call callback */
-                    LCML_DPRINT("calling callback in application %p \n",((LCML_DSP_INTERFACE *)arg)->dspCodec);
+                    OMX_PRINT2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "calling callback in application %p \n",((LCML_DSP_INTERFACE *)arg)->dspCodec);
 #ifdef __PERF_INSTRUMENTATION__
                     PERF_SendingCommand(hDSPInterface->pPERFcomp,
                                         msg.dwCmd,
@@ -2343,17 +2564,17 @@
                 }/* end of internal if(DSP_SUCCEEDED(status)) */
                 else
                 {
-                    LCML_DPRINT("%d :: DSPManager_getmessage() failed: 0x%lx",__LINE__, status);
+                    OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "%d :: DSPManager_getmessage() failed: 0x%lx",__LINE__, status);
                 }
 
             }/* end of internal while loop*/
-#ifdef __ERROR_PROPAGATION__                
-            }/*end of if(index == 0)*/            
+#ifdef __ERROR_PROPAGATION__
+            }/*end of if(index == 0)*/
             if (index == 1){
-            
+
                 struct DSP_PROCESSORSTATE  procState;
                 DSPProcessor_GetState(((LCML_DSP_INTERFACE *)arg)->dspCodec->hProc, &procState, sizeof(procState));
-                
+
                 /*
                 fprintf(stdout, " dwErrMask = %0x \n",procState.errInfo.dwErrMask);
                 fprintf(stdout, " dwVal1 = %0x \n",procState.errInfo.dwVal1);
@@ -2361,7 +2582,7 @@
                 fprintf(stdout, " dwVal3 = %0x \n",procState.errInfo.dwVal3);
                 fprintf(stdout, "MMU Fault Error.\n");
                 */
-            
+
                 TUsnCodecEvent  event = EMMCodecDspError;
                 void * args[10];
                 LCML_DSP_INTERFACE *hDSPInterface = ((LCML_DSP_INTERFACE *)arg) ;
@@ -2370,13 +2591,13 @@
                 args[5] = NULL;
                 args[6] = (void *) arg;  /* handle */
                 hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
-      
+
             }
             if (index == 2){
-            
+
                 struct DSP_PROCESSORSTATE  procState;
                 DSPProcessor_GetState(((LCML_DSP_INTERFACE *)arg)->dspCodec->hProc, &procState, sizeof(procState));
-                
+
                 /*
                 fprintf(stdout, " dwErrMask = %0x \n",procState.errInfo.dwErrMask);
                 fprintf(stdout, " dwVal1 = %0x \n",procState.errInfo.dwVal1);
@@ -2384,7 +2605,7 @@
                 fprintf(stdout, " dwVal3 = %0x \n",procState.errInfo.dwVal3);
                 fprintf(stdout, "SYS_ERROR Error.\n");
                 */
-            
+
                 TUsnCodecEvent  event = EMMCodecDspError;
                 void * args[10];
                 LCML_DSP_INTERFACE *hDSPInterface = ((LCML_DSP_INTERFACE *)arg) ;
@@ -2393,18 +2614,23 @@
                 args[5] = NULL;
                 args[6] = (void *) arg;  /* handle */
                 hDSPInterface->dspCodec->Callbacks.LCML_Callback(event,args);
-      
+
             }
-#endif            
+#endif
         } /* end of external if(DSP_SUCCEEDED(status)) */
         else
         {
-            LCML_DPRINT("%d :: DSPManager_WaitForEvents() failed: 0x%lx",__LINE__, status);
+            OMX_PRDSP2 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "%d :: DSPManager_WaitForEvents() failed: 0x%lx",__LINE__, status);
         }
 
     } /* end of external while(1) loop */
 
-    LCML_DPRINT("Exiting LOOP of LCML \n");
+	/* 720p implementation */
+    if (((LCML_DSP_INTERFACE *)arg)->ReUseMap)
+    {
+        pthread_mutex_unlock(&((LCML_DSP_INTERFACE *)arg)->m_isStopped_mutex);
+    }
+    OMX_PRINT1 (((LCML_CODEC_INTERFACE *)((LCML_DSP_INTERFACE *)arg)->pCodecinterfacehandle)->dbg, "Exiting LOOP of LCML \n");
 #ifdef __PERF_INSTRUMENTATION__
     PERF_Done(((LCML_DSP_INTERFACE *)arg)->pPERFcomp);
 #endif
@@ -2418,7 +2644,7 @@
     char *dsp_path = NULL;
     if (!(dsp_path = getenv("DSP_PATH")))
     {
-        printf("DSP_PATH Environment variable not set using /system/lib/dsp default");
+        OMXDBG_PRINT(stderr, PRINT, 2, OMX_DBG_BASEMASK, "DSP_PATH Environment variable not set using /system/lib/dsp default");
         dsp_path = "/system/lib/dsp";
     }
     len = strlen(dsp_path) + strlen("/") + strlen(dll64p_name) + 1 /* null terminator */;
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 f0c6acf..46ada09 100644
--- a/omx/system/src/openmax_il/omx_core/src/Android.mk
+++ b/omx/system/src/openmax_il/omx_core/src/Android.mk
@@ -13,6 +13,7 @@
 
 LOCAL_SHARED_LIBRARIES := \
 	libdl \
+	libVendor_ti_omx_config_parser \
 	liblog
 	
 LOCAL_CFLAGS := $(TI_OMX_CFLAGS)
@@ -23,7 +24,6 @@
 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 c2ed3ea..33fd603 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
@@ -52,7 +52,7 @@
 
 char *tComponentName[MAXCOMP][2] = {
     /*video and image components */
-    //{"OMX.TI.JPEG.decode", "image_decoder.jpeg" },
+    //{"OMX.TI.JPEG.decoder", "image_decoder.jpeg" },
     {"OMX.TI.JPEG.Encoder", "image_encoder.jpeg"},
     //{"OMX.TI.Video.Decoder", "video_decoder.h263"},
     {"OMX.TI.Video.Decoder", "video_decoder.avc"},
@@ -79,30 +79,25 @@
     {"OMX.TI.GSMFR.encode", NULL},
     {"OMX.TI.GSMFR.decode", NULL},
 */
-    {"OMX.TI.AMR.encode", "audio_encoder.amrnb"},
-    //{"OMX.TI.AMR.decode", "audio_decoder.amrnb"},
-    {"OMX.TI.WBAMR.encode", "audio_encoder.amrwb"},
-    //{"OMX.TI.WBAMR.decode", "audio_decoder.amrwb"},
 
     /* Audio components */
 #ifdef BUILD_WITH_TI_AUDIO
     {"OMX.TI.MP3.decode", "audio_decoder.mp3"},
-#endif
     {"OMX.TI.AAC.encode", "audio_encoder.aac"},
-#ifdef BUILD_WITH_TI_AUDIO
     {"OMX.TI.AAC.decode", "audio_decoder.aac"},
+    {"OMX.TI.WMA.decode", "audio_decoder.wma"},
+    {"OMX.TI.WBAMR.decode", "audio_decoder.amrwb"},
+    {"OMX.TI.AMR.decode", "audio_decoder.amrnb"},
+    {"OMX.TI.AMR.encode", "audio_encoder.amrnb"},
+    {"OMX.TI.WBAMR.encode", "audio_encoder.amrwb"},
 #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.PCM.decode", NULL},     
     {"OMX.TI.RAG.decode", "audio_decoder.ra"},
     {"OMX.TI.IMAADPCM.decode", NULL},
     {"OMX.TI.IMAADPCM.encode", NULL},
 */
+
     /* terminate the table */
     {NULL, NULL},
 };
@@ -177,6 +172,7 @@
     OMX_ERRORTYPE (*pComponentInit)(OMX_HANDLETYPE*);
     OMX_ERRORTYPE err = OMX_ErrorNone;
     OMX_COMPONENTTYPE *componentType;
+    const char* pErr = dlerror();
 
     if(pthread_mutex_lock(&mutex) != 0)
     {
@@ -209,10 +205,7 @@
     }
 
     int refIndex = 0;
-    *pHandle = NULL;
-    pComponents[i] = NULL;
-
-    for (refIndex=0; refIndex < tableCount; refIndex++) {
+    for (refIndex=0; refIndex < MAX_TABLE_SIZE; refIndex++) {
         //get the index for the component in the table
         if (strcmp(componentTable[refIndex].name, cComponentName) == 0) {
             LOGD("Found component %s with refCount %d\n",
@@ -255,7 +248,8 @@
                 /* 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( pComponentInit == NULL ) {
+                pErr = dlerror();
+                if( (pErr != NULL) || (pComponentInit == NULL) ) {
                     LOGE("%d:: dlsym failed for module %p\n", __LINE__, pModules[i]);
                     err = OMX_ErrorInvalidComponent;
                     goto CLEAN_UP;
@@ -288,6 +282,10 @@
                     componentTable[refIndex].refCount += 1;
                     goto UNLOCK_MUTEX;  // Component is found, and thus we are done
                 }
+                else if (err == OMX_ErrorInsufficientResources) {
+                        LOGE("%d :: Core: Insufficient Resources for Component %d\n",__LINE__, err);
+                        goto CLEAN_UP;
+                }
             }
         }
     }
@@ -296,8 +294,12 @@
     err = OMX_ErrorComponentNotFound;
     goto UNLOCK_MUTEX;
 CLEAN_UP:
-    free(*pHandle);
-    *pHandle = NULL;
+    if(*pHandle != NULL)
+    /* cover the case where we error out before malloc'd */
+    {
+        free(*pHandle);
+        *pHandle = NULL;
+    }
     pComponents[i] = NULL;
     dlclose(pModules[i]);
     pModules[i] = NULL;
@@ -358,7 +360,7 @@
     }
 
     int refIndex = 0, handleIndex = 0;
-    for (refIndex=0; refIndex < tableCount; refIndex++) {
+    for (refIndex=0; refIndex < MAX_TABLE_SIZE; refIndex++) {
         for (handleIndex=0; handleIndex < componentTable[refIndex].refCount; handleIndex++){
             /* get the position for the component in the table */
             if (componentTable[refIndex].pHandle[handleIndex] == hComponent){
@@ -553,25 +555,25 @@
             LOGE("pNumRoles is NULL\n");
         }
         eError = OMX_ErrorBadParameter;
-        goto EXIT;
+        goto EXIT;       
     }
     while (i < tableCount)
-    {
-        if (strcmp(cComponentName, componentTable[i].name) == 0)
-        {
-            bFound = OMX_TRUE;
-            break;
+    {

+        if (strcmp(cComponentName, componentTable[i].name) == 0)

+        {

+            bFound = OMX_TRUE;

+            break;

         }
-        i++;
+        i++;

     }
     if (!bFound)
     {
         eError = OMX_ErrorComponentNotFound;
         LOGE("component %s not found\n", cComponentName);
         goto EXIT;
-    }
+    } 
     if (roles == NULL)
-    {
+    { 
         *pNumRoles = componentTable[i].nRoles;
     }
     else
@@ -582,7 +584,7 @@
            than we return an error */
         if (*pNumRoles >= componentTable[i].nRoles)
         {
-            for (j = 0; j<componentTable[i].nRoles; j++)
+            for (j = 0; j<componentTable[i].nRoles; j++) 
             {
                 strcpy((OMX_STRING)roles[j], componentTable[i].pRoleArray[j]);
             }
@@ -614,7 +616,7 @@
 * Note
 *
 **************************************************************************/
-OMX_API OMX_ERRORTYPE TIOMX_GetComponentsOfRole (
+OMX_API OMX_ERRORTYPE TIOMX_GetComponentsOfRole ( 
     OMX_IN      OMX_STRING role,
     OMX_INOUT   OMX_U32 *pNumComps,
     OMX_INOUT   OMX_U8  **compNames)
@@ -648,15 +650,15 @@
     }
 
     /* no matter, we always want to know number of matching components
-       so this will always run */
+       so this will always run */ 
     for (i = 0; i < tableCount; i++)
     {
-        for (j = 0; j < componentTable[i].nRoles; j++)
-        {
+        for (j = 0; j < componentTable[i].nRoles; j++) 
+        { 
             if (strcmp(componentTable[i].pRoleArray[j], role) == 0)
             {
                 /* the first call to this function should only count the number
-                   of roles
+                   of roles 
                 */
                 compOfRoleCount++;
             }
@@ -690,8 +692,8 @@
             k = 0;
             for (i = 0; i < tableCount; i++)
             {
-                for (j = 0; j < componentTable[i].nRoles; j++)
-                {
+                for (j = 0; j < componentTable[i].nRoles; j++) 
+                { 
                     if (strcmp(componentTable[i].pRoleArray[j], role) == 0)
                     {
                         /*  the second call compNames can be allocated
@@ -705,11 +707,11 @@
                                so we can exit here */
                             *pNumComps = k;
                             goto EXIT;
-                        }
+                        } 
                     }
                 }
             }
-        }
+        }        
     }
 
     EXIT:
@@ -729,27 +731,29 @@
         if (tComponentName[i][0] == NULL) {
             break;
         }
-        for (j = 0; j < numFiles; j ++) {
-            if (!strcmp(componentTable[j].name, tComponentName[i][0])) {
-                /* insert the role */
-                if (tComponentName[i][1] != NULL)
-                {
-                    componentTable[j].pRoleArray[componentTable[j].nRoles] = tComponentName[i][1];
-                    componentTable[j].pHandle[componentTable[j].nRoles] = NULL; //initilize the pHandle element
-                    componentTable[j].nRoles ++;
+        if (numFiles <= MAX_TABLE_SIZE){
+            for (j = 0; j < numFiles; j ++) {
+                if (!strcmp(componentTable[j].name, tComponentName[i][0])) {
+                    /* insert the role */
+                    if (tComponentName[i][1] != NULL)
+                    {
+                        componentTable[j].pRoleArray[componentTable[j].nRoles] = tComponentName[i][1];
+                        componentTable[j].pHandle[componentTable[j].nRoles] = NULL; //initilize the pHandle element
+                        componentTable[j].nRoles ++;
+                    }
+                    break;
                 }
-                break;
             }
-        }
-        if (j == numFiles) { /* new component */
-            if (tComponentName[i][1] != NULL){
-                componentTable[numFiles].pRoleArray[0] = tComponentName[i][1];
-                componentTable[numFiles].nRoles = 1;
+            if (j == numFiles) { /* new component */
+                if (tComponentName[i][1] != NULL){
+                    componentTable[numFiles].pRoleArray[0] = tComponentName[i][1];
+                    componentTable[numFiles].nRoles = 1;
+                }
+                strcpy(compName[numFiles], tComponentName[i][0]);
+                componentTable[numFiles].name = compName[numFiles];
+                componentTable[numFiles].refCount = 0; //initialize reference counter.
+                numFiles ++;
             }
-            strcpy(compName[numFiles], tComponentName[i][0]);
-            componentTable[numFiles].name = compName[numFiles];
-            componentTable[numFiles].refCount = 0; //initialize reference counter.
-            numFiles ++;
         }
     }
     tableCount = numFiles;
diff --git a/omx/system/src/openmax_il/perf/Android.mk b/omx/system/src/openmax_il/perf/Android.mk
index c802878..d946197 100644
--- a/omx/system/src/openmax_il/perf/Android.mk
+++ b/omx/system/src/openmax_il/perf/Android.mk
@@ -1,3 +1,4 @@
+ifeq ($(PERF_INSTRUMENTATION),1)
 LOCAL_PATH:= $(call my-dir)
 
 include $(CLEAR_VARS)
@@ -38,3 +39,4 @@
 LOCAL_MODULE:= libPERF
 
 include $(BUILD_SHARED_LIBRARY)
+endif
diff --git a/omx/system/src/openmax_il/perf/src/perf_print.c b/omx/system/src/openmax_il/perf/src/perf_print.c
index 5c007ad..5173be8 100644
--- a/omx/system/src/openmax_il/perf/src/perf_print.c
+++ b/omx/system/src/openmax_il/perf/src/perf_print.c
@@ -371,8 +371,8 @@
 			me->csv ? "," : "(",
 			ulArgument,
             me->csv ? "," : ") = ",
-            (ulCommand < PERF_CommandMax  ?
-             PERF_CommandTypes[ulCommand] : "INVALID"),			
+            (ulCommand != PERF_CommandStatus  ?
+             "INVALID" : PERF_CommandTypes[ulCommand]),			
             me->csv ? "" : ")");
 
     print_print_location(perf, fOut, 5);
diff --git a/omx/system/src/openmax_il/perf/src/perf_rt.c b/omx/system/src/openmax_il/perf/src/perf_rt.c
index 87cc017..b5895be 100644
--- a/omx/system/src/openmax_il/perf/src/perf_rt.c
+++ b/omx/system/src/openmax_il/perf/src/perf_rt.c
@@ -131,8 +131,7 @@
         /* configuration */
         me->summary     = config->rt_summary != 0;
         me->debug       = config->rt_debug & 0x1FF;
-        me->detailed    = (config->rt_detailed < 0) ? 0 :
-                          (config->rt_detailed > 2) ? 2 : (int) config->rt_detailed;
+        me->detailed    = (config->rt_detailed > 2) ? 2 : (int) config->rt_detailed;
 
         me->granularity = (config->rt_granularity < 1) ? 1 :
                           (config->rt_granularity > MAX_GRANULARITY) ?
diff --git a/omx/ti_omx_config_parser/Android.mk b/omx/ti_omx_config_parser/Android.mk
index c6a0021..5c8ace8 100644
--- a/omx/ti_omx_config_parser/Android.mk
+++ b/omx/ti_omx_config_parser/Android.mk
@@ -1,5 +1,3 @@
-ifneq ($(BUILD_WITHOUT_PV),true)
-
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
 $(call add-prebuilt-files, ETC)
@@ -56,5 +54,3 @@
 LOCAL_SHARED_LIBRARIES += libopencore_common
 
 include $(BUILD_SHARED_LIBRARY)
-
-endif
diff --git a/omx/ti_omx_config_parser/inc/ti_m4v_config_parser.h b/omx/ti_omx_config_parser/inc/ti_m4v_config_parser.h
index a8ec2b2..acbe7ae 100644
--- a/omx/ti_omx_config_parser/inc/ti_m4v_config_parser.h
+++ b/omx/ti_omx_config_parser/inc/ti_m4v_config_parser.h
@@ -21,11 +21,16 @@
 #include "oscl_base.h"
 #include "oscl_types.h"
 
+#include <utils/Log.h>
+#define LOG_TAG "TI_Parser_Utils"
+
 #define USE_LATER 0  // for some code that will be needed in the future
 
 #define MP4_INVALID_VOL_PARAM -1
 #define SHORT_HEADER_MODE -4
 
+#define WVGA_MAX_WIDTH 900
+#define WVGA_MAX_HEIGHT WVGA_MAX_WIDTH
 
 #define VISUAL_OBJECT_SEQUENCE_START_CODE 	0x01B0
 #define VISUAL_OBJECT_SEQUENCE_END_CODE 	0x01B1
@@ -51,6 +56,7 @@
 #define H264_PROFILE_IDC_BASELINE 66
 #define H264_PROFILE_IDC_MAIN 77
 #define H264_PROFILE_IDC_EXTENDED 88
+#define H264_PROFILE_IDC_HIGH 100
 
 typedef struct
 {
@@ -115,7 +121,8 @@
 		int32 *, 
 		int32 *, 
 		int32 *profile, 
-		int32 *level);
+		int32 *level,
+		uint32 *entropy_coding_mode_flag);
 
 int32 FindNAL(uint8** nal_pnt, uint8* buffer, int32 length);
 int16 DecodeSPS(mp4StreamType *psBits, int32 *width, int32 *height, int32 *display_width, int32 *display_height, int32 *profile_idc, int32 *level_idc);
@@ -123,7 +130,7 @@
 int32 DecodeHRD(mp4StreamType *psBits);
 int32 DecodeVUI(mp4StreamType *psBits);
 #endif
-int32 DecodePPS(mp4StreamType *psBits);
+int32 DecodePPS(mp4StreamType *psBits, uint32 *entropy_coding_mode_flag);
 
 void ue_v(mp4StreamType *psBits, uint32 *codeNum);
 void se_v(mp4StreamType *psBits, int32 *value);
diff --git a/omx/ti_omx_config_parser/inc/ti_video_config_parser.h b/omx/ti_omx_config_parser/inc/ti_video_config_parser.h
index 0701014..5eec91a 100644
--- a/omx/ti_omx_config_parser/inc/ti_video_config_parser.h
+++ b/omx/ti_omx_config_parser/inc/ti_video_config_parser.h
@@ -23,10 +23,9 @@
 #include "pvmf_format_type.h"
 #include "oscl_stdstring.h"
 
-#define WVGA_MAX_WIDTH 864
+#define WVGA_MAX_WIDTH 900
 #define WVGA_MAX_HEIGHT WVGA_MAX_WIDTH
 #define TI_VID_DEC "OMX.TI.Video.Decoder"
-
 typedef struct
 {
     uint8 *inPtr;
@@ -43,9 +42,9 @@
 } tiVideoConfigParserOutputs;
 
 OSCL_IMPORT_REF int16 ti_video_config_parser(
-	tiVideoConfigParserInputs *aInputs, 
-	tiVideoConfigParserOutputs *aOutputs,
-    char * pComponentName);
+        tiVideoConfigParserInputs *aInputs,
+        tiVideoConfigParserOutputs *aOutputs,
+        char * pComponentName);
 
 #endif //TI_VIDEO_CONFIG_PARSER_H_INCLUDED
 
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 a06f59c..234a6cc 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,23 +99,6 @@
     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;
@@ -170,12 +153,7 @@
 
 
         ReadBits(psBits, 32, &codeword);
-        if (codeword != VISUAL_OBJECT_START_CODE)
-        {
-            if (SearchVOLHeader(psBits) != 0)
-                return MP4_INVALID_VOL_PARAM;
-            goto decode_vol;
-        }
+        if (codeword != VISUAL_OBJECT_START_CODE) return MP4_INVALID_VOL_PARAM;
 
         /*  is_visual_object_identifier            */
         ReadBits(psBits, 1, &codeword);
@@ -214,8 +192,17 @@
         }
         else
         {
-            if (SearchVOLHeader(psBits) != 0)
-                return MP4_INVALID_VOL_PARAM;
+            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));
             goto decode_vol;
         }
         /* next_start_code() */
@@ -249,8 +236,17 @@
             }
             else
             {
-                if (SearchVOLHeader(psBits) != 0)
-                    return MP4_INVALID_VOL_PARAM;
+                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));
                 goto decode_vol;
             }
         }
@@ -422,8 +418,19 @@
         }
         else
         {
-            if (SearchVOLHeader(psBits) != 0)
-                return MP4_INVALID_VOL_PARAM;
+            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));
             goto decode_vol;
         }
     }
@@ -787,7 +794,7 @@
 }
 
 
-OSCL_EXPORT_REF int16 iGetAVCConfigInfo(uint8 *buffer, int32 length, int32 *width, int32 *height, int32 *display_width, int32 *display_height, int32 *profile_idc, int32 *level_idc)
+OSCL_EXPORT_REF int16 iGetAVCConfigInfo(uint8 *buffer, int32 length, int32 *width, int32 *height, int32 *display_width, int32 *display_height, int32 *profile_idc, int32 *level_idc, uint32 *entropy_coding_mode_flag)
 {
     int16 status;
     mp4StreamType psBits;
@@ -896,13 +903,29 @@
     psBits.bytePos = 0;
     psBits.dataBitPos = 0;
 
-    status = DecodePPS(&psBits);
+    status = DecodePPS(&psBits, entropy_coding_mode_flag);
 
     OSCL_FREE(temp);
 
     return status;
 }
 
+void scaling_list_h264(int32 i4_list_size, mp4StreamType *psBits)
+{
+    int32 i4_j, i4_delta_scale, i4_lastScale = 8, i4_nextScale =8;
+
+
+    for(i4_j = 0; i4_j < i4_list_size; i4_j++)
+    {
+        if(i4_nextScale !=0)
+        {
+             se_v(psBits, &i4_delta_scale);
+            i4_nextScale = ((i4_lastScale + i4_delta_scale + 256) & 0xff);
+
+        }
+        i4_lastScale  = (i4_nextScale == 0)? (i4_lastScale) : (i4_nextScale);
+    }
+}
 
 int16 DecodeSPS(mp4StreamType *psBits, int32 *width, int32 *height, int32 *display_width, int32 *display_height, int32 *profile_idc, int32 *level_idc)
 {
@@ -910,20 +933,16 @@
     int32 temp0;
     uint left_offset, right_offset, top_offset, bottom_offset;
     uint i;
+    c_bool highProfileDetected = false;
 
     ReadBits(psBits, 8, &temp);
 
-
-
     if ((temp & 0x1F) != 7) return MP4_INVALID_VOL_PARAM;
 
     ReadBits(psBits, 8, &temp);
 
     *profile_idc = temp;
 
-    if(*profile_idc != H264_PROFILE_IDC_BASELINE)
-        return MP4_INVALID_VOL_PARAM;
-
     ReadBits(psBits, 1, &temp);
     ReadBits(psBits, 1, &temp);
     ReadBits(psBits, 1, &temp);
@@ -936,6 +955,75 @@
         return MP4_INVALID_VOL_PARAM;
 
     ue_v(psBits, &temp);
+
+    if(*profile_idc == H264_PROFILE_IDC_HIGH)
+    {
+        /* High Profile detected; additional parameters to be parsed */
+        uint32 i4_chroma_format_idc, i4_bit_depth_luma_minus8, i4_bit_depth_chroma_minus8;
+        uint32 i4_seq_scaling_matrix_present_flag, i4_qpprime_y_zero_transform_bypass_flag;
+
+        highProfileDetected = true;
+
+        /* reading chroma_format_idc   */
+        ue_v(psBits, &i4_chroma_format_idc);
+
+        if(i4_chroma_format_idc != 1 )
+        {
+            /* chroma_format_idc 1 represents 420. Other possibility is monochrome, not supported currently */
+            return (-1);
+        }
+
+        /* reading bit_depth_luma_minus8   */
+        ue_v(psBits, &i4_bit_depth_luma_minus8);
+
+        if(i4_bit_depth_luma_minus8 != 0)
+        {
+            /* only 8 bit supported, higher bit depth not supported */
+            return (-1);
+        }
+
+        /* reading bit_depth_chroma_minus8   */
+        ue_v(psBits, &i4_bit_depth_chroma_minus8);
+
+        if(i4_bit_depth_chroma_minus8 != 0)
+        {
+            /* only 8 bit supported, higher bit depth not supported */
+            return (-1);
+        }
+
+        /* reading qpprime_y_zero_transform_bypass_flag   */
+        ReadBits(psBits, 1, &i4_qpprime_y_zero_transform_bypass_flag);
+        if(i4_qpprime_y_zero_transform_bypass_flag != 0)
+        {
+            return (-1);
+        }
+
+        /* reading seq_scaling_matrix_present_flag   */
+        ReadBits(psBits, 1, &i4_seq_scaling_matrix_present_flag);
+
+        if(i4_seq_scaling_matrix_present_flag)
+        {
+            int32 i4_i;
+            for(i4_i =0; i4_i < 8; i4_i++)
+            {
+                uint32 i4_scaling_list_present;
+                ReadBits(psBits, 1, &i4_scaling_list_present);
+
+                if(i4_scaling_list_present)
+                {
+                    if(i4_i < 6)
+                    {
+                        scaling_list_h264(16, psBits);
+                    }
+                    else
+                    {
+                        scaling_list_h264(64, psBits);
+                    }
+                }
+            }
+        }
+    }
+
     ue_v(psBits, &temp);
     ue_v(psBits, &temp);
 
@@ -964,7 +1052,6 @@
     ue_v(psBits, &temp);
     *display_height = *height = (temp + 1) << 4;
 
-
     ReadBits(psBits, 1, &temp);
     if (!temp)
     {
@@ -1127,9 +1214,9 @@
 #endif
 
 // only check for entropy coding mode
-int32 DecodePPS(mp4StreamType *psBits)
+int32 DecodePPS(mp4StreamType *psBits, uint32 *entropy_coding_mode_flag)
 {
-    uint32 temp, pic_parameter_set_id, seq_parameter_set_id, entropy_coding_mode_flag;
+    uint32 temp, pic_parameter_set_id, seq_parameter_set_id;
 
     ReadBits(psBits, 8, &temp);
 
@@ -1138,11 +1225,7 @@
     ue_v(psBits, &pic_parameter_set_id);
     ue_v(psBits, &seq_parameter_set_id);
 
-    ReadBits(psBits, 1, &entropy_coding_mode_flag);
-    if (entropy_coding_mode_flag)
-    {
-        return 1;
-    }
+    ReadBits(psBits, 1, entropy_coding_mode_flag);
 
     return 0;
 }
diff --git a/omx/ti_omx_config_parser/src/ti_omx_config_parser.cpp b/omx/ti_omx_config_parser/src/ti_omx_config_parser.cpp
index b5523b9..2c6bb7a 100644
--- a/omx/ti_omx_config_parser/src/ti_omx_config_parser.cpp
+++ b/omx/ti_omx_config_parser/src/ti_omx_config_parser.cpp
@@ -61,10 +61,8 @@
 
 {
     OMXConfigParserInputs* pInputs;
-
     pInputs = (OMXConfigParserInputs*) aInputParameters;
 
-
     if (NULL != pInputs->cComponentRole)
     {
         if (0 == oscl_strncmp(pInputs->cComponentRole, (OMX_STRING)"audio_decoder", oscl_strlen("audio_decoder")))
diff --git a/omx/ti_omx_config_parser/src/ti_video_config_parser.cpp b/omx/ti_omx_config_parser/src/ti_video_config_parser.cpp
index 0e1aa1d..fba2252 100644
--- a/omx/ti_omx_config_parser/src/ti_video_config_parser.cpp
+++ b/omx/ti_omx_config_parser/src/ti_video_config_parser.cpp
@@ -63,7 +63,7 @@
 
 int32 GetNAL_Config(uint8** bitstream, int32* size);
 
-OSCL_EXPORT_REF int16 ti_video_config_parser(tiVideoConfigParserInputs *aInputs, tiVideoConfigParserOutputs *aOutputs, char *pComponentName)
+OSCL_EXPORT_REF int16 ti_video_config_parser(tiVideoConfigParserInputs *aInputs, tiVideoConfigParserOutputs *aOutputs, char* pComponentName)
 {
     if (aInputs->iMimeType == PVMF_MIME_M4V) //m4v
     {
@@ -91,13 +91,7 @@
         aOutputs->height = (uint32)display_height;
         aOutputs->profile = (uint32)profile_level; // for mp4, profile/level info is packed
         aOutputs->level = 0;
-        /* TI Video Decoder supports up to WVGA 864x480 resolutions, PV should
-         * use another component to render higher resolutions */
-        if ((width  > WVGA_MAX_WIDTH || height > WVGA_MAX_HEIGHT) && 0 == oscl_strncmp (pComponentName, TI_VID_DEC, oscl_strlen (TI_VID_DEC)))
-        {
-            return -1;
 
-        }
     }
     else if (aInputs->iMimeType == PVMF_MIME_H2631998 ||
              aInputs->iMimeType == PVMF_MIME_H2632000)//h263
@@ -113,6 +107,7 @@
     {
         int32 width, height, display_width, display_height = 0;
         int32 profile_idc, level_idc = 0;
+        uint32 entropy_coding_mode_flag = 0;
 
         uint8 *tp = aInputs->inPtr;
 
@@ -149,7 +144,8 @@
                                    (int*) & display_width,
                                    (int*) & display_height,
                                    (int*) & profile_idc,
-                                   (int*) & level_idc);
+                                   (int*) & level_idc,
+                                   (uint*) & entropy_coding_mode_flag);
         if (retval != 0)
         {
             return retval;
@@ -158,6 +154,19 @@
         aOutputs->height = (uint32)display_height;
         aOutputs->profile = (uint32)profile_idc;
         aOutputs->level = (uint32) level_idc;
+
+        /*When 720p and other profiles may be handled by other Video Decoder OMX Component,
+          this will let PV know that it will need to load other compponent*/
+        if ( 0 == oscl_strncmp (pComponentName, TI_VID_DEC, oscl_strlen (TI_VID_DEC)) )
+        {
+            if( ((width > WVGA_MAX_WIDTH) || (height > WVGA_MAX_HEIGHT)) ||
+                (profile_idc != H264_PROFILE_IDC_BASELINE) ||
+                entropy_coding_mode_flag )
+            {
+                return -1;
+            }
+        }
+
     }
     else if (aInputs->iMimeType == PVMF_MIME_WMV) //wmv
     {
diff --git a/omx/video/src/openmax_il/prepost_processor/Android.mk b/omx/video/src/openmax_il/prepost_processor/Android.mk
index d8293e9..a970ebd 100755
--- a/omx/video/src/openmax_il/prepost_processor/Android.mk
+++ b/omx/video/src/openmax_il/prepost_processor/Android.mk
@@ -40,7 +40,7 @@
 ifeq ($(BUILD_VPP_TEST),1)
 include $(CLEAR_VARS)
 
-LOCAL_SRC_FILES:=
+LOCAL_SRC_FILES:= tests/VPPTest.c
 
 LOCAL_C_INCLUDES := $(TI_OMX_COMP_C_INCLUDES) \
 	$(TI_OMX_VIDEO)/prepost_processor/inc \
diff --git a/omx/video/src/openmax_il/prepost_processor/src/OMX_VPP_Utils.c b/omx/video/src/openmax_il/prepost_processor/src/OMX_VPP_Utils.c
index 5963875..1e87a86 100755
--- a/omx/video/src/openmax_il/prepost_processor/src/OMX_VPP_Utils.c
+++ b/omx/video/src/openmax_il/prepost_processor/src/OMX_VPP_Utils.c
@@ -3591,18 +3591,20 @@
 void LinkedList_AddElement(LinkedList *LinkedList, void *pValue) {

     /* create new node and fill the value */

     Node *pNewNode = (Node *)malloc(sizeof(Node));

-    pNewNode->pValue = (void *)pValue;

-    /*printf("LinkedList:::: Pointer=%p has been added.\n", pNewNode->pValue); */

-    /* add new node on the root to implement quick FIFO */

-    /* modify new node pointers */

-    if(LinkedList->pRoot == NULL) {

-        pNewNode->pNextNode = NULL;

+    if (pNewNode != NULL) {

+        pNewNode->pValue = (void *)pValue;

+        /*printf("LinkedList:::: Pointer=%p has been added.\n", pNewNode->pValue); */

+        /* add new node on the root to implement quick FIFO */

+        /* modify new node pointers */

+        if (LinkedList->pRoot == NULL) {

+            pNewNode->pNextNode = NULL;

+        }

+        else {

+             pNewNode->pNextNode = LinkedList->pRoot;

+        }   

+        /*modify root */

+        LinkedList->pRoot = pNewNode;

     }

-    else {

-         pNewNode->pNextNode = LinkedList->pRoot;

-    }

-    /*modify root */

-    LinkedList->pRoot = pNewNode;

 }

 

 void LinkedList_FreeElement(LinkedList *LinkedList, void *pValue) {

diff --git a/omx/video/src/openmax_il/prepost_processor/tests/VPPTest.c b/omx/video/src/openmax_il/prepost_processor/tests/VPPTest.c
index 7924e1c..32aa165 100755
--- a/omx/video/src/openmax_il/prepost_processor/tests/VPPTest.c
+++ b/omx/video/src/openmax_il/prepost_processor/tests/VPPTest.c
@@ -868,15 +868,15 @@
         LoadBaseImage();
 #endif
 
-    error = OMX_Init();
+    error = TIOMX_Init();
     if(error != OMX_ErrorNone) {
-        printf("%d :: Error returned by OMX_Init()\n",__LINE__);
+        printf("%d :: Error returned by TIOMX_init()\n",__LINE__);
         goto EXIT;
     }
 
 /********************************************************************************************************/
     /* Load the VPP Component */
-    error = OMX_GetHandle(&pHandle,strAmrDecoder,&AppData, &AmrCaBa);
+    error = TIOMX_GetHandle(&pHandle,strAmrDecoder,&AppData, &AmrCaBa);
     if( (error != OMX_ErrorNone) || (pHandle == NULL) ){
         fprintf (stderr,"Error in Get Handle function\n");
         goto EXIT;
@@ -2007,7 +2007,7 @@
 EXIT:
     
     printf ("VPPTEST:: Free the Component handle\n"); 
-    error = OMX_FreeHandle(pHandle);
+    error = TIOMX_FreeHandle(pHandle);
     if( (error != OMX_ErrorNone)) {
         fprintf (stderr,"Error in Free Handle function\n");
         goto EXIT;
@@ -2022,7 +2022,7 @@
 
     
         /* De-Initialize OMX Core */
-    error = OMX_Deinit();
+    error = TIOMX_Deinit();
     if (error != OMX_ErrorNone) {
         printf("VPPTEST:: Failed to de-init OMX Core!\n");
         goto EXIT;
diff --git a/omx/video/src/openmax_il/video_decode/Android.mk b/omx/video/src/openmax_il/video_decode/Android.mk
index dab46c3..ddcca85 100644
--- a/omx/video/src/openmax_il/video_decode/Android.mk
+++ b/omx/video/src/openmax_il/video_decode/Android.mk
@@ -11,6 +11,7 @@
 
 LOCAL_C_INCLUDES := $(TI_OMX_COMP_C_INCLUDES) \
 	$(TI_OMX_VIDEO)/video_decode/inc \
+	
 
 ifeq ($(PERF_INSTRUMENTATION),1)
 LOCAL_C_INCLUDES += \
diff --git a/omx/video/src/openmax_il/video_decode/inc/OMX_VideoDec_DSP.h b/omx/video/src/openmax_il/video_decode/inc/OMX_VideoDec_DSP.h
index 53b786c..e00051a 100644
--- a/omx/video/src/openmax_il/video_decode/inc/OMX_VideoDec_DSP.h
+++ b/omx/video/src/openmax_il/video_decode/inc/OMX_VideoDec_DSP.h
@@ -42,12 +42,12 @@
 #ifndef OMX_VIDDEC_DSP__H
 #define OMX_VIDDEC_DSP__H
 
-#define OMX_H264DEC_NUM_DLLS 4 
-#define OMX_MP4DEC_NUM_DLLS  4 
+#define OMX_H264DEC_NUM_DLLS 5
+#define OMX_MP4DEC_NUM_DLLS  5
 #define OMX_MP2DEC_NUM_DLLS  4 
-#define OMX_WMVDEC_NUM_DLLS  4 
+#define OMX_WMVDEC_NUM_DLLS  5
  #ifdef VIDDEC_SPARK_CODE
-    #define OMX_SPARKDEC_NUM_DLLS  4 
+    #define OMX_SPARKDEC_NUM_DLLS  5
  #endif
 
 #ifndef VIDDEC_SN_R8_14
@@ -62,6 +62,7 @@
     #define WMV_DEC_NODE_DLL   "wmv9dec_sn.dll64P"
     #define RINGIO_NODE_DLL    "ringio.dll64P"
     #define USN_DLL            "usn.dll64P"
+    #define CONVERSIONS_DLL    "conversions.dll64P"
  #ifdef VIDDEC_SPARK_CODE
     #define SPARK_DEC_NODE_DLL  "sparkdec_sn.dll64P"
  #endif
@@ -72,6 +73,7 @@
     #define WMV_DEC_NODE_DLL  "\\windows\\wmv9dec_sn.dll64P"
     #define RINGIO_NODE_DLL   "\\windows\\ringio.dll64P"
     #define USN_DLL           "\\windows\\usn.dll64P"
+    #define CONVERSIONS_DLL   "\\windows\\conversions.dll64P"
  #ifdef VIDDEC_SPARK_CODE
     #define SPARK_DEC_NODE_DLL "\\windows\\sparkdec_sn.dll64P" 
  #endif
@@ -128,6 +130,12 @@
     }
 };
 
+static const struct DSP_UUID CONVERSIONS_UUID = {
+            0x722DD0DA, 0xF532, 0x4238, 0xB8, 0x46, {
+                        0xAB, 0xFF, 0x5D, 0xA4, 0xBA, 0x02
+            }
+};
+
 #ifdef VIDDEC_SPARK_CODE 
     #define STRING_SPARKDSOCKET_TI_UUID "DD8AC7F0_33BF_446B_938E_FDF00B467ED6"
     static const struct DSP_UUID SPARKDSOCKET_TI_UUID = {
@@ -154,11 +162,12 @@
     OMX_U32 ulMaxFrameRate;
     OMX_U32 ulMaxBitRate;
     OMX_U32 ulDataEndianness;
-    OMX_U32 ulProfile;
+    OMX_S32 ulProfile;
     OMX_S32 ulMaxLevel;
     OMX_U32 ulProcessMode;
     OMX_S32 lPreRollBufConfig;
-    OMX_S16 usIsElementaryStream;
+    OMX_U32 usIsElementaryStream;
+    OMX_U32 bCopiedCCDBuffer;
     OMX_U16 endArgs;
 } WMV9DEC_SNCreatePhArg;
 
@@ -283,7 +292,9 @@
 
 typedef struct
 {
-    long int nBuffCount;
+    OMX_S32 nBuffCount;
+    OMX_U32 uRingIOBlocksize;
+    OMX_S32 nPerformMode;
 } MP4VD_GPP_SN_UALGInputParams;
 
 typedef struct
@@ -594,7 +605,8 @@
   OMX_U32         ulDecodeHeader;    
   OMX_U32         ulDisplayWidth;  
   OMX_U32         ulFrameSkipMode; 
-  OMX_U32        ulPPType;
+  OMX_U32         ulPPType;
+  OMX_BOOL        useHighPrecIdctQp1;
 }MP4VDEC_UALGDynamicParams;
 
 #ifdef VIDDEC_SPARK_CODE 
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 be41808..dd511f4 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
@@ -23,7 +23,6 @@
 
 #define newmalloc(x) malloc(x)
 #define newfree(z) free(z)
-
 #ifdef ANDROID
 /* Log for Android system*/
 #include <utils/Log.h>
@@ -269,7 +268,6 @@
 #define VIDDEC_DEFAULT_MPEG2_BFRAMES                VIDDEC_MINUS
 #define VIDDEC_DEFAULT_MPEG2_PROFILE                OMX_VIDEO_MPEG2ProfileSimple
 #define VIDDEC_DEFAULT_MPEG2_LEVEL                  OMX_VIDEO_MPEG2LevelLL
-
 #define VIDDEC_DEFAULT_H264_PORTINDEX                 VIDDEC_INPUT_PORT
 #define VIDDEC_DEFAULT_H264_SLICEHEADERSPACING        VIDDEC_ZERO
 #define VIDDEC_DEFAULT_H264_PFRAMES                   VIDDEC_MINUS
@@ -315,6 +313,7 @@
 
 #define VIDDEC_PADDING_FULL                           256
 #define VIDDEC_PADDING_HALF                           VIDDEC_PADDING_FULL / 2
+
 #define VIDDEC_ALIGNMENT                              4
 
 #define VIDDEC_CLEARFLAGS                             0
@@ -362,8 +361,14 @@
 #define VIDDEC_VGA_WIDTH                              640
 #define VIDDEC_VGA_HEIGHT                             480
 
-#define VIDDEC_D1MAX_WIDTH                            720
-#define VIDDEC_D1MAX_HEIGHT                           576
+#define VIDDEC_D1MAX_WIDTH                            864
+#define VIDDEC_D1MAX_HEIGHT                           VIDDEC_D1MAX_WIDTH
+
+/* In the current release the suport for : VIDDEC_MAX_FRAMERATE  & VIDDEC_MAX_BITRATE
+ * is not provided by the algorithm. But is require to set this field to a non-zero value */
+#define VIDDEC_MAX_FRAMERATE                        30000  /* Max frame rate to be suported * 1000 */
+#define VIDDEC_MAX_BITRATE                        8000000  /* Max bit rate (in bits per second) to be suported */
+
 #define VIDDEC_WMV_PROFILE_ID0                          0
 #define VIDDEC_WMV_PROFILE_ID1                          1
 #define VIDDEC_WMV_PROFILE_ID2                          2
@@ -571,7 +576,7 @@
     OMX_PTR Elements;
     OMX_U32 CounterElements[VIDDEC_MAX_QUEUE_SIZE];
     OMX_U32 nHead;
-    OMX_U32 nTail;
+    OMX_S32 nTail;
     OMX_U32 nElements;
     OMX_U32 nErrorCount;
     pthread_mutex_t mMutex;
@@ -864,6 +869,7 @@
     OMX_PORT_PARAM_TYPE* pPortParamTypeAudio;
     OMX_PORT_PARAM_TYPE* pPortParamTypeImage;
     OMX_PORT_PARAM_TYPE* pPortParamTypeOthers;
+
 #endif
     OMX_CALLBACKTYPE cbInfo;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef[NUM_OF_PORTS];
@@ -929,6 +935,7 @@
 
     OMX_STATETYPE eIdleToLoad;
     OMX_STATETYPE eExecuteToIdle;
+    OMX_BOOL iEndofInputSent;
     OMX_BOOL bPipeCleaned;
     OMX_BOOL bFirstBuffer;
 
@@ -949,10 +956,10 @@
 #endif
     VIDDEC_RMPROXY_STATES eRMProxyState;
 
-    volatile int32_t nInputBCountDsp;
-    volatile int32_t nOutputBCountDsp;
-    volatile int32_t nInputBCountApp;
-    volatile int32_t nOutputBCountApp;
+    OMX_U8 nCountInputBFromDsp;
+    OMX_U8 nCountOutputBFromDsp;
+    OMX_U8 nCountInputBFromApp;
+    OMX_U8 nCountOutputBFromApp;
 
     VIDDEC_CBUFFER_BUFFERFLAGS aBufferFlags[CBUFFER_SIZE];
     VIDDEC_LCML_STATES eLCMLState;
@@ -962,6 +969,10 @@
     OMX_BOOL bIsSparkInput;
 #endif
     VIDDEC_MUTEX sMutex;
+    pthread_mutex_t mutexInputBFromApp;
+    pthread_mutex_t mutexOutputBFromApp;
+    pthread_mutex_t mutexInputBFromDSP;
+    pthread_mutex_t mutexOutputBFromDSP;
     VIDDEC_MUTEX sDynConfigMutex;
     VIDDEC_SEMAPHORE sInSemaphore;
     VIDDEC_SEMAPHORE sOutSemaphore;
@@ -1008,6 +1019,22 @@
 } VIDDEC_COMPONENT_PRIVATE;
 
 /*****************macro definitions*********************/
+/*----------------------------------------------------------------------------*/
+/**
+  * OMX_GET_DATABUFF_SIZE() Get the needed buffer data size base in the request.
+  *
+  * This method will give the needed data buffer size acording with
+  * specific requirements from the codec and component.
+  *
+  * @param _nSizeBytes_     Requested size from client
+  *
+  **/
+/*----------------------------------------------------------------------------*/
+
+#define OMX_GET_DATABUFF_SIZE(_nSizeBytes_)                         \
+         (_nSizeBytes_ + VIDDEC_PADDING_FULL + VIDDEC_WMV_BUFFER_OFFSET + VIDDEC_ALIGNMENT)
+
+
 #define OMX_MALLOC_STRUCT(_pStruct_, _sName_, _memusage_)           \
     _pStruct_ = (_sName_*)malloc(sizeof(_sName_));                  \
     if(_pStruct_ == NULL){                                          \
@@ -1035,35 +1062,24 @@
     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
+  * @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)));
+#define OMX_ALIGN_BUFFER(_pBuffer_, _nBytes_)                  \
+    while((OMX_U8)_pBuffer_ & (_nBytes_-1)){                   \
+       _pBuffer_++;                                            \
+    }
 
-/*----------------------------------------------------------------------------*/
-/**
-  * 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]);			\
@@ -1074,11 +1090,11 @@
 
 /*----------------------------------------------------------------------------*/
 /**
-  * OMX_FREE_VIDDEC() Free memory
+  * OMX_FREE() Free memory
   *
   * This method will free memory and set pointer to NULL
   *
-  * @param _pBuffer_	    Pointer to free
+  * @param _pBuffer_     Pointer to free
   *
   **/
 /*----------------------------------------------------------------------------*/
@@ -1127,9 +1143,6 @@
         OMX_PRBUFFER1(pComponentPrivate->dbg, "Free original allocated buffer: %p\n", _pBuffHead_->pBuffer);	\
         OMX_FREE_VIDDEC(_pBuffHead_->pBuffer);							    \
     }
-
-
-
 /*----------------------------------------------------------------------------*/
 /**
   * OMX_WMV_INSERT_CODEC_DATA()
@@ -1137,39 +1150,41 @@
   * This method will insert the codec data to the first frame to be sent to
   * queue in LCML
   *
-  * @param _pBuffHead_	    Buffer header pointer
+  * @param _pBuffHead_    Pointer to free
   * @param _pComponentPrivate_  Component private structure to provide needed
-  *				references
+  *                             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*/							\
+#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;		\
+                             \
+        _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_);              \
@@ -1405,7 +1420,7 @@
 OMX_ERRORTYPE VIDDEC_UnloadCodec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
 OMX_ERRORTYPE VIDDEC_LoadCodec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
 OMX_ERRORTYPE VIDDEC_Set_SN_StreamType(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
-OMX_ERRORTYPE VIDDEC_Set_Debocking(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
+OMX_ERRORTYPE VIDDEC_SetMpeg4_Parameters(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
 
 #ifdef VIDDEC_ACTIVATEPARSER
 OMX_ERRORTYPE VIDDEC_ParseVideo_WMV9_VC1( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead);
@@ -1418,9 +1433,10 @@
 OMX_ERRORTYPE VIDDEC_ParseVideo_MPEG2( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead);
 OMX_U32 VIDDEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition);
 OMX_S32 VIDDEC_UVLC_dec(OMX_U32 *nPosition, OMX_U8* pBuffer);
-
 OMX_ERRORTYPE AddStateTransition(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
 OMX_ERRORTYPE RemoveStateTransition(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BOOL bEnableSignal);
+OMX_ERRORTYPE IncrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex);
+OMX_ERRORTYPE DecrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex);
 
 #endif
 #endif
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 92c7cd4..a1ccc00 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,7 +72,6 @@
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include <cutils/atomic.h>
 
 #include "OMX_VideoDecoder.h"
 #include "OMX_VideoDec_Utils.h"
@@ -191,7 +190,7 @@
                                                    OMX_ErrorInsufficientResources, 
                                                    OMX_TI_ErrorSevere,
                                                    "Error from Component Thread in select");
-            eError = OMX_ErrorInsufficientResources;
+	     eError = OMX_ErrorInsufficientResources;
             break;
         }
         else {
@@ -292,7 +291,6 @@
                                                                OMX_TI_ErrorSevere,
                                                                "Error from Component Thread while processing dsp Responses");
                     }
-                    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);
@@ -313,7 +311,6 @@
                                                                OMX_TI_ErrorSevere,
                                                                "Error from Component Thread while processing input buffer");
                     }
-                    android_atomic_dec(&pComponentPrivate->nInputBCountApp);
                 }
                 }
                 if (FD_ISSET(pComponentPrivate->free_inpBuf_Q[VIDDEC_PIPE_READ], &rfds)) {
@@ -331,7 +328,6 @@
                                                                OMX_TI_ErrorSevere,
                                                                "Error from Component Thread while processing free input buffer");
                     }
-                    android_atomic_dec(&pComponentPrivate->nInputBCountDsp);
                 }
                 if (FD_ISSET(pComponentPrivate->free_outBuf_Q[VIDDEC_PIPE_READ], &rfds)) {
                      if(pComponentPrivate->bDynamicConfigurationInProgress){
@@ -349,7 +345,6 @@
                                                                OMX_TI_ErrorSevere,
                                                                "Error from Component Thread while processing free output buffer");
                     }
-                    android_atomic_dec(&pComponentPrivate->nOutputBCountApp);
                 }
             }
         }
@@ -359,7 +354,7 @@
     PERF_Done(pComponentPrivate->pPERFcomp);
 #endif
 
-    return (void*)eError;
+    return (void *)eError;
 }
 
 void* OMX_VidDec_Return (void* pThreadData)
@@ -394,10 +389,10 @@
     if (pComponentPrivate->filled_outBuf_Q[VIDDEC_PIPE_READ] > fdmax) {
         fdmax = pComponentPrivate->filled_outBuf_Q[VIDDEC_PIPE_READ];
     }
-    while ((pComponentPrivate->nInputBCountApp != 0 && 
-                (pComponentPrivate->eLCMLState == VidDec_LCML_State_Start && pComponentPrivate->bDynamicConfigurationInProgress == OMX_FALSE)) || 
-            pComponentPrivate->nOutputBCountApp != 0 ||
-            pComponentPrivate->nInputBCountDsp != 0 || pComponentPrivate->nOutputBCountDsp != 0) {
+    while ((pComponentPrivate->nCountInputBFromApp != 0 &&
+                (pComponentPrivate->eLCMLState == VidDec_LCML_State_Start && pComponentPrivate->bDynamicConfigurationInProgress == OMX_FALSE)) ||
+            pComponentPrivate->nCountOutputBFromApp != 0 ||
+            pComponentPrivate->nCountInputBFromDsp != 0 || pComponentPrivate->nCountOutputBFromDsp != 0) {
         FD_ZERO (&rfds);
         FD_SET(pComponentPrivate->filled_outBuf_Q[VIDDEC_PIPE_READ], &rfds);
         FD_SET(pComponentPrivate->free_inpBuf_Q[VIDDEC_PIPE_READ], &rfds);
@@ -436,8 +431,8 @@
                                                    OMX_ErrorInsufficientResources, 
                                                    OMX_TI_ErrorSevere,
                                                    "Error from Component Thread in select");
-            eError = OMX_ErrorInsufficientResources;
-            break;
+	     eError = OMX_ErrorInsufficientResources;
+	     break;
         } 
         else {
             if (FD_ISSET(pComponentPrivate->filled_outBuf_Q[VIDDEC_PIPE_READ], &rfds)) {
@@ -451,7 +446,6 @@
                                                            OMX_TI_ErrorSevere,
                                                            "Error from Component Thread while processing dsp Responses");
                 }
-                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);
@@ -466,7 +460,6 @@
                                                            OMX_TI_ErrorSevere,
                                                            "Error from Component Thread while processing input buffer");
                 }
-                android_atomic_dec(&pComponentPrivate->nInputBCountApp);
                 }
             }
             if (FD_ISSET(pComponentPrivate->free_inpBuf_Q[VIDDEC_PIPE_READ], &rfds)) {
@@ -480,7 +473,6 @@
                                                            OMX_TI_ErrorSevere,
                                                            "Error from Component Thread while processing free input buffer");
                 }
-                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);
@@ -494,12 +486,11 @@
                                                            OMX_TI_ErrorSevere,
                                                            "Error from Component Thread while processing free output buffer");
                 }
-                android_atomic_dec(&pComponentPrivate->nOutputBCountApp);
             }
         }
     }
     
     pComponentPrivate->bPipeCleaned = OMX_TRUE;
-    return (void*)eError;
+    return (void *)eError;
 }
 
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 ece2bf7..220bf9b 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
@@ -54,6 +54,7 @@
 #include "OMX_VideoDec_Utils.h"
 #include "OMX_VideoDec_DSP.h"
 #include "OMX_VideoDec_Thread.h"
+#define LOG_TAG "TI_Video_Decoder"
 /*----------------------------------------------------------------------------*/
 /**
   * VIDDEC_GetRMFrecuency() Return the value for frecuecny to use RM.
@@ -1144,10 +1145,11 @@
             pComponentPrivate->bIsStopping                      = 0;
             pComponentPrivate->bFirstBuffer                     = 1;
             pComponentPrivate->eIdleToLoad                      = OMX_StateInvalid;
-            pComponentPrivate->nInputBCountDsp                  = 0;
-            pComponentPrivate->nOutputBCountDsp                 = 0;
-            pComponentPrivate->nInputBCountApp                  = 0;
-            pComponentPrivate->nOutputBCountApp                 = 0;
+            pComponentPrivate->iEndofInputSent                  = 0;
+            pComponentPrivate->nCountInputBFromDsp                  = 0;
+            pComponentPrivate->nCountOutputBFromDsp                 = 0;
+            pComponentPrivate->nCountInputBFromApp                  = 0;
+            pComponentPrivate->nCountOutputBFromApp                 = 0;
             pComponentPrivate->frameCounter                     = 0;
             pComponentPrivate->bMult16Size                      = OMX_FALSE;
             pComponentPrivate->bFlushOut                        = OMX_FALSE;
@@ -1174,10 +1176,11 @@
             pComponentPrivate->bIsPaused                        = 0;
             pComponentPrivate->bIsStopping                      = 0;
             pComponentPrivate->bFirstBuffer                     = 1;
-            pComponentPrivate->nInputBCountDsp                  = 0;
-            pComponentPrivate->nOutputBCountDsp                 = 0;
-            pComponentPrivate->nInputBCountApp                  = 0;
-            pComponentPrivate->nOutputBCountApp                 = 0;
+            pComponentPrivate->iEndofInputSent                  = 0;
+            pComponentPrivate->nCountInputBFromDsp                  = 0;
+            pComponentPrivate->nCountOutputBFromDsp                 = 0;
+            pComponentPrivate->nCountInputBFromApp                  = 0;
+            pComponentPrivate->nCountOutputBFromApp                 = 0;
             pComponentPrivate->frameCounter                     = 0;
             pComponentPrivate->bMult16Size                      = OMX_FALSE;
             pComponentPrivate->bFlushOut                        = OMX_FALSE;
@@ -1821,7 +1824,6 @@
                 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,
@@ -1917,6 +1919,9 @@
     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__
@@ -1961,6 +1966,9 @@
                 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__
@@ -1969,6 +1977,7 @@
                                               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 = VIDDEC_FillBufferDone(pComponentPrivate, pBuffHead);
@@ -2269,7 +2278,6 @@
         }
     }
 EXIT:
-
     OMX_PRINT1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError);
     return eError;
 
@@ -2325,6 +2333,7 @@
 #else
    void* pMyLCML;
    VIDDEC_fpo fpGetHandle;
+   char* error;
 #endif
 
     OMX_PRINT1(pComponentPrivate->dbg, "+++ENTERING\n");
@@ -2422,9 +2431,9 @@
                     goto EXIT;
                 }
                 fpGetHandle = dlsym(pMyLCML, "GetHandle");
-                if (!fpGetHandle) {
+                if ((error = dlerror()) != NULL) {
                     OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n");
-                    fputs(dlerror(), stderr);
+                    fputs(error, stderr);
                     dlclose(pMyLCML);
                     pMyLCML = NULL;
                     eError = OMX_ErrorBadParameter;
@@ -2674,10 +2683,10 @@
                 pComponentPrivate->eState = OMX_StateIdle;
                 pComponentPrivate->bIsPaused = 0;
 
-               /* Decrement reference count with signal enabled */
-               if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
-                     return OMX_ErrorUndefined;
-               }
+                /* Decrement reference count with signal enabled */
+                if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
+                      return OMX_ErrorUndefined;
+                }
 
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
@@ -2691,7 +2700,7 @@
             else if (pComponentPrivate->eState == OMX_StateExecuting || pComponentPrivate->eState == OMX_StatePause) {
                 /*Set the bIsStopping bit*/
                 if (pComponentPrivate->bDynamicConfigurationInProgress == OMX_TRUE) {
-                    pComponentPrivate->bDynamicConfigurationInProgress = OMX_FALSE;
+	            pComponentPrivate->bDynamicConfigurationInProgress = OMX_FALSE;
                     OMX_PRSTATE1(pComponentPrivate->dbg, "We were doing DynamicConfiguration, canceling it. %d \n",pComponentPrivate->bDynamicConfigurationInProgress);
                 }
                 pComponentPrivate->bIsStopping = 1;
@@ -2705,6 +2714,7 @@
                               PERF_BoundaryComplete | PERF_BoundarySteadyState);
 #endif
                     pComponentPrivate->bIsPaused = 0;
+                    pComponentPrivate->iEndofInputSent = 0;
 /********************************************************************************************************************/
            if (pComponentPrivate->bIsStopping == OMX_TRUE) {
                 pComponentPrivate->bIsPaused = OMX_FALSE;
@@ -2758,11 +2768,10 @@
 
                 pComponentPrivate->bIsStopping = OMX_FALSE;
                 pComponentPrivate->eState = OMX_StateIdle;
-               /* Decrement reference count with signal enabled */
-               if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
-                     return OMX_ErrorUndefined;
-               }
-
+                /* Decrement reference count with signal enabled */
+                if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
+                      return OMX_ErrorUndefined;
+                }
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -3041,7 +3050,7 @@
 #endif
                 else {
                     if(pComponentPrivate->eState == OMX_StateIdle) {
-                        eError = VIDDEC_Set_Debocking(pComponentPrivate);
+                        eError = VIDDEC_SetMpeg4_Parameters(pComponentPrivate);
                         if (eError != OMX_ErrorNone){
                             goto EXIT;
                         }
@@ -3101,12 +3110,12 @@
 
                 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) {
-                     return OMX_ErrorUndefined;
-               }
-
+                /* Decrement reference count with signal enabled */
+                if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
+                      return OMX_ErrorUndefined;
+                }
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -3248,12 +3257,10 @@
                             eError = OMX_ErrorNone;
                             pComponentPrivate->bIsPaused = 0;
                             pComponentPrivate->eState = OMX_StateLoaded;
-
-                           /* Decrement reference count with signal enabled */
-                           if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
-                               return OMX_ErrorUndefined;
-                           }
-
+                            /* Decrement reference count with signal enabled */
+                            if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
+                                return OMX_ErrorUndefined;
+                            }
                             pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    OMX_EventCmdComplete,
@@ -3271,13 +3278,11 @@
                             eError = OMX_ErrorNone;
                             pComponentPrivate->bIsPaused = 0;
                             pComponentPrivate->eState = OMX_StateLoaded;
-
-                           /* Decrement reference count with signal enabled */
-                           if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
-                               return OMX_ErrorUndefined;
-                           }
-
-                           pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
+                            /* Decrement reference count with signal enabled */
+                            if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
+                                return OMX_ErrorUndefined;
+                            }
+                            pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    OMX_EventCmdComplete,
                                                                    OMX_CommandStateSet,
@@ -3301,12 +3306,10 @@
                         eError = OMX_ErrorNone;
                         pComponentPrivate->bIsPaused = 0;
                         pComponentPrivate->eState = OMX_StateLoaded;
-
                         /* Decrement reference count with signal enabled */
                         if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
-                             return OMX_ErrorUndefined;
+                            return OMX_ErrorUndefined;
                         }
-
                         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                                pComponentPrivate->pHandle->pApplicationPrivate,
                                                                OMX_EventCmdComplete,
@@ -3330,12 +3333,10 @@
                         eError = OMX_ErrorNone;
                         pComponentPrivate->bIsPaused = 0;
                         pComponentPrivate->eState = OMX_StateLoaded;
-
                         /* Decrement reference count with signal enabled */
                         if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
-                             return OMX_ErrorUndefined;
+                            return OMX_ErrorUndefined;
                         }
-
                         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                                pComponentPrivate->pHandle->pApplicationPrivate,
                                                                OMX_EventCmdComplete,
@@ -3373,12 +3374,10 @@
                     }
                     pComponentPrivate->eState = OMX_StateLoaded;
                     pComponentPrivate->bIsPaused = 0;
-
                     /* Decrement reference count with signal enabled */
                     if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
-                          return OMX_ErrorUndefined;
+                        return OMX_ErrorUndefined;
                     }
-
                     pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                            pComponentPrivate->pHandle->pApplicationPrivate,
                                                            OMX_EventCmdComplete,
@@ -3395,13 +3394,10 @@
             else if (pComponentPrivate->eState == OMX_StateWaitForResources) {
                 pComponentPrivate->eState = OMX_StateLoaded;
                 pComponentPrivate->bIsPaused = 0;
-
-
                 /* Decrement reference count with signal enabled */
                 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
-                     return OMX_ErrorUndefined;
+                    return OMX_ErrorUndefined;
                 }
-
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -3479,13 +3475,10 @@
                 eError = OMX_ErrorNone;
                 pComponentPrivate->bIsPaused = 1;
                 pComponentPrivate->eState = OMX_StatePause;
-
-
                 /* Decrement reference count with signal enabled */
                 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
                     return OMX_ErrorUndefined;
                 }
-
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -3525,12 +3518,10 @@
                 eError = OMX_ErrorNone;
                 pComponentPrivate->bIsPaused = 1;
                 pComponentPrivate->eState = OMX_StatePause;
-
                 /* Decrement reference count with signal enabled */
                 if(RemoveStateTransition(pComponentPrivate, OMX_TRUE) != OMX_ErrorNone) {
                     return OMX_ErrorUndefined;
                 }
-
                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                        OMX_EventCmdComplete,
@@ -3825,6 +3816,10 @@
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
+    eError = DecrementCount (&(pComponentPrivate->nCountOutputBFromApp), &(pComponentPrivate->mutexOutputBFromApp));
+    if (eError != OMX_ErrorNone) {
+        return eError;
+    }
     OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead 0x%p eExecuteToIdle 0x%x\n", pBuffHead, pComponentPrivate->eExecuteToIdle);
 
     if(pBuffHead->pOutputPortPrivate != NULL) {
@@ -3867,7 +3862,7 @@
 
             OMX_PRDSP1(pComponentPrivate->dbg, "LCML_QueueBuffer(OUTPUT)\n");
             eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                      EMMCodecOuputBuffer,
+                                      EMMCodecOutputBufferMapBufLen,
                                       pBuffHead->pBuffer,
                                       pBuffHead->nAllocLen,
                                       pBuffHead->nFilledLen,
@@ -4091,7 +4086,7 @@
 
     /*OMX_U32 nTotalInBytes = pBuffHead->nFilledLen;*/
     VIDDEC_MPEG4_ParserParam MPEG4_Param;
-    VIDDEC_MPEG4UncompressedVideoFormat iOutputFormat;
+    VIDDEC_MPEG4UncompressedVideoFormat iOutputFormat = {0};
     VIDDEC_MPEG4_ParserParam* sMPEG4_Param = &MPEG4_Param;
     VIDDEC_VideoPictureHeader sPictHeaderDummy;
     VIDDEC_MPEG4VisualVOLHeader sVolHeaderDummy;
@@ -4538,7 +4533,7 @@
 {
     OMX_ERRORTYPE eError = OMX_ErrorBadParameter;
     OMX_S32 i = 0;
-    VIDDEC_AVC_ParserParam* sParserParam;
+    VIDDEC_AVC_ParserParam* sParserParam = NULL;
     /*OMX_S32 nRetVal = 0;*/
     OMX_BOOL nStartFlag = OMX_FALSE;
     OMX_U32 nBitPosition = 0;
@@ -4560,17 +4555,14 @@
     nTotalInBytes = pBuffHead->nFilledLen;
     nBitStream = (OMX_U8*)pBuffHead->pBuffer;/* + (OMX_U8*)pBuffHead->nOffset;*/
     nRbspByte = (OMX_U8*)malloc(nTotalInBytes);
-    if ( nRbspByte == NULL )
-    {
-        eError = OMX_ErrorInsufficientResources;
+    if (!nRbspByte) {
+        eError =  OMX_ErrorInsufficientResources;
         goto EXIT;
     }
-
     memset(nRbspByte, 0x0, nTotalInBytes);
     sParserParam = (VIDDEC_AVC_ParserParam *)malloc(sizeof(VIDDEC_AVC_ParserParam));
-    if ( sParserParam == NULL )
-    {
-        eError = OMX_ErrorInsufficientResources;
+    if (!sParserParam) {
+        eError =  OMX_ErrorInsufficientResources;
         goto EXIT;
     }
 
@@ -4870,9 +4862,9 @@
     eError = OMX_ErrorNone;
 
 EXIT:
-    if ( nRbspByte != NULL )
+    if (nRbspByte)
         free( nRbspByte);
-    if ( sParserParam != NULL )
+    if (sParserParam)
         free( sParserParam);
     return eError;
 }
@@ -5022,6 +5014,8 @@
         else if( pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4  ||
                 pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
             VIDDEC_ParseVideo_MPEG4( &nWidth, &nHeight, pBuffHead);
+            /* Work around force reconfiguration */
+            bOutPortSettingsChanged = OMX_TRUE;
         }
         else if( pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
             VIDDEC_ParseVideo_MPEG2( &nWidth, &nHeight, pBuffHead);
@@ -5129,7 +5123,8 @@
             }
         }
 
-        /*Get minimum OUTPUT buffer size & verify if the actual allocated size is enough*/
+        /*Get minimum OUTPUT buffer size, 
+         * verify if the actual allocated size is the same as require by display driver*/
         nOutMinBufferSize = pComponentPrivate->pOutPortDef->format.video.nFrameWidth *
                             pComponentPrivate->pOutPortDef->format.video.nFrameHeight *
                             ((pComponentPrivate->pOutPortFormat->eColorFormat == VIDDEC_COLORFORMAT420) ? VIDDEC_FACTORFORMAT420 : VIDDEC_FACTORFORMAT422);
@@ -5200,7 +5195,8 @@
             eError = OMX_ErrorNone;
         }
 EXIT:
-    OMX_PRINT1(pComponentPrivate->dbg, "OUT\n");
+    if (pComponentPrivate)
+        OMX_PRINT1(pComponentPrivate->dbg, "OUT\n");
     return eError;
 }
 #endif
@@ -5230,6 +5226,7 @@
     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));
@@ -5238,7 +5235,10 @@
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
-
+    eError = DecrementCount (&(pComponentPrivate->nCountInputBFromApp), &(pComponentPrivate->mutexInputBFromApp));
+    if (eError != OMX_ErrorNone) {
+        return eError;
+    }
     if( pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingWMV &&
             pComponentPrivate->ProcessMode == 0 && 
             pBuffHead->nFilledLen != 0) {
@@ -5322,6 +5322,9 @@
                                                 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,
@@ -5365,6 +5368,9 @@
                         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,
@@ -5382,7 +5388,7 @@
                         return OMX_ErrorNone;
                    }
                    else {
-			/* VC-1: First data buffer received, add configuration data to it*/
+                        /* VC-1: First data buffer received, add configuration data to it*/
                         pComponentPrivate->bFirstHeader = OMX_TRUE;
                         OMX_WMV_INSERT_CODEC_DATA(pBuffHead, pComponentPrivate);
                         eError = OMX_ErrorNone;
@@ -5397,6 +5403,9 @@
                         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,
@@ -5472,6 +5481,9 @@
                     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,
@@ -5537,6 +5549,9 @@
                 }
 #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,
@@ -5665,6 +5680,8 @@
                 pUalgInpParams = (OMX_PTR)pBufferPrivate->pUalgParam;
                 if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) {
                     ((MP4VD_GPP_SN_UALGInputParams*)pUalgInpParams)->nBuffCount = ++pComponentPrivate->frameCounter;
+                    ((MP4VD_GPP_SN_UALGInputParams*)pUalgInpParams)->uRingIOBlocksize = 0;
+                    ((MP4VD_GPP_SN_UALGInputParams*)pUalgInpParams)->nPerformMode = 2;
                 }
                 size_dsp = sizeof(MP4VD_GPP_SN_UALGInputParams);
             }
@@ -5735,6 +5752,10 @@
 #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);
                     VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                     goto EXIT;
@@ -5765,7 +5786,10 @@
         else {
             pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
             OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
-            pComponentPrivate->nInputBCountDsp++;
+            eError = IncrementCount (&(pComponentPrivate->nCountInputBFromDsp), &(pComponentPrivate->mutexInputBFromDSP));
+            if (eError != OMX_ErrorNone) {
+                return eError;
+            }
             ret = write(pComponentPrivate->free_inpBuf_Q[1], &pBuffHead, sizeof(pBuffHead));
             if(ret == -1){
                 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%d)\n", OMX_ErrorInsufficientResources,ret);
@@ -5778,176 +5802,186 @@
             }
         }
 
-        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;
+        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);
             }
-            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;
             }
-            size_dsp = sizeof(WMV9DEC_UALGInputParam);
-            ((WMV9DEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = -1;
-            OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
+            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",
                     ((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;
             }
-            size_dsp = sizeof(MP4VD_GPP_SN_UALGInputParams);
-            ((MP4VD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nBuffCount = -1;
-            OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
+            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 = ++pComponentPrivate->frameCounter;
+                ((MP4VD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->uRingIOBlocksize = 0;
+                /* If EOS is sent, set nPerformMode to 0 (this handle thumbnail case)*/
+                ((MP4VD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->nPerformMode = 0;
+                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;
             }
-            size_dsp = sizeof(MP2VDEC_UALGInputParam);
-            ((MP2VDEC_UALGInputParam*)pComponentPrivate->pUalgParams)->lBuffCount = -1;
-            OMX_PRBUFFER1(pComponentPrivate->dbg, "lBuffCount 0x%lx\n",
+            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",
                     ((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",
+#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",
                     ((SPARKVD_GPP_SN_UALGInputParams*)pComponentPrivate->pUalgParams)->lBuffCount);
-        }
+            }
 #endif
-        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,
-                    pBuffHead->pBuffer,
-                    pBuffHead->nFilledLen,
-                    PERF_ModuleHLMM);
-#endif
-
-            if(pComponentPrivate->bDynamicConfigurationInProgress){
-                OMX_PRBUFFER2(pComponentPrivate->dbg, "Sending buffer back to client pBuffer=%p\n", pBuffHead->pBuffer);
-                VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
+            else {
+                eError = OMX_ErrorUnsupportedSetting;
                 goto EXIT;
             }
 
-            OMX_PRDSP2(pComponentPrivate->dbg, "LCML_QueueBuffer(INPUT)\n");
+#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);
+#endif
 
-            /* 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) {
+                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);
+                    VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
+                    goto EXIT;
+                }
+
+                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;
                         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);
+                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 EOS (0x%x)\n",eError);
+                    OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer 1 (0x%x)\n",eError);
                     eError = OMX_ErrorHardware;
                     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);
-            }
-            if (eError != OMX_ErrorNone){
-                OMX_PRDSP4(pComponentPrivate->dbg, "LCML_QueueBuffer 1 (0x%x)\n",eError);
+            else {
                 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;
@@ -6022,6 +6056,8 @@
                             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;
                             VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                             goto EXIT;
                         }
@@ -6185,7 +6221,10 @@
             else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
                      pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
                 pUalgInpParams = pBufferPrivate->pUalgParam;
-                if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) {
+                ((MP4VD_GPP_SN_UALGInputParams*)pUalgInpParams)->uRingIOBlocksize = 0;
+                ((MP4VD_GPP_SN_UALGInputParams*)pUalgInpParams)->nPerformMode = 2;
+
+               if ((pBuffHead->nFlags & OMX_BUFFERFLAG_EOS) == 0) {
                     ((MP4VD_GPP_SN_UALGInputParams*)pUalgInpParams)->nBuffCount = ++pComponentPrivate->frameCounter;
                 }
                 size_dsp = sizeof(MP4VD_GPP_SN_UALGInputParams);
@@ -6258,6 +6297,10 @@
 #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);
                     VIDDEC_EmptyBufferDone(pComponentPrivate, pBuffHead);
                     goto EXIT;
@@ -6316,7 +6359,10 @@
             pBuffHead->nFilledLen = 0;
             pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
             OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
-            pComponentPrivate->nInputBCountDsp++;
+            eError = IncrementCount (&(pComponentPrivate->nCountInputBFromDsp), &(pComponentPrivate->mutexInputBFromDSP));
+            if (eError != OMX_ErrorNone) {
+                return eError;
+            }
             ret = write(pComponentPrivate->free_inpBuf_Q[1], &pBuffHead, sizeof(pBuffHead));
             if(ret == -1){
                 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%d)\n", OMX_ErrorInsufficientResources,ret);
@@ -6326,6 +6372,7 @@
                                                        OMX_ErrorInsufficientResources,
                                                        OMX_TI_ErrorSevere,
                                                        "Error writing to the output pipe");
+                DecrementCount (&(pComponentPrivate->nCountInputBFromDsp), &(pComponentPrivate->mutexInputBFromDSP));
             }
         }
     }
@@ -6356,6 +6403,13 @@
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
+    eError = DecrementCount (&(pComponentPrivate->nCountOutputBFromDsp), &(pComponentPrivate->mutexOutputBFromDSP));
+    if (eError != OMX_ErrorNone) {
+        return eError;
+    }
+    OMX_PRBUFFER1(pComponentPrivate->dbg, "BufferSize fromDSP %lu \n",pBuffHead->nAllocLen);
+    OMX_PRBUFFER1(pComponentPrivate->dbg, "AllocLen: 0x%x, FilledLen: 0x%x\n", pBuffHead->nAllocLen, pBuffHead->nFilledLen);
+    OMX_PRSTATE1(pComponentPrivate->dbg, "pBuffHead 0x%p eExecuteToIdle 0x%x\n", pBuffHead,pComponentPrivate->eExecuteToIdle);
     if (pComponentPrivate->eState == OMX_StateLoaded || pComponentPrivate->eState == OMX_StateIdle) {
         eError = OMX_ErrorNone;
         goto EXIT;
@@ -6582,7 +6636,16 @@
                     eError = OMX_EmptyThisBuffer(pComponentPrivate->pCompPort[1]->hTunnelComponent, pBuffHead);
                 }
                 else {
-                    write(pComponentPrivate->free_outBuf_Q[1],&pBuffHead,sizeof(pBuffHead));
+                    ret = write(pComponentPrivate->free_outBuf_Q[1],&pBuffHead,sizeof(pBuffHead));
+                    if (ret == -1) {
+                        OMX_PRDSP4(pComponentPrivate->dbg, "Error while writing to out pipe to client\n");
+                        eError = OMX_ErrorHardware;
+                        return eError;
+                    }
+                    eError = IncrementCount (&(pComponentPrivate->nCountOutputBFromApp), &(pComponentPrivate->mutexOutputBFromApp));
+                    if (eError != OMX_ErrorNone) {
+                        return eError;
+                    }
                 }
             }
         }
@@ -6596,6 +6659,16 @@
     #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);
+                }
                 VIDDEC_FillBufferDone(pComponentPrivate, pBuffHead);
             }
         }
@@ -6631,13 +6704,21 @@
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
+    eError = IncrementCount (&(pComponentPrivate->nCountInputBFromDsp), &(pComponentPrivate->mutexInputBFromDSP));
+    if (eError != OMX_ErrorNone) {
+        return eError;
+    }
+    OMX_PRSTATE1(pComponentPrivate->dbg, "pBuffHead 0x%p eExecuteToIdle 0x%x\n", pBuffHead,pComponentPrivate->eExecuteToIdle);
     if (pComponentPrivate->eState == OMX_StateLoaded || pComponentPrivate->eState == OMX_StateIdle) {
         eError = OMX_ErrorNone;
         goto EXIT;
     }
     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,
@@ -6713,6 +6794,11 @@
     strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)RINGIO_NODE_DLL);
     lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT;
 
+    lcml_dsp->NodeInfo.AllUUIDs[4].uuid = (struct DSP_UUID *)&CONVERSIONS_UUID;
+    strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[4].DllName,(char*)CONVERSIONS_DLL);
+    lcml_dsp->NodeInfo.AllUUIDs[4].eDllType = DLL_DEPENDENT;
+
+
     lcml_dsp->SegID     = 0;
     lcml_dsp->Timeout   = -1;
     lcml_dsp->Alignment = 0;
@@ -6844,6 +6930,7 @@
     pCreatePhaseArgs->ulMaxLevel                = -1;
     pCreatePhaseArgs->ulProcessMode             = pComponentPrivate->ProcessMode;
     pCreatePhaseArgs->lPreRollBufConfig         = 0;
+    pCreatePhaseArgs->bCopiedCCDBuffer          = 0;
 
     if (pComponentPrivate->nWMVFileType == VIDDEC_WMV_ELEMSTREAM) {
         pCreatePhaseArgs->usIsElementaryStream = VIDDEC_SN_WMV_ELEMSTREAM;
@@ -6862,7 +6949,7 @@
         eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb);
         if (eError != OMX_ErrorNone) {
             OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError);
-            eError = OMX_ErrorInvalidState;
+            eError = OMX_ErrorHardware;
             goto EXIT;
         }
     }
@@ -6903,6 +6990,8 @@
     OMX_U32 nOutBuffSize = 0;
     H264VDEC_SNCreatePhArg* pCreatePhaseArgs = NULL;
     LCML_CALLBACKTYPE cb;
+    OMX_U32 nFrameWidth = 0;
+    OMX_U32 nFrameHeight = 0;
 
     OMX_PRDSP1(pComponentPrivate->dbg, "+++ENTERING\n");
 
@@ -6945,6 +7034,10 @@
     strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)RINGIO_NODE_DLL);
     lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT;
 
+    lcml_dsp->NodeInfo.AllUUIDs[4].uuid = (struct DSP_UUID *)&CONVERSIONS_UUID;
+    strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[4].DllName,(char*)CONVERSIONS_DLL);
+    lcml_dsp->NodeInfo.AllUUIDs[4].eDllType = DLL_DEPENDENT;
+
     lcml_dsp->SegID     = 0;
     lcml_dsp->Timeout   = -1;
     lcml_dsp->Alignment = 0;
@@ -7007,6 +7100,12 @@
         eError = OMX_ErrorInsufficientResources;
         goto EXIT;
     }
+
+    nFrameWidth = pComponentPrivate->pInPortDef->format.video.nFrameWidth;
+    nFrameHeight = pComponentPrivate->pInPortDef->format.video.nFrameHeight;
+    if (nFrameWidth & 0xF) nFrameWidth = (nFrameWidth & 0xFFF0) + 0x10;
+    if (nFrameHeight & 0xF) nFrameHeight = (nFrameHeight & 0xFFF0) + 0x10;
+
     pCreatePhaseArgs->unNumOfStreams            = 2;
     pCreatePhaseArgs->unInputStreamID           = 0;
     pCreatePhaseArgs->unInputBufferType         = 0;
@@ -7014,8 +7113,9 @@
     pCreatePhaseArgs->unOutputStreamID          = 1;
     pCreatePhaseArgs->unOutputBufferType        = 0;
     pCreatePhaseArgs->unOutputNumBufsPerStream  = (OMX_U16)nOutBuff;
-    pCreatePhaseArgs->ulMaxWidth                = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameWidth);
-    pCreatePhaseArgs->ulMaxHeight               = (OMX_U16)(pComponentPrivate->pInPortDef->format.video.nFrameHeight);
+    pCreatePhaseArgs->ulMaxWidth                = nFrameWidth;
+    pCreatePhaseArgs->ulMaxHeight               = nFrameHeight;
+
 
     if (pComponentPrivate->pOutPortDef->format.video.eColorFormat == VIDDEC_COLORFORMAT422) {
         pCreatePhaseArgs->ulYUVFormat           = H264VIDDEC_YUVFORMAT_INTERLEAVED422;
@@ -7051,7 +7151,7 @@
         eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb);
         if (eError != OMX_ErrorNone) {
             OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError);
-            eError = OMX_ErrorInvalidState;
+            eError = OMX_ErrorHardware;
             goto EXIT;
         }
     }
@@ -7060,10 +7160,10 @@
         goto EXIT;
     }
 EXIT:
-    if (  pCreatePhaseArgs  != NULL )
+    if (pCreatePhaseArgs) {
         free(pCreatePhaseArgs);
-    pCreatePhaseArgs = NULL;
-
+        pCreatePhaseArgs = NULL;
+    }
     OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError);
     return eError;
 }
@@ -7118,10 +7218,8 @@
     OMX_U32 nFrameWidth = pComponentPrivate->pOutPortDef->format.video.nFrameWidth;
     OMX_U32 nFrameHeight = pComponentPrivate->pOutPortDef->format.video.nFrameHeight;
 
-    /* nFrameWidth and nFrameHeight needs to be multiples of 16. */
     nFrameWidth = (nFrameWidth + 0x0f) & ~0x0f;
     nFrameHeight = (nFrameHeight + 0x0f) & ~0x0f;
-
     if (nFrameWidth * nFrameHeight > 880 * 720)
     {
         lcml_dsp->NodeInfo.AllUUIDs[0].uuid = (struct DSP_UUID *)&MP4D720PSOCKET_TI_UUID;
@@ -7155,6 +7253,10 @@
     strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)USN_DLL);
     lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT;
 
+    lcml_dsp->NodeInfo.AllUUIDs[4].uuid = (struct DSP_UUID *)&CONVERSIONS_UUID;
+    strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[4].DllName,(char*)CONVERSIONS_DLL);
+    lcml_dsp->NodeInfo.AllUUIDs[4].eDllType = DLL_DEPENDENT;
+
     lcml_dsp->SegID     = 0;
     lcml_dsp->Timeout   = -1;
     lcml_dsp->Alignment = 0;
@@ -7189,6 +7291,13 @@
     pCreatePhaseArgs->unOutputStreamID          = 1;
     pCreatePhaseArgs->unOutputBufferType        = 0;
     pCreatePhaseArgs->unOutputNumBufsPerStream  = (OMX_U16)(pComponentPrivate->pOutPortDef->nBufferCountActual);
+
+    /* ulMaxWidth and ulMaxHeight needs to be multiples of 16. */
+    nFrameWidth = pComponentPrivate->pInPortDef->format.video.nFrameWidth;
+    nFrameHeight = pComponentPrivate->pInPortDef->format.video.nFrameHeight;
+    if (nFrameWidth & 0xF) nFrameWidth = (nFrameWidth & 0xFFF0) + 0x10;
+    if (nFrameHeight & 0xF) nFrameHeight = (nFrameHeight & 0xFFF0) + 0x10;
+
     pCreatePhaseArgs->ulMaxWidth                = (OMX_U16)(nFrameWidth);
     pCreatePhaseArgs->ulMaxHeight               = (OMX_U16)(nFrameHeight);
 
@@ -7208,8 +7317,9 @@
 
     OMX_PRBUFFER1(pComponentPrivate->dbg, "pCreatePhaseArgs->ulMaxWidth %lu  pCreatePhaseArgs->ulMaxHeight %lu\n",
         pCreatePhaseArgs->ulMaxWidth,pCreatePhaseArgs->ulMaxHeight);
-    pCreatePhaseArgs->ulMaxFrameRate            = 0;
-    pCreatePhaseArgs->ulMaxBitRate              = -1;
+
+    pCreatePhaseArgs->ulMaxFrameRate            = VIDDEC_MAX_FRAMERATE;
+    pCreatePhaseArgs->ulMaxBitRate              = VIDDEC_MAX_BITRATE;
     pCreatePhaseArgs->ulDataEndianness          = 1;
     if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4){
         pCreatePhaseArgs->ulProfile                 = 0;
@@ -7234,7 +7344,7 @@
         eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb);
         if (eError != OMX_ErrorNone) {
             OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError);
-            eError = OMX_ErrorInvalidState;
+            eError = OMX_ErrorHardware;
             goto EXIT;
         }
     }
@@ -7243,10 +7353,10 @@
         goto EXIT;
     }
 EXIT:
-    if ( pCreatePhaseArgs != NULL )
+    if (pCreatePhaseArgs) {
         free(pCreatePhaseArgs);
-    pCreatePhaseArgs = NULL;
-
+        pCreatePhaseArgs = NULL;
+    }
     OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError);
     return eError;
 }
@@ -7413,7 +7523,7 @@
         eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb);
         if (eError != OMX_ErrorNone) {
             OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError);
-            eError = OMX_ErrorInvalidState;
+            eError = OMX_ErrorHardware;
             goto EXIT;
         }
     }
@@ -7422,10 +7532,10 @@
         goto EXIT;
     }
 EXIT:
-    if ( pCreatePhaseArgs != NULL )
+    if (pCreatePhaseArgs) {
         free(pCreatePhaseArgs);
-    pCreatePhaseArgs = NULL;
-
+        pCreatePhaseArgs = NULL;
+    }
     OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError);
     return eError;
 }
@@ -7493,6 +7603,10 @@
     strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[3].DllName,(char*)USN_DLL);
     lcml_dsp->NodeInfo.AllUUIDs[3].eDllType = DLL_DEPENDENT;
 
+    lcml_dsp->NodeInfo.AllUUIDs[4].uuid = (struct DSP_UUID *)&CONVERSIONS_UUID;
+    strcpy ((char*)lcml_dsp->NodeInfo.AllUUIDs[4].DllName,(char*)CONVERSIONS_DLL);
+    lcml_dsp->NodeInfo.AllUUIDs[4].eDllType = DLL_DEPENDENT;
+
     lcml_dsp->SegID     = 0;
     lcml_dsp->Timeout   = -1;
     lcml_dsp->Alignment = 0;
@@ -7602,7 +7716,7 @@
         eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, NULL, &pLcmlHandle, NULL, &cb);
         if (eError != OMX_ErrorNone) {
             OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...%x\n",eError);
-            eError = OMX_ErrorInvalidState;
+            eError = OMX_ErrorHardware;
             goto EXIT;
         }
     }
@@ -7611,10 +7725,10 @@
         goto EXIT;
     }
 EXIT:
-    if ( pCreatePhaseArgs != NULL )
+    if (pCreatePhaseArgs) {
         free(pCreatePhaseArgs);
-    pCreatePhaseArgs = NULL;
-
+        pCreatePhaseArgs = NULL;
+    }
     OMX_PRDSP1(pComponentPrivate->dbg, "---EXITING(0x%x)\n",eError);
     return eError;
 }
@@ -7852,8 +7966,11 @@
                                 pBuffHead->nFilledLen = (OMX_S32)argsCb[8];
                             /*}*/
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFilledLen %lu\n", pBuffHead->nFilledLen);
+                            eError = IncrementCount (&(pComponentPrivate->nCountOutputBFromDsp), &(pComponentPrivate->mutexOutputBFromDSP));
+                            if (eError != OMX_ErrorNone) {
+                                return eError;
+                            }
                             pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate;
-                            android_atomic_inc(&pComponentPrivate->nOutputBCountDsp);
                             pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
 #ifdef __PERF_INSTRUMENTATION__
@@ -7865,6 +7982,8 @@
 
                             nRetVal = write(pComponentPrivate->filled_outBuf_Q[1],&pBuffHead,sizeof(pBuffHead));
                             if(nRetVal == -1){
+                                DecrementCount (&(pComponentPrivate->nCountOutputBFromDsp), &(pComponentPrivate->mutexOutputBFromDSP));
+                                pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP;
                                 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%ld)\n", OMX_ErrorInsufficientResources,nRetVal);
                                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                                        pComponentPrivate->pHandle->pApplicationPrivate,
@@ -7902,8 +8021,11 @@
                         OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead Input 0x%p pBuffer 0x%p\n", pBuffHead, argsCb[1]);
                         pBuffer = (OMX_U8*)argsCb[1];
                         if(pBuffer != NULL){
+                            eError = IncrementCount (&(pComponentPrivate->nCountInputBFromDsp), &(pComponentPrivate->mutexInputBFromDSP));
+                            if (eError != OMX_ErrorNone) {
+                                return eError;
+                            }
                             pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                            pComponentPrivate->nInputBCountDsp++;
                             pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
     #ifdef __PERF_INSTRUMENTATION__
@@ -7928,6 +8050,8 @@
                             nRetVal = write(pComponentPrivate->free_inpBuf_Q[1], &pBuffHead, sizeof(pBuffHead));
                             if(nRetVal == -1){
                                 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%lu)\n", OMX_ErrorInsufficientResources,nRetVal);
+                                DecrementCount (&(pComponentPrivate->nCountInputBFromDsp), &(pComponentPrivate->mutexInputBFromDSP));
+                                pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP;
                                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                                        OMX_EventError,
@@ -8004,8 +8128,11 @@
                                 pBuffHead->nFilledLen = (OMX_S32)argsCb[8];
                             /*}*/
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead->nFilledLen %lu\n", pBuffHead->nFilledLen);
+                            eError = IncrementCount (&(pComponentPrivate->nCountOutputBFromDsp), &(pComponentPrivate->mutexOutputBFromDSP));
+                            if (eError != OMX_ErrorNone) {
+                                return eError;
+                            }
                             pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate;
-                            android_atomic_inc(&pComponentPrivate->nOutputBCountDsp);
                             pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
 #ifdef __PERF_INSTRUMENTATION__
@@ -8017,6 +8144,8 @@
 
                             nRetVal = write(pComponentPrivate->filled_outBuf_Q[1],&pBuffHead,sizeof(pBuffHead));
                             if(nRetVal == -1){
+                                DecrementCount (&(pComponentPrivate->nCountOutputBFromDsp), &(pComponentPrivate->mutexOutputBFromDSP));
+                                pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP;
                                 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%lu)\n", OMX_ErrorInsufficientResources,nRetVal);
                                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                                        pComponentPrivate->pHandle->pApplicationPrivate,
@@ -8053,8 +8182,11 @@
                         OMX_PRBUFFER1(pComponentPrivate->dbg, "pBuffHead Input 0x%p pBuffer 0x%p\n", pBuffHead, argsCb[1]);
                         pBuffer = (OMX_U8*)argsCb[1];
                         if(pBuffer != NULL){
+                            eError = IncrementCount (&(pComponentPrivate->nCountInputBFromDsp), &(pComponentPrivate->mutexInputBFromDSP));
+                            if (eError != OMX_ErrorNone) {
+                                return eError;
+                            }
                             pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
-                            pComponentPrivate->nInputBCountDsp++;
                             pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
                             OMX_PRBUFFER1(pComponentPrivate->dbg, "eBufferOwner 0x%x\n", pBufferPrivate->eBufferOwner);
     #ifdef __PERF_INSTRUMENTATION__
@@ -8079,6 +8211,8 @@
                             nRetVal = write(pComponentPrivate->free_inpBuf_Q[1], &pBuffHead, sizeof(pBuffHead));
                             if(nRetVal == -1){
                                 OMX_PRCOMM4(pComponentPrivate->dbg, "writing to the input pipe %x (%lu)\n", OMX_ErrorInsufficientResources,nRetVal);
+                                DecrementCount (&(pComponentPrivate->nCountInputBFromDsp), &(pComponentPrivate->mutexInputBFromDSP));
+                                pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_DSP;
                                 pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                                        pComponentPrivate->pHandle->pApplicationPrivate,
                                                                        OMX_EventError,
@@ -8251,40 +8385,32 @@
     pComponentPrivate->eFirstBuffer.bSaveFirstBuffer = OMX_FALSE;
 
     /* only if NAL-bitstream format in frame mode */
-    if (pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat > 0) {
+    if (
+        ((pComponentPrivate->ProcessMode == 0 && pComponentPrivate->H264BitStreamFormat > 0)
+     || (pBuffHead->nFilledLen > pComponentPrivate->eFirstBuffer.nFilledLen))
+     && (pBuffHead->nAllocLen >= pComponentPrivate->eFirstBuffer.nFilledLen + pBuffHead->nFilledLen)
+       ) {
         OMX_MALLOC_STRUCT_SIZED(pTemp, OMX_U8, pBuffHead->nFilledLen, NULL);
         memcpy(pTemp, pBuffHead->pBuffer, pBuffHead->nFilledLen); /*copy somewere actual buffer*/
         memcpy(pBuffHead->pBuffer, pComponentPrivate->eFirstBuffer.pFirstBufferSaved, pComponentPrivate->eFirstBuffer.nFilledLen); /*copy first buffer to the beganing of pBuffer.*/
-        memcpy(pBuffHead->pBuffer+((OMX_U8)pComponentPrivate->eFirstBuffer.nFilledLen), (OMX_U8 *)pTemp, pBuffHead->nFilledLen); /* copy back actual buffer after first buffer*/
-        pBuffHead->nFilledLen += (OMX_U8)pComponentPrivate->eFirstBuffer.nFilledLen; /*Add first buffer size*/
+        memcpy((OMX_U8 *)pBuffHead->pBuffer+pComponentPrivate->eFirstBuffer.nFilledLen, pTemp, pBuffHead->nFilledLen); /* copy back actual buffer after first buffer*/
+        pBuffHead->nFilledLen += pComponentPrivate->eFirstBuffer.nFilledLen; /*Add first buffer size*/
 
         free(pTemp);
         free(pComponentPrivate->eFirstBuffer.pFirstBufferSaved);
         pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL;
     }
-    else {
-        if (pBuffHead->nFilledLen > pComponentPrivate->eFirstBuffer.nFilledLen) {
-            OMX_MALLOC_STRUCT_SIZED(pTemp, OMX_U8, pBuffHead->nFilledLen, NULL);
-            memcpy(pTemp, pBuffHead->pBuffer, pBuffHead->nFilledLen); /*copy somewere actual buffer*/
-            memcpy(pBuffHead->pBuffer, pComponentPrivate->eFirstBuffer.pFirstBufferSaved, pComponentPrivate->eFirstBuffer.nFilledLen); /*copy first buffer to the beganing of pBuffer.*/
-            memcpy(pBuffHead->pBuffer+((OMX_U8)pComponentPrivate->eFirstBuffer.nFilledLen), (OMX_U8 *)pTemp, pBuffHead->nFilledLen); /* copy back actual buffer after first buffer*/
-            pBuffHead->nFilledLen += (OMX_U8)pComponentPrivate->eFirstBuffer.nFilledLen; /*Add first buffer size*/
-
-            free(pTemp);
-            free(pComponentPrivate->eFirstBuffer.pFirstBufferSaved);
-            pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL;
-        }
         /*The first buffer has more information than the second, so the first buffer will be send to codec*/
         /*We are loosing the second fame. TODO: Fix this*/
-        else {
+        else if (pBuffHead->nAllocLen >= pComponentPrivate->eFirstBuffer.nFilledLen){
             /*copy first buffer data to the actual buffer*/
             memcpy(pBuffHead->pBuffer, pComponentPrivate->eFirstBuffer.pFirstBufferSaved, pComponentPrivate->eFirstBuffer.nFilledLen); /*copy first buffer*/
             pBuffHead->nFilledLen = pComponentPrivate->eFirstBuffer.nFilledLen; /*Update buffer size*/
             free(pComponentPrivate->eFirstBuffer.pFirstBufferSaved);
             pComponentPrivate->eFirstBuffer.pFirstBufferSaved = NULL;
+        } else {
+            LOGE("Not enough memory in the buffer to concatenate the 2 frames, loosing first frame\n");
         }
-    }
-
 EXIT:
     OMX_PRINT1(pComponentPrivate->dbg, "OUT\n");
     return eError;
@@ -8318,6 +8444,7 @@
    LPFNDLLFUNC1 fpGetHandle1;
 #else
    VIDDEC_fpo fpGetHandle;
+   char* error;
 #endif
 
 #ifndef UNDER_CE
@@ -8329,9 +8456,9 @@
         goto EXIT;
     }
     fpGetHandle = dlsym(pComponentPrivate->pModLCML, "GetHandle");
-    if (!fpGetHandle) {
+    if ((error = dlerror()) != NULL) {
         OMX_PRDSP4(pComponentPrivate->dbg, "OMX_ErrorBadParameter\n");
-        fputs(dlerror(), stderr);
+        fputs(error, stderr);
         dlclose(pComponentPrivate->pModLCML);
         pComponentPrivate->pModLCML = NULL;
         eError = OMX_ErrorBadParameter;
@@ -8669,6 +8796,7 @@
                                            EMMCodecControlAlgCtrl,
                                            (void*)p);
                 if (eError != OMX_ErrorNone) {
+                    VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex);
                     eError = OMX_ErrorHardware;
                     OMX_MEMFREE_STRUCT_DSPALIGN (pDynParams,SPARKVDEC_UALGDynamicParams);
                     goto EXIT;
@@ -8687,11 +8815,9 @@
     }
 #endif
     else {
-        if(pComponentPrivate->eState == OMX_StateIdle) {
-            eError = VIDDEC_Set_Debocking(pComponentPrivate);
-            if (eError != OMX_ErrorNone){
-                goto EXIT;
-            }
+        eError = VIDDEC_SetMpeg4_Parameters(pComponentPrivate);
+        if (eError != OMX_ErrorNone){
+            goto EXIT;
         }
     }
 
@@ -8881,7 +9007,6 @@
         }
 
         OMX_MEMFREE_STRUCT_DSPALIGN(pDynParams,WMV9DEC_UALGDynamicParams);
-
         if (eError != OMX_ErrorNone) {
             OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError);
         }
@@ -8894,7 +9019,7 @@
 
 /* ========================================================================== */
 /**
- *  VIDDEC_Set_Debocking() Enable Deblocking filter
+ *  VIDDEC_SetMpeg4_Parameters() Enable Deblocking filter
  *       
  * @param
  *     pComponentPrivate            Component private structure
@@ -8905,7 +9030,7 @@
  **/
 /* ========================================================================== */
 
-OMX_ERRORTYPE VIDDEC_Set_Debocking(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate)
+OMX_ERRORTYPE VIDDEC_SetMpeg4_Parameters(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate)
 {
     MP4VDEC_UALGDynamicParams* pDynParams = NULL;
     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
@@ -8940,6 +9065,7 @@
     pDynParams->ulDecodeHeader = 0;
     pDynParams->ulDisplayWidth = 0;
     pDynParams->ulFrameSkipMode = 0;
+    pDynParams->useHighPrecIdctQp1 = 0;
 
 
     if(mDisableDeblockingIfD1){
@@ -8981,7 +9107,7 @@
         VIDDEC_PTHREAD_MUTEX_WAIT(pComponentPrivate->sMutex);
         VIDDEC_PTHREAD_MUTEX_UNLOCK(pComponentPrivate->sMutex);
         /*This flag is set to TRUE in the LCML callback from EMMCodecControlAlgCtrl
-         * this is not the case were we need it*/
+         * this is not the case were we need it*/       
         pComponentPrivate->bTransPause = OMX_FALSE;
     }
 
@@ -8991,12 +9117,11 @@
         OMX_PRDSP4(pComponentPrivate->dbg, "Codec AlgCtrl 0x%x\n",eError);
         goto EXIT;
     }
-
+            
 EXIT:
     return eError;
 }
 
-
 OMX_ERRORTYPE AddStateTransition(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate) {
 
     OMX_ERRORTYPE eError = OMX_ErrorNone;
@@ -9037,4 +9162,27 @@
     return eError;
 }
 
+OMX_ERRORTYPE IncrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex) {
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+    if(pthread_mutex_lock(pMutex)) {
+       return OMX_ErrorUndefined;
+    }
+    (*pCounter)++;
+    if(pthread_mutex_unlock(pMutex)) {
+       return OMX_ErrorUndefined;
+    }
+    return eError;
+}
+
+OMX_ERRORTYPE DecrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex) {
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+    if(pthread_mutex_lock(pMutex)) {
+       return OMX_ErrorUndefined;
+    }
+    (*pCounter)--;
+    if(pthread_mutex_unlock(pMutex)) {
+       return OMX_ErrorUndefined;
+    }
+    return eError;
+}
 
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 8450ad1..19dd214 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
@@ -96,6 +96,8 @@
 /*extern OMX_ERRORTYPE VIDDEC_HandleCommandMarkBuffer(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1, OMX_PTR pCmdData);
 extern OMX_ERRORTYPE VIDDEC_HandleCommandFlush(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1, OMX_PTR pCmdData);*/
 extern OMX_ERRORTYPE VIDDEC_Load_Defaults (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_S32 nPassing);
+extern OMX_ERRORTYPE IncrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex);
+extern OMX_ERRORTYPE DecrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex);
 
 /*******************************************************************************
 *  PUBLIC DECLARATIONS Defined here, used elsewhere
@@ -115,7 +117,6 @@
 #else
                                                                              {VIDDEC_CUSTOMPARAM_ISNALBIGENDIAN, VideoDecodeCustomParamIsNALBigEndian}};
 #endif
-
 /* H.263 Supported Levels & profiles */
 VIDEO_PROFILE_LEVEL_TYPE SupportedH263ProfileLevels[] = {
   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10},
@@ -160,7 +161,6 @@
   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel3},
   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel31},
   {-1,-1}};
-
 /*--------function prototypes ------------------------------------------------*/
 
 /*******************************************************************************
@@ -323,6 +323,23 @@
     pHandle->ComponentRoleEnum              = ComponentRoleEnum;
 #endif
 
+    /*mutex protection*/
+    if (pthread_mutex_init(&(pComponentPrivate->mutexInputBFromApp), NULL) != 0) {
+        eError = OMX_ErrorUndefined;
+        return eError;
+    }
+    if (pthread_mutex_init(&(pComponentPrivate->mutexOutputBFromApp), NULL) != 0) {
+        eError = OMX_ErrorUndefined;
+        return eError;
+    }
+    if (pthread_mutex_init(&(pComponentPrivate->mutexInputBFromDSP), NULL) != 0) {
+        eError = OMX_ErrorUndefined;
+        return eError;
+    }
+    if (pthread_mutex_init(&(pComponentPrivate->mutexOutputBFromDSP), NULL) != 0) {
+        eError = OMX_ErrorUndefined;
+        return eError;
+    }
     OMX_MALLOC_STRUCT(pComponentPrivate->pPortParamType, OMX_PORT_PARAM_TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
 #ifdef __STD_COMPONENT__
     OMX_MALLOC_STRUCT(pComponentPrivate->pPortParamTypeAudio, OMX_PORT_PARAM_TYPE,pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0]);
@@ -614,12 +631,10 @@
 
     switch (Cmd) {
         case OMX_CommandStateSet:
-
             /* Add a pending transition */
             if(AddStateTransition(pComponentPrivate) != OMX_ErrorNone) {
                 return OMX_ErrorUndefined;
             }
-
             pComponentPrivate->eIdleToLoad = nParam1;
             pComponentPrivate->eExecuteToIdle = nParam1;
             nRet = write(pComponentPrivate->cmdPipe[VIDDEC_PIPE_WRITE], &Cmd, sizeof(Cmd));
@@ -826,72 +841,74 @@
         }
         case OMX_IndexParamVideoProfileLevelQuerySupported:
             {
-			        VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
-                                OMX_U32 nNumberOfProfiles = 0;
-                                OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
-			        pParamProfileLevel->nPortIndex = pComponentPrivate->pInPortDef->nPortIndex;
+                VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
+                OMX_U32 nNumberOfProfiles = 0;
+                OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
+                pParamProfileLevel->nPortIndex = pComponentPrivate->pInPortDef->nPortIndex;
 
-				/* Choose table based on compression format */
-				switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat)
-				{
-				case OMX_VIDEO_CodingH263:
-				    pProfileLevel = SupportedH263ProfileLevels;
-                                    nNumberOfProfiles = sizeof(SupportedH263ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
-				    break;
-				case OMX_VIDEO_CodingMPEG4:
-				    pProfileLevel = SupportedMPEG4ProfileLevels;
-                                    nNumberOfProfiles = sizeof(SupportedMPEG4ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
-				    break;
-				case OMX_VIDEO_CodingAVC:
-				    pProfileLevel = SupportedAVCProfileLevels;
-                                    nNumberOfProfiles = sizeof(SupportedAVCProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
-				    break;
-                                default:
-                                    return OMX_ErrorBadParameter;
-				}
+                /* Choose table based on compression format */
+                switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat)
+                {
+                   case OMX_VIDEO_CodingH263:
+					    pProfileLevel = SupportedH263ProfileLevels;
+	                    nNumberOfProfiles = sizeof(SupportedH263ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
+                      break;
+                   case OMX_VIDEO_CodingMPEG4:
+					    pProfileLevel = SupportedMPEG4ProfileLevels;
+	                    nNumberOfProfiles = sizeof(SupportedMPEG4ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
+                      break;
+                   case OMX_VIDEO_CodingAVC:
+					    pProfileLevel = SupportedAVCProfileLevels;
+                        nNumberOfProfiles = sizeof(SupportedAVCProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
+                      break;
+                    default:
+                        return OMX_ErrorBadParameter;
+                  }
 
-                                if((pParamProfileLevel->nProfileIndex < 0) || (pParamProfileLevel->nProfileIndex >= (nNumberOfProfiles - 1)))
-                                    return OMX_ErrorBadParameter;
+                if((pParamProfileLevel->nProfileIndex < 0) || (pParamProfileLevel->nProfileIndex >= (nNumberOfProfiles - 1)))
+                    return OMX_ErrorBadParameter;
+                  /* Point to table entry based on index */
+                  pProfileLevel += pParamProfileLevel->nProfileIndex;
 
-				/* Point to table entry based on index */
-				pProfileLevel += pParamProfileLevel->nProfileIndex;
-
-				/* -1 indicates end of table */
-				if(pProfileLevel->nProfile != -1) {
-				    pParamProfileLevel->eProfile = pProfileLevel->nProfile;
-				    pParamProfileLevel->eLevel = pProfileLevel->nLevel;
-					eError = OMX_ErrorNone;
-				}
-				else {
-				    eError = OMX_ErrorNoMore;
-				}
-				break;
-	   }
+                  /* -1 indicates end of table */
+                  if(pProfileLevel->nProfile != -1) {
+                     pParamProfileLevel->eProfile = pProfileLevel->nProfile;
+                     pParamProfileLevel->eLevel = pProfileLevel->nLevel;
+                     eError = OMX_ErrorNone;
+                  }
+                  else {
+                     eError = OMX_ErrorNoMore;
+                  }
+                  break;
+                  }
         case OMX_IndexParamVideoProfileLevelCurrent:
-	   {
-			OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
-			if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
-				pParamProfileLevel->eProfile = pComponentPrivate->pH264->eProfile;
-				pParamProfileLevel->eLevel = pComponentPrivate->pH264->eLevel;
-			}
-			else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
-				pParamProfileLevel->eProfile = pComponentPrivate->pMpeg4->eProfile;
-				pParamProfileLevel->eLevel = pComponentPrivate->pMpeg4->eLevel;
-			}
-			else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
-				pParamProfileLevel->eProfile = pComponentPrivate->pH263->eProfile;
-				pParamProfileLevel->eLevel = pComponentPrivate->pH263->eLevel;
-			}
-			else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
-				pParamProfileLevel->eProfile = pComponentPrivate->pMpeg2->eProfile;
-				pParamProfileLevel->eLevel = pComponentPrivate->pMpeg2->eLevel;
-			}
-			else {
-                                OMX_ERROR4(pComponentPrivate->dbg, "Error in Getparameter OMX_IndexParamVideoProfileLevelCurrent \n");
-				eError = OMX_ErrorBadParameter;
-			}
-		}
-		     break;
+        {
+           OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
+           if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
+           LOGW("Getparameter OMX_IndexParamVideoProfileLevelCurrent AVC");
+           pParamProfileLevel->eProfile = pComponentPrivate->pH264->eProfile;
+           pParamProfileLevel->eLevel = pComponentPrivate->pH264->eLevel;
+        }
+        else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
+           LOGW("Getparameter OMX_IndexParamVideoProfileLevelCurrent MPEG4");
+           pParamProfileLevel->eProfile = pComponentPrivate->pMpeg4->eProfile;
+           pParamProfileLevel->eLevel = pComponentPrivate->pMpeg4->eLevel;
+        }
+        else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
+           LOGW("Getparameter OMX_IndexParamVideoProfileLevelCurrent H.263");
+           pParamProfileLevel->eProfile = pComponentPrivate->pH263->eProfile;
+           pParamProfileLevel->eLevel = pComponentPrivate->pH263->eLevel;
+        }
+        else if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG2) {
+           pParamProfileLevel->eProfile = pComponentPrivate->pMpeg2->eProfile;
+           pParamProfileLevel->eLevel = pComponentPrivate->pMpeg2->eLevel;
+        }
+        else {
+           LOGD("Error in Getparameter OMX_IndexParamVideoProfileLevelCurrent");
+           eError = OMX_ErrorBadParameter;
+         }
+      }
+      break;
         case OMX_IndexParamStandardComponentRole:
             if (ComponentParameterStructure != NULL) {
                 pRole = (OMX_PARAM_COMPONENTROLETYPE *)ComponentParameterStructure;
@@ -1463,11 +1480,16 @@
                 if(eError != OMX_ErrorNone) {
                     goto EXIT;
                 }
-
+#ifdef ANDROID
                 /* Set format according with hw accelerated rendering */
                 if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT422) {
                     eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_INTERLEAVED422);
                 }
+#else
+                if( pComponentPrivate->pOutPortFormat->eColorFormat != VIDDEC_COLORFORMAT420) {
+                    eError = VIDDEC_Load_Defaults(pComponentPrivate, VIDDEC_INIT_PLANAR420);
+                }
+#endif
                 memcpy( (void *)&pComponentPrivate->componentRole, (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
             } 
             else {
@@ -1511,9 +1533,11 @@
             if (mDebugFps == OMX_FALSE) {
                 if (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
                         pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263){
-                        pComponentPrivate->pDeblockingParamType->bDeblocking = 
-                            ((OMX_PARAM_DEBLOCKINGTYPE*)pCompParam)->bDeblocking;
-			 LOGD("Deblocking Enable");
+                        /*pComponentPrivate->pDeblockingParamType->bDeblocking = 
+                            ((OMX_PARAM_DEBLOCKINGTYPE*)pCompParam)->bDeblocking;*/
+                        /*codec is not supporting deblocking by now*/
+                        pComponentPrivate->pDeblockingParamType->bDeblocking = OMX_FALSE;
+                        eError = OMX_ErrorUnsupportedIndex;
                     break;
                 }
             }
@@ -1552,60 +1576,59 @@
         case OMX_IndexConfigAudioChannelVolume:
         case OMX_IndexConfigFlashControl:
         case OMX_IndexParamVideoProfileLevelQuerySupported:
-		     break;
+           break;
         case OMX_IndexParamVideoProfileLevelCurrent:
-                     {
-                         VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
-                         OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pCompParam;
+        {
+           VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
+           OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pCompParam;
 
-                         /* Choose table based on compression format */
-                         switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat)
-                         {
-                             case OMX_VIDEO_CodingH263:
-                                 pProfileLevel = SupportedH263ProfileLevels;
-                                 break;
-                             case OMX_VIDEO_CodingMPEG4:
-                                 pProfileLevel = SupportedMPEG4ProfileLevels;
-                                 break;
-                             case OMX_VIDEO_CodingAVC:
-                                 pProfileLevel = SupportedAVCProfileLevels;
-                                 break;
-                             default:
-                                 return OMX_ErrorBadParameter;
-                         }
+           /* Choose table based on compression format */
+           switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat)
+           {
+              case OMX_VIDEO_CodingH263:
+                 pProfileLevel = SupportedH263ProfileLevels;
+                 break;
+              case OMX_VIDEO_CodingMPEG4:
+                 pProfileLevel = SupportedMPEG4ProfileLevels;
+                 break;
+              case OMX_VIDEO_CodingAVC:
+                 pProfileLevel = SupportedAVCProfileLevels;
+                 break;
+             default:
+                 return OMX_ErrorBadParameter;
+            }
 
-                         /* Check validity of profile & level parameters */
-                         while((pProfileLevel->nProfile != (OMX_S32)pParamProfileLevel->eProfile) ||
-                                 (pProfileLevel->nLevel != (OMX_S32)pParamProfileLevel->eLevel)) {
-                             pProfileLevel++;
-                             if(pProfileLevel->nProfile == -1) break;
-                         }
+            /* Check validity of profile & level parameters */
+            while((pProfileLevel->nProfile != (OMX_S32)pParamProfileLevel->eProfile) ||
+                 (pProfileLevel->nLevel != (OMX_S32)pParamProfileLevel->eLevel)) {
+               pProfileLevel++;
+               if(pProfileLevel->nProfile == -1) break;
+             }
 
-                         if(pProfileLevel->nProfile != -1) {
-                             /* Update profile & level values in the compression format specific structure */
-                             switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat) {
-                                 case OMX_VIDEO_CodingH263:
-                                     pComponentPrivate->pH263->eProfile = pParamProfileLevel->eProfile;
-                                     pComponentPrivate->pH263->eLevel = pParamProfileLevel->eLevel;
-                                     break;
-                                 case OMX_VIDEO_CodingMPEG4:
-                                     pComponentPrivate->pMpeg4->eProfile = pParamProfileLevel->eProfile;
-                                     pComponentPrivate->pMpeg4->eLevel = pParamProfileLevel->eLevel;
-                                     break;
-                                 case OMX_VIDEO_CodingAVC:
-                                     pComponentPrivate->pH264->eProfile = pParamProfileLevel->eProfile;
-                                     pComponentPrivate->pH264->eLevel = pParamProfileLevel->eLevel;
-                                 default:
-                                     return OMX_ErrorBadParameter;
-                             }
-
-                             eError = OMX_ErrorNone;
-                         }
-                         else {
-                             eError = OMX_ErrorBadParameter;
-                         }
-                         break;
-                     }
+            if(pProfileLevel->nProfile != -1) {
+            /* Update profile & level values in the compression format specific structure */
+               switch(pComponentPrivate->pInPortDef->format.video.eCompressionFormat) {
+                  case OMX_VIDEO_CodingH263:
+                     pComponentPrivate->pH263->eProfile = pParamProfileLevel->eProfile;
+                     pComponentPrivate->pH263->eLevel = pParamProfileLevel->eLevel;
+                     break;
+                  case OMX_VIDEO_CodingMPEG4:
+                     pComponentPrivate->pMpeg4->eProfile = pParamProfileLevel->eProfile;
+                     pComponentPrivate->pMpeg4->eLevel = pParamProfileLevel->eLevel;
+                     break;
+                  case OMX_VIDEO_CodingAVC:
+                     pComponentPrivate->pH264->eProfile = pParamProfileLevel->eProfile;
+                     pComponentPrivate->pH264->eLevel = pParamProfileLevel->eLevel;
+                 default:
+                     return OMX_ErrorBadParameter;
+               }
+               eError = OMX_ErrorNone;
+            }
+            else {
+               eError = OMX_ErrorBadParameter;
+            }
+            break;
+            }
 
         case OMX_IndexConfigVideoBitrate:
         case OMX_IndexConfigVideoFramerate:
@@ -2248,11 +2271,12 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE VIDDEC_GetState (OMX_HANDLETYPE hComponent,
+static OMX_ERRORTYPE VIDDEC_GetState (OMX_HANDLETYPE hComponent, 
                                       OMX_STATETYPE* pState)
 {
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
     OMX_COMPONENTTYPE* pHandle = NULL;
+
     VIDDEC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     struct timespec abs_time = {0,0};
     int nPendingStateChangeRequests = 0;
@@ -2280,20 +2304,20 @@
            }
 
            /* No pending state transitions */
-	   *pState = ((VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->eState;
+          *pState = ((VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->eState;
             eError = OMX_ErrorNone;
         }
         else {
-           /* Wait for component to complete state transition */
+                  /* Wait for component to complete state transition */
            clock_gettime(CLOCK_REALTIME, &abs_time);
            abs_time.tv_sec += mutex_timeout;
            abs_time.tv_nsec = 0;
-           ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
+          ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
            if (!ret) {
               /* Component has completed state transitions*/
               *pState = ((VIDDEC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->eState;
               if(pthread_mutex_unlock(&pComponentPrivate->mutexStateChangeRequest)) {
-                 return OMX_ErrorUndefined;
+                  return OMX_ErrorUndefined;
               }
               eError = OMX_ErrorNone;
            }
@@ -2307,7 +2331,7 @@
      else {
         eError = OMX_ErrorInvalidComponent;
         *pState = OMX_StateInvalid;
-    }
+     }
 
     return eError;
 }
@@ -2342,8 +2366,8 @@
     pHandle = (OMX_COMPONENTTYPE *)pComponent;
     pComponentPrivate = (VIDDEC_COMPONENT_PRIVATE *)pHandle->pComponentPrivate;
 
-    OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p pBuffer 0x%p Index %lu\n",pComponent,
-            pBuffHead, pBuffHead->nInputPortIndex);
+    OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p pBuffer 0x%p Index %lu  state %x  nflags  %x  isfirst %x\n",pComponent,
+            pBuffHead, pBuffHead->nInputPortIndex,pComponentPrivate->eState,pBuffHead->nFlags,pComponentPrivate->bFirstHeader);
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedFrame(pComponentPrivate->pPERF,
@@ -2376,20 +2400,27 @@
     pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pInputPortPrivate;
     ret = pBufferPrivate->eBufferOwner;
     pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
-    android_atomic_inc(&pComponentPrivate->nInputBCountApp);
+    eError = IncrementCount (&(pComponentPrivate->nCountInputBFromApp), &(pComponentPrivate->mutexInputBFromApp));
+    if (eError != OMX_ErrorNone) {
+        return eError;
+    }
 
     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);
 
     ret = write (pComponentPrivate->filled_inpBuf_Q[VIDDEC_PIPE_WRITE], &(pBuffHead), sizeof(pBuffHead));
     if (ret == -1) {
+        /*like function returns error buffer still with Client IL*/
+        pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
         OMX_PRCOMM4(pComponentPrivate->dbg, "Error in Writing to the Data pipe\n");
+        DecrementCount (&(pComponentPrivate->nCountInputBFromApp), &(pComponentPrivate->mutexInputBFromApp));
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
 
 EXIT:
-    OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting 0x%x\n",eError);
+    if (pComponentPrivate)
+        OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting 0x%x\n", eError);
     return eError;
 }
 
@@ -2458,20 +2489,27 @@
     pBufferPrivate = (VIDDEC_BUFFER_PRIVATE* )pBuffHead->pOutputPortPrivate;
     ret = pBufferPrivate->eBufferOwner;
     pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_COMPONENT;
-    android_atomic_inc(&pComponentPrivate->nOutputBCountApp);
+    eError = IncrementCount (&(pComponentPrivate->nCountOutputBFromApp), &(pComponentPrivate->mutexOutputBFromApp));
+    if (eError != OMX_ErrorNone) {
+        return eError;
+    }
     pBuffHead->nFilledLen = 0;
-    pBuffHead->nFlags = 0;  // Clear flags
+    pBuffHead->nFlags = 0;
     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));
     if (ret == -1) {
+        /*like function returns error buffer still with Client IL*/
+        pBufferPrivate->eBufferOwner = VIDDEC_BUFFER_WITH_CLIENT;
         OMX_PRCOMM4(pComponentPrivate->dbg, "Error in Writing to the Data pipe\n");
+        DecrementCount (&(pComponentPrivate->nCountOutputBFromApp), &(pComponentPrivate->mutexOutputBFromApp));
         eError = OMX_ErrorHardware;
         goto EXIT;
     }
 
 EXIT:
-    OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting 0x%x\n",eError);
+    if (pComponentPrivate)
+        OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting 0x%x\n", eError);
     return eError;
 }
 
@@ -2548,7 +2586,6 @@
 
     if (pComponentPrivate->pInternalConfigBufferAVC != NULL)
       free(pComponentPrivate->pInternalConfigBufferAVC);
-
     for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) {
         if(pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr != NULL) {
             OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
@@ -2564,16 +2601,14 @@
         }
     }
 
-
     for (iCount = 0; iCount < MAX_PRIVATE_BUFFERS; iCount++) {
         if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr != NULL) {
             OMX_BUFFERHEADERTYPE* pBuffHead = NULL;
-            OMX_U8* pTemp = NULL;
             pBuffHead = pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr;
             if(pBuffHead != NULL){
-                if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->bAllocByComponent == OMX_TRUE){
+	         if(pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->bAllocByComponent == OMX_TRUE){
                     OMX_MEMFREE_STRUCT_DSPALIGN(pBuffHead->pBuffer,OMX_U8);
-                }
+	         }
                 free(pBuffHead);
                 pBuffHead = NULL;
                 pComponentPrivate->pCompPort[VIDDEC_OUTPUT_PORT]->pBufferPrivate[iCount]->pBufferHdr = NULL;
@@ -2783,6 +2818,10 @@
     VIDDEC_PTHREAD_SEMAPHORE_DESTROY(pComponentPrivate->sInSemaphore);
     VIDDEC_PTHREAD_SEMAPHORE_DESTROY(pComponentPrivate->sOutSemaphore);
 #endif
+    pthread_mutex_destroy(&(pComponentPrivate->mutexInputBFromApp));
+    pthread_mutex_destroy(&(pComponentPrivate->mutexOutputBFromApp));
+    pthread_mutex_destroy(&(pComponentPrivate->mutexInputBFromDSP));
+    pthread_mutex_destroy(&(pComponentPrivate->mutexOutputBFromDSP));
 
     pthread_mutex_destroy(&pComponentPrivate->mutexStateChangeRequest);
     pthread_cond_destroy(&pComponentPrivate->StateChangeCondition);
@@ -2975,7 +3014,9 @@
 #endif
     }
 EXIT:
-    OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", eError);
+    if (pComponentPrivate)
+        OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", \
+                                                         eError);
     return eError;  
 }
 
@@ -3142,8 +3183,14 @@
                              PERF_ModuleMemory);
 #endif
 
-           OMX_FREE_BUFFER_VIDDEC(pBuffHead, pCompPort);
-
+      /* Freeing the original buffer position were data buffer was allocated */
+           if(pBufferPrivate->pOriginalBuffer != NULL){
+              pBuffHead->pBuffer = pBufferPrivate->pOriginalBuffer;
+              pBufferPrivate->pOriginalBuffer = NULL;
+              OMX_FREE_VIDDEC(pBuffHead->pBuffer);
+           } else{
+               OMX_FREE_BUFFER_VIDDEC(pBuffHead, pCompPort);
+           }
         }
     }
 
@@ -3242,7 +3289,9 @@
     }
 
 EXIT:
-    OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", eError);
+    if (pComponentPrivate)
+        OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", \
+                                                        eError);
     return eError;
 }
 
@@ -3283,6 +3332,7 @@
     OMX_PRBUFFER1(pComponentPrivate->dbg, "+++Entering pHandle 0x%p pBuffHead 0x%p nPortIndex 0x%lx nSizeBytes 0x%lx\n",
         hComponent, *pBuffHead, nPortIndex, nSizeBytes);
 
+
     if (nPortIndex == pComponentPrivate->pInPortFormat->nPortIndex) {
         pCompPort = pComponentPrivate->pCompPort[VIDDEC_INPUT_PORT];
         pBufferCnt = pCompPort->nBufferCnt;
@@ -3314,10 +3364,8 @@
     memset(*pBuffHead, 0, sizeof(OMX_BUFFERHEADERTYPE));
     OMX_CONF_INIT_STRUCT(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr, OMX_BUFFERHEADERTYPE, pComponentPrivate->dbg);
     /* Allocate Video Decoder buffer */
-    OMX_MALLOC_BUFFER_VIDDEC(pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer,
-			nSizeBytes,
-			pCompPort->pBufferPrivate[pBufferCnt]->pOriginalBuffer);
-    if (!pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer) {
+    OMX_MALLOC_STRUCT_SIZED((*pBuffHead)->pBuffer, OMX_U8, OMX_GET_DATABUFF_SIZE(nSizeBytes), NULL);
+    if (!((*pBuffHead)->pBuffer)) {
         eError = OMX_ErrorInsufficientResources;
         pComponentPrivate->cbInfo.EventHandler(pComponentPrivate->pHandle,
                                                pComponentPrivate->pHandle->pApplicationPrivate,
@@ -3327,8 +3375,12 @@
                                                NULL);
         goto EXIT;
     }
+    /* Align and add padding for data buffer */
+    pCompPort->pBufferPrivate[pBufferCnt]->pOriginalBuffer = (*pBuffHead)->pBuffer;
+    (*pBuffHead)->pBuffer += VIDDEC_PADDING_HALF;
+    OMX_ALIGN_BUFFER((*pBuffHead)->pBuffer, VIDDEC_ALIGNMENT);
 #ifdef VIDDEC_WMVPOINTERFIXED
-    pCompPort->pBufferPrivate[pBufferCnt]->pTempBuffer = (pCompPort->pBufferPrivate[pBufferCnt]->pBufferHdr->pBuffer);
+    pCompPort->pBufferPrivate[pBufferCnt]->pTempBuffer = (*pBuffHead)->pBuffer;
     (*pBuffHead)->nOffset = 0;
 #endif
 
@@ -3424,7 +3476,9 @@
     }
 
 EXIT:
-    OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", eError);
+    if (pComponentPrivate)
+        OMX_PRBUFFER1(pComponentPrivate->dbg, "---Exiting eError 0x%x\n", \
+                                                         eError);
     return eError;
 }
 
diff --git a/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_CustomCmd.h b/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_CustomCmd.h
index 3a3d110..4a599ff 100644
--- a/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_CustomCmd.h
+++ b/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_CustomCmd.h
@@ -28,13 +28,13 @@
 /**
 * @file OMX_VideoEnc_CustomCmd.h
 *
-* This is an header file for an video Mpeg4 encoder that is fully 
+* This is an header file for an video Mpeg4 encoder that is fully
 * compliant with the OMX Video specification.
-* This the file that the application that uses OMX would include 
+* This the file that the application that uses OMX would include
 * in its code.
 *
 * @path $(CSLPATH)\
-* 
+*
 * @rev 0.1
 */
 /* -------------------------------------------------------------------------- */
@@ -42,13 +42,13 @@
 #ifndef OMX_VIDEOENC_CUSTOMCMD_H
 #define OMX_VIDEOENC_CUSTOMCMD_H
 
-#define VIDENC_PARAM_VBVSIZE               "OMX.TI.VideoEncode.Param.VBVSize"; 
-#define VIDENC_PARAM_DEBLOCK_FILTER        "OMX.TI.VideoEncode.Param.DeblockFilter"; 
-#define VIDENC_CONFIG_FORCE_I_FRAME        "OMX.TI.VideoEncode.Config.ForceIFrame"; 
-#define VIDENC_CONFIG_INTRA_FRAME_INTERVAL "OMX.TI.VideoEncode.Config.IntraFrameInterval"; 
-#define VIDENC_CONFIG_TARGET_FRAMERATE     "OMX.TI.VideoEncode.Config.TargetFrameRate"; 
-#define VIDENC_CONFIG_QPI                  "OMX.TI.VideoEncode.Config.QPI"; 
-#define VIDENC_CONFIG_AIRRATE              "OMX.TI.VideoEncode.Config.AIRRate"; 
+#define VIDENC_PARAM_VBVSIZE               "OMX.TI.VideoEncode.Param.VBVSize";
+#define VIDENC_PARAM_DEBLOCK_FILTER        "OMX.TI.VideoEncode.Param.DeblockFilter";
+#define VIDENC_CONFIG_FORCE_I_FRAME        "OMX.TI.VideoEncode.Config.ForceIFrame";
+#define VIDENC_CONFIG_INTRA_FRAME_INTERVAL "OMX.TI.VideoEncode.Config.IntraFrameInterval";
+#define VIDENC_CONFIG_TARGET_FRAMERATE     "OMX.TI.VideoEncode.Config.TargetFrameRate";
+#define VIDENC_CONFIG_QPI                  "OMX.TI.VideoEncode.Config.QPI";
+#define VIDENC_CONFIG_AIRRATE              "OMX.TI.VideoEncode.Config.AIRRate";
 #define VIDENC_CONFIG_TARGET_BITRATE       "OMX.TI.VideoEncode.Config.TargetBitRate";
 
 #endif /* OMX_VIDEOENC_CUSTOMCMD_H */
diff --git a/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_DSP.h b/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_DSP.h
index 489f3f6..6100ead 100644
--- a/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_DSP.h
+++ b/omx/video/src/openmax_il/video_encode/inc/OMX_VideoEnc_DSP.h
@@ -28,13 +28,13 @@
 /**
 * @file OMX_VideoEnc_DSP.h
 *
-* This is a header file for a TI OMX video component that is fully 
+* This is a header file for a TI OMX video component that is fully
 * compliant with the OMX Video specification.
-* This the file that the application that uses OMX would include 
+* This the file that the application that uses OMX would include
 * in its code.
 *
 * @path $(CSLPATH)\
-* 
+*
 * @rev 0.1
 */
 /* -------------------------------------------------------------------------- */
@@ -42,8 +42,8 @@
 #ifndef OMX_VIDEOENC_DSP__H
 #define OMX_VIDEOENC_DSP__H
 
-#define OMX_H264ENC_NUM_DLLS 3 
-#define OMX_MP4ENC_NUM_DLLS  3 
+#define OMX_H264ENC_NUM_DLLS 3
+#define OMX_MP4ENC_NUM_DLLS  3
 #define MAXNUMSLCGPS      8  /*< max. number of slice groups*/
 
 #ifndef UNDER_CE
@@ -51,8 +51,8 @@
     #define MP4_ENC_NODE_DLL  "m4venc_sn.dll64P"
     #define USN_DLL           "usn.dll64P"
 #else
-    #define H264_ENC_NODE_DLL "/windows/h264venc_sn.dll64P"    
-    #define MP4_ENC_NODE_DLL  "/windows/m4venc_sn.dll64P"    
+    #define H264_ENC_NODE_DLL "/windows/h264venc_sn.dll64P"
+    #define MP4_ENC_NODE_DLL  "/windows/m4venc_sn.dll64P"
     #define USN_DLL           "/windows/usn.dll64P"
 #endif
 
@@ -84,7 +84,7 @@
 }IH264VENC_StreamFormat;
 
 /*H264 Encoder Specific Error Code bits*/
-typedef enum 
+typedef enum
 {
   IH264VENC_SEQPARAMERR=0,          /* Indicates error during sequence parameter set generation*/
   IH264VENC_PICPARAMERR,            /* Indicates error during picture parameter set generation*/
@@ -99,7 +99,7 @@
 } IH264VENC_ErrorBit;
 
 /* H.264 Encoder Slice and Picture level Loop Filter Control*/
-typedef enum 
+typedef enum
 {
   FILTER_ALL_EDGES = 0,             /* Enable filtering of all the edges*/
   DISABLE_FILTER_ALL_EDGES,         /* Disable filtering of all the edges*/
@@ -109,7 +109,7 @@
 
 
 /* H.264 Encoder Slice level Control for Intra4x4 Modes */
-typedef enum 
+typedef enum
 {
   INTRA4x4_NONE = 0 ,   /* Disable Intra4x4 modes */
   INTRA4x4_ISLICES  ,   /* Enable Intra4x4 modes only in I Slices*/
@@ -150,7 +150,7 @@
   IH264_INTRAREFRESH_CYCLIC_SLICES  ,  /* Insters Intra Slices in a cyclic fashion: */
                                        /* no of intra slices is equal to sliceRefreshRowNumber*/
   IH264_INTRAREFRESH_RDOPT_MBS         /* position of intra macro blocks is intelligently */
-                                       /* chosen by encoder, but the number of forcely coded*/ 
+                                       /* chosen by encoder, but the number of forcely coded*/
                                        /* intra macro blocks in a frame is gaurnteed to be */
                                        /* equal to totalMbsInFrame/airMbPeriod : Not valid for DM6446*/
 
@@ -201,10 +201,10 @@
     unsigned char  ucProfile;
     unsigned char  ucLevel;
 
-	unsigned short usNalCallback;
+    unsigned short usNalCallback;
 
-	unsigned int   ulEncodingPreset;
-	unsigned int   ulRcAlgo;
+    unsigned int   ulEncodingPreset;
+    unsigned int   ulRcAlgo;
     unsigned short endArgs;
 } H264VE_GPP_SN_Obj_CreatePhase;
 
@@ -258,46 +258,45 @@
     void   (*pfNalUnitCallBack)(OMX_U32 *pNalu, OMX_U32 *pPacketSizeInBytes, void *pContext) ; /* Function pointer of the call-back function to be used by Encoder*/
     void *pContext                          ; /*pointer to context structure used during callback*/
     /*Following Parameter are related to Arbitrary Slice Ordering (ASO)*/
-    OMX_U32 numSliceASO                    ; /* Number of valid enteries in asoSliceOrder array valid range is [0,8], 
+    OMX_U32 numSliceASO                    ; /* Number of valid enteries in asoSliceOrder array valid range is [0,8],
                                                where 0 and 1 doesn't have any effect*/
     OMX_U32 asoSliceOrder[MAXNUMSLCGPS]    ; /* Array containing the order of slices in which they should
                                                 be present in bit-stream. vaild enteries are [0, any entry lesser than numSlicesASO]*/
     /* Following Parameter are related to Flexible macro block ordering (FMO)*/
     OMX_U32 numSliceGroups                 ; /* Total Number of slice groups, valid enteries are [0,8]*/
     OMX_U32 sliceGroupMapType              ; /* Slice GroupMapType : For Valid enteries see IH264VENC_SliceGroupMapType*/
-    OMX_U32 sliceGroupChangeDirectionFlag  ; /* Slice Group Change Direction Flag: Only valid when sliceGroupMapType 
-                                                 is equal to IH264_RASTER_SCAN_SLICE_GRP. 
+    OMX_U32 sliceGroupChangeDirectionFlag  ; /* Slice Group Change Direction Flag: Only valid when sliceGroupMapType
+                                                 is equal to IH264_RASTER_SCAN_SLICE_GRP.
                                                  For valid values refer IH264VENC_SliceGroupChangeDirection*/
-    OMX_U32 sliceGroupChangeRate           ; /* Slice Group Change Rate: Only valid when sliceGroupMapType 
-                                              is equal to IH264_RASTER_SCAN_SLICE_GRP. 
+    OMX_U32 sliceGroupChangeRate           ; /* Slice Group Change Rate: Only valid when sliceGroupMapType
+                                              is equal to IH264_RASTER_SCAN_SLICE_GRP.
                                                valid values are : [0, factor of number of Mbs in a row]*/
-    OMX_U32 sliceGroupChangeCycle          ; /* Slice Group Change Cycle: Only valid when sliceGroupMapType 
-                                               is equal to IH264_RASTER_SCAN_SLICE_GRP. 
+    OMX_U32 sliceGroupChangeCycle          ; /* Slice Group Change Cycle: Only valid when sliceGroupMapType
+                                               is equal to IH264_RASTER_SCAN_SLICE_GRP.
                                                Valid values can be 0 to numMbsRowsInPicture, also constrained
                                                by sliceGroupChangeRate*sliceGroupChangeCycle < totalMbsInFrame*/
-    OMX_U32 sliceGroupParams[MAXNUMSLCGPS] ; /* This field is useful in case of sliceGroupMapType equal to either 
+    OMX_U32 sliceGroupParams[MAXNUMSLCGPS] ; /* This field is useful in case of sliceGroupMapType equal to either
                                               IH264_INTERLEAVED_SLICE_GRP or IH264_FOREGRND_WITH_LEFTOVER_SLICE_GRP
                                               In both cases it has different meaning:
                                               In case of IH264_INTERLEAVED_SLICE_GRP:
-                                              The i-th entery in this array is used to specify the number of consecutive 
-                                               slice group macroblocks to be assigned to the i-th slice group in 
+                                              The i-th entery in this array is used to specify the number of consecutive
+                                               slice group macroblocks to be assigned to the i-th slice group in
                                                raster scan order of slice group macroblock units.
                                                Valid values are 0 to totalMbsInFrame again constrained by sum of all the elements
                                                shouldn't exceed totalMbsInFrame
                                                In case of IH264_FOREGRND_WITH_LEFTOVER_SLICE_GRP:
-                                               First entry in the array specify the start position of foreground region in terms 
+                                               First entry in the array specify the start position of foreground region in terms
                                                of macroblock number, valid values are [0, totalMbsInFrame-1]
-                                               Second entry in the array specify the end position of foreground region in terms 
+                                               Second entry in the array specify the end position of foreground region in terms
                                                of macroblock number, valid values are [0, totalMbsInFrame-1] with following constrains:
                                                endPos > startPos && endPos%mbsInOneRow > startPos%mbsInOneRow*/
 } IH264VENC_DynamicParams;
 
-
 /* H264 Encoder DSP s/n run-time input parameters */
 typedef struct H264VE_GPP_SN_UALGInputParams
 {
 
-    IH264VENC_DynamicParams H264VENC_TI_DYNAMICPARAMS; 
+    IH264VENC_DynamicParams H264VENC_TI_DYNAMICPARAMS;
     OMX_U32   ulFrameIndex;
 
 } H264VE_GPP_SN_UALGInputParams;
@@ -305,11 +304,11 @@
 /* H264 Encoder DSP s/n run-time output parameters */
 typedef struct H264VE_GPP_SN_UALGOutputParams {
     OMX_U32   ulBitstreamSize;
-	OMX_S32   lFrameType;
-	OMX_U32   ulNALUnitsPerFrame;	/*Number of total NAL units per frame*/
-	OMX_U32   ulNALUnitsSizes[240];
-	OMX_U32   ulFrameIndex;			/*Gives the number of the input frame wich NAL unit belongs*/
-	OMX_U32   ulNALUnitIndex;		/*Number of current NAL unit inside the frame*/
+    OMX_S32   lFrameType;
+    OMX_U32   ulNALUnitsPerFrame;   /*Number of total NAL units per frame*/
+    OMX_U32   ulNALUnitsSizes[240];
+    OMX_U32   ulFrameIndex;         /*Gives the number of the input frame wich NAL unit belongs*/
+    OMX_U32   ulNALUnitIndex;       /*Number of current NAL unit inside the frame*/
 } H264VE_GPP_SN_UALGOutputParams;
 
 /* MPEG4/H263 Encoder DSP s/n create phase arguments */
@@ -344,8 +343,8 @@
     unsigned int   ulMaxDelay;
 
 #ifndef MODE_3410
-	unsigned int   ulVbvParamEnable;	
-	unsigned int   ulH263SliceMode;	
+    unsigned int   ulVbvParamEnable;
+    unsigned int   ulH263SliceMode;
 #endif
 
     unsigned int   ulUseGOV;
@@ -375,13 +374,13 @@
     unsigned int   ulHalfPel;
     unsigned int   ulACPred;
     unsigned int   ul4MV;
-	unsigned int   uluseUMV;
+    unsigned int   uluseUMV;
     unsigned int   ulMVDataEnable;
     unsigned int   ulResyncDataEnable;
 
-	unsigned int   ulQPInter;           	/* default QP for P frame, range 1 to 31  */	
-	unsigned int   ulLastFrame;
-	unsigned int   ulcapturewidth;
+    unsigned int   ulQPInter;               /* default QP for P frame, range 1 to 31  */
+    unsigned int   ulLastFrame;
+    unsigned int   ulcapturewidth;
     unsigned int   ulQpMax;
     unsigned int   ulQpMin;
 } MP4VE_GPP_SN_UALGInputParams;
@@ -390,24 +389,24 @@
 typedef struct MP4VE_GPP_SN_UALGOutputParams {
     unsigned int   ulBitstreamSize;
     unsigned int  cFrameType;/*changed from unsigned char  as SN did*/
-	unsigned int   mvDataSize;
+    unsigned int   mvDataSize;
     unsigned int   numPackets;
     #ifdef MODE_3410
-	unsigned char   MVData[9600];
+    unsigned char   MVData[9600];
     unsigned char   ResyncData[4800];
-	#else
-	unsigned char   MVData[12960];
-    unsigned char   ResyncData[1620];
-	#endif
+    #else
+    unsigned char   MVData[12960];
+    unsigned int    ResyncData[1620];
+    #endif
 } MP4VE_GPP_SN_UALGOutputParams;
 
-/* 
+/*
  *  ======== IVIDEO_RateControlPreset ========
  *  IVIDEO_DEFAULT => Default rate control of encoder
- *  IVIDEO_LOW_DELAY => CBR rate control for video conferencing 
- *  IVIDEO_STORAGE => VBR rate control for local storage (DVD) recording 
+ *  IVIDEO_LOW_DELAY => CBR rate control for video conferencing
+ *  IVIDEO_STORAGE => VBR rate control for local storage (DVD) recording
  *  IVIDEO_TWOPASS => two pass rate control for non real time applications
- *  IVIDEO_USER_DEFINED => User defined configuration using advanced parameters 
+ *  IVIDEO_USER_DEFINED => User defined configuration using advanced parameters
  */
 typedef enum {
     IVIDEO_LOW_DELAY =1, IVIDEO_STORAGE, IVIDEO_TWOPASS, IVIDEO_NONE, IVIDEO_USER_DEFINED
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 e69dd5f..5e5470f 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
@@ -22,13 +22,13 @@
 *             Texas Instruments OMAP(TM) Platform Software
 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
 *
-*  Use of this software is controlled by the terms and conditions found 
+*  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * =========================================================================== */
 /**
 * @file OMX_VideoEnc_Utils.h
 *
-* This file implements OMX Component for MPEG-4 encoder that 
+* This file implements OMX Component for MPEG-4 encoder that
 * is fully compliant with the OMX specification 1.5.
 *
 * @path  $(CSLPATH)\inc
@@ -36,13 +36,13 @@
 * @rev  0.1
 */
 /* -------------------------------------------------------------------------- */
-/* ============================================================================= 
-*! 
-*! Revision History 
+/* =============================================================================
+*!
+*! Revision History
 *! ================================================================
 *!
-*! 02-Feb-2006 mf: Revisions appear in reverse chronological order; 
-*! that is, newest first.  The date format is dd-Mon-yyyy.  
+*! 02-Feb-2006 mf: Revisions appear in reverse chronological order;
+*! that is, newest first.  The date format is dd-Mon-yyyy.
 * =========================================================================== */
 
 #ifndef OMX_VIDEOENC_UTILS__H
@@ -60,6 +60,10 @@
     #endif
 #include <OMX_TI_Debug.h>
 #include <OMX_Component.h>
+#ifdef LOG_TAG
+    #undef LOG_TAG
+#endif
+#define LOG_TAG "TI_OMX_VideoEnc"
 
 #ifdef UNDER_CE
     #include <oaf_debug.h>
@@ -74,10 +78,12 @@
 #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
 
+#define VIDENC_MAXBITRATES 7
 
-#if 1 
+#if 1
     #define GPP_PRIVATE_NODE_HEAP
 #endif
 
@@ -88,21 +94,23 @@
 #if 1
     #define __KHRONOS_CONF_1_1__
 #endif
-    
+
 #define KHRONOS_1_2
 
-#define VIDENC_MAX_COMPONENT_TIMEOUT 0xFFFFFFFF 
+#define VIDENC_MAX_COMPONENT_TIMEOUT 0xFFFFFFFF
 #define OMX_NOPORT 0xFFFFFFFE
 #define MAXNUMSLCGPS 8  /*< max. number of slice groups*/
-/* Remove after OMX 1.1 migration */ 
+/* Remove after OMX 1.1 migration */
 #ifndef __KHRONOS_CONF_1_1__
-    #define OMX_BUFFERFLAG_SYNCFRAME 0x00000040 
+    #define OMX_BUFFERFLAG_SYNCFRAME 0x00000040
 #endif
 #define OMX_LFRAMETYPE_H264 1
 #define OMX_CFRAMETYPE_MPEG4 1
 /*Select Timeout */
 #define  VIDENC_TIMEOUT_SEC 120;
 #define  VIDENC_TIMEOUT_USEC 0;
+#define WVGA_MAX_WIDTH 854
+#define WVGA_MAX_HEIGHT WVGA_MAX_WIDTH
 
 /*
 * Definition of capabilities index and structure
@@ -121,7 +129,7 @@
     OMX_BOOL iOMXComponentUsesNALStartCode;
     OMX_BOOL iOMXComponentCanHandleIncompleteFrames;
     OMX_BOOL iOMXComponentUsesFullAVCFrames;
-} PV_OMXComponentCapabilityFlagsType; 
+} PV_OMXComponentCapabilityFlagsType;
 
 /*
  * Redirects control flow in an error situation.
@@ -136,7 +144,7 @@
 
 #define OMX_VIDENC_BAIL_IF_ERROR(_eError, _hComp)           \
 do {                                                        \
-    if(_eError != OMX_ErrorNone) {	\
+    if(_eError != OMX_ErrorNone) {  \
         _eError = OMX_VIDENC_HandleError(_hComp, _eError);  \
         if(_eError != OMX_ErrorNone) {                      \
             OMX_ERROR5(_hComp->dbg, "*Fatal Error : %x\n", _eError); \
@@ -164,10 +172,10 @@
 
 /*
  * Checking paramaters for non-NULL values.
- * The macro takes three parameters because inside the code the highest 
+ * The macro takes three parameters because inside the code the highest
  *   number of parameters passed for checking in a single instance is three.
- * In case one or two parameters are passed, the ramaining parameters 
- *   are set to 1 (or a nonzero value). 
+ * In case one or two parameters are passed, the ramaining parameters
+ *   are set to 1 (or a nonzero value).
  */
 #define OMX_CONF_CHECK_CMD(_ptr1, _ptr2, _ptr3)             \
 do {                                                        \
@@ -179,32 +187,32 @@
 
 /*
 * Initialize the Circular Buffer data. The Tail and Head pointers are NULL.
-*The number of nodes inside the circular buffer is equal to zero. 
+*The number of nodes inside the circular buffer is equal to zero.
 *Also the number of nodes that contains BufferData is iqual zero.
 *It should be in the ComponentInit call of the Component.
 */
 #define OMX_CONF_CIRCULAR_BUFFER_INIT(_pPrivateData_)       \
-do {                                                            \
+do {                                                        \
     (_pPrivateData_)->sCircularBuffer.pHead = NULL;         \
     (_pPrivateData_)->sCircularBuffer.pTail = NULL;         \
     (_pPrivateData_)->sCircularBuffer.nElements = 0;        \
-        (_pPrivateData_)->sCircularBuffer.nFillElements = 0;    \
+        (_pPrivateData_)->sCircularBuffer.nFillElements = 0;\
 } while(0)
 
 /*
-*Restart the Circular Buffer. The tail points to the same node as the head. The 
+*Restart the Circular Buffer. The tail points to the same node as the head. The
 *number of fill elements is set to zero. It should be put in the Idle->Execution
-*transition. 
+*transition.
 */
 #define OMX_CONF_CIRCULAR_BUFFER_RESTART(_sCircular_)       \
-do {                                                            \
+do {                                                        \
     (_sCircular_).pTail = (_sCircular_).pHead;              \
-        (_sCircular_).nFillElements = 0;                        \
+    (_sCircular_).nFillElements = 0;                        \
 } while(0)
-    
+
 /*
 *Add node to the Circular Buffer.  Should be use when UseBuffer or AllocateBuffer
-*is call. The new node is insert in the head of the list. The it will go the last node 
+*is call. The new node is insert in the head of the list. The it will go the last node
 *and rewrite pNext with the new address of the Head.
 */
 #define OMX_CONF_CIRCULAR_BUFFER_ADD_NODE(_pPrivateData_, _sCircular_)\
@@ -233,7 +241,7 @@
 } while(0)
 
 /*
-* Will move the Tail of the Cirular Buffer to the next element. In the tail resides the last buffer to enter 
+* Will move the Tail of the Cirular Buffer to the next element. In the tail resides the last buffer to enter
 *the component from the Application layer. It will get all the Data to be propageted from
 * the pBufferHeader and write it in the node. Then it will move the Tail to the next element.
 *It should be put in the function that handles the filled buffer from the application.
@@ -327,9 +335,9 @@
     if(_e_ != OMX_ErrorNone) goto OMX_CONF_CMD_BAIL;        \
 } while(0)
 
-/* 
+/*
  * Initializes a data structure using a pointer to the structure.
- * The initialization of OMX structures always sets up the nSize and nVersion fields 
+ * The initialization of OMX structures always sets up the nSize and nVersion fields
  *   of the structure.
  */
 #define OMX_CONF_INIT_STRUCT(_s_, _name_)       \
@@ -340,8 +348,8 @@
     (_s_)->nVersion.s.nRevision     = 0x0;      \
     (_s_)->nVersion.s.nStep         = 0x0;      \
 } while(0)
-    
-    
+
+
 /* Event Handler Macro*/
 #define OMX_VIDENC_EVENT_HANDLER(_hComponent_, _eEvent_, _nData1_, _nData2_, _pEventData_) \
 do {                                                        \
@@ -366,7 +374,7 @@
         goto OMX_CONF_CMD_BAIL;                             \
     }                                                       \
     else {                                                  \
-        OMX_TRACE1(dbg, "malloc() -> %p\n", _p_); \
+        OMX_TRACE1(dbg, "malloc() -> %p\n", _p_);           \
     }                                                       \
     memset((_p_), 0x0, _s_);                                \
     if ((_p_) == NULL) {                                    \
@@ -380,7 +388,7 @@
         goto OMX_CONF_CMD_BAIL;                             \
     }                                                       \
 } while(0)
-    
+
 #define VIDENC_FREE(_p_, _h_, dbg)                          \
 do {                                                        \
     OMX_VIDENC_ListRemove((&dbg), _h_, _p_);                \
@@ -392,7 +400,7 @@
     OMX_PTR pData;
     struct VIDENC_NODE* pNext;
 }VIDENC_NODE;
-    
+
 typedef enum VIDEOENC_PORT_INDEX
 {
     VIDENC_INPUT_PORT = 0x0,
@@ -437,11 +445,11 @@
     VideoEncodeCustomConfigIndexTargetFrameRate,
     VideoEncodeCustomConfigIndexQPI,
     VideoEncodeCustomConfigIndexAIRRate,
-    VideoEncodeCustomConfigIndexTargetBitRate,
+    VideoEncodeCustomConfigIndexUnrestrictedMV,
     /*Segment mode Metadata*/
-	VideoEncodeCustomConfigIndexMVDataEnable,
-	VideoEncodeCustomConfigIndexResyncDataEnable,
-	/*ASO*/
+    VideoEncodeCustomConfigIndexMVDataEnable,
+    VideoEncodeCustomConfigIndexResyncDataEnable,
+    /*ASO*/
     VideoEncodeCustomConfigIndexNumSliceASO,
     VideoEncodeCustomConfigIndexAsoSliceOrder,
     /*FMO*/
@@ -451,8 +459,8 @@
     VideoEncodeCustomConfigIndexSliceGroupChangeRate,
     VideoEncodeCustomConfigIndexSliceGroupChangeCycle,
     VideoEncodeCustomConfigIndexSliceGroupParams,
-	/*others*/
-	VideoEncodeCustomConfigIndexMIRRate,
+    /*others*/
+    VideoEncodeCustomConfigIndexMIRRate,
     VideoEncodeCustomConfigIndexMaxMVperMB,
     VideoEncodeCustomConfigIndexIntra4x4EnableIdc,
     /*only for H264*/
@@ -467,19 +475,19 @@
     VIDENC_BUFFER_WITH_CLIENT = 0x0,
     VIDENC_BUFFER_WITH_COMPONENT,
     VIDENC_BUFFER_WITH_DSP,
-    VIDENC_BUFFER_WITH_TUNNELEDCOMP 
+    VIDENC_BUFFER_WITH_TUNNELEDCOMP
 } VIDENC_BUFFER_OWNER;
 
 typedef enum VIDENC_AVC_NAL_FORMAT
 {
-	VIDENC_AVC_NAL_UNIT = 0,	/*Default, one buffer per frame, no NAL mode*/
-	VIDENC_AVC_NAL_SLICE,		/*One NAL unit per buffer, one or more NAL units conforms a Frame*/
-	VIDENC_AVC_NAL_FRAME		/*One frame per buffer, one or more NAL units inside the buffer*/
+    VIDENC_AVC_NAL_UNIT = 0,    /*Default, one buffer per frame, no NAL mode*/
+    VIDENC_AVC_NAL_SLICE,       /*One NAL unit per buffer, one or more NAL units conforms a Frame*/
+    VIDENC_AVC_NAL_FRAME        /*One frame per buffer, one or more NAL units inside the buffer*/
 }VIDENC_AVC_NAL_FORMAT;
 
 typedef struct VIDENC_BUFFER_PRIVATE
 {
-	OMX_PTR pMetaData;/*pointer to metadata structure, this structure is used when MPEG4 segment mode is enabled  */
+    OMX_PTR pMetaData;/*pointer to metadata structure, this structure is used when MPEG4 segment mode is enabled  */
     OMX_BUFFERHEADERTYPE* pBufferHdr;
     OMX_PTR pUalgParam;
     VIDENC_BUFFER_OWNER eBufferOwner;
@@ -489,10 +497,10 @@
 
 typedef struct VIDENC_MPEG4_SEGMENTMODE_METADATA
 {
-	unsigned int mvDataSize;/*unsigned int*/
-	unsigned int numPackets;/*unsigned int*/
-	OMX_PTR pMVData;/*pointer to unsigned char MVData[3264]*/
-	OMX_PTR pResyncData;/*pointer to unsigned char ResyncData[5408]*/
+    unsigned int mvDataSize;/*unsigned int*/
+    unsigned int numPackets;/*unsigned int*/
+    OMX_PTR pMVData;/*pointer to unsigned char MVData[3264]*/
+    OMX_PTR pResyncData;/*pointer to unsigned char ResyncData[5408]*/
 }VIDENC_MPEG4_SEGMENTMODE_METADATA;
 
 typedef struct VIDEOENC_PORT_TYPE
@@ -505,33 +513,33 @@
     OMX_VIDEO_PARAM_PORTFORMATTYPE* pPortFormat;
 
 #ifdef __KHRONOS_CONF_1_1__
-	OMX_VIDEO_PARAM_PROFILELEVELTYPE* pProfileType;
-	OMX_CONFIG_FRAMERATETYPE* pFrameRateConfig;
-	OMX_VIDEO_CONFIG_BITRATETYPE* pBitRateTypeConfig;
-	OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pErrorCorrectionType;
-	OMX_VIDEO_PARAM_INTRAREFRESHTYPE* pIntraRefreshType;
+    OMX_VIDEO_PARAM_PROFILELEVELTYPE* pProfileType;
+    OMX_CONFIG_FRAMERATETYPE* pFrameRateConfig;
+    OMX_VIDEO_CONFIG_BITRATETYPE* pBitRateTypeConfig;
+    OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* pErrorCorrectionType;
+    OMX_VIDEO_PARAM_INTRAREFRESHTYPE* pIntraRefreshType;
 #endif
 
-	OMX_VIDEO_PARAM_BITRATETYPE* pBitRateType;
+    OMX_VIDEO_PARAM_BITRATETYPE* pBitRateType;
     VIDENC_BUFFER_PRIVATE* pBufferPrivate[VIDENC_MAX_NUM_OF_BUFFERS];
 } VIDEOENC_PORT_TYPE;
 
 #ifndef KHRONOS_1_2
 typedef enum OMX_EXTRADATATYPE
 {
-	    OMX_ExtraDataNone = 0,
+        OMX_ExtraDataNone = 0,
         OMX_ExtraDataQuantization
-    } OMX_EXTRADATATYPE;
+} OMX_EXTRADATATYPE;
 #endif
 
 typedef struct OMX_OTHER_EXTRADATATYPE_1_1_2
 {
-	OMX_U32 nSize;
-	OMX_VERSIONTYPE nVersion;
-	OMX_U32 nPortIndex;
-	OMX_EXTRADATATYPE eType;
-	OMX_U32 nDataSize;
-	OMX_U8 data[1];
+    OMX_U32 nSize;
+    OMX_VERSIONTYPE nVersion;
+    OMX_U32 nPortIndex;
+    OMX_EXTRADATATYPE eType;
+    OMX_U32 nDataSize;
+    OMX_U8 data[1];
 } OMX_OTHER_EXTRADATATYPE_1_1_2;
 
 typedef struct VIDEO_PROFILE_LEVEL
@@ -540,9 +548,8 @@
     OMX_S32  nLevel;
 } VIDEO_PROFILE_LEVEL_TYPE;
 
-
 /**
- * The VIDENC_COMPONENT_PRIVATE data structure is used to store component's 
+ * The VIDENC_COMPONENT_PRIVATE data structure is used to store component's
  *                              private data.
  */
 typedef struct VIDENC_COMPONENT_PRIVATE
@@ -550,9 +557,9 @@
     OMX_PORT_PARAM_TYPE* pPortParamType;
     VIDEOENC_PORT_TYPE* pCompPort[VIDENC_NUM_OF_PORTS];
 #ifdef __KHRONOS_CONF_1_1__
-	OMX_PORT_PARAM_TYPE* pPortAudioType;
-	OMX_PORT_PARAM_TYPE* pPortImageType;
-	OMX_PORT_PARAM_TYPE* pPortOtherType;
+    OMX_PORT_PARAM_TYPE* pPortAudioType;
+    OMX_PORT_PARAM_TYPE* pPortImageType;
+    OMX_PORT_PARAM_TYPE* pPortOtherType;
 #endif
 
     OMX_PRIORITYMGMTTYPE* pPriorityMgmt;
@@ -573,21 +580,21 @@
     int nFree_oPipe[2];
     int nFilled_iPipe[2];
     int nCmdPipe[2];
-    int nCmdDataPipe[2]; 
+    int nCmdDataPipe[2];
     void* pModLcml;
     void* pLcmlHandle;
     LCML_DSP_INTERFACE* pLCML;
     int nFrameCnt;
 #ifdef __PERF_INSTRUMENTATION__
     PERF_OBJHANDLE pPERF, pPERFcomp;
-    OMX_U32 nLcml_nCntIp;         
+    OMX_U32 nLcml_nCntIp;
     OMX_U32 nLcml_nCntOpReceived;
 #endif
-    unsigned int nVBVSize; 
+    unsigned int nVBVSize;
     OMX_MARKTYPE* pMarkBuf;
     OMX_PTR pMarkData;
-    OMX_HANDLETYPE hMarkTargetComponent; 
-    OMX_U32 nFlags; 
+    OMX_HANDLETYPE hMarkTargetComponent;
+    OMX_U32 nFlags;
     OMX_U32 nCounter;
     /* these are duplicates */
     unsigned int nIntraFrameInterval;  /* should be OMX_VIDEO_CONFIG_AVCINTRAPERIOD */
@@ -595,18 +602,19 @@
     unsigned int nQPI;              /* same as OMX_VIDEO_PARAM_QUANTIZATIONTYPE */
     unsigned int nAIRRate;          /* same as OMX_VIDEO_PARAM_INTRAREFRESHTYPE */
     unsigned int nTargetBitRate;    /* should be OMX_VIDEO_CONFIG_BITRATETYPE */
-	OMX_U32 nMIRRate;
-    
+    OMX_U32 nMIRRate;
+    OMX_U8  ucUnrestrictedMV;
+
     OMX_U32 nInBufferSize;
     OMX_U32 nOutBufferSize;
 #ifndef UNDER_CE
-    pthread_mutex_t mVideoEncodeBufferMutex; 
+    pthread_mutex_t mVideoEncodeBufferMutex;
 #endif
     OMX_BOOL bDeblockFilter;
     OMX_BOOL bCodecStarted;
     OMX_BOOL bCodecLoaded;
     OMX_BOOL bDSPStopAck;
-    OMX_BOOL bForceIFrame; 
+    OMX_BOOL bForceIFrame;
     OMX_BOOL bFlushComplete;
     OMX_BOOL bEmptyPipes;
     OMX_BOOL bHideEvents;
@@ -635,12 +643,12 @@
     OMX_U32 sliceGroupChangeCycle;
     OMX_U32 sliceGroupParams[MAXNUMSLCGPS];
 #ifndef UNDER_CE
-	pthread_mutex_t videoe_mutex;	/* pthread_cond_t  control_cond; */
-	pthread_mutex_t videoe_mutex_app;
-	pthread_cond_t  populate_cond;
-	pthread_cond_t  unpopulate_cond;
-	pthread_cond_t  stop_cond;
-	pthread_cond_t  flush_cond;
+    pthread_mutex_t videoe_mutex;   /* pthread_cond_t  control_cond; */
+    pthread_mutex_t videoe_mutex_app;
+    pthread_cond_t  populate_cond;
+    pthread_cond_t  unpopulate_cond;
+    pthread_cond_t  stop_cond;
+    pthread_cond_t  flush_cond;
 #else
     OMX_Event AlloBuf_event;
     OMX_U8 AlloBuf_waitingsignal;
@@ -665,6 +673,11 @@
     OMX_COLOR_FORMATTYPE colorFormats[3];
     struct OMX_TI_Debug dbg;
     PV_OMXComponentCapabilityFlagsType* pCapabilityFlags;
+    /*Variables neded to manage the VOL header request*/
+    MP4VE_GPP_SN_UALGInputParams* pTempUalgInpParams;
+    OMX_BOOL bRequestVOLHeader;
+    OMX_BOOL bWaitingForVOLHeaderBuffer;
+    OMX_BOOL bWaitingVOLHeaderCallback;
 
     /* Reference count for pending state change requests */
     OMX_U32 nPendingStateChangeRequests;
@@ -716,7 +729,7 @@
 
 OMX_ERRORTYPE OMX_VIDENC_LCML_Callback(TUsnCodecEvent event, void* argsCb [10]);
 
-OMX_ERRORTYPE OMX_VIDENC_Allocate_DSPResources (OMX_IN VIDENC_COMPONENT_PRIVATE* pComponentPrivate,  
+OMX_ERRORTYPE OMX_VIDENC_Allocate_DSPResources (OMX_IN VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
                                                    OMX_IN OMX_U32 nPortIndex);
 OMX_ERRORTYPE OMX_VIDENC_EmptyDataPipes (void* pThreadData);
 
@@ -735,6 +748,17 @@
 
 OMX_U32 GetMaxAVCBufferSize(OMX_U32 width, OMX_U32 height);
 
+OMX_U32 OMX_VIDENC_GetDefaultBitRate(VIDENC_COMPONENT_PRIVATE* pComponentPrivate);
+
+void printMpeg4Params(MP4VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs,
+                      struct OMX_TI_Debug *dbg);
+
+void printH264CreateParams(H264VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs, struct OMX_TI_Debug *dbg);
+
+void printMpeg4UAlgInParam(MP4VE_GPP_SN_UALGInputParams* pUalgInpParams, int printAlways, struct OMX_TI_Debug *dbg);
+
+void printH264UAlgInParam(H264VE_GPP_SN_UALGInputParams* pUalgInpParams, int printAlways, struct OMX_TI_Debug *dbg);
+
 OMX_ERRORTYPE AddStateTransition(VIDENC_COMPONENT_PRIVATE* pComponentPrivate);
 OMX_ERRORTYPE RemoveStateTransition(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BOOL bEnableSignal);
 
diff --git a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Thread.c b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Thread.c
index 84ed84b..88d2b34 100644
--- a/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Thread.c
+++ b/omx/video/src/openmax_il/video_encode/src/OMX_VideoEnc_Thread.c
@@ -22,13 +22,13 @@
 *             Texas Instruments OMAP(TM) Platform Software
 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
 *
-*  Use of this software is controlled by the terms and conditions found 
+*  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * =========================================================================== */
 /**
 * @file OMX_VideoEnc_Thread.c
 *
-* This file implements OMX Component for MPEG-4 encoder that 
+* This file implements OMX Component for MPEG-4 encoder that
 * is fully compliant with the OMX specification 1.5.
 *
 * @path  $(CSLPATH)\src
@@ -36,27 +36,27 @@
 * @rev  0.1
 */
 /* -------------------------------------------------------------------------- */
-/* ============================================================================= 
-*! 
-*! Revision History 
+/* =============================================================================
+*!
+*! Revision History
 *! ================================================================
 *!
-*! 02-Feb-2006 mf: Revisions appear in reverse chronological order; 
-*! that is, newest first.  The date format is dd-Mon-yyyy.  
+*! 02-Feb-2006 mf: Revisions appear in reverse chronological order;
+*! that is, newest first.  The date format is dd-Mon-yyyy.
 * =========================================================================== */
 
 
 /* ------compilation control switches ----------------------------------------*/
 /******************************************************************************
-*  INCLUDE FILES                                                 
+*  INCLUDE FILES
 *******************************************************************************/
 /* ----- system and platform files -------------------------------------------*/
-#ifdef UNDER_CE 
+#ifdef UNDER_CE
     #include <windows.h>
     #include <oaf_osal.h>
     #include <omx_core.h>
 #else
-	#define _XOPEN_SOURCE 600
+    #define _XOPEN_SOURCE 600
     #include <wchar.h>
     #include <unistd.h>
     #include <sys/select.h>
@@ -102,7 +102,7 @@
   *
   * Called by VIDENC_Start_ComponentThread function.
   *
-  * @param pThreadData  
+  * @param pThreadData
   *
   * @retval OMX_ErrorNone                  success, ready to roll
   *         OMX_ErrorInsufficientResources if the malloc fails
@@ -120,7 +120,7 @@
     OMX_PTR pCmdData = NULL;
     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
-	sigset_t set;
+    sigset_t set;
 
     if (!pThreadData)
     {
@@ -137,10 +137,10 @@
                                                PERF_ModuleVideoEncode);
 #endif
 
-    /** Looking for highest number of file descriptor 
+    /** Looking for highest number of file descriptor
         for pipes inorder to put in select loop */
 
-    fdmax = pComponentPrivate->nCmdPipe[0];    
+    fdmax = pComponentPrivate->nCmdPipe[0];
 
     if (pComponentPrivate->nFree_oPipe[0] > fdmax)
     {
@@ -157,19 +157,19 @@
         FD_ZERO (&rfds);
         FD_SET (pComponentPrivate->nCmdPipe[0], &rfds);
         FD_SET (pComponentPrivate->nFree_oPipe[0], &rfds);
-        FD_SET (pComponentPrivate->nFilled_iPipe[0], &rfds);      
-        
-		sigemptyset(&set);
-		sigaddset(&set,SIGALRM);
+        FD_SET (pComponentPrivate->nFilled_iPipe[0], &rfds);
+
+        sigemptyset(&set);
+        sigaddset(&set,SIGALRM);
         status = pselect(fdmax+1, &rfds, NULL, NULL, NULL,&set);
 
         if (0 == status)
         {
             OMX_TRACE2(pComponentPrivate->dbg, "pselect() = 0\n");
-#ifndef UNDER_CE            
+#ifndef UNDER_CE
             sched_yield();
 #else
-           sched_yield();
+            sched_yield();
 #endif
         }
         else if (-1 == status)
@@ -179,9 +179,12 @@
                 OMX_TRACE3(pComponentPrivate->dbg, "select() error.\n");
                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, OMX_EventError, OMX_ErrorHardware, 0, NULL);
             }
-            OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorHardware, pComponentPrivate);
+            /*OMX_VIDENC_SET_ERROR_BAIL(eError, OMX_ErrorHardware, pComponentPrivate);*/
+            eError = OMX_ErrorHardware;
+            OMX_ERROR5(pComponentPrivate->dbg, "*Fatal Error : %x\n", eError);
+            OMX_VIDENC_HandleError(pComponentPrivate, eError);
         }
-        else 
+        else
         {
             if (FD_ISSET(pComponentPrivate->nCmdPipe[0], &rfds))
             {
@@ -195,17 +198,17 @@
                                               OMX_ErrorHardware,
                                               pComponentPrivate);
                 }
-                
+
 #ifdef __PERF_INSTRUMENTATION__
                         PERF_ReceivedCommand(pComponentPrivate->pPERFcomp,
                                              eCmd, 0, PERF_ModuleLLMM);
 #endif
-                if (eCmd == -1)
+                if (eCmd == (OMX_COMMANDTYPE)-1)
                 {
                     OMX_PRCOMM2(pComponentPrivate->dbg, "Received thread close command.\n");
                     OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorNone);
                 }
-                
+
                 if (eCmd == OMX_CommandMarkBuffer)
                 {
                     nRet = read(pComponentPrivate->nCmdDataPipe[0],
@@ -239,8 +242,8 @@
                                          (eCmd == OMX_CommandMarkBuffer) ? ((OMX_U32) pCmdData) : nParam1,
                                          PERF_ModuleLLMM);
 #endif
-                
-                switch (eCmd) 
+
+                switch (eCmd)
                 {
                     case OMX_CommandStateSet :
                     OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandStateSet\n");
@@ -251,7 +254,7 @@
                         break;
                     case OMX_CommandFlush :
                     OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandFlush\n");
-                        eError = OMX_VIDENC_HandleCommandFlush(pComponentPrivate, 
+                        eError = OMX_VIDENC_HandleCommandFlush(pComponentPrivate,
                                                                nParam1,
                                                                OMX_FALSE);
                         OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
@@ -266,7 +269,7 @@
                         break;
                     case OMX_CommandPortEnable :
                     OMX_PRSTATE2(pComponentPrivate->dbg, "Enters OMX_VIDENC_HandleCommandDisablePort\n");
-                        eError = OMX_VIDENC_HandleCommandEnablePort(pComponentPrivate, 
+                        eError = OMX_VIDENC_HandleCommandEnablePort(pComponentPrivate,
                                                                     nParam1);
                         OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
                     OMX_PRSTATE2(pComponentPrivate->dbg, "Exits OMX_VIDENC_HandleCommandDisablePort\n");
@@ -279,26 +282,26 @@
                         break;
                     default:
                         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                                 OMX_EventError, 
+                                                 OMX_EventError,
                                                  OMX_ErrorUndefined,
                                                  0,
                                                  NULL);
                 }
-            }    
+            }
 
             if(pComponentPrivate->bEmptyPipes)
             {
                     pComponentPrivate->bEmptyPipes = OMX_FALSE;
             }
-            else 
+            else
             {
-                
-                if ((FD_ISSET(pComponentPrivate->nFilled_iPipe[0], &rfds)) && 
+
+                if ((FD_ISSET(pComponentPrivate->nFilled_iPipe[0], &rfds)) &&
                     (pComponentPrivate->eState != OMX_StatePause &&
-                    pComponentPrivate->eState != OMX_StateIdle)) 
+                    pComponentPrivate->eState != OMX_StateIdle))
                 {
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FilledInBuf\n");
-                    eError = OMX_VIDENC_Process_FilledInBuf(pComponentPrivate);      
+                    OMX_PRBUFFER1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FilledInBuf\n");
+                    eError = OMX_VIDENC_Process_FilledInBuf(pComponentPrivate);
                     if (eError != OMX_ErrorNone)
                     {
                         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
@@ -308,25 +311,25 @@
                                                  NULL);
                         OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
                     }
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FilledInBuf\n");
+                    OMX_PRBUFFER1(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FilledInBuf\n");
                 }
-                
-                if (FD_ISSET(pComponentPrivate->nFree_oPipe[0], &rfds) && 
-                    (pComponentPrivate->eState != OMX_StatePause && 
+
+                if (FD_ISSET(pComponentPrivate->nFree_oPipe[0], &rfds) &&
+                    (pComponentPrivate->eState != OMX_StatePause &&
                     pComponentPrivate->eState != OMX_StateIdle))
                 {
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FreeOutBuf\n");
+                    OMX_PRBUFFER1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FreeOutBuf\n");
                     eError = OMX_VIDENC_Process_FreeOutBuf(pComponentPrivate);
                     if (eError != OMX_ErrorNone)
                     {
-                        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
+                        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
                                                  OMX_EventError,
                                                  OMX_ErrorUndefined,
                                                  0,
                                                  NULL);
                         OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
                     }
-                    OMX_PRBUFFER2(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FreeOutBuf\n");
+                    OMX_PRBUFFER1(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FreeOutBuf\n");
                 }
             }
         }
@@ -335,9 +338,10 @@
 OMX_CONF_CMD_BAIL:
 
 #ifdef __PERF_INSTRUMENTATION__
-    PERF_Done(pComponentPrivate->pPERFcomp);
+    if (pComponentPrivate)
+        PERF_Done(pComponentPrivate->pPERFcomp);
 #endif
-
-    OMX_PRINT2(pComponentPrivate->dbg, "Component Thread Exits\n");
-    return (void*)eError; 
+    if (pComponentPrivate)
+        OMX_PRINT2(pComponentPrivate->dbg, "Component Thread Exits\n");
+    return (void*)eError;
 }
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 2e9e977..ba0482b 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
@@ -22,13 +22,13 @@
 *             Texas Instruments OMAP(TM) Platform Software
 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
 *
-*  Use of this software is controlled by the terms and conditions found 
+*  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * ============================================================================*/
 /**
 * @file OMX_VideoEnc_Utils.c
 *
-* This file implements OMX Component for MPEG-4 encoder that 
+* This file implements OMX Component for MPEG-4 encoder that
 * is fully compliant with the OMX specification 1.5.
 *
 * @path  $(CSLPATH)\src
@@ -36,21 +36,21 @@
 * @rev  0.1
 */
 /* ---------------------------------------------------------------------------*/
-/* ============================================================================= 
-*! 
-*! Revision History 
+/* =============================================================================
+*!
+*! Revision History
 *! =============================================================================
 *!
-*! 02-Feb-2006 mf: Revisions appear in reverse chronological order; 
-*! that is, newest first.  The date format is dd-Mon-yyyy.  
+*! 02-Feb-2006 mf: Revisions appear in reverse chronological order;
+*! that is, newest first.  The date format is dd-Mon-yyyy.
 * ============================================================================*/
 
 /* ------compilation control switches ----------------------------------------*/
 /******************************************************************************
-*  INCLUDE FILES                                                 
+*  INCLUDE FILES
 *******************************************************************************/
 /* ----- system and platform files -------------------------------------------*/
-#ifdef UNDER_CE 
+#ifdef UNDER_CE
     #include <windows.h>
     #include <omx_core.h>
     #include <stdlib.h>
@@ -81,6 +81,11 @@
 
 #define DSP_MMU_FAULT_HANDLING
 
+// We cannot request the same MHz for all resolutions.
+// we have to change this implementation once we modify
+// opencore to request the correct level based on resolution/bitrate/etc
+#define VIDEO_ENCODER_MHZ (400 - 45 + 2) 
+
 #ifdef UNDER_CE
     HINSTANCE g_hLcmlDllHandle = NULL;
 #endif
@@ -125,8 +130,47 @@
         0xCF, 0x80, 0x57, 0x73, 0x05, 0x41
     }
 };
+
+OMX_U32 VIDENC_STRUCT_H264DEFBITRATE [VIDENC_MAXBITRATES][2] = {
+/*1*/    {176 * 144, 128000},     /*128KBps*/
+/*2*/    {320 * 240, 400000},     /*400KBps*/
+/*3*/    {352 * 288, 500000},     /*500kBps*/
+/*4*/    {640 * 480, 1500000},    /*1.5MBps*/
+/*5*/    {720 * 480, 2000000},    /*2MBps*/
+/*6*/    {720 * 576, 3000000},    /*3MBps*/
+/*7*/    {1280 * 720, 3000000},   /*3MBps*/
+};
+
+OMX_U32 VIDENC_STRUCT_MPEG4DEFBITRATE [VIDENC_MAXBITRATES][2] = {
+/*1*/    {176 * 144, 128000},     /*128KBps*/
+/*2*/    {320 * 240, 400000},     /*400KBps*/
+/*3*/    {352 * 288, 500000},     /*500kBps*/
+/*4*/    {640 * 480, 1500000},    /*1.5MBps*/
+/*5*/    {720 * 480, 2000000},    /*2MBps*/
+/*6*/    {720 * 576, 3000000},    /*3MBps*/
+/*7*/    {1280 * 720, 3000000},   /*3MBps*/
+};
+
+OMX_U32 VIDENC_STRUCT_H263DEFBITRATE [VIDENC_MAXBITRATES][2] = {
+/*1*/    {176 * 144, 128000},     /*128KBps*/
+/*2*/    {320 * 240, 400000},     /*400KBps*/
+/*3*/    {352 * 288, 500000},     /*500kBps*/
+/*4*/    {640 * 480, 1500000},    /*1.5MBps*/
+/*5*/    {720 * 480, 2000000},    /*2MBps*/
+/*6*/    {720 * 576, 3000000},    /*3MBps*/
+/*7*/    {1280 * 720, 3000000},   /*3MBps*/
+};
 /*--------macro definitions ---------------------------------------------------*/
 
+static const int iQ16_Const = 1 << 16;
+static const float fQ16_Const = (float)(1 << 16);
+
+static float Q16Tof(int nQ16)
+{
+    return nQ16 / fQ16_Const;
+}
+
+
 
 /*-----------------------------------------------------------------------------*/
 /**
@@ -135,10 +179,10 @@
   * Function call in OMX_ComponentInit(). Creates the List Head of the Component Memory List.
   *
   * @param pListHead VIDENC_NODE double pointer with the List Header of the Memory List.
-  *                
-  * @retval OMX_ErrorNone 
+  *
+  * @retval OMX_ErrorNone
   *               OMX_ErrorInsufficientResources if the malloc fails
-  *         
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE OMX_VIDENC_ListCreate(struct OMX_TI_Debug *dbg, struct VIDENC_NODE** pListHead)
@@ -146,15 +190,15 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
     *pListHead = (VIDENC_NODE*)malloc(sizeof(VIDENC_NODE)); /* need to malloc!!! */
-    if (*pListHead == NULL) 
-    {                                      
+    if (*pListHead == NULL)
+    {
         OMX_TRACE4(*dbg, "malloc() out of memory error\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
-    
+
     OMX_TRACE1(*dbg, "Create MemoryListHeader[%p]\n", *pListHead);
     memset(*pListHead, 0x0, sizeof(VIDENC_NODE));
-    
+
 OMX_CONF_CMD_BAIL:
     return eError;
 }
@@ -167,9 +211,9 @@
   *
   * @param pListHead VIDENC_NODE Points List Header of the Memory List.
   *                pData OMX_PTR points to the new allocated data.
-  * @retval OMX_ErrorNone 
+  * @retval OMX_ErrorNone
   *               OMX_ErrorInsufficientResources if the malloc fails
-  *         
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
@@ -179,23 +223,23 @@
     VIDENC_NODE* pTmp = NULL;
     VIDENC_NODE* pNewNode = NULL;
     pNewNode = (VIDENC_NODE*)malloc(sizeof(VIDENC_NODE)); /* need to malloc!!! */
-    if (pNewNode == NULL) 
+    if (pNewNode == NULL)
     {
         OMX_TRACE4(*dbg, "malloc() out of memory error\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
-    memset(pNewNode, 0x0, sizeof(VIDENC_NODE)); 
+    memset(pNewNode, 0x0, sizeof(VIDENC_NODE));
     pNewNode->pData = pData;
     pNewNode->pNext = NULL;
     OMX_TRACE1(*dbg, "Add MemoryNode[%p] -> [%p]\n", pNewNode, pNewNode->pData);
     pTmp = pListHead;
-    
+
     while (pTmp->pNext != NULL)
     {
         pTmp = pTmp->pNext;
     }
     pTmp->pNext = pNewNode;
-   
+
 OMX_CONF_CMD_BAIL:
     return eError;
 }
@@ -208,13 +252,13 @@
   *
   * @param pListHead VIDENC_NODE Points List Header of the Memory List.
   *                pData OMX_PTR points to the new allocated data.
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
-OMX_ERRORTYPE OMX_VIDENC_ListRemove(struct OMX_TI_Debug *dbg, struct VIDENC_NODE* pListHead, 
+OMX_ERRORTYPE OMX_VIDENC_ListRemove(struct OMX_TI_Debug *dbg, struct VIDENC_NODE* pListHead,
                                     OMX_PTR pData)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
@@ -248,10 +292,10 @@
   * Called inside OMX_ComponentDeInit()  Remove all nodes and free all the memory in the Component Memory List.
   *
   * @param pListHead VIDENC_NODE Points List Header of the Memory List.
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
@@ -265,17 +309,17 @@
     while (pNode->pNext != NULL)
     {
         pTmp = pNode->pNext;
-		pNode->pNext=pTmp->pNext;
+        pNode->pNext=pTmp->pNext;
         if (pTmp->pData != NULL)
         {
             OMX_TRACE0(*dbg, "Remove MemoryNode[%p] -> [%p]\n", pTmp, pTmp->pData);
-			free(pTmp->pData);		
-			pTmp->pData = NULL;            
-        } 
-		free(pTmp);		
-		pTmp = NULL;        
+            free(pTmp->pData);
+            pTmp->pData = NULL;
+        }
+        free(pTmp);
+        pTmp = NULL;
     }
-    
+
     OMX_TRACE1(*dbg, "Destroy MemoryListHeader[%p]\n", pListHead);
     free(pListHead);
     return eError;
@@ -285,11 +329,11 @@
 
 /*---------------------------------------------------------------------------------------*/
 /**
-  *  OMX_VIDENC_EmptyDataPipes  
-  * @param 
+  *  OMX_VIDENC_EmptyDataPipes
+  * @param
   *
   * @retval OMX_NoError              Success, ready to roll
-  *         
+  *
  **/
 /*---------------------------------------------------------------------------------------*/
 OMX_ERRORTYPE OMX_VIDENC_EmptyDataPipes (void* pThreadData)
@@ -304,10 +348,10 @@
     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
 
     OMX_CONF_CHECK_CMD(pThreadData, 1, 1);
-    
+
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pThreadData;
 
-    /** Looking for highest number of file descriptor 
+    /** Looking for highest number of file descriptor
         for pipes inorder to put in select loop */
 
     fdmax = pComponentPrivate->nFree_oPipe[0];
@@ -316,7 +360,7 @@
     {
         fdmax = pComponentPrivate->nFilled_iPipe[0];
     }
-    
+
     while (1)
     {
         FD_ZERO (&rfds);
@@ -324,10 +368,10 @@
         FD_SET (pComponentPrivate->nFilled_iPipe[0], &rfds);
         tv.tv_sec = 0;
         tv.tv_usec = 10;
-        
+
         status = select(fdmax+1, &rfds, NULL, NULL, &tv);
 
-        if (0 == status) 
+        if (0 == status)
         {
             OMX_TRACE2(pComponentPrivate->dbg, "selectEmpty() = 0\n");
             break;
@@ -339,9 +383,9 @@
         else
         {
             if ((FD_ISSET(pComponentPrivate->nFilled_iPipe[0], &rfds)))
-            { 
+            {
                 nRet = read(pComponentPrivate->nFilled_iPipe[0],
-                            &pBufHead, 
+                            &pBufHead,
                             sizeof(pBufHead));
                 OMX_PRBUFFER2(pComponentPrivate->dbg, "Flusing pipe nFilled_iPipe[0]!\n");
                 if (nRet == -1)
@@ -365,9 +409,9 @@
         }
     }
     pComponentPrivate->bEmptyPipes = OMX_TRUE;
-    
+
 OMX_CONF_CMD_BAIL:
-    return eError; 
+    return eError;
 }
 
 
@@ -381,20 +425,20 @@
   *         OMX_Error_BadParameter   The input parameter pointer is null
  **/
 /*---------------------------------------------------------------------------------------*/
-OMX_ERRORTYPE OMX_VIDENC_HandleError(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, 
+OMX_ERRORTYPE OMX_VIDENC_HandleError(VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
                                      OMX_ERRORTYPE eErrorCmp)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pComponentPrivate->bHandlingFatalError = OMX_TRUE;
-    
-    OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                             OMX_EventError, 
-                             eErrorCmp, 
+
+    OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                             OMX_EventError,
+                             eErrorCmp,
                              OMX_TI_ErrorSevere,
                              NULL);
-    
+
     switch (eErrorCmp)
     {
         case OMX_ErrorBadParameter:
@@ -405,7 +449,7 @@
         default:
             ;
     }
-    
+
     pComponentPrivate->bHideEvents = OMX_TRUE;
 
     eError = eErrorCmp;
@@ -418,7 +462,8 @@
                              NULL);
 
 OMX_CONF_CMD_BAIL:
-    pComponentPrivate->bHandlingFatalError = OMX_FALSE;
+    if (pComponentPrivate)
+        pComponentPrivate->bHandlingFatalError = OMX_FALSE;
     return eError;
 }
 
@@ -432,13 +477,13 @@
   *         OMX_Error_BadParameter   The input parameter pointer is null
  **/
 /*---------------------------------------------------------------------------------------*/
-OMX_ERRORTYPE OMX_VIDENC_HandleLcmlEvent(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, 
+OMX_ERRORTYPE OMX_VIDENC_HandleLcmlEvent(VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
                                          TUsnCodecEvent eEvent, void* argsCb [])
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    
+
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     switch(eEvent)
     {
     case EMMCodecDspMessageRecieved:
@@ -468,7 +513,7 @@
     case EMMCodecStrmCtrlAck:
         OMX_PRDSP1(pComponentPrivate->dbg, "EMMCodecStrmCtrlAck\n");
         break;
-	case EMMCodecInternalError:
+    case EMMCodecInternalError:
         OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecInternalError\n");
 #ifdef DSP_MMU_FAULT_HANDLING
         if((argsCb[4] == (void *)USN_ERR_UNKNOWN_MSG) && (argsCb[5] == (void*)NULL))
@@ -493,7 +538,7 @@
            eError = OMX_ErrorHardware;
 #endif
         break;
-	case EMMCodecInitError:
+    case EMMCodecInitError:
         OMX_PRDSP2(pComponentPrivate->dbg, "EMMCodecInitError\n");
 #ifdef DSP_MMU_FAULT_HANDLING
         if((argsCb[4] == (void *)USN_ERR_UNKNOWN_MSG) && (argsCb[5] == (void*)NULL))
@@ -555,13 +600,13 @@
   *
   * Called by component thread, handles commands sent by the app.
   *
-  * @param 
+  * @param
   *
   * @retval OMX_ErrorNone                  success, ready to roll
-  *         
+  *
   **/
 /*-----------------------------------------------------------------------------*/
-OMX_ERRORTYPE OMX_VIDENC_HandleCommandDisablePort (VIDENC_COMPONENT_PRIVATE* pComponentPrivate, 
+OMX_ERRORTYPE OMX_VIDENC_HandleCommandDisablePort (VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
                                                    OMX_U32 nParam1)
 {
     OMX_U8 i = 0;
@@ -571,21 +616,21 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     VIDEOENC_PORT_TYPE* pCompPortIn = NULL;
     VIDEOENC_PORT_TYPE* pCompPortOut = NULL;
-    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL; 
+    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pHandle         = (OMX_COMPONENTTYPE*)pComponentPrivate->pHandle;
     pCompPortIn     = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
     pCompPortOut    = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
     pPortDefIn      = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     pPortDefOut     = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
-    
+
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pHandle, pPortDefIn, pPortDefOut);
 
-    if (nParam1 == VIDENC_INPUT_PORT || nParam1 == -1)
+    if (nParam1 == VIDENC_INPUT_PORT || nParam1 == (OMX_U32)-1)
     {
         /* Flush the DSP side before sending buffers back to the client */
         bFlushFlag = OMX_FALSE;
@@ -596,7 +641,7 @@
                 bFlushFlag = OMX_TRUE;
             }
         }
-        
+
         if(bFlushFlag == OMX_TRUE)
         {
             eError = OMX_VIDENC_HandleCommandFlush(pComponentPrivate, VIDENC_INPUT_PORT, OMX_TRUE);
@@ -604,11 +649,11 @@
                                   "Flush command failed (%x)\n", eError);
             bFlushFlag = OMX_FALSE;
         }
-        
+
         /*Return buffer to client*/
         if (pCompPortIn->hTunnelComponent == NULL)
         {
-            for (i = 0; i < pPortDefIn->nBufferCountActual; i++) 
+            for (i = 0; i < pPortDefIn->nBufferCountActual; i++)
             {
                 if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
                     pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
@@ -630,7 +675,7 @@
         {
             for (i = 0; i < pPortDefIn->nBufferCountActual; i++)
             {
-                if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT || 
+                if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
                     pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
                 {
                     pCompPortIn->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_TUNNELEDCOMP;
@@ -640,7 +685,7 @@
                                       0,
                                       PERF_ModuleLLMM);
 #endif
-                    eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent, 
+                    eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent,
                                                 pCompPortIn->pBufferPrivate[i]->pBufferHdr);
                     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER4,
                                           "FillThisBuffer failed (%x)\n", eError);
@@ -648,7 +693,7 @@
             }
         }
     }
-    if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == -1)
+    if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == (OMX_U32)-1)
     {
         /* Flush the DSP side before sending buffers back to the client */
         bFlushFlag = OMX_FALSE;
@@ -659,7 +704,7 @@
                 bFlushFlag = OMX_TRUE;
             }
         }
-        
+
         if(bFlushFlag == OMX_TRUE)
         {
             eError = OMX_VIDENC_HandleCommandFlush(pComponentPrivate, VIDENC_OUTPUT_PORT, OMX_TRUE);
@@ -667,7 +712,7 @@
                                   "Flush command failed (%x)\n", eError);
             bFlushFlag = OMX_FALSE;
         }
-        
+
         /*Return buffer to client*/
         if (pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->hTunnelComponent == NULL)
         {
@@ -688,27 +733,27 @@
                                       0,
                                       PERF_ModuleHLMM);
 #endif
-                    OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[i]->pBufferHdr, 
+                    OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[i]->pBufferHdr,
                                                        pComponentPrivate->sCircularBuffer,
                                                        pComponentPrivate);
-                    /* trigger event handler if we are supposed to */ 
-                    if (pCompPortOut->pBufferPrivate[i]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle && 
-                        pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData) 
+                    /* trigger event handler if we are supposed to */
+                    if (pCompPortOut->pBufferPrivate[i]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle &&
+                        pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData)
                     {
-                        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,  
-                                                 OMX_EventMark, 
-                                                 0x0, 
-                                                 0x0, 
+                        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                                 OMX_EventMark,
+                                                 0x0,
+                                                 0x0,
                                                  pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData);
-                    }   
-                    
+                    }
+                    OMX_PRINT2(pComponentPrivate->dbg, "FBD %p, FilledLen=%lu\n", pCompPortOut->pBufferPrivate[i]->pBufferHdr, pCompPortOut->pBufferPrivate[i]->pBufferHdr->nFilledLen);
                     pComponentPrivate->sCbData.FillBufferDone(pComponentPrivate->pHandle,
                                                               pComponentPrivate->pHandle->pApplicationPrivate,
                                                               pCompPortOut->pBufferPrivate[i]->pBufferHdr);
                 }
             }
         }
-        else 
+        else
         {
          /* If tunneled with VPP  - NOT Implemented*/
 #ifdef __PERF_INSTRUMENTATION__
@@ -719,87 +764,87 @@
 #endif
         }
     }
-    
+
     OMX_PRBUFFER2(pComponentPrivate->dbg, "Flushing Pipes!\n");
     eError = OMX_VIDENC_EmptyDataPipes (pComponentPrivate);
     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER3,
                           "Flushing pipes failed (%x).\n", eError);
-    
-    /*while (1) 
+
+    /*while (1)
     {*/
 
         if (nParam1 == VIDENC_INPUT_PORT)
         {
-            while ((pPortDefIn->bPopulated)) 
+            while ((pPortDefIn->bPopulated))
             {
                 /*Send event*/
 #ifndef UNDER_CE
-	pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
-	pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
-	pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+    pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+    pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
+    pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
 #else
-		OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
+        OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
 #endif
-		break;
-            	}
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                             OMX_EventCmdComplete, 
-                             OMX_CommandPortDisable, 
-                             VIDENC_INPUT_PORT, 
+        break;
+                }
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                             OMX_EventCmdComplete,
+                             OMX_CommandPortDisable,
+                             VIDENC_INPUT_PORT,
                              NULL);
-                
+
             }
-        
+
         else if (nParam1 == VIDENC_OUTPUT_PORT)
         {
             while ((pPortDefOut->bPopulated))
             {
                 /*Send event*/
 #ifndef UNDER_CE
-	pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
-	pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
-	pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+    pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+    pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
+    pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
 #else
-		OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
+        OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
 #endif
-		break;
-            	}
-		OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                             OMX_EventCmdComplete, 
-                             OMX_CommandPortDisable, 
-                             VIDENC_OUTPUT_PORT, 
+        break;
+                }
+        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                             OMX_EventCmdComplete,
+                             OMX_CommandPortDisable,
+                             VIDENC_OUTPUT_PORT,
                              NULL);
-                
+
             }
-        
-        else if (nParam1 == -1)
+
+        else if (nParam1 == (OMX_U32)-1)
         {
             while ((pPortDefIn->bPopulated) || (pPortDefOut->bPopulated))
             {
-		/*Send events*/
+        /*Send events*/
 #ifndef UNDER_CE
-	pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
-	pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
-	pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+    pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+    pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
+    pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
 #else
-		OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
+        OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
 #endif
-		break;
-            	}
-		OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                             OMX_EventCmdComplete, 
-                             OMX_CommandPortDisable, 
-                             VIDENC_INPUT_PORT, 
+        break;
+                }
+        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                             OMX_EventCmdComplete,
+                             OMX_CommandPortDisable,
+                             VIDENC_INPUT_PORT,
                              NULL);
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                             OMX_EventCmdComplete, 
-                             OMX_CommandPortDisable, 
-                             VIDENC_OUTPUT_PORT, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                             OMX_EventCmdComplete,
+                             OMX_CommandPortDisable,
+                             VIDENC_OUTPUT_PORT,
                              NULL);
-                
-            
+
+
         }
-       
+
 
 OMX_CONF_CMD_BAIL:
     return eError;
@@ -811,10 +856,10 @@
   *
   * Called by component thread, handles commands sent by the app.
   *
-  * @param 
+  * @param
   *
   * @retval OMX_ErrorNone                  success, ready to roll
-  *         
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
@@ -825,11 +870,11 @@
     OMX_COMPONENTTYPE* pHandle = NULL;
     VIDENC_NODE* pMemoryListHead = NULL;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL; 
+    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pHandle = (OMX_COMPONENTTYPE*)pComponentPrivate->pHandle;
     pPortDefIn      = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     pPortDefOut     = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
@@ -842,80 +887,80 @@
         {
         if (pComponentPrivate->eState != OMX_StateLoaded)
         {
-		pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+        pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
             while (!pPortDefIn->bPopulated)
                {
 #ifndef UNDER_CE
-		pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
+        pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
 #else
-		OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
+        OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
 #endif
-		    
-            	}
-	}
-	pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
-		OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                             OMX_EventCmdComplete, 
-                                             OMX_CommandPortEnable, 
-                                             VIDENC_INPUT_PORT, 
+
+                }
+    }
+    pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                             OMX_EventCmdComplete,
+                                             OMX_CommandPortEnable,
+                                             VIDENC_INPUT_PORT,
                                              NULL);
-              
-               
+
+
         }
         else if(nParam1 == VIDENC_OUTPUT_PORT)
         {
         if (pComponentPrivate->eState != OMX_StateLoaded)
         {
-			pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+            pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
             while(!pPortDefOut->bPopulated)
             {
 #ifndef UNDER_CE
-		pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
+        pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
 #else
-		OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
+        OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
 #endif
- 
-            	}
-		}
-			pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                         OMX_EventCmdComplete, 
-                                         OMX_CommandPortEnable, 
-                                         VIDENC_OUTPUT_PORT, 
-                                         NULL);
-                
-            
+
+                }
         }
-        else if(nParam1 == -1)
+            pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                         OMX_EventCmdComplete,
+                                         OMX_CommandPortEnable,
+                                         VIDENC_OUTPUT_PORT,
+                                         NULL);
+
+
+        }
+        else if(nParam1 == (OMX_U32)-1)
         {
         if (pComponentPrivate->eState != OMX_StateLoaded)
         {
-			pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+            pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
             while(!pPortDefOut->bPopulated && !pPortDefIn->bPopulated)
             {
 #ifndef UNDER_CE
-			pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
+            pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
 #else
-		OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
+        OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
 #endif
       break;
-            	}
-		}
-			pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                         OMX_EventCmdComplete, 
-                                         OMX_CommandPortEnable, 
-                                         VIDENC_INPUT_PORT, 
-                                         NULL);
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                        OMX_EventCmdComplete, 
-                                        OMX_CommandPortEnable, 
-                                        VIDENC_OUTPUT_PORT, 
-                                        NULL);
-                
-            
+                }
         }
-        
+            pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                         OMX_EventCmdComplete,
+                                         OMX_CommandPortEnable,
+                                         VIDENC_INPUT_PORT,
+                                         NULL);
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                        OMX_EventCmdComplete,
+                                        OMX_CommandPortEnable,
+                                        VIDENC_OUTPUT_PORT,
+                                        NULL);
+
+
+        }
+
 
 OMX_CONF_CMD_BAIL:
     return eError;
@@ -933,7 +978,7 @@
   *         OMX_ErrorInsufficientResources if the malloc fails
   **/
 /*----------------------------------------------------------------------------*/
-  
+
 OMX_ERRORTYPE OMX_VIDENC_HandleCommandFlush(VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
                                             OMX_U32 nParam1,
                                             OMX_BOOL bInternalFlush)
@@ -946,9 +991,9 @@
     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
     VIDEOENC_PORT_TYPE* pCompPortIn = NULL;
     VIDEOENC_PORT_TYPE* pCompPortOut = NULL;
-    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL; 
+    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
-    
+
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
 
     pLcmlHandle     = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
@@ -959,25 +1004,25 @@
     pHandle         = (OMX_COMPONENTTYPE*)pComponentPrivate->pHandle;
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
 
-    if (nParam1 == VIDENC_INPUT_PORT || nParam1 == -1)
+    if (nParam1 == VIDENC_INPUT_PORT || nParam1 == (OMX_U32)-1)
     {
-        aParam[0] = USN_STRMCMD_FLUSH; 
-        aParam[1] = VIDENC_INPUT_PORT; 
-        aParam[2] = 0x0; 
+        aParam[0] = USN_STRMCMD_FLUSH;
+        aParam[1] = VIDENC_INPUT_PORT;
+        aParam[2] = 0x0;
 
         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                    EMMCodecControlStrmCtrl, 
+                                    EMMCodecControlStrmCtrl,
                                     (void*)aParam);
         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
                               "DSP Input flush failed (%x).\n", eError);
 
 #ifndef UNDER_CE
-		pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+        pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
         while (pComponentPrivate->bFlushComplete == OMX_FALSE)
         {
-			pthread_cond_wait(&pComponentPrivate->flush_cond, &pComponentPrivate->videoe_mutex_app);
-		}
-		pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+            pthread_cond_wait(&pComponentPrivate->flush_cond, &pComponentPrivate->videoe_mutex_app);
+        }
+        pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
 #else
         while (pComponentPrivate->bFlushComplete == OMX_FALSE)
         {
@@ -994,7 +1039,7 @@
                 if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
                     pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
                 {
-                    
+
                     pCompPortIn->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
 #ifdef __PERF_INSTRUMENTATION__
                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
@@ -1012,10 +1057,10 @@
         {
             for (i = 0; i < pPortDefIn->nBufferCountActual; i++)
             {
-                if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT || 
+                if (pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT ||
                     pCompPortIn->pBufferPrivate[i]->eBufferOwner == VIDENC_BUFFER_WITH_DSP)
-                { 
-                    
+                {
+
                     pCompPortIn->pBufferPrivate[i]->eBufferOwner = VIDENC_BUFFER_WITH_TUNNELEDCOMP;
 #ifdef __PERF_INSTRUMENTATION__
                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
@@ -1023,7 +1068,7 @@
                                       0,
                                       PERF_ModuleLLMM);
 #endif
-                    eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent, 
+                    eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent,
                                                 pCompPortIn->pBufferPrivate[i]->pBufferHdr);
                     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER4,
                                           "FillThisBuffer failed (%x)\n", eError);
@@ -1032,31 +1077,31 @@
         }
         if (bInternalFlush == OMX_FALSE)
         {
-            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                     OMX_EventCmdComplete, 
-                                     OMX_CommandFlush, 
-                                     VIDENC_INPUT_PORT, 
+            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                     OMX_EventCmdComplete,
+                                     OMX_CommandFlush,
+                                     VIDENC_INPUT_PORT,
                                      NULL);
         }
     }
-    if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == -1)
+    if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == (OMX_U32)-1)
     {
-        aParam[0] = USN_STRMCMD_FLUSH; 
-        aParam[1] = VIDENC_OUTPUT_PORT; 
-        aParam[2] = 0x0; 
+        aParam[0] = USN_STRMCMD_FLUSH;
+        aParam[1] = VIDENC_OUTPUT_PORT;
+        aParam[2] = 0x0;
 
         eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-                                   EMMCodecControlStrmCtrl, 
+                                   EMMCodecControlStrmCtrl,
                                    (void*)aParam);
         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
                               "DSP Output flush failed (%x).\n", eError);
 #ifndef UNDER_CE
-		pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+        pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
         while (pComponentPrivate->bFlushComplete == OMX_FALSE)
         {
-			pthread_cond_wait(&pComponentPrivate->flush_cond, &pComponentPrivate->videoe_mutex_app);
-		}
-		pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+            pthread_cond_wait(&pComponentPrivate->flush_cond, &pComponentPrivate->videoe_mutex_app);
+        }
+        pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
 #else
         while (pComponentPrivate->bFlushComplete == OMX_FALSE)
         {
@@ -1081,20 +1126,21 @@
                                       PREF(pCompPortOut->pBufferPrivate[i]->pBufferHdr,nFilledLen),
                                       PERF_ModuleHLMM);
 #endif
-                    /*Copy Buffer Data to be propagated*/        
-                    OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[i]->pBufferHdr, 
+                    /*Copy Buffer Data to be propagated*/
+                    OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[i]->pBufferHdr,
                                                        pComponentPrivate->sCircularBuffer,
                                                        pComponentPrivate);
-                     /* trigger event handler if we are supposed to */ 
-                    if (pCompPortOut->pBufferPrivate[i]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle && 
+                     /* trigger event handler if we are supposed to */
+                    if (pCompPortOut->pBufferPrivate[i]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle &&
                         pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData)
                     {
-                        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,  
-                                                 OMX_EventMark, 
-                                                 0x0, 
-                                                 0x0, 
+                        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                                 OMX_EventMark,
+                                                 0x0,
+                                                 0x0,
                                                  pCompPortOut->pBufferPrivate[i]->pBufferHdr->pMarkData);
-                    }                             
+                    }
+                    OMX_PRINT2(pComponentPrivate->dbg, "FBD %p, FilledLen=%lu\n", pCompPortOut->pBufferPrivate[i]->pBufferHdr, pCompPortOut->pBufferPrivate[i]->pBufferHdr->nFilledLen);
                     pComponentPrivate->sCbData.FillBufferDone(pComponentPrivate->pHandle,
                                                               pComponentPrivate->pHandle->pApplicationPrivate,
                                                               pCompPortOut->pBufferPrivate[i]->pBufferHdr);
@@ -1107,10 +1153,10 @@
         }
         if (bInternalFlush == OMX_FALSE)
         {
-            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                     OMX_EventCmdComplete, 
-                                     OMX_CommandFlush, 
-                                     VIDENC_OUTPUT_PORT, 
+            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                     OMX_EventCmdComplete,
+                                     OMX_CommandFlush,
+                                     VIDENC_OUTPUT_PORT,
                                      NULL);
         }
     }
@@ -1140,11 +1186,11 @@
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
-  
+
     switch (nParam1)
     {
     case OMX_StateIdle:
@@ -1170,21 +1216,21 @@
     case OMX_StateInvalid:
             if (pComponentPrivate->eState == OMX_StateInvalid)
             {
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                         OMX_EventError, 
-                                         OMX_ErrorSameState, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                         OMX_EventError,
+                                         OMX_ErrorSameState,
                                          OMX_TI_ErrorSevere,
                                          NULL);
             }
             else
             {
                 pComponentPrivate->eState = OMX_StateInvalid;
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                         OMX_EventError, 
-                                         OMX_ErrorInvalidState, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                         OMX_EventError,
+                                         OMX_ErrorInvalidState,
                                          OMX_TI_ErrorSevere,
                                          NULL);
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
                                          OMX_EventCmdComplete,
                                          OMX_CommandStateSet,
                                          OMX_StateInvalid,
@@ -1204,20 +1250,20 @@
             {
                 pComponentPrivate->eState = OMX_StateWaitForResources;
                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                         OMX_EventCmdComplete, 
-                                         OMX_CommandStateSet, 
-                                         OMX_StateWaitForResources, 
+                                         OMX_EventCmdComplete,
+                                         OMX_CommandStateSet,
+                                         OMX_StateWaitForResources,
                                          NULL);
             }
             else
             {
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                         OMX_EventError, 
-                                         OMX_ErrorIncorrectStateTransition, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                         OMX_EventError,
+                                         OMX_ErrorIncorrectStateTransition,
                                          OMX_TI_ErrorMinor,
                                          NULL);
             }
-            break;   
+            break;
         case OMX_StateMax:
             break;
     } /* End of Switch */
@@ -1250,26 +1296,26 @@
 
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pCompPortIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
     pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
-    
+
 
     switch (pComponentPrivate->eState)
     {
         case OMX_StateIdle:
-            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                     OMX_EventError, 
-                                     OMX_ErrorSameState, 
+            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                     OMX_EventError,
+                                     OMX_ErrorSameState,
                                      OMX_TI_ErrorMinor,
                                      NULL);
             break;
         case OMX_StateInvalid:
-            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                     OMX_EventError, 
-                                     OMX_ErrorIncorrectStateTransition, 
+            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                     OMX_EventError,
+                                     OMX_ErrorIncorrectStateTransition,
                                      OMX_TI_ErrorMajor,
                                      NULL);
             break;
@@ -1285,22 +1331,22 @@
             while ( (!pPortDefIn->bPopulated) || (!pPortDefOut->bPopulated))
             {
 #ifndef UNDER_CE
-				pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
+                pthread_cond_wait(&pComponentPrivate->populate_cond, &pComponentPrivate->videoe_mutex_app);
 #else
-			OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
+            OMX_WaitForEvent(&(pComponentPrivate->InLoaded_event));
 #endif
-			}
-			pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
-		}
-            /* Make sure the DSP node has been deleted first to cover 
+            }
+            pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+        }
+            /* Make sure the DSP node has been deleted first to cover
                    any idle->loaded->idle or idle->wfr->idle combinations
-                   */ 
-            if (pComponentPrivate->bCodecStarted == OMX_TRUE || 
-                pComponentPrivate->bCodecLoaded == OMX_TRUE) 
+                   */
+            if (pComponentPrivate->bCodecStarted == OMX_TRUE ||
+                pComponentPrivate->bCodecLoaded == OMX_TRUE)
             {
             OMX_PRDSP2(pComponentPrivate->dbg, "Attempting to destroy the node...\n");
                 pLcmlHandle = NULL;
-                pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML; 
+                pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
                 eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
                                            EMMCodecControlDestroy,
                                            NULL);
@@ -1326,12 +1372,12 @@
                 pComponentPrivate->bCodecStarted = OMX_FALSE;
                 pComponentPrivate->bCodecLoaded = OMX_FALSE;
             }
-            
+
             eError = OMX_VIDENC_InitLCML(pComponentPrivate);
         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
                               "Failed to initialize LCML (%x).\n", eError);
 
-#ifdef __PERF_INSTRUMENTATION__ 
+#ifdef __PERF_INSTRUMENTATION__
             pComponentPrivate->nLcml_nCntIp = 0;
             pComponentPrivate->nLcml_nCntOpReceived = 0;
 #endif
@@ -1341,7 +1387,7 @@
             OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
                                   "Failed to initialize H264 SN (%x).\n", eError);
             }
-            else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 || 
+            else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
                      pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
             {
                 eError = OMX_VIDENC_InitDSP_Mpeg4Enc(pComponentPrivate);
@@ -1354,7 +1400,7 @@
                          pPortDefOut->format.video.eCompressionFormat);
                 OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
             }
-                
+
 #ifdef RESOURCE_MANAGER_ENABLED
 
         OMX_PRMGR2(pComponentPrivate->dbg, "Setting CallBack In Video Encoder component\n");
@@ -1366,22 +1412,22 @@
                      {
                         case OMX_VIDEO_AVCLevel1:
                         case OMX_VIDEO_AVCLevel1b:
-                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                         RMProxy_RequestResource, 
-                                                         OMX_H264_Encode_COMPONENT, 
-                                                         90, 
+                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                         RMProxy_RequestResource,
+                                                         OMX_H264_Encode_COMPONENT,
+                                                         VIDEO_ENCODER_MHZ,
                                                          3456,
-														 &(pComponentPrivate->cRMCallBack)); 
-                                                         
+                                                         &(pComponentPrivate->cRMCallBack));
+
                             break;
                         case OMX_VIDEO_AVCLevel11:
                         case OMX_VIDEO_AVCLevel12:
-                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                         RMProxy_RequestResource, 
-                                                         OMX_H264_Encode_COMPONENT, 
-                                                         140, 
+                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                         RMProxy_RequestResource,
+                                                         OMX_H264_Encode_COMPONENT,
+                                                         VIDEO_ENCODER_MHZ,
                                                          3456,
-														 &(pComponentPrivate->cRMCallBack)); 
+                                                         &(pComponentPrivate->cRMCallBack));
                             break;
                         case OMX_VIDEO_AVCLevel13:
                         case OMX_VIDEO_AVCLevel2:
@@ -1389,20 +1435,13 @@
                         case OMX_VIDEO_AVCLevel22:
                         case OMX_VIDEO_AVCLevel3:
                          default:
-                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                            RMProxy_RequestResource, 
+                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                            RMProxy_RequestResource,
                                                             OMX_H264_Encode_COMPONENT,
-                                                            ((pPortDefOut->format.video.nFrameHeight >= 640 ||
-                                                              pPortDefOut->format.video.nFrameWidth >= 480) &&
-                                                             pPortDefIn->format.video.xFramerate > 15) ? 370 : 245,
+                                                            VIDEO_ENCODER_MHZ,
                                                             3456,
-                                                            &(pComponentPrivate->cRMCallBack)); 
+                                                            &(pComponentPrivate->cRMCallBack));
                     }
-             /*       eError = RMProxy_SendCommand(pComponentPrivate->pHandle, 
-                                                 RMProxy_RequestResource, 
-                                                 OMX_H264_Encode_COMPONENT, 
-                                                 nTmp, 
-                                                 NULL);*/
                     break;
                 case OMX_VIDEO_CodingMPEG4:
                     switch(pComponentPrivate->pMpeg4->eLevel)
@@ -1410,30 +1449,30 @@
                         case 0:
                         case 1:
                         case 100:
-                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                         RMProxy_RequestResource, 
-                                                         OMX_MPEG4_Encode_COMPONENT, 
-                                                         30, 
+                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                         RMProxy_RequestResource,
+                                                         OMX_MPEG4_Encode_COMPONENT,
+                                                         VIDEO_ENCODER_MHZ,
                                                          3456,
-														 &(pComponentPrivate->cRMCallBack)); 
+                                                         &(pComponentPrivate->cRMCallBack));
                             break;
                         case 2:
                         case 3:
-                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                         RMProxy_RequestResource, 
+                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                         RMProxy_RequestResource,
                                                          OMX_MPEG4_Encode_COMPONENT,
-                                                         110, 
+                                                         VIDEO_ENCODER_MHZ,
                                                          3456,
-														 &(pComponentPrivate->cRMCallBack)); 
+                                                         &(pComponentPrivate->cRMCallBack));
                             break;
                         case 4:
                         default:
-                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                         RMProxy_RequestResource, 
-                                                         OMX_MPEG4_Encode_COMPONENT, 
-                                                         300, 
+                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                         RMProxy_RequestResource,
+                                                         OMX_MPEG4_Encode_COMPONENT,
+                                                         VIDEO_ENCODER_MHZ,
                                                          3456,
-														 &(pComponentPrivate->cRMCallBack)); 
+                                                         &(pComponentPrivate->cRMCallBack));
                     }
                     break;
                 case OMX_VIDEO_CodingH263:
@@ -1441,22 +1480,22 @@
                     {
                         case OMX_VIDEO_H263Level10:
                         case OMX_VIDEO_H263Level40:
-                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                         RMProxy_RequestResource, 
-                                                         OMX_H263_Encode_COMPONENT, 
-                                                         30, 
+                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                         RMProxy_RequestResource,
+                                                         OMX_H263_Encode_COMPONENT,
+                                                         VIDEO_ENCODER_MHZ,
                                                          3456,
-														 &(pComponentPrivate->cRMCallBack)); 
+                                                         &(pComponentPrivate->cRMCallBack));
                             break;
                         case OMX_VIDEO_H263Level20:
                         case OMX_VIDEO_H263Level30:
                         default:
-                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                         RMProxy_RequestResource, 
-                                                         OMX_H263_Encode_COMPONENT, 
-                                                         90, 
+                            eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                         RMProxy_RequestResource,
+                                                         OMX_H263_Encode_COMPONENT,
+                                                         VIDEO_ENCODER_MHZ,
                                                          3456,
-														 &(pComponentPrivate->cRMCallBack)); 
+                                                         &(pComponentPrivate->cRMCallBack));
                     }
                     break;
                 default:
@@ -1465,16 +1504,16 @@
                     OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
             }
 
-			/* Resource Manager Proxy Calls */
+            /* Resource Manager Proxy Calls */
                 if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
                 {
                     /* TODO: Disable RM Send for now */
                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Idle from Loaded\n");
-                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                 RMProxy_StateSet, 
-                                                 OMX_H264_Encode_COMPONENT, 
-                                                 OMX_StateIdle, 
+                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                 RMProxy_StateSet,
+                                                 OMX_H264_Encode_COMPONENT,
+                                                 OMX_StateIdle,
                                                  3456,
                                                  NULL);
                 }
@@ -1483,10 +1522,10 @@
                     /* TODO: Disable RM Send for now */
                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Idle from Loaded\n");
-					eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                 RMProxy_StateSet, 
-                                                 OMX_MPEG4_Encode_COMPONENT, 
-                                                 OMX_StateIdle, 
+                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                 RMProxy_StateSet,
+                                                 OMX_MPEG4_Encode_COMPONENT,
+                                                 OMX_StateIdle,
                                                  3456,
                                                  NULL);
                 }
@@ -1495,22 +1534,22 @@
                     /* TODO: Disable RM Send for now */
                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
             OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Idle from Loaded\n");
-                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                 RMProxy_StateSet, 
-                                                 OMX_H263_Encode_COMPONENT, 
-                                                 OMX_StateIdle, 
+                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                 RMProxy_StateSet,
+                                                 OMX_H263_Encode_COMPONENT,
+                                                 OMX_StateIdle,
                                                  3456,
-                                                 NULL);                  
+                                                 NULL);
                 }
         if (eError != OMX_ErrorNone)
         {
-               OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                             OMX_EventError, 
-                                             OMX_ErrorHardware, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                             OMX_EventError,
+                                             OMX_ErrorHardware,
                                              OMX_TI_ErrorSevere,
                                              NULL);
                 }
-                  	
+
            if (eError == OMX_ErrorNone) {
 
                pComponentPrivate->eState = OMX_StateIdle;
@@ -1525,16 +1564,16 @@
                }
 
                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                         OMX_EventCmdComplete, 
-                                         OMX_CommandStateSet, 
-                                         OMX_StateIdle, 
+                                         OMX_EventCmdComplete,
+                                         OMX_CommandStateSet,
+                                         OMX_StateIdle,
                                          NULL);
             }
             else if (eError == OMX_ErrorInsufficientResources)
             {
                 pComponentPrivate->eState = OMX_StateWaitForResources;
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                         OMX_EventError, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                         OMX_EventError,
                                          OMX_ErrorInsufficientResources,
                                          OMX_TI_ErrorMajor,
                                          NULL);
@@ -1546,17 +1585,17 @@
                           PERF_BoundaryComplete | PERF_BoundarySetup);
 #endif
 
-               /* Decrement reference count with signal enabled */
-               if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
-                     return OMX_ErrorUndefined;
-               }
+            /* Decrement reference count with signal enabled */
+            if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
+                return OMX_ErrorUndefined;
+            }
 
-            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                     OMX_EventCmdComplete, 
+            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                     OMX_EventCmdComplete,
                                      OMX_CommandStateSet,
-                                     OMX_StateIdle, 
+                                     OMX_StateIdle,
                                      NULL);
-#endif            
+#endif
             break;
         case OMX_StateExecuting:
         case OMX_StatePause:
@@ -1567,32 +1606,32 @@
 #endif
 
             pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
-            eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 
-                                       MMCodecControlStop, 
+            eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                       MMCodecControlStop,
                                        NULL);
         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP3,
                               "Failed to stop socket node (%x).\n", eError);
-            pComponentPrivate->bCodecStarted = OMX_FALSE; 
+            pComponentPrivate->bCodecStarted = OMX_FALSE;
         OMX_PRDSP2(pComponentPrivate->dbg, "MMCodecControlStop called...\n");
 
 #ifndef UNDER_CE
-		    pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+            pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
         while (pComponentPrivate->bDSPStopAck == OMX_FALSE)
         {
-     			pthread_cond_wait(&pComponentPrivate->stop_cond, &pComponentPrivate->videoe_mutex_app);
-	    	}
-		    pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+                pthread_cond_wait(&pComponentPrivate->stop_cond, &pComponentPrivate->videoe_mutex_app);
+            }
+            pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
 #else
         while (pComponentPrivate->bDSPStopAck == OMX_FALSE)
         {
                 sched_yield();
             }
 #endif
-            pComponentPrivate->bDSPStopAck = OMX_FALSE; 
- 
+            pComponentPrivate->bDSPStopAck = OMX_FALSE;
+
             for (nCount = 0; nCount < pPortDefIn->nBufferCountActual; nCount++)
             {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [OWNER = %d]\n", 
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [OWNER = %d]\n",
                           nCount,
                           VIDENC_INPUT_PORT,
                           pCompPortIn->pBufferPrivate[nCount]->pBufferHdr,
@@ -1601,24 +1640,24 @@
                 if (pCompPortIn->pBufferPrivate[nCount]->eBufferOwner == VIDENC_BUFFER_WITH_DSP ||
                     pCompPortIn->pBufferPrivate[nCount]->eBufferOwner == VIDENC_BUFFER_WITH_COMPONENT)
                 {
-                OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [SEND BACK TO SUPPLIER]\n", 
+                OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [SEND BACK TO SUPPLIER]\n",
                               nCount,
-                              VIDENC_INPUT_PORT, 
+                              VIDENC_INPUT_PORT,
                               pCompPortIn->pBufferPrivate[nCount]->pBufferHdr);
 
                     if (pCompPortIn->hTunnelComponent == NULL)
                     {
-                        
-                        pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0; 
-                    OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [memset %lu bytes]\n", 
+
+                        pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0;
+                    OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [memset %lu bytes]\n",
                                   nCount,
-                                  VIDENC_INPUT_PORT, 
+                                  VIDENC_INPUT_PORT,
                                   pCompPortIn->pBufferPrivate[nCount]->pBufferHdr,
                                   pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nAllocLen);
-                                                  
-                        memset(pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->pBuffer, 
+
+                        memset(pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->pBuffer,
                                0x0,
-                               pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nAllocLen); 
+                               pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nAllocLen);
 
                         pCompPortIn->pBufferPrivate[nCount]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
 #ifdef __PERF_INSTRUMENTATION__
@@ -1631,9 +1670,9 @@
                                                                    pComponentPrivate->pHandle->pApplicationPrivate,
                                                                    pCompPortIn->pBufferPrivate[nCount]->pBufferHdr);
                     }
-                    else 
+                    else
                     {
-                        pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0; 
+                        pCompPortIn->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0;
                         pCompPortIn->pBufferPrivate[nCount]->eBufferOwner = VIDENC_BUFFER_WITH_TUNNELEDCOMP;
 #ifdef __PERF_INSTRUMENTATION__
                         PERF_SendingFrame(pComponentPrivate->pPERFcomp,
@@ -1641,7 +1680,7 @@
                                           0,
                                           PERF_ModuleLLMM);
 #endif
-                        eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent, 
+                        eError = OMX_FillThisBuffer(pCompPortIn->hTunnelComponent,
                                                     pCompPortIn->pBufferPrivate[nCount]->pBufferHdr);
                     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER4,
                                           "FillThisBuffer failed (%x).\n", eError);
@@ -1651,7 +1690,7 @@
 
             for (nCount = 0; nCount < pPortDefOut->nBufferCountActual; nCount++)
             {
-            OMX_PRBUFFER2(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [OWNER = %d]\n", 
+            OMX_PRBUFFER2(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [OWNER = %d]\n",
                           nCount,
                           VIDENC_OUTPUT_PORT,
                           pCompPortOut->pBufferPrivate[nCount]->pBufferHdr,
@@ -1663,22 +1702,22 @@
 
                     if (pCompPortOut->hTunnelComponent == NULL)
                     {
-                    OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [memset %lu bytes]\n", 
+                    OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [memset %lu bytes]\n",
                                   nCount,
-                                  VIDENC_OUTPUT_PORT, 
+                                  VIDENC_OUTPUT_PORT,
                                   pCompPortOut->pBufferPrivate[nCount]->pBufferHdr,
                                   pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nAllocLen);
-                                  
-                        memset(pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->pBuffer, 
+
+                        memset(pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->pBuffer,
                                0x0,
-                               pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nAllocLen); 
+                               pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nAllocLen);
                     }
 
                 OMX_PRBUFFER1(pComponentPrivate->dbg, "Buffer[%d]:port[%d] -> %p [SEND BACK TO SUPPLIER]\n", nCount,
-                                                         VIDENC_OUTPUT_PORT, 
+                                                         VIDENC_OUTPUT_PORT,
                                                          pCompPortOut->pBufferPrivate[nCount]->pBufferHdr);
 
-                    pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0; 
+                    pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nFilledLen = 0;
                     pCompPortOut->pBufferPrivate[nCount]->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
 #ifdef __PERF_INSTRUMENTATION__
                     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
@@ -1687,24 +1726,24 @@
                                       PERF_ModuleHLMM);
 #endif
                     /*Propagate pBufferHeader Data*/
-                    OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[nCount]->pBufferHdr, 
+                    OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pCompPortOut->pBufferPrivate[nCount]->pBufferHdr,
                                                    pComponentPrivate->sCircularBuffer,
                                                    pComponentPrivate);
-                    /* trigger event handler if we are supposed to */ 
-                    if (pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle && 
+                    /* trigger event handler if we are supposed to */
+                    if (pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->hMarkTargetComponent == pComponentPrivate->pHandle &&
                         pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->pMarkData)
                     {
-                        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,  
-                                                 OMX_EventMark, 
-                                                 0x0, 
-                                                 0x0, 
+                        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                                 OMX_EventMark,
+                                                 0x0,
+                                                 0x0,
                                                  pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->pMarkData);
-                    }   
-                    OMX_PRINT2(pComponentPrivate->dbg, "sending FillBufferDone %p \n", pCompPortOut->pBufferPrivate[nCount]->pBufferHdr);
+                    }
+                    OMX_PRINT2(pComponentPrivate->dbg, "FBD %p, FilledLen=%lu\n", pCompPortOut->pBufferPrivate[nCount]->pBufferHdr, pCompPortOut->pBufferPrivate[nCount]->pBufferHdr->nFilledLen);
                     pComponentPrivate->sCbData.FillBufferDone(pComponentPrivate->pHandle,
                                                               pComponentPrivate->pHandle->pApplicationPrivate,
                                                               pCompPortOut->pBufferPrivate[nCount]->pBufferHdr);
-                } 
+                }
             }
 
 #ifdef RESOURCE_MANAGER_ENABLED /* Resource Manager Proxy Calls */
@@ -1712,10 +1751,10 @@
                 {
                     /* TODO: Disable RM Send for now */
                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
-                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                 RMProxy_StateSet, 
-                                                 OMX_H264_Encode_COMPONENT, 
-                                                 OMX_StateIdle, 
+                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                 RMProxy_StateSet,
+                                                 OMX_H264_Encode_COMPONENT,
+                                                 OMX_StateIdle,
                                                  3456,
                                                  NULL);
                 }
@@ -1723,10 +1762,10 @@
                 {
                     /* TODO: Disable RM Send for now */
                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
-                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                 RMProxy_StateSet, 
-                                                 OMX_MPEG4_Encode_COMPONENT, 
-                                                 OMX_StateIdle, 
+                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                 RMProxy_StateSet,
+                                                 OMX_MPEG4_Encode_COMPONENT,
+                                                 OMX_StateIdle,
                                                  3456,
                                                  NULL);
                 }
@@ -1735,23 +1774,23 @@
                     /* TODO: Disable RM Send for now */
                     /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
             OMX_PRMGR2(pComponentPrivate->dbg, "Setting Idle state from Executing to RMProxy\n");
-                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                                 RMProxy_StateSet, 
-                                                 OMX_H263_Encode_COMPONENT, 
-                                                 OMX_StateIdle, 
+                    eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                                 RMProxy_StateSet,
+                                                 OMX_H263_Encode_COMPONENT,
+                                                 OMX_StateIdle,
                                                  3456,
-                                                 NULL);                  
+                                                 NULL);
                 }
         if (eError != OMX_ErrorNone)
         {
-                    OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                             OMX_EventError, 
-                                             OMX_ErrorHardware, 
+                    OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                             OMX_EventError,
+                                             OMX_ErrorHardware,
                                              OMX_TI_ErrorMajor,
                                              NULL);
                 }
-                
-#endif                
+
+#endif
         OMX_PRBUFFER2(pComponentPrivate->dbg, "Flushing Pipes!\n");
         eError = OMX_VIDENC_EmptyDataPipes (pComponentPrivate);
         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRBUFFER3,
@@ -1759,22 +1798,21 @@
 
         pComponentPrivate->eState = OMX_StateIdle;
 
-         /* Decrement reference count with signal enabled */
-         if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
-              return OMX_ErrorUndefined;
-         }
+        /* Decrement reference count with signal enabled */
+        if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
+             return OMX_ErrorUndefined;
+        }
 
-         OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                     OMX_EventCmdComplete, 
-                                     OMX_CommandStateSet, 
-                                     OMX_StateIdle, 
-                                     NULL);
-          break;
-
+        OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                 OMX_EventCmdComplete,
+                                 OMX_CommandStateSet,
+                                 OMX_StateIdle,
+                                 NULL);
+        break;
         default:
-            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                     OMX_EventError, 
-                                     OMX_ErrorIncorrectStateTransition, 
+            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                     OMX_EventError,
+                                     OMX_ErrorIncorrectStateTransition,
                                      OMX_TI_ErrorMinor,
                                      NULL);
     }
@@ -1797,14 +1835,14 @@
 OMX_ERRORTYPE OMX_VIDENC_HandleCommandStateSetExecuting(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    LCML_DSP_INTERFACE* pLcmlHandle = NULL;  
+    LCML_DSP_INTERFACE* pLcmlHandle = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
-    pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef; 
+    pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
 
     switch (pComponentPrivate->eState)
     {
@@ -1826,7 +1864,7 @@
                                            NULL);
             OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
                                   "Failed to start socket node (%x).\n", eError);
-                
+
                 pComponentPrivate->bCodecStarted = OMX_TRUE;
             }
 
@@ -1836,10 +1874,10 @@
                 /* TODO: Disable RM Send for now */
             OMX_PRMGR2(pComponentPrivate->dbg, "Setting executing state to RMProxy\n");
                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
-                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                             RMProxy_StateSet, 
-                                             OMX_H264_Encode_COMPONENT, 
-                                             OMX_StateExecuting, 
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_StateSet,
+                                             OMX_H264_Encode_COMPONENT,
+                                             OMX_StateExecuting,
                                              3456,
                                              NULL);
             }
@@ -1848,10 +1886,10 @@
                 /* TODO: Disable RM Send for now */
             OMX_PRMGR2(pComponentPrivate->dbg, "Setting executing state to RMProxy\n");
                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
-                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                             RMProxy_StateSet, 
-                                             OMX_MPEG4_Encode_COMPONENT, 
-                                             OMX_StateExecuting, 
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_StateSet,
+                                             OMX_MPEG4_Encode_COMPONENT,
+                                             OMX_StateExecuting,
                                              3456,
                                              NULL);
 
@@ -1861,23 +1899,23 @@
                 /* TODO: Disable RM Send for now */
                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
             OMX_PRMGR2(pComponentPrivate->dbg, "Setting executing state to RMProxy\n");
-                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                             RMProxy_StateSet, 
-                                             OMX_H263_Encode_COMPONENT, 
-                                             OMX_StateExecuting, 
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_StateSet,
+                                             OMX_H263_Encode_COMPONENT,
+                                             OMX_StateExecuting,
                                              3456,
                                              NULL);
             }
             if (eError != OMX_ErrorNone)
             {
                 pComponentPrivate->eState = OMX_StateWaitForResources;
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                         OMX_EventError, 
-                                         OMX_ErrorHardware, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                         OMX_EventError,
+                                         OMX_ErrorHardware,
                                          OMX_TI_ErrorMajor,
                                          NULL);
             }
-#endif         
+#endif
             pComponentPrivate->eState = OMX_StateExecuting;
 #ifdef __PERF_INSTRUMENTATION__
             PERF_Boundary(pComponentPrivate->pPERFcomp,
@@ -1891,15 +1929,15 @@
 
             /*Send state change notificaiton to Application*/
             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                     OMX_EventCmdComplete, 
-                                     OMX_CommandStateSet, 
-                                     OMX_StateExecuting, 
+                                     OMX_EventCmdComplete,
+                                     OMX_CommandStateSet,
+                                     OMX_StateExecuting,
                                      NULL);
             break;
         default:
             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                     OMX_EventError, 
-                                     OMX_ErrorIncorrectStateTransition, 
+                                     OMX_EventError,
+                                     OMX_ErrorIncorrectStateTransition,
                                      OMX_TI_ErrorMinor,
                                      NULL);
     }
@@ -1925,20 +1963,20 @@
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
-        
-    OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
-	pLcmlHandle 	= (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
-    pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
-    pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;  
 
-    
+    OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
+
+    pLcmlHandle     = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
+    pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
+    pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
+
+
     switch (pComponentPrivate->eState)
     {
         case OMX_StatePause:
             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                     OMX_EventError, 
-                                     OMX_ErrorSameState, 
+                                     OMX_EventError,
+                                     OMX_ErrorSameState,
                                      OMX_TI_ErrorMinor,
                                      NULL);
             break;
@@ -1950,32 +1988,32 @@
                           PERF_BoundaryComplete | PERF_BoundarySteadyState);
 #endif
             pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
-            eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 
-                                       EMMCodecControlPause, 
+            eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                       EMMCodecControlPause,
                                    NULL);
         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
                               "Failed to pause socket node (%x).\n", eError);
 
 
-        pComponentPrivate->bCodecStarted = OMX_FALSE; 
+        pComponentPrivate->bCodecStarted = OMX_FALSE;
         OMX_PRDSP2(pComponentPrivate->dbg, "MMCodecControlPaused called...\n");
 
-            
+
 #ifndef UNDER_CE
-			pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+            pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
         while (pComponentPrivate->bDSPStopAck == OMX_FALSE)
         {
-				pthread_cond_wait(&pComponentPrivate->stop_cond, &pComponentPrivate->videoe_mutex_app);
-			}
-			pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+                pthread_cond_wait(&pComponentPrivate->stop_cond, &pComponentPrivate->videoe_mutex_app);
+            }
+            pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
 #else
         while (pComponentPrivate->bDSPStopAck == OMX_FALSE)
         {
-				sched_yield();
-			}
+                sched_yield();
+            }
 #endif
 
-			pComponentPrivate->bDSPStopAck = OMX_FALSE; 
+            pComponentPrivate->bDSPStopAck = OMX_FALSE;
 
             pComponentPrivate->eState = OMX_StatePause;
 
@@ -1985,19 +2023,19 @@
             }
 
             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                     OMX_EventCmdComplete, 
-                                     OMX_CommandStateSet, 
-                                     OMX_StatePause, 
+                                     OMX_EventCmdComplete,
+                                     OMX_CommandStateSet,
+                                     OMX_StatePause,
                                      NULL);
             break;
         default:
             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                     OMX_EventError, 
-                                     OMX_ErrorIncorrectStateTransition, 
+                                     OMX_EventError,
+                                     OMX_ErrorIncorrectStateTransition,
                                      OMX_TI_ErrorMinor,
                                      NULL);
     }
-    
+
 OMX_CONF_CMD_BAIL:
     return eError;
 }
@@ -2017,131 +2055,48 @@
 OMX_ERRORTYPE OMX_VIDENC_HandleCommandStateSetLoaded (VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    LCML_DSP_INTERFACE* pLcmlHandle = NULL;  
+    LCML_DSP_INTERFACE* pLcmlHandle = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
-    
+
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-   
+
     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
-    pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;  
+    pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
 
     switch (pComponentPrivate->eState)
     {
         case OMX_StateLoaded:
             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                     OMX_EventError, 
-                                     OMX_ErrorSameState, 
+                                     OMX_EventError,
+                                     OMX_ErrorSameState,
                                      OMX_TI_ErrorMinor,
                                      NULL);
-            break;        
-		case OMX_StateWaitForResources:
+            break;
+        case OMX_StateWaitForResources:
         OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning from WFR to Loaded\n");
 #ifdef RESOURCE_MANAGER_ENABLED
-			if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
-			{
-				/* TODO: Disable RM Send for now */
-				/* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
-            OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
-				eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-											 RMProxy_StateSet, 
-											 OMX_H264_Encode_COMPONENT, 
-											 OMX_StateLoaded, 
-											 3456,
-											 NULL);
-			}
-			else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
-			{
-				/* TODO: Disable RM Send for now */
-				/* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
-            OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
-				eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-											 RMProxy_StateSet, 
-											 OMX_MPEG4_Encode_COMPONENT, 
-											 OMX_StateLoaded, 
-											 3456,
-											 NULL);
-			}
-			else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
-			{
-				/* TODO: Disable RM Send for now */
-				/* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
-            OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
-				eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-											 RMProxy_StateSet, 
-											 OMX_H263_Encode_COMPONENT, 
-											 OMX_StateLoaded, 
-											 3456,
-											 NULL);
-			}
-			if (eError != OMX_ErrorNone)
-			{
-				OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-										 OMX_EventError, 
-										 OMX_ErrorHardware, 
-										 OMX_TI_ErrorMajor,
-										 NULL);
-				break;
-			}
-#endif
-		       pComponentPrivate->eState = OMX_StateLoaded;
-                       /* Decrement reference count with signal enabled */
-                       if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
-                             return OMX_ErrorUndefined;
-                        }
-
-					
-			#ifdef __PERF_INSTRUMENTATION__
-				PERF_Boundary(pComponentPrivate->pPERFcomp,
-							  PERF_BoundaryComplete | PERF_BoundaryCleanup);
-			#endif
-			OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-									 OMX_EventCmdComplete, 
-									 OMX_CommandStateSet, 
-									 OMX_StateLoaded, 
-									 NULL);
-			break;
-		case OMX_StateIdle:
-        OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning from Idle to Loaded\n");
-            pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
-	#ifdef __PERF_INSTRUMENTATION__
-            PERF_Boundary(pComponentPrivate->pPERFcomp,
-                          PERF_BoundaryStart | PERF_BoundaryCleanup); 
-	#endif
-        if ( pPortDefIn->bEnabled == OMX_TRUE || pPortDefOut->bEnabled == OMX_TRUE )
-        {
-            pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
-            while ( (pPortDefIn->bPopulated) || (pPortDefOut->bPopulated))
-            {
-	#ifndef UNDER_CE
-					pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
-	#else
-					OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
-	#endif
-				}
-				pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
-			}
-            
-	#ifdef RESOURCE_MANAGER_ENABLED /* Resource Manager Proxy Calls */
             if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
             {
                 /* TODO: Disable RM Send for now */
                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
-                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                             RMProxy_FreeResource, 
-                                             OMX_H264_Encode_COMPONENT, 
-                                             0, 
+            OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_StateSet,
+                                             OMX_H264_Encode_COMPONENT,
+                                             OMX_StateLoaded,
                                              3456,
-                                             NULL);              
+                                             NULL);
             }
             else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
             {
                 /* TODO: Disable RM Send for now */
                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
-                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                             RMProxy_FreeResource, 
-                                             OMX_MPEG4_Encode_COMPONENT, 
-                                             0, 
+            OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_StateSet,
+                                             OMX_MPEG4_Encode_COMPONENT,
+                                             OMX_StateLoaded,
                                              3456,
                                              NULL);
             }
@@ -2149,23 +2104,104 @@
             {
                 /* TODO: Disable RM Send for now */
                 /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
-                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle, 
-                                             RMProxy_FreeResource, 
-                                             OMX_H263_Encode_COMPONENT, 
-                                             0, 
+            OMX_PRMGR2(pComponentPrivate->dbg, "RMProxy_SendCommand: Setting state to Loaded from WFR\n");
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_StateSet,
+                                             OMX_H263_Encode_COMPONENT,
+                                             OMX_StateLoaded,
                                              3456,
                                              NULL);
             }
             if (eError != OMX_ErrorNone)
             {
                 OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                         OMX_EventError, 
-                                         OMX_ErrorHardware, 
+                                         OMX_EventError,
+                                         OMX_ErrorHardware,
+                                         OMX_TI_ErrorMajor,
+                                         NULL);
+                break;
+            }
+#endif
+            pComponentPrivate->eState = OMX_StateLoaded;
+            /* Decrement reference count with signal enabled */
+            if(RemoveStateTransition(pComponentPrivate, 1) != OMX_ErrorNone) {
+                return OMX_ErrorUndefined;
+            }
+
+            #ifdef __PERF_INSTRUMENTATION__
+                PERF_Boundary(pComponentPrivate->pPERFcomp,
+                              PERF_BoundaryComplete | PERF_BoundaryCleanup);
+            #endif
+            OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                     OMX_EventCmdComplete,
+                                     OMX_CommandStateSet,
+                                     OMX_StateLoaded,
+                                     NULL);
+            break;
+        case OMX_StateIdle:
+        OMX_PRSTATE2(pComponentPrivate->dbg, "Transitioning from Idle to Loaded\n");
+            pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
+    #ifdef __PERF_INSTRUMENTATION__
+            PERF_Boundary(pComponentPrivate->pPERFcomp,
+                          PERF_BoundaryStart | PERF_BoundaryCleanup);
+    #endif
+        if ( pPortDefIn->bEnabled == OMX_TRUE || pPortDefOut->bEnabled == OMX_TRUE )
+        {
+            pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+            while ( (pPortDefIn->bPopulated) || (pPortDefOut->bPopulated))
+            {
+    #ifndef UNDER_CE
+                    pthread_cond_wait(&pComponentPrivate->unpopulate_cond, &pComponentPrivate->videoe_mutex_app);
+    #else
+                    OMX_WaitForEvent(&(pComponentPrivate->InIdle_event));
+    #endif
+                }
+                pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+            }
+
+    #ifdef RESOURCE_MANAGER_ENABLED /* Resource Manager Proxy Calls */
+            if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
+            {
+                /* TODO: Disable RM Send for now */
+                /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H264_Encode_COMPONENT, 0); */
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_FreeResource,
+                                             OMX_H264_Encode_COMPONENT,
+                                             0,
+                                             3456,
+                                             NULL);
+            }
+            else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
+            {
+                /* TODO: Disable RM Send for now */
+                /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_MPEG4_Encode_COMPONENT, 0); */
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_FreeResource,
+                                             OMX_MPEG4_Encode_COMPONENT,
+                                             0,
+                                             3456,
+                                             NULL);
+            }
+            else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
+            {
+                /* TODO: Disable RM Send for now */
+                /* eError = RMProxy_SendCommand(pHandle, RMProxy_RequestResource, OMX_H263_Encode_COMPONENT, 0); */
+                eError = RMProxy_NewSendCommand(pComponentPrivate->pHandle,
+                                             RMProxy_FreeResource,
+                                             OMX_H263_Encode_COMPONENT,
+                                             0,
+                                             3456,
+                                             NULL);
+            }
+            if (eError != OMX_ErrorNone)
+            {
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                         OMX_EventError,
+                                         OMX_ErrorHardware,
                                          OMX_TI_ErrorMajor,
                                          NULL);
             }
-	#endif      
-
+    #endif
              /* Make sure the DSP node has been deleted */
              if (pComponentPrivate->bCodecStarted == OMX_TRUE || pComponentPrivate->bCodecLoaded == OMX_TRUE)
              {
@@ -2192,7 +2228,7 @@
 
 #ifdef __KHRONOS_CONF__
             pComponentPrivate->bPassingIdleToLoaded = OMX_FALSE;
-#endif            
+#endif
             pComponentPrivate->eState = OMX_StateLoaded;
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -2206,9 +2242,9 @@
             }
 
             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
-                                     OMX_EventCmdComplete, 
-                                     OMX_CommandStateSet, 
-                                     OMX_StateLoaded, 
+                                     OMX_EventCmdComplete,
+                                     OMX_CommandStateSet,
+                                     OMX_StateLoaded,
                                      NULL);
             break;
         default:
@@ -2238,7 +2274,7 @@
   **/
 /*---------------------------------------------------------------------------------------*/
 
-OMX_ERRORTYPE OMX_VIDENC_Process_FreeOutBuf(VIDENC_COMPONENT_PRIVATE* pComponentPrivate) 
+OMX_ERRORTYPE OMX_VIDENC_Process_FreeOutBuf(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
 {
     int nRet = -1;
     void *pUalgOutParams = NULL;
@@ -2248,13 +2284,13 @@
     LCML_DSP_INTERFACE* pLcmlHandle = NULL;
      VIDENC_BUFFER_PRIVATE* pBufferPrivate = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
-    
+
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
 
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
     pLcmlHandle = (LCML_DSP_INTERFACE*)(((VIDENC_COMPONENT_PRIVATE*)pComponentPrivate)->pLCML);
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
-    
+
 #ifndef UNDER_CE
     if (pthread_mutex_lock(&(pComponentPrivate->mVideoEncodeBufferMutex)) != 0)
     {
@@ -2262,15 +2298,15 @@
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
     }
     nRet = read(pComponentPrivate->nFree_oPipe[0], &pBufHead, sizeof(pBufHead));
-    if (nRet == -1)
+    if ((nRet == -1) || !pBufHead || !pBufHead->pOutputPortPrivate)
     {
-    	pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
+        pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
         OMX_ERROR4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
     }
-    OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, 1, 1);
+
     pBufferPrivate = pBufHead->pOutputPortPrivate;
-    
+
     pBufferPrivate->bReadFromPipe = OMX_TRUE;
     if (pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex)) != 0)
     {
@@ -2279,7 +2315,7 @@
     }
 #else
     nRet = read(pComponentPrivate->nFree_oPipe[0], &pBufHead, sizeof(pBufHead));
-    if (nRet == -1)
+    if ((nRet == -1) || (pBufHead == NULL) || (pBufHead->pOutputPortPrivate == NULL))
     {
         OMX_ERROR4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
@@ -2302,49 +2338,47 @@
         pBufferPrivate->eBufferOwner == VIDENC_BUFFER_WITH_CLIENT)
     {
 goto EXIT;
-	
+
 }
 
-	if(!pBufferPrivate || !pLcmlHandle || !pPortDefOut)
-		goto EXIT;
+    if(!pBufferPrivate || !pLcmlHandle || !pPortDefOut)
+        goto EXIT;
 
     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
     {
             pUalgOutParams =(H264VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam;
         OMX_PRBUFFER1(pComponentPrivate->dbg, " %p \n", (void*)pBufHead);
             pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
-            eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 
-                                      EMMCodecOuputBuffer, 
-                                      pBufHead->pBuffer, 
-                                      pPortDefOut->nBufferSize, 
-                                      0, 
-                                      (OMX_U8*)pUalgOutParams, 
-                                      sizeof(H264VE_GPP_SN_UALGOutputParams), 
+            eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                      EMMCodecOuputBuffer,
+                                      pBufHead->pBuffer,
+                                      pBufHead->nAllocLen,
+                                      0,
+                                      (OMX_U8*)pUalgOutParams,
+                                      sizeof(H264VE_GPP_SN_UALGOutputParams),
                                       (void*)pBufHead);
             if (eError != OMX_ErrorNone)
         {
             OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
         }
-                
+
     }
     else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
              pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
     {
-            pUalgOutParams = (MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam;
-
+        pUalgOutParams = (MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam;
         OMX_PRBUFFER1(pComponentPrivate->dbg, " %p\n", (void*)pBufHead);
-
-            pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
-            eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 
-                                      EMMCodecOuputBuffer, 
-                                      pBufHead->pBuffer, 
-                                      pPortDefOut->nBufferSize, 
-                                      0, 
-                                      (OMX_U8*)pUalgOutParams, 
-                                      sizeof(MP4VE_GPP_SN_UALGOutputParams), 
-                                      (void*)pBufHead);
-            if (eError != OMX_ErrorNone)
+        pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
+        eError = LCML_QueueBuffer(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                  EMMCodecOuputBuffer,
+                                  pBufHead->pBuffer,
+                                  pBufHead->nAllocLen,
+                                  0,
+                                  (OMX_U8*)pUalgOutParams,
+                                  sizeof(MP4VE_GPP_SN_UALGOutputParams),
+                                  (void*)pBufHead);
+        if (eError != OMX_ErrorNone)
         {
             OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
@@ -2356,7 +2390,7 @@
                       pPortDefOut->format.video.eCompressionFormat);
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
     }
-	EXIT:
+    EXIT:
 OMX_CONF_CMD_BAIL:
     return eError;
 }
@@ -2388,16 +2422,16 @@
     VIDENC_BUFFER_PRIVATE* pBufferPrivate = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
-	VIDEOENC_PORT_TYPE* pCompPortOut			= NULL;
-    
+    VIDEOENC_PORT_TYPE* pCompPortOut            = NULL;
+
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
 
-	pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
+    pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
-	pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
+    pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
-	
+
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pLcmlHandle, pPortDefIn, 1);
 
 #ifndef UNDER_CE
@@ -2407,9 +2441,9 @@
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
     }
     nRet = read(pComponentPrivate->nFilled_iPipe[0], &(pBufHead), sizeof(pBufHead));
-    if (nRet == -1)
+    if ((nRet == -1) || !pBufHead || !pBufHead->pInputPortPrivate)
     {
-    	pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
+        pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
         OMX_TRACE4(pComponentPrivate->dbg, "Error while reading from the pipe\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
     }
@@ -2418,10 +2452,9 @@
     {
     pBufferPrivate = (VIDENC_BUFFER_PRIVATE*)pBufHead->pInputPortPrivate;
    	}
-
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, pBufferPrivate, 1);
     pBufferPrivate->bReadFromPipe = OMX_TRUE;
-    
+
     if (pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex)) != 0)
     {
         OMX_TRACE4(pComponentPrivate->dbg, "pthread_mutex_unlock() failed.\n");
@@ -2438,10 +2471,10 @@
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, pBufferPrivate, 1);
     pBufferPrivate->bReadFromPipe = OMX_TRUE;
 #endif
-    
+
 #ifdef __PERF_INSTRUMENTATION__
     /*For Steady State Instumentation*/
-    #if 0 
+    #if 0
     if ((pComponentPrivate->nLcml_nCntIp == 1))
     {
         PERF_Boundary(pComponentPrivate->pPERFcomp,
@@ -2450,7 +2483,7 @@
     #endif
     PERF_SendingFrame(pComponentPrivate->pPERFcomp,
                       PREF(pBufHead,pBuffer),
-                      pPortDefIn->nBufferSize, 
+                      pPortDefIn->nBufferSize,
                       PERF_ModuleCommonLayer);
 #endif
 
@@ -2458,16 +2491,16 @@
         pBufferPrivate->eBufferOwner == VIDENC_BUFFER_WITH_CLIENT)
     {
         goto EXIT;
-    }	
+    }
 
 
 
     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
     {
-        
-        pUalgInpParams = (H264VE_GPP_SN_UALGInputParams*)pBufferPrivate->pUalgParam; 
+
+        pUalgInpParams = (H264VE_GPP_SN_UALGInputParams*)pBufferPrivate->pUalgParam;
         OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pUalgInpParams, 1, 1);
-        
+
         /*< must be followed for all video encoders*/
         /*  size of this structure             */
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.size = sizeof(H264VE_GPP_SN_UALGInputParams);
@@ -2476,11 +2509,11 @@
         /*  Input frame width                  */
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.inputWidth  = pPortDefIn->format.video.nFrameWidth;
         /*  Reference or input frame rate*1000 */
-        ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.refFrameRate = pPortDefIn->format.video.xFramerate*1000;
+        ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.refFrameRate = (OMX_U32)(Q16Tof(pPortDefIn->format.video.xFramerate)*1000.0);
         /*  Target frame rate * 1000           */
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.targetFrameRate = pComponentPrivate->nTargetFrameRate;
         /*  Target bit rate in bits per second */
-        ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.targetBitRate = pComponentPrivate->nTargetBitRate;
+        ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.targetBitRate = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate;
         /*  I frame interval e.g. 30           */
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.intraFrameInterval = pComponentPrivate->nIntraFrameInterval;
         /*  XDM_ENCODE_AU, XDM_GENERATE_HEADER */
@@ -2492,11 +2525,11 @@
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.captureWidth = 0;
         /*  Force given frame as I or IDR (in H.264)  frame    */
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.videncDynamicParams.forceIFrame = pComponentPrivate->bForceIFrame;
-        
-        
-        
+
+
+
         /*< initial QP of I frames Range[-1,51]. -1 is for auto initialization.*/
-        ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.qpIntra = 0x0000001c; 
+        ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.qpIntra = 0x0000001c;
         /*< initial QP of P frames Range[-1,51]. -1 is for auto initialization.*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.qpInter = 0x0000001c;
         /*< Maximum QP to be used  Range[0,51]*/
@@ -2509,9 +2542,9 @@
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.quartPelDisable = 0x00000000;
         /*< Adaptive Intra Refesh MB Period: Period at which intra macro blocks should be insterted in a frame*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.airMbPeriod = pComponentPrivate->nAIRRate;
-        /*< Maximum number of macro block in a slice - values less than 8 don't take effect. Setting to zero for better performance*/
+        /*< Maximum number of macro block in a slice <minimum value is 8>*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.maxMBsPerSlice = 0;
-        /*< Maximum number of bytes in a slice. Setting to zero for better performance*/
+        /*< Maximum number of bytes in a slice */
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.maxBytesPerSlice = 0;
         /*< Row number from which slice needs to be intra coded*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceRefreshRowStartNumber = 0;
@@ -2558,182 +2591,84 @@
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.pContext = NULL;
 
         /*< Following Parameter are related to Arbitrary Slice Ordering (ASO)*/
-        /*< Number of valid enteries in asoSliceOrder array valid range is [0,8], 
+        /*< Number of valid enteries in asoSliceOrder array valid range is [0,8],
         //!< where 0 and 1 doesn't have any effect*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.numSliceASO = pComponentPrivate->numSliceASO;
         /*!< Array containing the order of slices in which they should
         //!< be present in bit-stream. vaild enteries are [0, any entry lesser than numSlicesASO]*/
         for( i=0; i<MAXNUMSLCGPS;i++)
             ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.asoSliceOrder[i] = pComponentPrivate->asoSliceOrder[i];
-        
+
         /*< Following Parameter are related to Flexible macro block ordering (FMO)*/
         /*< Total Number of slice groups, valid enteries are [0,8]*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.numSliceGroups = pComponentPrivate->numSliceGroups;
         /*< Slice GroupMapType : For Valid enteries see IH264VENC_SliceGroupMapType*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupMapType = pComponentPrivate->sliceGroupMapType;
-        /*< Slice Group Change Direction Flag: Only valid when sliceGroupMapType 
-        //!< is equal to IH264_RASTER_SCAN_SLICE_GRP. 
+        /*< Slice Group Change Direction Flag: Only valid when sliceGroupMapType
+        //!< is equal to IH264_RASTER_SCAN_SLICE_GRP.
         //!< For valid values refer IH264VENC_SliceGroupChangeDirection*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeDirectionFlag = pComponentPrivate->sliceGroupChangeDirectionFlag;
-        /*< Slice Group Change Rate: Only valid when sliceGroupMapType 
-        //!< is equal to IH264_RASTER_SCAN_SLICE_GRP. 
+        /*< Slice Group Change Rate: Only valid when sliceGroupMapType
+        //!< is equal to IH264_RASTER_SCAN_SLICE_GRP.
         //!< valid values are : [0, factor of number of Mbs in a row]*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeRate = pComponentPrivate->sliceGroupChangeRate;
-        /*< Slice Group Change Cycle: Only valid when sliceGroupMapType 
-        //!< is equal to IH264_RASTER_SCAN_SLICE_GRP. 
+        /*< Slice Group Change Cycle: Only valid when sliceGroupMapType
+        //!< is equal to IH264_RASTER_SCAN_SLICE_GRP.
         //!< Valid values can be 0 to numMbsRowsInPicture, also constrained
         //!< by sliceGroupChangeRate*sliceGroupChangeCycle < totalMbsInFrame*/
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeCycle = pComponentPrivate->sliceGroupChangeCycle;
-        /*< This field is useful in case of sliceGroupMapType equal to either 
+        /*< This field is useful in case of sliceGroupMapType equal to either
         //!< IH264_INTERLEAVED_SLICE_GRP or IH264_FOREGRND_WITH_LEFTOVER_SLICE_GRP
         //!< In both cases it has different meaning:
         //!< In case of IH264_INTERLEAVED_SLICE_GRP:
-        //!< The i-th entery in this array is used to specify the number of consecutive 
-        //!< slice group macroblocks to be assigned to the i-th slice group in 
+        //!< The i-th entery in this array is used to specify the number of consecutive
+        //!< slice group macroblocks to be assigned to the i-th slice group in
         //!< raster scan order of slice group macroblock units.
         //!< Valid values are 0 to totalMbsInFrame again constrained by sum of all the elements
         //!< shouldn't exceed totalMbsInFrame
         //!< In case of IH264_FOREGRND_WITH_LEFTOVER_SLICE_GRP:
-        //!< First entry in the array specify the start position of foreground region in terms 
+        //!< First entry in the array specify the start position of foreground region in terms
         //!< of macroblock number, valid values are [0, totalMbsInFrame-1]
-        //!< Second entry in the array specify the end position of foreground region in terms 
+        //!< Second entry in the array specify the end position of foreground region in terms
         //!< of macroblock number, valid values are [0, totalMbsInFrame-1] with following constrains:
         //!< endPos > startPos && endPos%mbsInOneRow > startPos%mbsInOneRow*/
         for( i=0; i<MAXNUMSLCGPS;i++)
         {
             ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->H264VENC_TI_DYNAMICPARAMS.sliceGroupParams[i] = pComponentPrivate->sliceGroupParams[i];
         }
-   
+
         ((H264VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulFrameIndex = pComponentPrivate->nFrameCnt;
-        
-        pComponentPrivate->bForceIFrame = 0;   
+
+        pComponentPrivate->bForceIFrame = 0;
         ++pComponentPrivate->nFrameCnt;
-        
-        OMX_CONF_CIRCULAR_BUFFER_MOVE_TAIL(pBufHead, 
-                                           pComponentPrivate->sCircularBuffer, 
+
+        printH264UAlgInParam(pUalgInpParams, 0, &pComponentPrivate->dbg);
+        OMX_CONF_CIRCULAR_BUFFER_MOVE_TAIL(pBufHead,
+                                           pComponentPrivate->sCircularBuffer,
                                            pComponentPrivate);
-              
+
        /*Send Buffer to LCML*/
-        OMX_PRBUFFER1(pComponentPrivate->dbg, " %p\n", (void*)pBufHead); 
+        OMX_PRBUFFER1(pComponentPrivate->dbg, " %p\n", (void*)pBufHead);
         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
-        eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle, 
-                                  EMMCodecInputBuffer, 
+        eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
+                                  EMMCodecInputBuffer,
                                   pBufHead->pBuffer,
-                                  pPortDefIn->nBufferSize,
+                                  pBufHead->nAllocLen,
                                   pBufHead->nFilledLen,
-                                  (OMX_U8*)pUalgInpParams, 
-                                  sizeof(H264VE_GPP_SN_UALGInputParams), 
+                                  (OMX_U8*)pUalgInpParams,
+                                  sizeof(H264VE_GPP_SN_UALGInputParams),
                                   (OMX_U8*)pBufHead);
         if (eError != OMX_ErrorNone)
         {
             OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
         }
-            
+
     }
     else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
              pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
     {
-        
-        pUalgInpParams = (MP4VE_GPP_SN_UALGInputParams*)pBufferPrivate->pUalgParam; 
-        OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pUalgInpParams, 1, 1);
-        
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulFrameIndex         = pComponentPrivate->nFrameCnt;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulTargetFrameRate    = pComponentPrivate->nTargetFrameRate;            
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulTargetBitRate      = pComponentPrivate->nTargetBitRate;
-        if(pComponentPrivate->nFrameCnt == 0 && pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4){
-            /*OMX_TRACE("GENERATING VOL HEADER\n");*/
-            ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulGenerateHeader     = 1;
-        }
-        else
-            ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulGenerateHeader     = 0;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulForceIFrame        = pComponentPrivate->bForceIFrame;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulResyncInterval     = pCompPortOut->pErrorCorrectionType->nResynchMarkerSpacing;
-        if(pCompPortOut->pErrorCorrectionType->bEnableHEC)
-			((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulHecInterval        = 3;
-		else
-			((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulHecInterval        = 0;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulAIRRate            = pCompPortOut->pIntraRefreshType->nAirRef;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulMIRRate            = pComponentPrivate->nMIRRate;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulfCode              = 5;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulHalfPel            = 1;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ul4MV                = 0;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulIntraFrameInterval = pComponentPrivate->nIntraFrameInterval;   
-            
-        /*Set nQPI Value*/
-        if (((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulForceIFrame == OMX_TRUE)
-        {
-            ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulQPIntra = pComponentPrivate->nQPI; 
-        }
-        else
-        {
-            ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulQPIntra    = 0; 
-        }
-       
-	   /*Set segment mode params*/
-        if (pComponentPrivate->bMVDataEnable)
-        {
-		   ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ul4MV				  =1;
-		   ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->uluseUMV			  =1;
-		   ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulMVDataEnable		  =1;
-		   }
-        else
-        {
-		   ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ul4MV				  =0;
-		   ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->uluseUMV			  =0;
-		   ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulMVDataEnable		  =0;
-		   }
-	   if(pComponentPrivate->bResyncDataEnable) 
-		   ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulResyncDataEnable	  =1;
-	   else
-		   ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulResyncDataEnable	  =0;
-        /* Reset bForceMPEG4IFrame to zero */
-        pComponentPrivate->bForceIFrame = OMX_FALSE;  
-        
-        /*Set ulACPred Value*/
-        if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)        
-        {
-           ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulACPred         = pComponentPrivate->pMpeg4->bACPred;
-        }
-        else
-        {
-            ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulACPred        = 0;
-        }
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulQPInter           = 8;
-		((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulLastFrame         = 0;
-		((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulcapturewidth      = 0;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulQpMax             = 31;
-        ((MP4VE_GPP_SN_UALGInputParams*)pUalgInpParams)->ulQpMin             = 2;
-
-        ++pComponentPrivate->nFrameCnt;
-        OMX_PRDSP1(pComponentPrivate->dbg,
-                   "TargetFrameRate -> %d\n\
-                   TargetBitRate   -> %d\n\
-                   QPI             -> %d\n", pComponentPrivate->nTargetFrameRate,
-                   pComponentPrivate->nTargetBitRate,
-                   pComponentPrivate->nQPI);
-                                                 
-        OMX_CONF_CIRCULAR_BUFFER_MOVE_TAIL(pBufHead, 
-                                           pComponentPrivate->sCircularBuffer, 
-                                           pComponentPrivate);
-                        
-        /*Send Buffer to LCML*/
-        OMX_PRBUFFER1(pComponentPrivate->dbg, " %p\n", (void*)pBufHead);
-        pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
-        eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle, 
-                                  EMMCodecInputBuffer, 
-                                  pBufHead->pBuffer, 
-                                  pBufHead->nAllocLen, 
-                                  pBufHead->nFilledLen, 
-                                  (OMX_U8*)pUalgInpParams, 
-                                  sizeof(MP4VE_GPP_SN_UALGInputParams), 
-                                  (OMX_U8*)pBufHead);
-        if (eError != OMX_ErrorNone)
-        {
-            OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
-            OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorHardware);
-        }
-              
+        eError = OMX_VIDENC_Queue_Mpeg4_Buffer(pComponentPrivate, pBufHead);
     }
     else
     {
@@ -2742,10 +2677,145 @@
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
     }
 OMX_CONF_CMD_BAIL:
-	EXIT:
+EXIT:
     return eError;
 }
 
+OMX_ERRORTYPE OMX_VIDENC_Queue_Mpeg4_Buffer(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE* pBufHead)
+{
+    MP4VE_GPP_SN_UALGInputParams* pUalgInpParams = NULL;
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+    VIDENC_BUFFER_PRIVATE* pBufferPrivate;
+    LCML_DSP_INTERFACE* pLcmlHandle = NULL;
+    VIDEOENC_PORT_TYPE* pCompPortOut = NULL;
+    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
+
+    pBufferPrivate = (VIDENC_BUFFER_PRIVATE*)pBufHead->pInputPortPrivate;
+    pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
+    pPortDefOut = pCompPortOut->pPortDef;
+    pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
+
+    pUalgInpParams = (MP4VE_GPP_SN_UALGInputParams*)pBufferPrivate->pUalgParam;
+    OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pUalgInpParams, 1, 1);
+
+    pUalgInpParams->ulFrameIndex         = pComponentPrivate->nFrameCnt;
+    pUalgInpParams->ulTargetFrameRate    = pComponentPrivate->nTargetFrameRate;
+    pUalgInpParams->ulTargetBitRate      = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate;
+    pUalgInpParams->ulGenerateHeader     = 0;
+    pUalgInpParams->ulForceIFrame        = pComponentPrivate->bForceIFrame;
+    pUalgInpParams->ulResyncInterval     = pCompPortOut->pErrorCorrectionType->nResynchMarkerSpacing;
+    if(pCompPortOut->pErrorCorrectionType->bEnableHEC)
+        pUalgInpParams->ulHecInterval    = 3;
+    else
+    pUalgInpParams->ulHecInterval        = 0;
+    pUalgInpParams->ulAIRRate            = pCompPortOut->pIntraRefreshType->nAirRef;
+    pUalgInpParams->ulMIRRate            = pComponentPrivate->nMIRRate;
+    pUalgInpParams->ulfCode              = 5;
+    pUalgInpParams->ulHalfPel            = 1;
+    pUalgInpParams->ul4MV                = 0;
+    pUalgInpParams->ulIntraFrameInterval = pComponentPrivate->nIntraFrameInterval;
+
+    /*Set nQPI Value*/
+    if (pUalgInpParams->ulForceIFrame == OMX_TRUE)
+    {
+        pUalgInpParams->ulQPIntra = pComponentPrivate->nQPI;
+    }
+    else
+    {
+        pUalgInpParams->ulQPIntra    = 0;
+    }
+
+    /*Set segment mode params*/
+    if (pComponentPrivate->bMVDataEnable)
+    {
+        pUalgInpParams->ul4MV                 =1;
+        pUalgInpParams->uluseUMV              =1;
+        pUalgInpParams->ulMVDataEnable        =1;
+    }
+    else
+    {
+        pUalgInpParams->ul4MV                 =0;
+        pUalgInpParams->uluseUMV              =0;
+        pUalgInpParams->ulMVDataEnable        =0;
+    }
+    if (pComponentPrivate->bResyncDataEnable)
+        pUalgInpParams->ulResyncDataEnable    =1;
+    else
+        pUalgInpParams->ulResyncDataEnable    =0;
+    /* Reset bForceMPEG4IFrame to zero */
+    pComponentPrivate->bForceIFrame = OMX_FALSE;
+
+    /*Set ulACPred Value*/
+    if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
+    {
+        pUalgInpParams->ulACPred         = pComponentPrivate->pMpeg4->bACPred;
+    }
+    else
+    {
+        pUalgInpParams->ulACPred        = 0;
+    }
+    pUalgInpParams->ulQPInter           = 8;
+    pUalgInpParams->ulLastFrame         = 0;
+    pUalgInpParams->ulcapturewidth      = 0;
+    pUalgInpParams->ulQpMax             = 31;
+    pUalgInpParams->ulQpMin             = 2;
+    ++pComponentPrivate->nFrameCnt;
+
+    if(pComponentPrivate->bRequestVOLHeader == OMX_TRUE)
+    {
+        /*In the case of Mpeg4 we have to send an extra Buffer to LCML requesting for VOL Header*/
+        memcpy(pComponentPrivate->pTempUalgInpParams,pUalgInpParams,sizeof(MP4VE_GPP_SN_UALGInputParams));
+        pComponentPrivate->pTempUalgInpParams->ulGenerateHeader = 1;
+        pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
+        eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
+                                  EMMCodecInputBuffer,
+                                  pComponentPrivate->pTempUalgInpParams,/*send any buffer*/
+                                  1,
+                                  0,
+                                  pComponentPrivate->pTempUalgInpParams,
+                                  sizeof(MP4VE_GPP_SN_UALGInputParams),
+                                  (OMX_U8*)pBufHead);
+        if (eError != OMX_ErrorNone)
+        {
+            OMX_PRDSP2(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
+        }
+        pComponentPrivate->bRequestVOLHeader = OMX_FALSE;
+    }
+
+    OMX_PRDSP1(pComponentPrivate->dbg,
+               "TargetFrameRate -> %d\n\
+               TargetBitRate   -> %d\n\
+               QPI             -> %d\n", pComponentPrivate->nTargetFrameRate,
+               (int)pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate,
+               pComponentPrivate->nQPI);
+
+    printMpeg4UAlgInParam(pUalgInpParams, 0, &pComponentPrivate->dbg);
+    OMX_CONF_CIRCULAR_BUFFER_MOVE_TAIL(pBufHead,
+                                           pComponentPrivate->sCircularBuffer,
+                                           pComponentPrivate);
+
+        /*Send Buffer to LCML*/
+        OMX_PRBUFFER1(pComponentPrivate->dbg, " %p\n", (void*)pBufHead);
+        pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_DSP;
+        eError = LCML_QueueBuffer(pLcmlHandle->pCodecinterfacehandle,
+                                  EMMCodecInputBuffer,
+                                  pBufHead->pBuffer,
+                                  pBufHead->nAllocLen,
+                                  pBufHead->nFilledLen,
+                                  (OMX_U8*)pUalgInpParams,
+                                  sizeof(MP4VE_GPP_SN_UALGInputParams),
+                                  (OMX_U8*)pBufHead);
+    if (eError != OMX_ErrorNone)
+    {
+        OMX_PRDSP4(pComponentPrivate->dbg, "LCML QueueBuffer failed: %x\n", eError);
+    }
+
+OMX_CONF_CMD_BAIL:
+
+    return eError;
+}
+
+
 /*---------------------------------------------------------------------------------------*/
 /**
   * OMX_VIDENC_Process_FilledOutBuf()
@@ -2770,28 +2840,29 @@
     OMX_U32* pIndexNal;
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
 
    if (pComponentPrivate->bCodecStarted == OMX_TRUE)
     {
-        
+
         pBufferPrivate = pBufHead->pOutputPortPrivate;
         pSNPrivateParams = (H264VE_GPP_SN_UALGOutputParams*)(pBufferPrivate->pUalgParam);
         pBufHead->nFilledLen = ((H264VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->ulBitstreamSize;
-        
+
         if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC)
         {
-        /*Copy Buffer Data to be propagated*/        
+        /*Copy Buffer Data to be propagated*/
         if((pComponentPrivate->AVCNALFormat == VIDENC_AVC_NAL_SLICE) &&
-                (pSNPrivateParams->ulNALUnitsPerFrame != (pSNPrivateParams->ulNALUnitIndex+1)))
-            {
+                (pSNPrivateParams->ulNALUnitsPerFrame != (pSNPrivateParams->ulNALUnitIndex+1)) &&
+                (pSNPrivateParams->ulNALUnitsPerFrame != 0))
+        {
 
             pBufHead->pMarkData = NULL;
             pBufHead->hMarkTargetComponent = NULL;
-            pBufHead->nFlags = 0;
             pBufHead->nTickCount = pComponentPrivate->sCircularBuffer.pHead->nTickCount;
             pBufHead->nTimeStamp = pComponentPrivate->sCircularBuffer.pHead->nTimeStamp;
+            pBufHead->nFlags = 0;
         }
             else
             {
@@ -2803,8 +2874,8 @@
             /* Set lFrameType*/
             if (((H264VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->lFrameType == OMX_LFRAMETYPE_H264)
             {
-                /* IDR Frame */ 
-                pBufHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; 
+                /* IDR Frame */
+                pBufHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
             }
 
             /* if NAL frame mode */
@@ -2830,7 +2901,7 @@
 
                 *pIndexNal = pSNPrivateParams->ulNALUnitsPerFrame;
                 pIndexNal++;
-                for (nNalSlices = 0; nNalSlices < pSNPrivateParams->ulNALUnitsPerFrame; nNalSlices++, pIndexNal++)
+                for (nNalSlices = 0; (OMX_U32)nNalSlices < pSNPrivateParams->ulNALUnitsPerFrame; nNalSlices++, pIndexNal++)
                 {
 
                     *pIndexNal = (OMX_U32)(pSNPrivateParams->ulNALUnitsSizes[nNalSlices]);
@@ -2852,37 +2923,46 @@
         else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
                  pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
         {
-            OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pBufHead, pComponentPrivate->sCircularBuffer,
-                                               pComponentPrivate);
+            /*We ignore the first Mpeg4 buffer which contains VOL Header since we did not add it to the circular list*/
+            if(pComponentPrivate->bWaitingForVOLHeaderBuffer == OMX_FALSE)
+            {
+                OMX_CONF_CIRCULAR_BUFFER_MOVE_HEAD(pBufHead, pComponentPrivate->sCircularBuffer,
+                                                   pComponentPrivate);
+            }
+            else
+            {
+                pComponentPrivate->bWaitingForVOLHeaderBuffer = OMX_FALSE;
+            }
+
             pBufHead->nFlags |= OMX_BUFFERFLAG_ENDOFFRAME;
 
             /* Set cFrameType*/
             if (((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->cFrameType == OMX_CFRAMETYPE_MPEG4)
             {
-                /* I-VOP Frame */ 
+                /* I-VOP Frame */
                 pBufHead->nFlags |= OMX_BUFFERFLAG_SYNCFRAME;
             }
-			VIDENC_MPEG4_SEGMENTMODE_METADATA* pMetaData;
-			/*copy MPEG4 segment mode meta data */	
-			pMetaData=(VIDENC_MPEG4_SEGMENTMODE_METADATA*)pBufferPrivate->pMetaData;
+            VIDENC_MPEG4_SEGMENTMODE_METADATA* pMetaData;
+            /*copy MPEG4 segment mode meta data */
+            pMetaData=(VIDENC_MPEG4_SEGMENTMODE_METADATA*)pBufferPrivate->pMetaData;
             if (pComponentPrivate->bMVDataEnable==OMX_TRUE)
             {
-			   pMetaData->mvDataSize=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->mvDataSize;
-			   pMetaData->pMVData=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->MVData;
-			}
+               pMetaData->mvDataSize=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->mvDataSize;
+               pMetaData->pMVData=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->MVData;
+            }
             if (pComponentPrivate->bResyncDataEnable==OMX_TRUE)
             {
-			   pMetaData->pResyncData=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->ResyncData;
-			   pMetaData->numPackets=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->numPackets;
-			}
+               pMetaData->pResyncData=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->ResyncData;
+               pMetaData->numPackets=((MP4VE_GPP_SN_UALGOutputParams*)pBufferPrivate->pUalgParam)->numPackets;
+            }
         }
-        else 
+        else
         {
             OMX_PRBUFFER4(pComponentPrivate->dbg, "Unsupported compression format (%d)\n",
                           pPortDefOut->format.video.eCompressionFormat);
             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
         }
-            
+
         if (pBufHead->nFlags & OMX_BUFFERFLAG_EOS)
         {
             /* trigger event handler */
@@ -2890,14 +2970,14 @@
             /* clear flag */
             pComponentPrivate->nFlags = 0;
         }
-        
+
         if (pBufHead->pMarkData != NULL)
         {
-            /* trigger event handler if we are supposed to */ 
-            if (pBufHead->hMarkTargetComponent == pComponentPrivate->pHandle && 
+            /* trigger event handler if we are supposed to */
+            if (pBufHead->hMarkTargetComponent == pComponentPrivate->pHandle &&
                 pBufHead->pMarkData)
             {
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,  OMX_EventMark, 0x0, 0x0, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,  OMX_EventMark, 0x0, 0x0,
                                         pBufHead->pMarkData);
             }
         }
@@ -2908,6 +2988,7 @@
                            pBufHead->nFilledLen,
                            PERF_ModuleHLMM);
 #endif
+        OMX_PRINT2(pComponentPrivate->dbg, "FBD %p, FilledLen=%lu\n", pBufHead, pBufHead->nFilledLen);
         pComponentPrivate->sCbData.FillBufferDone(pComponentPrivate->pHandle,
                                                   pComponentPrivate->pHandle->pApplicationPrivate,
                                                   pBufHead);
@@ -2935,13 +3016,13 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_HANDLETYPE hTunnelComponent = NULL;
     VIDENC_BUFFER_PRIVATE* pBufferPrivate = NULL;
-    
+
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     hTunnelComponent = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->hTunnelComponent;
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
 
-	/*pBufHead is checked for NULL*/
+    /*pBufHead is checked for NULL*/
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, 1, 1);
     pBufferPrivate = pBufHead->pInputPortPrivate;
 
@@ -2959,7 +3040,7 @@
         OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg,
                               OMX_PRBUFFER4, "FillThisBuffer failed (%x)", eError);
     }
-    else 
+    else
     {
         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
 #ifdef __PERF_INSTRUMENTATION__
@@ -2968,12 +3049,11 @@
                           0,
                           PERF_ModuleHLMM);
 #endif
-
-   pComponentPrivate->sCbData.EmptyBufferDone(pComponentPrivate->pHandle,
-                                              pComponentPrivate->pHandle->pApplicationPrivate,
-                                              pBufHead);
+    pComponentPrivate->sCbData.EmptyBufferDone(pComponentPrivate->pHandle,
+                                               pComponentPrivate->pHandle->pApplicationPrivate,
+                                               pBufHead);
    }
-    
+
 OMX_CONF_CMD_BAIL:
     return eError;
 }
@@ -2981,10 +3061,10 @@
 /**
   *  Function to initialize LCML
   *
-  * 
+  *
   *
   * @retval OMX_NoError              Success, ready to roll
-  *         
+  *
   **/
 /*---------------------------------------------------------------------------------------*/
 
@@ -2993,18 +3073,18 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_HANDLETYPE hLCML = NULL;
     VIDENC_NODE* pMemoryListHead = NULL;
-#ifdef UNDER_CE   
-    typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);   
+#ifdef UNDER_CE
+    typedef OMX_ERRORTYPE (*LPFNDLLFUNC1)(OMX_HANDLETYPE);
     LPFNDLLFUNC1 fpGetHandle1;
-#else   
-    void* pMyLCML = NULL;   
-    fpo   fpGetHandle = NULL;   
+#else
+    void* pMyLCML = NULL;
+    fpo   fpGetHandle = NULL;
     char* error = NULL;
 #endif
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
 
-#ifndef UNDER_CE    
+#ifndef UNDER_CE
     pMyLCML = dlopen("libLCML.so", RTLD_LAZY);
     pComponentPrivate->pModLcml = pMyLCML;
     if (!pMyLCML)
@@ -3012,14 +3092,14 @@
         OMX_ERROR5(pComponentPrivate->dbg, "Could not open LCML library\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
     }
-    
+
     fpGetHandle = dlsym(pMyLCML, "GetHandle");
     if ((error = dlerror()) != NULL)
-    {    
+    {
         OMX_ERROR4(pComponentPrivate->dbg, "No GetHandle in LCML library\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
     }
-    
+
     eError = (*fpGetHandle)(&hLCML);
     if (eError != OMX_ErrorNone)
     {
@@ -3030,8 +3110,8 @@
     pComponentPrivate->pLCML = (LCML_DSP_INTERFACE*)hLCML;
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
     pComponentPrivate->pLCML->pComponentPrivate = (VIDENC_COMPONENT_PRIVATE *)pComponentPrivate;
-    
-#else 
+
+#else
     g_hLcmlDllHandle = LoadLibraryEx(TEXT("oaf_bml.dll"), NULL, 0);
     if (g_hLcmlDllHandle == NULL)
     {
@@ -3065,10 +3145,10 @@
 /**
   *  Function to fill DSP structures via LCML
   *
-  * 
+  *
   *
   * @retval OMX_NoError              Success, ready to roll
-  *         
+  *
   **/
 /*---------------------------------------------------------------------------------------*/
 
@@ -3081,9 +3161,9 @@
     VIDENC_NODE* pMemoryListHead = NULL;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_VIDEO_PARAM_AVCTYPE* pH264 = NULL;
-    LCML_DSP_INTERFACE* pLcmlHandle = NULL; 
+    LCML_DSP_INTERFACE* pLcmlHandle = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
-    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL; 
+    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
     OMX_VIDEO_PARAM_BITRATETYPE* pVidParamBitrate = NULL;
     OMX_VIDEO_PARAM_QUANTIZATIONTYPE* pQuantization = NULL;
     H264VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs = NULL;
@@ -3094,23 +3174,17 @@
     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
     pH264 = pComponentPrivate->pH264;
-    pVidParamBitrate = pComponentPrivate->pVidParamBitrate;
+    pVidParamBitrate = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType;
     pQuantization = pComponentPrivate->pQuantization;
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
     /* pH264IntraPeriod = pComponentPrivate->pH264IntraPeriod; */
     pMotionVector = pComponentPrivate->pMotionVector;
-
-    /*Q16 conversion*/
-    float xFrameRate=(float)pPortDefIn->format.video.xFramerate;
-    xFrameRate/=(1<<16);
-    xFrameRate*=1000;//this is needed by SN
-
     pComponentPrivate->bErrorLcmlHandle = OMX_FALSE;
 
     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
     pLcmlDSP = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
     pLcmlDSP = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
-    
+
     pLcmlDSP->In_BufInfo.nBuffers           = pPortDefIn->nBufferCountActual;
     pLcmlDSP->In_BufInfo.nSize              = pComponentPrivate->nInBufferSize;
     pLcmlDSP->In_BufInfo.DataTrMethod       = DMM_METHOD;
@@ -3132,9 +3206,9 @@
     strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[2].DllName,USN_DLL);
     pLcmlDSP->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
 
-    pLcmlDSP->SegID                         = 0; 
+    pLcmlDSP->SegID                         = 0;
     pLcmlDSP->Timeout                       = -1;
-    pLcmlDSP->Alignment                     = 0; 
+    pLcmlDSP->Alignment                     = 0;
     pLcmlDSP->Priority                      = 5;
 
     #ifdef GPP_PRIVATE_NODE_HEAP
@@ -3142,7 +3216,7 @@
             (pPortDefIn->format.video.nFrameHeight <= 144))
         {
             pLcmlDSP->ProfileID = 0;
-        } 
+        }
         else if ((pPortDefIn->format.video.nFrameWidth <= 352) &&
                  (pPortDefIn->format.video.nFrameHeight <= 288))
         {
@@ -3158,9 +3232,9 @@
 
     /* pLcmlDSP->buffindx                      = 999; */
 
-    VIDENC_MALLOC(pCreatePhaseArgs, 
-                  sizeof(H264VE_GPP_SN_Obj_CreatePhase), 
-                  H264VE_GPP_SN_Obj_CreatePhase, 
+    VIDENC_MALLOC(pCreatePhaseArgs,
+                  sizeof(H264VE_GPP_SN_Obj_CreatePhase),
+                  H264VE_GPP_SN_Obj_CreatePhase,
                   pMemoryListHead,
                   pComponentPrivate->dbg);
 
@@ -3173,35 +3247,34 @@
     pCreatePhaseArgs->usMaxBuffsInStream2     = (OMX_U16)pPortDefOut->nBufferCountActual;
 
     pCreatePhaseArgs->ulWidth                 = pPortDefIn->format.video.nFrameWidth;
-    pCreatePhaseArgs->ulHeight                = pPortDefIn->format.video.nFrameHeight; 
+    pCreatePhaseArgs->ulHeight                = pPortDefIn->format.video.nFrameHeight;
     pCreatePhaseArgs->ulTargetBitRate         = pPortDefOut->format.video.nBitrate;
     pCreatePhaseArgs->ulBitstreamBuffSize     = pComponentPrivate->nOutBufferSize;
-    pCreatePhaseArgs->ulFrameRate             = (unsigned int)xFrameRate;
-    
+    pCreatePhaseArgs->ulFrameRate             = (unsigned int)(Q16Tof(pPortDefIn->format.video.xFramerate)*1000.0);
+
     /* set run-time frame and bit rates to create-time values */
     pComponentPrivate->nTargetFrameRate       = pCreatePhaseArgs->ulFrameRate;
-    pComponentPrivate->nTargetBitRate         = pCreatePhaseArgs->ulTargetBitRate;
 
-        
+
     if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar)
     {
         pCreatePhaseArgs->ucYUVFormat         = 0;
     }
-    else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatCbYCrY) /*422 LE UYVY*/ 
+    else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatCbYCrY) /*422 LE UYVY*/
     {
         pCreatePhaseArgs->ucYUVFormat         = 2;
     }
-    else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYCbYCr) /*422 BE YUYV */ 
+    else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYCbYCr) /*422 BE YUYV */
     {
         pCreatePhaseArgs->ucYUVFormat         = 1;
     }
-    else 
+    else
     {
         OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported YUV format.\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
     }
 
-    pCreatePhaseArgs->ucUnrestrictedMV        = 0;
+    pCreatePhaseArgs->ucUnrestrictedMV        = pComponentPrivate->ucUnrestrictedMV;
     pCreatePhaseArgs->ucNumRefFrames          = 1;
 
     if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateVariable)
@@ -3224,11 +3297,11 @@
 
     pCreatePhaseArgs->ucIDREnable             = 1;
 
-    if (pComponentPrivate->bDeblockFilter == OMX_FALSE) 
+    if (pComponentPrivate->bDeblockFilter == OMX_FALSE)
     {
         pCreatePhaseArgs->ucDeblockingEnable  = 0;
     }
-    else if (pComponentPrivate->bDeblockFilter == OMX_TRUE) 
+    else if (pComponentPrivate->bDeblockFilter == OMX_TRUE)
     {
         pCreatePhaseArgs->ucDeblockingEnable  = 1;
     }
@@ -3242,7 +3315,7 @@
     pCreatePhaseArgs->ucQPIFrame              = 28;
     pCreatePhaseArgs->ucProfile               = 66;
     pCreatePhaseArgs->ulIntraFramePeriod      = pCreatePhaseArgs->ulFrameRate > 15000 ? 29 : 14;
-    
+
     if (pH264->eLevel == OMX_VIDEO_AVCLevel1b)
     {
         pCreatePhaseArgs->ucLevel = 9;
@@ -3279,7 +3352,7 @@
     {
         pCreatePhaseArgs->ucLevel = 30;
         if ((pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar) &&
-            (pPortDefIn->format.video.nFrameWidth == 320) && 
+            (pPortDefIn->format.video.nFrameWidth == 320) &&
             (pPortDefIn->format.video.nFrameHeight == 240))
         {
             pCreatePhaseArgs->ucQPIFrame = 0;
@@ -3294,11 +3367,11 @@
 
     /* override parameters for VGA & D1 encoding */
     if ((pPortDefIn->format.video.nFrameWidth >= 640 ||
-        pPortDefIn->format.video.nFrameHeight > 480) &&
+        pPortDefIn->format.video.nFrameHeight >= 480) &&
         pCreatePhaseArgs->ulFrameRate > 15000)
     {
         pComponentPrivate->maxMVperMB = 1;
-        pComponentPrivate->intra4x4EnableIdc = INTRA4x4_ISLICES;
+        pComponentPrivate->intra4x4EnableIdc = INTRA4x4_NONE;
         pComponentPrivate->nIntraFrameInterval = 30;
         pComponentPrivate->nAIRRate = 0;
         /* Encoding preset = 4 enables DSP side optimizations for high resolutions */
@@ -3306,6 +3379,8 @@
         pCreatePhaseArgs->ulIntraFramePeriod = 0;
         /* Constant bit rate control enabled */
         pCreatePhaseArgs->ucRateControlAlgorithm = 1;
+        /* Disable deblocking */
+        pCreatePhaseArgs->ucDeblockingEnable  = 0;
         pCreatePhaseArgs->ucLevel = 30;
     }
 
@@ -3313,6 +3388,7 @@
     pCreatePhaseArgs->ulEncodingPreset = pComponentPrivate->nEncodingPreset;
     pCreatePhaseArgs->ulRcAlgo = 0;
     pCreatePhaseArgs->endArgs = END_OF_CR_PHASE_ARGS;
+    printH264CreateParams(pCreatePhaseArgs, &pComponentPrivate->dbg);
 
     pTmp = memcpy (nArr, pCreatePhaseArgs, sizeof(H264VE_GPP_SN_Obj_CreatePhase));
     if (pTmp == NULL)
@@ -3323,17 +3399,17 @@
     pLcmlDSP->pCrPhArgs = nArr;
     sCb.LCML_Callback = (void *)OMX_VIDENC_LCML_Callback;
 
-    eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 
-                              NULL, 
-                              &pLcmlHandle, 
-                              NULL, 
+    eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                              NULL,
+                              &pLcmlHandle,
+                              NULL,
                               &sCb);
     if (eError != OMX_ErrorNone)
     {
         OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...\n");
         /*TODO: Validate eError from LCML_InitMMCodec for ResourceExhaustionTest */
         pComponentPrivate->bErrorLcmlHandle = OMX_TRUE;
-        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInvalidState);
+        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
     pComponentPrivate->bCodecLoaded = OMX_TRUE;
     VIDENC_FREE(pCreatePhaseArgs, pMemoryListHead,
@@ -3346,10 +3422,10 @@
 /**
   *  Function to fill DSP structures via LCML
   *
-  * 
+  *
   *
   * @retval OMX_NoError              Success, ready to roll
-  *         
+  *
   **/
 /*---------------------------------------------------------------------------------------*/
 
@@ -3361,7 +3437,7 @@
     LCML_DSP* pLcmlDSP = NULL;
     VIDENC_NODE* pMemoryListHead = NULL;
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    LCML_DSP_INTERFACE* pLcmlHandle = NULL; 
+    LCML_DSP_INTERFACE* pLcmlHandle = NULL;
     OMX_VIDEO_PARAM_H263TYPE* pH263 = NULL;
     OMX_VIDEO_PARAM_MPEG4TYPE* pMpeg4 = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn = NULL;
@@ -3369,21 +3445,21 @@
     MP4VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs = NULL;
     OMX_VIDEO_PARAM_BITRATETYPE* pVidParamBitrate = NULL;
     OMX_VIDEO_PARAM_QUANTIZATIONTYPE* pQuantization = NULL;
-	VIDEOENC_PORT_TYPE* pCompPortOut			= NULL;
+    VIDEOENC_PORT_TYPE* pCompPortOut            = NULL;
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
-	pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
-    pVidParamBitrate = pComponentPrivate->pVidParamBitrate;
+    pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
+    pVidParamBitrate = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType;
     pQuantization = pComponentPrivate->pQuantization;
     pH263 = pComponentPrivate->pH263;
     pMpeg4 = pComponentPrivate->pMpeg4;
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
-    
+
     pComponentPrivate->bErrorLcmlHandle = OMX_FALSE;
-    
+
     pLcmlHandle = (LCML_DSP_INTERFACE*)pComponentPrivate->pLCML;
     pLcmlDSP    = (((LCML_DSP_INTERFACE*)pLcmlHandle)->dspCodec);
 
@@ -3395,51 +3471,51 @@
     pLcmlDSP->Out_BufInfo.nSize             = pComponentPrivate->nOutBufferSize;
     pLcmlDSP->Out_BufInfo.DataTrMethod      = DMM_METHOD;
 
-    pLcmlDSP->NodeInfo.nNumOfDLLs           = OMX_MP4ENC_NUM_DLLS; 
-    pLcmlDSP->NodeInfo.AllUUIDs[0].uuid     = &MP4VESOCKET_TI_UUID; 
-    strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[0].DllName,MP4_ENC_NODE_DLL); 
+    pLcmlDSP->NodeInfo.nNumOfDLLs           = OMX_MP4ENC_NUM_DLLS;
+    pLcmlDSP->NodeInfo.AllUUIDs[0].uuid     = &MP4VESOCKET_TI_UUID;
+    strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[0].DllName,MP4_ENC_NODE_DLL);
     pLcmlDSP->NodeInfo.AllUUIDs[0].eDllType = DLL_NODEOBJECT;
 
-    pLcmlDSP->NodeInfo.AllUUIDs[1].uuid     = &MP4VESOCKET_TI_UUID; 
-    strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[1].DllName,MP4_ENC_NODE_DLL); 
+    pLcmlDSP->NodeInfo.AllUUIDs[1].uuid     = &MP4VESOCKET_TI_UUID;
+    strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[1].DllName,MP4_ENC_NODE_DLL);
     pLcmlDSP->NodeInfo.AllUUIDs[1].eDllType = DLL_DEPENDENT;
 
     pLcmlDSP->NodeInfo.AllUUIDs[2].uuid     = &USN_UUID;
     strcpy ((char *)pLcmlDSP->NodeInfo.AllUUIDs[2].DllName,USN_DLL);
     pLcmlDSP->NodeInfo.AllUUIDs[2].eDllType = DLL_DEPENDENT;
 
-    pLcmlDSP->SegID     = 0; 
+    pLcmlDSP->SegID     = 0;
     pLcmlDSP->Timeout   = -1;
-    pLcmlDSP->Alignment = 0; 
+    pLcmlDSP->Alignment = 0;
     pLcmlDSP->Priority  = 5;
 
     #ifdef GPP_PRIVATE_NODE_HEAP
-        if ((pPortDefIn->format.video.nFrameWidth <= 176) && 
+        if ((pPortDefIn->format.video.nFrameWidth <= 176) &&
             (pPortDefIn->format.video.nFrameHeight <= 144))
         {
             pLcmlDSP->ProfileID = 0;
-        } 
-        else if ((pPortDefIn->format.video.nFrameWidth <= 352) && 
+        }
+        else if ((pPortDefIn->format.video.nFrameWidth <= 352) &&
                  (pPortDefIn->format.video.nFrameHeight <= 288))
         {
             pLcmlDSP->ProfileID = 1;
         }
-        else if ((pPortDefIn->format.video.nFrameWidth <= 640) && 
+        else if ((pPortDefIn->format.video.nFrameWidth <= 640) &&
                  (pPortDefIn->format.video.nFrameHeight <= 480))
         {
             pLcmlDSP->ProfileID = 2;
         }
-        else if ((pPortDefIn->format.video.nFrameWidth <= 720) && 
+        else if ((pPortDefIn->format.video.nFrameWidth <= 720) &&
                  (pPortDefIn->format.video.nFrameHeight <= 480))
         {
             pLcmlDSP->ProfileID = 3;
         }
-        else if ((pPortDefIn->format.video.nFrameWidth <= 720) && 
+        else if ((pPortDefIn->format.video.nFrameWidth <= 720) &&
                  (pPortDefIn->format.video.nFrameHeight <= 576))
         {
             pLcmlDSP->ProfileID = 4;
         }
-        else 
+        else
         {
             pLcmlDSP->ProfileID = 4;
         }
@@ -3449,11 +3525,14 @@
 
     /* pLcmlDSP->buffindx = 999; */
 
-    VIDENC_MALLOC(pCreatePhaseArgs, 
-                  sizeof(MP4VE_GPP_SN_Obj_CreatePhase), 
-                  MP4VE_GPP_SN_Obj_CreatePhase, 
+    VIDENC_MALLOC(pCreatePhaseArgs,
+                  sizeof(MP4VE_GPP_SN_Obj_CreatePhase),
+                  MP4VE_GPP_SN_Obj_CreatePhase,
                   pMemoryListHead,
-                  pComponentPrivate->dbg); 
+                  pComponentPrivate->dbg);
+
+    pCreatePhaseArgs->ucUnrestrictedMV        = pComponentPrivate->ucUnrestrictedMV;
+    pCreatePhaseArgs->ucProfile               = 1;
 
     pCreatePhaseArgs->usNumStreams            = 2;
     pCreatePhaseArgs->usStreamId              = 0;
@@ -3464,43 +3543,47 @@
     pCreatePhaseArgs->usMaxBuffsInStream2     = (OMX_U16)pPortDefOut->nBufferCountActual;
 
     pCreatePhaseArgs->ulWidth                 = pPortDefIn->format.video.nFrameWidth;
-    pCreatePhaseArgs->ulHeight                = pPortDefIn->format.video.nFrameHeight; 
+    pCreatePhaseArgs->ulHeight                = pPortDefIn->format.video.nFrameHeight;
     pCreatePhaseArgs->ulTargetBitRate         = pPortDefOut->format.video.nBitrate;
-    pCreatePhaseArgs->ulVBVSize               = pComponentPrivate->nVBVSize; 
-    
-    if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) 
-    {   
+    pCreatePhaseArgs->ulVBVSize               = pComponentPrivate->nVBVSize;
+
+    if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
+    {
         pCreatePhaseArgs->ulGOBHeadersInterval    = pH263->nGOBHeaderInterval;
     }
-    else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) 
+    else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
     {
         pCreatePhaseArgs->ulGOBHeadersInterval    = 0;
     }
 
-    if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) 
+    if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingH263)
     {
         pCreatePhaseArgs->ucIsMPEG4 = 0;
     }
-    else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) 
+    else if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
     {
         pCreatePhaseArgs->ucIsMPEG4 = 1;
+        /*Initialize variables for the generation of VOL Header*/
+        pComponentPrivate->bRequestVOLHeader = OMX_TRUE;
+        pComponentPrivate->bWaitingForVOLHeaderBuffer = OMX_TRUE;
+        pComponentPrivate->bWaitingVOLHeaderCallback = OMX_TRUE;
     }
-    else 
+    else
     {
         OMX_PRDSP4(pComponentPrivate->dbg, "Unsupported video format (%d).\n",
                    pPortDefOut->format.video.eCompressionFormat);
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
     }
-            
+
     if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYUV420Planar)
     {
         pCreatePhaseArgs->ucYUVFormat         = 0;
     }
-    else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatCbYCrY) /*422 LE UYVY*/ 
+    else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatCbYCrY) /*422 LE UYVY*/
     {
         pCreatePhaseArgs->ucYUVFormat         = 2;
     }
-    else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYCbYCr) /*422 BE YUYV */ 
+    else if (pPortDefIn->format.video.eColorFormat == OMX_COLOR_FormatYCbYCr) /*422 BE YUYV */
     {
         pCreatePhaseArgs->ucYUVFormat         = 1;
     }
@@ -3510,85 +3593,80 @@
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
     }
     if(pCompPortOut->pErrorCorrectionType->bEnableHEC)
-	    pCreatePhaseArgs->ucHEC                   = 1;
-	else
-		pCreatePhaseArgs->ucHEC                   = 0;/**/
-	
-    if(pCompPortOut->pErrorCorrectionType->bEnableResync)
-	    pCreatePhaseArgs->ucResyncMarker          = 1;
-	else
-		pCreatePhaseArgs->ucResyncMarker          = 0;/**/  
-	
-    if(pCompPortOut->pErrorCorrectionType->bEnableDataPartitioning)
-	    pCreatePhaseArgs->ucDataPartitioning      = 1;
-	else
-		pCreatePhaseArgs->ucDataPartitioning      = 0;/**/
-	
-    if(pCompPortOut->pErrorCorrectionType->bEnableRVLC)
-	    pCreatePhaseArgs->ucReversibleVLC      = 1;
-	else
-		pCreatePhaseArgs->ucReversibleVLC         = 0;/**/
+        pCreatePhaseArgs->ucHEC                   = 1;
+    else
+        pCreatePhaseArgs->ucHEC                   = 0;/**/
 
-	pCreatePhaseArgs->ucUnrestrictedMV        = 0;/**/
-        /*Q16 conversion*/
-        float xFrameRate=(float)pPortDefIn->format.video.xFramerate;
-        xFrameRate/=(1<<16);
-        pCreatePhaseArgs->ucFrameRate             = xFrameRate;
-    
+    if(pCompPortOut->pErrorCorrectionType->bEnableResync)
+        pCreatePhaseArgs->ucResyncMarker          = 1;
+    else
+        pCreatePhaseArgs->ucResyncMarker          = 0;/**/
+
+    if(pCompPortOut->pErrorCorrectionType->bEnableDataPartitioning)
+        pCreatePhaseArgs->ucDataPartitioning      = 1;
+    else
+        pCreatePhaseArgs->ucDataPartitioning      = 0;/**/
+
+    if(pCompPortOut->pErrorCorrectionType->bEnableRVLC)
+        pCreatePhaseArgs->ucReversibleVLC      = 1;
+    else
+        pCreatePhaseArgs->ucReversibleVLC         = 0;/**/
+
+    pCreatePhaseArgs->ucFrameRate             = (OMX_U8) Q16Tof(pPortDefIn->format.video.xFramerate);
+
    /* set run-time frame and bit rates to create-time values */
     pComponentPrivate->nTargetFrameRate       = pCreatePhaseArgs->ucFrameRate;
     pComponentPrivate->nTargetBitRate         = pCreatePhaseArgs->ulTargetBitRate; 
 
-     if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateConstant) 
+     if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateConstant)
     {
         pCreatePhaseArgs->ucRateControlAlgorithm  = IVIDEO_LOW_DELAY;
     }
-    else if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateVariable) 
+    else if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateVariable)
     {
         pCreatePhaseArgs->ucRateControlAlgorithm  = IVIDEO_STORAGE;
     }
-	else if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateDisable) 
+    else if (pVidParamBitrate->eControlRate == OMX_Video_ControlRateDisable)
     {
         pCreatePhaseArgs->ucRateControlAlgorithm  = IVIDEO_NONE;
     }
-    else 
+    else
     {
         OMX_PRDSP2(pComponentPrivate->dbg, "Unsupported rate control algorithm.\n");
     OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUnsupportedSetting);
     }
 
-    pCreatePhaseArgs->ucQPFirstIFrame         = 8;
-    pCreatePhaseArgs->ucProfile               = 1;
+    pCreatePhaseArgs->ucQPFirstIFrame         = (OMX_U8)pQuantization->nQpI;
 
-    if (pCreatePhaseArgs->ucIsMPEG4 == 1) 
+    if (pCreatePhaseArgs->ucIsMPEG4 == 1)
     {
 #ifdef __KHRONOS_CONF_1_1__
-        if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level0) 
+        if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level0)
         {
             pCreatePhaseArgs->ucLevel = 0;
         }
-        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level1) 
+        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level1)
         {
             pCreatePhaseArgs->ucLevel = 1;
         }
-        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level2) 
+        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level2)
         {
             pCreatePhaseArgs->ucLevel = 2;
         }
-        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level3) 
+        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level3)
         {
             pCreatePhaseArgs->ucLevel = 3;
         }
         else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level4a ||
-                 pMpeg4->eLevel == OMX_VIDEO_MPEG4Level4) 
+                 pMpeg4->eLevel == OMX_VIDEO_MPEG4Level4)
         {
             pCreatePhaseArgs->ucLevel = 4;
         }
-        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level5) 
+        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level5)
         {
             pCreatePhaseArgs->ucLevel = 5;
         }
-        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level0b) 
+        else if (pMpeg4->eLevel == OMX_VIDEO_MPEG4Level0b)
         {
             pCreatePhaseArgs->ucLevel = 100;
         }
@@ -3607,35 +3685,35 @@
     }
     else
     {
-        if (pH263->eLevel == OMX_VIDEO_H263Level10) 
+        if (pH263->eLevel == OMX_VIDEO_H263Level10)
         {
             pCreatePhaseArgs->ucLevel = 10;
         }
-        else if (pH263->eLevel == OMX_VIDEO_H263Level20) 
+        else if (pH263->eLevel == OMX_VIDEO_H263Level20)
         {
             pCreatePhaseArgs->ucLevel = 20;
         }
-        else if (pH263->eLevel == OMX_VIDEO_H263Level30) 
+        else if (pH263->eLevel == OMX_VIDEO_H263Level30)
         {
             pCreatePhaseArgs->ucLevel = 30;
         }
-        else if (pH263->eLevel == OMX_VIDEO_H263Level40) 
+        else if (pH263->eLevel == OMX_VIDEO_H263Level40)
         {
             pCreatePhaseArgs->ucLevel = 40;
         }
-		else if (pH263->eLevel == OMX_VIDEO_H263Level45) 
+        else if (pH263->eLevel == OMX_VIDEO_H263Level45)
         {
             pCreatePhaseArgs->ucLevel = 45;
         }
-		else if (pH263->eLevel == OMX_VIDEO_H263Level50) 
+        else if (pH263->eLevel == OMX_VIDEO_H263Level50)
         {
             pCreatePhaseArgs->ucLevel = 50;
         }
-		else if (pH263->eLevel == OMX_VIDEO_H263Level60) 
+        else if (pH263->eLevel == OMX_VIDEO_H263Level60)
         {
             pCreatePhaseArgs->ucLevel = 60;
         }
-		else if (pH263->eLevel == OMX_VIDEO_H263Level70) 
+        else if (pH263->eLevel == OMX_VIDEO_H263Level70)
         {
             pCreatePhaseArgs->ucLevel = 70;
         }
@@ -3650,63 +3728,64 @@
         pCreatePhaseArgs->enableH263AnnexT  = 0;
     }
     pCreatePhaseArgs->ulMaxDelay              = 300;
-	#ifndef MODE_3410
-	pCreatePhaseArgs->ulVbvParamEnable        = 0;
-	pCreatePhaseArgs->ulH263SliceMode         = 0;
-	#endif
-	pCreatePhaseArgs->ulUseGOV                = 0;
+    #ifndef MODE_3410
+    pCreatePhaseArgs->ulVbvParamEnable        = 0;
+    pCreatePhaseArgs->ulH263SliceMode         = 0;
+    #endif
+    pCreatePhaseArgs->ulUseGOV                = 0;
     if (pPortDefOut->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
         pCreatePhaseArgs->ulUseVOS            = 1;//needed to generate VOL Header
     else
         pCreatePhaseArgs->ulUseVOS            = 0;
     pCreatePhaseArgs->endArgs                 = END_OF_CR_PHASE_ARGS;
     pTmp = memcpy(nArr, pCreatePhaseArgs, sizeof(MP4VE_GPP_SN_Obj_CreatePhase));
-    if (pTmp == NULL) 
+    if (pTmp == NULL)
     {
         OMX_TRACE4(pComponentPrivate->dbg, "memcpy() out of memory error.\n");
-        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
+        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
 
     pLcmlDSP->pCrPhArgs = nArr;
+    printMpeg4Params(pCreatePhaseArgs, &pComponentPrivate->dbg);
 
     sCb.LCML_Callback = (void *)OMX_VIDENC_LCML_Callback;
-    eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle, 
-                              NULL, 
-                              &pLcmlHandle, 
-                              NULL, 
+    eError = LCML_InitMMCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                              NULL,
+                              &pLcmlHandle,
+                              NULL,
                               &sCb);
-                              
-    if (eError != OMX_ErrorNone) 
+
+    if (eError != OMX_ErrorNone)
     {
-        OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...\n");  
+        OMX_PRDSP4(pComponentPrivate->dbg, "LCML_InitMMCodec Failed!...\n");
         /*TODO: Validate eError from LCML_InitMMCodec for ResourceExhaustionTest */
         pComponentPrivate->bErrorLcmlHandle = OMX_TRUE;
-        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInvalidState);
+        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
     pComponentPrivate->bCodecLoaded = OMX_TRUE;
     VIDENC_FREE(pCreatePhaseArgs, pMemoryListHead,
                 pComponentPrivate->dbg);
-    
+
 OMX_CONF_CMD_BAIL:
     return eError;
 }
 /*----------------------------------------------------------------------------*/
 /**
-  *  OMX_VIDENC_Allocate_DSPResources() 
+  *  OMX_VIDENC_Allocate_DSPResources()
   *
-  * 
-  * 
   *
-  * @param 
-  * @param 
-  * @param 
+  *
+  *
+  * @param
+  * @param
+  * @param
   *
   * @retval OMX_NoError              Success, ready to roll
   *         OMX_Error_BadParameter   The input parameter pointer is null
   **/
 /*----------------------------------------------------------------------------*/
 
-OMX_ERRORTYPE OMX_VIDENC_Allocate_DSPResources(VIDENC_COMPONENT_PRIVATE* pComponentPrivate, 
+OMX_ERRORTYPE OMX_VIDENC_Allocate_DSPResources(VIDENC_COMPONENT_PRIVATE* pComponentPrivate,
                                                OMX_IN OMX_U32 nPortIndex)
 {
     char* pTemp = NULL;
@@ -3718,55 +3797,66 @@
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut = NULL;
 
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
-    
+
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
     pCompPort = pComponentPrivate->pCompPort[nPortIndex];
     nBufferCnt = pComponentPrivate->pCompPort[nPortIndex]->nBufferCnt;
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
     eCompressionFormat = pPortDefOut->format.video.eCompressionFormat;
-    
-    if (nPortIndex == VIDENC_INPUT_PORT) 
+
+    if (nPortIndex == VIDENC_INPUT_PORT)
     {
         if (eCompressionFormat == OMX_VIDEO_CodingAVC)
         {
             H264VE_GPP_SN_UALGInputParams* pUalgParam;
-            
-            VIDENC_MALLOC(pUalgParam, 
-                          sizeof(H264VE_GPP_SN_UALGInputParams) + 256, 
-                          H264VE_GPP_SN_UALGInputParams, 
+
+            VIDENC_MALLOC(pUalgParam,
+                          sizeof(H264VE_GPP_SN_UALGInputParams) + 256,
+                          H264VE_GPP_SN_UALGInputParams,
                           pMemoryListHead,
                           pComponentPrivate->dbg);
-                          
+
             pTemp = (char*)pUalgParam;
             pTemp += 128;
-            pUalgParam = (H264VE_GPP_SN_UALGInputParams*)pTemp;        
+            pUalgParam = (H264VE_GPP_SN_UALGInputParams*)pTemp;
             pCompPort->pBufferPrivate[nBufferCnt]->pUalgParam = pUalgParam;
         }
         else if (eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
-                 eCompressionFormat == OMX_VIDEO_CodingH263) 
+                 eCompressionFormat == OMX_VIDEO_CodingH263)
         {
             MP4VE_GPP_SN_UALGInputParams* pUalgParam;
-            
-            VIDENC_MALLOC(pUalgParam, 
+
+            VIDENC_MALLOC(pUalgParam,
                           sizeof(MP4VE_GPP_SN_UALGInputParams) + 256,
-                          MP4VE_GPP_SN_UALGInputParams, 
+                          MP4VE_GPP_SN_UALGInputParams,
                           pMemoryListHead,
-                          pComponentPrivate->dbg); 
+                          pComponentPrivate->dbg);
             pTemp = (char*)pUalgParam;
             pTemp += 128;
-            pUalgParam = (MP4VE_GPP_SN_UALGInputParams*)pTemp;        
+            pUalgParam = (MP4VE_GPP_SN_UALGInputParams*)pTemp;
             pCompPort->pBufferPrivate[nBufferCnt]->pUalgParam = pUalgParam;
+            if(eCompressionFormat == OMX_VIDEO_CodingMPEG4)
+            {/*Structure needed to send the request for VOLHeader to SN*/
+                VIDENC_MALLOC(pComponentPrivate->pTempUalgInpParams,
+                              sizeof(MP4VE_GPP_SN_UALGInputParams) + 256,
+                              MP4VE_GPP_SN_UALGInputParams,
+                              pMemoryListHead,
+                              pComponentPrivate->dbg);
+                pTemp = (char*)pComponentPrivate->pTempUalgInpParams;
+                pTemp += 128;
+                pComponentPrivate->pTempUalgInpParams = (MP4VE_GPP_SN_UALGInputParams*)pTemp;
+            }
         }
     }
     else if (nPortIndex == VIDENC_OUTPUT_PORT)
     {
-        if (eCompressionFormat == OMX_VIDEO_CodingAVC) 
+        if (eCompressionFormat == OMX_VIDEO_CodingAVC)
         {
             H264VE_GPP_SN_UALGOutputParams* pUalgParam;
-            
-            VIDENC_MALLOC(pUalgParam, 
+
+            VIDENC_MALLOC(pUalgParam,
                           sizeof(H264VE_GPP_SN_UALGOutputParams) + 256,
-                          H264VE_GPP_SN_UALGOutputParams, 
+                          H264VE_GPP_SN_UALGOutputParams,
                           pMemoryListHead,
                           pComponentPrivate->dbg);
             pTemp = (char*)pUalgParam;
@@ -3775,18 +3865,18 @@
             pCompPort->pBufferPrivate[nBufferCnt]->pUalgParam = pUalgParam;
         }
         else if (eCompressionFormat == OMX_VIDEO_CodingMPEG4 ||
-                 eCompressionFormat == OMX_VIDEO_CodingH263) 
+                 eCompressionFormat == OMX_VIDEO_CodingH263)
         {
             MP4VE_GPP_SN_UALGOutputParams* pUalgParam;
-            
-            VIDENC_MALLOC(pUalgParam, 
-                          sizeof(MP4VE_GPP_SN_UALGOutputParams) + 256, 
-                          MP4VE_GPP_SN_UALGOutputParams, 
+
+            VIDENC_MALLOC(pUalgParam,
+                          sizeof(MP4VE_GPP_SN_UALGOutputParams) + 256,
+                          MP4VE_GPP_SN_UALGOutputParams,
                           pMemoryListHead,
                           pComponentPrivate->dbg);
             pTemp = (char*)pUalgParam;
             pTemp += 128;
-            pUalgParam = (MP4VE_GPP_SN_UALGOutputParams*)pTemp;        
+            pUalgParam = (MP4VE_GPP_SN_UALGOutputParams*)pTemp;
             pCompPort->pBufferPrivate[nBufferCnt]->pUalgParam = pUalgParam;
         }
     }
@@ -3817,8 +3907,8 @@
 
     OMX_CONF_CHECK_CMD(argsCb, 1, 1);
 
-    if (argsCb[6]) 
-    { 
+    if (argsCb[6])
+    {
         pLcmlDspInterface = (LCML_DSP_INTERFACE*)argsCb[6];
         pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pLcmlDspInterface->pComponentPrivate;
         pHandle = (OMX_COMPONENTTYPE *)pComponentPrivate->pHandle;
@@ -3827,8 +3917,8 @@
     {
         OMXDBG_PRINT(stderr, DSP, 5, 0, "No LCML handle\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter);
-	}
-	
+    }
+
 
     if (eEvent == EMMCodecBufferProcessed)
     {
@@ -3844,14 +3934,17 @@
 
             pComponentPrivate->nLcml_nCntOpReceived++;
 
-            if ((pComponentPrivate->nLcml_nCntIp >= 1) && 
-                (pComponentPrivate->nLcml_nCntOpReceived == 1)) 
+            if ((pComponentPrivate->nLcml_nCntIp >= 1) &&
+                (pComponentPrivate->nLcml_nCntOpReceived == 1))
             {
                 PERF_Boundary(pComponentPrivate->pPERFcomp,
                               PERF_BoundaryStart | PERF_BoundarySteadyState);
             }
 #endif
             OMX_PRDSP1(pComponentPrivate->dbg, " [OUT] -> %p\n", pBufHead);
+            if(pBufHead->nFilledLen > pBufHead->nAllocLen) {
+                LOGD("VE Warning!!! Output buffer overflow.");
+            }
             pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_COMPONENT;
             if (pComponentPrivate->bCodecStarted == OMX_TRUE)
             {
@@ -3859,14 +3952,14 @@
               eError = OMX_VIDENC_Process_FilledOutBuf(pComponentPrivate, pBufHead);
               if (eError != OMX_ErrorNone)
               {
-                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
+                OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
                            OMX_EventError,
                            OMX_ErrorUndefined,
                            OMX_TI_ErrorCritical,
                            NULL);
                 OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
               }
-            }  
+            }
         }
         if ((int)argsCb [0] == EMMCodecInputBuffer)
         {
@@ -3882,8 +3975,9 @@
 
             OMX_PRDSP1(pComponentPrivate->dbg, " [IN] -> %p\n", pBufHead);
             pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_COMPONENT;
-            if (pComponentPrivate->bCodecStarted == OMX_TRUE) 
-            { 
+            /*we should ignore the callback asociated to the VOL Header request*/
+            if (pComponentPrivate->bCodecStarted == OMX_TRUE && pComponentPrivate->bWaitingVOLHeaderCallback == OMX_FALSE)
+            {
                 OMX_PRDSP1(pComponentPrivate->dbg, "Enters OMX_VIDENC_Process_FreeInBuf\n");
                eError = OMX_VIDENC_Process_FreeInBuf(pComponentPrivate, pBufHead);
                if (eError != OMX_ErrorNone)
@@ -3896,33 +3990,37 @@
                  OMX_VIDENC_BAIL_IF_ERROR(eError, pComponentPrivate);
                }
                 OMX_PRDSP1(pComponentPrivate->dbg, "Exits OMX_VIDENC_Process_FreeInBuf\n");
-            } 
+            }
+            else if(pComponentPrivate->bWaitingVOLHeaderCallback == OMX_TRUE)
+            {
+                pComponentPrivate->bWaitingVOLHeaderCallback = OMX_FALSE;
+            }
         }
     }
-    
+
     if(eEvent == EMMCodecProcessingPaused ||
        eEvent == EMMCodecProcessingStoped)
     {
-        if (pComponentPrivate != NULL) 
+        if (pComponentPrivate != NULL)
         {
             pComponentPrivate->bDSPStopAck = OMX_TRUE;
-			#ifndef UNDER_CE
-				pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
-				pthread_cond_signal(&pComponentPrivate->stop_cond);
-				pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+            #ifndef UNDER_CE
+                pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+                pthread_cond_signal(&pComponentPrivate->stop_cond);
+                pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
             #endif
         }
     }
-    
+
     if(eEvent == EMMCodecStrmCtrlAck)
     {
-        if ((int)argsCb [0] == USN_ERR_NONE) 
+        if ((int)argsCb [0] == USN_ERR_NONE)
         {
-            pComponentPrivate->bFlushComplete = OMX_TRUE;			
+            pComponentPrivate->bFlushComplete = OMX_TRUE;
             #ifndef UNDER_CE
-				pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
-				pthread_cond_signal(&pComponentPrivate->flush_cond);
-				pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
+                pthread_mutex_lock(&pComponentPrivate->videoe_mutex_app);
+                pthread_cond_signal(&pComponentPrivate->flush_cond);
+                pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
             #endif
         }
     }
@@ -3932,9 +4030,9 @@
         OMX_ERROR4(pComponentPrivate->dbg, "LCML Event Handler failed.\n");
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
     }
-    
+
 OMX_CONF_CMD_BAIL:
-	return eError;
+    return eError;
 }
 
 
@@ -4003,10 +4101,10 @@
 /**
   * OMX_VIDENC_ResourceManagerCallBack()
   *
-  * Called from Resource Manager() 
+  * Called from Resource Manager()
   *
- *               
-  *         
+ *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 void OMX_VIDENC_ResourceManagerCallBack(RMPROXY_COMMANDDATATYPE cbData)
@@ -4021,15 +4119,15 @@
     OMX_PRMGR2(pCompPrivate->dbg, "Arguments:\ncbData.RM_Error = %dcbData.RM_Cmd = %d\n", *(cbData.RM_Error), cbData.RM_Cmd);
     if (*(cbData.RM_Error) == OMX_ErrorResourcesPreempted)
     {
-        if (pCompPrivate->eState== OMX_StateExecuting || 
+        if (pCompPrivate->eState== OMX_StateExecuting ||
             pCompPrivate->eState == OMX_StatePause)
         {
 
         pCompPrivate->sCbData.EventHandler (
-	                        pHandle, pHandle->pApplicationPrivate,
-	                        OMX_EventError, 
+                            pHandle, pHandle->pApplicationPrivate,
+                            OMX_EventError,
                            OMX_ErrorResourcesPreempted,OMX_TI_ErrorMinor,
-	                        "Componentn Preempted\n");
+                            "Componentn Preempted\n");
 
             OMX_PRSTATE2(pCompPrivate->dbg, "Send command to Idle from RM CallBack\n");
         OMX_SendCommand(pHandle, Cmd, state, NULL);
@@ -4040,11 +4138,11 @@
     else if (*(cbData.RM_Error) == OMX_RmProxyCallback_ResourcesAcquired)
     {
         pCompPrivate->sCbData.EventHandler (
-	                        pHandle, pHandle->pApplicationPrivate,
-	                        OMX_EventResourcesAcquired, 0,0,
-	                        NULL);
-        OMX_PRSTATE2(pCompPrivate->dbg, "Send command to Executing from RM CallBack\n");            
-        OMX_SendCommand(pHandle, Cmd, OMX_StateExecuting, NULL);        
+                            pHandle, pHandle->pApplicationPrivate,
+                            OMX_EventResourcesAcquired, 0,0,
+                            NULL);
+        OMX_PRSTATE2(pCompPrivate->dbg, "Send command to Executing from RM CallBack\n");
+        OMX_SendCommand(pHandle, Cmd, OMX_StateExecuting, NULL);
     }
 }
 #endif
@@ -4075,7 +4173,6 @@
                                     pCompPort->format.video.nFrameHeight / 2;
         }
         pCompPort->nBufferSize += 256;
-        OMX_ERROR5(pCompPrivate->dbg, "*The output buffer size is %lu and number of buffer is %lu. WIDTH=%lu HEIGHT=%lu FORMAT %d\n", pCompPort->nBufferSize, pCompPort->nBufferCountActual, pCompPort->format.video.nFrameWidth, pCompPort->format.video.nFrameHeight, pCompPort->format.video.eCompressionFormat);
     }
 }
 
@@ -4100,7 +4197,7 @@
         MaxCPB = 4000;
     }
     else if(nMacroBlocks <= 1620) {
-        /* Note - Max bitrate in this case is assumed to max 4 Mbps to limit the buffer size
+        /* Note - Max bitrate in this case is assumed to max 4 Mbps to limit the buffer size 
            If bitrate in this particular case could be higher than 4 Mbps, increase MxCPB value */
         MaxCPB = 4000;
     }
@@ -4109,7 +4206,202 @@
 
     /* MaxCPB are in units of 1200 bits i.e. 150 bytes */
     /* Return  buffer size in bytes*/
-    return (150 * MaxCPB);
+    /*Last patch to improve the performance*/
+    /*return (150 * MaxCPB);*/
+    return (width * height) / 2;
+}
+OMX_U32 OMX_VIDENC_GetDefaultBitRate(VIDENC_COMPONENT_PRIVATE* pComponentPrivate)
+{
+    OMX_PARAM_PORTDEFINITIONTYPE* pPortDef;
+    OMX_U32 bitrate;
+    int nCount;
+
+    pPortDef = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
+    for ( nCount = 0; nCount < VIDENC_MAXBITRATES; nCount++ ) {
+        if (pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
+            bitrate = VIDENC_STRUCT_H264DEFBITRATE [nCount][1];
+            if ((pPortDef->format.video.nFrameWidth * pPortDef->format.video.nFrameHeight)
+                <= VIDENC_STRUCT_H264DEFBITRATE[nCount][0]) {
+                break;
+            }
+        }
+        else if (pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
+            bitrate = VIDENC_STRUCT_MPEG4DEFBITRATE [nCount][1];
+            if ((pPortDef->format.video.nFrameWidth * pPortDef->format.video.nFrameHeight)
+                <= VIDENC_STRUCT_MPEG4DEFBITRATE[nCount][0]) {
+                break;
+            }
+        }
+        else {
+            bitrate = VIDENC_STRUCT_H263DEFBITRATE [nCount][1];
+            if ((pPortDef->format.video.nFrameWidth * pPortDef->format.video.nFrameHeight)
+                <= VIDENC_STRUCT_H263DEFBITRATE[nCount][0]) {
+                break;
+            }
+        }
+    }
+
+    return bitrate;
+}
+
+
+void printMpeg4Params(MP4VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs,
+                      struct OMX_TI_Debug *dbg)
+{
+    OMX_PRDSP2(*dbg, "\nusNumStreams = %d\n", pCreatePhaseArgs->usNumStreams);
+    OMX_PRDSP2(*dbg, "usStreamId = %d\n", pCreatePhaseArgs->usStreamId);
+    OMX_PRDSP2(*dbg, "usBuffTypeInStream = %d\n", pCreatePhaseArgs->usBuffTypeInStream);
+    OMX_PRDSP2(*dbg, "usMaxBuffsInStream = %d\n", pCreatePhaseArgs->usMaxBuffsInStream);
+    OMX_PRDSP2(*dbg, "usStreamId2 = %d\n", pCreatePhaseArgs->usStreamId2);
+    OMX_PRDSP2(*dbg, "usBuffTypeInStream2 = %d\n", pCreatePhaseArgs->usBuffTypeInStream2);
+    OMX_PRDSP2(*dbg, "usMaxBuffsInStream2 = %d\n", pCreatePhaseArgs->usMaxBuffsInStream2);
+
+    OMX_PRDSP2(*dbg, "ulWidth = %d\n", pCreatePhaseArgs->ulWidth);
+    OMX_PRDSP2(*dbg, "ulHeight = %d\n", pCreatePhaseArgs->ulHeight);
+    OMX_PRDSP2(*dbg, "ulTargetBitRate = %d\n", pCreatePhaseArgs->ulTargetBitRate);
+    OMX_PRDSP2(*dbg, "ulVBVSize = %d\n", pCreatePhaseArgs->ulVBVSize);
+    OMX_PRDSP2(*dbg, "ulGOBHeadersInterval = %d\n", pCreatePhaseArgs->ulGOBHeadersInterval);
+
+    OMX_PRDSP2(*dbg, "ucIsMPEG4 = %d\n", pCreatePhaseArgs->ucIsMPEG4);
+    OMX_PRDSP2(*dbg, "ucYUVFormat = %d\n", pCreatePhaseArgs->ucYUVFormat);
+    OMX_PRDSP2(*dbg, "ucHEC = %d\n", pCreatePhaseArgs->ucHEC);
+    OMX_PRDSP2(*dbg, "ucResyncMarker = %d\n", pCreatePhaseArgs->ucResyncMarker);
+    OMX_PRDSP2(*dbg, "ucDataPartitioning = %d\n", pCreatePhaseArgs->ucDataPartitioning);
+    OMX_PRDSP2(*dbg, "ucReversibleVLC = %d\n", pCreatePhaseArgs->ucReversibleVLC);
+    OMX_PRDSP2(*dbg, "ucUnrestrictedMV = %d\n", pCreatePhaseArgs->ucUnrestrictedMV);
+    OMX_PRDSP2(*dbg, "ucFrameRate = %d\n", pCreatePhaseArgs->ucFrameRate);
+    OMX_PRDSP2(*dbg, "ucRateControlAlgorithm = %d\n", pCreatePhaseArgs->ucRateControlAlgorithm);
+    OMX_PRDSP2(*dbg, "ucQPFirstIFrame = %d\n", pCreatePhaseArgs->ucQPFirstIFrame);
+    OMX_PRDSP2(*dbg, "ucProfile = %d\n", pCreatePhaseArgs->ucProfile);
+    OMX_PRDSP2(*dbg, "ucLevel = %d\n", pCreatePhaseArgs->ucLevel);
+    OMX_PRDSP2(*dbg, "ulMaxDelay = %d\n", pCreatePhaseArgs->ulMaxDelay);
+    /*
+    OMX_PRDSP2(*dbg, "ulVbvParamEnable = %d\n", pCreatePhaseArgs->ulVbvParamEnable);
+    OMX_PRDSP2(*dbg, "ulH263SliceMode = %d\n", pCreatePhaseArgs->ulH263SliceMode);
+    */
+    OMX_PRDSP2(*dbg, "ulUseGOV = %d\n", pCreatePhaseArgs->ulUseGOV);
+    OMX_PRDSP2(*dbg, "ulUseVOS = %d\n", pCreatePhaseArgs->ulUseVOS);
+    OMX_PRDSP2(*dbg, "enableH263AnnexI = %d\n", pCreatePhaseArgs->enableH263AnnexI);
+    OMX_PRDSP2(*dbg, "enableH263AnnexJ = %d\n", pCreatePhaseArgs->enableH263AnnexJ);
+    OMX_PRDSP2(*dbg, "enableH263AnnexT = %d\n", pCreatePhaseArgs->enableH263AnnexT);
+}
+void printH264CreateParams(H264VE_GPP_SN_Obj_CreatePhase* pCreatePhaseArgs, struct OMX_TI_Debug *dbg)
+{
+    OMX_PRDSP2(*dbg, "\nusNumStreams = %d\n", pCreatePhaseArgs->usNumStreams);
+    OMX_PRDSP2(*dbg, "usStreamId = %d\n", pCreatePhaseArgs->usStreamId);
+    OMX_PRDSP2(*dbg, "usBuffTypeInStream = %d\n", pCreatePhaseArgs->usBuffTypeInStream);
+    OMX_PRDSP2(*dbg, "usMaxBuffsInStream = %d\n", pCreatePhaseArgs->usMaxBuffsInStream);
+    OMX_PRDSP2(*dbg, "usStreamId2 = %d\n", pCreatePhaseArgs->usStreamId2);
+    OMX_PRDSP2(*dbg, "usBuffTypeInStream2 = %d\n", pCreatePhaseArgs->usBuffTypeInStream2);
+    OMX_PRDSP2(*dbg, "usMaxBuffsInStream2 = %d\n", pCreatePhaseArgs->usMaxBuffsInStream2);
+
+    OMX_PRDSP2(*dbg, "ulWidth = %d\n", pCreatePhaseArgs->ulWidth);
+    OMX_PRDSP2(*dbg, "ulHeight = %d\n", pCreatePhaseArgs->ulHeight);
+    OMX_PRDSP2(*dbg, "ulTargetBitRate = %d\n", pCreatePhaseArgs->ulTargetBitRate);
+    OMX_PRDSP2(*dbg, "ulBitstreamBuffSize = %d\n", pCreatePhaseArgs->ulBitstreamBuffSize);
+    OMX_PRDSP2(*dbg, "ulIntraFramePeriod = %d\n", pCreatePhaseArgs->ulIntraFramePeriod);
+    OMX_PRDSP2(*dbg, "ulFrameRate = %d\n", pCreatePhaseArgs->ulFrameRate);
+
+    OMX_PRDSP2(*dbg, "ucYUVFormat = %d\n", pCreatePhaseArgs->ucYUVFormat);
+    OMX_PRDSP2(*dbg, "ucUnrestrictedMV = %d\n", pCreatePhaseArgs->ucUnrestrictedMV);
+    OMX_PRDSP2(*dbg, "ucNumRefFrames = %d\n", pCreatePhaseArgs->ucNumRefFrames);
+    OMX_PRDSP2(*dbg, "ucRateControlAlgorithm = %d\n", pCreatePhaseArgs->ucRateControlAlgorithm);
+    OMX_PRDSP2(*dbg, "ucIDREnable = %d\n", pCreatePhaseArgs->ucIDREnable);
+    OMX_PRDSP2(*dbg, "ucDeblockingEnable = %d\n", pCreatePhaseArgs->ucDeblockingEnable);
+    OMX_PRDSP2(*dbg, "ucMVRange = %d\n", pCreatePhaseArgs->ucMVRange);
+    OMX_PRDSP2(*dbg, "ucQPIFrame = %d\n", pCreatePhaseArgs->ucQPIFrame);
+    OMX_PRDSP2(*dbg, "ucProfile = %d\n", pCreatePhaseArgs->ucProfile);
+    OMX_PRDSP2(*dbg, "ucLevel = %d\n", pCreatePhaseArgs->ucLevel);
+
+    OMX_PRDSP2(*dbg, "usNalCallback = %d\n", pCreatePhaseArgs->usNalCallback);
+    OMX_PRDSP2(*dbg, "ulEncodingPreset = %d\n", pCreatePhaseArgs->ulEncodingPreset);
+    OMX_PRDSP2(*dbg, "ulRcAlgo = %d\n", pCreatePhaseArgs->ulRcAlgo);
+}
+
+void printMpeg4UAlgInParam(MP4VE_GPP_SN_UALGInputParams* pUalgInpParams, int printAlways, struct OMX_TI_Debug *dbg)
+{
+    static int printed=0;
+
+    if(printAlways || !printed)
+    {
+        printed++;
+        OMX_PRDSP2(*dbg, "\nulFrameIndex = %u\n", pUalgInpParams->ulFrameIndex);
+        OMX_PRDSP2(*dbg, "ulTargetFrameRate = %u\n", pUalgInpParams->ulTargetFrameRate);
+        OMX_PRDSP2(*dbg, "ulTargetBitRate = %u\n", pUalgInpParams->ulTargetBitRate);
+        OMX_PRDSP2(*dbg, "ulIntraFrameInterval = %u\n", pUalgInpParams->ulIntraFrameInterval);
+        OMX_PRDSP2(*dbg, "ulGenerateHeader = %u\n", pUalgInpParams->ulGenerateHeader);
+        OMX_PRDSP2(*dbg, "ulForceIFrame = %u\n", pUalgInpParams->ulForceIFrame);
+        OMX_PRDSP2(*dbg, "ulResyncInterval = %u\n", pUalgInpParams->ulResyncInterval);
+        OMX_PRDSP2(*dbg, "ulHecInterval = %u\n", pUalgInpParams->ulHecInterval);
+        OMX_PRDSP2(*dbg, "ulAIRRate = %u\n", pUalgInpParams->ulAIRRate);
+        OMX_PRDSP2(*dbg, "ulMIRRate = %u\n", pUalgInpParams->ulMIRRate);
+        OMX_PRDSP2(*dbg, "ulQPIntra = %u\n", pUalgInpParams->ulQPIntra);
+        OMX_PRDSP2(*dbg, "ulfCode = %u\n", pUalgInpParams->ulfCode);
+        OMX_PRDSP2(*dbg, "ulHalfPel = %u\n", pUalgInpParams->ulHalfPel);
+        OMX_PRDSP2(*dbg, "ulACPred = %u\n", pUalgInpParams->ulACPred);
+        OMX_PRDSP2(*dbg, "ul4MV = %u\n", pUalgInpParams->ul4MV);
+        OMX_PRDSP2(*dbg, "uluseUMV = %u\n", pUalgInpParams->uluseUMV);
+        OMX_PRDSP2(*dbg, "ulMVDataEnable = %u\n", pUalgInpParams->ulMVDataEnable);
+        OMX_PRDSP2(*dbg, "ulResyncDataEnable = %u\n", pUalgInpParams->ulResyncDataEnable);
+        OMX_PRDSP2(*dbg, "ulQPInter = %u\n", pUalgInpParams->ulQPInter);
+        OMX_PRDSP2(*dbg, "ulLastFrame = %u\n", pUalgInpParams->ulLastFrame);
+        OMX_PRDSP2(*dbg, "ulcapturewidth = %u\n", pUalgInpParams->ulcapturewidth);
+        OMX_PRDSP2(*dbg, "ulQpMax = %u\n", pUalgInpParams->ulQpMax);
+        OMX_PRDSP2(*dbg, "ulQpMin = %u\n", pUalgInpParams->ulQpMin);
+    }
+}
+
+
+void printH264UAlgInParam(H264VE_GPP_SN_UALGInputParams* pUalgInpParams, int printAlways, struct OMX_TI_Debug *dbg)
+{
+    static int printed=0;
+
+    if(printAlways || !printed)
+    {
+        printed++;
+        OMX_PRDSP2(*dbg, "\nqpIntra = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.qpIntra);
+        OMX_PRDSP2(*dbg, "qpInter = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.qpInter);
+        OMX_PRDSP2(*dbg, "qpMax = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.qpMax);
+        OMX_PRDSP2(*dbg, "qpMin = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.qpMin);
+        OMX_PRDSP2(*dbg, "lfDisableIdc = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.lfDisableIdc);
+        OMX_PRDSP2(*dbg, "quartPelDisable = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.quartPelDisable);
+        OMX_PRDSP2(*dbg, "airMbPeriod = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.airMbPeriod);
+        OMX_PRDSP2(*dbg, "maxMBsPerSlice = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.maxMBsPerSlice);
+        OMX_PRDSP2(*dbg, "maxBytesPerSlice = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.maxBytesPerSlice);
+        OMX_PRDSP2(*dbg, "sliceRefreshRowStartNumber = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceRefreshRowStartNumber);
+        OMX_PRDSP2(*dbg, "sliceRefreshRowNumber = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceRefreshRowNumber);
+        OMX_PRDSP2(*dbg, "filterOffsetA = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.filterOffsetA);
+        OMX_PRDSP2(*dbg, "filterOffsetB = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.filterOffsetB);
+        OMX_PRDSP2(*dbg, "log2MaxFNumMinus4 = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.log2MaxFNumMinus4);
+        OMX_PRDSP2(*dbg, "chromaQPIndexOffset = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.chromaQPIndexOffset);
+        OMX_PRDSP2(*dbg, "constrainedIntraPredEnable = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.constrainedIntraPredEnable);
+        OMX_PRDSP2(*dbg, "picOrderCountType = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.picOrderCountType);
+        OMX_PRDSP2(*dbg, "maxMVperMB = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.maxMVperMB);
+        OMX_PRDSP2(*dbg, "intra4x4EnableIdc = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.intra4x4EnableIdc);
+        OMX_PRDSP2(*dbg, "mvDataEnable = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.mvDataEnable);
+        OMX_PRDSP2(*dbg, "hierCodingEnable = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.hierCodingEnable);
+        OMX_PRDSP2(*dbg, "streamFormat = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.streamFormat);
+        OMX_PRDSP2(*dbg, "intraRefreshMethod = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.intraRefreshMethod);
+        OMX_PRDSP2(*dbg, "perceptualQuant = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.perceptualQuant);
+        OMX_PRDSP2(*dbg, "sceneChangeDet = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sceneChangeDet);
+        OMX_PRDSP2(*dbg, "numSliceASO = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.numSliceASO);
+        OMX_PRDSP2(*dbg, "numSliceGroups = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.numSliceGroups);
+        OMX_PRDSP2(*dbg, "sliceGroupMapType = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceGroupMapType);
+        OMX_PRDSP2(*dbg, "sliceGroupChangeDirectionFlag = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeDirectionFlag);
+        OMX_PRDSP2(*dbg, "sliceGroupChangeRate = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeRate);
+        OMX_PRDSP2(*dbg, "sliceGroupChangeCycle = %lu\n", pUalgInpParams->H264VENC_TI_DYNAMICPARAMS.sliceGroupChangeCycle);
+        OMX_PRDSP2(*dbg, "ulFrameIndex = %lu\n", pUalgInpParams->ulFrameIndex);
+    }
+}
+
+OMX_ERRORTYPE IsResolutionPlayable (OMX_U32 width, OMX_U32 height)
+{
+    if (width  > WVGA_MAX_WIDTH || height > WVGA_MAX_HEIGHT) 
+    {
+        return OMX_ErrorBadParameter;
+    }
+    return OMX_ErrorNone;
+
 }
 
 OMX_ERRORTYPE AddStateTransition(VIDENC_COMPONENT_PRIVATE* pComponentPrivate) {
@@ -4140,7 +4432,7 @@
 
     pComponentPrivate->nPendingStateChangeRequests--;
 
-    /* If there are no more pending requests, signal the thread waiting on this*/
+   /* If there are no more pending requests, signal the thread waiting on this*/
     if(!pComponentPrivate->nPendingStateChangeRequests && bEnableSignal) {
        pthread_cond_signal(&(pComponentPrivate->StateChangeCondition));
     }
@@ -4151,4 +4443,3 @@
 
     return eError;
 }
-
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 8cf3bb8..20056f1 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
@@ -22,13 +22,13 @@
 *             Texas Instruments OMAP(TM) Platform Software
 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
 *
-*  Use of this software is controlled by the terms and conditions found 
+*  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * ============================================================================*/
 /**
 * @file OMX_VideoEncoder.c
 *
-* This file implements OMX Component for MPEG-4 encoder that 
+* This file implements OMX Component for MPEG-4 encoder that
 * is fully compliant with the OMX specification 1.5.
 *
 * @path  $(CSLPATH)\src
@@ -36,21 +36,21 @@
 * @rev  0.1
 */
 /* ---------------------------------------------------------------------------*/
-/* =============================================================================  
-*! 
-*! Revision History 
+/* =============================================================================
+*!
+*! Revision History
 *! =============================================================================
 *!
-*! 24-Jul-2005 mf: Revisions appear in reverse chronological order; 
-*! that is, newest first.  The date format is dd-Mon-yyyy.  
+*! 24-Jul-2005 mf: Revisions appear in reverse chronological order;
+*! that is, newest first.  The date format is dd-Mon-yyyy.
 * ============================================================================*/
 
 /* ------compilation control switches ----------------------------------------*/
 /******************************************************************************
-*  INCLUDE FILES                                                 
+*  INCLUDE FILES
 *******************************************************************************/
 /* ----- system and platform files -------------------------------------------*/
-#ifdef UNDER_CE 
+#ifdef UNDER_CE
     #include <windows.h>
     #include <oaf_osal.h>
     #include <omx_core.h>
@@ -63,7 +63,7 @@
     #include <sys/select.h>
     #include <errno.h>
     #include <pthread.h>
-	#include <dlfcn.h>
+    #include <dlfcn.h>
 #endif
 
 #include <string.h>
@@ -83,7 +83,6 @@
 #ifdef UNDER_CE
     extern HINSTANCE g_hLcmlDllHandle;
 #endif
-
 /* H.263 Supported Levels & profiles */
 VIDEO_PROFILE_LEVEL_TYPE SupportedH263ProfileLevels[] = {
   {OMX_VIDEO_H263ProfileBaseline, OMX_VIDEO_H263Level10},
@@ -128,8 +127,6 @@
   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel3},
   {OMX_VIDEO_AVCProfileBaseline, OMX_VIDEO_AVCLevel31},
   {-1,-1}};
-
-
 /******************************************************************************
 *  EXTERNAL REFERENCES NOTE : only use if not found in header file
 *******************************************************************************/
@@ -200,12 +197,12 @@
     }
 
 /*--------function prototypes ------------------------------------------------*/
-static OMX_ERRORTYPE SetCallbacks (OMX_IN OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE SetCallbacks (OMX_IN OMX_HANDLETYPE hComponent,
                                    OMX_IN OMX_CALLBACKTYPE* pCallBacks,
                                    OMX_IN OMX_PTR pAppData);
 
 static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComponent,
-                                          OMX_STRING  szComponentName,      
+                                          OMX_STRING  szComponentName,
                                           OMX_VERSIONTYPE* pComponentVersion,
                                           OMX_VERSIONTYPE* pSpecVersion,
                                           OMX_UUIDTYPE* pComponentUUID);
@@ -215,15 +212,15 @@
                                   OMX_IN OMX_U32 nParam1,
                                   OMX_IN OMX_PTR pCmdData);
 
-static OMX_ERRORTYPE GetParameter (OMX_IN OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE GetParameter (OMX_IN OMX_HANDLETYPE hComponent,
                                    OMX_IN OMX_INDEXTYPE nParamIndex,
                                    OMX_INOUT OMX_PTR CompParamStruct);
 
-static OMX_ERRORTYPE SetParameter (OMX_IN OMX_HANDLETYPE hComponent, 
-                                   OMX_IN OMX_INDEXTYPE nParamIndex, 
+static OMX_ERRORTYPE SetParameter (OMX_IN OMX_HANDLETYPE hComponent,
+                                   OMX_IN OMX_INDEXTYPE nParamIndex,
                                    OMX_IN OMX_PTR CompParamStruct);
 
-static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComponent,
                                 OMX_INDEXTYPE nConfigIndex,
                                 OMX_PTR ComponentConfigStructure);
 
@@ -231,16 +228,16 @@
                                 OMX_INDEXTYPE nConfigIndex,
                                 OMX_PTR ComponentConfigStructure);
 
-static OMX_ERRORTYPE EmptyThisBuffer (OMX_IN OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE EmptyThisBuffer (OMX_IN OMX_HANDLETYPE hComponent,
                                       OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
 
-static OMX_ERRORTYPE FillThisBuffer (OMX_IN OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE FillThisBuffer (OMX_IN OMX_HANDLETYPE hComponent,
                                      OMX_IN OMX_BUFFERHEADERTYPE* pBuffer);
 
 static OMX_ERRORTYPE GetState (OMX_IN OMX_HANDLETYPE hComponent,
                                OMX_OUT OMX_STATETYPE* pState);
 
-static OMX_ERRORTYPE ComponentTunnelRequest (OMX_IN OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE ComponentTunnelRequest (OMX_IN OMX_HANDLETYPE hComponent,
                                              OMX_IN OMX_U32 nPort,
                                              OMX_IN OMX_HANDLETYPE hTunneledComp,
                                              OMX_IN  OMX_U32 nTunneledPort,
@@ -251,13 +248,13 @@
                                 OMX_IN OMX_U32 nPortIndex,
                                 OMX_IN OMX_PTR pAppPrivate,
                                 OMX_IN OMX_U32 nSizeBytes,
-                                OMX_IN OMX_U8* pBuffer); 
+                                OMX_IN OMX_U8* pBuffer);
 
 static OMX_ERRORTYPE AllocateBuffer (OMX_IN OMX_HANDLETYPE hComponent,
                                      OMX_INOUT OMX_BUFFERHEADERTYPE** pBuffer,
                                      OMX_IN OMX_U32 nPortIndex,
                                      OMX_IN OMX_PTR pAppPrivate,
-                                     OMX_IN OMX_U32 nSizeBytes); 
+                                     OMX_IN OMX_U32 nSizeBytes);
 
 static OMX_ERRORTYPE FreeBuffer (OMX_IN OMX_HANDLETYPE hComponent,
                                  OMX_IN OMX_U32 nPortIndex,
@@ -274,13 +271,32 @@
                                      OMX_IN OMX_STRING cParameterName,
                                      OMX_OUT OMX_INDEXTYPE* pIndexType);
 
-#ifdef __KHRONOS_CONF_1_1__                                       
+#ifdef __KHRONOS_CONF_1_1__
 static OMX_ERRORTYPE ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent,
                                        OMX_OUT OMX_U8 *cRole,
                                        OMX_IN OMX_U32 nIndex);
 #endif
 
 void CalculateBufferSize(OMX_PARAM_PORTDEFINITIONTYPE* pCompPort, VIDENC_COMPONENT_PRIVATE* pCompPrivate);
+OMX_ERRORTYPE IsResolutionPlayable (OMX_U32 width, OMX_U32 height);
+
+static const int iQ16_Const = 1 << 16;
+static const float fQ16_Const = (float)(1 << 16);
+
+static float Q16Tof(int nQ16)
+{
+    return nQ16 / fQ16_Const;
+}
+
+static int fToQ16(float f)
+{
+    return(int)(f*fQ16_Const);
+}
+
+extern OMX_U32 VIDENC_STRUCT_H264DEFBITRATE [VIDENC_MAXBITRATES][2];
+extern OMX_U32 VIDENC_STRUCT_MPEG4DEFBITRATE [VIDENC_MAXBITRATES][2];
+extern OMX_U32 VIDENC_STRUCT_H263DEFBITRATE [VIDENC_MAXBITRATES][2];
+
 /*----------------------------------------------------------------------------*/
 /**
   * OMX_ComponentInit() Set the all the function pointers of component
@@ -312,19 +328,19 @@
 
     OMX_S32 nError = 0;
     OMX_U32 i = 0;
-	char* sDynamicFormat;
+    char* sDynamicFormat;
 #ifdef UNDER_CE
     pthread_attr_t attr;
     memset(&attr, 0, sizeof(attr));
-#endif 
+#endif
 
 
     /* get default settings for debug */
     OMX_DBG_INIT(dbg, "OMX_DBG_VIDENC");
 
-	/*dlopen("libLCML.so", RTLD_LAZY);*/
+    /*dlopen("libLCML.so", RTLD_LAZY);*/
     OMX_PRINT2(dbg, "Enter to ComponetInit\n");
-    if (!hComponent) 
+    if (!hComponent)
     {
         eError = OMX_ErrorBadParameter;
         goto OMX_CONF_CMD_BAIL;
@@ -332,13 +348,13 @@
     pHandle = (OMX_COMPONENTTYPE*)hComponent;
     eError = OMX_VIDENC_ListCreate(&dbg, &pMemoryListHead);
     OMX_CONF_BAIL_IF_ERROR(eError);
- 
+
     /* Allocate memory for component's private data area */
-    VIDENC_MALLOC(pHandle->pComponentPrivate, 
-                  sizeof(VIDENC_COMPONENT_PRIVATE), 
-                  VIDENC_COMPONENT_PRIVATE, 
+    VIDENC_MALLOC(pHandle->pComponentPrivate,
+                  sizeof(VIDENC_COMPONENT_PRIVATE),
+                  VIDENC_COMPONENT_PRIVATE,
                   pMemoryListHead, dbg);
-    
+
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
     pComponentPrivate->pMemoryListHead = pMemoryListHead;
 
@@ -358,16 +374,17 @@
 
     pComponentPrivate->bDeblockFilter       = OMX_TRUE;
     pComponentPrivate->nVBVSize             = 120;
-    pComponentPrivate->bForceIFrame         = OMX_FALSE; 
+    pComponentPrivate->bForceIFrame         = OMX_FALSE;
     pComponentPrivate->nIntraFrameInterval  = 30;
-    pComponentPrivate->nQPI                 = 12; 
-    pComponentPrivate->nAIRRate             = 0; 
+    pComponentPrivate->nQPI                 = 12;
+    pComponentPrivate->nAIRRate             = 0;
+    pComponentPrivate->ucUnrestrictedMV     = 0;
     pComponentPrivate->bHideEvents          = OMX_FALSE;
     pComponentPrivate->bHandlingFatalError  = OMX_FALSE;
     pComponentPrivate->bUnresponsiveDsp     = OMX_FALSE;
     pComponentPrivate->bCodecLoaded         = OMX_FALSE;
-    pComponentPrivate->cComponentName		= "OMX.TI.Video.encoder";
-		
+    pComponentPrivate->cComponentName       = "OMX.TI.Video.encoder";
+
 #ifdef __KHRONOS_CONF__
     pComponentPrivate->bPassingIdleToLoaded = OMX_FALSE;
     pComponentPrivate->bErrorLcmlHandle     = OMX_FALSE;
@@ -391,8 +408,8 @@
     {
         pComponentPrivate->sliceGroupParams[i] = 0;
     }
-    
-    /*Assigning address of Component Structure point to place holder inside 
+
+    /*Assigning address of Component Structure point to place holder inside
        component private structure
     */
     ((VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->pHandle = pHandle;
@@ -426,144 +443,144 @@
         {
 
     strcpy((char *)pComponentPrivate->componentRole.cRole, "video_encoder.mpeg4");
-		}
+        }
         else if (strcmp(sDynamicFormat,  "H263") == 0 )
         {
     strcpy((char *)pComponentPrivate->componentRole.cRole, "video_encoder.h263");
-		}
+        }
         else if (strcmp(sDynamicFormat,  "H264") == 0 )
         {
     strcpy((char *)pComponentPrivate->componentRole.cRole, "video_encoder.avc");
-		}
-		}
+        }
+        }
     else
     {
     strcpy((char *)pComponentPrivate->componentRole.cRole, "video_encoder.avc");
-		}
+        }
 #else
     strcpy((char *)pComponentPrivate->componentRole.cRole, "VideoEncode");
 /*    strcpy((char *)pComponentPrivate->componentRole.cRole, "video_encoder.mpeg4");*/
 #endif
-#endif    
+#endif
 
     /* Allocate memory for component data structures */
-    VIDENC_MALLOC(pComponentPrivate->pPortParamType, 
-                  sizeof(OMX_PORT_PARAM_TYPE), 
-                  OMX_PORT_PARAM_TYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pPortParamType,
+                  sizeof(OMX_PORT_PARAM_TYPE),
+                  OMX_PORT_PARAM_TYPE,
                   pMemoryListHead, dbg);
 #ifdef __KHRONOS_CONF_1_1__
-    VIDENC_MALLOC(pComponentPrivate->pPortAudioType, 
-                  sizeof(OMX_PORT_PARAM_TYPE), 
-                  OMX_PORT_PARAM_TYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pPortAudioType,
+                  sizeof(OMX_PORT_PARAM_TYPE),
+                  OMX_PORT_PARAM_TYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pPortImageType, 
-              sizeof(OMX_PORT_PARAM_TYPE), 
-              OMX_PORT_PARAM_TYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pPortImageType,
+              sizeof(OMX_PORT_PARAM_TYPE),
+              OMX_PORT_PARAM_TYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pPortOtherType, 
-                  sizeof(OMX_PORT_PARAM_TYPE), 
-                  OMX_PORT_PARAM_TYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pPortOtherType,
+                  sizeof(OMX_PORT_PARAM_TYPE),
+                  OMX_PORT_PARAM_TYPE,
                   pMemoryListHead, dbg);
 #endif
 
 
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT], 
-                  sizeof(VIDEOENC_PORT_TYPE), 
-                  VIDEOENC_PORT_TYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT],
+                  sizeof(VIDEOENC_PORT_TYPE),
+                  VIDEOENC_PORT_TYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT], 
-                  sizeof(VIDEOENC_PORT_TYPE), 
-                  VIDEOENC_PORT_TYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT],
+                  sizeof(VIDEOENC_PORT_TYPE),
+                  VIDEOENC_PORT_TYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef, 
-                  sizeof(OMX_PARAM_PORTDEFINITIONTYPE), 
-                  OMX_PARAM_PORTDEFINITIONTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef,
+                  sizeof(OMX_PARAM_PORTDEFINITIONTYPE),
+                  OMX_PARAM_PORTDEFINITIONTYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef, 
-                  sizeof(OMX_PARAM_PORTDEFINITIONTYPE), 
-                  OMX_PARAM_PORTDEFINITIONTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef,
+                  sizeof(OMX_PARAM_PORTDEFINITIONTYPE),
+                  OMX_PARAM_PORTDEFINITIONTYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortFormat, 
-                  sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE), 
-                  OMX_VIDEO_PARAM_PORTFORMATTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortFormat,
+                  sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE),
+                  OMX_VIDEO_PARAM_PORTFORMATTYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortFormat, 
-                  sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE), 
-                  OMX_VIDEO_PARAM_PORTFORMATTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortFormat,
+                  sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE),
+                  OMX_VIDEO_PARAM_PORTFORMATTYPE,
                   pMemoryListHead, dbg);
 #ifdef __KHRONOS_CONF_1_1__
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pProfileType, 
-                  sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE), 
-                  OMX_VIDEO_PARAM_PROFILELEVELTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pProfileType,
+                  sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE),
+                  OMX_VIDEO_PARAM_PROFILELEVELTYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pProfileType, 
-                  sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE), 
-                  OMX_VIDEO_PARAM_PROFILELEVELTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pProfileType,
+                  sizeof(OMX_VIDEO_PARAM_PROFILELEVELTYPE),
+                  OMX_VIDEO_PARAM_PROFILELEVELTYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pBitRateTypeConfig, 
-                  sizeof(OMX_VIDEO_CONFIG_BITRATETYPE), 
-                  OMX_VIDEO_CONFIG_BITRATETYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pBitRateTypeConfig,
+                  sizeof(OMX_VIDEO_CONFIG_BITRATETYPE),
+                  OMX_VIDEO_CONFIG_BITRATETYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig, 
-                  sizeof(OMX_VIDEO_CONFIG_BITRATETYPE), 
-                  OMX_VIDEO_CONFIG_BITRATETYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig,
+                  sizeof(OMX_VIDEO_CONFIG_BITRATETYPE),
+                  OMX_VIDEO_CONFIG_BITRATETYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pFrameRateConfig, 
-                  sizeof(OMX_CONFIG_FRAMERATETYPE), 
-                  OMX_CONFIG_FRAMERATETYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pFrameRateConfig,
+                  sizeof(OMX_CONFIG_FRAMERATETYPE),
+                  OMX_CONFIG_FRAMERATETYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pFrameRateConfig, 
-                  sizeof(OMX_CONFIG_FRAMERATETYPE), 
-                  OMX_CONFIG_FRAMERATETYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pFrameRateConfig,
+                  sizeof(OMX_CONFIG_FRAMERATETYPE),
+                  OMX_CONFIG_FRAMERATETYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType, 
-                  sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE), 
-                  OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType,
+                  sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE),
+                  OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE,
                   pMemoryListHead, dbg);
-	VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pIntraRefreshType, 
-                  sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE), 
-                  OMX_VIDEO_PARAM_INTRAREFRESHTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pIntraRefreshType,
+                  sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE),
+                  OMX_VIDEO_PARAM_INTRAREFRESHTYPE,
                   pMemoryListHead, dbg);
 #endif
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pBitRateType, 
-                  sizeof(OMX_VIDEO_PARAM_BITRATETYPE), 
-                  OMX_VIDEO_PARAM_BITRATETYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pBitRateType,
+                  sizeof(OMX_VIDEO_PARAM_BITRATETYPE),
+                  OMX_VIDEO_PARAM_BITRATETYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType, 
-                  sizeof(OMX_VIDEO_PARAM_BITRATETYPE), 
-                  OMX_VIDEO_PARAM_BITRATETYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType,
+                  sizeof(OMX_VIDEO_PARAM_BITRATETYPE),
+                  OMX_VIDEO_PARAM_BITRATETYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pPriorityMgmt, 
-                  sizeof(OMX_PRIORITYMGMTTYPE), 
-                  OMX_PRIORITYMGMTTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pPriorityMgmt,
+                  sizeof(OMX_PRIORITYMGMTTYPE),
+                  OMX_PRIORITYMGMTTYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pH264, 
-                  sizeof(OMX_VIDEO_PARAM_AVCTYPE), 
-                  OMX_VIDEO_PARAM_AVCTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pH264,
+                  sizeof(OMX_VIDEO_PARAM_AVCTYPE),
+                  OMX_VIDEO_PARAM_AVCTYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pMpeg4, 
-                  sizeof(OMX_VIDEO_PARAM_MPEG4TYPE), 
-                  OMX_VIDEO_PARAM_MPEG4TYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pMpeg4,
+                  sizeof(OMX_VIDEO_PARAM_MPEG4TYPE),
+                  OMX_VIDEO_PARAM_MPEG4TYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pH263, 
-                  sizeof(OMX_VIDEO_PARAM_H263TYPE), 
-                  OMX_VIDEO_PARAM_H263TYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pH263,
+                  sizeof(OMX_VIDEO_PARAM_H263TYPE),
+                  OMX_VIDEO_PARAM_H263TYPE,
                   pMemoryListHead, dbg);
     VIDENC_MALLOC(pComponentPrivate->pVidParamBitrate, 
                   sizeof(OMX_VIDEO_PARAM_BITRATETYPE), 
                   OMX_VIDEO_PARAM_BITRATETYPE, 
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pQuantization, 
-                  sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE), 
-                  OMX_VIDEO_PARAM_QUANTIZATIONTYPE, 
+    VIDENC_MALLOC(pComponentPrivate->pQuantization,
+                  sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE),
+                  OMX_VIDEO_PARAM_QUANTIZATIONTYPE,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pH264IntraPeriod, 
+    VIDENC_MALLOC(pComponentPrivate->pH264IntraPeriod,
                   sizeof(OMX_VIDEO_CONFIG_AVCINTRAPERIOD),
-                  OMX_VIDEO_CONFIG_AVCINTRAPERIOD, 
+                  OMX_VIDEO_CONFIG_AVCINTRAPERIOD,
                   pMemoryListHead, dbg);
-    VIDENC_MALLOC(pComponentPrivate->pMotionVector, 
+    VIDENC_MALLOC(pComponentPrivate->pMotionVector,
                   sizeof(OMX_VIDEO_PARAM_MOTIONVECTORTYPE),
-                  OMX_VIDEO_PARAM_MOTIONVECTORTYPE, 
+                  OMX_VIDEO_PARAM_MOTIONVECTORTYPE,
                   pMemoryListHead, dbg);
     VIDENC_MALLOC(pComponentPrivate->pCapabilityFlags,
                   sizeof(PV_OMXComponentCapabilityFlagsType),
@@ -590,7 +607,7 @@
 
 #endif
 
-	pCompPortIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
+    pCompPortIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
 
     /* Set input port defaults */
 
@@ -598,43 +615,42 @@
     OMX_CONF_INIT_STRUCT(pPortDef, OMX_PARAM_PORTDEFINITIONTYPE);
     pPortDef->nPortIndex                         = VIDENC_INPUT_PORT;
     pPortDef->eDir                               = OMX_DirInput;
-    pPortDef->nBufferCountActual                 = VIDENC_NUM_OF_IN_BUFFERS; 
+    pPortDef->nBufferCountActual                 = VIDENC_NUM_OF_IN_BUFFERS;
     pPortDef->nBufferCountMin                    = 1;
     pPortDef->nBufferSize                        = 0;    /* It is calculated below */
     pPortDef->bEnabled                           = OMX_TRUE;
     pPortDef->bPopulated                         = OMX_FALSE;
     pPortDef->eDomain                            = OMX_PortDomainVideo;
     pPortDef->format.video.cMIMEType             = "yuv";
-    pPortDef->format.video.pNativeRender         = NULL; 
+    pPortDef->format.video.pNativeRender         = NULL;
     pPortDef->format.video.nFrameWidth           = 176;
     pPortDef->format.video.nFrameHeight          = 144;
-    pPortDef->format.video.nStride               = -1; 
-    pPortDef->format.video.nSliceHeight          = -1; 
-    pPortDef->format.video.xFramerate            = 15; 
+    pPortDef->format.video.nStride               = -1;
+    pPortDef->format.video.nSliceHeight          = -1;
+    pPortDef->format.video.xFramerate            = fToQ16(15.0);
     pPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
     pPortDef->format.video.eCompressionFormat    = OMX_VIDEO_CodingUnused;
     pPortDef->format.video.eColorFormat          = OMX_COLOR_FormatYUV420Planar;
-    
-    /* Set the default value of the run-time Target Frame Rate to the create-time Frame Rate */
-    pComponentPrivate->nTargetFrameRate = pPortDef->format.video.xFramerate;  
 
-    /* Calculate default input buffer size */
+    /* Set the default value of the run-time Target Frame Rate to the create-time Frame Rate */
+    pComponentPrivate->nTargetFrameRate = Q16Tof(pPortDef->format.video.xFramerate);
+
     CalculateBufferSize(pPortDef, pComponentPrivate);
     pComponentPrivate->nInBufferSize = 0;
 
-    for (i = 0; i < VIDENC_MAX_NUM_OF_IN_BUFFERS; i++) 
+    for (i = 0; i < VIDENC_MAX_NUM_OF_IN_BUFFERS; i++)
     {
-        VIDENC_MALLOC(pCompPortIn->pBufferPrivate[i], 
-                      sizeof(VIDENC_BUFFER_PRIVATE), 
-                      VIDENC_BUFFER_PRIVATE, 
-                      pMemoryListHead, dbg); 
+        VIDENC_MALLOC(pCompPortIn->pBufferPrivate[i],
+                      sizeof(VIDENC_BUFFER_PRIVATE),
+                      VIDENC_BUFFER_PRIVATE,
+                      pMemoryListHead, dbg);
     }
     for (i = 0; i < VIDENC_MAX_NUM_OF_IN_BUFFERS; i++)
     {
         pCompPortIn->pBufferPrivate[i]->pBufferHdr = NULL;
     }
     pCompPortIn->nBufferCnt = 0;
-    
+
     /* Set output port defaults */
     pCompPortOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
     pPortDef = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
@@ -642,87 +658,88 @@
     pPortDef->nPortIndex                         = VIDENC_OUTPUT_PORT;
     pPortDef->eDir                               = OMX_DirOutput;
     pPortDef->nBufferCountActual                 = VIDENC_NUM_OF_OUT_BUFFERS;
-    pPortDef->nBufferCountMin                    = 1; 
+    pPortDef->nBufferCountMin                    = 1;
     pPortDef->nBufferSize                        = 0;  /* It is calculated below */
     pPortDef->bEnabled                           = OMX_TRUE;
     pPortDef->bPopulated                         = OMX_FALSE;
     pPortDef->eDomain                            = OMX_PortDomainVideo;
     pPortDef->format.video.cMIMEType             = "264";
-    pPortDef->format.video.pNativeRender         = NULL; 
+    pPortDef->format.video.pNativeRender         = NULL;
     pPortDef->format.video.nFrameWidth           = 176;
     pPortDef->format.video.nFrameHeight          = 144;
-    pPortDef->format.video.nStride               = -1; 
-    pPortDef->format.video.nSliceHeight          = -1; 
-    pPortDef->format.video.nBitrate              = 64000;  
-    pPortDef->format.video.xFramerate            = (15<<16); 
+    pPortDef->format.video.nStride               = -1;
+    pPortDef->format.video.nSliceHeight          = -1;
+    pPortDef->format.video.xFramerate            = fToQ16(15.0);
     pPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
 
     if (sDynamicFormat != NULL)
     {
         if ( strcmp(sDynamicFormat,  "MPEG4") == 0 )
         {
-
-		pPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
-		}
+            pPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
+            pPortDef->format.video.cMIMEType             = "mp4";
+            pPortDef->format.video.nBitrate              = VIDENC_STRUCT_MPEG4DEFBITRATE[0][1];
+        }
         else if (strcmp(sDynamicFormat,  "H263") == 0 )
         {
-
-		pPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingH263;
-		}
+            pPortDef->format.video.eCompressionFormat  = OMX_VIDEO_CodingH263;
+            pPortDef->format.video.cMIMEType             = "mp4";
+            pPortDef->format.video.nBitrate              = VIDENC_STRUCT_H263DEFBITRATE[0][1];
+        }
         else if (strcmp(sDynamicFormat,  "H264") == 0 )
         {
-		pPortDef->format.video.eCompressionFormat    = OMX_VIDEO_CodingAVC; 
-		}
-		}
+            pPortDef->format.video.eCompressionFormat    = OMX_VIDEO_CodingAVC;
+            pPortDef->format.video.cMIMEType             = "264";
+            pPortDef->format.video.nBitrate              = VIDENC_STRUCT_H264DEFBITRATE[0][1];
+        }
+    }
     else
     {
-		pPortDef->format.video.eCompressionFormat    = OMX_VIDEO_CodingAVC; 
-		}
+        pPortDef->format.video.eCompressionFormat    = OMX_VIDEO_CodingAVC;
+        pPortDef->format.video.cMIMEType             = "264";
+        pPortDef->format.video.nBitrate              = VIDENC_STRUCT_H264DEFBITRATE[0][1];
+    }
 
     pPortDef->format.video.eColorFormat          = OMX_COLOR_FormatUnused;
-    
-    /* Set the default value of the run-time Target Bit Rate to the create-time Bit Rate */
-    pComponentPrivate->nTargetBitRate = pPortDef->format.video.nBitrate;    
 
-    /* Calculate default output buffer size */
     CalculateBufferSize(pPortDef, pComponentPrivate);
     pComponentPrivate->nOutBufferSize = 0;
 
     for (i = 0; i < VIDENC_MAX_NUM_OF_OUT_BUFFERS; i++)
     {
-        VIDENC_MALLOC(pCompPortOut->pBufferPrivate[i], 
-                      sizeof(VIDENC_BUFFER_PRIVATE), 
-                      VIDENC_BUFFER_PRIVATE, 
+        VIDENC_MALLOC(pCompPortOut->pBufferPrivate[i],
+                      sizeof(VIDENC_BUFFER_PRIVATE),
+                      VIDENC_BUFFER_PRIVATE,
                       pMemoryListHead, pComponentPrivate->dbg);
     }
-    for (i = 0; i < VIDENC_MAX_NUM_OF_OUT_BUFFERS; i++) 
+    for (i = 0; i < VIDENC_MAX_NUM_OF_OUT_BUFFERS; i++)
     {
         pCompPortOut->pBufferPrivate[i]->pBufferHdr = NULL;
     }
-		/*allocate MPEG4 metadata structure*/
-		for (i = 0; i < VIDENC_MAX_NUM_OF_OUT_BUFFERS; i++)
-		  {
-			VIDENC_MALLOC(pCompPortOut->pBufferPrivate[i]->pMetaData, 
-						  sizeof(VIDENC_MPEG4_SEGMENTMODE_METADATA), 
-						  VIDENC_MPEG4_SEGMENTMODE_METADATA, 
+    /*allocate MPEG4 metadata structure*/
+    for (i = 0; i < VIDENC_MAX_NUM_OF_OUT_BUFFERS; i++)
+    {
+        VIDENC_MALLOC(pCompPortOut->pBufferPrivate[i]->pMetaData,
+                      sizeof(VIDENC_MPEG4_SEGMENTMODE_METADATA),
+                      VIDENC_MPEG4_SEGMENTMODE_METADATA,
                       pMemoryListHead, pComponentPrivate->dbg);
-		  }
-	
-		/*segment mode defaults*/
-		pComponentPrivate->bMVDataEnable=OMX_FALSE;
-		pComponentPrivate->bResyncDataEnable=OMX_FALSE; 
-	pCompPortOut->nBufferCnt = 0;
-    
+    }
+
+    /*segment mode defaults*/
+    pComponentPrivate->bMVDataEnable=OMX_FALSE;
+    pComponentPrivate->bResyncDataEnable=OMX_FALSE;
+    pCompPortOut->nBufferCnt = 0;
+
     /* Set input port format defaults */
-    pPortFormat = pCompPortIn->pPortFormat; 
+    pPortFormat = pCompPortIn->pPortFormat;
     OMX_CONF_INIT_STRUCT(pPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);
     pPortFormat->nPortIndex         = VIDENC_INPUT_PORT;
     pPortFormat->nIndex             = 0x0;
-    pPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused; 
+    pPortFormat->eCompressionFormat = OMX_VIDEO_CodingUnused;
     pPortFormat->eColorFormat       = OMX_COLOR_FormatYUV420Planar;
 
     /* Set output port format defaults */
-    pPortFormat = pCompPortOut->pPortFormat; 
+    pPortFormat = pCompPortOut->pPortFormat;
     OMX_CONF_INIT_STRUCT(pPortFormat, OMX_VIDEO_PARAM_PORTFORMATTYPE);
     pPortFormat->nPortIndex         = VIDENC_OUTPUT_PORT;
     pPortFormat->nIndex             = 0x0;
@@ -744,9 +761,8 @@
     }
     else
     {
-    pPortFormat->eCompressionFormat = OMX_VIDEO_CodingAVC;
-		}
-
+        pPortFormat->eCompressionFormat = OMX_VIDEO_CodingAVC;
+    }
 
     pPortFormat->eColorFormat       = OMX_COLOR_FormatUnused;
 
@@ -754,7 +770,7 @@
     pPriorityMgmt = pComponentPrivate->pPriorityMgmt;
     OMX_CONF_INIT_STRUCT(pPriorityMgmt, OMX_PRIORITYMGMTTYPE);
     pPriorityMgmt->nGroupPriority   = -1;
-    pPriorityMgmt->nGroupID         = -1; 
+    pPriorityMgmt->nGroupID         = -1;
 
     /* Buffer supplier setting */
     pCompPortIn->eSupplierSetting = OMX_BufferSupplyOutput;
@@ -769,28 +785,28 @@
     pComponentPrivate->pH264->nRefFrames                = 1; /*-1;  */
     pComponentPrivate->pH264->nRefIdx10ActiveMinus1     = -1;
     pComponentPrivate->pH264->nRefIdx11ActiveMinus1     = -1;
-    pComponentPrivate->pH264->bEnableUEP                = OMX_FALSE;  
-    pComponentPrivate->pH264->bEnableFMO                = OMX_FALSE;  
-    pComponentPrivate->pH264->bEnableASO                = OMX_FALSE;  
-    pComponentPrivate->pH264->bEnableRS                 = OMX_FALSE;   
+    pComponentPrivate->pH264->bEnableUEP                = OMX_FALSE;
+    pComponentPrivate->pH264->bEnableFMO                = OMX_FALSE;
+    pComponentPrivate->pH264->bEnableASO                = OMX_FALSE;
+    pComponentPrivate->pH264->bEnableRS                 = OMX_FALSE;
     pComponentPrivate->pH264->eProfile                  = OMX_VIDEO_AVCProfileBaseline; /*0x01;*/
-    pComponentPrivate->pH264->eLevel                    = OMX_VIDEO_AVCLevel1; /*OMX_VIDEO_AVCLevel11; */
-    pComponentPrivate->pH264->nAllowedPictureTypes      = -1;  
+    pComponentPrivate->pH264->eLevel                    = OMX_VIDEO_AVCLevel1; /*OMX_VIDEO_AVCLevel11;*/
+    pComponentPrivate->pH264->nAllowedPictureTypes      = -1;
     pComponentPrivate->pH264->bFrameMBsOnly             = OMX_FALSE;
-    pComponentPrivate->pH264->bMBAFF                    = OMX_FALSE;               
-    pComponentPrivate->pH264->bEntropyCodingCABAC       = OMX_FALSE;  
-    pComponentPrivate->pH264->bWeightedPPrediction      = OMX_FALSE; 
-    pComponentPrivate->pH264->nWeightedBipredicitonMode = -1; 
+    pComponentPrivate->pH264->bMBAFF                    = OMX_FALSE;
+    pComponentPrivate->pH264->bEntropyCodingCABAC       = OMX_FALSE;
+    pComponentPrivate->pH264->bWeightedPPrediction      = OMX_FALSE;
+    pComponentPrivate->pH264->nWeightedBipredicitonMode = -1;
     pComponentPrivate->pH264->bconstIpred               = OMX_FALSE;
-    pComponentPrivate->pH264->bDirect8x8Inference       = OMX_FALSE;  
+    pComponentPrivate->pH264->bDirect8x8Inference       = OMX_FALSE;
     pComponentPrivate->pH264->bDirectSpatialTemporal    = OMX_FALSE;
     pComponentPrivate->pH264->nCabacInitIdc             = -1;
-    pComponentPrivate->pH264->eLoopFilterMode           = 1; 
-	/*other h264 defaults*/
-	pComponentPrivate->intra4x4EnableIdc                = INTRA4x4_IPSLICES;
-	pComponentPrivate->maxMVperMB                       = 4;
-	pComponentPrivate->nEncodingPreset	                = 3;/*0:DEFAULT/ 1:HIGH QUALITY/ 2:HIGH SPEED/ 3:USER DEFINED*/
-   pComponentPrivate->AVCNALFormat						= VIDENC_AVC_NAL_SLICE;/*VIDENC_AVC_NAL_UNIT;*/
+    pComponentPrivate->pH264->eLoopFilterMode           = 1;
+    /*other h264 defaults*/
+    pComponentPrivate->intra4x4EnableIdc                = INTRA4x4_IPSLICES;
+    pComponentPrivate->maxMVperMB                       = 4;
+    pComponentPrivate->nEncodingPreset                  = 3;/*0:DEFAULT/ 1:HIGH QUALITY/ 2:HIGH SPEED/ 3:USER DEFINED*/
+    pComponentPrivate->AVCNALFormat                      = VIDENC_AVC_NAL_SLICE;/*VIDENC_AVC_NAL_UNIT;*/
     /* Set pMpeg4 defaults */
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pMpeg4, OMX_VIDEO_PARAM_MPEG4TYPE);
     pComponentPrivate->pMpeg4->nPortIndex           = VIDENC_OUTPUT_PORT;
@@ -828,25 +844,25 @@
 
     /* Set pVidParamBitrate and intraRefreshType defaults */
     OMX_CONF_INIT_STRUCT(pCompPortOut->pErrorCorrectionType, OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE);
-	OMX_CONF_INIT_STRUCT(pCompPortOut->pIntraRefreshType, OMX_VIDEO_PARAM_INTRAREFRESHTYPE);
+    OMX_CONF_INIT_STRUCT(pCompPortOut->pIntraRefreshType, OMX_VIDEO_PARAM_INTRAREFRESHTYPE);
     pCompPortOut->pErrorCorrectionType->nPortIndex= VIDENC_OUTPUT_PORT;
-	pCompPortOut->pIntraRefreshType->nPortIndex= VIDENC_OUTPUT_PORT;
-	/*initDSP params*/
-	/*Error resilience tools used by MPEG4/H263 encoder*/
-	pCompPortOut->pErrorCorrectionType->bEnableHEC= OMX_TRUE;/*shouldn't be 0?*/
-	pCompPortOut->pErrorCorrectionType->bEnableResync = OMX_TRUE;/*shouldn't be 0?*/
-	pCompPortOut->pErrorCorrectionType->bEnableDataPartitioning= OMX_FALSE;
-	pCompPortOut->pErrorCorrectionType->bEnableRVLC= OMX_FALSE;
-	pCompPortOut->pErrorCorrectionType->nResynchMarkerSpacing = 1024;
+    pCompPortOut->pIntraRefreshType->nPortIndex= VIDENC_OUTPUT_PORT;
+    /*initDSP params*/
+    /*Error resilience tools used by MPEG4/H263 encoder*/
+    pCompPortOut->pErrorCorrectionType->bEnableHEC= OMX_TRUE;/*shouldn't be 0?*/
+    pCompPortOut->pErrorCorrectionType->bEnableResync = OMX_TRUE;/*shouldn't be 0?*/
+    pCompPortOut->pErrorCorrectionType->bEnableDataPartitioning= OMX_FALSE;
+    pCompPortOut->pErrorCorrectionType->bEnableRVLC= OMX_FALSE;
+    pCompPortOut->pErrorCorrectionType->nResynchMarkerSpacing = 1024;
 
-	pCompPortOut->pIntraRefreshType->nAirRef = 10;
+    pCompPortOut->pIntraRefreshType->nAirRef = 10;
     /* Set pVidParamBitrate defaults */
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pVidParamBitrate, OMX_VIDEO_PARAM_BITRATETYPE);
     pComponentPrivate->pVidParamBitrate->nPortIndex     = VIDENC_OUTPUT_PORT;
     pComponentPrivate->pVidParamBitrate->eControlRate   = OMX_Video_ControlRateConstant; 
     pComponentPrivate->pVidParamBitrate->nTargetBitrate = 64000;
-	/**/
-	pComponentPrivate->nMIRRate=0;
+    /**/
+    pComponentPrivate->nMIRRate=0;
     /* Set pQuantization defaults */
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pQuantization, OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
     pComponentPrivate->pQuantization->nPortIndex = VIDENC_OUTPUT_PORT;
@@ -861,7 +877,7 @@
     pComponentPrivate->pMotionVector->bUnrestrictedMVs = 0;   /* unused */
     pComponentPrivate->pMotionVector->eAccuracy  = OMX_Video_MotionVectorQuarterPel;
     pComponentPrivate->pMotionVector->sXSearchRange = pComponentPrivate->pMotionVector->sXSearchRange = 64;
-    
+
     /* Set pIntraPeriod defaults */
     OMX_CONF_INIT_STRUCT(pComponentPrivate->pH264IntraPeriod, OMX_VIDEO_CONFIG_AVCINTRAPERIOD);
     pComponentPrivate->pH264IntraPeriod->nPortIndex = VIDENC_OUTPUT_PORT;
@@ -869,43 +885,52 @@
     pComponentPrivate->pH264IntraPeriod->nPFrames = 30;
 
 #ifdef __KHRONOS_CONF_1_1__
-	OMX_CONF_INIT_STRUCT(pCompPortIn->pProfileType, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
-	pCompPortIn->pProfileType->nPortIndex = VIDENC_INPUT_PORT;
-	pCompPortIn->pProfileType->eLevel = OMX_VIDEO_AVCLevel1;
-	pCompPortIn->pProfileType->eProfile = OMX_VIDEO_AVCProfileBaseline;
-	pCompPortIn->pProfileType->nProfileIndex = 0;
+    OMX_CONF_INIT_STRUCT(pCompPortIn->pProfileType, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
+    pCompPortIn->pProfileType->nPortIndex = VIDENC_INPUT_PORT;
+    pCompPortIn->pProfileType->eLevel = OMX_VIDEO_AVCLevel1;
+    pCompPortIn->pProfileType->eProfile = OMX_VIDEO_AVCProfileBaseline;
+    pCompPortIn->pProfileType->nProfileIndex = 0;
 
-	OMX_CONF_INIT_STRUCT(pCompPortOut->pProfileType, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
-	pCompPortOut->pProfileType->nPortIndex = VIDENC_OUTPUT_PORT;
-	pCompPortOut->pProfileType->eLevel = OMX_VIDEO_AVCLevel1;
-	pCompPortOut->pProfileType->eProfile = OMX_VIDEO_AVCProfileBaseline;
-	pCompPortOut->pProfileType->nProfileIndex = 0;
-	OMX_CONF_INIT_STRUCT(pCompPortIn->pFrameRateConfig, OMX_CONFIG_FRAMERATETYPE);
-	pCompPortIn->pFrameRateConfig->nPortIndex = VIDENC_INPUT_PORT;
-	pCompPortIn->pFrameRateConfig->xEncodeFramerate = 0;
+    OMX_CONF_INIT_STRUCT(pCompPortOut->pProfileType, OMX_VIDEO_PARAM_PROFILELEVELTYPE);
+    pCompPortOut->pProfileType->nPortIndex = VIDENC_OUTPUT_PORT;
+    pCompPortOut->pProfileType->eLevel = OMX_VIDEO_AVCLevel1;
+    pCompPortOut->pProfileType->eProfile = OMX_VIDEO_AVCProfileBaseline;
+    pCompPortOut->pProfileType->nProfileIndex = 0;
+    OMX_CONF_INIT_STRUCT(pCompPortIn->pFrameRateConfig, OMX_CONFIG_FRAMERATETYPE);
+    pCompPortIn->pFrameRateConfig->nPortIndex = VIDENC_INPUT_PORT;
+    pCompPortIn->pFrameRateConfig->xEncodeFramerate = 0;
 
-	OMX_CONF_INIT_STRUCT(pCompPortOut->pFrameRateConfig, OMX_CONFIG_FRAMERATETYPE);
-	pCompPortOut->pFrameRateConfig->nPortIndex = VIDENC_OUTPUT_PORT;
-	pCompPortOut->pFrameRateConfig->xEncodeFramerate = (15<<16);
+    OMX_CONF_INIT_STRUCT(pCompPortOut->pFrameRateConfig, OMX_CONFIG_FRAMERATETYPE);
+    pCompPortOut->pFrameRateConfig->nPortIndex = VIDENC_OUTPUT_PORT;
+    pCompPortOut->pFrameRateConfig->xEncodeFramerate = (15<<16);
 
-	OMX_CONF_INIT_STRUCT(pCompPortIn->pBitRateTypeConfig, OMX_VIDEO_CONFIG_BITRATETYPE);
-	pCompPortIn->pBitRateTypeConfig->nPortIndex = VIDENC_INPUT_PORT;
-	pCompPortIn->pBitRateTypeConfig->nEncodeBitrate = 0;
+    OMX_CONF_INIT_STRUCT(pCompPortIn->pBitRateTypeConfig, OMX_VIDEO_CONFIG_BITRATETYPE);
+    pCompPortIn->pBitRateTypeConfig->nPortIndex = VIDENC_INPUT_PORT;
+    pCompPortIn->pBitRateTypeConfig->nEncodeBitrate = 0;
 
-	OMX_CONF_INIT_STRUCT(pCompPortOut->pBitRateTypeConfig, OMX_VIDEO_CONFIG_BITRATETYPE);
-	pCompPortOut->pBitRateTypeConfig->nPortIndex = VIDENC_OUTPUT_PORT;
-	pCompPortOut->pBitRateTypeConfig->nEncodeBitrate = 64000;
+    OMX_CONF_INIT_STRUCT(pCompPortOut->pBitRateTypeConfig, OMX_VIDEO_CONFIG_BITRATETYPE);
+    pCompPortOut->pBitRateTypeConfig->nPortIndex = VIDENC_OUTPUT_PORT;
+    if(pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4)
+    {
+        pCompPortOut->pBitRateTypeConfig->nEncodeBitrate = VIDENC_STRUCT_MPEG4DEFBITRATE[0][1];
+    }
+    else if(pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
+        pCompPortOut->pBitRateTypeConfig->nEncodeBitrate = VIDENC_STRUCT_H263DEFBITRATE[0][1];
+    }
+    else {
+        pCompPortOut->pBitRateTypeConfig->nEncodeBitrate = VIDENC_STRUCT_H264DEFBITRATE[0][1];
+    }
 
 #endif
-	OMX_CONF_INIT_STRUCT(pCompPortIn->pBitRateType, OMX_VIDEO_PARAM_BITRATETYPE);
-	pCompPortIn->pBitRateType->nPortIndex = VIDENC_INPUT_PORT;
-	pCompPortIn->pBitRateType->eControlRate = OMX_Video_ControlRateDisable;
-	pCompPortIn->pBitRateType->nTargetBitrate = 64000;
+    OMX_CONF_INIT_STRUCT(pCompPortIn->pBitRateType, OMX_VIDEO_PARAM_BITRATETYPE);
+    pCompPortIn->pBitRateType->nPortIndex = VIDENC_INPUT_PORT;
+    pCompPortIn->pBitRateType->eControlRate = OMX_Video_ControlRateDisable;
+    pCompPortIn->pBitRateType->nTargetBitrate = 0;
 
-	OMX_CONF_INIT_STRUCT(pCompPortOut->pBitRateType, OMX_VIDEO_PARAM_BITRATETYPE);
-	pCompPortOut->pBitRateType->nPortIndex = VIDENC_OUTPUT_PORT;
-	pCompPortOut->pBitRateType->eControlRate = OMX_Video_ControlRateConstant;
-	pCompPortOut->pBitRateType->nTargetBitrate = 64000;
+    OMX_CONF_INIT_STRUCT(pCompPortOut->pBitRateType, OMX_VIDEO_PARAM_BITRATETYPE);
+    pCompPortOut->pBitRateType->nPortIndex = VIDENC_OUTPUT_PORT;
+    pCompPortOut->pBitRateType->eControlRate = OMX_Video_ControlRateConstant;
+    pCompPortOut->pBitRateType->nTargetBitrate = pCompPortOut->pBitRateTypeConfig->nEncodeBitrate;
 
     /*set the capability Flags needed by Opencore*/
     pComponentPrivate->pCapabilityFlags->iIsOMXComponentMultiThreaded=OMX_TRUE;
@@ -915,14 +940,14 @@
     pComponentPrivate->pCapabilityFlags->iOMXComponentSupportsMovableInputBuffers=OMX_TRUE;
     pComponentPrivate->pCapabilityFlags->iOMXComponentSupportsPartialFrames=OMX_FALSE;
     pComponentPrivate->pCapabilityFlags->iOMXComponentUsesFullAVCFrames=OMX_FALSE;
-    pComponentPrivate->pCapabilityFlags->iOMXComponentUsesNALStartCode=OMX_FALSE; 
+    pComponentPrivate->pCapabilityFlags->iOMXComponentUsesNALStartCode=OMX_FALSE;
 
 #ifndef UNDER_CE
     /* Initialize Mutex for Buffer Tracking */
     pthread_mutex_init(&(pComponentPrivate->mVideoEncodeBufferMutex), NULL);
 #else
     /* Add WinCE critical section API */
-#endif 
+#endif
 
     /* create the pipe used to maintain free input buffers*/
     eError = pipe(pComponentPrivate->nFree_oPipe);
@@ -935,7 +960,7 @@
     eError = pipe(pComponentPrivate->nFilled_iPipe);
     if (eError)
     {
-        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources); 
+        OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
 
     /* create the pipe used to send commands to the thread */
@@ -944,17 +969,17 @@
     {
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
-    
+
     /* create the pipe used to send commands to the thread */
     eError = pipe(pComponentPrivate->nCmdDataPipe);
     if (eError)
     {
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
-      
+
 #ifdef RESOURCE_MANAGER_ENABLED
     /* Initialize Resource Manager */
-    eError = RMProxy_NewInitalizeEx(OMX_COMPONENTTYPE_VIDEO); 
+    eError = RMProxy_NewInitalizeEx(OMX_COMPONENTTYPE_VIDEO);
     if (eError != OMX_ErrorNone)
     {
         OMX_PRMGR4(dbg, "Error returned from loading ResourceManagerProxy thread...\n");
@@ -976,7 +1001,7 @@
     {
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
     }
-#else 
+#else
     if (nError || !(pComponentPrivate->ComponentThread))
     {
         OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorInsufficientResources);
@@ -988,27 +1013,26 @@
                        PERF_FOURCC('V','E',' ','T'));
 #endif
 #ifndef UNDER_CE
-/*    pthread_mutex_init(&pComponentPrivate->videoe_mutex_app, NULL);*/
+    /*pthread_mutex_init(&pComponentPrivate->videoe_mutex_app, NULL);*/
     pthread_mutex_init(&pComponentPrivate->videoe_mutex, NULL);
     pthread_cond_init (&pComponentPrivate->populate_cond, NULL);
     pthread_mutex_init(&pComponentPrivate->videoe_mutex_app, NULL);
     pthread_cond_init (&pComponentPrivate->unpopulate_cond, NULL);
-	pthread_cond_init (&pComponentPrivate->flush_cond, NULL);
-	pthread_cond_init (&pComponentPrivate->stop_cond, NULL);
-	
+    pthread_cond_init (&pComponentPrivate->flush_cond, NULL);
+    pthread_cond_init (&pComponentPrivate->stop_cond, NULL);
+
 #else
     OMX_CreateEvent(&(pComponentPrivate->InLoaded_event));
     OMX_CreateEvent(&(pComponentPrivate->InIdle_event));
 #endif
 
-	if(pthread_mutex_init(&pComponentPrivate->mutexStateChangeRequest, NULL)) {
-	   return OMX_ErrorUndefined;
-	}
+    if(pthread_mutex_init(&pComponentPrivate->mutexStateChangeRequest, NULL)) {
+       return OMX_ErrorUndefined;
+    }
 
-	if(pthread_cond_init (&pComponentPrivate->StateChangeCondition, NULL)) {
-	   return OMX_ErrorUndefined;
-	}
-
+    if(pthread_cond_init (&pComponentPrivate->StateChangeCondition, NULL)) {
+       return OMX_ErrorUndefined;
+    }
 OMX_CONF_CMD_BAIL:
     OMX_PRINT2(dbg, "Component Init Exit\n");
     return eError;
@@ -1018,12 +1042,12 @@
 /**
   *  SetCallbacks() Sets application callbacks to the component
   *
-  * This method will update application callbacks 
+  * This method will update application callbacks
   * the application.
   *
   * @param pComp         handle for this instance of the component
   * @param pCallBacks    application callbacks
-  * @param ptr           
+  * @param ptr
   *
   * @retval OMX_NoError              Success, ready to roll
   *         OMX_Error_BadParameter   The input parameter pointer is null
@@ -1038,11 +1062,11 @@
     OMX_COMPONENTTYPE* pHandle                  = NULL;
     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     OMX_U32* pTmp                               = NULL;
-    
+
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     OMX_CONF_CHECK_CMD(pComponentPrivate, 1, 1);
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pCallBacks, 1, 1);
-    
+
     /*Copy the callbacks of the application to the component private */
     pTmp = memcpy (&(pComponentPrivate->sCbData), pCallBacks, sizeof(OMX_CALLBACKTYPE));
     if (pTmp == NULL)
@@ -1050,7 +1074,7 @@
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUndefined, pComponentPrivate->dbg,
                                OMX_TRACE4, "Failed to copy callbacks.\n");
     }
-    
+
     /*copy the application private data to component memory*/
     pHandle = (OMX_COMPONENTTYPE*)hComponent;
     pHandle->pApplicationPrivate = pAppData;
@@ -1076,10 +1100,10 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp, 
+static OMX_ERRORTYPE GetComponentVersion (OMX_HANDLETYPE hComp,
                                           OMX_STRING  szComponentName,
-                                          OMX_VERSIONTYPE* pComponentVersion, 
-                                          OMX_VERSIONTYPE* pSpecVersion, 
+                                          OMX_VERSIONTYPE* pComponentVersion,
+                                          OMX_VERSIONTYPE* pSpecVersion,
                                           OMX_UUIDTYPE* pComponentUUID)
 {
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
@@ -1089,7 +1113,7 @@
     OMX_CONF_CHECK_CMD(hComp, ((OMX_COMPONENTTYPE *) hComp)->pComponentPrivate, 1);
     pHandle = (OMX_COMPONENTTYPE*)hComp;
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
-    
+
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, szComponentName, pComponentVersion, pSpecVersion);
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pComponentUUID, 1, 1);
 
@@ -1099,13 +1123,13 @@
                                pComponentPrivate->dbg, OMX_PRSTATE3,
                                "Component is in invalid state.\n");
     }
-                              
+
     strcpy(szComponentName, pComponentPrivate->cComponentName);
     memcpy(pComponentVersion,
            &(pComponentPrivate->ComponentVersion.s),
            sizeof(pComponentPrivate->ComponentVersion.s));
     memcpy(pSpecVersion,
-           &(pComponentPrivate->SpecVersion.s), 
+           &(pComponentPrivate->SpecVersion.s),
            sizeof(pComponentPrivate->SpecVersion.s));
 
 OMX_CONF_CMD_BAIL:
@@ -1128,17 +1152,17 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE SendCommand (OMX_IN OMX_HANDLETYPE hComponent, 
-                                  OMX_IN OMX_COMMANDTYPE Cmd, 
+static OMX_ERRORTYPE SendCommand (OMX_IN OMX_HANDLETYPE hComponent,
+                                  OMX_IN OMX_COMMANDTYPE Cmd,
                                   OMX_IN OMX_U32 nParam1,
-                                  OMX_IN OMX_PTR pCmdData) 
+                                  OMX_IN OMX_PTR pCmdData)
 {
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
     int nRet                                    = 0;
     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     char* szCommandType                         = NULL;
     char* szParam                               = NULL;
-    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn    = NULL; 
+    OMX_PARAM_PORTDEFINITIONTYPE* pPortDefIn    = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut   = NULL;
     VIDENC_NODE* pMemoryListHead                = NULL;
 
@@ -1149,14 +1173,14 @@
     {
         OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pCmdData, 1, 1);
     }
-        
+
     if (pComponentPrivate->eState == OMX_StateInvalid)
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
                                pComponentPrivate->dbg, OMX_PRSTATE3,
                                "Component is in invalid state.\n");
     }
-    
+
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -1166,18 +1190,20 @@
                         PERF_ModuleComponent);
 #endif
 
-    switch (Cmd) 
+    switch (Cmd)
     {
         case OMX_CommandStateSet:
             /* Add a pending transition */
             if(AddStateTransition(pComponentPrivate) != OMX_ErrorNone) {
                return OMX_ErrorUndefined;
-	     }
+           }
 
-#ifdef __KHRONOS_CONF__        
-            if(nParam1 == OMX_StateLoaded && pComponentPrivate->eState == OMX_StateIdle) {
+#ifdef __KHRONOS_CONF__
+            if(nParam1 == OMX_StateLoaded &&
+               pComponentPrivate->eState == OMX_StateIdle)
+            {
                 pComponentPrivate->bPassingIdleToLoaded = OMX_TRUE;
-            }    
+            }
 #endif
         OMX_PRCOMM2(pComponentPrivate->dbg, "Write to cmd pipe!\n");
             nRet = write(pComponentPrivate->nCmdPipe[1], &Cmd, sizeof(Cmd));
@@ -1187,8 +1213,8 @@
                      return OMX_ErrorUndefined;
                  }
             }
-            nRet = write(pComponentPrivate->nCmdDataPipe[1], 
-                         &nParam1, 
+            nRet = write(pComponentPrivate->nCmdDataPipe[1],
+                         &nParam1,
                          sizeof(nParam1));
             if (nRet == -1) {
                  /* Decrement reference count without generating any signal */
@@ -1198,7 +1224,7 @@
             }
             break;
         case OMX_CommandFlush:
-            if (nParam1 > 1 && nParam1 != -1)
+            if (nParam1 > 1 && nParam1 != (OMX_U32)-1)
             {
             OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadPortIndex,
                                    pComponentPrivate->dbg, OMX_PRBUFFER4,
@@ -1212,7 +1238,7 @@
                                    "Failed to write to cmd pipe.\n");
             }
             nRet = write(pComponentPrivate->nCmdDataPipe[1],
-                       &nParam1, 
+                       &nParam1,
                        sizeof(nParam1));
             if (nRet == -1)
             {
@@ -1226,28 +1252,28 @@
             pPortDefIn = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
             pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
 
-            if (nParam1 == VIDENC_INPUT_PORT || 
-                nParam1 == VIDENC_OUTPUT_PORT || 
-                nParam1 == -1)
+            if (nParam1 == VIDENC_INPUT_PORT ||
+                nParam1 == VIDENC_OUTPUT_PORT ||
+                nParam1 == (OMX_U32)-1)
             {
-                if (nParam1 == VIDENC_INPUT_PORT || nParam1 == -1)
+                if (nParam1 == VIDENC_INPUT_PORT || nParam1 == (OMX_U32)-1)
                 {
 
                     pPortDefIn->bEnabled = OMX_FALSE;
                 }
-                if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == -1)
+                if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == (OMX_U32)-1)
                 {
 
                     pPortDefOut->bEnabled = OMX_FALSE;
                 }
-            }          
-            else 
+            }
+            else
             {
             OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter,
                                    pComponentPrivate->dbg, OMX_PRBUFFER4,
                                    "Invalid port disable nParam1 (%lu).\n", nParam1);
             }
-          
+
             nRet = write(pComponentPrivate->nCmdPipe[1], &Cmd, sizeof(Cmd));
             if (nRet == -1)
             {
@@ -1255,10 +1281,10 @@
                                    pComponentPrivate->dbg, OMX_PRCOMM4,
                                    "Failed to write to cmd pipe.\n");
             }
-            nRet = write(pComponentPrivate->nCmdDataPipe[1], 
-                         &nParam1, 
+            nRet = write(pComponentPrivate->nCmdDataPipe[1],
+                         &nParam1,
                          sizeof(nParam1));
-            if (nRet == -1) 
+            if (nRet == -1)
             {
             OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                    pComponentPrivate->dbg, OMX_PRCOMM4,
@@ -1271,13 +1297,13 @@
 
             if (nParam1 == VIDENC_INPUT_PORT ||
                 nParam1 == VIDENC_OUTPUT_PORT ||
-                nParam1 == -1)
+                nParam1 == (OMX_U32)-1)
             {
-                if (nParam1 == VIDENC_INPUT_PORT || nParam1 == -1)
+                if (nParam1 == VIDENC_INPUT_PORT || nParam1 == (OMX_U32)-1)
                 {
                     pPortDefIn->bEnabled = OMX_TRUE;
                 }
-                if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == -1)
+                if (nParam1 == VIDENC_OUTPUT_PORT || nParam1 == (OMX_U32)-1)
                 {
                     pPortDefOut->bEnabled = OMX_TRUE;
                 }
@@ -1297,7 +1323,7 @@
                                    "Failed to write to cmd pipe.\n");
             }
             nRet = write(pComponentPrivate->nCmdDataPipe[1],
-                         &nParam1, 
+                         &nParam1,
                          sizeof(nParam1));
             if (nRet == -1)
             {
@@ -1309,9 +1335,9 @@
         case OMX_CommandMarkBuffer:
             if (nParam1 > 0)
             {
-            OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter,
+            OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadPortIndex,
                                    pComponentPrivate->dbg, OMX_PRBUFFER4,
-                                   "Invalid mark nParam1 (%lu).\n", nParam1);
+                                   "Invalid port number (%lu).\n", nParam1);
             }
             nRet = write(pComponentPrivate->nCmdPipe[1], &Cmd, sizeof(Cmd));
             if (nRet == -1)
@@ -1320,7 +1346,7 @@
                                    pComponentPrivate->dbg, OMX_PRCOMM4,
                                    "Failed to write to cmd pipe.\n");
             }
-            nRet = write(pComponentPrivate->nCmdDataPipe[1], 
+            nRet = write(pComponentPrivate->nCmdDataPipe[1],
                          &pCmdData,
                          sizeof(pCmdData));
             if (nRet == -1)
@@ -1341,11 +1367,11 @@
     OMX_CONVERT_CMD(szCommandType, Cmd);
     if (Cmd == OMX_CommandStateSet)
     {
-        OMX_CONVERT_STATE(szParam, nParam1);  
+        OMX_CONVERT_STATE(szParam, nParam1);
         OMX_PRSTATE2(pComponentPrivate->dbg, "%s -> %s\n", szCommandType, szParam);
     }
 
-OMX_CONF_CMD_BAIL:  
+OMX_CONF_CMD_BAIL:
     return eError;
 }
 
@@ -1366,7 +1392,7 @@
 /*----------------------------------------------------------------------------*/
 
 static OMX_ERRORTYPE GetParameter (OMX_IN OMX_HANDLETYPE hComponent,
-                                   OMX_IN OMX_INDEXTYPE nParamIndex, 
+                                   OMX_IN OMX_INDEXTYPE nParamIndex,
                                    OMX_INOUT OMX_PTR ComponentParameterStructure)
 {
     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
@@ -1386,10 +1412,10 @@
                                pComponentPrivate->dbg, OMX_PRSTATE3,
                                "Component is in invalid state.\n");
     }
-    
+
     pCompPortIn     = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
     pCompPortOut    = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
-    
+
     switch (nParamIndex)
     {
         case OMX_IndexParamVideoInit:
@@ -1444,12 +1470,12 @@
 #endif
 
         case OMX_IndexParamPortDefinition:
-		{
-            if (((OMX_PARAM_PORTDEFINITIONTYPE*)(ComponentParameterStructure))->nPortIndex == 
-                pCompPortIn->pPortDef->nPortIndex)
+        {
+            OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE*)(ComponentParameterStructure);
+            if (pPortDef->nPortIndex == pCompPortIn->pPortDef->nPortIndex)
             {
-                pTmp = memcpy(ComponentParameterStructure, 
-                              pCompPortIn->pPortDef, 
+                pTmp = memcpy(ComponentParameterStructure,
+                              pCompPortIn->pPortDef,
                               sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
                 if (pTmp == NULL)
                 {
@@ -1458,11 +1484,10 @@
                                            "Failed to copy parameter.\n");
                 }
             }
-            else if (((OMX_PARAM_PORTDEFINITIONTYPE*)(ComponentParameterStructure))->nPortIndex == 
-                pCompPortOut->pPortDef->nPortIndex)
+            else if (pPortDef->nPortIndex == pCompPortOut->pPortDef->nPortIndex)
             {
-                pTmp = memcpy(ComponentParameterStructure, 
-                              pCompPortOut->pPortDef, 
+                pTmp = memcpy(ComponentParameterStructure,
+                              pCompPortOut->pPortDef,
                               sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
                 if (pTmp == NULL)
                 {
@@ -1476,9 +1501,9 @@
                 eError = OMX_ErrorBadPortIndex;
             }
             break;
-        	}
+            }
         case OMX_IndexParamVideoPortFormat:
-            if (((OMX_VIDEO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nPortIndex == 
+            if (((OMX_VIDEO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nPortIndex ==
                 pCompPortIn->pPortFormat->nPortIndex)
         {
                 if (((OMX_VIDEO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nIndex < 3)
@@ -1487,14 +1512,14 @@
                     pComponentPrivate->colorFormats[((OMX_VIDEO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nIndex];
                     eError = OMX_ErrorNone;
                 }
-                else 
+                else
                 {
                     OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorNoMore,
                                            pComponentPrivate->dbg, OMX_TRACE4,
                                            "No such index.\n");
                 }
             }
-            else if (((OMX_VIDEO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nPortIndex == 
+            else if (((OMX_VIDEO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nPortIndex ==
                      pCompPortOut->pPortFormat->nPortIndex)
             {
                 if (((OMX_VIDEO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nIndex < 3)
@@ -1503,20 +1528,20 @@
                     pComponentPrivate->compressionFormats[((OMX_VIDEO_PARAM_PORTFORMATTYPE*)(ComponentParameterStructure))->nIndex];
                     eError = OMX_ErrorNone;
                 }
-                else 
+                else
                 {
                     /*OMX_TRACE("OMX_IndexParamVideoPortFormat OMX_ErrorNoMore, no such index\n");*/
                     OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorNoMore);
                 }
             }
-            else 
+            else
         {
                 eError = OMX_ErrorBadPortIndex;
             }
             break;
         case OMX_IndexParamPriorityMgmt:
-            pTmp = memcpy(ComponentParameterStructure, 
-                          pComponentPrivate->pPriorityMgmt, 
+            pTmp = memcpy(ComponentParameterStructure,
+                          pComponentPrivate->pPriorityMgmt,
                           sizeof(OMX_PRIORITYMGMTTYPE));
             if (pTmp == NULL)
             {
@@ -1526,11 +1551,11 @@
             }
             break;
         case OMX_IndexParamVideoAvc:
-            if (((OMX_VIDEO_PARAM_AVCTYPE*)(ComponentParameterStructure))->nPortIndex == 
+            if (((OMX_VIDEO_PARAM_AVCTYPE*)(ComponentParameterStructure))->nPortIndex ==
                 pComponentPrivate->pH264->nPortIndex)
             {
-                pTmp = memcpy(ComponentParameterStructure, 
-                              pComponentPrivate->pH264, 
+                pTmp = memcpy(ComponentParameterStructure,
+                              pComponentPrivate->pH264,
                               sizeof(OMX_VIDEO_PARAM_AVCTYPE));
                 if (pTmp == NULL)
                 {
@@ -1545,10 +1570,10 @@
             }
             break;
         case OMX_IndexParamVideoMpeg4:
-            if (((OMX_VIDEO_PARAM_MPEG4TYPE*)(ComponentParameterStructure))->nPortIndex == 
+            if (((OMX_VIDEO_PARAM_MPEG4TYPE*)(ComponentParameterStructure))->nPortIndex ==
                 pComponentPrivate->pMpeg4->nPortIndex)
             {
-                pTmp = memcpy(ComponentParameterStructure, 
+                pTmp = memcpy(ComponentParameterStructure,
                               pComponentPrivate->pMpeg4,
                               sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
                 if (pTmp == NULL)
@@ -1575,20 +1600,20 @@
                 pBuffSupplierParam->eBufferSupplier = pCompPortOut->eSupplierSetting;
             }
             else
-            { 
+            {
                 eError = OMX_ErrorBadPortIndex;
             }
             break;
         }
 
         case OMX_IndexParamVideoBitrate:
-            if (((OMX_VIDEO_PARAM_BITRATETYPE*)(ComponentParameterStructure))->nPortIndex == 
-                pComponentPrivate->pVidParamBitrate->nPortIndex) 
+            if (((OMX_VIDEO_PARAM_BITRATETYPE*)(ComponentParameterStructure))->nPortIndex ==
+            pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType->nPortIndex)
             {
-                pTmp = memcpy(ComponentParameterStructure, 
-                              pComponentPrivate->pVidParamBitrate,
+                pTmp = memcpy(ComponentParameterStructure,
+                              pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType,
                               sizeof(OMX_VIDEO_PARAM_BITRATETYPE));
-                if (pTmp == NULL) 
+                if (pTmp == NULL)
                 {
                 OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                        pComponentPrivate->dbg, OMX_TRACE4,
@@ -1602,11 +1627,11 @@
             break;
 
         case OMX_IndexParamVideoH263:
-            if (((OMX_VIDEO_PARAM_H263TYPE*)(ComponentParameterStructure))->nPortIndex == 
+            if (((OMX_VIDEO_PARAM_H263TYPE*)(ComponentParameterStructure))->nPortIndex ==
                 pComponentPrivate->pH263->nPortIndex)
             {
                 pTmp = memcpy(ComponentParameterStructure,
-                              pComponentPrivate->pH263, 
+                              pComponentPrivate->pH263,
                               sizeof(OMX_VIDEO_PARAM_H263TYPE));
                 if (pTmp == NULL)
                 {
@@ -1621,11 +1646,11 @@
             }
             break;
         case OMX_IndexParamVideoQuantization:
-            if (((OMX_VIDEO_PARAM_QUANTIZATIONTYPE*)(ComponentParameterStructure))->nPortIndex == 
+            if (((OMX_VIDEO_PARAM_QUANTIZATIONTYPE*)(ComponentParameterStructure))->nPortIndex ==
                 pComponentPrivate->pQuantization->nPortIndex)
             {
-                pTmp = memcpy(ComponentParameterStructure, 
-                              pComponentPrivate->pQuantization, 
+                pTmp = memcpy(ComponentParameterStructure,
+                              pComponentPrivate->pQuantization,
                               sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE));
                 if (pTmp == NULL)
                 {
@@ -1638,83 +1663,82 @@
             {
                 eError = OMX_ErrorBadPortIndex;
             }
-            break;  
+            break;
 
-	case OMX_IndexParamVideoProfileLevelQuerySupported:
-		{
-				VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
-                                OMX_U32 nNumberOfProfiles = 0;
-				OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
-				pParamProfileLevel->nPortIndex = pCompPortOut->pPortDef->nPortIndex;
 
-				/* Choose table based on compression format */
-				switch(pCompPortOut->pPortDef->format.video.eCompressionFormat)
-       		         {
-				case OMX_VIDEO_CodingH263:
-					pProfileLevel = SupportedH263ProfileLevels;
-                                        nNumberOfProfiles = sizeof(SupportedH263ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
-					break;
-				case OMX_VIDEO_CodingMPEG4:
-					pProfileLevel = SupportedMPEG4ProfileLevels;
-                                        nNumberOfProfiles = sizeof(SupportedMPEG4ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
-					break;
-				case OMX_VIDEO_CodingAVC:
-					pProfileLevel = SupportedAVCProfileLevels;
-                                        nNumberOfProfiles = sizeof(SupportedAVCProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
-					break;
-                                default:
-                                       eError = OMX_ErrorBadParameter;
-                                       return eError;
-                		   }
+    case OMX_IndexParamVideoProfileLevelQuerySupported:
+    {
+       VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
+        OMX_U32 nNumberOfProfiles = 0;
+       OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
+       pParamProfileLevel->nPortIndex = pCompPortOut->pPortDef->nPortIndex;
+         /* Choose table based on compression format */
+       switch(pCompPortOut->pPortDef->format.video.eCompressionFormat)
+       {
+          case OMX_VIDEO_CodingH263:
+             pProfileLevel = SupportedH263ProfileLevels;
+             nNumberOfProfiles = sizeof(SupportedH263ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
+             break;
+          case OMX_VIDEO_CodingMPEG4:
+             pProfileLevel = SupportedMPEG4ProfileLevels;
+             nNumberOfProfiles = sizeof(SupportedMPEG4ProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
+             break;
+           case OMX_VIDEO_CodingAVC:
+             pProfileLevel = SupportedAVCProfileLevels;
+             nNumberOfProfiles = sizeof(SupportedAVCProfileLevels) / sizeof (VIDEO_PROFILE_LEVEL_TYPE);
+             break;
+           default:
+              eError = OMX_ErrorBadParameter;
+              return eError;
+        }
+        if((pParamProfileLevel->nProfileIndex < 0) || (pParamProfileLevel->nProfileIndex >= nNumberOfProfiles)) {
+            return OMX_ErrorBadParameter;
+        }
+        /* Point to table entry based on index */
+        pProfileLevel += pParamProfileLevel->nProfileIndex;
 
-                                if((pParamProfileLevel->nProfileIndex < 0) || (pParamProfileLevel->nProfileIndex >= nNumberOfProfiles)) {
-                                    return OMX_ErrorBadParameter;
-                                }
+        /* -1 indicates end of table */
+        if(pProfileLevel->nProfile != -1) {
+           pParamProfileLevel->eProfile = pProfileLevel->nProfile;
+           pParamProfileLevel->eLevel = pProfileLevel->nLevel;
+           eError = OMX_ErrorNone;
+        }
+        else {
+           eError = OMX_ErrorNoMore;
+        }
+    }
+    break;
+    case OMX_IndexParamVideoProfileLevelCurrent:
+    {
+       OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)  ComponentParameterStructure;
+       if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
+          pParamProfileLevel->eProfile = pComponentPrivate->pH264->eProfile;
+           pParamProfileLevel->eLevel = pComponentPrivate->pH264->eLevel;
+       }
+       else if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
+          pParamProfileLevel->eProfile = pComponentPrivate->pMpeg4->eProfile;
+          pParamProfileLevel->eLevel = pComponentPrivate->pMpeg4->eLevel;
 
-				/* Point to table entry based on index */
-				pProfileLevel += pParamProfileLevel->nProfileIndex;
+       }
+       else if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
+          pParamProfileLevel->eProfile = pComponentPrivate->pH263->eProfile;
+          pParamProfileLevel->eLevel = pComponentPrivate->pH263->eLevel;
+       }
+       else {
+          eError = OMX_ErrorBadParameter;
+       }
 
-				/* -1 indicates end of table */
-				if(pProfileLevel->nProfile != -1) {
-					pParamProfileLevel->eProfile = pProfileLevel->nProfile;
-					pParamProfileLevel->eLevel = pProfileLevel->nLevel;
-					eError = OMX_ErrorNone;
-					}
-				else {
-					eError = OMX_ErrorNoMore;
-            }
-				}
-			break;
+    }
+    break;
 
-	case OMX_IndexParamVideoProfileLevelCurrent:
-			{
-				OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)ComponentParameterStructure;
-				if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingAVC) {
-					pParamProfileLevel->eProfile = pComponentPrivate->pH264->eProfile;
-					pParamProfileLevel->eLevel = pComponentPrivate->pH264->eLevel;
-					}
-				else if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
-					pParamProfileLevel->eProfile = pComponentPrivate->pMpeg4->eProfile;
-					pParamProfileLevel->eLevel = pComponentPrivate->pMpeg4->eLevel;
-				}
-				else if (pCompPortOut->pPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingH263) {
-					pParamProfileLevel->eProfile = pComponentPrivate->pH263->eProfile;
-					pParamProfileLevel->eLevel = pComponentPrivate->pH263->eLevel;
-					}
-				else {
-					eError = OMX_ErrorBadParameter;
-            }
-				}
-			break;
-
-		case OMX_IndexParamVideoErrorCorrection:
-					{
-					if (((OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)(ComponentParameterStructure))->nPortIndex == 
-						VIDENC_OUTPUT_PORT)
-					{
-						pTmp = memcpy(ComponentParameterStructure, 
-									  pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType,
-									  sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
+        case OMX_IndexParamVideoErrorCorrection:
+                    {
+                    if (((OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)(ComponentParameterStructure))->nPortIndex ==
+                        VIDENC_OUTPUT_PORT)
+                    {
+                        pTmp = memcpy(ComponentParameterStructure,
+                                      pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType,
+                                      sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
                 if (pTmp == NULL)
                 {
                     OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
@@ -1722,22 +1746,25 @@
                                            "Failed to copy OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE parameter.\n");
                 }
             }
-					else
-					{
-						eError = OMX_ErrorBadPortIndex;
-					}
-					break;	
-				}
-				
+                    else
+                    {
+                        eError = OMX_ErrorBadPortIndex;
+                    }
+                    break;
+                }
+
         case VideoEncodeCustomParamIndexVBVSize:
             (*((OMX_U32*)ComponentParameterStructure)) = (OMX_U32)pComponentPrivate->nVBVSize;
             break;
-        case VideoEncodeCustomParamIndexDeblockFilter:     
+        case VideoEncodeCustomParamIndexDeblockFilter:
             (*((OMX_BOOL*)ComponentParameterStructure)) = (OMX_BOOL)pComponentPrivate->bDeblockFilter;
             break;
-		case VideoEncodeCustomParamIndexEncodingPreset:
-			(*((unsigned int*)ComponentParameterStructure)) = (unsigned int)pComponentPrivate->nEncodingPreset; 
-			break;
+        case VideoEncodeCustomParamIndexEncodingPreset:
+            (*((unsigned int*)ComponentParameterStructure)) = (unsigned int)pComponentPrivate->nEncodingPreset;
+            break;
+        case VideoEncodeCustomConfigIndexUnrestrictedMV:
+            (*((OMX_U8*)ComponentParameterStructure)) = (OMX_U8)pComponentPrivate->ucUnrestrictedMV;
+            break;
        case VideoEncodeCustomParamIndexNALFormat:
            (*((unsigned int*)ComponentParameterStructure)) = (unsigned int)pComponentPrivate->AVCNALFormat;
            break;
@@ -1749,7 +1776,7 @@
             {
                 OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorUndefined);
             }
-            break; 
+            break;
        //not supported yet
        case OMX_IndexConfigCommonRotate:
            break;
@@ -1777,7 +1804,7 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE SetParameter (OMX_IN OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE SetParameter (OMX_IN OMX_HANDLETYPE hComponent,
                                    OMX_IN OMX_INDEXTYPE nParamIndex,
                                    OMX_IN OMX_PTR pCompParam)
 {
@@ -1787,28 +1814,31 @@
     VIDENC_NODE* pMemoryListHead                = NULL;
     VIDEOENC_PORT_TYPE* pCompPortIn             = NULL;
     VIDEOENC_PORT_TYPE* pCompPortOut            = NULL;
-	
+
 #ifdef __KHRONOS_CONF_1_1__
     OMX_PARAM_COMPONENTROLETYPE  *pRole = NULL;
-	OMX_VIDEO_PARAM_PROFILELEVELTYPE* sProfileLevel;
+    OMX_VIDEO_PARAM_PROFILELEVELTYPE* sProfileLevel;
 #endif
     OMX_CONF_CHECK_CMD(hComponent, ((OMX_COMPONENTTYPE *) hComponent)->pComponentPrivate, 1);
 
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pCompParam, 1, 1);
 
-    if (pComponentPrivate->eState == OMX_StateInvalid)
-    {
-        OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
-                               pComponentPrivate->dbg, OMX_PRSTATE3,
-                               "Component is in invalid state.\n");
-    }   
-    
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
     pCompPortIn     = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT];
     pCompPortOut    = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT];
 
-    switch (nParamIndex) 
+    if ((pComponentPrivate->eState != OMX_StateLoaded) &&
+        (pComponentPrivate->eState != OMX_StateWaitForResources) &&
+        (nParamIndex != OMX_IndexParamPortDefinition ||
+            (pCompPortIn->pPortDef->bEnabled && pCompPortOut->pPortDef->bEnabled)))
+    {
+        OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
+                               pComponentPrivate->dbg, OMX_PRSTATE3,
+                               "Call in an invalid state.\n");
+    }
+
+    switch (nParamIndex)
     {
         case OMX_IndexParamVideoPortFormat:
         {
@@ -1816,7 +1846,7 @@
             if (pComponentParam->nPortIndex == pCompPortIn->pPortFormat->nPortIndex)
             {
                 pTmp = memcpy(pCompPortIn->pPortFormat,
-                              pComponentParam, 
+                              pComponentParam,
                               sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE));
                 if (pTmp == NULL)
                 {
@@ -1825,7 +1855,7 @@
                                            "Failed to copy parameter.\n");
                 }
             }
-            else if (pComponentParam->nPortIndex == pCompPortOut->pPortFormat->nPortIndex) 
+            else if (pComponentParam->nPortIndex == pCompPortOut->pPortFormat->nPortIndex)
             {
                 pTmp = memcpy(pCompPortOut->pPortFormat,
                               pComponentParam,
@@ -1837,7 +1867,7 @@
                                            "Failed to copy parameter.\n");
                 }
             }
-            else 
+            else
             {
                 eError = OMX_ErrorBadPortIndex;
             }
@@ -1857,7 +1887,14 @@
         case OMX_IndexParamPortDefinition:
         {
             OMX_PARAM_PORTDEFINITIONTYPE* pComponentParam = (OMX_PARAM_PORTDEFINITIONTYPE*)pCompParam;
-            if (pComponentParam->nPortIndex == pCompPortIn->pPortDef->nPortIndex) 
+            eError = IsResolutionPlayable(pCompPortIn->pPortDef->format.video.nFrameWidth, pCompPortIn->pPortDef->format.video.nFrameHeight);
+            if (eError != OMX_ErrorNone)
+            {
+                /* OMX components co-existance, if resolution is 720p or higher let the 720p OMX
+                 * component to take care of them */
+                return OMX_ErrorBadParameter;
+            }
+            if (pComponentParam->nPortIndex == pCompPortIn->pPortDef->nPortIndex)
             {
                 pTmp = memcpy(pCompPortIn->pPortDef,
                               pComponentParam,
@@ -1868,7 +1905,6 @@
                                            pComponentPrivate->dbg, OMX_TRACE4,
                                            "Failed to copy parameter.\n");
                 }
-                /* Calculate input buffer size based on these port settings */
                 CalculateBufferSize(pCompPortIn->pPortDef, pComponentPrivate);
             }
             else if (pComponentParam->nPortIndex == pCompPortOut->pPortDef->nPortIndex)
@@ -1882,8 +1918,14 @@
                                            pComponentPrivate->dbg, OMX_TRACE4,
                                            "Failed to copy parameter.\n");
                 }
-                /* Calculate output buffer size based on these port settings */
                 CalculateBufferSize(pCompPortOut->pPortDef, pComponentPrivate);
+                if(!pCompPortOut->pPortDef->format.video.nBitrate)
+                {
+                    pCompPortOut->pPortDef->format.video.nBitrate = OMX_VIDENC_GetDefaultBitRate(pComponentPrivate);
+                }
+                pCompPortOut->pBitRateTypeConfig->nEncodeBitrate =
+                pCompPortOut->pBitRateType->nTargetBitrate =
+                pCompPortOut->pPortDef->format.video.nBitrate;
             }
             else
             {
@@ -1896,7 +1938,7 @@
             OMX_VIDEO_PARAM_AVCTYPE* pComponentParam = (OMX_VIDEO_PARAM_AVCTYPE*)pCompParam;
             if (pComponentParam->nPortIndex == pComponentPrivate->pH264->nPortIndex)
             {
-                pTmp = memcpy(pComponentPrivate->pH264, 
+                pTmp = memcpy(pComponentPrivate->pH264,
                               pCompParam,
                               sizeof(OMX_VIDEO_PARAM_AVCTYPE));
                 if (pTmp == NULL)
@@ -1910,7 +1952,7 @@
             else
             {
                 eError = OMX_ErrorBadPortIndex;
-            } 
+            }
             break;
         }
         case OMX_IndexParamVideoMpeg4:
@@ -1919,7 +1961,7 @@
             if (pComponentParam->nPortIndex == pComponentPrivate->pMpeg4->nPortIndex)
             {
                 pTmp = memcpy(pComponentPrivate->pMpeg4,
-                              pCompParam, 
+                              pCompParam,
                               sizeof(OMX_VIDEO_PARAM_MPEG4TYPE));
                 if (pTmp == NULL)
                 {
@@ -1928,7 +1970,7 @@
                                            "Failed to copy parameter.\n");
                 }
             }
-            else 
+            else
             {
                 eError = OMX_ErrorBadPortIndex;
             }
@@ -1948,7 +1990,7 @@
         case OMX_IndexParamCompBufferSupplier:
         {
             OMX_PARAM_BUFFERSUPPLIERTYPE* pBuffSupplierParam = (OMX_PARAM_BUFFERSUPPLIERTYPE*)pCompParam;
-            if (pBuffSupplierParam->nPortIndex == VIDENC_INPUT_PORT) 
+            if (pBuffSupplierParam->nPortIndex == VIDENC_INPUT_PORT)
             {
                 pCompPortIn->eSupplierSetting = pBuffSupplierParam->eBufferSupplier;
             }
@@ -1965,10 +2007,10 @@
         case OMX_IndexParamVideoBitrate:
         {
             OMX_VIDEO_PARAM_BITRATETYPE* pComponentParam = (OMX_VIDEO_PARAM_BITRATETYPE*)pCompParam;
-            if (pComponentParam->nPortIndex == pComponentPrivate->pVidParamBitrate->nPortIndex)
+            if (pComponentParam->nPortIndex == pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType->nPortIndex)
             {
-                pTmp = memcpy(pComponentPrivate->pVidParamBitrate,
-                              pCompParam, 
+                pTmp = memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType,
+                              pCompParam,
                               sizeof(OMX_VIDEO_PARAM_BITRATETYPE));
                 if (pTmp == NULL)
                 {
@@ -1976,6 +2018,13 @@
                                            pComponentPrivate->dbg, OMX_TRACE4,
                                            "Failed to copy parameter.\n");
                 }
+                if(!pCompPortOut->pBitRateType->nTargetBitrate)
+                {
+                    pCompPortOut->pBitRateType->nTargetBitrate = OMX_VIDENC_GetDefaultBitRate(pComponentPrivate);
+                }
+                pCompPortOut->pPortDef->format.video.nBitrate =
+                pCompPortOut->pBitRateTypeConfig->nEncodeBitrate =
+                pCompPortOut->pBitRateType->nTargetBitrate;
             }
             else
             {
@@ -1983,26 +2032,26 @@
             }
             break;
         }
-		case OMX_IndexParamVideoErrorCorrection:
-				{
-					   pTmp = memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType,
-									 pCompParam,
-									 sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));	
-					   if (pTmp == NULL)
-						{
+        case OMX_IndexParamVideoErrorCorrection:
+                {
+                       pTmp = memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType,
+                                     pCompParam,
+                                     sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
+                       if (pTmp == NULL)
+                        {
                 OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                        pComponentPrivate->dbg, OMX_TRACE4,
                                        "Failed to copy parameter.\n");
-						}
-				}
-				break;
+                        }
+                }
+                break;
         case OMX_IndexParamVideoH263:
         {
             OMX_VIDEO_PARAM_H263TYPE* pComponentParam = (OMX_VIDEO_PARAM_H263TYPE*)pCompParam;
             if (pComponentParam->nPortIndex == pComponentPrivate->pH263->nPortIndex)
             {
                 pTmp = memcpy(pComponentPrivate->pH263,
-                              pCompParam, 
+                              pCompParam,
                               sizeof(OMX_VIDEO_PARAM_H263TYPE));
                 if (pTmp == NULL)
                 {
@@ -2011,7 +2060,7 @@
                                            "Failed to copy parameter.\n");
                 }
             }
-            else 
+            else
             {
                 eError = OMX_ErrorBadPortIndex;
             }
@@ -2032,117 +2081,118 @@
                                            "Failed to copy parameter.\n");
                 }
             }
-            else 
+            else
             {
                 eError = OMX_ErrorBadPortIndex;
             }
             break;
-        }                       
+        }
         case VideoEncodeCustomParamIndexVBVSize:
-            pComponentPrivate->nVBVSize = (OMX_U32)(*((OMX_U32*)pCompParam)); 
+            pComponentPrivate->nVBVSize = (OMX_U32)(*((OMX_U32*)pCompParam));
             break;
         case VideoEncodeCustomParamIndexDeblockFilter:
-            pComponentPrivate->bDeblockFilter = (OMX_BOOL)(*((OMX_BOOL*)pCompParam)); 
+            pComponentPrivate->bDeblockFilter = (OMX_BOOL)(*((OMX_BOOL*)pCompParam));
             break;
 
 #ifdef __KHRONOS_CONF_1_1__
-	case OMX_IndexParamStandardComponentRole:
+    case OMX_IndexParamStandardComponentRole:
         if (pCompParam)
         {
-			pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
-			memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
+            pRole = (OMX_PARAM_COMPONENTROLETYPE *)pCompParam;
+            memcpy(&(pComponentPrivate->componentRole), (void *)pRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
             if (strcmp((char *)pRole->cRole,"video_encoder.mpeg4")==0)
             {
-		        pCompPortOut->pPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
-				pCompPortOut->pPortFormat->eCompressionFormat = OMX_VIDEO_CodingMPEG4;
-				}
+                pCompPortOut->pPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingMPEG4;
+                pCompPortOut->pPortFormat->eCompressionFormat = OMX_VIDEO_CodingMPEG4;
+                pCompPortOut->pPortDef->format.video.nBitrate = VIDENC_STRUCT_MPEG4DEFBITRATE[0][1];
+            }
             else if (strcmp((char *)pRole->cRole,"video_encoder.h263")==0)
             {
-				pCompPortOut->pPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingH263;
-				pCompPortOut->pPortFormat->eCompressionFormat = OMX_VIDEO_CodingH263;
-				}
+                pCompPortOut->pPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingH263;
+                pCompPortOut->pPortFormat->eCompressionFormat = OMX_VIDEO_CodingH263;
+                pCompPortOut->pPortDef->format.video.nBitrate = VIDENC_STRUCT_H263DEFBITRATE[0][1];
+            }
             else if (strcmp((char *)pRole->cRole,"video_encoder.avc")==0)
             {
-				pCompPortOut->pPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
-				pCompPortOut->pPortFormat->eCompressionFormat= OMX_VIDEO_CodingAVC;
-				}
-				
-			pCompPortOut->pPortFormat->eColorFormat = OMX_COLOR_FormatUnused;
-			pCompPortOut->pPortDef->eDomain = OMX_PortDomainVideo; 
-    		pCompPortOut->pPortDef->format.video.eColorFormat = OMX_COLOR_FormatUnused;
-        	pCompPortOut->pPortDef->format.video.nFrameWidth = 176;
-		    pCompPortOut->pPortDef->format.video.nFrameHeight = 144;
-			pCompPortOut->pPortDef->format.video.nBitrate = 64000;
-        	pCompPortOut->pPortDef->format.video.xFramerate = (15 << 16);
-		
+                pCompPortOut->pPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingAVC;
+                pCompPortOut->pPortFormat->eCompressionFormat= OMX_VIDEO_CodingAVC;
+                pCompPortOut->pPortDef->format.video.nBitrate = VIDENC_STRUCT_H264DEFBITRATE[0][1];
+            }
+
+            pCompPortOut->pPortFormat->eColorFormat = OMX_COLOR_FormatUnused;
+            pCompPortOut->pPortDef->eDomain = OMX_PortDomainVideo;
+            pCompPortOut->pPortDef->format.video.eColorFormat = OMX_COLOR_FormatUnused;
+            pCompPortOut->pPortDef->format.video.nFrameWidth = 176;
+            pCompPortOut->pPortDef->format.video.nFrameHeight = 144;
+            pCompPortOut->pPortDef->format.video.xFramerate = fToQ16(15.0);
         }
         else
         {
-			eError = OMX_ErrorBadParameter;
-		}
-		break;
+            eError = OMX_ErrorBadParameter;
+        }
+        break;
 
-	case OMX_IndexParamVideoProfileLevelCurrent:
-			{
-			VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
-			OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pCompParam;
+    case OMX_IndexParamVideoProfileLevelCurrent:
+        {
+           VIDEO_PROFILE_LEVEL_TYPE* pProfileLevel = NULL;
+           OMX_VIDEO_PARAM_PROFILELEVELTYPE *pParamProfileLevel = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pCompParam;
 
-			/* Choose table based on compression format */
-			switch(pCompPortOut->pPortDef->format.video.eCompressionFormat)
-	            {
-			case OMX_VIDEO_CodingH263:
-				pProfileLevel = SupportedH263ProfileLevels;
-				break;
-			case OMX_VIDEO_CodingMPEG4:
-				pProfileLevel = SupportedMPEG4ProfileLevels;
-				break;
-			case OMX_VIDEO_CodingAVC:
-				pProfileLevel = SupportedAVCProfileLevels;
-				break;
-                        default:
-                               eError = OMX_ErrorBadParameter;
-                               return eError;
-	            }
+           /* Choose table based on compression format */
+           switch(pCompPortOut->pPortDef->format.video.eCompressionFormat)
 
-			/* Check validity of profile & level parameters */
-			while((pProfileLevel->nProfile != (OMX_S32)pParamProfileLevel->eProfile) ||
-				  (pProfileLevel->nLevel != (OMX_S32)pParamProfileLevel->eLevel)) {
-				pProfileLevel++;
-				if(pProfileLevel->nProfile == -1) break;
-	            }
-
-			if(pProfileLevel->nProfile != -1) {
-				/* Update profile & level values in the compression format specific structure */
-				switch(pCompPortOut->pPortDef->format.video.eCompressionFormat) {
-				case OMX_VIDEO_CodingH263:
-					pComponentPrivate->pH263->eProfile = pParamProfileLevel->eProfile;
-					pComponentPrivate->pH263->eLevel = pParamProfileLevel->eLevel;
-					break;
-				case OMX_VIDEO_CodingMPEG4:
-					pComponentPrivate->pMpeg4->eProfile = pParamProfileLevel->eProfile;
-					pComponentPrivate->pMpeg4->eLevel = pParamProfileLevel->eLevel;
-	            break;			
-				case OMX_VIDEO_CodingAVC:
-					pComponentPrivate->pH264->eProfile = pParamProfileLevel->eProfile;
-					pComponentPrivate->pH264->eLevel = pParamProfileLevel->eLevel;
-                                default:
-                                        eError = OMX_ErrorBadParameter;
-                                        return eError;
-				}
-
-				eError = OMX_ErrorNone;
-			}
-			else {
-				eError = OMX_ErrorBadParameter;
-			}
-		}
-		break;
-
+            {
+              case OMX_VIDEO_CodingH263:
+                 pProfileLevel = &SupportedH263ProfileLevels;
+                 break;
+              case OMX_VIDEO_CodingMPEG4:
+                 pProfileLevel = &SupportedMPEG4ProfileLevels;
+                 break;
+              case OMX_VIDEO_CodingAVC:
+                 pProfileLevel = &SupportedAVCProfileLevels;
+                 break;
+              default:
+                 eError = OMX_ErrorBadParameter;
+                 return eError;
+            }
+            /* Check validity of profile & level parameters */
+            while((pProfileLevel->nProfile != (OMX_S32)pParamProfileLevel->eProfile) ||
+               (pProfileLevel->nLevel != (OMX_S32)pParamProfileLevel->eLevel)) {
+               pProfileLevel++;
+               if(pProfileLevel->nProfile == -1) break;
+            }
+            if(pProfileLevel->nProfile != -1) {
+            /* Update profile & level values in the compression format specific structure */
+               switch(pCompPortOut->pPortDef->format.video.eCompressionFormat) {
+                  case OMX_VIDEO_CodingH263:
+                     pComponentPrivate->pH263->eProfile = pParamProfileLevel->eProfile;
+                     pComponentPrivate->pH263->eLevel = pParamProfileLevel->eLevel;
+                     break;
+                  case OMX_VIDEO_CodingMPEG4:
+                     pComponentPrivate->pMpeg4->eProfile = pParamProfileLevel->eProfile;
+                     pComponentPrivate->pMpeg4->eLevel = pParamProfileLevel->eLevel;
+                     break;
+                  case OMX_VIDEO_CodingAVC:
+                     pComponentPrivate->pH264->eProfile = pParamProfileLevel->eProfile;
+                     pComponentPrivate->pH264->eLevel = pParamProfileLevel->eLevel;
+                  default:
+                     eError = OMX_ErrorBadParameter;
+                     return eError;
+                }
+                eError = OMX_ErrorNone;
+            }
+            else {
+               eError = OMX_ErrorBadParameter;
+            }
+        }
+        break;
 #endif
-		/*valid for H264 only*/
-		case VideoEncodeCustomParamIndexEncodingPreset:
-				pComponentPrivate->nEncodingPreset = (unsigned int)(*((unsigned int*)pCompParam)); 
-			break;
+        /*valid for H264 only*/
+        case VideoEncodeCustomParamIndexEncodingPreset:
+                pComponentPrivate->nEncodingPreset = (unsigned int)(*((unsigned int*)pCompParam));
+            break;
+        case VideoEncodeCustomConfigIndexUnrestrictedMV:
+            pComponentPrivate->ucUnrestrictedMV = (OMX_U8)(*((OMX_U8*)pCompParam));
+            break;
        case VideoEncodeCustomParamIndexNALFormat:
               pComponentPrivate->AVCNALFormat = (VIDENC_AVC_NAL_FORMAT)(*((unsigned int*)pCompParam));
        break;
@@ -2174,14 +2224,14 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE GetConfig (OMX_HANDLETYPE hComponent,
                                 OMX_INDEXTYPE nConfigIndex,
                                 OMX_PTR ComponentConfigStructure)
 {
     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
     VIDENC_NODE* pMemoryListHead                = NULL;
-	OMX_U32* pTmp								= NULL;
+    OMX_U32* pTmp                               = NULL;
 
     OMX_CONF_CHECK_CMD(hComponent, ((OMX_COMPONENTTYPE *) hComponent)->pComponentPrivate, 1);
 
@@ -2193,13 +2243,13 @@
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
                                pComponentPrivate->dbg, OMX_PRSTATE3,
                                "Component is in invalid state.\n");
-    }   
-    
+    }
+
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
-      
+
     switch (nConfigIndex)
     {
-        case VideoEncodeCustomConfigIndexForceIFrame:     
+        case VideoEncodeCustomConfigIndexForceIFrame:
             (*((OMX_BOOL*)ComponentConfigStructure)) = (OMX_BOOL)pComponentPrivate->bForceIFrame;
             break;
         case VideoEncodeCustomConfigIndexIntraFrameInterval:
@@ -2214,9 +2264,6 @@
         case VideoEncodeCustomConfigIndexAIRRate:
             (*((OMX_U32*)ComponentConfigStructure)) = (OMX_U32)pComponentPrivate->nAIRRate;
             break;
-        case VideoEncodeCustomConfigIndexTargetBitRate:
-            (*((OMX_U32*)ComponentConfigStructure)) = (OMX_U32)pComponentPrivate->nTargetBitRate;
-            break;
         /*ASO/FMO*/
         case VideoEncodeCustomConfigIndexNumSliceASO:
             (*((OMX_U32*)ComponentConfigStructure)) = (OMX_U32)pComponentPrivate->numSliceASO;
@@ -2238,39 +2285,39 @@
             break;
         case VideoEncodeCustomConfigIndexSliceGroupChangeCycle:
             (*((OMX_U32*)ComponentConfigStructure)) = (OMX_U32)pComponentPrivate->sliceGroupChangeCycle;
-            break;    
+            break;
         case VideoEncodeCustomConfigIndexSliceGroupParams:
             (*((OMX_U32*)ComponentConfigStructure)) = (OMX_U32)pComponentPrivate->sliceGroupParams;
             break;
 
 #ifdef __KHRONOS_CONF_1_1__
-	case OMX_IndexConfigVideoFramerate:
-			{
+    case OMX_IndexConfigVideoFramerate:
+            {
 
             pTmp = memcpy(ComponentConfigStructure,
-				          pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pFrameRateConfig,
-				          sizeof(OMX_CONFIG_FRAMERATETYPE));
-			if (pTmp == NULL)
+                          pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pFrameRateConfig,
+                          sizeof(OMX_CONFIG_FRAMERATETYPE));
+            if (pTmp == NULL)
             {
                 OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                        pComponentPrivate->dbg, OMX_TRACE4,
                                        "Failed to copy config.\n");
             }
-		}
-	break;
-	case OMX_IndexConfigVideoBitrate:
-			{
+        }
+    break;
+    case OMX_IndexConfigVideoBitrate:
+            {
             pTmp = memcpy(ComponentConfigStructure,
-				          pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig,
-				          sizeof(OMX_VIDEO_CONFIG_BITRATETYPE));
-			if (pTmp == NULL)
+                          pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig,
+                          sizeof(OMX_VIDEO_CONFIG_BITRATETYPE));
+            if (pTmp == NULL)
             {
                 OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                        pComponentPrivate->dbg, OMX_TRACE4,
                                        "Failed to copy config.\n");
             }
-		}
-	break;
+        }
+    break;
 #endif
     case OMX_IndexParamVideoMotionVector:
         {
@@ -2304,25 +2351,25 @@
                                        "Failed to copy structure OMX_VIDEO_CONFIG_AVCINTRAPERIOD.\n");
             }
         }
-	case OMX_IndexParamVideoIntraRefresh:
-			 {	 
-       			 pTmp = memcpy(ComponentConfigStructure, 
-		    			       pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pIntraRefreshType,
-			    		       sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE));	 
-			     if (pTmp == NULL)
+    case OMX_IndexParamVideoIntraRefresh:
+             {
+                 pTmp = memcpy(ComponentConfigStructure,
+                               pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pIntraRefreshType,
+                               sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE));
+                 if (pTmp == NULL)
             {
                 OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorUndefined,
                                        pComponentPrivate->dbg, OMX_TRACE4,
                                        "Failed to copy structure OMX_VIDEO_PARAM_INTRAREFRESHTYPE.\n");
             }
-		}
-	break;
-	case OMX_IndexParamVideoErrorCorrection:
-			{
-            if (((OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)(ComponentConfigStructure))->nPortIndex == 
+        }
+    break;
+    case OMX_IndexParamVideoErrorCorrection:
+            {
+            if (((OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE*)(ComponentConfigStructure))->nPortIndex ==
                 VIDENC_OUTPUT_PORT)
             {
-                pTmp = memcpy(ComponentConfigStructure, 
+                pTmp = memcpy(ComponentConfigStructure,
                               pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType,
                               sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
                 if (pTmp == NULL)
@@ -2336,26 +2383,26 @@
             {
                 eError = OMX_ErrorBadPortIndex;
             }
-            break;  
+            break;
         }
     case VideoEncodeCustomConfigIndexDebug:
         OMX_DBG_GETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
         break;
     case VideoEncodeCustomConfigIndexMIRRate:
-			(*((OMX_U32*)ComponentConfigStructure)) = (OMX_U32)pComponentPrivate->nMIRRate;
+            (*((OMX_U32*)ComponentConfigStructure)) = (OMX_U32)pComponentPrivate->nMIRRate;
             break;
-	case VideoEncodeCustomConfigIndexMVDataEnable:
-			(*((OMX_BOOL*)ComponentConfigStructure)) = (OMX_BOOL)pComponentPrivate->bMVDataEnable;
-			 break;
-	case VideoEncodeCustomConfigIndexResyncDataEnable:
-			(*((OMX_BOOL*)ComponentConfigStructure)) = (OMX_BOOL)pComponentPrivate->bResyncDataEnable;
-			 break;
-	case VideoEncodeCustomConfigIndexMaxMVperMB:
-	    	(*((OMX_U32*)ComponentConfigStructure))  =  (OMX_U32)pComponentPrivate->maxMVperMB;
-		 	break;
-	case VideoEncodeCustomConfigIndexIntra4x4EnableIdc:
-	        (*((IH264VENC_Intra4x4Params*)ComponentConfigStructure)) = (IH264VENC_Intra4x4Params)pComponentPrivate->intra4x4EnableIdc;
-		 break;
+    case VideoEncodeCustomConfigIndexMVDataEnable:
+            (*((OMX_BOOL*)ComponentConfigStructure)) = (OMX_BOOL)pComponentPrivate->bMVDataEnable;
+             break;
+    case VideoEncodeCustomConfigIndexResyncDataEnable:
+            (*((OMX_BOOL*)ComponentConfigStructure)) = (OMX_BOOL)pComponentPrivate->bResyncDataEnable;
+             break;
+    case VideoEncodeCustomConfigIndexMaxMVperMB:
+            (*((OMX_U32*)ComponentConfigStructure))  =  (OMX_U32)pComponentPrivate->maxMVperMB;
+            break;
+    case VideoEncodeCustomConfigIndexIntra4x4EnableIdc:
+            (*((IH264VENC_Intra4x4Params*)ComponentConfigStructure)) = (IH264VENC_Intra4x4Params)pComponentPrivate->intra4x4EnableIdc;
+         break;
         default:
             eError = OMX_ErrorUnsupportedIndex;
             break;
@@ -2381,14 +2428,14 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE SetConfig (OMX_HANDLETYPE hComponent,
                                 OMX_INDEXTYPE nConfigIndex,
                                 OMX_PTR ComponentConfigStructure)
 {
     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
     VIDENC_NODE* pMemoryListHead                = NULL;
-    OMX_U32 i;    
+    OMX_U32 i;
 
     OMX_CONF_CHECK_CMD(hComponent, ((OMX_COMPONENTTYPE *) hComponent)->pComponentPrivate, 1);
 
@@ -2400,10 +2447,10 @@
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
                                pComponentPrivate->dbg, OMX_PRSTATE3,
                                "Component is in invalid state.\n");
-    }   
-    
+    }
+
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
-      
+
     switch (nConfigIndex)
     {
         case VideoEncodeCustomConfigIndexForceIFrame:
@@ -2421,9 +2468,6 @@
         case VideoEncodeCustomConfigIndexAIRRate:
             pComponentPrivate->nAIRRate = (OMX_U32)(*((OMX_U32*)ComponentConfigStructure));
             break;
-        case VideoEncodeCustomConfigIndexTargetBitRate:
-            pComponentPrivate->nTargetBitRate = (OMX_U32)(*((OMX_U32*)ComponentConfigStructure));
-            break;
         /*ASO/FMO*/
         case VideoEncodeCustomConfigIndexNumSliceASO:
             pComponentPrivate->numSliceASO = (OMX_U32)(*((OMX_U32*)ComponentConfigStructure));
@@ -2448,42 +2492,49 @@
             break;
         case VideoEncodeCustomConfigIndexSliceGroupChangeCycle:
             pComponentPrivate->sliceGroupChangeCycle = (OMX_U32)(*((OMX_U32*)ComponentConfigStructure));
-            break;    
+            break;
         case VideoEncodeCustomConfigIndexSliceGroupParams:
             for(i=0; i<MAXNUMSLCGPS;i++)
             {
                 pComponentPrivate->sliceGroupParams[i] = (OMX_U32)(*((*((OMX_U32**)ComponentConfigStructure))+i));
             }
             break;
-	case OMX_IndexConfigVideoFramerate:
-			{
-            memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pFrameRateConfig,
-				ComponentConfigStructure, 
-				sizeof(OMX_CONFIG_FRAMERATETYPE));
-	}
-	break;
-	case OMX_IndexConfigVideoBitrate:
-		{
-		memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig,
-				ComponentConfigStructure,
-				sizeof(OMX_VIDEO_CONFIG_BITRATETYPE));
+    case OMX_IndexConfigVideoFramerate:
+    {
+        memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pFrameRateConfig,
+               ComponentConfigStructure,
+               sizeof(OMX_CONFIG_FRAMERATETYPE));
+    }
+    break;
+    case OMX_IndexConfigVideoBitrate:
+    {
+        memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig,
+               ComponentConfigStructure,
+               sizeof(OMX_VIDEO_CONFIG_BITRATETYPE));
 
-	}
-break;
-	case OMX_IndexParamVideoErrorCorrection:
-		{
-		memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType,
-				ComponentConfigStructure,
-				sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));	
-		}
-		break;
-	case OMX_IndexParamVideoIntraRefresh:
-		{
-		memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pIntraRefreshType,
-				ComponentConfigStructure,
-				sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE));	
-		}
-		break;
+        if(!pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate)
+        {
+            pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate = OMX_VIDENC_GetDefaultBitRate(pComponentPrivate);
+        }
+        pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef->format.video.nBitrate =
+        pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateType->nTargetBitrate =
+        pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pBitRateTypeConfig->nEncodeBitrate;
+    }
+    break;
+    case OMX_IndexParamVideoErrorCorrection:
+    {
+        memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pErrorCorrectionType,
+               ComponentConfigStructure,
+               sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE));
+    }
+    break;
+    case OMX_IndexParamVideoIntraRefresh:
+        {
+        memcpy(pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pIntraRefreshType,
+                ComponentConfigStructure,
+                sizeof(OMX_VIDEO_PARAM_INTRAREFRESHTYPE));
+        }
+        break;
     case OMX_IndexParamVideoMotionVector:
         {
             memcpy(pComponentPrivate->pMotionVector,
@@ -2509,40 +2560,40 @@
     case VideoEncodeCustomConfigIndexDebug:
         OMX_DBG_SETCONFIG(pComponentPrivate->dbg, ComponentConfigStructure);
         break;
-	case VideoEncodeCustomConfigIndexMIRRate:
-				pComponentPrivate->nMIRRate = (OMX_U32)(*((OMX_U32*)ComponentConfigStructure));
-		break;
-	case VideoEncodeCustomConfigIndexMVDataEnable:
-		pComponentPrivate->bMVDataEnable = (OMX_BOOL)(*((OMX_BOOL*)ComponentConfigStructure));
-		 break;
-	case VideoEncodeCustomConfigIndexResyncDataEnable:
-		pComponentPrivate->bResyncDataEnable = (OMX_BOOL)(*((OMX_BOOL*)ComponentConfigStructure));
-		 break;
+    case VideoEncodeCustomConfigIndexMIRRate:
+                pComponentPrivate->nMIRRate = (OMX_U32)(*((OMX_U32*)ComponentConfigStructure));
+        break;
+    case VideoEncodeCustomConfigIndexMVDataEnable:
+        pComponentPrivate->bMVDataEnable = (OMX_BOOL)(*((OMX_BOOL*)ComponentConfigStructure));
+         break;
+    case VideoEncodeCustomConfigIndexResyncDataEnable:
+        pComponentPrivate->bResyncDataEnable = (OMX_BOOL)(*((OMX_BOOL*)ComponentConfigStructure));
+         break;
     case VideoEncodeCustomConfigIndexMaxMVperMB:
-	    i = (OMX_U32)(*((OMX_U32*)ComponentConfigStructure));
-		if (i==1 || i==4)
-			pComponentPrivate->maxMVperMB=i;
-		else
-			eError = OMX_ErrorBadParameter;
-		 break;
-	case VideoEncodeCustomConfigIndexIntra4x4EnableIdc:
-	    pComponentPrivate->intra4x4EnableIdc = (IH264VENC_Intra4x4Params)(*((IH264VENC_Intra4x4Params*)ComponentConfigStructure));
-		 break;
+        i = (OMX_U32)(*((OMX_U32*)ComponentConfigStructure));
+        if (i==1 || i==4)
+            pComponentPrivate->maxMVperMB=i;
+        else
+            eError = OMX_ErrorBadParameter;
+         break;
+    case VideoEncodeCustomConfigIndexIntra4x4EnableIdc:
+        pComponentPrivate->intra4x4EnableIdc = (IH264VENC_Intra4x4Params)(*((IH264VENC_Intra4x4Params*)ComponentConfigStructure));
+         break;
     default:
         eError = OMX_ErrorUnsupportedIndex;
          break;
         }
-    
+
 OMX_CONF_CMD_BAIL:
     return eError;
 }
 
 /*----------------------------------------------------------------------------*/
 /**
-  *  ExtensionIndex() 
+  *  ExtensionIndex()
   *
-  * 
-  * 
+  *
+  *
   *
   * @param pComponent    handle for this instance of the component
   * @param pCallBacks    application callbacks
@@ -2553,53 +2604,54 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE ExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, 
-                                       OMX_IN OMX_STRING cParameterName, 
+static OMX_ERRORTYPE ExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent,
+                                       OMX_IN OMX_STRING cParameterName,
                                        OMX_OUT OMX_INDEXTYPE* pIndexType)
 {
-    VIDENC_CUSTOM_DEFINITION sVideoEncodeCustomIndex[] = {
+    VIDENC_CUSTOM_DEFINITION sVideoEncodeCustomIndex[] =
+    {
         {"OMX.TI.VideoEncode.Param.VBVSize", VideoEncodeCustomParamIndexVBVSize},
-                                    {"OMX.TI.VideoEncode.Param.DeblockFilter", VideoEncodeCustomParamIndexDeblockFilter},
-                                    {"OMX.TI.VideoEncode.Config.ForceIFrame", VideoEncodeCustomConfigIndexForceIFrame},
-                                    {"OMX.TI.VideoEncode.Config.IntraFrameInterval", VideoEncodeCustomConfigIndexIntraFrameInterval},
-                                    {"OMX.TI.VideoEncode.Config.TargetFrameRate", VideoEncodeCustomConfigIndexTargetFrameRate},
-                                    {"OMX.TI.VideoEncode.Config.QPI", VideoEncodeCustomConfigIndexQPI},
-                                    {"OMX.TI.VideoEncode.Config.AIRRate", VideoEncodeCustomConfigIndexAIRRate},                                    
-                                    {"OMX.TI.VideoEncode.Config.TargetBitRate", VideoEncodeCustomConfigIndexTargetBitRate},
+        {"OMX.TI.VideoEncode.Param.DeblockFilter", VideoEncodeCustomParamIndexDeblockFilter},
+        {"OMX.TI.VideoEncode.Config.ForceIFrame", VideoEncodeCustomConfigIndexForceIFrame},
+        {"OMX.TI.VideoEncode.Config.IntraFrameInterval", VideoEncodeCustomConfigIndexIntraFrameInterval},
+        {"OMX.TI.VideoEncode.Config.TargetFrameRate", VideoEncodeCustomConfigIndexTargetFrameRate},
+        {"OMX.TI.VideoEncode.Config.QPI", VideoEncodeCustomConfigIndexQPI},
+        {"OMX.TI.VideoEncode.Config.AIRRate", VideoEncodeCustomConfigIndexAIRRate},
+        {"OMX.TI.VideoEncode.Config.UnrestrictedMV", VideoEncodeCustomConfigIndexUnrestrictedMV},
 
-									/*Segment mode Metadata*/
-									{"OMX.TI.VideoEncode.Config.MVDataEnable", VideoEncodeCustomConfigIndexMVDataEnable},
-									{"OMX.TI.VideoEncode.Config.ResyncDataEnable", VideoEncodeCustomConfigIndexResyncDataEnable},
+        /*Segment mode Metadata*/
+        {"OMX.TI.VideoEncode.Config.MVDataEnable", VideoEncodeCustomConfigIndexMVDataEnable},
+        {"OMX.TI.VideoEncode.Config.ResyncDataEnable", VideoEncodeCustomConfigIndexResyncDataEnable},
 
-                                    /*ASO*/
-                                    {"OMX.TI.VideoEncode.Config.NumSliceASO", VideoEncodeCustomConfigIndexNumSliceASO},
-                                    {"OMX.TI.VideoEncode.Config.AsoSliceOrder", VideoEncodeCustomConfigIndexAsoSliceOrder},
-                                    /*FMO*/
-                                    {"OMX.TI.VideoEncode.Config.NumSliceGroups", VideoEncodeCustomConfigIndexNumSliceGroups},
-                                    {"OMX.TI.VideoEncode.Config.SliceGroupMapType", VideoEncodeCustomConfigIndexSliceGroupMapType},
-                                    {"OMX.TI.VideoEncode.Config.SliceGroupChangeDirectionFlag", VideoEncodeCustomConfigIndexSliceGroupChangeDirectionFlag},
-                                    {"OMX.TI.VideoEncode.Config.SliceGroupChangeRate", VideoEncodeCustomConfigIndexSliceGroupChangeRate},
-                                    {"OMX.TI.VideoEncode.Config.SliceGroupChangeCycle", VideoEncodeCustomConfigIndexSliceGroupChangeCycle},
-                                    {"OMX.TI.VideoEncode.Config.SliceGroupParams", VideoEncodeCustomConfigIndexSliceGroupParams},
-                                    /**/
-								    {"OMX.TI.VideoEncode.Config.MIRRate", VideoEncodeCustomConfigIndexMIRRate},
-                                     {"OMX.TI.VideoEncode.Config.MaxMVperMB", VideoEncodeCustomConfigIndexMaxMVperMB},
-                                     {"OMX.TI.VideoEncode.Config.Intra4x4EnableIdc", VideoEncodeCustomConfigIndexIntra4x4EnableIdc},
-                                     {"OMX.TI.VideoEncode.Config.EncodingPreset", VideoEncodeCustomParamIndexEncodingPreset},
+        /*ASO*/
+        {"OMX.TI.VideoEncode.Config.NumSliceASO", VideoEncodeCustomConfigIndexNumSliceASO},
+        {"OMX.TI.VideoEncode.Config.AsoSliceOrder", VideoEncodeCustomConfigIndexAsoSliceOrder},
+        /*FMO*/
+        {"OMX.TI.VideoEncode.Config.NumSliceGroups", VideoEncodeCustomConfigIndexNumSliceGroups},
+        {"OMX.TI.VideoEncode.Config.SliceGroupMapType", VideoEncodeCustomConfigIndexSliceGroupMapType},
+        {"OMX.TI.VideoEncode.Config.SliceGroupChangeDirectionFlag", VideoEncodeCustomConfigIndexSliceGroupChangeDirectionFlag},
+        {"OMX.TI.VideoEncode.Config.SliceGroupChangeRate", VideoEncodeCustomConfigIndexSliceGroupChangeRate},
+        {"OMX.TI.VideoEncode.Config.SliceGroupChangeCycle", VideoEncodeCustomConfigIndexSliceGroupChangeCycle},
+        {"OMX.TI.VideoEncode.Config.SliceGroupParams", VideoEncodeCustomConfigIndexSliceGroupParams},
+        /**/
+        {"OMX.TI.VideoEncode.Config.MIRRate", VideoEncodeCustomConfigIndexMIRRate},
+        {"OMX.TI.VideoEncode.Config.MaxMVperMB", VideoEncodeCustomConfigIndexMaxMVperMB},
+        {"OMX.TI.VideoEncode.Config.Intra4x4EnableIdc", VideoEncodeCustomConfigIndexIntra4x4EnableIdc},
+        {"OMX.TI.VideoEncode.Config.EncodingPreset", VideoEncodeCustomParamIndexEncodingPreset},
         {"OMX.TI.VideoEncode.Config.NALFormat", VideoEncodeCustomParamIndexNALFormat},
         {"OMX.TI.VideoEncode.Debug", VideoEncodeCustomConfigIndexDebug}
     };
     OMX_ERRORTYPE eError = OMX_ErrorNone;
- 
-    if (!hComponent || !pIndexType) 
+    int nIndex = 0;
+    const int nNumberIndices = sizeof(sVideoEncodeCustomIndex)/sizeof(sVideoEncodeCustomIndex[0]);
+
+    if (!hComponent || !pIndexType)
     {
         eError = OMX_ErrorBadParameter;
         goto OMX_CONF_CMD_BAIL;
     }
 
-    OMX_U32 nIndex = 0;
-    const OMX_U32 size = sizeof(sVideoEncodeCustomIndex)/sizeof(VIDENC_CUSTOM_DEFINITION);
-    for (nIndex = 0; nIndex < size; nIndex++)
+    for (nIndex = 0; nIndex < nNumberIndices; nIndex++)
     {
         if (!strcmp((const char*)cParameterName, (const char*)(&(sVideoEncodeCustomIndex[nIndex].cCustomName))))
         {
@@ -2647,7 +2699,7 @@
 
     pHandle = (OMX_COMPONENTTYPE*)hComponent;
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
-    
+
     /* Retrieve current state */
     if (pHandle && pHandle->pComponentPrivate) {
         /* Check for any pending state transition requests */
@@ -2661,15 +2713,15 @@
            }
 
            /* No pending state transitions */
-	   *pState = ((VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->eState;
-            eError = OMX_ErrorNone;
+           *pState = ((VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->eState;
+           eError = OMX_ErrorNone;
         }
         else {
-           /* Wait for component to complete state transition */
+                  /* Wait for component to complete state transition */
            clock_gettime(CLOCK_REALTIME, &abs_time);
            abs_time.tv_sec += mutex_timeout;
            abs_time.tv_nsec = 0;
-	   ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
+          ret = pthread_cond_timedwait(&(pComponentPrivate->StateChangeCondition), &(pComponentPrivate->mutexStateChangeRequest), &abs_time);
            if (!ret) {
               /* Component has completed state transitions*/
               *pState = ((VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate)->eState;
@@ -2684,7 +2736,7 @@
               return OMX_ErrorTimeout;
            }
         }
-     }
+    }
      else {
         eError = OMX_ErrorInvalidComponent;
         *pState = OMX_StateInvalid;
@@ -2709,7 +2761,7 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-static OMX_ERRORTYPE EmptyThisBuffer (OMX_IN OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE EmptyThisBuffer (OMX_IN OMX_HANDLETYPE hComponent,
                                       OMX_IN OMX_BUFFERHEADERTYPE* pBufHead)
 {
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
@@ -2740,13 +2792,13 @@
     if(!hTunnelComponent)
     {
         if (pBufHead->nInputPortIndex != 0x0  ||
-            pBufHead->nOutputPortIndex != OMX_NOPORT) 
+            pBufHead->nOutputPortIndex != OMX_NOPORT)
         {
             OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadPortIndex,
                                    pComponentPrivate->dbg, OMX_PRBUFFER4,
                                    "Emptying buffer on invalid port.\n");
         }
-        
+
         if (pComponentPrivate->eState != OMX_StateExecuting &&
             pComponentPrivate->eState != OMX_StatePause)
         {
@@ -2780,11 +2832,11 @@
     pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_COMPONENT;
     pBufferPrivate->bReadFromPipe = OMX_FALSE;
     nRet = write(pComponentPrivate->nFilled_iPipe[1],
-                 &(pBufHead), 
+                 &(pBufHead),
                  sizeof(pBufHead));
     if (nRet == -1)
     {
-    	pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
+        pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorHardware,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
                                "failed to write to nFilled_iPipe.\n");
@@ -2812,7 +2864,7 @@
 OMX_CONF_CMD_BAIL:
     return eError;
 }
-                
+
 /*----------------------------------------------------------------------------*/
 /**
   *  FillThisBuffer() Sets application callbacks to the component
@@ -2828,16 +2880,16 @@
   *         OMX_Error_BadParameter   The input parameter pointer is null
   **/
 /*----------------------------------------------------------------------------*/
-static OMX_ERRORTYPE FillThisBuffer (OMX_IN OMX_HANDLETYPE hComponent, 
+static OMX_ERRORTYPE FillThisBuffer (OMX_IN OMX_HANDLETYPE hComponent,
                                      OMX_IN OMX_BUFFERHEADERTYPE* pBufHead)
 {
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
-    VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL; 
+    VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     int nRet                                    = 0;
     VIDENC_BUFFER_PRIVATE* pBufferPrivate       = NULL;
     OMX_HANDLETYPE hTunnelComponent             = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDefOut   = NULL;
-    
+
     OMX_CONF_CHECK_CMD(hComponent, ((OMX_COMPONENTTYPE *) hComponent)->pComponentPrivate, 1);
 
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
@@ -2848,14 +2900,14 @@
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
     pBufHead->nFilledLen = 0;
     pBufferPrivate = (VIDENC_BUFFER_PRIVATE*)pBufHead->pOutputPortPrivate;
-	
-	if (!(pPortDefOut->bEnabled))
+
+    if (!(pPortDefOut->bEnabled))
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
                                "Filling buffer on disabled port.\n");
     }
-    
+
     if(!hTunnelComponent)
     {
         if (pBufHead->nOutputPortIndex != 0x1  ||
@@ -2867,7 +2919,7 @@
         }
 
         if (pComponentPrivate->eState != OMX_StateExecuting &&
-            pComponentPrivate->eState != OMX_StatePause) 
+            pComponentPrivate->eState != OMX_StatePause)
         {
             OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
                                    pComponentPrivate->dbg, OMX_PRBUFFER4,
@@ -2882,7 +2934,7 @@
                        PERF_ModuleHLMM);
 #endif
 
-    if (pComponentPrivate->pMarkBuf) 
+    if (pComponentPrivate->pMarkBuf)
     {
         pBufHead->hMarkTargetComponent = pComponentPrivate->pMarkBuf->hMarkTargetComponent;
         pBufHead->pMarkData = pComponentPrivate->pMarkBuf->pMarkData;
@@ -2908,11 +2960,11 @@
     pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_COMPONENT;
     pBufferPrivate->bReadFromPipe = OMX_FALSE;
     nRet = write(pComponentPrivate->nFree_oPipe[1],
-                 &(pBufHead), 
+                 &(pBufHead),
                  sizeof (pBufHead));
     if (nRet == -1)
     {
-		pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
+        pthread_mutex_unlock(&(pComponentPrivate->mVideoEncodeBufferMutex));
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorHardware,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
                                "failed to write to nFree_oPipe.\n");
@@ -2930,7 +2982,7 @@
     nRet = write(pComponentPrivate->nFree_oPipe[1],
                  &(pBufHead),
                  sizeof (pBufHead));
-    if (nRet == -1) 
+    if (nRet == -1)
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorHardware,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
@@ -2967,19 +3019,19 @@
     OMX_S32 nStop       = -1;
     OMX_U32 nTimeout    = 0;
     struct OMX_TI_Debug dbg;
-    
+
     OMX_CONF_CHECK_CMD(hComponent, ((OMX_COMPONENTTYPE *) hComponent)->pComponentPrivate, 1);
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
 
     dbg = pComponentPrivate->dbg;
 
-    pMemoryListHead=pComponentPrivate->pMemoryListHead; 
-    
+    pMemoryListHead=pComponentPrivate->pMemoryListHead;
+
 #ifdef __PERF_INSTRUMENTATION__
     PERF_Boundary(pComponentPrivate->pPERF,
                   PERF_BoundaryStart | PERF_BoundaryCleanup);
 #endif
-    while(1) 
+    while(1)
     {
         if(!(pComponentPrivate->bHandlingFatalError))
         {
@@ -2989,23 +3041,23 @@
                 pLcmlHandle = pComponentPrivate->pLCML;
                 if (pLcmlHandle != NULL)
                 {
-	                if (pComponentPrivate->bCodecStarted == OMX_TRUE || 
-    	            pComponentPrivate->bCodecLoaded == OMX_TRUE)
-	                {
-	                    eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
-	                                               EMMCodecControlDestroy,
-	                                               NULL);
-	                    if (eError != OMX_ErrorNone) 
-	                    {
+                    if (pComponentPrivate->bCodecStarted == OMX_TRUE ||
+                    pComponentPrivate->bCodecLoaded == OMX_TRUE)
+                    {
+                        eError = LCML_ControlCodec(((LCML_DSP_INTERFACE*)pLcmlHandle)->pCodecinterfacehandle,
+                                                   EMMCodecControlDestroy,
+                                                   NULL);
+                        if (eError != OMX_ErrorNone)
+                        {
                             OMX_PRDSP4(dbg, "error when requesting EMMCodecControlDestroy");
-	                        eError = OMX_ErrorUndefined;
-	                    }
+                            eError = OMX_ErrorUndefined;
+                        }
 
 #ifdef UNDER_CE
-	                    FreeLibrary(g_hLcmlDllHandle);
-	                    g_hLcmlDllHandle = NULL;
+                        FreeLibrary(g_hLcmlDllHandle);
+                        g_hLcmlDllHandle = NULL;
 #endif
-	                }
+                    }
                 }
             }
             break;
@@ -3031,8 +3083,8 @@
        pComponentPrivate->pLCML = NULL;
     }
 
-	
-	pComponentPrivate->bCodecStarted = OMX_FALSE;
+
+    pComponentPrivate->bCodecStarted = OMX_FALSE;
 
     nStop = -1;
 #ifdef __PERF_INSTRUMENTATION__
@@ -3041,8 +3093,8 @@
     OMX_PRCOMM2(dbg, "eCmd: -1 Send\n");
     nRet = write(pComponentPrivate->nCmdPipe[1],
                  &nStop,
-                 sizeof(OMX_COMMANDTYPE)); 
-    
+                 sizeof(OMX_COMMANDTYPE));
+
     /*Join the component thread*/
     /*pthread_cancel(ComponentThread);*/
 #ifdef UNDER_CE
@@ -3113,11 +3165,11 @@
         eError = OMX_ErrorHardware;
         OMX_PRCOMM4(dbg, "Error while closing data pipe (%d).\n", eErr);
     }
-    
+
     OMX_PRINT2(dbg, "pipes closed...\n");
 
 #ifndef UNDER_CE
-    OMX_TRACE2(dbg, "destroy mVideoEncodeBufferMutex -> %p\n", 
+    OMX_TRACE2(dbg, "destroy mVideoEncodeBufferMutex -> %p\n",
               &(pComponentPrivate->mVideoEncodeBufferMutex));
     /* Destroy Mutex for Buffer Tracking */
     nRet = pthread_mutex_destroy(&(pComponentPrivate->mVideoEncodeBufferMutex));
@@ -3136,8 +3188,8 @@
     pthread_cond_destroy(&pComponentPrivate->populate_cond);
     pthread_mutex_destroy(&pComponentPrivate->videoe_mutex_app);
     pthread_cond_destroy(&pComponentPrivate->unpopulate_cond);
-	pthread_cond_destroy(&pComponentPrivate->flush_cond);
-	pthread_cond_destroy(&pComponentPrivate->stop_cond);
+    pthread_cond_destroy(&pComponentPrivate->flush_cond);
+    pthread_cond_destroy(&pComponentPrivate->stop_cond);
 #else
     OMX_DestroyEvent(&(pComponentPrivate->InLoaded_event));
     OMX_DestroyEvent(&(pComponentPrivate->InIdle_event));
@@ -3145,7 +3197,7 @@
 
 #ifdef RESOURCE_MANAGER_ENABLED
     /* Deinitialize Resource Manager */
-    eError = RMProxy_DeinitalizeEx(OMX_COMPONENTTYPE_VIDEO); 
+    eError = RMProxy_DeinitalizeEx(OMX_COMPONENTTYPE_VIDEO);
     if (eError != OMX_ErrorNone)
     {
         OMX_PRMGR4(dbg, "Error returned from destroy ResourceManagerProxy thread\n");
@@ -3159,14 +3211,14 @@
     PERF_Done(pComponentPrivate->pPERF);
 #endif
 
-	pthread_mutex_destroy(&pComponentPrivate->mutexStateChangeRequest);
-	pthread_cond_destroy(&pComponentPrivate->StateChangeCondition);
+    pthread_mutex_destroy(&pComponentPrivate->mutexStateChangeRequest);
+    pthread_cond_destroy(&pComponentPrivate->StateChangeCondition);
 
     if (pComponentPrivate != NULL)
-    { 
-        VIDENC_FREE(pComponentPrivate, pMemoryListHead, dbg); 
+    {
+        VIDENC_FREE(pComponentPrivate, pMemoryListHead, dbg);
     }
-    
+
     /* Free Resources */
     OMX_VIDENC_ListDestroy(&dbg, pMemoryListHead);
 
@@ -3178,14 +3230,14 @@
 
 /*----------------------------------------------------------------------------*/
 /**
-  *  UseBuffer() 
+  *  UseBuffer()
   *
-  * 
-  * 
   *
-  * @param 
-  * @param 
-  * @param 
+  *
+  *
+  * @param
+  * @param
+  * @param
   *
   * @retval OMX_NoError              Success, ready to roll
   *         OMX_Error_BadParameter   The input parameter pointer is null
@@ -3199,29 +3251,29 @@
                         OMX_IN OMX_U32 nSizeBytes,
                         OMX_IN OMX_U8* pBuffer)
 {
-    VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL; 
+    VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef      = NULL;
     VIDEOENC_PORT_TYPE* pCompPort               = NULL;
     VIDENC_BUFFER_PRIVATE* pBufferPrivate       = NULL;
-    OMX_U32 nBufferCnt      = -1; 
+    OMX_U32 nBufferCnt      = -1;
     OMX_ERRORTYPE eError    = OMX_ErrorNone;
     OMX_HANDLETYPE hTunnelComponent = NULL;
     VIDENC_NODE* pMemoryListHead    = NULL;
-    
+
     OMX_CONF_CHECK_CMD(hComponent, ((OMX_COMPONENTTYPE *) hComponent)->pComponentPrivate, 1);
 
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, ppBufferHdr, pBuffer, 1);
 
-    if (nPortIndex == VIDENC_INPUT_PORT) 
+    if (nPortIndex == VIDENC_INPUT_PORT)
     {
        pPortDef = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     }
-    else if (nPortIndex == VIDENC_OUTPUT_PORT) 
+    else if (nPortIndex == VIDENC_OUTPUT_PORT)
     {
         pPortDef = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
-    }        
-    else 
+    }
+    else
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
@@ -3235,23 +3287,29 @@
                                "Using buffer on disabled port.\n");
     }
 
-    if (nSizeBytes < pPortDef->nBufferSize || pPortDef->bPopulated)
+    if (pPortDef->bPopulated)
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
-                               "Using duplicate buffer or of invalid size.\n");
+                               "Allocating duplicate buffer\n");
     }
-    
- 
+    if (nSizeBytes < pPortDef->nBufferSize)
+    {
+        OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter,
+            pComponentPrivate->dbg, OMX_PRBUFFER4,
+            "Allocating invalid size buffer: nBufferSize: %lu nSizeBytes: %lu\n", pPortDef->nBufferSize, nSizeBytes);
+    }
+
+
     if (pComponentPrivate->eState == OMX_StateInvalid)
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorInvalidState,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
                                "Using buffer in invalid state.\n");
     }
-    
+
     pMemoryListHead=pComponentPrivate->pMemoryListHead;
-    
+
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_ReceivedBuffer(pComponentPrivate->pPERF,
@@ -3259,7 +3317,7 @@
                         PERF_ModuleHLMM);
 #endif
 
-    nBufferCnt       = pComponentPrivate->pCompPort[nPortIndex]->nBufferCnt; 
+    nBufferCnt       = pComponentPrivate->pCompPort[nPortIndex]->nBufferCnt;
     hTunnelComponent = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->hTunnelComponent;
     pCompPort        = pComponentPrivate->pCompPort[nPortIndex];
     pBufferPrivate   = pCompPort->pBufferPrivate[nBufferCnt];
@@ -3279,13 +3337,13 @@
         /* set direction dependent fields */
         if (pPortDef->eDir == OMX_DirInput)
         {
-            pBufferPrivate->pBufferHdr->nInputPortIndex  = nPortIndex; 
-            pBufferPrivate->pBufferHdr->nOutputPortIndex = pCompPort->nTunnelPort; 
-        } 
+            pBufferPrivate->pBufferHdr->nInputPortIndex  = nPortIndex;
+            pBufferPrivate->pBufferHdr->nOutputPortIndex = pCompPort->nTunnelPort;
+        }
         else
         {
             pBufferPrivate->pBufferHdr->nInputPortIndex  = pCompPort->nTunnelPort;
-            pBufferPrivate->pBufferHdr->nOutputPortIndex = nPortIndex; 
+            pBufferPrivate->pBufferHdr->nOutputPortIndex = nPortIndex;
         }
     }
     else
@@ -3295,7 +3353,7 @@
             pBufferPrivate->pBufferHdr->nInputPortIndex  = VIDENC_INPUT_PORT;
             pBufferPrivate->pBufferHdr->nOutputPortIndex = OMX_NOPORT;
         }
-        else 
+        else
         {
             pBufferPrivate->pBufferHdr->nInputPortIndex  = OMX_NOPORT;
             pBufferPrivate->pBufferHdr->nOutputPortIndex = VIDENC_OUTPUT_PORT;
@@ -3332,8 +3390,8 @@
     eError = OMX_VIDENC_Allocate_DSPResources(pComponentPrivate, nPortIndex);
     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
                           "Failed to allocate DSP resources.\n");
-    
-    OMX_CONF_CIRCULAR_BUFFER_ADD_NODE(pComponentPrivate, 
+
+    OMX_CONF_CIRCULAR_BUFFER_ADD_NODE(pComponentPrivate,
                                       pComponentPrivate->sCircularBuffer);
     pCompPort->nBufferCnt++;
     if(pCompPort->nBufferCnt == pPortDef->nBufferCountActual)
@@ -3353,14 +3411,14 @@
 
 /*----------------------------------------------------------------------------*/
 /**
-  *  FreeBuffer() 
+  *  FreeBuffer()
   *
-  * 
-  * 
   *
-  * @param 
-  * @param 
-  * @param 
+  *
+  *
+  * @param
+  * @param
+  * @param
   *
   * @retval OMX_NoError              Success, ready to roll
   *         OMX_Error_BadParameter   The input parameter pointer is null
@@ -3389,15 +3447,15 @@
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, 1, 1);
     /*OMX_CONF_CHK_VERSION(pBufHead, OMX_BUFFERHEADERTYPE, eError); Makes CONF_FlushTest Fail*/
-        
-    pHandle = (OMX_COMPONENTTYPE*)hComponent; 
+
+    pHandle = (OMX_COMPONENTTYPE*)hComponent;
 
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
     pCompPort = pComponentPrivate->pCompPort[nPortIndex];
     pPortDefOut = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
     pPortDef = pComponentPrivate->pCompPort[nPortIndex]->pPortDef;
     nBufferCnt = pComponentPrivate->pCompPort[nPortIndex]->nBufferCnt;
-    
+
     eCompressionFormat = pPortDefOut->format.video.eCompressionFormat;
 
     if (nPortIndex == VIDENC_INPUT_PORT)
@@ -3405,7 +3463,7 @@
         pBufferPrivate = pBufHead->pInputPortPrivate;
         if (pBufferPrivate != NULL)
         {
-			if (pBufferPrivate->pUalgParam != NULL)
+            if (pBufferPrivate->pUalgParam != NULL)
             {
                 pTemp = (char*)pBufferPrivate->pUalgParam;
                 pTemp -= 128;
@@ -3442,21 +3500,22 @@
                 }
             }
             VIDENC_FREE(pBufferPrivate->pUalgParam, pMemoryListHead, pComponentPrivate->dbg);
-    	}
+        }
     }
-    else 
+    else
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadPortIndex,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
                                "Freeing buffer on invalid port index.\n");
     }
-    
-    if (pPortDef->bEnabled && pComponentPrivate->eState != OMX_StateIdle)
+
+    if (pPortDef->bEnabled && pComponentPrivate->eState != OMX_StateIdle && pComponentPrivate->eState != OMX_StateInvalid)
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
                                "Freeing buffer in invalid state or on a disabled port.\n");
     }
+    OMX_CONF_CHECK_CMD(pBufferPrivate, 1, 1);
 
 #ifdef __PERF_INSTRUMENTATION__
     PERF_SendingBuffer(pComponentPrivate->pPERF,
@@ -3471,7 +3530,7 @@
         if (pBufHead->pBuffer != NULL)
         {
             pBufHead->pBuffer -= 128;
-            pBufHead->pBuffer = (unsigned char*)pBufHead->pBuffer;             
+            pBufHead->pBuffer = (unsigned char*)pBufHead->pBuffer;
             VIDENC_FREE(pBufHead->pBuffer, pMemoryListHead, pComponentPrivate->dbg);
         }
     }
@@ -3484,16 +3543,16 @@
         }
         nCount++;
     }
-    
+
     if (pBufHead != NULL)
     {
         VIDENC_FREE(pBufHead, pMemoryListHead, pComponentPrivate->dbg);
     }
 
-    OMX_CONF_CIRCULAR_BUFFER_DELETE_NODE(pComponentPrivate, 
+    OMX_CONF_CIRCULAR_BUFFER_DELETE_NODE(pComponentPrivate,
                                          pComponentPrivate->sCircularBuffer);
     pCompPort->nBufferCnt--;
-    if (pCompPort->nBufferCnt == 0) 
+    if (pCompPort->nBufferCnt == 0)
     {
         pPortDef->bPopulated = OMX_FALSE;
 
@@ -3505,35 +3564,35 @@
            OMX_SignalEvent(&(pComponentPrivate->InIdle_event));
 #endif
     }
-    
-    if (pPortDef->bEnabled && 
-        (pComponentPrivate->eState == OMX_StateIdle || 
-         pComponentPrivate->eState == OMX_StateExecuting  || 
+
+    if (pPortDef->bEnabled &&
+        (pComponentPrivate->eState == OMX_StateIdle ||
+         pComponentPrivate->eState == OMX_StateExecuting  ||
          pComponentPrivate->eState == OMX_StatePause))
     {
-#ifdef  __KHRONOS_CONF__         
-         if(!pComponentPrivate->bPassingIdleToLoaded) 
-#endif         
-             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate, 
-                                      OMX_EventError, 
-                                      OMX_ErrorPortUnpopulated, 
+#ifdef  __KHRONOS_CONF__
+         if(!pComponentPrivate->bPassingIdleToLoaded)
+#endif
+             OMX_VIDENC_EVENT_HANDLER(pComponentPrivate,
+                                      OMX_EventError,
+                                      OMX_ErrorPortUnpopulated,
                                       nPortIndex,
-                                      NULL);     
+                                      NULL);
     }
-OMX_CONF_CMD_BAIL: 
+OMX_CONF_CMD_BAIL:
     return eError;
 }
 
 /*----------------------------------------------------------------------------*/
 /**
-  *  AllocateBuffer() 
+  *  AllocateBuffer()
   *
-  * 
-  * 
   *
-  * @param 
-  * @param 
-  * @param 
+  *
+  *
+  * @param
+  * @param
+  * @param
   *
   * @retval OMX_NoError              Success, ready to roll
   *         OMX_Error_BadParameter   The input parameter pointer is null
@@ -3550,8 +3609,8 @@
     VIDENC_COMPONENT_PRIVATE* pComponentPrivate = NULL;
     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef      = NULL;
     VIDEOENC_PORT_TYPE* pCompPort               = NULL;
-    OMX_HANDLETYPE hTunnelComponent             = NULL; 
-    VIDENC_BUFFER_PRIVATE* pBufferPrivate       = NULL; 
+    OMX_HANDLETYPE hTunnelComponent             = NULL;
+    VIDENC_BUFFER_PRIVATE* pBufferPrivate       = NULL;
     OMX_U32 nBufferCnt                          = -1;
     OMX_ERRORTYPE eError                        = OMX_ErrorNone;
     VIDENC_NODE* pMemoryListHead                = NULL;
@@ -3560,17 +3619,17 @@
 
     pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)(((OMX_COMPONENTTYPE*)hComponent)->pComponentPrivate);
     OMX_DBG_CHECK_CMD(pComponentPrivate->dbg, pBufHead, 1, 1);
-    
+
     pHandle = (OMX_COMPONENTTYPE*)hComponent;
 
-    if (nPortIndex == VIDENC_INPUT_PORT) 
+    if (nPortIndex == VIDENC_INPUT_PORT)
     {
        pPortDef = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef;
     }
     else if (nPortIndex == VIDENC_OUTPUT_PORT)
     {
         pPortDef = pComponentPrivate->pCompPort[VIDENC_OUTPUT_PORT]->pPortDef;
-    }        
+    }
     else
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter,
@@ -3582,22 +3641,28 @@
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorIncorrectStateOperation,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
                                "Allocating buffer on disabled port.\n");
-    }   
+    }
 
-    if (nSizeBytes < pPortDef->nBufferSize || pPortDef->bPopulated)
+    if (pPortDef->bPopulated)
     {
         OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter,
                                pComponentPrivate->dbg, OMX_PRBUFFER4,
-                               "Allocating duplicate buffer or of invalid size.\n");
+                               "Allocating duplicate buffer\n");
     }
-    
+    if (nSizeBytes < pPortDef->nBufferSize)
+    {
+        OMX_DBG_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter,
+            pComponentPrivate->dbg, OMX_PRBUFFER4,
+            "Allocating invalid size buffer: nBufferSize: %lu nSizeBytes: %lu\n", pPortDef->nBufferSize, nSizeBytes);
+    }
+
     pMemoryListHead = pComponentPrivate->pMemoryListHead;
     pCompPort = pComponentPrivate->pCompPort[nPortIndex];
     nBufferCnt = pComponentPrivate->pCompPort[nPortIndex]->nBufferCnt;
     hTunnelComponent = pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->hTunnelComponent;
     pBufferPrivate = pComponentPrivate->pCompPort[nPortIndex]->pBufferPrivate[nBufferCnt];
 
-    VIDENC_MALLOC(*pBufHead, 
+    VIDENC_MALLOC(*pBufHead,
                   sizeof(OMX_BUFFERHEADERTYPE),
                   OMX_BUFFERHEADERTYPE,
                   pMemoryListHead, pComponentPrivate->dbg);
@@ -3613,16 +3678,16 @@
         (*pBufHead)->nOutputPortIndex = VIDENC_OUTPUT_PORT;
     }
 
-    VIDENC_MALLOC((*pBufHead)->pBuffer, 
-                  nSizeBytes + 256, 
-                  OMX_U8, 
+    VIDENC_MALLOC((*pBufHead)->pBuffer,
+                  nSizeBytes + 256,
+                  OMX_U8,
                   pMemoryListHead, pComponentPrivate->dbg);
     ((*pBufHead)->pBuffer) += 128;
     ((*pBufHead)->pBuffer) = (unsigned char*)((*pBufHead)->pBuffer);
     (*pBufHead)->nSize       = sizeof(OMX_BUFFERHEADERTYPE);
     (*pBufHead)->nVersion    = pPortDef->nVersion;
     (*pBufHead)->pAppPrivate = pAppPrivate;
-    (*pBufHead)->nAllocLen   = nSizeBytes; 
+    (*pBufHead)->nAllocLen   = nSizeBytes;
     pBufferPrivate->pBufferHdr = *pBufHead;
 
 #ifdef __PERF_INSTRUMENTATION__
@@ -3638,7 +3703,7 @@
             pComponentPrivate->nInBufferSize = nSizeBytes;
         }
     }
-    else 
+    else
     {
         pBufferPrivate->pBufferHdr->pOutputPortPrivate = pBufferPrivate;
         if(!pComponentPrivate->nOutBufferSize || (pComponentPrivate->nOutBufferSize > nSizeBytes)) {
@@ -3647,7 +3712,7 @@
     }
     pBufferPrivate->bAllocByComponent = OMX_TRUE;
 
-    if (hTunnelComponent != NULL) 
+    if (hTunnelComponent != NULL)
     {
         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_TUNNELEDCOMP;
     }
@@ -3655,14 +3720,14 @@
     {
         pBufferPrivate->eBufferOwner = VIDENC_BUFFER_WITH_CLIENT;
     }
-   
+
     eError = OMX_VIDENC_Allocate_DSPResources(pComponentPrivate, nPortIndex);
     OMX_DBG_BAIL_IF_ERROR(eError, pComponentPrivate->dbg, OMX_PRDSP4,
                           "Failed to allocate DSP resources.\n");
-   
-    OMX_CONF_CIRCULAR_BUFFER_ADD_NODE(pComponentPrivate, 
+
+    OMX_CONF_CIRCULAR_BUFFER_ADD_NODE(pComponentPrivate,
                                       pComponentPrivate->sCircularBuffer);
-                                      
+
     pCompPort->nBufferCnt++;
     if(pCompPort->nBufferCnt == pPortDef->nBufferCountActual)
     {
@@ -3673,7 +3738,7 @@
         pthread_mutex_unlock(&pComponentPrivate->videoe_mutex_app);
 #else
         OMX_SignalEvent(&(pComponentPrivate->InLoaded_event));
-#endif	
+#endif
     }
 
 OMX_CONF_CMD_BAIL:
@@ -3683,22 +3748,22 @@
 
 /*----------------------------------------------------------------------------*/
 /**
-  *  VerifyTunnelConnection() 
+  *  VerifyTunnelConnection()
   *
-  * 
-  * 
   *
-  * @param         
-  * @param    
-  * @param 
+  *
+  *
+  * @param
+  * @param
+  * @param
   *
   * @retval OMX_NoError              Success, ready to roll
   *         OMX_Error_BadParameter   The input parameter pointer is null
   **/
 /*----------------------------------------------------------------------------*/
 
-OMX_ERRORTYPE VerifyTunnelConnection(VIDEOENC_PORT_TYPE* pPort, 
-                                     OMX_HANDLETYPE hTunneledComp, 
+OMX_ERRORTYPE VerifyTunnelConnection(VIDEOENC_PORT_TYPE* pPort,
+                                     OMX_HANDLETYPE hTunneledComp,
                                      OMX_PARAM_PORTDEFINITIONTYPE* pPortDef,
                                      struct OMX_TI_Debug *dbg)
 {
@@ -3712,7 +3777,7 @@
    sPortDef.nVersion.s.nVersionMinor = 0x0;
    sPortDef.nPortIndex = pPort->nTunnelPort;
 
-   eError = OMX_GetParameter(hTunneledComp, 
+   eError = OMX_GetParameter(hTunneledComp,
                              OMX_IndexParamPortDefinition,
                              &sPortDef);
    if (eError != OMX_ErrorNone)
@@ -3725,7 +3790,7 @@
        case OMX_PortDomainOther:
            if (sPortDef.format.other.eFormat!= pPortDef->format.other.eFormat)
            {
-               pPort->hTunnelComponent = 0; 
+               pPort->hTunnelComponent = 0;
                pPort->nTunnelPort      = 0;
                return OMX_ErrorPortsNotCompatible;
            }
@@ -3733,7 +3798,7 @@
        case OMX_PortDomainAudio:
            if (sPortDef.format.audio.eEncoding != pPortDef->format.audio.eEncoding)
            {
-               pPort->hTunnelComponent = 0; 
+               pPort->hTunnelComponent = 0;
                pPort->nTunnelPort      = 0;
                return OMX_ErrorPortsNotCompatible;
            }
@@ -3741,7 +3806,7 @@
        case OMX_PortDomainVideo:
            if (sPortDef.format.video.eCompressionFormat != pPortDef->format.video.eCompressionFormat)
            {
-               pPort->hTunnelComponent = 0; 
+               pPort->hTunnelComponent = 0;
                pPort->nTunnelPort      = 0;
                return OMX_ErrorPortsNotCompatible;
            }
@@ -3749,15 +3814,15 @@
        case OMX_PortDomainImage:
            if (sPortDef.format.image.eCompressionFormat != pPortDef->format.image.eCompressionFormat)
            {
-               pPort->hTunnelComponent = 0; 
+               pPort->hTunnelComponent = 0;
                pPort->nTunnelPort      = 0;
                return OMX_ErrorPortsNotCompatible;
            }
            break;
-       default: 
+       default:
            pPort->hTunnelComponent = 0;
            pPort->nTunnelPort      = 0;
-           return OMX_ErrorPortsNotCompatible; 
+           return OMX_ErrorPortsNotCompatible;
    }
 
 OMX_CONF_CMD_BAIL:
@@ -3770,7 +3835,7 @@
   * Check if the component is TI component.
   * @param hTunneledComp Component Tunnel Pipe
   * @retval OMX_TRUE   Input is a TI component.
-  *             OMX_FALSE  Input is a not a TI component. 
+  *             OMX_FALSE  Input is a not a TI component.
   *
   **/
 /*-------------------------------------------------------------------*/
@@ -3790,33 +3855,33 @@
 
     if (pTunnelcComponentName == NULL)
     {
-        eError = OMX_ErrorInsufficientResources;  
+        eError = OMX_ErrorInsufficientResources;
         OMX_TRACE4(*dbg, "Error in video encoder OMX_ErrorInsufficientResources %d\n",__LINE__);
-        goto EXIT;                                
+        goto EXIT;
     }
 
     pTunnelComponentVersion = malloc(sizeof(OMX_VERSIONTYPE));
     if (pTunnelComponentVersion == NULL)
     {
         OMX_TRACE4(*dbg, "Error in video encoder OMX_ErrorInsufficientResources %d\n",__LINE__);
-        eError = OMX_ErrorInsufficientResources;  
-        goto EXIT;                                
+        eError = OMX_ErrorInsufficientResources;
+        goto EXIT;
     }
 
     pSpecVersion = malloc(sizeof(OMX_VERSIONTYPE));
     if (pSpecVersion == NULL)
     {
         OMX_TRACE4(*dbg, "Error in video encoder OMX_ErrorInsufficientResources %d\n",__LINE__);
-        eError = OMX_ErrorInsufficientResources;  
-        goto EXIT;                                
+        eError = OMX_ErrorInsufficientResources;
+        goto EXIT;
     }
 
     pComponentUUID = malloc(sizeof(OMX_UUIDTYPE));
     if (pComponentUUID == NULL)
     {
         OMX_TRACE4(*dbg, "Error in video encoder OMX_ErrorInsufficientResources %d\n",__LINE__);
-        eError = OMX_ErrorInsufficientResources;  
-        goto EXIT;                                
+        eError = OMX_ErrorInsufficientResources;
+        goto EXIT;
     }
 
     eError = OMX_GetComponentVersion (hComp, pTunnelcComponentName, pTunnelComponentVersion, pSpecVersion, pComponentUUID);
@@ -3856,7 +3921,7 @@
   **/
 /*----------------------------------------------------------------------------*/
 
-OMX_ERRORTYPE ComponentTunnelRequest(OMX_IN  OMX_HANDLETYPE hComponent, 
+OMX_ERRORTYPE ComponentTunnelRequest(OMX_IN  OMX_HANDLETYPE hComponent,
                                      OMX_IN  OMX_U32 nPort,
                                      OMX_IN  OMX_HANDLETYPE hTunneledComp,
                                      OMX_IN  OMX_U32 nTunneledPort,
@@ -3874,29 +3939,29 @@
         pPort->nTunnelPort = 0;
         pPort->eSupplierSetting = OMX_BufferSupplyUnspecified;
     }
-    else 
+    else
     {
         pHandle = (OMX_COMPONENTTYPE*)hComponent;
-        if (!pHandle->pComponentPrivate) 
+        if (!pHandle->pComponentPrivate)
         {
             OMX_CONF_SET_ERROR_BAIL(eError, OMX_ErrorBadParameter);
         }
         pComponentPrivate = (VIDENC_COMPONENT_PRIVATE*)pHandle->pComponentPrivate;
         pPort = pComponentPrivate->pCompPort[nPort];
-        
-        if (pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef->eDir != OMX_DirInput && 
+
+        if (pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef->eDir != OMX_DirInput &&
             pComponentPrivate->pCompPort[VIDENC_INPUT_PORT]->pPortDef->eDir != OMX_DirOutput)
         {
             return OMX_ErrorBadParameter;
         }
 
-		/* Check if the other component is developed by TI */
+        /* Check if the other component is developed by TI */
         if (IsTIOMXComponent(hTunneledComp, &pComponentPrivate->dbg) != OMX_TRUE)
         {
-		    eError = OMX_ErrorTunnelingUnsupported;
-			goto OMX_CONF_CMD_BAIL;
-		}
-		pPort->hTunnelComponent = hTunneledComp;
+            eError = OMX_ErrorTunnelingUnsupported;
+            goto OMX_CONF_CMD_BAIL;
+        }
+        pPort->hTunnelComponent = hTunneledComp;
         pPort->nTunnelPort = nTunneledPort;
 
         if (pPort->pPortDef->eDir == OMX_DirOutput)
@@ -3917,7 +3982,7 @@
                                        pComponentPrivate->dbg, OMX_PRCOMM3,
                                        "VerifyTunnelConnection failed.\n");
             }
-           
+
             /* If specified obey output port's preferences. Otherwise choose output */
             pPort->eSupplierSetting = pTunnelSetup->eSupplier;
             if (OMX_BufferSupplyUnspecified == pPort->eSupplierSetting)
@@ -3932,7 +3997,7 @@
             sBufferSupplier.nPortIndex = nTunneledPort;
             sBufferSupplier.eBufferSupplier = pPort->eSupplierSetting;
 
-            eError = OMX_SetParameter(hTunneledComp, 
+            eError = OMX_SetParameter(hTunneledComp,
                                       OMX_IndexParamCompBufferSupplier,
                                       &sBufferSupplier);
             eError = OMX_GetParameter(hTunneledComp,
@@ -3955,7 +4020,7 @@
 
 /*----------------------------------------------------------------------------*/
 /**
-  *  ComponentRoleEnum() 
+  *  ComponentRoleEnum()
   *
   *
   * @param pComp         handle for this instance of the component
@@ -3973,15 +4038,15 @@
 
     if (hComponent==NULL)
     {
-        eError= OMX_ErrorBadParameter;
         goto OMX_CONF_CMD_BAIL;
-    }
+        eError= OMX_ErrorBadParameter;
+        }
 
     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
     {
diff --git a/omx/video/src/openmax_il/video_encode/test/Android.mk b/omx/video/src/openmax_il/video_encode/test/Android.mk
index 62badfe..08c2eec 100755
--- a/omx/video/src/openmax_il/video_encode/test/Android.mk
+++ b/omx/video/src/openmax_il/video_encode/test/Android.mk
@@ -1,4 +1,3 @@
-ifeq ($(BUILD_VIDEO_ENC_TEST),1)

 LOCAL_PATH:= $(call my-dir)

 

 include $(CLEAR_VARS)

@@ -20,4 +19,3 @@
 LOCAL_MODULE:= VideoEncTest

 

 include $(BUILD_EXECUTABLE)

-endif

diff --git a/omx/video/src/openmax_il/video_encode/test/VideoEncTest.c b/omx/video/src/openmax_il/video_encode/test/VideoEncTest.c
index 31f78c8..6f98ca9 100755
--- a/omx/video/src/openmax_il/video_encode/test/VideoEncTest.c
+++ b/omx/video/src/openmax_il/video_encode/test/VideoEncTest.c
@@ -18,13 +18,13 @@
 *             Texas Instruments OMAP(TM) Platform Software
 *  (c) Copyright Texas Instruments, Incorporated.  All Rights Reserved.
 *
-*  Use of this software is controlled by the terms and conditions found 
+*  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * =========================================================================== */
 /**
 * @file VideoEncTest.c
 *
-* This file implements OMX Component for MPEG-4 encoder that 
+* This file implements OMX Component for MPEG-4 encoder that
 * is fully compliant with the OMX specification 1.5.
 *
 * @path  $(CSLPATH)\src
@@ -32,40 +32,40 @@
 * @rev  0.1
 */
 /* -------------------------------------------------------------------------- */
-/* ============================================================================= 
-*! 
-*! Revision History 
+/* =============================================================================
+*!
+*! Revision History
 *! ===================================
 *!
-*! 02-Feb-2006 mf: Revisions appear in reverse chronological order; 
-*! that is, newest first.  The date format is dd-Mon-yyyy.  
+*! 02-Feb-2006 mf: Revisions appear in reverse chronological order;
+*! that is, newest first.  The date format is dd-Mon-yyyy.
 * =========================================================================== */
 #define _XOPEN_SOURCE 600
 
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h> 
-#include <string.h> 
-#include <sched.h> 
-#include <unistd.h> 
-#include <sys/types.h> 
+#include <stdarg.h>
+#include <string.h>
+#include <sched.h>
+#include <unistd.h>
+#include <sys/types.h>
 #include <sys/select.h>
-#include <time.h> 
-#include <OMX_Component.h> 
+#include <time.h>
+#include <OMX_Component.h>
 #include <getopt.h>
 #include <sys/types.h>
 
 #define DSP_MMU_FAULT_HANDLING
 
-#ifdef DSP_MMU_FAULT_HANDLING 
+#ifdef DSP_MMU_FAULT_HANDLING
 #include <dbapi.h>
 #include <DSPManager.h>
 #include <DSPProcessor.h>
 #include <DSPProcessor_OEM.h>
 #endif
 
-/* For debug printing 
+/* For debug printing
    Add -DAPP_DEBUG to CFLAGS in test Makefile */
 #define KHRONOS_1_2
 #if VIDENCTEST_DEBUG
@@ -77,11 +77,14 @@
     #define VIDENCTEST_MAX_TIME_OUTS 1000000
 #endif
 #define VIDENCTEST_UNUSED_ARG(arg) (void)(arg)
-#if 0 
-    #define VIDENCTEST_COLOR 
+#if 0
+    #define VIDENCTEST_COLOR
     #define VIDENCTEST_PRINT_PARAMS
 #endif
 
+#define VIDENCTEST_USE_DEFAULT_VALUE (OMX_U32)-1
+#define VIDENCTEST_USE_DEFAULT_VALUE_UI (unsigned int)-1
+
 #define VIDENCTEST_MALLOC(_p_, _s_, _c_, _h_)                           \
     _p_ = (_c_*)malloc(_s_);                                            \
     if (_p_ == NULL) {                                                  \
@@ -114,21 +117,20 @@
         VIDENCTEST_HandleError(pAppData, _e_);               \
         goto EXIT;                                          \
     }                                                       \
-    
+
 #define VIDENCTEST_CHECK_EXIT(_e_, _s_)                     \
     if (_e_ != OMX_ErrorNone){                              \
         printf("\n------VIDENCTEST ERROR-------\n %x : %s \n", _e_, _s_);  \
         goto EXIT;                                          \
-    }      
-    
-    
+    }
+
 #if 1
     #define CALC_TIME
 #endif
 
 #define MAX_UNRESPONSIVE_COUNT 50
-#define NUM_OF_IN_BUFFERS 4 
-#define NUM_OF_OUT_BUFFERS 4 
+#define NUM_OF_IN_BUFFERS 4
+#define NUM_OF_OUT_BUFFERS 4
 #define MAX_NUM_OF_PORTS 16
 #define MAX_EVENTS 256
 /*
@@ -174,7 +176,7 @@
     }
 
 
-static const int iQ16_Const = 1 << 16;
+/*static const int iQ16_Const = 1 << 16;*/
 static const float fQ16_Const = (float)(1 << 16);
 
 /*static float Q16Tof(int nQ16)
@@ -182,34 +184,35 @@
     return nQ16 / fQ16_Const;
 }*/
 
-static float fToQ16(float f)
+static int fToQ16(float f)
 {
     return (int)(f*fQ16_Const);
 }
-    
-#ifdef DSP_MMU_FAULT_HANDLING 
+
+#ifdef DSP_MMU_FAULT_HANDLING
 static int bInvalid_state;
 int LoadBaseImage();
 #endif
-    
-void VIDENCTEST_Log(int iLineNum, const char *szFunctionName, const char *strFormat, ...)
+
+void VIDENCTEST_Log(const char *szFileName, int iLineNum, const char *szFunctionName, const char *strFormat, ...)
 {
     va_list list;
-
-    fprintf(stdout, "%d. %s():", iLineNum, szFunctionName);
+    VIDENCTEST_UNUSED_ARG(szFileName);
+    VIDENCTEST_UNUSED_ARG(iLineNum);
+    fprintf(stdout, "%s():", szFunctionName);
     va_start(list, strFormat);
     vfprintf(stdout, strFormat, list);
     va_end(list);
 }
 
 #ifdef __VIDENCTEST_DPRINT__
-    #define VIDENCTEST_DPRINT(STR, ARG...) VIDENCTEST_Log(__LINE__, __FUNCTION__, STR, ##ARG) 
+    #define VIDENCTEST_DPRINT(STR, ARG...) VIDENCTEST_Log(__FILE__, __LINE__, __FUNCTION__, STR, ##ARG)
 #else
     #define VIDENCTEST_DPRINT(...)
 #endif
 
 #ifdef __VIDENCTEST_MTRACE__
-    #define VIDENCTEST_MTRACE(STR, ARG...) VIDENCTEST_Log(__LINE__, __FUNCTION__, STR, ##ARG) 
+    #define VIDENCTEST_MTRACE(STR, ARG...) VIDENCTEST_Log(__FILE__, __LINE__, __FUNCTION__, STR, ##ARG)
 #else
     #define VIDENCTEST_MTRACE(...)
 #endif
@@ -346,7 +349,7 @@
     OMX_U32 nTargetFrameRate;
     OMX_U32 nAIRRate;
     OMX_U32 nTargetBitRate;
-    OMX_U32 nStartPortNumber; 
+    OMX_U32 nStartPortNumber;
     OMX_U32 nPorts;
     OMX_U8 nInBufferCount;
     OMX_U8 nOutBufferCount;
@@ -356,7 +359,7 @@
     OMX_BOOL bExit;
     OMX_U32 nSizeIn;
     OMX_U32 nSizeOut;
-    
+
     OMX_U32 nReferenceFrame;
     OMX_U32 nNumberOfTimesTodo;
     OMX_U32 nNumberOfTimesDone;
@@ -367,8 +370,10 @@
     OMX_U32 nMIRRate;
     OMX_U32 nResynchMarkerSpacing;
     unsigned int nEncodingPreset;
+    OMX_U8 nUnrestrictedMV;
     OMX_U8 NalFormat;
     OMX_U8 bLastOutBuffer;
+    OMX_U32  nQPIoF;
 } MYDATATYPE;
 
 typedef struct EVENT_PRIVATE {
@@ -393,10 +398,10 @@
   * Creates the List Head of the Component Memory List.
   *
   * @param pListHead VIDENCTEST_NODE double pointer with the List Header of the Memory List.
-  *                
-  * @retval OMX_ErrorNone 
+  *
+  * @retval OMX_ErrorNone
   *               OMX_ErrorInsufficientResources if the malloc fails
-  *         
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_ListCreate(struct VIDENCTEST_NODE** pListHead)
@@ -404,15 +409,15 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
 
     *pListHead = (VIDENCTEST_NODE*)malloc(sizeof(VIDENCTEST_NODE)); /* need to malloc!!! */
-    if (*pListHead == NULL) {                                      
-        VIDENCTEST_DPRINT("malloc() error.\n");                    
-        eError = OMX_ErrorInsufficientResources;            
-        goto EXIT;                                          
-    }      
-     
+    if (*pListHead == NULL) {
+        VIDENCTEST_DPRINT("malloc() error.\n");
+        eError = OMX_ErrorInsufficientResources;
+        goto EXIT;
+    }
+
     VIDENCTEST_DPRINT("Create MemoryListHeader[%p]\n", *pListHead);
     memset(*pListHead, 0x0, sizeof(VIDENCTEST_NODE));
-    
+
 EXIT:
     return eError;
 }
@@ -425,9 +430,9 @@
   *
   * @param pListHead VIDENCTEST_NODE Points List Header of the Memory List.
   *                pData OMX_PTR points to the new allocated data.
-  * @retval OMX_ErrorNone 
+  * @retval OMX_ErrorNone
   *               OMX_ErrorInsufficientResources if the malloc fails
-  *         
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
@@ -438,25 +443,25 @@
     VIDENCTEST_NODE* pNewNode = NULL;
 
     pNewNode = (VIDENCTEST_NODE*)malloc(sizeof(VIDENCTEST_NODE)); /* need to malloc!!! */
-    if (pNewNode == NULL) {                                      
-        VIDENCTEST_DPRINT("malloc() error.\n");                    
-        eError = OMX_ErrorInsufficientResources;            
-        goto EXIT;                                          
-    }       
-    
-    memset(pNewNode, 0x0, sizeof(VIDENCTEST_NODE)); 
+    if (pNewNode == NULL) {
+        VIDENCTEST_DPRINT("malloc() error.\n");
+        eError = OMX_ErrorInsufficientResources;
+        goto EXIT;
+    }
+
+    memset(pNewNode, 0x0, sizeof(VIDENCTEST_NODE));
     pNewNode->pData = pData;
     pNewNode->pNext = NULL;
     VIDENCTEST_DPRINT("Add MemoryNode[%p] -> [%p]\n", pNewNode, pNewNode->pData);
-    
+
     pTmp = pListHead;
 
     while (pTmp->pNext != NULL) {
         pTmp = pTmp->pNext;
     }
     pTmp->pNext = pNewNode;
-   
-EXIT:    
+
+EXIT:
     return eError;
 }
 
@@ -468,9 +473,9 @@
   *
   * @param pListHead VIDENCTEST_NODE Points List Header of the Memory List.
   *                pData OMX_PTR points to the new allocated data.
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
@@ -505,10 +510,10 @@
   * Called inside OMX_ComponentDeInit()  Remove all nodes and free all the memory in the Component Memory List.
   *
   * @param pListHead VIDENCTEST_NODE Points List Header of the Memory List.
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
@@ -523,11 +528,11 @@
         pTmp = pNode->pNext;
         if (pTmp->pData != NULL) {
             VIDENCTEST_FREE(pTmp->pData, pListHead);
-        } 
+        }
         pNode->pNext = pTmp->pNext;
         VIDENCTEST_FREE(pTmp, pListHead);
     }
-    
+
     VIDENCTEST_DPRINT("Destroy MemoryListHeader[%p]\n", pListHead);
     free(pListHead);
     return eError;
@@ -540,10 +545,10 @@
   * Called inside OMX_ComponentDeInit()  Remove all nodes and free all the memory in the Component Memory List.
   *
   * @param pListHead VIDENCTEST_NODE Points List Header of the Memory List.
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 void VIDENCTEST_EventHandler(OMX_HANDLETYPE hComponent, MYDATATYPE* pAppData, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData)
@@ -552,7 +557,7 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_HANDLETYPE pHandle;
     VIDENCTEST_NODE* pListHead;
-    
+
     pHandle= pAppData->pHandle;
     pListHead = pAppData->pMemoryListHead;
     VIDENCTEST_UNUSED_ARG(hComponent);
@@ -567,7 +572,7 @@
     pEventPrivate->pAppData = pAppData;
     pEventPrivate->eEvent = eEvent;
     pEventPrivate->nData1 = nData1;
-    pEventPrivate->nData2 = nData2; 
+    pEventPrivate->nData2 = nData2;
     pEventPrivate->pEventData = pEventData;
 
     write(pAppData->eventPipe[1], &pEventPrivate, sizeof(pEventPrivate));
@@ -580,19 +585,18 @@
   *
   * Callback function when output buffer is done fill with h.264/mpeg4/h.263 data
   *
-  * @param 
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  * @param
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 void VIDENCTEST_FillBufferDone(OMX_HANDLETYPE hComponent, MYDATATYPE* pAppData, OMX_BUFFERHEADERTYPE* pBuffer)
 {
-    /*pAppData->nOutBufferCount++;*/
     VIDENCTEST_UNUSED_ARG(hComponent);
     VIDENCTEST_DPRINT("FillBufferDone :: %p \n", pBuffer);
-    write(pAppData->OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer)); 
+    write(pAppData->OpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
 }
 
 /*-----------------------------------------------------------------------------*/
@@ -601,18 +605,18 @@
   *
   * Callback function when and input buffer has been encoded. Returns an Empty Buffer.
   *
-  * @param 
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  * @param
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 void VIDENCTEST_EmptyBufferDone(OMX_HANDLETYPE hComponent, MYDATATYPE* pAppData, OMX_BUFFERHEADERTYPE* pBuffer)
 {
     VIDENCTEST_UNUSED_ARG(hComponent);
     VIDENCTEST_DPRINT("EmptyBufferDone :: %p \n", pBuffer);
-    write(pAppData->IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer)); 
+    write(pAppData->IpBuf_Pipe[1], &pBuffer, sizeof(pBuffer));
 }
 
 /*-----------------------------------------------------------------------------*/
@@ -621,11 +625,11 @@
   *
   * Fill buffer with data from the input file (YUV data 420/422 little endian/ 422 big endian).
   *
-  * @param 
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  * @param
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 int VIDENCTEST_fill_data(OMX_BUFFERHEADERTYPE *pBuf, FILE *fIn, int buffersize)
@@ -645,13 +649,13 @@
     nError = feof(fIn);
     if (nError != 0 ) {
         VIDENCTEST_DPRINT("EOS reached...\n");
-    }               
-    
+    }
+
     pBuf->nFilledLen = nRead;
     if (feof(fIn)) {
-        VIDENCTEST_DPRINT("Setting OMX_BUFFERFLAGE_EOS -> %p\n", pBuf);                
+        VIDENCTEST_DPRINT("Setting OMX_BUFFERFLAGE_EOS -> %p\n", pBuf);
         pBuf->nFlags = OMX_BUFFERFLAG_EOS;
-    }               
+    }
     return nRead;
 }
 
@@ -662,11 +666,11 @@
   * Function call when an error ocurrs. The function un-load and free all the resource
   * depending the eError recieved.
   * @param pHandle Handle of MYDATATYPE structure
-  * @param eError Error ocurred. 
- *  
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  * @param eError Error ocurred.
+ *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
@@ -677,10 +681,10 @@
     OMX_U32 nCounter;
     VIDENCTEST_NODE* pListHead;
     OMX_ERRORTYPE eErr = OMX_ErrorNone;
-    
+
     VIDENCTEST_DPRINT ("Enters to HandleError\n");
     pListHead = pAppData->pMemoryListHead;
-    
+
     switch (pAppData->eCurrentState) {
         case VIDENCTEST_StateReady:
         case VIDENCTEST_StateStarting:
@@ -692,26 +696,26 @@
         case VIDENCTEST_StateWaitEvent:
          VIDENCTEST_DPRINT ("Free buffers\n");
             if (pAppData->bAllocateOBuf == OMX_TRUE) {
-                for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {                   
-                    pAppData->pOBuffer[nCounter] -= 128;                        
+                for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
+                    pAppData->pOBuffer[nCounter] -= 128;
                     pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
                     VIDENCTEST_FREE(pAppData->pOBuffer[nCounter], pListHead);
                     pAppData->pOBuffer[nCounter] = NULL;
-                }  
+                }
             }
             for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
                 eError = OMX_FreeBuffer(pHandle, pAppData->pOutPortDef->nPortIndex, pAppData->pOutBuff[nCounter]);
             }
-            if (pAppData->bAllocateIBuf == OMX_TRUE) { 
-                for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {                      
+            if (pAppData->bAllocateIBuf == OMX_TRUE) {
+                for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
                     pAppData->pIBuffer[nCounter] -= 128;
-                    pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];                           
+                    pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];
                     VIDENCTEST_FREE(pAppData->pIBuffer[nCounter], pListHead);
                     pAppData->pIBuffer[nCounter] = NULL;
-                } 
+                }
             }
             for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
-                eError = OMX_FreeBuffer(pHandle, pAppData->pInPortDef->nPortIndex, pAppData->pInBuff[nCounter]);    
+                eError = OMX_FreeBuffer(pHandle, pAppData->pInPortDef->nPortIndex, pAppData->pInBuff[nCounter]);
             }
         case VIDENCTEST_StateLoaded:
             VIDENCTEST_DPRINT ("DeInit Component\n");
@@ -724,7 +728,7 @@
             if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
                 fclose(pAppData->fNalnd);
             }
-            
+
             eErr = close(pAppData->IpBuf_Pipe[0]);
             if (0 != eErr && OMX_ErrorNone == eError) {
                 eError = OMX_ErrorHardware;
@@ -742,7 +746,7 @@
                 eError = OMX_ErrorHardware;
                 VIDENCTEST_DPRINT ("Error while closing data pipe\n");
             }
-            
+
             eErr = close(pAppData->IpBuf_Pipe[1]);
             if (0 != eErr && OMX_ErrorNone == eError) {
                 eError = OMX_ErrorHardware;
@@ -769,14 +773,14 @@
         default:
             ;
     }
-    
-#ifdef DSP_MMU_FAULT_HANDLING 
+
+#ifdef DSP_MMU_FAULT_HANDLING
     if(bInvalid_state == OMX_TRUE)
     {
         LoadBaseImage();
     }
 #endif
-        
+
 EXIT:
     return eErrorHandleError;
 }
@@ -788,10 +792,10 @@
   * Initialize H264 Parameters.
   *
   * @param pAppData
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_SetH264Parameter(MYDATATYPE* pAppData)
@@ -801,24 +805,16 @@
 
     /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (input) */
     /**********************************************************************/
-    memset(pAppData->pInPortDef, 0x0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));    
-    pAppData->pInPortDef->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);         
-    pAppData->pInPortDef->nVersion.s.nVersionMajor = 0x1;       
-    pAppData->pInPortDef->nVersion.s.nVersionMinor = 0x0;       
-    pAppData->pInPortDef->nVersion.s.nRevision = 0x0;           
-    pAppData->pInPortDef->nVersion.s.nStep = 0x0;
-    pAppData->pInPortDef->nPortIndex = VIDENC_INPUT_PORT;
-    pAppData->pInPortDef->eDir = OMX_DirInput;
     pAppData->pInPortDef->nBufferCountActual = NUM_OF_IN_BUFFERS;
     pAppData->pInPortDef->nBufferCountMin = 1;
     pAppData->pInPortDef->bEnabled = OMX_TRUE;
     pAppData->pInPortDef->bPopulated = OMX_FALSE;
     pAppData->pInPortDef->eDomain = OMX_PortDomainVideo;
-    
+
     /* OMX_VIDEO_PORTDEFINITION values for input port */
     pAppData->pInPortDef->format.video.cMIMEType = "yuv";
-    pAppData->pInPortDef->format.video.pNativeRender = NULL; 
-    pAppData->pInPortDef->format.video.nStride = -1; 
+    pAppData->pInPortDef->format.video.pNativeRender = NULL;
+    pAppData->pInPortDef->format.video.nStride = -1;
     pAppData->pInPortDef->format.video.nSliceHeight = -1;
     pAppData->pInPortDef->format.video.xFramerate = fToQ16(pAppData->nFramerate);
     pAppData->pInPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
@@ -827,110 +823,112 @@
     pAppData->pInPortDef->format.video.nFrameHeight = pAppData->nHeight;
 
 
-    if (pAppData->eColorFormat == OMX_COLOR_FormatYUV420Planar) {
-        pAppData->pInPortDef->nBufferSize = (pAppData->pInPortDef->format.video.nFrameWidth * pAppData->pInPortDef->format.video.nFrameHeight * 1.5);
-    }
-    else if (pAppData->eColorFormat == OMX_COLOR_FormatYCbYCr || pAppData->eColorFormat == OMX_COLOR_FormatCbYCrY) {
-        pAppData->pInPortDef->nBufferSize = (pAppData->pInPortDef->format.video.nFrameWidth * pAppData->pInPortDef->format.video.nFrameHeight * 2);
-    }
-    else {
-        VIDENCTEST_DPRINT("Error: Invalid color format.\n");
-        eError = OMX_ErrorUnsupportedSetting;
-        goto EXIT;
-    }
 
     eError = OMX_SetParameter(pHandle, OMX_IndexParamPortDefinition, pAppData->pInPortDef);
     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
 
-    /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (output) */
-    /***********************************************************************/
-    memset(pAppData->pOutPortDef, 0x1, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));   
-    pAppData->pOutPortDef->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);                
-    pAppData->pOutPortDef->nVersion.s.nVersionMajor = 0x1;      
-    pAppData->pOutPortDef->nVersion.s.nVersionMinor = 0x0;      
-    pAppData->pOutPortDef->nVersion.s.nRevision = 0x0;          
-    pAppData->pOutPortDef->nVersion.s.nStep = 0x0;
-    pAppData->pOutPortDef->nPortIndex = VIDENC_OUTPUT_PORT;
-    pAppData->pOutPortDef->eDir = OMX_DirOutput;
-    pAppData->pOutPortDef->nBufferCountActual = NUM_OF_OUT_BUFFERS; 
-    pAppData->pOutPortDef->nBufferCountMin = 1; 
-    pAppData->pOutPortDef->nBufferSize = pAppData->nOutBuffSize; 
-    pAppData->pOutPortDef->bEnabled = OMX_TRUE;
-    pAppData->pOutPortDef->bPopulated = OMX_FALSE;
-    pAppData->pOutPortDef->eDomain = OMX_PortDomainVideo;
-    
-    /* OMX_VIDEO_PORTDEFINITION values for input port */
-    pAppData->pOutPortDef->format.video.cMIMEType = "264";
-    pAppData->pOutPortDef->format.video.pNativeRender = NULL; 
-    pAppData->pOutPortDef->format.video.nFrameWidth = pAppData->nWidth;
-    pAppData->pOutPortDef->format.video.nFrameHeight = pAppData->nHeight;
-    pAppData->pOutPortDef->format.video.nStride = 0; 
-    pAppData->pOutPortDef->format.video.nSliceHeight = 0; 
-    pAppData->pOutPortDef->format.video.nBitrate = pAppData->nBitrate; 
-    pAppData->pOutPortDef->format.video.xFramerate = 0; 
-    pAppData->pOutPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
-    pAppData->pOutPortDef->format.video.eCompressionFormat = pAppData->eCompressionFormat;
+    /* To get nBufferSize */
+    eError = OMX_GetParameter(pHandle, OMX_IndexParamPortDefinition, pAppData->pInPortDef);
+    VIDENCTEST_CHECK_EXIT(eError, "Error at GetParameter");
 
-    eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
-    VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
+    pAppData->nSizeIn = pAppData->pInPortDef->nBufferSize;
 
     /* Set the component's OMX_VIDEO_PARAM_AVCTYPE structure (output) */
     /*************************************************************/
-    memset(pAppData->pH264, 0x0, sizeof(OMX_VIDEO_PARAM_AVCTYPE));      
-    pAppData->pH264->nSize = sizeof(OMX_VIDEO_PARAM_AVCTYPE);           
-    pAppData->pH264->nVersion.s.nVersionMajor = 0x1;    
-    pAppData->pH264->nVersion.s.nVersionMinor = 0x0;    
-    pAppData->pH264->nVersion.s.nRevision = 0x0;                
+    memset(pAppData->pH264, 0x0, sizeof(OMX_VIDEO_PARAM_AVCTYPE));
+    pAppData->pH264->nSize = sizeof(OMX_VIDEO_PARAM_AVCTYPE);
+    pAppData->pH264->nVersion.s.nVersionMajor = 0x1;
+    pAppData->pH264->nVersion.s.nVersionMinor = 0x0;
+    pAppData->pH264->nVersion.s.nRevision = 0x0;
     pAppData->pH264->nVersion.s.nStep = 0x0;
     pAppData->pH264->nPortIndex = VIDENC_OUTPUT_PORT;
-    pAppData->pH264->nSliceHeaderSpacing = 0;  
-    pAppData->pH264->nPFrames = -1;     
-    pAppData->pH264->nBFrames = -1;     
+    pAppData->pH264->nSliceHeaderSpacing = 0;
+    pAppData->pH264->nPFrames = -1;
+    pAppData->pH264->nBFrames = -1;
     pAppData->pH264->bUseHadamard = 0;
-    pAppData->pH264->nRefFrames = -1;  
+    pAppData->pH264->nRefFrames = -1;
     pAppData->pH264->nRefIdx10ActiveMinus1 = -1;
     pAppData->pH264->nRefIdx11ActiveMinus1 = -1;
-    pAppData->pH264->bEnableUEP = OMX_FALSE;  
-    pAppData->pH264->bEnableFMO = OMX_FALSE;  
-    pAppData->pH264->bEnableASO = OMX_FALSE;  
-    pAppData->pH264->bEnableRS = OMX_FALSE;  
+    pAppData->pH264->bEnableUEP = OMX_FALSE;
+    pAppData->pH264->bEnableFMO = OMX_FALSE;
+    pAppData->pH264->bEnableASO = OMX_FALSE;
+    pAppData->pH264->bEnableRS = OMX_FALSE;
     pAppData->pH264->eProfile = OMX_VIDEO_AVCProfileBaseline;
-    pAppData->pH264->nAllowedPictureTypes = -1;  
-    pAppData->pH264->bFrameMBsOnly = OMX_FALSE;                                                                             
-    pAppData->pH264->bMBAFF = OMX_FALSE;               
-    pAppData->pH264->bEntropyCodingCABAC = OMX_FALSE; 
-    pAppData->pH264->bWeightedPPrediction = OMX_FALSE; 
+    pAppData->pH264->nAllowedPictureTypes = -1;
+    pAppData->pH264->bFrameMBsOnly = OMX_FALSE;
+    pAppData->pH264->bMBAFF = OMX_FALSE;
+    pAppData->pH264->bEntropyCodingCABAC = OMX_FALSE;
+    pAppData->pH264->bWeightedPPrediction = OMX_FALSE;
     pAppData->pH264->nWeightedBipredicitonMode = -1;
     pAppData->pH264->bconstIpred = OMX_FALSE;
-    pAppData->pH264->bDirect8x8Inference = OMX_FALSE; 
+    pAppData->pH264->bDirect8x8Inference = OMX_FALSE;
     pAppData->pH264->bDirectSpatialTemporal = OMX_FALSE;
     pAppData->pH264->nCabacInitIdc = -1;
     pAppData->pH264->eLoopFilterMode = OMX_VIDEO_AVCLoopFilterDisable;
     pAppData->pH264->eLevel = pAppData->eLevelH264;
 
     eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoAvc, pAppData->pH264);
-    VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter"); 
+    VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
+
+    /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (output) */
+    /***********************************************************************/
+    /*memset(pAppData->pOutPortDef, 0x1, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
+    pAppData->pOutPortDef->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);
+    pAppData->pOutPortDef->nVersion.s.nVersionMajor = 0x1;
+    pAppData->pOutPortDef->nVersion.s.nVersionMinor = 0x0;
+    pAppData->pOutPortDef->nVersion.s.nRevision = 0x0;
+    pAppData->pOutPortDef->nVersion.s.nStep = 0x0;
+    pAppData->pOutPortDef->nPortIndex = VIDENC_OUTPUT_PORT;
+    pAppData->pOutPortDef->eDir = OMX_DirOutput;*/
+    pAppData->pOutPortDef->nBufferCountActual = NUM_OF_OUT_BUFFERS;
+    pAppData->pOutPortDef->nBufferCountMin = 1;
+    /*pAppData->pOutPortDef->nBufferSize = pAppData->nOutBuffSize;*/
+    pAppData->pOutPortDef->bEnabled = OMX_TRUE;
+    pAppData->pOutPortDef->bPopulated = OMX_FALSE;
+    pAppData->pOutPortDef->eDomain = OMX_PortDomainVideo;
+
+    /* OMX_VIDEO_PORTDEFINITION values for input port */
+    pAppData->pOutPortDef->format.video.cMIMEType = "264";
+    pAppData->pOutPortDef->format.video.pNativeRender = NULL;
+    pAppData->pOutPortDef->format.video.nFrameWidth = pAppData->nWidth;
+    pAppData->pOutPortDef->format.video.nFrameHeight = pAppData->nHeight;
+    pAppData->pOutPortDef->format.video.nStride = 0;
+    pAppData->pOutPortDef->format.video.nSliceHeight = 0;
+    pAppData->pOutPortDef->format.video.nBitrate = pAppData->nBitrate;
+    pAppData->pOutPortDef->format.video.xFramerate = 0;
+    pAppData->pOutPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
+    pAppData->pOutPortDef->format.video.eCompressionFormat = pAppData->eCompressionFormat;
+
+    eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
+    VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
+
+    /* Retreive nBufferSize */
+    eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
+    VIDENCTEST_CHECK_EXIT(eError, "Error at GetParameter");
+
+    pAppData->nSizeOut = pAppData->pOutPortDef->nBufferSize;
 
     /* Set the component's OMX_VIDEO_PARAM_BITRATETYPE structure (output) */
     /*************************************************************/
-    pAppData->pVidParamBitrate->nSize = sizeof(OMX_VIDEO_PARAM_BITRATETYPE);            
-    pAppData->pVidParamBitrate->nVersion.s.nVersionMajor = 0x1; 
-    pAppData->pVidParamBitrate->nVersion.s.nVersionMinor = 0x0; 
-    pAppData->pVidParamBitrate->nVersion.s.nRevision = 0x0;             
+    pAppData->pVidParamBitrate->nSize = sizeof(OMX_VIDEO_PARAM_BITRATETYPE);
+    pAppData->pVidParamBitrate->nVersion.s.nVersionMajor = 0x1;
+    pAppData->pVidParamBitrate->nVersion.s.nVersionMinor = 0x0;
+    pAppData->pVidParamBitrate->nVersion.s.nRevision = 0x0;
     pAppData->pVidParamBitrate->nVersion.s.nStep = 0x0;
     pAppData->pVidParamBitrate->nPortIndex = VIDENC_OUTPUT_PORT;
     pAppData->pVidParamBitrate->eControlRate = pAppData->eControlRate;
+    pAppData->pVidParamBitrate->nTargetBitrate = pAppData->pOutPortDef->format.video.nBitrate;
 
     /* TODO: need to convert what value DSP is expecting to equivalent OMX value */
     eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoBitrate, pAppData->pVidParamBitrate);
     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
-    
+
     /* Set the component's OMX_VIDEO_PARAM_QUANTIZATIONTYPE structure (output) */
     /*************************************************************/
-    pAppData->pQuantization->nSize = sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE);          
-    pAppData->pQuantization->nVersion.s.nVersionMajor = 0x1;    
-    pAppData->pQuantization->nVersion.s.nVersionMinor = 0x0;    
-    pAppData->pQuantization->nVersion.s.nRevision = 0x0;                
+    pAppData->pQuantization->nSize = sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
+    pAppData->pQuantization->nVersion.s.nVersionMajor = 0x1;
+    pAppData->pQuantization->nVersion.s.nVersionMinor = 0x0;
+    pAppData->pQuantization->nVersion.s.nRevision = 0x0;
     pAppData->pQuantization->nVersion.s.nStep = 0x0;
     pAppData->pQuantization->nPortIndex = VIDENC_OUTPUT_PORT;
     pAppData->pQuantization->nQpI = pAppData->nQpI;
@@ -945,19 +943,27 @@
     eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->bDeblockFilter));
     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
 
-    if(pAppData->nEncodingPreset>-1 && pAppData->nEncodingPreset<4){
+    if(pAppData->nEncodingPreset!=VIDENCTEST_USE_DEFAULT_VALUE_UI && pAppData->nEncodingPreset<=4){
         printf("EncodingPreset %d selected\n", pAppData->nEncodingPreset);
         eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.EncodingPreset", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
         VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
         eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nEncodingPreset));
         VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for nEncodingPreset");
     }
-    
-        eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.NALFormat", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
+
+    if(pAppData->nUnrestrictedMV != (OMX_U8)VIDENCTEST_USE_DEFAULT_VALUE_UI){
+        printf("nUnrestrictedMV %d selected\n", pAppData->nUnrestrictedMV);
+        eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.UnrestrictedMV", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
         VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
-        eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->NalFormat));
-        VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for NalFormat");
-    
+        eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nUnrestrictedMV));
+        VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for nUnrestrictedMV");
+    }
+
+    eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.NALFormat", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
+    VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
+    eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->NalFormat));
+    VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for NalFormat");
+
 EXIT:
     return eError;
 }
@@ -969,102 +975,84 @@
   * Intialize Mpeg4 structures.
   *
   * @param pAppData
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_SetMpeg4Parameter(MYDATATYPE* pAppData)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_HANDLETYPE pHandle = pAppData->pHandle;
-   
+
     /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (input) */
     /**********************************************************************/
-    memset(pAppData->pInPortDef, 0x0, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));    
-    pAppData->pInPortDef->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);         
-    pAppData->pInPortDef->nVersion.s.nVersionMajor = 0x1;       
-    pAppData->pInPortDef->nVersion.s.nVersionMinor = 0x0;       
-    pAppData->pInPortDef->nVersion.s.nRevision = 0x0;           
-    pAppData->pInPortDef->nVersion.s.nStep = 0x0;
-    pAppData->pInPortDef->nPortIndex = VIDENC_INPUT_PORT;
-    pAppData->pInPortDef->eDir = OMX_DirInput;
     pAppData->pInPortDef->nBufferCountActual = NUM_OF_IN_BUFFERS;
     pAppData->pInPortDef->nBufferCountMin = 2;
     pAppData->pInPortDef->bEnabled = OMX_TRUE;
     pAppData->pInPortDef->bPopulated = OMX_FALSE;
     pAppData->pInPortDef->eDomain = OMX_PortDomainVideo;
-        
+
     /* OMX_VIDEO_PORTDEFINITION values for input port */
     pAppData->pInPortDef->format.video.cMIMEType = "yuv";
-    pAppData->pInPortDef->format.video.pNativeRender = NULL; 
-    pAppData->pInPortDef->format.video.nStride = -1; 
-    pAppData->pInPortDef->format.video.nSliceHeight = -1; 
+    pAppData->pInPortDef->format.video.pNativeRender = NULL;
+    pAppData->pInPortDef->format.video.nStride = -1;
+    pAppData->pInPortDef->format.video.nSliceHeight = -1;
     pAppData->pInPortDef->format.video.xFramerate = fToQ16(pAppData->nFramerate);
     pAppData->pInPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
     pAppData->pInPortDef->format.video.eColorFormat = pAppData->eColorFormat;
     pAppData->pInPortDef->format.video.nFrameWidth = pAppData->nWidth;
     pAppData->pInPortDef->format.video.nFrameHeight = pAppData->nHeight;
-    
-    if (pAppData->eColorFormat == OMX_COLOR_FormatYUV420Planar) {
-        pAppData->pInPortDef->nBufferSize = (pAppData->pInPortDef->format.video.nFrameWidth * pAppData->pInPortDef->format.video.nFrameHeight * 1.5);
-    }
-    else if (pAppData->eColorFormat == OMX_COLOR_FormatYCbYCr ||
-             pAppData->eColorFormat == OMX_COLOR_FormatCbYCrY) {
-        pAppData->pInPortDef->nBufferSize = (pAppData->pInPortDef->format.video.nFrameWidth * pAppData->pInPortDef->format.video.nFrameHeight * 2);
-    }
-    else {
-        VIDENCTEST_DPRINT("Error: Invalid color format.\n");
-        eError = OMX_ErrorUnsupportedSetting;
-        goto EXIT;
-    }
-        
+
     eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pInPortDef);
     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
-    
+
+    /* To get nBufferSize */
+    eError = OMX_GetParameter(pHandle, OMX_IndexParamPortDefinition, pAppData->pInPortDef);
+    VIDENCTEST_CHECK_EXIT(eError, "Error at GetParameter");
+
+    pAppData->nSizeIn = pAppData->pInPortDef->nBufferSize;
 
     /* Set the component's OMX_PARAM_PORTDEFINITIONTYPE structure (output) */
     /*************************************************************/
-    memset(pAppData->pOutPortDef, 0x1, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));   
-    pAppData->pOutPortDef->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE);                
-    pAppData->pOutPortDef->nVersion.s.nVersionMajor = 0x1;      
-    pAppData->pOutPortDef->nVersion.s.nVersionMinor = 0x0;      
-    pAppData->pOutPortDef->nVersion.s.nRevision = 0x0;          
-    pAppData->pOutPortDef->nVersion.s.nStep = 0x0;
-    pAppData->pOutPortDef->nPortIndex = VIDENC_OUTPUT_PORT;
-    pAppData->pOutPortDef->eDir = OMX_DirOutput;
     pAppData->pOutPortDef->nBufferCountActual = NUM_OF_OUT_BUFFERS;
     pAppData->pOutPortDef->nBufferCountMin = 1;
-    pAppData->pOutPortDef->nBufferSize = pAppData->nWidth * pAppData->nHeight / 2; 
     pAppData->pOutPortDef->bEnabled = OMX_TRUE;
     pAppData->pOutPortDef->bPopulated = OMX_FALSE;
     pAppData->pOutPortDef->eDomain = OMX_PortDomainVideo;
-    
+
     /* OMX_VIDEO_PORTDEFINITION values for input port */
     pAppData->pOutPortDef->format.video.cMIMEType = "mp4";
-    pAppData->pOutPortDef->format.video.pNativeRender = NULL; 
+    pAppData->pOutPortDef->format.video.pNativeRender = NULL;
     pAppData->pOutPortDef->format.video.nFrameWidth = pAppData->nWidth;
     pAppData->pOutPortDef->format.video.nFrameHeight = pAppData->nHeight;
     pAppData->pOutPortDef->format.video.nStride = 0;
-    pAppData->pOutPortDef->format.video.nSliceHeight = 0; 
-    pAppData->pOutPortDef->format.video.nBitrate = pAppData->nBitrate; 
-    pAppData->pOutPortDef->format.video.xFramerate = 0; 
+    pAppData->pOutPortDef->format.video.nSliceHeight = 0;
+    pAppData->pOutPortDef->format.video.nBitrate = pAppData->nBitrate;
+    pAppData->pOutPortDef->format.video.xFramerate = 0;
     pAppData->pOutPortDef->format.video.bFlagErrorConcealment = OMX_FALSE;
     pAppData->pOutPortDef->format.video.eCompressionFormat = pAppData->eCompressionFormat;
 
     eError = OMX_SetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
-  
+
+    /* Retreive nBufferSize */
+    eError = OMX_GetParameter (pHandle, OMX_IndexParamPortDefinition, pAppData->pOutPortDef);
+    VIDENCTEST_CHECK_EXIT(eError, "Error at GetParameter");
+
+    pAppData->nSizeOut = pAppData->pOutPortDef->nBufferSize;
+
     /* Set the component's OMX_VIDEO_PARAM_BITRATETYPE structure (output) */
     /*************************************************************/
-    pAppData->pVidParamBitrate->nSize = sizeof(OMX_VIDEO_PARAM_BITRATETYPE);            
-    pAppData->pVidParamBitrate->nVersion.s.nVersionMajor = 0x1; 
-    pAppData->pVidParamBitrate->nVersion.s.nVersionMinor = 0x0; 
-    pAppData->pVidParamBitrate->nVersion.s.nRevision = 0x0;             
+    pAppData->pVidParamBitrate->nSize = sizeof(OMX_VIDEO_PARAM_BITRATETYPE);
+    pAppData->pVidParamBitrate->nVersion.s.nVersionMajor = 0x1;
+    pAppData->pVidParamBitrate->nVersion.s.nVersionMinor = 0x0;
+    pAppData->pVidParamBitrate->nVersion.s.nRevision = 0x0;
     pAppData->pVidParamBitrate->nVersion.s.nStep = 0x0;
     pAppData->pVidParamBitrate->nPortIndex = VIDENC_OUTPUT_PORT;
     pAppData->pVidParamBitrate->eControlRate = pAppData->eControlRate;
+    pAppData->pVidParamBitrate->nTargetBitrate = pAppData->pOutPortDef->format.video.nBitrate;
 
     /* TODO: need to convert what value DSP is expecting to equivalent OMX value */
 
@@ -1073,26 +1061,26 @@
 
     /* Set the component's OMX_VIDEO_PARAM_H263TYPE structure (output) */
     /*************************************************************/
-    if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {    
-        pAppData->pH263->nSize = sizeof(OMX_VIDEO_PARAM_H263TYPE);              
-        pAppData->pH263->nVersion.s.nVersionMajor = 0x1;        
-        pAppData->pH263->nVersion.s.nVersionMinor = 0x0;        
-        pAppData->pH263->nVersion.s.nRevision = 0x0;            
+    if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
+        pAppData->pH263->nSize = sizeof(OMX_VIDEO_PARAM_H263TYPE);
+        pAppData->pH263->nVersion.s.nVersionMajor = 0x1;
+        pAppData->pH263->nVersion.s.nVersionMinor = 0x0;
+        pAppData->pH263->nVersion.s.nRevision = 0x0;
         pAppData->pH263->nVersion.s.nStep = 0x0;
         pAppData->pH263->nPortIndex = VIDENC_OUTPUT_PORT;
-        pAppData->pH263->eLevel = pAppData->eLevelH63; 
+        pAppData->pH263->eLevel = pAppData->eLevelH63;
         pAppData->pH263->nGOBHeaderInterval = pAppData->nGOBHeaderInterval;
 
         eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoH263, pAppData->pH263);
         VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
-    } 
+    }
 
     /* Set the component's OMX_VIDEO_PARAM_QUANTIZATIONTYPE structure (output) */
     /*************************************************************/
-    pAppData->pQuantization->nSize = sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE);          
-    pAppData->pQuantization->nVersion.s.nVersionMajor = 0x1;    
-    pAppData->pQuantization->nVersion.s.nVersionMinor = 0x0;    
-    pAppData->pQuantization->nVersion.s.nRevision = 0x0;                
+    pAppData->pQuantization->nSize = sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE);
+    pAppData->pQuantization->nVersion.s.nVersionMajor = 0x1;
+    pAppData->pQuantization->nVersion.s.nVersionMinor = 0x0;
+    pAppData->pQuantization->nVersion.s.nRevision = 0x0;
     pAppData->pQuantization->nVersion.s.nStep = 0x0;
     pAppData->pQuantization->nPortIndex = VIDENC_OUTPUT_PORT;
     pAppData->pQuantization->nQpI = pAppData->nQpI;
@@ -1102,27 +1090,27 @@
 
     /* Set the component's OMX_VIDEO_PARAM_MPEG4TYPE structure (output) */
     /*************************************************************/
-    if (pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) {    
-        pAppData->pMpeg4->nSize = sizeof(OMX_VIDEO_PARAM_MPEG4TYPE);                
-        pAppData->pMpeg4->nVersion.s.nVersionMajor = 0x1;   
-        pAppData->pMpeg4->nVersion.s.nVersionMinor = 0x0;   
-        pAppData->pMpeg4->nVersion.s.nRevision = 0x0;               
+    if (pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4) {
+        pAppData->pMpeg4->nSize = sizeof(OMX_VIDEO_PARAM_MPEG4TYPE);
+        pAppData->pMpeg4->nVersion.s.nVersionMajor = 0x1;
+        pAppData->pMpeg4->nVersion.s.nVersionMinor = 0x0;
+        pAppData->pMpeg4->nVersion.s.nRevision = 0x0;
         pAppData->pMpeg4->nVersion.s.nStep = 0x0;
         pAppData->pMpeg4->nPortIndex = VIDENC_OUTPUT_PORT;
         pAppData->pMpeg4->eLevel = pAppData->eLevelMpeg4;
-        
+
         eError = OMX_SetParameter (pHandle, OMX_IndexParamVideoMpeg4, pAppData->pMpeg4);
         VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
     }
-    
+
     /* SR10527: Set MPEG4/H263 encode VBV Size using the custom OMX index */
     eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Param.VBVSize", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
     VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
-    
+
     eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nVBVSize));
     VIDENCTEST_CHECK_EXIT(eError, "Error at SetParameter");
 
-    if(pAppData->nMIRRate != -1){
+    if(pAppData->nMIRRate != VIDENCTEST_USE_DEFAULT_VALUE){
         printf("MIRRate selected\n");
         eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.MIRRate", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
         VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
@@ -1130,7 +1118,7 @@
         VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for nMIRRate");
     }
 
-    if(pAppData->nResynchMarkerSpacing != -1){
+    if(pAppData->nResynchMarkerSpacing != VIDENCTEST_USE_DEFAULT_VALUE){
         printf("ResynchMarkerSpacing selected\n");
         OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE ErrorCorrectionType;
         ErrorCorrectionType.nSize = sizeof(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE);
@@ -1144,10 +1132,17 @@
         ErrorCorrectionType.bEnableDataPartitioning= OMX_FALSE;
         ErrorCorrectionType.bEnableRVLC= OMX_FALSE;
         ErrorCorrectionType.nResynchMarkerSpacing = pAppData->nResynchMarkerSpacing;
-        
+
         eError = OMX_SetConfig(pHandle, OMX_IndexParamVideoErrorCorrection, &ErrorCorrectionType);
         VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for ErrorCorrection");
     }
+    if(pAppData->nUnrestrictedMV != (OMX_U8)VIDENCTEST_USE_DEFAULT_VALUE_UI){
+        printf("nUnrestrictedMV %d selected\n", pAppData->nUnrestrictedMV);
+        eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.UnrestrictedMV", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
+        VIDENCTEST_CHECK_EXIT(eError, "OMX_GetExtensionIndex function");
+        eError = OMX_SetParameter(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nUnrestrictedMV));
+        VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for nUnrestrictedMV");
+    }
 EXIT:
     return eError;
 }
@@ -1159,63 +1154,24 @@
   * Allocate necesary resources.
   *
   * @param pAppData
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_AllocateResources(MYDATATYPE* pAppData)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     int retval = 0;
-    OMX_U8 nCounter = 0;
     VIDENCTEST_NODE* pListHead;
-    
+
     pListHead = pAppData->pMemoryListHead;
 
-    if (pAppData->eColorFormat == OMX_COLOR_FormatYUV420Planar) {
-        pAppData->nSizeIn = pAppData->nWidth * pAppData->nHeight * 1.5;
-    }
-    else if (pAppData->eColorFormat == OMX_COLOR_FormatYCbYCr || pAppData->eColorFormat == OMX_COLOR_FormatCbYCrY) {
-        pAppData->nSizeIn = pAppData->nWidth * pAppData->nHeight * 2.0;
-    }
-    else {
-        VIDENCTEST_DPRINT("Error: Invalid color format value.\n");
-        eError = OMX_ErrorUnsupportedSetting;
-        goto EXIT;
-    }
-        
-    if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263 || pAppData->eCompressionFormat == OMX_VIDEO_CodingMPEG4 ) { 
-        pAppData->nSizeOut = pAppData->nWidth * pAppData->nHeight / 2; 
-    }
-    else if (pAppData->eCompressionFormat == OMX_VIDEO_CodingAVC) { 
-        pAppData->nSizeOut = pAppData->nOutBuffSize;
-    }
-    else {
-        VIDENCTEST_DPRINT("Error: Invalid compression format value.\n");
-        eError = OMX_ErrorUnsupportedSetting;
-        goto EXIT;
-    }
-
     VIDENCTEST_MALLOC(pAppData->pCb, sizeof(OMX_CALLBACKTYPE), OMX_CALLBACKTYPE, pListHead);
-    VIDENCTEST_MALLOC(pAppData->pInPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE), OMX_PARAM_PORTDEFINITIONTYPE, pListHead); 
-    VIDENCTEST_MALLOC(pAppData->pOutPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE), OMX_PARAM_PORTDEFINITIONTYPE, pListHead); 
+    VIDENCTEST_MALLOC(pAppData->pInPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE), OMX_PARAM_PORTDEFINITIONTYPE, pListHead);
+    VIDENCTEST_MALLOC(pAppData->pOutPortDef, sizeof(OMX_PARAM_PORTDEFINITIONTYPE), OMX_PARAM_PORTDEFINITIONTYPE, pListHead);
 
-    for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
-        if (pAppData->bAllocateIBuf == OMX_TRUE) { 
-            VIDENCTEST_MALLOC(pAppData->pIBuffer[nCounter], pAppData->nSizeIn + 256, OMX_U8, pListHead);         
-            pAppData->pIBuffer[nCounter] += 128;           
-            pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];          
-        }
-    }
-    for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
-        if (pAppData->bAllocateOBuf == OMX_TRUE) {
-            VIDENCTEST_MALLOC(pAppData->pOBuffer[nCounter], pAppData->nSizeOut + 256, OMX_U8, pListHead);            
-            pAppData->pOBuffer[nCounter] += 128;
-            pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
-            }
-    }
     if (pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
         VIDENCTEST_MALLOC(pAppData->pVidParamBitrate, sizeof(OMX_VIDEO_PARAM_BITRATETYPE), OMX_VIDEO_PARAM_BITRATETYPE, pListHead);
         VIDENCTEST_MALLOC(pAppData->pH263, sizeof(OMX_VIDEO_PARAM_H263TYPE), OMX_VIDEO_PARAM_H263TYPE, pListHead);
@@ -1234,7 +1190,7 @@
         goto EXIT;
     }
     VIDENCTEST_MALLOC(pAppData->pQuantization, sizeof(OMX_VIDEO_PARAM_QUANTIZATIONTYPE), OMX_VIDEO_PARAM_QUANTIZATIONTYPE, pListHead);
-        
+
     /* Create a pipe used to queue data from the callback. */
     retval = pipe(pAppData->IpBuf_Pipe);
     if (retval != 0) {
@@ -1258,15 +1214,54 @@
 
 /*-----------------------------------------------------------------------------*/
 /**
+  * AllocateBuffers()
+  *
+  * Allocate necesary resources.
+  *
+  * @param pAppData
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
+  **/
+/*-----------------------------------------------------------------------------*/
+OMX_ERRORTYPE VIDENCTEST_AllocateBuffers(MYDATATYPE* pAppData)
+{
+    OMX_ERRORTYPE eError = OMX_ErrorNone;
+    OMX_U8 nCounter = 0;
+    VIDENCTEST_NODE* pListHead;
+
+    pListHead = pAppData->pMemoryListHead;
+
+    for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
+        if (pAppData->bAllocateIBuf == OMX_TRUE) {
+            VIDENCTEST_MALLOC(pAppData->pIBuffer[nCounter], pAppData->nSizeIn + 256, OMX_U8, pListHead);
+            pAppData->pIBuffer[nCounter] += 128;
+            pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];
+        }
+    }
+    for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
+        if (pAppData->bAllocateOBuf == OMX_TRUE) {
+            VIDENCTEST_MALLOC(pAppData->pOBuffer[nCounter], pAppData->nSizeOut + 256, OMX_U8, pListHead);
+            pAppData->pOBuffer[nCounter] += 128;
+            pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
+            }
+    }
+
+    return eError;
+}
+
+/*-----------------------------------------------------------------------------*/
+/**
   * FreeResources()
   *
   * Free all allocated memory.
   *
   * @param pAppData
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_FreeResources(MYDATATYPE* pAppData)
@@ -1274,9 +1269,9 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_U32 i = 0;
     VIDENCTEST_NODE* pListHead;
-    
+
     pListHead = pAppData->pMemoryListHead;
-    
+
     VIDENCTEST_FREE(pAppData->pCb, pListHead);
     VIDENCTEST_FREE(pAppData->pInPortDef, pListHead);
     VIDENCTEST_FREE(pAppData->pOutPortDef, pListHead);
@@ -1305,7 +1300,7 @@
     for (i = 0; i < pAppData->nEventCount; i++) {
         VIDENCTEST_FREE(pAppData->pEventArray[i], pListHead);
     }
-    
+
     return eError;
 }
 
@@ -1313,16 +1308,16 @@
 /**
   * PrintCorrectArgs()
   *
-  * Print the description of the input arguments. Also Prints a sample line. 
+  * Print the description of the input arguments. Also Prints a sample line.
   *
   * @param bPrintH264. IF set will print the H264 argument description.
   * @param bPrintMpeg4. If set will print the Mpeg4/H263  argument description.
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
-/*-----------------------------------------------------------------------------*/    
+/*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_PrintCorrectArgs(OMX_BOOL bPrintH264, OMX_BOOL bPrintMpeg4)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
@@ -1330,43 +1325,43 @@
     if (bPrintMpeg4 == OMX_TRUE) {
         printf("MPEG4/H.263 Encode Usage: ./VideoEncTest <arg01> <arg02> <arg03> ...");
         printf("\narg01 : <input.yuv>");
-        printf("\narg02 : <output.mp4>");                                        
-        printf("\narg03 : <width>");                                           
-        printf("\narg04 : <height>");                                              
-        printf("\narg05 : <19:420/25:422-BE/26:422-LE>");                                          
-        printf("\narg06 : <bitrate>");                                                
-        printf("\narg07 : <framerate>");                                                  
-        printf("\narg08 : <3:H263/4:MPEG4/7:H264>");                                            
-        printf("\narg09 : <rateCtrl/1:var/2:const>");                                                 
-        printf("\narg10 : <GOB> --H.263 only--");                            
-        printf("\narg11 : <QPI>");                                               
-        printf("\narg12 : <level>");                                                      
-        printf("\narg13 : <allocateBufFlag>");                                               
-        printf("\narg14 : <VBVsize>");                                                                
+        printf("\narg02 : <output.mp4>");
+        printf("\narg03 : <width>");
+        printf("\narg04 : <height>");
+        printf("\narg05 : <19:420/25:422-BE/26:422-LE>");
+        printf("\narg06 : <bitrate>");
+        printf("\narg07 : <framerate>");
+        printf("\narg08 : <3:H263/4:MPEG4/7:H264>");
+        printf("\narg09 : <rateCtrl/1:var/2:const>");
+        printf("\narg10 : <GOB> --H.263 only--");
+        printf("\narg11 : <QPI>");
+        printf("\narg12 : <level>");
+        printf("\narg13 : <allocateBufFlag>");
+        printf("\narg14 : <VBVsize>");
         printf("\narg15 : <0:full-rec/1:partial-rec->stop/2:rec->pause->resume/3:rec->stop->restart>");
         printf("\narg16 : <stop/pause frame/iteration> -- use zero if arg15 = 0:full-rec <or> use a valid frame # if arg15 = 1, 2, 3 --\n");
         printf("\narg17 : <Number of Repetitions of test>");
         printf("\nSample OMX MPEG4 Encode test:\n");
         printf("/omx/VideoEncTest /omx/patterns/carphone_qcif_420p_short.yuv /omx/patterns/carphone_qcif_420p_short.mp4 176 144 19 64000 15 4 1 0 12 0 1 120 0 0 1\n");
         printf("\nSample OMX H.263 Encode test:\n");
-        printf("/omx/VideoEncTest /omx/patterns/carphone_qcif_420p_short.yuv /omx/patterns/carphone_qcif_420p_short.263 176 144 19 64000 15 3 2 0 12 10 1 120 0 0 1\n\n");          
+        printf("/omx/VideoEncTest /omx/patterns/carphone_qcif_420p_short.yuv /omx/patterns/carphone_qcif_420p_short.263 176 144 19 64000 15 3 2 0 12 10 1 120 0 0 1\n\n");
     }
     if (bPrintH264 == OMX_TRUE) {
-        printf("H.264 Encode Usage: ./VideoEncTest <arg01> <arg02> <arg03> ..."); 
-        printf("\narg01 :: <input.yuv>");                                                  
-        printf("\narg02 :: <output.H264>");                                                     
-        printf("\narg03 :: <width>");                                                                 
-        printf("\narg04 :: <height>");                                     
-        printf("\narg05 :: <19:420/25:422-BE/26:422-LE>");                               
-        printf("\narg06 :: <bitrate>");                                       
-        printf("\narg07 :: <framerate>");                                       
-        printf("\narg08 :: <3:H263/4:MPEG4/7:H264>");                              
-        printf("\narg09 :: <level>");                                                 
-        printf("\narg10 :: <out_buff_size>");                                             
-        printf("\narg11 :: <allocateBufFlag>");                                               
-        printf("\narg12 :: <deblockFilter>");                                                   
-        printf("\narg13 :: <rateCtrl/0:none/1:var/2:const>");                              
-        printf("\narg14 :: <QPI> --set rate control to zero--");                                    
+        printf("H.264 Encode Usage: ./VideoEncTest <arg01> <arg02> <arg03> ...");
+        printf("\narg01 :: <input.yuv>");
+        printf("\narg02 :: <output.H264>");
+        printf("\narg03 :: <width>");
+        printf("\narg04 :: <height>");
+        printf("\narg05 :: <19:420/25:422-BE/26:422-LE>");
+        printf("\narg06 :: <bitrate>");
+        printf("\narg07 :: <framerate>");
+        printf("\narg08 :: <3:H263/4:MPEG4/7:H264>");
+        printf("\narg09 :: <level>");
+        printf("\narg10 :: <out_buff_size>");
+        printf("\narg11 :: <allocateBufFlag>");
+        printf("\narg12 :: <deblockFilter>");
+        printf("\narg13 :: <rateCtrl/0:none/1:var/2:const>");
+        printf("\narg14 :: <QPI> --set rate control to zero--");
         printf("\narg15 :: <0:full-rec/1:partial-rec->stop/2:rec->pause->resume/3:rec->stop->restart>");
         printf("\narg16 :: <stop/pause frame/iteration> -- use zero if arg15 = 0:full-rec <or> use a valid frame # if arg15 = 1, 2, 3 --\n");
         printf("\narg17 :: <Number of Repetitions of test>");
@@ -1374,7 +1369,7 @@
         printf("/omx/VideoEncTest /omx/patterns/carphone_qcif_420p_short.yuv /omx/patterns/carphone_qcif_420p_short.264 176 144 19 64000 15 7 10 26250 1 1 1 0 0 0 1\n\n");
     }
     return eError;
-}        
+}
 
 /*-----------------------------------------------------------------------------*/
 /**
@@ -1383,12 +1378,12 @@
   *Initialize all the parameters for the VideoEncoder Structures
   *
   * @param  pAppData MYDATA handle
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
-/*-----------------------------------------------------------------------------*/        
+/*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_PassToLoaded(MYDATATYPE* pAppData)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
@@ -1396,7 +1391,7 @@
     VIDENCTEST_NODE* pListHead;
     OMX_U32 i;
     OMX_CALLBACKTYPE sCb = {(void*)VIDENCTEST_EventHandler, (void*)VIDENCTEST_EmptyBufferDone, (void*)VIDENCTEST_FillBufferDone};
-    
+
     pListHead = pAppData->pMemoryListHead;
 
     eError = VIDENCTEST_AllocateResources(pAppData);
@@ -1408,7 +1403,7 @@
 
     pAppData->fdmax = maxint(pAppData->OpBuf_Pipe[0], pAppData->fdmax);
 
-    
+
 
     /* Initialize OMX Core */
 
@@ -1424,7 +1419,7 @@
         eError = OMX_ErrorUndefined;
         goto EXIT;
     }
-        
+
     pAppData->pHandle = pHandle;
 
     /* Get starting port number and the number of ports */
@@ -1442,9 +1437,10 @@
     for (i = pAppData->nStartPortNumber; i < pAppData->nPorts; i++) {
         VIDENCTEST_MALLOC(pAppData->pPortDef[i], sizeof(OMX_PARAM_PORTDEFINITIONTYPE), OMX_PARAM_PORTDEFINITIONTYPE, pListHead);
 
+        pAppData->pPortDef[i]->nPortIndex = i;
         eError = OMX_GetParameter(pHandle, OMX_IndexParamPortDefinition, pAppData->pPortDef[i]);
         VIDENCTEST_CHECK_EXIT(eError, "Error returned from GetParameter()");
-        
+
         if (pAppData->pPortDef[i]->eDir == OMX_DirInput) {
             memcpy(pAppData->pInPortDef, pAppData->pPortDef[i], sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
         }
@@ -1453,9 +1449,9 @@
         }
         VIDENCTEST_FREE(pAppData->pPortDef[i], pListHead);
     }
-        
+
     switch (pAppData->eCompressionFormat) {
-        case OMX_VIDEO_CodingH263: 
+        case OMX_VIDEO_CodingH263:
             eError = VIDENCTEST_SetMpeg4Parameter(pAppData);
             VIDENCTEST_CHECK_EXIT(eError, "Error returned from SetMpeg4Parameter()");
             break;
@@ -1472,12 +1468,15 @@
             eError = OMX_ErrorUnsupportedSetting;
             goto EXIT;
     }
-    
+
+    VIDENCTEST_AllocateBuffers(pAppData);
+    VIDENCTEST_CHECK_EXIT(eError, "Error at Allocation of Resources");
+
     pAppData->eCurrentState = VIDENCTEST_StateLoaded;
-    
+
  EXIT:
     return eError;
-    
+
 }
 
 /*-----------------------------------------------------------------------------*/
@@ -1487,74 +1486,74 @@
   *Pass the Component to Idle and allocate the buffers
   *
   * @param  pAppData MYDATA handle
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
-/*-----------------------------------------------------------------------------*/  
+/*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_PassToReady(MYDATATYPE* pAppData)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_HANDLETYPE pHandle;
     OMX_U32 nCounter;
-    
+
     pHandle = pAppData->pHandle;
-    
+
     eError = OMX_SendCommand(pHandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
     VIDENCTEST_CHECK_EXIT(eError, "Error from SendCommand-Idle(Init) State function");
 
     for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
        if (pAppData->bAllocateIBuf == OMX_TRUE) {
-            eError = OMX_UseBuffer(pHandle, 
-                                  &pAppData->pInBuff[nCounter], 
-                                  pAppData->pInPortDef->nPortIndex, 
-                                  pAppData, 
+            eError = OMX_UseBuffer(pHandle,
+                                  &pAppData->pInBuff[nCounter],
+                                  pAppData->pInPortDef->nPortIndex,
+                                  pAppData,
                                   pAppData->pInPortDef->nBufferSize,
                                   pAppData->pIBuffer[nCounter]);
             VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_UseBuffer function");
        }
        else {
-            eError = OMX_AllocateBuffer(pHandle, 
-                                       &pAppData->pInBuff[nCounter], 
-                                       pAppData->pInPortDef->nPortIndex, 
-                                       pAppData, 
+            eError = OMX_AllocateBuffer(pHandle,
+                                       &pAppData->pInBuff[nCounter],
+                                       pAppData->pInPortDef->nPortIndex,
+                                       pAppData,
                                        pAppData->pInPortDef->nBufferSize);
-            VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_AllocateBuffer State function");                           
+            VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_AllocateBuffer State function");
        }
     }
-    
+
     pAppData->nInBufferCount = NUM_OF_IN_BUFFERS;
-    
+
     for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
         if (pAppData->bAllocateOBuf == OMX_TRUE) {
-            eError = OMX_UseBuffer(pHandle, 
-                                   &pAppData->pOutBuff[nCounter], 
-                                   pAppData->pOutPortDef->nPortIndex, 
-                                   pAppData, 
+            eError = OMX_UseBuffer(pHandle,
+                                   &pAppData->pOutBuff[nCounter],
+                                   pAppData->pOutPortDef->nPortIndex,
+                                   pAppData,
                                    pAppData->pOutPortDef->nBufferSize,
                                    pAppData->pOBuffer[nCounter]);
-            VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_UseBuffer function");                       
+            VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_UseBuffer function");
         }
         else {
-            eError = OMX_AllocateBuffer(pHandle, 
-                                        &pAppData->pOutBuff[nCounter], 
-                                        pAppData->pOutPortDef->nPortIndex, 
-                                        pAppData, 
+            eError = OMX_AllocateBuffer(pHandle,
+                                        &pAppData->pOutBuff[nCounter],
+                                        pAppData->pOutPortDef->nPortIndex,
+                                        pAppData,
                                         pAppData->pOutPortDef->nBufferSize);
-            VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_AllocateBuffer function");                            
+            VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_AllocateBuffer function");
         }
     }
-    
+
     pAppData->nOutBufferCount = NUM_OF_OUT_BUFFERS;
-    
+
     pAppData->bLastOutBuffer = 0;
-    
-    
+
+
 EXIT:
     return eError;
-    
-}   
+
+}
 
 /*-----------------------------------------------------------------------------*/
 /**
@@ -1563,29 +1562,29 @@
   *Pass the component to executing  and fill the first 4 buffers.
   *
   * @param  pAppData MYDATA handle
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
-/*-----------------------------------------------------------------------------*/  
+/*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_Starting(MYDATATYPE* pAppData)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_HANDLETYPE pHandle;
     OMX_U32 nCounter = 0;
     OMX_U32 nBuffersToSend;
-    
+
     pHandle = pAppData->pHandle;
     pAppData->pComponent = (OMX_COMPONENTTYPE*)pHandle;
 
     /* SR10519/17735: Set the interval for the insertion of intra frames at run-time using a custom OMX index */
     eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.IntraFrameInterval", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
-   
+
    /* MPEG4/H263 DSP socket node default value */
-    if(pAppData->nIntraFrameInterval == -1){
-            pAppData->nIntraFrameInterval = 30; 
+    if(pAppData->nIntraFrameInterval == VIDENCTEST_USE_DEFAULT_VALUE){
+            pAppData->nIntraFrameInterval = 30;
     }
     eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nIntraFrameInterval));
     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_SetConfig function");
@@ -1595,28 +1594,28 @@
         pAppData->eCompressionFormat == OMX_VIDEO_CodingH263) {
         /* SR10540: Set the Target Frame Rate at run-time using a custom OMX index */
         eError = OMX_GetExtensionIndex(pHandle,
-                                       "OMX.TI.VideoEncode.Config.TargetFrameRate", 
+                                       "OMX.TI.VideoEncode.Config.TargetFrameRate",
                                        (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
         VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
-        
-        pAppData->nTargetFrameRate = pAppData->nFramerate; /* Refer to DSP socket node interface guide for usage */ 
+
+        pAppData->nTargetFrameRate = pAppData->nFramerate; /* Refer to DSP socket node interface guide for usage */
         eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nTargetFrameRate));
         VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_SetConfig function");
     }
 
     /* SR10523: Set the AIRRate at run-time using a custom OMX index */
     eError = OMX_GetExtensionIndex(pHandle,
-                                   "OMX.TI.VideoEncode.Config.AIRRate", 
+                                   "OMX.TI.VideoEncode.Config.AIRRate",
                                    (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
-    pAppData->nAIRRate = 0; /* Refer to DSP socket node interface guide for usage */ 
+    pAppData->nAIRRate = 0; /* Refer to DSP socket node interface guide for usage */
     eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nAIRRate));
     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_SetConfig function");
 
     /* SR12005: Set the Target Bit Rate at run-time using a custom OMX index */
     eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.TargetBitRate", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
-    
+
     pAppData->nTargetBitRate = pAppData->nBitrate; /* Refer to DSP socket node interface guide for usage */
     eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nTargetBitRate));
     VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_SetConfig function");
@@ -1624,7 +1623,7 @@
     /*Initialize Frame Counter */
     pAppData->nCurrentFrameIn = 0;
     pAppData->nCurrentFrameOut = 0;
-    
+
 
     /*Validation of stopframe in cases of Pause->Resume and Stop->Restart test cases*/
     if ( pAppData->eTypeOfTest == VIDENCTEST_StopRestart || pAppData->eTypeOfTest == VIDENCTEST_PauseResume) {
@@ -1647,7 +1646,7 @@
             nBuffersToSend = pAppData->nReferenceFrame;
             }
 
-        
+
 
     for (nCounter = 0; nCounter < nBuffersToSend; nCounter++) {
         pAppData->pOutBuff[nCounter]->nFilledLen = 0;
@@ -1655,7 +1654,7 @@
         VIDENCTEST_CHECK_EXIT(eError, "Error in FillThisBuffer");
         pAppData->nOutBufferCount--;
     }
-    
+
     /* Send EmptyThisBuffer to OMX Video Encoder */
     for (nCounter = 0; nCounter < nBuffersToSend; nCounter++) {
         pAppData->pInBuff[nCounter]->nFilledLen = VIDENCTEST_fill_data(pAppData->pInBuff[nCounter], pAppData->fIn , pAppData->pInPortDef->nBufferSize);
@@ -1667,13 +1666,13 @@
             pAppData->nInBufferCount--;
             goto EXIT;
         }
-        else {              
+        else {
             pAppData->pComponent->EmptyThisBuffer(pHandle, pAppData->pInBuff[nCounter]);
             pAppData->nInBufferCount--;
             pAppData->nCurrentFrameIn++;
-        }                
+        }
     }
-    
+
     pAppData->eCurrentState = VIDENCTEST_StateEncoding;
 
 EXIT:
@@ -1687,20 +1686,20 @@
   *Pass the component to executing  and fill the first 4 buffers.
   *
   * @param  pAppData MYDATA handle
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
-/*-----------------------------------------------------------------------------*/  
+/*-----------------------------------------------------------------------------*/
  OMX_ERRORTYPE VIDENCTEST_DeInit(MYDATATYPE* pAppData)
- {   
+ {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     OMX_ERRORTYPE eErr = OMX_ErrorNone;
     VIDENCTEST_NODE* pListHead;
     OMX_HANDLETYPE pHandle = pAppData->pHandle;
     pListHead = pAppData->pMemoryListHead;
- 
+
     /* Free Component Handle */
     eError = TIOMX_FreeHandle(pHandle);
     VIDENCTEST_CHECK_EXIT(eError, "Error in TIOMX_FreeHandle");
@@ -1708,14 +1707,14 @@
     /* De-Initialize OMX Core */
     eError = TIOMX_Deinit();
     VIDENCTEST_CHECK_EXIT(eError, "Error in TIOMX_Deinit");
-    
+
     /* shutdown */
     fclose(pAppData->fIn);
     fclose(pAppData->fOut);
     if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
         fclose(pAppData->fNalnd);
     }
-    
+
     eErr = close(pAppData->IpBuf_Pipe[0]);
     if (0 != eErr && OMX_ErrorNone == eError) {
         eError = OMX_ErrorHardware;
@@ -1733,7 +1732,7 @@
         eError = OMX_ErrorHardware;
         VIDENCTEST_DPRINT ("Error while closing data pipe\n");
     }
-    
+
     eErr = close(pAppData->IpBuf_Pipe[1]);
     if (0 != eErr && OMX_ErrorNone == eError) {
         eError = OMX_ErrorHardware;
@@ -1751,21 +1750,21 @@
         eError = OMX_ErrorHardware;
         VIDENCTEST_DPRINT ("Error while closing data pipe\n");
     }
-    
+
     pAppData->fIn = NULL;
     pAppData->fOut = NULL;
     pAppData->fNalnd = NULL;
- 
+
     VIDENCTEST_FreeResources(pAppData);
     VIDENCTEST_CHECK_EXIT(eError, "Error in FillThisBuffer");
-    
+
     VIDENCTEST_FREE(pAppData, pListHead);
     VIDENCTEST_ListDestroy(pListHead);
     pAppData = NULL;
-    
+
 EXIT:
     return eError;
- 
+
 }
 
 /*-----------------------------------------------------------------------------*/
@@ -1776,10 +1775,10 @@
   *
   * @param  pAppData
   * @param  nData2 - State that has been set.
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_HandleState(MYDATATYPE* pAppData, OMX_U32 eState)
@@ -1788,7 +1787,7 @@
     OMX_HANDLETYPE pHandle = pAppData->pHandle;
     OMX_U32 nCounter = 0;
     VIDENCTEST_NODE* pListHead;
-    
+
     pListHead = pAppData->pMemoryListHead;
 
     switch (eState) {
@@ -1819,18 +1818,18 @@
                     }
                     pAppData->bStop = OMX_FALSE;
                 }
-                
+
                 VIDENCTEST_PRINT("Disable Input Port\n");
                 eError = OMX_SendCommand(pHandle, OMX_CommandPortDisable, VIDENC_INPUT_PORT, NULL);
                 VIDENCTEST_CHECK_EXIT(eError, "Error from OMX_SendCommand function\n");
 
-                if (pAppData->bAllocateIBuf == OMX_TRUE) { 
+                if (pAppData->bAllocateIBuf == OMX_TRUE) {
                     for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
                         pAppData->pIBuffer[nCounter] -= 128;
                         pAppData->pIBuffer[nCounter] = (unsigned char*)pAppData->pIBuffer[nCounter];
                         VIDENCTEST_FREE(pAppData->pIBuffer[nCounter], pListHead);
                         pAppData->pIBuffer[nCounter] = NULL;
-                    } 
+                    }
                 }
                 for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
                     eError = OMX_FreeBuffer(pHandle, pAppData->pInPortDef->nPortIndex, pAppData->pInBuff[nCounter]);
@@ -1875,16 +1874,16 @@
   *
   * @param  pAppData
   * @param  argv
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_CheckArgs_H263(MYDATATYPE* pAppData, char** argv)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    
+
     switch (atoi(argv[9])) {
         case 0:
             pAppData->eControlRate = OMX_Video_ControlRateDisable;
@@ -1900,10 +1899,10 @@
             printf("*Error: Input Argument CONTROL RATE is not valid");
             goto EXIT;
     }
-    
+
     pAppData->nGOBHeaderInterval = atoi(argv[10]);
     pAppData->nQpI = atoi(argv[11]);
-        
+
     switch (atoi(argv[12])) {
         case 10:
             pAppData->eLevelH63 = OMX_VIDEO_H263Level10;
@@ -1934,19 +1933,19 @@
             printf("*Error: Input Argument LEVEL is not valid");
             goto EXIT;
     }
-    
-    if (atoi(argv[13]) == 0) { 
+
+    if (atoi(argv[13]) == 0) {
         pAppData->bAllocateIBuf = OMX_FALSE;
         pAppData->bAllocateOBuf = OMX_FALSE;
     }
-    else { 
+    else {
         pAppData->bAllocateIBuf = OMX_TRUE;
         pAppData->bAllocateOBuf = OMX_TRUE;
     }
 
     pAppData->nVBVSize = atoi(argv[14]);
-    
-    
+
+
 EXIT:
     return eError;
 }
@@ -1959,16 +1958,16 @@
   *
   * @param  pAppData
   * @param  argv
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_CheckArgs_Mpeg4(MYDATATYPE* pAppData, char** argv)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    
+
     switch (atoi(argv[9])) {
         case 0:
             pAppData->eControlRate = OMX_Video_ControlRateDisable;
@@ -1984,13 +1983,13 @@
             printf("*Error: Input Argument CONTROL RATE is not valid");
             goto EXIT;
     }
-            
+
     pAppData->nQpI = atoi(argv[11]);
 
 #if 0
    pAppData->eLevelMpeg4 = atoi(argv[12]);
 
-#else    
+#else
     switch (atoi(argv[12])) {
         case 0:
             pAppData->eLevelMpeg4 = OMX_VIDEO_MPEG4Level0;
@@ -2019,20 +2018,20 @@
             goto EXIT;
         }
 #endif
-    
 
-    if (atoi(argv[13]) == 0) { 
+
+    if (atoi(argv[13]) == 0) {
         pAppData->bAllocateIBuf = OMX_FALSE;
         pAppData->bAllocateOBuf = OMX_FALSE;
     }
-    else { 
+    else {
         pAppData->bAllocateIBuf = OMX_TRUE;
         pAppData->bAllocateOBuf = OMX_TRUE;
     }
 
     pAppData->nVBVSize = atoi(argv[14]);
-    
-    
+
+
 EXIT:
     return eError;
 }
@@ -2045,16 +2044,16 @@
   *
   * @param  pAppData
   * @param  argv
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_CheckArgs_AVC(MYDATATYPE* pAppData, char** argv)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    
+
     switch (atoi(argv[9])) {
         case 10:
             pAppData->eLevelH264 = OMX_VIDEO_AVCLevel1;
@@ -2091,11 +2090,11 @@
 
     pAppData->nOutBuffSize  = atoi(argv[10]);
 
-    if (atoi(argv[11]) == 0) { 
+    if (atoi(argv[11]) == 0) {
         pAppData->bAllocateIBuf = OMX_FALSE;
         pAppData->bAllocateOBuf = OMX_FALSE;
     }
-    else { 
+    else {
         pAppData->bAllocateIBuf = OMX_TRUE;
         pAppData->bAllocateOBuf = OMX_TRUE;
     }
@@ -2111,8 +2110,8 @@
         printf("*Error: Input Argument DEBLOCK FILTER is not valid");
         goto EXIT;
     }
-    
-    
+
+
     switch (atoi(argv[13])) {
         case 0:
             pAppData->eControlRate = OMX_Video_ControlRateDisable;
@@ -2126,9 +2125,9 @@
         default:
             ;
     }
-    
+
     pAppData->nQpI = atoi(argv[14]);
-     
+
 EXIT:
     return eError;
 }
@@ -2141,10 +2140,10 @@
   *
   * @param  argc
   * @param  argv
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 
@@ -2160,6 +2159,8 @@
         {"nEncodingPreset",   1, NULL, 'p'},
         {"nRrker",   1, NULL, 'e'},
         {"NALFormat",   1, NULL, 'n'},
+        {"nQPIoF", 1, NULL, 'q'},
+        {"nUnrestrictedMV", 1, NULL, 'u'},
         {NULL,          0, NULL,   0}
     };
 
@@ -2193,13 +2194,20 @@
                 printf("%d Nal Format found, Value= %s\n",next_option,optarg);
                 pAppData->NalFormat=atoi(optarg);
                 break;
+            case 'q':
+                printf("%d QPI value changed each %d frames\n",next_option,atoi(optarg));
+                pAppData->nQPIoF=atoi(optarg);
+            case 'u':
+                printf("%d nUnrestrictedMV found, Value= %s\n",next_option,optarg);
+                pAppData->nUnrestrictedMV=atoi(optarg);
+                break;
             case -1:
                 break;
             default:
                 printf("** Warning: %d No valid param found. Proceeding with test. optarg= %s\n",next_option,optarg);
-                
+
             }
-    
+
     }
     while(next_option != -1);
 
@@ -2216,10 +2224,10 @@
   * @param  argc
   * @param  argv
   * @param pAppDataTmp
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_CheckArgs(int argc, char** argv, MYDATATYPE** pAppDataTmp)
@@ -2227,22 +2235,25 @@
     OMX_ERRORTYPE eError = OMX_ErrorNone;
     VIDENCTEST_NODE*  pMemoryListHead;
     MYDATATYPE* pAppData;
-    
-    eError = VIDENCTEST_ListCreate(&pMemoryListHead);    
+
+    eError = VIDENCTEST_ListCreate(&pMemoryListHead);
     VIDENCTEST_CHECK_EXIT(eError, "Error at Creating Memory List");
-    
+
     VIDENCTEST_MALLOC(pAppData, sizeof(MYDATATYPE), MYDATATYPE, pMemoryListHead);
     VIDENCTEST_CHECK_EXIT(eError, "Error at Allocating MYDATATYPE structure");
     *pAppDataTmp = pAppData;
     pAppData->pMemoryListHead = pMemoryListHead;
     pAppData->eCurrentState = VIDENCTEST_StateUnLoad;
-    pAppData->nMIRRate=-1;
-    pAppData->nResynchMarkerSpacing=-1;
-    pAppData->nIntraFrameInterval=-1;
-    pAppData->nEncodingPreset=-1;
+    pAppData->nMIRRate=VIDENCTEST_USE_DEFAULT_VALUE;
+    pAppData->nResynchMarkerSpacing=VIDENCTEST_USE_DEFAULT_VALUE;
+    pAppData->nIntraFrameInterval=VIDENCTEST_USE_DEFAULT_VALUE;
+    pAppData->nEncodingPreset=VIDENCTEST_USE_DEFAULT_VALUE_UI;
+    pAppData->nUnrestrictedMV=(OMX_U8)VIDENCTEST_USE_DEFAULT_VALUE_UI;
     pAppData->NalFormat = 0;
+    pAppData->nQPIoF = 0;
+    pAppData->bForceIFrame = 0;
 
-    
+
     if (argc < 15){
         printf("*Error: Input argument COLOR FORMAT is not valid");
         VIDENCTEST_PrintCorrectArgs(OMX_TRUE, OMX_TRUE);
@@ -2250,33 +2261,33 @@
         goto EXIT;
     }
     else {
-        
+
         pAppData->szInFile = argv[1];
         pAppData->fIn = fopen(pAppData->szInFile, "r");
         if (!pAppData->fIn) {
             printf("Error: failed to open the file <%s>", pAppData->szInFile);
             eError = OMX_ErrorBadParameter;
             goto EXIT;
-        }    
-        
+        }
+
         pAppData->szOutFile = argv[2];
         pAppData->fOut = fopen(pAppData->szOutFile, "w");
         if (!pAppData->fOut) {
             VIDENCTEST_DPRINT("Error: failed to open the file <%s>", pAppData->szOutFile);
             eError = OMX_ErrorBadParameter;
             goto EXIT;
-        }   
-        
+        }
+
         pAppData->nWidth = atoi(argv[3]);
         if (pAppData->nWidth & 15) {
-            printf("**Warning: Input Argument WIDTH is not multiple of 16. \n"); 
+            printf("**Warning: Input Argument WIDTH is not multiple of 16. \n");
         }
-        
+
         pAppData->nHeight = atoi(argv[4]);
         if (pAppData->nHeight & 15) {
             printf("**Warning: Input Argument HEIGHT is not multiple of 16. \n");
         }
-        
+
         switch (atoi(argv[5])) {
             case 19:
                 pAppData->eColorFormat = OMX_COLOR_FormatYUV420Planar;/*420*/
@@ -2293,17 +2304,17 @@
                 eError = OMX_ErrorBadParameter;
                 goto EXIT;
         }
-        
+
         pAppData->nBitrate = atoi(argv[6]);
-        if(pAppData->nBitrate < 64000 || pAppData->nBitrate > 8000000) {
+        if(pAppData->nBitrate > 10000000) {
             printf("**Warning: Input argument BITRATE outside of tested range, behavior of component unknown.\n");
         }
-        
+
         pAppData->nFramerate = atoi(argv[7]);
         if(pAppData->nFramerate < 7 || pAppData->nFramerate > 30) {
             printf("**Warning: Input argument FRAMERATE outside of tested range, behavior of component unknown.\n");
         }
-        
+
         switch (atoi(argv[8])) {
             case 3:
                 pAppData->eCompressionFormat = OMX_VIDEO_CodingH263;
@@ -2327,7 +2338,7 @@
                 goto EXIT;
         }
     }
-    
+
     if (argc < 16) {
         pAppData->eTypeOfTest = VIDENCTEST_FullRecord;
         printf("**Warning: Input Arguments TYPE OF TEST is not include input. Using Default value VIDENCTEST_FullRecord.\n");
@@ -2363,15 +2374,13 @@
     else{
         pAppData->nReferenceFrame = atoi(argv[16]);
     }
-    
+
     if (argc < 18) {
         pAppData->nNumberOfTimesTodo = 1;
-        printf("**Warning: Input Arguments nNumberOfTimesTodo has not been specified. Using Default value 1.\n");
     }
     else{
         if(argv[17][0]<'0' || argv[17][0] > '9'){
             pAppData->nNumberOfTimesTodo = 1;
-            printf("**Warning: Input Arguments nNumberOfTimesTodo has not been specified.. Using Default value 1.\n");
         }
         else{
             pAppData->nNumberOfTimesTodo  = atoi(argv[17]);
@@ -2382,7 +2391,7 @@
     VIDENCTEST_CheckOptionalArgs(pAppData, argc, argv);
 
     if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
-        VIDENCTEST_MALLOC(pAppData->szOutFileNal, strlen(pAppData->szOutFile)+3, char, pMemoryListHead); 
+        VIDENCTEST_MALLOC(pAppData->szOutFileNal, strlen(pAppData->szOutFile)+3, char, pMemoryListHead);
         strcpy(pAppData->szOutFileNal, pAppData->szOutFile);
         strcat(pAppData->szOutFileNal, "nd");
         pAppData->fNalnd = fopen(pAppData->szOutFileNal, "w");
@@ -2401,15 +2410,15 @@
 /**
   * Confirm()
   *
-  *Check what type of test, repetions to be done and takes certain path. 
+  *Check what type of test, repetions to be done and takes certain path.
   *
   * @param  argc
   * @param  argv
   * @param pAppDataTmp
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_Confirm(MYDATATYPE* pAppData)
@@ -2466,12 +2475,12 @@
                     else{
                         pAppData->bStop = OMX_FALSE;
                     }
-                    
+
                     pAppData->fOut = fopen(pAppData->szOutFile, "w");
                     if (!pAppData->fOut){
                         VIDENCTEST_CHECK_EXIT(OMX_ErrorUndefined, "Error at fopen function");
                     }
-                    if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) { 
+                    if(pAppData->NalFormat == VIDENC_TEST_NAL_FRAME || pAppData->NalFormat == VIDENC_TEST_NAL_SLICE) {
                         pAppData->fNalnd = fopen(pAppData->szOutFileNal, "w");
                         if (!pAppData->fNalnd){
                             VIDENCTEST_CHECK_EXIT(OMX_ErrorUndefined, "Error at fopen function");
@@ -2483,9 +2492,9 @@
                 VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
             }
         }
-        
+
         pAppData->eCurrentState = VIDENCTEST_StateWaitEvent;
-        
+
 EXIT:
     return eError;
 }
@@ -2499,10 +2508,10 @@
   * @param  argc
   * @param  argv
   * @param pAppDataTmp
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_HandlePortDisable(MYDATATYPE* pAppData, OMX_U32 ePort)
@@ -2511,17 +2520,17 @@
     OMX_HANDLETYPE pHandle = pAppData->pHandle;
     OMX_U32 nCounter;
     VIDENCTEST_NODE* pListHead;
-    
+
     pAppData->nUnresponsiveCount = 0;
     pListHead = pAppData->pMemoryListHead;
-    
+
     if (ePort == VIDENC_INPUT_PORT){
         eError = OMX_SendCommand(pHandle, OMX_CommandPortDisable, VIDENC_OUTPUT_PORT, NULL);
         VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
-        
+
         if (pAppData->bAllocateOBuf == OMX_TRUE) {
-            for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {                   
-                pAppData->pOBuffer[nCounter] -= 128;                        
+            for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
+                pAppData->pOBuffer[nCounter] -= 128;
                 pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
                 VIDENCTEST_FREE(pAppData->pOBuffer[nCounter], pListHead);
                 pAppData->pOBuffer[nCounter] = NULL;
@@ -2541,7 +2550,7 @@
         else {
             eError = OMX_SendCommand(pHandle, OMX_CommandPortEnable, VIDENC_INPUT_PORT, NULL);
             VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
-            
+
             for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
                 if (pAppData->bAllocateIBuf == OMX_TRUE) {
                     VIDENCTEST_MALLOC(pAppData->pIBuffer[nCounter], pAppData->nSizeIn + 256, OMX_U8, pListHead);
@@ -2552,26 +2561,26 @@
 
             for (nCounter = 0; nCounter < NUM_OF_IN_BUFFERS; nCounter++) {
                 if (pAppData->bAllocateIBuf == OMX_TRUE) {
-                eError = OMX_UseBuffer(pHandle, 
-                                        &pAppData->pInBuff[nCounter], 
-                                        pAppData->pInPortDef->nPortIndex, 
-                                        pAppData, 
+                eError = OMX_UseBuffer(pHandle,
+                                        &pAppData->pInBuff[nCounter],
+                                        pAppData->pInPortDef->nPortIndex,
+                                        pAppData,
                                         pAppData->pInPortDef->nBufferSize,
                                         pAppData->pIBuffer[nCounter]);
                 VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_UseBuffer function");
                 }
                 else {
-                    eError = OMX_AllocateBuffer(pHandle, 
-                                                &pAppData->pInBuff[nCounter], 
-                                                pAppData->pInPortDef->nPortIndex, 
-                                                pAppData, 
+                    eError = OMX_AllocateBuffer(pHandle,
+                                                &pAppData->pInBuff[nCounter],
+                                                pAppData->pInPortDef->nPortIndex,
+                                                pAppData,
                                                 pAppData->pInPortDef->nBufferSize);
                     VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_AllocateBuffer function");
                 }
             }
         }
     }
-    
+
 
 EXIT:
     return eError;
@@ -2584,11 +2593,11 @@
   *Handles PortEnable Event
   *
   * @param  pAppData
-  * @param  nPort 
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  * @param  nPort
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_HandlePortEnable(MYDATATYPE* pAppData, OMX_U32 ePort)
@@ -2597,37 +2606,37 @@
     OMX_HANDLETYPE pHandle = pAppData->pHandle;
     OMX_U32 nCounter;
     VIDENCTEST_NODE* pListHead;
-    
+
     pAppData->nUnresponsiveCount = 0;
     pListHead = pAppData->pMemoryListHead;
-    
+
     if (ePort == VIDENC_INPUT_PORT){
         eError = OMX_SendCommand(pHandle, OMX_CommandPortEnable, VIDENC_OUTPUT_PORT, NULL);
         VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_SendCommand function");
-        
+
         for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
             if (pAppData->bAllocateOBuf == OMX_TRUE) {
-                VIDENCTEST_MALLOC(pAppData->pOBuffer[nCounter], pAppData->nSizeOut + 256, OMX_U8, pListHead);                          
-                pAppData->pOBuffer[nCounter] += 128;                          
+                VIDENCTEST_MALLOC(pAppData->pOBuffer[nCounter], pAppData->nSizeOut + 256, OMX_U8, pListHead);
+                pAppData->pOBuffer[nCounter] += 128;
                 pAppData->pOBuffer[nCounter] = (unsigned char*)pAppData->pOBuffer[nCounter];
             }
         }
 
         for (nCounter = 0; nCounter < NUM_OF_OUT_BUFFERS; nCounter++) {
             if (pAppData->bAllocateOBuf == OMX_TRUE) {
-                eError = OMX_UseBuffer(pHandle, 
-                                        &pAppData->pOutBuff[nCounter], 
-                                        pAppData->pOutPortDef->nPortIndex, 
-                                        pAppData, 
+                eError = OMX_UseBuffer(pHandle,
+                                        &pAppData->pOutBuff[nCounter],
+                                        pAppData->pOutPortDef->nPortIndex,
+                                        pAppData,
                                         pAppData->pOutPortDef->nBufferSize,
                                         pAppData->pOBuffer[nCounter]);
                 VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_UseBuffer function");
             }
             else {
-                eError = OMX_AllocateBuffer(pHandle, 
-                                            &pAppData->pOutBuff[nCounter], 
-                                            pAppData->pOutPortDef->nPortIndex, 
-                                            pAppData, 
+                eError = OMX_AllocateBuffer(pHandle,
+                                            &pAppData->pOutBuff[nCounter],
+                                            pAppData->pOutPortDef->nPortIndex,
+                                            pAppData,
                                             pAppData->pOutPortDef->nBufferSize);
                 VIDENCTEST_CHECK_EXIT(eError, "Error at OMX_AllocateBuffer function");
             }
@@ -2649,11 +2658,11 @@
   *Handles PortEnable Event
   *
   * @param  pAppData
-  * @param  nPort 
-  * 
-  * @retval OMX_ErrorNone 
+  * @param  nPort
   *
-  *         
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 OMX_ERRORTYPE VIDENCTEST_HandleEventError(MYDATATYPE* pAppData, OMX_U32 eErr, OMX_U32 nData2)
@@ -2663,7 +2672,7 @@
     VIDENCTEST_PRINT("\n------VIDENCTEST ERROR-------\nOMX_EventError\n");
     VIDENCTEST_PRINT("eErr : %x \n", eErr);
     VIDENCTEST_PRINT("nData2 : %x \n", nData2);
-    
+
     switch (eErr){
      case OMX_ErrorNone:
         break;
@@ -2679,34 +2688,34 @@
      case OMX_ErrorUnderflow:
      case OMX_ErrorOverflow:
         break;
-     case OMX_ErrorInvalidState: 
-#ifdef DSP_MMU_FAULT_HANDLING 
+     case OMX_ErrorInvalidState:
+#ifdef DSP_MMU_FAULT_HANDLING
         bInvalid_state = OMX_TRUE;
 #endif
      case OMX_ErrorHardware:
-     case OMX_ErrorStreamCorrupt: 
-     case OMX_ErrorPortsNotCompatible: 
+     case OMX_ErrorStreamCorrupt:
+     case OMX_ErrorPortsNotCompatible:
      case OMX_ErrorResourcesLost:
-     case OMX_ErrorNoMore: 
-     case OMX_ErrorVersionMismatch: 
-     case OMX_ErrorNotReady: 
-     case OMX_ErrorTimeout: 
-     case OMX_ErrorSameState: 
-     case OMX_ErrorResourcesPreempted: 
+     case OMX_ErrorNoMore:
+     case OMX_ErrorVersionMismatch:
+     case OMX_ErrorNotReady:
+     case OMX_ErrorTimeout:
+     case OMX_ErrorSameState:
+     case OMX_ErrorResourcesPreempted:
         eError = eErr;
         break;
-     case OMX_ErrorPortUnresponsiveDuringAllocation: 
-     case OMX_ErrorPortUnresponsiveDuringDeallocation: 
+     case OMX_ErrorPortUnresponsiveDuringAllocation:
+     case OMX_ErrorPortUnresponsiveDuringDeallocation:
      case OMX_ErrorPortUnresponsiveDuringStop:
         if(pAppData->nUnresponsiveCount++ > MAX_UNRESPONSIVE_COUNT){
             eError = eErr;
         }
         break;
-     case OMX_ErrorIncorrectStateTransition: 
+     case OMX_ErrorIncorrectStateTransition:
      case OMX_ErrorIncorrectStateOperation:
-     case OMX_ErrorUnsupportedSetting: 
-     case OMX_ErrorUnsupportedIndex: 
-     case OMX_ErrorBadPortIndex: 
+     case OMX_ErrorUnsupportedSetting:
+     case OMX_ErrorUnsupportedIndex:
+     case OMX_ErrorBadPortIndex:
      case OMX_ErrorMax:
      default:
         ;
@@ -2724,16 +2733,16 @@
   *
   * @param  argc
   * @param argv
-  *       
-  * @retval OMX_ErrorNone 
-  *               
-  *         
+  *
+  * @retval OMX_ErrorNone
+  *
+  *
   **/
 /*-----------------------------------------------------------------------------*/
 int main(int argc, char** argv)
 {
     OMX_ERRORTYPE eError = OMX_ErrorNone;
-    OMX_HANDLETYPE pHandle;        
+    OMX_HANDLETYPE pHandle;
     OMX_BUFFERHEADERTYPE* pBuffer;
     OMX_U32 nError;
     OMX_U32 nTimeCount;
@@ -2743,7 +2752,7 @@
     sigset_t set;
 
     nTimeCount = 0;
-#ifdef DSP_MMU_FAULT_HANDLING 
+#ifdef DSP_MMU_FAULT_HANDLING
     bInvalid_state = OMX_FALSE;
 #endif
     OMX_OTHER_EXTRADATATYPE_1_1_2 *pExtraDataType;
@@ -2751,7 +2760,7 @@
     OMX_U32* pIndexNal;
     OMX_U32 nNalSlices;
 
-    
+
     VIDENCTEST_PRINT("Enter to CheckArgs\n");
 
     eError = VIDENCTEST_CheckArgs(argc, argv, &pAppData);
@@ -2763,25 +2772,25 @@
     eError = VIDENCTEST_PassToLoaded(pAppData);
     VIDENCTEST_CHECK_ERROR(eError, "Error at Initialization of Component");
     VIDENCTEST_PRINT("Exit to PassToLoaded\n");
-    
+
     pListHead = pAppData->pMemoryListHead;
     pHandle = pAppData->pHandle;
-    
+
     VIDENCTEST_PRINT("Enter to PassToReady\n");
     eError = VIDENCTEST_PassToReady(pAppData);
     VIDENCTEST_CHECK_ERROR(eError, "Error at Passing to ComponentReady State");
     VIDENCTEST_PRINT("Exit to PassToReady\n");
-    
+
     while(1){
         FD_ZERO(&rfds);
         FD_SET(pAppData->IpBuf_Pipe[0], &rfds);
-        FD_SET(pAppData->OpBuf_Pipe[0], &rfds); 
+        FD_SET(pAppData->OpBuf_Pipe[0], &rfds);
         FD_SET(pAppData->eventPipe[0], &rfds);
-        
+
         sigemptyset(&set);
         sigaddset(&set,SIGALRM);
         pAppData->nRetVal = pselect(pAppData->fdmax+1, &rfds, NULL, NULL, NULL,&set);
-        
+
         if (pAppData->nRetVal == -1) {
             perror("pselect()");
             VIDENCTEST_DPRINT("Error\n");
@@ -2800,7 +2809,7 @@
         else{
             nTimeCount = 0;
         }
-        
+
         if (FD_ISSET(pAppData->eventPipe[0], &rfds)) {
             EVENT_PRIVATE* pEventPrivate = NULL;
             OMX_EVENTTYPE eEvent = -1;
@@ -2835,7 +2844,7 @@
                             VIDENCTEST_CHECK_ERROR(eError, "Error at PortPortEnable function");
                             VIDENCTEST_PRINT("Exits to HandlePortEnable\n");
                             break;
-                        case OMX_CommandMarkBuffer: 
+                        case OMX_CommandMarkBuffer:
                             ;
                     }
                     break;
@@ -2877,62 +2886,89 @@
                     VIDENCTEST_CHECK_ERROR(OMX_ErrorUndefined, "Error at EmptyThisBuffer function");
                     break;
             }
-            
+
             VIDENCTEST_FREE(pEventPrivate, pListHead);
         }
-        
+
         if(FD_ISSET(pAppData->IpBuf_Pipe[0], &rfds)){
             VIDENCTEST_PRINT("Input Pipe event receive\n");
             read(pAppData->IpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
             pAppData->nInBufferCount++;
-            
+
             if(pAppData->eCurrentState == VIDENCTEST_StateEncoding) {
                 pBuffer->nFilledLen = VIDENCTEST_fill_data(pBuffer, pAppData->fIn , pAppData->pInPortDef->nBufferSize);
-                
+
                 if (pBuffer->nFlags == OMX_BUFFERFLAG_EOS && pBuffer->nFilledLen == 0) {
                     pAppData->eCurrentState = VIDENCTEST_StateStopping;
                     eError = pAppData->pComponent->EmptyThisBuffer(pHandle, pBuffer);
                     VIDENCTEST_CHECK_ERROR(eError, "Error at EmptyThisBuffer function");
                     pAppData->nInBufferCount--;
                 }
-                
-                if( pAppData->eTypeOfTest != VIDENCTEST_FullRecord){
+
+                if(pAppData->eTypeOfTest != VIDENCTEST_FullRecord){
                     if(pAppData->nCurrentFrameIn == pAppData->nReferenceFrame){
-                            pAppData->eCurrentState = VIDENCTEST_StateStopping;
+                        pAppData->eCurrentState = VIDENCTEST_StateStopping;
+                        if(pAppData->eTypeOfTest == VIDENCTEST_PauseResume) {
+                            eError = pAppData->pComponent->EmptyThisBuffer(pHandle, pBuffer);
+                            VIDENCTEST_CHECK_ERROR(eError, "Error at EmptyThisBuffer function");
+                            pAppData->nInBufferCount--;
+                            pAppData->nCurrentFrameIn++;
+                        }
                     }
-                }    
-                
+                }
+
                 if(pAppData->eCurrentState == VIDENCTEST_StateEncoding){
+                    if(pAppData->nQPIoF > 0) {
+                        if(!(pAppData->nCurrentFrameIn % pAppData->nQPIoF)) {
+                            pAppData->bForceIFrame = OMX_TRUE;
+
+                            eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.ForceIFrame", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
+                            VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
+                            eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->bForceIFrame));
+                            VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for bForceIFrame");
+                            eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.QPI", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
+                            VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
+                            eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->nQpI));
+                            VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for bForceIFrame");
+                        }
+                        else {
+                            pAppData->bForceIFrame = OMX_FALSE;
+                            eError = OMX_GetExtensionIndex(pHandle,"OMX.TI.VideoEncode.Config.ForceIFrame", (OMX_INDEXTYPE*)(&(pAppData->nVideoEncodeCustomParamIndex)));
+                            VIDENCTEST_CHECK_EXIT(eError, "Error in OMX_GetExtensionIndex function");
+                            eError = OMX_SetConfig(pHandle, pAppData->nVideoEncodeCustomParamIndex, &(pAppData->bForceIFrame));
+                            VIDENCTEST_CHECK_EXIT(eError, "Error at SetConfig for bForceIFrame");
+                        }
+                    }
                     eError = pAppData->pComponent->EmptyThisBuffer(pHandle, pBuffer);
                     VIDENCTEST_CHECK_ERROR(eError, "Error at EmptyThisBuffer function");
                     pAppData->nInBufferCount--;
                     pAppData->nCurrentFrameIn++;
                 }
             }
-            
+
             if(pAppData->eCurrentState == VIDENCTEST_StateStopping) {
                 if(pAppData->nInBufferCount == NUM_OF_IN_BUFFERS){
                     pAppData->eCurrentState = VIDENCTEST_StateConfirm;
                 }
             }
         }
-        
+
         if(FD_ISSET(pAppData->OpBuf_Pipe[0], &rfds)){
             VIDENCTEST_PRINT("Output Pipe event receive\n");
             read(pAppData->OpBuf_Pipe[0], &pBuffer, sizeof(pBuffer));
             pAppData->nOutBufferCount++;
-            pAppData->nCurrentFrameOut++;
-            
-            
+
+
             /* check is it is the last buffer */
             if((pBuffer->nFlags & OMX_BUFFERFLAG_EOS) ||
-                (pAppData->eTypeOfTest != VIDENCTEST_FullRecord && 
+                (pAppData->eTypeOfTest != VIDENCTEST_FullRecord &&
                 pAppData->nCurrentFrameIn == pAppData->nReferenceFrame)) {
                 pAppData->bLastOutBuffer = 1;
             }
 
             /*App sends last buffer as null buffer, so buffer with EOS contains only garbage*/
-            /*if(!(pBuffer->nFlags & OMX_BUFFERFLAG_EOS))*/ {
+            if(pBuffer->nFilledLen) {
+                pAppData->nCurrentFrameOut++;
                 fwrite(pBuffer->pBuffer, 1, pBuffer->nFilledLen, pAppData->fOut);
                 nError = ferror(pAppData->fOut);
                 if (nError != 0) {
@@ -2942,7 +2978,7 @@
                 if (nError != 0) {
                     VIDENCTEST_DPRINT("ERROR: flushing file\n");
                 }
-               
+
                 if(pAppData->NalFormat == VIDENC_TEST_NAL_SLICE){
                     nNalSlices = 1;
                     fwrite(&nNalSlices, 1, sizeof(OMX_U32), pAppData->fNalnd);
@@ -2990,7 +3026,7 @@
                 pAppData->nOutBufferCount--;
             }
         }
-        
+
         if (pAppData->eCurrentState == VIDENCTEST_StateConfirm ) {
             if (pAppData->bLastOutBuffer){
                 VIDENCTEST_PRINT("Number of Input  Buffer at Client Side : %i\n", pAppData->nInBufferCount);
@@ -3002,42 +3038,46 @@
                 VIDENCTEST_PRINT("Exits to Confirm Function\n");
             }
         }
-        
+
         if (pAppData->eCurrentState == VIDENCTEST_StateUnLoad) {
             VIDENCTEST_PRINT("Exiting while\n");
             break;
         }
         sched_yield();
     }
-    
+    if(pAppData->nCurrentFrameIn != pAppData->nCurrentFrameOut)
+    {
+        printf("App: Warning!!! FrameIn: %d FrameOut: %d\n", (int)pAppData->nCurrentFrameIn, (int)pAppData->nCurrentFrameOut);
+    }
+
     eError = VIDENCTEST_DeInit(pAppData);
 
-EXIT:    
+EXIT:
     return eError;
 }
 
-#ifdef DSP_MMU_FAULT_HANDLING 
+#ifdef DSP_MMU_FAULT_HANDLING
 int LoadBaseImage()
 {
     unsigned int uProcId = 0;   /* default proc ID is 0. */
     unsigned int index = 0;
-    
+
     struct DSP_PROCESSORINFO dspInfo;
     DSP_HPROCESSOR hProc;
     DSP_STATUS status = DSP_SOK;
     unsigned int numProcs;
     char* argv[2];
-   
+
     argv[0] = "/lib/dsp/baseimage.dof";
-    
+
     status = (DBAPI)DspManager_Open(0, NULL);
     if (DSP_FAILED(status)) {
         printf("DSPManager_Open failed \n");
         return -1;
-    } 
+    }
     while (DSP_SUCCEEDED(DSPManager_EnumProcessorInfo(index,&dspInfo,
         (unsigned int)sizeof(struct DSP_PROCESSORINFO),&numProcs))) {
-        if ((dspInfo.uProcessorType == DSPTYPE_55) || 
+        if ((dspInfo.uProcessorType == DSPTYPE_55) ||
             (dspInfo.uProcessorType == DSPTYPE_64)) {
             uProcId = index;
             status = DSP_SOK;
@@ -3054,11 +3094,11 @@
                 status = DSPProcessor_Start(hProc);
                 if (DSP_SUCCEEDED(status)) {
                     fprintf(stderr,"Baseimage Loaded\n");
-                } 
+                }
                 else {
                     fprintf(stderr,"APP: Baseimage start error!\n");
                 }
-            } 
+            }
             else {
                 fprintf(stderr,"APP: Baseimage load error!\n");
             }