Merge "Prevent video decoder component to overwrite client's set parameter request This patch was originally from MOT/TI"
diff --git a/liboverlay/v4l2_utils.c b/liboverlay/v4l2_utils.c
index 2590097..78aa3ff 100644
--- a/liboverlay/v4l2_utils.c
+++ b/liboverlay/v4l2_utils.c
@@ -193,27 +193,15 @@
     int fd;
 
     switch (fmt) {
-        case OVERLAY_FORMAT_RGBA_8888:
-            return -1;
         case OVERLAY_FORMAT_RGB_565:
             pix->pixelformat = V4L2_PIX_FMT_RGB565;
             break;
-        case OVERLAY_FORMAT_BGRA_8888:
-            return -1;
-        case OVERLAY_FORMAT_YCbCr_422_SP:
-            break;
-        case OVERLAY_FORMAT_YCbCr_420_SP:
-            return -1;
         case OVERLAY_FORMAT_YCbYCr_422_I:
             pix->pixelformat = V4L2_PIX_FMT_YUYV;
             break;
         case OVERLAY_FORMAT_CbYCrY_422_I:
             pix->pixelformat = V4L2_PIX_FMT_UYVY;
             break;
-        case OVERLAY_FORMAT_YCbYCr_420_I:
-            return -1;
-        case OVERLAY_FORMAT_CbYCrY_420_I:
-            return -1;
         default:
             return -1;
     }
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 4daf12a..d4ddeed 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
@@ -939,6 +939,9 @@
 
     struct OMX_TI_Debug dbg;
 
+    /** Indicate when first output buffer received from DSP **/
+    OMX_U32 first_output_buf_rcv;
+
 } AACDEC_COMPONENT_PRIVATE;
 
 /* ================================================================================= * */
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 16d756e..02c1911 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
@@ -383,6 +383,7 @@
     pComponentPrivate->num_Sent_Ip_Buff = 0;
     pComponentPrivate->num_Reclaimed_Op_Buff = 0;
     pComponentPrivate->bIsEOFSent = 0;
+    pComponentPrivate->first_output_buf_rcv = 0;
 
     nRet = pipe (pComponentPrivate->dataPipe);
     if (0 != nRet) {
@@ -1788,7 +1789,10 @@
             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;
+                if (pComponentPrivate->first_output_buf_rcv != 0) {
+                    pComponentPrivate->first_buff = 0;
+                    pComponentPrivate->first_output_buf_rcv = 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;
@@ -2662,6 +2666,7 @@
                 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: Output: Filled Len = %ld\n",__LINE__, pLcmlHdr->pBufHdr->nFilledLen);
                 OMX_PRCOMM2(pComponentPrivate->dbg, "%d :: Output: pLcmlHeader->pBufHdr = %p\n",__LINE__, pLcmlHdr->pBufHdr);
                 pComponentPrivate->lcml_nCntOpReceived++;
+                pComponentPrivate->first_output_buf_rcv = 1;
 #ifdef __PERF_INSTRUMENTATION__
                 PERF_ReceivedFrame(pComponentPrivate->pPERFcomp,
                                    PREF(pLcmlHdr->pBufHdr,pBuffer),
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 833cfe2..f8b6fb0 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
@@ -850,6 +850,9 @@
 
     struct OMX_TI_Debug dbg;
 
+    /** Indicate when first output buffer received from DSP **/
+    OMX_U32 first_output_buf_rcv;
+
 } AMRDEC_COMPONENT_PRIVATE;
 
 typedef enum OMX_NBAMRDEC_INDEXAUDIOTYPE {
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 6096b24..13147d4 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
@@ -411,6 +411,7 @@
     pComponentPrivate->lcml_nIpBuf = 0;
     pComponentPrivate->app_nBuf = 0;
     pComponentPrivate->num_Reclaimed_Op_Buff = 0;
+    pComponentPrivate->first_output_buf_rcv = 0;
 
     /* create the pipe used to send buffers to the thread */
     eError = pipe (pComponentPrivate->cmdDataPipe);
@@ -1648,7 +1649,10 @@
             OMX_PRCOMM1(pComponentPrivate->dbg, "Flushing out port %d\n",pComponentPrivate->nUnhandledFillThisBuffers);
             if (pComponentPrivate->nUnhandledFillThisBuffers == 0)  {
                 pComponentPrivate->bFlushOutputPortCommandPending = OMX_FALSE;
-                pComponentPrivate->first_buff = 0;
+                if (pComponentPrivate->first_output_buf_rcv != 0) {
+                    pComponentPrivate->first_buff = 0;
+                    pComponentPrivate->first_output_buf_rcv = 0;
+                }
 
                 aParam[0] = USN_STRMCMD_FLUSH; 
                 aParam[1] = 0x1; 
@@ -2669,6 +2673,7 @@
 
             NBAMRDEC_ClearPending(pComponentPrivate,pLcmlHdr->buffer,OMX_DirOutput);
             pComponentPrivate->nOutStandingFillDones++;
+            pComponentPrivate->first_output_buf_rcv = 1;
 
             for(i=0;i<pLcmlHdr->pBufferParam->usNbFrames;i++){
                  if ( (pLcmlHdr->pFrameParam+i)->usLastFrame & OMX_BUFFERFLAG_EOS){